@harbour-enterprises/superdoc 0.25.0-next.6 → 0.25.0-next.7
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/chunks/{PdfViewer-BeQy7uL0.cjs → PdfViewer-B2IOirxr.cjs} +1 -1
- package/dist/chunks/{PdfViewer-BOrm7Awj.es.js → PdfViewer-lMsL6l5A.es.js} +1 -1
- package/dist/chunks/{index-DDGjYIm1.es.js → index-DOLVGSYC.es.js} +2 -2
- package/dist/chunks/{index-7exCeEb1.cjs → index-aoNHRlnl.cjs} +2 -2
- package/dist/chunks/{super-editor.es-GExnUB7l.cjs → super-editor.es-B2cypcnX.cjs} +198 -0
- package/dist/chunks/{super-editor.es-XXbEUVCc.es.js → super-editor.es-CHq5MqBc.es.js} +198 -0
- package/dist/super-editor/ai-writer.es.js +1 -1
- package/dist/super-editor/chunks/{editor-D1Q0suDz.js → editor-CEZNgaJQ.js} +198 -0
- package/dist/super-editor/chunks/{toolbar-DjuLzygc.js → toolbar-C6e42Zol.js} +1 -1
- package/dist/super-editor/editor.es.js +1 -1
- package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content-commands.d.ts +25 -0
- package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTablesById.d.ts +10 -0
- package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/index.d.ts +1 -0
- package/dist/super-editor/super-editor/src/extensions/table/table.d.ts +84 -0
- package/dist/super-editor/super-editor/src/extensions/table/tableHelpers/appendRows.d.ts +139 -0
- package/dist/super-editor/super-editor.es.js +3 -3
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +1 -1
- package/dist/super-editor.es.js +1 -1
- package/dist/superdoc.cjs +2 -2
- package/dist/superdoc.es.js +2 -2
- package/dist/superdoc.umd.js +198 -0
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/superdoc.umd.js
CHANGED
|
@@ -63466,10 +63466,27 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
63466
63466
|
const result = findChildren$5(state2.doc, (node) => node.type.name === "structuredContentBlock");
|
|
63467
63467
|
return result;
|
|
63468
63468
|
}
|
|
63469
|
+
function getStructuredContentTablesById(id, state2) {
|
|
63470
|
+
if (!id || !state2) return [];
|
|
63471
|
+
const blocks = getStructuredContentTagsById(id, state2).filter(
|
|
63472
|
+
({ node }) => node.type.name === "structuredContentBlock"
|
|
63473
|
+
);
|
|
63474
|
+
if (!blocks.length) return [];
|
|
63475
|
+
const { pos: blockPos, node: blockNode } = blocks[0];
|
|
63476
|
+
const tablesInBlock = [];
|
|
63477
|
+
blockNode.descendants((child, relPos) => {
|
|
63478
|
+
if (child.type.name === "table") {
|
|
63479
|
+
const absPos = blockPos + 1 + relPos;
|
|
63480
|
+
tablesInBlock.push({ node: child, pos: absPos });
|
|
63481
|
+
}
|
|
63482
|
+
});
|
|
63483
|
+
return tablesInBlock;
|
|
63484
|
+
}
|
|
63469
63485
|
const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
63470
63486
|
__proto__: null,
|
|
63471
63487
|
getStructuredContentBlockTags,
|
|
63472
63488
|
getStructuredContentInlineTags,
|
|
63489
|
+
getStructuredContentTablesById,
|
|
63473
63490
|
getStructuredContentTags,
|
|
63474
63491
|
getStructuredContentTagsById
|
|
63475
63492
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -63666,6 +63683,36 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
63666
63683
|
tr.replaceWith(posFrom, posTo, content);
|
|
63667
63684
|
}
|
|
63668
63685
|
return true;
|
|
63686
|
+
},
|
|
63687
|
+
/**
|
|
63688
|
+
* Append multiple rows to the end of a table inside a structured content block.
|
|
63689
|
+
* Each inner array represents the cell values for one new row.
|
|
63690
|
+
* @category Command
|
|
63691
|
+
* @param {StructuredContentTableAppendRowsOptions} options - Append configuration
|
|
63692
|
+
* @example
|
|
63693
|
+
* editor.commands.appendRowsToStructuredContentTable({
|
|
63694
|
+
* id: 'block-123',
|
|
63695
|
+
* tableIndex: 0,
|
|
63696
|
+
* rows: [['A', 'B'], ['C', 'D']],
|
|
63697
|
+
* copyRowStyle: true,
|
|
63698
|
+
* });
|
|
63699
|
+
*/
|
|
63700
|
+
appendRowsToStructuredContentTable: ({ id, tableIndex = 0, rows = [], copyRowStyle = false }) => ({ state: state2, commands: commands2, dispatch }) => {
|
|
63701
|
+
const normalized = normalizeRowsInput(rows);
|
|
63702
|
+
if (!normalized.length) return true;
|
|
63703
|
+
const tables = getStructuredContentTablesById(id, state2);
|
|
63704
|
+
if (!tables.length || tableIndex < 0 || tableIndex >= tables.length) return true;
|
|
63705
|
+
const { node: tableNode, pos: tablePos } = tables[tableIndex];
|
|
63706
|
+
if (dispatch) {
|
|
63707
|
+
return commands2.appendRowsWithContent({ tablePos, tableNode, valueRows: normalized, copyRowStyle });
|
|
63708
|
+
}
|
|
63709
|
+
return commands2.appendRowsWithContent({
|
|
63710
|
+
tablePos,
|
|
63711
|
+
tableNode,
|
|
63712
|
+
valueRows: normalized,
|
|
63713
|
+
copyRowStyle,
|
|
63714
|
+
dispatch: false
|
|
63715
|
+
});
|
|
63669
63716
|
}
|
|
63670
63717
|
};
|
|
63671
63718
|
},
|
|
@@ -63675,6 +63722,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
63675
63722
|
};
|
|
63676
63723
|
}
|
|
63677
63724
|
});
|
|
63725
|
+
const normalizeRowsInput = (rowsOrValues) => {
|
|
63726
|
+
if (!Array.isArray(rowsOrValues) || !rowsOrValues.length) {
|
|
63727
|
+
return [];
|
|
63728
|
+
}
|
|
63729
|
+
if (Array.isArray(rowsOrValues[0])) {
|
|
63730
|
+
return rowsOrValues;
|
|
63731
|
+
}
|
|
63732
|
+
return [rowsOrValues];
|
|
63733
|
+
};
|
|
63678
63734
|
class DocumentSectionView {
|
|
63679
63735
|
constructor(node, getPos, decorations, editor) {
|
|
63680
63736
|
__privateAdd$1(this, _DocumentSectionView_instances);
|
|
@@ -69427,6 +69483,107 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
69427
69483
|
}
|
|
69428
69484
|
return null;
|
|
69429
69485
|
}
|
|
69486
|
+
function resolveTable(tr, tablePos, tableNode) {
|
|
69487
|
+
if (tableNode && tableNode.type && tableNode.type.name === "table") {
|
|
69488
|
+
return tableNode;
|
|
69489
|
+
}
|
|
69490
|
+
if (typeof tablePos === "number") {
|
|
69491
|
+
const current = tr.doc.nodeAt(tablePos);
|
|
69492
|
+
if (current && current.type.name === "table") {
|
|
69493
|
+
return current;
|
|
69494
|
+
}
|
|
69495
|
+
}
|
|
69496
|
+
return null;
|
|
69497
|
+
}
|
|
69498
|
+
function pickTemplateRowForAppend(tableNode, schema) {
|
|
69499
|
+
const RowType = schema.nodes.tableRow;
|
|
69500
|
+
const rows = [];
|
|
69501
|
+
tableNode.descendants((child) => {
|
|
69502
|
+
if (child.type === RowType) rows.push(child);
|
|
69503
|
+
});
|
|
69504
|
+
if (!rows.length) return null;
|
|
69505
|
+
for (let i2 = rows.length - 1; i2 >= 0; i2--) {
|
|
69506
|
+
const r2 = rows[i2];
|
|
69507
|
+
const hasBodyCell = r2.content?.content?.some((c2) => c2.type.name === "tableCell");
|
|
69508
|
+
if (hasBodyCell) return r2;
|
|
69509
|
+
}
|
|
69510
|
+
return rows[rows.length - 1];
|
|
69511
|
+
}
|
|
69512
|
+
function extractRowTemplateFormatting(cellNode, schema) {
|
|
69513
|
+
const ParagraphType = schema.nodes.paragraph;
|
|
69514
|
+
let blockType = ParagraphType;
|
|
69515
|
+
let blockAttrs = null;
|
|
69516
|
+
let textMarks = [];
|
|
69517
|
+
const blocks = cellNode?.content?.content || [];
|
|
69518
|
+
for (const block of blocks) {
|
|
69519
|
+
const isParagraphish = block.type === ParagraphType || block.type.name === "heading";
|
|
69520
|
+
if (isParagraphish) {
|
|
69521
|
+
blockType = block.type || ParagraphType;
|
|
69522
|
+
blockAttrs = block.attrs || null;
|
|
69523
|
+
}
|
|
69524
|
+
let foundText = null;
|
|
69525
|
+
block.descendants?.((n) => {
|
|
69526
|
+
if (!foundText && n.isText) foundText = n;
|
|
69527
|
+
});
|
|
69528
|
+
if (foundText) {
|
|
69529
|
+
textMarks = foundText.marks ? Array.from(foundText.marks) : [];
|
|
69530
|
+
break;
|
|
69531
|
+
}
|
|
69532
|
+
}
|
|
69533
|
+
if (!blockType || !blockType.validContent) blockType = ParagraphType;
|
|
69534
|
+
return { blockType, blockAttrs, textMarks };
|
|
69535
|
+
}
|
|
69536
|
+
function buildFormattedCellBlock(schema, value, { blockType, blockAttrs, textMarks }, copyRowStyle = false) {
|
|
69537
|
+
const text = typeof value === "string" ? value : value == null ? "" : String(value);
|
|
69538
|
+
const marks = copyRowStyle ? textMarks || [] : [];
|
|
69539
|
+
const textNode = schema.text(text, marks);
|
|
69540
|
+
const type2 = blockType || schema.nodes.paragraph;
|
|
69541
|
+
return type2.createAndFill(blockAttrs || null, textNode);
|
|
69542
|
+
}
|
|
69543
|
+
function buildRowFromTemplateRow({ schema, tableNode, templateRow, values, copyRowStyle = false }) {
|
|
69544
|
+
const RowType = schema.nodes.tableRow;
|
|
69545
|
+
const CellType = schema.nodes.tableCell;
|
|
69546
|
+
const HeaderType = schema.nodes.tableHeader;
|
|
69547
|
+
const map2 = TableMap.get(tableNode);
|
|
69548
|
+
const totalColumns = map2.width;
|
|
69549
|
+
const byColumns = Array.isArray(values) && values.length === totalColumns;
|
|
69550
|
+
const newCells = [];
|
|
69551
|
+
let columnCursor = 0;
|
|
69552
|
+
templateRow.content.content.forEach((cellNode, cellIndex) => {
|
|
69553
|
+
const isHeaderCell = cellNode.type === HeaderType;
|
|
69554
|
+
const targetCellType = isHeaderCell ? CellType : cellNode.type;
|
|
69555
|
+
const attrs = { ...cellNode.attrs };
|
|
69556
|
+
const formatting = extractRowTemplateFormatting(cellNode, schema);
|
|
69557
|
+
let cellValue = "";
|
|
69558
|
+
if (byColumns) {
|
|
69559
|
+
const span = Math.max(1, attrs.colspan || 1);
|
|
69560
|
+
cellValue = values[columnCursor] ?? "";
|
|
69561
|
+
columnCursor += span;
|
|
69562
|
+
} else {
|
|
69563
|
+
cellValue = Array.isArray(values) ? values[cellIndex] ?? "" : "";
|
|
69564
|
+
}
|
|
69565
|
+
const content = buildFormattedCellBlock(schema, cellValue, formatting, copyRowStyle);
|
|
69566
|
+
const newCell = targetCellType.createAndFill(attrs, content);
|
|
69567
|
+
if (newCell) newCells.push(newCell);
|
|
69568
|
+
});
|
|
69569
|
+
return RowType.createAndFill(null, newCells);
|
|
69570
|
+
}
|
|
69571
|
+
function insertRowsAtTableEnd({ tr, tablePos, tableNode, rows }) {
|
|
69572
|
+
if (!rows || !rows.length) return;
|
|
69573
|
+
const RowTypeName = "tableRow";
|
|
69574
|
+
let lastRowRelPos = 0;
|
|
69575
|
+
let lastRowNode = null;
|
|
69576
|
+
tableNode.descendants((child, relPos) => {
|
|
69577
|
+
if (child.type.name === RowTypeName) {
|
|
69578
|
+
lastRowRelPos = relPos;
|
|
69579
|
+
lastRowNode = child;
|
|
69580
|
+
}
|
|
69581
|
+
});
|
|
69582
|
+
if (!lastRowNode) return;
|
|
69583
|
+
const lastRowAbsEnd = tablePos + 1 + lastRowRelPos + lastRowNode.nodeSize;
|
|
69584
|
+
const frag = Fragment.fromArray(rows);
|
|
69585
|
+
tr.insert(lastRowAbsEnd, frag);
|
|
69586
|
+
}
|
|
69430
69587
|
const Table = Node$1.create({
|
|
69431
69588
|
name: "table",
|
|
69432
69589
|
content: "tableRow+",
|
|
@@ -69586,6 +69743,47 @@ Please report this to https://github.com/markedjs/marked.`, e) {
|
|
|
69586
69743
|
},
|
|
69587
69744
|
addCommands() {
|
|
69588
69745
|
return {
|
|
69746
|
+
/**
|
|
69747
|
+
* Append multiple rows to the end of a table in a single transaction.
|
|
69748
|
+
* @category Command
|
|
69749
|
+
* @param {appendRowsWithContentOptions} options - Append configuration
|
|
69750
|
+
* @example
|
|
69751
|
+
* editor.commands.appendRowsWithContent({ tablePos, valueRows: [['A','B'], ['C','D']], copyRowStyle: true })
|
|
69752
|
+
*/
|
|
69753
|
+
appendRowsWithContent: ({ tablePos, tableNode, valueRows = [], copyRowStyle = false }) => ({ editor, chain }) => {
|
|
69754
|
+
if (typeof tablePos !== "number" && !tableNode || !Array.isArray(valueRows) || !valueRows.length) {
|
|
69755
|
+
return false;
|
|
69756
|
+
}
|
|
69757
|
+
return chain().command(({ tr, dispatch }) => {
|
|
69758
|
+
const workingTable = resolveTable(tr, tablePos, tableNode);
|
|
69759
|
+
if (!workingTable) return false;
|
|
69760
|
+
const templateRow = pickTemplateRowForAppend(workingTable, editor.schema);
|
|
69761
|
+
if (!templateRow) return false;
|
|
69762
|
+
const newRows = valueRows.map(
|
|
69763
|
+
(vals) => buildRowFromTemplateRow({
|
|
69764
|
+
schema: editor.schema,
|
|
69765
|
+
tableNode: workingTable,
|
|
69766
|
+
templateRow,
|
|
69767
|
+
values: vals,
|
|
69768
|
+
copyRowStyle
|
|
69769
|
+
})
|
|
69770
|
+
).filter(Boolean);
|
|
69771
|
+
if (!newRows.length) return false;
|
|
69772
|
+
let resolvedTablePos = tablePos;
|
|
69773
|
+
if (typeof resolvedTablePos !== "number" && workingTable) {
|
|
69774
|
+
const tables = editor.getNodesOfType("table");
|
|
69775
|
+
const match = workingTable ? tables.find((t) => t.node.eq(workingTable)) : tables[0];
|
|
69776
|
+
resolvedTablePos = match?.pos ?? null;
|
|
69777
|
+
}
|
|
69778
|
+
if (typeof resolvedTablePos !== "number") {
|
|
69779
|
+
return false;
|
|
69780
|
+
}
|
|
69781
|
+
if (dispatch) {
|
|
69782
|
+
insertRowsAtTableEnd({ tr, tablePos, tableNode: workingTable, rows: newRows });
|
|
69783
|
+
}
|
|
69784
|
+
return true;
|
|
69785
|
+
}).run();
|
|
69786
|
+
},
|
|
69589
69787
|
/**
|
|
69590
69788
|
* Insert a new table into the document
|
|
69591
69789
|
* @category Command
|