oasis-editor 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { n as normalizeSelection, g as getParagraphs, c as createEditorParagraphFromRuns, a as getParagraphLength, b as createEditorRun, d as getDocumentSections, e as createEditorStyledRun, f as getParagraphText, h as getActiveZone, i as getActiveSectionIndex, p as positionToParagraphOffset, j as paragraphOffsetToPosition, k as clampPosition, l as findParagraphIndex, m as createCollapsedSelection, o as isSelectionCollapsed, q as createEditorParagraph, r as getBlockParagraphs, s as findParagraphTableLocation, t as buildTableCellLayout, u as createEditorTableCell, v as createEditorTable, w as createEditorTableRow, x as underlineStyleToCssDecorationStyle, y as resolveImageSrc, z as createEditorFootnote, A as createFootnoteReferenceRun, B as renumberFootnotes, C as iterateFootnoteReferenceRuns, D as getFootnoteDisplayMarker, E as createSignal, F as createEffect, G as onCleanup, H as buildCanvasLayoutSnapshot, I as on, J as onMount, K as debounce, L as unwrap, M as getDocumentParagraphs, N as getDocumentSectionsCanonical, O as createEditorDocument, P as getPageContentWidth, Q as getDocumentPageSettings, R as getTableCellContentWidthForParagraph, S as resolveResizedDimensions, T as resolveTextBoxRenderHeight, U as resolveEffectiveParagraphStyle, V as resolveEffectiveTextStyleForParagraph, W as iterateEndnoteReferenceRuns, X as JSZip, Y as imageContentTypeDefaults, Z as imageExtensionFromMime, _ as pxToPt$1, $ as buildSegmentTable, a0 as buildCanvasTableLayout, a1 as resolveFloatingObjectRect, a2 as getTextBoxFloatingGeometry, a3 as getPresetPathSegments, a4 as projectBlocksLayout, a5 as textStyleToFontSizePt, a6 as PX_PER_POINT, a7 as DEFAULT_FONT_SIZE_PX, a8 as isDoubleUnderlineStyle, a9 as isWavyUnderlineStyle, aa as underlineStyleLineWidthPx, ab as underlineStyleDashArray, ac as getListLabelInset, ad as getParagraphBorderInsets, ae as normalizeFamily, af as ROBOTO_FONT_FILES, ag as loadFontAsset, ah as OFFICE_COMPAT_FONT_FAMILIES, ai as buildSfnt, aj as defaultFontDecoderRegistry, ak as SfntFontProgram, al as collectPdfFontFamilies, am as projectDocumentLayout, an as getPageHeaderZoneTop, ao as getPageBodyTop, ap as getPageColumnRects, aq as findFootnoteReference, ar as FOOTNOTE_MARKER_GUTTER_PX, as as resolveImporterForFile, at as createEditorStateFromDocument, au as getDocumentParagraphsCanonical, av as getToolbarStyleState, aw as STANDARD_FONT_SIZES_PT, ax as fontSizePxToPt, ay as probeLocalFontFamilies, az as createInitialEditorState, aA as parseFontSizePtToPx, aB as formatFontSizePt, aC as listKindForTag, aD as isParagraphTag, aE as collectInlineRuns, aF as parseParagraphStyle, aG as t, aH as preciseFontModeVersion, aI as isPreciseFontModeEnabled, aJ as togglePreciseFontMode, aK as nextFontSizePt, aL as previousFontSizePt, aM as fontSizePtToPx, aN as createDefaultToolbarPreset, aO as defaultMenuItems, aP as MenuRegistry, aQ as createToolbarRegistry, aR as Editor, aS as resolveCommandRef, aT as commandRefName, aU as InlineShell, aV as BalloonShell, aW as DocumentShell, aX as createMemo, aY as getCaretRectFromSnapshot, aZ as getParagraphRectFromSnapshot, a_ as createComponent, a$ as CaretOverlay, b0 as Show, b1 as createRenderEffect, b2 as style, b3 as setAttribute, b4 as setStyleProperty, b5 as memo, b6 as template, b7 as insert, b8 as use, b9 as addEventListener, ba as Dialog, bb as delegateEvents, bc as className, bd as For, be as UNDERLINE_STYLE_OPTIONS, bf as Tabs, bg as measureParagraphMinContentWidthPx, bh as getEditableBlocksForZone, bi as findParagraphLocation, bj as createSectionBoundaryParagraph, bk as normalizePageSettings, bl as DEFAULT_EDITOR_PAGE_SETTINGS, bm as markStart, bn as markEnd, bo as getParagraphEntries, bp as getParagraphById, bq as PluginUiHost, br as OasisEditorEditor, bs as perfTimer, bt as OasisBrandMark, bu as setPreciseFontPreference, bv as setWelcomeSeen, bw as enablePreciseFontMode, bx as createOasisEditorClient, by as setLocale, bz as createEditorZoom, bA as startLongTaskObserver, bB as installGlobalReport, bC as applyStoredPreciseFontPreference, bD as getWelcomeSeen, bE as isLocalFontAccessSupported, bF as EDITOR_SCROLL_PADDING_PX, bG as Toolbar, bH as OasisEditorLoading, bI as createEditorLogger, bJ as getCachedCanvasImage, bK as registerDomStatsSurface } from "./index-BaKkmGAh.js";
4
+ import { n as normalizeSelection, g as getParagraphs, c as createEditorParagraphFromRuns, a as getParagraphLength, b as createEditorRun, d as getDocumentSections, e as createEditorStyledRun, f as getParagraphText, h as getActiveZone, i as getActiveSectionIndex, p as positionToParagraphOffset, j as paragraphOffsetToPosition, k as clampPosition, l as findParagraphIndex, m as createCollapsedSelection, o as isSelectionCollapsed, q as createEditorParagraph, r as getBlockParagraphs, s as findParagraphTableLocation, t as buildTableCellLayout, u as createEditorTableCell, v as createEditorTable, w as createEditorTableRow, x as underlineStyleToCssDecorationStyle, y as resolveImageSrc, z as createEditorFootnote, A as createFootnoteReferenceRun, B as renumberFootnotes, C as iterateFootnoteReferenceRuns, D as getFootnoteDisplayMarker, E as createSignal, F as createEffect, G as onCleanup, H as buildCanvasLayoutSnapshot, I as on, J as onMount, K as debounce, L as unwrap, M as getDocumentParagraphs, N as getDocumentSectionsCanonical, O as createEditorDocument, P as getPageContentWidth, Q as getDocumentPageSettings, R as getTableCellContentWidthForParagraph, S as resolveResizedDimensions, T as resolveTextBoxRenderHeight, U as resolveEffectiveParagraphStyle, V as resolveEffectiveTextStyleForParagraph, W as iterateEndnoteReferenceRuns, X as JSZip, Y as imageContentTypeDefaults, Z as imageExtensionFromMime, _ as pxToPt$1, $ as buildSegmentTable, a0 as buildCanvasTableLayout, a1 as resolveFloatingObjectRect, a2 as getTextBoxFloatingGeometry, a3 as getPresetPathSegments, a4 as projectBlocksLayout, a5 as textStyleToFontSizePt, a6 as PX_PER_POINT, a7 as DEFAULT_FONT_SIZE_PX, a8 as isDoubleUnderlineStyle, a9 as isWavyUnderlineStyle, aa as underlineStyleLineWidthPx, ab as underlineStyleDashArray, ac as getListLabelInset, ad as getParagraphBorderInsets, ae as normalizeFamily, af as ROBOTO_FONT_FILES, ag as loadFontAsset, ah as OFFICE_COMPAT_FONT_FAMILIES, ai as buildSfnt, aj as defaultFontDecoderRegistry, ak as SfntFontProgram, al as collectPdfFontFamilies, am as projectDocumentLayout, an as getPageHeaderZoneTop, ao as getPageBodyTop, ap as getPageColumnRects, aq as findFootnoteReference, ar as FOOTNOTE_MARKER_GUTTER_PX, as as resolveImporterForFile, at as createEditorStateFromDocument, au as getDocumentParagraphsCanonical, av as getToolbarStyleState, aw as STANDARD_FONT_SIZES_PT, ax as fontSizePxToPt, ay as probeLocalFontFamilies, az as createInitialEditorState, aA as parseFontSizePtToPx, aB as formatFontSizePt, aC as listKindForTag, aD as isParagraphTag, aE as collectInlineRuns, aF as parseParagraphStyle, aG as t, aH as getHeadingLevel, aI as preciseFontModeVersion, aJ as isPreciseFontModeEnabled, aK as togglePreciseFontMode, aL as nextFontSizePt, aM as previousFontSizePt, aN as fontSizePtToPx, aO as createDefaultToolbarPreset, aP as defaultMenuItems, aQ as MenuRegistry, aR as createToolbarRegistry, aS as Editor, aT as resolveCommandRef, aU as commandRefName, aV as InlineShell, aW as BalloonShell, aX as DocumentShell, aY as createMemo, aZ as getCaretRectFromSnapshot, a_ as getParagraphRectFromSnapshot, a$ as createComponent, b0 as CaretOverlay, b1 as Show, b2 as createRenderEffect, b3 as style, b4 as setAttribute, b5 as setStyleProperty, b6 as memo, b7 as template, b8 as insert, b9 as use, ba as addEventListener, bb as Dialog, bc as delegateEvents, bd as className, be as For, bf as UNDERLINE_STYLE_OPTIONS, bg as Tabs, bh as measureParagraphMinContentWidthPx, bi as getEditableBlocksForZone, bj as findParagraphLocation, bk as createSectionBoundaryParagraph, bl as normalizePageSettings, bm as DEFAULT_EDITOR_PAGE_SETTINGS, bn as markStart, bo as markEnd, bp as getParagraphEntries, bq as getParagraphById, br as PluginUiHost, bs as OasisEditorEditor, bt as perfTimer, bu as OasisBrandMark, bv as setPreciseFontPreference, bw as setWelcomeSeen, bx as enablePreciseFontMode, by as createOasisEditorClient, bz as setLocale, bA as createEditorZoom, bB as startLongTaskObserver, bC as installGlobalReport, bD as applyStoredPreciseFontPreference, bE as getWelcomeSeen, bF as isLocalFontAccessSupported, bG as EDITOR_SCROLL_PADDING_PX, bH as Toolbar, bI as OasisEditorLoading, bJ as createEditorLogger, bK as getCachedCanvasImage, bL as registerDomStatsSurface } from "./index-CMOt03WH.js";
5
5
  function getSelectedObjectRun(state, predicate) {
6
6
  const normalized = normalizeSelection(state);
7
7
  if (normalized.isCollapsed || normalized.startIndex !== normalized.endIndex || normalized.endParagraphOffset - normalized.startParagraphOffset !== 1) {
@@ -7753,8 +7753,8 @@ const WORD_NS$1 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
7753
7753
  const PACKAGE_REL_NS = "http://schemas.openxmlformats.org/package/2006/relationships";
7754
7754
  const OFFICE_REL_NS = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
7755
7755
  const WORD14_NS = "http://schemas.microsoft.com/office/word/2010/wordml";
7756
- const TWIPS_PER_INCH = 1440;
7757
- const PX_PER_INCH = 96;
7756
+ const TWIPS_PER_INCH$1 = 1440;
7757
+ const PX_PER_INCH$1 = 96;
7758
7758
  const TWIPS_PER_POINT = 20;
7759
7759
  function escapeXml(text) {
7760
7760
  return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
@@ -7763,19 +7763,19 @@ function pxToTwips(value, fallback) {
7763
7763
  if (!Number.isFinite(value)) {
7764
7764
  return fallback;
7765
7765
  }
7766
- return Math.max(0, Math.round(value / PX_PER_INCH * TWIPS_PER_INCH));
7766
+ return Math.max(0, Math.round(value / PX_PER_INCH$1 * TWIPS_PER_INCH$1));
7767
7767
  }
7768
7768
  function toTwips(value) {
7769
7769
  if (value === void 0 || value === null || !Number.isFinite(value)) {
7770
7770
  return null;
7771
7771
  }
7772
- return Math.round(value / PX_PER_INCH * TWIPS_PER_INCH);
7772
+ return Math.round(value / PX_PER_INCH$1 * TWIPS_PER_INCH$1);
7773
7773
  }
7774
7774
  function toHalfPoints(value) {
7775
7775
  if (value === void 0 || value === null || !Number.isFinite(value)) {
7776
7776
  return null;
7777
7777
  }
7778
- return Math.round(value / PX_PER_INCH * 72 * 2);
7778
+ return Math.round(value / PX_PER_INCH$1 * 72 * 2);
7779
7779
  }
7780
7780
  function pointsToTwips(value) {
7781
7781
  if (value === void 0 || value === null || !Number.isFinite(value)) {
@@ -40911,6 +40911,171 @@ function createEditorContextMenuClipboard(deps) {
40911
40911
  programmaticPaste
40912
40912
  };
40913
40913
  }
40914
+ const DEFAULT_TOC_MAX_LEVEL = 3;
40915
+ const TOC_INSTRUCTION = ' TOC \\o "1-3" \\h \\z \\u ';
40916
+ const PX_TO_PT = 72 / 96;
40917
+ const TWIPS_PER_INCH = 1440;
40918
+ const PX_PER_INCH = 96;
40919
+ const twipsToPx = (twips) => Math.round(twips / TWIPS_PER_INCH * PX_PER_INCH);
40920
+ function collectTocHeadings(state, maxLevel = DEFAULT_TOC_MAX_LEVEL) {
40921
+ var _a;
40922
+ const headings = [];
40923
+ for (const paragraph of getDocumentParagraphs(state.document)) {
40924
+ const level = getHeadingLevel((_a = paragraph.style) == null ? void 0 : _a.styleId);
40925
+ if (level === null || level > maxLevel) continue;
40926
+ const text = getParagraphText(paragraph).trim();
40927
+ if (!text) continue;
40928
+ headings.push({ id: paragraph.id, level, text });
40929
+ }
40930
+ return headings;
40931
+ }
40932
+ function makeRun(partial) {
40933
+ const run = createEditorRun(partial.text ?? "");
40934
+ return { ...run, ...partial, id: run.id };
40935
+ }
40936
+ function makeParagraph(runs, style2) {
40937
+ const paragraph = createEditorParagraph("");
40938
+ paragraph.runs = runs;
40939
+ if (style2) paragraph.style = style2;
40940
+ return paragraph;
40941
+ }
40942
+ function buildEntryParagraph(heading, pageNumber, rightTabPositionPt) {
40943
+ const pageLabel = pageNumber !== void 0 ? String(pageNumber) : "";
40944
+ const run = makeRun({ text: `${heading.text} ${pageLabel}` });
40945
+ const style2 = {
40946
+ tabs: [{ position: rightTabPositionPt, type: "right", leader: "dot" }],
40947
+ spacingAfter: twipsToPx(40),
40948
+ indentLeft: twipsToPx((heading.level - 1) * 397)
40949
+ };
40950
+ return makeParagraph([run], style2);
40951
+ }
40952
+ function rightTabPositionForSection(section) {
40953
+ const { width, margins } = section.pageSettings;
40954
+ const contentWidthPx = Math.max(0, width - margins.left - margins.right);
40955
+ return Math.round(contentWidthPx * PX_TO_PT * 100) / 100;
40956
+ }
40957
+ function buildStartMarkerParagraph() {
40958
+ return makeParagraph([
40959
+ makeRun({ text: "", fieldChar: { kind: "begin" } }),
40960
+ makeRun({ text: "", fieldInstruction: TOC_INSTRUCTION }),
40961
+ makeRun({ text: "", fieldChar: { kind: "separate" } })
40962
+ ]);
40963
+ }
40964
+ function buildEndMarkerParagraph() {
40965
+ return makeParagraph([makeRun({ text: "", fieldChar: { kind: "end" } })]);
40966
+ }
40967
+ function buildTocBlocks(headings, resolvePage, rightTabPositionPt) {
40968
+ const entries = headings.map(
40969
+ (heading) => buildEntryParagraph(heading, resolvePage(heading.id), rightTabPositionPt)
40970
+ );
40971
+ return [buildStartMarkerParagraph(), ...entries, buildEndMarkerParagraph()];
40972
+ }
40973
+ function replaceSectionBlocks(state, sectionIndex, nextBlocks, selectionParagraph) {
40974
+ const sections = getDocumentSections(state.document);
40975
+ const section = sections[sectionIndex];
40976
+ if (!section) return state;
40977
+ const nextSections = [...sections];
40978
+ nextSections[sectionIndex] = { ...section, blocks: nextBlocks };
40979
+ return {
40980
+ ...state,
40981
+ document: { ...state.document, sections: nextSections },
40982
+ selection: withSelection(paragraphOffsetToPosition(selectionParagraph, 0))
40983
+ };
40984
+ }
40985
+ function insertTableOfContents(state, resolvePage = () => void 0, maxLevel = DEFAULT_TOC_MAX_LEVEL) {
40986
+ const zone = getActiveZone(state);
40987
+ if (zone !== "main") return state;
40988
+ const sectionIndex = getActiveSectionIndex(state);
40989
+ const sections = getDocumentSections(state.document);
40990
+ const section = sections[sectionIndex];
40991
+ if (!section) return state;
40992
+ const headings = collectTocHeadings(state, maxLevel);
40993
+ const tocBlocks = buildTocBlocks(
40994
+ headings,
40995
+ resolvePage,
40996
+ rightTabPositionForSection(section)
40997
+ );
40998
+ const focus = clampPosition(state, state.selection.focus);
40999
+ const blockIndex = section.blocks.findIndex((block) => {
41000
+ if (block.id === focus.paragraphId) return true;
41001
+ if (block.type === "paragraph") return false;
41002
+ return getBlockParagraphs(block).some((p) => p.id === focus.paragraphId);
41003
+ });
41004
+ const insertAt = blockIndex === -1 ? section.blocks.length : blockIndex + 1;
41005
+ const nextBlocks = [
41006
+ ...section.blocks.slice(0, insertAt),
41007
+ ...tocBlocks,
41008
+ ...section.blocks.slice(insertAt)
41009
+ ];
41010
+ return replaceSectionBlocks(state, sectionIndex, nextBlocks, tocBlocks[0]);
41011
+ }
41012
+ function findTocRegion(blocks) {
41013
+ var _a, _b, _c;
41014
+ let depth = 0;
41015
+ let instruction = "";
41016
+ let separateBlockIndex = -1;
41017
+ let beginBlockIndex = -1;
41018
+ let isToc = false;
41019
+ for (let i = 0; i < blocks.length; i += 1) {
41020
+ const block = blocks[i];
41021
+ if (block.type !== "paragraph") continue;
41022
+ for (const run of block.runs) {
41023
+ if (((_a = run.fieldChar) == null ? void 0 : _a.kind) === "begin") {
41024
+ depth += 1;
41025
+ if (depth === 1) {
41026
+ beginBlockIndex = i;
41027
+ instruction = "";
41028
+ isToc = false;
41029
+ separateBlockIndex = -1;
41030
+ }
41031
+ } else if (depth === 1 && run.fieldInstruction !== void 0) {
41032
+ instruction += run.fieldInstruction;
41033
+ if (/\bTOC\b/i.test(instruction)) isToc = true;
41034
+ } else if (((_b = run.fieldChar) == null ? void 0 : _b.kind) === "separate") {
41035
+ if (depth === 1) separateBlockIndex = i;
41036
+ } else if (((_c = run.fieldChar) == null ? void 0 : _c.kind) === "end") {
41037
+ if (depth === 1) {
41038
+ if (isToc) {
41039
+ return {
41040
+ startBlockIndex: separateBlockIndex >= 0 ? separateBlockIndex : beginBlockIndex,
41041
+ endBlockIndex: i
41042
+ };
41043
+ }
41044
+ }
41045
+ depth = Math.max(0, depth - 1);
41046
+ }
41047
+ }
41048
+ }
41049
+ return null;
41050
+ }
41051
+ function updateTableOfContents(state, resolvePage = () => void 0, maxLevel = DEFAULT_TOC_MAX_LEVEL) {
41052
+ const sectionIndex = getActiveSectionIndex(state);
41053
+ const sections = getDocumentSections(state.document);
41054
+ const section = sections[sectionIndex];
41055
+ if (!section) return state;
41056
+ const region = findTocRegion(section.blocks);
41057
+ if (!region) return state;
41058
+ const headings = collectTocHeadings(state, maxLevel);
41059
+ const entries = headings.map(
41060
+ (heading) => buildEntryParagraph(
41061
+ heading,
41062
+ resolvePage(heading.id),
41063
+ rightTabPositionForSection(section)
41064
+ )
41065
+ );
41066
+ const nextBlocks = [
41067
+ ...section.blocks.slice(0, region.startBlockIndex + 1),
41068
+ ...entries,
41069
+ ...section.blocks.slice(region.endBlockIndex)
41070
+ ];
41071
+ const selectionParagraph = entries[0] ?? section.blocks[region.startBlockIndex];
41072
+ return replaceSectionBlocks(
41073
+ state,
41074
+ sectionIndex,
41075
+ nextBlocks,
41076
+ selectionParagraph
41077
+ );
41078
+ }
40914
41079
  function createCommandBuilder(isCommandEnabled) {
40915
41080
  return (name, execute, state) => ({
40916
41081
  execute,
@@ -41452,6 +41617,19 @@ function createEditorEssentialsRuntimePlugin(options) {
41452
41617
  undo: () => (options.historyActions.performUndo(), true),
41453
41618
  redo: () => (options.historyActions.performRedo(), true)
41454
41619
  };
41620
+ const buildTocPageResolver = (state) => {
41621
+ const layout = projectDocumentLayout(state.document);
41622
+ const pageByParagraph = /* @__PURE__ */ new Map();
41623
+ for (const page of layout.pages) {
41624
+ for (const block of page.blocks) {
41625
+ const paragraphId = block.paragraphId;
41626
+ if (paragraphId && !pageByParagraph.has(paragraphId)) {
41627
+ pageByParagraph.set(paragraphId, page.index + 1);
41628
+ }
41629
+ }
41630
+ }
41631
+ return (headingId) => pageByParagraph.get(headingId);
41632
+ };
41455
41633
  const essentialsFormatting = {
41456
41634
  selectAll: () => {
41457
41635
  const paragraphs = getDocumentParagraphs(options.state().document);
@@ -41472,6 +41650,20 @@ function createEditorEssentialsRuntimePlugin(options) {
41472
41650
  return true;
41473
41651
  },
41474
41652
  insertFootnote: () => (options.commandsController.applyInsertFootnoteCommand(), true),
41653
+ insertTableOfContents: () => {
41654
+ options.applyTransactionalState(
41655
+ (current) => insertTableOfContents(current, buildTocPageResolver(current))
41656
+ );
41657
+ options.focusInput();
41658
+ return true;
41659
+ },
41660
+ updateTableOfContents: () => {
41661
+ options.applyTransactionalState(
41662
+ (current) => updateTableOfContents(current, buildTocPageResolver(current))
41663
+ );
41664
+ options.focusInput();
41665
+ return true;
41666
+ },
41475
41667
  pastePlainText: () => {
41476
41668
  options.forcePlainTextPaste.set(true);
41477
41669
  options.focusInput();
@@ -1,2 +1,2 @@
1
- export declare const OASIS_BUILTIN_COMMANDS: readonly ["selectAll", "insertFootnote", "pastePlainText", "bold", "italic", "underline", "strike", "superscript", "subscript", "link", "unlink", "alignLeft", "alignCenter", "alignRight", "alignJustify", "orderedList", "bulletList", "find", "replace", "toggleTrackChanges", "acceptRevisions", "rejectRevisions", "toggleShowMargins", "toggleShowParagraphMarks", "togglePreciseFonts", "undo", "redo", "pageBreak", "lineBreak", "splitBlock", "setFontFamily", "setFontSize", "increaseFontSize", "decreaseFontSize", "changeTextCase", "clearFormatting", "setColor", "setHighlight", "setTextShading", "setStyleId", "setUnderlineStyle", "documentStyles", "print", "copy", "exportDocx", "exportPdf", "importDocument", "insertImage", "editImageAlt", "insertImageCaption", "outdent", "indent", "togglePageBreakBefore", "toggleKeepWithNext", "setSpacingAfter", "setSpacingBefore", "setIndentLeft", "setIndentRight", "setIndentFirstLine", "setIndentHanging", "setSpecialIndent", "setParagraphShading", "applyParagraphBorders", "setLineHeight", "setListFormat", "setListStartAt", "toggleOrientation", "setOrientation", "sectionBreakNextPage", "sectionBreakContinuous", "setPageMargins", "tableContext", "tableMerge", "tableSplit", "tableInsertColumnBefore", "tableInsertColumnAfter", "tableDeleteColumn", "tableInsertRowBefore", "tableInsertRowAfter", "tableDeleteRow", "tableCellShading", "tableCellBorders", "tableCellNoBorders", "tableWidth100", "tableAlignLeft", "tableAlignCenter", "tableAlignRight", "tableSetCellWidth", "insertTable"];
1
+ export declare const OASIS_BUILTIN_COMMANDS: readonly ["selectAll", "insertFootnote", "insertTableOfContents", "updateTableOfContents", "pastePlainText", "bold", "italic", "underline", "strike", "superscript", "subscript", "link", "unlink", "alignLeft", "alignCenter", "alignRight", "alignJustify", "orderedList", "bulletList", "find", "replace", "toggleTrackChanges", "acceptRevisions", "rejectRevisions", "toggleShowMargins", "toggleShowParagraphMarks", "togglePreciseFonts", "undo", "redo", "pageBreak", "lineBreak", "splitBlock", "setFontFamily", "setFontSize", "increaseFontSize", "decreaseFontSize", "changeTextCase", "clearFormatting", "setColor", "setHighlight", "setTextShading", "setStyleId", "setUnderlineStyle", "documentStyles", "print", "copy", "exportDocx", "exportPdf", "importDocument", "insertImage", "editImageAlt", "insertImageCaption", "outdent", "indent", "togglePageBreakBefore", "toggleKeepWithNext", "setSpacingAfter", "setSpacingBefore", "setIndentLeft", "setIndentRight", "setIndentFirstLine", "setIndentHanging", "setSpecialIndent", "setParagraphShading", "applyParagraphBorders", "setLineHeight", "setListFormat", "setListStartAt", "toggleOrientation", "setOrientation", "sectionBreakNextPage", "sectionBreakContinuous", "setPageMargins", "tableContext", "tableMerge", "tableSplit", "tableInsertColumnBefore", "tableInsertColumnAfter", "tableDeleteColumn", "tableInsertRowBefore", "tableInsertRowAfter", "tableDeleteRow", "tableCellShading", "tableCellBorders", "tableCellNoBorders", "tableWidth100", "tableAlignLeft", "tableAlignCenter", "tableAlignRight", "tableSetCellWidth", "insertTable"];
2
2
  export type OasisBuiltinCommand = (typeof OASIS_BUILTIN_COMMANDS)[number];
@@ -0,0 +1,32 @@
1
+ import { EditorState } from '../model.js';
2
+
3
+ /** Default TOC scope: outline levels 1–3, matching Word's `TOC \o "1-3"`. */
4
+ export declare const DEFAULT_TOC_MAX_LEVEL = 3;
5
+ /** A heading captured for a TOC entry. */
6
+ export interface TocHeading {
7
+ id: string;
8
+ level: number;
9
+ text: string;
10
+ }
11
+ /** Page number resolver: heading paragraph id → printed page number. */
12
+ export type TocPageNumberResolver = (headingId: string) => number | undefined;
13
+ /**
14
+ * Collect heading paragraphs (levels 1..maxLevel) in document order. Headings
15
+ * are detected case-insensitively via {@link getHeadingLevel}, so both the
16
+ * editor's own `heading1` and Word's imported `Heading1` styles qualify.
17
+ */
18
+ export declare function collectTocHeadings(state: EditorState, maxLevel?: number): TocHeading[];
19
+ /**
20
+ * Insert a generated table of contents after the block holding the caret.
21
+ * Operates on section blocks (not the flattened paragraph list) so it is safe
22
+ * in documents containing tables.
23
+ */
24
+ export declare function insertTableOfContents(state: EditorState, resolvePage?: TocPageNumberResolver, maxLevel?: number): EditorState;
25
+ /**
26
+ * Regenerate the entries of an existing TOC field from the current headings,
27
+ * preserving the field's begin/instruction/separate and end markers. Returns
28
+ * the unchanged state when no TOC field is present.
29
+ */
30
+ export declare function updateTableOfContents(state: EditorState, resolvePage?: TocPageNumberResolver, maxLevel?: number): EditorState;
31
+ /** Whether a TOC field exists in the active section (for menu enablement). */
32
+ export declare function hasTableOfContents(state: EditorState): boolean;
@@ -6,4 +6,12 @@ export interface OutlineItem {
6
6
  text: string;
7
7
  anchor: string;
8
8
  }
9
+ /**
10
+ * Resolve the heading level (1-9) of a paragraph style id, or null if the style
11
+ * is not a heading. Case-insensitive and tolerant of an optional space, so it
12
+ * matches both the editor's own convention (`heading1`) and Word's imported
13
+ * style ids (`Heading1`, `Heading 1`). Keeping detection here means imported
14
+ * `styleId`s round-trip unchanged on export.
15
+ */
16
+ export declare function getHeadingLevel(styleId: string | undefined): number | null;
9
17
  export declare function outlineFrom(doc: EditorDocument): OutlineItem[];
@@ -412,6 +412,8 @@ export declare const en: {
412
412
  "menu.view.outline": string;
413
413
  "menu.view.fullscreen": string;
414
414
  "menu.insert": string;
415
+ "menu.insert.toc": string;
416
+ "menu.insert.updateToc": string;
415
417
  "menu.layout": string;
416
418
  "menu.format": string;
417
419
  "menu.format.align": string;
@@ -412,6 +412,8 @@ export declare const ptBR: {
412
412
  "menu.view.outline": string;
413
413
  "menu.view.fullscreen": string;
414
414
  "menu.insert": string;
415
+ "menu.insert.toc": string;
416
+ "menu.insert.updateToc": string;
415
417
  "menu.layout": string;
416
418
  "menu.format": string;
417
419
  "menu.format.align": string;