@ones-editor/editor 1.1.31-beta.2 → 1.1.31-beta.3

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.
@@ -1,6 +1,6 @@
1
1
  import { TypedEmitter } from 'tiny-typed-emitter';
2
2
  import { CloseReason, CommandItem, Closeable } from '../../../../@ones-editor/core';
3
- import { AbstractManualCommandBar, AbstractCommandBar, CommandBarEvents, CommandBarOptions, CommandItemElement, CreateManualCommandBarFunction, ManualShowCommandBarOptions } from './types';
3
+ import { AbstractManualCommandBar, AbstractCommandBar, CommandBarEvents, CommandBarOptions, CommandItemElement, CreateManualCommandBarFunction, ManualShowCommandBarOptions, SelectItemFrom } from './types';
4
4
  import 'tippy.js/dist/tippy.css';
5
5
  export default abstract class CommandBar extends TypedEmitter<CommandBarEvents> implements AbstractCommandBar {
6
6
  content: HTMLElement;
@@ -30,7 +30,7 @@ export default abstract class CommandBar extends TypedEmitter<CommandBarEvents>
30
30
  private getPrevItemIndex;
31
31
  private getNextItemIndex;
32
32
  protected clearSelectedItem(): void;
33
- selectItem(id: string): void;
33
+ selectItem(id: string, from?: SelectItemFrom): void;
34
34
  private lastEnterPauseTime;
35
35
  private startPauseMouseEnter;
36
36
  private handleItemMouseEnter;
@@ -66,3 +66,4 @@ export type CreateManualCommandBarFunction = (parentItem: CommandItem, closeable
66
66
  export type PopoverOptions = {
67
67
  overflowBoundary?: Element;
68
68
  };
69
+ export type SelectItemFrom = 'event' | 'manual';
package/dist/index.js CHANGED
@@ -8278,8 +8278,8 @@ var __publicField = (obj, key, value) => {
8278
8278
  }
8279
8279
  div.style.position = "fixed";
8280
8280
  div.style.opacity = "0";
8281
- const body = /<body[^>]*>([\s\S]*)<\/body>/.exec(html != null ? html : "");
8282
- div.innerHTML = body ? body[1] : html != null ? html : "";
8281
+ const body = /<body(\s+[^>]*)?>([\s\S]*)<\/body>/.exec(html != null ? html : "");
8282
+ div.innerHTML = body ? body[2] : html != null ? html : "";
8283
8283
  document.body.appendChild(div);
8284
8284
  select(div);
8285
8285
  document.execCommand("copy");
@@ -27628,6 +27628,33 @@ ${codeText}
27628
27628
  this.endGroup();
27629
27629
  }
27630
27630
  }
27631
+ verifyPos(pos) {
27632
+ const block = this.editor.getBlockById(pos.blockId);
27633
+ if (pos.isSimple()) {
27634
+ const ok = pos.offset >= 0 && pos.offset <= getBlockTextLength$4(this.editor, block);
27635
+ if (!ok) {
27636
+ assert(logger$2I, false, "invalid block position, out of range");
27637
+ }
27638
+ } else {
27639
+ const childContainerId = pos.childContainerId;
27640
+ const container = this.editor.getContainerById(childContainerId);
27641
+ const ok = !!container;
27642
+ if (!ok) {
27643
+ assert(logger$2I, false, "invalid complex block position, no container found");
27644
+ }
27645
+ }
27646
+ }
27647
+ checkRange() {
27648
+ const { start, end } = this.editor.selection.range;
27649
+ try {
27650
+ this.verifyPos(start);
27651
+ this.verifyPos(end);
27652
+ } catch (err) {
27653
+ logger$2I.error(`undo: failed to restore caret pos: ${err.message}`);
27654
+ const firstBlock = this.editor.getFirstBlock();
27655
+ this.editor.selection.setRange(createBlockSimpleRange(this.editor, firstBlock, 0), { noScroll: true });
27656
+ }
27657
+ }
27631
27658
  undo() {
27632
27659
  if (this.undoCursor === -1) {
27633
27660
  this.undoCursor = this.actions.length;
@@ -27653,6 +27680,7 @@ ${codeText}
27653
27680
  return false;
27654
27681
  } finally {
27655
27682
  this.undoRedoing = false;
27683
+ this.checkRange();
27656
27684
  }
27657
27685
  }
