@textbus/xnote 0.0.10 → 0.0.11

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.
@@ -1834,11 +1834,18 @@ function findNonIntersectingRectangles(rectangles) {
1834
1834
  function getMaxRectangle(start, rectangles) {
1835
1835
  let merged = start;
1836
1836
  const remaining = [...rectangles];
1837
+ const unMerged = [];
1837
1838
  while (remaining.length > 0) {
1838
1839
  const current = remaining.shift();
1839
1840
  if (current.intersects(merged)) {
1840
1841
  merged = current.merge(merged);
1841
1842
  }
1843
+ else {
1844
+ unMerged.push(current);
1845
+ }
1846
+ }
1847
+ if (unMerged.length && merged !== start) {
1848
+ return getMaxRectangle(merged, unMerged);
1842
1849
  }
1843
1850
  return merged;
1844
1851
  }
@@ -2073,13 +2080,13 @@ class TableComponent extends Component {
2073
2080
  endIndex: i.length
2074
2081
  };
2075
2082
  });
2076
- this.selection.setSelectedRanges(slotRanges);
2077
2083
  this.tableSelection.set({
2078
2084
  startColumn: 0,
2079
2085
  endColumn: this.state.columnsConfig.length,
2080
2086
  startRow: startIndex,
2081
2087
  endRow: endIndex,
2082
2088
  });
2089
+ this.selection.setSelectedRanges(slotRanges);
2083
2090
  this.focus.next(true);
2084
2091
  if (slotRanges.length) {
2085
2092
  setTimeout(() => {
@@ -2108,13 +2115,13 @@ class TableComponent extends Component {
2108
2115
  endIndex: i.length
2109
2116
  };
2110
2117
  });
2111
- this.selection.setSelectedRanges(slotRanges);
2112
2118
  this.tableSelection.set({
2113
2119
  startColumn: startIndex,
2114
2120
  endColumn: endIndex,
2115
2121
  startRow: 0,
2116
2122
  endRow: this.state.rows.length,
2117
2123
  });
2124
+ this.selection.setSelectedRanges(slotRanges);
2118
2125
  this.focus.next(true);
2119
2126
  this.selection.restore();
2120
2127
  this.textbus.focus();
@@ -6204,24 +6211,25 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6204
6211
  return false;
6205
6212
  }
6206
6213
  const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6207
- const renderer = this.domAdapter;
6208
6214
  if (!rect) {
6209
6215
  return false;
6210
6216
  }
6211
- const normalizedSlots = commonAncestorComponent.getSelectedNormalizedSlotsByRectangle(rect);
6212
- const rects = normalizedSlots.map(row => {
6213
- return row.cells.filter(i => i.visible).map(i => {
6214
- const td = renderer.getNativeNodeBySlot(i.raw.slot);
6215
- return td.getBoundingClientRect();
6216
- });
6217
- }).flat();
6218
- const left = Math.min(...rects.map(i => i.left));
6219
- const top = Math.min(...rects.map(i => i.top));
6217
+ const dom = this.domAdapter.getNativeNodeByComponent(commonAncestorComponent);
6218
+ const content = dom.querySelector('.xnote-table-content');
6219
+ const trs = content.querySelectorAll('tr');
6220
+ const cols = content.querySelectorAll('col');
6221
+ const top = trs[rect.y1].getBoundingClientRect().top;
6222
+ const left = cols[rect.x1].getBoundingClientRect().left;
6223
+ let height = trs[rect.y2 - 1].getBoundingClientRect().bottom - top;
6224
+ if (height === 0) {
6225
+ height = trs[rect.y2 - 1].children.item(0).getBoundingClientRect().bottom - top;
6226
+ }
6227
+ const width = cols[rect.x2 - 1].getBoundingClientRect().right - left;
6220
6228
  return [{
6221
6229
  left,
6222
6230
  top,
6223
- width: Math.max(...rects.map(i => i.right)) - left,
6224
- height: Math.max(...rects.map(i => i.bottom)) - top
6231
+ width,
6232
+ height
6225
6233
  }];
6226
6234
  }
6227
6235
  };
@@ -6349,9 +6357,22 @@ class XNoteMessageBug extends MessageBus {
6349
6357
  get() {
6350
6358
  const selection = this.selection;
6351
6359
  const c = selection.commonAncestorComponent;
6352
- return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6360
+ const msg = Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths() });
6361
+ if (!selection.isCollapsed && c instanceof TableComponent) {
6362
+ const selection = c.tableSelection();
6363
+ if (selection) {
6364
+ msg.data = {
6365
+ x1: selection.startColumn,
6366
+ x2: selection.endColumn,
6367
+ y1: selection.startRow,
6368
+ y2: selection.endRow,
6369
+ };
6370
+ }
6371
+ }
6372
+ return msg;
6353
6373
  }
