quoin-editor 0.4.1 → 1.0.0
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/CHANGELOG.md +205 -0
- package/MIGRATION.md +233 -0
- package/README.md +78 -715
- package/dist/ai.cjs +1107 -0
- package/dist/ai.cjs.map +1 -0
- package/dist/ai.d.cts +68 -0
- package/dist/ai.d.ts +68 -0
- package/dist/ai.js +1107 -0
- package/dist/ai.js.map +1 -0
- package/dist/catalogue.cjs +59 -0
- package/dist/catalogue.cjs.map +1 -0
- package/dist/catalogue.d.cts +39 -0
- package/dist/catalogue.d.ts +39 -0
- package/dist/catalogue.js +59 -0
- package/dist/catalogue.js.map +1 -0
- package/dist/chunk-2QCRZ7OL.cjs +319 -0
- package/dist/chunk-2QCRZ7OL.cjs.map +1 -0
- package/dist/chunk-2VDK27IF.cjs +6666 -0
- package/dist/chunk-2VDK27IF.cjs.map +1 -0
- package/dist/chunk-47MLKSI2.js +326 -0
- package/dist/chunk-47MLKSI2.js.map +1 -0
- package/dist/chunk-5DNCCN6X.cjs +326 -0
- package/dist/chunk-5DNCCN6X.cjs.map +1 -0
- package/dist/chunk-AEJXZBVR.cjs +1378 -0
- package/dist/chunk-AEJXZBVR.cjs.map +1 -0
- package/dist/chunk-CDELOHDY.cjs +239 -0
- package/dist/chunk-CDELOHDY.cjs.map +1 -0
- package/dist/chunk-E75EHRPA.cjs +175 -0
- package/dist/chunk-E75EHRPA.cjs.map +1 -0
- package/dist/chunk-EL2OEJQC.cjs +562 -0
- package/dist/chunk-EL2OEJQC.cjs.map +1 -0
- package/dist/chunk-GLLXHMH2.cjs +25 -0
- package/dist/chunk-GLLXHMH2.cjs.map +1 -0
- package/dist/chunk-GTTPVJSD.cjs +3286 -0
- package/dist/chunk-GTTPVJSD.cjs.map +1 -0
- package/dist/chunk-HELJTLNC.cjs +100 -0
- package/dist/chunk-HELJTLNC.cjs.map +1 -0
- package/dist/chunk-HJIQT3S5.js +4047 -0
- package/dist/chunk-HJIQT3S5.js.map +1 -0
- package/dist/chunk-HZSSEYJS.cjs +504 -0
- package/dist/chunk-HZSSEYJS.cjs.map +1 -0
- package/dist/chunk-JDPTZUBW.js +184 -0
- package/dist/chunk-JDPTZUBW.js.map +1 -0
- package/dist/chunk-JEIFJHEI.js +14 -0
- package/dist/chunk-JEIFJHEI.js.map +1 -0
- package/dist/chunk-K574XHMM.js +25 -0
- package/dist/chunk-K574XHMM.js.map +1 -0
- package/dist/chunk-KAVU6T6J.js +249 -0
- package/dist/chunk-KAVU6T6J.js.map +1 -0
- package/dist/chunk-KXOBZGQO.js +1378 -0
- package/dist/chunk-KXOBZGQO.js.map +1 -0
- package/dist/chunk-LCQSG4M6.js +3335 -0
- package/dist/chunk-LCQSG4M6.js.map +1 -0
- package/dist/chunk-MQ2XQ4MX.js +100 -0
- package/dist/chunk-MQ2XQ4MX.js.map +1 -0
- package/dist/chunk-ND5XJVK2.cjs +3335 -0
- package/dist/chunk-ND5XJVK2.cjs.map +1 -0
- package/dist/chunk-NNDYYEW5.js +504 -0
- package/dist/chunk-NNDYYEW5.js.map +1 -0
- package/dist/chunk-NOKWNK2O.js +319 -0
- package/dist/chunk-NOKWNK2O.js.map +1 -0
- package/dist/chunk-OMOBMXD5.cjs +57 -0
- package/dist/chunk-OMOBMXD5.cjs.map +1 -0
- package/dist/chunk-PMWCQSQX.js +239 -0
- package/dist/chunk-PMWCQSQX.js.map +1 -0
- package/dist/chunk-POBM7MGR.js +30 -0
- package/dist/chunk-POBM7MGR.js.map +1 -0
- package/dist/chunk-PWUEPDA3.cjs +598 -0
- package/dist/chunk-PWUEPDA3.cjs.map +1 -0
- package/dist/chunk-PZ4GT5JO.cjs +4047 -0
- package/dist/chunk-PZ4GT5JO.cjs.map +1 -0
- package/dist/chunk-QAW5NH6S.cjs +14 -0
- package/dist/chunk-QAW5NH6S.cjs.map +1 -0
- package/dist/chunk-RDG4VI6E.cjs +706 -0
- package/dist/chunk-RDG4VI6E.cjs.map +1 -0
- package/dist/chunk-RUDWMKYX.js +562 -0
- package/dist/chunk-RUDWMKYX.js.map +1 -0
- package/dist/chunk-SG37UBDO.js +706 -0
- package/dist/chunk-SG37UBDO.js.map +1 -0
- package/dist/chunk-SLVDAHHK.cjs +30 -0
- package/dist/chunk-SLVDAHHK.cjs.map +1 -0
- package/dist/chunk-T7SW6OWV.js +598 -0
- package/dist/chunk-T7SW6OWV.js.map +1 -0
- package/dist/chunk-TC4DARU2.js +175 -0
- package/dist/chunk-TC4DARU2.js.map +1 -0
- package/dist/chunk-WQHV3MRE.cjs +184 -0
- package/dist/chunk-WQHV3MRE.cjs.map +1 -0
- package/dist/chunk-WXMYDXPN.cjs +33 -0
- package/dist/chunk-WXMYDXPN.cjs.map +1 -0
- package/dist/chunk-XEBWC7ZL.js +57 -0
- package/dist/chunk-XEBWC7ZL.js.map +1 -0
- package/dist/chunk-ZC24WB7Y.cjs +249 -0
- package/dist/chunk-ZC24WB7Y.cjs.map +1 -0
- package/dist/chunk-ZGZEJCRV.js +6666 -0
- package/dist/chunk-ZGZEJCRV.js.map +1 -0
- package/dist/chunk-ZHOSSWUM.js +33 -0
- package/dist/chunk-ZHOSSWUM.js.map +1 -0
- package/dist/chunk-ZS2WA357.js +3286 -0
- package/dist/chunk-ZS2WA357.js.map +1 -0
- package/dist/comments.cjs +993 -0
- package/dist/comments.cjs.map +1 -0
- package/dist/comments.d.cts +88 -0
- package/dist/comments.d.ts +88 -0
- package/dist/comments.js +993 -0
- package/dist/comments.js.map +1 -0
- package/dist/diff.cjs +343 -0
- package/dist/diff.cjs.map +1 -0
- package/dist/diff.d.cts +67 -0
- package/dist/diff.d.ts +67 -0
- package/dist/diff.js +343 -0
- package/dist/diff.js.map +1 -0
- package/dist/docx.cjs +854 -0
- package/dist/docx.cjs.map +1 -0
- package/dist/docx.d.cts +27 -0
- package/dist/docx.d.ts +27 -0
- package/dist/docx.js +854 -0
- package/dist/docx.js.map +1 -0
- package/dist/embed-provider-jXwlRmnp.d.cts +19 -0
- package/dist/embed-provider-jXwlRmnp.d.ts +19 -0
- package/dist/embed.cjs +17 -0
- package/dist/embed.cjs.map +1 -0
- package/dist/embed.d.cts +56 -0
- package/dist/embed.d.ts +56 -0
- package/dist/embed.js +17 -0
- package/dist/embed.js.map +1 -0
- package/dist/emoji-data.cjs +1968 -0
- package/dist/emoji-data.cjs.map +1 -0
- package/dist/emoji-data.js +1968 -0
- package/dist/emoji-data.js.map +1 -0
- package/dist/emoji-extension-C12gDPm6.d.cts +46 -0
- package/dist/emoji-extension-DpQ43HjE.d.ts +46 -0
- package/dist/emoji.cjs +18 -0
- package/dist/emoji.cjs.map +1 -0
- package/dist/emoji.d.cts +31 -0
- package/dist/emoji.d.ts +31 -0
- package/dist/emoji.js +18 -0
- package/dist/emoji.js.map +1 -0
- package/dist/engine.cjs +119 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +144 -0
- package/dist/engine.d.ts +144 -0
- package/dist/engine.js +119 -0
- package/dist/engine.js.map +1 -0
- package/dist/find-extension-DKqLLSuP.d.ts +41 -0
- package/dist/find-extension-_sbZEt3R.d.cts +41 -0
- package/dist/find.cjs +20 -0
- package/dist/find.cjs.map +1 -0
- package/dist/find.d.cts +44 -0
- package/dist/find.d.ts +44 -0
- package/dist/find.js +20 -0
- package/dist/find.js.map +1 -0
- package/dist/headless.cjs +151 -518
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +102 -69
- package/dist/headless.d.ts +102 -69
- package/dist/headless.js +149 -467
- package/dist/headless.js.map +1 -1
- package/dist/index-CgD72kHB.d.cts +65 -0
- package/dist/index-DNYbTK3w.d.ts +65 -0
- package/dist/index.cjs +183 -2753
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +345 -253
- package/dist/index.d.ts +345 -253
- package/dist/index.js +168 -2696
- package/dist/index.js.map +1 -1
- package/dist/math.cjs +18 -0
- package/dist/math.cjs.map +1 -0
- package/dist/math.d.cts +49 -0
- package/dist/math.d.ts +49 -0
- package/dist/math.js +18 -0
- package/dist/math.js.map +1 -0
- package/dist/mention.cjs +18 -0
- package/dist/mention.cjs.map +1 -0
- package/dist/mention.d.cts +50 -0
- package/dist/mention.d.ts +50 -0
- package/dist/mention.js +18 -0
- package/dist/mention.js.map +1 -0
- package/dist/presence.cjs +565 -0
- package/dist/presence.cjs.map +1 -0
- package/dist/presence.d.cts +30 -0
- package/dist/presence.d.ts +30 -0
- package/dist/presence.js +565 -0
- package/dist/presence.js.map +1 -0
- package/dist/registry-CWBOSAHm.d.cts +121 -0
- package/dist/registry-CWBOSAHm.d.ts +121 -0
- package/dist/stats-extension-Bly88uio.d.ts +40 -0
- package/dist/stats-extension-CJPijvUb.d.cts +40 -0
- package/dist/stats.cjs +19 -0
- package/dist/stats.cjs.map +1 -0
- package/dist/stats.d.cts +19 -0
- package/dist/stats.d.ts +19 -0
- package/dist/stats.js +19 -0
- package/dist/stats.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/table-extension-BTLxFy2S.d.cts +57 -0
- package/dist/table-extension-Dzf4k6hI.d.ts +57 -0
- package/dist/table.cjs +50 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +57 -0
- package/dist/table.d.ts +57 -0
- package/dist/table.js +50 -0
- package/dist/table.js.map +1 -0
- package/dist/to-html-C5t7xyaM.d.ts +21 -0
- package/dist/to-html-CNCITCln.d.cts +21 -0
- package/dist/toc-extension-B3-s6h2x.d.cts +25 -0
- package/dist/toc-extension-DWm5alVj.d.ts +25 -0
- package/dist/toc.cjs +18 -0
- package/dist/toc.cjs.map +1 -0
- package/dist/toc.d.cts +24 -0
- package/dist/toc.d.ts +24 -0
- package/dist/toc.js +18 -0
- package/dist/toc.js.map +1 -0
- package/dist/types-Cz7XJLaK.d.cts +366 -0
- package/dist/types-DULc8wwg.d.cts +120 -0
- package/dist/types-DULc8wwg.d.ts +120 -0
- package/dist/types-a1CRBlEh.d.ts +366 -0
- package/dist/view-controller-DSHw0ltQ.d.cts +118 -0
- package/dist/view-controller-UbpzblGl.d.ts +118 -0
- package/dist/view.cjs +23 -0
- package/dist/view.cjs.map +1 -0
- package/dist/view.d.cts +40 -0
- package/dist/view.d.ts +40 -0
- package/dist/view.js +23 -0
- package/dist/view.js.map +1 -0
- package/dist/yjs.cjs +1026 -0
- package/dist/yjs.cjs.map +1 -0
- package/dist/yjs.d.cts +22 -0
- package/dist/yjs.d.ts +22 -0
- package/dist/yjs.js +1026 -0
- package/dist/yjs.js.map +1 -0
- package/package.json +219 -20
|
@@ -0,0 +1,1378 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunk2VDK27IFcjs = require('./chunk-2VDK27IF.cjs');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var _chunkGTTPVJSDcjs = require('./chunk-GTTPVJSD.cjs');
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
var _chunkPZ4GT5JOcjs = require('./chunk-PZ4GT5JO.cjs');
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
var _chunkND5XJVK2cjs = require('./chunk-ND5XJVK2.cjs');
|
|
63
|
+
|
|
64
|
+
// src/engine/commands/table-shape.ts
|
|
65
|
+
var CELL = /^cell:(\d+):(\d+)$/;
|
|
66
|
+
var tableShape = (block) => ({
|
|
67
|
+
rows: _chunkND5XJVK2cjs.countOf.call(void 0, block.attrs.rows),
|
|
68
|
+
cols: _chunkND5XJVK2cjs.countOf.call(void 0, block.attrs.cols)
|
|
69
|
+
});
|
|
70
|
+
var ALIGNS = ["left", "center", "right"];
|
|
71
|
+
var columnAligns = (block, cols) => Array.from({ length: cols }, (_, col) => {
|
|
72
|
+
const align = Array.isArray(block.attrs.align) ? block.attrs.align[col] : null;
|
|
73
|
+
return ALIGNS.includes(align) ? align : null;
|
|
74
|
+
});
|
|
75
|
+
var validWidths = (value, cols) => Array.isArray(value) && value.length === cols && value.every((width) => typeof width === "number" && width > 0) ? value : null;
|
|
76
|
+
var storedWidths = (block, cols) => validWidths(block.attrs.widths, cols);
|
|
77
|
+
function cellOf(region) {
|
|
78
|
+
const match = CELL.exec(region);
|
|
79
|
+
return match === null ? null : [Number(match[1]), Number(match[2])];
|
|
80
|
+
}
|
|
81
|
+
function tableBlock(doc, id) {
|
|
82
|
+
const block = _chunkND5XJVK2cjs.blockById.call(void 0, doc, id);
|
|
83
|
+
return _optionalChain([block, 'optionalAccess', _2 => _2.type]) === "TABLE" ? block : null;
|
|
84
|
+
}
|
|
85
|
+
var isIndex = (index, length) => Number.isInteger(index) && index >= 0 && index < length;
|
|
86
|
+
function movedOrder(length, from, to) {
|
|
87
|
+
const order = Array.from({ length }, (_, i) => i).filter((i) => i !== from);
|
|
88
|
+
order.splice(to, 0, from);
|
|
89
|
+
return order;
|
|
90
|
+
}
|
|
91
|
+
function rebuiltTable(block, plan) {
|
|
92
|
+
const regions = {};
|
|
93
|
+
for (let row = 0; row < plan.rows; row++) {
|
|
94
|
+
for (let col = 0; col < plan.cols; col++) {
|
|
95
|
+
const from = plan.source(row, col);
|
|
96
|
+
regions[_chunkND5XJVK2cjs.cellKey.call(void 0, row, col)] = from === null ? [] : _nullishCoalesce(block.regions[_chunkND5XJVK2cjs.cellKey.call(void 0, ...from)], () => ( []));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return { ...block, attrs: { ...block.attrs, ...plan.attrs, rows: plan.rows, cols: plan.cols }, regions };
|
|
100
|
+
}
|
|
101
|
+
function followedPos(pos, blockId, plan) {
|
|
102
|
+
const cell = pos.block === blockId ? cellOf(pos.region) : null;
|
|
103
|
+
if (cell === null) return pos;
|
|
104
|
+
const moved = plan.target(cell);
|
|
105
|
+
return moved === null ? { block: blockId, region: _chunkND5XJVK2cjs.cellKey.call(void 0, ...plan.landing(cell)), offset: 0 } : { ...pos, region: _chunkND5XJVK2cjs.cellKey.call(void 0, ...moved) };
|
|
106
|
+
}
|
|
107
|
+
function followedSelection(selection, blockId, plan) {
|
|
108
|
+
if (_optionalChain([selection, 'optionalAccess', _3 => _3.kind]) !== "text") return selection;
|
|
109
|
+
const anchor = followedPos(selection.anchor, blockId, plan);
|
|
110
|
+
const head = followedPos(selection.head, blockId, plan);
|
|
111
|
+
return anchor === selection.anchor && head === selection.head ? selection : _chunkPZ4GT5JOcjs.textSelection.call(void 0, anchor, head);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/engine/state/cell-selection.ts
|
|
115
|
+
var cellSelectionKey = _chunkPZ4GT5JOcjs.createPluginKey.call(void 0, "cellSelection");
|
|
116
|
+
function rangeOfSelection({ doc, selection }) {
|
|
117
|
+
if (_optionalChain([selection, 'optionalAccess', _4 => _4.kind]) !== "text") return null;
|
|
118
|
+
const { anchor, head } = selection;
|
|
119
|
+
if (anchor.block !== head.block || anchor.region === head.region || tableBlock(doc, anchor.block) === null) return null;
|
|
120
|
+
const from = cellOf(anchor.region);
|
|
121
|
+
const to = cellOf(head.region);
|
|
122
|
+
return from && to ? { block: anchor.block, anchor: from, head: to } : null;
|
|
123
|
+
}
|
|
124
|
+
var sameCell = (a, b) => a[0] === b[0] && a[1] === b[1];
|
|
125
|
+
var sameRange = (a, b) => a === b || a !== null && b !== null && a.block === b.block && sameCell(a.anchor, b.anchor) && sameCell(a.head, b.head);
|
|
126
|
+
var cellSelectionPlugin = {
|
|
127
|
+
key: cellSelectionKey,
|
|
128
|
+
init: rangeOfSelection,
|
|
129
|
+
apply(_tr, value, _old, next) {
|
|
130
|
+
const range = rangeOfSelection(next);
|
|
131
|
+
return sameRange(range, value) ? value : range;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
function cellSelection(state) {
|
|
135
|
+
const held = state.pluginState.get(cellSelectionKey.name);
|
|
136
|
+
return held === void 0 ? rangeOfSelection(state) : held;
|
|
137
|
+
}
|
|
138
|
+
var between = (value, a, b) => value >= Math.min(a, b) && value <= Math.max(a, b);
|
|
139
|
+
var rangeHasCell = ({ anchor, head }, [row, col]) => between(row, anchor[0], head[0]) && between(col, anchor[1], head[1]);
|
|
140
|
+
function cellsInRange({ anchor, head }) {
|
|
141
|
+
const cells = [];
|
|
142
|
+
for (let row = Math.min(anchor[0], head[0]); row <= Math.max(anchor[0], head[0]); row++) {
|
|
143
|
+
for (let col = Math.min(anchor[1], head[1]); col <= Math.max(anchor[1], head[1]); col++) cells.push([row, col]);
|
|
144
|
+
}
|
|
145
|
+
return cells;
|
|
146
|
+
}
|
|
147
|
+
function selectCells(blockId, anchor, head) {
|
|
148
|
+
return (state, dispatch) => {
|
|
149
|
+
const block = tableBlock(state.doc, blockId);
|
|
150
|
+
const { rows, cols } = block === null ? { rows: 0, cols: 0 } : tableShape(block);
|
|
151
|
+
const inside = ([row, col]) => isIndex(row, rows) && isIndex(col, cols);
|
|
152
|
+
if (block === null || !inside(anchor) || !inside(head)) return false;
|
|
153
|
+
const end2 = _chunkND5XJVK2cjs.cellKey.call(void 0, ...head);
|
|
154
|
+
const selection = _chunkPZ4GT5JOcjs.textSelection.call(void 0,
|
|
155
|
+
{ block: blockId, region: _chunkND5XJVK2cjs.cellKey.call(void 0, ...anchor), offset: 0 },
|
|
156
|
+
{ block: blockId, region: end2, offset: _chunkND5XJVK2cjs.inlineLength.call(void 0, _nullishCoalesce(block.regions[end2], () => ( []))) }
|
|
157
|
+
);
|
|
158
|
+
_optionalChain([dispatch, 'optionalCall', _5 => _5(new (0, _chunkPZ4GT5JOcjs.Transaction)(state).setSelection(selection))]);
|
|
159
|
+
return true;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/engine/commands/cell-commands.ts
|
|
164
|
+
function filledCells(doc, range) {
|
|
165
|
+
const regions = _nullishCoalesce(_optionalChain([_chunkND5XJVK2cjs.blockById.call(void 0, doc, range.block), 'optionalAccess', _6 => _6.regions]), () => ( {}));
|
|
166
|
+
return cellsInRange(range).flatMap((cell) => {
|
|
167
|
+
const region = _chunkND5XJVK2cjs.cellKey.call(void 0, ...cell);
|
|
168
|
+
const length = _chunkND5XJVK2cjs.inlineLength.call(void 0, _nullishCoalesce(regions[region], () => ( [])));
|
|
169
|
+
return length > 0 ? [{ region, length }] : [];
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function firstCell({ block, anchor, head }) {
|
|
173
|
+
return { block, region: _chunkND5XJVK2cjs.cellKey.call(void 0, Math.min(anchor[0], head[0]), Math.min(anchor[1], head[1])), offset: 0 };
|
|
174
|
+
}
|
|
175
|
+
function emptied(state, range) {
|
|
176
|
+
const tr = new (0, _chunkPZ4GT5JOcjs.Transaction)(state);
|
|
177
|
+
for (const { region, length } of filledCells(state.doc, range)) {
|
|
178
|
+
tr.step(_chunkPZ4GT5JOcjs.replaceInlineStep.call(void 0, range.block, region, 0, length, []));
|
|
179
|
+
}
|
|
180
|
+
return tr;
|
|
181
|
+
}
|
|
182
|
+
var deleteCellContents = (state, dispatch) => {
|
|
183
|
+
const range = cellSelection(state);
|
|
184
|
+
if (range === null) return false;
|
|
185
|
+
_optionalChain([dispatch, 'optionalCall', _7 => _7(emptied(state, range).setSelection(_chunkPZ4GT5JOcjs.textSelection.call(void 0, firstCell(range))))]);
|
|
186
|
+
return true;
|
|
187
|
+
};
|
|
188
|
+
function typeOverCells(text) {
|
|
189
|
+
return (state, dispatch) => {
|
|
190
|
+
const range = cellSelection(state);
|
|
191
|
+
if (range === null || text === "") return false;
|
|
192
|
+
const tr = emptied(state, range);
|
|
193
|
+
_optionalChain([dispatch, 'optionalCall', _8 => _8(tr.setSelection(_chunkPZ4GT5JOcjs.textSelection.call(void 0, _chunkPZ4GT5JOcjs.insertTextAt.call(void 0, tr, state.schema, firstCell(range), text))))]);
|
|
194
|
+
return true;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function setCellsMark(type, attrs) {
|
|
198
|
+
return (state, dispatch) => {
|
|
199
|
+
const range = cellSelection(state);
|
|
200
|
+
const cells = range === null ? [] : filledCells(state.doc, range);
|
|
201
|
+
const regions = range === null ? void 0 : _optionalChain([_chunkND5XJVK2cjs.blockById.call(void 0, state.doc, range.block), 'optionalAccess', _9 => _9.regions]);
|
|
202
|
+
if (range === null || regions === void 0 || cells.length === 0) return false;
|
|
203
|
+
const carried = cells.every(({ region }) => _chunkPZ4GT5JOcjs.markCoverage.call(void 0, regions[region], type, attrs).every);
|
|
204
|
+
const mark = carried ? _chunkPZ4GT5JOcjs.toggleMark.call(void 0, type, attrs) : _chunkPZ4GT5JOcjs.setMark.call(void 0, type, attrs);
|
|
205
|
+
const tr = new (0, _chunkPZ4GT5JOcjs.Transaction)(state);
|
|
206
|
+
for (const { region, length } of cells) {
|
|
207
|
+
const start = { block: range.block, region, offset: 0 };
|
|
208
|
+
const whole = _chunkPZ4GT5JOcjs.textSelection.call(void 0, start, { ...start, offset: length });
|
|
209
|
+
mark({ ...state, doc: tr.doc, selection: whole, storedMarks: null }, (cell) => {
|
|
210
|
+
for (const step of cell.steps) tr.step(step);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (!tr.docChanged) return false;
|
|
214
|
+
_optionalChain([dispatch, 'optionalCall', _10 => _10(tr)]);
|
|
215
|
+
return true;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/extensions/table/TableBlock.tsx
|
|
220
|
+
var _react = require('react');
|
|
221
|
+
|
|
222
|
+
// src/extensions/table/controls-slot.ts
|
|
223
|
+
var CONTROLS_SLOT = "data-quoin-table-controls";
|
|
224
|
+
var controlsSlot = (controller, blockId) => _nullishCoalesce(_optionalChain([controller, 'access', _11 => _11.blockElement, 'call', _12 => _12(blockId), 'optionalAccess', _13 => _13.querySelector, 'call', _14 => _14(`[${CONTROLS_SLOT}]`)]), () => ( null));
|
|
225
|
+
|
|
226
|
+
// src/extensions/table/TableCell.tsx
|
|
227
|
+
|
|
228
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
229
|
+
var TableCell = _react.memo.call(void 0, function TableCell2({ controller, blockId, row, col, header, align, label }) {
|
|
230
|
+
const inRange = _chunkGTTPVJSDcjs.useEditorState.call(void 0,
|
|
231
|
+
controller,
|
|
232
|
+
_react.useCallback.call(void 0,
|
|
233
|
+
(state) => {
|
|
234
|
+
const range = cellSelection(state);
|
|
235
|
+
return _optionalChain([range, 'optionalAccess', _15 => _15.block]) === blockId && rangeHasCell(range, [row, col]);
|
|
236
|
+
},
|
|
237
|
+
[blockId, row, col]
|
|
238
|
+
)
|
|
239
|
+
);
|
|
240
|
+
const Cell = header ? "th" : "td";
|
|
241
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
242
|
+
Cell,
|
|
243
|
+
{
|
|
244
|
+
scope: header ? "col" : void 0,
|
|
245
|
+
"data-row": row,
|
|
246
|
+
"data-col": col,
|
|
247
|
+
"data-in-range": inRange ? "" : void 0,
|
|
248
|
+
style: align === null ? void 0 : { textAlign: align },
|
|
249
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkGTTPVJSDcjs.EditableRegion, { block: blockId, region: _chunkND5XJVK2cjs.cellKey.call(void 0, row, col), label, className: "quoin-table-text" })
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// src/extensions/table/table-ui-store.ts
|
|
255
|
+
|
|
256
|
+
function createTableUiStore() {
|
|
257
|
+
let state = { preview: null };
|
|
258
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
259
|
+
return {
|
|
260
|
+
get: () => state,
|
|
261
|
+
set(patch) {
|
|
262
|
+
state = { ...state, ...patch };
|
|
263
|
+
for (const listener of [...listeners]) listener();
|
|
264
|
+
},
|
|
265
|
+
subscribe(listener) {
|
|
266
|
+
listeners.add(listener);
|
|
267
|
+
return () => void listeners.delete(listener);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
var stores = /* @__PURE__ */ new WeakMap();
|
|
272
|
+
function tableUiStore(controller) {
|
|
273
|
+
let store = stores.get(controller);
|
|
274
|
+
if (store === void 0) {
|
|
275
|
+
store = createTableUiStore();
|
|
276
|
+
stores.set(controller, store);
|
|
277
|
+
}
|
|
278
|
+
return store;
|
|
279
|
+
}
|
|
280
|
+
function useWidthPreview(controller, blockId) {
|
|
281
|
+
const store = tableUiStore(controller);
|
|
282
|
+
const read = _react.useCallback.call(void 0, () => {
|
|
283
|
+
const { preview } = store.get();
|
|
284
|
+
return _optionalChain([preview, 'optionalAccess', _16 => _16.block]) === blockId ? preview.widths : null;
|
|
285
|
+
}, [store, blockId]);
|
|
286
|
+
return _react.useSyncExternalStore.call(void 0, store.subscribe, read, read);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/extensions/table/use-cell-press.ts
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
// src/engine/commands/table-commands.ts
|
|
293
|
+
function changeTable(blockId, change, plan) {
|
|
294
|
+
return (state, dispatch) => {
|
|
295
|
+
const block = tableBlock(state.doc, blockId);
|
|
296
|
+
const next = block && change(block);
|
|
297
|
+
if (!next) return false;
|
|
298
|
+
const tr = new (0, _chunkPZ4GT5JOcjs.Transaction)(state).step(_chunkPZ4GT5JOcjs.replaceBlockStep.call(void 0, next));
|
|
299
|
+
_optionalChain([dispatch, 'optionalCall', _17 => _17(plan ? tr.setSelection(followedSelection(state.selection, blockId, plan)) : tr)]);
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function reshape(blockId, plan) {
|
|
304
|
+
return (state, dispatch) => {
|
|
305
|
+
const block = tableBlock(state.doc, blockId);
|
|
306
|
+
const made = block && plan(block, tableShape(block));
|
|
307
|
+
return made ? changeTable(blockId, (table) => rebuiltTable(table, made), made)(state, dispatch) : false;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function spliced(list, index, remove, ...insert) {
|
|
311
|
+
const copy = [...list];
|
|
312
|
+
copy.splice(index, remove, ...insert);
|
|
313
|
+
return copy;
|
|
314
|
+
}
|
|
315
|
+
var reordered = (list, order) => order.map((i) => list[i]);
|
|
316
|
+
var columnAttrs = (align, widths) => widths === null ? { align } : { align, widths };
|
|
317
|
+
var addRow = (blockId, index) => reshape(
|
|
318
|
+
blockId,
|
|
319
|
+
(_, { rows, cols }) => isIndex(index, rows + 1) ? {
|
|
320
|
+
rows: rows + 1,
|
|
321
|
+
cols,
|
|
322
|
+
source: (row, col) => row === index ? null : [row < index ? row : row - 1, col],
|
|
323
|
+
target: ([row, col]) => [row < index ? row : row + 1, col],
|
|
324
|
+
landing: (cell) => cell
|
|
325
|
+
} : null
|
|
326
|
+
);
|
|
327
|
+
var removeRow = (blockId, index) => reshape(
|
|
328
|
+
blockId,
|
|
329
|
+
(_, { rows, cols }) => isIndex(index, rows) && rows > 1 ? {
|
|
330
|
+
rows: rows - 1,
|
|
331
|
+
cols,
|
|
332
|
+
source: (row, col) => [row < index ? row : row + 1, col],
|
|
333
|
+
target: ([row, col]) => row === index ? null : [row < index ? row : row - 1, col],
|
|
334
|
+
landing: ([, col]) => [Math.min(index, rows - 2), col]
|
|
335
|
+
} : null
|
|
336
|
+
);
|
|
337
|
+
var moveRow = (blockId, from, to) => reshape(blockId, (_, { rows, cols }) => {
|
|
338
|
+
if (!isIndex(from, rows) || !isIndex(to, rows) || from === to) return null;
|
|
339
|
+
const order = movedOrder(rows, from, to);
|
|
340
|
+
return {
|
|
341
|
+
rows,
|
|
342
|
+
cols,
|
|
343
|
+
source: (row, col) => [order[row], col],
|
|
344
|
+
target: ([row, col]) => [order.indexOf(row), col],
|
|
345
|
+
landing: (cell) => cell
|
|
346
|
+
};
|
|
347
|
+
});
|
|
348
|
+
var addColumn = (blockId, index) => reshape(blockId, (block, { rows, cols }) => {
|
|
349
|
+
if (!isIndex(index, cols + 1)) return null;
|
|
350
|
+
const widths = storedWidths(block, cols);
|
|
351
|
+
return {
|
|
352
|
+
rows,
|
|
353
|
+
cols: cols + 1,
|
|
354
|
+
source: (row, col) => col === index ? null : [row, col < index ? col : col - 1],
|
|
355
|
+
target: ([row, col]) => [row, col < index ? col : col + 1],
|
|
356
|
+
landing: (cell) => cell,
|
|
357
|
+
attrs: columnAttrs(
|
|
358
|
+
spliced(columnAligns(block, cols), index, 0, null),
|
|
359
|
+
widths && spliced(widths, index, 0, widths[Math.max(index - 1, 0)])
|
|
360
|
+
)
|
|
361
|
+
};
|
|
362
|
+
});
|
|
363
|
+
var removeColumn = (blockId, index) => reshape(blockId, (block, { rows, cols }) => {
|
|
364
|
+
if (!isIndex(index, cols) || cols < 2) return null;
|
|
365
|
+
const widths = storedWidths(block, cols);
|
|
366
|
+
return {
|
|
367
|
+
rows,
|
|
368
|
+
cols: cols - 1,
|
|
369
|
+
source: (row, col) => [row, col < index ? col : col + 1],
|
|
370
|
+
target: ([row, col]) => col === index ? null : [row, col < index ? col : col - 1],
|
|
371
|
+
landing: ([row]) => [row, Math.min(index, cols - 2)],
|
|
372
|
+
attrs: columnAttrs(spliced(columnAligns(block, cols), index, 1), widths && spliced(widths, index, 1))
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
var moveColumn = (blockId, from, to) => reshape(blockId, (block, { rows, cols }) => {
|
|
376
|
+
if (!isIndex(from, cols) || !isIndex(to, cols) || from === to) return null;
|
|
377
|
+
const order = movedOrder(cols, from, to);
|
|
378
|
+
const widths = storedWidths(block, cols);
|
|
379
|
+
return {
|
|
380
|
+
rows,
|
|
381
|
+
cols,
|
|
382
|
+
source: (row, col) => [row, order[col]],
|
|
383
|
+
target: ([row, col]) => [row, order.indexOf(col)],
|
|
384
|
+
landing: (cell) => cell,
|
|
385
|
+
attrs: columnAttrs(reordered(columnAligns(block, cols), order), widths && reordered(widths, order))
|
|
386
|
+
};
|
|
387
|
+
});
|
|
388
|
+
var toggleHeaderRow = (blockId) => changeTable(blockId, (block) => ({ ...block, attrs: { ...block.attrs, header: block.attrs.header === false } }));
|
|
389
|
+
var withAttrs = (block, attrs) => ({ ...block, attrs: { ...block.attrs, ...attrs } });
|
|
390
|
+
var setColumnAlign = (blockId, col, align) => changeTable(blockId, (block) => {
|
|
391
|
+
const aligns = columnAligns(block, tableShape(block).cols);
|
|
392
|
+
if (!isIndex(col, aligns.length) || aligns[col] === align) return null;
|
|
393
|
+
return withAttrs(block, { align: spliced(aligns, col, 1, align) });
|
|
394
|
+
});
|
|
395
|
+
var DEFAULT_COLUMN_WIDTH = 120;
|
|
396
|
+
var setColumnWidth = (blockId, col, px, drawn) => changeTable(blockId, (block) => {
|
|
397
|
+
const { cols } = tableShape(block);
|
|
398
|
+
const width = Math.round(px);
|
|
399
|
+
if (!isIndex(col, cols) || !(width > 0)) return null;
|
|
400
|
+
const stored = storedWidths(block, cols);
|
|
401
|
+
if (_optionalChain([stored, 'optionalAccess', _18 => _18[col]]) === width) return null;
|
|
402
|
+
const measured = drawn && validWidths(drawn.map(Math.round), cols);
|
|
403
|
+
const widths = _nullishCoalesce(_nullishCoalesce(stored, () => ( measured)), () => ( Array(cols).fill(DEFAULT_COLUMN_WIDTH)));
|
|
404
|
+
return withAttrs(block, { widths: spliced(widths, col, 1, width) });
|
|
405
|
+
});
|
|
406
|
+
var isCount = (value) => Number.isInteger(value) && value > 0;
|
|
407
|
+
function emptyCells({ rows, cols }) {
|
|
408
|
+
const regions = {};
|
|
409
|
+
for (let row = 0; row < rows; row++) for (let col = 0; col < cols; col++) regions[_chunkND5XJVK2cjs.cellKey.call(void 0, row, col)] = [];
|
|
410
|
+
return regions;
|
|
411
|
+
}
|
|
412
|
+
function insertTable(rows, cols, options = {}) {
|
|
413
|
+
return (state, dispatch) => {
|
|
414
|
+
const { doc, schema } = state;
|
|
415
|
+
const id = _chunkPZ4GT5JOcjs.headBlockId.call(void 0, state.selection);
|
|
416
|
+
if (id === null || !isCount(rows) || !isCount(cols)) return false;
|
|
417
|
+
const index = _chunkND5XJVK2cjs.requireBlockIndex.call(void 0, doc, id);
|
|
418
|
+
const current = doc.blocks[index];
|
|
419
|
+
const fills = _chunkPZ4GT5JOcjs.isParagraph.call(void 0, current) && _chunkPZ4GT5JOcjs.regionLength.call(void 0, current, _nullishCoalesce(_chunkPZ4GT5JOcjs.primaryRegion.call(void 0, schema, current), () => ( ""))) === 0;
|
|
420
|
+
const table = {
|
|
421
|
+
id: fills ? current.id : (_nullishCoalesce(options.newId, () => ( (0, _chunkND5XJVK2cjs.newId))))(),
|
|
422
|
+
type: "TABLE",
|
|
423
|
+
indent: current.indent,
|
|
424
|
+
attrs: { header: true, align: Array.from({ length: cols }, () => null), rows, cols },
|
|
425
|
+
regions: emptyCells({ rows, cols })
|
|
426
|
+
};
|
|
427
|
+
const tr = new (0, _chunkPZ4GT5JOcjs.Transaction)(state).step(
|
|
428
|
+
fills ? _chunkPZ4GT5JOcjs.replaceBlockStep.call(void 0, table) : _chunkPZ4GT5JOcjs.insertBlocksStep.call(void 0, _chunkPZ4GT5JOcjs.descendantsEnd.call(void 0, doc, index), [table])
|
|
429
|
+
);
|
|
430
|
+
_optionalChain([dispatch, 'optionalCall', _19 => _19(tr.setSelection(_chunkPZ4GT5JOcjs.textSelection.call(void 0, { block: table.id, region: _chunkND5XJVK2cjs.cellKey.call(void 0, 0, 0), offset: 0 })))]);
|
|
431
|
+
return true;
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/extensions/table/table-keys.ts
|
|
436
|
+
function headCell({ doc, selection }) {
|
|
437
|
+
if (_optionalChain([selection, 'optionalAccess', _20 => _20.kind]) !== "text") return null;
|
|
438
|
+
const { head } = selection;
|
|
439
|
+
const block = tableBlock(doc, head.block);
|
|
440
|
+
const cell = block && cellOf(head.region);
|
|
441
|
+
return block && cell ? { block, cell, head, shape: tableShape(block) } : null;
|
|
442
|
+
}
|
|
443
|
+
var cellLength = (block, [row, col]) => _chunkND5XJVK2cjs.inlineLength.call(void 0, _nullishCoalesce(block.regions[_chunkND5XJVK2cjs.cellKey.call(void 0, row, col)], () => ( [])));
|
|
444
|
+
var cellPos = (block, cell, atEnd = false) => ({
|
|
445
|
+
block: block.id,
|
|
446
|
+
region: _chunkND5XJVK2cjs.cellKey.call(void 0, ...cell),
|
|
447
|
+
offset: atEnd ? cellLength(block, cell) : 0
|
|
448
|
+
});
|
|
449
|
+
var moveTo = (state, pos) => new (0, _chunkPZ4GT5JOcjs.Transaction)(state).setSelection(_chunkPZ4GT5JOcjs.textSelection.call(void 0, pos));
|
|
450
|
+
var thenCaretIn = (command, blockId, at) => (state, dispatch) => {
|
|
451
|
+
const caret = _chunkPZ4GT5JOcjs.textSelection.call(void 0, { block: blockId, region: _chunkND5XJVK2cjs.cellKey.call(void 0, ...at), offset: 0 });
|
|
452
|
+
return command(state, dispatch && ((tr) => dispatch(tr.setSelection(caret))));
|
|
453
|
+
};
|
|
454
|
+
var cellAtIndex = (index, { cols }) => [Math.floor(index / cols), index % cols];
|
|
455
|
+
var indexOfCell = ([row, col], { cols }) => row * cols + col;
|
|
456
|
+
var nextCell = (state, dispatch) => {
|
|
457
|
+
const caret = headCell(state);
|
|
458
|
+
if (caret === null) return false;
|
|
459
|
+
const { block, cell, shape } = caret;
|
|
460
|
+
const next = indexOfCell(cell, shape) + 1;
|
|
461
|
+
if (next === shape.rows * shape.cols) {
|
|
462
|
+
return thenCaretIn(addRow(block.id, shape.rows), block.id, [shape.rows, 0])(state, dispatch);
|
|
463
|
+
}
|
|
464
|
+
_optionalChain([dispatch, 'optionalCall', _21 => _21(moveTo(state, cellPos(block, cellAtIndex(next, shape), true)))]);
|
|
465
|
+
return true;
|
|
466
|
+
};
|
|
467
|
+
var previousCell = (state, dispatch) => {
|
|
468
|
+
const caret = headCell(state);
|
|
469
|
+
if (caret === null) return false;
|
|
470
|
+
const { block, cell, shape } = caret;
|
|
471
|
+
const previous = indexOfCell(cell, shape) - 1;
|
|
472
|
+
if (previous >= 0) _optionalChain([dispatch, 'optionalCall', _22 => _22(moveTo(state, cellPos(block, cellAtIndex(previous, shape), true)))]);
|
|
473
|
+
return true;
|
|
474
|
+
};
|
|
475
|
+
var enterInCell = (state, dispatch) => {
|
|
476
|
+
const caret = headCell(state);
|
|
477
|
+
if (caret === null) return false;
|
|
478
|
+
if (cellSelection(state) !== null) return true;
|
|
479
|
+
const { block, cell, shape } = caret;
|
|
480
|
+
const [row, col] = cell;
|
|
481
|
+
if (row === shape.rows - 1 && cellLength(block, cell) === 0) {
|
|
482
|
+
return thenCaretIn(addRow(block.id, shape.rows), block.id, [shape.rows, col])(state, dispatch);
|
|
483
|
+
}
|
|
484
|
+
return _chunkPZ4GT5JOcjs.insertHardBreak.call(void 0, state, dispatch);
|
|
485
|
+
};
|
|
486
|
+
var stopAtCellEdge = (atEnd) => (state) => {
|
|
487
|
+
const caret = headCell(state);
|
|
488
|
+
if (caret === null || !_chunkPZ4GT5JOcjs.isCollapsed.call(void 0, state.selection)) return false;
|
|
489
|
+
return caret.head.offset === (atEnd ? cellLength(caret.block, caret.cell) : 0);
|
|
490
|
+
};
|
|
491
|
+
var firstThatApplies = (...commands) => (state, dispatch) => commands.some((command) => command(state, dispatch));
|
|
492
|
+
var MARK_KEYS = {
|
|
493
|
+
"Mod-b": "bold",
|
|
494
|
+
"Mod-i": "italic",
|
|
495
|
+
"Mod-u": "underline",
|
|
496
|
+
"Mod-Shift-s": "strike",
|
|
497
|
+
"Mod-e": "code",
|
|
498
|
+
"Mod-Shift-h": "highlight"
|
|
499
|
+
};
|
|
500
|
+
var tableKeymap = {
|
|
501
|
+
Tab: nextCell,
|
|
502
|
+
"Shift-Tab": previousCell,
|
|
503
|
+
Enter: enterInCell,
|
|
504
|
+
Backspace: firstThatApplies(deleteCellContents, stopAtCellEdge(false)),
|
|
505
|
+
Delete: firstThatApplies(deleteCellContents, stopAtCellEdge(true)),
|
|
506
|
+
...Object.fromEntries(Object.entries(MARK_KEYS).map(([name, mark]) => [name, setCellsMark(mark)]))
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// src/extensions/table/use-cell-press.ts
|
|
510
|
+
function cellOf2(element) {
|
|
511
|
+
const row = element.getAttribute("data-row");
|
|
512
|
+
const col = element.getAttribute("data-col");
|
|
513
|
+
return element.matches("td, th") && row !== null && col !== null ? [Number(row), Number(col)] : null;
|
|
514
|
+
}
|
|
515
|
+
function useCellPress(controller, blockId, table, editable) {
|
|
516
|
+
_react.useEffect.call(void 0, () => {
|
|
517
|
+
const element = table.current;
|
|
518
|
+
if (!editable || element === null) return;
|
|
519
|
+
const onPointerDown = (event) => {
|
|
520
|
+
const cell = event.button === 0 && event.pointerType !== "touch" ? cellOf2(event.target) : null;
|
|
521
|
+
const block = cell && _chunkND5XJVK2cjs.blockById.call(void 0, controller.editor.state.doc, blockId);
|
|
522
|
+
if (!cell || !block) return;
|
|
523
|
+
event.preventDefault();
|
|
524
|
+
event.stopPropagation();
|
|
525
|
+
controller.focus(cellPos(block, cell, true));
|
|
526
|
+
};
|
|
527
|
+
element.addEventListener("pointerdown", onPointerDown);
|
|
528
|
+
return () => element.removeEventListener("pointerdown", onPointerDown);
|
|
529
|
+
}, [controller, blockId, table, editable]);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// src/extensions/table/use-reveal-cell.ts
|
|
533
|
+
|
|
534
|
+
function useRevealCell(controller, blockId) {
|
|
535
|
+
const region = _chunkGTTPVJSDcjs.useEditorState.call(void 0,
|
|
536
|
+
controller,
|
|
537
|
+
_react.useCallback.call(void 0,
|
|
538
|
+
(state) => {
|
|
539
|
+
const caret = headCell(state);
|
|
540
|
+
return _optionalChain([caret, 'optionalAccess', _23 => _23.block, 'access', _24 => _24.id]) === blockId ? caret.head.region : null;
|
|
541
|
+
},
|
|
542
|
+
[blockId]
|
|
543
|
+
)
|
|
544
|
+
);
|
|
545
|
+
_react.useEffect.call(void 0, () => {
|
|
546
|
+
const host = region === null ? void 0 : controller.registry.get(blockId, region);
|
|
547
|
+
const root = controller.root;
|
|
548
|
+
if (!host || !_optionalChain([root, 'optionalAccess', _25 => _25.contains, 'call', _26 => _26(root.ownerDocument.activeElement)])) return;
|
|
549
|
+
_optionalChain([host, 'access', _27 => _27.closest, 'call', _28 => _28("td, th"), 'optionalAccess', _29 => _29.scrollIntoView, 'call', _30 => _30({ block: "nearest", inline: "nearest" })]);
|
|
550
|
+
}, [controller, blockId, region]);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/extensions/table/use-table-keys.ts
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
// src/extensions/table/vertical-cell-move.ts
|
|
557
|
+
var VERTICAL = { ArrowUp: -1, ArrowDown: 1 };
|
|
558
|
+
function caretAtGoal(controller, blockId, cell, direction) {
|
|
559
|
+
const region = _chunkND5XJVK2cjs.cellKey.call(void 0, ...cell);
|
|
560
|
+
const host = controller.registry.get(blockId, region);
|
|
561
|
+
const { goalX } = controller;
|
|
562
|
+
const line = host && _chunkGTTPVJSDcjs.lineEdgeRect.call(void 0, host, direction < 0);
|
|
563
|
+
if (!host || !line || goalX === null) return null;
|
|
564
|
+
const box = host.getBoundingClientRect();
|
|
565
|
+
const x = Math.min(Math.max(goalX, box.left), box.right - 1);
|
|
566
|
+
const point = _chunkGTTPVJSDcjs.caretFromPoint.call(void 0, host.ownerDocument, x, line.top + line.height / 2);
|
|
567
|
+
const pos = point && _chunkGTTPVJSDcjs.domToPos.call(void 0, controller.registry, point.node, point.offset);
|
|
568
|
+
return pos && pos.block === blockId && pos.region === region ? pos : null;
|
|
569
|
+
}
|
|
570
|
+
var plainArrow = (event) => event.altKey || event.ctrlKey || event.metaKey ? void 0 : VERTICAL[event.key];
|
|
571
|
+
function caretOnEdgeLine(controller, head, direction) {
|
|
572
|
+
const host = controller.registry.get(head.block, head.region);
|
|
573
|
+
const point = _chunkGTTPVJSDcjs.posToDom.call(void 0, controller.registry, head);
|
|
574
|
+
if (!host || !point || !(direction < 0 ? _chunkGTTPVJSDcjs.isOnFirstLine.call(void 0, host, point) : _chunkGTTPVJSDcjs.isOnLastLine.call(void 0, host, point))) return null;
|
|
575
|
+
return { left: _nullishCoalesce(_optionalChain([_chunkGTTPVJSDcjs.caretClientRect.call(void 0, point), 'optionalAccess', _31 => _31.left]), () => ( null)) };
|
|
576
|
+
}
|
|
577
|
+
function columnAt(controller, blockId, row, x) {
|
|
578
|
+
const cells = Array.from(_nullishCoalesce(_optionalChain([controller, 'access', _32 => _32.blockElement, 'call', _33 => _33(blockId), 'optionalAccess', _34 => _34.querySelector, 'call', _35 => _35("table"), 'optionalAccess', _36 => _36.rows, 'access', _37 => _37[row], 'optionalAccess', _38 => _38.cells]), () => ( [])));
|
|
579
|
+
const index = cells.findIndex((cell) => x < cell.getBoundingClientRect().right);
|
|
580
|
+
return index === -1 ? Math.max(cells.length - 1, 0) : index;
|
|
581
|
+
}
|
|
582
|
+
function enterTable(controller, blockId, event) {
|
|
583
|
+
const direction = plainArrow(event);
|
|
584
|
+
const { state } = controller.editor;
|
|
585
|
+
const { selection } = state;
|
|
586
|
+
const block = tableBlock(state.doc, blockId);
|
|
587
|
+
if (direction === void 0 || event.shiftKey || block === null || _optionalChain([selection, 'optionalAccess', _39 => _39.kind]) !== "text") return false;
|
|
588
|
+
if (!_chunkPZ4GT5JOcjs.isCollapsed.call(void 0, selection) || _optionalChain([_chunkGTTPVJSDcjs.neighbourBlock.call(void 0, state.doc, selection.head.block, direction), 'optionalAccess', _40 => _40.id]) !== blockId) return false;
|
|
589
|
+
const caret = caretOnEdgeLine(controller, selection.head, direction);
|
|
590
|
+
if (caret === null) return false;
|
|
591
|
+
controller.goalX ??= caret.left;
|
|
592
|
+
const { rows, cols } = tableShape(block);
|
|
593
|
+
const row = direction > 0 ? 0 : rows - 1;
|
|
594
|
+
const { goalX } = controller;
|
|
595
|
+
const cell = [row, goalX === null ? direction > 0 ? 0 : cols - 1 : columnAt(controller, blockId, row, goalX)];
|
|
596
|
+
const pos = _nullishCoalesce(caretAtGoal(controller, blockId, cell, direction), () => ( cellPos(block, cell, direction < 0)));
|
|
597
|
+
controller.dispatch(controller.editor.createTransaction().setSelection(_chunkPZ4GT5JOcjs.textSelection.call(void 0, pos)));
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
function moveBetweenRows(controller, blockId, event) {
|
|
601
|
+
const direction = plainArrow(event);
|
|
602
|
+
const { state } = controller.editor;
|
|
603
|
+
const caret = headCell(state);
|
|
604
|
+
if (direction === void 0 || caret === null || caret.block.id !== blockId || _optionalChain([state, 'access', _41 => _41.selection, 'optionalAccess', _42 => _42.kind]) !== "text") {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
const target = [caret.cell[0] + direction, caret.cell[1]];
|
|
608
|
+
if (target[0] < 0 || target[0] >= caret.shape.rows) return false;
|
|
609
|
+
const edge = caretOnEdgeLine(controller, caret.head, direction);
|
|
610
|
+
if (edge === null) return false;
|
|
611
|
+
controller.goalX ??= edge.left;
|
|
612
|
+
const pos = _nullishCoalesce(caretAtGoal(controller, blockId, target, direction), () => ( cellPos(caret.block, target, direction < 0)));
|
|
613
|
+
const selection = event.shiftKey ? _chunkPZ4GT5JOcjs.textSelection.call(void 0, state.selection.anchor, pos) : _chunkPZ4GT5JOcjs.textSelection.call(void 0, pos);
|
|
614
|
+
controller.dispatch(controller.editor.createTransaction().setSelection(selection));
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/extensions/table/use-table-keys.ts
|
|
619
|
+
var printable = (event) => [...event.key].length === 1 && !event.ctrlKey && !event.metaKey;
|
|
620
|
+
function typeOver(controller, blockId, event) {
|
|
621
|
+
if (_optionalChain([cellSelection, 'call', _43 => _43(controller.editor.state), 'optionalAccess', _44 => _44.block]) !== blockId || !printable(event)) return false;
|
|
622
|
+
return controller.run(typeOverCells(event.key));
|
|
623
|
+
}
|
|
624
|
+
function useTableKeys(controller, blockId, editable) {
|
|
625
|
+
_react.useEffect.call(void 0, () => {
|
|
626
|
+
if (!editable) return;
|
|
627
|
+
const intercept = (event) => {
|
|
628
|
+
if (_chunkGTTPVJSDcjs.isComposingKey.call(void 0, controller, event)) return false;
|
|
629
|
+
const handled = typeOver(controller, blockId, event) || moveBetweenRows(controller, blockId, event) || enterTable(controller, blockId, event);
|
|
630
|
+
if (handled) event.preventDefault();
|
|
631
|
+
return handled;
|
|
632
|
+
};
|
|
633
|
+
return _chunk2VDK27IFcjs.interceptKeys.call(void 0, controller, intercept);
|
|
634
|
+
}, [controller, blockId, editable]);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// src/extensions/table/TableBlock.tsx
|
|
638
|
+
|
|
639
|
+
var indexes = (from, to) => Array.from({ length: Math.max(to - from, 0) }, (_, i) => from + i);
|
|
640
|
+
function TableBlock({ block, controller, labels }) {
|
|
641
|
+
const readOnly = _chunkGTTPVJSDcjs.useReadOnly.call(void 0, controller);
|
|
642
|
+
const table = _react.useRef.call(void 0, null);
|
|
643
|
+
const { rows, cols } = tableShape(block);
|
|
644
|
+
const header = block.attrs.header !== false && rows > 0;
|
|
645
|
+
const aligns = columnAligns(block, cols);
|
|
646
|
+
const preview = useWidthPreview(controller, block.id);
|
|
647
|
+
const widths = _optionalChain([preview, 'optionalAccess', _45 => _45.length]) === cols ? preview : storedWidths(block, cols);
|
|
648
|
+
useTableKeys(controller, block.id, !readOnly);
|
|
649
|
+
useCellPress(controller, block.id, table, !readOnly);
|
|
650
|
+
useRevealCell(controller, block.id);
|
|
651
|
+
const row = (index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: indexes(0, cols).map((col) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
652
|
+
TableCell,
|
|
653
|
+
{
|
|
654
|
+
controller,
|
|
655
|
+
blockId: block.id,
|
|
656
|
+
row: index,
|
|
657
|
+
col,
|
|
658
|
+
header: header && index === 0,
|
|
659
|
+
align: aligns[col],
|
|
660
|
+
label: labels.cell(index + 1, col + 1)
|
|
661
|
+
},
|
|
662
|
+
col
|
|
663
|
+
)) }, index);
|
|
664
|
+
const scroller = readOnly ? { role: "region", "aria-label": labels.table, tabIndex: 0 } : void 0;
|
|
665
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { contentEditable: false, className: "quoin-table", "data-readonly": readOnly ? "" : void 0, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: `quoin-table-scroll ${readOnly ? _chunk2VDK27IFcjs.FOCUS_RING : ""}`, ...scroller, children: [
|
|
666
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
667
|
+
"table",
|
|
668
|
+
{
|
|
669
|
+
ref: table,
|
|
670
|
+
"aria-label": readOnly ? void 0 : labels.table,
|
|
671
|
+
style: widths === null ? void 0 : { width: widths.reduce((sum, width) => sum + width, 0), tableLayout: "fixed" },
|
|
672
|
+
children: [
|
|
673
|
+
widths !== null && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "colgroup", { children: widths.map((width, col) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "col", { style: { width } }, col)) }),
|
|
674
|
+
header && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "thead", { children: row(0) }),
|
|
675
|
+
rows > (header ? 1 : 0) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tbody", { children: indexes(header ? 1 : 0, rows).map(row) })
|
|
676
|
+
]
|
|
677
|
+
}
|
|
678
|
+
),
|
|
679
|
+
!readOnly && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "quoin-table-controls", ...{ [CONTROLS_SLOT]: "" } })
|
|
680
|
+
] }) });
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// src/extensions/table/TableControls.tsx
|
|
684
|
+
|
|
685
|
+
var _reactdom = require('react-dom');
|
|
686
|
+
|
|
687
|
+
// src/extensions/table/menu-cells.ts
|
|
688
|
+
var EMPTY = [];
|
|
689
|
+
function menuCells(block, target, axis) {
|
|
690
|
+
const { rows, cols } = tableShape(block);
|
|
691
|
+
const row = Math.min(target.row, rows - 1);
|
|
692
|
+
const col = Math.min(target.col, cols - 1);
|
|
693
|
+
return Array.from(
|
|
694
|
+
{ length: axis === "row" ? cols : rows },
|
|
695
|
+
(_, index) => axis === "row" ? _nullishCoalesce(block.regions[_chunkND5XJVK2cjs.cellKey.call(void 0, row, index)], () => ( EMPTY)) : _nullishCoalesce(block.regions[_chunkND5XJVK2cjs.cellKey.call(void 0, index, col)], () => ( EMPTY))
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
function sameMenuCells(opened, current, target, axis) {
|
|
699
|
+
const before = menuCells(opened, target, axis);
|
|
700
|
+
const after = menuCells(current, target, axis);
|
|
701
|
+
return before.length === after.length && before.every((cell, index) => _chunkND5XJVK2cjs.equalInline.call(void 0, cell, after[index]));
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// src/extensions/table/TableHandles.tsx
|
|
705
|
+
|
|
706
|
+
var _lucidereact = require('lucide-react');
|
|
707
|
+
|
|
708
|
+
// src/extensions/table/ColumnResizer.tsx
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
var MIN_COLUMN_WIDTH = 48;
|
|
712
|
+
var MAX_COLUMN_WIDTH = 1200;
|
|
713
|
+
var STEP = 10;
|
|
714
|
+
var LARGE_STEP = 50;
|
|
715
|
+
var clampWidth = (px) => Math.min(MAX_COLUMN_WIDTH, Math.max(MIN_COLUMN_WIDTH, Math.round(px)));
|
|
716
|
+
function ColumnResizer(props) {
|
|
717
|
+
const { controller, labels, blockId, col, drawn, style, resizerRef, onHold, onBack } = props;
|
|
718
|
+
const drag = _react.useRef.call(void 0, null);
|
|
719
|
+
const width = Math.round(_nullishCoalesce(drawn[col], () => ( 0)));
|
|
720
|
+
const store = tableUiStore(controller);
|
|
721
|
+
const write = (px, widths) => {
|
|
722
|
+
if (!controller.readOnly) controller.run(setColumnWidth(blockId, col, px, widths));
|
|
723
|
+
};
|
|
724
|
+
const onKeyDown = (event) => {
|
|
725
|
+
if (_chunkGTTPVJSDcjs.isComposingKey.call(void 0, controller, event.nativeEvent)) return;
|
|
726
|
+
const step = event.shiftKey ? LARGE_STEP : STEP;
|
|
727
|
+
const tab = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
728
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
729
|
+
const next = clampWidth(width + (event.key === "ArrowLeft" ? -step : step));
|
|
730
|
+
if (next !== width) write(next, drawn);
|
|
731
|
+
} else if (tab && event.shiftKey) onBack();
|
|
732
|
+
else if (tab || event.key === "Escape") controller.focus();
|
|
733
|
+
else return;
|
|
734
|
+
event.preventDefault();
|
|
735
|
+
};
|
|
736
|
+
const onPointerDown = (event) => {
|
|
737
|
+
if (event.button !== 0) return;
|
|
738
|
+
_optionalChain([event, 'access', _46 => _46.currentTarget, 'access', _47 => _47.setPointerCapture, 'optionalCall', _48 => _48(event.pointerId)]);
|
|
739
|
+
drag.current = { x: event.clientX, widths: [...drawn], to: null };
|
|
740
|
+
onHold(true);
|
|
741
|
+
};
|
|
742
|
+
const onPointerMove = (event) => {
|
|
743
|
+
const current = drag.current;
|
|
744
|
+
if (current === null) return;
|
|
745
|
+
current.to = clampWidth(current.widths[col] + event.clientX - current.x);
|
|
746
|
+
const widths = current.widths.map((px, i) => i === col ? _nullishCoalesce(current.to, () => ( px)) : px);
|
|
747
|
+
store.set({ preview: { block: blockId, widths } });
|
|
748
|
+
};
|
|
749
|
+
const stop = () => {
|
|
750
|
+
const current = drag.current;
|
|
751
|
+
drag.current = null;
|
|
752
|
+
store.set({ preview: null });
|
|
753
|
+
onHold(false);
|
|
754
|
+
return current;
|
|
755
|
+
};
|
|
756
|
+
_react.useEffect.call(void 0,
|
|
757
|
+
() => () => {
|
|
758
|
+
if (drag.current !== null) store.set({ preview: null });
|
|
759
|
+
},
|
|
760
|
+
[store]
|
|
761
|
+
);
|
|
762
|
+
const end2 = () => {
|
|
763
|
+
const ended = stop();
|
|
764
|
+
if (_optionalChain([ended, 'optionalAccess', _49 => _49.to]) != null && ended.to !== Math.round(ended.widths[col])) write(ended.to, ended.widths);
|
|
765
|
+
};
|
|
766
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
767
|
+
"div",
|
|
768
|
+
{
|
|
769
|
+
ref: resizerRef,
|
|
770
|
+
role: "separator",
|
|
771
|
+
tabIndex: -1,
|
|
772
|
+
"aria-orientation": "vertical",
|
|
773
|
+
"aria-label": labels.resizeColumn(col + 1),
|
|
774
|
+
"aria-valuenow": width,
|
|
775
|
+
"aria-valuemin": MIN_COLUMN_WIDTH,
|
|
776
|
+
"aria-valuemax": MAX_COLUMN_WIDTH,
|
|
777
|
+
"aria-valuetext": labels.columnWidth(width),
|
|
778
|
+
className: "quoin-table-resizer",
|
|
779
|
+
style,
|
|
780
|
+
...{ [_chunkGTTPVJSDcjs.NATIVE_INTERACTION]: "" },
|
|
781
|
+
onKeyDown,
|
|
782
|
+
onPointerDown,
|
|
783
|
+
onPointerMove,
|
|
784
|
+
onPointerUp: end2,
|
|
785
|
+
onPointerCancel: stop
|
|
786
|
+
}
|
|
787
|
+
);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/extensions/table/HandleMenu.tsx
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
var DESTRUCTIVE = "text-destructive focus:text-destructive";
|
|
795
|
+
function HandleMenu({ controller, axis, label, style, items, open, onOpenChange, buttonRef, children }) {
|
|
796
|
+
const run = (item3) => {
|
|
797
|
+
if (controller.run(item3.command)) controller.announce(item3.done);
|
|
798
|
+
};
|
|
799
|
+
const item2 = (entry) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
800
|
+
_chunk2VDK27IFcjs.DropdownMenuItem,
|
|
801
|
+
{
|
|
802
|
+
disabled: entry.disabled,
|
|
803
|
+
className: entry.destructive ? DESTRUCTIVE : void 0,
|
|
804
|
+
onSelect: () => run(entry),
|
|
805
|
+
children: [
|
|
806
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.MenuIcon, { icon: entry.icon }),
|
|
807
|
+
entry.label
|
|
808
|
+
]
|
|
809
|
+
},
|
|
810
|
+
entry.id
|
|
811
|
+
);
|
|
812
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunk2VDK27IFcjs.DropdownMenu, { open, onOpenChange, children: [
|
|
813
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
814
|
+
"button",
|
|
815
|
+
{
|
|
816
|
+
ref: buttonRef,
|
|
817
|
+
type: "button",
|
|
818
|
+
tabIndex: -1,
|
|
819
|
+
"aria-label": label,
|
|
820
|
+
"data-axis": axis,
|
|
821
|
+
className: "quoin-table-handle",
|
|
822
|
+
style,
|
|
823
|
+
children: axis === "row" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.GripVertical, { "aria-hidden": "true" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.GripHorizontal, { "aria-hidden": "true" })
|
|
824
|
+
}
|
|
825
|
+
) }),
|
|
826
|
+
open && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
827
|
+
_chunk2VDK27IFcjs.DropdownMenuContent,
|
|
828
|
+
{
|
|
829
|
+
align: "start",
|
|
830
|
+
"aria-label": label,
|
|
831
|
+
"aria-labelledby": void 0,
|
|
832
|
+
onCloseAutoFocus: _chunk2VDK27IFcjs.returnFocusToText.call(void 0, controller),
|
|
833
|
+
..._chunk2VDK27IFcjs.bubblePart.call(void 0, controller),
|
|
834
|
+
children: [
|
|
835
|
+
items.filter((entry) => !entry.destructive).map(item2),
|
|
836
|
+
children,
|
|
837
|
+
items.filter((entry) => entry.destructive).map((entry) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.Fragment, { children: [
|
|
838
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.DropdownMenuSeparator, {}),
|
|
839
|
+
item2(entry)
|
|
840
|
+
] }, entry.id))
|
|
841
|
+
]
|
|
842
|
+
}
|
|
843
|
+
)
|
|
844
|
+
] });
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/extensions/table/table-menu-items.ts
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
var item = (id, label, icon, command, done, options = {}) => ({ id, label, icon, command, done, ...options });
|
|
863
|
+
function rowMenuItems(labels, blockId, row, { rows }) {
|
|
864
|
+
const { rowInserted, rowMoved, rowDeleted } = labels;
|
|
865
|
+
return [
|
|
866
|
+
item("above", labels.insertRowAbove, _lucidereact.ArrowUpToLine, addRow(blockId, row), rowInserted),
|
|
867
|
+
item("below", labels.insertRowBelow, _lucidereact.ArrowDownToLine, addRow(blockId, row + 1), rowInserted),
|
|
868
|
+
item("up", labels.moveRowUp, _lucidereact.ArrowUp, moveRow(blockId, row, row - 1), rowMoved, { disabled: row === 0 }),
|
|
869
|
+
item("down", labels.moveRowDown, _lucidereact.ArrowDown, moveRow(blockId, row, row + 1), rowMoved, { disabled: row === rows - 1 }),
|
|
870
|
+
item("delete", labels.deleteRow, _lucidereact.Trash, removeRow(blockId, row), rowDeleted, { disabled: rows === 1, destructive: true })
|
|
871
|
+
];
|
|
872
|
+
}
|
|
873
|
+
function columnMenuItems(labels, blockId, col, { cols }) {
|
|
874
|
+
const { columnInserted, columnMoved, columnDeleted } = labels;
|
|
875
|
+
const last = col === cols - 1;
|
|
876
|
+
return [
|
|
877
|
+
item("left", labels.insertColumnLeft, _lucidereact.ArrowLeftToLine, addColumn(blockId, col), columnInserted),
|
|
878
|
+
item("right", labels.insertColumnRight, _lucidereact.ArrowRightToLine, addColumn(blockId, col + 1), columnInserted),
|
|
879
|
+
item("move-left", labels.moveColumnLeft, _lucidereact.ArrowLeft, moveColumn(blockId, col, col - 1), columnMoved, { disabled: col === 0 }),
|
|
880
|
+
item("move-right", labels.moveColumnRight, _lucidereact.ArrowRight, moveColumn(blockId, col, col + 1), columnMoved, { disabled: last }),
|
|
881
|
+
item("delete", labels.deleteColumn, _lucidereact.Trash, removeColumn(blockId, col), columnDeleted, {
|
|
882
|
+
disabled: cols === 1,
|
|
883
|
+
destructive: true
|
|
884
|
+
})
|
|
885
|
+
];
|
|
886
|
+
}
|
|
887
|
+
var alignItems = (labels) => [
|
|
888
|
+
{ value: "left", label: labels.alignLeft, icon: _lucidereact.AlignLeft, done: labels.alignedLeft },
|
|
889
|
+
{ value: "center", label: labels.alignCenter, icon: _lucidereact.AlignCenter, done: labels.alignedCenter },
|
|
890
|
+
{ value: "right", label: labels.alignRight, icon: _lucidereact.AlignRight, done: labels.alignedRight }
|
|
891
|
+
];
|
|
892
|
+
|
|
893
|
+
// src/extensions/table/TableHandles.tsx
|
|
894
|
+
|
|
895
|
+
var BESIDE = 4;
|
|
896
|
+
var end = (span) => span.start + span.size;
|
|
897
|
+
function edgeOf(spans, edge) {
|
|
898
|
+
if (edge === null || !Number.isInteger(edge) || edge < 0 || edge > spans.length || spans.length === 0) return null;
|
|
899
|
+
return edge === spans.length ? end(spans[edge - 1]) : spans[edge].start;
|
|
900
|
+
}
|
|
901
|
+
var middle = (span) => span.start + span.size / 2;
|
|
902
|
+
var isTab = (event) => event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
|
903
|
+
function TableHandles(props) {
|
|
904
|
+
const { controller, labels, block, target, geometry, menu, onMenu, onHold, focusRequested, onFocused } = props;
|
|
905
|
+
const rowHandle = _react.useRef.call(void 0, null);
|
|
906
|
+
const columnHandle = _react.useRef.call(void 0, null);
|
|
907
|
+
const resizer = _react.useRef.call(void 0, null);
|
|
908
|
+
const shape = tableShape(block);
|
|
909
|
+
const row = Math.min(target.row, shape.rows - 1);
|
|
910
|
+
const col = Math.min(target.col, shape.cols - 1);
|
|
911
|
+
const align = columnAligns(block, shape.cols)[col];
|
|
912
|
+
const drawn = geometry.cols.map((span) => span.size);
|
|
913
|
+
const { rowEdge, colEdge } = target;
|
|
914
|
+
const rowInsertAt = edgeOf(geometry.rows, rowEdge);
|
|
915
|
+
const columnInsertAt = edgeOf(geometry.cols, colEdge);
|
|
916
|
+
_chunkGTTPVJSDcjs.useIsomorphicLayoutEffect.call(void 0, () => {
|
|
917
|
+
if (!focusRequested) return;
|
|
918
|
+
_optionalChain([(_nullishCoalesce(columnHandle.current, () => ( rowHandle.current))), 'optionalAccess', _50 => _50.focus, 'call', _51 => _51()]);
|
|
919
|
+
onFocused();
|
|
920
|
+
}, [focusRequested, onFocused]);
|
|
921
|
+
const run = (command, done) => {
|
|
922
|
+
if (controller.run(command)) controller.announce(done);
|
|
923
|
+
};
|
|
924
|
+
const onKeyDown = (event) => {
|
|
925
|
+
const handles = [rowHandle.current, columnHandle.current].filter((handle) => handle !== null);
|
|
926
|
+
const index = handles.indexOf(event.target);
|
|
927
|
+
if (index === -1 || _chunkGTTPVJSDcjs.isComposingKey.call(void 0, controller, event.nativeEvent)) return;
|
|
928
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowRight") handles[(index + 1) % handles.length].focus();
|
|
929
|
+
else if (isTab(event) && !event.shiftKey && resizer.current !== null) resizer.current.focus();
|
|
930
|
+
else if (isTab(event) || event.key === "Escape") controller.focus();
|
|
931
|
+
else return;
|
|
932
|
+
event.preventDefault();
|
|
933
|
+
};
|
|
934
|
+
const place = (left, top) => ({ left, top });
|
|
935
|
+
const opener = (kind) => (open) => onMenu(open ? kind : null);
|
|
936
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
937
|
+
geometry.cols.map((span, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
938
|
+
ColumnResizer,
|
|
939
|
+
{
|
|
940
|
+
controller,
|
|
941
|
+
labels,
|
|
942
|
+
blockId: block.id,
|
|
943
|
+
col: index,
|
|
944
|
+
drawn,
|
|
945
|
+
style: { left: end(span), top: geometry.top, height: geometry.height },
|
|
946
|
+
resizerRef: index === col ? resizer : void 0,
|
|
947
|
+
onHold,
|
|
948
|
+
onBack: () => _optionalChain([(_nullishCoalesce(columnHandle.current, () => ( rowHandle.current))), 'optionalAccess', _52 => _52.focus, 'call', _53 => _53()])
|
|
949
|
+
},
|
|
950
|
+
index
|
|
951
|
+
)),
|
|
952
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { role: "toolbar", "aria-label": labels.tableControls, className: "quoin-table-toolbar", onKeyDown, children: [
|
|
953
|
+
rowInsertAt === null && geometry.rows[row] && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
954
|
+
HandleMenu,
|
|
955
|
+
{
|
|
956
|
+
controller,
|
|
957
|
+
axis: "row",
|
|
958
|
+
label: labels.rowOptions(row + 1),
|
|
959
|
+
style: place(geometry.left - BESIDE, middle(geometry.rows[row])),
|
|
960
|
+
items: rowMenuItems(labels, block.id, row, shape),
|
|
961
|
+
open: menu === "row",
|
|
962
|
+
onOpenChange: opener("row"),
|
|
963
|
+
buttonRef: rowHandle,
|
|
964
|
+
children: row === 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
965
|
+
_chunk2VDK27IFcjs.DropdownMenuCheckboxItem,
|
|
966
|
+
{
|
|
967
|
+
checked: block.attrs.header !== false,
|
|
968
|
+
onCheckedChange: (on) => run(toggleHeaderRow(block.id), on ? labels.headerRowOn : labels.headerRowOff),
|
|
969
|
+
children: labels.headerRow
|
|
970
|
+
}
|
|
971
|
+
)
|
|
972
|
+
}
|
|
973
|
+
),
|
|
974
|
+
columnInsertAt === null && geometry.cols[col] && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
975
|
+
HandleMenu,
|
|
976
|
+
{
|
|
977
|
+
controller,
|
|
978
|
+
axis: "column",
|
|
979
|
+
label: labels.columnOptions(col + 1),
|
|
980
|
+
style: place(middle(geometry.cols[col]), geometry.top),
|
|
981
|
+
items: columnMenuItems(labels, block.id, col, shape),
|
|
982
|
+
open: menu === "column",
|
|
983
|
+
onOpenChange: opener("column"),
|
|
984
|
+
buttonRef: columnHandle,
|
|
985
|
+
children: [
|
|
986
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.DropdownMenuSeparator, {}),
|
|
987
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.DropdownMenuRadioGroup, { value: _nullishCoalesce(align, () => ( "")), children: alignItems(labels).map(({ value, label, icon, done }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
988
|
+
_chunk2VDK27IFcjs.DropdownMenuRadioItem,
|
|
989
|
+
{
|
|
990
|
+
value,
|
|
991
|
+
onSelect: () => align === value ? run(setColumnAlign(block.id, col, null), labels.alignmentCleared) : run(setColumnAlign(block.id, col, value), done),
|
|
992
|
+
children: [
|
|
993
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk2VDK27IFcjs.MenuIcon, { icon }),
|
|
994
|
+
label
|
|
995
|
+
]
|
|
996
|
+
},
|
|
997
|
+
value
|
|
998
|
+
)) })
|
|
999
|
+
]
|
|
1000
|
+
}
|
|
1001
|
+
)
|
|
1002
|
+
] }),
|
|
1003
|
+
rowEdge !== null && rowInsertAt !== null && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1004
|
+
"button",
|
|
1005
|
+
{
|
|
1006
|
+
type: "button",
|
|
1007
|
+
tabIndex: -1,
|
|
1008
|
+
"aria-label": labels.insertRowAt(rowEdge + 1),
|
|
1009
|
+
"data-axis": "row",
|
|
1010
|
+
className: "quoin-table-insert",
|
|
1011
|
+
style: place(geometry.left - BESIDE, rowInsertAt),
|
|
1012
|
+
onPointerDown: _chunk2VDK27IFcjs.keepFocus,
|
|
1013
|
+
onMouseDown: _chunk2VDK27IFcjs.keepFocus,
|
|
1014
|
+
onClick: () => run(addRow(block.id, rowEdge), labels.rowInserted),
|
|
1015
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Plus, { "aria-hidden": "true" })
|
|
1016
|
+
}
|
|
1017
|
+
),
|
|
1018
|
+
colEdge !== null && columnInsertAt !== null && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1019
|
+
"button",
|
|
1020
|
+
{
|
|
1021
|
+
type: "button",
|
|
1022
|
+
tabIndex: -1,
|
|
1023
|
+
"aria-label": labels.insertColumnAt(colEdge + 1),
|
|
1024
|
+
"data-axis": "column",
|
|
1025
|
+
className: "quoin-table-insert",
|
|
1026
|
+
style: place(columnInsertAt, geometry.top),
|
|
1027
|
+
onPointerDown: _chunk2VDK27IFcjs.keepFocus,
|
|
1028
|
+
onMouseDown: _chunk2VDK27IFcjs.keepFocus,
|
|
1029
|
+
onClick: () => run(addColumn(block.id, colEdge), labels.columnInserted),
|
|
1030
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _lucidereact.Plus, { "aria-hidden": "true" })
|
|
1031
|
+
}
|
|
1032
|
+
)
|
|
1033
|
+
] });
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
// src/extensions/table/use-table-geometry.ts
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
// src/extensions/table/table-geometry.ts
|
|
1040
|
+
function measureTable(table, origin) {
|
|
1041
|
+
const box = table.getBoundingClientRect();
|
|
1042
|
+
const first = table.rows[0];
|
|
1043
|
+
return {
|
|
1044
|
+
left: box.left - origin.left,
|
|
1045
|
+
top: box.top - origin.top,
|
|
1046
|
+
width: box.width,
|
|
1047
|
+
height: box.height,
|
|
1048
|
+
rows: Array.from(table.rows, (row) => {
|
|
1049
|
+
const rect = row.getBoundingClientRect();
|
|
1050
|
+
return { start: rect.top - origin.top, size: rect.height };
|
|
1051
|
+
}),
|
|
1052
|
+
cols: Array.from(_nullishCoalesce(_optionalChain([first, 'optionalAccess', _54 => _54.cells]), () => ( [])), (cell) => {
|
|
1053
|
+
const rect = cell.getBoundingClientRect();
|
|
1054
|
+
return { start: rect.left - origin.left, size: rect.width };
|
|
1055
|
+
})
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
var sameSpans = (a, b) => a.length === b.length && a.every((span, i) => span.start === b[i].start && span.size === b[i].size);
|
|
1059
|
+
var sameGeometry = (a, b) => a === b || a !== null && b !== null && a.left === b.left && a.top === b.top && a.width === b.width && a.height === b.height && sameSpans(a.rows, b.rows) && sameSpans(a.cols, b.cols);
|
|
1060
|
+
function spanAt(spans, at) {
|
|
1061
|
+
const inside = spans.findIndex((span) => at < span.start + span.size);
|
|
1062
|
+
return inside === -1 ? spans.length - 1 : inside;
|
|
1063
|
+
}
|
|
1064
|
+
function edgeNear(spans, at, reach) {
|
|
1065
|
+
if (spans.length === 0) return null;
|
|
1066
|
+
const edges = [spans[0].start, ...spans.map((span) => span.start + span.size)];
|
|
1067
|
+
const index = edges.findIndex((edge) => Math.abs(edge - at) <= reach);
|
|
1068
|
+
return index === -1 ? null : index;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// src/extensions/table/use-table-geometry.ts
|
|
1072
|
+
function useTableGeometry(controller, blockId, slot) {
|
|
1073
|
+
const [geometry, setGeometry] = _react.useState.call(void 0, null);
|
|
1074
|
+
_chunkGTTPVJSDcjs.useIsomorphicLayoutEffect.call(void 0, () => {
|
|
1075
|
+
const table = _optionalChain([controller, 'access', _55 => _55.blockElement, 'call', _56 => _56(blockId), 'optionalAccess', _57 => _57.querySelector, 'call', _58 => _58("table")]);
|
|
1076
|
+
const view = slot.ownerDocument.defaultView;
|
|
1077
|
+
if (!table || !view) return;
|
|
1078
|
+
const measure = () => {
|
|
1079
|
+
const next = measureTable(table, slot.getBoundingClientRect());
|
|
1080
|
+
setGeometry((current) => sameGeometry(current, next) ? current : next);
|
|
1081
|
+
};
|
|
1082
|
+
measure();
|
|
1083
|
+
let frame = 0;
|
|
1084
|
+
const later = () => {
|
|
1085
|
+
view.cancelAnimationFrame(frame);
|
|
1086
|
+
frame = view.requestAnimationFrame(measure);
|
|
1087
|
+
};
|
|
1088
|
+
const unsubscribe = controller.editor.subscribe(later);
|
|
1089
|
+
const observer = new ResizeObserver(later);
|
|
1090
|
+
observer.observe(table);
|
|
1091
|
+
view.addEventListener("resize", later);
|
|
1092
|
+
return () => {
|
|
1093
|
+
view.cancelAnimationFrame(frame);
|
|
1094
|
+
unsubscribe();
|
|
1095
|
+
observer.disconnect();
|
|
1096
|
+
view.removeEventListener("resize", later);
|
|
1097
|
+
};
|
|
1098
|
+
}, [controller, blockId, slot]);
|
|
1099
|
+
return geometry;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/extensions/table/use-cut-cells.ts
|
|
1103
|
+
|
|
1104
|
+
function useCutCells(controller) {
|
|
1105
|
+
_react.useEffect.call(void 0, () => {
|
|
1106
|
+
const root = controller.root;
|
|
1107
|
+
if (root === null) return;
|
|
1108
|
+
const onCut = (event) => {
|
|
1109
|
+
if (controller.readOnly || cellSelection(controller.editor.state) === null) return;
|
|
1110
|
+
event.stopPropagation();
|
|
1111
|
+
_chunkGTTPVJSDcjs.handleCopy.call(void 0, controller, event, false);
|
|
1112
|
+
controller.run(deleteCellContents);
|
|
1113
|
+
};
|
|
1114
|
+
root.addEventListener("cut", onCut, true);
|
|
1115
|
+
return () => root.removeEventListener("cut", onCut, true);
|
|
1116
|
+
}, [controller]);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/extensions/table/use-table-target.ts
|
|
1120
|
+
|
|
1121
|
+
var EDGE_ZONE = 24;
|
|
1122
|
+
var EDGE_REACH = 8;
|
|
1123
|
+
var VIEWPORT = { left: 0, top: 0 };
|
|
1124
|
+
var CONTROLS = `[${CONTROLS_SLOT}]`;
|
|
1125
|
+
var sameTarget = (a, b) => a === b || a !== null && b !== null && a.block === b.block && a.row === b.row && a.col === b.col && a.rowEdge === b.rowEdge && a.colEdge === b.colEdge;
|
|
1126
|
+
function caretTarget(state) {
|
|
1127
|
+
const caret = headCell(state);
|
|
1128
|
+
return caret && { block: caret.block.id, row: caret.cell[0], col: caret.cell[1], rowEdge: null, colEdge: null };
|
|
1129
|
+
}
|
|
1130
|
+
function pointerTarget(controller, event) {
|
|
1131
|
+
const blockId = controller.blockAt(event.target);
|
|
1132
|
+
const block = blockId === void 0 ? null : tableBlock(controller.editor.state.doc, blockId);
|
|
1133
|
+
const table = block && _optionalChain([controller, 'access', _59 => _59.blockElement, 'call', _60 => _60(block.id), 'optionalAccess', _61 => _61.querySelector, 'call', _62 => _62("table")]);
|
|
1134
|
+
if (!block || !table) return null;
|
|
1135
|
+
const geometry = measureTable(table, VIEWPORT);
|
|
1136
|
+
const { clientX: x, clientY: y } = event;
|
|
1137
|
+
const row = spanAt(geometry.rows, y);
|
|
1138
|
+
const col = spanAt(geometry.cols, x);
|
|
1139
|
+
if (row < 0 || col < 0) return null;
|
|
1140
|
+
const rowEdge = x < geometry.left + EDGE_ZONE ? edgeNear(geometry.rows, y, EDGE_REACH) : null;
|
|
1141
|
+
const colEdge = y < geometry.top + EDGE_ZONE ? edgeNear(geometry.cols, x, EDGE_REACH) : null;
|
|
1142
|
+
return { block: block.id, row, col, rowEdge, colEdge };
|
|
1143
|
+
}
|
|
1144
|
+
function shapeOf(state, blockId) {
|
|
1145
|
+
const block = tableBlock(state.doc, blockId);
|
|
1146
|
+
if (block === null) return null;
|
|
1147
|
+
const { rows, cols } = tableShape(block);
|
|
1148
|
+
return `${rows}x${cols}`;
|
|
1149
|
+
}
|
|
1150
|
+
function focusOf(root) {
|
|
1151
|
+
const active = root.ownerDocument.activeElement;
|
|
1152
|
+
if (active === null || !root.contains(active)) return "none";
|
|
1153
|
+
return active.closest(CONTROLS) === null ? "editor" : "controls";
|
|
1154
|
+
}
|
|
1155
|
+
function useTableTarget(controller, held) {
|
|
1156
|
+
const [hovered, setHovered] = _react.useState.call(void 0, null);
|
|
1157
|
+
const [focus, setFocus] = _react.useState.call(void 0, "none");
|
|
1158
|
+
const caret = _chunkGTTPVJSDcjs.useEditorState.call(void 0, controller, caretTarget, sameTarget);
|
|
1159
|
+
const hoveredBlock = _nullishCoalesce(_optionalChain([hovered, 'optionalAccess', _63 => _63.target, 'access', _64 => _64.block]), () => ( null));
|
|
1160
|
+
const shape = _chunkGTTPVJSDcjs.useEditorState.call(void 0,
|
|
1161
|
+
controller,
|
|
1162
|
+
_react.useCallback.call(void 0, (state) => hoveredBlock === null ? null : shapeOf(state, hoveredBlock), [hoveredBlock])
|
|
1163
|
+
);
|
|
1164
|
+
const pointed = hovered !== null && hovered.shape === shape ? hovered.target : null;
|
|
1165
|
+
_react.useEffect.call(void 0, () => {
|
|
1166
|
+
const root = controller.root;
|
|
1167
|
+
if (root === null) return;
|
|
1168
|
+
const onPointerMove = (event) => {
|
|
1169
|
+
if (event.pointerType === "touch") return;
|
|
1170
|
+
const target = pointerTarget(controller, event);
|
|
1171
|
+
const next = target && { target, shape: shapeOf(controller.editor.state, target.block) };
|
|
1172
|
+
setHovered(
|
|
1173
|
+
(current) => current !== null && next !== null && sameTarget(current.target, next.target) && current.shape === next.shape ? current : next
|
|
1174
|
+
);
|
|
1175
|
+
};
|
|
1176
|
+
const onPointerLeave = () => setHovered(null);
|
|
1177
|
+
const onFocusChange = () => setFocus(focusOf(root));
|
|
1178
|
+
const onFocusOut = (event) => {
|
|
1179
|
+
const next = event.relatedTarget;
|
|
1180
|
+
setFocus(next !== null && root.contains(next) ? next.closest(CONTROLS) ? "controls" : "editor" : "none");
|
|
1181
|
+
};
|
|
1182
|
+
setFocus(focusOf(root));
|
|
1183
|
+
root.addEventListener("pointermove", onPointerMove);
|
|
1184
|
+
root.addEventListener("pointerleave", onPointerLeave);
|
|
1185
|
+
root.addEventListener("focusin", onFocusChange);
|
|
1186
|
+
root.addEventListener("focusout", onFocusOut);
|
|
1187
|
+
return () => {
|
|
1188
|
+
root.removeEventListener("pointermove", onPointerMove);
|
|
1189
|
+
root.removeEventListener("pointerleave", onPointerLeave);
|
|
1190
|
+
root.removeEventListener("focusin", onFocusChange);
|
|
1191
|
+
root.removeEventListener("focusout", onFocusOut);
|
|
1192
|
+
};
|
|
1193
|
+
}, [controller]);
|
|
1194
|
+
if (held !== null) return held;
|
|
1195
|
+
if (focus === "controls") return _nullishCoalesce(caret, () => ( pointed));
|
|
1196
|
+
return _nullishCoalesce(pointed, () => ( (focus === "editor" ? caret : null)));
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// src/extensions/table/TableControls.tsx
|
|
1200
|
+
|
|
1201
|
+
var isFocusKey = (event) => event.key === "F10" && event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
|
|
1202
|
+
var takesFocusKey = (state) => _chunkPZ4GT5JOcjs.isCollapsed.call(void 0, state.selection) || cellSelection(state) !== null;
|
|
1203
|
+
function TableControls({ controller, labels }) {
|
|
1204
|
+
const readOnly = _chunkGTTPVJSDcjs.useReadOnly.call(void 0, controller);
|
|
1205
|
+
const [held, setHeld] = _react.useState.call(void 0, null);
|
|
1206
|
+
const [focusFor, setFocusFor] = _react.useState.call(void 0, null);
|
|
1207
|
+
const [slot, setSlot] = _react.useState.call(void 0, null);
|
|
1208
|
+
const target = useTableTarget(controller, _nullishCoalesce(_optionalChain([held, 'optionalAccess', _65 => _65.target]), () => ( null)));
|
|
1209
|
+
useCutCells(controller);
|
|
1210
|
+
const blockId = _nullishCoalesce(_optionalChain([target, 'optionalAccess', _66 => _66.block]), () => ( null));
|
|
1211
|
+
const block = _chunkGTTPVJSDcjs.useEditorState.call(void 0,
|
|
1212
|
+
controller,
|
|
1213
|
+
_react.useCallback.call(void 0, (state) => blockId === null ? null : tableBlock(state.doc, blockId), [blockId])
|
|
1214
|
+
);
|
|
1215
|
+
if (_optionalChain([held, 'optionalAccess', _67 => _67.menu]) && held.opened && block && !sameMenuCells(held.opened, block, held.target, held.menu)) setHeld(null);
|
|
1216
|
+
_react.useEffect.call(void 0, () => {
|
|
1217
|
+
if (!readOnly && block !== null) return;
|
|
1218
|
+
setHeld(null);
|
|
1219
|
+
setFocusFor(null);
|
|
1220
|
+
}, [readOnly, block]);
|
|
1221
|
+
_react.useEffect.call(void 0, () => {
|
|
1222
|
+
if (readOnly) return;
|
|
1223
|
+
const intercept = (event) => {
|
|
1224
|
+
const { state } = controller.editor;
|
|
1225
|
+
const caret = caretTarget(state);
|
|
1226
|
+
if (!isFocusKey(event) || _chunkGTTPVJSDcjs.isComposingKey.call(void 0, controller, event) || caret === null || !takesFocusKey(state)) return false;
|
|
1227
|
+
event.preventDefault();
|
|
1228
|
+
setHeld({ target: caret, menu: null });
|
|
1229
|
+
setFocusFor(caret.block);
|
|
1230
|
+
return true;
|
|
1231
|
+
};
|
|
1232
|
+
return _chunk2VDK27IFcjs.interceptKeys.call(void 0, controller, intercept);
|
|
1233
|
+
}, [controller, readOnly]);
|
|
1234
|
+
const onMenu = _react.useCallback.call(void 0,
|
|
1235
|
+
(menu) => setHeld(menu === null || target === null || block === null ? null : { target, menu, opened: block }),
|
|
1236
|
+
[target, block]
|
|
1237
|
+
);
|
|
1238
|
+
const onHold = _react.useCallback.call(void 0, (hold) => setHeld(hold && target !== null ? { target, menu: null } : null), [target]);
|
|
1239
|
+
const onFocused = _react.useCallback.call(void 0, () => {
|
|
1240
|
+
setFocusFor(null);
|
|
1241
|
+
setHeld((current) => _optionalChain([current, 'optionalAccess', _68 => _68.menu]) === null ? null : current);
|
|
1242
|
+
}, []);
|
|
1243
|
+
_chunkGTTPVJSDcjs.useIsomorphicLayoutEffect.call(void 0, () => {
|
|
1244
|
+
const drawn = block === null || readOnly ? null : controlsSlot(controller, block.id);
|
|
1245
|
+
setSlot((current) => current === drawn ? current : drawn);
|
|
1246
|
+
});
|
|
1247
|
+
if (target === null || block === null || readOnly || slot === null || !slot.isConnected) return null;
|
|
1248
|
+
return _reactdom.createPortal.call(void 0,
|
|
1249
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1250
|
+
PlacedHandles,
|
|
1251
|
+
{
|
|
1252
|
+
controller,
|
|
1253
|
+
labels,
|
|
1254
|
+
block,
|
|
1255
|
+
target,
|
|
1256
|
+
slot,
|
|
1257
|
+
menu: _nullishCoalesce(_optionalChain([held, 'optionalAccess', _69 => _69.menu]), () => ( null)),
|
|
1258
|
+
onMenu,
|
|
1259
|
+
onHold,
|
|
1260
|
+
focusRequested: focusFor === block.id,
|
|
1261
|
+
onFocused
|
|
1262
|
+
},
|
|
1263
|
+
block.id
|
|
1264
|
+
),
|
|
1265
|
+
slot
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
function PlacedHandles({ slot, ...props }) {
|
|
1269
|
+
const geometry = useTableGeometry(props.controller, props.block.id, slot);
|
|
1270
|
+
return geometry === null ? null : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TableHandles, { ...props, geometry });
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// src/extensions/table/table-labels.ts
|
|
1274
|
+
var englishTableLabels = {
|
|
1275
|
+
table: "Table",
|
|
1276
|
+
tableDescription: "Rows and columns of text",
|
|
1277
|
+
cell: (row, col) => `Row ${row}, column ${col}`,
|
|
1278
|
+
tableControls: "Table controls",
|
|
1279
|
+
rowOptions: (row) => `Row ${row} options`,
|
|
1280
|
+
columnOptions: (col) => `Column ${col} options`,
|
|
1281
|
+
insertRowAbove: "Insert row above",
|
|
1282
|
+
insertRowBelow: "Insert row below",
|
|
1283
|
+
insertColumnLeft: "Insert column left",
|
|
1284
|
+
insertColumnRight: "Insert column right",
|
|
1285
|
+
moveRowUp: "Move row up",
|
|
1286
|
+
moveRowDown: "Move row down",
|
|
1287
|
+
moveColumnLeft: "Move column left",
|
|
1288
|
+
moveColumnRight: "Move column right",
|
|
1289
|
+
deleteRow: "Delete row",
|
|
1290
|
+
deleteColumn: "Delete column",
|
|
1291
|
+
headerRow: "Header row",
|
|
1292
|
+
alignLeft: "Align left",
|
|
1293
|
+
alignCenter: "Align center",
|
|
1294
|
+
alignRight: "Align right",
|
|
1295
|
+
insertRowAt: (row) => `Insert row ${row}`,
|
|
1296
|
+
insertColumnAt: (col) => `Insert column ${col}`,
|
|
1297
|
+
resizeColumn: (col) => `Resize column ${col}`,
|
|
1298
|
+
columnWidth: (px) => `${px} pixels`,
|
|
1299
|
+
rowInserted: "Row inserted",
|
|
1300
|
+
rowDeleted: "Row deleted",
|
|
1301
|
+
rowMoved: "Row moved",
|
|
1302
|
+
columnInserted: "Column inserted",
|
|
1303
|
+
columnDeleted: "Column deleted",
|
|
1304
|
+
columnMoved: "Column moved",
|
|
1305
|
+
headerRowOn: "Header row on",
|
|
1306
|
+
headerRowOff: "Header row off",
|
|
1307
|
+
alignedLeft: "Column aligned left",
|
|
1308
|
+
alignedCenter: "Column aligned center",
|
|
1309
|
+
alignedRight: "Column aligned right",
|
|
1310
|
+
alignmentCleared: "Column alignment cleared"
|
|
1311
|
+
};
|
|
1312
|
+
function resolveTableLabels(overrides) {
|
|
1313
|
+
const given = Object.entries(_nullishCoalesce(overrides, () => ( {}))).filter(([, value]) => value !== void 0);
|
|
1314
|
+
return given.length === 0 ? englishTableLabels : { ...englishTableLabels, ...Object.fromEntries(given) };
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// src/extensions/table/table-slash-item.ts
|
|
1318
|
+
|
|
1319
|
+
var NEW_TABLE = { rows: 3, cols: 3 };
|
|
1320
|
+
var tableSlashItem = (labels) => ({
|
|
1321
|
+
id: "table",
|
|
1322
|
+
title: labels.table,
|
|
1323
|
+
description: labels.tableDescription,
|
|
1324
|
+
group: "advanced",
|
|
1325
|
+
icon: _lucidereact.Table,
|
|
1326
|
+
keywords: ["grid", "rows", "columns", "spreadsheet", "|"],
|
|
1327
|
+
command: () => insertTable(NEW_TABLE.rows, NEW_TABLE.cols)
|
|
1328
|
+
});
|
|
1329
|
+
|
|
1330
|
+
// src/extensions/table/table-extension.tsx
|
|
1331
|
+
|
|
1332
|
+
var ABOVE_CORE_KEYS = 200;
|
|
1333
|
+
var pasteOverCells = {
|
|
1334
|
+
name: "table-cells",
|
|
1335
|
+
match: (text, state) => cellSelection(state) === null ? null : typeOverCells(text.replace(/\r\n?/g, "\n"))
|
|
1336
|
+
};
|
|
1337
|
+
function tableExtension(options = {}) {
|
|
1338
|
+
const labels = resolveTableLabels(options.labels);
|
|
1339
|
+
const TableRenderer = (props) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TableBlock, { ...props, labels });
|
|
1340
|
+
const TableOverlay = ({ controller }) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, TableControls, { controller, labels });
|
|
1341
|
+
const ui = {
|
|
1342
|
+
slashItems: [tableSlashItem(labels)],
|
|
1343
|
+
renderers: { TABLE: TableRenderer },
|
|
1344
|
+
blockNames: { TABLE: labels.table },
|
|
1345
|
+
overlays: [TableOverlay]
|
|
1346
|
+
};
|
|
1347
|
+
return _chunkPZ4GT5JOcjs.defineExtension.call(void 0, {
|
|
1348
|
+
name: "table",
|
|
1349
|
+
priority: ABOVE_CORE_KEYS,
|
|
1350
|
+
plugins: [cellSelectionPlugin],
|
|
1351
|
+
keymap: tableKeymap,
|
|
1352
|
+
pasteRules: [pasteOverCells],
|
|
1353
|
+
ui
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
|
|
1358
|
+
|
|
1359
|
+
|
|
1360
|
+
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
|
|
1370
|
+
|
|
1371
|
+
|
|
1372
|
+
|
|
1373
|
+
|
|
1374
|
+
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
exports.cellSelectionKey = cellSelectionKey; exports.cellSelectionPlugin = cellSelectionPlugin; exports.cellSelection = cellSelection; exports.cellsInRange = cellsInRange; exports.selectCells = selectCells; exports.deleteCellContents = deleteCellContents; exports.setCellsMark = setCellsMark; exports.addRow = addRow; exports.removeRow = removeRow; exports.moveRow = moveRow; exports.addColumn = addColumn; exports.removeColumn = removeColumn; exports.moveColumn = moveColumn; exports.toggleHeaderRow = toggleHeaderRow; exports.setColumnAlign = setColumnAlign; exports.setColumnWidth = setColumnWidth; exports.insertTable = insertTable; exports.englishTableLabels = englishTableLabels; exports.tableExtension = tableExtension;
|
|
1378
|
+
//# sourceMappingURL=chunk-AEJXZBVR.cjs.map
|