@ones-editor/editor 2.9.8-beta.21 → 2.9.8-beta.22

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.
@@ -7,7 +7,7 @@ export default class ListProvider implements OnesEditorCommandProvider {
7
7
  getAvailableCommands(editor: OnesEditor, block: BlockElement, range: SelectionRange, params?: CommandParams): CommandItem[];
8
8
  getInsertCommands(): CommandItem[];
9
9
  convertToList(editor: OnesEditor, block: BlockElement, listType: 'unordered' | 'ordered' | 'unchecked'): void;
10
- insertList(editor: OnesEditor, containerId: string, blockIndex: number, listType: 'unordered' | 'ordered' | 'unchecked'): void;
10
+ insertList(editor: OnesEditor, containerId: string, blockIndex: number, listType: 'unordered' | 'ordered' | 'unchecked', command: CommandItem): void;
11
11
  executeCommand(editor: OnesEditor, block: BlockElement, range: SelectionRange, command: CommandItem): boolean;
12
12
  executeInsertCommand: (editor: OnesEditor, containerId: string, blockIndex: number, command: CommandItem) => boolean;
13
13
  }
package/dist/index.js CHANGED
@@ -28825,10 +28825,19 @@ var __publicField = (obj, key, value) => {
28825
28825
  });
28826
28826
  this.editor = editor;
28827
28827
  const block = editor.getFirstBlock();
28828
- const blockId = getBlockId(block);
28829
28828
  this.caret = new EditorCaret(editor);
28830
- const pos = createSimpleBlockPosition(blockId, 0, "normal");
28831
- this._range = createEditorSelectionRange(editor, { anchor: pos, focus: pos });
28829
+ if (isComplexKindBlock(editor, block)) {
28830
+ const simpleBlock = complexBlockGetFirstSimpleChild(editor, block, {
28831
+ visibleOnly: true
28832
+ }) || block;
28833
+ const blockId = getBlockId(simpleBlock);
28834
+ const pos = createSimpleBlockPosition(blockId, 0, "normal");
28835
+ this._range = createEditorSelectionRange(editor, { anchor: pos, focus: pos });
28836
+ } else {
28837
+ const blockId = getBlockId(block);
28838
+ const pos = createSimpleBlockPosition(blockId, 0, "normal");
28839
+ this._range = createEditorSelectionRange(editor, { anchor: pos, focus: pos });
28840
+ }
28832
28841
  this.lastCaretRect = null;
28833
28842
  this.editor.addListener("blockDeleted", this.handleBlockDelete);