6354
6374
  consume(message) {
6375
+ message = message.filter(i => i.message);
6355
6376
  this.messageChangeEvent.next([...message]);
6356
6377
  this.collaborateCursor.draw(message.filter(item => {
6357
6378
  return item.message.id !== this.userinfo.id;
package/bundles/index.js CHANGED
@@ -1836,11 +1836,18 @@ function findNonIntersectingRectangles(rectangles) {
1836
1836
  function getMaxRectangle(start, rectangles) {
1837
1837
  let merged = start;
1838
1838
  const remaining = [...rectangles];
1839
+ const unMerged = [];
1839
1840
  while (remaining.length > 0) {
1840
1841
  const current = remaining.shift();
1841
1842
  if (current.intersects(merged)) {
1842
1843
  merged = current.merge(merged);
1843
1844
  }
1845
+ else {
1846
+ unMerged.push(current);
1847
+ }
1848
+ }
1849
+ if (unMerged.length && merged !== start) {
1850
+ return getMaxRectangle(merged, unMerged);
1844
1851
  }
1845
1852
  return merged;
1846
1853
  }
@@ -2075,13 +2082,13 @@ class TableComponent extends core$1.Component {
2075
2082
  endIndex: i.length
2076
2083
  };
2077
2084
  });
2078
- this.selection.setSelectedRanges(slotRanges);
2079
2085
  this.tableSelection.set({
2080
2086
  startColumn: 0,
2081
2087
  endColumn: this.state.columnsConfig.length,
2082
2088
  startRow: startIndex,
2083
2089
  endRow: endIndex,
2084
2090
  });
2091
+ this.selection.setSelectedRanges(slotRanges);
2085
2092
  this.focus.next(true);
2086
2093
  if (slotRanges.length) {
2087
2094
  setTimeout(() => {
@@ -2110,13 +2117,13 @@ class TableComponent extends core$1.Component {
2110
2117
  endIndex: i.length
2111
2118
  };
2112
2119
  });
2113
- this.selection.setSelectedRanges(slotRanges);
2114
2120
  this.tableSelection.set({
2115
2121
  startColumn: startIndex,
2116
2122
  endColumn: endIndex,
2117
2123
  startRow: 0,
2118
2124
  endRow: this.state.rows.length,
2119
2125
  });
2126
+ this.selection.setSelectedRanges(slotRanges);
2120
2127
  this.focus.next(true);
2121
2128
  this.selection.restore();
2122
2129
  this.textbus.focus();
@@ -6206,24 +6213,25 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6206
6213
  return false;
6207
6214
  }
6208
6215
  const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6209
- const renderer = this.domAdapter;
6210
6216
  if (!rect) {
6211
6217
  return false;
6212
6218
  }
6213
- const normalizedSlots = commonAncestorComponent.getSelectedNormalizedSlotsByRectangle(rect);
6214
- const rects = normalizedSlots.map(row => {
6215
- return row.cells.filter(i => i.visible).map(i => {
6216
- const td = renderer.getNativeNodeBySlot(i.raw.slot);
6217
- return td.getBoundingClientRect();
6218
- });
6219
- }).flat();
6220
- const left = Math.min(...rects.map(i => i.left));
6221
- const top = Math.min(...rects.map(i => i.top));
6219
+ const dom = this.domAdapter.getNativeNodeByComponent(commonAncestorComponent);
6220
+ const content = dom.querySelector('.xnote-table-content');
6221
+ const trs = content.querySelectorAll('tr');
6222
+ const cols = content.querySelectorAll('col');
6223
+ const top = trs[rect.y1].getBoundingClientRect().top;
6224
+ const left = cols[rect.x1].getBoundingClientRect().left;
6225
+ let height = trs[rect.y2 - 1].getBoundingClientRect().bottom - top;
6226
+ if (height === 0) {
6227
+ height = trs[rect.y2 - 1].children.item(0).getBoundingClientRect().bottom - top;
6228
+ }
6229
+ const width = cols[rect.x2 - 1].getBoundingClientRect().right - left;
6222
6230
  return [{
6223
6231
  left,
6224
6232
  top,
6225
- width: Math.max(...rects.map(i => i.right)) - left,
6226
- height: Math.max(...rects.map(i => i.bottom)) - top
6233
+ width,
6234
+ height
6227
6235
  }];
6228
6236
  }
6229
6237
  };
@@ -6351,9 +6359,22 @@ class XNoteMessageBug extends collaborate.MessageBus {
6351
6359
  get() {
6352
6360
  const selection = this.selection;
6353
6361
  const c = selection.commonAncestorComponent;
6354
- return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6362
+ const msg = Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths() });
6363
+ if (!selection.isCollapsed && c instanceof TableComponent) {
6364
+ const selection = c.tableSelection();
6365
+ if (selection) {
6366
+ msg.data = {
6367
+ x1: selection.startColumn,
6368
+ x2: selection.endColumn,
6369
+ y1: selection.startRow,
6370
+ y2: selection.endRow,
6371
+ };
6372
+ }
6373
+ }
6374
+ return msg;
6355
6375
  }
6356
6376
  consume(message) {
6377
+ message = message.filter(i => i.message);
6357
6378
  this.messageChangeEvent.next([...message]);
6358
6379
  this.collaborateCursor.draw(message.filter(item => {
6359
6380
  return item.message.id !== this.userinfo.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/xnote",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "A high-performance rich text editor that supports multiplayer online collaboration.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",