@worktile/theia 15.0.18 → 15.1.0

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.
Files changed (69) hide show
  1. package/esm2020/interfaces/editor.mjs +1 -1
  2. package/esm2020/interfaces/plugins/plugin-key.mjs +2 -2
  3. package/esm2020/interfaces/valid-children-types.mjs +7 -7
  4. package/esm2020/plugins/common/insert-data-by-invalid-type.mjs +23 -0
  5. package/esm2020/plugins/deserialize/deserialize-html.plugin.mjs +53 -0
  6. package/esm2020/plugins/deserialize/deserialize-md.plugin.mjs +130 -0
  7. package/esm2020/plugins/index.mjs +5 -5
  8. package/esm2020/plugins/mention/mention.plugin.mjs +3 -2
  9. package/esm2020/plugins/mention/mention.type.mjs +1 -1
  10. package/esm2020/plugins/table/components/insert-mark/insert-mark.component.mjs +18 -7
  11. package/esm2020/plugins/table/components/row/row.component.mjs +3 -5
  12. package/esm2020/plugins/table/components/table.component.mjs +17 -107
  13. package/esm2020/plugins/table/components/td/td.component.mjs +3 -4
  14. package/esm2020/plugins/table/components/toolbar/table-options.component.mjs +5 -4
  15. package/esm2020/plugins/table/components/toolbar/table-toolbar.component.mjs +12 -7
  16. package/esm2020/plugins/table/table.editor.mjs +5 -6
  17. package/esm2020/plugins/table/table.plugin.mjs +16 -17
  18. package/esm2020/plugins/table/table.store.mjs +58 -174
  19. package/esm2020/plugins/table/transforms/clear-table-node.mjs +3 -3
  20. package/esm2020/plugins/table/transforms/insert-column.mjs +4 -3
  21. package/esm2020/plugins/table/transforms/insert-row.mjs +4 -3
  22. package/esm2020/plugins/table/transforms/remove-column.mjs +3 -3
  23. package/esm2020/plugins/table/transforms/remove-row.mjs +3 -5
  24. package/esm2020/plugins/table/transforms/remove-table.mjs +4 -4
  25. package/esm2020/plugins/table/utils/calculate-table.mjs +109 -0
  26. package/esm2020/plugins/table/utils/cell-position.mjs +36 -0
  27. package/esm2020/plugins/table/utils/create-table-position.mjs +10 -0
  28. package/esm2020/plugins/table/utils/get-grid-columns.mjs +7 -2
  29. package/esm2020/plugins/table/utils/get-min-max-cell-index.mjs +64 -0
  30. package/esm2020/plugins/table/utils/get-select-cell-node.mjs +3 -6
  31. package/esm2020/plugins/table/utils/is-range-in-table.mjs +6 -6
  32. package/esm2020/plugins/table/utils/is-selection-in-table.mjs +3 -5
  33. package/esm2020/plugins/table/utils/merge-cell.mjs +17 -2
  34. package/esm2020/plugins/table/utils/split-cell.mjs +3 -6
  35. package/esm2020/plugins/table/utils/table-entry.mjs +21 -0
  36. package/esm2020/services/table-contextmenu.service.mjs +10 -7
  37. package/esm2020/utils/index.mjs +2 -1
  38. package/esm2020/utils/insert-data-by-invalid-type.mjs +62 -0
  39. package/esm2020/utils/merge-element-options.mjs +5 -5
  40. package/fesm2015/worktile-theia.mjs +460 -407
  41. package/fesm2015/worktile-theia.mjs.map +1 -1
  42. package/fesm2020/worktile-theia.mjs +461 -409
  43. package/fesm2020/worktile-theia.mjs.map +1 -1
  44. package/interfaces/plugins/plugin-key.d.ts +1 -1
  45. package/interfaces/valid-children-types.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/plugins/common/insert-data-by-invalid-type.d.ts +2 -0
  48. package/plugins/mention/mention.type.d.ts +3 -1
  49. package/plugins/table/components/insert-mark/insert-mark.component.d.ts +6 -3
  50. package/plugins/table/components/table.component.d.ts +0 -13
  51. package/plugins/table/components/toolbar/table-options.component.d.ts +1 -1
  52. package/plugins/table/table.editor.d.ts +4 -1
  53. package/plugins/table/table.store.d.ts +2 -20
  54. package/plugins/table/utils/calculate-table.d.ts +3 -0
  55. package/plugins/table/utils/cell-position.d.ts +14 -0
  56. package/plugins/table/utils/create-table-position.d.ts +3 -0
  57. package/plugins/table/utils/get-grid-columns.d.ts +1 -1
  58. package/plugins/table/utils/get-min-max-cell-index.d.ts +4 -0
  59. package/plugins/table/utils/is-range-in-table.d.ts +2 -2
  60. package/plugins/table/utils/merge-cell.d.ts +1 -0
  61. package/plugins/table/utils/table-entry.d.ts +5 -0
  62. package/utils/index.d.ts +1 -0
  63. package/utils/insert-data-by-invalid-type.d.ts +1 -0
  64. package/esm2020/plugins/common/auto-insert-data.mjs +0 -75
  65. package/esm2020/plugins/deserializers/deserialize-html.plugin.mjs +0 -48
  66. package/esm2020/plugins/deserializers/deserialize-md.plugin.mjs +0 -130
  67. package/plugins/common/auto-insert-data.d.ts +0 -2
  68. /package/plugins/{deserializers → deserialize}/deserialize-html.plugin.d.ts +0 -0
  69. /package/plugins/{deserializers → deserialize}/deserialize-md.plugin.d.ts +0 -0
