superdoc 2.0.0-next.45 → 2.0.0-next.46

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 (34) hide show
  1. package/AGENTS.md +15 -8
  2. package/dist/chunks/{create-super-doc-ui-DDxbK_M7.cjs → create-super-doc-ui-6FUZ9d-y.cjs} +201 -122
  3. package/dist/chunks/{create-super-doc-ui-BTOlZen9.es.js → create-super-doc-ui-DCFTmVRK.es.js} +202 -123
  4. package/dist/collaboration-upgrade-engine.cjs +1 -1
  5. package/dist/collaboration-upgrade-engine.es.js +1 -1
  6. package/dist/document-api/src/contract/command-catalog.d.ts +1 -1
  7. package/dist/document-api/src/contract/operation-definitions.d.ts +1 -1
  8. package/dist/public/ui-react.cjs +17 -14
  9. package/dist/public/ui-react.es.js +17 -14
  10. package/dist/public/ui.cjs +1 -1
  11. package/dist/public/ui.es.js +1 -1
  12. package/dist/style.css +23 -23
  13. package/dist/style.layered.css +23 -23
  14. package/dist/superdoc/src/components/surfaces/FindReplaceSurface.vue.d.ts +2 -2
  15. package/dist/superdoc/src/components/surfaces/PasswordPromptSurface.vue.d.ts +2 -2
  16. package/dist/superdoc/src/components/surfaces/SurfaceExternalMount.vue.d.ts +2 -2
  17. package/dist/superdoc/src/composables/use-find-replace.d.ts +2 -2
  18. package/dist/superdoc/src/core/SuperDoc.d.ts +41 -0
  19. package/dist/superdoc/src/core/types/index.d.ts +2 -14
  20. package/dist/superdoc/src/internal/toolbar/built-in-toolbar.d.ts +5 -5
  21. package/dist/superdoc/src/public/browser-document-api.d.ts +53 -0
  22. package/dist/superdoc/src/public/index.d.cts +4 -0
  23. package/dist/superdoc/src/public/index.d.ts +2 -0
  24. package/dist/superdoc/src/public/ui/react.d.ts +18 -7
  25. package/dist/superdoc/src/public/ui/types.d.ts +81 -12
  26. package/dist/superdoc/src/public/ui-react.d.ts +4 -3
  27. package/dist/superdoc/src/public/ui.d.cts +8 -0
  28. package/dist/superdoc/src/public/ui.d.ts +1 -1
  29. package/dist/superdoc.cjs +53 -43
  30. package/dist/superdoc.es.js +53 -43
  31. package/dist-cdn/style.layered.css +1 -1
  32. package/dist-cdn/superdoc.min.css +1 -1
  33. package/dist-cdn/superdoc.min.js +35 -35
  34. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import { CommentsListQuery as DocumentApiCommentsListQuery, CommentsListResult, TrackChangesListResult, EntityAddress, TextAddress, TextTarget, ScrollIntoViewInput, ScrollIntoViewOutput, SelectionInfo, SelectionTarget, Receipt, ReceiptFailureCode, ContentControlInfo, StyleCatalogItem, StyleCatalogDiagnostic, StyleCatalogSourceStatus, StylesGetCatalogInput, StylesGetCatalogResult } from '../../../../document-api/src/index.js';
2
+ import { PartialBrowserDocumentApi } from '../browser-document-api.js';
2
3
  import { SuperDocUIReason } from './reasons.js';
3
4
  /**
4
5
  * v2-native `superdoc/ui` controller types.
@@ -26,9 +27,10 @@ import { SuperDocUIReason } from './reasons.js';
26
27
  * (`scripts/ensure-types.cjs` `rewriteDocApiPaths`), so no bare private
27
28
  * specifier leaks into the emitted `.d.ts`.
28
29
  */
29
- export type { Receipt, SelectionInfo, SelectionTarget, SelectionPoint, TextTarget, TextAddress, ScrollIntoViewInput, ScrollIntoViewOutput, EntityAddress, CommentsListQuery as DocumentApiCommentsListQuery, CommentsListResult, TrackChangesListResult, ContentControlsListResult, ContentControlInfo, } from '../../../../document-api/src/index.js';
30
+ export type { Receipt, SelectionInfo, SelectionTarget, SelectionPoint, TextTarget, TextAddress, ScrollIntoViewInput, ScrollIntoViewOutput, DocumentApi, EntityAddress, CommentsListQuery as DocumentApiCommentsListQuery, CommentsListResult, TrackChangesListResult, ContentControlsListResult, ContentControlInfo, } from '../../../../document-api/src/index.js';
30
31
  export type { StyleCatalogView, StyleCatalogItemType, StyleCatalogFilterType, StyleProvenance, StyleCatalogItemVisibility, StyleCatalogItemUsage, StyleCatalogItemPreview, StyleCatalogItem, StyleCatalogDefaults, StyleCatalogDiagnostic, StyleCatalogSourceStatus, StylesGetCatalogInput, StylesGetCatalogResult, } from '../../../../document-api/src/index.js';
