@ones-editor/editor 5.0.5 → 5.0.6-beta.DNP8216.2
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/@ones-editor/core/src/core/composition/clipboard/resources/doc-resource-hooks.d.ts +6 -0
- package/@ones-editor/core/src/core/doc/doc.d.ts +72 -0
- package/@ones-editor/core/src/core/editor/index.d.ts +1 -0
- package/@ones-editor/core/src/core/editor/wiki-macro-locks.d.ts +9 -0
- package/@ones-editor/core/src/core/editor-doc/editor-doc.d.ts +6 -0
- package/@ones-editor/core/src/core/types.d.ts +19 -1
- package/@ones-editor/core/src/core/undo-manager/actions/macro-edit-action.d.ts +10 -0
- package/@ones-editor/core/src/core/undo-manager/undo-manager.d.ts +10 -0
- package/@ones-editor/core/src/local-doc/index.d.ts +7 -1
- package/@ones-editor/sharedb-doc/src/doc/auth-connection.d.ts +12 -0
- package/@ones-editor/sharedb-doc/src/doc/sharedb-client.d.ts +2 -1
- package/@ones-editor/sharedb-doc/src/doc/sharedb-doc.d.ts +6 -0
- package/@ones-editor/sharedb-doc/src/doc/sharedb-local-doc.d.ts +1 -0
- package/@ones-editor/sharedb-doc/src/types.d.ts +4 -0
- package/@ones-editor/sharedb-doc/src/versions/sharedb-server.d.ts +2 -0
- package/@ones-editor/sharedb-doc/src/versions/simple-client.d.ts +2 -1
- package/@ones-editor/tsconfig.tsbuildinfo +1 -1
- package/@ones-editor/ui/src/block-menu/index.d.ts +1 -0
- package/@ones-editor/versions/src/history-diff.d.ts +1 -0
- package/@ones-editor/versions/src/history-doc/history-doc.d.ts +6 -1
- package/dist/index.js +613 -30
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24923,6 +24923,19 @@ var __publicField = (obj, key, value) => {
|
|
|
24923
24923
|
}
|
|
24924
24924
|
return versions;
|
|
24925
24925
|
}
|
|
24926
|
+
class WikiMacroError extends Error {
|
|
24927
|
+
constructor(details, requestId) {
|
|
24928
|
+
super(details.message || details.code);
|
|
24929
|
+
__publicField(this, "code");
|
|
24930
|
+
__publicField(this, "sizeBytes");
|
|
24931
|
+
__publicField(this, "limitBytes");
|
|
24932
|
+
this.requestId = requestId;
|
|
24933
|
+
this.name = "WikiMacroError";
|
|
24934
|
+
this.code = details.code;
|
|
24935
|
+
this.sizeBytes = details.sizeBytes;
|
|
24936
|
+
this.limitBytes = details.limitBytes;
|
|
24937
|
+
}
|
|
24938
|
+
}
|
|
24926
24939
|
const logger$4b = getLogger("create-text-op");
|
|
24927
24940
|
function createTextOp(text2, attributes) {
|
|
24928
24941
|
assert(logger$4b, text2, "text is empty");
|
|
@@ -27514,6 +27527,83 @@ var __publicField = (obj, key, value) => {
|
|
|
27514
27527
|
const defaultRange = { anchor: defaultPos, focus: defaultPos };
|
|
27515
27528
|
return editorInsertBlock(editor, result.containerId, result.blockIndex, blockData, newRange != null ? newRange : defaultRange, insertBlockOptions);
|
|
27516
27529
|
}
|
|
27530
|
+
const editorLeases = /* @__PURE__ */ new WeakMap();
|
|
27531
|
+
function getLeaseState(editor) {
|
|
27532
|
+
let state = editorLeases.get(editor);
|
|
27533
|
+
if (!state) {
|
|
27534
|
+
state = { locks: /* @__PURE__ */ new Map(), activeSessions: /* @__PURE__ */ new Set(), known: true };
|
|
27535
|
+
editorLeases.set(editor, state);
|
|
27536
|
+
}
|
|
27537
|
+
return state;
|
|
27538
|
+
}
|
|
27539
|
+
function initializeWikiMacroLocks(editor) {
|
|
27540
|
+
getLeaseState(editor).known = false;
|
|
27541
|
+
}
|
|
27542
|
+
function updateWikiMacroLocks(editor, locks) {
|
|
27543
|
+
const state = getLeaseState(editor);
|
|
27544
|
+
state.known = true;
|
|
27545
|
+
state.locks.clear();
|
|
27546
|
+
locks.forEach((lock) => state.locks.set(lock.blockId, lock));
|
|
27547
|
+
}
|
|
27548
|
+
function setWikiMacroLockSession(editor, sessionId, active) {
|
|
27549
|
+
const state = getLeaseState(editor);
|
|
27550
|
+
if (active) {
|
|
27551
|
+
state.activeSessions.add(sessionId);
|
|
27552
|
+
} else {
|
|
27553
|
+
state.activeSessions.delete(sessionId);
|
|
27554
|
+
}
|
|
27555
|
+
}
|
|
27556
|
+
function isWikiMacroBlockLocked(editor, block, macroSessionId) {
|
|
27557
|
+
var _a;
|
|
27558
|
+
const state = editorLeases.get(editor);
|
|
27559
|
+
if (!state || state.known && state.locks.size === 0)
|
|
27560
|
+
return false;
|
|
27561
|
+
const mayOwnLease = !!macroSessionId && state.activeSessions.has(macroSessionId);
|
|
27562
|
+
if (!((_a = block.children) == null ? void 0 : _a.length)) {
|
|
27563
|
+
if (block.type !== "embed" || block.embedType !== "ones-open-wiki-macro")
|
|
27564
|
+
return false;
|
|
27565
|
+
if (!state.known)
|
|
27566
|
+
return true;
|
|
27567
|
+
const lease = state.locks.get(block.id);
|
|
27568
|
+
return !!lease && (!mayOwnLease || lease.sessionId !== macroSessionId);
|
|
27569
|
+
}
|
|
27570
|
+
const visited = /* @__PURE__ */ new Set();
|
|
27571
|
+
const hasLockedDescendant = (data2) => {
|
|
27572
|
+
if (visited.has(data2.id))
|
|
27573
|
+
return false;
|
|
27574
|
+
visited.add(data2.id);
|
|
27575
|
+
if (data2.type === "embed" && data2.embedType === "ones-open-wiki-macro") {
|
|
27576
|
+
if (!state.known)
|
|
27577
|
+
return true;
|
|
27578
|
+
const lease = state.locks.get(data2.id);
|
|
27579
|
+
if (lease && (!mayOwnLease || lease.sessionId !== macroSessionId))
|
|
27580
|
+
return true;
|
|
27581
|
+
}
|
|
27582
|
+
for (const containerId of data2.children || []) {
|
|
27583
|
+
const children = editor.doc.findContainerBlocks(containerId) || [];
|
|
27584
|
+
if (children.some(hasLockedDescendant))
|
|
27585
|
+
return true;
|
|
27586
|
+
}
|
|
27587
|
+
return false;
|
|
27588
|
+
};
|
|
27589
|
+
return hasLockedDescendant(block);
|
|
27590
|
+
}
|
|
27591
|
+
function isWikiMacroElementLocked(editor, block, macroSessionId) {
|
|
27592
|
+
const state = editorLeases.get(editor);
|
|
27593
|
+
if (!state || state.known && state.locks.size === 0)
|
|
27594
|
+
return false;
|
|
27595
|
+
if (isWikiMacroBlockLocked(editor, editor.getBlockData(block), macroSessionId))
|
|
27596
|
+
return true;
|
|
27597
|
+
return isHeadingBlock$1(block) && isCollapsedHeadingBlock(block) && getHeadingBlockChildren(block).some(
|
|
27598
|
+
(child) => isWikiMacroBlockLocked(editor, editor.getBlockData(child), macroSessionId)
|
|
27599
|
+
);
|
|
27600
|
+
}
|
|
27601
|
+
function clearWikiMacroLocks(editor) {
|
|
27602
|
+
const state = editorLeases.get(editor);
|
|
27603
|
+
state == null ? void 0 : state.locks.clear();
|
|
27604
|
+
state == null ? void 0 : state.activeSessions.clear();
|
|
27605
|
+
editorLeases.delete(editor);
|
|
27606
|
+
}
|
|
27517
27607
|
const logger$3J = getLogger("delete-block");
|
|
27518
27608
|
function getAllChildContainers(editor, blockData, containerIds) {
|
|
27519
27609
|
if (blockData.children) {
|
|
@@ -27543,6 +27633,8 @@ var __publicField = (obj, key, value) => {
|
|
|
27543
27633
|
return blockData;
|
|
27544
27634
|
}
|
|
27545
27635
|
function editorDeleteBlock(editor, block, newDocRange) {
|
|
27636
|
+
if (isWikiMacroElementLocked(editor, block))
|
|
27637
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
27546
27638
|
return editor.undoManager.runInGroup(() => {
|
|
27547
27639
|
const container = getParentContainer(block);
|
|
27548
27640
|
if (getChildBlockCount(container) === 1) {
|
|
@@ -27909,6 +28001,9 @@ var __publicField = (obj, key, value) => {
|
|
|
27909
28001
|
blockData[newKey] = value;
|
|
27910
28002
|
});
|
|
27911
28003
|
blockData.id = genId();
|
|
28004
|
+
if (blockData.type === "embed" && blockData.embedType === "ones-open-wiki-macro") {
|
|
28005
|
+
blockData.macroRevision = 1;
|
|
28006
|
+
}
|
|
27912
28007
|
if (info) {
|
|
27913
28008
|
info.blockIdMap.set(data2.id, blockData.id);
|
|
27914
28009
|
childContainerIdMap.forEach((newId, oldId) => info.containerIdMap.set(oldId, newId));
|
|
@@ -29899,6 +29994,56 @@ var __publicField = (obj, key, value) => {
|
|
|
29899
29994
|
});
|
|
29900
29995
|
return true;
|
|
29901
29996
|
}
|
|
29997
|
+
const editorHooks = /* @__PURE__ */ new WeakMap();
|
|
29998
|
+
function registerDocResourceHook(editor, hook) {
|
|
29999
|
+
if (editor.destroyed) {
|
|
30000
|
+
throw new Error("Cannot register a document resource hook on a destroyed editor");
|
|
30001
|
+
}
|
|
30002
|
+
const registration = { hook, collect: hook.collect, rewrite: hook.rewrite };
|
|
30003
|
+
let hooks = editorHooks.get(editor);
|
|
30004
|
+
if (!hooks) {
|
|
30005
|
+
hooks = /* @__PURE__ */ new Set();
|
|
30006
|
+
editorHooks.set(editor, hooks);
|
|
30007
|
+
}
|
|
30008
|
+
const registrations = hooks;
|
|
30009
|
+
registrations.add(registration);
|
|
30010
|
+
return () => {
|
|
30011
|
+
if (!registrations.delete(registration)) {
|
|
30012
|
+
return;
|
|
30013
|
+
}
|
|
30014
|
+
if (registrations.size === 0 && editorHooks.get(editor) === registrations) {
|
|
30015
|
+
editorHooks.delete(editor);
|
|
30016
|
+
}
|
|
30017
|
+
};
|
|
30018
|
+
}
|
|
30019
|
+
function collectDocResourceHooks(editor, doc2, resources) {
|
|
30020
|
+
const hooks = editorHooks.get(editor);
|
|
30021
|
+
if (!hooks) {
|
|
30022
|
+
return;
|
|
30023
|
+
}
|
|
30024
|
+
for (const registration of hooks) {
|
|
30025
|
+
const ids = registration.collect.call(registration.hook, doc2);
|
|
30026
|
+
for (const id of ids) {
|
|
30027
|
+
resources.add(id);
|
|
30028
|
+
}
|
|
30029
|
+
}
|
|
30030
|
+
}
|
|
30031
|
+
function rewriteDocResourceHooks(editor, doc2, resources) {
|
|
30032
|
+
const hooks = editorHooks.get(editor);
|
|
30033
|
+
if (!hooks) {
|
|
30034
|
+
return;
|
|
30035
|
+
}
|
|
30036
|
+
for (const registration of hooks) {
|
|
30037
|
+
registration.rewrite.call(registration.hook, doc2, resources);
|
|
30038
|
+
}
|
|
30039
|
+
}
|
|
30040
|
+
function clearDocResourceHooks(editor) {
|
|
30041
|
+
const hooks = editorHooks.get(editor);
|
|
30042
|
+
if (hooks) {
|
|
30043
|
+
hooks.clear();
|
|
30044
|
+
editorHooks.delete(editor);
|
|
30045
|
+
}
|
|
30046
|
+
}
|
|
29902
30047
|
function defaultGetResourceFromBlock(editor, doc2, block, resources) {
|
|
29903
30048
|
if (block.type === "embed") {
|
|
29904
30049
|
const embedData = block.embedData;
|
|
@@ -29973,6 +30118,7 @@ var __publicField = (obj, key, value) => {
|
|
|
29973
30118
|
defaultGetResourceFromBlock(editor, doc2, block, resources);
|
|
29974
30119
|
}
|
|
29975
30120
|
});
|
|
30121
|
+
collectDocResourceHooks(editor, doc2, resources);
|
|
29976
30122
|
return Array.from(resources);
|
|
29977
30123
|
}
|
|
29978
30124
|
function injectDocToHtmlFragment(htmlFragment, doc2) {
|
|
@@ -30345,6 +30491,7 @@ ${codeText}
|
|
|
30345
30491
|
defaultReplaceBlockResources(doc2, block, resources);
|
|
30346
30492
|
}
|
|
30347
30493
|
});
|
|
30494
|
+
rewriteDocResourceHooks(editor, doc2, resources);
|
|
30348
30495
|
}
|
|
30349
30496
|
async function addLocalResourcesToDoc(editor, resources) {
|
|
30350
30497
|
let localResources = resources.filter((res) => res.indexOf(":") === -1);
|
|
@@ -31045,10 +31192,38 @@ ${codeText}
|
|
|
31045
31192
|
constructor(editor, externalDoc, localEvents) {
|
|
31046
31193
|
super();
|
|
31047
31194
|
__publicField(this, "localEvents", []);
|
|
31195
|
+
__publicField(this, "unsubscribeMacroLocks");
|
|
31048
31196
|
this.editor = editor;
|
|
31049
31197
|
this.externalDoc = externalDoc;
|
|
31050
31198
|
this.externalDoc.registerCallback(this);
|
|
31051
31199
|
this.registerLocalEvents(localEvents);
|
|
31200
|
+
this.subscribeMacroLocks();
|
|
31201
|
+
}
|
|
31202
|
+
subscribeMacroLocks() {
|
|
31203
|
+
initializeWikiMacroLocks(this.editor);
|
|
31204
|
+
try {
|
|
31205
|
+
this.unsubscribeMacroLocks = this.externalDoc.onWikiMacroLocks((locks) => {
|
|
31206
|
+
updateWikiMacroLocks(this.editor, locks);
|
|
31207
|
+
this.editor.emit("wikiMacroLocksChanged", this.editor);
|
|
31208
|
+
});
|
|
31209
|
+
} catch (error2) {
|
|
31210
|
+
clearWikiMacroLocks(this.editor);
|
|
31211
|
+
if (!(error2 instanceof WikiMacroError) || error2.code !== "READ_ONLY")
|
|
31212
|
+
throw error2;
|
|
31213
|
+
}
|
|
31214
|
+
}
|
|
31215
|
+
requestWikiMacro(message) {
|
|
31216
|
+
if (this.editor.readonly && message.operation !== "locks" && message.operation !== "getEditResult" && message.operation !== "cancelEdit") {
|
|
31217
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY" }));
|
|
31218
|
+
}
|
|
31219
|
+
return this.externalDoc.requestWikiMacro(message);
|
|
31220
|
+
}
|
|
31221
|
+
onWikiMacroLocks(listener) {
|
|
31222
|
+
return this.externalDoc.onWikiMacroLocks(listener);
|
|
31223
|
+
}
|
|
31224
|
+
getDocumentVersion() {
|
|
31225
|
+
var _a, _b;
|
|
31226
|
+
return (_b = (_a = this.externalDoc).getDocumentVersion) == null ? void 0 : _b.call(_a);
|
|
31052
31227
|
}
|
|
31053
31228
|
beginBatchUpdate() {
|
|
31054
31229
|
return this.externalDoc.beginBatchUpdate();
|
|
@@ -31087,6 +31262,8 @@ ${codeText}
|
|
|
31087
31262
|
}
|
|
31088
31263
|
localUpdateBlockText(containerId, blockIndex, actions2, options) {
|
|
31089
31264
|
const blockData = this.getBlockData(containerId, blockIndex);
|
|
31265
|
+
if (isWikiMacroBlockLocked(this.editor, blockData))
|
|
31266
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31090
31267
|
const oldText = blockData.text;
|
|
31091
31268
|
assert(logger$3l, oldText, `no text, ${containerId}, ${blockIndex}`);
|
|
31092
31269
|
const newRange = transformSelection(this.editor, blockData.id, actions2, true);
|
|
@@ -31098,6 +31275,10 @@ ${codeText}
|
|
|
31098
31275
|
}
|
|
31099
31276
|
localUpdateBlockData(containerId, blockIndex, delta, newRange, options) {
|
|
31100
31277
|
const block = this.editor.getBlockByIndex(containerId, blockIndex);
|
|
31278
|
+
const blockedByMacroLease = isWikiMacroBlockLocked(this.editor, this.getBlockData(containerId, blockIndex));
|
|
31279
|
+
if (blockedByMacroLease && (delta.delete.some((key) => key !== "comments") || Object.keys(delta.insert).some((key) => key !== "comments"))) {
|
|
31280
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31281
|
+
}
|
|
31101
31282
|
if (!this.editor.isBlockWritable(block)) {
|
|
31102
31283
|
const deletedKeys = Array.from(delta.delete).filter((key) => key !== "comments");
|
|
31103
31284
|
const insertedKeys = Object.keys(delta.insert).filter((key) => key !== "comments");
|
|
@@ -31114,6 +31295,8 @@ ${codeText}
|
|
|
31114
31295
|
}
|
|
31115
31296
|
localInsertBlock(containerId, blockIndex, data2, newRange, options) {
|
|
31116
31297
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31298
|
+
if (isWikiMacroBlockLocked(this.editor, data2))
|
|
31299
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31117
31300
|
this.localEvents.forEach((event) => event.onBeforeInsertBlock(containerId, blockIndex, data2, newRange));
|
|
31118
31301
|
const ret = this.externalDoc.localInsertBlock(containerId, blockIndex, data2, newRange);
|
|
31119
31302
|
if (!(options == null ? void 0 : options.noFocus)) {
|
|
@@ -31132,6 +31315,9 @@ ${codeText}
|
|
|
31132
31315
|
}
|
|
31133
31316
|
localDeleteChildContainers(containerIds) {
|
|
31134
31317
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31318
|
+
if (containerIds.some((containerId) => this.getContainerBlocks(containerId).some((block) => isWikiMacroBlockLocked(this.editor, block)))) {
|
|
31319
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31320
|
+
}
|
|
31135
31321
|
containerIds.forEach((containerId) => {
|
|
31136
31322
|
const blocks = cloneDeep__default.default(this.getContainerBlocks(containerId));
|
|
31137
31323
|
this.localEvents.forEach((event) => event.onBeforeDeleteChildContainer(containerId, blocks));
|
|
@@ -31140,6 +31326,9 @@ ${codeText}
|
|
|
31140
31326
|
}
|
|
31141
31327
|
localInsertChildContainers(containers) {
|
|
31142
31328
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31329
|
+
if (containers.some((container) => container.blocks.some((block) => isWikiMacroBlockLocked(this.editor, block)))) {
|
|
31330
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31331
|
+
}
|
|
31143
31332
|
const data2 = cloneDeep__default.default(containers);
|
|
31144
31333
|
data2.forEach((item) => {
|
|
31145
31334
|
this.localEvents.forEach((event) => event.onBeforeInsertChildContainer(item.containerId, item.blocks));
|
|
@@ -31248,6 +31437,11 @@ ${codeText}
|
|
|
31248
31437
|
(_b = (_a = this.externalDoc).triggerReAuth) == null ? void 0 : _b.call(_a, auto);
|
|
31249
31438
|
}
|
|
31250
31439
|
destroy() {
|
|
31440
|
+
var _a;
|
|
31441
|
+
this.editor.undoManager.destroy();
|
|
31442
|
+
(_a = this.unsubscribeMacroLocks) == null ? void 0 : _a.call(this);
|
|
31443
|
+
this.unsubscribeMacroLocks = void 0;
|
|
31444
|
+
clearWikiMacroLocks(this.editor);
|
|
31251
31445
|
this.externalDoc.destroy();
|
|
31252
31446
|
this.clearCallbacks();
|
|
31253
31447
|
}
|
|
@@ -31256,24 +31450,17 @@ ${codeText}
|
|
|
31256
31450
|
return (_c = (_b = (_a = this.externalDoc).getServerMeta) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
31257
31451
|
}
|
|
31258
31452
|
reset(doc2) {
|
|
31453
|
+
var _a;
|
|
31259
31454
|
logger$3l.log("reset doc");
|
|
31455
|
+
(_a = this.unsubscribeMacroLocks) == null ? void 0 : _a.call(this);
|
|
31456
|
+
clearWikiMacroLocks(this.editor);
|
|
31260
31457
|
this.externalDoc = doc2;
|
|
31261
31458
|
this.externalDoc.registerCallback(this);
|
|
31459
|
+
initializeWikiMacroLocks(this.editor);
|
|
31262
31460
|
this.editor.reload();
|
|
31461
|
+
this.subscribeMacroLocks();
|
|
31263
31462
|
}
|
|
31264
31463
|
}
|
|
31265
|
-
function addActions(actions2, action) {
|
|
31266
|
-
if (actions2.length === 0) {
|
|
31267
|
-
actions2.push(action);
|
|
31268
|
-
return;
|
|
31269
|
-
}
|
|
31270
|
-
const last = actions2[actions2.length - 1];
|
|
31271
|
-
if (!last.combinable(action)) {
|
|
31272
|
-
actions2.push(action);
|
|
31273
|
-
return;
|
|
31274
|
-
}
|
|
31275
|
-
last.combine(action);
|
|
31276
|
-
}
|
|
31277
31464
|
const logger$3k = getLogger("undo-action");
|
|
31278
31465
|
class Action {
|
|
31279
31466
|
constructor(editor, containerId, afterRange, batchActionId) {
|
|
@@ -31337,6 +31524,38 @@ ${codeText}
|
|
|
31337
31524
|
return true;
|
|
31338
31525
|
}
|
|
31339
31526
|
}
|
|
31527
|
+
class MacroEditAction extends Action {
|
|
31528
|
+
constructor(editor, options) {
|
|
31529
|
+
super(editor, "", editor.selection.range.toDocRange());
|
|
31530
|
+
__publicField(this, "options");
|
|
31531
|
+
this.options = options;
|
|
31532
|
+
}
|
|
31533
|
+
apply(direction) {
|
|
31534
|
+
if (!this.options) {
|
|
31535
|
+
return Promise.reject(new WikiMacroError({ code: "SESSION_EXPIRED", message: "Macro history action disposed" }));
|
|
31536
|
+
}
|
|
31537
|
+
return this.options[direction]();
|
|
31538
|
+
}
|
|
31539
|
+
reportError(error2) {
|
|
31540
|
+
var _a, _b;
|
|
31541
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, error2);
|
|
31542
|
+
}
|
|
31543
|
+
dispose() {
|
|
31544
|
+
this.options = null;
|
|
31545
|
+
}
|
|
31546
|
+
}
|
|
31547
|
+
function addActions(actions2, action) {
|
|
31548
|
+
if (actions2.length === 0) {
|
|
31549
|
+
actions2.push(action);
|
|
31550
|
+
return;
|
|
31551
|
+
}
|
|
31552
|
+
const last = actions2[actions2.length - 1];
|
|
31553
|
+
if (!last.combinable(action)) {
|
|
31554
|
+
actions2.push(action);
|
|
31555
|
+
return;
|
|
31556
|
+
}
|
|
31557
|
+
last.combine(action);
|
|
31558
|
+
}
|
|
31340
31559
|
const logger$3j = getLogger("block-action");
|
|
31341
31560
|
class BlockAction extends Action {
|
|
31342
31561
|
constructor(editor, containerId, blockIndex, data2, afterRange) {
|
|
@@ -31394,10 +31613,32 @@ ${codeText}
|
|
|
31394
31613
|
}
|
|
31395
31614
|
class DeleteBlockAction$1 extends BlockAction {
|
|
31396
31615
|
undo(editor) {
|
|
31397
|
-
|
|
31616
|
+
if (this.blockData.type !== "embed" || this.blockData.embedType !== "ones-open-wiki-macro") {
|
|
31617
|
+
return this.insertBlock(editor, this.beforeRange);
|
|
31618
|
+
}
|
|
31619
|
+
const revision = this.blockData.macroRevision;
|
|
31620
|
+
this.blockData.macroRevision = revision + 1;
|
|
31621
|
+
let inserted = false;
|
|
31622
|
+
try {
|
|
31623
|
+
inserted = this.insertBlock(editor, this.beforeRange);
|
|
31624
|
+
return inserted;
|
|
31625
|
+
} finally {
|
|
31626
|
+
if (!inserted)
|
|
31627
|
+
this.blockData.macroRevision = revision;
|
|
31628
|
+
}
|
|
31398
31629
|
}
|
|
31399
31630
|
redo(editor) {
|
|
31400
|
-
|
|
31631
|
+
if (this.blockData.type !== "embed" || this.blockData.embedType !== "ones-open-wiki-macro") {
|
|
31632
|
+
return this.deleteBlock(editor, this.afterRange);
|
|
31633
|
+
}
|
|
31634
|
+
const block = editor.findBlockById(this.blockData.id);
|
|
31635
|
+
if (!block)
|
|
31636
|
+
return false;
|
|
31637
|
+
const deletedSnapshot = cloneDeep__default.default(editor.getBlockData(block));
|
|
31638
|
+
const deleted = this.deleteBlock(editor, this.afterRange);
|
|
31639
|
+
if (deleted)
|
|
31640
|
+
this.blockData = deletedSnapshot;
|
|
31641
|
+
return deleted;
|
|
31401
31642
|
}
|
|
31402
31643
|
}
|
|
31403
31644
|
class GroupAction extends Action {
|
|
@@ -31674,6 +31915,11 @@ ${codeText}
|
|
|
31674
31915
|
__publicField(this, "currentGroup", null);
|
|
31675
31916
|
__publicField(this, "groupCounter", 0);
|
|
31676
31917
|
__publicField(this, "undoRedoing", false);
|
|
31918
|
+
__publicField(this, "macroSessions", /* @__PURE__ */ new Set());
|
|
31919
|
+
__publicField(this, "macroActionIds", /* @__PURE__ */ new Set());
|
|
31920
|
+
__publicField(this, "pendingMacroAction", null);
|
|
31921
|
+
__publicField(this, "macroGeneration", 0);
|
|
31922
|
+
__publicField(this, "destroyed", false);
|
|
31677
31923
|
__publicField(this, "handleSelectionChange", (editor) => {
|
|
31678
31924
|
if (this.currentGroup) {
|
|
31679
31925
|
this.currentGroup.setAfterRange(editor.selection.range.toDocRange());
|
|
@@ -31690,13 +31936,104 @@ ${codeText}
|
|
|
31690
31936
|
this.undoCursor = -1;
|
|
31691
31937
|
this.editor.addListener("selectionChanged", this.handleSelectionChange);
|
|
31692
31938
|
}
|
|
31939
|
+
registerMacroEditAction(options) {
|
|
31940
|
+
if (this.destroyed) {
|
|
31941
|
+
throw new WikiMacroError({ code: "SESSION_EXPIRED", message: "Editor destroyed" });
|
|
31942
|
+
}
|
|
31943
|
+
if (this.macroActionIds.has(options.actionId))
|
|
31944
|
+
return;
|
|
31945
|
+
this.prepareSaveUndoState();
|
|
31946
|
+
this.macroActionIds.add(options.actionId);
|
|
31947
|
+
const action = new MacroEditAction(this.editor, options);
|
|
31948
|
+
this.actions.push(action);
|
|
31949
|
+
this.editor.input.handleChanged(action);
|
|
31950
|
+
}
|
|
31951
|
+
setMacroEditSessionActive(sessionId, active) {
|
|
31952
|
+
if (this.destroyed)
|
|
31953
|
+
return;
|
|
31954
|
+
setWikiMacroLockSession(this.editor, sessionId, active);
|
|
31955
|
+
if (active) {
|
|
31956
|
+
this.macroSessions.add(sessionId);
|
|
31957
|
+
} else {
|
|
31958
|
+
this.macroSessions.delete(sessionId);
|
|
31959
|
+
}
|
|
31960
|
+
}
|
|
31961
|
+
destroy() {
|
|
31962
|
+
this.destroyed = true;
|
|
31963
|
+
this.reset();
|
|
31964
|
+
this.macroSessions.clear();
|
|
31965
|
+
this.editor.removeListener("selectionChanged", this.handleSelectionChange);
|
|
31966
|
+
}
|
|
31967
|
+
applyMacroAction(action, direction) {
|
|
31968
|
+
const generation = this.macroGeneration;
|
|
31969
|
+
const cursor = this.undoCursor;
|
|
31970
|
+
const historyLength = this.actions.length;
|
|
31971
|
+
this.pendingMacroAction = action;
|
|
31972
|
+
Promise.resolve().then(() => action.apply(direction)).then(() => {
|
|
31973
|
+
if (generation !== this.macroGeneration || this.destroyed)
|
|
31974
|
+
return;
|
|
31975
|
+
const index2 = this.actions.indexOf(action);
|
|
31976
|
+
if (direction === "undo") {
|
|
31977
|
+
if (index2 < 0)
|
|
31978
|
+
return;
|
|
31979
|
+
if (this.undoCursor === cursor && this.actions.length === historyLength) {
|
|
31980
|
+
this.undoCursor = index2;
|
|
31981
|
+
} else {
|
|
31982
|
+
this.actions.splice(index2, 1);
|
|
31983
|
+
this.actions.push(action);
|
|
31984
|
+
this.undoCursor = this.actions.length - 1;
|
|
31985
|
+
}
|
|
31986
|
+
} else if (index2 >= 0 && this.undoCursor === cursor && this.actions.length === historyLength) {
|
|
31987
|
+
this.undoCursor = index2 + 1;
|
|
31988
|
+
} else {
|
|
31989
|
+
if (index2 >= 0)
|
|
31990
|
+
this.actions.splice(index2, 1);
|
|
31991
|
+
this.actions.push(action);
|
|
31992
|
+
this.undoCursor = -1;
|
|
31993
|
+
}
|
|
31994
|
+
try {
|
|
31995
|
+
this.editor.input.handleChanged(action);
|
|
31996
|
+
} catch (error2) {
|
|
31997
|
+
logger$3f.error("Macro history change observer failed");
|
|
31998
|
+
}
|
|
31999
|
+
}).catch((error2) => {
|
|
32000
|
+
if (generation !== this.macroGeneration || this.destroyed)
|
|
32001
|
+
return;
|
|
32002
|
+
const failure = error2 instanceof Error ? error2 : new Error("Macro history action failed");
|
|
32003
|
+
try {
|
|
32004
|
+
action.reportError(failure);
|
|
32005
|
+
} catch (callbackError) {
|
|
32006
|
+
logger$3f.error("Macro history error callback failed");
|
|
32007
|
+
}
|
|
32008
|
+
}).finally(() => {
|
|
32009
|
+
if (generation === this.macroGeneration) {
|
|
32010
|
+
this.pendingMacroAction = null;
|
|
32011
|
+
if (!this.actions.includes(action))
|
|
32012
|
+
action.dispose();
|
|
32013
|
+
}
|
|
32014
|
+
});
|
|
32015
|
+
return true;
|
|
32016
|
+
}
|
|
31693
32017
|
reset() {
|
|
32018
|
+
var _a;
|
|
32019
|
+
this.macroGeneration += 1;
|
|
32020
|
+
(_a = this.pendingMacroAction) == null ? void 0 : _a.dispose();
|
|
32021
|
+
this.pendingMacroAction = null;
|
|
32022
|
+
this.actions.forEach((action) => {
|
|
32023
|
+
if (action instanceof MacroEditAction)
|
|
32024
|
+
action.dispose();
|
|
32025
|
+
});
|
|
32026
|
+
this.macroActionIds.clear();
|
|
31694
32027
|
this.actions = [];
|
|
31695
32028
|
this.undoCursor = -1;
|
|
31696
32029
|
}
|
|
31697
32030
|
prepareSaveUndoState() {
|
|
31698
32031
|
if (this.undoCursor !== -1) {
|
|
31699
|
-
this.actions.splice(this.undoCursor);
|
|
32032
|
+
const removed = this.actions.splice(this.undoCursor);
|
|
32033
|
+
removed.forEach((action) => {
|
|
32034
|
+
if (action instanceof MacroEditAction && action !== this.pendingMacroAction)
|
|
32035
|
+
action.dispose();
|
|
32036
|
+
});
|
|
31700
32037
|
this.undoCursor = -1;
|
|
31701
32038
|
}
|
|
31702
32039
|
}
|
|
@@ -31778,14 +32115,22 @@ ${codeText}
|
|
|
31778
32115
|
}
|
|
31779
32116
|
}
|
|
31780
32117
|
undo() {
|
|
32118
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32119
|
+
return false;
|
|
32120
|
+
const candidate = this.actions[(this.undoCursor === -1 ? this.actions.length : this.undoCursor) - 1];
|
|
32121
|
+
if (candidate instanceof MacroEditAction)
|
|
32122
|
+
return this.applyMacroAction(candidate, "undo");
|
|
31781
32123
|
if (this.undoCursor === -1) {
|
|
31782
32124
|
this.undoCursor = this.actions.length;
|
|
31783
32125
|
}
|
|
31784
32126
|
try {
|
|
31785
32127
|
this.undoRedoing = true;
|
|
31786
32128
|
while (this.undoCursor > 0) {
|
|
32129
|
+
const action = this.actions[this.undoCursor - 1];
|
|
32130
|
+
if (action instanceof MacroEditAction) {
|
|
32131
|
+
return this.applyMacroAction(action, "undo");
|
|
32132
|
+
}
|
|
31787
32133
|
this.undoCursor -= 1;
|
|
31788
|
-
const action = this.actions[this.undoCursor];
|
|
31789
32134
|
if (action.undo(this.editor)) {
|
|
31790
32135
|
try {
|
|
31791
32136
|
this.editor.selection.setRange(fromDocRange(this.editor, action.beforeRange));
|
|
@@ -31811,6 +32156,11 @@ ${codeText}
|
|
|
31811
32156
|
}
|
|
31812
32157
|
}
|
|
31813
32158
|
redo() {
|
|
32159
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32160
|
+
return false;
|
|
32161
|
+
const candidate = this.actions[this.undoCursor];
|
|
32162
|
+
if (candidate instanceof MacroEditAction)
|
|
32163
|
+
return this.applyMacroAction(candidate, "redo");
|
|
31814
32164
|
if (this.undoCursor === -1) {
|
|
31815
32165
|
this.undoCursor = this.actions.length;
|
|
31816
32166
|
}
|
|
@@ -31818,6 +32168,9 @@ ${codeText}
|
|
|
31818
32168
|
this.undoRedoing = true;
|
|
31819
32169
|
while (this.undoCursor < this.actions.length) {
|
|
31820
32170
|
const action = this.actions[this.undoCursor];
|
|
32171
|
+
if (action instanceof MacroEditAction) {
|
|
32172
|
+
return this.applyMacroAction(action, "redo");
|
|
32173
|
+
}
|
|
31821
32174
|
this.undoCursor += 1;
|
|
31822
32175
|
if (action.redo(this.editor)) {
|
|
31823
32176
|
try {
|
|
@@ -31846,6 +32199,8 @@ ${codeText}
|
|
|
31846
32199
|
}
|
|
31847
32200
|
}
|
|
31848
32201
|
canUndo() {
|
|
32202
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32203
|
+
return false;
|
|
31849
32204
|
if (this.actions.length === 0) {
|
|
31850
32205
|
return false;
|
|
31851
32206
|
}
|
|
@@ -31855,6 +32210,8 @@ ${codeText}
|
|
|
31855
32210
|
return true;
|
|
31856
32211
|
}
|
|
31857
32212
|
canRedo() {
|
|
32213
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32214
|
+
return false;
|
|
31858
32215
|
if (this.actions.length === 0) {
|
|
31859
32216
|
return false;
|
|
31860
32217
|
}
|
|
@@ -31880,6 +32237,10 @@ ${codeText}
|
|
|
31880
32237
|
if (lastAction === action) {
|
|
31881
32238
|
return true;
|
|
31882
32239
|
}
|
|
32240
|
+
if (this.pendingMacroAction || lastAction instanceof MacroEditAction) {
|
|
32241
|
+
this.undo();
|
|
32242
|
+
return false;
|
|
32243
|
+
}
|
|
31883
32244
|
if (!this.undo()) {
|
|
31884
32245
|
return false;
|
|
31885
32246
|
}
|
|
@@ -32586,9 +32947,21 @@ ${codeText}
|
|
|
32586
32947
|
createInsertion(blockContent, insertion) {
|
|
32587
32948
|
return this.editorInsertions.createInsertion(blockContent, insertion);
|
|
32588
32949
|
}
|
|
32950
|
+
addDocResourceHook(hook) {
|
|
32951
|
+
return registerDocResourceHook(this, hook);
|
|
32952
|
+
}
|
|
32953
|
+
registerMacroEditAction(options) {
|
|
32954
|
+
this.undoManager.registerMacroEditAction(options);
|
|
32955
|
+
}
|
|
32956
|
+
setMacroEditSessionActive(sessionId, active) {
|
|
32957
|
+
if (this.destroyed)
|
|
32958
|
+
return;
|
|
32959
|
+
this.undoManager.setMacroEditSessionActive(sessionId, active);
|
|
32960
|
+
}
|
|
32589
32961
|
destroy() {
|
|
32590
32962
|
logger$3b.debug("destroy editor");
|
|
32591
32963
|
this.emit("destroy", this);
|
|
32964
|
+
this.undoManager.destroy();
|
|
32592
32965
|
this.input.destroy();
|
|
32593
32966
|
this.rootContainerObject.destroy();
|
|
32594
32967
|
this.rootElement.remove();
|
|
@@ -32599,6 +32972,7 @@ ${codeText}
|
|
|
32599
32972
|
this.domEvents.destroy();
|
|
32600
32973
|
this.removeAllListeners();
|
|
32601
32974
|
this.inputHandlers.destroy();
|
|
32975
|
+
clearDocResourceHooks(this);
|
|
32602
32976
|
this._destroyed = true;
|
|
32603
32977
|
}
|
|
32604
32978
|
get destroyed() {
|
|
@@ -32613,7 +32987,15 @@ ${codeText}
|
|
|
32613
32987
|
isWritable() {
|
|
32614
32988
|
return editorIsWritable(this);
|
|
32615
32989
|
}
|
|
32616
|
-
isBlockWritable(block) {
|
|
32990
|
+
isBlockWritable(block, macroSessionId) {
|
|
32991
|
+
if (macroSessionId && this.readonly)
|
|
32992
|
+
return false;
|
|
32993
|
+
if (Array.isArray(block)) {
|
|
32994
|
+
if (block.some((item) => isWikiMacroElementLocked(this, item, macroSessionId)))
|
|
32995
|
+
return false;
|
|
32996
|
+
} else if (isWikiMacroElementLocked(this, block, macroSessionId)) {
|
|
32997
|
+
return false;
|
|
32998
|
+
}
|
|
32617
32999
|
return editorIsBlockWritable(this, block);
|
|
32618
33000
|
}
|
|
32619
33001
|
getChildContainerData(childContainerId) {
|
|
@@ -32962,6 +33344,7 @@ ${codeText}
|
|
|
32962
33344
|
super();
|
|
32963
33345
|
__publicField(this, "doc");
|
|
32964
33346
|
__publicField(this, "serviceUrl");
|
|
33347
|
+
__publicField(this, "documentVersion");
|
|
32965
33348
|
if (doc2) {
|
|
32966
33349
|
this.doc = doc2;
|
|
32967
33350
|
} else {
|
|
@@ -32976,6 +33359,16 @@ ${codeText}
|
|
|
32976
33359
|
};
|
|
32977
33360
|
}
|
|
32978
33361
|
this.serviceUrl = (options == null ? void 0 : options.serverUrl) || "";
|
|
33362
|
+
this.documentVersion = options == null ? void 0 : options.documentVersion;
|
|
33363
|
+
}
|
|
33364
|
+
requestWikiMacro(message) {
|
|
33365
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY", message: "Local and history documents cannot edit Wiki macros" }));
|
|
33366
|
+
}
|
|
33367
|
+
onWikiMacroLocks(listener) {
|
|
33368
|
+
throw new WikiMacroError({ code: "READ_ONLY", message: "Local and history documents have no macro lock channel" });
|
|
33369
|
+
}
|
|
33370
|
+
getDocumentVersion() {
|
|
33371
|
+
return this.documentVersion;
|
|
32979
33372
|
}
|
|
32980
33373
|
beginBatchUpdate() {
|
|
32981
33374
|
return 0;
|
|
@@ -33114,8 +33507,9 @@ ${codeText}
|
|
|
33114
33507
|
getRemoteUsers() {
|
|
33115
33508
|
return new RemoteUsers();
|
|
33116
33509
|
}
|
|
33117
|
-
setDoc(doc2) {
|
|
33510
|
+
setDoc(doc2, documentVersion) {
|
|
33118
33511
|
this.doc = cloneDeep__default.default(doc2);
|
|
33512
|
+
this.documentVersion = documentVersion;
|
|
33119
33513
|
this.callbacks.forEach((c) => {
|
|
33120
33514
|
var _a;
|
|
33121
33515
|
return (_a = c.onRequestReload) == null ? void 0 : _a.call(c, "change doc");
|
|
@@ -38659,6 +39053,11 @@ ${codeText}
|
|
|
38659
39053
|
__publicField(this, "connectionStatus", null);
|
|
38660
39054
|
__publicField(this, "reauthing", false);
|
|
38661
39055
|
__publicField(this, "ready", false);
|
|
39056
|
+
__publicField(this, "macroRequests", /* @__PURE__ */ new Map());
|
|
39057
|
+
__publicField(this, "macroLocksListeners", /* @__PURE__ */ new Set());
|
|
39058
|
+
__publicField(this, "macroLocks", []);
|
|
39059
|
+
__publicField(this, "macroLocksKnown", false);
|
|
39060
|
+
__publicField(this, "macroLocksLoading", false);
|
|
38662
39061
|
__publicField(this, "pingOptions", { interval: 5e4, timeout: 15e4 });
|
|
38663
39062
|
__publicField(this, "handleAuthError", (err) => {
|
|
38664
39063
|
if (!this.renewTokenFunc) {
|
|
@@ -38706,6 +39105,7 @@ ${codeText}
|
|
|
38706
39105
|
});
|
|
38707
39106
|
__publicField(this, "handleDisconnected", (reason) => {
|
|
38708
39107
|
this.connectionDisconnected = true;
|
|
39108
|
+
this.clearWikiMacroRequests("Document disconnected; query the original request before retrying");
|
|
38709
39109
|
this.emit("disconnected", reason);
|
|
38710
39110
|
});
|
|
38711
39111
|
__publicField(this, "handleVisibilityChange", () => {
|
|
@@ -38723,6 +39123,111 @@ ${codeText}
|
|
|
38723
39123
|
this.renewTokenFunc = renewTokenFunc;
|
|
38724
39124
|
this.authMessage = authMessage;
|
|
38725
39125
|
}
|
|
39126
|
+
loadWikiMacroLocks() {
|
|
39127
|
+
if (this.closed || this.macroLocksLoading || this.macroLocksListeners.size === 0)
|
|
39128
|
+
return;
|
|
39129
|
+
this.macroLocksLoading = true;
|
|
39130
|
+
this.requestWikiMacro({ operation: "locks" }).then((result) => {
|
|
39131
|
+
if (this.closed)
|
|
39132
|
+
return;
|
|
39133
|
+
if (!Array.isArray(result.locks)) {
|
|
39134
|
+
throw new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Macro lock snapshot unavailable" });
|
|
39135
|
+
}
|
|
39136
|
+
this.notifyWikiMacroLocks(result.locks);
|
|
39137
|
+
}).catch(() => {
|
|
39138
|
+
if (!this.closed)
|
|
39139
|
+
logger$31.warn("Macro lock snapshot unavailable");
|
|
39140
|
+
}).finally(() => {
|
|
39141
|
+
this.macroLocksLoading = false;
|
|
39142
|
+
});
|
|
39143
|
+
}
|
|
39144
|
+
requestWikiMacro(message) {
|
|
39145
|
+
var _a;
|
|
39146
|
+
const requestId = genId();
|
|
39147
|
+
if (this.closed || ((_a = this.connection) == null ? void 0 : _a.state) !== "connected" || this.reauthing || this.connectionDisconnected) {
|
|
39148
|
+
return Promise.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document connection unavailable" }, requestId));
|
|
39149
|
+
}
|
|
39150
|
+
return new Promise((resolve, reject) => {
|
|
39151
|
+
const timeout = window.setTimeout(() => {
|
|
39152
|
+
this.macroRequests.delete(requestId);
|
|
39153
|
+
reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Macro result unknown; query the original request" }, requestId));
|
|
39154
|
+
}, 6e4);
|
|
39155
|
+
this.macroRequests.set(requestId, { resolve, reject, timeout });
|
|
39156
|
+
try {
|
|
39157
|
+
this.connection.send({
|
|
39158
|
+
a: "wikiMacro",
|
|
39159
|
+
requestId,
|
|
39160
|
+
operation: message.operation,
|
|
39161
|
+
blockId: message.blockId,
|
|
39162
|
+
sessionId: message.sessionId,
|
|
39163
|
+
fence: message.fence,
|
|
39164
|
+
expectedRevision: message.expectedRevision,
|
|
39165
|
+
content: message.content,
|
|
39166
|
+
actionId: message.actionId,
|
|
39167
|
+
direction: message.direction,
|
|
39168
|
+
targetRequestId: message.targetRequestId
|
|
39169
|
+
});
|
|
39170
|
+
} catch (error2) {
|
|
39171
|
+
this.macroRequests.delete(requestId);
|
|
39172
|
+
window.clearTimeout(timeout);
|
|
39173
|
+
reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Unable to send macro request" }, requestId));
|
|
39174
|
+
}
|
|
39175
|
+
});
|
|
39176
|
+
}
|
|
39177
|
+
onWikiMacroLocks(listener) {
|
|
39178
|
+
if (this.closed) {
|
|
39179
|
+
throw new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document connection closed" });
|
|
39180
|
+
}
|
|
39181
|
+
this.macroLocksListeners.add(listener);
|
|
39182
|
+
try {
|
|
39183
|
+
if (this.macroLocksKnown)
|
|
39184
|
+
listener(this.macroLocks || []);
|
|
39185
|
+
} catch (error2) {
|
|
39186
|
+
this.macroLocksListeners.delete(listener);
|
|
39187
|
+
throw error2;
|
|
39188
|
+
}
|
|
39189
|
+
this.loadWikiMacroLocks();
|
|
39190
|
+
return () => {
|
|
39191
|
+
this.macroLocksListeners.delete(listener);
|
|
39192
|
+
};
|
|
39193
|
+
}
|
|
39194
|
+
handleWikiMacroReply(message) {
|
|
39195
|
+
if (message.operation === "locks" && Array.isArray(message.locks)) {
|
|
39196
|
+
this.notifyWikiMacroLocks(message.locks);
|
|
39197
|
+
}
|
|
39198
|
+
if (!message.requestId)
|
|
39199
|
+
return;
|
|
39200
|
+
const pending = this.macroRequests.get(message.requestId);
|
|
39201
|
+
if (!pending)
|
|
39202
|
+
return;
|
|
39203
|
+
this.macroRequests.delete(message.requestId);
|
|
39204
|
+
window.clearTimeout(pending.timeout);
|
|
39205
|
+
if (message.error) {
|
|
39206
|
+
pending.reject(new WikiMacroError(message.error, message.requestId));
|
|
39207
|
+
} else if (message.result) {
|
|
39208
|
+
pending.resolve({ ...message.result, requestId: message.requestId });
|
|
39209
|
+
} else {
|
|
39210
|
+
pending.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Invalid macro acknowledgement" }, message.requestId));
|
|
39211
|
+
}
|
|
39212
|
+
}
|
|
39213
|
+
clearWikiMacroRequests(message) {
|
|
39214
|
+
this.macroRequests.forEach((pending, requestId) => {
|
|
39215
|
+
window.clearTimeout(pending.timeout);
|
|
39216
|
+
pending.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message }, requestId));
|
|
39217
|
+
});
|
|
39218
|
+
this.macroRequests.clear();
|
|
39219
|
+
}
|
|
39220
|
+
notifyWikiMacroLocks(locks) {
|
|
39221
|
+
this.macroLocks = locks;
|
|
39222
|
+
this.macroLocksKnown = true;
|
|
39223
|
+
this.macroLocksListeners.forEach((listener) => {
|
|
39224
|
+
try {
|
|
39225
|
+
listener(locks);
|
|
39226
|
+
} catch (error2) {
|
|
39227
|
+
logger$31.error("Wiki macro lock listener failed");
|
|
39228
|
+
}
|
|
39229
|
+
});
|
|
39230
|
+
}
|
|
38726
39231
|
getBaseURL() {
|
|
38727
39232
|
const parsedURL = new URL(this.url);
|
|
38728
39233
|
const protocol = parsedURL.protocol === "wss:" ? "https:" : "http:";
|
|
@@ -38817,6 +39322,10 @@ ${codeText}
|
|
|
38817
39322
|
const msg = message;
|
|
38818
39323
|
if (this.connection)
|
|
38819
39324
|
this.connection.lastReceiveTime = Date.now();
|
|
39325
|
+
if (msg.a === "wikiMacro") {
|
|
39326
|
+
this.handleWikiMacroReply(msg);
|
|
39327
|
+
return;
|
|
39328
|
+
}
|
|
38820
39329
|
if ("err" in msg || msg.a === "pong") {
|
|
38821
39330
|
this.handleMessage(msg);
|
|
38822
39331
|
} else {
|
|
@@ -38833,6 +39342,7 @@ ${codeText}
|
|
|
38833
39342
|
this.emit("ready");
|
|
38834
39343
|
this.ready = true;
|
|
38835
39344
|
this.connectionDisconnected = false;
|
|
39345
|
+
this.loadWikiMacroLocks();
|
|
38836
39346
|
}
|
|
38837
39347
|
}
|
|
38838
39348
|
try {
|
|
@@ -38910,6 +39420,10 @@ ${codeText}
|
|
|
38910
39420
|
end(logout) {
|
|
38911
39421
|
var _a, _b, _c, _d, _e;
|
|
38912
39422
|
this.closed = true;
|
|
39423
|
+
this.clearWikiMacroRequests("Document connection closed");
|
|
39424
|
+
this.macroLocksListeners.clear();
|
|
39425
|
+
this.macroLocks = [];
|
|
39426
|
+
this.macroLocksKnown = false;
|
|
38913
39427
|
this.renewTokenFunc = void 0;
|
|
38914
39428
|
this.removeAllListeners();
|
|
38915
39429
|
(_a = this.autoRenewToken) == null ? void 0 : _a.destroy();
|
|
@@ -39204,10 +39718,16 @@ ${codeText}
|
|
|
39204
39718
|
return versions;
|
|
39205
39719
|
}
|
|
39206
39720
|
async getVersion(ver) {
|
|
39721
|
+
return (await this.getVersionSnapshot(ver)).doc;
|
|
39722
|
+
}
|
|
39723
|
+
async getVersionSnapshot(ver) {
|
|
39207
39724
|
const server = this.apiServer();
|
|
39208
39725
|
const api = `${server}/versions/${ver}`;
|
|
39209
39726
|
const ret = await this.request(api);
|
|
39210
|
-
return
|
|
39727
|
+
return {
|
|
39728
|
+
doc: JSON.parse(ret.data.data),
|
|
39729
|
+
documentVersion: typeof ret.data.documentVersion === "number" ? ret.data.documentVersion : void 0
|
|
39730
|
+
};
|
|
39211
39731
|
}
|
|
39212
39732
|
async getLatestVersion() {
|
|
39213
39733
|
const server = this.apiServer();
|
|
@@ -40218,6 +40738,21 @@ ${codeText}
|
|
|
40218
40738
|
this.editStatus = new EditStatus(options);
|
|
40219
40739
|
this.client.connection.addListener("opReceived", this.handleOpReceived);
|
|
40220
40740
|
}
|
|
40741
|
+
requestWikiMacro(message) {
|
|
40742
|
+
if (this.destroyed) {
|
|
40743
|
+
return Promise.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document destroyed" }));
|
|
40744
|
+
}
|
|
40745
|
+
if (this.getUser().permission !== "w" && message.operation !== "locks" && message.operation !== "getEditResult" && message.operation !== "cancelEdit") {
|
|
40746
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY" }));
|
|
40747
|
+
}
|
|
40748
|
+
return this.client.connection.requestWikiMacro(message);
|
|
40749
|
+
}
|
|
40750
|
+
onWikiMacroLocks(listener) {
|
|
40751
|
+
return this.client.connection.onWikiMacroLocks(listener);
|
|
40752
|
+
}
|
|
40753
|
+
getDocumentVersion() {
|
|
40754
|
+
return typeof this.doc.version === "number" ? this.doc.version : void 0;
|
|
40755
|
+
}
|
|
40221
40756
|
beginBatchUpdate() {
|
|
40222
40757
|
this.doc.preventCompose = false;
|
|
40223
40758
|
this.batching++;
|
|
@@ -40635,6 +41170,10 @@ ${codeText}
|
|
|
40635
41170
|
const data2 = await this.client.getVersion(ver);
|
|
40636
41171
|
return editorDoc2DocObject(data2);
|
|
40637
41172
|
}
|
|
41173
|
+
async getVersionSnapshot(ver) {
|
|
41174
|
+
const snapshot2 = await this.client.getVersionSnapshot(ver);
|
|
41175
|
+
return { doc: editorDoc2DocObject(snapshot2.doc), documentVersion: snapshot2.documentVersion };
|
|
41176
|
+
}
|
|
40638
41177
|
async getLatestVersion() {
|
|
40639
41178
|
const doc2 = await this.client.getLatestVersion();
|
|
40640
41179
|
return editorDoc2DocObject(doc2);
|
|
@@ -40981,7 +41520,8 @@ ${codeText}
|
|
|
40981
41520
|
class ShareDBLocalDoc extends LocalDoc {
|
|
40982
41521
|
constructor(docObject, _options) {
|
|
40983
41522
|
super(docObject, {
|
|
40984
|
-
serverUrl: _options.serverUrl
|
|
41523
|
+
serverUrl: _options.serverUrl,
|
|
41524
|
+
documentVersion: _options.documentVersion
|
|
40985
41525
|
});
|
|
40986
41526
|
__publicField(this, "_client");
|
|
40987
41527
|
this._options = _options;
|
|
@@ -41088,10 +41628,16 @@ ${codeText}
|
|
|
41088
41628
|
return versions;
|
|
41089
41629
|
}
|
|
41090
41630
|
async getVersion(ver) {
|
|
41631
|
+
return (await this.getVersionSnapshot(ver)).doc;
|
|
41632
|
+
}
|
|
41633
|
+
async getVersionSnapshot(ver) {
|
|
41091
41634
|
const server = this.apiServer();
|
|
41092
41635
|
const api = `${server}/versions/${ver}`;
|
|
41093
41636
|
const ret = await this.request(api);
|
|
41094
|
-
return
|
|
41637
|
+
return {
|
|
41638
|
+
doc: JSON.parse(ret.data.data),
|
|
41639
|
+
documentVersion: typeof ret.data.documentVersion === "number" ? ret.data.documentVersion : void 0
|
|
41640
|
+
};
|
|
41095
41641
|
}
|
|
41096
41642
|
async getLatestVersion() {
|
|
41097
41643
|
const server = this.apiServer();
|
|
@@ -41215,6 +41761,10 @@ ${codeText}
|
|
|
41215
41761
|
const data2 = await this.client.getVersion(ver);
|
|
41216
41762
|
return editorDoc2DocObject(data2);
|
|
41217
41763
|
}
|
|
41764
|
+
async getVersionSnapshot(ver) {
|
|
41765
|
+
const snapshot2 = await this.client.getVersionSnapshot(ver);
|
|
41766
|
+
return { doc: editorDoc2DocObject(snapshot2.doc), documentVersion: snapshot2.documentVersion };
|
|
41767
|
+
}
|
|
41218
41768
|
async getLatestVersion() {
|
|
41219
41769
|
const doc2 = await this.client.getLatestVersion();
|
|
41220
41770
|
return editorDoc2DocObject(doc2);
|
|
@@ -63804,6 +64354,8 @@ $$${mathData.mathjaxText}$$
|
|
|
63804
64354
|
const blockId = item.data;
|
|
63805
64355
|
try {
|
|
63806
64356
|
const block = editor.getBlockById(blockId);
|
|
64357
|
+
if ((item.id === "delete" || item.id === "cut") && isWikiMacroElementLocked(editor, block))
|
|
64358
|
+
return;
|
|
63807
64359
|
if (item.id === "delete") {
|
|
63808
64360
|
this.deleteBlock(editor, block);
|
|
63809
64361
|
return;
|
|
@@ -63823,6 +64375,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63823
64375
|
commands(editor, blockElement) {
|
|
63824
64376
|
const locked = isBlockLocked(editor, blockElement);
|
|
63825
64377
|
const lockedBySelf = locked && isBlockLockedBySelf(editor, blockElement);
|
|
64378
|
+
const macroLeased = isWikiMacroElementLocked(editor, blockElement);
|
|
63826
64379
|
const data2 = getBlockId(blockElement);
|
|
63827
64380
|
const isEnvSecure = window.isSecureContext;
|
|
63828
64381
|
const isBlockExclusive = isExclusiveBlock(blockElement);
|
|
@@ -63844,7 +64397,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63844
64397
|
data: data2,
|
|
63845
64398
|
icon: CutIcon,
|
|
63846
64399
|
order: 20,
|
|
63847
|
-
states: locked && !lockedBySelf || !isEnvSecure || isBlockExclusive ? ["disabled"] : [],
|
|
64400
|
+
states: macroLeased || locked && !lockedBySelf || !isEnvSecure || isBlockExclusive ? ["disabled"] : [],
|
|
63848
64401
|
disableReason: !isEnvSecure ? i18n$1.t("copyCutProperty.unsafeEnvTips", {
|
|
63849
64402
|
shortCut: shortcutToDisplayText("CtrlOrCmd+X"),
|
|
63850
64403
|
operation: i18n$1.t("copyCutProperty.cut")
|
|
@@ -63856,7 +64409,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63856
64409
|
data: data2,
|
|
63857
64410
|
icon: DeleteIcon,
|
|
63858
64411
|
order: 30,
|
|
63859
|
-
states: locked && !lockedBySelf || isBlockExclusive ? ["disabled"] : []
|
|
64412
|
+
states: macroLeased || locked && !lockedBySelf || isBlockExclusive ? ["disabled"] : []
|
|
63860
64413
|
};
|
|
63861
64414
|
return {
|
|
63862
64415
|
group: "standard-block-actions",
|
|
@@ -63897,6 +64450,15 @@ $$${mathData.mathjaxText}$$
|
|
|
63897
64450
|
this.menu.updateItems(items);
|
|
63898
64451
|
this.commandBlock = this.currentBlock;
|
|
63899
64452
|
});
|
|
64453
|
+
__publicField(this, "handleMacroLocksChanged", () => {
|
|
64454
|
+
if (!this.menu.isVisible)
|
|
64455
|
+
return;
|
|
64456
|
+
if (!this.currentBlock || !this.editor.contains(this.currentBlock)) {
|
|
64457
|
+
this.close();
|
|
64458
|
+
return;
|
|
64459
|
+
}
|
|
64460
|
+
this.handleShow();
|
|
64461
|
+
});
|
|
63900
64462
|
__publicField(this, "handleClose", () => {
|
|
63901
64463
|
if (shouldFocusToEditor(this.editor)) {
|
|
63902
64464
|
this.editor.focus();
|
|
@@ -63922,6 +64484,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63922
64484
|
this.menu.on("close", this.handleClose);
|
|
63923
64485
|
this.menu.on("click", this.handleItemClick);
|
|
63924
64486
|
editor.blockHooks.push(new StandardBlockActionHook());
|
|
64487
|
+
editor.addListener("wikiMacroLocksChanged", this.handleMacroLocksChanged);
|
|
63925
64488
|
}
|
|
63926
64489
|
addFilter(id, filter) {
|
|
63927
64490
|
var _a, _b;
|
|
@@ -63943,6 +64506,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63943
64506
|
return this.menu.isVisible;
|
|
63944
64507
|
}
|
|
63945
64508
|
destroy() {
|
|
64509
|
+
this.editor.removeListener("wikiMacroLocksChanged", this.handleMacroLocksChanged);
|
|
63946
64510
|
this.menu.destroy();
|
|
63947
64511
|
}
|
|
63948
64512
|
}
|
|
@@ -83480,11 +84044,21 @@ ${docStr}
|
|
|
83480
84044
|
assert(logger$C, false, "no local actions for history doc");
|
|
83481
84045
|
}
|
|
83482
84046
|
class HistoryDoc extends EventCallbacks {
|
|
83483
|
-
constructor(server, docObject, editorOptions) {
|
|
84047
|
+
constructor(server, docObject, editorOptions, documentVersion) {
|
|
83484
84048
|
super();
|
|
83485
84049
|
this.server = server;
|
|
83486
84050
|
this.docObject = docObject;
|
|
83487
84051
|
this.editorOptions = editorOptions;
|
|
84052
|
+
this.documentVersion = documentVersion;
|
|
84053
|
+
}
|
|
84054
|
+
requestWikiMacro(message) {
|
|
84055
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY", message: "History documents cannot edit Wiki macros" }));
|
|
84056
|
+
}
|
|
84057
|
+
onWikiMacroLocks(listener) {
|
|
84058
|
+
throw new WikiMacroError({ code: "READ_ONLY", message: "History documents have no macro lock channel" });
|
|
84059
|
+
}
|
|
84060
|
+
getDocumentVersion() {
|
|
84061
|
+
return this.documentVersion;
|
|
83488
84062
|
}
|
|
83489
84063
|
beginBatchUpdate() {
|
|
83490
84064
|
return 0;
|
|
@@ -84477,6 +85051,7 @@ ${docStr}
|
|
|
84477
85051
|
const forceRequestVersionAsLatest = !!((_d = this.versionOptions) == null ? void 0 : _d.forceRequestVersionAsLatest);
|
|
84478
85052
|
let docObject;
|
|
84479
85053
|
let historyData;
|
|
85054
|
+
let snapshotVersion;
|
|
84480
85055
|
if (from) {
|
|
84481
85056
|
const requestVersion = forceRequestVersionAsLatest ? -1 : Math.max(version.version, from);
|
|
84482
85057
|
const requestFrom = forceRequestVersionAsLatest ? from : Math.min(version.version, from);
|
|
@@ -84484,12 +85059,18 @@ ${docStr}
|
|
|
84484
85059
|
docObject = ret.doc;
|
|
84485
85060
|
historyData = ret.historyData;
|
|
84486
85061
|
} else {
|
|
84487
|
-
|
|
85062
|
+
if (this.versionHelper.getVersionSnapshot) {
|
|
85063
|
+
const snapshot2 = await this.versionHelper.getVersionSnapshot(version.version);
|
|
85064
|
+
docObject = snapshot2.doc;
|
|
85065
|
+
snapshotVersion = snapshot2.documentVersion;
|
|
85066
|
+
} else {
|
|
85067
|
+
docObject = await this.versionHelper.getVersion(version.version);
|
|
85068
|
+
}
|
|
84488
85069
|
historyData = [];
|
|
84489
85070
|
}
|
|
84490
85071
|
const { editorContainer: editorElement } = this.components;
|
|
84491
85072
|
editorElement.innerHTML = "";
|
|
84492
|
-
const historyDoc = new HistoryDoc(this.server, docObject, this.editorOptions);
|
|
85073
|
+
const historyDoc = new HistoryDoc(this.server, docObject, this.editorOptions, snapshotVersion);
|
|
84493
85074
|
const viewer = this.provider.createHistoryEditor(editorElement, historyDoc);
|
|
84494
85075
|
viewer.editorBlockRenders.registerRender(new OnesEditorHistoryRender());
|
|
84495
85076
|
viewer.editorBoxes.registerBoxClass(HistoryDeletedTextBox);
|
|
@@ -84696,7 +85277,7 @@ ${docStr}
|
|
|
84696
85277
|
}
|
|
84697
85278
|
async function createOnesEditorHistoryDiff(parent, options) {
|
|
84698
85279
|
var _a;
|
|
84699
|
-
const historyDoc = new HistoryDoc(options.server, options.doc, options.editorOptions);
|
|
85280
|
+
const historyDoc = new HistoryDoc(options.server, options.doc, options.editorOptions, options.documentVersion);
|
|
84700
85281
|
const viewer = options.provider.createHistoryEditor(parent, historyDoc);
|
|
84701
85282
|
viewer.editorBlockRenders.registerRender(new OnesEditorHistoryRender());
|
|
84702
85283
|
viewer.editorBoxes.registerBoxClass(HistoryDeletedTextBox);
|
|
@@ -97862,7 +98443,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97862
98443
|
}
|
|
97863
98444
|
}
|
|
97864
98445
|
});
|
|
97865
|
-
editor.version = "5.0.
|
|
98446
|
+
editor.version = "5.0.6-beta.DNP8216.2";
|
|
97866
98447
|
return editor;
|
|
97867
98448
|
}
|
|
97868
98449
|
function isDoc(doc2) {
|
|
@@ -97998,7 +98579,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97998
98579
|
OnesEditorDropTarget.register(editor);
|
|
97999
98580
|
OnesEditorTocProvider.register(editor);
|
|
98000
98581
|
OnesEditorExclusiveBlock.register(editor);
|
|
98001
|
-
editor.version = "5.0.
|
|
98582
|
+
editor.version = "5.0.6-beta.DNP8216.2";
|
|
98002
98583
|
return editor;
|
|
98003
98584
|
} catch (error2) {
|
|
98004
98585
|
try {
|
|
@@ -98141,7 +98722,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
98141
98722
|
}
|
|
98142
98723
|
}
|
|
98143
98724
|
});
|
|
98144
|
-
editor.version = "5.0.
|
|
98725
|
+
editor.version = "5.0.6-beta.DNP8216.2";
|
|
98145
98726
|
return editor;
|
|
98146
98727
|
}
|
|
98147
98728
|
const emojis$1 = {
|
|
@@ -144162,6 +144743,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
144162
144743
|
exports2.WarningFilledIcon = WarningFilledIcon;
|
|
144163
144744
|
exports2.WarningIcon = WarningIcon;
|
|
144164
144745
|
exports2.WebPageIcon = WebPageIcon;
|
|
144746
|
+
exports2.WikiMacroError = WikiMacroError;
|
|
144165
144747
|
exports2.YoukuIcon = YoukuIcon;
|
|
144166
144748
|
exports2.ZERO_WIDTH_SPACE_CHAR = ZERO_WIDTH_SPACE_CHAR;
|
|
144167
144749
|
exports2.abbreviation = abbreviation;
|
|
@@ -144616,6 +145198,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
144616
145198
|
exports2.isToday = isToday;
|
|
144617
145199
|
exports2.isValidOffset = isValidOffset;
|
|
144618
145200
|
exports2.isVisibleBlock = isVisibleBlock;
|
|
145201
|
+
exports2.isWikiMacroElementLocked = isWikiMacroElementLocked;
|
|
144619
145202
|
exports2.isYesterday = isYesterday;
|
|
144620
145203
|
exports2.loadJs = loadJs;
|
|
144621
145204
|
exports2.loadJsPromise = loadJsPromise;
|