@etrepum/lexical-builder-markdown 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/dist/MarkdownExport.d.ts +8 -0
- package/dist/MarkdownExport.d.ts.map +1 -0
- package/dist/MarkdownImport.d.ts +8 -0
- package/dist/MarkdownImport.d.ts.map +1 -0
- package/dist/MarkdownShortcutsPlan.d.ts +13 -0
- package/dist/MarkdownShortcutsPlan.d.ts.map +1 -0
- package/dist/MarkdownTransformersPlan.d.ts +15 -0
- package/dist/MarkdownTransformersPlan.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +365 -0
- package/dist/shared/invariant.d.ts +9 -0
- package/dist/shared/invariant.d.ts.map +1 -0
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ElementNode } from 'lexical';
|
2
|
+
import { MarkdownTransformerOptions, TransformersByType } from './types';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Renders string from markdown. The selection is moved to the start after the operation.
|
6
|
+
*/
|
7
|
+
export declare function createMarkdownExport(byType: TransformersByType, { shouldPreserveNewlines }: MarkdownTransformerOptions): (node?: ElementNode) => string;
|
8
|
+
//# sourceMappingURL=MarkdownExport.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MarkdownExport.d.ts","sourceRoot":"","sources":["../src/MarkdownExport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,KAAK,EACV,WAAW,EAIZ,MAAM,SAAS,CAAC;AAajB,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE9E;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,kBAAkB,EAC1B,EAAE,sBAAsB,EAAE,EAAE,0BAA0B,GACrD,CAAC,IAAI,CAAC,EAAE,WAAW,KAAK,MAAM,CAsChC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ElementNode } from 'lexical';
|
2
|
+
import { MarkdownTransformerOptions, TransformersByType } from './types';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Creates an array of ElementNode from the given markdown string
|
6
|
+
*/
|
7
|
+
export declare function createMarkdownImport(byType: TransformersByType, defaultOptions: MarkdownTransformerOptions): (markdownString: string, options?: MarkdownTransformerOptions) => ElementNode[];
|
8
|
+
//# sourceMappingURL=MarkdownImport.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../src/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH,OAAO,EAML,WAAW,EACZ,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AASzE;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,kBAAkB,EAC1B,cAAc,EAAE,0BAA0B,GACzC,CACD,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,0BAA0B,KACjC,WAAW,EAAE,CA0DjB"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { LexicalEditor } from 'lexical';
|
2
|
+
import { TransformersByType } from './types';
|
3
|
+
|
4
|
+
export declare function registerMarkdownShortcuts(editor: LexicalEditor, byType: TransformersByType): () => void;
|
5
|
+
export interface MarkdownShortcutsConfig {
|
6
|
+
enabled: boolean;
|
7
|
+
}
|
8
|
+
export interface MarkdownShortcutsOutput {
|
9
|
+
getEnabled: () => boolean;
|
10
|
+
setEnabled: (enabled: boolean) => void;
|
11
|
+
}
|
12
|
+
export declare const MarkdownShortcutsPlan: import('@etrepum/lexical-builder').LexicalPlan<MarkdownShortcutsConfig, "@etrepum/lexical-builder-markdown/MarkdownShortcuts", MarkdownShortcutsOutput, unknown>;
|
13
|
+
//# sourceMappingURL=MarkdownShortcutsPlan.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MarkdownShortcutsPlan.d.ts","sourceRoot":"","sources":["../src/MarkdownShortcutsPlan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAEL,KAAK,aAAa,EAUnB,MAAM,SAAS,CAAC;AAKjB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA0SlD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,kBAAkB,GACzB,MAAM,IAAI,CA+FZ;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,OAAO,CAAC;CAClB;AACD,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,qBAAqB,kKA6BhC,CAAC"}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { createMarkdownImport } from './MarkdownImport';
|
2
|
+
import { MarkdownTransformerOptions, TransformersByType } from './types';
|
3
|
+
import { createMarkdownExport } from './MarkdownExport';
|
4
|
+
|
5
|
+
export type MarkdownTransformersConfig = MarkdownTransformerOptions & {
|
6
|
+
[K in keyof TransformersByType as `${K}Transformers`]: TransformersByType[K];
|
7
|
+
};
|
8
|
+
export interface MarkdownTransformersOutput {
|
9
|
+
readonly transformerOptions: MarkdownTransformerOptions;
|
10
|
+
readonly transformersByType: TransformersByType;
|
11
|
+
readonly $markdownImport: ReturnType<typeof createMarkdownImport>;
|
12
|
+
readonly $markdownExport: ReturnType<typeof createMarkdownExport>;
|
13
|
+
}
|
14
|
+
export declare const MarkdownTransformersPlan: import('@etrepum/lexical-builder').LexicalPlan<MarkdownTransformersConfig, "@etrepum/lexical-builder-markdown/MarkdownTransformers", MarkdownTransformersOutput, MarkdownTransformersOutput>;
|
15
|
+
//# sourceMappingURL=MarkdownTransformersPlan.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"MarkdownTransformersPlan.d.ts","sourceRoot":"","sources":["../src/MarkdownTransformersPlan.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,MAAM,0BAA0B,GAAG,0BAA0B,GAAG;KACnE,CAAC,IAAI,MAAM,kBAAkB,IAAI,GAAG,CAAC,cAAc,GAAG,kBAAkB,CAAC,CAAC,CAAC;CAC7E,CAAC;AASF,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,kBAAkB,EAAE,0BAA0B,CAAC;IACxD,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAChD,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;IAClE,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;CACnE;AAED,eAAO,MAAM,wBAAwB,8LAuCnC,CAAC"}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
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 { type MarkdownTransformerOptions, type TransformersByType, } from './types';
|
9
|
+
export { type MarkdownTransformersConfig, type MarkdownTransformersOutput, MarkdownTransformersPlan, } from './MarkdownTransformersPlan';
|
10
|
+
export declare const PACKAGE_VERSION: string;
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AACpC,eAAO,MAAM,eAAe,EAAE,MAAwC,CAAC"}
|
package/dist/index.js
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
import { definePlan as b, RichTextPlan as L, safeCast as D, getKnownTypesAndNodes as y, provideOutput as j } from "@etrepum/lexical-builder";
|
2
|
+
import { ELEMENT_TRANSFORMERS as z, TEXT_FORMAT_TRANSFORMERS as K, TEXT_MATCH_TRANSFORMERS as W } from "@lexical/markdown";
|
3
|
+
import { $createCodeNode as X } from "@lexical/code";
|
4
|
+
import { $isListNode as x, $isListItemNode as G } from "@lexical/list";
|
5
|
+
import { $isQuoteNode as U } from "@lexical/rich-text";
|
6
|
+
import { $findMatchingParent as H, IS_SAFARI as N, IS_IOS as E, IS_APPLE_WEBKIT as $ } from "@lexical/utils";
|
7
|
+
import { $getSelection as S, $setSelection as Q, $isParagraphNode as P, $isTextNode as p, $createParagraphNode as _, $isElementNode as m, $createTextNode as F, $createLineBreakNode as V, $isRootOrShadowRoot as Y, $getRoot as q, $isDecoratorNode as k, $isLineBreakNode as J } from "lexical";
|
8
|
+
const R = /[!-/:-@[-`{-~\s]/, Z = /^\s{0,3}$/;
|
9
|
+
function T(e) {
|
10
|
+
if (!P(e))
|
11
|
+
return !1;
|
12
|
+
const t = e.getFirstChild();
|
13
|
+
return t == null || e.getChildrenSize() === 1 && p(t) && Z.test(t.getTextContent());
|
14
|
+
}
|
15
|
+
function ee(e) {
|
16
|
+
return function(...n) {
|
17
|
+
const i = S(), s = i ? i.clone() : null, r = e(...n), c = S(), o = s && s.is(i) && !Object.isFrozen(i) ? i : s;
|
18
|
+
return c !== o && Q(o), r;
|
19
|
+
};
|
20
|
+
}
|
21
|
+
function u(e, t, ...n) {
|
22
|
+
if (!e)
|
23
|
+
throw new Error(
|
24
|
+
n.reduce((i, s) => i.replace("%s", String(s)), t || "")
|
25
|
+
);
|
26
|
+
}
|
27
|
+
const w = /^[ \t]*```(\w{1,10})?\s?$/;
|
28
|
+
function te(e, t) {
|
29
|
+
const n = ie(
|
30
|
+
e.textFormat || []
|
31
|
+
);
|
32
|
+
return function(s, { shouldPreserveNewlines: r } = t) {
|
33
|
+
const c = s.split(`
|
34
|
+
`), o = c.length, l = _();
|
35
|
+
for (let f = 0; f < o; f++) {
|
36
|
+
const A = c[f], [B, I] = oe(c, f, l);
|
37
|
+
if (B != null) {
|
38
|
+
f = I;
|
39
|
+
continue;
|
40
|
+
}
|
41
|
+
ne(
|
42
|
+
A,
|
43
|
+
l,
|
44
|
+
e.element,
|
45
|
+
n,
|
46
|
+
e.textMatch
|
47
|
+
);
|
48
|
+
}
|
49
|
+
const a = [];
|
50
|
+
for (let f = l.getFirstChild(); f; f = f.getNextSibling())
|
51
|
+
u(
|
52
|
+
m(f),
|
53
|
+
"markdownImport: Expected child of type %s to be an ElementNode",
|
54
|
+
f.getType()
|
55
|
+
), (r || !T(f)) && a.push(f);
|
56
|
+
return l.clear(), a;
|
57
|
+
};
|
58
|
+
}
|
59
|
+
function ne(e, t, n, i, s) {
|
60
|
+
const r = e.trim(), c = F(r), o = _();
|
61
|
+
o.append(c), t.append(o);
|
62
|
+
for (const { regExp: l, replace: a } of n) {
|
63
|
+
const f = e.match(l);
|
64
|
+
if (f) {
|
65
|
+
c.setTextContent(e.slice(f[0].length)), a(o, [c], f, !0);
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
if (d(
|
70
|
+
c,
|
71
|
+
i,
|
72
|
+
s
|
73
|
+
), o.isAttached() && r.length > 0) {
|
74
|
+
const l = o.getPreviousSibling();
|
75
|
+
if (P(l) || U(l) || x(l)) {
|
76
|
+
let a = l;
|
77
|
+
if (x(l)) {
|
78
|
+
const f = l.getLastDescendant();
|
79
|
+
f == null ? a = null : a = H(f, G);
|
80
|
+
}
|
81
|
+
a != null && a.getTextContentSize() > 0 && (a.splice(a.getChildrenSize(), 0, [
|
82
|
+
V(),
|
83
|
+
...o.getChildren()
|
84
|
+
]), o.remove());
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
function oe(e, t, n) {
|
89
|
+
const i = e[t].match(w);
|
90
|
+
if (i) {
|
91
|
+
let s = t;
|
92
|
+
const r = e.length;
|
93
|
+
for (; ++s < r; )
|
94
|
+
if (e[s].match(w)) {
|
95
|
+
const o = X(i[1]), l = F(
|
96
|
+
e.slice(t + 1, s).join(`
|
97
|
+
`)
|
98
|
+
);
|
99
|
+
return o.append(l), n.append(o), [o, s];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
return [null, t];
|
103
|
+
}
|
104
|
+
function d(e, t, n) {
|
105
|
+
const i = e.getTextContent(), s = re(i, t);
|
106
|
+
if (!s) {
|
107
|
+
O(e, n);
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
u(
|
111
|
+
s[1] !== void 0 && s[2] !== void 0,
|
112
|
+
"importTextMatchTransformers: expecting match with two groups"
|
113
|
+
);
|
114
|
+
let r, c, o;
|
115
|
+
if (s[0] === i)
|
116
|
+
r = e;
|
117
|
+
else {
|
118
|
+
const a = s.index || 0, f = a + s[0].length;
|
119
|
+
a === 0 ? [r, c] = e.splitText(f) : [o, r, c] = e.splitText(
|
120
|
+
a,
|
121
|
+
f
|
122
|
+
);
|
123
|
+
}
|
124
|
+
u(
|
125
|
+
r !== void 0,
|
126
|
+
"importTextMatchTransformers: currentNode must be defined"
|
127
|
+
), r.setTextContent(s[2]);
|
128
|
+
const l = t.transformersByTag[s[1]];
|
129
|
+
if (l)
|
130
|
+
for (const a of l.format)
|
131
|
+
r.hasFormat(a) || r.toggleFormat(a);
|
132
|
+
r.hasFormat("code") || d(
|
133
|
+
r,
|
134
|
+
t,
|
135
|
+
n
|
136
|
+
), o && d(
|
137
|
+
o,
|
138
|
+
t,
|
139
|
+
n
|
140
|
+
), c && d(
|
141
|
+
c,
|
142
|
+
t,
|
143
|
+
n
|
144
|
+
);
|
145
|
+
}
|
146
|
+
function O(e, t) {
|
147
|
+
let n = e;
|
148
|
+
e:
|
149
|
+
for (; n; ) {
|
150
|
+
for (const i of t) {
|
151
|
+
const s = n.getTextContent().match(i.importRegExp);
|
152
|
+
if (!s)
|
153
|
+
continue;
|
154
|
+
const r = s.index || 0, c = r + s[0].length;
|
155
|
+
let o, l;
|
156
|
+
if (r === 0) {
|
157
|
+
const a = n.splitText(c);
|
158
|
+
u(
|
159
|
+
a[0] !== void 0 && a[1] !== void 0,
|
160
|
+
"importTextMatchTransformers: splitText expected two nodes"
|
161
|
+
), [o, n] = a;
|
162
|
+
} else {
|
163
|
+
const a = n.splitText(r, c);
|
164
|
+
u(
|
165
|
+
a[1] !== void 0 && a[2] !== void 0,
|
166
|
+
"importTextMatchTransformers: splitText expected three nodes"
|
167
|
+
), [, o, l] = a, l && O(l, t);
|
168
|
+
}
|
169
|
+
i.replace(o, s);
|
170
|
+
continue e;
|
171
|
+
}
|
172
|
+
break;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
function re(e, t) {
|
176
|
+
const n = e.match(t.openTagsRegExp);
|
177
|
+
if (n == null)
|
178
|
+
return null;
|
179
|
+
for (const i of n) {
|
180
|
+
const s = i.replace(/^\s/, ""), r = t.fullMatchRegExpByTag[s];
|
181
|
+
if (r == null)
|
182
|
+
continue;
|
183
|
+
const c = e.match(r), o = t.transformersByTag[s];
|
184
|
+
if (c != null && o != null) {
|
185
|
+
if (o.intraword !== !1)
|
186
|
+
return c;
|
187
|
+
const { index: l = 0 } = c, a = e[l - 1], f = e[l + c[0].length];
|
188
|
+
if ((!a || R.test(a)) && (!f || R.test(f)))
|
189
|
+
return c;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
return null;
|
193
|
+
}
|
194
|
+
function ie(e) {
|
195
|
+
const t = {}, n = {}, i = [], s = "(?<![\\\\])";
|
196
|
+
for (const r of e) {
|
197
|
+
const { tag: c } = r;
|
198
|
+
t[c] = r;
|
199
|
+
const o = c.replace(/(\*|\^|\+)/g, "\\$1");
|
200
|
+
i.push(o), N || E || $ ? n[c] = new RegExp(
|
201
|
+
`(${o})(?![${o}\\s])(.*?[^${o}\\s])${o}(?!${o})`
|
202
|
+
) : n[c] = new RegExp(
|
203
|
+
`(?<![\\\\${o}])(${o})((\\\\${o})?.*?[^${o}\\s](\\\\${o})?)((?<!\\\\)|(?<=\\\\\\\\))(${o})(?![\\\\${o}])`
|
204
|
+
);
|
205
|
+
}
|
206
|
+
return {
|
207
|
+
// Reg exp to find open tag + content + close tag
|
208
|
+
fullMatchRegExpByTag: n,
|
209
|
+
// Reg exp to find opening tags
|
210
|
+
openTagsRegExp: new RegExp(
|
211
|
+
(N || E || $ ? "" : `${s}`) + "(" + i.join("|") + ")",
|
212
|
+
"g"
|
213
|
+
),
|
214
|
+
transformersByTag: t
|
215
|
+
};
|
216
|
+
}
|
217
|
+
function se(e, { shouldPreserveNewlines: t }) {
|
218
|
+
const n = !t, i = e.textFormat.filter(
|
219
|
+
(s) => s.format.length === 1
|
220
|
+
);
|
221
|
+
return function(r = q()) {
|
222
|
+
const c = [], o = Y(r) ? r.getChildren() : [r];
|
223
|
+
for (let l = 0; l < o.length; l++) {
|
224
|
+
const a = o[l], f = ce(
|
225
|
+
a,
|
226
|
+
e.element,
|
227
|
+
i,
|
228
|
+
e.textMatch
|
229
|
+
);
|
230
|
+
f != null && c.push(
|
231
|
+
// separate consecutive group of texts with a line break: eg. ["hello", "world"] -> ["hello", "\nworld"]
|
232
|
+
n && l > 0 && !T(a) && !T(o[l - 1]) ? `
|
233
|
+
`.concat(f) : f
|
234
|
+
);
|
235
|
+
}
|
236
|
+
return c.join(`
|
237
|
+
`);
|
238
|
+
};
|
239
|
+
}
|
240
|
+
function ce(e, t, n, i) {
|
241
|
+
for (const s of t) {
|
242
|
+
const r = s.export(
|
243
|
+
e,
|
244
|
+
(c) => g(c, n, i)
|
245
|
+
);
|
246
|
+
if (r != null)
|
247
|
+
return r;
|
248
|
+
}
|
249
|
+
return m(e) ? g(e, n, i) : k(e) ? e.getTextContent() : null;
|
250
|
+
}
|
251
|
+
function g(e, t, n) {
|
252
|
+
const i = [], s = e.getChildren();
|
253
|
+
e:
|
254
|
+
for (const r of s) {
|
255
|
+
for (const c of n) {
|
256
|
+
const o = c.export(
|
257
|
+
r,
|
258
|
+
(l) => g(
|
259
|
+
l,
|
260
|
+
t,
|
261
|
+
n
|
262
|
+
),
|
263
|
+
(l, a) => C(l, a, t)
|
264
|
+
);
|
265
|
+
if (o != null) {
|
266
|
+
i.push(o);
|
267
|
+
continue e;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
J(r) ? i.push(`
|
271
|
+
`) : p(r) ? i.push(
|
272
|
+
C(r, r.getTextContent(), t)
|
273
|
+
) : m(r) ? i.push(
|
274
|
+
g(r, t, n)
|
275
|
+
) : k(r) && i.push(r.getTextContent());
|
276
|
+
}
|
277
|
+
return i.join("");
|
278
|
+
}
|
279
|
+
function C(e, t, n) {
|
280
|
+
const i = t.trim();
|
281
|
+
let s = i;
|
282
|
+
const r = /* @__PURE__ */ new Set();
|
283
|
+
for (const c of n) {
|
284
|
+
const o = c.format[0], l = c.tag;
|
285
|
+
if (u(
|
286
|
+
o !== void 0,
|
287
|
+
"TextFormatTransformer for tag %s has empty format array",
|
288
|
+
l
|
289
|
+
), h(e, o) && !r.has(o)) {
|
290
|
+
r.add(o);
|
291
|
+
const a = v(e, !0);
|
292
|
+
h(a, o) || (s = l + s);
|
293
|
+
const f = v(e, !1);
|
294
|
+
h(f, o) || (s += l);
|
295
|
+
}
|
296
|
+
}
|
297
|
+
return t.replace(i, () => s);
|
298
|
+
}
|
299
|
+
function v(e, t) {
|
300
|
+
let n = t ? e.getPreviousSibling() : e.getNextSibling();
|
301
|
+
if (!n) {
|
302
|
+
const i = e.getParentOrThrow();
|
303
|
+
i.isInline() && (n = t ? i.getPreviousSibling() : i.getNextSibling());
|
304
|
+
}
|
305
|
+
for (; n; ) {
|
306
|
+
if (m(n)) {
|
307
|
+
if (!n.isInline())
|
308
|
+
break;
|
309
|
+
const i = t ? n.getLastDescendant() : n.getFirstDescendant();
|
310
|
+
if (p(i))
|
311
|
+
return i;
|
312
|
+
n = t ? n.getPreviousSibling() : n.getNextSibling();
|
313
|
+
}
|
314
|
+
if (p(n))
|
315
|
+
return n;
|
316
|
+
if (!m(n))
|
317
|
+
return null;
|
318
|
+
}
|
319
|
+
return null;
|
320
|
+
}
|
321
|
+
function h(e, t) {
|
322
|
+
return p(e) && e.hasFormat(t);
|
323
|
+
}
|
324
|
+
function M({ nodes: e }, t) {
|
325
|
+
const n = e.has.bind(e);
|
326
|
+
return t.filter((i) => i.dependencies.every(n));
|
327
|
+
}
|
328
|
+
const ge = b({
|
329
|
+
name: "@etrepum/lexical-builder-markdown/MarkdownTransformers",
|
330
|
+
dependencies: [L],
|
331
|
+
config: D({
|
332
|
+
elementTransformers: z,
|
333
|
+
textFormatTransformers: K,
|
334
|
+
textMatchTransformers: W,
|
335
|
+
shouldPreserveNewlines: !1
|
336
|
+
}),
|
337
|
+
// For now we replace the transformer arrays with the default
|
338
|
+
// shallowMergeConfig. I think ideally these should be additive
|
339
|
+
init(e, t, n) {
|
340
|
+
const i = y(e), s = {
|
341
|
+
shouldPreserveNewlines: t.shouldPreserveNewlines
|
342
|
+
}, r = {
|
343
|
+
// Only register transforms for nodes that are configured
|
344
|
+
element: M(i, t.elementTransformers),
|
345
|
+
textMatch: M(i, t.textMatchTransformers),
|
346
|
+
textFormat: t.textFormatTransformers
|
347
|
+
}, c = ee(
|
348
|
+
te(r, s)
|
349
|
+
), o = se(
|
350
|
+
r,
|
351
|
+
s
|
352
|
+
);
|
353
|
+
return {
|
354
|
+
transformerOptions: s,
|
355
|
+
transformersByType: r,
|
356
|
+
$markdownExport: o,
|
357
|
+
$markdownImport: c
|
358
|
+
};
|
359
|
+
},
|
360
|
+
register: (e, t, n) => j(n.getInitResult())
|
361
|
+
}), he = "0.0.25";
|
362
|
+
export {
|
363
|
+
ge as MarkdownTransformersPlan,
|
364
|
+
he as PACKAGE_VERSION
|
365
|
+
};
|
@@ -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/dist/types.d.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Transformer } from '@lexical/markdown';
|
2
|
+
|
3
|
+
export interface MarkdownTransformerOptions {
|
4
|
+
shouldPreserveNewlines: boolean;
|
5
|
+
}
|
6
|
+
type Filter<T, U> = T extends U ? T : never;
|
7
|
+
type KebabToCamel<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamel<U>>}` : S;
|
8
|
+
export type TransformersByType = {
|
9
|
+
readonly [K in Transformer["type"] as KebabToCamel<K>]: Filter<Transformer, {
|
10
|
+
type: K;
|
11
|
+
}>[];
|
12
|
+
};
|
13
|
+
export {};
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,MAAM,WAAW,0BAA0B;IACzC,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAED,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAC5C,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,CAAC,EAAE,GACnE,GAAG,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,GACpC,CAAC,CAAC;AAEN,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,CAC5D,WAAW,EACX;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CACZ,EAAE;CACJ,CAAC"}
|
package/dist/utils.d.ts
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
import { ParagraphNode, Spread, LexicalNode } from 'lexical';
|
2
|
+
|
3
|
+
export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string): Readonly<Record<string, Array<T>>>;
|
4
|
+
export declare const PUNCTUATION_OR_SPACE: RegExp;
|
5
|
+
declare const EmptyParagraphNodeBrand: unique symbol;
|
6
|
+
export declare function $isEmptyParagraph(node: LexicalNode | undefined | null): node is Spread<{
|
7
|
+
[EmptyParagraphNodeBrand]: never;
|
8
|
+
}, ParagraphNode>;
|
9
|
+
/**
|
10
|
+
* Run a update function but make sure it does not change the selection.
|
11
|
+
* This is useful for when you know that the selection should not change,
|
12
|
+
* the update will not change any content under the selection, but the
|
13
|
+
* update you're running includes selection modifications that you do not
|
14
|
+
* want.
|
15
|
+
*
|
16
|
+
* This is useful because the existing @lexical/markdown importers
|
17
|
+
* mangle the selection because of legacy mistakes.
|
18
|
+
*/
|
19
|
+
export declare function $wrapWithIgnoreSelection<Parameters extends any[], Returns>($update: (...args: Parameters) => Returns): (...args: Parameters) => Returns;
|
20
|
+
export {};
|
21
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,WAAW,EAGjB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,OAAO,CAAC,CAAC,EACvB,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,EACd,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAC5B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAcpC;AAED,eAAO,MAAM,oBAAoB,QAAqB,CAAC;AAIvD,QAAA,MAAM,uBAAuB,EAAE,OAAO,MAErC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,GACnC,IAAI,IAAI,MAAM,CAAC;IAAE,CAAC,uBAAuB,CAAC,EAAE,KAAK,CAAA;CAAE,EAAE,aAAa,CAAC,CAYrE;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,SAAS,GAAG,EAAE,EAAE,OAAO,EACxE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,KAAK,OAAO,GACxC,CAAC,GAAG,IAAI,EAAE,UAAU,KAAK,OAAO,CAqBlC"}
|
package/package.json
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"name": "@etrepum/lexical-builder-markdown",
|
3
|
+
"description": "[EXPERIMENTAL] Lexical Builder @etrepum/lexical-builder-markdown",
|
4
|
+
"type": "module",
|
5
|
+
"keywords": [
|
6
|
+
"lexical",
|
7
|
+
"lexical-builder",
|
8
|
+
"plug-in",
|
9
|
+
"plan",
|
10
|
+
"markdown"
|
11
|
+
],
|
12
|
+
"scripts": {
|
13
|
+
"build": "tsc --noEmit && vite build",
|
14
|
+
"dev": "vite",
|
15
|
+
"test": "vitest run",
|
16
|
+
"test:watch": "vitest"
|
17
|
+
},
|
18
|
+
"version": "0.0.25",
|
19
|
+
"license": "MIT",
|
20
|
+
"repository": {
|
21
|
+
"type": "git",
|
22
|
+
"url": "git+https://github.com/etrepum/lexical-builder.git",
|
23
|
+
"directory": "packages/lexical-builder-markdown"
|
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.16.0-0",
|
34
|
+
"@lexical/code": ">=0.16.0-0",
|
35
|
+
"@lexical/list": ">=0.16.0-0",
|
36
|
+
"@lexical/markdown": ">=0.16.0-0",
|
37
|
+
"@lexical/rich-text": ">=0.16.0-0",
|
38
|
+
"@lexical/utils": ">=0.16.0-0"
|
39
|
+
},
|
40
|
+
"sideEffects": false,
|
41
|
+
"devDependencies": {
|
42
|
+
"@testing-library/dom": "^10.1.0",
|
43
|
+
"@testing-library/jest-dom": "^6.4.5",
|
44
|
+
"@testing-library/user-event": "^14.5.2",
|
45
|
+
"jsdom": "^24.1.0",
|
46
|
+
"tslib": "^2.6.2",
|
47
|
+
"typescript": "^5.4.5",
|
48
|
+
"vite": "^5.2.11",
|
49
|
+
"vite-plugin-dts": "^3.9.1",
|
50
|
+
"vite-plugin-package-version": "^1.1.0",
|
51
|
+
"vitest": "^1.6.0"
|
52
|
+
},
|
53
|
+
"module": "dist/index.js",
|
54
|
+
"types": "dist/index.d.ts",
|
55
|
+
"files": [
|
56
|
+
"dist"
|
57
|
+
]
|
58
|
+
}
|