@kedataindo/docflow-core 0.0.38 → 0.0.40

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.
package/dist/index.cjs CHANGED
@@ -1654,17 +1654,26 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1654
1654
  const r = td.getBoundingClientRect();
1655
1655
  const parent = td.parentElement;
1656
1656
  if (!parent) return;
1657
- const colIdx = Array.from(parent.children).indexOf(td);
1658
- if (colIdx === -1) return;
1657
+ const cellColSpan = td.colSpan || 1;
1658
+ let logicalStart = 0;
1659
+ let foundCell = false;
1660
+ for (const sibling of Array.from(parent.children)) {
1661
+ if (sibling === td) {
1662
+ foundCell = true;
1663
+ break;
1664
+ }
1665
+ logicalStart += sibling.colSpan || 1;
1666
+ }
1667
+ if (!foundCell) return;
1659
1668
  const table = td.closest("table");
1660
1669
  if (!table) return;
1661
1670
  const distRight = Math.abs(event.clientX - r.right);
1662
1671
  const distLeft = Math.abs(event.clientX - r.left);
1663
1672
  let targetColIdx = -1;
1664
1673
  if (distRight <= 16) {
1665
- targetColIdx = colIdx;
1666
- } else if (distLeft <= 16 && colIdx > 0) {
1667
- targetColIdx = colIdx - 1;
1674
+ targetColIdx = logicalStart + cellColSpan - 1;
1675
+ } else if (distLeft <= 16 && logicalStart > 0) {
1676
+ targetColIdx = logicalStart - 1;
1668
1677
  } else {
1669
1678
  return;
1670
1679
  }
@@ -1677,20 +1686,19 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1677
1686
  allColWidths[c] = w || initialWidth(table, c);
1678
1687
  }
1679
1688
  const isLastCol = targetColIdx === totalCols - 1;
1689
+ const neighborIdx = targetColIdx + 1;
1680
1690
  const startX = event.clientX;
1681
1691
  const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
1692
+ const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
1682
1693
  const maxContainerW = getMaxContainerWidth(table);
1683
1694
  let otherColsW = 0;
1684
1695
  allColWidths.forEach((w, idx) => {
1685
- if (idx !== targetColIdx) {
1686
- otherColsW += w;
1687
- }
1696
+ if (idx !== targetColIdx) otherColsW += w;
1688
1697
  });
