@phuong-tran-redoc/document-engine-core 0.1.5 → 0.1.6

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 (2) hide show
  1. package/index.esm.js +32 -8
  2. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -1273,6 +1273,30 @@ function calculateColumnWidthsForNewColumn(oldColWidths) {
1273
1273
  const reduction = MIN_NEW_COL_WIDTH / oldColWidths.length;
1274
1274
  return oldColWidths.map((w) => w - reduction);
1275
1275
  }
1276
+ /**
1277
+ * Read the `border` attrs of the cell the command should merge against.
1278
+ *
1279
+ * `$from.node(-1)` alone is only the cell for a collapsed cursor: with a `CellSelection`
1280
+ * prosemirror-tables resolves `$from` *before* the head cell, so that lookup lands on the
1281
+ * row and reports an empty border — which, now that an omitted field means "leave this
1282
+ * one alone", would clear every field the caller did not pass. `getSelectedCells` covers
1283
+ * the cell-selection and cursor cases; the depth walk covers a text selection inside one
1284
+ * cell, which `getSelectedCells` returns nothing for.
1285
+ */
1286
+ function getCurrentCellBorder(state) {
1287
+ var _a, _b, _c, _d;
1288
+ const [firstSelected] = getSelectedCells(state);
1289
+ if (firstSelected)
1290
+ return (_b = (_a = firstSelected.node.attrs) === null || _a === void 0 ? void 0 : _a['border']) !== null && _b !== void 0 ? _b : {};
1291
+ const { $from } = state.selection;
1292
+ for (let depth = $from.depth; depth > 0; depth--) {
1293
+ const node = $from.node(depth);
1294
+ if (node.type.name === 'tableCell' || node.type.name === 'tableHeader') {
1295
+ return (_d = (_c = node.attrs) === null || _c === void 0 ? void 0 : _c['border']) !== null && _d !== void 0 ? _d : {};
1296
+ }
1297
+ }
1298
+ return {};
1299
+ }
1276
1300
  const TableDefaultAttributes = {
1277
1301
  border: {
1278
1302
  style: 'double',
@@ -1598,7 +1622,6 @@ const StyledTable = Table.extend({
1598
1622
  },
1599
1623
  // Cell
1600
1624
  setCellBorder: (border) => ({ chain, state }) => {
1601
- var _a;
1602
1625
  if (!border)
1603
1626
  return chain()
1604
1627
  .focus()
@@ -1606,14 +1629,15 @@ const StyledTable = Table.extend({
1606
1629
  .updateAttributes('tableHeader', { border: null })
1607
1630
  .run();
1608
1631
  // Get current border and merge with new values
1609
- const { selection } = state;
1610
- const { $from } = selection;
1611
- const cellPos = $from.node(-1);
1612
- const currentBorder = ((_a = cellPos === null || cellPos === void 0 ? void 0 : cellPos.attrs) === null || _a === void 0 ? void 0 : _a['border']) || {};
1632
+ const currentBorder = getCurrentCellBorder(state);
1633
+ // `undefined` means "leave this field alone"; an explicit `null` clears it.
1634
+ // A truthiness check conflates the two, so clearing a cell's border colour
1635
+ // fell straight back to the colour being cleared and the UI could never
1636
+ // remove one. Matches `setTableBorder` above.
1613
1637
  const mergedBorder = {
1614
- style: border.style ? border.style : currentBorder.style || null,
1615
- color: border.color ? border.color : currentBorder.color || null,
1616
- width: border.width ? border.width : currentBorder.width || null,
1638
+ style: border.style !== undefined ? border.style : currentBorder.style || null,
1639
+ color: border.color !== undefined ? border.color : currentBorder.color || null,
1640
+ width: border.width !== undefined ? border.width : currentBorder.width || null,
1617
1641
  };
1618
1642
  return chain()
1619
1643
  .focus()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phuong-tran-redoc/document-engine-core",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Realestatedoc (Redoc)",