superdoc 2.7.0-next.1 → 2.7.0-next.10

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.
Files changed (41) hide show
  1. package/dist/chunks/{create-super-doc-ui-DCjm-_Xo.es.js → create-super-doc-ui-BTNVc3UD.es.js} +7 -3
  2. package/dist/chunks/{create-super-doc-ui-CwCvqMOa.cjs → create-super-doc-ui-C44xPZxz.cjs} +7 -3
  3. package/dist/collaboration-upgrade-engine.cjs +1 -1
  4. package/dist/collaboration-upgrade-engine.es.js +1 -1
  5. package/dist/document-api/src/content-projection/validation.d.ts +3 -0
  6. package/dist/document-api/src/contract/command-catalog.d.ts +1 -1
  7. package/dist/document-api/src/contract/operation-definitions.d.ts +22 -0
  8. package/dist/document-api/src/contract/operation-registry.d.ts +11 -0
  9. package/dist/document-api/src/get-html/get-html.d.ts +6 -6
  10. package/dist/document-api/src/get-markdown/get-markdown.d.ts +2 -4
  11. package/dist/document-api/src/index.d.ts +11 -0
  12. package/dist/document-api/src/project-html/project-html.d.ts +5 -0
  13. package/dist/document-api/src/project-markdown/project-markdown.d.ts +5 -0
  14. package/dist/document-api/src/ranges/ranges.types.d.ts +5 -2
  15. package/dist/document-api/src/replace/replace.d.ts +15 -3
  16. package/dist/document-api/src/types/address.d.ts +2 -0
  17. package/dist/document-api/src/types/content-projection.d.ts +126 -0
  18. package/dist/document-api/src/types/index.d.ts +1 -0
  19. package/dist/document-api/src/types/mutation-plan.types.d.ts +3 -0
  20. package/dist/document-api/src/types/sd-contract.d.ts +4 -2
  21. package/dist/document-api/src/types/structural-input.d.ts +18 -3
  22. package/dist/layout-engine/painters/dom/src/index.d.ts +2 -0
  23. package/dist/layout-engine/painters/dom/src/web-flow/index.d.ts +3 -0
  24. package/dist/layout-engine/painters/dom/src/web-flow/painter.d.ts +2 -0
  25. package/dist/layout-engine/painters/dom/src/web-flow/render.d.ts +8 -0
  26. package/dist/layout-engine/painters/dom/src/web-flow/styles.d.ts +10 -0
  27. package/dist/layout-engine/painters/dom/src/web-flow/types.d.ts +77 -0
  28. package/dist/public/ui-react.cjs +1 -1
  29. package/dist/public/ui-react.es.js +1 -1
  30. package/dist/public/ui.cjs +1 -1
  31. package/dist/public/ui.es.js +1 -1
  32. package/dist/superdoc/src/composables/use-link-popover.d.ts +3 -14
  33. package/dist/superdoc/src/core/types/index.d.ts +12 -5
  34. package/dist/superdoc/src/helpers/v2-review-mutation-impact.d.ts +2 -3
  35. package/dist/superdoc.cjs +36 -128
  36. package/dist/superdoc.es.js +36 -128
  37. package/dist/word-layout/src/index.d.ts +2 -0
  38. package/dist/word-layout/src/list-marker.d.ts +8 -0
  39. package/dist/word-layout/src/review-aware-numbering.d.ts +41 -0
  40. package/dist-cdn/superdoc.min.js +37 -37
  41. package/package.json +2 -2
@@ -3,7 +3,7 @@ import { t as blank_default } from "./chunks/blank-docx-DzQccOlW.es.js";
3
3
  import { t as import_eventemitter3 } from "./chunks/eventemitter3-CMOjDs74.es.js";
4
4
  import { t as v4 } from "./chunks/uuid-H0Xcmmhy.es.js";
5
5
  import { a as init_dist$1, i as global, n as init_dist$2, o as Buffer, r as process$1, s as init_dist, t as require_jszip_min } from "./chunks/jszip-VxCFV9YS.es.js";
