@underverse-ui/underverse 1.0.142 → 1.0.143
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/api-reference.json +1 -1
- package/dist/index.cjs +284 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +287 -230
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/api-reference.json
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -27302,7 +27302,7 @@ function buildUEditorExtensions({
|
|
|
27302
27302
|
handleWidth: 10,
|
|
27303
27303
|
allowTableNodeSelection: true,
|
|
27304
27304
|
HTMLAttributes: {
|
|
27305
|
-
class: "border-collapse
|
|
27305
|
+
class: "border-collapse my-4"
|
|
27306
27306
|
}
|
|
27307
27307
|
}),
|
|
27308
27308
|
table_row_default,
|
|
@@ -27825,6 +27825,229 @@ var ImageInput = ({ onSubmit, onCancel }) => {
|
|
|
27825
27825
|
] });
|
|
27826
27826
|
};
|
|
27827
27827
|
|
|
27828
|
+
// src/components/UEditor/table-cell-commands.ts
|
|
27829
|
+
var import_state7 = require("@tiptap/pm/state");
|
|
27830
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
27831
|
+
function getCellSelectionPositions(selection) {
|
|
27832
|
+
const value = selection;
|
|
27833
|
+
const anchor = value.$anchorCell?.pos;
|
|
27834
|
+
const head = value.$headCell?.pos;
|
|
27835
|
+
return typeof anchor === "number" && typeof head === "number" ? { anchor, head } : null;
|
|
27836
|
+
}
|
|
27837
|
+
function findTableInfoFromCellPos(editor, cellPos) {
|
|
27838
|
+
const $pos = editor.state.doc.resolve(cellPos);
|
|
27839
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
27840
|
+
const node = $pos.node(depth);
|
|
27841
|
+
if (node.type.name === "table") {
|
|
27842
|
+
return {
|
|
27843
|
+
table: node,
|
|
27844
|
+
tablePos: $pos.before(depth),
|
|
27845
|
+
tableStart: $pos.start(depth)
|
|
27846
|
+
};
|
|
27847
|
+
}
|
|
27848
|
+
}
|
|
27849
|
+
return null;
|
|
27850
|
+
}
|
|
27851
|
+
function getFocusableCellPos(editor, cellPos) {
|
|
27852
|
+
const cellNode = editor.state.doc.nodeAt(cellPos);
|
|
27853
|
+
if (!cellNode) return cellPos + 1;
|
|
27854
|
+
let offset = cellPos + 1;
|
|
27855
|
+
let node = cellNode.firstChild ?? null;
|
|
27856
|
+
while (node && !node.isTextblock) {
|
|
27857
|
+
offset += 1;
|
|
27858
|
+
node = node.firstChild ?? null;
|
|
27859
|
+
}
|
|
27860
|
+
return node?.isTextblock ? offset + 1 : cellPos + 1;
|
|
27861
|
+
}
|
|
27862
|
+
function focusCell(editor, cellPos) {
|
|
27863
|
+
const selection = import_state7.TextSelection.near(editor.state.doc.resolve(getFocusableCellPos(editor, cellPos)));
|
|
27864
|
+
editor.view.dispatch(editor.state.tr.setSelection(selection));
|
|
27865
|
+
editor.view.focus();
|
|
27866
|
+
}
|
|
27867
|
+
function collectChildren(node) {
|
|
27868
|
+
const children = [];
|
|
27869
|
+
node.forEach((child) => children.push(child));
|
|
27870
|
+
return children;
|
|
27871
|
+
}
|
|
27872
|
+
function createEmptyCellNode(cellNode) {
|
|
27873
|
+
return cellNode.type.createAndFill(cellNode.attrs) ?? cellNode;
|
|
27874
|
+
}
|
|
27875
|
+
function getSelectedTableRect(editor) {
|
|
27876
|
+
const cellSelection = getCellSelectionPositions(editor.state.selection);
|
|
27877
|
+
if (cellSelection) {
|
|
27878
|
+
const tableInfo = findTableInfoFromCellPos(editor, cellSelection.anchor);
|
|
27879
|
+
if (tableInfo) {
|
|
27880
|
+
const map = import_tables.TableMap.get(tableInfo.table);
|
|
27881
|
+
const rect = map.rectBetween(
|
|
27882
|
+
cellSelection.anchor - tableInfo.tableStart,
|
|
27883
|
+
cellSelection.head - tableInfo.tableStart
|
|
27884
|
+
);
|
|
27885
|
+
return {
|
|
27886
|
+
...rect,
|
|
27887
|
+
map,
|
|
27888
|
+
table: tableInfo.table,
|
|
27889
|
+
tableStart: tableInfo.tableStart
|
|
27890
|
+
};
|
|
27891
|
+
}
|
|
27892
|
+
}
|
|
27893
|
+
return (0, import_tables.selectedRect)(editor.state);
|
|
27894
|
+
}
|
|
27895
|
+
function parsePixelWidth(value) {
|
|
27896
|
+
if (!value) return null;
|
|
27897
|
+
const parsed = Number.parseFloat(value);
|
|
27898
|
+
return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : null;
|
|
27899
|
+
}
|
|
27900
|
+
function getDomColumnWidths(editor, rect) {
|
|
27901
|
+
const tableDom = editor.view.nodeDOM(rect.tableStart - 1);
|
|
27902
|
+
if (!(tableDom instanceof HTMLTableElement)) return null;
|
|
27903
|
+
const cols = Array.from(tableDom.querySelectorAll("colgroup > col"));
|
|
27904
|
+
if (cols.length === 0) return null;
|
|
27905
|
+
const widths = [];
|
|
27906
|
+
for (let col = rect.left; col < rect.right; col += 1) {
|
|
27907
|
+
const colElement = cols[col];
|
|
27908
|
+
if (!colElement) return null;
|
|
27909
|
+
const width = parsePixelWidth(colElement.style.width) ?? parsePixelWidth(colElement.getAttribute("width")) ?? Math.round(colElement.getBoundingClientRect().width);
|
|
27910
|
+
if (!Number.isFinite(width) || width <= 0) return null;
|
|
27911
|
+
widths.push(width);
|
|
27912
|
+
}
|
|
27913
|
+
return widths.length > 0 ? widths : null;
|
|
27914
|
+
}
|
|
27915
|
+
function getNodeColumnWidths(rect) {
|
|
27916
|
+
const widths = [];
|
|
27917
|
+
for (let col = rect.left; col < rect.right; col += 1) {
|
|
27918
|
+
let width = null;
|
|
27919
|
+
const seen = /* @__PURE__ */ new Set();
|
|
27920
|
+
for (let row = 0; row < rect.map.height && width == null; row += 1) {
|
|
27921
|
+
const cellPos = rect.map.map[row * rect.map.width + col];
|
|
27922
|
+
if (seen.has(cellPos)) continue;
|
|
27923
|
+
seen.add(cellPos);
|
|
27924
|
+
const cell = rect.table.nodeAt(cellPos);
|
|
27925
|
+
const colwidth = cell?.attrs.colwidth;
|
|
27926
|
+
if (!Array.isArray(colwidth)) continue;
|
|
27927
|
+
const cellLeft = rect.map.colCount(cellPos);
|
|
27928
|
+
const widthIndex = col - cellLeft;
|
|
27929
|
+
const candidate = colwidth[widthIndex];
|
|
27930
|
+
if (typeof candidate === "number" && candidate > 0) {
|
|
27931
|
+
width = candidate;
|
|
27932
|
+
}
|
|
27933
|
+
}
|
|
27934
|
+
if (width == null) return null;
|
|
27935
|
+
widths.push(width);
|
|
27936
|
+
}
|
|
27937
|
+
return widths.length > 0 ? widths : null;
|
|
27938
|
+
}
|
|
27939
|
+
function getSelectedColumnWidths(editor, rect) {
|
|
27940
|
+
return getDomColumnWidths(editor, rect) ?? getNodeColumnWidths(rect);
|
|
27941
|
+
}
|
|
27942
|
+
function dispatchTableLayoutChange(editor) {
|
|
27943
|
+
editor.view.dom.dispatchEvent(new CustomEvent(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, { bubbles: true }));
|
|
27944
|
+
}
|
|
27945
|
+
function mergeTableCellsPreservingColumnWidths(editor) {
|
|
27946
|
+
const rect = getSelectedTableRect(editor);
|
|
27947
|
+
const widths = getSelectedColumnWidths(editor, rect);
|
|
27948
|
+
const merged = editor.chain().focus().mergeCells().run();
|
|
27949
|
+
if (!merged) return merged;
|
|
27950
|
+
if (!widths) {
|
|
27951
|
+
dispatchTableLayoutChange(editor);
|
|
27952
|
+
return merged;
|
|
27953
|
+
}
|
|
27954
|
+
const nextRect = getSelectedTableRect(editor);
|
|
27955
|
+
const cellPos = nextRect.map.map[nextRect.top * nextRect.map.width + nextRect.left];
|
|
27956
|
+
const absolutePos = nextRect.tableStart + cellPos;
|
|
27957
|
+
const node = editor.state.doc.nodeAt(absolutePos);
|
|
27958
|
+
if (!node) return merged;
|
|
27959
|
+
editor.view.dispatch(
|
|
27960
|
+
editor.state.tr.setNodeMarkup(absolutePos, node.type, {
|
|
27961
|
+
...node.attrs,
|
|
27962
|
+
colwidth: widths
|
|
27963
|
+
})
|
|
27964
|
+
);
|
|
27965
|
+
dispatchTableLayoutChange(editor);
|
|
27966
|
+
return true;
|
|
27967
|
+
}
|
|
27968
|
+
function runTableCommandAtCellPos(editor, cellPos, command) {
|
|
27969
|
+
if (cellPos == null) return false;
|
|
27970
|
+
focusCell(editor, cellPos);
|
|
27971
|
+
return command(editor.chain().focus(null, { scrollIntoView: false })).run();
|
|
27972
|
+
}
|
|
27973
|
+
function getTableCornerCellPos(editor, activePos) {
|
|
27974
|
+
const tableInfo = findTableInfoFromCellPos(editor, activePos);
|
|
27975
|
+
if (!tableInfo) return null;
|
|
27976
|
+
const map = import_tables.TableMap.get(tableInfo.table);
|
|
27977
|
+
return tableInfo.tableStart + map.positionAt(map.height - 1, map.width - 1, tableInfo.table);
|
|
27978
|
+
}
|
|
27979
|
+
function replaceTableAtCellPos(editor, cellPos, updateTable) {
|
|
27980
|
+
if (cellPos == null) return false;
|
|
27981
|
+
const tableInfo = findTableInfoFromCellPos(editor, cellPos);
|
|
27982
|
+
if (!tableInfo) return false;
|
|
27983
|
+
const nextTable = updateTable(tableInfo.table);
|
|
27984
|
+
if (!nextTable) return false;
|
|
27985
|
+
editor.view.dispatch(editor.state.tr.replaceWith(tableInfo.tablePos, tableInfo.tablePos + tableInfo.table.nodeSize, nextTable));
|
|
27986
|
+
dispatchTableLayoutChange(editor);
|
|
27987
|
+
return true;
|
|
27988
|
+
}
|
|
27989
|
+
function duplicateTableRowAt(editor, rowIndex, cellPos) {
|
|
27990
|
+
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
27991
|
+
const rows = collectChildren(tableNode);
|
|
27992
|
+
const rowNode = rows[rowIndex];
|
|
27993
|
+
if (!rowNode) return null;
|
|
27994
|
+
rows.splice(rowIndex + 1, 0, rowNode.copy(rowNode.content));
|
|
27995
|
+
return tableNode.type.create(tableNode.attrs, rows);
|
|
27996
|
+
});
|
|
27997
|
+
}
|
|
27998
|
+
function clearTableRowAt(editor, rowIndex, cellPos) {
|
|
27999
|
+
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28000
|
+
const rows = collectChildren(tableNode);
|
|
28001
|
+
const rowNode = rows[rowIndex];
|
|
28002
|
+
if (!rowNode) return null;
|
|
28003
|
+
const cells = collectChildren(rowNode).map((cellNode) => createEmptyCellNode(cellNode));
|
|
28004
|
+
rows[rowIndex] = rowNode.type.create(rowNode.attrs, cells);
|
|
28005
|
+
return tableNode.type.create(tableNode.attrs, rows);
|
|
28006
|
+
});
|
|
28007
|
+
}
|
|
28008
|
+
function duplicateTableColumnAt(editor, columnIndex, cellPos) {
|
|
28009
|
+
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28010
|
+
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
28011
|
+
const cells = collectChildren(rowNode);
|
|
28012
|
+
const cellNode = cells[columnIndex];
|
|
28013
|
+
if (!cellNode) return rowNode;
|
|
28014
|
+
cells.splice(columnIndex + 1, 0, cellNode.copy(cellNode.content));
|
|
28015
|
+
return rowNode.type.create(rowNode.attrs, cells);
|
|
28016
|
+
});
|
|
28017
|
+
return tableNode.type.create(tableNode.attrs, rows);
|
|
28018
|
+
});
|
|
28019
|
+
}
|
|
28020
|
+
function clearTableColumnAt(editor, columnIndex, cellPos) {
|
|
28021
|
+
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28022
|
+
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
28023
|
+
const cells = collectChildren(rowNode);
|
|
28024
|
+
const cellNode = cells[columnIndex];
|
|
28025
|
+
if (!cellNode) return rowNode;
|
|
28026
|
+
cells[columnIndex] = createEmptyCellNode(cellNode);
|
|
28027
|
+
return rowNode.type.create(rowNode.attrs, cells);
|
|
28028
|
+
});
|
|
28029
|
+
return tableNode.type.create(tableNode.attrs, rows);
|
|
28030
|
+
});
|
|
28031
|
+
}
|
|
28032
|
+
function expandTableFromCell(editor, activeCellPos, rows, columns) {
|
|
28033
|
+
let cornerCellPos = getTableCornerCellPos(editor, activeCellPos);
|
|
28034
|
+
if (cornerCellPos == null) return false;
|
|
28035
|
+
for (let index = 0; index < rows; index += 1) {
|
|
28036
|
+
const ok = runTableCommandAtCellPos(editor, cornerCellPos, (chain) => chain.addRowAfter());
|
|
28037
|
+
if (!ok) return false;
|
|
28038
|
+
cornerCellPos = getTableCornerCellPos(editor, cornerCellPos);
|
|
28039
|
+
if (cornerCellPos == null) return false;
|
|
28040
|
+
}
|
|
28041
|
+
for (let index = 0; index < columns; index += 1) {
|
|
28042
|
+
const ok = runTableCommandAtCellPos(editor, cornerCellPos, (chain) => chain.addColumnAfter());
|
|
28043
|
+
if (!ok) return false;
|
|
28044
|
+
cornerCellPos = getTableCornerCellPos(editor, cornerCellPos);
|
|
28045
|
+
if (cornerCellPos == null) return false;
|
|
28046
|
+
}
|
|
28047
|
+
dispatchTableLayoutChange(editor);
|
|
28048
|
+
return true;
|
|
28049
|
+
}
|
|
28050
|
+
|
|
27828
28051
|
// src/components/UEditor/typography-options.ts
|
|
27829
28052
|
function normalizeStyleValue(value) {
|
|
27830
28053
|
return typeof value === "string" ? value.trim().replace(/^['"]|['"]$/g, "") : "";
|
|
@@ -28020,6 +28243,8 @@ var EditorToolbar = ({
|
|
|
28020
28243
|
const currentTableAlign = tableAlignAttr === "center" || tableAlignAttr === "right" ? tableAlignAttr : "left";
|
|
28021
28244
|
const isTableSelected = tableInfo !== null;
|
|
28022
28245
|
const hasTableContext = isTableSelected || tableCommandAnchorPosRef.current !== null;
|
|
28246
|
+
const canMergeCells = hasTableContext && editor.can().mergeCells();
|
|
28247
|
+
const canSplitCell = hasTableContext && editor.can().splitCell();
|
|
28023
28248
|
const currentFontFamily = normalizeStyleValue(textStyleAttrs.fontFamily);
|
|
28024
28249
|
const currentFontSize = normalizeStyleValue(textStyleAttrs.fontSize);
|
|
28025
28250
|
const currentTextColor = normalizeStyleValue(textStyleAttrs.color) || "inherit";
|
|
@@ -28789,7 +29014,62 @@ var EditorToolbar = ({
|
|
|
28789
29014
|
),
|
|
28790
29015
|
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(ToolbarDivider, {}),
|
|
28791
29016
|
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(ToolbarButton, { onClick: () => editor.chain().focus().undo().run(), disabled: !editor.can().undo(), title: t("toolbar.undo"), children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.Undo, { className: "w-4 h-4" }) }),
|
|
28792
|
-
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(ToolbarButton, { onClick: () => editor.chain().focus().redo().run(), disabled: !editor.can().redo(), title: t("toolbar.redo"), children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.Redo, { className: "w-4 h-4" }) })
|
|
29017
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(ToolbarButton, { onClick: () => editor.chain().focus().redo().run(), disabled: !editor.can().redo(), title: t("toolbar.redo"), children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.Redo, { className: "w-4 h-4" }) }),
|
|
29018
|
+
hasTableContext && /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)(import_jsx_runtime85.Fragment, { children: [
|
|
29019
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(ToolbarDivider, {}),
|
|
29020
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
|
|
29021
|
+
ToolbarButton,
|
|
29022
|
+
{
|
|
29023
|
+
onClick: () => editor.chain().focus().addColumnBefore().run(),
|
|
29024
|
+
disabled: !editor.can().addColumnBefore(),
|
|
29025
|
+
title: t("tableMenu.addColumnBefore"),
|
|
29026
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.ArrowLeft, { className: "w-4 h-4" })
|
|
29027
|
+
}
|
|
29028
|
+
),
|
|
29029
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
|
|
29030
|
+
ToolbarButton,
|
|
29031
|
+
{
|
|
29032
|
+
onClick: () => editor.chain().focus().addColumnAfter().run(),
|
|
29033
|
+
disabled: !editor.can().addColumnAfter(),
|
|
29034
|
+
title: t("tableMenu.addColumnAfter"),
|
|
29035
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.ArrowRight, { className: "w-4 h-4" })
|
|
29036
|
+
}
|
|
29037
|
+
),
|
|
29038
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
|
|
29039
|
+
ToolbarButton,
|
|
29040
|
+
{
|
|
29041
|
+
onClick: () => editor.chain().focus().addRowBefore().run(),
|
|
29042
|
+
disabled: !editor.can().addRowBefore(),
|
|
29043
|
+
title: t("tableMenu.addRowBefore"),
|
|
29044
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.ArrowUp, { className: "w-4 h-4" })
|
|
29045
|
+
}
|
|
29046
|
+
),
|
|
29047
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
|
|
29048
|
+
ToolbarButton,
|
|
29049
|
+
{
|
|
29050
|
+
onClick: () => editor.chain().focus().addRowAfter().run(),
|
|
29051
|
+
disabled: !editor.can().addRowAfter(),
|
|
29052
|
+
title: t("tableMenu.addRowAfter"),
|
|
29053
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.ArrowDown, { className: "w-4 h-4" })
|
|
29054
|
+
}
|
|
29055
|
+
),
|
|
29056
|
+
/* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
|
|
29057
|
+
ToolbarButton,
|
|
29058
|
+
{
|
|
29059
|
+
onClick: () => {
|
|
29060
|
+
if (canSplitCell) {
|
|
29061
|
+
editor.chain().focus().splitCell().run();
|
|
29062
|
+
return;
|
|
29063
|
+
}
|
|
29064
|
+
mergeTableCellsPreservingColumnWidths(editor);
|
|
29065
|
+
},
|
|
29066
|
+
active: canSplitCell,
|
|
29067
|
+
disabled: !canMergeCells && !canSplitCell,
|
|
29068
|
+
title: canSplitCell ? t("tableMenu.splitCell") : t("tableMenu.mergeCells"),
|
|
29069
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_lucide_react48.TableCellsMerge, { className: "w-4 h-4" })
|
|
29070
|
+
}
|
|
29071
|
+
)
|
|
29072
|
+
] })
|
|
28793
29073
|
] });
|
|
28794
29074
|
};
|
|
28795
29075
|
|
|
@@ -28799,231 +29079,6 @@ var import_react63 = require("@tiptap/react");
|
|
|
28799
29079
|
var import_tables2 = require("@tiptap/pm/tables");
|
|
28800
29080
|
var import_react_dom8 = require("react-dom");
|
|
28801
29081
|
var import_lucide_react49 = require("lucide-react");
|
|
28802
|
-
|
|
28803
|
-
// src/components/UEditor/table-cell-commands.ts
|
|
28804
|
-
var import_state7 = require("@tiptap/pm/state");
|
|
28805
|
-
var import_tables = require("@tiptap/pm/tables");
|
|
28806
|
-
function getCellSelectionPositions(selection) {
|
|
28807
|
-
const value = selection;
|
|
28808
|
-
const anchor = value.$anchorCell?.pos;
|
|
28809
|
-
const head = value.$headCell?.pos;
|
|
28810
|
-
return typeof anchor === "number" && typeof head === "number" ? { anchor, head } : null;
|
|
28811
|
-
}
|
|
28812
|
-
function findTableInfoFromCellPos(editor, cellPos) {
|
|
28813
|
-
const $pos = editor.state.doc.resolve(cellPos);
|
|
28814
|
-
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
28815
|
-
const node = $pos.node(depth);
|
|
28816
|
-
if (node.type.name === "table") {
|
|
28817
|
-
return {
|
|
28818
|
-
table: node,
|
|
28819
|
-
tablePos: $pos.before(depth),
|
|
28820
|
-
tableStart: $pos.start(depth)
|
|
28821
|
-
};
|
|
28822
|
-
}
|
|
28823
|
-
}
|
|
28824
|
-
return null;
|
|
28825
|
-
}
|
|
28826
|
-
function getFocusableCellPos(editor, cellPos) {
|
|
28827
|
-
const cellNode = editor.state.doc.nodeAt(cellPos);
|
|
28828
|
-
if (!cellNode) return cellPos + 1;
|
|
28829
|
-
let offset = cellPos + 1;
|
|
28830
|
-
let node = cellNode.firstChild ?? null;
|
|
28831
|
-
while (node && !node.isTextblock) {
|
|
28832
|
-
offset += 1;
|
|
28833
|
-
node = node.firstChild ?? null;
|
|
28834
|
-
}
|
|
28835
|
-
return node?.isTextblock ? offset + 1 : cellPos + 1;
|
|
28836
|
-
}
|
|
28837
|
-
function focusCell(editor, cellPos) {
|
|
28838
|
-
const selection = import_state7.TextSelection.near(editor.state.doc.resolve(getFocusableCellPos(editor, cellPos)));
|
|
28839
|
-
editor.view.dispatch(editor.state.tr.setSelection(selection));
|
|
28840
|
-
editor.view.focus();
|
|
28841
|
-
}
|
|
28842
|
-
function collectChildren(node) {
|
|
28843
|
-
const children = [];
|
|
28844
|
-
node.forEach((child) => children.push(child));
|
|
28845
|
-
return children;
|
|
28846
|
-
}
|
|
28847
|
-
function createEmptyCellNode(cellNode) {
|
|
28848
|
-
return cellNode.type.createAndFill(cellNode.attrs) ?? cellNode;
|
|
28849
|
-
}
|
|
28850
|
-
function getSelectedTableRect(editor) {
|
|
28851
|
-
const cellSelection = getCellSelectionPositions(editor.state.selection);
|
|
28852
|
-
if (cellSelection) {
|
|
28853
|
-
const tableInfo = findTableInfoFromCellPos(editor, cellSelection.anchor);
|
|
28854
|
-
if (tableInfo) {
|
|
28855
|
-
const map = import_tables.TableMap.get(tableInfo.table);
|
|
28856
|
-
const rect = map.rectBetween(
|
|
28857
|
-
cellSelection.anchor - tableInfo.tableStart,
|
|
28858
|
-
cellSelection.head - tableInfo.tableStart
|
|
28859
|
-
);
|
|
28860
|
-
return {
|
|
28861
|
-
...rect,
|
|
28862
|
-
map,
|
|
28863
|
-
table: tableInfo.table,
|
|
28864
|
-
tableStart: tableInfo.tableStart
|
|
28865
|
-
};
|
|
28866
|
-
}
|
|
28867
|
-
}
|
|
28868
|
-
return (0, import_tables.selectedRect)(editor.state);
|
|
28869
|
-
}
|
|
28870
|
-
function parsePixelWidth(value) {
|
|
28871
|
-
if (!value) return null;
|
|
28872
|
-
const parsed = Number.parseFloat(value);
|
|
28873
|
-
return Number.isFinite(parsed) && parsed > 0 ? Math.round(parsed) : null;
|
|
28874
|
-
}
|
|
28875
|
-
function getDomColumnWidths(editor, rect) {
|
|
28876
|
-
const tableDom = editor.view.nodeDOM(rect.tableStart - 1);
|
|
28877
|
-
if (!(tableDom instanceof HTMLTableElement)) return null;
|
|
28878
|
-
const cols = Array.from(tableDom.querySelectorAll("colgroup > col"));
|
|
28879
|
-
if (cols.length === 0) return null;
|
|
28880
|
-
const widths = [];
|
|
28881
|
-
for (let col = rect.left; col < rect.right; col += 1) {
|
|
28882
|
-
const colElement = cols[col];
|
|
28883
|
-
if (!colElement) return null;
|
|
28884
|
-
const width = parsePixelWidth(colElement.style.width) ?? parsePixelWidth(colElement.getAttribute("width")) ?? Math.round(colElement.getBoundingClientRect().width);
|
|
28885
|
-
if (!Number.isFinite(width) || width <= 0) return null;
|
|
28886
|
-
widths.push(width);
|
|
28887
|
-
}
|
|
28888
|
-
return widths.length > 0 ? widths : null;
|
|
28889
|
-
}
|
|
28890
|
-
function getNodeColumnWidths(rect) {
|
|
28891
|
-
const widths = [];
|
|
28892
|
-
for (let col = rect.left; col < rect.right; col += 1) {
|
|
28893
|
-
let width = null;
|
|
28894
|
-
const seen = /* @__PURE__ */ new Set();
|
|
28895
|
-
for (let row = 0; row < rect.map.height && width == null; row += 1) {
|
|
28896
|
-
const cellPos = rect.map.map[row * rect.map.width + col];
|
|
28897
|
-
if (seen.has(cellPos)) continue;
|
|
28898
|
-
seen.add(cellPos);
|
|
28899
|
-
const cell = rect.table.nodeAt(cellPos);
|
|
28900
|
-
const colwidth = cell?.attrs.colwidth;
|
|
28901
|
-
if (!Array.isArray(colwidth)) continue;
|
|
28902
|
-
const cellLeft = rect.map.colCount(cellPos);
|
|
28903
|
-
const widthIndex = col - cellLeft;
|
|
28904
|
-
const candidate = colwidth[widthIndex];
|
|
28905
|
-
if (typeof candidate === "number" && candidate > 0) {
|
|
28906
|
-
width = candidate;
|
|
28907
|
-
}
|
|
28908
|
-
}
|
|
28909
|
-
if (width == null) return null;
|
|
28910
|
-
widths.push(width);
|
|
28911
|
-
}
|
|
28912
|
-
return widths.length > 0 ? widths : null;
|
|
28913
|
-
}
|
|
28914
|
-
function getSelectedColumnWidths(editor, rect) {
|
|
28915
|
-
return getDomColumnWidths(editor, rect) ?? getNodeColumnWidths(rect);
|
|
28916
|
-
}
|
|
28917
|
-
function dispatchTableLayoutChange(editor) {
|
|
28918
|
-
editor.view.dom.dispatchEvent(new CustomEvent(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT, { bubbles: true }));
|
|
28919
|
-
}
|
|
28920
|
-
function mergeTableCellsPreservingColumnWidths(editor) {
|
|
28921
|
-
const rect = getSelectedTableRect(editor);
|
|
28922
|
-
const widths = getSelectedColumnWidths(editor, rect);
|
|
28923
|
-
const merged = editor.chain().focus().mergeCells().run();
|
|
28924
|
-
if (!merged) return merged;
|
|
28925
|
-
if (!widths) {
|
|
28926
|
-
dispatchTableLayoutChange(editor);
|
|
28927
|
-
return merged;
|
|
28928
|
-
}
|
|
28929
|
-
const nextRect = getSelectedTableRect(editor);
|
|
28930
|
-
const cellPos = nextRect.map.map[nextRect.top * nextRect.map.width + nextRect.left];
|
|
28931
|
-
const absolutePos = nextRect.tableStart + cellPos;
|
|
28932
|
-
const node = editor.state.doc.nodeAt(absolutePos);
|
|
28933
|
-
if (!node) return merged;
|
|
28934
|
-
editor.view.dispatch(
|
|
28935
|
-
editor.state.tr.setNodeMarkup(absolutePos, node.type, {
|
|
28936
|
-
...node.attrs,
|
|
28937
|
-
colwidth: widths
|
|
28938
|
-
})
|
|
28939
|
-
);
|
|
28940
|
-
dispatchTableLayoutChange(editor);
|
|
28941
|
-
return true;
|
|
28942
|
-
}
|
|
28943
|
-
function runTableCommandAtCellPos(editor, cellPos, command) {
|
|
28944
|
-
if (cellPos == null) return false;
|
|
28945
|
-
focusCell(editor, cellPos);
|
|
28946
|
-
return command(editor.chain().focus(null, { scrollIntoView: false })).run();
|
|
28947
|
-
}
|
|
28948
|
-
function getTableCornerCellPos(editor, activePos) {
|
|
28949
|
-
const tableInfo = findTableInfoFromCellPos(editor, activePos);
|
|
28950
|
-
if (!tableInfo) return null;
|
|
28951
|
-
const map = import_tables.TableMap.get(tableInfo.table);
|
|
28952
|
-
return tableInfo.tableStart + map.positionAt(map.height - 1, map.width - 1, tableInfo.table);
|
|
28953
|
-
}
|
|
28954
|
-
function replaceTableAtCellPos(editor, cellPos, updateTable) {
|
|
28955
|
-
if (cellPos == null) return false;
|
|
28956
|
-
const tableInfo = findTableInfoFromCellPos(editor, cellPos);
|
|
28957
|
-
if (!tableInfo) return false;
|
|
28958
|
-
const nextTable = updateTable(tableInfo.table);
|
|
28959
|
-
if (!nextTable) return false;
|
|
28960
|
-
editor.view.dispatch(editor.state.tr.replaceWith(tableInfo.tablePos, tableInfo.tablePos + tableInfo.table.nodeSize, nextTable));
|
|
28961
|
-
dispatchTableLayoutChange(editor);
|
|
28962
|
-
return true;
|
|
28963
|
-
}
|
|
28964
|
-
function duplicateTableRowAt(editor, rowIndex, cellPos) {
|
|
28965
|
-
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28966
|
-
const rows = collectChildren(tableNode);
|
|
28967
|
-
const rowNode = rows[rowIndex];
|
|
28968
|
-
if (!rowNode) return null;
|
|
28969
|
-
rows.splice(rowIndex + 1, 0, rowNode.copy(rowNode.content));
|
|
28970
|
-
return tableNode.type.create(tableNode.attrs, rows);
|
|
28971
|
-
});
|
|
28972
|
-
}
|
|
28973
|
-
function clearTableRowAt(editor, rowIndex, cellPos) {
|
|
28974
|
-
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28975
|
-
const rows = collectChildren(tableNode);
|
|
28976
|
-
const rowNode = rows[rowIndex];
|
|
28977
|
-
if (!rowNode) return null;
|
|
28978
|
-
const cells = collectChildren(rowNode).map((cellNode) => createEmptyCellNode(cellNode));
|
|
28979
|
-
rows[rowIndex] = rowNode.type.create(rowNode.attrs, cells);
|
|
28980
|
-
return tableNode.type.create(tableNode.attrs, rows);
|
|
28981
|
-
});
|
|
28982
|
-
}
|
|
28983
|
-
function duplicateTableColumnAt(editor, columnIndex, cellPos) {
|
|
28984
|
-
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28985
|
-
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
28986
|
-
const cells = collectChildren(rowNode);
|
|
28987
|
-
const cellNode = cells[columnIndex];
|
|
28988
|
-
if (!cellNode) return rowNode;
|
|
28989
|
-
cells.splice(columnIndex + 1, 0, cellNode.copy(cellNode.content));
|
|
28990
|
-
return rowNode.type.create(rowNode.attrs, cells);
|
|
28991
|
-
});
|
|
28992
|
-
return tableNode.type.create(tableNode.attrs, rows);
|
|
28993
|
-
});
|
|
28994
|
-
}
|
|
28995
|
-
function clearTableColumnAt(editor, columnIndex, cellPos) {
|
|
28996
|
-
return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
|
|
28997
|
-
const rows = collectChildren(tableNode).map((rowNode) => {
|
|
28998
|
-
const cells = collectChildren(rowNode);
|
|
28999
|
-
const cellNode = cells[columnIndex];
|
|
29000
|
-
if (!cellNode) return rowNode;
|
|
29001
|
-
cells[columnIndex] = createEmptyCellNode(cellNode);
|
|
29002
|
-
return rowNode.type.create(rowNode.attrs, cells);
|
|
29003
|
-
});
|
|
29004
|
-
return tableNode.type.create(tableNode.attrs, rows);
|
|
29005
|
-
});
|
|
29006
|
-
}
|
|
29007
|
-
function expandTableFromCell(editor, activeCellPos, rows, columns) {
|
|
29008
|
-
let cornerCellPos = getTableCornerCellPos(editor, activeCellPos);
|
|
29009
|
-
if (cornerCellPos == null) return false;
|
|
29010
|
-
for (let index = 0; index < rows; index += 1) {
|
|
29011
|
-
const ok = runTableCommandAtCellPos(editor, cornerCellPos, (chain) => chain.addRowAfter());
|
|
29012
|
-
if (!ok) return false;
|
|
29013
|
-
cornerCellPos = getTableCornerCellPos(editor, cornerCellPos);
|
|
29014
|
-
if (cornerCellPos == null) return false;
|
|
29015
|
-
}
|
|
29016
|
-
for (let index = 0; index < columns; index += 1) {
|
|
29017
|
-
const ok = runTableCommandAtCellPos(editor, cornerCellPos, (chain) => chain.addColumnAfter());
|
|
29018
|
-
if (!ok) return false;
|
|
29019
|
-
cornerCellPos = getTableCornerCellPos(editor, cornerCellPos);
|
|
29020
|
-
if (cornerCellPos == null) return false;
|
|
29021
|
-
}
|
|
29022
|
-
dispatchTableLayoutChange(editor);
|
|
29023
|
-
return true;
|
|
29024
|
-
}
|
|
29025
|
-
|
|
29026
|
-
// src/components/UEditor/menus.tsx
|
|
29027
29082
|
var import_jsx_runtime86 = require("react/jsx-runtime");
|
|
29028
29083
|
var FloatingSlashCommandMenu = ({ editor, onClose }) => {
|
|
29029
29084
|
const t = useSmartTranslations("UEditor");
|
|
@@ -35636,6 +35691,7 @@ var UEDITOR_PROSEMIRROR_CLASS_NAME = cn(
|
|
|
35636
35691
|
"[&_.tableWrapper::-webkit-scrollbar-thumb]:border-transparent",
|
|
35637
35692
|
"[&_.tableWrapper::-webkit-scrollbar-thumb]:bg-border/70",
|
|
35638
35693
|
"[&_.tableWrapper::-webkit-scrollbar-thumb:hover]:bg-muted-foreground/45",
|
|
35694
|
+
"[&_table]:w-auto",
|
|
35639
35695
|
"[&_table]:table-fixed",
|
|
35640
35696
|
"[&_table]:overflow-hidden",
|
|
35641
35697
|
"[&_table]:select-text",
|
|
@@ -36891,7 +36947,7 @@ var MenuBar = ({
|
|
|
36891
36947
|
"div",
|
|
36892
36948
|
{
|
|
36893
36949
|
"data-testid": "preview-content",
|
|
36894
|
-
className:
|
|
36950
|
+
className: UEDITOR_PROSEMIRROR_CLASS_NAME,
|
|
36895
36951
|
dangerouslySetInnerHTML: { __html: editor.getHTML() }
|
|
36896
36952
|
}
|
|
36897
36953
|
)
|