31
32
  export type { ListPresetId } from '../../../../document-api/src/index.js';
33
+ export type { BrowserDocumentApi, PartialBrowserDocumentApi } from '../browser-document-api.js';
32
34
  export type { SuperDocUIReason } from './reasons.js';
33
35
  /** Equality predicate used to suppress redundant slice notifications. */
34
36
  export type EqualityFn<T> = (a: T, b: T) => boolean;
@@ -414,14 +416,44 @@ export interface CustomCommandContext<TPayload = unknown> {
414
416
  editor: SuperDocEditorLike | null;
415
417
  superdoc: SuperDocLike;
416
418
  context?: ViewportContext;
417
- /** The live UI controller (shared command-state truth). */
418
- ui: SuperDocUI;
419
+ /**
420
+ * The live UI controller (shared command-state truth).
421
+ *
422
+ * Borrowed: a custom command runs against whichever controller invoked it,
423
+ * which for `superdoc.ui.commands.register(...)` is the instance-owned
424
+ * singleton the built-in toolbar also reads. Typing this as the owned form
425
+ * would let a command callback destroy it, which is the hole the borrowed
426
+ * handle exists to close.
427
+ *
428
+ * Borrowed unconditionally, including for a controller you built with
429
+ * `createSuperDocUI()`. That costs an owner nothing: you necessarily hold the
430
+ * owned reference already, since you called `.commands.register(...)` on it,
431
+ * so tear it down through that instead of through the context. Varying this
432
+ * by ownership would mean `SuperDocUI` and {@link BorrowedSuperDocUI} needing
433
+ * different `commands` handles, and the borrowed form is derived from the
434
+ * owned one precisely so the two cannot drift.
435
+ */
436
+ ui: BorrowedSuperDocUI;
419
437
  /** Run a catalog command id through the shared controller. */
420
438
  execute(id: string, payload?: unknown): CommandExecutionResult;
421
439
  /** Run a catalog command id and await its settled result. */
422
440
  executeAsync(id: string, payload?: unknown): Promise<CommandExecutionResult>;
423
- /** Public browser Document API facade (read-only-guarded, async-capable), or `null` when unavailable. */
424
- doc: Record<string, any> | null;
441
+ /**
442
+ * The host's browser Document API facade (read-only-guarded, async-capable),
443
+ * or `null` when unavailable.
444
+ *
445
+ * Partial for the same reason {@link SuperDocEditorLike.doc} is: this is the
446
+ * host's own object handed straight through, and a duck-typed host is only
447
+ * required to carry the operations it implements. Typing it as the complete
448
+ * facade would promise operations a custom adapter or stub never defines.
449
+ *
450
+ * Prefer {@link CustomCommandContext.execute}, `executeAsync`, and
451
+ * `insertText` where they cover the work: those route through the controller
452
+ * and fail closed with a reason or a receipt when an operation is missing.
453
+ * Reach for `doc` when you need an operation the controller does not route,
454
+ * and guard the call.
455
+ */
456
+ doc: PartialBrowserDocumentApi | null;
425
457
  /** Read-only selection snapshot at invocation time. */
426
458
  selection: SelectionSlice;
427
459
  /** Current document mode. */
@@ -1228,14 +1260,23 @@ export interface SearchHandle extends SnapshotSubscribable<SearchSlice> {
1228
1260
  export interface SuperDocEditorLike {
1229
1261
  /** Runtime evidence of the bundled v2 editor. */
1230
1262
  editorVersion?: number;
1231
- /** Public, read-only-guarded browser Document API facade (async-capable in browser). */
1232
- doc?: Record<string, any> | null;
1263
+ /**
1264
+ * Public, read-only-guarded browser Document API facade (async-capable in
1265
+ * browser). Partial by design: this is what a host supplies, and a stub or
1266
+ * custom adapter carries only the operations it implements.
1267
+ *
1268
+ * `CustomCommandContext.doc` is the same partial type, because the controller
1269
+ * passes this object straight through and can promise no more than the host
1270
+ * does. {@link BrowserDocumentApi}, the complete facade, is the type of
1271
+ * `activeEditor.doc` on a real `Editor`.
1272
+ */
1273
+ doc?: PartialBrowserDocumentApi | null;
1233
1274
  /** Stable reason the Document API is unavailable. */
1234
1275
  documentApiUnavailableReason?: string | null;
1235
1276
  /** Editor-scoped event subscription. */
1236
- on?(event: string, handler: (...args: any[]) => void): unknown;
1277
+ on?(event: string, handler: (...args: unknown[]) => void): unknown;
1237
1278
  /** Editor-scoped event unsubscription. */
1238
- off?(event: string, handler: (...args: any[]) => void): unknown;
1279
+ off?(event: string, handler: (...args: unknown[]) => void): unknown;
1239
1280
  /** Export the active editor's document. */
1240
1281
  exportDocx?(...args: unknown[]): Promise<unknown>;
1241
1282
  /** Save the active editor's document. */
@@ -1251,10 +1292,19 @@ export interface SuperDocEditorLike {
1251
1292
  export interface SuperDocLike {
1252
1293
  /** The routed active editor, when one is mounted. */
1253
1294
  activeEditor?: SuperDocEditorLike | null;
1295
+ /**
1296
+ * The host-owned UI controller. A real `SuperDoc` instance always exposes
1297
+ * one and owns its lifecycle; bare structural stubs may not, which is why
1298
+ * this is optional. Consumers should read it rather than build their own.
1299
+ *
1300
+ * Borrowed, not owned: the host tears this down, so the type omits
1301
+ * `destroy()` and a reader cannot call it.
1302
+ */
1303
+ ui?: BorrowedSuperDocUI;
1254
1304
  /** Lifecycle event subscription. */
1255
- on?(event: string, handler: (...args: any[]) => void): unknown;
1305
+ on?(event: string, handler: (...args: unknown[]) => void): unknown;
1256
1306
  /** Lifecycle event unsubscription. */
1257
- off?(event: string, handler: (...args: any[]) => void): unknown;
1307
+ off?(event: string, handler: (...args: unknown[]) => void): unknown;
1258
1308
  /** Set the document mode across the instance. */
1259
1309
  setDocumentMode?(mode: string): unknown;
1260
1310
  /** Export the active document. */
@@ -1351,6 +1401,25 @@ export interface SuperDocUI {
1351
1401
  readonly formatPainter: FormatPainterHandle;
1352
1402
  /** Create a disposable subscription scope. */
1353
1403
  createScope(): SuperDocUIScope;
1354
- /** Tear down all subscriptions and detach from the host. */
1404
+ /**
1405
+ * Tear down all subscriptions and detach from the host.
1406
+ *
1407
+ * Only the owner calls this. A controller obtained from `createSuperDocUI()`
1408
+ * is owned by its caller. The one at `superdoc.ui` is owned by the instance
1409
+ * and is typed {@link BorrowedSuperDocUI}, which does not carry this method.
1410
+ */
1355
1411
  destroy(): void;
1356
1412
  }
1413
+ /**
1414
+ * The controller as a *consumer* sees it: everything except `destroy()`.
1415
+ *
1416
+ * This is what `superdoc.ui` and the React hooks return. The instance owns that
1417
+ * controller and tears it down in `superdoc.destroy()`, so a consumer calling
1418
+ * `destroy()` would freeze command state for the built-in toolbar and every
1419
+ * other reader of the same instance. Omitting the method makes that a compile
1420
+ * error rather than a documented convention nobody reads.
1421
+ *
1422
+ * Derived from {@link SuperDocUI} rather than declared separately so the two
1423
+ * cannot drift: every handle added there appears here automatically.
1424
+ */
1425
+ export type BorrowedSuperDocUI = Omit<SuperDocUI, 'destroy'>;
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * SuperDoc public facade: `superdoc/ui/react` entry.
3
3
  *
4
- * v2-native React bindings for the `createSuperDocUI` controller: the
5
- * provider, the lifecycle bind hook, the generic slice hook, and the domain
6
- * hooks.
4
+ * v2-native React bindings for the SuperDoc-owned UI controller
5
+ * (`superdoc.ui`): the provider, the bind hook, the generic slice hook, and
6
+ * the domain hooks. This layer consumes the controller; SuperDoc creates and
7
+ * destroys it.
7
8
  *
8
9
  * v2 NOTE: this is NOT the v1 re-export. It routes through the local,
9
10
  * self-contained v2 React layer under `./ui/react.ts`, which is built on the
@@ -1,5 +1,7 @@
1
1
  // Generated by scripts/ensure-types.cjs. Do not edit by hand.
2
2
  import type { ActiveParagraphStyle as __Cjs_ActiveParagraphStyle } from './ui.js' with { "resolution-mode": "import" };
3
+ import type { BorrowedSuperDocUI as __Cjs_BorrowedSuperDocUI } from './ui.js' with { "resolution-mode": "import" };
4
+ import type { BrowserDocumentApi as __Cjs_BrowserDocumentApi } from './ui.js' with { "resolution-mode": "import" };
3
5
  import type { CommandExecutionResult as __Cjs_CommandExecutionResult } from './ui.js' with { "resolution-mode": "import" };
4
6
  import type { CommandHandle as __Cjs_CommandHandle } from './ui.js' with { "resolution-mode": "import" };
5
7
  import type { CommandsHandle as __Cjs_CommandsHandle } from './ui.js' with { "resolution-mode": "import" };
@@ -22,6 +24,7 @@ import type { CustomCommandHandle as __Cjs_CustomCommandHandle } from './ui.js'
22
24
  import type { CustomCommandHandleState as __Cjs_CustomCommandHandleState } from './ui.js' with { "resolution-mode": "import" };
23
25
  import type { CustomCommandRegistration as __Cjs_CustomCommandRegistration } from './ui.js' with { "resolution-mode": "import" };
24
26
  import type { CustomCommandRegistrationResult as __Cjs_CustomCommandRegistrationResult } from './ui.js' with { "resolution-mode": "import" };
27
+ import type { DocumentApi as __Cjs_DocumentApi } from './ui.js' with { "resolution-mode": "import" };
25
28
  import type { DocumentHandle as __Cjs_DocumentHandle } from './ui.js' with { "resolution-mode": "import" };
26
29
  import type { DocumentSlice as __Cjs_DocumentSlice } from './ui.js' with { "resolution-mode": "import" };
27
30
  import type { EntityAddress as __Cjs_EntityAddress } from './ui.js' with { "resolution-mode": "import" };
@@ -31,6 +34,7 @@ import type { FontsHandle as __Cjs_FontsHandle } from './ui.js' with { "resoluti
31
34
  import type { FontSizeOption as __Cjs_FontSizeOption } from './ui.js' with { "resolution-mode": "import" };
32
35
  import type { FontsSlice as __Cjs_FontsSlice } from './ui.js' with { "resolution-mode": "import" };
33
36
  import type { MetadataHandle as __Cjs_MetadataHandle } from './ui.js' with { "resolution-mode": "import" };
37
+ import type { PartialBrowserDocumentApi as __Cjs_PartialBrowserDocumentApi } from './ui.js' with { "resolution-mode": "import" };
34
38
  import type { Receipt as __Cjs_Receipt } from './ui.js' with { "resolution-mode": "import" };
35
39
  import type { ScrollIntoViewInput as __Cjs_ScrollIntoViewInput } from './ui.js' with { "resolution-mode": "import" };
36
40
  import type { ScrollIntoViewOutput as __Cjs_ScrollIntoViewOutput } from './ui.js' with { "resolution-mode": "import" };
@@ -90,6 +94,8 @@ import type { WorkflowScrollResult as __Cjs_WorkflowScrollResult } from './ui.js
90
94
  import type { ZoomHandle as __Cjs_ZoomHandle } from './ui.js' with { "resolution-mode": "import" };
91
95
  import type { ZoomSlice as __Cjs_ZoomSlice } from './ui.js' with { "resolution-mode": "import" };
92
96
  export type { __Cjs_ActiveParagraphStyle as ActiveParagraphStyle };
97
+ export type { __Cjs_BorrowedSuperDocUI as BorrowedSuperDocUI };
98
+ export type { __Cjs_BrowserDocumentApi as BrowserDocumentApi };
93
99
  export declare const BUILT_IN_COMMAND_IDS: typeof import('./ui.js', { with: { "resolution-mode": "import" } }).BUILT_IN_COMMAND_IDS;
94
100
  export type { __Cjs_CommandExecutionResult as CommandExecutionResult };
95
101
  export type { __Cjs_CommandHandle as CommandHandle };
@@ -114,6 +120,7 @@ export type { __Cjs_CustomCommandHandle as CustomCommandHandle };
114
120
  export type { __Cjs_CustomCommandHandleState as CustomCommandHandleState };
115
121
  export type { __Cjs_CustomCommandRegistration as CustomCommandRegistration };
116
122
  export type { __Cjs_CustomCommandRegistrationResult as CustomCommandRegistrationResult };
123
+ export type { __Cjs_DocumentApi as DocumentApi };
117
124
  export type { __Cjs_DocumentHandle as DocumentHandle };
118
125
  export type { __Cjs_DocumentSlice as DocumentSlice };
119
126
  export type { __Cjs_EntityAddress as EntityAddress };
@@ -123,6 +130,7 @@ export type { __Cjs_FontsHandle as FontsHandle };
123
130
  export type { __Cjs_FontSizeOption as FontSizeOption };
124
131
  export type { __Cjs_FontsSlice as FontsSlice };
125
132
  export type { __Cjs_MetadataHandle as MetadataHandle };
133
+ export type { __Cjs_PartialBrowserDocumentApi as PartialBrowserDocumentApi };
126
134
  export type { __Cjs_Receipt as Receipt };
127
135
  export type { __Cjs_ScrollIntoViewInput as ScrollIntoViewInput };
128
136
  export type { __Cjs_ScrollIntoViewOutput as ScrollIntoViewOutput };
@@ -26,4 +26,4 @@
26
26
  export { createSuperDocUI } from './ui/create-super-doc-ui.js';
27
27
  export { shallowEqual } from './ui/equality.js';
28
28
  export { BUILT_IN_COMMAND_IDS } from './ui/commands.js';
29
- export type { EqualityFn, SelectorFn, Subscribable, SuperDocUI, SuperDocUIOptions, SuperDocUIState, SuperDocUIScope, SuperDocLike, SuperDocEditorLike, CommandHandle, CommandState, CommandExecutionResult, WorkflowReceipt, WorkflowActionResult, WorkflowScrollResult, SelectionRestoreResult, SuperDocUIReason, CommandsHandle, ContextMenuItem, CustomCommandHandle, CustomCommandHandleState, CustomCommandRegistration, CustomCommandRegistrationResult, MetadataHandle, SelectionHandle, ToolbarHandle, CommentsHandle, TrackChangesHandle, ContentControlsHandle, ContentControlFocusResult, FontsHandle, ZoomHandle, DocumentHandle, ViewportHandle, StylesHandle, ActiveParagraphStyle, SliceStatus, SelectionSlice, SelectionCapture, CommentAnchorCapture, ToolbarSnapshotSlice, CommentsSlice, TrackChangesSlice, ContentControlsSlice, FontsSlice, ZoomSlice, DocumentSlice, StylesSlice, StyleCatalogView, StyleCatalogItemType, StyleCatalogFilterType, StyleProvenance, StyleCatalogItemVisibility, StyleCatalogItemUsage, StyleCatalogItemPreview, StyleCatalogItem, StyleCatalogDefaults, StyleCatalogDiagnostic, StyleCatalogSourceStatus, StylesGetCatalogInput, StylesGetCatalogResult, CommentInfo, CommentsListQuery, TrackChangeInfo, TrackChangePointHit, TrackChangesItem, FontFamilyOption, FontSizeOption, CommentAddress, TrackedChangeAddress, ContentControlViewportAddress, ViewportEntityAddress, ViewportEntityHit, ViewportContext, ViewportRect, ViewportGetRectInput, ViewportRectResult, Receipt, SelectionInfo, SelectionTarget, SelectionPoint, TextTarget, TextAddress, ScrollIntoViewInput, ScrollIntoViewOutput, EntityAddress, CommentsListResult, TrackChangesListResult, ContentControlsListResult, ContentControlInfo, } from './ui/types.js';
29
+ export type { EqualityFn, SelectorFn, Subscribable, SuperDocUI, BorrowedSuperDocUI, SuperDocUIOptions, SuperDocUIState, SuperDocUIScope, SuperDocLike, SuperDocEditorLike, CommandHandle, CommandState, CommandExecutionResult, WorkflowReceipt, WorkflowActionResult, WorkflowScrollResult, SelectionRestoreResult, SuperDocUIReason, CommandsHandle, ContextMenuItem, CustomCommandHandle, CustomCommandHandleState, CustomCommandRegistration, CustomCommandRegistrationResult, MetadataHandle, SelectionHandle, ToolbarHandle, CommentsHandle, TrackChangesHandle, ContentControlsHandle, ContentControlFocusResult, FontsHandle, ZoomHandle, DocumentHandle, ViewportHandle, StylesHandle, ActiveParagraphStyle, SliceStatus, SelectionSlice, SelectionCapture, CommentAnchorCapture, ToolbarSnapshotSlice, CommentsSlice, TrackChangesSlice, ContentControlsSlice, FontsSlice, ZoomSlice, DocumentSlice, StylesSlice, StyleCatalogView, StyleCatalogItemType, StyleCatalogFilterType, StyleProvenance, StyleCatalogItemVisibility, StyleCatalogItemUsage, StyleCatalogItemPreview, StyleCatalogItem, StyleCatalogDefaults, StyleCatalogDiagnostic, StyleCatalogSourceStatus, StylesGetCatalogInput, StylesGetCatalogResult, CommentInfo, CommentsListQuery, TrackChangeInfo, TrackChangePointHit, TrackChangesItem, FontFamilyOption, FontSizeOption, CommentAddress, TrackedChangeAddress, ContentControlViewportAddress, ViewportEntityAddress, ViewportEntityHit, ViewportContext, ViewportRect, ViewportGetRectInput, ViewportRectResult, BrowserDocumentApi, PartialBrowserDocumentApi, DocumentApi, Receipt, SelectionInfo, SelectionTarget, SelectionPoint, TextTarget, TextAddress, ScrollIntoViewInput, ScrollIntoViewOutput, EntityAddress, CommentsListResult, TrackChangesListResult, ContentControlsListResult, ContentControlInfo, } from './ui/types.js';
package/dist/superdoc.cjs CHANGED
@@ -6,7 +6,7 @@ const require_uuid = require("./chunks/uuid-CFp0WGVU.cjs");
6
6
  const require_jszip = require("./chunks/jszip-BdUBlUeG.cjs");
7
7
  const require__plugin_vue_export_helper = require("./chunks/_plugin-vue_export-helper-BTwbGDKw.cjs");
8
8
  const require_constants = require("./chunks/constants-sbCZ2O_A.cjs");
9
- const require_create_super_doc_ui = require("./chunks/create-super-doc-ui-DDxbK_M7.cjs");
9
+ const require_create_super_doc_ui = require("./chunks/create-super-doc-ui-6FUZ9d-y.cjs");
10
10
  let vue = require("vue");
11
11
  vue = require_rolldown_runtime.__toESM(vue);
12
12
  require("y-websocket");
@@ -13807,6 +13807,7 @@ var _hoisted_1$16 = {
13807
13807
  var _hoisted_2$13 = ["innerHTML"];
13808
13808
  var _hoisted_3$10 = { class: "superdoc__document document" };
13809
13809
  var _hoisted_4$7 = { class: "floating-comments" };
13810
+ var UNAVAILABLE_COMMAND_RESULT = false;
13810
13811
  var V2_SELECTION_TOOLBAR_SYNC_RETRY_FRAMES = 3;
13811
13812
  var V2_TYPING_REVIEW_HYDRATION_IDLE_MS = 6500;
13812
13813
  var V2_TYPING_REVIEW_HYDRATION_CEILING_MS = 8e3;
@@ -13927,19 +13928,19 @@ var _sfc_main$20 = {
13927
13928
  const v2GeometryEpoch = (0, vue.ref)(null);
13928
13929
  let v2GeometryRafHandle = 0;
13929
13930
  const activeEditorRef = (0, vue.computed)(() => proxy.$superdoc.activeEditor);
13930
- let linkPopoverUi = null;
13931
+ const getSuperDocUI = () => proxy.$superdoc?.ui ?? null;
13932
+ const UNAVAILABLE_COMMAND_STATE = Object.freeze({
13933
+ enabled: false,
13934
+ active: false,
13935
+ supported: false
13936
+ });
13931
13937
  const findReplace = useFindReplace({
13932
13938
  getSurfaceManager: () => surfaceManager,
13933
13939
  getActiveEditor: () => proxy.$superdoc?.activeEditor,
13934
13940
  activeEditorRef,
13935
13941
  getFindReplaceConfig: () => proxy.$superdoc?.config?.modules?.surfaces?.findReplace,
13936
- getSuperDocUI: () => getLinkPopoverUi()
13942
+ getSuperDocUI
13937
13943
  });
13938
- const getLinkPopoverUi = () => {
13939
- if (proxy.$superdoc?.toolbar?.ui) return proxy.$superdoc.toolbar.ui;
13940
- if (!linkPopoverUi && proxy.$superdoc) linkPopoverUi = require_create_super_doc_ui.createSuperDocUI({ superdoc: proxy.$superdoc });
13941
- return linkPopoverUi;
13942
- };
13943
13944
  const getLinkPopoverSurfaceManager = () => {
13944
13945
  if (surfaceManager) return surfaceManager;
13945
13946
  if (typeof proxy.$superdoc?.openSurface !== "function") return null;
@@ -13948,7 +13949,7 @@ var _sfc_main$20 = {
13948
13949
  const linkPopover = useLinkPopover({
13949
13950
  getSurfaceManager: getLinkPopoverSurfaceManager,
13950
13951
  getActiveEditor: () => proxy.$superdoc?.activeEditor,
13951
- getUi: getLinkPopoverUi,
13952
+ getUi: getSuperDocUI,
13952
13953
  getResolver: () => proxy.$superdoc?.config?.modules?.links?.popoverResolver,
13953
13954
  getLayerElement: () => layers.value,
13954
13955
  emitException: (payload) => {
@@ -14019,11 +14020,6 @@ var _sfc_main$20 = {
14019
14020
  } catch (err) {
14020
14021
  console.warn("[SuperDoc] v2 command-shortcut unbind failed", err);
14021
14022
  }
14022
- try {
14023
- entry.ui?.destroy?.();
14024
- } catch (err) {
14025
- console.warn("[SuperDoc] v2 command-shortcut UI teardown failed", err);
14026
- }
14027
14023
  };
14028
14024
  const resolveV2LinkWorkflowOpener = () => {
14029
14025
  const toolbar = proxy.$superdoc?.toolbar;
@@ -14039,20 +14035,19 @@ var _sfc_main$20 = {
14039
14035
  if (!documentId) return;
14040
14036
  clearV2CommandShortcutBinding(documentId);
14041
14037
  if (typeof bindEditShortcuts !== "function") return;
14042
- const fallbackUi = require_create_super_doc_ui.createSuperDocUI({ superdoc: proxy.$superdoc });
14043
- const resolveUi = () => proxy.$superdoc?.toolbar?.ui ?? fallbackUi;
14044
14038
  const openLinkWorkflow = resolveV2LinkWorkflowOpener();
14045
14039
  const unbind = bindEditShortcuts({
14046
14040
  commandRoute: {
14047
- executeAsync: (commandId, payload) => resolveUi().commands.executeAsync(commandId, payload),
14048
- getState: (commandId) => resolveUi().commands.get(commandId).getState()
14041
+ executeAsync: (commandId, payload) => {
14042
+ const ui = getSuperDocUI();
14043
+ if (!ui) return Promise.resolve(UNAVAILABLE_COMMAND_RESULT);
14044
+ return ui.commands.executeAsync(commandId, payload);
14045
+ },
14046
+ getState: (commandId) => getSuperDocUI()?.commands.get(commandId).getState() ?? UNAVAILABLE_COMMAND_STATE
14049
14047
  },
14050
14048
  ...openLinkWorkflow ? { openLinkWorkflow } : {}
14051
14049
  });
14052
- v2CommandShortcutBindings.set(documentId, {
14053
- unbind,
14054
- ui: fallbackUi
14055
- });
14050
+ v2CommandShortcutBindings.set(documentId, { unbind });
14056
14051
  };
14057
14052
  const clearV2SessionShortcutBinding = (documentId) => {
14058
14053
  const entry = v2SessionShortcutBindings.get(documentId);
@@ -15604,8 +15599,6 @@ var _sfc_main$20 = {
15604
15599
  passwordPrompt.destroy();
15605
15600
  findReplace.destroy();
15606
15601
  linkPopover.destroy();
15607
- linkPopoverUi?.destroy?.();
15608
- linkPopoverUi = null;
15609
15602
  cancelScheduledV2DomSelectionSync();
15610
15603
  cancelScheduledV2SelectionToolbarSync();
15611
15604
  for (const documentId of Array.from(v2Runtimes.keys())) clearV2RuntimeRegistration(documentId);
@@ -16122,7 +16115,7 @@ var _sfc_main$20 = {
16122
16115
  };
16123
16116
  }
16124
16117
  };
16125
- var SuperDoc_default = /* @__PURE__ */ require__plugin_vue_export_helper.__plugin_vue_export_helper_default(_sfc_main$20, [["__scopeId", "data-v-91c4cd11"]]);
16118
+ var SuperDoc_default = /* @__PURE__ */ require__plugin_vue_export_helper.__plugin_vue_export_helper_default(_sfc_main$20, [["__scopeId", "data-v-41f40a40"]]);
16126
16119
  var PINIA_DEVTOOLS_SETUP_EVENT = "devtools-plugin:setup";
16127
16120
  var PINIA_DEVTOOLS_PLUGIN_ID = "dev.esm.pinia";
16128
16121
  var piniaDevtoolsSuppressionState = {
@@ -33930,24 +33923,31 @@ var BuiltInToolbar = class extends require_eventemitter3.import_eventemitter3.de
33930
33923
  const uiFontFamily = (this.config?.uiDisplayFallbackFont || "").toString().trim() || "Arial, Helvetica, sans-serif";
33931
33924
  this.toolbarContainer.style.setProperty("--sd-ui-font-family", uiFontFamily);
33932
33925
  }
33933
- this.#initController();
33934
- this.#initToolbarGroups();
33935
- this.#makeToolbarItems();
33936
- this.#bindHostEvents();
33937
- this._lastFontOptionsSignature = this.#fontOptionsSignature();
33938
- if (!this.toolbarContainer) {
33926
+ try {
33927
+ this.#initController();
33928
+ this.#initToolbarGroups();
33929
+ this.#makeToolbarItems();
33930
+ this.#bindHostEvents();
33931
+ this._lastFontOptionsSignature = this.#fontOptionsSignature();
33932
+ if (!this.toolbarContainer) {
33933
+ this.updateToolbarState();
33934
+ return;
33935
+ }
33936
+ this.app = (0, vue.createApp)(Toolbar_default);
33937
+ this.app.directive("click-outside", v_click_outside_default);
33938
+ this.app.config.globalProperties.$toolbar = this;
33939
+ this.toolbar = this.app.mount(this.toolbarContainer);
33939
33940
  this.updateToolbarState();
33940
- return;
33941
+ } catch (error) {
33942
+ try {
33943
+ this.destroy();
33944
+ } catch {}
33945
+ throw error;
33941
33946
  }
33942
- this.app = (0, vue.createApp)(Toolbar_default);
33943
- this.app.directive("click-outside", v_click_outside_default);
33944
- this.app.config.globalProperties.$toolbar = this;
33945
- this.toolbar = this.app.mount(this.toolbarContainer);
33946
- this.updateToolbarState();
33947
33947
  }
33948
33948
  #initController() {
33949
- if (!this.superdoc) return;
33950
- this.ui = require_create_super_doc_ui.createSuperDocUI({ superdoc: this.superdoc });
33949
+ this.ui = this.superdoc?.ui ?? null;
33950
+ if (!this.ui) return;
33951
33951
  this.snapshot = this.ui.toolbar.getSnapshot();
33952
33952
  this._unsubscribeController = this.ui.toolbar.subscribe(() => {
33953
33953
  this.snapshot = this.ui.toolbar.getSnapshot();
@@ -33968,9 +33968,6 @@ var BuiltInToolbar = class extends require_eventemitter3.import_eventemitter3.de
33968
33968
  reg.unregister?.();
33969
33969
  } catch {}
33970
33970
  this._customCommandRegs.clear();
33971
- try {
33972
- this.ui?.destroy?.();
33973
- } catch {}
33974
33971
  this.ui = null;
33975
33972
  this.snapshot = null;
33976
33973
  }
@@ -34591,6 +34588,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
34591
34588
  #v2LockUnsub = null;
34592
34589
  #pendingV2LockSeed = null;
34593
34590
  #mountWrapper = null;
34591
+ #ui = null;
34594
34592
  #surfaceManager;
34595
34593
  #editorRuntimeRegistry = new EditorRuntimeRegistry();
34596
34594
  #editorRuntimeRegistryUnsub = null;
@@ -34697,7 +34695,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
34697
34695
  this.config.colors = shuffleArray(this.config.colors);
34698
34696
  this.userColorMap = /* @__PURE__ */ new Map();
34699
34697
  this.colorIndex = 0;
34700
- this.version = "2.0.0-next.45";
34698
+ this.version = "2.0.0-next.46";
34701
34699
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
34702
34700
  this.superdocId = config.superdocId || require_uuid.v4_default();
34703
34701
  this.colors = this.config.colors ?? [];
@@ -34749,6 +34747,13 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
34749
34747
  get requiredNumberOfEditors() {
34750
34748
  return this.#requireSuperdocStore("requiredNumberOfEditors").documents.filter((d) => d.type === DOCX).length;
34751
34749
  }
34750
+ get ui() {
34751
+ if (!this.#ui) {
34752
+ this.#ui = require_create_super_doc_ui.createSuperDocUI({ superdoc: this });
34753
+ if (this.#destroyed) this.#ui.destroy();
34754
+ }
34755
+ return this.#ui;
34756
+ }
34752
34757
  get state() {
34753
34758
  return {
34754
34759
  documents: this.#requireSuperdocStore("state").documents,
@@ -35456,10 +35461,12 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
35456
35461
  return this.#fontsApi;
35457
35462
  }
35458
35463
  #clearActiveEditorProjection() {
35464
+ const hadActiveEditor = this.activeEditor !== null;
35459
35465
  this.#teardownV2FontsRelay();
35460
35466
  this.activeEditor = null;
35461
35467
  if (this.toolbar?.setActiveEditor) this.toolbar.setActiveEditor(null);
35462
35468
  else if (this.toolbar) this.toolbar.activeEditor = null;
35469
+ if (hadActiveEditor) this.emit("active-editor-change");
35463
35470
  }
35464
35471
  #v2FontsUnsub = null;
35465
35472
  #teardownV2FontsRelay() {
@@ -35494,9 +35501,11 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
35494
35501
  #setActiveEditorCompatibilityProjection(editor) {
35495
35502
  if (isV2ActiveEditorFacade(editor)) {
35496
35503
  if (!this.#applyingRuntimeActiveChange && this.#editorRuntimeRegistry.getActive()) this.#editorRuntimeRegistry.setActive(null, "set-active-v2-facade");
35504
+ const previous = this.activeEditor;
35497
35505
  this.activeEditor = editor;
35498
35506
  this.#wireV2FontsRelay(editor);
35499
35507
  this.toolbar?.setActiveEditor?.(editor);
35508
+ if (previous !== this.activeEditor) this.emit("active-editor-change");
35500
35509
  return;
35501
35510
  }
35502
35511
  this.#clearActiveEditorProjection();
@@ -36215,6 +36224,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
36215
36224
  delete this.app.config.globalProperties.$config;
36216
36225
  delete this.app.config.globalProperties.$superdoc;
36217
36226
  }
36227
+ this.#ui?.destroy();
36218
36228
  this.#cleanupCollaboration();
36219
36229
  this.#editorRuntimeRegistryUnsub?.();
36220
36230
  this.#editorRuntimeRegistryUnsub = null;