@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,CA+FZ;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,OAAO,CAAC;CACnB;AACD,MAAM,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAE3D,eAAO,MAAM,qBAAqB,+JAmBhC,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;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":"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"}
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, 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, n) {
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 i = n(r), t = o[i];
12
- t ? t.push(r) : o[i] = [r];
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]/, Ee = /^\s{0,3}$/;
17
- function _(e) {
16
+ const $ = /[!-/:-@[-`{-~\s]/, $e = /^\s{0,3}$/;
17
+ function k(e) {
18
18
  if (!V(e))
19
19
  return !1;
20
- const n = e.getFirstChild();
21
- return n == null || e.getChildrenSize() === 1 && x(n) && Ee.test(n.getTextContent());
20
+ const t = e.getFirstChild();
21
+ return t == null || e.getChildrenSize() === 1 && x(t) && $e.test(t.getTextContent());
22
22
  }
23
- function $e(e) {
23
+ function we(e) {
24
24
  return function(...o) {
25
- const r = C(), i = r ? r.clone() : null, t = e(...o), c = C(), s = i && i.is(r) && !Object.isFrozen(r) ? r : i;
26
- return c !== s && Q(s), t;
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, n, ...o) {
29
+ function T(e, t, ...o) {
30
30
  if (!e)
31
31
  throw new Error(
32
- o.reduce((r, i) => r.replace("%s", String(i)), n || "")
32
+ o.reduce((r, c) => r.replace("%s", String(c)), t || "")
33
33
  );
34
34
  }
35
- const D = /^[ \t]*```(\w{1,10})?\s?$/;
36
- function we(e, n) {
37
- const o = _e(
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(i, { shouldPreserveNewlines: t } = n) {
41
- const c = i.split(`
42
- `), s = c.length, l = Y();
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 m = c[f], [g, u] = Me(c, f, l);
45
- if (g != null) {
46
- f = u;
44
+ const u = i[f], [d, g] = _e(i, f, a);
45
+ if (d != null) {
46
+ f = g;
47
47
  continue;
48
48
  }
49
- Re(
50
- m,
51
- l,
49
+ Me(
50
+ u,
51
+ a,
52
52
  e.element,
53
53
  o,
54
54
  e.textMatch
55
55
  );
56
56
  }
57
- const a = [];
58
- for (let f = l.getFirstChild(); f; f = f.getNextSibling())
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
- ), (t || !_(f)) && a.push(f);
64
- return l.clear(), a;
63
+ ), (n || !k(f)) && l.push(f);
64
+ return a.clear(), l;
65
65
  };
66
66
  }
67
- function Re(e, n, o, r, i) {
68
- const t = e.trim(), c = J(t), s = Y();
69
- s.append(c), n.append(s);
70
- for (const { regExp: l, replace: a } of o) {
71
- const f = e.match(l);
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
- c.setTextContent(e.slice(f[0].length)), a(s, [c], f, !0);
73
+ i.setTextContent(e.slice(f[0].length)), l(s, [i], f, !0);
74
74
  break;
75
75
  }
76
76
  }
77
- if (E(
78
- c,
77
+ if (C(
78
+ i,
79
79
  r,
80
- i
81
- ), s.isAttached() && t.length > 0) {
82
- const l = s.getPreviousSibling();
83
- if (V(l) || Ce(l) || L(l)) {
84
- let a = l;
85
- if (L(l)) {
86
- const f = l.getLastDescendant();
87
- f == null ? a = null : a = Ne(f, Se);
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
- a != null && a.getTextContentSize() > 0 && (a.splice(a.getChildrenSize(), 0, [
90
- pe(),
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 Me(e, n, o) {
97
- const r = D.exec(e[n]);
96
+ function _e(e, t, o) {
97
+ const r = K.exec(e[t]);
98
98
  if (r) {
99
- let i = n;
100
- const t = e.length;
101
- for (; ++i < t; )
102
- if (D.exec(e[i])) {
103
- const s = xe(r[1]), l = J(
104
- e.slice(n + 1, i).join(`
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(l), o.append(s), [s, i];
107
+ return s.append(a), o.append(s), [s, c];
108
108
  }
109
109
  }
110
- return [null, n];
110
+ return [null, t];
111
111
  }
112
- function E(e, n, o) {
113
- const r = e.getTextContent(), i = Pe(r, n);
114
- if (!i) {
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
- i[1] !== void 0 && i[2] !== void 0,
119
+ c[1] !== void 0 && c[2] !== void 0,
120
120
  "importTextMatchTransformers: expecting match with two groups"
121
121
  );
122
- let t, c, s;
123
- if (i[0] === r)
124
- t = e;
122
+ let n, i, s;
123
+ if (c[0] === r)
124
+ n = e;
125
125
  else {
126
- const a = i.index || 0, f = a + i[0].length;
127
- a === 0 ? [t, c] = e.splitText(f) : [s, t, c] = e.splitText(
128
- a,
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
- t !== void 0,
133
+ n !== void 0,
134
134
  "importTextMatchTransformers: currentNode must be defined"
135
- ), t.setTextContent(i[2]);
136
- const l = n.transformersByTag[i[1]];
137
- if (l)
138
- for (const a of l.format)
139
- t.hasFormat(a) || t.toggleFormat(a);
140
- t.hasFormat("code") || E(
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 && E(
144
+ ), s && C(
145
145
  s,
146
- n,
146
+ t,
147
147
  o
148
- ), c && E(
149
- c,
150
- n,
148
+ ), i && C(
149
+ i,
150
+ t,
151
151
  o
152
152
  );
153
153
  }
154
- function ne(e, n) {
154
+ function ne(e, t) {
155
+ var r;
155
156
  let o = e;
156
157
  e: for (; o; ) {
157
- const r = o.getTextContent();
158
- for (const i of n) {
159
- const t = r.match(i.importRegExp);
160
- if (!t)
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 c = t.index || 0, s = c + t[0].length;
163
- let l, a;
164
- if (c === 0) {
165
- const f = o.splitText(s);
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
- f[0] !== void 0,
168
+ u[0] !== void 0,
168
169
  "importTextMatchTransformers: splitText expected at least one node"
169
- ), [l, o] = f;
170
+ ), [l, o] = u;
170
171
  } else {
171
- const f = o.splitText(c, s);
172
+ const u = o.splitText(s, a);
172
173
  T(
173
- f[1] !== void 0,
174
+ u[1] !== void 0,
174
175
  "importTextMatchTransformers: splitText expected at least two nodes"
175
- ), [, l, a] = f, a && ne(a, n);
176
+ ), [, l, f] = u, f && ne(f, t);
176
177
  }
177
- i.replace(l, t);
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, n) {
184
- const o = e.match(n.openTagsRegExp);
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 i = r.replace(/^\s/, ""), t = n.fullMatchRegExpByTag[i];
189
- if (t == null)
189
+ const c = r.replace(/^\s/, ""), n = t.fullMatchRegExpByTag[c];
190
+ if (n == null)
190
191
  continue;
191
- const c = e.match(t), s = n.transformersByTag[i];
192
- if (c != null && s != null) {
192
+ const i = e.match(n), s = t.transformersByTag[c];
193
+ if (i != null && s != null) {
193
194
  if (s.intraword !== !1)
194
- return c;
195
- const { index: l = 0 } = c, a = e[l - 1], f = e[l + c[0].length];
196
- if ((!a || $.test(a)) && (!f || $.test(f)))
197
- return c;
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 _e(e) {
203
- const n = {}, o = {}, r = [], i = "(?<![\\\\])";
204
- for (const t of e) {
205
- const { tag: c } = t;
206
- n[c] = t;
207
- const s = c.replace(/(\*|\^|\+)/g, "\\$1");
208
- r.push(s), O || A || B ? o[c] = new RegExp(
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[c] = new RegExp(
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
- `${O || A || B ? "" : i}(${r.join("|")})`,
220
+ `${A || B || y ? "" : c}(${r.join("|")})`,
220
221
  "g"
221
222
  ),
222
- transformersByTag: n
223
+ transformersByTag: t
223
224
  };
224
225
  }
225
- function ke(e, { shouldPreserveNewlines: n }) {
226
- const o = !n, r = e.textFormat.filter(
227
- (i) => i.format.length === 1
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(t = me()) {
230
- const c = [], s = Z(t) ? t.getChildren() : [t];
231
- for (let l = 0; l < s.length; l++) {
232
- const a = s[l], f = Fe(
233
- a,
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 && c.push(
239
+ f != null && i.push(
239
240
  // separate consecutive group of texts with a line break: eg. ["hello", "world"] -> ["hello", "\nworld"]
240
- o && l > 0 && !_(a) && !_(s[l - 1]) ? `
241
+ o && a > 0 && !k(l) && !k(s[a - 1]) ? `
241
242
  `.concat(f) : f
242
243
  );
243
244
  }
244
- return c.join(`
245
+ return i.join(`
245
246
  `);
246
247
  };
247
248
  }
248
- function Fe(e, n, o, r) {
249
- for (const i of n) {
250
- const t = i.export(
249
+ function ve(e, t, o, r) {
250
+ for (const c of t) {
251
+ const n = c.export(
251
252
  e,
252
- (c) => w(c, o, r)
253
+ (i) => w(i, o, r)
253
254
  );
254
- if (t != null)
255
- return t;
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, n, o) {
260
- const r = [], i = e.getChildren();
261
- e: for (const t of i) {
262
- for (const c of o) {
263
- const s = c.export(
264
- t,
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
- n,
270
+ t,
268
271
  o
269
272
  ),
270
- (l, a) => K(l, a, n)
273
+ (l, f) => j(l, f, t)
271
274
  );
272
- if (s != null) {
273
- r.push(s);
275
+ if (a != null) {
276
+ r.push(a);
274
277
  continue e;
275
278
  }
276
279
  }
277
- te(t) ? r.push(`
278
- `) : x(t) ? r.push(
279
- K(t, t.getTextContent(), n)
280
- ) : N(t) ? r.push(
281
- w(t, n, o)
282
- ) : ee(t) && r.push(t.getTextContent());
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 K(e, n, o) {
287
- const r = n.trim();
288
- let i = r;
289
- const t = /* @__PURE__ */ new Set();
290
- for (const c of o) {
291
- const s = c.format[0], l = c.tag;
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
- l
296
- ), M(e, s) && !t.has(s)) {
297
- t.add(s);
298
- const a = j(e, !0);
299
- M(a, s) || (i = l + i);
300
- const f = j(e, !1);
301
- M(f, s) || (i += l);
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 n.replace(r, () => i);
307
+ return t.replace(r, () => c);
305
308
  }
306
- function j(e, n) {
307
- let o = n ? e.getPreviousSibling() : e.getNextSibling();
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 = n ? r.getPreviousSibling() : r.getNextSibling());
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 = n ? o.getLastDescendant() : o.getFirstDescendant();
319
+ const r = t ? o.getLastDescendant() : o.getFirstDescendant();
317
320
  if (x(r))
318
321
  return r;
319
- o = n ? o.getPreviousSibling() : o.getNextSibling();
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, n) {
329
- return x(e) && e.hasFormat(n);
331
+ function M(e, t) {
332
+ return x(e) && e.hasFormat(t);
330
333
  }
331
- function z({ nodes: e }, n) {
334
+ function _({ nodes: e }, t) {
332
335
  const o = e.has.bind(e);
333
- return n.filter((r) => r.dependencies.every(o));
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, n, o) {
350
- const r = ce(e), i = {
351
- shouldPreserveNewlines: n.shouldPreserveNewlines
352
- }, t = z(
353
+ init(e, t, o) {
354
+ const r = ce(e), c = {
355
+ shouldPreserveNewlines: t.shouldPreserveNewlines
356
+ }, n = _(
353
357
  r,
354
- n.elementTransformers
358
+ t.elementTransformers
355
359
  );
356
360
  if (o.getPeer(U)) {
357
- const a = t.indexOf(ge);
358
- a >= 0 && t.splice(a, 0, de);
361
+ const l = n.indexOf(de);
362
+ l >= 0 && n.splice(l, 0, pe);
359
363
  }
360
- const c = {
364
+ const i = {
361
365
  // Only register transforms for nodes that are configured
362
- element: t,
363
- textMatch: z(r, n.textMatchTransformers),
364
- textFormat: n.textFormatTransformers
365
- }, s = $e(
366
- we(c, i)
367
- ), l = ke(
368
- c,
369
- i
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: i,
373
- transformersByType: c,
374
- $markdownExport: l,
380
+ transformerOptions: c,
381
+ transformersByType: i,
382
+ $markdownExport: a,
375
383
  $markdownImport: s
376
384
  };
377
385
  },
378
- register: (e, n, o) => q(o.getInitResult())
386
+ register: (e, t, o) => q(o.getInitResult())
379
387
  });
380
- function ve(e, n, o, r) {
381
- const i = e.getParent();
382
- if (!Z(i) || e.getFirstChild() !== n)
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 t = n.getTextContent();
385
- if (t[o - 1] !== " ")
392
+ const n = t.getTextContent();
393
+ if (n[o - 1] !== " ")
386
394
  return !1;
387
- for (const { regExp: c, replace: s } of r) {
388
- const l = t.match(c);
389
- if (l && l[0].length === o) {
390
- const a = n.getNextSiblings(), [f, m] = n.splitText(o);
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 g = m ? [m, ...a] : a;
393
- return s(e, g, l, !1), !0;
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, n, o) {
406
+ function be(e, t, o) {
407
+ var i;
399
408
  let r = e.getTextContent();
400
- const i = r[n - 1], t = o[i];
401
- if (t == null)
409
+ const c = r[t - 1], n = o[c];
410
+ if (n == null)
402
411
  return !1;
403
- n < r.length && (r = r.slice(0, n));
404
- for (const c of t) {
405
- const s = r.match(c.regExp);
406
- if (s === null)
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 = s.index || 0, a = l + s[0].length;
409
- let f;
410
- return l === 0 ? f = e.splitText(a)[0] : f = e.splitText(l, a)[1], T(
411
- x(f),
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(a),
423
+ String(f),
415
424
  String(l === 0 ? 0 : 1)
416
- ), f.selectNext(0, 0), c.replace(f, s), !0;
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 Ie(e, n, o) {
421
- const r = e.getTextContent(), i = n - 1, t = r[i], c = o[t];
422
- if (!c)
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 c) {
425
- const { tag: l } = s, a = l.length, f = i - a + 1;
426
- if (a > 1 && !oe(r, f, l, 0, a) || r[f - 1] === " ")
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 m = r[i + 1];
429
- if (s.intraword === !1 && m && !$.test(m))
437
+ const u = r[c + 1];
438
+ if (s.intraword === !1 && u && !$.test(u))
430
439
  continue;
431
- const g = e;
432
- let u = g, d = X(
440
+ const d = e;
441
+ let g = d, p = X(
433
442
  r,
434
443
  f,
435
- l
436
- ), S = u;
437
- for (; d < 0 && (S = S.getPreviousSibling()) && !te(S); )
438
- if (x(S)) {
439
- const h = S.getTextContent();
440
- u = S, d = X(
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
- l
452
+ a
444
453
  );
445
454
  }
446
- if (d < 0 || u === g && d + a === f)
455
+ if (p < 0 || g === d && p + l === f)
447
456
  continue;
448
- const R = u.getTextContent();
449
- if (d > 0 && R[d - 1] === t)
457
+ const R = g.getTextContent();
458
+ if (p > 0 && R[p - 1] === n)
450
459
  continue;
451
- const k = R[d - 1];
452
- if (s.intraword === !1 && k && !$.test(k))
460
+ const F = R[p - 1];
461
+ if (s.intraword === !1 && F && !$.test(F))
453
462
  continue;
454
- const F = g.getTextContent(), v = F.slice(0, f) + F.slice(i + 1);
455
- g.setTextContent(v);
456
- const b = u === g ? v : R;
457
- u.setTextContent(
458
- b.slice(0, d) + b.slice(d + a)
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 I = C(), p = he();
461
- Q(p);
462
- const re = i - a * (u === g ? 2 : 1) + 1;
463
- p.anchor.set(u.__key, d, "text"), p.focus.set(g.__key, re, "text");
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
- p.hasFormat(h) || p.formatText(h);
466
- p.anchor.set(
467
- p.focus.key,
468
- p.focus.offset,
469
- p.focus.type
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
- p.hasFormat(h) && p.toggleFormat(h);
473
- return P(I) && (p.format = I.format), !0;
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, n, o) {
486
+ function X(e, t, o) {
478
487
  const r = o.length;
479
- for (let i = n; i >= r; i--) {
480
- const t = i - r;
481
- if (oe(e, t, o, 0, r) && // Space after opening tag cancels transformation
482
- e[t + r] !== " ")
483
- return t;
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, n, o, r, i) {
488
- for (let t = 0; t < i; t++)
489
- if (e[n + t] !== o[r + t])
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 Le(e, n) {
494
- const o = y(
495
- n.textFormat,
496
- ({ tag: t }) => t[t.length - 1]
497
- ), r = y(
498
- n.textMatch,
499
- ({ trigger: t }) => t
500
- ), i = (t, c, s) => {
501
- ve(
502
- t,
503
- c,
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
- n.element
516
+ t.element
506
517
  ) || be(
507
- c,
518
+ i,
508
519
  s,
509
520
  r
510
- ) || Ie(
511
- c,
521
+ ) || Le(
522
+ i,
512
523
  s,
513
524
  o
514
525
  );
515
526
  };
516
527
  return e.registerUpdateListener(
517
- ({ tags: t, dirtyLeaves: c, editorState: s, prevEditorState: l }) => {
518
- if (t.has("collaboration") || t.has("historic") || e.isComposing())
528
+ ({ tags: n, dirtyLeaves: i, editorState: s, prevEditorState: a }) => {
529
+ if (n.has("collaboration") || n.has("historic") || e.isComposing())
519
530
  return;
520
- const a = s.read(C), f = l.read(C);
521
- if (!P(f) || !P(a) || !a.isCollapsed())
531
+ const l = s.read(S), f = a.read(S);
532
+ if (!P(f) || !P(l) || !l.isCollapsed())
522
533
  return;
523
- const m = a.anchor.key, g = a.anchor.offset, u = s._nodeMap.get(m);
524
- !x(u) || !c.has(m) || g !== 1 && g > f.anchor.offset + 1 || e.update(() => {
525
- if (u.hasFormat("code"))
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 d = u.getParent();
528
- d === null || Te(d) || i(d, u, a.anchor.offset);
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 ze = G({
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, n, o) {
550
+ register(e, t, o) {
540
551
  return q(
541
552
  ...le({
542
- disabled: n.disabled,
543
- register: () => Le(
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
- }), Ue = "0.0.36-nightly.20250430.0";
561
+ }), We = "0.0.36-nightly.20250502.0";
551
562
  export {
552
- ze as MarkdownShortcutsPlan,
563
+ Ue as MarkdownShortcutsPlan,
553
564
  W as MarkdownTransformersPlan,
554
- Ue as PACKAGE_VERSION
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.20250430.0",
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.17.2-nightly.20240906.0",
36
- "@lexical/list": ">=0.17.2-nightly.20240906.0",
37
- "@lexical/markdown": ">=0.17.2-nightly.20240906.0",
38
- "@lexical/rich-text": ">=0.17.2-nightly.20240906.0",
39
- "@lexical/utils": ">=0.17.2-nightly.20240906.0",
40
- "lexical": ">=0.17.2-nightly.20240906.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": {