1689
- const maxNw = Math.max(20, maxContainerW - otherColsW);
1690
- function updateDOMWidths(targetIdx, targetW) {
1698
+ const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
1699
+ function updateDOMWidths() {
1691
1700
  let totalWidth = 0;
1692
- allColWidths.forEach((_, idx) => {
1693
- const w = idx === targetIdx ? targetW : allColWidths[idx];
1701
+ allColWidths.forEach((w, idx) => {
1694
1702
  const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
1695
1703
  if (col) col.style.setProperty("width", w + "px", "important");
1696
1704
  table.querySelectorAll("tr").forEach(function(row) {
@@ -1708,23 +1716,27 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1708
1716
  }
1709
1717
  event.stopPropagation();
1710
1718
  let lastNw = startW;
1711
- let moveCount = 0;
1712
1719
  const onMove = function(e) {
1713
- moveCount++;
1714
1720
  if (!e.buttons) {
1715
1721
  onUp(e);
1716
1722
  return;
1717
1723
  }
1718
- const diff = e.clientX - startX;
1719
- const nw = Math.min(maxNw, Math.max(20, startW + diff));
1720
- lastNw = nw;
1721
- let borderPos = table.getBoundingClientRect().left;
1722
- for (let i = 0; i <= targetColIdx; i++) {
1723
- borderPos += i === targetColIdx ? nw : allColWidths[i];
1724
+ const rawDiff = e.clientX - startX;
1725
+ if (isLastCol) {
1726
+ const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
1727
+ allColWidths[targetColIdx] = nw;
1728
+ lastNw = nw;
1729
+ } else {
1730
+ const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
1731
+ allColWidths[targetColIdx] = startW + delta;
1732
+ allColWidths[neighborIdx] = startNeighborW - delta;
1733
+ lastNw = allColWidths[targetColIdx];
1724
1734
  }
1735
+ let borderPos = table.getBoundingClientRect().left;
1736
+ for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
1725
1737
  showLine(table, borderPos);
1726
1738
  pauseObserver();
1727
- updateDOMWidths(targetColIdx, nw);
1739
+ updateDOMWidths();
1728
1740
  resumeObserver();
1729
1741
  };
1730
1742
  const onUp = function(upEvent) {
@@ -1733,8 +1745,6 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1733
1745
  upEvent.stopPropagation();
1734
1746
  hideLine();
1735
1747
  if (lastNw === startW) return;
1736
- allColWidths[targetColIdx] = lastNw;
1737
- console.log("[Resize] onUp:", { lastNw, startW, isLastCol, targetColIdx, allColWidths });
1738
1748
  try {
1739
1749
  const { state } = view;
1740
1750
  const { doc } = state;
@@ -1757,7 +1767,6 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1757
1767
  const tableNode = doc.nodeAt(tablePos);
1758
1768
  if (tableNode) {
1759
1769
  const tr = state.tr;
1760
- let cellsUpdated = 0;
1761
1770
  tableNode.forEach((row, rowOffset) => {
1762
1771
  let cellColIdx = 0;
1763
1772
  row.forEach((cell, cellOffset) => {
@@ -1768,13 +1777,12 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1768
1777
  cw[k] = allColWidths[cellColIdx + k] || 100;
1769
1778
  }
1770
1779
  tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
1771
- cellsUpdated++;
1772
1780
  cellColIdx += colspan;
1773
1781
  });
1774
1782
  });
1775
1783
  view.dispatch(tr);
1776
1784
  pauseObserver();
1777
- updateDOMWidths(targetColIdx, lastNw);
1785
+ updateDOMWidths();
1778
1786
  resumeObserver();
1779
1787
  }
1780
1788
  } else {
@@ -1783,7 +1791,7 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1783
1791
  } catch (err) {
1784
1792
  console.warn("[Resize] transaction failed, falling back to DOM:", err);
1785
1793
  pauseObserver();
1786
- updateDOMWidths(targetColIdx, lastNw);
1794
+ updateDOMWidths();
1787
1795
  resumeObserver();
1788
1796
  }
1789
1797
  };
package/dist/index.js CHANGED
@@ -1596,17 +1596,26 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1596
1596
  const r = td.getBoundingClientRect();
1597
1597
  const parent = td.parentElement;
1598
1598
  if (!parent) return;
1599
- const colIdx = Array.from(parent.children).indexOf(td);
1600
- if (colIdx === -1) return;
1599
+ const cellColSpan = td.colSpan || 1;
1600
+ let logicalStart = 0;
1601
+ let foundCell = false;
1602
+ for (const sibling of Array.from(parent.children)) {
1603
+ if (sibling === td) {
1604
+ foundCell = true;
1605
+ break;
1606
+ }
1607
+ logicalStart += sibling.colSpan || 1;
1608
+ }
1609
+ if (!foundCell) return;
1601
1610
  const table = td.closest("table");
1602
1611
  if (!table) return;
1603
1612
  const distRight = Math.abs(event.clientX - r.right);
1604
1613
  const distLeft = Math.abs(event.clientX - r.left);
1605
1614
  let targetColIdx = -1;
1606
1615
  if (distRight <= 16) {
1607
- targetColIdx = colIdx;
1608
- } else if (distLeft <= 16 && colIdx > 0) {
1609
- targetColIdx = colIdx - 1;
1616
+ targetColIdx = logicalStart + cellColSpan - 1;
1617
+ } else if (distLeft <= 16 && logicalStart > 0) {
1618
+ targetColIdx = logicalStart - 1;
1610
1619
  } else {
1611
1620
  return;
1612
1621
  }
@@ -1619,20 +1628,19 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1619
1628
  allColWidths[c] = w || initialWidth(table, c);
1620
1629
  }
1621
1630
  const isLastCol = targetColIdx === totalCols - 1;
1631
+ const neighborIdx = targetColIdx + 1;
1622
1632
  const startX = event.clientX;
1623
1633
  const startW = allColWidths[targetColIdx] || initialWidth(table, targetColIdx);
1634
+ const startNeighborW = !isLastCol ? allColWidths[neighborIdx] || initialWidth(table, neighborIdx) : 0;
1624
1635
  const maxContainerW = getMaxContainerWidth(table);
1625
1636
  let otherColsW = 0;
1626
1637
  allColWidths.forEach((w, idx) => {
1627
- if (idx !== targetColIdx) {
1628
- otherColsW += w;
1629
- }
1638
+ if (idx !== targetColIdx) otherColsW += w;
1630
1639
  });
1631
- const maxNw = Math.max(20, maxContainerW - otherColsW);
1632
- function updateDOMWidths(targetIdx, targetW) {
1640
+ const maxNwLastCol = Math.max(20, maxContainerW - otherColsW);
1641
+ function updateDOMWidths() {
1633
1642
  let totalWidth = 0;
1634
- allColWidths.forEach((_, idx) => {
1635
- const w = idx === targetIdx ? targetW : allColWidths[idx];
1643
+ allColWidths.forEach((w, idx) => {
1636
1644
  const col = table.querySelector(`colgroup col:nth-child(${idx + 1})`);
1637
1645
  if (col) col.style.setProperty("width", w + "px", "important");
1638
1646
  table.querySelectorAll("tr").forEach(function(row) {
@@ -1650,23 +1658,27 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1650
1658
  }
1651
1659
  event.stopPropagation();
1652
1660
  let lastNw = startW;
1653
- let moveCount = 0;
1654
1661
  const onMove = function(e) {
1655
- moveCount++;
1656
1662
  if (!e.buttons) {
1657
1663
  onUp(e);
1658
1664
  return;
1659
1665
  }
1660
- const diff = e.clientX - startX;
1661
- const nw = Math.min(maxNw, Math.max(20, startW + diff));
1662
- lastNw = nw;
1663
- let borderPos = table.getBoundingClientRect().left;
1664
- for (let i = 0; i <= targetColIdx; i++) {
1665
- borderPos += i === targetColIdx ? nw : allColWidths[i];
1666
+ const rawDiff = e.clientX - startX;
1667
+ if (isLastCol) {
1668
+ const nw = Math.min(maxNwLastCol, Math.max(20, startW + rawDiff));
1669
+ allColWidths[targetColIdx] = nw;
1670
+ lastNw = nw;
1671
+ } else {
1672
+ const delta = Math.max(20 - startW, Math.min(rawDiff, startNeighborW - 20));
1673
+ allColWidths[targetColIdx] = startW + delta;
1674
+ allColWidths[neighborIdx] = startNeighborW - delta;
1675
+ lastNw = allColWidths[targetColIdx];
1666
1676
  }
1677
+ let borderPos = table.getBoundingClientRect().left;
1678
+ for (let i = 0; i <= targetColIdx; i++) borderPos += allColWidths[i];
1667
1679
  showLine(table, borderPos);
1668
1680
  pauseObserver();
1669
- updateDOMWidths(targetColIdx, nw);
1681
+ updateDOMWidths();
1670
1682
  resumeObserver();
1671
1683
  };
1672
1684
  const onUp = function(upEvent) {
@@ -1675,8 +1687,6 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1675
1687
  upEvent.stopPropagation();
1676
1688
  hideLine();
1677
1689
  if (lastNw === startW) return;
1678
- allColWidths[targetColIdx] = lastNw;
1679
- console.log("[Resize] onUp:", { lastNw, startW, isLastCol, targetColIdx, allColWidths });
1680
1690
  try {
1681
1691
  const { state } = view;
1682
1692
  const { doc } = state;
@@ -1699,7 +1709,6 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1699
1709
  const tableNode = doc.nodeAt(tablePos);
1700
1710
  if (tableNode) {
1701
1711
  const tr = state.tr;
1702
- let cellsUpdated = 0;
1703
1712
  tableNode.forEach((row, rowOffset) => {
1704
1713
  let cellColIdx = 0;
1705
1714
  row.forEach((cell, cellOffset) => {
@@ -1710,13 +1719,12 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1710
1719
  cw[k] = allColWidths[cellColIdx + k] || 100;
1711
1720
  }
1712
1721
  tr.setNodeMarkup(cellPos, null, { ...cell.attrs, colwidth: cw });
1713
- cellsUpdated++;
1714
1722
  cellColIdx += colspan;
1715
1723
  });
1716
1724
  });
1717
1725
  view.dispatch(tr);
1718
1726
  pauseObserver();
1719
- updateDOMWidths(targetColIdx, lastNw);
1727
+ updateDOMWidths();
1720
1728
  resumeObserver();
1721
1729
  }
1722
1730
  } else {
@@ -1725,7 +1733,7 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
1725
1733
  } catch (err) {
1726
1734
  console.warn("[Resize] transaction failed, falling back to DOM:", err);
1727
1735
  pauseObserver();
1728
- updateDOMWidths(targetColIdx, lastNw);
1736
+ updateDOMWidths();
1729
1737
  resumeObserver();
1730
1738
  }
1731
1739
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kedataindo/docflow-core",
3
3
  "license": "UNLICENSED",
4
- "version": "0.0.38",
4
+ "version": "0.0.40",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",