27658
27686
  redo() {
@@ -27682,6 +27710,7 @@ ${codeText}
27682
27710
  return false;
27683
27711
  } finally {
27684
27712
  this.undoRedoing = false;
27713
+ this.checkRange();
27685
27714
  }
27686
27715
  }
27687
27716
  canUndo() {
@@ -37150,7 +37179,7 @@ ${codeText}
37150
37179
  removeClass(elem, "selected");
37151
37180
  }
37152
37181
  }
37153
- selectItem(id) {
37182
+ selectItem(id, from = "event") {
37154
37183
  const exists = this.getSelectedItem();
37155
37184
  if (exists) {
37156
37185
  if (exists.id === id) {
@@ -37166,7 +37195,7 @@ ${codeText}
37166
37195
  if (item) {
37167
37196
  addClass(item, "selected");
37168
37197
  this.emit("selectionChange", this, item.getAttribute("data-id") || "");
37169
- if (!this.options.disableSelectedScroll) {
37198
+ if (!this.options.disableSelectedScroll && from === "event") {
37170
37199
  item.scrollIntoView({ block: "nearest" });
37171
37200
  }
37172
37201
  } else {
@@ -38056,7 +38085,7 @@ ${codeText}
38056
38085
  if (items.length > 0) {
38057
38086
  const firstItem = items.find((item) => item.type !== "section" && item.type !== "separator");
38058
38087
  if (firstItem) {
38059
- this.menu.selectItem(firstItem.id);
38088
+ this.menu.selectItem(firstItem.id, "manual");
38060
38089
  }
38061
38090
  }
38062
38091
  }
@@ -40057,16 +40086,21 @@ ${codeText}
40057
40086
  children.forEach((containerId, index2) => {
40058
40087
  const cellColSpan = this._data[`${containerId}_colSpan`] || 1;
40059
40088
  const cellRowSpan = this._data[`${containerId}_rowSpan`] || 1;
40089
+ const cellBackground = this._data[`${containerId}_background`] || "";
40060
40090
  for (let y = 0; y < cellRowSpan; y++) {
40061
40091
  for (let x = 0; x < cellColSpan; x++) {
40062
- this._rows[row + y].setCell(col + x, {
40092
+ const cellData = {
40063
40093
  col,
40064
40094
  row,
40065
40095
  containerId,
40066
40096
  virtual: x !== 0 || y !== 0,
40067
40097
  colSpan: cellColSpan,
40068
40098
  rowSpan: cellRowSpan
40069
- });
40099
+ };
40100
+ if (cellBackground) {
40101
+ cellData.background = cellBackground;
40102
+ }
40103
+ this._rows[row + y].setCell(col + x, cellData);
40070
40104
  }
40071
40105
  }
40072
40106
  const next = this.getNextEmptyCell(col, row);
@@ -40102,6 +40136,14 @@ ${codeText}
40102
40136
  }
40103
40137
  }
40104
40138
  const logger$2d = getLogger("table-data");
40139
+ function getBackgroundFromCell(cell) {
40140
+ for (const cls of Array.from(cell.classList)) {
40141
+ if (cls.startsWith("style-bg-color-")) {
40142
+ return cls;
40143
+ }
40144
+ }
40145
+ return "";
40146
+ }
40105
40147
  function getCellChildContainer(cell) {
40106
40148
  const container = cell.firstElementChild;
40107
40149
  assert(logger$2d, container, "no child element for cell");
@@ -40114,6 +40156,7 @@ ${codeText}
40114
40156
  assert(logger$2d, block, "no parent block for table");
40115
40157
  const cellIds = [];
40116
40158
  const spanData = {};
40159
+ const backgroundData = {};
40117
40160
  Array.from(table.rows).forEach((row) => {
40118
40161
  Array.from(row.cells).forEach((cell) => {
40119
40162
  const container = getCellChildContainer(cell);
@@ -40123,6 +40166,10 @@ ${codeText}
40123
40166
  spanData[`${containerId}_colSpan`] = cell.colSpan;
40124
40167
  spanData[`${containerId}_rowSpan`] = cell.rowSpan;
40125
40168
  }
40169
+ const background = getBackgroundFromCell(cell);
40170
+ if (background) {
40171
+ backgroundData[`${containerId}_background`] = background;
40172
+ }
40126
40173
  });
40127
40174
  });
40128
40175
  const rows = table.rows.length;
@@ -40134,7 +40181,8 @@ ${codeText}
40134
40181
  cols,
40135
40182
  children: cellIds,
40136
40183
  colsWidth: Array(cols).fill(100),
40137
- ...spanData
40184
+ ...spanData,
40185
+ ...backgroundData
40138
40186
  };
40139
40187
  return tableData;
40140
40188
  }
@@ -40153,6 +40201,7 @@ ${codeText}
40153
40201
  __publicField(this, "col");
40154
40202
  __publicField(this, "colSpan");
40155
40203
  __publicField(this, "rowSpan");
40204
+ __publicField(this, "background");
40156
40205
  __publicField(this, "virtual");
40157
40206
  __publicField(this, "table");
40158
40207
  this.table = table;
@@ -40162,6 +40211,9 @@ ${codeText}
40162
40211
  this.colSpan = cellData.colSpan;
40163
40212
  this.rowSpan = cellData.rowSpan;
40164
40213
  this.virtual = cellData.virtual;
40214
+ if (cellData.background) {
40215
+ this.background = cellData.background;
40216
+ }
40165
40217
  }
40166
40218
  get cell() {
40167
40219
  const container = this.container;
@@ -40858,6 +40910,7 @@ ${codeText}
40858
40910
  assert(logger$27, !cellData.virtual, "should not split virtual cell");
40859
40911
  assert(logger$27, cellData.colSpan > 1 || cellData.rowSpan > 1, "cell does not has span data");
40860
40912
  const virtualCellContainers = grid.getVirtualCellContainersGrid();
40913
+ const newCellContainers = [];
40861
40914
  for (let y = 0; y < cellData.rowSpan; y++) {
40862
40915
  for (let x = 0; x < cellData.colSpan; x++) {
40863
40916
  if (y === 0 && x === 0) {
@@ -40867,12 +40920,19 @@ ${codeText}
40867
40920
  const colIndex = x + cellData.col;
40868
40921
  const newContainerId = createEmptyContainer(editor.doc);
40869
40922
  virtualCellContainers[rowIndex][colIndex] = newContainerId;
40923
+ newCellContainers.push(newContainerId);
40870
40924
  }
40871
40925
  }
40872
40926
  const oldData = editor.getBlockData(block);
40873
40927
  const newData = cloneDeep__default.default(oldData);
40874
40928
  newData[`${cellData.containerId}_colSpan`] = null;
40875
40929
  newData[`${cellData.containerId}_rowSpan`] = null;
40930
+ const background = cellData.background;
40931
+ if (background && newCellContainers.length > 0) {
40932
+ newCellContainers.forEach((containerId) => {
40933
+ newData[`${containerId}_background`] = background;
40934
+ });
40935
+ }
40876
40936
  newData.children = TableGrid.virtualCellContainersGridToChildren(virtualCellContainers);
40877
40937
  const blocks = editor.getChildContainerData(cellData.containerId);
40878
40938
  const focusedBlock = blocks[0];
@@ -42757,10 +42817,48 @@ ${codeText}
42757
42817
  }
42758
42818
  }
42759
42819
  }
42760
- editor.doc.endBatchUpdate();
42820
+ const updatePayload = {};
42821
+ const deletedContainerIds = [];
42822
+ for (let col = 0; col < tempGrid.colCount; col++) {
42823
+ for (let row = 0; row < tempGrid.rowCount; row++) {
42824
+ const tempCellData = tempGrid.getCell({ col, row });
42825
+ const destCol = currentCol + col;
42826
+ const destRow = currentRow + row;
42827
+ const destIndex = { col: destCol, row: destRow };
42828
+ const cell = grid.getCell(destIndex);
42829
+ const containerId = cell.containerId;
42830
+ if (!tempCellData.virtual) {
42831
+ if (tempCellData.colSpan !== 1) {
42832
+ updatePayload[`${containerId}_colSpan`] = tempCellData.colSpan;
42833
+ }
42834
+ if (tempCellData.rowSpan !== 1) {
42835
+ updatePayload[`${containerId}_rowSpan`] = tempCellData.rowSpan;
42836
+ }
42837
+ if (tempCellData.background) {
42838
+ updatePayload[`${containerId}_background`] = tempCellData.background;
42839
+ }
42840
+ } else {
42841
+ deletedContainerIds.push(containerId);
42842
+ }
42843
+ }
42844
+ }
42845
+ const oldBlockData = editor.getBlockData(tableBlock);
42846
+ if (deletedContainerIds.length > 0) {
42847
+ deletedContainerIds.forEach((containerId) => {
42848
+ oldBlockData.children = oldBlockData.children.filter((id) => id !== containerId);
42849
+ });
42850
+ }
42851
+ const unsafeTableData = {
42852
+ ...oldBlockData,
42853
+ ...updatePayload
42854
+ };
42855
+ tableData2Grid(unsafeTableData);
42761
42856
  assert(logger$1V, lastContainer, "no last container");
42762
42857
  const lastBlock2 = getLastChildBlock(lastContainer);
42763
42858
  editor.selection.selectBlock(lastBlock2, getBlockTextLength$4(editor, lastBlock2));
42859
+ const safetyTableData = unsafeTableData;
42860
+ editor.updateBlockData(tableBlock, safetyTableData);
42861
+ editor.doc.endBatchUpdate();
42764
42862
  });
