@etrepum/lexical-builder-table 0.0.33 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -125
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { ReadableStore } from '@etrepum/lexical-builder';
|
2
2
|
|
3
3
|
export declare const PACKAGE_VERSION: string;
|
4
4
|
export interface TableConfig {
|
@@ -6,9 +6,10 @@ export interface TableConfig {
|
|
6
6
|
hasCellBackgroundColor: boolean;
|
7
7
|
hasTabHandler: boolean;
|
8
8
|
}
|
9
|
-
export
|
10
|
-
hasCellMerge:
|
11
|
-
hasCellBackgroundColor:
|
12
|
-
hasTabHandler:
|
13
|
-
}
|
9
|
+
export interface TableOutput {
|
10
|
+
hasCellMerge: ReadableStore<boolean>;
|
11
|
+
hasCellBackgroundColor: ReadableStore<boolean>;
|
12
|
+
hasTabHandler: ReadableStore<boolean>;
|
13
|
+
}
|
14
|
+
export declare const TablePlan: import('@etrepum/lexical-builder').LexicalPlan<TableConfig, "@lexical/table", TableOutput, TableOutput>;
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkCH,OAAO,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkCH,OAAO,EAGL,KAAK,aAAa,EAInB,MAAM,0BAA0B,CAAC;AAGlC,eAAO,MAAM,eAAe,EAAE,MAAwC,CAAC;AAEvE,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACrC,sBAAsB,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/C,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACvC;AAED,eAAO,MAAM,SAAS,yGA4LpB,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
import { TableNode as N, TableRowNode as
|
2
|
-
import { mergeRegister as E, $insertNodeToNearestRoot as
|
3
|
-
import { $isTextNode as
|
4
|
-
import { definePlan as
|
5
|
-
function w(a, c, ...
|
1
|
+
import { TableNode as N, TableRowNode as x, TableCellNode as T, INSERT_TABLE_COMMAND as y, $createTableNodeWithDimensions as B, $computeTableMapSkipCellCheck as _, $createTableCellNode as M, $isTableNode as A, $getNodeTriplet as I, $computeTableMap as D, $isTableRowNode as $, $isTableCellNode as H, applyTableHandlers as K } from "@lexical/table";
|
2
|
+
import { mergeRegister as E, $insertNodeToNearestRoot as L, $insertFirst as O } from "@lexical/utils";
|
3
|
+
import { $isTextNode as v, COMMAND_PRIORITY_EDITOR as P, $createParagraphNode as F, $getNodeByKey as j } from "lexical";
|
4
|
+
import { definePlan as z, safeCast as V, Store as h, provideOutput as G, registerStoreToggle as m } from "@etrepum/lexical-builder";
|
5
|
+
function w(a, c, ...C) {
|
6
6
|
if (!a)
|
7
7
|
throw new Error(
|
8
|
-
|
8
|
+
C.reduce((f, p) => f.replace("%s", String(p)), c || "")
|
9
9
|
);
|
10
10
|
}
|
11
|
-
const
|
11
|
+
const Q = "0.0.34", U = z({
|
12
12
|
name: "@lexical/table",
|
13
|
-
nodes: [N,
|
14
|
-
config:
|
13
|
+
nodes: [N, x, T],
|
14
|
+
config: V({
|
15
15
|
hasCellMerge: !0,
|
16
16
|
hasCellBackgroundColor: !0,
|
17
17
|
hasTabHandler: !0
|
@@ -23,133 +23,136 @@ const q = "0.0.33", J = j({
|
|
23
23
|
hasTabHandler: new h(c.hasTabHandler)
|
24
24
|
};
|
25
25
|
},
|
26
|
-
register(a, c,
|
27
|
-
const { hasCellMerge:
|
28
|
-
return
|
29
|
-
|
30
|
-
|
31
|
-
(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
const l = e.getFirstDescendant();
|
39
|
-
return O(l) && l.select(), !0;
|
40
|
-
},
|
41
|
-
P
|
42
|
-
),
|
43
|
-
a.registerNodeTransform(N, (t) => {
|
44
|
-
const [o] = B(t, null, null);
|
45
|
-
let r = 0;
|
46
|
-
for (const e of o)
|
47
|
-
r = Math.max(r, e.length);
|
48
|
-
for (const e of o) {
|
49
|
-
const l = e.length;
|
50
|
-
if (l === r || l === 0)
|
51
|
-
continue;
|
52
|
-
const n = e[l - 1].cell;
|
53
|
-
for (let s = l; s < r; ++s) {
|
54
|
-
const d = M(0);
|
55
|
-
d.append(v()), n.insertAfter(d);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}),
|
59
|
-
m(
|
60
|
-
R,
|
61
|
-
// Returning true mimics useEffect, we will call the register
|
62
|
-
// function any time the value changes
|
63
|
-
() => !0,
|
64
|
-
() => {
|
65
|
-
const t = R.get(), o = /* @__PURE__ */ new Map(), r = (e) => {
|
66
|
-
const l = e.getKey(), i = a.getElementByKey(
|
67
|
-
l
|
26
|
+
register(a, c, C) {
|
27
|
+
const f = C.getInitResult(), { hasCellMerge: p, hasCellBackgroundColor: k, hasTabHandler: R } = f;
|
28
|
+
return G(
|
29
|
+
f,
|
30
|
+
E(
|
31
|
+
a.registerCommand(
|
32
|
+
y,
|
33
|
+
({ columns: t, rows: o, includeHeaders: r }) => {
|
34
|
+
const e = B(
|
35
|
+
Number(o),
|
36
|
+
Number(t),
|
37
|
+
r
|
68
38
|
);
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
});
|
89
|
-
else if (i === "destroyed") {
|
90
|
-
const n = o.get(l);
|
91
|
-
n !== void 0 && (n.removeListeners(), o.delete(l));
|
92
|
-
}
|
93
|
-
},
|
94
|
-
{ skipInitialization: !1 }
|
95
|
-
),
|
96
|
-
// Hook might be called multiple times so cleaning up tables listeners as well,
|
97
|
-
// as it'll be reinitialized during recurring call
|
98
|
-
() => {
|
99
|
-
for (const [, e] of o)
|
100
|
-
e.removeListeners();
|
39
|
+
L(e);
|
40
|
+
const l = e.getFirstDescendant();
|
41
|
+
return v(l) && l.select(), !0;
|
42
|
+
},
|
43
|
+
P
|
44
|
+
),
|
45
|
+
a.registerNodeTransform(N, (t) => {
|
46
|
+
const [o] = _(t, null, null);
|
47
|
+
let r = 0;
|
48
|
+
for (const e of o)
|
49
|
+
r = Math.max(r, e.length);
|
50
|
+
for (const e of o) {
|
51
|
+
const l = e.length;
|
52
|
+
if (l === r || l === 0)
|
53
|
+
continue;
|
54
|
+
const n = e[l - 1].cell;
|
55
|
+
for (let s = l; s < r; ++s) {
|
56
|
+
const d = M(0);
|
57
|
+
d.append(F()), n.insertAfter(d);
|
101
58
|
}
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
const
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
59
|
+
}
|
60
|
+
}),
|
61
|
+
m(
|
62
|
+
R,
|
63
|
+
// Returning true mimics useEffect, we will call the register
|
64
|
+
// function any time the value changes
|
65
|
+
() => !0,
|
66
|
+
() => {
|
67
|
+
const t = R.get(), o = /* @__PURE__ */ new Map(), r = (e) => {
|
68
|
+
const l = e.getKey(), i = a.getElementByKey(
|
69
|
+
l
|
70
|
+
);
|
71
|
+
if (i && !o.has(l)) {
|
72
|
+
const n = K(
|
73
|
+
e,
|
74
|
+
i,
|
75
|
+
a,
|
76
|
+
t
|
77
|
+
);
|
78
|
+
o.set(l, n);
|
79
|
+
}
|
80
|
+
};
|
81
|
+
return E(
|
82
|
+
a.registerMutationListener(
|
83
|
+
N,
|
84
|
+
(e) => {
|
85
|
+
for (const [l, i] of e)
|
86
|
+
if (i === "created")
|
87
|
+
a.getEditorState().read(() => {
|
88
|
+
const n = j(l);
|
89
|
+
A(n) && r(n);
|
90
|
+
});
|
91
|
+
else if (i === "destroyed") {
|
92
|
+
const n = o.get(l);
|
93
|
+
n !== void 0 && (n.removeListeners(), o.delete(l));
|
94
|
+
}
|
95
|
+
},
|
96
|
+
{ skipInitialization: !1 }
|
97
|
+
),
|
98
|
+
// Hook might be called multiple times so cleaning up tables listeners as well,
|
99
|
+
// as it'll be reinitialized during recurring call
|
100
|
+
() => {
|
101
|
+
for (const [, e] of o)
|
102
|
+
e.removeListeners();
|
103
|
+
}
|
115
104
|
);
|
116
|
-
|
117
|
-
|
118
|
-
|
105
|
+
}
|
106
|
+
),
|
107
|
+
m(
|
108
|
+
p,
|
109
|
+
(t) => t,
|
110
|
+
() => a.registerNodeTransform(T, (t) => {
|
111
|
+
if (t.getColSpan() > 1 || t.getRowSpan() > 1) {
|
112
|
+
const [, , o] = I(t), [r] = D(o, t, t);
|
113
|
+
let e = o.getFirstChild();
|
114
|
+
w(
|
119
115
|
$(e),
|
120
116
|
"Expected TableNode first child to be a RowNode"
|
121
|
-
)
|
122
|
-
|
123
|
-
for (let
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
)
|
132
|
-
|
133
|
-
|
117
|
+
);
|
118
|
+
const l = r.length, i = r[0].length, n = [];
|
119
|
+
for (let s = 0; s < l; s++) {
|
120
|
+
s !== 0 && (e = e.getNextSibling(), w(
|
121
|
+
$(e),
|
122
|
+
"Expected TableNode first child to be a RowNode"
|
123
|
+
));
|
124
|
+
let d = null;
|
125
|
+
for (let u = 0; u < i; u++) {
|
126
|
+
const b = r[s][u], g = b.cell;
|
127
|
+
if (b.startRow === s && b.startColumn === u)
|
128
|
+
d = g, n.push(g);
|
129
|
+
else if (g.getColSpan() > 1 || g.getRowSpan() > 1) {
|
130
|
+
w(
|
131
|
+
H(g),
|
132
|
+
"Expected TableNode cell to be a TableCellNode"
|
133
|
+
);
|
134
|
+
const S = M(g.__headerState);
|
135
|
+
d !== null ? d.insertAfter(S) : O(e, S);
|
136
|
+
}
|
134
137
|
}
|
135
138
|
}
|
139
|
+
for (const s of n)
|
140
|
+
s.setColSpan(1), s.setRowSpan(1);
|
136
141
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
t.getBackgroundColor() !== null && t.setBackgroundColor(null);
|
147
|
-
})
|
142
|
+
})
|
143
|
+
),
|
144
|
+
m(
|
145
|
+
k,
|
146
|
+
(t) => t,
|
147
|
+
() => a.registerNodeTransform(T, (t) => {
|
148
|
+
t.getBackgroundColor() !== null && t.setBackgroundColor(null);
|
149
|
+
})
|
150
|
+
)
|
148
151
|
)
|
149
152
|
);
|
150
153
|
}
|
151
154
|
});
|
152
155
|
export {
|
153
|
-
|
154
|
-
|
156
|
+
Q as PACKAGE_VERSION,
|
157
|
+
U as TablePlan
|
155
158
|
};
|