feat: the ribbon's References, Review and View tabs
References inserts the table of contents and sets how deep it goes — the depth attribute round-tripped with no way to change it. Review holds the statistics panel and the spell-check language, View the ruler, formatting marks and zoom; each of those had lived only in the status bar or the secondary toolbar. That is all seven fixed tabs.
This commit is contained in:
1 parent
5600e84605
commit
0f53571b1f
8 files changed
+279
No files matched your search
@@ -832,6 +832,12 @@
|
||||
bind:chromeMode
|
||||
bind:documentName
|
||||
bind:showFormattingMarks
|
||||
bind:showRuler
|
||||
{documentLanguage}
|
||||
onLanguage={(code) => (documentLanguage = code)}
|
||||
{zoom}
|
||||
onZoom={setZoom}
|
||||
onDebugDump={import.meta.env.DEV ? handleDebugDump : undefined}
|
||||
bind:pageMargins
|
||||
bind:pageOrientation
|
||||
bind:pageFormat
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
import HomeTab from './tabs/HomeTab.svelte';
|
||||
import InsertTab from './tabs/InsertTab.svelte';
|
||||
import LayoutTab from './tabs/LayoutTab.svelte';
|
||||
import ReferencesTab from './tabs/ReferencesTab.svelte';
|
||||
import ReviewTab from './tabs/ReviewTab.svelte';
|
||||
import ViewTab from './tabs/ViewTab.svelte';
|
||||
import UiLanguagePicker from '../UiLanguagePicker.svelte';
|
||||
import { clickOutside, isMenuOpen, toggleMenu, closeMenu } from './menu.svelte';
|
||||
import { t } from '../../i18n/i18n.svelte';
|
||||
@@ -17,6 +20,7 @@
|
||||
import type { Orientation } from '../../storage/pageOrientation';
|
||||
import type { PageFormat } from '../../storage/pageFormat';
|
||||
import type { HfZone } from '../../storage/headerFooter';
|
||||
import type { DocumentLanguage } from '../../storage/documentLanguage';
|
||||
|
||||
let {
|
||||
editor,
|
||||
@@ -24,6 +28,12 @@
|
||||
chromeMode = $bindable<ChromeMode>('ribbon'),
|
||||
documentName = $bindable(''),
|
||||
showFormattingMarks = $bindable(false),
|
||||
showRuler = $bindable(true),
|
||||
documentLanguage,
|
||||
onLanguage,
|
||||
zoom = 100,
|
||||
onZoom,
|
||||
onDebugDump,
|
||||
pageMargins = $bindable(DEFAULT_MARGINS),
|
||||
pageOrientation = $bindable<Orientation>('portrait'),
|
||||
pageFormat = $bindable<PageFormat>('A4'),
|
||||
@@ -44,6 +54,12 @@
|
||||
chromeMode?: ChromeMode;
|
||||
documentName?: string;
|
||||
showFormattingMarks?: boolean;
|
||||
showRuler?: boolean;
|
||||
documentLanguage: DocumentLanguage;
|
||||
onLanguage: (code: DocumentLanguage) => void;
|
||||
zoom?: number;
|
||||
onZoom?: (value: number) => void;
|
||||
onDebugDump?: () => void;
|
||||
pageMargins?: PageMargins;
|
||||
pageOrientation?: Orientation;
|
||||
pageFormat?: PageFormat;
|
||||
@@ -207,6 +223,12 @@
|
||||
<InsertTab {editor} {tick} {hfActive} {pageMargins} {pageOrientation} {pageFormat} {onEditZone} {onManageTableStyles} />
|
||||
{:else if tab === 'layout'}
|
||||
<LayoutTab {editor} {tick} {hfActive} bind:pageMargins bind:pageOrientation bind:pageFormat />
|
||||
{:else if tab === 'references'}
|
||||
<ReferencesTab {editor} {tick} {hfActive} />
|
||||
{:else if tab === 'review'}
|
||||
<ReviewTab {editor} {tick} {documentLanguage} {onLanguage} />
|
||||
{:else if tab === 'view'}
|
||||
<ViewTab bind:showRuler bind:showFormattingMarks {zoom} {onZoom} {onDebugDump} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -55,6 +55,13 @@ export const STROKED = {
|
||||
highlighter: ['M5.5 9.5 10 5l3 3-4.5 4.5H5.5z', 'M9.25 3.25 12.75 6.75', 'M2.5 13.5h4'],
|
||||
shading: ['M4 8.5 8.5 4l4 4-4.5 4.5a1.4 1.4 0 0 1-2 0L4 10.5a1.4 1.4 0 0 1 0-2z', 'M6.5 2 8.5 4', 'M2.5 13.5h11'],
|
||||
|
||||
toc: ['M2 3h6M2 6.5h5M2 10h6M2 13.5h4', 'M11 3h3M10 6.5h4M11 10h3M10 13.5h4'],
|
||||
tocLevels: ['M2.5 3.5h11M4.5 7h9M6.5 10.5h7M8.5 14h5'],
|
||||
wordCount: ['M2.5 2.5h11v11h-11z', 'M5 6h6M5 9h4'],
|
||||
ruler: ['M1.5 5.5h13v5h-13z', 'M4 5.5v2.2M6.5 5.5v3M9 5.5v2.2M11.5 5.5v3'],
|
||||
zoomIn: ['M7.25 12.5a5.25 5.25 0 1 0 0-10.5 5.25 5.25 0 0 0 0 10.5z', 'M11.2 11.2 14 14', 'M5.25 7.25h4M7.25 5.25v4'],
|
||||
zoomOut: ['M7.25 12.5a5.25 5.25 0 1 0 0-10.5 5.25 5.25 0 0 0 0 10.5z', 'M11.2 11.2 14 14', 'M5.25 7.25h4'],
|
||||
zoomReset: ['M7.25 12.5a5.25 5.25 0 1 0 0-10.5 5.25 5.25 0 0 0 0 10.5z', 'M11.2 11.2 14 14'],
|
||||
find: ['M7.25 12.5a5.25 5.25 0 1 0 0-10.5 5.25 5.25 0 0 0 0 10.5z', 'M11.2 11.2 14 14'],
|
||||
replace: ['M2 4.5h6.5M2 4.5 4 2.5M2 4.5l2 2', 'M14 11.5H7.5M14 11.5l-2-2M14 11.5l-2 2'],
|
||||
margins: ['M1.75 1.75h12.5v12.5H1.75z', 'M4.5 1.75v12.5M11.5 1.75v12.5', 'M1.75 4.5h12.5M1.75 11.5h12.5'],
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<script lang="ts">
|
||||
import type { Editor } from '@tiptap/core';
|
||||
import RibbonGroup from '../RibbonGroup.svelte';
|
||||
import RibbonButton from '../RibbonButton.svelte';
|
||||
import { anchored, clickOutside, isMenuOpen, toggleMenu, closeMenu } from '../menu.svelte';
|
||||
import type { HfZone } from '../../../storage/headerFooter';
|
||||
import { t } from '../../../i18n/i18n.svelte';
|
||||
|
||||
let { editor, tick, hfActive = null }: {
|
||||
editor: Editor | null;
|
||||
tick: number;
|
||||
hfActive?: HfZone | null;
|
||||
} = $props();
|
||||
|
||||
// The document holds at most one, so the first hit is it.
|
||||
let toc = $derived.by<{ pos: number; maxLevel: number } | null>(() => {
|
||||
if (tick < 0 || !editor) return null;
|
||||
let found: { pos: number; maxLevel: number } | null = null;
|
||||
editor.state.doc.descendants((node, pos) => {
|
||||
if (found || node.type.name !== 'tableOfContents') return;
|
||||
found = { pos, maxLevel: (node.attrs.maxLevel ?? 5) as number };
|
||||
});
|
||||
return found;
|
||||
});
|
||||
const LEVELS = [1, 2, 3, 4, 5];
|
||||
|
||||
function setMaxLevel(level: number) {
|
||||
closeMenu();
|
||||
if (!editor || !toc) return;
|
||||
editor.chain().focus().setNodeSelection(toc.pos).updateAttributes('tableOfContents', { maxLevel: level }).run();
|
||||
}
|
||||
</script>
|
||||
|
||||
<RibbonGroup label={t().ribbon.groups.toc}>
|
||||
<RibbonButton
|
||||
variant="big"
|
||||
icon="toc"
|
||||
label={t().ribbon.toc}
|
||||
title={hfActive ? t().toolbarExpanded.tocNotInHf : t().toolbarExpanded.insertToc}
|
||||
disabled={!editor || !!hfActive}
|
||||
onclick={() => editor?.chain().focus().setTableOfContents().run()}
|
||||
/>
|
||||
<div class="rb-menu-wrap" use:clickOutside={'tocLevels'}>
|
||||
<RibbonButton
|
||||
variant="big"
|
||||
icon="tocLevels"
|
||||
label={t().ribbon.tocOptions}
|
||||
title={t().ribbon.tocOptions}
|
||||
disabled={!toc}
|
||||
caret
|
||||
caretActive={isMenuOpen('tocLevels')}
|
||||
onclick={() => toggleMenu('tocLevels')}
|
||||
onCaret={() => toggleMenu('tocLevels')}
|
||||
/>
|
||||
{#if isMenuOpen('tocLevels')}
|
||||
<div class="ribbon-menu" use:anchored role="menu">
|
||||
<div class="rb-menu-label">{t().ribbon.tocMaxLevel}</div>
|
||||
{#each LEVELS as l}
|
||||
<button class:selected={toc?.maxLevel === l} onclick={() => setMaxLevel(l)}>{l}</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</RibbonGroup>
|
||||
|
||||
<style>
|
||||
.rb-menu-wrap { position: relative; }
|
||||
</style>
|
||||
@@ -0,0 +1,105 @@
|
||||
<script lang="ts">
|
||||
import type { Editor } from '@tiptap/core';
|
||||
import RibbonGroup from '../RibbonGroup.svelte';
|
||||
import RibbonButton from '../RibbonButton.svelte';
|
||||
import LanguagePicker from '../../LanguagePicker.svelte';
|
||||
import { anchored, clickOutside, isMenuOpen, toggleMenu } from '../menu.svelte';
|
||||
import { countText, type TextStats } from '../../../utils/wordCount';
|
||||
import type { DocumentLanguage } from '../../../storage/documentLanguage';
|
||||
import { t } from '../../../i18n/i18n.svelte';
|
||||
|
||||
let { editor, tick, documentLanguage, onLanguage }: {
|
||||
editor: Editor | null;
|
||||
tick: number;
|
||||
documentLanguage: DocumentLanguage;
|
||||
onLanguage: (code: DocumentLanguage) => void;
|
||||
} = $props();
|
||||
|
||||
let stats = $derived.by<TextStats>(() => {
|
||||
if (tick < 0 || !editor) return { words: 0, charsWithSpaces: 0, charsNoSpaces: 0, paragraphs: 0 };
|
||||
const { doc } = editor.state;
|
||||
return countText(doc, 0, doc.content.size);
|
||||
});
|
||||
|
||||
let selStats = $derived.by<TextStats | null>(() => {
|
||||
if (tick < 0 || !editor) return null;
|
||||
const { from, to, empty } = editor.state.selection;
|
||||
return empty ? null : countText(editor.state.doc, from, to);
|
||||
});
|
||||
|
||||
const ROWS = (s: TextStats) => [
|
||||
{ label: t().status.wordsLabel, value: s.words },
|
||||
{ label: t().status.charsWithSpaces, value: s.charsWithSpaces },
|
||||
{ label: t().status.charsNoSpaces, value: s.charsNoSpaces },
|
||||
{ label: t().status.paragraphs, value: s.paragraphs },
|
||||
];
|
||||
</script>
|
||||
|
||||
<RibbonGroup label={t().ribbon.groups.proofing}>
|
||||
<div class="rb-menu-wrap" use:clickOutside={'wordCount'}>
|
||||
<RibbonButton
|
||||
variant="big"
|
||||
icon="wordCount"
|
||||
label={t().status.statistics}
|
||||
title={t().status.statistics}
|
||||
active={isMenuOpen('wordCount')}
|
||||
onclick={() => toggleMenu('wordCount')}
|
||||
/>
|
||||
{#if isMenuOpen('wordCount')}
|
||||
<div class="ribbon-menu stats-menu" use:anchored role="menu">
|
||||
{#if selStats}
|
||||
<div class="rb-menu-label">{t().status.selection}</div>
|
||||
{#each ROWS(selStats) as r}
|
||||
<div class="stat"><span>{r.label}</span><b>{t().status.num(r.value)}</b></div>
|
||||
{/each}
|
||||
{/if}
|
||||
<div class="rb-menu-label">{t().status.document}</div>
|
||||
{#each ROWS(stats) as r}
|
||||
<div class="stat"><span>{r.label}</span><b>{t().status.num(r.value)}</b></div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</RibbonGroup>
|
||||
|
||||
<div class="ribbon-sep"></div>
|
||||
|
||||
<RibbonGroup label={t().ribbon.groups.language}>
|
||||
<div class="rb-captioned">
|
||||
<LanguagePicker value={documentLanguage} onChange={onLanguage} />
|
||||
<span class="rb-caption">{t().spellPicker.label}</span>
|
||||
</div>
|
||||
</RibbonGroup>
|
||||
|
||||
<style>
|
||||
.rb-menu-wrap { position: relative; }
|
||||
.stats-menu { min-width: 240px; }
|
||||
|
||||
.stat {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 3px 12px;
|
||||
font-family: var(--w-font);
|
||||
font-size: 12px;
|
||||
color: var(--w-text-dim);
|
||||
}
|
||||
|
||||
.stat b { color: var(--w-text); }
|
||||
|
||||
.rb-captioned {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 4px 7px 6px;
|
||||
}
|
||||
|
||||
.rb-caption {
|
||||
font-family: var(--w-font);
|
||||
font-size: 12px;
|
||||
color: var(--w-text);
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script lang="ts">
|
||||
import RibbonGroup from '../RibbonGroup.svelte';
|
||||
import RibbonButton from '../RibbonButton.svelte';
|
||||
import { MIN_ZOOM, MAX_ZOOM } from '../../../utils/zoom';
|
||||
import { t } from '../../../i18n/i18n.svelte';
|
||||
import { shortcutHint } from '../../../editor/shortcuts';
|
||||
|
||||
let {
|
||||
showRuler = $bindable(true),
|
||||
showFormattingMarks = $bindable(false),
|
||||
zoom = 100,
|
||||
onZoom,
|
||||
onDebugDump,
|
||||
}: {
|
||||
showRuler?: boolean;
|
||||
showFormattingMarks?: boolean;
|
||||
zoom?: number;
|
||||
onZoom?: (value: number) => void;
|
||||
onDebugDump?: () => void;
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<RibbonGroup label={t().ribbon.groups.show}>
|
||||
<div class="rb-col">
|
||||
<RibbonButton variant="small" icon="ruler" label={t().ruler.show} active={showRuler} onclick={() => (showRuler = !showRuler)} />
|
||||
<RibbonButton variant="small" icon="pilcrow" label={t().toolbarExpanded.formattingMarks} title={`${t().toolbarExpanded.formattingMarks} (${shortcutHint('formattingMarks')})`} active={showFormattingMarks} onclick={() => (showFormattingMarks = !showFormattingMarks)} />
|
||||
</div>
|
||||
</RibbonGroup>
|
||||
|
||||
<div class="ribbon-sep"></div>
|
||||
|
||||
<RibbonGroup label={t().status.zoom}>
|
||||
<RibbonButton variant="big" icon="zoomOut" label={t().status.zoomOut} title={`${t().status.zoomOut} (${shortcutHint('zoomOut')})`} disabled={zoom <= MIN_ZOOM} onclick={() => onZoom?.(zoom - 10)} />
|
||||
<RibbonButton variant="big" icon="zoomReset" label={`${zoom}%`} title={`${t().status.resetZoom} (${shortcutHint('zoomReset')})`} onclick={() => onZoom?.(100)} />
|
||||
<RibbonButton variant="big" icon="zoomIn" label={t().status.zoomIn} title={`${t().status.zoomIn} (${shortcutHint('zoomIn')})`} disabled={zoom >= MAX_ZOOM} onclick={() => onZoom?.(zoom + 10)} />
|
||||
</RibbonGroup>
|
||||
|
||||
{#if onDebugDump}
|
||||
<div class="ribbon-sep"></div>
|
||||
<RibbonGroup label={t().ribbon.groups.debug}>
|
||||
<RibbonButton variant="big" icon="export" label={t().ribbon.debugDump} onclick={onDebugDump} />
|
||||
</RibbonGroup>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.rb-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -471,6 +471,11 @@ const de: Messages = {
|
||||
text: 'Text',
|
||||
symbols: 'Symbole',
|
||||
pageSetup: 'Seite einrichten',
|
||||
toc: 'Inhaltsverzeichnis',
|
||||
proofing: 'Rechtschreibung',
|
||||
language: 'Sprache',
|
||||
show: 'Anzeigen',
|
||||
debug: 'Debug',
|
||||
editing: 'Bearbeiten',
|
||||
},
|
||||
case: {
|
||||
@@ -515,6 +520,10 @@ const de: Messages = {
|
||||
narrow: 'Schmal',
|
||||
wide: 'Breit',
|
||||
},
|
||||
toc: 'Inhaltsverzeichnis',
|
||||
tocOptions: 'Ebenen',
|
||||
tocMaxLevel: 'Tiefste angezeigte Ebene',
|
||||
debugDump: 'Dump',
|
||||
chrome: {
|
||||
title: 'Symbolleisten-Stil',
|
||||
ribbon: 'Menüband',
|
||||
|
||||
@@ -475,6 +475,11 @@ const en = {
|
||||
text: 'Text',
|
||||
symbols: 'Symbols',
|
||||
pageSetup: 'Page Setup',
|
||||
toc: 'Table of Contents',
|
||||
proofing: 'Proofing',
|
||||
language: 'Language',
|
||||
show: 'Show',
|
||||
debug: 'Debug',
|
||||
editing: 'Editing',
|
||||
},
|
||||
case: {
|
||||
@@ -519,6 +524,10 @@ const en = {
|
||||
narrow: 'Narrow',
|
||||
wide: 'Wide',
|
||||
},
|
||||
toc: 'Table of contents',
|
||||
tocOptions: 'Levels',
|
||||
tocMaxLevel: 'Deepest level shown',
|
||||
debugDump: 'Dump',
|
||||
chrome: {
|
||||
title: 'Toolbar style',
|
||||
ribbon: 'Ribbon',
|
||||
|
||||
Reference in new issue
Block a user