@etrepum/lexical-builder-markdown 0.0.27-nightly.20240701.0 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MarkdownExport.d.ts","sourceRoot":"","sources":["../src/MarkdownExport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
1
|
+
{"version":3,"file":"MarkdownExport.d.ts","sourceRoot":"","sources":["../src/MarkdownExport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,KAAK,EACV,WAAW,EAIZ,MAAM,SAAS,CAAC;AAWjB,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"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../src/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
1
|
+
{"version":3,"file":"MarkdownImport.d.ts","sourceRoot":"","sources":["../src/MarkdownImport.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EAOL,KAAK,WAAW,EACjB,MAAM,SAAS,CAAC;AAYjB,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,kBAAkB,EACxB,MAAM,SAAS,CAAC;AASjB;;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"}
|
@@ -3,11 +3,11 @@ import { TransformersByType } from './types';
|
|
3
3
|
|
4
4
|
export declare function registerMarkdownShortcuts(editor: LexicalEditor, byType: TransformersByType): () => void;
|
5
5
|
export interface MarkdownShortcutsConfig {
|
6
|
-
|
6
|
+
disabled: boolean;
|
7
7
|
}
|
8
8
|
export interface MarkdownShortcutsOutput {
|
9
|
-
|
10
|
-
|
9
|
+
isDisabled: () => boolean;
|
10
|
+
setDisabled: (disabled: boolean) => void;
|
11
11
|
}
|
12
12
|
export declare const MarkdownShortcutsPlan: import('@etrepum/lexical-builder').LexicalPlan<MarkdownShortcutsConfig, "@etrepum/lexical-builder-markdown/MarkdownShortcuts", MarkdownShortcutsOutput, unknown>;
|
13
13
|
//# sourceMappingURL=MarkdownShortcutsPlan.d.ts.map
|
@@ -1 +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;
|
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;AASjB,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,QAAQ,EAAE,OAAO,CAAC;CACnB;AACD,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,WAAW,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,eAAO,MAAM,qBAAqB,kKAmBhC,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MarkdownTransformersPlan.d.ts","sourceRoot":"","sources":["../src/MarkdownTransformersPlan.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"MarkdownTransformersPlan.d.ts","sourceRoot":"","sources":["../src/MarkdownTransformersPlan.ts"],"names":[],"mappings":"AAmBA,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;AAYF,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,8LAsDnC,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,242 +1,242 @@
|
|
1
|
-
import { definePlan as G, RichTextPlan as
|
2
|
-
import { ELEMENT_TRANSFORMERS as
|
3
|
-
import { $
|
4
|
-
import { $
|
5
|
-
import { $
|
6
|
-
import { $
|
7
|
-
import { $
|
8
|
-
function
|
9
|
-
const
|
10
|
-
for (const
|
11
|
-
const i =
|
12
|
-
|
1
|
+
import { definePlan as G, RichTextPlan as se, declarePeerDependency as ie, safeCast as H, getKnownTypesAndNodes as ce, provideOutput as q, disabledToggle as le } from "@etrepum/lexical-builder";
|
2
|
+
import { ELEMENT_TRANSFORMERS as ae, TEXT_FORMAT_TRANSFORMERS as fe, TEXT_MATCH_TRANSFORMERS as ue, UNORDERED_LIST as ge, CHECK_LIST as de } from "@lexical/markdown";
|
3
|
+
import { $getSelection as C, $setSelection as Q, $isParagraphNode as V, $isTextNode as x, $createParagraphNode as Y, $isElementNode as N, $createTextNode as J, $createLineBreakNode as pe, $isRootOrShadowRoot as Z, $getRoot as me, $isDecoratorNode as ee, $isLineBreakNode as te, $isRangeSelection as P, $createRangeSelection as he } from "lexical";
|
4
|
+
import { $createCodeNode as xe, $isCodeNode as Te } from "@lexical/code";
|
5
|
+
import { $isListNode as L, $isListItemNode as Se } from "@lexical/list";
|
6
|
+
import { $isQuoteNode as Ce } from "@lexical/rich-text";
|
7
|
+
import { $findMatchingParent as Ne, IS_SAFARI as O, IS_IOS as A, IS_APPLE_WEBKIT as B } from "@lexical/utils";
|
8
|
+
function y(e, t) {
|
9
|
+
const n = {};
|
10
|
+
for (const r of e) {
|
11
|
+
const i = t(r);
|
12
|
+
n[i] ? n[i].push(r) : n[i] = [r];
|
13
13
|
}
|
14
|
-
return
|
14
|
+
return n;
|
15
15
|
}
|
16
|
-
const $ = /[!-/:-@[-`{-~\s]/,
|
17
|
-
function
|
18
|
-
if (!
|
16
|
+
const $ = /[!-/:-@[-`{-~\s]/, Ee = /^\s{0,3}$/;
|
17
|
+
function _(e) {
|
18
|
+
if (!V(e))
|
19
19
|
return !1;
|
20
|
-
const
|
21
|
-
return
|
20
|
+
const t = e.getFirstChild();
|
21
|
+
return t == null || e.getChildrenSize() === 1 && x(t) && Ee.test(t.getTextContent());
|
22
22
|
}
|
23
|
-
function
|
24
|
-
return function(...
|
25
|
-
const
|
26
|
-
return c !== s &&
|
23
|
+
function $e(e) {
|
24
|
+
return function(...n) {
|
25
|
+
const r = C(), i = r ? r.clone() : null, o = e(...n), c = C(), s = i && i.is(r) && !Object.isFrozen(r) ? r : i;
|
26
|
+
return c !== s && Q(s), o;
|
27
27
|
};
|
28
28
|
}
|
29
|
-
function T(
|
30
|
-
if (!
|
29
|
+
function T(e, t, ...n) {
|
30
|
+
if (!e)
|
31
31
|
throw new Error(
|
32
|
-
|
32
|
+
n.reduce((r, i) => r.replace("%s", String(i)), t || "")
|
33
33
|
);
|
34
34
|
}
|
35
35
|
const D = /^[ \t]*```(\w{1,10})?\s?$/;
|
36
|
-
function
|
37
|
-
const
|
38
|
-
|
36
|
+
function we(e, t) {
|
37
|
+
const n = _e(
|
38
|
+
e.textFormat
|
39
39
|
);
|
40
|
-
return function(i, { shouldPreserveNewlines:
|
40
|
+
return function(i, { shouldPreserveNewlines: o } = t) {
|
41
41
|
const c = i.split(`
|
42
|
-
`), s = c.length, l =
|
42
|
+
`), s = c.length, l = Y();
|
43
43
|
for (let f = 0; f < s; f++) {
|
44
|
-
const m = c[f], [g, u] =
|
44
|
+
const m = c[f], [g, u] = Me(c, f, l);
|
45
45
|
if (g != null) {
|
46
46
|
f = u;
|
47
47
|
continue;
|
48
48
|
}
|
49
|
-
|
49
|
+
Re(
|
50
50
|
m,
|
51
51
|
l,
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
e.element,
|
53
|
+
n,
|
54
|
+
e.textMatch
|
55
55
|
);
|
56
56
|
}
|
57
57
|
const a = [];
|
58
58
|
for (let f = l.getFirstChild(); f; f = f.getNextSibling())
|
59
59
|
T(
|
60
|
-
|
60
|
+
N(f),
|
61
61
|
"markdownImport: Expected child of type %s to be an ElementNode",
|
62
62
|
f.getType()
|
63
|
-
), (
|
63
|
+
), (o || !_(f)) && a.push(f);
|
64
64
|
return l.clear(), a;
|
65
65
|
};
|
66
66
|
}
|
67
|
-
function
|
68
|
-
const
|
69
|
-
s.append(c),
|
70
|
-
for (const { regExp: l, replace: a } of
|
71
|
-
const f =
|
67
|
+
function Re(e, t, n, r, i) {
|
68
|
+
const o = e.trim(), c = J(o), s = Y();
|
69
|
+
s.append(c), t.append(s);
|
70
|
+
for (const { regExp: l, replace: a } of n) {
|
71
|
+
const f = e.match(l);
|
72
72
|
if (f) {
|
73
|
-
c.setTextContent(
|
73
|
+
c.setTextContent(e.slice(f[0].length)), a(s, [c], f, !0);
|
74
74
|
break;
|
75
75
|
}
|
76
76
|
}
|
77
|
-
if (
|
77
|
+
if (E(
|
78
78
|
c,
|
79
|
-
|
79
|
+
r,
|
80
80
|
i
|
81
|
-
), s.isAttached() &&
|
81
|
+
), s.isAttached() && o.length > 0) {
|
82
82
|
const l = s.getPreviousSibling();
|
83
|
-
if (
|
83
|
+
if (V(l) || Ce(l) || L(l)) {
|
84
84
|
let a = l;
|
85
|
-
if (
|
85
|
+
if (L(l)) {
|
86
86
|
const f = l.getLastDescendant();
|
87
|
-
f == null ? a = null : a =
|
87
|
+
f == null ? a = null : a = Ne(f, Se);
|
88
88
|
}
|
89
89
|
a != null && a.getTextContentSize() > 0 && (a.splice(a.getChildrenSize(), 0, [
|
90
|
-
|
90
|
+
pe(),
|
91
91
|
...s.getChildren()
|
92
92
|
]), s.remove());
|
93
93
|
}
|
94
94
|
}
|
95
95
|
}
|
96
|
-
function
|
97
|
-
const
|
98
|
-
if (
|
99
|
-
let i =
|
100
|
-
const
|
101
|
-
for (; ++i <
|
102
|
-
if (
|
103
|
-
const s =
|
104
|
-
|
96
|
+
function Me(e, t, n) {
|
97
|
+
const r = D.exec(e[t]);
|
98
|
+
if (r) {
|
99
|
+
let i = t;
|
100
|
+
const o = e.length;
|
101
|
+
for (; ++i < o; )
|
102
|
+
if (D.exec(e[i])) {
|
103
|
+
const s = xe(r[1]), l = J(
|
104
|
+
e.slice(t + 1, i).join(`
|
105
105
|
`)
|
106
106
|
);
|
107
|
-
return s.append(l),
|
107
|
+
return s.append(l), n.append(s), [s, i];
|
108
108
|
}
|
109
109
|
}
|
110
|
-
return [null,
|
110
|
+
return [null, t];
|
111
111
|
}
|
112
|
-
function
|
113
|
-
const
|
112
|
+
function E(e, t, n) {
|
113
|
+
const r = e.getTextContent(), i = Pe(r, t);
|
114
114
|
if (!i) {
|
115
|
-
|
115
|
+
ne(e, n);
|
116
116
|
return;
|
117
117
|
}
|
118
118
|
T(
|
119
119
|
i[1] !== void 0 && i[2] !== void 0,
|
120
120
|
"importTextMatchTransformers: expecting match with two groups"
|
121
121
|
);
|
122
|
-
let
|
123
|
-
if (i[0] ===
|
124
|
-
|
122
|
+
let o, c, s;
|
123
|
+
if (i[0] === r)
|
124
|
+
o = e;
|
125
125
|
else {
|
126
126
|
const a = i.index || 0, f = a + i[0].length;
|
127
|
-
a === 0 ? [
|
127
|
+
a === 0 ? [o, c] = e.splitText(f) : [s, o, c] = e.splitText(
|
128
128
|
a,
|
129
129
|
f
|
130
130
|
);
|
131
131
|
}
|
132
132
|
T(
|
133
|
-
|
133
|
+
o !== void 0,
|
134
134
|
"importTextMatchTransformers: currentNode must be defined"
|
135
|
-
),
|
136
|
-
const l =
|
135
|
+
), o.setTextContent(i[2]);
|
136
|
+
const l = t.transformersByTag[i[1]];
|
137
137
|
if (l)
|
138
138
|
for (const a of l.format)
|
139
|
-
|
140
|
-
|
141
|
-
n,
|
139
|
+
o.hasFormat(a) || o.toggleFormat(a);
|
140
|
+
o.hasFormat("code") || E(
|
142
141
|
o,
|
143
|
-
|
144
|
-
|
142
|
+
t,
|
143
|
+
n
|
144
|
+
), s && E(
|
145
145
|
s,
|
146
|
-
|
147
|
-
|
148
|
-
), c &&
|
146
|
+
t,
|
147
|
+
n
|
148
|
+
), c && E(
|
149
149
|
c,
|
150
|
-
|
151
|
-
|
150
|
+
t,
|
151
|
+
n
|
152
152
|
);
|
153
153
|
}
|
154
|
-
function
|
155
|
-
let
|
156
|
-
|
157
|
-
for (const
|
158
|
-
const i =
|
154
|
+
function ne(e, t) {
|
155
|
+
let n = e;
|
156
|
+
e: for (; n; ) {
|
157
|
+
for (const r of t) {
|
158
|
+
const i = n.getTextContent().match(r.importRegExp);
|
159
159
|
if (!i)
|
160
160
|
continue;
|
161
|
-
const
|
161
|
+
const o = i.index || 0, c = o + i[0].length;
|
162
162
|
let s, l;
|
163
|
-
if (
|
164
|
-
const a =
|
163
|
+
if (o === 0) {
|
164
|
+
const a = n.splitText(c);
|
165
165
|
T(
|
166
|
-
a[0] !== void 0
|
167
|
-
"importTextMatchTransformers: splitText expected
|
168
|
-
), [s,
|
166
|
+
a[0] !== void 0,
|
167
|
+
"importTextMatchTransformers: splitText expected at least one node"
|
168
|
+
), [s, n] = a;
|
169
169
|
} else {
|
170
|
-
const a =
|
170
|
+
const a = n.splitText(o, c);
|
171
171
|
T(
|
172
|
-
a[1] !== void 0
|
173
|
-
"importTextMatchTransformers: splitText expected
|
174
|
-
), [, s, l] = a, l &&
|
172
|
+
a[1] !== void 0,
|
173
|
+
"importTextMatchTransformers: splitText expected at least two nodes"
|
174
|
+
), [, s, l] = a, l && ne(l, t);
|
175
175
|
}
|
176
|
-
|
177
|
-
continue
|
176
|
+
r.replace(s, i);
|
177
|
+
continue e;
|
178
178
|
}
|
179
179
|
break;
|
180
180
|
}
|
181
181
|
}
|
182
|
-
function
|
183
|
-
const
|
184
|
-
if (
|
182
|
+
function Pe(e, t) {
|
183
|
+
const n = e.match(t.openTagsRegExp);
|
184
|
+
if (n == null)
|
185
185
|
return null;
|
186
|
-
for (const
|
187
|
-
const i =
|
188
|
-
if (
|
186
|
+
for (const r of n) {
|
187
|
+
const i = r.replace(/^\s/, ""), o = t.fullMatchRegExpByTag[i];
|
188
|
+
if (o == null)
|
189
189
|
continue;
|
190
|
-
const c =
|
190
|
+
const c = e.match(o), s = t.transformersByTag[i];
|
191
191
|
if (c != null && s != null) {
|
192
192
|
if (s.intraword !== !1)
|
193
193
|
return c;
|
194
|
-
const { index: l = 0 } = c, a =
|
194
|
+
const { index: l = 0 } = c, a = e[l - 1], f = e[l + c[0].length];
|
195
195
|
if ((!a || $.test(a)) && (!f || $.test(f)))
|
196
196
|
return c;
|
197
197
|
}
|
198
198
|
}
|
199
199
|
return null;
|
200
200
|
}
|
201
|
-
function
|
202
|
-
const
|
203
|
-
for (const
|
204
|
-
const { tag: c } =
|
205
|
-
|
201
|
+
function _e(e) {
|
202
|
+
const t = {}, n = {}, r = [], i = "(?<![\\\\])";
|
203
|
+
for (const o of e) {
|
204
|
+
const { tag: c } = o;
|
205
|
+
t[c] = o;
|
206
206
|
const s = c.replace(/(\*|\^|\+)/g, "\\$1");
|
207
|
-
|
207
|
+
r.push(s), O || A || B ? n[c] = new RegExp(
|
208
208
|
`(${s})(?![${s}\\s])(.*?[^${s}\\s])${s}(?!${s})`
|
209
|
-
) :
|
209
|
+
) : n[c] = new RegExp(
|
210
210
|
`(?<![\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?![\\\\${s}])`
|
211
211
|
);
|
212
212
|
}
|
213
213
|
return {
|
214
214
|
// Reg exp to find open tag + content + close tag
|
215
|
-
fullMatchRegExpByTag:
|
215
|
+
fullMatchRegExpByTag: n,
|
216
216
|
// Reg exp to find opening tags
|
217
217
|
openTagsRegExp: new RegExp(
|
218
|
-
|
218
|
+
`${O || A || B ? "" : i}(${r.join("|")})`,
|
219
219
|
"g"
|
220
220
|
),
|
221
|
-
transformersByTag:
|
221
|
+
transformersByTag: t
|
222
222
|
};
|
223
223
|
}
|
224
|
-
function
|
225
|
-
const
|
224
|
+
function ke(e, { shouldPreserveNewlines: t }) {
|
225
|
+
const n = !t, r = e.textFormat.filter(
|
226
226
|
(i) => i.format.length === 1
|
227
227
|
);
|
228
|
-
return function(
|
229
|
-
const c = [], s =
|
228
|
+
return function(o = me()) {
|
229
|
+
const c = [], s = Z(o) ? o.getChildren() : [o];
|
230
230
|
for (let l = 0; l < s.length; l++) {
|
231
|
-
const a = s[l], f =
|
231
|
+
const a = s[l], f = Fe(
|
232
232
|
a,
|
233
|
-
|
234
|
-
|
235
|
-
|
233
|
+
e.element,
|
234
|
+
r,
|
235
|
+
e.textMatch
|
236
236
|
);
|
237
237
|
f != null && c.push(
|
238
238
|
// separate consecutive group of texts with a line break: eg. ["hello", "world"] -> ["hello", "\nworld"]
|
239
|
-
|
239
|
+
n && l > 0 && !_(a) && !_(s[l - 1]) ? `
|
240
240
|
`.concat(f) : f
|
241
241
|
);
|
242
242
|
}
|
@@ -244,158 +244,169 @@ function wt(t, { shouldPreserveNewlines: o }) {
|
|
244
244
|
`);
|
245
245
|
};
|
246
246
|
}
|
247
|
-
function
|
248
|
-
for (const i of
|
249
|
-
const
|
250
|
-
|
251
|
-
(c) => w(c,
|
247
|
+
function Fe(e, t, n, r) {
|
248
|
+
for (const i of t) {
|
249
|
+
const o = i.export(
|
250
|
+
e,
|
251
|
+
(c) => w(c, n, r)
|
252
252
|
);
|
253
|
-
if (
|
254
|
-
return
|
253
|
+
if (o != null)
|
254
|
+
return o;
|
255
255
|
}
|
256
|
-
return
|
256
|
+
return N(e) ? w(e, n, r) : ee(e) ? e.getTextContent() : null;
|
257
257
|
}
|
258
|
-
function w(
|
259
|
-
const
|
260
|
-
|
261
|
-
for (const c of
|
258
|
+
function w(e, t, n) {
|
259
|
+
const r = [], i = e.getChildren();
|
260
|
+
e: for (const o of i) {
|
261
|
+
for (const c of n) {
|
262
262
|
const s = c.export(
|
263
|
-
|
263
|
+
o,
|
264
264
|
(l) => w(
|
265
265
|
l,
|
266
|
-
|
267
|
-
|
266
|
+
t,
|
267
|
+
n
|
268
268
|
),
|
269
|
-
(l, a) => K(l, a,
|
269
|
+
(l, a) => K(l, a, t)
|
270
270
|
);
|
271
271
|
if (s != null) {
|
272
|
-
|
273
|
-
continue
|
272
|
+
r.push(s);
|
273
|
+
continue e;
|
274
274
|
}
|
275
275
|
}
|
276
|
-
|
277
|
-
`) : x(
|
278
|
-
K(
|
279
|
-
) :
|
280
|
-
w(
|
281
|
-
) :
|
276
|
+
te(o) ? r.push(`
|
277
|
+
`) : x(o) ? r.push(
|
278
|
+
K(o, o.getTextContent(), t)
|
279
|
+
) : N(o) ? r.push(
|
280
|
+
w(o, t, n)
|
281
|
+
) : ee(o) && r.push(o.getTextContent());
|
282
282
|
}
|
283
|
-
return
|
283
|
+
return r.join("");
|
284
284
|
}
|
285
|
-
function K(
|
286
|
-
const
|
287
|
-
let i =
|
288
|
-
const
|
289
|
-
for (const c of
|
285
|
+
function K(e, t, n) {
|
286
|
+
const r = t.trim();
|
287
|
+
let i = r;
|
288
|
+
const o = /* @__PURE__ */ new Set();
|
289
|
+
for (const c of n) {
|
290
290
|
const s = c.format[0], l = c.tag;
|
291
291
|
if (T(
|
292
292
|
s !== void 0,
|
293
293
|
"TextFormatTransformer for tag %s has empty format array",
|
294
294
|
l
|
295
|
-
), M(
|
296
|
-
|
297
|
-
const a = j(
|
295
|
+
), M(e, s) && !o.has(s)) {
|
296
|
+
o.add(s);
|
297
|
+
const a = j(e, !0);
|
298
298
|
M(a, s) || (i = l + i);
|
299
|
-
const f = j(
|
299
|
+
const f = j(e, !1);
|
300
300
|
M(f, s) || (i += l);
|
301
301
|
}
|
302
302
|
}
|
303
|
-
return
|
303
|
+
return t.replace(r, () => i);
|
304
304
|
}
|
305
|
-
function j(
|
306
|
-
let
|
307
|
-
if (!
|
308
|
-
const
|
309
|
-
|
305
|
+
function j(e, t) {
|
306
|
+
let n = t ? e.getPreviousSibling() : e.getNextSibling();
|
307
|
+
if (!n) {
|
308
|
+
const r = e.getParentOrThrow();
|
309
|
+
r.isInline() && (n = t ? r.getPreviousSibling() : r.getNextSibling());
|
310
310
|
}
|
311
|
-
for (;
|
312
|
-
if (
|
313
|
-
if (!
|
311
|
+
for (; n; ) {
|
312
|
+
if (N(n)) {
|
313
|
+
if (!n.isInline())
|
314
314
|
break;
|
315
|
-
const
|
316
|
-
if (x(
|
317
|
-
return
|
318
|
-
|
315
|
+
const r = t ? n.getLastDescendant() : n.getFirstDescendant();
|
316
|
+
if (x(r))
|
317
|
+
return r;
|
318
|
+
n = t ? n.getPreviousSibling() : n.getNextSibling();
|
319
319
|
}
|
320
|
-
if (x(
|
321
|
-
return
|
322
|
-
if (!
|
320
|
+
if (x(n))
|
321
|
+
return n;
|
322
|
+
if (!N(n))
|
323
323
|
return null;
|
324
324
|
}
|
325
325
|
return null;
|
326
326
|
}
|
327
|
-
function M(
|
328
|
-
return x(
|
327
|
+
function M(e, t) {
|
328
|
+
return x(e) && e.hasFormat(t);
|
329
329
|
}
|
330
|
-
function z({ nodes:
|
331
|
-
const
|
332
|
-
return
|
330
|
+
function z({ nodes: e }, t) {
|
331
|
+
const n = e.has.bind(e);
|
332
|
+
return t.filter((r) => r.dependencies.every(n));
|
333
333
|
}
|
334
|
-
const W = G({
|
334
|
+
const U = "@etrepum/lexical-builder-list/CheckList", W = G({
|
335
335
|
name: "@etrepum/lexical-builder-markdown/MarkdownTransformers",
|
336
|
-
dependencies: [
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
336
|
+
dependencies: [se],
|
337
|
+
peerDependencies: [
|
338
|
+
ie(U)
|
339
|
+
],
|
340
|
+
config: H({
|
341
|
+
elementTransformers: ae,
|
342
|
+
textFormatTransformers: fe,
|
343
|
+
textMatchTransformers: ue,
|
341
344
|
shouldPreserveNewlines: !1
|
342
345
|
}),
|
343
346
|
// For now we replace the transformer arrays with the default
|
344
347
|
// shallowMergeConfig. I think ideally these should be additive
|
345
|
-
init(
|
346
|
-
const
|
347
|
-
shouldPreserveNewlines:
|
348
|
-
},
|
348
|
+
init(e, t, n) {
|
349
|
+
const r = ce(e), i = {
|
350
|
+
shouldPreserveNewlines: t.shouldPreserveNewlines
|
351
|
+
}, o = z(
|
352
|
+
r,
|
353
|
+
t.elementTransformers
|
354
|
+
);
|
355
|
+
if (n.getPeer(U)) {
|
356
|
+
const a = o.indexOf(ge);
|
357
|
+
a >= 0 && o.splice(a, 0, de);
|
358
|
+
}
|
359
|
+
const c = {
|
349
360
|
// Only register transforms for nodes that are configured
|
350
|
-
element:
|
351
|
-
textMatch: z(
|
352
|
-
textFormat:
|
353
|
-
},
|
354
|
-
|
355
|
-
),
|
356
|
-
|
361
|
+
element: o,
|
362
|
+
textMatch: z(r, t.textMatchTransformers),
|
363
|
+
textFormat: t.textFormatTransformers
|
364
|
+
}, s = $e(
|
365
|
+
we(c, i)
|
366
|
+
), l = ke(
|
367
|
+
c,
|
357
368
|
i
|
358
369
|
);
|
359
370
|
return {
|
360
371
|
transformerOptions: i,
|
361
|
-
transformersByType:
|
362
|
-
$markdownExport:
|
363
|
-
$markdownImport:
|
372
|
+
transformersByType: c,
|
373
|
+
$markdownExport: l,
|
374
|
+
$markdownImport: s
|
364
375
|
};
|
365
376
|
},
|
366
|
-
register: (
|
377
|
+
register: (e, t, n) => q(n.getInitResult())
|
367
378
|
});
|
368
|
-
function
|
369
|
-
const i =
|
370
|
-
if (!
|
379
|
+
function ve(e, t, n, r) {
|
380
|
+
const i = e.getParent();
|
381
|
+
if (!Z(i) || e.getFirstChild() !== t)
|
371
382
|
return !1;
|
372
|
-
const
|
373
|
-
if (n
|
383
|
+
const o = t.getTextContent();
|
384
|
+
if (o[n - 1] !== " ")
|
374
385
|
return !1;
|
375
|
-
for (const { regExp: c, replace: s } of
|
376
|
-
const l =
|
377
|
-
if (l && l[0].length ===
|
378
|
-
const a =
|
386
|
+
for (const { regExp: c, replace: s } of r) {
|
387
|
+
const l = o.match(c);
|
388
|
+
if (l && l[0].length === n) {
|
389
|
+
const a = t.getNextSiblings(), [f, m] = t.splitText(n);
|
379
390
|
f.remove();
|
380
391
|
const g = m ? [m, ...a] : a;
|
381
|
-
return s(
|
392
|
+
return s(e, g, l, !1), !0;
|
382
393
|
}
|
383
394
|
}
|
384
395
|
return !1;
|
385
396
|
}
|
386
|
-
function
|
387
|
-
let
|
388
|
-
const i =
|
389
|
-
if (
|
397
|
+
function be(e, t, n) {
|
398
|
+
let r = e.getTextContent();
|
399
|
+
const i = r[t - 1], o = n[i];
|
400
|
+
if (o == null)
|
390
401
|
return !1;
|
391
|
-
|
392
|
-
for (const c of
|
393
|
-
const s =
|
402
|
+
t < r.length && (r = r.slice(0, t));
|
403
|
+
for (const c of o) {
|
404
|
+
const s = r.match(c.regExp);
|
394
405
|
if (s === null)
|
395
406
|
continue;
|
396
407
|
const l = s.index || 0, a = l + s[0].length;
|
397
408
|
let f;
|
398
|
-
return l === 0 ? f =
|
409
|
+
return l === 0 ? f = e.splitText(a)[0] : f = e.splitText(l, a)[1], T(
|
399
410
|
x(f),
|
400
411
|
"MarkdownShortcuts: splitText(%s, %s)[%s] did not return the expected TextNode",
|
401
412
|
String(l),
|
@@ -405,24 +416,24 @@ function vt(t, o, r) {
|
|
405
416
|
}
|
406
417
|
return !1;
|
407
418
|
}
|
408
|
-
function
|
409
|
-
const
|
419
|
+
function Ie(e, t, n) {
|
420
|
+
const r = e.getTextContent(), i = t - 1, o = r[i], c = n[o];
|
410
421
|
if (!c)
|
411
422
|
return !1;
|
412
423
|
for (const s of c) {
|
413
424
|
const { tag: l } = s, a = l.length, f = i - a + 1;
|
414
|
-
if (a > 1 && !
|
425
|
+
if (a > 1 && !oe(r, f, l, 0, a) || r[f - 1] === " ")
|
415
426
|
continue;
|
416
|
-
const m =
|
427
|
+
const m = r[i + 1];
|
417
428
|
if (s.intraword === !1 && m && !$.test(m))
|
418
429
|
continue;
|
419
|
-
const g =
|
430
|
+
const g = e;
|
420
431
|
let u = g, d = X(
|
421
|
-
|
432
|
+
r,
|
422
433
|
f,
|
423
434
|
l
|
424
435
|
), S = u;
|
425
|
-
for (; d < 0 && (S = S.getPreviousSibling()) && !
|
436
|
+
for (; d < 0 && (S = S.getPreviousSibling()) && !te(S); )
|
426
437
|
if (x(S)) {
|
427
438
|
const h = S.getTextContent();
|
428
439
|
u = S, d = X(
|
@@ -434,21 +445,21 @@ function kt(t, o, r) {
|
|
434
445
|
if (d < 0 || u === g && d + a === f)
|
435
446
|
continue;
|
436
447
|
const R = u.getTextContent();
|
437
|
-
if (d > 0 && R[d - 1] ===
|
448
|
+
if (d > 0 && R[d - 1] === o)
|
438
449
|
continue;
|
439
|
-
const
|
440
|
-
if (s.intraword === !1 &&
|
450
|
+
const k = R[d - 1];
|
451
|
+
if (s.intraword === !1 && k && !$.test(k))
|
441
452
|
continue;
|
442
|
-
const
|
443
|
-
g.setTextContent(
|
444
|
-
const b = u === g ?
|
453
|
+
const F = g.getTextContent(), v = F.slice(0, f) + F.slice(i + 1);
|
454
|
+
g.setTextContent(v);
|
455
|
+
const b = u === g ? v : R;
|
445
456
|
u.setTextContent(
|
446
457
|
b.slice(0, d) + b.slice(d + a)
|
447
458
|
);
|
448
|
-
const I =
|
449
|
-
|
450
|
-
const
|
451
|
-
p.anchor.set(u.__key, d, "text"), p.focus.set(g.__key,
|
459
|
+
const I = C(), p = he();
|
460
|
+
Q(p);
|
461
|
+
const re = i - a * (u === g ? 2 : 1) + 1;
|
462
|
+
p.anchor.set(u.__key, d, "text"), p.focus.set(g.__key, re, "text");
|
452
463
|
for (const h of s.format)
|
453
464
|
p.hasFormat(h) || p.formatText(h);
|
454
465
|
p.anchor.set(
|
@@ -458,91 +469,86 @@ function kt(t, o, r) {
|
|
458
469
|
);
|
459
470
|
for (const h of s.format)
|
460
471
|
p.hasFormat(h) && p.toggleFormat(h);
|
461
|
-
return
|
472
|
+
return P(I) && (p.format = I.format), !0;
|
462
473
|
}
|
463
474
|
return !1;
|
464
475
|
}
|
465
|
-
function X(
|
466
|
-
const
|
467
|
-
for (let i =
|
468
|
-
const
|
469
|
-
if (
|
470
|
-
|
471
|
-
return
|
476
|
+
function X(e, t, n) {
|
477
|
+
const r = n.length;
|
478
|
+
for (let i = t; i >= r; i--) {
|
479
|
+
const o = i - r;
|
480
|
+
if (oe(e, o, n, 0, r) && // Space after opening tag cancels transformation
|
481
|
+
e[o + r] !== " ")
|
482
|
+
return o;
|
472
483
|
}
|
473
484
|
return -1;
|
474
485
|
}
|
475
|
-
function
|
476
|
-
for (let
|
477
|
-
if (t
|
486
|
+
function oe(e, t, n, r, i) {
|
487
|
+
for (let o = 0; o < i; o++)
|
488
|
+
if (e[t + o] !== n[r + o])
|
478
489
|
return !1;
|
479
490
|
return !0;
|
480
491
|
}
|
481
|
-
function
|
482
|
-
const
|
483
|
-
|
484
|
-
({ tag:
|
485
|
-
),
|
486
|
-
|
487
|
-
({ trigger:
|
488
|
-
), i = (
|
489
|
-
|
490
|
-
|
492
|
+
function Le(e, t) {
|
493
|
+
const n = y(
|
494
|
+
t.textFormat,
|
495
|
+
({ tag: o }) => o[o.length - 1]
|
496
|
+
), r = y(
|
497
|
+
t.textMatch,
|
498
|
+
({ trigger: o }) => o
|
499
|
+
), i = (o, c, s) => {
|
500
|
+
ve(
|
501
|
+
o,
|
491
502
|
c,
|
492
503
|
s,
|
493
|
-
|
494
|
-
) ||
|
504
|
+
t.element
|
505
|
+
) || be(
|
495
506
|
c,
|
496
507
|
s,
|
497
|
-
|
498
|
-
) ||
|
508
|
+
r
|
509
|
+
) || Ie(
|
499
510
|
c,
|
500
511
|
s,
|
501
|
-
|
512
|
+
n
|
502
513
|
);
|
503
514
|
};
|
504
|
-
return
|
505
|
-
({ tags:
|
506
|
-
if (
|
515
|
+
return e.registerUpdateListener(
|
516
|
+
({ tags: o, dirtyLeaves: c, editorState: s, prevEditorState: l }) => {
|
517
|
+
if (o.has("collaboration") || o.has("historic") || e.isComposing())
|
507
518
|
return;
|
508
|
-
const a = s.read(
|
509
|
-
if (!
|
519
|
+
const a = s.read(C), f = l.read(C);
|
520
|
+
if (!P(f) || !P(a) || !a.isCollapsed())
|
510
521
|
return;
|
511
522
|
const m = a.anchor.key, g = a.anchor.offset, u = s._nodeMap.get(m);
|
512
|
-
!x(u) || !c.has(m) || g !== 1 && g > f.anchor.offset + 1 ||
|
523
|
+
!x(u) || !c.has(m) || g !== 1 && g > f.anchor.offset + 1 || e.update(() => {
|
513
524
|
if (u.hasFormat("code"))
|
514
525
|
return;
|
515
526
|
const d = u.getParent();
|
516
|
-
d === null ||
|
527
|
+
d === null || Te(d) || i(d, u, a.anchor.offset);
|
517
528
|
});
|
518
529
|
}
|
519
530
|
);
|
520
531
|
}
|
521
|
-
const
|
532
|
+
const ze = G({
|
522
533
|
name: "@etrepum/lexical-builder-markdown/MarkdownShortcuts",
|
523
534
|
dependencies: [W],
|
524
|
-
config:
|
525
|
-
|
535
|
+
config: H({
|
536
|
+
disabled: !1
|
526
537
|
}),
|
527
|
-
register(
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
) : !c && e !== null && (e(), e = null);
|
537
|
-
}
|
538
|
-
return n(o.enabled), q(
|
539
|
-
{ getEnabled: i, setEnabled: n },
|
540
|
-
() => n(!1)
|
538
|
+
register(e, t, n) {
|
539
|
+
return q(
|
540
|
+
...le({
|
541
|
+
disabled: t.disabled,
|
542
|
+
register: () => Le(
|
543
|
+
e,
|
544
|
+
n.getDependency(W).output.transformersByType
|
545
|
+
)
|
546
|
+
})
|
541
547
|
);
|
542
548
|
}
|
543
|
-
}),
|
549
|
+
}), Ue = "0.0.27";
|
544
550
|
export {
|
545
|
-
|
551
|
+
ze as MarkdownShortcutsPlan,
|
546
552
|
W as MarkdownTransformersPlan,
|
547
|
-
|
553
|
+
Ue as PACKAGE_VERSION
|
548
554
|
};
|
package/package.json
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
"test": "vitest run",
|
17
17
|
"test:watch": "vitest"
|
18
18
|
},
|
19
|
-
"version": "0.0.27
|
19
|
+
"version": "0.0.27",
|
20
20
|
"license": "MIT",
|
21
21
|
"repository": {
|
22
22
|
"type": "git",
|
@@ -28,15 +28,16 @@
|
|
28
28
|
},
|
29
29
|
"homepage": "https://github.com/etrepum/lexical-builder",
|
30
30
|
"dependencies": {
|
31
|
-
"@etrepum/lexical-builder": "*"
|
31
|
+
"@etrepum/lexical-builder": "*",
|
32
|
+
"@etrepum/lexical-builder-list": "*"
|
32
33
|
},
|
33
34
|
"peerDependencies": {
|
34
|
-
"@lexical/code": ">=0.16.
|
35
|
-
"@lexical/list": ">=0.16.
|
36
|
-
"@lexical/markdown": ">=0.16.
|
37
|
-
"@lexical/rich-text": ">=0.16.
|
38
|
-
"@lexical/utils": ">=0.16.
|
39
|
-
"lexical": ">=0.16.
|
35
|
+
"@lexical/code": ">=0.16.1-nightly.20240626",
|
36
|
+
"@lexical/list": ">=0.16.1-nightly.20240626",
|
37
|
+
"@lexical/markdown": ">=0.16.1-nightly.20240626",
|
38
|
+
"@lexical/rich-text": ">=0.16.1-nightly.20240626",
|
39
|
+
"@lexical/utils": ">=0.16.1-nightly.20240626",
|
40
|
+
"lexical": ">=0.16.1-nightly.20240626"
|
40
41
|
},
|
41
42
|
"sideEffects": false,
|
42
43
|
"devDependencies": {
|