6
- import { a as DOM_CLASS_NAMES, i as getV2TrackedChangeMutationImpact, t as createSuperDocUI } from "./chunks/create-super-doc-ui-DCjm-_Xo.es.js";
6
+ import { a as DOM_CLASS_NAMES, i as getV2TrackedChangeMutationImpact, t as createSuperDocUI } from "./chunks/create-super-doc-ui-BTNVc3UD.es.js";
7
7
  import { t as _plugin_vue_export_helper_default } from "./chunks/_plugin-vue_export-helper-BOaGB7Aw.es.js";
8
8
  import { t as PDF_TO_CSS_UNITS } from "./chunks/constants-B6VBlmKp.es.js";
9
9
  import * as Vue from "vue";
@@ -18163,10 +18163,9 @@ function scrollToElement(targetElement, options = {
18163
18163
  */
18164
18164
  /**
18165
18165
  * Result of `doc.bookmarks.get()` as read here (Document API `BookmarkInfo`).
18166
- * `range.from.blockId` is the bookmark's `w14:paraId`, used to find/reveal
18167
- * the target paragraph. `address.story` is populated for non-body
18168
- * bookmarks (omitted for body) — used to scope this fix to body targets,
18169
- * since `revealBodyTarget`/`pageIndexForBodyTarget` are body-only.
18166
+ * `range.from.blockId` identifies the model paragraph sent to the viewport.
18167
+ * `address.story` is populated for non-body bookmarks (omitted for body),
18168
+ * which keeps anchor navigation scoped to body targets.
18170
18169
  * @typedef {Object} BookmarkGetResult
18171
18170
  * @property {{ story?: { kind?: string, storyType?: string } }} [address]
18172
18171
  * @property {{ from?: { blockId?: string } }} [range]
@@ -18185,15 +18184,6 @@ function scrollToElement(targetElement, options = {
18185
18184
  * @property {{ get?: (input: { target: { kind: 'entity', entityType: 'bookmark', name: string } }) => BookmarkGetResult | Promise<BookmarkGetResult | null | undefined> | null | undefined } | null} [bookmarks]
18186
18185
  */
18187
18186
  /**
18188
- * Result of `activeEditor.pageMetrics.revealBodyTarget()` as read here
18189
- * (`V2EditorHostRevealBodyTargetResult`). Only available in editing/
18190
- * suggesting mode — the host rejects with `editing-not-mounted` in
18191
- * viewing mode.
18192
- * @typedef {Object} RevealBodyTargetResult
18193
- * @property {'revealed' | 'rejected'} [status]
18194
- * @property {string} [reason]
18195
- */
18196
- /**
18197
18187
  * The `v2-link-click` payload the shell relays from the v2 host's
18198
18188
  * `onLinkClick` callback.
18199
18189
  * @typedef {Object} LinkClickPayload
@@ -18535,20 +18525,8 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getResolver
18535
18525
  handle.result?.then?.((outcome) => clearCurrentPopover(handle, outcome), () => clearCurrentPopover(handle));
18536
18526
  }
18537
18527
  /**
18538
- * Look up a real `<a name>` anchor, or a bookmark-marker span, in the
18539
- * currently mounted DOM. The marker span
18540
- * (`data-bookmark-marker`/`data-bookmark-name`) is a best-effort fast
18541
- * path only: layout-engine measuring drops those zero-width marker runs
18542
- * from paint whenever the wrapping paragraph has other visible content
18543
- * (the standard shape for a TOC bookmark wrapping heading text,
18544
- * `<w:bookmarkStart .../><w:r>Heading</w:r><w:bookmarkEnd/>`) — but it
18545
- * DOES survive for a standalone/empty bookmark paragraph (a supported v2
18546
- * shape, see `v2-layout-adapter/src/empty-paragraph.test.ts` and
18547
- * `isSyntheticStandaloneBookmarkParagraph` in
18548
- * `v2-host/src/compose-exact-complete-render.ts`), where it lets a
18549
- * mounted bookmark scroll immediately without a Document API round trip.
18550
- * `findPaintedParagraphByParaId` remains the reliable fallback for the
18551
- * common (marker-not-painted) case.
18528
+ * Find a mounted named anchor for runtimes that do not expose the bookmark
18529
+ * model. Model-backed runtimes never use DOM identity for navigation.
18552
18530
  * @param {HTMLElement | null} container
18553
18531
  * @param {string} escapedAnchorName
18554
18532
  * @returns {HTMLElement | null}
@@ -18557,44 +18535,6 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getResolver
18557
18535
  return container?.querySelector?.(`a[name='${escapedAnchorName}'], [data-bookmark-marker='start'][data-bookmark-name='${escapedAnchorName}']`) ?? null;
18558
18536
  }
18559
18537
  /**
18560
- * Find the painted paragraph element for a `w14:paraId`, mirroring the
18561
- * attribute chain `paintedParaIdElement` uses in v2-host
18562
- * (`create-v2-editor-host.ts`) to confirm a paragraph is painted.
18563
- * @param {HTMLElement | null} container
18564
- * @param {string} paraId
18565
- * @returns {HTMLElement | null}
18566
- */
18567
- function findPaintedParagraphByParaId(container, paraId) {
18568
- if (!container) return null;
18569
- const escaped = cssEscape(paraId);
18570
- return container.querySelector(`[data-source-node-id='${escaped}']`) ?? container.querySelector(`[data-layout-paraid='${escaped}']`) ?? container.querySelector(`[data-block-id$='/${escaped}']`) ?? container.querySelector(`[data-layout-block-ref$='/${escaped}']`) ?? null;
18571
- }
18572
- /**
18573
- * Poll for an element across a bounded number of animation frames. Used
18574
- * after `scrollToPage()` in review/viewing mode, where — unlike
18575
- * `revealBodyTarget` in editing mode — there is no promise that resolves
18576
- * once the deep-jumped page's geometry reconciles and paints.
18577
- * @param {() => HTMLElement | null} lookup
18578
- * @param {number} maxTicks
18579
- * @returns {Promise<HTMLElement | null>}
18580
- */
18581
- function pollForElement(lookup, maxTicks = 30) {
18582
- return new Promise((resolve) => {
18583
- const raf = typeof window !== "undefined" ? window.requestAnimationFrame : null;
18584
- let ticks = 0;
18585
- const tick = () => {
18586
- const found = lookup();
18587
- if (found || ticks >= maxTicks || typeof raf !== "function") {
18588
- resolve(found ?? null);
18589
- return;
18590
- }
18591
- ticks += 1;
18592
- raf(tick);
18593
- };
18594
- tick();
18595
- });
18596
- }
18597
- /**
18598
18538
  * Move the editable caret to the start of a resolved target paragraph after
18599
18539
  * navigating to it. Mirrors V1's `goToAnchor`, whose final step places the
18600
18540
  * caret at the bookmark position: without it a V2 TOC click only scrolls, so
@@ -18634,87 +18574,59 @@ function useLinkPopover({ getSurfaceManager, getActiveEditor, getUi, getResolver
18634
18574
  } catch {}
18635
18575
  }
18636
18576
  /**
18637
- * Navigate to an internal `#anchor` link (TOC entries, bookmark links).
18638
- * Tries a real `<a name>` anchor in the currently mounted DOM first, then
18639
- * resolves the bookmark's target paragraph through the Document API and
18640
- * scrolls to that paragraph by its `paraId` — not to a bookmark-marker
18641
- * element, which layout-engine measuring may have excluded from paint.
18642
- *
18643
- * In editing/suggesting mode (`placeCaret`), also moves the caret to the
18644
- * start of the resolved target paragraph, matching V1's `goToAnchor`.
18645
- *
18646
- * If the paragraph isn't mounted (the v2 layout engine only mounts a
18647
- * sliding window of pages), asks the host to reveal it:
18648
- * - In editing/suggesting mode, `pageMetrics.revealBodyTarget` deep-jumps
18649
- * into unmounted pages and resolves once the target is painted. Any
18650
- * rejection here OTHER than `editing-not-mounted` is a real failure of
18651
- * this strong, paint-confirmed path and is left as a no-op rather than
18652
- * silently degrading to the weaker path below.
18653
- * - In viewing mode the host is mounted in "review" mode, where
18654
- * `revealBodyTarget` always rejects with reason `editing-not-mounted`
18655
- * (or is simply unpublished); only then falls back to
18656
- * `pageIndexForBodyTarget` + `scrollToPage` (neither gated on mount
18657
- * mode) and polls for paint, since neither returns a paint-complete
18658
- * promise.
18659
- *
18660
- * Out of scope: bookmarks outside the body story (headers/footers/
18661
- * footnotes) — `revealBodyTarget`/`pageIndexForBodyTarget` are body-only.
18577
+ * Navigate to a body bookmark through its model address. A mounted-anchor
18578
+ * fallback is reserved for runtimes without a callable bookmark model.
18662
18579
  * @param {string | null | undefined} anchorUrl
18663
18580
  * @param {{ placeCaret?: boolean }} [options]
18664
18581
  */
18665
18582
  async function navigateToAnchor(anchorUrl, { placeCaret = false } = {}) {
18666
18583
  if (typeof anchorUrl !== "string" || !anchorUrl.startsWith("#")) return;
18667
18584
  const anchorName = anchorUrl.slice(1);
18668
- const escapedAnchorName = cssEscape(anchorName);
18669
- const mountedAnchor = findMountedAnchor(getUi()?.viewport?.getHost?.() ?? null, escapedAnchorName);
18670
- if (mountedAnchor) {
18671
- scrollToElement(mountedAnchor);
18672
- return;
18673
- }
18674
18585
  /** @type {LinkPopoverDocumentApi | null | undefined} */
18675
18586
  const doc = getActiveEditor()?.doc;
18587
+ const bookmarkGet = doc?.bookmarks?.get;
18588
+ if (typeof bookmarkGet !== "function") {
18589
+ const mountedAnchor = findMountedAnchor(getUi()?.viewport?.getHost?.() ?? null, cssEscape(anchorName));
18590
+ if (mountedAnchor) scrollToElement(mountedAnchor, {
18591
+ block: "start",
18592
+ behavior: "instant"
18593
+ });
18594
+ return;
18595
+ }
18676
18596
  /** @type {BookmarkGetResult | null} */
18677
18597
  let bookmark = null;
18678
18598
  try {
18679
- bookmark = await Promise.resolve(doc?.bookmarks?.get?.({ target: {
18599
+ bookmark = await Promise.resolve(bookmarkGet.call(doc.bookmarks, { target: {
18680
18600
  kind: "entity",
18681
18601
  entityType: "bookmark",
18682
18602
  name: anchorName
18683
18603
  } }));
18684
18604
  bookmark ??= null;
18685
18605
  } catch {
18686
- bookmark = null;
18606
+ return;
18687
18607
  }
18688
18608
  const story = bookmark?.address?.story;
18689
18609
  if (story && story.storyType !== "body") return;
18690
18610
  const blockId = bookmark?.range?.from?.blockId;
18691
18611
  if (typeof blockId !== "string") return;
18692
18612
  if (placeCaret) await placeCaretAtHeadingStart(blockId);
18693
- const mountedParagraph = findPaintedParagraphByParaId(getUi()?.viewport?.getHost?.() ?? null, blockId);
18694
- if (mountedParagraph) {
18695
- scrollToElement(mountedParagraph);
18696
- return;
18697
- }
18698
- const pageMetrics = getActiveEditor()?.pageMetrics;
18699
- const revealBodyTarget = pageMetrics?.revealBodyTarget;
18700
- let revealResult;
18613
+ const viewport = getUi()?.viewport;
18614
+ const scrollIntoView = viewport?.scrollIntoView;
18615
+ if (typeof scrollIntoView !== "function") return;
18701
18616
  try {
18702
- revealResult = await revealBodyTarget?.({ paraId: blockId });
18703
- } catch {
18704
- revealResult = void 0;
18705
- }
18706
- if (revealResult?.status === "revealed") {
18707
- const revealedParagraph = findPaintedParagraphByParaId(getUi()?.viewport?.getHost?.() ?? null, blockId);
18708
- if (revealedParagraph) scrollToElement(revealedParagraph);
18709
- return;
18710
- }
18711
- if (revealBodyTarget && revealResult?.reason !== "editing-not-mounted") return;
18712
- const pageIndexForBodyTarget = pageMetrics?.pageIndexForBodyTarget;
18713
- const scrollToPage = pageMetrics?.scrollToPage;
18714
- const pageIndex = pageIndexForBodyTarget?.({ paraId: blockId });
18715
- if (typeof pageIndex !== "number" || !scrollToPage?.(pageIndex)) return;
18716
- const revealedByScroll = await pollForElement(() => findPaintedParagraphByParaId(getUi()?.viewport?.getHost?.() ?? null, blockId));
18717
- if (revealedByScroll) scrollToElement(revealedByScroll);
18617
+ await Promise.resolve(scrollIntoView.call(viewport, {
18618
+ target: {
18619
+ kind: "text",
18620
+ blockId,
18621
+ range: {
18622
+ start: 0,
18623
+ end: 0
18624
+ }
18625
+ },
18626
+ block: "start",
18627
+ behavior: "instant"
18628
+ }));
18629
+ } catch {}
18718
18630
  }
18719
18631
  /**
18720
18632
  * @param {LinkPopoverContext} ctx
@@ -43505,10 +43417,6 @@ var SuperDoc = class extends import_eventemitter3.default {
43505
43417
  this.config.layoutEngineOptions = this.config.layoutEngineOptions || {};
43506
43418
  const isWebLayout = this.config.viewOptions?.layout === "web";
43507
43419
  const isSemanticFlow = this.config.layoutEngineOptions?.flowMode === "semantic";
43508
- if (isWebLayout && this.config.useLayoutEngine && !isSemanticFlow) {
43509
- console.warn("[SuperDoc] Web layout uses PM fallback unless layoutEngineOptions.flowMode is set to 'semantic'. Automatically disabling layout engine.");
43510
- this.config.useLayoutEngine = false;
43511
- }
43512
43420
  if (!isWebLayout && isSemanticFlow) {
43513
43421
  console.warn("[SuperDoc] flowMode 'semantic' is only valid with web layout. Coercing to 'paginated'.");
43514
43422
  this.config.layoutEngineOptions.flowMode = "paginated";
@@ -43539,7 +43447,7 @@ var SuperDoc = class extends import_eventemitter3.default {
43539
43447
  this.config.colors = shuffleArray(this.config.colors);
43540
43448
  this.userColorMap = /* @__PURE__ */ new Map();
43541
43449
  this.colorIndex = 0;
43542
- this.version = "2.7.0-next.1";
43450
+ this.version = "2.7.0-next.10";
43543
43451
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
43544
43452
  this.superdocId = config.superdocId || v4();
43545
43453
  this.colors = this.config.colors ?? [];
@@ -7,6 +7,8 @@ export { createNumberingManager } from './numbering-manager.js';
7
7
  export type { NumberingManager, NumberingManagerSnapshot, NumberingCursor } from './numbering-manager.js';
8
8
  export { computeWordListMarker } from './list-marker.js';
9
9
  export type { ComputeWordListMarkerInput, ComputeWordListMarkerResult, WordListMarkerDefinition, } from './list-marker.js';
10
+ export { createReviewAwareWordNumberingSequence, reviewAwareWordNumberingCounterScope, } from './review-aware-numbering.js';
11
+ export type { ReviewAwareNumberingMembership, ReviewAwareNumberingStateMode, ReviewAwareWordMarkerFact, ReviewAwareWordNumberingDefinition, ReviewAwareWordNumberingResult, ReviewAwareWordNumberingSequence, ReviewAwareWordNumberingSnapshot, } from './review-aware-numbering.js';
10
12
  /**
11
13
  * Computes the complete layout properties for a Word paragraph, including indentation,
12
14
  * tabs, and optional list marker positioning.
@@ -19,6 +19,14 @@ export interface WordListMarkerDefinition {
19
19
  numFmt?: string;
20
20
  /** Custom format string when `numFmt === 'custom'`. */
21
21
  customFormat?: string;
22
+ /** True when the level carries Word's legal-numbering semantics. */
23
+ isLegal?: boolean;
24
+ /** Effective numbering formats for placeholders that reference each level. */
25
+ levelNumberingFormats?: Array<{
26
+ ilvl: number;
27
+ numFmt?: string;
28
+ customFormat?: string;
29
+ }>;
22
30
  /** `w:suff`. Defaults to `tab` when absent. */
23
31
  suffix?: string;
24
32
  /** `w:lvlJc`. Defaults to `left`. */
@@ -0,0 +1,41 @@
1
+ import { ComputeWordListMarkerResult, WordListMarkerDefinition } from './list-marker.js';
2
+ import { NumberingCursor, NumberingManager, NumberingManagerSnapshot } from './numbering-manager.js';
3
+ export type ReviewAwareNumberingMembership = 'ordinary' | 'inserted' | 'deleted' | 'malformed';
4
+ export type ReviewAwareNumberingStateMode = 'snapshot' | 'cursor';
5
+ export interface ReviewAwareWordNumberingDefinition extends WordListMarkerDefinition {
6
+ restartNumberingAfterBreak?: boolean;
7
+ }
8
+ export type ReviewAwareWordMarkerFact = {
9
+ status: 'resolved';
10
+ result: ComputeWordListMarkerResult;
11
+ } | {
12
+ status: 'unresolved';
13
+ reason: 'missingLvlText' | 'malformedMembership';
14
+ };
15
+ export interface ReviewAwareWordNumberingResult {
16
+ final: ReviewAwareWordMarkerFact | null;
17
+ original: ReviewAwareWordMarkerFact | null;
18
+ redline: ReviewAwareWordMarkerFact;
19
+ }
20
+ export interface ReviewAwareWordNumberingSnapshot {
21
+ live?: NumberingManagerSnapshot | NumberingCursor;
22
+ original?: NumberingManagerSnapshot | NumberingCursor;
23
+ liveSectionEpoch: number;
24
+ originalSectionEpoch: number;
25
+ }
26
+ export interface ReviewAwareWordNumberingSequence {
27
+ advance(input: {
28
+ definition: ReviewAwareWordNumberingDefinition;
29
+ paragraphOrdinal: number;
30
+ membership: ReviewAwareNumberingMembership;
31
+ }): ReviewAwareWordNumberingResult;
32
+ advanceSectionBreak(membership: ReviewAwareNumberingMembership): void;
33
+ captureSnapshot(): ReviewAwareWordNumberingSnapshot;
34
+ restoreSnapshot(snapshot: ReviewAwareWordNumberingSnapshot | null): void;
35
+ counterScope(definition: ReviewAwareWordNumberingDefinition, plane: 'live' | 'original'): string;
36
+ retainedState(): readonly [NumberingManager, NumberingManager];
37
+ }
38
+ export declare function createReviewAwareWordNumberingSequence(options?: {
39
+ stateMode?: ReviewAwareNumberingStateMode;
40
+ }): ReviewAwareWordNumberingSequence;
41
+ export declare function reviewAwareWordNumberingCounterScope(definition: ReviewAwareWordNumberingDefinition, plane: 'live' | 'original', epochs: Pick<ReviewAwareWordNumberingSnapshot, 'liveSectionEpoch' | 'originalSectionEpoch'>): string;