42765
42863
  }
42766
42864
  const logger$1U = getLogger("paste-in-table-block");
@@ -55325,6 +55423,15 @@ $$${mathData.mathjaxText}$$
55325
55423
  return getTableSelectedContainers(editor, block, from, to);
55326
55424
  }
55327
55425
  const logger$1q = getLogger("table-selection-to-doc");
55426
+ function getSelectedCellColors(blockData, selectedCellContainers) {
55427
+ return selectedCellContainers.reduce((acc, containerId) => {
55428
+ const existColorKey = getCellBkgColorKey(containerId);
55429
+ if (blockData[existColorKey]) {
55430
+ acc[existColorKey] = blockData[existColorKey];
55431
+ }
55432
+ return acc;
55433
+ }, {});
55434
+ }
55328
55435
  function selectionToDoc(editor, selectedBlock) {
55329
55436
  const { start, end, block } = selectedBlock;
55330
55437
  const blockType = getBlockType(block);
@@ -55401,6 +55508,7 @@ $$${mathData.mathjaxText}$$
55401
55508
  const colsWidth = getTableColumnWidths(getBlockTable(block)).slice(fromCol, toCol + 1);
55402
55509
  const id = genId();
55403
55510
  const type = blockType;
55511
+ const selectedCellColors = getSelectedCellColors(blockData, children);
55404
55512
  const newBlock = {
55405
55513
  id,
55406
55514
  type,
@@ -55408,6 +55516,7 @@ $$${mathData.mathjaxText}$$
55408
55516
  colsWidth,
55409
55517
  rows: toRow - fromRow + 1,
55410
55518
  cols: toCol - fromCol + 1,
55519
+ ...selectedCellColors,
55411
55520
  ...spanData
55412
55521
  };
55413
55522
  const newDoc = {
@@ -60232,9 +60341,12 @@ ${codeText}
60232
60341
  if (eleRect.width > width || eleRect.height >= MAX_HEIGHT_PIXEL) {
60233
60342
  return "";
60234
60343
  }
60235
- const orgDataUrl = await domToImage__default.default.toSvg(element);
60236
- const svgDataUrl = orgDataUrl.replace(/margin-block:.*?;/, "").replace(/margin:.*?;/, "");
60237
- return svgDataUrl;
60344
+ const orgDataUrl = await domToImage__default.default.toPng(element, {
60345
+ style: {
60346
+ margin: 0
60347
+ }
60348
+ });
60349
+ return orgDataUrl;
60238
60350
  }
60239
60351
  const logger$11 = getLogger("drag-preview-image");
60240
60352
  class DragPreviewImage {
@@ -77508,7 +77620,7 @@ ${data.flowchartText}
77508
77620
  }
77509
77621
  }