28834
28843
  setTimeout(() => {
@@ -43871,6 +43880,9 @@ ${codeText}
43871
43880
  __publicField(this, "handlePaletteClick", (type, value) => {
43872
43881
  this.setLatestColors(type, value);
43873
43882
  this.emit("onClick", type, value);
43883
+ setTimeout(() => {
43884
+ this.editor.emit("textColorChanged", this.editor, this);
43885
+ }, 100);
43874
43886
  });
43875
43887
  __publicField(this, "handleButtonClick", () => {
43876
43888
  const [color, backgroundColor] = this.latestColors;
@@ -43896,6 +43908,9 @@ ${codeText}
43896
43908
  this.emit("onClick", "backgroundColor", backgroundColor);
43897
43909
  }
43898
43910
  this.currentTextColors = [color, backgroundColor];
43911
+ setTimeout(() => {
43912
+ this.editor.emit("textColorChanged", this.editor, this);
43913
+ }, 100);
43899
43914
  });
43900
43915
  __publicField(this, "setLatestColors", (type, value) => {
43901
43916
  var _a, _b;
@@ -43933,6 +43948,13 @@ ${codeText}
43933
43948
  this.element.addEventListener("click", this.handleButtonClick);
43934
43949
  this.bindColorButtonEvents();
43935
43950
  this.element.setAttribute(`data-editor-tooltip-${editor.clientId}`, this.name);
43951
+ this.editor.addListener("textColorChanged", (e2, sender) => {
43952
+ if (sender !== this) {
43953
+ this.latestColors = this.getColorsFromLocalStorage();
43954
+ this.setCurrentButtonColor(this.latestColors);
43955
+ this.updatePaletteColor();
43956
+ }
43957
+ });
43936
43958
  }
43937
43959
  bindColorButtonEvents() {
43938
43960
  if (clientType.isMobile) {
@@ -53197,15 +53219,15 @@ ${codeText}
53197
53219
  __publicField(this, "id", "ListProvider");
53198
53220
  __publicField(this, "executeInsertCommand", (editor, containerId, blockIndex, command) => {
53199
53221
  if (command.id === "unordered-list") {
53200
- this.insertList(editor, containerId, blockIndex, "unordered");
53222
+ this.insertList(editor, containerId, blockIndex, "unordered", command);
53201
53223
  return true;
53202
53224
  }
53203
53225
  if (command.id === "ordered-list") {
53204
- this.insertList(editor, containerId, blockIndex, "ordered");
53226
+ this.insertList(editor, containerId, blockIndex, "ordered", command);
53205
53227
  return true;
53206
53228
  }
53207
53229
  if (command.id === "check-list") {
53208
- this.insertList(editor, containerId, blockIndex, "unchecked");
53230
+ this.insertList(editor, containerId, blockIndex, "unchecked", command);
53209
53231
  return true;
53210
53232
  }
53211
53233
  return false;
@@ -53288,21 +53310,66 @@ ${codeText}
53288
53310
  });
53289
53311
  }
53290
53312
  }
53291
- insertList(editor, containerId, blockIndex, listType) {
53313
+ insertList(editor, containerId, blockIndex, listType, command) {
53292
53314
  var _a;
53293
- const blockList = editor.getChildContainerData(containerId);
53294
- const block = (_a = editor.findBlockByIndex(containerId, blockIndex)) != null ? _a : editor.getBlockById(blockList[blockList.length - 1].id);
53295
- const convertResult = convertBlockFrom(editor, block, "list", {
53315
+ editor.getChildContainerData(containerId);
53316
+ let sourceIndex = blockIndex;
53317
+ let insertBefore = true;
53318
+ if (((_a = command.source) == null ? void 0 : _a.indexOf("/insert-block-after")) !== -1) {
53319
+ insertBefore = false;
53320
+ if (blockIndex > 0) {
53321
+ sourceIndex = blockIndex - 1;
53322
+ }
53323
+ }
53324
+ const currentBlock = editor.findBlockByIndex(containerId, sourceIndex);
53325
+ if (!currentBlock) {
53326
+ return;
53327
+ }
53328
+ const convertResult = convertBlockFrom(editor, currentBlock, "list", {
53296
53329
  offset: 0,
53297
53330
  data: {
53298
53331
  listType
53299
53332
  }
53300
53333
  });
53301
- if (convertResult) {
53302
- editor.undoManager.runInGroup(() => {
53303
- editor.insertBlock(containerId, blockIndex, convertResult.blockData);
53304
- });
53334
+ const newData = convertResult == null ? void 0 : convertResult.blockData;
53335
+ if (!newData) {
53336
+ return;
53305
53337
  }
53338
+ const oldData = editor.getBlockData(currentBlock);
53339
+ const oldType = getListType(oldData);
53340
+ const newType = getListType(newData);
53341
+ if (oldType === newType) {
53342
+ if (typeof newData.start === "number") {
53343
+ if (typeof oldData.start === "number") {
53344
+ if (insertBefore) {
53345
+ newData.start = oldData.start - 1;
53346
+ } else {
53347
+ newData.start = oldData.start + 1;
53348
+ }
53349
+ } else {
53350
+ if (insertBefore) {
53351
+ newData.start -= 1;
53352
+ } else {
53353
+ newData.start += 1;
53354
+ }
53355
+ }
53356
+ }
53357
+ if (typeof newData.start === "number" && newData.start <= 0) {
53358
+ newData.start = 1;
53359
+ }
53360
+ newData.groupId = oldData.groupId;
53361
+ }
53362
+ newData.text = [];
53363
+ if (oldType === newType) {
53364
+ newData.heading = oldData.heading;
53365
+ } else {
53366
+ delete newData.heading;
53367
+ }
53368
+ editor.undoManager.runInGroup(() => {
53369
+ const newBlock = editor.insertBlock(containerId, blockIndex, newData);
53370
+ const fix = new FixStartByList(editor, newBlock);
53371
+ fix.fix();
53372
+ });
53306
53373
  }
53307
53374
  executeCommand(editor, block, range, command) {
53308
53375
  if (!isTextKindBlock(editor, block)) {
@@ -64261,7 +64328,7 @@ $$${mathData.mathjaxText}$$
64261
64328
  const failedLoad = !!block.querySelector(".images > .image-container.error, .images > .image-container.empty ");
64262
64329
  const width = calImageBlockStyleWidth(editor, blockData, parentContainer, failedLoad);
64263
64330
  const height = calBlockHeight(editor, blockData, parentContainer, failedLoad);
64264
- if (width.startsWith("0") && height.startsWith("0")) {
64331
+ if (width.startsWith("0") || height.startsWith("0")) {
64265
64332
  const image = block.querySelector("img");
64266
64333
  if (image) {
64267
64334
  image.onload = () => {
@@ -94125,9 +94192,11 @@ ${JSON.stringify(error2, null, 2)}`);
94125
94192
  Heading3Icon,
94126
94193
  Heading4Icon,
94127
94194
  Heading5Icon,
94128
- Heading6Icon
94195
+ Heading6Icon,
94196
+ Heading7Icon,
94197
+ Heading8Icon
94129
94198
  ];
94130
- for (let i = 1; i <= 6; i++) {
94199
+ for (let i = 1; i <= 8; i++) {
94131
94200
  this.children.push({
94132
94201
  name: i18n$1.t("commands.heading", { name: `${i}` }),
94133
94202
  id: `heading-${i}`,
@@ -94362,6 +94431,8 @@ ${JSON.stringify(error2, null, 2)}`);
94362
94431
  event.stopPropagation();
94363
94432
  });
94364
94433
  this.provider = new ColorStyleProvider(editor);
94434
+ this.latestColors = this.getColorsFromLocalStorage();
94435
+ this.setCurrentButtonColor(this.latestColors);
94365
94436
  this.addListener("onClick", this.handleChangeColor);
94366
94437
  this.element.addEventListener("mousedown", this.handleMousedown);
94367
94438
  }
@@ -94529,7 +94600,7 @@ ${JSON.stringify(error2, null, 2)}`);
94529
94600
  async onClick(editor, item) {
94530
94601
  const block = editor.getBlockById(editor.selection.range.start.blockId);
94531
94602
  const container = editor.getParentContainer(block);
94532
- const index2 = editor.getBlockIndex(block);
94603
+ let index2 = editor.getBlockIndex(block);
94533
94604
  const file2 = await selectFile("*");
94534
94605
  if (!file2) {
94535
94606
  return;
@@ -94547,7 +94618,14 @@ ${JSON.stringify(error2, null, 2)}`);
94547
94618
  creator: editor.doc.getUser().displayName,
94548
94619
  previewType: FilePreviewType.Card
94549
94620
  };
94550
- editor.insertEmbed(getContainerId(container), index2 + 1, "office", data2);
94621
+ if (!isEmptyTextBlock(editor, block)) {
94622
+ index2 += 1;
94623
+ }
94624
+ const embedBlock = editor.insertEmbed(getContainerId(container), index2, "office", data2);
94625
+ const nextBlock = getNextBlock(embedBlock);
94626
+ if (nextBlock && isTextKindBlock(editor, nextBlock)) {
94627
+ editor.selection.selectBlock(nextBlock, 0);
94628
+ }
94551
94629
  }
94552
94630
  }
94553
94631
  class InsertMentionItem {
@@ -94741,6 +94819,12 @@ ${JSON.stringify(error2, null, 2)}`);
94741
94819
  tooltipId: editor.clientId,
94742
94820
  id: "main-toolbar"
94743
94821
  });
94822
+ this.toolbar.addListener("closing", () => {
94823
+ setTimeout(() => {
94824
+ editor.focus();
94825
+ }, 100);
94826
+ return true;
94827
+ });
94744
94828
  this.toolbar.addListener("click", this.handleClick);
94745
94829
  this.editor.addListener("selectionChanged", this.handleSelectionChanged);
94746
94830
  this.updateState();
@@ -95365,7 +95449,7 @@ ${JSON.stringify(error2, null, 2)}`);
95365
95449
  }
95366
95450
  }
95367
95451
  });
95368
- editor.version = "2.9.8-beta.21";
95452
+ editor.version = "2.9.8-beta.22";
95369
95453
  return editor;
95370
95454
  }
95371
95455
  function isDoc(doc2) {
@@ -95497,7 +95581,7 @@ ${JSON.stringify(error2, null, 2)}`);
95497
95581
  OnesEditorDropTarget.register(editor);
95498
95582
  OnesEditorTocProvider.register(editor);
95499
95583
  OnesEditorExclusiveBlock.register(editor);
95500
- editor.version = "2.9.8-beta.21";
95584
+ editor.version = "2.9.8-beta.22";
95501
95585
  return editor;
95502
95586
  }
95503
95587
  async function showDocVersions(editor, options, serverUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.9.8-beta.21",
3
+ "version": "2.9.8-beta.22",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "dependencies": {