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