@haklex/rich-headless 0.0.11
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/LICENSE +28 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +403 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Innei
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Additional Terms and Conditions
|
|
25
|
+
|
|
26
|
+
----------------
|
|
27
|
+
|
|
28
|
+
Use of this software is governed by the terms of MIT and, in addition, by the terms and conditions described in the additional file (ADDITIONAL_TERMS.md). By using this software, you agree to abide by these additional terms and conditions.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DecoratorNode, ElementNode, Klass, LexicalNode, NodeKey, SerializedElementNode, SerializedLexicalNode } from 'lexical';
|
|
2
|
+
export declare const builtinNodes: Klass<LexicalNode>[];
|
|
3
|
+
export declare class SpoilerNode extends ElementNode {
|
|
4
|
+
static getType(): string;
|
|
5
|
+
static clone(node: SpoilerNode): SpoilerNode;
|
|
6
|
+
constructor(key?: NodeKey);
|
|
7
|
+
static importJSON(_json: SerializedElementNode): SpoilerNode;
|
|
8
|
+
exportJSON(): SerializedElementNode;
|
|
9
|
+
createDOM(): HTMLElement;
|
|
10
|
+
updateDOM(): boolean;
|
|
11
|
+
isInline(): boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class DetailsNode extends ElementNode {
|
|
14
|
+
__summary: string;
|
|
15
|
+
__open: boolean;
|
|
16
|
+
static getType(): string;
|
|
17
|
+
static clone(node: DetailsNode): DetailsNode;
|
|
18
|
+
constructor(key?: NodeKey);
|
|
19
|
+
static importJSON(json: SerializedElementNode & {
|
|
20
|
+
summary?: string;
|
|
21
|
+
open?: boolean;
|
|
22
|
+
}): DetailsNode;
|
|
23
|
+
exportJSON(): SerializedElementNode & {
|
|
24
|
+
summary: string;
|
|
25
|
+
open: boolean;
|
|
26
|
+
};
|
|
27
|
+
createDOM(): HTMLElement;
|
|
28
|
+
updateDOM(): boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare const ImageNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
31
|
+
export declare const VideoNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
32
|
+
export declare const LinkCardNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
33
|
+
export declare const KaTeXInlineNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
34
|
+
export declare const KaTeXBlockNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
35
|
+
export declare const MermaidNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
36
|
+
export declare const MentionNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
37
|
+
export declare const CodeBlockNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
38
|
+
export declare const FootnoteNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
39
|
+
export declare const FootnoteSectionNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
40
|
+
export declare const EmbedNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
41
|
+
export declare const CodeSnippetNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
42
|
+
export declare const GalleryNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
43
|
+
export declare const TldrawNode: import('lexical').KlassConstructor<typeof LexicalNode>;
|
|
44
|
+
export declare class BannerNode extends DecoratorNode<null> {
|
|
45
|
+
__bannerType: string;
|
|
46
|
+
__contentState: unknown;
|
|
47
|
+
static getType(): string;
|
|
48
|
+
constructor(key?: NodeKey);
|
|
49
|
+
static clone(node: BannerNode): BannerNode;
|
|
50
|
+
static importJSON(json: SerializedLexicalNode & {
|
|
51
|
+
bannerType?: string;
|
|
52
|
+
content?: unknown;
|
|
53
|
+
}): BannerNode;
|
|
54
|
+
exportJSON(): SerializedLexicalNode;
|
|
55
|
+
createDOM(): HTMLElement;
|
|
56
|
+
updateDOM(): boolean;
|
|
57
|
+
decorate(): null;
|
|
58
|
+
getTextContent(): string;
|
|
59
|
+
}
|
|
60
|
+
export declare class AlertQuoteNode extends DecoratorNode<null> {
|
|
61
|
+
__alertType: string;
|
|
62
|
+
__contentState: unknown;
|
|
63
|
+
static getType(): string;
|
|
64
|
+
constructor(key?: NodeKey);
|
|
65
|
+
static clone(node: AlertQuoteNode): AlertQuoteNode;
|
|
66
|
+
static importJSON(json: SerializedLexicalNode & {
|
|
67
|
+
alertType?: string;
|
|
68
|
+
content?: unknown;
|
|
69
|
+
}): AlertQuoteNode;
|
|
70
|
+
exportJSON(): SerializedLexicalNode;
|
|
71
|
+
createDOM(): HTMLElement;
|
|
72
|
+
updateDOM(): boolean;
|
|
73
|
+
decorate(): null;
|
|
74
|
+
getTextContent(): string;
|
|
75
|
+
}
|
|
76
|
+
export declare class GridContainerNode extends DecoratorNode<null> {
|
|
77
|
+
__cols: number;
|
|
78
|
+
__gap: string;
|
|
79
|
+
__cells: unknown[];
|
|
80
|
+
static getType(): string;
|
|
81
|
+
constructor(key?: NodeKey);
|
|
82
|
+
static clone(node: GridContainerNode): GridContainerNode;
|
|
83
|
+
static importJSON(json: SerializedLexicalNode & {
|
|
84
|
+
cols?: number;
|
|
85
|
+
gap?: string | number;
|
|
86
|
+
cells?: unknown[];
|
|
87
|
+
}): GridContainerNode;
|
|
88
|
+
exportJSON(): SerializedLexicalNode;
|
|
89
|
+
createDOM(): HTMLElement;
|
|
90
|
+
updateDOM(): boolean;
|
|
91
|
+
decorate(): null;
|
|
92
|
+
getTextContent(): string;
|
|
93
|
+
}
|
|
94
|
+
export declare const customHeadlessNodes: Klass<LexicalNode>[];
|
|
95
|
+
export declare const allHeadlessNodes: Klass<LexicalNode>[];
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,OAAO,EACL,aAAa,EACb,WAAW,EAEX,KAAK,KAAK,EAEV,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,SAAS,CAAA;AAIhB,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,EAa5C,CAAA;AAyBD,qBAAa,WAAY,SAAQ,WAAW;IAC1C,MAAM,CAAC,OAAO,IAAI,MAAM;IAGxB,MAAM,CAAC,KAAK,CAAC,IAAI,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AO,EAAE,OAAO,EAAE,CAAK;IAEvB,MAAM,CAAC,OAAO,IAAI,MAAM;gBAGZ,GAAG,CAAC,EAAE,OAAO;IAGzB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,iBAAiB,GAAG,iBAAiB;IAOxD,MAAM,CAAC,UAAU,CACf,IAAI,EAAE,qBAAqB,GAAG;QAC5B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACrB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAA;KAClB,GACA,iBAAiB;IASpB,UAAU,IAAI,qBAAqB;IASnC,SAAS,IAAI,WAAW;IAGxB,SAAS,IAAI,OAAO;IAGpB,QAAQ,IAAI,IAAI;IAGhB,cAAc,IAAI,MAAM;CAGzB;AAID,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,WAAW,CAAC,EAoBnD,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,WAAW,CAAC,EAGhD,CAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { CodeNode, CodeHighlightNode } from "@lexical/code";
|
|
2
|
+
import { HorizontalRuleNode } from "@lexical/extension";
|
|
3
|
+
import { LinkNode, AutoLinkNode } from "@lexical/link";
|
|
4
|
+
import { ListNode, ListItemNode } from "@lexical/list";
|
|
5
|
+
import { HeadingNode, QuoteNode } from "@lexical/rich-text";
|
|
6
|
+
import { TableNode, TableCellNode, TableRowNode } from "@lexical/table";
|
|
7
|
+
import { ElementNode, DecoratorNode } from "lexical";
|
|
8
|
+
const builtinNodes = [
|
|
9
|
+
HeadingNode,
|
|
10
|
+
QuoteNode,
|
|
11
|
+
ListNode,
|
|
12
|
+
ListItemNode,
|
|
13
|
+
LinkNode,
|
|
14
|
+
AutoLinkNode,
|
|
15
|
+
HorizontalRuleNode,
|
|
16
|
+
TableNode,
|
|
17
|
+
TableCellNode,
|
|
18
|
+
TableRowNode,
|
|
19
|
+
CodeNode,
|
|
20
|
+
CodeHighlightNode
|
|
21
|
+
];
|
|
22
|
+
function stubDOM() {
|
|
23
|
+
return document.createElement("span");
|
|
24
|
+
}
|
|
25
|
+
function extractText(state) {
|
|
26
|
+
if (!state || typeof state !== "object") return "";
|
|
27
|
+
const root = state.root;
|
|
28
|
+
if (!root) return "";
|
|
29
|
+
return walkChildren(root);
|
|
30
|
+
}
|
|
31
|
+
function walkChildren(node) {
|
|
32
|
+
const children = node.children;
|
|
33
|
+
if (!children) return node.text ?? "";
|
|
34
|
+
return children.map(walkChildren).join("\n");
|
|
35
|
+
}
|
|
36
|
+
class SpoilerNode extends ElementNode {
|
|
37
|
+
static getType() {
|
|
38
|
+
return "spoiler";
|
|
39
|
+
}
|
|
40
|
+
static clone(node) {
|
|
41
|
+
return new SpoilerNode(node.__key);
|
|
42
|
+
}
|
|
43
|
+
constructor(key) {
|
|
44
|
+
super(key);
|
|
45
|
+
}
|
|
46
|
+
static importJSON(_json) {
|
|
47
|
+
return new SpoilerNode();
|
|
48
|
+
}
|
|
49
|
+
exportJSON() {
|
|
50
|
+
return { ...super.exportJSON(), type: "spoiler", version: 1 };
|
|
51
|
+
}
|
|
52
|
+
createDOM() {
|
|
53
|
+
return stubDOM();
|
|
54
|
+
}
|
|
55
|
+
updateDOM() {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
isInline() {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class DetailsNode extends ElementNode {
|
|
63
|
+
constructor(key) {
|
|
64
|
+
super(key);
|
|
65
|
+
this.__summary = "";
|
|
66
|
+
this.__open = false;
|
|
67
|
+
}
|
|
68
|
+
static getType() {
|
|
69
|
+
return "details";
|
|
70
|
+
}
|
|
71
|
+
static clone(node) {
|
|
72
|
+
const n = new DetailsNode(node.__key);
|
|
73
|
+
n.__summary = node.__summary;
|
|
74
|
+
n.__open = node.__open;
|
|
75
|
+
return n;
|
|
76
|
+
}
|
|
77
|
+
static importJSON(json) {
|
|
78
|
+
const node = new DetailsNode();
|
|
79
|
+
node.__summary = json.summary ?? "";
|
|
80
|
+
node.__open = json.open ?? false;
|
|
81
|
+
return node;
|
|
82
|
+
}
|
|
83
|
+
exportJSON() {
|
|
84
|
+
return {
|
|
85
|
+
...super.exportJSON(),
|
|
86
|
+
type: "details",
|
|
87
|
+
summary: this.__summary,
|
|
88
|
+
open: this.__open
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
createDOM() {
|
|
92
|
+
return stubDOM();
|
|
93
|
+
}
|
|
94
|
+
updateDOM() {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function headlessDecorator(type, propKeys, defaults, inline = false) {
|
|
99
|
+
class Node extends DecoratorNode {
|
|
100
|
+
constructor(key) {
|
|
101
|
+
super(key);
|
|
102
|
+
for (const k of propKeys) {
|
|
103
|
+
this[`__${k}`] = defaults[k];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
static getType() {
|
|
107
|
+
return type;
|
|
108
|
+
}
|
|
109
|
+
static clone(node) {
|
|
110
|
+
const n = new Node(node.__key);
|
|
111
|
+
for (const k of propKeys) {
|
|
112
|
+
n[`__${k}`] = node[`__${k}`];
|
|
113
|
+
}
|
|
114
|
+
return n;
|
|
115
|
+
}
|
|
116
|
+
static importJSON(json) {
|
|
117
|
+
const node = new Node();
|
|
118
|
+
for (const k of propKeys) {
|
|
119
|
+
node[`__${k}`] = json[k] ?? defaults[k];
|
|
120
|
+
}
|
|
121
|
+
return node;
|
|
122
|
+
}
|
|
123
|
+
exportJSON() {
|
|
124
|
+
const out = { type, version: 1 };
|
|
125
|
+
for (const k of propKeys) {
|
|
126
|
+
out[k] = this[`__${k}`];
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
createDOM(_config) {
|
|
131
|
+
return stubDOM();
|
|
132
|
+
}
|
|
133
|
+
updateDOM() {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
decorate(_editor, _config) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
isInline() {
|
|
140
|
+
return inline;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return Node;
|
|
144
|
+
}
|
|
145
|
+
const ImageNode = headlessDecorator(
|
|
146
|
+
"image",
|
|
147
|
+
["src", "altText", "width", "height", "caption", "thumbhash", "accent"],
|
|
148
|
+
{
|
|
149
|
+
src: "",
|
|
150
|
+
altText: "",
|
|
151
|
+
width: void 0,
|
|
152
|
+
height: void 0,
|
|
153
|
+
caption: void 0,
|
|
154
|
+
thumbhash: void 0,
|
|
155
|
+
accent: void 0
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
const VideoNode = headlessDecorator(
|
|
159
|
+
"video",
|
|
160
|
+
["src", "poster", "width", "height"],
|
|
161
|
+
{ src: "", poster: void 0, width: void 0, height: void 0 }
|
|
162
|
+
);
|
|
163
|
+
const LinkCardNode = headlessDecorator(
|
|
164
|
+
"link-card",
|
|
165
|
+
["url", "source", "id", "title", "description", "favicon", "image"],
|
|
166
|
+
{
|
|
167
|
+
url: "",
|
|
168
|
+
source: void 0,
|
|
169
|
+
id: void 0,
|
|
170
|
+
title: void 0,
|
|
171
|
+
description: void 0,
|
|
172
|
+
favicon: void 0,
|
|
173
|
+
image: void 0
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
const KaTeXInlineNode = headlessDecorator(
|
|
177
|
+
"katex-inline",
|
|
178
|
+
["equation"],
|
|
179
|
+
{ equation: "" },
|
|
180
|
+
true
|
|
181
|
+
);
|
|
182
|
+
const KaTeXBlockNode = headlessDecorator("katex-block", ["equation"], {
|
|
183
|
+
equation: ""
|
|
184
|
+
});
|
|
185
|
+
const MermaidNode = headlessDecorator("mermaid", ["diagram"], {
|
|
186
|
+
diagram: ""
|
|
187
|
+
});
|
|
188
|
+
const MentionNode = headlessDecorator(
|
|
189
|
+
"mention",
|
|
190
|
+
["platform", "handle", "displayName"],
|
|
191
|
+
{ platform: "", handle: "", displayName: void 0 },
|
|
192
|
+
true
|
|
193
|
+
);
|
|
194
|
+
const CodeBlockNode = headlessDecorator(
|
|
195
|
+
"code-block",
|
|
196
|
+
["code", "language"],
|
|
197
|
+
{ code: "", language: "" }
|
|
198
|
+
);
|
|
199
|
+
const FootnoteNode = headlessDecorator(
|
|
200
|
+
"footnote",
|
|
201
|
+
["identifier"],
|
|
202
|
+
{ identifier: "" },
|
|
203
|
+
true
|
|
204
|
+
);
|
|
205
|
+
const FootnoteSectionNode = headlessDecorator(
|
|
206
|
+
"footnote-section",
|
|
207
|
+
["definitions"],
|
|
208
|
+
{ definitions: {} }
|
|
209
|
+
);
|
|
210
|
+
const EmbedNode = headlessDecorator("embed", ["url", "source"], {
|
|
211
|
+
url: "",
|
|
212
|
+
source: null
|
|
213
|
+
});
|
|
214
|
+
const CodeSnippetNode = headlessDecorator("code-snippet", ["files"], {
|
|
215
|
+
files: []
|
|
216
|
+
});
|
|
217
|
+
const GalleryNode = headlessDecorator("gallery", ["images", "layout"], {
|
|
218
|
+
images: [],
|
|
219
|
+
layout: "grid"
|
|
220
|
+
});
|
|
221
|
+
const TldrawNode = headlessDecorator("tldraw", ["snapshot"], {
|
|
222
|
+
snapshot: ""
|
|
223
|
+
});
|
|
224
|
+
class BannerNode extends DecoratorNode {
|
|
225
|
+
constructor(key) {
|
|
226
|
+
super(key);
|
|
227
|
+
this.__bannerType = "note";
|
|
228
|
+
this.__contentState = null;
|
|
229
|
+
}
|
|
230
|
+
static getType() {
|
|
231
|
+
return "banner";
|
|
232
|
+
}
|
|
233
|
+
static clone(node) {
|
|
234
|
+
const n = new BannerNode(node.__key);
|
|
235
|
+
n.__bannerType = node.__bannerType;
|
|
236
|
+
n.__contentState = node.__contentState;
|
|
237
|
+
return n;
|
|
238
|
+
}
|
|
239
|
+
static importJSON(json) {
|
|
240
|
+
const node = new BannerNode();
|
|
241
|
+
node.__bannerType = json.bannerType ?? "note";
|
|
242
|
+
node.__contentState = json.content ?? null;
|
|
243
|
+
return node;
|
|
244
|
+
}
|
|
245
|
+
exportJSON() {
|
|
246
|
+
return {
|
|
247
|
+
type: "banner",
|
|
248
|
+
version: 1,
|
|
249
|
+
bannerType: this.__bannerType,
|
|
250
|
+
content: this.__contentState
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
createDOM() {
|
|
254
|
+
return stubDOM();
|
|
255
|
+
}
|
|
256
|
+
updateDOM() {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
decorate() {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
getTextContent() {
|
|
263
|
+
return extractText(this.__contentState);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
class AlertQuoteNode extends DecoratorNode {
|
|
267
|
+
constructor(key) {
|
|
268
|
+
super(key);
|
|
269
|
+
this.__alertType = "note";
|
|
270
|
+
this.__contentState = null;
|
|
271
|
+
}
|
|
272
|
+
static getType() {
|
|
273
|
+
return "alert-quote";
|
|
274
|
+
}
|
|
275
|
+
static clone(node) {
|
|
276
|
+
const n = new AlertQuoteNode(node.__key);
|
|
277
|
+
n.__alertType = node.__alertType;
|
|
278
|
+
n.__contentState = node.__contentState;
|
|
279
|
+
return n;
|
|
280
|
+
}
|
|
281
|
+
static importJSON(json) {
|
|
282
|
+
const node = new AlertQuoteNode();
|
|
283
|
+
node.__alertType = json.alertType ?? "note";
|
|
284
|
+
node.__contentState = json.content ?? null;
|
|
285
|
+
return node;
|
|
286
|
+
}
|
|
287
|
+
exportJSON() {
|
|
288
|
+
return {
|
|
289
|
+
type: "alert-quote",
|
|
290
|
+
version: 1,
|
|
291
|
+
alertType: this.__alertType,
|
|
292
|
+
content: this.__contentState
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
createDOM() {
|
|
296
|
+
return stubDOM();
|
|
297
|
+
}
|
|
298
|
+
updateDOM() {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
decorate() {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
getTextContent() {
|
|
305
|
+
return extractText(this.__contentState);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
class GridContainerNode extends DecoratorNode {
|
|
309
|
+
constructor(key) {
|
|
310
|
+
super(key);
|
|
311
|
+
this.__cols = 2;
|
|
312
|
+
this.__gap = "16px";
|
|
313
|
+
this.__cells = [];
|
|
314
|
+
}
|
|
315
|
+
static getType() {
|
|
316
|
+
return "grid-container";
|
|
317
|
+
}
|
|
318
|
+
static clone(node) {
|
|
319
|
+
const n = new GridContainerNode(node.__key);
|
|
320
|
+
n.__cols = node.__cols;
|
|
321
|
+
n.__gap = node.__gap;
|
|
322
|
+
n.__cells = node.__cells;
|
|
323
|
+
return n;
|
|
324
|
+
}
|
|
325
|
+
static importJSON(json) {
|
|
326
|
+
const node = new GridContainerNode();
|
|
327
|
+
node.__cols = json.cols ?? 2;
|
|
328
|
+
const rawGap = json.gap;
|
|
329
|
+
node.__gap = typeof rawGap === "number" ? `${rawGap}px` : rawGap ?? "16px";
|
|
330
|
+
node.__cells = json.cells ?? [];
|
|
331
|
+
return node;
|
|
332
|
+
}
|
|
333
|
+
exportJSON() {
|
|
334
|
+
return {
|
|
335
|
+
type: "grid-container",
|
|
336
|
+
version: 1,
|
|
337
|
+
cols: this.__cols,
|
|
338
|
+
gap: this.__gap,
|
|
339
|
+
cells: this.__cells
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
createDOM() {
|
|
343
|
+
return stubDOM();
|
|
344
|
+
}
|
|
345
|
+
updateDOM() {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
decorate() {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
getTextContent() {
|
|
352
|
+
return this.__cells.map((cell) => extractText(cell)).join("\n");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const customHeadlessNodes = [
|
|
356
|
+
SpoilerNode,
|
|
357
|
+
DetailsNode,
|
|
358
|
+
ImageNode,
|
|
359
|
+
VideoNode,
|
|
360
|
+
LinkCardNode,
|
|
361
|
+
KaTeXInlineNode,
|
|
362
|
+
KaTeXBlockNode,
|
|
363
|
+
MermaidNode,
|
|
364
|
+
MentionNode,
|
|
365
|
+
CodeBlockNode,
|
|
366
|
+
FootnoteNode,
|
|
367
|
+
FootnoteSectionNode,
|
|
368
|
+
EmbedNode,
|
|
369
|
+
CodeSnippetNode,
|
|
370
|
+
GalleryNode,
|
|
371
|
+
TldrawNode,
|
|
372
|
+
BannerNode,
|
|
373
|
+
AlertQuoteNode,
|
|
374
|
+
GridContainerNode
|
|
375
|
+
];
|
|
376
|
+
const allHeadlessNodes = [
|
|
377
|
+
...builtinNodes,
|
|
378
|
+
...customHeadlessNodes
|
|
379
|
+
];
|
|
380
|
+
export {
|
|
381
|
+
AlertQuoteNode,
|
|
382
|
+
BannerNode,
|
|
383
|
+
CodeBlockNode,
|
|
384
|
+
CodeSnippetNode,
|
|
385
|
+
DetailsNode,
|
|
386
|
+
EmbedNode,
|
|
387
|
+
FootnoteNode,
|
|
388
|
+
FootnoteSectionNode,
|
|
389
|
+
GalleryNode,
|
|
390
|
+
GridContainerNode,
|
|
391
|
+
ImageNode,
|
|
392
|
+
KaTeXBlockNode,
|
|
393
|
+
KaTeXInlineNode,
|
|
394
|
+
LinkCardNode,
|
|
395
|
+
MentionNode,
|
|
396
|
+
MermaidNode,
|
|
397
|
+
SpoilerNode,
|
|
398
|
+
TldrawNode,
|
|
399
|
+
VideoNode,
|
|
400
|
+
allHeadlessNodes,
|
|
401
|
+
builtinNodes,
|
|
402
|
+
customHeadlessNodes
|
|
403
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@haklex/rich-headless",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Headless Lexical node registry for server-side parsing (no React)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.mjs",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@lexical/code": "^0.40.0",
|
|
19
|
+
"@lexical/extension": "^0.40.0",
|
|
20
|
+
"@lexical/link": "^0.40.0",
|
|
21
|
+
"@lexical/list": "^0.40.0",
|
|
22
|
+
"@lexical/rich-text": "^0.40.0",
|
|
23
|
+
"@lexical/table": "^0.40.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"lexical": "^0.40.0",
|
|
27
|
+
"typescript": "^5.9.0",
|
|
28
|
+
"vite": "^7.3.1",
|
|
29
|
+
"vite-plugin-dts": "^4.5.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"lexical": "^0.40.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "vite build",
|
|
39
|
+
"dev:build": "vite build --watch"
|
|
40
|
+
},
|
|
41
|
+
"types": "./dist/index.d.ts"
|
|
42
|
+
}
|