@ones-editor/editor 5.0.5 → 5.0.6-beta.DNP8216.1
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 +590 -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));
|
|
@@ -31045,10 +31140,38 @@ ${codeText}
|
|
|
31045
31140
|
constructor(editor, externalDoc, localEvents) {
|
|
31046
31141
|
super();
|
|
31047
31142
|
__publicField(this, "localEvents", []);
|
|
31143
|
+
__publicField(this, "unsubscribeMacroLocks");
|
|
31048
31144
|
this.editor = editor;
|
|
31049
31145
|
this.externalDoc = externalDoc;
|
|
31050
31146
|
this.externalDoc.registerCallback(this);
|
|
31051
31147
|
this.registerLocalEvents(localEvents);
|
|
31148
|
+
this.subscribeMacroLocks();
|
|
31149
|
+
}
|
|
31150
|
+
subscribeMacroLocks() {
|
|
31151
|
+
initializeWikiMacroLocks(this.editor);
|
|
31152
|
+
try {
|
|
31153
|
+
this.unsubscribeMacroLocks = this.externalDoc.onWikiMacroLocks((locks) => {
|
|
31154
|
+
updateWikiMacroLocks(this.editor, locks);
|
|
31155
|
+
this.editor.emit("wikiMacroLocksChanged", this.editor);
|
|
31156
|
+
});
|
|
31157
|
+
} catch (error2) {
|
|
31158
|
+
clearWikiMacroLocks(this.editor);
|
|
31159
|
+
if (!(error2 instanceof WikiMacroError) || error2.code !== "READ_ONLY")
|
|
31160
|
+
throw error2;
|
|
31161
|
+
}
|
|
31162
|
+
}
|
|
31163
|
+
requestWikiMacro(message) {
|
|
31164
|
+
if (this.editor.readonly && message.operation !== "locks" && message.operation !== "getEditResult" && message.operation !== "cancelEdit") {
|
|
31165
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY" }));
|
|
31166
|
+
}
|
|
31167
|
+
return this.externalDoc.requestWikiMacro(message);
|
|
31168
|
+
}
|
|
31169
|
+
onWikiMacroLocks(listener) {
|
|
31170
|
+
return this.externalDoc.onWikiMacroLocks(listener);
|
|
31171
|
+
}
|
|
31172
|
+
getDocumentVersion() {
|
|
31173
|
+
var _a, _b;
|
|
31174
|
+
return (_b = (_a = this.externalDoc).getDocumentVersion) == null ? void 0 : _b.call(_a);
|
|
31052
31175
|
}
|
|
31053
31176
|
beginBatchUpdate() {
|
|
31054
31177
|
return this.externalDoc.beginBatchUpdate();
|
|
@@ -31087,6 +31210,8 @@ ${codeText}
|
|
|
31087
31210
|
}
|
|
31088
31211
|
localUpdateBlockText(containerId, blockIndex, actions2, options) {
|
|
31089
31212
|
const blockData = this.getBlockData(containerId, blockIndex);
|
|
31213
|
+
if (isWikiMacroBlockLocked(this.editor, blockData))
|
|
31214
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31090
31215
|
const oldText = blockData.text;
|
|
31091
31216
|
assert(logger$3l, oldText, `no text, ${containerId}, ${blockIndex}`);
|
|
31092
31217
|
const newRange = transformSelection(this.editor, blockData.id, actions2, true);
|
|
@@ -31098,6 +31223,10 @@ ${codeText}
|
|
|
31098
31223
|
}
|
|
31099
31224
|
localUpdateBlockData(containerId, blockIndex, delta, newRange, options) {
|
|
31100
31225
|
const block = this.editor.getBlockByIndex(containerId, blockIndex);
|
|
31226
|
+
const blockedByMacroLease = isWikiMacroBlockLocked(this.editor, this.getBlockData(containerId, blockIndex));
|
|
31227
|
+
if (blockedByMacroLease && (delta.delete.some((key) => key !== "comments") || Object.keys(delta.insert).some((key) => key !== "comments"))) {
|
|
31228
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31229
|
+
}
|
|
31101
31230
|
if (!this.editor.isBlockWritable(block)) {
|
|
31102
31231
|
const deletedKeys = Array.from(delta.delete).filter((key) => key !== "comments");
|
|
31103
31232
|
const insertedKeys = Object.keys(delta.insert).filter((key) => key !== "comments");
|
|
@@ -31114,6 +31243,8 @@ ${codeText}
|
|
|
31114
31243
|
}
|
|
31115
31244
|
localInsertBlock(containerId, blockIndex, data2, newRange, options) {
|
|
31116
31245
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31246
|
+
if (isWikiMacroBlockLocked(this.editor, data2))
|
|
31247
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31117
31248
|
this.localEvents.forEach((event) => event.onBeforeInsertBlock(containerId, blockIndex, data2, newRange));
|
|
31118
31249
|
const ret = this.externalDoc.localInsertBlock(containerId, blockIndex, data2, newRange);
|
|
31119
31250
|
if (!(options == null ? void 0 : options.noFocus)) {
|
|
@@ -31132,6 +31263,9 @@ ${codeText}
|
|
|
31132
31263
|
}
|
|
31133
31264
|
localDeleteChildContainers(containerIds) {
|
|
31134
31265
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31266
|
+
if (containerIds.some((containerId) => this.getContainerBlocks(containerId).some((block) => isWikiMacroBlockLocked(this.editor, block)))) {
|
|
31267
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31268
|
+
}
|
|
31135
31269
|
containerIds.forEach((containerId) => {
|
|
31136
31270
|
const blocks = cloneDeep__default.default(this.getContainerBlocks(containerId));
|
|
31137
31271
|
this.localEvents.forEach((event) => event.onBeforeDeleteChildContainer(containerId, blocks));
|
|
@@ -31140,6 +31274,9 @@ ${codeText}
|
|
|
31140
31274
|
}
|
|
31141
31275
|
localInsertChildContainers(containers) {
|
|
31142
31276
|
assert(logger$3l, !this.editor.readonly, "editor is readonly");
|
|
31277
|
+
if (containers.some((container) => container.blocks.some((block) => isWikiMacroBlockLocked(this.editor, block)))) {
|
|
31278
|
+
throw new WikiMacroError({ code: "LOCK_CONFLICT" });
|
|
31279
|
+
}
|
|
31143
31280
|
const data2 = cloneDeep__default.default(containers);
|
|
31144
31281
|
data2.forEach((item) => {
|
|
31145
31282
|
this.localEvents.forEach((event) => event.onBeforeInsertChildContainer(item.containerId, item.blocks));
|
|
@@ -31248,6 +31385,11 @@ ${codeText}
|
|
|
31248
31385
|
(_b = (_a = this.externalDoc).triggerReAuth) == null ? void 0 : _b.call(_a, auto);
|
|
31249
31386
|
}
|
|
31250
31387
|
destroy() {
|
|
31388
|
+
var _a;
|
|
31389
|
+
this.editor.undoManager.destroy();
|
|
31390
|
+
(_a = this.unsubscribeMacroLocks) == null ? void 0 : _a.call(this);
|
|
31391
|
+
this.unsubscribeMacroLocks = void 0;
|
|
31392
|
+
clearWikiMacroLocks(this.editor);
|
|
31251
31393
|
this.externalDoc.destroy();
|
|
31252
31394
|
this.clearCallbacks();
|
|
31253
31395
|
}
|
|
@@ -31256,24 +31398,17 @@ ${codeText}
|
|
|
31256
31398
|
return (_c = (_b = (_a = this.externalDoc).getServerMeta) == null ? void 0 : _b.call(_a)) != null ? _c : {};
|
|
31257
31399
|
}
|
|
31258
31400
|
reset(doc2) {
|
|
31401
|
+
var _a;
|
|
31259
31402
|
logger$3l.log("reset doc");
|
|
31403
|
+
(_a = this.unsubscribeMacroLocks) == null ? void 0 : _a.call(this);
|
|
31404
|
+
clearWikiMacroLocks(this.editor);
|
|
31260
31405
|
this.externalDoc = doc2;
|
|
31261
31406
|
this.externalDoc.registerCallback(this);
|
|
31407
|
+
initializeWikiMacroLocks(this.editor);
|
|
31262
31408
|
this.editor.reload();
|
|
31409
|
+
this.subscribeMacroLocks();
|
|
31263
31410
|
}
|
|
31264
31411
|
}
|
|
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
31412
|
const logger$3k = getLogger("undo-action");
|
|
31278
31413
|
class Action {
|
|
31279
31414
|
constructor(editor, containerId, afterRange, batchActionId) {
|
|
@@ -31337,6 +31472,38 @@ ${codeText}
|
|
|
31337
31472
|
return true;
|
|
31338
31473
|
}
|
|
31339
31474
|
}
|
|
31475
|
+
class MacroEditAction extends Action {
|
|
31476
|
+
constructor(editor, options) {
|
|
31477
|
+
super(editor, "", editor.selection.range.toDocRange());
|
|
31478
|
+
__publicField(this, "options");
|
|
31479
|
+
this.options = options;
|
|
31480
|
+
}
|
|
31481
|
+
apply(direction) {
|
|
31482
|
+
if (!this.options) {
|
|
31483
|
+
return Promise.reject(new WikiMacroError({ code: "SESSION_EXPIRED", message: "Macro history action disposed" }));
|
|
31484
|
+
}
|
|
31485
|
+
return this.options[direction]();
|
|
31486
|
+
}
|
|
31487
|
+
reportError(error2) {
|
|
31488
|
+
var _a, _b;
|
|
31489
|
+
(_b = (_a = this.options) == null ? void 0 : _a.onError) == null ? void 0 : _b.call(_a, error2);
|
|
31490
|
+
}
|
|
31491
|
+
dispose() {
|
|
31492
|
+
this.options = null;
|
|
31493
|
+
}
|
|
31494
|
+
}
|
|
31495
|
+
function addActions(actions2, action) {
|
|
31496
|
+
if (actions2.length === 0) {
|
|
31497
|
+
actions2.push(action);
|
|
31498
|
+
return;
|
|
31499
|
+
}
|
|
31500
|
+
const last = actions2[actions2.length - 1];
|
|
31501
|
+
if (!last.combinable(action)) {
|
|
31502
|
+
actions2.push(action);
|
|
31503
|
+
return;
|
|
31504
|
+
}
|
|
31505
|
+
last.combine(action);
|
|
31506
|
+
}
|
|
31340
31507
|
const logger$3j = getLogger("block-action");
|
|
31341
31508
|
class BlockAction extends Action {
|
|
31342
31509
|
constructor(editor, containerId, blockIndex, data2, afterRange) {
|
|
@@ -31394,10 +31561,32 @@ ${codeText}
|
|
|
31394
31561
|
}
|
|
31395
31562
|
class DeleteBlockAction$1 extends BlockAction {
|
|
31396
31563
|
undo(editor) {
|
|
31397
|
-
|
|
31564
|
+
if (this.blockData.type !== "embed" || this.blockData.embedType !== "ones-open-wiki-macro") {
|
|
31565
|
+
return this.insertBlock(editor, this.beforeRange);
|
|
31566
|
+
}
|
|
31567
|
+
const revision = this.blockData.macroRevision;
|
|
31568
|
+
this.blockData.macroRevision = revision + 1;
|
|
31569
|
+
let inserted = false;
|
|
31570
|
+
try {
|
|
31571
|
+
inserted = this.insertBlock(editor, this.beforeRange);
|
|
31572
|
+
return inserted;
|
|
31573
|
+
} finally {
|
|
31574
|
+
if (!inserted)
|
|
31575
|
+
this.blockData.macroRevision = revision;
|
|
31576
|
+
}
|
|
31398
31577
|
}
|
|
31399
31578
|
redo(editor) {
|
|
31400
|
-
|
|
31579
|
+
if (this.blockData.type !== "embed" || this.blockData.embedType !== "ones-open-wiki-macro") {
|
|
31580
|
+
return this.deleteBlock(editor, this.afterRange);
|
|
31581
|
+
}
|
|
31582
|
+
const block = editor.findBlockById(this.blockData.id);
|
|
31583
|
+
if (!block)
|
|
31584
|
+
return false;
|
|
31585
|
+
const deletedSnapshot = cloneDeep__default.default(editor.getBlockData(block));
|
|
31586
|
+
const deleted = this.deleteBlock(editor, this.afterRange);
|
|
31587
|
+
if (deleted)
|
|
31588
|
+
this.blockData = deletedSnapshot;
|
|
31589
|
+
return deleted;
|
|
31401
31590
|
}
|
|
31402
31591
|
}
|
|
31403
31592
|
class GroupAction extends Action {
|
|
@@ -31674,6 +31863,11 @@ ${codeText}
|
|
|
31674
31863
|
__publicField(this, "currentGroup", null);
|
|
31675
31864
|
__publicField(this, "groupCounter", 0);
|
|
31676
31865
|
__publicField(this, "undoRedoing", false);
|
|
31866
|
+
__publicField(this, "macroSessions", /* @__PURE__ */ new Set());
|
|
31867
|
+
__publicField(this, "macroActionIds", /* @__PURE__ */ new Set());
|
|
31868
|
+
__publicField(this, "pendingMacroAction", null);
|
|
31869
|
+
__publicField(this, "macroGeneration", 0);
|
|
31870
|
+
__publicField(this, "destroyed", false);
|
|
31677
31871
|
__publicField(this, "handleSelectionChange", (editor) => {
|
|
31678
31872
|
if (this.currentGroup) {
|
|
31679
31873
|
this.currentGroup.setAfterRange(editor.selection.range.toDocRange());
|
|
@@ -31690,13 +31884,104 @@ ${codeText}
|
|
|
31690
31884
|
this.undoCursor = -1;
|
|
31691
31885
|
this.editor.addListener("selectionChanged", this.handleSelectionChange);
|
|
31692
31886
|
}
|
|
31887
|
+
registerMacroEditAction(options) {
|
|
31888
|
+
if (this.destroyed) {
|
|
31889
|
+
throw new WikiMacroError({ code: "SESSION_EXPIRED", message: "Editor destroyed" });
|
|
31890
|
+
}
|
|
31891
|
+
if (this.macroActionIds.has(options.actionId))
|
|
31892
|
+
return;
|
|
31893
|
+
this.prepareSaveUndoState();
|
|
31894
|
+
this.macroActionIds.add(options.actionId);
|
|
31895
|
+
const action = new MacroEditAction(this.editor, options);
|
|
31896
|
+
this.actions.push(action);
|
|
31897
|
+
this.editor.input.handleChanged(action);
|
|
31898
|
+
}
|
|
31899
|
+
setMacroEditSessionActive(sessionId, active) {
|
|
31900
|
+
if (this.destroyed)
|
|
31901
|
+
return;
|
|
31902
|
+
setWikiMacroLockSession(this.editor, sessionId, active);
|
|
31903
|
+
if (active) {
|
|
31904
|
+
this.macroSessions.add(sessionId);
|
|
31905
|
+
} else {
|
|
31906
|
+
this.macroSessions.delete(sessionId);
|
|
31907
|
+
}
|
|
31908
|
+
}
|
|
31909
|
+
destroy() {
|
|
31910
|
+
this.destroyed = true;
|
|
31911
|
+
this.reset();
|
|
31912
|
+
this.macroSessions.clear();
|
|
31913
|
+
this.editor.removeListener("selectionChanged", this.handleSelectionChange);
|
|
31914
|
+
}
|
|
31915
|
+
applyMacroAction(action, direction) {
|
|
31916
|
+
const generation = this.macroGeneration;
|
|
31917
|
+
const cursor = this.undoCursor;
|
|
31918
|
+
const historyLength = this.actions.length;
|
|
31919
|
+
this.pendingMacroAction = action;
|
|
31920
|
+
Promise.resolve().then(() => action.apply(direction)).then(() => {
|
|
31921
|
+
if (generation !== this.macroGeneration || this.destroyed)
|
|
31922
|
+
return;
|
|
31923
|
+
const index2 = this.actions.indexOf(action);
|
|
31924
|
+
if (direction === "undo") {
|
|
31925
|
+
if (index2 < 0)
|
|
31926
|
+
return;
|
|
31927
|
+
if (this.undoCursor === cursor && this.actions.length === historyLength) {
|
|
31928
|
+
this.undoCursor = index2;
|
|
31929
|
+
} else {
|
|
31930
|
+
this.actions.splice(index2, 1);
|
|
31931
|
+
this.actions.push(action);
|
|
31932
|
+
this.undoCursor = this.actions.length - 1;
|
|
31933
|
+
}
|
|
31934
|
+
} else if (index2 >= 0 && this.undoCursor === cursor && this.actions.length === historyLength) {
|
|
31935
|
+
this.undoCursor = index2 + 1;
|
|
31936
|
+
} else {
|
|
31937
|
+
if (index2 >= 0)
|
|
31938
|
+
this.actions.splice(index2, 1);
|
|
31939
|
+
this.actions.push(action);
|
|
31940
|
+
this.undoCursor = -1;
|
|
31941
|
+
}
|
|
31942
|
+
try {
|
|
31943
|
+
this.editor.input.handleChanged(action);
|
|
31944
|
+
} catch (error2) {
|
|
31945
|
+
logger$3f.error("Macro history change observer failed");
|
|
31946
|
+
}
|
|
31947
|
+
}).catch((error2) => {
|
|
31948
|
+
if (generation !== this.macroGeneration || this.destroyed)
|
|
31949
|
+
return;
|
|
31950
|
+
const failure = error2 instanceof Error ? error2 : new Error("Macro history action failed");
|
|
31951
|
+
try {
|
|
31952
|
+
action.reportError(failure);
|
|
31953
|
+
} catch (callbackError) {
|
|
31954
|
+
logger$3f.error("Macro history error callback failed");
|
|
31955
|
+
}
|
|
31956
|
+
}).finally(() => {
|
|
31957
|
+
if (generation === this.macroGeneration) {
|
|
31958
|
+
this.pendingMacroAction = null;
|
|
31959
|
+
if (!this.actions.includes(action))
|
|
31960
|
+
action.dispose();
|
|
31961
|
+
}
|
|
31962
|
+
});
|
|
31963
|
+
return true;
|
|
31964
|
+
}
|
|
31693
31965
|
reset() {
|
|
31966
|
+
var _a;
|
|
31967
|
+
this.macroGeneration += 1;
|
|
31968
|
+
(_a = this.pendingMacroAction) == null ? void 0 : _a.dispose();
|
|
31969
|
+
this.pendingMacroAction = null;
|
|
31970
|
+
this.actions.forEach((action) => {
|
|
31971
|
+
if (action instanceof MacroEditAction)
|
|
31972
|
+
action.dispose();
|
|
31973
|
+
});
|
|
31974
|
+
this.macroActionIds.clear();
|
|
31694
31975
|
this.actions = [];
|
|
31695
31976
|
this.undoCursor = -1;
|
|
31696
31977
|
}
|
|
31697
31978
|
prepareSaveUndoState() {
|
|
31698
31979
|
if (this.undoCursor !== -1) {
|
|
31699
|
-
this.actions.splice(this.undoCursor);
|
|
31980
|
+
const removed = this.actions.splice(this.undoCursor);
|
|
31981
|
+
removed.forEach((action) => {
|
|
31982
|
+
if (action instanceof MacroEditAction && action !== this.pendingMacroAction)
|
|
31983
|
+
action.dispose();
|
|
31984
|
+
});
|
|
31700
31985
|
this.undoCursor = -1;
|
|
31701
31986
|
}
|
|
31702
31987
|
}
|
|
@@ -31778,14 +32063,22 @@ ${codeText}
|
|
|
31778
32063
|
}
|
|
31779
32064
|
}
|
|
31780
32065
|
undo() {
|
|
32066
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32067
|
+
return false;
|
|
32068
|
+
const candidate = this.actions[(this.undoCursor === -1 ? this.actions.length : this.undoCursor) - 1];
|
|
32069
|
+
if (candidate instanceof MacroEditAction)
|
|
32070
|
+
return this.applyMacroAction(candidate, "undo");
|
|
31781
32071
|
if (this.undoCursor === -1) {
|
|
31782
32072
|
this.undoCursor = this.actions.length;
|
|
31783
32073
|
}
|
|
31784
32074
|
try {
|
|
31785
32075
|
this.undoRedoing = true;
|
|
31786
32076
|
while (this.undoCursor > 0) {
|
|
32077
|
+
const action = this.actions[this.undoCursor - 1];
|
|
32078
|
+
if (action instanceof MacroEditAction) {
|
|
32079
|
+
return this.applyMacroAction(action, "undo");
|
|
32080
|
+
}
|
|
31787
32081
|
this.undoCursor -= 1;
|
|
31788
|
-
const action = this.actions[this.undoCursor];
|
|
31789
32082
|
if (action.undo(this.editor)) {
|
|
31790
32083
|
try {
|
|
31791
32084
|
this.editor.selection.setRange(fromDocRange(this.editor, action.beforeRange));
|
|
@@ -31811,6 +32104,11 @@ ${codeText}
|
|
|
31811
32104
|
}
|
|
31812
32105
|
}
|
|
31813
32106
|
redo() {
|
|
32107
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32108
|
+
return false;
|
|
32109
|
+
const candidate = this.actions[this.undoCursor];
|
|
32110
|
+
if (candidate instanceof MacroEditAction)
|
|
32111
|
+
return this.applyMacroAction(candidate, "redo");
|
|
31814
32112
|
if (this.undoCursor === -1) {
|
|
31815
32113
|
this.undoCursor = this.actions.length;
|
|
31816
32114
|
}
|
|
@@ -31818,6 +32116,9 @@ ${codeText}
|
|
|
31818
32116
|
this.undoRedoing = true;
|
|
31819
32117
|
while (this.undoCursor < this.actions.length) {
|
|
31820
32118
|
const action = this.actions[this.undoCursor];
|
|
32119
|
+
if (action instanceof MacroEditAction) {
|
|
32120
|
+
return this.applyMacroAction(action, "redo");
|
|
32121
|
+
}
|
|
31821
32122
|
this.undoCursor += 1;
|
|
31822
32123
|
if (action.redo(this.editor)) {
|
|
31823
32124
|
try {
|
|
@@ -31846,6 +32147,8 @@ ${codeText}
|
|
|
31846
32147
|
}
|
|
31847
32148
|
}
|
|
31848
32149
|
canUndo() {
|
|
32150
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32151
|
+
return false;
|
|
31849
32152
|
if (this.actions.length === 0) {
|
|
31850
32153
|
return false;
|
|
31851
32154
|
}
|
|
@@ -31855,6 +32158,8 @@ ${codeText}
|
|
|
31855
32158
|
return true;
|
|
31856
32159
|
}
|
|
31857
32160
|
canRedo() {
|
|
32161
|
+
if (this.destroyed || this.macroSessions.size > 0 || this.pendingMacroAction)
|
|
32162
|
+
return false;
|
|
31858
32163
|
if (this.actions.length === 0) {
|
|
31859
32164
|
return false;
|
|
31860
32165
|
}
|
|
@@ -31880,6 +32185,10 @@ ${codeText}
|
|
|
31880
32185
|
if (lastAction === action) {
|
|
31881
32186
|
return true;
|
|
31882
32187
|
}
|
|
32188
|
+
if (this.pendingMacroAction || lastAction instanceof MacroEditAction) {
|
|
32189
|
+
this.undo();
|
|
32190
|
+
return false;
|
|
32191
|
+
}
|
|
31883
32192
|
if (!this.undo()) {
|
|
31884
32193
|
return false;
|
|
31885
32194
|
}
|
|
@@ -32416,6 +32725,35 @@ ${codeText}
|
|
|
32416
32725
|
return void 0;
|
|
32417
32726
|
}
|
|
32418
32727
|
}
|
|
32728
|
+
const editorHooks = /* @__PURE__ */ new WeakMap();
|
|
32729
|
+
function registerDocResourceHook(editor, hook) {
|
|
32730
|
+
if (editor.destroyed) {
|
|
32731
|
+
throw new Error("Cannot register a document resource hook on a destroyed editor");
|
|
32732
|
+
}
|
|
32733
|
+
const registration = { hook, collect: hook.collect, rewrite: hook.rewrite };
|
|
32734
|
+
let hooks = editorHooks.get(editor);
|
|
32735
|
+
if (!hooks) {
|
|
32736
|
+
hooks = /* @__PURE__ */ new Set();
|
|
32737
|
+
editorHooks.set(editor, hooks);
|
|
32738
|
+
}
|
|
32739
|
+
const registrations = hooks;
|
|
32740
|
+
registrations.add(registration);
|
|
32741
|
+
return () => {
|
|
32742
|
+
if (!registrations.delete(registration)) {
|
|
32743
|
+
return;
|
|
32744
|
+
}
|
|
32745
|
+
if (registrations.size === 0 && editorHooks.get(editor) === registrations) {
|
|
32746
|
+
editorHooks.delete(editor);
|
|
32747
|
+
}
|
|
32748
|
+
};
|
|
32749
|
+
}
|
|
32750
|
+
function clearDocResourceHooks(editor) {
|
|
32751
|
+
const hooks = editorHooks.get(editor);
|
|
32752
|
+
if (hooks) {
|
|
32753
|
+
hooks.clear();
|
|
32754
|
+
editorHooks.delete(editor);
|
|
32755
|
+
}
|
|
32756
|
+
}
|
|
32419
32757
|
const logger$3b = getLogger("editor");
|
|
32420
32758
|
class Editor extends tinyTypedEmitter.TypedEmitter {
|
|
32421
32759
|
constructor(parent, doc2, optionalOptions) {
|
|
@@ -32586,9 +32924,21 @@ ${codeText}
|
|
|
32586
32924
|
createInsertion(blockContent, insertion) {
|
|
32587
32925
|
return this.editorInsertions.createInsertion(blockContent, insertion);
|
|
32588
32926
|
}
|
|
32927
|
+
addDocResourceHook(hook) {
|
|
32928
|
+
return registerDocResourceHook(this, hook);
|
|
32929
|
+
}
|
|
32930
|
+
registerMacroEditAction(options) {
|
|
32931
|
+
this.undoManager.registerMacroEditAction(options);
|
|
32932
|
+
}
|
|
32933
|
+
setMacroEditSessionActive(sessionId, active) {
|
|
32934
|
+
if (this.destroyed)
|
|
32935
|
+
return;
|
|
32936
|
+
this.undoManager.setMacroEditSessionActive(sessionId, active);
|
|
32937
|
+
}
|
|
32589
32938
|
destroy() {
|
|
32590
32939
|
logger$3b.debug("destroy editor");
|
|
32591
32940
|
this.emit("destroy", this);
|
|
32941
|
+
this.undoManager.destroy();
|
|
32592
32942
|
this.input.destroy();
|
|
32593
32943
|
this.rootContainerObject.destroy();
|
|
32594
32944
|
this.rootElement.remove();
|
|
@@ -32599,6 +32949,7 @@ ${codeText}
|
|
|
32599
32949
|
this.domEvents.destroy();
|
|
32600
32950
|
this.removeAllListeners();
|
|
32601
32951
|
this.inputHandlers.destroy();
|
|
32952
|
+
clearDocResourceHooks(this);
|
|
32602
32953
|
this._destroyed = true;
|
|
32603
32954
|
}
|
|
32604
32955
|
get destroyed() {
|
|
@@ -32613,7 +32964,15 @@ ${codeText}
|
|
|
32613
32964
|
isWritable() {
|
|
32614
32965
|
return editorIsWritable(this);
|
|
32615
32966
|
}
|
|
32616
|
-
isBlockWritable(block) {
|
|
32967
|
+
isBlockWritable(block, macroSessionId) {
|
|
32968
|
+
if (macroSessionId && this.readonly)
|
|
32969
|
+
return false;
|
|
32970
|
+
if (Array.isArray(block)) {
|
|
32971
|
+
if (block.some((item) => isWikiMacroElementLocked(this, item, macroSessionId)))
|
|
32972
|
+
return false;
|
|
32973
|
+
} else if (isWikiMacroElementLocked(this, block, macroSessionId)) {
|
|
32974
|
+
return false;
|
|
32975
|
+
}
|
|
32617
32976
|
return editorIsBlockWritable(this, block);
|
|
32618
32977
|
}
|
|
32619
32978
|
getChildContainerData(childContainerId) {
|
|
@@ -32962,6 +33321,7 @@ ${codeText}
|
|
|
32962
33321
|
super();
|
|
32963
33322
|
__publicField(this, "doc");
|
|
32964
33323
|
__publicField(this, "serviceUrl");
|
|
33324
|
+
__publicField(this, "documentVersion");
|
|
32965
33325
|
if (doc2) {
|
|
32966
33326
|
this.doc = doc2;
|
|
32967
33327
|
} else {
|
|
@@ -32976,6 +33336,16 @@ ${codeText}
|
|
|
32976
33336
|
};
|
|
32977
33337
|
}
|
|
32978
33338
|
this.serviceUrl = (options == null ? void 0 : options.serverUrl) || "";
|
|
33339
|
+
this.documentVersion = options == null ? void 0 : options.documentVersion;
|
|
33340
|
+
}
|
|
33341
|
+
requestWikiMacro(message) {
|
|
33342
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY", message: "Local and history documents cannot edit Wiki macros" }));
|
|
33343
|
+
}
|
|
33344
|
+
onWikiMacroLocks(listener) {
|
|
33345
|
+
throw new WikiMacroError({ code: "READ_ONLY", message: "Local and history documents have no macro lock channel" });
|
|
33346
|
+
}
|
|
33347
|
+
getDocumentVersion() {
|
|
33348
|
+
return this.documentVersion;
|
|
32979
33349
|
}
|
|
32980
33350
|
beginBatchUpdate() {
|
|
32981
33351
|
return 0;
|
|
@@ -33114,8 +33484,9 @@ ${codeText}
|
|
|
33114
33484
|
getRemoteUsers() {
|
|
33115
33485
|
return new RemoteUsers();
|
|
33116
33486
|
}
|
|
33117
|
-
setDoc(doc2) {
|
|
33487
|
+
setDoc(doc2, documentVersion) {
|
|
33118
33488
|
this.doc = cloneDeep__default.default(doc2);
|
|
33489
|
+
this.documentVersion = documentVersion;
|
|
33119
33490
|
this.callbacks.forEach((c) => {
|
|
33120
33491
|
var _a;
|
|
33121
33492
|
return (_a = c.onRequestReload) == null ? void 0 : _a.call(c, "change doc");
|
|
@@ -38659,6 +39030,11 @@ ${codeText}
|
|
|
38659
39030
|
__publicField(this, "connectionStatus", null);
|
|
38660
39031
|
__publicField(this, "reauthing", false);
|
|
38661
39032
|
__publicField(this, "ready", false);
|
|
39033
|
+
__publicField(this, "macroRequests", /* @__PURE__ */ new Map());
|
|
39034
|
+
__publicField(this, "macroLocksListeners", /* @__PURE__ */ new Set());
|
|
39035
|
+
__publicField(this, "macroLocks", []);
|
|
39036
|
+
__publicField(this, "macroLocksKnown", false);
|
|
39037
|
+
__publicField(this, "macroLocksLoading", false);
|
|
38662
39038
|
__publicField(this, "pingOptions", { interval: 5e4, timeout: 15e4 });
|
|
38663
39039
|
__publicField(this, "handleAuthError", (err) => {
|
|
38664
39040
|
if (!this.renewTokenFunc) {
|
|
@@ -38706,6 +39082,7 @@ ${codeText}
|
|
|
38706
39082
|
});
|
|
38707
39083
|
__publicField(this, "handleDisconnected", (reason) => {
|
|
38708
39084
|
this.connectionDisconnected = true;
|
|
39085
|
+
this.clearWikiMacroRequests("Document disconnected; query the original request before retrying");
|
|
38709
39086
|
this.emit("disconnected", reason);
|
|
38710
39087
|
});
|
|
38711
39088
|
__publicField(this, "handleVisibilityChange", () => {
|
|
@@ -38723,6 +39100,111 @@ ${codeText}
|
|
|
38723
39100
|
this.renewTokenFunc = renewTokenFunc;
|
|
38724
39101
|
this.authMessage = authMessage;
|
|
38725
39102
|
}
|
|
39103
|
+
loadWikiMacroLocks() {
|
|
39104
|
+
if (this.closed || this.macroLocksLoading || this.macroLocksListeners.size === 0)
|
|
39105
|
+
return;
|
|
39106
|
+
this.macroLocksLoading = true;
|
|
39107
|
+
this.requestWikiMacro({ operation: "locks" }).then((result) => {
|
|
39108
|
+
if (this.closed)
|
|
39109
|
+
return;
|
|
39110
|
+
if (!Array.isArray(result.locks)) {
|
|
39111
|
+
throw new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Macro lock snapshot unavailable" });
|
|
39112
|
+
}
|
|
39113
|
+
this.notifyWikiMacroLocks(result.locks);
|
|
39114
|
+
}).catch(() => {
|
|
39115
|
+
if (!this.closed)
|
|
39116
|
+
logger$31.warn("Macro lock snapshot unavailable");
|
|
39117
|
+
}).finally(() => {
|
|
39118
|
+
this.macroLocksLoading = false;
|
|
39119
|
+
});
|
|
39120
|
+
}
|
|
39121
|
+
requestWikiMacro(message) {
|
|
39122
|
+
var _a;
|
|
39123
|
+
const requestId = genId();
|
|
39124
|
+
if (this.closed || ((_a = this.connection) == null ? void 0 : _a.state) !== "connected" || this.reauthing || this.connectionDisconnected) {
|
|
39125
|
+
return Promise.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document connection unavailable" }, requestId));
|
|
39126
|
+
}
|
|
39127
|
+
return new Promise((resolve, reject) => {
|
|
39128
|
+
const timeout = window.setTimeout(() => {
|
|
39129
|
+
this.macroRequests.delete(requestId);
|
|
39130
|
+
reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Macro result unknown; query the original request" }, requestId));
|
|
39131
|
+
}, 6e4);
|
|
39132
|
+
this.macroRequests.set(requestId, { resolve, reject, timeout });
|
|
39133
|
+
try {
|
|
39134
|
+
this.connection.send({
|
|
39135
|
+
a: "wikiMacro",
|
|
39136
|
+
requestId,
|
|
39137
|
+
operation: message.operation,
|
|
39138
|
+
blockId: message.blockId,
|
|
39139
|
+
sessionId: message.sessionId,
|
|
39140
|
+
fence: message.fence,
|
|
39141
|
+
expectedRevision: message.expectedRevision,
|
|
39142
|
+
content: message.content,
|
|
39143
|
+
actionId: message.actionId,
|
|
39144
|
+
direction: message.direction,
|
|
39145
|
+
targetRequestId: message.targetRequestId
|
|
39146
|
+
});
|
|
39147
|
+
} catch (error2) {
|
|
39148
|
+
this.macroRequests.delete(requestId);
|
|
39149
|
+
window.clearTimeout(timeout);
|
|
39150
|
+
reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Unable to send macro request" }, requestId));
|
|
39151
|
+
}
|
|
39152
|
+
});
|
|
39153
|
+
}
|
|
39154
|
+
onWikiMacroLocks(listener) {
|
|
39155
|
+
if (this.closed) {
|
|
39156
|
+
throw new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document connection closed" });
|
|
39157
|
+
}
|
|
39158
|
+
this.macroLocksListeners.add(listener);
|
|
39159
|
+
try {
|
|
39160
|
+
if (this.macroLocksKnown)
|
|
39161
|
+
listener(this.macroLocks || []);
|
|
39162
|
+
} catch (error2) {
|
|
39163
|
+
this.macroLocksListeners.delete(listener);
|
|
39164
|
+
throw error2;
|
|
39165
|
+
}
|
|
39166
|
+
this.loadWikiMacroLocks();
|
|
39167
|
+
return () => {
|
|
39168
|
+
this.macroLocksListeners.delete(listener);
|
|
39169
|
+
};
|
|
39170
|
+
}
|
|
39171
|
+
handleWikiMacroReply(message) {
|
|
39172
|
+
if (message.operation === "locks" && Array.isArray(message.locks)) {
|
|
39173
|
+
this.notifyWikiMacroLocks(message.locks);
|
|
39174
|
+
}
|
|
39175
|
+
if (!message.requestId)
|
|
39176
|
+
return;
|
|
39177
|
+
const pending = this.macroRequests.get(message.requestId);
|
|
39178
|
+
if (!pending)
|
|
39179
|
+
return;
|
|
39180
|
+
this.macroRequests.delete(message.requestId);
|
|
39181
|
+
window.clearTimeout(pending.timeout);
|
|
39182
|
+
if (message.error) {
|
|
39183
|
+
pending.reject(new WikiMacroError(message.error, message.requestId));
|
|
39184
|
+
} else if (message.result) {
|
|
39185
|
+
pending.resolve({ ...message.result, requestId: message.requestId });
|
|
39186
|
+
} else {
|
|
39187
|
+
pending.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Invalid macro acknowledgement" }, message.requestId));
|
|
39188
|
+
}
|
|
39189
|
+
}
|
|
39190
|
+
clearWikiMacroRequests(message) {
|
|
39191
|
+
this.macroRequests.forEach((pending, requestId) => {
|
|
39192
|
+
window.clearTimeout(pending.timeout);
|
|
39193
|
+
pending.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message }, requestId));
|
|
39194
|
+
});
|
|
39195
|
+
this.macroRequests.clear();
|
|
39196
|
+
}
|
|
39197
|
+
notifyWikiMacroLocks(locks) {
|
|
39198
|
+
this.macroLocks = locks;
|
|
39199
|
+
this.macroLocksKnown = true;
|
|
39200
|
+
this.macroLocksListeners.forEach((listener) => {
|
|
39201
|
+
try {
|
|
39202
|
+
listener(locks);
|
|
39203
|
+
} catch (error2) {
|
|
39204
|
+
logger$31.error("Wiki macro lock listener failed");
|
|
39205
|
+
}
|
|
39206
|
+
});
|
|
39207
|
+
}
|
|
38726
39208
|
getBaseURL() {
|
|
38727
39209
|
const parsedURL = new URL(this.url);
|
|
38728
39210
|
const protocol = parsedURL.protocol === "wss:" ? "https:" : "http:";
|
|
@@ -38817,6 +39299,10 @@ ${codeText}
|
|
|
38817
39299
|
const msg = message;
|
|
38818
39300
|
if (this.connection)
|
|
38819
39301
|
this.connection.lastReceiveTime = Date.now();
|
|
39302
|
+
if (msg.a === "wikiMacro") {
|
|
39303
|
+
this.handleWikiMacroReply(msg);
|
|
39304
|
+
return;
|
|
39305
|
+
}
|
|
38820
39306
|
if ("err" in msg || msg.a === "pong") {
|
|
38821
39307
|
this.handleMessage(msg);
|
|
38822
39308
|
} else {
|
|
@@ -38833,6 +39319,7 @@ ${codeText}
|
|
|
38833
39319
|
this.emit("ready");
|
|
38834
39320
|
this.ready = true;
|
|
38835
39321
|
this.connectionDisconnected = false;
|
|
39322
|
+
this.loadWikiMacroLocks();
|
|
38836
39323
|
}
|
|
38837
39324
|
}
|
|
38838
39325
|
try {
|
|
@@ -38910,6 +39397,10 @@ ${codeText}
|
|
|
38910
39397
|
end(logout) {
|
|
38911
39398
|
var _a, _b, _c, _d, _e;
|
|
38912
39399
|
this.closed = true;
|
|
39400
|
+
this.clearWikiMacroRequests("Document connection closed");
|
|
39401
|
+
this.macroLocksListeners.clear();
|
|
39402
|
+
this.macroLocks = [];
|
|
39403
|
+
this.macroLocksKnown = false;
|
|
38913
39404
|
this.renewTokenFunc = void 0;
|
|
38914
39405
|
this.removeAllListeners();
|
|
38915
39406
|
(_a = this.autoRenewToken) == null ? void 0 : _a.destroy();
|
|
@@ -39204,10 +39695,16 @@ ${codeText}
|
|
|
39204
39695
|
return versions;
|
|
39205
39696
|
}
|
|
39206
39697
|
async getVersion(ver) {
|
|
39698
|
+
return (await this.getVersionSnapshot(ver)).doc;
|
|
39699
|
+
}
|
|
39700
|
+
async getVersionSnapshot(ver) {
|
|
39207
39701
|
const server = this.apiServer();
|
|
39208
39702
|
const api = `${server}/versions/${ver}`;
|
|
39209
39703
|
const ret = await this.request(api);
|
|
39210
|
-
return
|
|
39704
|
+
return {
|
|
39705
|
+
doc: JSON.parse(ret.data.data),
|
|
39706
|
+
documentVersion: typeof ret.data.documentVersion === "number" ? ret.data.documentVersion : void 0
|
|
39707
|
+
};
|
|
39211
39708
|
}
|
|
39212
39709
|
async getLatestVersion() {
|
|
39213
39710
|
const server = this.apiServer();
|
|
@@ -40218,6 +40715,21 @@ ${codeText}
|
|
|
40218
40715
|
this.editStatus = new EditStatus(options);
|
|
40219
40716
|
this.client.connection.addListener("opReceived", this.handleOpReceived);
|
|
40220
40717
|
}
|
|
40718
|
+
requestWikiMacro(message) {
|
|
40719
|
+
if (this.destroyed) {
|
|
40720
|
+
return Promise.reject(new WikiMacroError({ code: "RESOURCE_SERVICE_UNAVAILABLE", message: "Document destroyed" }));
|
|
40721
|
+
}
|
|
40722
|
+
if (this.getUser().permission !== "w" && message.operation !== "locks" && message.operation !== "getEditResult" && message.operation !== "cancelEdit") {
|
|
40723
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY" }));
|
|
40724
|
+
}
|
|
40725
|
+
return this.client.connection.requestWikiMacro(message);
|
|
40726
|
+
}
|
|
40727
|
+
onWikiMacroLocks(listener) {
|
|
40728
|
+
return this.client.connection.onWikiMacroLocks(listener);
|
|
40729
|
+
}
|
|
40730
|
+
getDocumentVersion() {
|
|
40731
|
+
return typeof this.doc.version === "number" ? this.doc.version : void 0;
|
|
40732
|
+
}
|
|
40221
40733
|
beginBatchUpdate() {
|
|
40222
40734
|
this.doc.preventCompose = false;
|
|
40223
40735
|
this.batching++;
|
|
@@ -40635,6 +41147,10 @@ ${codeText}
|
|
|
40635
41147
|
const data2 = await this.client.getVersion(ver);
|
|
40636
41148
|
return editorDoc2DocObject(data2);
|
|
40637
41149
|
}
|
|
41150
|
+
async getVersionSnapshot(ver) {
|
|
41151
|
+
const snapshot2 = await this.client.getVersionSnapshot(ver);
|
|
41152
|
+
return { doc: editorDoc2DocObject(snapshot2.doc), documentVersion: snapshot2.documentVersion };
|
|
41153
|
+
}
|
|
40638
41154
|
async getLatestVersion() {
|
|
40639
41155
|
const doc2 = await this.client.getLatestVersion();
|
|
40640
41156
|
return editorDoc2DocObject(doc2);
|
|
@@ -40981,7 +41497,8 @@ ${codeText}
|
|
|
40981
41497
|
class ShareDBLocalDoc extends LocalDoc {
|
|
40982
41498
|
constructor(docObject, _options) {
|
|
40983
41499
|
super(docObject, {
|
|
40984
|
-
serverUrl: _options.serverUrl
|
|
41500
|
+
serverUrl: _options.serverUrl,
|
|
41501
|
+
documentVersion: _options.documentVersion
|
|
40985
41502
|
});
|
|
40986
41503
|
__publicField(this, "_client");
|
|
40987
41504
|
this._options = _options;
|
|
@@ -41088,10 +41605,16 @@ ${codeText}
|
|
|
41088
41605
|
return versions;
|
|
41089
41606
|
}
|
|
41090
41607
|
async getVersion(ver) {
|
|
41608
|
+
return (await this.getVersionSnapshot(ver)).doc;
|
|
41609
|
+
}
|
|
41610
|
+
async getVersionSnapshot(ver) {
|
|
41091
41611
|
const server = this.apiServer();
|
|
41092
41612
|
const api = `${server}/versions/${ver}`;
|
|
41093
41613
|
const ret = await this.request(api);
|
|
41094
|
-
return
|
|
41614
|
+
return {
|
|
41615
|
+
doc: JSON.parse(ret.data.data),
|
|
41616
|
+
documentVersion: typeof ret.data.documentVersion === "number" ? ret.data.documentVersion : void 0
|
|
41617
|
+
};
|
|
41095
41618
|
}
|
|
41096
41619
|
async getLatestVersion() {
|
|
41097
41620
|
const server = this.apiServer();
|
|
@@ -41215,6 +41738,10 @@ ${codeText}
|
|
|
41215
41738
|
const data2 = await this.client.getVersion(ver);
|
|
41216
41739
|
return editorDoc2DocObject(data2);
|
|
41217
41740
|
}
|
|
41741
|
+
async getVersionSnapshot(ver) {
|
|
41742
|
+
const snapshot2 = await this.client.getVersionSnapshot(ver);
|
|
41743
|
+
return { doc: editorDoc2DocObject(snapshot2.doc), documentVersion: snapshot2.documentVersion };
|
|
41744
|
+
}
|
|
41218
41745
|
async getLatestVersion() {
|
|
41219
41746
|
const doc2 = await this.client.getLatestVersion();
|
|
41220
41747
|
return editorDoc2DocObject(doc2);
|
|
@@ -63804,6 +64331,8 @@ $$${mathData.mathjaxText}$$
|
|
|
63804
64331
|
const blockId = item.data;
|
|
63805
64332
|
try {
|
|
63806
64333
|
const block = editor.getBlockById(blockId);
|
|
64334
|
+
if ((item.id === "delete" || item.id === "cut") && isWikiMacroElementLocked(editor, block))
|
|
64335
|
+
return;
|
|
63807
64336
|
if (item.id === "delete") {
|
|
63808
64337
|
this.deleteBlock(editor, block);
|
|
63809
64338
|
return;
|
|
@@ -63823,6 +64352,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63823
64352
|
commands(editor, blockElement) {
|
|
63824
64353
|
const locked = isBlockLocked(editor, blockElement);
|
|
63825
64354
|
const lockedBySelf = locked && isBlockLockedBySelf(editor, blockElement);
|
|
64355
|
+
const macroLeased = isWikiMacroElementLocked(editor, blockElement);
|
|
63826
64356
|
const data2 = getBlockId(blockElement);
|
|
63827
64357
|
const isEnvSecure = window.isSecureContext;
|
|
63828
64358
|
const isBlockExclusive = isExclusiveBlock(blockElement);
|
|
@@ -63844,7 +64374,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63844
64374
|
data: data2,
|
|
63845
64375
|
icon: CutIcon,
|
|
63846
64376
|
order: 20,
|
|
63847
|
-
states: locked && !lockedBySelf || !isEnvSecure || isBlockExclusive ? ["disabled"] : [],
|
|
64377
|
+
states: macroLeased || locked && !lockedBySelf || !isEnvSecure || isBlockExclusive ? ["disabled"] : [],
|
|
63848
64378
|
disableReason: !isEnvSecure ? i18n$1.t("copyCutProperty.unsafeEnvTips", {
|
|
63849
64379
|
shortCut: shortcutToDisplayText("CtrlOrCmd+X"),
|
|
63850
64380
|
operation: i18n$1.t("copyCutProperty.cut")
|
|
@@ -63856,7 +64386,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63856
64386
|
data: data2,
|
|
63857
64387
|
icon: DeleteIcon,
|
|
63858
64388
|
order: 30,
|
|
63859
|
-
states: locked && !lockedBySelf || isBlockExclusive ? ["disabled"] : []
|
|
64389
|
+
states: macroLeased || locked && !lockedBySelf || isBlockExclusive ? ["disabled"] : []
|
|
63860
64390
|
};
|
|
63861
64391
|
return {
|
|
63862
64392
|
group: "standard-block-actions",
|
|
@@ -63897,6 +64427,15 @@ $$${mathData.mathjaxText}$$
|
|
|
63897
64427
|
this.menu.updateItems(items);
|
|
63898
64428
|
this.commandBlock = this.currentBlock;
|
|
63899
64429
|
});
|
|
64430
|
+
__publicField(this, "handleMacroLocksChanged", () => {
|
|
64431
|
+
if (!this.menu.isVisible)
|
|
64432
|
+
return;
|
|
64433
|
+
if (!this.currentBlock || !this.editor.contains(this.currentBlock)) {
|
|
64434
|
+
this.close();
|
|
64435
|
+
return;
|
|
64436
|
+
}
|
|
64437
|
+
this.handleShow();
|
|
64438
|
+
});
|
|
63900
64439
|
__publicField(this, "handleClose", () => {
|
|
63901
64440
|
if (shouldFocusToEditor(this.editor)) {
|
|
63902
64441
|
this.editor.focus();
|
|
@@ -63922,6 +64461,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63922
64461
|
this.menu.on("close", this.handleClose);
|
|
63923
64462
|
this.menu.on("click", this.handleItemClick);
|
|
63924
64463
|
editor.blockHooks.push(new StandardBlockActionHook());
|
|
64464
|
+
editor.addListener("wikiMacroLocksChanged", this.handleMacroLocksChanged);
|
|
63925
64465
|
}
|
|
63926
64466
|
addFilter(id, filter) {
|
|
63927
64467
|
var _a, _b;
|
|
@@ -63943,6 +64483,7 @@ $$${mathData.mathjaxText}$$
|
|
|
63943
64483
|
return this.menu.isVisible;
|
|
63944
64484
|
}
|
|
63945
64485
|
destroy() {
|
|
64486
|
+
this.editor.removeListener("wikiMacroLocksChanged", this.handleMacroLocksChanged);
|
|
63946
64487
|
this.menu.destroy();
|
|
63947
64488
|
}
|
|
63948
64489
|
}
|
|
@@ -83480,11 +84021,21 @@ ${docStr}
|
|
|
83480
84021
|
assert(logger$C, false, "no local actions for history doc");
|
|
83481
84022
|
}
|
|
83482
84023
|
class HistoryDoc extends EventCallbacks {
|
|
83483
|
-
constructor(server, docObject, editorOptions) {
|
|
84024
|
+
constructor(server, docObject, editorOptions, documentVersion) {
|
|
83484
84025
|
super();
|
|
83485
84026
|
this.server = server;
|
|
83486
84027
|
this.docObject = docObject;
|
|
83487
84028
|
this.editorOptions = editorOptions;
|
|
84029
|
+
this.documentVersion = documentVersion;
|
|
84030
|
+
}
|
|
84031
|
+
requestWikiMacro(message) {
|
|
84032
|
+
return Promise.reject(new WikiMacroError({ code: "READ_ONLY", message: "History documents cannot edit Wiki macros" }));
|
|
84033
|
+
}
|
|
84034
|
+
onWikiMacroLocks(listener) {
|
|
84035
|
+
throw new WikiMacroError({ code: "READ_ONLY", message: "History documents have no macro lock channel" });
|
|
84036
|
+
}
|
|
84037
|
+
getDocumentVersion() {
|
|
84038
|
+
return this.documentVersion;
|
|
83488
84039
|
}
|
|
83489
84040
|
beginBatchUpdate() {
|
|
83490
84041
|
return 0;
|
|
@@ -84477,6 +85028,7 @@ ${docStr}
|
|
|
84477
85028
|
const forceRequestVersionAsLatest = !!((_d = this.versionOptions) == null ? void 0 : _d.forceRequestVersionAsLatest);
|
|
84478
85029
|
let docObject;
|
|
84479
85030
|
let historyData;
|
|
85031
|
+
let snapshotVersion;
|
|
84480
85032
|
if (from) {
|
|
84481
85033
|
const requestVersion = forceRequestVersionAsLatest ? -1 : Math.max(version.version, from);
|
|
84482
85034
|
const requestFrom = forceRequestVersionAsLatest ? from : Math.min(version.version, from);
|
|
@@ -84484,12 +85036,18 @@ ${docStr}
|
|
|
84484
85036
|
docObject = ret.doc;
|
|
84485
85037
|
historyData = ret.historyData;
|
|
84486
85038
|
} else {
|
|
84487
|
-
|
|
85039
|
+
if (this.versionHelper.getVersionSnapshot) {
|
|
85040
|
+
const snapshot2 = await this.versionHelper.getVersionSnapshot(version.version);
|
|
85041
|
+
docObject = snapshot2.doc;
|
|
85042
|
+
snapshotVersion = snapshot2.documentVersion;
|
|
85043
|
+
} else {
|
|
85044
|
+
docObject = await this.versionHelper.getVersion(version.version);
|
|
85045
|
+
}
|
|
84488
85046
|
historyData = [];
|
|
84489
85047
|
}
|
|
84490
85048
|
const { editorContainer: editorElement } = this.components;
|
|
84491
85049
|
editorElement.innerHTML = "";
|
|
84492
|
-
const historyDoc = new HistoryDoc(this.server, docObject, this.editorOptions);
|
|
85050
|
+
const historyDoc = new HistoryDoc(this.server, docObject, this.editorOptions, snapshotVersion);
|
|
84493
85051
|
const viewer = this.provider.createHistoryEditor(editorElement, historyDoc);
|
|
84494
85052
|
viewer.editorBlockRenders.registerRender(new OnesEditorHistoryRender());
|
|
84495
85053
|
viewer.editorBoxes.registerBoxClass(HistoryDeletedTextBox);
|
|
@@ -84696,7 +85254,7 @@ ${docStr}
|
|
|
84696
85254
|
}
|
|
84697
85255
|
async function createOnesEditorHistoryDiff(parent, options) {
|
|
84698
85256
|
var _a;
|
|
84699
|
-
const historyDoc = new HistoryDoc(options.server, options.doc, options.editorOptions);
|
|
85257
|
+
const historyDoc = new HistoryDoc(options.server, options.doc, options.editorOptions, options.documentVersion);
|
|
84700
85258
|
const viewer = options.provider.createHistoryEditor(parent, historyDoc);
|
|
84701
85259
|
viewer.editorBlockRenders.registerRender(new OnesEditorHistoryRender());
|
|
84702
85260
|
viewer.editorBoxes.registerBoxClass(HistoryDeletedTextBox);
|
|
@@ -97862,7 +98420,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97862
98420
|
}
|
|
97863
98421
|
}
|
|
97864
98422
|
});
|
|
97865
|
-
editor.version = "5.0.
|
|
98423
|
+
editor.version = "5.0.6-beta.DNP8216.1";
|
|
97866
98424
|
return editor;
|
|
97867
98425
|
}
|
|
97868
98426
|
function isDoc(doc2) {
|
|
@@ -97998,7 +98556,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
97998
98556
|
OnesEditorDropTarget.register(editor);
|
|
97999
98557
|
OnesEditorTocProvider.register(editor);
|
|
98000
98558
|
OnesEditorExclusiveBlock.register(editor);
|
|
98001
|
-
editor.version = "5.0.
|
|
98559
|
+
editor.version = "5.0.6-beta.DNP8216.1";
|
|
98002
98560
|
return editor;
|
|
98003
98561
|
} catch (error2) {
|
|
98004
98562
|
try {
|
|
@@ -98141,7 +98699,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
98141
98699
|
}
|
|
98142
98700
|
}
|
|
98143
98701
|
});
|
|
98144
|
-
editor.version = "5.0.
|
|
98702
|
+
editor.version = "5.0.6-beta.DNP8216.1";
|
|
98145
98703
|
return editor;
|
|
98146
98704
|
}
|
|
98147
98705
|
const emojis$1 = {
|
|
@@ -144162,6 +144720,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
144162
144720
|
exports2.WarningFilledIcon = WarningFilledIcon;
|
|
144163
144721
|
exports2.WarningIcon = WarningIcon;
|
|
144164
144722
|
exports2.WebPageIcon = WebPageIcon;
|
|
144723
|
+
exports2.WikiMacroError = WikiMacroError;
|
|
144165
144724
|
exports2.YoukuIcon = YoukuIcon;
|
|
144166
144725
|
exports2.ZERO_WIDTH_SPACE_CHAR = ZERO_WIDTH_SPACE_CHAR;
|
|
144167
144726
|
exports2.abbreviation = abbreviation;
|
|
@@ -144616,6 +145175,7 @@ ${JSON.stringify(error2, null, 2)}`);
|
|
|
144616
145175
|
exports2.isToday = isToday;
|
|
144617
145176
|
exports2.isValidOffset = isValidOffset;
|
|
144618
145177
|
exports2.isVisibleBlock = isVisibleBlock;
|
|
145178
|
+
exports2.isWikiMacroElementLocked = isWikiMacroElementLocked;
|
|
144619
145179
|
exports2.isYesterday = isYesterday;
|
|
144620
145180
|
exports2.loadJs = loadJs;
|
|
144621
145181
|
exports2.loadJsPromise = loadJsPromise;
|