@etrepum/lexical-builder-markdown 0.0.27-nightly.20240628.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;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"}
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;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"}
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
- enabled: boolean;
6
+ disabled: boolean;
7
7
  }
8
8
  export interface MarkdownShortcutsOutput {
9
- getEnabled: () => boolean;
10
- setEnabled: (enabled: boolean) => void;
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;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"}
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":"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"}
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 rt, safeCast as U, getKnownTypesAndNodes as st, provideOutput as q } from "@etrepum/lexical-builder";
2
- import { ELEMENT_TRANSFORMERS as it, TEXT_FORMAT_TRANSFORMERS as ct, TEXT_MATCH_TRANSFORMERS as lt } from "@lexical/markdown";
3
- import { $createCodeNode as at, $isCodeNode as ft } from "@lexical/code";
4
- import { $isListNode as B, $isListItemNode as ut } from "@lexical/list";
5
- import { $isQuoteNode as gt } from "@lexical/rich-text";
6
- import { $findMatchingParent as dt, IS_SAFARI as O, IS_IOS as A, IS_APPLE_WEBKIT as y } from "@lexical/utils";
7
- import { $getSelection as N, $setSelection as H, $isParagraphNode as Q, $isTextNode as x, $createParagraphNode as V, $isElementNode as E, $createTextNode as Y, $createLineBreakNode as pt, $isRootOrShadowRoot as J, $getRoot as mt, $isDecoratorNode as Z, $isLineBreakNode as tt, $isRangeSelection as v, $createRangeSelection as ht } from "lexical";
8
- function L(t, o) {
9
- const r = {};
10
- for (const e of t) {
11
- const i = o(e);
12
- r[i] ? r[i].push(e) : r[i] = [e];
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 r;
14
+ return n;
15
15
  }
16
- const $ = /[!-/:-@[-`{-~\s]/, xt = /^\s{0,3}$/;
17
- function k(t) {
18
- if (!Q(t))
16
+ const $ = /[!-/:-@[-`{-~\s]/, Ee = /^\s{0,3}$/;
17
+ function _(e) {
18
+ if (!V(e))
19
19
  return !1;
20
- const o = t.getFirstChild();
21
- return o == null || t.getChildrenSize() === 1 && x(o) && xt.test(o.getTextContent());
20
+ const t = e.getFirstChild();
21
+ return t == null || e.getChildrenSize() === 1 && x(t) && Ee.test(t.getTextContent());
22
22
  }
23
- function Tt(t) {
24
- return function(...r) {
25
- const e = N(), i = e ? e.clone() : null, n = t(...r), c = N(), s = i && i.is(e) && !Object.isFrozen(e) ? e : i;
26
- return c !== s && H(s), n;
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(t, o, ...r) {
30
- if (!t)
29
+ function T(e, t, ...n) {
30
+ if (!e)
31
31
  throw new Error(
32
- r.reduce((e, i) => e.replace("%s", String(i)), o || "")
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 St(t, o) {
37
- const r = $t(
38
- t.textFormat || []
36
+ function we(e, t) {
37
+ const n = _e(
38
+ e.textFormat
39
39
  );
40
- return function(i, { shouldPreserveNewlines: n } = o) {
40
+ return function(i, { shouldPreserveNewlines: o } = t) {
41
41
  const c = i.split(`
42
- `), s = c.length, l = V();
42
+ `), s = c.length, l = Y();
43
43
  for (let f = 0; f < s; f++) {
44
- const m = c[f], [g, u] = Et(c, f, l);
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
- Nt(
49
+ Re(
50
50
  m,
51
51
  l,
52
- t.element,
53
- r,
54
- t.textMatch
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
- E(f),
60
+ N(f),
61
61
  "markdownImport: Expected child of type %s to be an ElementNode",
62
62
  f.getType()
63
- ), (n || !k(f)) && a.push(f);
63
+ ), (o || !_(f)) && a.push(f);
64
64
  return l.clear(), a;
65
65
  };
66
66
  }
67
- function Nt(t, o, r, e, i) {
68
- const n = t.trim(), c = Y(n), s = V();
69
- s.append(c), o.append(s);
70
- for (const { regExp: l, replace: a } of r) {
71
- const f = t.match(l);
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(t.slice(f[0].length)), a(s, [c], f, !0);
73
+ c.setTextContent(e.slice(f[0].length)), a(s, [c], f, !0);
74
74
  break;
75
75
  }
76
76
  }
77
- if (C(
77
+ if (E(
78
78
  c,
79
- e,
79
+ r,
80
80
  i
81
- ), s.isAttached() && n.length > 0) {
81
+ ), s.isAttached() && o.length > 0) {
82
82
  const l = s.getPreviousSibling();
83
- if (Q(l) || gt(l) || B(l)) {
83
+ if (V(l) || Ce(l) || L(l)) {
84
84
  let a = l;
85
- if (B(l)) {
85
+ if (L(l)) {
86
86
  const f = l.getLastDescendant();
87
- f == null ? a = null : a = dt(f, ut);
87
+ f == null ? a = null : a = Ne(f, Se);
88
88
  }
89
89
  a != null && a.getTextContentSize() > 0 && (a.splice(a.getChildrenSize(), 0, [
90
- pt(),
90
+ pe(),
91
91
  ...s.getChildren()
92
92
  ]), s.remove());
93
93
  }
94
94
  }
95
95
  }
96
- function Et(t, o, r) {
97
- const e = t[o].match(D);
98
- if (e) {
99
- let i = o;
100
- const n = t.length;
101
- for (; ++i < n; )
102
- if (t[i].match(D)) {
103
- const s = at(e[1]), l = Y(
104
- t.slice(o + 1, i).join(`
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), r.append(s), [s, i];
107
+ return s.append(l), n.append(s), [s, i];
108
108
  }
109
109
  }
110
- return [null, o];
110
+ return [null, t];
111
111
  }
112
- function C(t, o, r) {
113
- const e = t.getTextContent(), i = Ct(e, o);
112
+ function E(e, t, n) {
113
+ const r = e.getTextContent(), i = Pe(r, t);
114
114
  if (!i) {
115
- et(t, r);
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 n, c, s;
123
- if (i[0] === e)
124
- n = t;
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 ? [n, c] = t.splitText(f) : [s, n, c] = t.splitText(
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
- n !== void 0,
133
+ o !== void 0,
134
134
  "importTextMatchTransformers: currentNode must be defined"
135
- ), n.setTextContent(i[2]);
136
- const l = o.transformersByTag[i[1]];
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
- n.hasFormat(a) || n.toggleFormat(a);
140
- n.hasFormat("code") || C(
141
- n,
139
+ o.hasFormat(a) || o.toggleFormat(a);
140
+ o.hasFormat("code") || E(
142
141
  o,
143
- r
144
- ), s && C(
142
+ t,
143
+ n
144
+ ), s && E(
145
145
  s,
146
- o,
147
- r
148
- ), c && C(
146
+ t,
147
+ n
148
+ ), c && E(
149
149
  c,
150
- o,
151
- r
150
+ t,
151
+ n
152
152
  );
153
153
  }
154
- function et(t, o) {
155
- let r = t;
156
- t: for (; r; ) {
157
- for (const e of o) {
158
- const i = r.getTextContent().match(e.importRegExp);
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 n = i.index || 0, c = n + i[0].length;
161
+ const o = i.index || 0, c = o + i[0].length;
162
162
  let s, l;
163
- if (n === 0) {
164
- const a = r.splitText(c);
163
+ if (o === 0) {
164
+ const a = n.splitText(c);
165
165
  T(
166
- a[0] !== void 0 && a[1] !== void 0,
167
- "importTextMatchTransformers: splitText expected two nodes"
168
- ), [s, r] = a;
166
+ a[0] !== void 0,
167
+ "importTextMatchTransformers: splitText expected at least one node"
168
+ ), [s, n] = a;
169
169
  } else {
170
- const a = r.splitText(n, c);
170
+ const a = n.splitText(o, c);
171
171
  T(
172
- a[1] !== void 0 && a[2] !== void 0,
173
- "importTextMatchTransformers: splitText expected three nodes"
174
- ), [, s, l] = a, l && et(l, o);
172
+ a[1] !== void 0,
173
+ "importTextMatchTransformers: splitText expected at least two nodes"
174
+ ), [, s, l] = a, l && ne(l, t);
175
175
  }
176
- e.replace(s, i);
177
- continue t;
176
+ r.replace(s, i);
177
+ continue e;
178
178
  }
179
179
  break;
180
180
  }
181
181
  }
182
- function Ct(t, o) {
183
- const r = t.match(o.openTagsRegExp);
184
- if (r == null)
182
+ function Pe(e, t) {
183
+ const n = e.match(t.openTagsRegExp);
184
+ if (n == null)
185
185
  return null;
186
- for (const e of r) {
187
- const i = e.replace(/^\s/, ""), n = o.fullMatchRegExpByTag[i];
188
- if (n == null)
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 = t.match(n), s = o.transformersByTag[i];
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 = t[l - 1], f = t[l + c[0].length];
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 $t(t) {
202
- const o = {}, r = {}, e = [], i = "(?<![\\\\])";
203
- for (const n of t) {
204
- const { tag: c } = n;
205
- o[c] = n;
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
- e.push(s), O || A || y ? r[c] = new RegExp(
207
+ r.push(s), O || A || B ? n[c] = new RegExp(
208
208
  `(${s})(?![${s}\\s])(.*?[^${s}\\s])${s}(?!${s})`
209
- ) : r[c] = new RegExp(
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: r,
215
+ fullMatchRegExpByTag: n,
216
216
  // Reg exp to find opening tags
217
217
  openTagsRegExp: new RegExp(
218
- (O || A || y ? "" : `${i}`) + "(" + e.join("|") + ")",
218
+ `${O || A || B ? "" : i}(${r.join("|")})`,
219
219
  "g"
220
220
  ),
221
- transformersByTag: o
221
+ transformersByTag: t
222
222
  };
223
223
  }
224
- function wt(t, { shouldPreserveNewlines: o }) {
225
- const r = !o, e = t.textFormat.filter(
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(n = mt()) {
229
- const c = [], s = J(n) ? n.getChildren() : [n];
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 = Rt(
231
+ const a = s[l], f = Fe(
232
232
  a,
233
- t.element,
234
- e,
235
- t.textMatch
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
- r && l > 0 && !k(a) && !k(s[l - 1]) ? `
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 Rt(t, o, r, e) {
248
- for (const i of o) {
249
- const n = i.export(
250
- t,
251
- (c) => w(c, r, e)
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 (n != null)
254
- return n;
253
+ if (o != null)
254
+ return o;
255
255
  }
256
- return E(t) ? w(t, r, e) : Z(t) ? t.getTextContent() : null;
256
+ return N(e) ? w(e, n, r) : ee(e) ? e.getTextContent() : null;
257
257
  }
258
- function w(t, o, r) {
259
- const e = [], i = t.getChildren();
260
- t: for (const n of i) {
261
- for (const c of r) {
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
- n,
263
+ o,
264
264
  (l) => w(
265
265
  l,
266
- o,
267
- r
266
+ t,
267
+ n
268
268
  ),
269
- (l, a) => K(l, a, o)
269
+ (l, a) => K(l, a, t)
270
270
  );
271
271
  if (s != null) {
272
- e.push(s);
273
- continue t;
272
+ r.push(s);
273
+ continue e;
274
274
  }
275
275
  }
276
- tt(n) ? e.push(`
277
- `) : x(n) ? e.push(
278
- K(n, n.getTextContent(), o)
279
- ) : E(n) ? e.push(
280
- w(n, o, r)
281
- ) : Z(n) && e.push(n.getTextContent());
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 e.join("");
283
+ return r.join("");
284
284
  }
285
- function K(t, o, r) {
286
- const e = o.trim();
287
- let i = e;
288
- const n = /* @__PURE__ */ new Set();
289
- for (const c of r) {
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(t, s) && !n.has(s)) {
296
- n.add(s);
297
- const a = j(t, !0);
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(t, !1);
299
+ const f = j(e, !1);
300
300
  M(f, s) || (i += l);
301
301
  }
302
302
  }
303
- return o.replace(e, () => i);
303
+ return t.replace(r, () => i);
304
304
  }
305
- function j(t, o) {
306
- let r = o ? t.getPreviousSibling() : t.getNextSibling();
307
- if (!r) {
308
- const e = t.getParentOrThrow();
309
- e.isInline() && (r = o ? e.getPreviousSibling() : e.getNextSibling());
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 (; r; ) {
312
- if (E(r)) {
313
- if (!r.isInline())
311
+ for (; n; ) {
312
+ if (N(n)) {
313
+ if (!n.isInline())
314
314
  break;
315
- const e = o ? r.getLastDescendant() : r.getFirstDescendant();
316
- if (x(e))
317
- return e;
318
- r = o ? r.getPreviousSibling() : r.getNextSibling();
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(r))
321
- return r;
322
- if (!E(r))
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(t, o) {
328
- return x(t) && t.hasFormat(o);
327
+ function M(e, t) {
328
+ return x(e) && e.hasFormat(t);
329
329
  }
330
- function z({ nodes: t }, o) {
331
- const r = t.has.bind(t);
332
- return o.filter((e) => e.dependencies.every(r));
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: [rt],
337
- config: U({
338
- elementTransformers: it,
339
- textFormatTransformers: ct,
340
- textMatchTransformers: lt,
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(t, o, r) {
346
- const e = st(t), i = {
347
- shouldPreserveNewlines: o.shouldPreserveNewlines
348
- }, n = {
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: z(e, o.elementTransformers),
351
- textMatch: z(e, o.textMatchTransformers),
352
- textFormat: o.textFormatTransformers
353
- }, c = Tt(
354
- St(n, i)
355
- ), s = wt(
356
- n,
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: n,
362
- $markdownExport: s,
363
- $markdownImport: c
372
+ transformersByType: c,
373
+ $markdownExport: l,
374
+ $markdownImport: s
364
375
  };
365
376
  },
366
- register: (t, o, r) => q(r.getInitResult())
377
+ register: (e, t, n) => q(n.getInitResult())
367
378
  });
368
- function Mt(t, o, r, e) {
369
- const i = t.getParent();
370
- if (!J(i) || t.getFirstChild() !== o)
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 n = o.getTextContent();
373
- if (n[r - 1] !== " ")
383
+ const o = t.getTextContent();
384
+ if (o[n - 1] !== " ")
374
385
  return !1;
375
- for (const { regExp: c, replace: s } of e) {
376
- const l = n.match(c);
377
- if (l && l[0].length === r) {
378
- const a = o.getNextSiblings(), [f, m] = o.splitText(r);
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(t, g, l, !1), !0;
392
+ return s(e, g, l, !1), !0;
382
393
  }
383
394
  }
384
395
  return !1;
385
396
  }
386
- function vt(t, o, r) {
387
- let e = t.getTextContent();
388
- const i = e[o - 1], n = r[i];
389
- if (n == null)
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
- o < e.length && (e = e.slice(0, o));
392
- for (const c of n) {
393
- const s = e.match(c.regExp);
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 = t.splitText(a)[0] : f = t.splitText(l, a)[1], T(
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 kt(t, o, r) {
409
- const e = t.getTextContent(), i = o - 1, n = e[i], c = r[n];
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 && !nt(e, f, l, 0, a) || e[f - 1] === " ")
425
+ if (a > 1 && !oe(r, f, l, 0, a) || r[f - 1] === " ")
415
426
  continue;
416
- const m = e[i + 1];
427
+ const m = r[i + 1];
417
428
  if (s.intraword === !1 && m && !$.test(m))
418
429
  continue;
419
- const g = t;
430
+ const g = e;
420
431
  let u = g, d = X(
421
- e,
432
+ r,
422
433
  f,
423
434
  l
424
435
  ), S = u;
425
- for (; d < 0 && (S = S.getPreviousSibling()) && !tt(S); )
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] === n)
448
+ if (d > 0 && R[d - 1] === o)
438
449
  continue;
439
- const F = R[d - 1];
440
- if (s.intraword === !1 && F && !$.test(F))
450
+ const k = R[d - 1];
451
+ if (s.intraword === !1 && k && !$.test(k))
441
452
  continue;
442
- const P = g.getTextContent(), _ = P.slice(0, f) + P.slice(i + 1);
443
- g.setTextContent(_);
444
- const b = u === g ? _ : R;
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 = N(), p = ht();
449
- H(p);
450
- const ot = i - a * (u === g ? 2 : 1) + 1;
451
- p.anchor.set(u.__key, d, "text"), p.focus.set(g.__key, ot, "text");
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 v(I) && (p.format = I.format), !0;
472
+ return P(I) && (p.format = I.format), !0;
462
473
  }
463
474
  return !1;
464
475
  }
465
- function X(t, o, r) {
466
- const e = r.length;
467
- for (let i = o; i >= e; i--) {
468
- const n = i - e;
469
- if (nt(t, n, r, 0, e) && // Space after opening tag cancels transformation
470
- t[n + e] !== " ")
471
- return n;
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 nt(t, o, r, e, i) {
476
- for (let n = 0; n < i; n++)
477
- if (t[o + n] !== r[e + n])
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 Ft(t, o) {
482
- const r = L(
483
- o.textFormat,
484
- ({ tag: n }) => n[n.length - 1]
485
- ), e = L(
486
- o.textMatch,
487
- ({ trigger: n }) => n
488
- ), i = (n, c, s) => {
489
- Mt(
490
- n,
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
- o.element
494
- ) || vt(
504
+ t.element
505
+ ) || be(
495
506
  c,
496
507
  s,
497
- e
498
- ) || kt(
508
+ r
509
+ ) || Ie(
499
510
  c,
500
511
  s,
501
- r
512
+ n
502
513
  );
503
514
  };
504
- return t.registerUpdateListener(
505
- ({ tags: n, dirtyLeaves: c, editorState: s, prevEditorState: l }) => {
506
- if (n.has("collaboration") || n.has("historic") || t.isComposing())
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(N), f = l.read(N);
509
- if (!v(f) || !v(a) || !a.isCollapsed())
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 || t.update(() => {
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 || ft(d) || i(d, u, a.anchor.offset);
527
+ d === null || Te(d) || i(d, u, a.anchor.offset);
517
528
  });
518
529
  }
519
530
  );
520
531
  }
521
- const yt = G({
532
+ const ze = G({
522
533
  name: "@etrepum/lexical-builder-markdown/MarkdownShortcuts",
523
534
  dependencies: [W],
524
- config: U({
525
- enabled: !0
535
+ config: H({
536
+ disabled: !1
526
537
  }),
527
- register(t, o, r) {
528
- let e = null;
529
- function i() {
530
- return e !== null;
531
- }
532
- function n(c) {
533
- c && e === null ? e = Ft(
534
- t,
535
- r.getDependency(W).output.transformersByType
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
- }), Lt = "0.0.27-nightly.20240628.0";
549
+ }), Ue = "0.0.27";
544
550
  export {
545
- yt as MarkdownShortcutsPlan,
551
+ ze as MarkdownShortcutsPlan,
546
552
  W as MarkdownTransformersPlan,
547
- Lt as PACKAGE_VERSION
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-nightly.20240628.0",
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.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
- "lexical": ">=0.16.0-0"
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": {