77510
77622
  });
77511
- editor.version = "1.1.31-beta.2";
77623
+ editor.version = "1.1.31-beta.3";
77512
77624
  if (Logger$2.level === LogLevel.DEBUG) {
77513
77625
  window.setReauthFail = (fail) => {
77514
77626
  window.isReauthError = fail;
@@ -77550,61 +77662,54 @@ ${data.flowchartText}
77550
77662
  },
77551
77663
  shortcuts: [TableShortcuts, FindReplaceShortcuts, TextStyleShortcuts, DefaultShortcuts]
77552
77664
  });
77553
- try {
77554
- editor.editorCommandProviders.registerCommandProvider(new TextCommandProvider(editor));
77555
- editor.input.addHandler(new MarkdownInputHandler());
77556
- editor.input.addHandler(
77557
- new EnforceWithDocumentTitleHandler(editor, {
77558
- hideTitle: options.hideTitle,
77559
- headingLevel: 1,
77560
- titlePlaceholder: i18n$1.t("placeholder.common.title"),
77561
- contentPlaceholder: i18n$1.t("placeholder.common.content"),
77562
- readonlyTitlePlaceholder: i18n$1.t("placeholder.local.readonlyTitle"),
77563
- addPlaceholderToAllCurrentEmptyBlock: true
77564
- })
77665
+ editor.editorCommandProviders.registerCommandProvider(new TextCommandProvider(editor));
77666
+ editor.input.addHandler(new MarkdownInputHandler());
77667
+ editor.input.addHandler(
77668
+ new EnforceWithDocumentTitleHandler(editor, {
77669
+ hideTitle: options.hideTitle,
77670
+ headingLevel: 1,
77671
+ titlePlaceholder: i18n$1.t("placeholder.common.title"),
77672
+ contentPlaceholder: i18n$1.t("placeholder.common.content"),
77673
+ readonlyTitlePlaceholder: i18n$1.t("placeholder.local.readonlyTitle"),
77674
+ addPlaceholderToAllCurrentEmptyBlock: true
77675
+ })
77676
+ );
77677
+ editor.input.addHandler(new OnesEditorQuickMenu(editor, (_h = options.componentsOptions) == null ? void 0 : _h.quickMenu));
77678
+ editor.input.addHandler(new PasteSpecialHandler(editor));
77679
+ editor.input.addHandler(new OnesEditorPasteHandler(editor));
77680
+ editor.input.addHandler(new BlockLockerPasteHandler());
77681
+ editor.input.addHandler(new ListPasteHandler());
77682
+ editor.addCustom("block-menu", (editor2) => new OnesEditorBlockMenuButton(editor2));
77683
+ if (!clientType.isMobile) {
77684
+ editor.addCustom("editor-tooltip", () => new OnesEditorTooltip(editor));
77685
+ }
77686
+ editor.addCustom("image-paste-handler", () => new ImagePasteHandler(editor));
77687
+ if (options == null ? void 0 : options.enableComments) {
77688
+ editor.addCustom(
77689
+ "editor-comments",
77690
+ (editor2) => new OnesEditorComments(editor2, new LocalDocCommentsProvider(editor2, doc2))
77565
77691
  );
77566
- editor.input.addHandler(new OnesEditorQuickMenu(editor, (_h = options.componentsOptions) == null ? void 0 : _h.quickMenu));
77567
- editor.input.addHandler(new PasteSpecialHandler(editor));
77568
- editor.input.addHandler(new OnesEditorPasteHandler(editor));
77569
- editor.input.addHandler(new BlockLockerPasteHandler());
77570
- editor.input.addHandler(new ListPasteHandler());
77571
- editor.addCustom("block-menu", (editor2) => new OnesEditorBlockMenuButton(editor2));
77572
- if (!clientType.isMobile) {
77573
- editor.addCustom("editor-tooltip", () => new OnesEditorTooltip(editor));
77574
- }
77575
- editor.addCustom("image-paste-handler", () => new ImagePasteHandler(editor));
77576
- if (options == null ? void 0 : options.enableComments) {
77577
- editor.addCustom(
77578
- "editor-comments",
77579
- (editor2) => new OnesEditorComments(editor2, new LocalDocCommentsProvider(editor2, doc2))
77580
- );
77581
- }
77582
- if (options.enableContextMenu !== false) {
77583
- editor.addCustom("editor-context-menu", (editor2) => new OnesEditorContextMenu(editor2));
77692
+ }
77693
+ if (options.enableContextMenu !== false) {
77694
+ editor.addCustom("editor-context-menu", (editor2) => new OnesEditorContextMenu(editor2));
77695
+ }
77696
+ editor.addCustom("heading-collapse", () => new HeadingBlockCollapseButton(editor));
77697
+ editor.addListener("clickLink", (editor2, event, link2) => {
77698
+ var _a2;
77699
+ if ((_a2 = options == null ? void 0 : options.events) == null ? void 0 : _a2.onClickLink) {
77700
+ options.events.onClickLink(editor2, event, link2);
77701
+ return;
77584
77702
  }
77585
- editor.addCustom("heading-collapse", () => new HeadingBlockCollapseButton(editor));
77586
- editor.addListener("clickLink", (editor2, event, link2) => {
77587
- var _a2;
77588
- if ((_a2 = options == null ? void 0 : options.events) == null ? void 0 : _a2.onClickLink) {
77589
- options.events.onClickLink(editor2, event, link2);
77590
- return;
77591
- }
77592
- const href = link2.getAttribute("link");
77593
- if (href) {
77594
- if (editor2.readonly || event.ctrlKey || event.metaKey) {
77595
- window.open(href, "_blank");
77596
- }
77703
+ const href = link2.getAttribute("link");
77704
+ if (href) {
77705
+ if (editor2.readonly || event.ctrlKey || event.metaKey) {
77706
+ window.open(href, "_blank");
77597
77707
  }
77598
- });
77599
- editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
77600
- OnesEditorToolbar.register(editor);
77601
- editor.version = "1.1.31-beta.2";
77602
- } catch (error2) {
77603
- if (options.readonly) {
77604
- editor.readonly = true;
77605
77708
  }
77606
- throw error2;
77607
- }
77709
+ });
77710
+ editor.addCustom(DOC_RE_AUTH_KEYS, (editor2) => new DocReAuthCallbacks(editor2));
77711
+ OnesEditorToolbar.register(editor);
77712
+ editor.version = "1.1.31-beta.3";
77608
77713
  return editor;
77609
77714
  }
77610
77715
  async function showDocVersions(editor, options, serverUrl) {
package/dist/types.d.ts CHANGED
@@ -99,5 +99,4 @@ export interface CreateLocalEditorOptions {
99
99
  events?: EditorEvents;
100
100
  componentsOptions?: EditorComponentOptions;
101
101
  hideTitle?: boolean;
102
- readonly?: boolean;
103
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "1.1.31-beta.2",
3
+ "version": "1.1.31-beta.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",