@etrepum/lexical-builder-table 0.0.33
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/README.md +3 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/shared/invariant.d.ts +9 -0
- package/dist/shared/invariant.d.ts.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Store } from '@etrepum/lexical-builder';
|
2
|
+
|
3
|
+
export declare const PACKAGE_VERSION: string;
|
4
|
+
export interface TableConfig {
|
5
|
+
hasCellMerge: boolean;
|
6
|
+
hasCellBackgroundColor: boolean;
|
7
|
+
hasTabHandler: boolean;
|
8
|
+
}
|
9
|
+
export declare const TablePlan: import('@etrepum/lexical-builder').LexicalPlan<TableConfig, "@lexical/table", unknown, {
|
10
|
+
hasCellMerge: Store<boolean>;
|
11
|
+
hasCellBackgroundColor: Store<boolean>;
|
12
|
+
hasTabHandler: Store<boolean>;
|
13
|
+
}>;
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkCH,OAAO,EAIL,KAAK,EACN,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,eAAO,MAAM,SAAS;;;;EAyLpB,CAAC"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
import { TableNode as N, TableRowNode as k, TableCellNode as T, INSERT_TABLE_COMMAND as x, $createTableNodeWithDimensions as y, $computeTableMapSkipCellCheck as B, $createTableCellNode as M, $isTableNode as _, $getNodeTriplet as A, $computeTableMap as I, $isTableRowNode as $, $isTableCellNode as D, applyTableHandlers as H } from "@lexical/table";
|
2
|
+
import { mergeRegister as E, $insertNodeToNearestRoot as K, $insertFirst as L } from "@lexical/utils";
|
3
|
+
import { $isTextNode as O, COMMAND_PRIORITY_EDITOR as P, $createParagraphNode as v, $getNodeByKey as F } from "lexical";
|
4
|
+
import { definePlan as j, safeCast as z, Store as h, registerStoreToggle as m } from "@etrepum/lexical-builder";
|
5
|
+
function w(a, c, ...u) {
|
6
|
+
if (!a)
|
7
|
+
throw new Error(
|
8
|
+
u.reduce((C, b) => C.replace("%s", String(b)), c || "")
|
9
|
+
);
|
10
|
+
}
|
11
|
+
const q = "0.0.33", J = j({
|
12
|
+
name: "@lexical/table",
|
13
|
+
nodes: [N, k, T],
|
14
|
+
config: z({
|
15
|
+
hasCellMerge: !0,
|
16
|
+
hasCellBackgroundColor: !0,
|
17
|
+
hasTabHandler: !0
|
18
|
+
}),
|
19
|
+
init(a, c) {
|
20
|
+
return {
|
21
|
+
hasCellMerge: new h(c.hasCellMerge),
|
22
|
+
hasCellBackgroundColor: new h(c.hasCellBackgroundColor),
|
23
|
+
hasTabHandler: new h(c.hasTabHandler)
|
24
|
+
};
|
25
|
+
},
|
26
|
+
register(a, c, u) {
|
27
|
+
const { hasCellMerge: C, hasCellBackgroundColor: b, hasTabHandler: R } = u.getInitResult();
|
28
|
+
return E(
|
29
|
+
a.registerCommand(
|
30
|
+
x,
|
31
|
+
({ columns: t, rows: o, includeHeaders: r }) => {
|
32
|
+
const e = y(
|
33
|
+
Number(o),
|
34
|
+
Number(t),
|
35
|
+
r
|
36
|
+
);
|
37
|
+
K(e);
|
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
|
68
|
+
);
|
69
|
+
if (i && !o.has(l)) {
|
70
|
+
const n = H(
|
71
|
+
e,
|
72
|
+
i,
|
73
|
+
a,
|
74
|
+
t
|
75
|
+
);
|
76
|
+
o.set(l, n);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
return E(
|
80
|
+
a.registerMutationListener(
|
81
|
+
N,
|
82
|
+
(e) => {
|
83
|
+
for (const [l, i] of e)
|
84
|
+
if (i === "created")
|
85
|
+
a.getEditorState().read(() => {
|
86
|
+
const n = F(l);
|
87
|
+
_(n) && r(n);
|
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();
|
101
|
+
}
|
102
|
+
);
|
103
|
+
}
|
104
|
+
),
|
105
|
+
m(
|
106
|
+
C,
|
107
|
+
(t) => t,
|
108
|
+
() => a.registerNodeTransform(T, (t) => {
|
109
|
+
if (t.getColSpan() > 1 || t.getRowSpan() > 1) {
|
110
|
+
const [, , o] = A(t), [r] = I(o, t, t);
|
111
|
+
let e = o.getFirstChild();
|
112
|
+
w(
|
113
|
+
$(e),
|
114
|
+
"Expected TableNode first child to be a RowNode"
|
115
|
+
);
|
116
|
+
const l = r.length, i = r[0].length, n = [];
|
117
|
+
for (let s = 0; s < l; s++) {
|
118
|
+
s !== 0 && (e = e.getNextSibling(), w(
|
119
|
+
$(e),
|
120
|
+
"Expected TableNode first child to be a RowNode"
|
121
|
+
));
|
122
|
+
let d = null;
|
123
|
+
for (let f = 0; f < i; f++) {
|
124
|
+
const p = r[s][f], g = p.cell;
|
125
|
+
if (p.startRow === s && p.startColumn === f)
|
126
|
+
d = g, n.push(g);
|
127
|
+
else if (g.getColSpan() > 1 || g.getRowSpan() > 1) {
|
128
|
+
w(
|
129
|
+
D(g),
|
130
|
+
"Expected TableNode cell to be a TableCellNode"
|
131
|
+
);
|
132
|
+
const S = M(g.__headerState);
|
133
|
+
d !== null ? d.insertAfter(S) : L(e, S);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
for (const s of n)
|
138
|
+
s.setColSpan(1), s.setRowSpan(1);
|
139
|
+
}
|
140
|
+
})
|
141
|
+
),
|
142
|
+
m(
|
143
|
+
b,
|
144
|
+
(t) => t,
|
145
|
+
() => a.registerNodeTransform(T, (t) => {
|
146
|
+
t.getBackgroundColor() !== null && t.setBackgroundColor(null);
|
147
|
+
})
|
148
|
+
)
|
149
|
+
);
|
150
|
+
}
|
151
|
+
});
|
152
|
+
export {
|
153
|
+
q as PACKAGE_VERSION,
|
154
|
+
J as TablePlan
|
155
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
export default function invariant(cond?: boolean, message?: string, ...args: string[]): asserts cond;
|
9
|
+
//# sourceMappingURL=invariant.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../../src/shared/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,MAAM,EAChB,GAAG,IAAI,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,IAAI,CAQd"}
|
package/package.json
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
{
|
2
|
+
"name": "@etrepum/lexical-builder-table",
|
3
|
+
"description": "[EXPERIMENTAL] Lexical Builder @etrepum/lexical-builder-table",
|
4
|
+
"type": "module",
|
5
|
+
"keywords": [
|
6
|
+
"lexical",
|
7
|
+
"lexical-builder",
|
8
|
+
"plug-in",
|
9
|
+
"plan"
|
10
|
+
],
|
11
|
+
"scripts": {
|
12
|
+
"build": "tsc --noEmit && vite build",
|
13
|
+
"dev": "vite",
|
14
|
+
"test": "vitest run",
|
15
|
+
"test:watch": "vitest",
|
16
|
+
"lint": "eslint"
|
17
|
+
},
|
18
|
+
"version": "0.0.33",
|
19
|
+
"license": "MIT",
|
20
|
+
"repository": {
|
21
|
+
"type": "git",
|
22
|
+
"url": "git+https://github.com/etrepum/lexical-builder.git",
|
23
|
+
"directory": "packages/lexical-builder-table"
|
24
|
+
},
|
25
|
+
"bugs": {
|
26
|
+
"url": "https://github.com/etrepum/lexical-builder/issues"
|
27
|
+
},
|
28
|
+
"homepage": "https://github.com/etrepum/lexical-builder",
|
29
|
+
"dependencies": {
|
30
|
+
"@etrepum/lexical-builder": "*"
|
31
|
+
},
|
32
|
+
"peerDependencies": {
|
33
|
+
"lexical": ">=0.17.0-0",
|
34
|
+
"@lexical/table": ">=0.17.0-0",
|
35
|
+
"@lexical/utils": ">=0.17.0-0"
|
36
|
+
},
|
37
|
+
"sideEffects": false,
|
38
|
+
"devDependencies": {
|
39
|
+
"@testing-library/dom": "*",
|
40
|
+
"@testing-library/jest-dom": "*",
|
41
|
+
"@testing-library/user-event": "*",
|
42
|
+
"@repo/eslint-config": "*",
|
43
|
+
"eslint": "*",
|
44
|
+
"jsdom": "*",
|
45
|
+
"tslib": "*",
|
46
|
+
"typescript": "*",
|
47
|
+
"vite": "*",
|
48
|
+
"vite-plugin-dts": "*",
|
49
|
+
"vite-plugin-package-version": "*",
|
50
|
+
"vitest": "*"
|
51
|
+
},
|
52
|
+
"module": "dist/index.js",
|
53
|
+
"types": "dist/index.d.ts",
|
54
|
+
"files": [
|
55
|
+
"dist"
|
56
|
+
]
|
57
|
+
}
|