@ones-editor/editor 3.1.2-beta.2 → 3.1.2-beta.ONES22301271.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/dist/index.js CHANGED
@@ -27250,9 +27250,16 @@ var __publicField = (obj, key, value) => {
27250
27250
  const logger$3I = getLogger("delete-block");
27251
27251
  function getAllChildContainers(editor, blockData, containerIds) {
27252
27252
  if (blockData.children) {
27253
- containerIds.push(...blockData.children);
27254
27253
  blockData.children.forEach((childContainerId) => {
27255
- const childBlocks = editor.getChildContainerData(childContainerId);
27254
+ if (containerIds.has(childContainerId)) {
27255
+ return;
27256
+ }
27257
+ const childBlocks = editor.doc.findContainerBlocks(childContainerId);
27258
+ if (!Array.isArray(childBlocks)) {
27259
+ logger$3I.warn(`skip invalid child container while deleting: parentBlock=${blockData.id}, container=${childContainerId}`);
27260
+ return;
27261
+ }
27262
+ containerIds.add(childContainerId);
27256
27263
  childBlocks.forEach((childBlock) => {
27257
27264
  getAllChildContainers(editor, childBlock, containerIds);
27258
27265
  });
@@ -27284,31 +27291,31 @@ var __publicField = (obj, key, value) => {
27284
27291
  }
27285
27292
  }
27286
27293
  const blockData = editorDeleteBlockWithoutChildren(editor, block, newRange);
27287
- const childContainerIds = [];
27294
+ const childContainerIds = /* @__PURE__ */ new Set();
27288
27295
  getAllChildContainers(editor, blockData, childContainerIds);
27289
- if (childContainerIds.length > 0) {
27290
- editor.doc.localDeleteChildContainers(childContainerIds);
27296
+ if (childContainerIds.size > 0) {
27297
+ editor.doc.localDeleteChildContainers(Array.from(childContainerIds));
27291
27298
  }
27292
27299
  return blockData;
27293
27300
  });
27294
27301
  }
27295
27302
  function editorDeleteChildContainer(editor, containerId) {
27296
- const containerIds = [containerId];
27303
+ const containerIds = /* @__PURE__ */ new Set([containerId]);
27297
27304
  const childBlocks = editor.doc.getContainerBlocks(containerId);
27298
27305
  childBlocks.forEach((childBlock) => {
27299
27306
  getAllChildContainers(editor, childBlock, containerIds);
27300
27307
  });
27301
- editor.doc.localDeleteChildContainers(containerIds);
27308
+ editor.doc.localDeleteChildContainers(Array.from(containerIds));
27302
27309
  }
27303
27310
  function editorDeleteChildContainers(editor, childContainerIds) {
27304
- const containerIds = [...childContainerIds];
27311
+ const containerIds = new Set(childContainerIds);
27305
27312
  childContainerIds.forEach((containerId) => {
27306
27313
  const childBlocks = editor.doc.getContainerBlocks(containerId);
27307
27314
  childBlocks.forEach((childBlock) => {
27308
27315
  getAllChildContainers(editor, childBlock, containerIds);
27309
27316
  });
27310
27317
  });
27311
- editor.doc.localDeleteChildContainers(containerIds);
27318
+ editor.doc.localDeleteChildContainers(Array.from(containerIds));
27312
27319
  }
27313
27320
  const logger$3H = getLogger("merge-text-block");
27314
27321
  function editorMergeTextBlock(editor, block1, block2) {
@@ -32135,7 +32142,7 @@ ${codeText}
32135
32142
  const logger$3a = getLogger("editor");
32136
32143
  class Editor extends tinyTypedEmitter.TypedEmitter {
32137
32144
  constructor(parent, doc2, optionalOptions) {
32138
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
32145
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
32139
32146
  super();
32140
32147
  __publicField(this, "parent");
32141
32148
  __publicField(this, "rootElement");
@@ -32180,22 +32187,27 @@ ${codeText}
32180
32187
  this.setMaxListeners(100);
32181
32188
  this.options = {
32182
32189
  colors: (_a = optionalOptions == null ? void 0 : optionalOptions.colors) != null ? _a : ["#B21B57", "#008796", "#7241CC", "#CC4C08", "#5D8F00", "#BD2C1C", "#D17D00"],
32183
- componentsOptions: (_c = (_b = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _b.options) != null ? _c : {},
32190
+ readonly: (_b = optionalOptions == null ? void 0 : optionalOptions.readonly) != null ? _b : false,
32191
+ componentsOptions: (_d = (_c = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _c.options) != null ? _d : {},
32184
32192
  scrollContainer: optionalOptions == null ? void 0 : optionalOptions.scrollContainer,
32185
- enableComments: (_d = optionalOptions == null ? void 0 : optionalOptions.enableComments) != null ? _d : true,
32186
- enableResolveComments: (_e = optionalOptions == null ? void 0 : optionalOptions.enableResolveComments) != null ? _e : true,
32187
- enableContextMenu: (_f = optionalOptions == null ? void 0 : optionalOptions.enableContextMenu) != null ? _f : true,
32188
- dateTimeFormatter: (_g = optionalOptions == null ? void 0 : optionalOptions.dateTimeFormatter) != null ? _g : (v) => v.toLocaleString()
32193
+ enableComments: (_e = optionalOptions == null ? void 0 : optionalOptions.enableComments) != null ? _e : true,
32194
+ enableResolveComments: (_f = optionalOptions == null ? void 0 : optionalOptions.enableResolveComments) != null ? _f : true,
32195
+ enableContextMenu: (_g = optionalOptions == null ? void 0 : optionalOptions.enableContextMenu) != null ? _g : true,
32196
+ dateTimeFormatter: (_h = optionalOptions == null ? void 0 : optionalOptions.dateTimeFormatter) != null ? _h : (v) => v.toLocaleString()
32189
32197
  };
32190
- this.settingsProvider = (_h = optionalOptions == null ? void 0 : optionalOptions.settingsProvider) != null ? _h : new DefaultSettingsProvider(this);
32198
+ this._readonly = this.options.readonly;
32199
+ this.settingsProvider = (_i = optionalOptions == null ? void 0 : optionalOptions.settingsProvider) != null ? _i : new DefaultSettingsProvider(this);
32191
32200
  registerComponents(this, optionalOptions == null ? void 0 : optionalOptions.components);
32192
- this.blockHooks.push(...(_j = (_i = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _i.blockHooks) != null ? _j : []);
32193
- this.id = (_k = optionalOptions == null ? void 0 : optionalOptions.id) != null ? _k : genId();
32201
+ this.blockHooks.push(...(_k = (_j = optionalOptions == null ? void 0 : optionalOptions.components) == null ? void 0 : _j.blockHooks) != null ? _k : []);
32202
+ this.id = (_l = optionalOptions == null ? void 0 : optionalOptions.id) != null ? _l : genId();
32194
32203
  this.clientId = genId();
32195
32204
  this.undoManager = new UndoManager(this);
32196
32205
  this.doc = new EditorDoc(this, doc2, this.undoManager);
32197
32206
  this.parent = parent;
32198
32207
  this.rootElement = createElement("div", ["editor-root"], this.parent);
32208
+ if (this._readonly) {
32209
+ addClass(this.rootElement, "readonly");
32210
+ }
32199
32211
  this.rootElement.setAttribute("data-editor-client-id", this.clientId);
32200
32212
  this.contentElement = createElement("div", ["editor-content"], this.rootElement);
32201
32213
  this.rootContainerObject = createRootContainer(this);
@@ -32213,7 +32225,7 @@ ${codeText}
32213
32225
  addClass(this.rootElement, "safari");
32214
32226
  }
32215
32227
  if (this._readonly) {
32216
- addClass(this.rootElement, "readonly");
32228
+ this.readonly = true;
32217
32229
  }
32218
32230
  this.emit("load", this, false);
32219
32231
  }
@@ -64281,7 +64293,7 @@ $$${mathData.mathjaxText}$$
64281
64293
  return attributes.filter((attribute) => attribute.startsWith("comment-")).map((attribute) => attribute.replace("comment-", ""));
64282
64294
  }
64283
64295
  const logger$1I = getLogger("doc-comments");
64284
- function addBlockComments$1(doc2, block, result, resultSet) {
64296
+ function addBlockComments$1(doc2, block, result, resultSet, invalidContainers) {
64285
64297
  if (block.comments) {
64286
64298
  const blockComments = block.comments;
64287
64299
  if (Array.isArray(blockComments)) {
@@ -64317,19 +64329,23 @@ $$${mathData.mathjaxText}$$
64317
64329
  children.forEach((childContainerId) => {
64318
64330
  const childBlocks = doc2.blocks[childContainerId];
64319
64331
  if (!Array.isArray(childBlocks)) {
64320
- logger$1I.error(`skip invalid comment child container: parent=${block.id}, container=${childContainerId}`);
64332
+ if (!invalidContainers.has(childContainerId)) {
64333
+ invalidContainers.add(childContainerId);
64334
+ logger$1I.warn(`skip invalid comment child container: parentBlock=${block.id}, container=${childContainerId}`);
64335
+ }
64321
64336
  return;
64322
64337
  }
64323
64338
  childBlocks.forEach((subBlock) => {
64324
- addBlockComments$1(doc2, subBlock, result, resultSet);
64339
+ addBlockComments$1(doc2, subBlock, result, resultSet, invalidContainers);
64325
64340
  });
64326
64341
  });
64327
64342
  }
64328
64343
  function getCommentsFromDoc(doc2) {
64329
64344
  const result = [];
64330
64345
  const resultSet = /* @__PURE__ */ new Set();
64346
+ const invalidContainers = /* @__PURE__ */ new Set();
64331
64347
  doc2.blocks.root.forEach((block) => {
64332
- addBlockComments$1(doc2, block, result, resultSet);
64348
+ addBlockComments$1(doc2, block, result, resultSet, invalidContainers);
64333
64349
  });
64334
64350
  const resultMap = /* @__PURE__ */ new Map();
64335
64351
  result.forEach((commentId, index2) => resultMap.set(commentId, index2));
@@ -71511,7 +71527,7 @@ ${codeText}
71511
71527
  }
71512
71528
  }
71513
71529
  const logger$1f = getLogger("block-comments");
71514
- function addBlockComments(doc2, block, resultMap) {
71530
+ function addBlockComments(doc2, block, resultMap, invalidContainers) {
71515
71531
  if (block.comments) {
71516
71532
  const blockComments = block.comments;
71517
71533
  if (Array.isArray(blockComments)) {
@@ -71551,18 +71567,22 @@ ${codeText}
71551
71567
  children.forEach((childContainerId) => {
71552
71568
  const childBlocks = doc2.blocks[childContainerId];
71553
71569
  if (!Array.isArray(childBlocks)) {
71554
- logger$1f.error(`skip invalid comment child container: parent=${block.id}, container=${childContainerId}`);
71570
+ if (!invalidContainers.has(childContainerId)) {
71571
+ invalidContainers.add(childContainerId);
71572
+ logger$1f.warn(`skip invalid comment child container: parentBlock=${block.id}, container=${childContainerId}`);
71573
+ }
71555
71574
  return;
71556
71575
  }
71557
71576
  childBlocks.forEach((subBlock) => {
71558
- addBlockComments(doc2, subBlock, resultMap);
71577
+ addBlockComments(doc2, subBlock, resultMap, invalidContainers);
71559
71578
  });
71560
71579
  });
71561
71580
  }
71562
71581
  function getBlockCommentsFromDoc(doc2) {
71563
71582
  const resultMap = /* @__PURE__ */ new Map();
71583
+ const invalidContainers = /* @__PURE__ */ new Set();
71564
71584
  doc2.blocks.root.forEach((block) => {
71565
- addBlockComments(doc2, block, resultMap);
71585
+ addBlockComments(doc2, block, resultMap, invalidContainers);
71566
71586
  });
71567
71587
  return resultMap;
71568
71588
  }
@@ -97080,7 +97100,7 @@ ${JSON.stringify(error2, null, 2)}`);
97080
97100
  }
97081
97101
  }
97082
97102
  });
97083
- editor.version = "3.1.2-beta.2";
97103
+ editor.version = "3.1.2-beta.ONES22301271.2";
97084
97104
  return editor;
97085
97105
  }
97086
97106
  function isDoc(doc2) {
@@ -97099,35 +97119,31 @@ ${JSON.stringify(error2, null, 2)}`);
97099
97119
  const enableComments = options == null ? void 0 : options.enableComments;
97100
97120
  const quickMenu = (_c = (_b = options.componentsOptions) == null ? void 0 : _b.quickMenu) != null ? _c : { id: "quick-menu", trigger: ["/"], commandProviders: [] };
97101
97121
  (_d = quickMenu.commandProviders) == null ? void 0 : _d.push(new GraphCommandProvider());
97102
- let editorForCleanup;
97122
+ const editor = createEditor(root2, doc2, {
97123
+ id: options.id,
97124
+ readonly: options.readonly,
97125
+ scrollContainer: options == null ? void 0 : options.scrollContainer,
97126
+ enableResolveComments: options == null ? void 0 : options.enableResolveComments,
97127
+ enableComments,
97128
+ dateTimeFormatter: options.dateTimeFormatter,
97129
+ components: {
97130
+ blocks: [...StandardBlocks, ...(_f = (_e = options.components) == null ? void 0 : _e.blocks) != null ? _f : []],
97131
+ commandProviders: [new TableBlockCommandProvider()],
97132
+ decorators: [new CodeTextDecorator(), new RemoteCaretsDecorator()],
97133
+ embeds: [...StandardEmbeds, ...((_g = options.components) == null ? void 0 : _g.embeds) || []],
97134
+ boxes: [MathjaxBox, MentionBox, FileBox, StatusBox, ...((_h = options.components) == null ? void 0 : _h.boxes) || []],
97135
+ insertions: [RemoteCaretsInsertion],
97136
+ blockHooks: [...((_i = options.components) == null ? void 0 : _i.blockHooks) || []],
97137
+ textRenders: [
97138
+ enableComments && new OnesEditorCommentsRender(),
97139
+ new BlockPaddingRender(),
97140
+ ...((_j = options.components) == null ? void 0 : _j.textRenders) || []
97141
+ ].filter(Boolean),
97142
+ options: { ...options.componentsOptions, quickMenu }
97143
+ },
97144
+ shortcuts: [TableShortcuts, FindReplaceShortcuts, TextStyleShortcuts, DefaultShortcuts]
97145
+ });
97103
97146
  try {
97104
- const editor = createEditor(root2, doc2, {
97105
- id: options.id,
97106
- scrollContainer: options == null ? void 0 : options.scrollContainer,
97107
- enableResolveComments: options == null ? void 0 : options.enableResolveComments,
97108
- enableComments,
97109
- dateTimeFormatter: options.dateTimeFormatter,
97110
- components: {
97111
- blocks: [...StandardBlocks, ...(_f = (_e = options.components) == null ? void 0 : _e.blocks) != null ? _f : []],
97112
- commandProviders: [new TableBlockCommandProvider()],
97113
- decorators: [new CodeTextDecorator(), new RemoteCaretsDecorator()],
97114
- embeds: [...StandardEmbeds, ...((_g = options.components) == null ? void 0 : _g.embeds) || []],
97115
- boxes: [MathjaxBox, MentionBox, FileBox, StatusBox, ...((_h = options.components) == null ? void 0 : _h.boxes) || []],
97116
- insertions: [RemoteCaretsInsertion],
97117
- blockHooks: [...((_i = options.components) == null ? void 0 : _i.blockHooks) || []],
97118
- textRenders: [
97119
- enableComments && new OnesEditorCommentsRender(),
97120
- new BlockPaddingRender(),
97121
- ...((_j = options.components) == null ? void 0 : _j.textRenders) || []
97122
- ].filter(Boolean),
97123
- options: { ...options.componentsOptions, quickMenu }
97124
- },
97125
- shortcuts: [TableShortcuts, FindReplaceShortcuts, TextStyleShortcuts, DefaultShortcuts]
97126
- });
97127
- editorForCleanup = editor;
97128
- if (options.readonly) {
97129
- editor.readonly = true;
97130
- }
97131
97147
  if (options.compact) {
97132
97148
  addClass(editor.rootElement, "compact");
97133
97149
  if (options.headingButton === false)
@@ -97220,19 +97236,14 @@ ${JSON.stringify(error2, null, 2)}`);
97220
97236
  OnesEditorDropTarget.register(editor);
97221
97237
  OnesEditorTocProvider.register(editor);
97222
97238
  OnesEditorExclusiveBlock.register(editor);
97223
- editor.version = "3.1.2-beta.2";
97239
+ editor.version = "3.1.2-beta.ONES22301271.2";
97224
97240
  return editor;
97225
97241
  } catch (error2) {
97226
- if (editorForCleanup) {
97227
- try {
97228
- editorForCleanup.destroy();
97229
- } catch (destroyError) {
97230
- logger.error(destroyError);
97231
- }
97232
- } else {
97233
- doc2.destroy();
97242
+ try {
97243
+ editor.destroy();
97244
+ } catch (destroyError) {
97245
+ logger.error(`failed to rollback local editor: ${destroyError.message}`);
97234
97246
  }
97235
- root2.replaceChildren();
97236
97247
  throw error2;
97237
97248
  }
97238
97249
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "3.1.2-beta.2",
3
+ "version": "3.1.2-beta.ONES22301271.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {