superdoc 2.18.0-next.11 → 2.18.0-next.12
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.
- package/dist/collaboration-upgrade-engine.cjs +1 -1
- package/dist/collaboration-upgrade-engine.es.js +1 -1
- package/dist/superdoc/src/core/SuperDoc.d.ts +3 -3
- package/dist/superdoc/src/core/types/index.d.ts +9 -0
- package/dist/superdoc/src/public/index.d.cts +4 -0
- package/dist/superdoc/src/public/index.d.ts +2 -0
- package/dist/superdoc.cjs +81 -23
- package/dist/superdoc.es.js +81 -23
- package/dist-cdn/superdoc.min.js +10 -10
- package/package.json +2 -2
|
@@ -19,7 +19,7 @@ var COLLABORATION_UPGRADE_ENGINE_MINIMUM_NODE_MAJOR = 20;
|
|
|
19
19
|
var PRIVATE_ENGINE_INFO = (0, _superdoc_docx_engine_collaboration_upgrade_engine.getCollaborationUpgradeEngineInfo)();
|
|
20
20
|
var ENGINE_INFO = Object.freeze({
|
|
21
21
|
...PRIVATE_ENGINE_INFO,
|
|
22
|
-
superdocVersion: "2.18.0-next.
|
|
22
|
+
superdocVersion: "2.18.0-next.12",
|
|
23
23
|
roomSchemaVersion: Object.freeze({ ...PRIVATE_ENGINE_INFO.roomSchemaVersion }),
|
|
24
24
|
supportedBundleVersions: SUPPORTED_COLLABORATION_UPGRADE_BUNDLE_VERSIONS,
|
|
25
25
|
supportedV1ReaderContractVersions: SUPPORTED_V1_READER_CONTRACT_VERSIONS
|
|
@@ -18,7 +18,7 @@ var COLLABORATION_UPGRADE_ENGINE_MINIMUM_NODE_MAJOR = 20;
|
|
|
18
18
|
var PRIVATE_ENGINE_INFO = getCollaborationUpgradeEngineInfo$1();
|
|
19
19
|
var ENGINE_INFO = Object.freeze({
|
|
20
20
|
...PRIVATE_ENGINE_INFO,
|
|
21
|
-
superdocVersion: "2.18.0-next.
|
|
21
|
+
superdocVersion: "2.18.0-next.12",
|
|
22
22
|
roomSchemaVersion: Object.freeze({ ...PRIVATE_ENGINE_INFO.roomSchemaVersion }),
|
|
23
23
|
supportedBundleVersions: SUPPORTED_COLLABORATION_UPGRADE_BUNDLE_VERSIONS,
|
|
24
24
|
supportedV1ReaderContractVersions: SUPPORTED_V1_READER_CONTRACT_VERSIONS
|
|
@@ -9,7 +9,7 @@ import { normalizeInteractionConfig } from './config/normalize-interaction-confi
|
|
|
9
9
|
import { normalizeSurfacesConfig } from './config/normalize-surfaces-config.js';
|
|
10
10
|
import { EditorRuntimeFocusOptions } from './editor-runtime/types.js';
|
|
11
11
|
import { BorrowedSuperDocUI } from '../public/ui/types.js';
|
|
12
|
-
import { AwarenessUser, CanPerformPermissionParams, CollaborationProvider, Config, ContentControlActiveChangePayload, ContentControlClickPayload, DocumentMode, Editor, EditorUpdateEvent, ExportParams, FontsChangedPayload, FontsResolvedPayload, InternalConfig, ListDefinitionsPayload, NavigableAddress, DocumentRendererRuntime, SearchMatch, SuperDocAwarenessUpdatePayload, SuperDocCommentsUpdatePayload, SuperDocCommentsListChangePayload, SuperDocDocumentModeChangePayload, SuperDocDocumentReplacedPayload, SuperDocEditorPayload, SuperDocExceptionPayload, SuperDocFontsApi, SuperDocFormattingMarksChangePayload, SuperDocLockedPayload, SuperDocCollaborationConnectionChangePayload, SuperDocMeasurementUnit, SuperDocMeasurementUnitChangePayload, SuperDocPageMarginsChangePayload, SuperDocPaginationUpdatePayload, SuperDocReadyPayload, SuperDocState, SuperDocTrackedChangesBulkDecisionPayload, SuperDocViewportChangePayload, SuperDocViewportMetrics, SuperDocZoomMode, SuperDocZoomPayload, SuperDocZoomState, SurfaceHandle, SurfaceRequest, UpgradeToCollaborationOptions, User, ViewingOptions } from './types/index.js';
|
|
12
|
+
import { AwarenessUser, CanPerformPermissionParams, CollaborationProvider, Config, ContentControlActiveChangePayload, ContentControlClickPayload, DocumentMode, Editor, EditorUpdateEvent, ExportParams, FontsChangedPayload, FontsResolvedPayload, InternalConfig, ListDefinitionsPayload, NavigableAddress, DocumentRendererRuntime, SearchMatch, SuperDocAwarenessUpdatePayload, SuperDocCommentsUpdatePayload, SuperDocCommentsListChangePayload, SuperDocDocumentModeChangePayload, SuperDocDocumentReplacedPayload, SuperDocEditorPayload, SuperDocExceptionPayload, SuperDocFontsApi, SuperDocFormattingMarksChangePayload, SuperDocLockedPayload, SuperDocCollaborationConnectionChangePayload, SuperDocMeasurementUnit, SuperDocMeasurementUnitChangePayload, SuperDocPageMarginsChangePayload, SuperDocPaginationUpdatePayload, SuperDocReadyPayload, SuperDocState, SuperDocTrackedChangesBulkDecisionPayload, SuperDocViewportChangePayload, SuperDocViewportMetrics, SuperDocZoomMode, SuperDocZoomPayload, SuperDocZoomState, SurfaceHandle, SurfaceRequest, UpgradeToCollaborationOptions, UpgradeToCollaborationResult, User, ViewingOptions } from './types/index.js';
|
|
13
13
|
import { WhiteboardData } from './whiteboard/Whiteboard.js';
|
|
14
14
|
type ToolbarLike = {
|
|
15
15
|
activeEditor?: unknown;
|
|
@@ -367,9 +367,9 @@ export declare class SuperDoc extends EventEmitter<SuperDocEventMap> {
|
|
|
367
367
|
* - A supported v2 single-doc `v2Collaboration` target
|
|
368
368
|
* - Create-and-upgrade only (no merge semantics)
|
|
369
369
|
*
|
|
370
|
-
* @returns
|
|
370
|
+
* @returns The attached room and document once the collaborative runtime is ready
|
|
371
371
|
*/
|
|
372
|
-
upgradeToCollaboration(options: UpgradeToCollaborationOptions): Promise<
|
|
372
|
+
upgradeToCollaboration(options: UpgradeToCollaborationOptions): Promise<UpgradeToCollaborationResult>;
|
|
373
373
|
/**
|
|
374
374
|
* Add a user to the shared users list. Requires the instance to be
|
|
375
375
|
* ready; pre-ready mutations would be silently overwritten by the
|
|
@@ -1193,6 +1193,15 @@ export interface UpgradeToCollaborationOptions {
|
|
|
1193
1193
|
*/
|
|
1194
1194
|
provider?: CollaborationProvider;
|
|
1195
1195
|
}
|
|
1196
|
+
/** Confirmed identities of the room and local document attached by a successful upgrade. */
|
|
1197
|
+
export interface UpgradeToCollaborationResult {
|
|
1198
|
+
roomId: string;
|
|
1199
|
+
documentId: string;
|
|
1200
|
+
}
|
|
1201
|
+
/** Machine-readable failures returned by a create-and-upgrade attempt. */
|
|
1202
|
+
export interface SuperDocCollaborationUpgradeError extends Error {
|
|
1203
|
+
code: 'collaboration-v2-room-already-exists' | 'collaboration-upgrade-target-conflict';
|
|
1204
|
+
}
|
|
1196
1205
|
/** Context passed to a hyperlink activation handler. */
|
|
1197
1206
|
export interface HyperlinkActivationContext {
|
|
1198
1207
|
/** The editor instance. */
|
|
@@ -130,6 +130,7 @@ import type { SuperDocCharRange as __Cjs_SuperDocCharRange } from './index.js' w
|
|
|
130
130
|
import type { SuperDocCollaborationConnectionChangePayload as __Cjs_SuperDocCollaborationConnectionChangePayload } from './index.js' with { "resolution-mode": "import" };
|
|
131
131
|
import type { SuperDocCollaborationConnectionKind as __Cjs_SuperDocCollaborationConnectionKind } from './index.js' with { "resolution-mode": "import" };
|
|
132
132
|
import type { SuperDocCollaborationConnectionState as __Cjs_SuperDocCollaborationConnectionState } from './index.js' with { "resolution-mode": "import" };
|
|
133
|
+
import type { SuperDocCollaborationUpgradeError as __Cjs_SuperDocCollaborationUpgradeError } from './index.js' with { "resolution-mode": "import" };
|
|
133
134
|
import type { SuperDocCommandApi as __Cjs_SuperDocCommandApi } from './index.js' with { "resolution-mode": "import" };
|
|
134
135
|
import type { SuperDocCommandExecuteContext as __Cjs_SuperDocCommandExecuteContext } from './index.js' with { "resolution-mode": "import" };
|
|
135
136
|
import type { SuperDocCommandState as __Cjs_SuperDocCommandState } from './index.js' with { "resolution-mode": "import" };
|
|
@@ -273,6 +274,7 @@ import type { TrackedChangeSemanticColorKey as __Cjs_TrackedChangeSemanticColorK
|
|
|
273
274
|
import type { TrackedChangeSemanticColorResolverInput as __Cjs_TrackedChangeSemanticColorResolverInput } from './index.js' with { "resolution-mode": "import" };
|
|
274
275
|
import type { UIConfig as __Cjs_UIConfig } from './index.js' with { "resolution-mode": "import" };
|
|
275
276
|
import type { UpgradeToCollaborationOptions as __Cjs_UpgradeToCollaborationOptions } from './index.js' with { "resolution-mode": "import" };
|
|
277
|
+
import type { UpgradeToCollaborationResult as __Cjs_UpgradeToCollaborationResult } from './index.js' with { "resolution-mode": "import" };
|
|
276
278
|
import type { User as __Cjs_User } from './index.js' with { "resolution-mode": "import" };
|
|
277
279
|
import type { V2CollaborationConfig as __Cjs_V2CollaborationConfig } from './index.js' with { "resolution-mode": "import" };
|
|
278
280
|
import type { ViewingOptions as __Cjs_ViewingOptions } from './index.js' with { "resolution-mode": "import" };
|
|
@@ -420,6 +422,7 @@ export type { __Cjs_SuperDocCharRange as SuperDocCharRange };
|
|
|
420
422
|
export type { __Cjs_SuperDocCollaborationConnectionChangePayload as SuperDocCollaborationConnectionChangePayload };
|
|
421
423
|
export type { __Cjs_SuperDocCollaborationConnectionKind as SuperDocCollaborationConnectionKind };
|
|
422
424
|
export type { __Cjs_SuperDocCollaborationConnectionState as SuperDocCollaborationConnectionState };
|
|
425
|
+
export type { __Cjs_SuperDocCollaborationUpgradeError as SuperDocCollaborationUpgradeError };
|
|
423
426
|
export type { __Cjs_SuperDocCommandApi as SuperDocCommandApi };
|
|
424
427
|
export type { __Cjs_SuperDocCommandExecuteContext as SuperDocCommandExecuteContext };
|
|
425
428
|
export type { __Cjs_SuperDocCommandState as SuperDocCommandState };
|
|
@@ -563,6 +566,7 @@ export type { __Cjs_TrackedChangeSemanticColorKey as TrackedChangeSemanticColorK
|
|
|
563
566
|
export type { __Cjs_TrackedChangeSemanticColorResolverInput as TrackedChangeSemanticColorResolverInput };
|
|
564
567
|
export type { __Cjs_UIConfig as UIConfig };
|
|
565
568
|
export type { __Cjs_UpgradeToCollaborationOptions as UpgradeToCollaborationOptions };
|
|
569
|
+
export type { __Cjs_UpgradeToCollaborationResult as UpgradeToCollaborationResult };
|
|
566
570
|
export type { __Cjs_User as User };
|
|
567
571
|
export type { __Cjs_V2CollaborationConfig as V2CollaborationConfig };
|
|
568
572
|
export type { __Cjs_ViewingOptions as ViewingOptions };
|
|
@@ -181,6 +181,8 @@ export type { InteractionConfig } from '../core/types/index.js';
|
|
|
181
181
|
export type { SurfacesConfig } from '../core/types/index.js';
|
|
182
182
|
export type { UIConfig } from '../core/types/index.js';
|
|
183
183
|
export type { UpgradeToCollaborationOptions } from '../core/types/index.js';
|
|
184
|
+
export type { UpgradeToCollaborationResult } from '../core/types/index.js';
|
|
185
|
+
export type { SuperDocCollaborationUpgradeError } from '../core/types/index.js';
|
|
184
186
|
export type { V2CollaborationConfig } from '../core/types/index.js';
|
|
185
187
|
export type { User } from '../core/types/index.js';
|
|
186
188
|
export type { ViewOptions } from '../core/types/index.js';
|
package/dist/superdoc.cjs
CHANGED
|
@@ -316,7 +316,7 @@ var shuffleArray = (array) => {
|
|
|
316
316
|
var DEFAULT_ENDPOINT = "https://ingest.superdoc.dev/v1/collect";
|
|
317
317
|
function getSuperdocVersion() {
|
|
318
318
|
try {
|
|
319
|
-
return "2.18.0-next.
|
|
319
|
+
return "2.18.0-next.12";
|
|
320
320
|
} catch {
|
|
321
321
|
return "unknown";
|
|
322
322
|
}
|
|
@@ -45435,6 +45435,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
45435
45435
|
#destroyed;
|
|
45436
45436
|
#diagnostics;
|
|
45437
45437
|
#isUpgrading;
|
|
45438
|
+
#pendingUpgrade;
|
|
45438
45439
|
/** Aborts an in-flight upgrade (sync wait or ready wait). */
|
|
45439
45440
|
#abortUpgrade;
|
|
45440
45441
|
/**
|
|
@@ -45540,6 +45541,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
45540
45541
|
super();
|
|
45541
45542
|
this.#destroyed = false;
|
|
45542
45543
|
this.#isUpgrading = false;
|
|
45544
|
+
this.#pendingUpgrade = null;
|
|
45543
45545
|
this.#abortUpgrade = null;
|
|
45544
45546
|
this.#v2AwarenessUnsub = null;
|
|
45545
45547
|
this.#v2LockUnsub = null;
|
|
@@ -45744,7 +45746,7 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
45744
45746
|
this.config.colors = shuffleArray(this.config.colors);
|
|
45745
45747
|
this.userColorMap = /* @__PURE__ */ new Map();
|
|
45746
45748
|
this.colorIndex = 0;
|
|
45747
|
-
this.version = "2.18.0-next.
|
|
45749
|
+
this.version = "2.18.0-next.12";
|
|
45748
45750
|
this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
|
|
45749
45751
|
this.superdocId = config.superdocId || require_uuid.v4();
|
|
45750
45752
|
this.colors = this.config.colors ?? [];
|
|
@@ -46319,29 +46321,78 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
46319
46321
|
* - A supported v2 single-doc `v2Collaboration` target
|
|
46320
46322
|
* - Create-and-upgrade only (no merge semantics)
|
|
46321
46323
|
*
|
|
46322
|
-
* @returns
|
|
46324
|
+
* @returns The attached room and document once the collaborative runtime is ready
|
|
46323
46325
|
*/
|
|
46324
46326
|
async upgradeToCollaboration(options) {
|
|
46327
|
+
if (this.#pendingUpgrade) {
|
|
46328
|
+
const { target } = this.#resolveCollaborationUpgradeTarget(options);
|
|
46329
|
+
if (this.#sameUpgradeTarget(target, this.#pendingUpgrade.target)) return this.#pendingUpgrade.promise;
|
|
46330
|
+
throw Object.assign(/* @__PURE__ */ new Error("SuperDoc: a different collaboration target is already upgrading"), { code: "collaboration-upgrade-target-conflict" });
|
|
46331
|
+
}
|
|
46325
46332
|
const { target } = this.#validateUpgradePrerequisites(options);
|
|
46326
46333
|
this.#isUpgrading = true;
|
|
46327
|
-
|
|
46328
|
-
const localSource = await this.#captureCurrentDocxSourceForUpgrade();
|
|
46329
|
-
const rollback = this.#snapshotV2UpgradeState();
|
|
46330
|
-
const lockSeed = this.#snapshotV2LockSeed();
|
|
46331
|
-
this.#assertNotDestroyed();
|
|
46334
|
+
const operation = (async () => {
|
|
46332
46335
|
try {
|
|
46333
|
-
|
|
46334
|
-
const
|
|
46335
|
-
this.#
|
|
46336
|
-
this.#
|
|
46337
|
-
|
|
46338
|
-
|
|
46339
|
-
|
|
46340
|
-
|
|
46341
|
-
|
|
46342
|
-
|
|
46343
|
-
|
|
46344
|
-
|
|
46336
|
+
const localSource = await this.#captureCurrentDocxSourceForUpgrade();
|
|
46337
|
+
const rollback = this.#snapshotV2UpgradeState();
|
|
46338
|
+
const lockSeed = this.#snapshotV2LockSeed();
|
|
46339
|
+
this.#assertNotDestroyed();
|
|
46340
|
+
try {
|
|
46341
|
+
this.#pendingV2LockSeed = lockSeed;
|
|
46342
|
+
const promotion = await this.#promoteSingleDocumentToV2Collaboration(target, localSource);
|
|
46343
|
+
this.#finalizeSingleDocumentV2Collaboration(promotion, target);
|
|
46344
|
+
this.#pendingV2LockSeed = null;
|
|
46345
|
+
const attachedDocumentId = this.activeEditor?.options?.documentId;
|
|
46346
|
+
const attachedRoomId = promotion.configDoc.v2Collaboration?.documentId;
|
|
46347
|
+
if (typeof attachedDocumentId !== "string" || attachedDocumentId !== promotion.configDoc.id || typeof attachedRoomId !== "string" || attachedRoomId !== target.documentId) throw new Error("SuperDoc: collaboration upgrade did not attach the expected room and document");
|
|
46348
|
+
return {
|
|
46349
|
+
roomId: attachedRoomId,
|
|
46350
|
+
documentId: attachedDocumentId
|
|
46351
|
+
};
|
|
46352
|
+
} catch (err) {
|
|
46353
|
+
this.#rollbackV2UpgradeState(rollback);
|
|
46354
|
+
throw err;
|
|
46355
|
+
}
|
|
46356
|
+
} finally {
|
|
46357
|
+
this.#abortUpgrade = null;
|
|
46358
|
+
this.#isUpgrading = false;
|
|
46359
|
+
this.#pendingUpgrade = null;
|
|
46360
|
+
}
|
|
46361
|
+
})();
|
|
46362
|
+
this.#pendingUpgrade = {
|
|
46363
|
+
target,
|
|
46364
|
+
promise: operation
|
|
46365
|
+
};
|
|
46366
|
+
return operation;
|
|
46367
|
+
}
|
|
46368
|
+
#sameUpgradeTarget(left, right) {
|
|
46369
|
+
if (left.token !== right.token) return false;
|
|
46370
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
46371
|
+
const sameValue = (first, second) => {
|
|
46372
|
+
if (Object.is(first, second)) return true;
|
|
46373
|
+
if (!first || !second || typeof first !== "object" || typeof second !== "object") return false;
|
|
46374
|
+
if (Object.getPrototypeOf(first) !== Object.getPrototypeOf(second)) return false;
|
|
46375
|
+
if (seen.has(first)) return seen.get(first) === second;
|
|
46376
|
+
seen.set(first, second);
|
|
46377
|
+
if (first instanceof Date && second instanceof Date) return first.getTime() === second.getTime();
|
|
46378
|
+
if (first instanceof RegExp && second instanceof RegExp) return first.source === second.source && first.flags === second.flags;
|
|
46379
|
+
if (first instanceof ArrayBuffer && second instanceof ArrayBuffer) return sameValue(Array.from(new Uint8Array(first)), Array.from(new Uint8Array(second)));
|
|
46380
|
+
if (ArrayBuffer.isView(first) && ArrayBuffer.isView(second)) return first.constructor === second.constructor && sameValue(Array.from(new Uint8Array(first.buffer, first.byteOffset, first.byteLength)), Array.from(new Uint8Array(second.buffer, second.byteOffset, second.byteLength)));
|
|
46381
|
+
if (first instanceof Map && second instanceof Map) return first.size === second.size && sameValue(Array.from(first.entries()), Array.from(second.entries()));
|
|
46382
|
+
if (first instanceof Set && second instanceof Set) return first.size === second.size && sameValue(Array.from(first.values()), Array.from(second.values()));
|
|
46383
|
+
if (Array.isArray(first) && Array.isArray(second)) return first.length === second.length && first.every((value, index) => sameValue(value, second[index]));
|
|
46384
|
+
if (Object.getPrototypeOf(first) !== Object.prototype && Object.getPrototypeOf(first) !== null) return false;
|
|
46385
|
+
const keys = Object.keys(first).sort();
|
|
46386
|
+
const otherKeys = Object.keys(second).sort();
|
|
46387
|
+
return keys.length === otherKeys.length && keys.every((key, index) => key === otherKeys[index] && sameValue(first[key], second[key]));
|
|
46388
|
+
};
|
|
46389
|
+
return sameValue({
|
|
46390
|
+
...left,
|
|
46391
|
+
token: void 0
|
|
46392
|
+
}, {
|
|
46393
|
+
...right,
|
|
46394
|
+
token: void 0
|
|
46395
|
+
});
|
|
46345
46396
|
}
|
|
46346
46397
|
#snapshotV2LockSeed() {
|
|
46347
46398
|
return {
|
|
@@ -46668,9 +46719,13 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
46668
46719
|
if (docxDocs.length > 1) throw new Error("SuperDoc: upgradeToCollaboration() only supports a single DOCX document");
|
|
46669
46720
|
if (cfg.documents.length !== docxDocs.length) throw new Error("SuperDoc: upgradeToCollaboration() only supports single-DOCX instances");
|
|
46670
46721
|
if (!isV2ActiveEditorFacade(this.#resolveSourceEditor())) throw new Error("SuperDoc: upgradeToCollaboration() requires a ready v2 DOCX editor");
|
|
46671
|
-
const
|
|
46672
|
-
const mountedDocumentId = configDoc.id;
|
|
46722
|
+
const mountedDocumentId = docxDocs[0].id;
|
|
46673
46723
|
if (typeof mountedDocumentId !== "string" || mountedDocumentId.length === 0) throw new Error("SuperDoc: source document is missing its mounted document identity");
|
|
46724
|
+
return this.#resolveCollaborationUpgradeTarget(options);
|
|
46725
|
+
}
|
|
46726
|
+
#resolveCollaborationUpgradeTarget(options) {
|
|
46727
|
+
const cfg = this.config;
|
|
46728
|
+
const configDoc = cfg.documents.find((doc) => doc.type === DOCX);
|
|
46674
46729
|
const collaborationModule = cfg.modules?.collaboration;
|
|
46675
46730
|
const legacyCollaboration = options.ydoc || options.provider ? {
|
|
46676
46731
|
ydoc: options.ydoc,
|
|
@@ -46686,7 +46741,10 @@ var SuperDoc = class extends require_eventemitter3.import_eventemitter3.default
|
|
|
46686
46741
|
...typeof window !== "undefined" ? { authEndpointBaseUrl: window.location.href } : {}
|
|
46687
46742
|
});
|
|
46688
46743
|
if (!resolution.ok) throw new Error(`SuperDoc: upgradeToCollaboration() ${resolution.reason}: ${resolution.message}`);
|
|
46689
|
-
return { target:
|
|
46744
|
+
return { target: {
|
|
46745
|
+
...resolution.target,
|
|
46746
|
+
roomMode: "create"
|
|
46747
|
+
} };
|
|
46690
46748
|
}
|
|
46691
46749
|
#unwrapMaybeRef(value) {
|
|
46692
46750
|
if (value && typeof value === "object" && "value" in value) return value.value;
|
package/dist/superdoc.es.js
CHANGED
|
@@ -315,7 +315,7 @@ var shuffleArray = (array) => {
|
|
|
315
315
|
var DEFAULT_ENDPOINT = "https://ingest.superdoc.dev/v1/collect";
|
|
316
316
|
function getSuperdocVersion() {
|
|
317
317
|
try {
|
|
318
|
-
return "2.18.0-next.
|
|
318
|
+
return "2.18.0-next.12";
|
|
319
319
|
} catch {
|
|
320
320
|
return "unknown";
|
|
321
321
|
}
|
|
@@ -45366,6 +45366,7 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
45366
45366
|
#destroyed;
|
|
45367
45367
|
#diagnostics;
|
|
45368
45368
|
#isUpgrading;
|
|
45369
|
+
#pendingUpgrade;
|
|
45369
45370
|
/** Aborts an in-flight upgrade (sync wait or ready wait). */
|
|
45370
45371
|
#abortUpgrade;
|
|
45371
45372
|
/**
|
|
@@ -45471,6 +45472,7 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
45471
45472
|
super();
|
|
45472
45473
|
this.#destroyed = false;
|
|
45473
45474
|
this.#isUpgrading = false;
|
|
45475
|
+
this.#pendingUpgrade = null;
|
|
45474
45476
|
this.#abortUpgrade = null;
|
|
45475
45477
|
this.#v2AwarenessUnsub = null;
|
|
45476
45478
|
this.#v2LockUnsub = null;
|
|
@@ -45675,7 +45677,7 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
45675
45677
|
this.config.colors = shuffleArray(this.config.colors);
|
|
45676
45678
|
this.userColorMap = /* @__PURE__ */ new Map();
|
|
45677
45679
|
this.colorIndex = 0;
|
|
45678
|
-
this.version = "2.18.0-next.
|
|
45680
|
+
this.version = "2.18.0-next.12";
|
|
45679
45681
|
this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
|
|
45680
45682
|
this.superdocId = config.superdocId || v4();
|
|
45681
45683
|
this.colors = this.config.colors ?? [];
|
|
@@ -46250,29 +46252,78 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
46250
46252
|
* - A supported v2 single-doc `v2Collaboration` target
|
|
46251
46253
|
* - Create-and-upgrade only (no merge semantics)
|
|
46252
46254
|
*
|
|
46253
|
-
* @returns
|
|
46255
|
+
* @returns The attached room and document once the collaborative runtime is ready
|
|
46254
46256
|
*/
|
|
46255
46257
|
async upgradeToCollaboration(options) {
|
|
46258
|
+
if (this.#pendingUpgrade) {
|
|
46259
|
+
const { target } = this.#resolveCollaborationUpgradeTarget(options);
|
|
46260
|
+
if (this.#sameUpgradeTarget(target, this.#pendingUpgrade.target)) return this.#pendingUpgrade.promise;
|
|
46261
|
+
throw Object.assign(/* @__PURE__ */ new Error("SuperDoc: a different collaboration target is already upgrading"), { code: "collaboration-upgrade-target-conflict" });
|
|
46262
|
+
}
|
|
46256
46263
|
const { target } = this.#validateUpgradePrerequisites(options);
|
|
46257
46264
|
this.#isUpgrading = true;
|
|
46258
|
-
|
|
46259
|
-
const localSource = await this.#captureCurrentDocxSourceForUpgrade();
|
|
46260
|
-
const rollback = this.#snapshotV2UpgradeState();
|
|
46261
|
-
const lockSeed = this.#snapshotV2LockSeed();
|
|
46262
|
-
this.#assertNotDestroyed();
|
|
46265
|
+
const operation = (async () => {
|
|
46263
46266
|
try {
|
|
46264
|
-
|
|
46265
|
-
const
|
|
46266
|
-
this.#
|
|
46267
|
-
this.#
|
|
46268
|
-
|
|
46269
|
-
|
|
46270
|
-
|
|
46271
|
-
|
|
46272
|
-
|
|
46273
|
-
|
|
46274
|
-
|
|
46275
|
-
|
|
46267
|
+
const localSource = await this.#captureCurrentDocxSourceForUpgrade();
|
|
46268
|
+
const rollback = this.#snapshotV2UpgradeState();
|
|
46269
|
+
const lockSeed = this.#snapshotV2LockSeed();
|
|
46270
|
+
this.#assertNotDestroyed();
|
|
46271
|
+
try {
|
|
46272
|
+
this.#pendingV2LockSeed = lockSeed;
|
|
46273
|
+
const promotion = await this.#promoteSingleDocumentToV2Collaboration(target, localSource);
|
|
46274
|
+
this.#finalizeSingleDocumentV2Collaboration(promotion, target);
|
|
46275
|
+
this.#pendingV2LockSeed = null;
|
|
46276
|
+
const attachedDocumentId = this.activeEditor?.options?.documentId;
|
|
46277
|
+
const attachedRoomId = promotion.configDoc.v2Collaboration?.documentId;
|
|
46278
|
+
if (typeof attachedDocumentId !== "string" || attachedDocumentId !== promotion.configDoc.id || typeof attachedRoomId !== "string" || attachedRoomId !== target.documentId) throw new Error("SuperDoc: collaboration upgrade did not attach the expected room and document");
|
|
46279
|
+
return {
|
|
46280
|
+
roomId: attachedRoomId,
|
|
46281
|
+
documentId: attachedDocumentId
|
|
46282
|
+
};
|
|
46283
|
+
} catch (err) {
|
|
46284
|
+
this.#rollbackV2UpgradeState(rollback);
|
|
46285
|
+
throw err;
|
|
46286
|
+
}
|
|
46287
|
+
} finally {
|
|
46288
|
+
this.#abortUpgrade = null;
|
|
46289
|
+
this.#isUpgrading = false;
|
|
46290
|
+
this.#pendingUpgrade = null;
|
|
46291
|
+
}
|
|
46292
|
+
})();
|
|
46293
|
+
this.#pendingUpgrade = {
|
|
46294
|
+
target,
|
|
46295
|
+
promise: operation
|
|
46296
|
+
};
|
|
46297
|
+
return operation;
|
|
46298
|
+
}
|
|
46299
|
+
#sameUpgradeTarget(left, right) {
|
|
46300
|
+
if (left.token !== right.token) return false;
|
|
46301
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
46302
|
+
const sameValue = (first, second) => {
|
|
46303
|
+
if (Object.is(first, second)) return true;
|
|
46304
|
+
if (!first || !second || typeof first !== "object" || typeof second !== "object") return false;
|
|
46305
|
+
if (Object.getPrototypeOf(first) !== Object.getPrototypeOf(second)) return false;
|
|
46306
|
+
if (seen.has(first)) return seen.get(first) === second;
|
|
46307
|
+
seen.set(first, second);
|
|
46308
|
+
if (first instanceof Date && second instanceof Date) return first.getTime() === second.getTime();
|
|
46309
|
+
if (first instanceof RegExp && second instanceof RegExp) return first.source === second.source && first.flags === second.flags;
|
|
46310
|
+
if (first instanceof ArrayBuffer && second instanceof ArrayBuffer) return sameValue(Array.from(new Uint8Array(first)), Array.from(new Uint8Array(second)));
|
|
46311
|
+
if (ArrayBuffer.isView(first) && ArrayBuffer.isView(second)) return first.constructor === second.constructor && sameValue(Array.from(new Uint8Array(first.buffer, first.byteOffset, first.byteLength)), Array.from(new Uint8Array(second.buffer, second.byteOffset, second.byteLength)));
|
|
46312
|
+
if (first instanceof Map && second instanceof Map) return first.size === second.size && sameValue(Array.from(first.entries()), Array.from(second.entries()));
|
|
46313
|
+
if (first instanceof Set && second instanceof Set) return first.size === second.size && sameValue(Array.from(first.values()), Array.from(second.values()));
|
|
46314
|
+
if (Array.isArray(first) && Array.isArray(second)) return first.length === second.length && first.every((value, index) => sameValue(value, second[index]));
|
|
46315
|
+
if (Object.getPrototypeOf(first) !== Object.prototype && Object.getPrototypeOf(first) !== null) return false;
|
|
46316
|
+
const keys = Object.keys(first).sort();
|
|
46317
|
+
const otherKeys = Object.keys(second).sort();
|
|
46318
|
+
return keys.length === otherKeys.length && keys.every((key, index) => key === otherKeys[index] && sameValue(first[key], second[key]));
|
|
46319
|
+
};
|
|
46320
|
+
return sameValue({
|
|
46321
|
+
...left,
|
|
46322
|
+
token: void 0
|
|
46323
|
+
}, {
|
|
46324
|
+
...right,
|
|
46325
|
+
token: void 0
|
|
46326
|
+
});
|
|
46276
46327
|
}
|
|
46277
46328
|
#snapshotV2LockSeed() {
|
|
46278
46329
|
return {
|
|
@@ -46599,9 +46650,13 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
46599
46650
|
if (docxDocs.length > 1) throw new Error("SuperDoc: upgradeToCollaboration() only supports a single DOCX document");
|
|
46600
46651
|
if (cfg.documents.length !== docxDocs.length) throw new Error("SuperDoc: upgradeToCollaboration() only supports single-DOCX instances");
|
|
46601
46652
|
if (!isV2ActiveEditorFacade(this.#resolveSourceEditor())) throw new Error("SuperDoc: upgradeToCollaboration() requires a ready v2 DOCX editor");
|
|
46602
|
-
const
|
|
46603
|
-
const mountedDocumentId = configDoc.id;
|
|
46653
|
+
const mountedDocumentId = docxDocs[0].id;
|
|
46604
46654
|
if (typeof mountedDocumentId !== "string" || mountedDocumentId.length === 0) throw new Error("SuperDoc: source document is missing its mounted document identity");
|
|
46655
|
+
return this.#resolveCollaborationUpgradeTarget(options);
|
|
46656
|
+
}
|
|
46657
|
+
#resolveCollaborationUpgradeTarget(options) {
|
|
46658
|
+
const cfg = this.config;
|
|
46659
|
+
const configDoc = cfg.documents.find((doc) => doc.type === DOCX);
|
|
46605
46660
|
const collaborationModule = cfg.modules?.collaboration;
|
|
46606
46661
|
const legacyCollaboration = options.ydoc || options.provider ? {
|
|
46607
46662
|
ydoc: options.ydoc,
|
|
@@ -46617,7 +46672,10 @@ var SuperDoc = class extends import_eventemitter3.default {
|
|
|
46617
46672
|
...typeof window !== "undefined" ? { authEndpointBaseUrl: window.location.href } : {}
|
|
46618
46673
|
});
|
|
46619
46674
|
if (!resolution.ok) throw new Error(`SuperDoc: upgradeToCollaboration() ${resolution.reason}: ${resolution.message}`);
|
|
46620
|
-
return { target:
|
|
46675
|
+
return { target: {
|
|
46676
|
+
...resolution.target,
|
|
46677
|
+
roomMode: "create"
|
|
46678
|
+
} };
|
|
46621
46679
|
}
|
|
46622
46680
|
#unwrapMaybeRef(value) {
|
|
46623
46681
|
if (value && typeof value === "object" && "value" in value) return value.value;
|