From 1ed9f3d172220b1a18c1790072a495d288a2f1a4 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Tue, 4 Aug 2026 22:45:23 +0200 Subject: [PATCH] feat: table-styles --- src/App.svelte | 22 +- src/lib/components/Editor.svelte | 3 + src/lib/components/StyleManagerDialog.svelte | 317 ++++++++++++++++--- src/lib/components/TablePicker.svelte | 58 ++++ src/lib/components/TableStylePicker.svelte | 226 +++++++++++++ src/lib/components/TableToolbar.svelte | 3 + src/lib/components/Toolbar.svelte | 21 +- src/lib/components/ToolbarExpanded.svelte | 5 +- src/lib/editor/extensions.ts | 4 + src/lib/editor/extensions/paragraphStyle.ts | 2 +- src/lib/editor/extensions/tableStyle.ts | 197 ++++++++++++ src/lib/editor/extensions/tableView.ts | 10 + src/lib/export/docx.ts | 84 +++-- src/lib/export/odt.ts | 89 ++++-- src/lib/i18n/locales/de.ts | 39 +++ src/lib/i18n/locales/en.ts | 39 +++ src/lib/import/docx.ts | 9 +- src/lib/import/docxStyles.ts | 10 +- src/lib/import/odt.ts | 9 +- src/lib/import/styleResolver.ts | 8 +- src/lib/styles/sheet.svelte.ts | 30 +- src/lib/styles/styleSheet.ts | 40 ++- src/lib/styles/tableStyles.ts | 240 ++++++++++++++ tests/docx-roundtrip.test.ts | 32 ++ tests/roundtrip.test.ts | 46 +++ tests/unit/table-style.test.ts | 201 ++++++++++++ 26 files changed, 1634 insertions(+), 110 deletions(-) create mode 100644 src/lib/components/TableStylePicker.svelte create mode 100644 src/lib/editor/extensions/tableStyle.ts create mode 100644 src/lib/styles/tableStyles.ts create mode 100644 tests/unit/table-style.test.ts diff --git a/src/App.svelte b/src/App.svelte index f4d6143..6430c16 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -25,7 +25,7 @@ import { loadOrientation, saveOrientation, type Orientation } from './lib/storage/pageOrientation'; import { loadPageFormat, savePageFormat, type PageFormat } from './lib/storage/pageFormat'; import { setStyleSheet, styleSheet } from './lib/styles/sheet.svelte'; - import { builtinStyleSheet } from './lib/styles/styleSheet'; + import { builtinStyleSheet, type StyleFamily } from './lib/styles/styleSheet'; import { loadHfDoc, saveHfDoc, loadHfDistances, saveHfDistances, loadDifferentFirstPage, saveDifferentFirstPage, loadDifferentOddEven, saveDifferentOddEven, hfIsEmpty, DEFAULT_HF_DISTANCES, type HfDoc, type HfZone, type HfDistances } from './lib/storage/headerFooter'; import { loadDocName, saveDocName, stripOdtExtension, sanitizeNameForFile } from './lib/storage/documentName'; import { loadDocumentLanguage, saveDocumentLanguage, odfFromLanguage, type DocumentLanguage } from './lib/storage/documentLanguage'; @@ -33,6 +33,7 @@ import LanguagePicker from './lib/components/LanguagePicker.svelte'; import UiLanguagePicker from './lib/components/UiLanguagePicker.svelte'; import AboutDialog from './lib/components/AboutDialog.svelte'; + import StyleManagerDialog from './lib/components/StyleManagerDialog.svelte'; import { t } from './lib/i18n/i18n.svelte'; import { withShortcut } from './lib/i18n/shortcut'; import { DEFAULT_SHORTCUTS, matchesEvent, shortcutHint } from './lib/editor/shortcuts'; @@ -47,6 +48,13 @@ let currentPage: number = $state(1); let numPages: number = $state(1); let aboutOpen = $state(false); + let styleManagerOpen = $state(false); + let styleManagerFamily = $state('paragraph'); + + function openStyleManager(family: StyleFamily) { + styleManagerFamily = family; + styleManagerOpen = true; + } // Header/footer content + live-edit state. While a zone is being edited, the // top toolbars target hfEditor instead of the body editor (activeEditor below). @@ -470,8 +478,10 @@ // Adopt the document's spell-check language (the $effect switches the // controller + loads its dictionary). null = file declared none; keep ours. if (result.language) documentLanguage = result.language; - // Adopt the document's named paragraph styles (built-ins + the file's own). - setStyleSheet(result.styles); + // Adopt the document's named paragraph styles (built-ins + the file's own). Table + // styles are not stored in the file (ODF has no banding), so the registry survives — + // an imported table finds its style again by name. + setStyleSheet({ ...result.styles, table: styleSheet().table }); // Adopt header/footer + first-page variants (null clears the zone); end any edit. hfActive = null; headerDoc = result.header; @@ -772,7 +782,7 @@ - +
{#snippet saveIcon()} @@ -976,6 +986,7 @@ hfActive={hfActive} onEditZone={(zone) => (hfActive = zone)} onDebugDump={handleDebugDump} + onManageTableStyles={() => openStyleManager('table')} />
{@render toolbarScrollbar()} @@ -1073,6 +1084,9 @@ + + diff --git a/src/lib/components/TableStylePicker.svelte b/src/lib/components/TableStylePicker.svelte new file mode 100644 index 0000000..80fc759 --- /dev/null +++ b/src/lib/components/TableStylePicker.svelte @@ -0,0 +1,226 @@ + + +
+ + + {#if open} +
+
{t().table.tableStyle}
+
+ + + {#each styles as style (style.name)} + + {/each} +
+
+ {/if} +
+ + diff --git a/src/lib/components/TableToolbar.svelte b/src/lib/components/TableToolbar.svelte index e5411de..5a7e88f 100644 --- a/src/lib/components/TableToolbar.svelte +++ b/src/lib/components/TableToolbar.svelte @@ -4,6 +4,7 @@ import { isHeaderStyled } from '../editor/extensions/tableHeaderRow'; import ColorPicker from './ColorPicker.svelte'; import TableBorderPicker from './TableBorderPicker.svelte'; + import TableStylePicker from './TableStylePicker.svelte'; import { t } from '../i18n/i18n.svelte'; let { @@ -218,6 +219,8 @@ + +