@@ -2019,28 +2019,28 @@ const inValidTypes = [
2019
2019
  const DefaultElementOptions = [
2020
2020
  {
2021
2021
  type: ElementKinds.bulletedList,
2022
- inValidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2022
+ invalidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2023
2023
  },
2024
2024
  {
2025
2025
  type: ElementKinds.numberedList,
2026
- inValidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2026
+ invalidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2027
2027
  },
2028
2028
  {
2029
2029
  type: ElementKinds.listItem,
2030
- inValidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2030
+ invalidChildrenTypes: [...inValidTypes, ...HEADING_TYPES]
2031
2031
  },
2032
2032
  {
2033
2033
  type: ElementKinds.blockquote,
2034
- inValidChildrenTypes: inValidTypes
2034
+ invalidChildrenTypes: inValidTypes
2035
2035
  },
2036
2036
  {
2037
2037
  type: ElementKinds.table,
2038
- inValidChildrenTypes: [ElementKinds.table]
2038
+ invalidChildrenTypes: [ElementKinds.table]
2039
2039
  },
2040
2040
  {
2041
2041
  type: ElementKinds.tableCell,
2042
2042
  isSecondaryContainer: true,
2043
- inValidChildrenTypes: [ElementKinds.table, ElementKinds.tableCell]
2043
+ invalidChildrenTypes: [ElementKinds.table, ElementKinds.tableCell]
2044
2044
  }
2045
2045
  ];
2046
2046
 
@@ -2071,7 +2071,7 @@ var PluginKeys;
2071
2071
  PluginKeys["removeVoid"] = "remove-void";
2072
2072
  PluginKeys["removeEmpty"] = "remove-empty";
2073
2073
  PluginKeys["theHistory"] = "the-history";
2074
- PluginKeys["autoInsertData"] = "auto-insert-data";
2074
+ PluginKeys["insertDataByInvalidType"] = "insert-data-by-invalid-type";
2075
2075
  PluginKeys["autoFormat"] = "auto-format";
2076
2076
  PluginKeys["transforms"] = "transforms";
2077
2077
  PluginKeys["moveSelection"] = "move-selection";
@@ -2217,19 +2217,19 @@ const isPureEmptyParagraph = (editor, block) => {
2217
2217
  };
2218
2218
 
2219
2219
  const mergeElementOptions = (elementOptions) => {
2220
- elementOptions = elementOptions.filter(item => item.inValidChildrenTypes.length > 0);
2220
+ elementOptions = elementOptions.filter(item => item.invalidChildrenTypes.length > 0);
2221
2221
  const combinationData = [...DefaultElementOptions, ...elementOptions];
2222
2222
  const dataInfo = {};
2223
2223
  combinationData.forEach(item => {
2224
- const { type, inValidChildrenTypes, isSecondaryContainer } = item;
2224
+ const { type, invalidChildrenTypes, isSecondaryContainer } = item;
2225
2225
  if (!dataInfo[type]) {
2226
2226
  dataInfo[type] = {
2227
2227
  type,
2228
- inValidChildrenTypes,
2228
+ invalidChildrenTypes,
2229
2229
  isSecondaryContainer
2230
2230
  };
2231
2231
  }
2232
- dataInfo[type].inValidChildrenTypes = Array.from(new Set([...inValidChildrenTypes, ...dataInfo[type].inValidChildrenTypes]));
2232
+ dataInfo[type].invalidChildrenTypes = Array.from(new Set([...invalidChildrenTypes, ...dataInfo[type].inValidChildrenTypes]));
2233
2233
  });
2234
2234
  return dataInfo;
2235
2235
  };
@@ -2436,6 +2436,62 @@ const refocus = (editor) => {
2436
2436
  AngularEditor.focus(editor);
2437
2437
  };
2438
2438
 
2439
+ function insertDataByInvalidType(editor, fragment) {
2440
+ if (fragment) {
2441
+ let allElementOptions = DefaultElementOptions;
2442
+ if (editor.extraElementOptions?.length) {
2443
+ const extraInfo = mergeElementOptions(editor.extraElementOptions);
2444
+ allElementOptions = Object.values(extraInfo);
2445
+ }
2446
+ if (isAcrossBlocks(editor, fragment) || Editor.isVoid(editor, fragment[0])) {
2447
+ const { selection } = editor;
2448
+ const [start] = Editor.edges(editor, selection);
2449
+ // query whether there is a node to be verified
2450
+ const tryVerifyNode = allElementOptions.find(item => getAboveByType(editor, item.type, { at: start, mode: 'lowest' }));
2451
+ if (tryVerifyNode) {
2452
+ // is exist invalid element type in fragment
2453
+ const invalidIndex = fragment.findIndex(item => tryVerifyNode.invalidChildrenTypes.includes(item.type));
2454
+ if (invalidIndex > -1) {
2455
+ const invalidFragmentData = fragment.slice(invalidIndex, fragment.length);
2456
+ const allowParentTypes = getPluginOptions(editor, invalidFragmentData[0].type)?.allowParentTypes || [];
2457
+ const insertNodePath = getInsertElementsPath(editor, allowParentTypes);
2458
+ if (insertNodePath) {
2459
+ Editor.withoutNormalizing(editor, () => {
2460
+ Transforms.insertNodes(editor, fragment, { at: insertNodePath });
2461
+ Transforms.select(editor, Editor.start(editor, insertNodePath));
2462
+ });
2463
+ return false;
2464
+ }
2465
+ const [, anchorBlockPath] = anchorBlockEntry(editor);
2466
+ const nextPath = Path.next([anchorBlockPath[0]]);
2467
+ Transforms.insertNodes(editor, fragment, { at: nextPath });
2468
+ Transforms.select(editor, Editor.start(editor, nextPath));
2469
+ return false;
2470
+ }
2471
+ }
2472
+ Editor.withoutNormalizing(editor, () => {
2473
+ const isEmptyParagraph$1 = isEmptyParagraph(editor, editor.selection.anchor);
2474
+ const emptyPath = Path.parent(editor.selection.anchor.path);
2475
+ Transforms.insertNodes(editor, fragment);
2476
+ if (isEmptyParagraph$1) {
2477
+ Transforms.delete(editor, { at: emptyPath });
2478
+ const lastPath = emptyPath.pop();
2479
+ Transforms.select(editor, [...emptyPath, lastPath + fragment.length - 1]);
2480
+ }
2481
+ else {
2482
+ const lastPath = emptyPath.pop();
2483
+ Transforms.select(editor, [...emptyPath, lastPath + fragment.length]);
2484
+ }
2485
+ AngularEditor.focus(editor);
2486
+ Transforms.collapse(editor, { edge: 'end' });
2487
+ });
2488
+ return false;
2489
+ }
2490
+ return true;
2491
+ }
2492
+ return true;
2493
+ }
2494
+
2439
2495
  const toolbarInitialize = (toolbarItems, global = DefaultGlobalToolbarDefinition, inline = DefaultInlineToolbarDefinition) => {
2440
2496
  const toolbarDefinition = {
2441
2497
  global,
@@ -3771,13 +3827,21 @@ class TablePosition {
3771
3827
  }
3772
3828
  }
3773
3829
 
3830
+ const createTablePosition = (editor, path) => {
3831
+ path = path || editor.selection.anchor?.path;
3832
+ if (!path) {
3833
+ throw new Error('Path invalid');
3834
+ }
3835
+ return TablePosition.create(new TableOptions(), editor, path);
3836
+ };
3837
+
3774
3838
  /**
3775
3839
  * True if the given range is inside one table
3776
3840
  */
3777
- function isRangeInTable(opts, node, range) {
3778
- const { anchor, focus } = range;
3779
- const startPosition = TablePosition.create(opts, node, anchor.path);
3780
- const endPosition = TablePosition.create(opts, node, focus.path);
3841
+ function isRangeInTable(opts, editor, range) {
3842
+ const { focus } = range;
3843
+ const startPosition = createTablePosition(editor);
3844
+ const endPosition = createTablePosition(editor, focus.path);
3781
3845
  // Only handle events in tables
3782
3846
  if (!startPosition.isInTable() || !endPosition.isInTable()) {
3783
3847
  return false;
@@ -3811,8 +3875,7 @@ function isRectangularInTableCells(editor, cells) {
3811
3875
  let minCol = col;
3812
3876
  let maxRow = row;
3813
3877
  let minRow = row;
3814
- const path = editor.selection.anchor.path;
3815
- const pos = TablePosition.create(new TableOptions(), editor, path);
3878
+ const pos = createTablePosition(editor);
3816
3879
  for (let { row, col } of cells) {
3817
3880
  const { hidden, rowspan, colspan } = pos.findCellByPath({ row, col });
3818
3881
  if (hidden) {
@@ -4157,7 +4220,7 @@ function insertTable(opts, editor, rows = 3, columns = 3, getCellContent) {
4157
4220
  }
4158
4221
 
4159
4222
  function getInsertRowState(opts, editor, count = 1, at) {
4160
- const tablePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
4223
+ const tablePosition = createTablePosition(editor);
4161
4224
  let table = tablePosition.table;
4162
4225
  let tableEntry = tablePosition.tableEntry;
4163
4226
  // Create a new row with the right count of cells
@@ -4247,7 +4310,7 @@ function insertColumn(opts, editor, count = 1, at, // Column index
4247
4310
  getCell) {
4248
4311
  const { selection } = editor;
4249
4312
  const { anchor: { path } } = selection;
4250
- const tablePosition = TablePosition.create(opts, editor, path);
4313
+ const tablePosition = createTablePosition(editor, path);
4251
4314
  let table = tablePosition.table;
4252
4315
  let tableEntry = tablePosition.tableEntry;
4253
4316
  const insertColumnIndex = typeof at === 'undefined' ? tablePosition.getColumnIndex() + 1 : at;
@@ -4316,9 +4379,7 @@ function clearCell(opts, editor, cellEntry) {
4316
4379
  }
4317
4380
 
4318
4381
  function removeRow(opts, editor, selectRowIndex) {
4319
- const { selection } = editor;
4320
- const { anchor: { path } } = selection;
4321
- const tablePosition = TablePosition.create(opts, editor, path);
4382
+ const tablePosition = createTablePosition(editor);
4322
4383
  const { tableEntry, table, rowEntry: [rowNode, rowPath] } = tablePosition;
4323
4384
  selectRowIndex = selectRowIndex === undefined ? [...rowPath].pop() : selectRowIndex;
4324
4385
  const at = tableEntry[1].concat(selectRowIndex);
@@ -4388,7 +4449,7 @@ function removeColumns(table, columnsCount, index) {
4388
4449
  function removeColumn(opts, editor, selectColIndex) {
4389
4450
  const { selection } = editor;
4390
4451
  const { anchor: { path } } = selection;
4391
- const tablePosition = TablePosition.create(opts, editor, path);
4452
+ const tablePosition = createTablePosition(editor, path);
4392
4453
  const { tableEntry, table, row, cellEntry: [cellNode, cellPath] } = tablePosition;
4393
4454
  const rows = tableEntry[0].children;
4394
4455
  selectColIndex = selectColIndex === undefined ? [...cellPath].pop() : selectColIndex;
@@ -4440,8 +4501,8 @@ const NextPath = (path) => {
4440
4501
  function removeTable(opts, editor) {
4441
4502
  const { selection } = editor;
4442
4503
  const { anchor: { path } } = selection;
4443
- const pos = TablePosition.create(opts, editor, path);
4444
- const { table, tableEntry: [, tablePath] } = pos;
4504
+ const pos = createTablePosition(editor, path);
4505
+ const { tableEntry: [, tablePath] } = pos;
4445
4506
  let nextFocusEntry = null;
4446
4507
  let shouldCollapseToEnd = false;
4447
4508
  const nextEntry = Editor.next(editor, { at: tablePath });
@@ -5212,7 +5273,8 @@ const withMention = (editor) => {
5212
5273
  else {
5213
5274
  const mentions = getPluginOptions(editor, PluginKeys.mention)?.mentions;
5214
5275
  const currentMention = mentions?.find(m => m?.trigger === text);
5215
- if (editor.selection && currentMention) {
5276
+ const isDisabledTrigger = currentMention && currentMention.disableTrigger ? currentMention?.disableTrigger(editor) : false;
5277
+ if (editor.selection && currentMention && !isDisabledTrigger) {
5216
5278
  MentionEditor.openSuggestion(editor, currentMention.type);
5217
5279
  }
5218
5280
  const searchInfo = MentionEditor.getSearchInfo(editor);
@@ -6209,7 +6271,7 @@ const TableEditor = {
6209
6271
  const tableNode = getAboveByType(editor, ElementKinds.table);
6210
6272
  if (tableNode) {
6211
6273
  const tableComponent = ELEMENT_TO_COMPONENT.get(tableNode[0]);
6212
- const selectedCellPositions = tableComponent.tableStore.selectedCellPositions;
6274
+ const selectedCellPositions = tableComponent.tableStore.getSelectedCellPositions();
6213
6275
  if (selectedCellPositions.length > 0) {
6214
6276
  return selectedCellPositions;
6215
6277
  }
@@ -6323,9 +6385,7 @@ const TableEditor = {
6323
6385
  if (!TableEditor.hasHeaderRow(editor) && !TableEditor.hasHeaderColumn(editor)) {
6324
6386
  return false;
6325
6387
  }
6326
- const opts = new TableOptions();
6327
- const selection = editor.selection;
6328
- const position = TablePosition.create(opts, editor, selection.focus.path);
6388
+ const position = createTablePosition(editor, editor.selection.focus.path);
6329
6389
  if (TableEditor.hasHeaderRow(editor) && position.getRowIndex() === 0) {
6330
6390
  return true;
6331
6391
  }
@@ -7318,62 +7378,13 @@ const createColorPlugin = createPluginFactory({
7318
7378
  }
7319
7379
  });
7320
7380
 
7321
- const withAutoInsertData = (editor) => {
7381
+ const withInsertDataByInvalidType = (editor) => {
7322
7382
  const { insertData } = editor;
7323
- let allElementOptions = DefaultElementOptions;
7324
- // if (validChildren?.length) {
7325
- // const validInfo = mergeElementOptions(validChildren);
7326
- // allElementOptions = Object.values(validInfo);
7327
- // }
7328
7383
  editor.insertData = (data) => {
7329
- if (editor.extraElementOptions?.length) {
7330
- const extraInfo = mergeElementOptions(editor.extraElementOptions);
7331
- allElementOptions = Object.values(extraInfo);
7332
- }
7333
7384
  const fragment = extractFragment(data);
7334
7385
  if (fragment) {
7335
- if (isAcrossBlocks(editor, fragment) || Editor.isVoid(editor, fragment[0])) {
7336
- const { selection } = editor;
7337
- const [start] = Editor.edges(editor, selection);
7338
- // query whether there is a node to be verified
7339
- const tryVerifyNode = allElementOptions.find(item => getAboveByType(editor, item.type, { at: start, mode: 'lowest' }));
7340
- if (tryVerifyNode) {
7341
- // is exist invalid element type in fragment
7342
- const invalidIndex = fragment.findIndex(item => tryVerifyNode.inValidChildrenTypes.includes(item.type));
7343
- if (invalidIndex > -1) {
7344
- const invalidFragmentData = fragment.slice(invalidIndex, fragment.length);
7345
- const allowParentTypes = getPluginOptions(editor, invalidFragmentData[0].type)?.allowParentTypes || [];
7346
- const insertNodePath = getInsertElementsPath(editor, allowParentTypes);
7347
- if (insertNodePath) {
7348
- Editor.withoutNormalizing(editor, () => {
7349
- Transforms.insertNodes(editor, fragment, { at: insertNodePath });
7350
- Transforms.select(editor, Editor.start(editor, insertNodePath));
7351
- });
7352
- return;
7353
- }
7354
- const [, anchorBlockPath] = anchorBlockEntry(editor);
7355
- const nextPath = Path.next([anchorBlockPath[0]]);
7356
- Transforms.insertNodes(editor, fragment, { at: nextPath });
7357
- Transforms.select(editor, Editor.start(editor, nextPath));
7358
- return;
7359
- }
7360
- }
7361
- Editor.withoutNormalizing(editor, () => {
7362
- const isEmptyParagraph$1 = isEmptyParagraph(editor, editor.selection.anchor);
7363
- const emptyPath = Path.parent(editor.selection.anchor.path);
7364
- Transforms.insertNodes(editor, fragment);
7365
- if (isEmptyParagraph$1) {
7366
- Transforms.delete(editor, { at: emptyPath });
7367
- const lastPath = emptyPath.pop();
7368
- Transforms.select(editor, [...emptyPath, lastPath + fragment.length - 1]);
7369
- }
7370
- else {
7371
- const lastPath = emptyPath.pop();
7372
- Transforms.select(editor, [...emptyPath, lastPath + fragment.length]);
7373
- }
7374
- AngularEditor.focus(editor);
7375
- Transforms.collapse(editor, { edge: 'end' });
7376
- });
7386
+ const isContinue = insertDataByInvalidType(editor, fragment);
7387
+ if (!isContinue) {
7377
7388
  return;
7378
7389
  }
7379
7390
  }
@@ -7381,9 +7392,9 @@ const withAutoInsertData = (editor) => {
7381
7392
  };
7382
7393
  return editor;
7383
7394
  };
7384
- const createAutoInsertDataPlugin = createPluginFactory({
7385
- key: PluginKeys.autoInsertData,
7386
- withOverrides: withAutoInsertData
7395
+ const createInsertDataByInvalidTypePlugin = createPluginFactory({
7396
+ key: PluginKeys.insertDataByInvalidType,
7397
+ withOverrides: withInsertDataByInvalidType
7387
7398
  });
7388
7399
 
7389
7400
  const withBlockCard = (editor) => {
@@ -8009,6 +8020,10 @@ const withDeserializeHTML = (editor) => {
8009
8020
  ImageEditor.handleBase64ImageElement(editor, node);
8010
8021
  }
8011
8022
  });
8023
+ const isContinue = insertDataByInvalidType(editor, fragment);
8024
+ if (!isContinue) {
8025
+ return;
8026
+ }
8012
8027
  Transforms.insertFragment(editor, fragment);
8013
8028
  return;
8014
8029
  }
@@ -11122,9 +11137,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
11122
11137
  }], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
11123
11138
 
11124
11139
  function splitCell(editor) {
11125
- const opts = new TableOptions();
11126
- const { anchor } = editor.selection;
11127
- const tablePosition = TablePosition.create(opts, editor, anchor.path);
11140
+ const tablePosition = createTablePosition(editor);
11128
11141
  const { cell, table, cellEntry } = tablePosition;
11129
11142
  if ((!cell.rowspan && !cell.colspan) || (cell.rowspan === 1 && cell.colspan === 1))
11130
11143
  return editor;
@@ -11150,9 +11163,7 @@ function resetTableCell(editor, table, cell, cellRow, cellCol) {
11150
11163
  }
11151
11164
 
11152
11165
  function getSelectCellNode(editor, selectedCells) {
11153
- const { anchor } = editor.selection;
11154
- const opts = new TableOptions();
11155
- const pos = TablePosition.create(opts, editor, anchor.path);
11166
+ const pos = createTablePosition(editor);
11156
11167
  return selectedCells
11157
11168
  .map(item => {
11158
11169
  const node = pos.findCellByPath(item);
@@ -11166,12 +11177,48 @@ function getSelectCellNode(editor, selectedCells) {
11166
11177
  .filter(item => item);
11167
11178
  }
11168
11179
 
11180
+ /* cell-position 有关的函数 */
11181
+ const isSelectedAllCell = (editor, selectedCellPositions) => {
11182
+ const pos = createTablePosition(editor);
11183
+ return !!selectedCellPositions.length && pos.getHeight() * pos.getWidth() === selectedCellPositions.length;
11184
+ };
11185
+ const getSelectedCellPositions = (editor, selectedCells) => {
11186
+ return selectedCells?.map((cell) => {
11187
+ const path = AngularEditor.findPath(editor, cell);
11188
+ const [row, col] = path.slice(-2);
11189
+ return { row, col };
11190
+ });
11191
+ };
11192
+ /* 获取一定范围内所有的单元格 */
11193
+ const getCellPositionsFromRange = (startRow, startCol, endRow, endCol) => {
11194
+ const result = [];
11195
+ for (let row = startRow; row < endRow; row++) {
11196
+ for (let col = startCol; col < endCol; col++) {
11197
+ result.push({ row, col });
11198
+ }
11199
+ }
11200
+ return result;
11201
+ };
11202
+ /**
11203
+ * 去重重复的单元格位置
11204
+ * @returns
11205
+ */
11206
+ const uniqueCellPosition = (cells, selectedCellPositions) => {
11207
+ const result = [];
11208
+ const modCells = new Set();
11209
+ cells.concat(selectedCellPositions).forEach(cell => modCells.add(JSON.stringify(cell)));
11210
+ modCells.forEach((cell) => result.push(JSON.parse(cell)));
11211
+ return result;
11212
+ };
11213
+
11169
11214
  function isSelectedCellMerged(editor) {
11170
11215
  if (editor && editor.selection) {
11171
11216
  const opts = new TableOptions();
11172
11217
  const { anchor } = editor.selection;
11173
11218
  const { cell } = TablePosition.create(opts, editor, anchor.path);
11174
- return (cell.colspan && cell.colspan !== 1) || (cell.rowspan && cell.rowspan !== 1);
11219
+ if (cell) {
11220
+ return (cell.colspan && cell.colspan !== 1) || (cell.rowspan && cell.rowspan !== 1);
11221
+ }
11175
11222
  }
11176
11223
  return false;
11177
11224
  }
@@ -11251,6 +11298,17 @@ function mergeCellContent(editor, leftTopCellPath, cellPath) {
11251
11298
  });
11252
11299
  });
11253
11300
  }
11301
+ // 计算合并前的单元格
11302
+ function getCellPositionsBeforeMerge(editor, { row, col }) {
11303
+ const pos = createTablePosition(editor);
11304
+ const { rowspan, colspan } = pos.findCellByPath({ row, col });
11305
+ if (rowspan || colspan) {
11306
+ const colSpan = colspan ?? 1;
11307
+ const rowSpan = rowspan ?? 1;
11308
+ return getCellPositionsFromRange(row, col, row + rowSpan, col + colSpan);
11309
+ }
11310
+ return [{ row, col }];
11311
+ }
11254
11312
 
11255
11313
  function setCellMenuVisibility(editor, menuList, tableInfo) {
11256
11314
  const { selectedCellPositions, isFullscreen, isSelectedTable, selectedRowsIndex, selectedColumnsIndex } = tableInfo;
@@ -11356,10 +11414,91 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
11356
11414
  args: ['mousedown', ['$event']]
11357
11415
  }] } });
11358
11416
 
11359
- class TableStore {
11360
- get selectedCellPositions() {
11361
- return this.getSelectedCellPositions();
11417
+ const getTableEntry = (editor) => {
11418
+ const { tableEntry } = createTablePosition(editor);
11419
+ return tableEntry;
11420
+ };
11421
+ const getTablePath = (editor) => {
11422
+ const tableEntry = getTableEntry(editor);
11423
+ return tableEntry[1];
11424
+ };
11425
+ const getTable = (editor) => {
11426
+ const { tableEntry } = createTablePosition(editor);
11427
+ return tableEntry[0];
11428
+ };
11429
+ const getSelectedCell = (editor) => {
11430
+ if (editor && editor.selection) {
11431
+ const { cell } = createTablePosition(editor);
11432
+ return cell;
11362
11433
  }
11434
+ return null;
11435
+ };
11436
+
11437
+ const getMinAndMaxCellIndex = (editor, selectedCellPositions, maxRow, maxCol, minRow, minCol, table) => {
11438
+ const beforeCols = [];
11439
+ const beforeRows = [];
11440
+ let spanSelectedCells = [];
11441
+ if (selectedCellPositions.length) {
11442
+ spanSelectedCells = selectedCellPositions
11443
+ .map(item => {
11444
+ const { row, col } = item;
11445
+ const node = table.children[row].children[col];
11446
+ if (!node.hidden) {
11447
+ return {
11448
+ ...item,
11449
+ colspan: node.colspan || 1,
11450
+ rowspan: node.rowspan || 1
11451
+ };
11452
+ }
11453
+ })
11454
+ .filter(item => item);
11455
+ }
11456
+ table.children.map((row, rowIndex) => {
11457
+ if (rowIndex <= maxRow) {
11458
+ row.children.map((cell, colIndex) => {
11459
+ if (colIndex <= maxCol) {
11460
+ const cellRowIndex = rowIndex + (cell.rowspan || 1) - 1;
11461
+ const cellColIndex = colIndex + (cell.colspan || 1) - 1;
11462
+ if (spanSelectedCells.length) {
11463
+ const { row: selectRow, col: selectCol, rowspan: selectRowspan, colspan: selectColspan } = spanSelectedCells[0];
11464
+ if (selectRow + selectRowspan - 1 >= minRow && selectCol + selectColspan - 1 >= minCol) {
11465
+ minRow = Math.min(spanSelectedCells[0].row, minRow);
11466
+ minCol = Math.min(spanSelectedCells[0].col, minCol);
11467
+ }
11468
+ }
11469
+ if (cell.colspan && cell.colspan > 1) {
11470
+ beforeCols.push({ rowIndex, colIndex, cellColIndex });
11471
+ if (cellColIndex >= minCol && cellRowIndex >= minRow) {
11472
+ maxCol = Math.max(maxCol, cellColIndex);
11473
+ minCol = Math.min(minCol, colIndex);
11474
+ }
11475
+ }
11476
+ if (cell.rowspan && cell.rowspan > 1) {
11477
+ beforeRows.push({ rowIndex, colIndex, cellRowIndex });
11478
+ if (cellColIndex >= minCol && cellRowIndex >= minRow) {
11479
+ minRow = Math.min(minRow, rowIndex);
11480
+ maxRow = Math.max(maxRow, cellRowIndex);
11481
+ }
11482
+ }
11483
+ }
11484
+ });
11485
+ }
11486
+ });
11487
+ // 判断选区范围内之前的单元格 如果存在cellColIndex === minCol,表示当前获取的minCol并不是最小的,重新获取minCol
11488
+ const colNode = beforeCols.filter(item => item.rowIndex <= maxRow && item.colIndex <= maxCol && item.rowIndex >= minRow && item.cellColIndex === minCol);
11489
+ const rowNode = beforeRows.filter(item => item.rowIndex <= maxRow && item.colIndex <= maxCol && item.colIndex >= minCol && item.cellRowIndex === minRow);
11490
+ if (colNode.length || rowNode.length) {
11491
+ return getMinAndMaxCellIndex(editor, selectedCellPositions, maxRow, maxCol, minRow, minCol, table);
11492
+ }
11493
+ return {
11494
+ minRow,
11495
+ maxRow,
11496
+ minCol,
11497
+ maxCol
11498
+ };
11499
+ };
11500
+
11501
+ class TableStore {
11363
11502
  get dangerousCells() {
11364
11503
  return this.dangerousCells$.getValue();
11365
11504
  }
@@ -11377,44 +11516,31 @@ class TableStore {
11377
11516
  this.isRightClicking = false;
11378
11517
  this.pointerSelection = false;
11379
11518
  this.isSelectedAllCell = () => {
11380
- const pos = this.createTablePosition();
11381
- return !!this.selectedCellPositions.length && pos.getHeight() * pos.getWidth() === this.selectedCellPositions.length;
11382
- };
11383
- this.createTablePosition = () => {
11384
- const { path } = this.editor.selection.anchor;
11385
- const opts = new TableOptions();
11386
- return TablePosition.create(opts, this.editor, path);
11519
+ if (!this.editor.selection)
11520
+ return false;
11521
+ const pos = createTablePosition(this.editor);
11522
+ const selectedCellPositions = this.getSelectedCellPositions();
11523
+ return !!selectedCellPositions.length && pos.getHeight() * pos.getWidth() === selectedCellPositions.length;
11387
11524
  };
11388
11525
  }
11389
- getTableEntry() {
11390
- const { tableEntry } = this.createTablePosition();
11391
- return tableEntry;
11392
- }
11393
- getTablePath() {
11394
- const tableEntry = this.getTableEntry();
11395
- return tableEntry[1];
11396
- }
11397
11526
  getSelectedCellPositions() {
11398
- return this.selectedCells$.getValue().map((cell) => {
11399
- const path = AngularEditor.findPath(this.editor, cell);
11400
- const [row, col] = path.slice(-2);
11401
- return { row, col };
11402
- });
11527
+ return getSelectedCellPositions(this.editor, this.selectedCells$.getValue());
11403
11528
  }
11404
- calculateSelectedColumnsAndRowIndex() {
11529
+ setSelectedColumnsAndRowIndex() {
11405
11530
  if (!this.editor?.selection) {
11406
11531
  return;
11407
11532
  }
11408
- const pos = this.createTablePosition();
11533
+ const pos = createTablePosition(this.editor);
11409
11534
  if (!pos?.table) {
11410
11535
  return;
11411
11536
  }
11412
11537
  const mergeBeforeCells = [];
11413
- this.selectedCellPositions.forEach(({ row, col }) => {
11538
+ const selectedCellPositions = this.getSelectedCellPositions();
11539
+ selectedCellPositions.forEach(({ row, col }) => {
11414
11540
  // 计算合并单元格数据时,要按合并前的数据处理
11415
- mergeBeforeCells.push(...this.getCellPositionsBeforeMerge({ row, col }));
11541
+ mergeBeforeCells.push(...getCellPositionsBeforeMerge(this.editor, { row, col }));
11416
11542
  });
11417
- const cells = this.uniqueCellPosition(mergeBeforeCells);
11543
+ const cells = uniqueCellPosition(mergeBeforeCells, selectedCellPositions);
11418
11544
  const rowGroup = groupBy(cells, ({ row }) => row);
11419
11545
  const colGroup = groupBy(cells, ({ col }) => col);
11420
11546
  this.selectedRowsIndex = [];
@@ -11431,7 +11557,7 @@ class TableStore {
11431
11557
  }
11432
11558
  this.selectedRowsIndex = uniq(this.selectedRowsIndex);
11433
11559
  this.selectedColumnsIndex = uniq(this.selectedColumnsIndex);
11434
- if (this.selectedRowsIndex.length === pos.getHeight() && this.selectedColumnsIndex.length === pos.getWidth()) {
11560
+ if (isSelectedAllCell(this.editor, selectedCellPositions)) {
11435
11561
  this.isSelectedTable = true;
11436
11562
  }
11437
11563
  else {
@@ -11439,64 +11565,40 @@ class TableStore {
11439
11565
  }
11440
11566
  }
11441
11567
  setSelectedCells(cells, pos) {
11442
- const uniqueCells = this.pointerSelection ? this.uniqueCellPosition(cells) : cells;
11568
+ const uniqueCells = this.pointerSelection ? uniqueCellPosition(cells, this.getSelectedCellPositions()) : cells;
11443
11569
  const cellElements = uniqueCells.map(cell => {
11444
11570
  return pos.findCellByPath(cell);
11445
11571
  });
11446
11572
  this.selectedCells$.next(cellElements);
11447
- this.calculateSelectedColumnsAndRowIndex();
11573
+ this.setSelectedColumnsAndRowIndex();
11448
11574
  }
11449
11575
  initEditor(editor) {
11450
11576
  this.editor = editor;
11451
11577
  }
11452
- /**
11453
- * 去重重复的单元格位置
11454
- * @returns
11455
- */
11456
- uniqueCellPosition(cells) {
11457
- const result = [];
11458
- const modCells = new Set();
11459
- cells.concat(this.selectedCellPositions).forEach(cell => modCells.add(JSON.stringify(cell)));
11460
- modCells.forEach((cell) => result.push(JSON.parse(cell)));
11461
- return result;
11462
- }
11463
- /**
11464
- * 获取一定范围内所有的单元格
11465
- * @returns
11466
- */
11467
- getCellPositionsFromRange(startRow, startCol, endRow, endCol) {
11468
- const result = [];
11469
- for (let row = startRow; row < endRow; row++) {
11470
- for (let col = startCol; col < endCol; col++) {
11471
- result.push({ row, col });
11472
- }
11473
- }
11474
- return result;
11475
- }
11476
11578
  selectRow(editor, index) {
11477
11579
  this.clearLastFocusPath();
11478
- const pos = this.createTablePosition();
11479
- const cells = this.getCellPositionsFromRange(index, 0, index + 1, pos.getWidth());
11580
+ const pos = createTablePosition(editor);
11581
+ const cells = getCellPositionsFromRange(index, 0, index + 1, pos.getWidth());
11480
11582
  this.setSelectedCells(cells, pos);
11481
11583
  this.focusCell(editor, pos.tableEntry[1].concat([index, 0]));
11482
11584
  }
11483
11585
  selectColumn(editor, index) {
11484
11586
  this.clearLastFocusPath();
11485
- const pos = this.createTablePosition();
11486
- const cells = this.getCellPositionsFromRange(0, index, pos.getHeight(), index + 1);
11587
+ const pos = createTablePosition(editor);
11588
+ const cells = getCellPositionsFromRange(0, index, pos.getHeight(), index + 1);
11487
11589
  this.setSelectedCells(cells, pos);
11488
11590
  this.focusCell(editor, pos.tableEntry[1].concat([0, index]));
11489
11591
  }
11490
11592
  selectTable(editor) {
11491
11593
  this.isSelectedTable = true;
11492
- const pos = this.createTablePosition();
11493
- const cells = this.getCellPositionsFromRange(0, 0, pos.getHeight(), pos.getWidth());
11594
+ const pos = createTablePosition(editor);
11595
+ const cells = getCellPositionsFromRange(0, 0, pos.getHeight(), pos.getWidth());
11494
11596
  this.setSelectedCells(cells, pos);
11495
11597
  this.focusCell(editor, pos.tableEntry[1].concat([0, 0]));
11496
11598
  }
11497
11599
  // 拖选
11498
11600
  selectCells(editor) {
11499
- const pos = this.createTablePosition();
11601
+ const pos = createTablePosition(editor);
11500
11602
  const anchorPath = this.anchorCellPath.slice(-2);
11501
11603
  const focusPath = this.focusCellPath.slice(-2);
11502
11604
  const rows = [anchorPath[0], focusPath[0]].sort((m, n) => m - n);
@@ -11509,73 +11611,10 @@ class TableStore {
11509
11611
  const focusCol = focusPath[1] + (focusColspanCount || 1) - 1;
11510
11612
  let initMaxCol = Math.max(anchorCol, focusCol);
11511
11613
  let initMaxRow = Math.max(anchorRow, focusRow);
11512
- const { minRow, maxRow, minCol, maxCol } = this.getMinAndMaxCellIndex(initMaxRow, initMaxCol, rows[0], columns[0], pos.table);
11513
- const cells = this.getCellPositionsFromRange(minRow, minCol, maxRow + 1, maxCol + 1);
11614
+ const { minRow, maxRow, minCol, maxCol } = getMinAndMaxCellIndex(this.editor, this.getSelectedCellPositions(), initMaxRow, initMaxCol, rows[0], columns[0], pos.table);
11615
+ const cells = getCellPositionsFromRange(minRow, minCol, maxRow + 1, maxCol + 1);
11514
11616
  this.setSelectedCells(cells, pos);
11515
11617
  }
11516
- getMinAndMaxCellIndex(maxRow, maxCol, minRow, minCol, table) {
11517
- const beforeCols = [];
11518
- const beforeRows = [];
11519
- let spanSelectedCells = [];
11520
- if (this.selectedCellPositions.length) {
11521
- spanSelectedCells = this.selectedCellPositions
11522
- .map(item => {
11523
- const { row, col } = item;
11524
- const node = table.children[row].children[col];
11525
- if (!node.hidden) {
11526
- return {
11527
- ...item,
11528
- colspan: node.colspan || 1,
11529
- rowspan: node.rowspan || 1
11530
- };
11531
- }
11532
- })
11533
- .filter(item => item);
11534
- }
11535
- table.children.map((row, rowIndex) => {
11536
- if (rowIndex <= maxRow) {
11537
- row.children.map((cell, colIndex) => {
11538
- if (colIndex <= maxCol) {
11539
- const cellRowIndex = rowIndex + (cell.rowspan || 1) - 1;
11540
- const cellColIndex = colIndex + (cell.colspan || 1) - 1;
11541
- if (spanSelectedCells.length) {
11542
- const { row: selectRow, col: selectCol, rowspan: selectRowspan, colspan: selectColspan } = spanSelectedCells[0];
11543
- if (selectRow + selectRowspan - 1 >= minRow && selectCol + selectColspan - 1 >= minCol) {
11544
- minRow = Math.min(spanSelectedCells[0].row, minRow);
11545
- minCol = Math.min(spanSelectedCells[0].col, minCol);
11546
- }
11547
- }
11548
- if (cell.colspan && cell.colspan > 1) {
11549
- beforeCols.push({ rowIndex, colIndex, cellColIndex });
11550
- if (cellColIndex >= minCol && cellRowIndex >= minRow) {
11551
- maxCol = Math.max(maxCol, cellColIndex);
11552
- minCol = Math.min(minCol, colIndex);
11553
- }
11554
- }
11555
- if (cell.rowspan && cell.rowspan > 1) {
11556
- beforeRows.push({ rowIndex, colIndex, cellRowIndex });
11557
- if (cellColIndex >= minCol && cellRowIndex >= minRow) {
11558
- minRow = Math.min(minRow, rowIndex);
11559
- maxRow = Math.max(maxRow, cellRowIndex);
11560
- }
11561
- }
11562
- }
11563
- });
11564
- }
11565
- });
11566
- // 判断选区范围内之前的单元格 如果存在cellColIndex === minCol,表示当前获取的minCol并不是最小的,重新获取minCol
11567
- const colNode = beforeCols.filter(item => item.rowIndex <= maxRow && item.colIndex <= maxCol && item.rowIndex >= minRow && item.cellColIndex === minCol);
11568
- const rowNode = beforeRows.filter(item => item.rowIndex <= maxRow && item.colIndex <= maxCol && item.colIndex >= minCol && item.cellRowIndex === minRow);
11569
- if (colNode.length || rowNode.length) {
11570
- return this.getMinAndMaxCellIndex(maxRow, maxCol, minRow, minCol, table);
11571
- }
11572
- return {
11573
- minRow,
11574
- maxRow,
11575
- minCol,
11576
- maxCol
11577
- };
11578
- }
11579
11618
  // 选择单元格
11580
11619
  selectCell(cell, editor) {
11581
11620
  const node = AngularEditor.toSlateNode(editor, cell);
@@ -11584,33 +11623,23 @@ class TableStore {
11584
11623
  this.focusCellPath = path;
11585
11624
  this.focusCellElement = cell;
11586
11625
  const [row, col] = path.slice(-2);
11587
- const pos = this.createTablePosition();
11626
+ const pos = createTablePosition(editor);
11588
11627
  const result = [{ row, col }];
11628
+ const selectedCellPositions = this.getSelectedCellPositions();
11589
11629
  if (this.pointerSelection) {
11590
- result.push(...this.selectedCellPositions);
11630
+ result.push(...selectedCellPositions);
11591
11631
  // 处理单元格选中时,处理为选中多单元格
11592
- const selectedCells = this.getCellPositionsBeforeMerge({ row, col });
11632
+ const selectedCells = getCellPositionsBeforeMerge(this.editor, { row, col });
11593
11633
  result.push(...selectedCells);
11594
11634
  // 已聚焦的单元格在多选模式下选中(暂存上次聚焦的单元格数据)
11595
11635
  const focusCell = this.lastFocusCellPath?.slice(-2);
11596
11636
  if (focusCell) {
11597
- const focusCells = this.getCellPositionsBeforeMerge({ row: focusCell[0], col: focusCell[1] });
11637
+ const focusCells = getCellPositionsBeforeMerge(this.editor, { row: focusCell[0], col: focusCell[1] });
11598
11638
  result.push(...focusCells);
11599
11639
  }
11600
11640
  }
11601
11641
  this.setSelectedCells(result, pos);
11602
11642
  }
11603
- // 计算合并前的单元格
11604
- getCellPositionsBeforeMerge({ row, col }) {
11605
- const pos = this.createTablePosition();
11606
- const { rowspan, colspan } = pos.findCellByPath({ row, col });
11607
- if (rowspan || colspan) {
11608
- const colSpan = colspan ?? 1;
11609
- const rowSpan = rowspan ?? 1;
11610
- return this.getCellPositionsFromRange(row, col, row + rowSpan, col + colSpan);
11611
- }
11612
- return [{ row, col }];
11613
- }
11614
11643
  selectedCellsChange() {
11615
11644
  return this.selectedCells$.asObservable().pipe(skip(1));
11616
11645
  }
@@ -11664,9 +11693,10 @@ class TableStore {
11664
11693
  this.focusCellElement = cell;
11665
11694
  }
11666
11695
  else {
11696
+ const selectedCellPositions = this.getSelectedCellPositions();
11667
11697
  isChanged =
11668
11698
  !this.focusCellPath ||
11669
- (this.focusCellPath.toString() === this.anchorCellPath.toString() && this.selectedCellPositions.length === 0);
11699
+ (this.focusCellPath.toString() === this.anchorCellPath.toString() && selectedCellPositions.length === 0);
11670
11700
  }
11671
11701
  if (this.isPrepareSelecting && isChanged) {
11672
11702
  if (JSON.stringify(this.preFocusCellPath) !== JSON.stringify(this.focusCellPath)) {
@@ -11692,15 +11722,16 @@ class TableStore {
11692
11722
  return this.dangerousCells$.asObservable().pipe(skip(1));
11693
11723
  }
11694
11724
  setDangerousCells() {
11725
+ const selectedCellPositions = this.getSelectedCellPositions();
11695
11726
  this.dangerousRowsIndex = this.selectedRowsIndex;
11696
11727
  this.dangerousColumnsIndex = this.selectedColumnsIndex;
11697
- this.dangerousCells$.next(this.selectedCellPositions);
11728
+ this.dangerousCells$.next(selectedCellPositions);
11698
11729
  }
11699
11730
  clearDangerousCells() {
11700
11731
  this.dangerousRowsIndex = [];
11701
11732
  this.dangerousColumnsIndex = [];
11702
11733
  this.dangerousCells$.next([]);
11703
- const pos = this.createTablePosition();
11734
+ const pos = createTablePosition(this.editor);
11704
11735
  if (pos.table) {
11705
11736
  this.isSelectedTable = this.selectedRowsIndex.length === pos.getHeight() && this.selectedColumnsIndex.length === pos.getWidth();
11706
11737
  }
@@ -11709,9 +11740,10 @@ class TableStore {
11709
11740
  return merge(this.dangerousCells$.asObservable().pipe(skip(1)), this.selectedCells$.asObservable().pipe(skip(1)));
11710
11741
  }
11711
11742
  setDangerousRows() {
11712
- const cells = this.selectedCellPositions;
11743
+ const selectedCellPositions = this.getSelectedCellPositions();
11744
+ const cells = selectedCellPositions;
11713
11745
  const rows = uniq(map(cells, 'row')).valueOf();
11714
- const pos = this.createTablePosition();
11746
+ const pos = createTablePosition(this.editor);
11715
11747
  const result = [];
11716
11748
  this.dangerousRowsIndex = rows;
11717
11749
  this.isSelectedTable = rows.length === pos.getHeight();
@@ -11729,9 +11761,10 @@ class TableStore {
11729
11761
  this.dangerousCells$.next(result);
11730
11762
  }
11731
11763
  setDangerousColumns() {
11732
- const cells = this.selectedCellPositions;
11764
+ const selectedCellPositions = this.getSelectedCellPositions();
11765
+ const cells = selectedCellPositions;
11733
11766
  const cols = uniq(map(cells, 'col')).valueOf();
11734
- const pos = this.createTablePosition();
11767
+ const pos = createTablePosition(this.editor);
11735
11768
  const result = [];
11736
11769
  this.dangerousColumnsIndex = cols;
11737
11770
  this.isSelectedTable = cols.length === pos.getWidth();
@@ -11750,21 +11783,22 @@ class TableStore {
11750
11783
  }
11751
11784
  setDangerousTable() {
11752
11785
  this.isSelectedTable = true;
11753
- const pos = this.createTablePosition();
11754
- const cells = this.getCellPositionsFromRange(0, 0, pos.getHeight(), pos.getWidth());
11786
+ const pos = createTablePosition(this.editor);
11787
+ const cells = getCellPositionsFromRange(0, 0, pos.getHeight(), pos.getWidth());
11755
11788
  this.dangerousRowsIndex = [...Array(pos.getHeight())].map((_, i) => i);
11756
11789
  this.dangerousColumnsIndex = [...Array(pos.getWidth())].map((_, i) => i);
11757
11790
  this.dangerousCells$.next(cells);
11758
11791
  }
11759
11792
  selectFirstCell() {
11760
- const { row, col } = this.selectedCellPositions[0];
11761
- const tablePath = this.getTablePath();
11793
+ const selectedCellPositions = this.getSelectedCellPositions();
11794
+ const { row, col } = selectedCellPositions[0];
11795
+ const tablePath = getTablePath(this.editor);
11762
11796
  const path = Editor.start(this.editor, [...tablePath, row, col]);
11763
11797
  Transforms.select(this.editor, path);
11764
11798
  }
11765
11799
  setSelectedCellsBackgroundColor(backgroundColor) {
11766
- const cells = this.selectedCellPositions;
11767
- const tablePath = this.getTablePath();
11800
+ const tablePath = getTablePath(this.editor);
11801
+ const cells = this.getSelectedCellPositions();
11768
11802
  Editor.withoutNormalizing(this.editor, () => {
11769
11803
  for (const { row, col } of cells) {
11770
11804
  const cellPath = [...tablePath, row, col];
@@ -11772,16 +11806,9 @@ class TableStore {
11772
11806
  }
11773
11807
  });
11774
11808
  }
11775
- getSelectedCellBackgroundColor() {
11776
- if (this.editor && this.editor.selection) {
11777
- const { cell } = this.createTablePosition();
11778
- return cell && cell.backgroundColor;
11779
- }
11780
- return '';
11781
- }
11782
11809
  clearSelectedCellsContent() {
11783
- const cells = this.selectedCellPositions;
11784
- const tablePosition = this.createTablePosition();
11810
+ const cells = this.getSelectedCellPositions();
11811
+ const tablePosition = createTablePosition(this.editor);
11785
11812
  if (tablePosition.isInTable()) {
11786
11813
  Editor.withoutNormalizing(this.editor, () => {
11787
11814
  for (const { row, col } of cells) {
@@ -11793,12 +11820,9 @@ class TableStore {
11793
11820
  Transforms.select(this.editor, Editor.start(this.editor, tablePosition.cellEntry[1]));
11794
11821
  }
11795
11822
  }
11796
- mergeCell(editor) {
11797
- mergeCell(editor, this.selectedCellPositions);
11798
- }
11799
11823
  setTableOptions(editor, newOptions) {
11800
- const tablePosition = this.createTablePosition();
11801
- const tablePath = this.getTablePath();
11824
+ const tablePosition = createTablePosition(editor);
11825
+ const tablePath = getTablePath(this.editor);
11802
11826
  const table = tablePosition.table;
11803
11827
  const options = { ...table.options, ...newOptions };
11804
11828
  Transforms.setNodes(editor, { options }, { at: tablePath });
@@ -11809,7 +11833,7 @@ class TableStore {
11809
11833
  }
11810
11834
  removeColumnOrRows(selectedRowIndexs = this.selectedRowsIndex, selectedColumnIndexs = this.selectedColumnsIndex) {
11811
11835
  const { isSelectedTable } = this;
11812
- const tablePosition = this.createTablePosition();
11836
+ const tablePosition = createTablePosition(this.editor);
11813
11837
  if (isSelectedTable) {
11814
11838
  TableEditor.removeTable(this.editor);
11815
11839
  return;
@@ -11860,7 +11884,8 @@ class TheTableContextMenuService {
11860
11884
  return this.tableStore && this.tableStore.editor;
11861
11885
  }
11862
11886
  get backgroundColor() {
11863
- return this.tableStore.getSelectedCellBackgroundColor();
11887
+ const cell = getSelectedCell(this.editor);
11888
+ return cell ? cell.backgroundColor : '';
11864
11889
  }
11865
11890
  constructor(colorSelectService, tableStore, thyPopover, ngZone, theContextService) {
11866
11891
  this.colorSelectService = colorSelectService;
@@ -11977,7 +12002,7 @@ class TheTableContextMenuService {
11977
12002
  name: '合并单元格',
11978
12003
  visibility: true,
11979
12004
  actionHandle: () => {
11980
- this.tableStore.mergeCell(this.editor);
12005
+ mergeCell(this.editor, this.tableStore.getSelectedCellPositions());
11981
12006
  }
11982
12007
  },
11983
12008
  {
@@ -12036,7 +12061,7 @@ class TheTableContextMenuService {
12036
12061
  ];
12037
12062
  }
12038
12063
  getSelectedCell() {
12039
- const selectedCellPositions = this.tableStore.selectedCellPositions;
12064
+ const selectedCellPositions = this.tableStore.getSelectedCellPositions();
12040
12065
  const selectCellNodes = getSelectCellNode(this.editor, selectedCellPositions);
12041
12066
  sortCell(selectCellNodes);
12042
12067
  const leftCellDict = getLeftCellDict(selectCellNodes);
@@ -12052,14 +12077,15 @@ class TheTableContextMenuService {
12052
12077
  }
12053
12078
  openMenuList(event) {
12054
12079
  this.ngZone.run(() => {
12055
- const { selectedCellPositions, isFullscreen, selectedRowsIndex, selectedColumnsIndex, isSelectedTable } = this.tableStore;
12080
+ const { isFullscreen, selectedRowsIndex, selectedColumnsIndex, isSelectedTable } = this.tableStore;
12081
+ const selectedCellPositions = this.tableStore.getSelectedCellPositions();
12056
12082
  const tableInfo = { selectedCellPositions, isFullscreen, selectedRowsIndex, selectedColumnsIndex, isSelectedTable };
12057
12083
  const { row, col } = this.getSelectedCell();
12058
12084
  setCellMenuVisibility(this.editor, this.menuEntities, tableInfo);
12059
12085
  this.menuEntities.forEach(item => {
12060
12086
  switch (item.key) {
12061
12087
  case 'background-color':
12062
- item.backgroundColor = this.tableStore.getSelectedCellBackgroundColor();
12088
+ item.backgroundColor = this.backgroundColor;
12063
12089
  break;
12064
12090
  case TableInsertType.insertRowsUp:
12065
12091
  case TableInsertType.insertRowsDown:
@@ -12128,9 +12154,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
12128
12154
  }], ctorParameters: function () { return [{ type: TheColorSelectService }, { type: TableStore }, { type: i1$1.ThyPopover }, { type: i0.NgZone }, { type: TheContextService }]; } });
12129
12155
 
12130
12156
  class TheTableOptionsComponent {
12131
- get table() {
12132
- return this.tableStore && this.tableStore.getTableEntry()[0];
12133
- }
12134
12157
  constructor(popoverRef) {
12135
12158
  this.popoverRef = popoverRef;
12136
12159
  this.tableDropdownList = [
@@ -12151,6 +12174,9 @@ class TheTableOptionsComponent {
12151
12174
  ngOnInit() {
12152
12175
  this.setColumnOptions();
12153
12176
  }
12177
+ get table() {
12178
+ return getTable(this.editor);
12179
+ }
12154
12180
  setColumnOptions() {
12155
12181
  this.tableDropdownList.forEach(item => {
12156
12182
  const tableComponent = ELEMENT_TO_COMPONENT.get(this.table);
@@ -12238,7 +12264,7 @@ class TheTableToolbarComponent {
12238
12264
  actionHandle: () => {
12239
12265
  event.preventDefault();
12240
12266
  event.stopPropagation();
12241
- this.tableStore.mergeCell(this.editor);
12267
+ mergeCell(this.editor, this.tableStore.getSelectedCellPositions());
12242
12268
  this.popoverRef.close();
12243
12269
  this.tableStore.clearSelectedCells();
12244
12270
  }
@@ -12260,12 +12286,13 @@ class TheTableToolbarComponent {
12260
12286
  }
12261
12287
  ngOnInit() {
12262
12288
  this.isColumnEqual = this.tableElement?.columns?.every(col => this.tableElement.columns[0].width === col.width) ?? true;
12263
- const { selectedCellPositions, isSelectedTable } = this.tableStore;
12264
- const tableInfo = { selectedCellPositions, isSelectedTable };
12289
+ const selectedCellPositions = this.tableStore.getSelectedCellPositions();
12290
+ const tableInfo = { selectedCellPositions, isSelectedTable: this.tableStore.isSelectedTable };
12265
12291
  this.isRectangle = isRectangularInTableCells(this.editor, selectedCellPositions);
12266
12292
  this.setDeleteIcon();
12267
12293
  setCellMenuVisibility(this.editor, this.cellMenuList, tableInfo);
12268
- this.selectedColor = this.tableStore.getSelectedCellBackgroundColor();
12294
+ const cell = getSelectedCell(this.editor);
12295
+ this.selectedColor = cell ? cell.backgroundColor : '';
12269
12296
  const path = TheEditor.findPath(this.editor, this.tableElement);
12270
12297
  this.tableChangeSubscriber = this.tableStore.tableChange().subscribe(() => {
12271
12298
  const columns = getNode(this.editor, path).columns;
@@ -12277,8 +12304,9 @@ class TheTableToolbarComponent {
12277
12304
  this.colorSelectService.closeColorSelect();
12278
12305
  }
12279
12306
  setDeleteIcon() {
12280
- const { selectedCellPositions, selectedRowsIndex, selectedColumnsIndex, createTablePosition } = this.tableStore;
12281
- const pos = createTablePosition();
12307
+ const { selectedRowsIndex, selectedColumnsIndex } = this.tableStore;
12308
+ const selectedCellPositions = this.tableStore.getSelectedCellPositions();
12309
+ const pos = createTablePosition(this.editor);
12282
12310
  if (this.tableStore.selectedRowsIndex.length > 0) {
12283
12311
  this.deleteIcon = DeleteIcon['table-delete-rows'];
12284
12312
  this.iconName = '删除整行';
@@ -12553,9 +12581,13 @@ const getGridColumns = (headerRow, cellsWidth) => {
12553
12581
  });
12554
12582
  return result;
12555
12583
  };
12556
- const getColumnsWidth = (cellRow) => {
12584
+ const getColumnsWidth = (cellRow, isColgroup = false) => {
12557
12585
  const result = [];
12558
12586
  cellRow.childNodes.forEach((item) => {
12587
+ if (isColgroup && IS_SAFARI) {
12588
+ result.push(item.offsetWidth);
12589
+ return;
12590
+ }
12559
12591
  if (item.getBoundingClientRect) {
12560
12592
  result.push(item.getBoundingClientRect().width);
12561
12593
  }
@@ -12563,6 +12595,113 @@ const getColumnsWidth = (cellRow) => {
12563
12595
  return result;
12564
12596
  };
12565
12597
 
12598
+ /**
12599
+ * 计算最小行跨距单元格
12600
+ * @param element TableElement
12601
+ * @returns
12602
+ */
12603
+ const calculateMinRowSpanCellForRows = (element) => {
12604
+ const cells = element.children.map((row, index) => {
12605
+ const noHiddenCells = row.children.filter(cell => !cell.hidden);
12606
+ if (noHiddenCells.length > 0) {
12607
+ const minRowspan = Math.min.apply(Math, noHiddenCells.map(cell => {
12608
+ return cell.rowspan || 1;
12609
+ }));
12610
+ const cell = row.children.find(item => !item.hidden && (item.rowspan || 1) === minRowspan);
12611
+ return {
12612
+ cell,
12613
+ rowIndex: index
12614
+ };
12615
+ }
12616
+ else {
12617
+ return {
12618
+ rowIndex: index
12619
+ };
12620
+ }
12621
+ });
12622
+ return cells;
12623
+ };
12624
+ /**
12625
+ * 计算行控件的平均高度
12626
+ * @param previousCombineRowIndex
12627
+ * @param previousRowIndex
12628
+ * @param rowControls
12629
+ */
12630
+ const calculateRowControlsAvgHeight = (previousCombineRowIndex, previousRowIndex, rowControls) => {
12631
+ const rowControl = rowControls[previousRowIndex];
12632
+ const count = previousCombineRowIndex - previousRowIndex;
12633
+ const avgHeight = Math.floor(rowControl.height / (count + 1));
12634
+ const firstHeight = rowControl.height - avgHeight * count;
12635
+ rowControl.height = firstHeight;
12636
+ rowControls
12637
+ .filter((_, index) => index > previousRowIndex && index <= previousCombineRowIndex)
12638
+ .forEach(rowControl => {
12639
+ rowControl.height = avgHeight;
12640
+ });
12641
+ };
12642
+ const getBelowRowHeight = (editor, cells, index, rowIndex, rowspan) => {
12643
+ let belowRowlHeight = 0;
12644
+ cells.slice(index + 1, cells.length).map(item => {
12645
+ if (!item.cell) {
12646
+ return;
12647
+ }
12648
+ if (rowIndex + rowspan > item.rowIndex) {
12649
+ const cellDom = AngularEditor.toDOMNode(editor, item.cell);
12650
+ if (item.cell.rowspan > 1) {
12651
+ // 如果下方单元格的rowspan > 1,递归计算
12652
+ const height = getBelowRowHeight(editor, cells, cells.findIndex(cell => cell.rowIndex === item.rowIndex), item.rowIndex, item.cell.rowspan);
12653
+ belowRowlHeight += getElementHeight(cellDom) - height;
12654
+ }
12655
+ else {
12656
+ belowRowlHeight += getElementHeight(cellDom);
12657
+ }
12658
+ }
12659
+ });
12660
+ return belowRowlHeight;
12661
+ };
12662
+ const calculateRowControls = (editor, element) => {
12663
+ const minRowSpanCellForRows = calculateMinRowSpanCellForRows(element);
12664
+ const rowControls = [];
12665
+ let previousRowIndex = 0;
12666
+ let previousCombineRowIndex = 0;
12667
+ minRowSpanCellForRows.forEach((cellInfo, index) => {
12668
+ if (!cellInfo.cell) {
12669
+ rowControls.push({
12670
+ height: 0,
12671
+ rowIndex: index
12672
+ });
12673
+ previousCombineRowIndex = index;
12674
+ if (index === minRowSpanCellForRows.length - 1) {
12675
+ calculateRowControlsAvgHeight(previousCombineRowIndex, previousRowIndex, rowControls);
12676
+ }
12677
+ return;
12678
+ }
12679
+ // calculate combine row height
12680
+ if (previousCombineRowIndex > previousRowIndex) {
12681
+ calculateRowControlsAvgHeight(previousCombineRowIndex, previousRowIndex, rowControls);
12682
+ previousCombineRowIndex = 0;
12683
+ }
12684
+ const cellDom = AngularEditor.toDOMNode(editor, cellInfo.cell);
12685
+ let height = getElementHeight(cellDom);
12686
+ // 当cell为合并的单元格(rowspan > 1),计算其实际高度(当前单元格的高度 - 下方合并单元格的高度)
12687
+ if (cellInfo.cell.rowspan > 1) {
12688
+ const calcHeight = height - getBelowRowHeight(editor, minRowSpanCellForRows, index, cellInfo.rowIndex, cellInfo.cell.rowspan);
12689
+ rowControls.push({
12690
+ height: calcHeight,
12691
+ rowIndex: cellInfo.rowIndex
12692
+ });
12693
+ }
12694
+ else {
12695
+ rowControls.push({
12696
+ height,
12697
+ rowIndex: cellInfo.rowIndex
12698
+ });
12699
+ }
12700
+ previousRowIndex = index;
12701
+ });
12702
+ return rowControls;
12703
+ };
12704
+
12566
12705
  const TABLE_SELECTOR = '.the-table';
12567
12706
  const TABLE_WRAPPER_SELECTOR = '.the-table-wrapper';
12568
12707
  const RESIZE_OVERLAY_SELECTOR = '.the-table-resize-overlay-thumb';
@@ -12658,19 +12797,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
12658
12797
  }] }]; } });
12659
12798
 
12660
12799
  class TheInsertMarkComponent {
12661
- get disabled() {
12662
- return this.tableStore && !!this.tableStore.selectedCellPositions.length;
12663
- }
12664
12800
  get editor() {
12665
12801
  return this.tableStore && this.tableStore.editor;
12666
12802
  }
12667
12803
  constructor(cdr, renderer2) {
12668
12804
  this.cdr = cdr;
12669
12805
  this.renderer2 = renderer2;
12806
+ this.destroy$ = new Subject();
12670
12807
  this.tooltipContent = '';
12808
+ this.disabled = false;
12671
12809
  }
12672
12810
  ngOnInit() {
12673
12811
  this.tooltipContent = this.type === 'row' ? '插入行' : '插入列';
12812
+ this.tableStore
12813
+ .selectedCellsChange()
12814
+ .pipe(takeUntil(this.destroy$))
12815
+ .subscribe(selectedCellPositions => {
12816
+ this.disabled = !!selectedCellPositions.length;
12817
+ });
12818
+ }
12819
+ ngOnDestroy() {
12820
+ this.destroy$?.next();
12821
+ this.destroy$?.complete();
12674
12822
  }
12675
12823
  onMouseDown(event) {
12676
12824
  event.preventDefault();
@@ -12706,7 +12854,7 @@ class TheInsertMarkComponent {
12706
12854
  getLength() {
12707
12855
  const { selection } = this.editor;
12708
12856
  if (selection && Range.isCollapsed(selection)) {
12709
- const { table } = TablePosition.create(new TableOptions(), this.editor, selection.anchor.path);
12857
+ const { table } = createTablePosition(this.editor, selection.anchor.path);
12710
12858
  if (!table) {
12711
12859
  return;
12712
12860
  }
@@ -12766,7 +12914,7 @@ class TheTableComponent extends TheBaseElementComponent {
12766
12914
  if (this.initialized) {
12767
12915
  Promise.resolve().then(() => {
12768
12916
  this.tableStore.emitTableChange();
12769
- this.tableStore.calculateSelectedColumnsAndRowIndex();
12917
+ this.tableStore.setSelectedColumnsAndRowIndex();
12770
12918
  this.bindTableScrollingShadow();
12771
12919
  this.useRowControls();
12772
12920
  this.setHeaderCellStyle();
@@ -12834,7 +12982,7 @@ class TheTableComponent extends TheBaseElementComponent {
12834
12982
  .selectedCellsChange()
12835
12983
  .pipe(takeUntil(this.destroy$))
12836
12984
  .subscribe(() => {
12837
- this.isSelectedAllCell = this.tableStore.isSelectedAllCell();
12985
+ this.isSelectedAllCell = isSelectedAllCell(this.editor, this.tableStore.getSelectedCellPositions());
12838
12986
  });
12839
12987
  }
12840
12988
  getWrapperWidth() {
@@ -12930,7 +13078,7 @@ class TheTableComponent extends TheBaseElementComponent {
12930
13078
  }
12931
13079
  }
12932
13080
  calcHeaderRowShadow() {
12933
- const headerRowHeight = this.calculateRowControls()[0]?.height;
13081
+ const headerRowHeight = calculateRowControls(this.editor, this.element)[0]?.height;
12934
13082
  let height = headerRowHeight;
12935
13083
  // 默认(没有聚焦)的 top 值:滚动容器高度 + 表格的padding(8)
12936
13084
  let top = this.scrollContainerTop + TABLE_PADDING$1;
@@ -12955,7 +13103,7 @@ class TheTableComponent extends TheBaseElementComponent {
12955
13103
  this.scrollContainerTop = event.target.getBoundingClientRect().top;
12956
13104
  const clientRect = this.theTableElement.nativeElement.getBoundingClientRect();
12957
13105
  const headerTopHeight = this.isInTable ? -19 : 11;
12958
- const headerRowHeight = this.calculateRowControls()[0]?.height;
13106
+ const headerRowHeight = calculateRowControls(this.editor, this.element)[0]?.height;
12959
13107
  const top = clientRect.top + headerTopHeight;
12960
13108
  this.isStickyTop =
12961
13109
  top <= this.scrollContainerTop + 8 &&
@@ -13035,7 +13183,9 @@ class TheTableComponent extends TheBaseElementComponent {
13035
13183
  const colControl = this.columnControlsWrapper.nativeElement;
13036
13184
  if (this.freezeRowPipe.transform(this.element, this.headerRow, this.tablePluginOptions)) {
13037
13185
  const headerRow = this.tbodyElement.nativeElement.childNodes[0];
13038
- const cellsWidth = this.colgroup?.nativeElement ? getColumnsWidth(this.colgroup.nativeElement) : this.getDefaultCellWidth();
13186
+ const cellsWidth = this.colgroup?.nativeElement
13187
+ ? getColumnsWidth(this.colgroup.nativeElement, true)
13188
+ : this.getDefaultCellWidth();
13039
13189
  const gridColumns = getGridColumns(headerRow, cellsWidth);
13040
13190
  const tablePadding = 44;
13041
13191
  let tableWidth = this.elementRef.nativeElement.getBoundingClientRect().width;
@@ -13052,7 +13202,7 @@ class TheTableComponent extends TheBaseElementComponent {
13052
13202
  const headerRow = this.nativeElement.querySelector('tbody tr');
13053
13203
  const rowControlInner = this.rowControlsInner.nativeElement;
13054
13204
  const tableCornerBtn = this.cornerControl.nativeElement;
13055
- const headerRowHeight = this.calculateRowControls()[0]?.height;
13205
+ const headerRowHeight = calculateRowControls(this.editor, this.element)[0]?.height;
13056
13206
  const numberedColumn = this.element.options?.numberedColumn;
13057
13207
  if (this.isStickyTop) {
13058
13208
  this.renderer.addClass(this.nativeElement, TableWithStickyRowClass);
@@ -13149,107 +13299,12 @@ class TheTableComponent extends TheBaseElementComponent {
13149
13299
  }
13150
13300
  useRowControls() {
13151
13301
  if ((this.selection && !this.readonly) || this.element.options?.numberedColumn || this.tableStore.isRightClicking) {
13152
- this.rowControls = this.calculateRowControls();
13302
+ this.rowControls = calculateRowControls(this.editor, this.element);
13153
13303
  }
13154
13304
  }
13155
13305
  detectChanges() {
13156
13306
  this.cdr.detectChanges();
13157
13307
  }
13158
- calculateMinRowSpanCellForRows() {
13159
- const cells = this.element.children.map((row, index) => {
13160
- const noHiddenCells = row.children.filter(cell => !cell.hidden);
13161
- if (noHiddenCells.length > 0) {
13162
- const minRowspan = Math.min.apply(Math, noHiddenCells.map(cell => {
13163
- return cell.rowspan || 1;
13164
- }));
13165
- const cell = row.children.find(item => !item.hidden && (item.rowspan || 1) === minRowspan);
13166
- return {
13167
- cell,
13168
- rowIndex: index
13169
- };
13170
- }
13171
- else {
13172
- return {
13173
- rowIndex: index
13174
- };
13175
- }
13176
- });
13177
- return cells;
13178
- }
13179
- calculateRowControls() {
13180
- const minRowSpanCellForRows = this.calculateMinRowSpanCellForRows();
13181
- const rowControls = [];
13182
- let previousRowIndex = 0;
13183
- let previousCombineRowIndex = 0;
13184
- minRowSpanCellForRows.forEach((cellInfo, index) => {
13185
- if (!cellInfo.cell) {
13186
- rowControls.push({
13187
- height: 0,
13188
- rowIndex: index
13189
- });
13190
- previousCombineRowIndex = index;
13191
- if (index === minRowSpanCellForRows.length - 1) {
13192
- this.calculateRowControlsAvgHeight(previousCombineRowIndex, previousRowIndex, rowControls);
13193
- }
13194
- return;
13195
- }
13196
- // calculate combine row height
13197
- if (previousCombineRowIndex > previousRowIndex) {
13198
- this.calculateRowControlsAvgHeight(previousCombineRowIndex, previousRowIndex, rowControls);
13199
- previousCombineRowIndex = 0;
13200
- }
13201
- const cellDom = AngularEditor.toDOMNode(this.editor, cellInfo.cell);
13202
- let height = getElementHeight(cellDom);
13203
- // 当cell为合并的单元格(rowspan > 1),计算其实际高度(当前单元格的高度 - 下方合并单元格的高度)
13204
- if (cellInfo.cell.rowspan > 1) {
13205
- const calcHeight = height - this.getBelowRowHeight(minRowSpanCellForRows, index, cellInfo.rowIndex, cellInfo.cell.rowspan);
13206
- rowControls.push({
13207
- height: calcHeight,
13208
- rowIndex: cellInfo.rowIndex
13209
- });
13210
- }
13211
- else {
13212
- rowControls.push({
13213
- height,
13214
- rowIndex: cellInfo.rowIndex
13215
- });
13216
- }
13217
- previousRowIndex = index;
13218
- });
13219
- return rowControls;
13220
- }
13221
- calculateRowControlsAvgHeight(previousCombineRowIndex, previousRowIndex, rowControls) {
13222
- const rowControl = rowControls[previousRowIndex];
13223
- const count = previousCombineRowIndex - previousRowIndex;
13224
- const avgHeight = Math.floor(rowControl.height / (count + 1));
13225
- const firstHeight = rowControl.height - avgHeight * count;
13226
- rowControl.height = firstHeight;
13227
- rowControls
13228
- .filter((item, _index) => _index > previousRowIndex && _index <= previousCombineRowIndex)
13229
- .forEach(rowControl => {
13230
- rowControl.height = avgHeight;
13231
- });
13232
- }
13233
- getBelowRowHeight(cells, index, rowIndex, rowspan) {
13234
- let belowRowlHeight = 0;
13235
- cells.slice(index + 1, cells.length).map(item => {
13236
- if (!item.cell) {
13237
- return;
13238
- }
13239
- if (rowIndex + rowspan > item.rowIndex) {
13240
- const cellDom = AngularEditor.toDOMNode(this.editor, item.cell);
13241
- if (item.cell.rowspan > 1) {
13242
- // 如果下方单元格的rowspan > 1,递归计算
13243
- const height = this.getBelowRowHeight(cells, cells.findIndex(cell => cell.rowIndex === item.rowIndex), item.rowIndex, item.cell.rowspan);
13244
- belowRowlHeight += getElementHeight(cellDom) - height;
13245
- }
13246
- else {
13247
- belowRowlHeight += getElementHeight(cellDom);
13248
- }
13249
- }
13250
- });
13251
- return belowRowlHeight;
13252
- }
13253
13308
  resolveImage() {
13254
13309
  const imageElements = this.nativeElement.querySelectorAll('img');
13255
13310
  if (imageElements.length) {
@@ -13278,8 +13333,8 @@ class TheTableComponent extends TheBaseElementComponent {
13278
13333
  if (this.selection && !this.readonly) {
13279
13334
  const opts = new TableOptions();
13280
13335
  const selection = this.editor.selection;
13281
- const startPosition = TablePosition.create(opts, this.editor, selection.anchor.path);
13282
- const endPosition = TablePosition.create(opts, this.editor, selection.focus.path);
13336
+ const startPosition = createTablePosition(this.editor);
13337
+ const endPosition = createTablePosition(this.editor, selection.focus.path);
13283
13338
  this.isInTable = startPosition.isInTable() && endPosition.isInTable();
13284
13339
  }
13285
13340
  else {
@@ -13425,7 +13480,8 @@ class TheTableComponent extends TheBaseElementComponent {
13425
13480
  return !isVirtualKey(e) && !this.theTableContextMenuService.isOpened;
13426
13481
  })))
13427
13482
  .pipe(filter(() => {
13428
- return this.tableStore.selectedCellPositions?.length > 0;
13483
+ const selectedCellPositions = this.tableStore.getSelectedCellPositions();
13484
+ return selectedCellPositions?.length > 0;
13429
13485
  }), takeUntil(this.destroy$))
13430
13486
  .subscribe((e) => {
13431
13487
  if (e.type === 'keydown') {
@@ -13610,7 +13666,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
13610
13666
  */
13611
13667
  function clearTableNode(opts, editor, isTopToBot) {
13612
13668
  const { selection } = editor;
13613
- const element = TablePosition.create(opts, editor, selection.focus.path);
13669
+ const element = createTablePosition(editor, selection.focus.path);
13614
13670
  const rowIndex = element.getRowIndex();
13615
13671
  const colIndex = element.getColumnIndex();
13616
13672
  const removeRow = isTopToBot ? 0 : rowIndex + 1;
@@ -13661,9 +13717,8 @@ class TheTableRowComponent extends TheBaseElementComponent {
13661
13717
  }
13662
13718
  onContextChange() {
13663
13719
  super.onContextChange();
13664
- const opts = new TableOptions();
13665
13720
  const path = TheEditor.findPath(this.editor, this.element);
13666
- const tablePosition = TablePosition.create(opts, this.editor, path.concat(0));
13721
+ const tablePosition = createTablePosition(this.editor, path.concat(0));
13667
13722
  const rowIndex = tablePosition.getRowIndex();
13668
13723
  if (rowIndex === 0) {
13669
13724
  this.renderer.addClass(this.elementRef.nativeElement, 'the-sticky-row');
@@ -14214,10 +14269,9 @@ class TheTdComponent extends TheBaseElementComponent {
14214
14269
  useElementStyle(this.elementRef.nativeElement, this.element);
14215
14270
  }
14216
14271
  useTablePosition() {
14217
- const opts = new TableOptions();
14218
14272
  const path = TheEditor.findPath(this.editor, this.element);
14219
14273
  // must be path of cell's children
14220
- this.tablePosition = TablePosition.create(opts, this.editor, path.concat(0));
14274
+ this.tablePosition = createTablePosition(this.editor, path.concat(0));
14221
14275
  }
14222
14276
  useBackground() {
14223
14277
  if (this.element.backgroundColor !== this.backgroundColor) {
@@ -14875,7 +14929,7 @@ const withTable = (editor) => {
14875
14929
  const [, startBlockPath] = Editor.above(editor, {
14876
14930
  match: n => Editor.isBlock(editor, n)
14877
14931
  });
14878
- const startPosition = TablePosition.create(opts, editor, selection.anchor.path);
14932
+ const startPosition = createTablePosition(editor);
14879
14933
  if (startBlockPath.length <= startPosition.cellEntry[1].length + 1 &&
14880
14934
  startBlockPath.pop() === 0 &&
14881
14935
  selection.anchor.offset === 0 &&
@@ -14889,8 +14943,8 @@ const withTable = (editor) => {
14889
14943
  const opts = new TableOptions();
14890
14944
  const afterPoint = Editor.after(editor, editor.selection);
14891
14945
  if (afterPoint && isRangeInTable(opts, editor, { anchor: afterPoint, focus: afterPoint })) {
14892
- const beforePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
14893
- const afterPosition = TablePosition.create(opts, editor, afterPoint.path);
14946
+ const beforePosition = createTablePosition(editor);
14947
+ const afterPosition = createTablePosition(editor, afterPoint.path);
14894
14948
  if (beforePosition.cell && beforePosition.cell !== afterPosition.cell) {
14895
14949
  return;
14896
14950
  }
@@ -14926,8 +14980,8 @@ const withTable = (editor) => {
14926
14980
  onKeydown(event);
14927
14981
  return;
14928
14982
  }
14929
- const startPosition = TablePosition.create(opts, editor, selection.anchor.path);
14930
- const endPosition = TablePosition.create(opts, editor, selection.focus.path);
14983
+ const startPosition = createTablePosition(editor);
14984
+ const endPosition = createTablePosition(editor, selection.focus.path);
14931
14985
  const isCollapsed = Range.isCollapsed(selection);
14932
14986
  if (startPosition && endPosition && endPosition.isInTable()) {
14933
14987
  // for keyboard up and down key in the table
@@ -15004,7 +15058,7 @@ const withTable = (editor) => {
15004
15058
  }
15005
15059
  if (isMoveBackward) {
15006
15060
  const beforePoint = Editor.before(editor, editor.selection);
15007
- const beforePosition = beforePoint && TablePosition.create(opts, editor, beforePoint.path);
15061
+ const beforePosition = beforePoint && createTablePosition(editor, beforePoint.path);
15008
15062
  if (beforePosition && beforePosition.cell && beforePosition.cell.hidden) {
15009
15063
  event.preventDefault();
15010
15064
  const at = Editor.end(editor, TheEditor.findPath(editor, beforePosition.findPrevious()));
@@ -15013,7 +15067,7 @@ const withTable = (editor) => {
15013
15067
  }
15014
15068
  if (isMoveForward) {
15015
15069
  const afterPoint = Editor.after(editor, editor.selection);
15016
- const afterPosition = afterPoint && TablePosition.create(opts, editor, afterPoint.path);
15070
+ const afterPosition = afterPoint && createTablePosition(editor, afterPoint.path);
15017
15071
  if (afterPosition.cell && afterPosition.cell.hidden) {
15018
15072
  event.preventDefault();
15019
15073
  const nextCell = afterPosition.findNext();
@@ -15062,10 +15116,9 @@ const withTable = (editor) => {
15062
15116
  setFragmentData(unit);
15063
15117
  return;
15064
15118
  }
15065
- const { selection } = editor;
15066
- const tablePosition = TablePosition.create(opts, editor, selection.anchor.path);
15119
+ const tablePosition = createTablePosition(editor);
15067
15120
  const tableComponent = ELEMENT_TO_COMPONENT.get(tablePosition.table);
15068
- const selectedCellPositions = tableComponent.tableStore.selectedCellPositions;
15121
+ const selectedCellPositions = tableComponent.tableStore.getSelectedCellPositions();
15069
15122
  let tableFragment = null;
15070
15123
  if (tableComponent.tableStore.selectedRowsIndex.length > 0) {
15071
15124
  const rows = tablePosition.table.children.slice(tableComponent.tableStore.selectedRowsIndex[0], tableComponent.tableStore.selectedRowsIndex[tableComponent.tableStore.selectedRowsIndex.length - 1] + 1);
@@ -15117,7 +15170,7 @@ const withTable = (editor) => {
15117
15170
  fragment.length === 1 &&
15118
15171
  Element$1.isElement(fragment[0]) &&
15119
15172
  fragment[0].type === ElementKinds.table) {
15120
- const tablePosition = TablePosition.create(opts, editor, selection.anchor.path);
15173
+ const tablePosition = createTablePosition(editor);
15121
15174
  const clipboardTable = fragment[0].children;
15122
15175
  const clipboardRow = clipboardTable[0].children;
15123
15176
  const selectRowIndex = tablePosition.getRowIndex();
@@ -15259,7 +15312,7 @@ const withTable = (editor) => {
15259
15312
  node.hidden) {
15260
15313
  setTimeout(() => {
15261
15314
  const opts = new TableOptions();
15262
- const tablePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
15315
+ const tablePosition = createTablePosition(editor);
15263
15316
  const origin = getOriginCell(tablePosition.table, tablePosition.getRowIndex(), tablePosition.getColumnIndex());
15264
15317
  if (origin) {
15265
15318
  const path = AngularEditor.findPath(editor, origin);
@@ -15295,10 +15348,9 @@ const withTable = (editor) => {
15295
15348
  deleteCutData();
15296
15349
  return;
15297
15350
  }
15298
- const { selection } = editor;
15299
- const element = TablePosition.create(opts, editor, selection.anchor.path);
15351
+ const element = createTablePosition(editor);
15300
15352
  const tableComponent = ELEMENT_TO_COMPONENT.get(element.table);
15301
- const selectedCellPositions = tableComponent.tableStore.selectedCellPositions;
15353
+ const selectedCellPositions = tableComponent.tableStore.getSelectedCellPositions();
15302
15354
  if (selectedCellPositions.length > 0) {
15303
15355
  Editor.withoutNormalizing(editor, () => {
15304
15356
  if (tableComponent.tableStore.isSelectedTable) {
@@ -15325,7 +15377,7 @@ const withTable = (editor) => {
15325
15377
  const isSelectionOperation = editor.operations.every(op => Operation.isSelectionOperation(op));
15326
15378
  if (isCollapsed && isSelectionOperation) {
15327
15379
  const opts = new TableOptions();
15328
- const tablePosition = TablePosition.create(opts, editor, editor.selection.anchor.path);
15380
+ const tablePosition = createTablePosition(editor);
15329
15381
  if (tablePosition.isInTable() && tablePosition.cell.hidden) {
15330
15382
  TableEditor.selectOriginCell(editor, tablePosition.table, tablePosition.getRowIndex(), tablePosition.getColumnIndex(), false);
15331
15383
  }
@@ -15520,7 +15572,7 @@ const createTodoItemPlugin = createPluginFactory({
15520
15572
  const internalPlugins = () => [
15521
15573
  createTheHistoryPlugin(),
15522
15574
  createCommonPlugin(),
15523
- createAutoInsertDataPlugin(),
15575
+ createInsertDataByInvalidTypePlugin(),
15524
15576
  createRemoveEmptyPlugin(),
15525
15577
  createRemoveVoidPlugin(),
15526
15578
  createBlockCardPlugin(),
@@ -16491,5 +16543,5 @@ const withTestPlugin = (plugins, initValue) => {
16491
16543
  * Generated bundle index. Do not edit.
16492
16544
  */
16493
16545
 
16494
- export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETE_BACKWARD_TYPES, BackgroundColors, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, ColorEditor, Colors, ColumnResizeNotifierSource, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DISABLED_OPERATE_TYPES, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultPluginMenu, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HoveredCellInfo, HrEditor, IS_MAC, ImageEditor, IndentEditor, Indents, InlineCodeEditor, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, MentionEditor, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, PluginKeys, PluginMenuIcons, PluginMenuSvgs, Position, QuickInsertEditor, STANDARD_HEADING_TYPES, ScrollDirection, SpecialBackgroundColor, SpecialTextColor, TAB_SPACE, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_ORIGIN_ANCHOR, THE_EDITOR_POPOVER_REF, THE_EDITOR_PREVIOUS_SELECTION, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_LISTBOX_PARENT_GROUP_TOKEN, THE_LISTBOX_PARENT_OPTION_TOKEN, THE_LISTBOX_TOKEN, THE_MODE_PROVIDER, THE_MODE_TOKEN, THE_PLUGIN_MENU_REF, THE_UPLOAD_SERVICE_TOKEN, TableCellEventDispatcher, TableEditor, TableHeaderBackgroundColor, TheBaseElementComponent, TheBaseSuggestion, TheBaseToolbarDropdown, TheBaseToolbarItem, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheListboxDirective, TheListboxGroupDirective, TheListboxOptionDirective, TheMode, TheModeConfig, ThePluginMenu, ThePluginMenuComponent, ThePluginMenuItemType, ThePreventDefaultDirective, index$1 as TheQueries, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, autoFocus, base64toBlob, buildPluginMenu, buildPluginMenuItemMap, coercePixelsFromCssValue, combinePlugins, copyNode, copyNodeForSafari, createEmptyParagraph, createMentionPlugin, createPluginFactory, createToolbar, createVerticalAlignPlugin, dataDeserialize, dataSerializing, deleteElementKey, extractFragment, filterTextFormat, flattenDeepPlugins, getColsTotalWidth, getEditorUUID, getElementClassByPrefix, getElementHeight, getElementWidth, getEndBlock, getPlugin, getPluginOptions, getPlugins, getRowsTotalHeight, getStartBlock, getToolbarClass, headingOptions, htmlToTheia, idCreator, inValidTypes, initializeDefaultMenuIcons, internalPlugins, isCleanEmptyParagraph, isDirectionKeydown, isPureEmptyParagraph, mergeArray, mergeDeepPlugins, mergeElementOptions, mergeOptions, nestedStructureByKey, plainToTheia, pluginsByKey, reSelection, recursionNodes, refocus, scrollIntoView, setEditorUUID, useElementStyle, withMention, withTestPlugin, withTheia };
16546
+ export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETE_BACKWARD_TYPES, BackgroundColors, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, ColorEditor, Colors, ColumnResizeNotifierSource, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DISABLED_OPERATE_TYPES, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultPluginMenu, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HoveredCellInfo, HrEditor, IS_MAC, ImageEditor, IndentEditor, Indents, InlineCodeEditor, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, MentionEditor, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, PluginKeys, PluginMenuIcons, PluginMenuSvgs, Position, QuickInsertEditor, STANDARD_HEADING_TYPES, ScrollDirection, SpecialBackgroundColor, SpecialTextColor, TAB_SPACE, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_ORIGIN_ANCHOR, THE_EDITOR_POPOVER_REF, THE_EDITOR_PREVIOUS_SELECTION, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_LISTBOX_PARENT_GROUP_TOKEN, THE_LISTBOX_PARENT_OPTION_TOKEN, THE_LISTBOX_TOKEN, THE_MODE_PROVIDER, THE_MODE_TOKEN, THE_PLUGIN_MENU_REF, THE_UPLOAD_SERVICE_TOKEN, TableCellEventDispatcher, TableEditor, TableHeaderBackgroundColor, TheBaseElementComponent, TheBaseSuggestion, TheBaseToolbarDropdown, TheBaseToolbarItem, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheListboxDirective, TheListboxGroupDirective, TheListboxOptionDirective, TheMode, TheModeConfig, ThePluginMenu, ThePluginMenuComponent, ThePluginMenuItemType, ThePreventDefaultDirective, index$1 as TheQueries, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, autoFocus, base64toBlob, buildPluginMenu, buildPluginMenuItemMap, coercePixelsFromCssValue, combinePlugins, copyNode, copyNodeForSafari, createEmptyParagraph, createMentionPlugin, createPluginFactory, createToolbar, createVerticalAlignPlugin, dataDeserialize, dataSerializing, deleteElementKey, extractFragment, filterTextFormat, flattenDeepPlugins, getColsTotalWidth, getEditorUUID, getElementClassByPrefix, getElementHeight, getElementWidth, getEndBlock, getPlugin, getPluginOptions, getPlugins, getRowsTotalHeight, getStartBlock, getToolbarClass, headingOptions, htmlToTheia, idCreator, inValidTypes, initializeDefaultMenuIcons, insertDataByInvalidType, internalPlugins, isCleanEmptyParagraph, isDirectionKeydown, isPureEmptyParagraph, mergeArray, mergeDeepPlugins, mergeElementOptions, mergeOptions, nestedStructureByKey, plainToTheia, pluginsByKey, reSelection, recursionNodes, refocus, scrollIntoView, setEditorUUID, useElementStyle, withMention, withTestPlugin, withTheia };
16495
16547
  //# sourceMappingURL=worktile-theia.mjs.map