@pibit.ai/cure-design-system 0.6.51 → 0.6.53

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,100 +1,109 @@
1
- import { jsx as m, jsxs as ie } from "react/jsx-runtime";
2
- import { forwardRef as le, useRef as _, useState as ae, useMemo as ce, useEffect as P, useImperativeHandle as ue } from "react";
3
- import { Placeholder as fe } from "@tiptap/extension-placeholder";
4
- import { useEditor as de, EditorContent as pe } from "@tiptap/react";
5
- import { StarterKit as me } from "@tiptap/starter-kit";
6
- import { cx as z } from "../../utils/cn.js";
7
- import { segmentsToDoc as E, rangeToText as xe, docToSegments as be } from "./segments.js";
8
- import { TokenNode as ye } from "./token-node.js";
9
- import { createTokenSuggestionExtension as ke } from "./token-suggestion.js";
10
- const Te = {
1
+ import { jsx as k, jsxs as me } from "react/jsx-runtime";
2
+ import { forwardRef as xe, useRef as S, useState as te, useMemo as ye, useEffect as w, useImperativeHandle as be } from "react";
3
+ import { Extension as ke } from "@tiptap/core";
4
+ import { Slice as Te } from "@tiptap/pm/model";
5
+ import { Plugin as he, PluginKey as ge } from "@tiptap/pm/state";
6
+ import { Placeholder as Pe } from "@tiptap/extension-placeholder";
7
+ import { useEditor as _e, EditorContent as Me } from "@tiptap/react";
8
+ import { StarterKit as De } from "@tiptap/starter-kit";
9
+ import { cx as V } from "../../utils/cn.js";
10
+ import { segmentsToDoc as z, rangeToText as Ne, docToSegments as Se } from "./segments.js";
11
+ import { TokenNode as we, TokenRenderVersion as ze } from "./token-node.js";
12
+ import { createTokenSuggestionExtension as Ie } from "./token-suggestion.js";
13
+ const Re = {
11
14
  neutral: "border-secondary bg-primary text-secondary",
12
15
  brand: "border-utility-brand-200 bg-utility-brand-50 text-utility-brand-700",
13
16
  error: "border-utility-error-200 bg-utility-error-50 text-utility-error-700"
14
17
  };
15
- function ge({
16
- label: x,
17
- icon: i,
18
- tone: b = "neutral",
19
- selected: f
18
+ function Be({
19
+ label: g,
20
+ icon: u,
21
+ tone: P = "neutral",
22
+ selected: m
20
23
  }) {
21
- return /* @__PURE__ */ ie(
24
+ return /* @__PURE__ */ me(
22
25
  "span",
23
26
  {
24
- className: z(
27
+ className: V(
25
28
  "inline-flex max-w-60 items-center gap-1 rounded-md border px-1.5 py-px text-xs font-medium",
26
- Te[b],
27
- f && "ring-2 ring-brand"
29
+ Re[P],
30
+ m && "ring-2 ring-brand"
28
31
  ),
29
32
  children: [
30
- i && /* @__PURE__ */ m("span", { className: "flex size-3.5 shrink-0 items-center", children: i }),
31
- /* @__PURE__ */ m("span", { className: "truncate", children: x })
33
+ u && /* @__PURE__ */ k("span", { className: "flex size-3.5 shrink-0 items-center", children: u }),
34
+ /* @__PURE__ */ k("span", { className: "truncate", children: g })
32
35
  ]
33
36
  }
34
37
  );
35
38
  }
36
- const I = (x) => x.replace(/\r\n|\r|\n/g, ""), Re = le(
39
+ const B = (g) => g.replace(/\r\n|\r|\n/g, ""), Oe = xe(
37
40
  function({
38
- value: i,
39
- onChange: b,
40
- parse: f,
41
- serialize: R,
42
- renderToken: S,
43
- getTokenDisplay: w,
44
- suggestions: y,
45
- placeholder: v,
46
- readOnly: k = !1,
47
- isInvalid: K = !1,
48
- allowNewlines: T = !1,
49
- preservePastedNewlines: U,
50
- tokenPaste: j = !0,
51
- filterTextInput: F,
52
- onKeyDownCapture: L,
53
- onKeyDown: V,
54
- onFocus: q,
55
- onBlur: H,
56
- extensions: C,
57
- onEditorChange: d,
58
- chrome: ee = !0,
59
- className: te,
60
- contentClassName: re,
61
- contentAttributes: ne
62
- }, se) {
63
- const o = _({
64
- value: i,
65
- onChange: b,
66
- parse: f,
67
- serialize: R,
68
- renderToken: S,
69
- getTokenDisplay: w,
70
- allowNewlines: T,
71
- preservePastedNewlines: U ?? T,
72
- tokenPaste: j,
73
- filterTextInput: F,
74
- onKeyDownCapture: L,
75
- onKeyDown: V,
76
- onFocus: q,
77
- onBlur: H
41
+ value: u,
42
+ onChange: P,
43
+ parse: m,
44
+ serialize: K,
45
+ renderToken: U,
46
+ tokenWrapperClassName: v = "inline-flex align-middle",
47
+ autoTokenize: F,
48
+ getTokenDisplay: j,
49
+ suggestions: _,
50
+ placeholder: re,
51
+ readOnly: M = !1,
52
+ isInvalid: A = !1,
53
+ allowNewlines: D = !1,
54
+ preservePastedNewlines: J,
55
+ tokenPaste: L = !0,
56
+ filterTextInput: W,
57
+ onKeyDownCapture: q,
58
+ onKeyDown: H,
59
+ onFocus: O,
60
+ onBlur: G,
61
+ extensions: ne,
62
+ onEditorChange: x,
63
+ chrome: se = !0,
64
+ className: oe,
65
+ contentClassName: ae,
66
+ contentAttributes: ie
67
+ }, le) {
68
+ const o = S({
69
+ value: u,
70
+ onChange: P,
71
+ parse: m,
72
+ serialize: K,
73
+ renderToken: U,
74
+ tokenWrapperClassName: v,
75
+ autoTokenize: F,
76
+ getTokenDisplay: j,
77
+ allowNewlines: D,
78
+ preservePastedNewlines: J ?? D,
79
+ tokenPaste: L,
80
+ filterTextInput: W,
81
+ onKeyDownCapture: q,
82
+ onKeyDown: H,
83
+ onFocus: O,
84
+ onBlur: G
78
85
  });
79
86
  o.current = {
80
- value: i,
81
- onChange: b,
82
- parse: f,
83
- serialize: R,
84
- renderToken: S,
85
- getTokenDisplay: w,
86
- allowNewlines: T,
87
- preservePastedNewlines: U ?? T,
88
- tokenPaste: j,
89
- filterTextInput: F,
90
- onKeyDownCapture: L,
91
- onKeyDown: V,
92
- onFocus: q,
93
- onBlur: H
87
+ value: u,
88
+ onChange: P,
89
+ parse: m,
90
+ serialize: K,
91
+ renderToken: U,
92
+ tokenWrapperClassName: v,
93
+ autoTokenize: F,
94
+ getTokenDisplay: j,
95
+ allowNewlines: D,
96
+ preservePastedNewlines: J ?? D,
97
+ tokenPaste: L,
98
+ filterTextInput: W,
99
+ onKeyDownCapture: q,
100
+ onKeyDown: H,
101
+ onFocus: O,
102
+ onBlur: G
94
103
  };
95
- const D = _(!1), J = _(!1), [A, G] = ae(!1), O = (t) => o.current.serialize([{ type: "token", value: t }]), M = (t) => o.current.serialize(be(t.getJSON())), oe = ce(
104
+ const I = S(!1), Q = S(!1), [ce, ue] = te(0), [X, Y] = te(!1), Z = (e) => o.current.serialize([{ type: "token", value: e }]), R = (e) => o.current.serialize(Se(e.getJSON())), fe = ye(
96
105
  () => [
97
- me.configure({
106
+ De.configure({
98
107
  bold: !1,
99
108
  blockquote: !1,
100
109
  bulletList: !1,
@@ -110,177 +119,229 @@ const I = (x) => x.replace(/\r\n|\r|\n/g, ""), Re = le(
110
119
  listItem: !1,
111
120
  listKeymap: !1
112
121
  }),
113
- fe.configure({ placeholder: v ?? "" }),
114
- ye.configure({
115
- getRenderToken: () => o.current.renderToken ?? ((t) => {
116
- var n, r;
117
- return /* @__PURE__ */ m(
118
- ge,
122
+ Pe.configure({ placeholder: re ?? "" }),
123
+ we.configure({
124
+ getRenderToken: () => o.current.renderToken ?? ((e) => {
125
+ var s, r;
126
+ return /* @__PURE__ */ k(
127
+ Be,
119
128
  {
120
- ...((r = (n = o.current).getTokenDisplay) == null ? void 0 : r.call(n, t.value)) ?? {
121
- label: t.value
129
+ ...((r = (s = o.current).getTokenDisplay) == null ? void 0 : r.call(s, e.value)) ?? {
130
+ label: e.value
122
131
  },
123
- selected: t.selected
132
+ selected: e.selected
124
133
  }
125
134
  );
126
135
  }),
127
- getTokenText: () => O
136
+ getTokenText: () => Z,
137
+ getWrapperClassName: () => o.current.tokenWrapperClassName
128
138
  }),
129
- ...y != null && y.length ? [
130
- ke(y, (t) => {
131
- J.current = t;
139
+ ke.create({
140
+ name: "tokenAutoTokenize",
141
+ addProseMirrorPlugins() {
142
+ return [
143
+ new he({
144
+ key: new ge("tokenAutoTokenize"),
145
+ appendTransaction: (e, s, r) => {
146
+ const n = o.current.autoTokenize;
147
+ if (!n || !e.some((a) => a.docChanged))
148
+ return null;
149
+ const c = r.schema.nodes.token, f = [];
150
+ if (r.doc.descendants((a, T) => {
151
+ if (!(!a.isText || !a.text))
152
+ for (const p of n(a.text))
153
+ f.push({
154
+ from: T + p.start,
155
+ to: T + p.end,
156
+ value: p.value
157
+ });
158
+ }), !f.length) return null;
159
+ const y = r.tr;
160
+ for (const a of f.reverse())
161
+ y.replaceWith(
162
+ a.from,
163
+ a.to,
164
+ c.create({ value: a.value })
165
+ );
166
+ return y;
167
+ }
168
+ })
169
+ ];
170
+ }
171
+ }),
172
+ ..._ != null && _.length ? [
173
+ Ie(_, (e) => {
174
+ Q.current = e;
132
175
  })
133
176
  ] : [],
134
- ...C ?? []
177
+ ...ne ?? []
135
178
  ],
136
179
  // Extensions are fixed for the editor's lifetime, like the original inputs.
137
180
  // eslint-disable-next-line react-hooks/exhaustive-deps
138
181
  []
139
- ), e = de({
182
+ ), t = _e({
140
183
  immediatelyRender: !1,
141
- editable: !k,
142
- extensions: oe,
143
- content: E(f(i)),
184
+ editable: !M,
185
+ extensions: fe,
186
+ content: z(m(u)),
144
187
  editorProps: {
145
- attributes: ne ?? {
188
+ attributes: ie ?? {
146
189
  class: "w-full outline-none text-sm text-primary"
147
190
  },
148
191
  handleDOMEvents: {
149
- focus: (t, n) => {
150
- var r, s;
151
- return G(!0), (s = (r = o.current).onFocus) == null || s.call(r, n), !1;
192
+ focus: (e, s) => {
193
+ var r, n;
194
+ return Y(!0), (n = (r = o.current).onFocus) == null || n.call(r, s), !1;
152
195
  },
153
- blur: (t, n) => {
154
- var r, s;
155
- return G(!1), (s = (r = o.current).onBlur) == null || s.call(r, n), !1;
196
+ blur: (e, s) => {
197
+ var r, n;
198
+ return Y(!1), (n = (r = o.current).onBlur) == null || n.call(r, s), !1;
156
199
  }
157
200
  },
158
- clipboardTextSerializer: (t, n) => {
159
- const { from: r, to: s } = n.state.selection;
160
- return xe(n.state.doc, r, s, O);
201
+ clipboardTextSerializer: (e, s) => {
202
+ const { from: r, to: n } = s.state.selection;
203
+ return Ne(s.state.doc, r, n, Z);
161
204
  },
162
- handlePaste: (t, n) => {
163
- var $;
164
- n.preventDefault();
205
+ handlePaste: (e, s) => {
206
+ var E;
207
+ s.preventDefault();
165
208
  const r = o.current;
166
- let s = (($ = n.clipboardData) == null ? void 0 : $.getData("text/plain")) || "";
167
- if (!s || !r.preservePastedNewlines && (s = I(s), !s))
209
+ let n = ((E = s.clipboardData) == null ? void 0 : E.getData("text/plain")) || "";
210
+ if (!n || !r.preservePastedNewlines && (n = B(n), !n))
168
211
  return !0;
169
- const { from: a, to: p } = t.state.selection, X = {
170
- docText: t.state.doc.textBetween(
212
+ const { from: c, to: f } = e.state.selection, y = {
213
+ docText: e.state.doc.textBetween(
171
214
  0,
172
- t.state.doc.content.size,
215
+ e.state.doc.content.size,
173
216
  "",
174
217
  ""
175
218
  ),
176
- textBefore: t.state.doc.textBetween(0, a, "", ""),
177
- raw: s
178
- }, g = r.filterTextInput, Y = Q.current, Z = r.tokenPaste ? r.parse(s) : [];
179
- if (Y && Z.some((c) => c.type === "token")) {
180
- const c = [];
181
- for (const l of Z)
219
+ textBefore: e.state.doc.textBetween(0, c, "", ""),
220
+ raw: n
221
+ }, a = r.filterTextInput, T = $.current, p = r.tokenPaste ? r.parse(n) : [];
222
+ if (r.preservePastedNewlines) {
223
+ const h = (r.tokenPaste ? p : n.split(/\r\n|\r|\n/).flatMap(
224
+ (i, b) => b > 0 ? [{ type: "newline" }, { type: "text", text: i }] : [{ type: "text", text: i }]
225
+ )).flatMap((i) => i.type !== "text" ? [i] : (a ? a(i.text, y) : i.text).split(/\r\n|\r|\n/).flatMap(
226
+ (ee, pe) => pe > 0 ? [{ type: "newline" }, { type: "text", text: ee }] : [{ type: "text", text: ee }]
227
+ )), l = e.state.schema.nodeFromJSON(z(h));
228
+ return e.dispatch(
229
+ e.state.tr.replaceSelection(new Te(l.content, 1, 1)).scrollIntoView()
230
+ ), !0;
231
+ }
232
+ if (T && p.some((d) => d.type === "token")) {
233
+ const d = [];
234
+ for (const l of p)
182
235
  if (l.type === "token")
183
- c.push({ token: l.value });
236
+ d.push({ token: l.value });
184
237
  else {
185
- const u = l.type === "newline" ? `
186
- ` : l.text, B = c[c.length - 1];
187
- B && "text" in B ? B.text += u : c.push({ text: u });
238
+ const i = l.type === "newline" ? `
239
+ ` : l.text, b = d[d.length - 1];
240
+ b && "text" in b ? b.text += i : d.push({ text: i });
188
241
  }
189
- const N = Y.chain().focus();
190
- for (const l of c)
242
+ const h = T.chain().focus();
243
+ for (const l of d)
191
244
  if ("token" in l)
192
- N.insertToken(l.token);
245
+ h.insertToken(l.token);
193
246
  else {
194
- let u = g ? g(l.text, X) : l.text;
195
- r.preservePastedNewlines || (u = I(u)), u && N.insertContent(u);
247
+ let i = a ? a(l.text, y) : l.text;
248
+ r.preservePastedNewlines || (i = B(i)), i && h.insertContent(i);
196
249
  }
197
- return N.run(), !0;
250
+ return h.run(), !0;
198
251
  }
199
- let h = g ? g(s, X) : s;
200
- return r.preservePastedNewlines || (h = I(h)), h && t.dispatch(t.state.tr.insertText(h, a, p)), !0;
252
+ let N = a ? a(n, y) : n;
253
+ return r.preservePastedNewlines || (N = B(N)), N && e.dispatch(e.state.tr.insertText(N, c, f)), !0;
201
254
  },
202
- handleTextInput: (t, n, r, s) => {
203
- const a = o.current.filterTextInput;
204
- if (!a) return !1;
205
- const p = a(s, {
206
- docText: t.state.doc.textBetween(
255
+ handleTextInput: (e, s, r, n) => {
256
+ const c = o.current.filterTextInput;
257
+ if (!c) return !1;
258
+ const f = c(n, {
259
+ docText: e.state.doc.textBetween(
207
260
  0,
208
- t.state.doc.content.size,
261
+ e.state.doc.content.size,
209
262
  "",
210
263
  ""
211
264
  ),
212
- textBefore: t.state.doc.textBetween(0, n, "", ""),
213
- raw: s
265
+ textBefore: e.state.doc.textBetween(0, s, "", ""),
266
+ raw: n
214
267
  });
215
- return p === s ? !1 : (p && t.dispatch(t.state.tr.insertText(p, n, r)), !0);
268
+ return f === n ? !1 : (f && e.dispatch(e.state.tr.insertText(f, s, r)), !0);
216
269
  },
217
- handleKeyDown: (t, n) => {
218
- var s, a;
270
+ handleKeyDown: (e, s) => {
271
+ var n, c;
219
272
  const r = o.current;
220
- return (s = r.onKeyDownCapture) != null && s.call(r, t, n) ? !0 : J.current ? !1 : !r.allowNewlines && n.key === "Enter" ? (n.preventDefault(), !0) : ((a = r.onKeyDown) == null ? void 0 : a.call(r, t, n)) ?? !1;
273
+ return (n = r.onKeyDownCapture) != null && n.call(r, e, s) ? !0 : Q.current ? !1 : !r.allowNewlines && s.key === "Enter" ? (s.preventDefault(), !0) : ((c = r.onKeyDown) == null ? void 0 : c.call(r, e, s)) ?? !1;
221
274
  }
222
275
  }
223
- }), Q = _(null);
224
- Q.current = e, P(() => (d == null || d(e), () => d == null ? void 0 : d(null)), [e]), P(() => {
225
- !e || e.isDestroyed || (!D.current && M(e) !== i && e.commands.setContent(E(f(i)), {
276
+ }), $ = S(null);
277
+ $.current = t, w(() => (x == null || x(t), () => x == null ? void 0 : x(null)), [t]), w(() => {
278
+ !t || t.isDestroyed || (!I.current && R(t) !== u && t.commands.setContent(z(m(u)), {
226
279
  emitUpdate: !1
227
- }), D.current = !1);
228
- }, [i, e]), P(() => {
229
- !e || e.isDestroyed || e.setEditable(!k);
230
- }, [e, k]), P(() => {
231
- if (!e || e.isDestroyed) return;
232
- const t = () => {
233
- const n = M(e);
234
- n !== o.current.value && (D.current = !0, o.current.onChange(n));
280
+ }), I.current = !1);
281
+ }, [u, t]), w(() => {
282
+ !t || t.isDestroyed || t.setEditable(!M);
283
+ }, [t, M]), w(() => {
284
+ if (!t || t.isDestroyed) return;
285
+ const e = () => {
286
+ const s = R(t);
287
+ s !== o.current.value && (I.current = !0, o.current.onChange(s));
235
288
  };
236
- return e.on("update", t), () => {
237
- e.off("update", t);
289
+ return t.on("update", e), () => {
290
+ t.off("update", e);
238
291
  };
239
- }, [e]), ue(
240
- se,
292
+ }, [t]), be(
293
+ le,
241
294
  () => ({
242
- editor: e,
243
- insertToken: (t) => {
244
- e == null || e.chain().focus().insertToken(t).run();
295
+ editor: t,
296
+ insertToken: (e) => {
297
+ t == null || t.chain().focus().insertToken(e).run();
245
298
  },
246
- focus: () => e == null ? void 0 : e.commands.focus(),
247
- getValue: () => e && !e.isDestroyed ? M(e) : ""
299
+ reload: () => {
300
+ !t || t.isDestroyed || (t.commands.setContent(
301
+ z(o.current.parse(o.current.value)),
302
+ {
303
+ emitUpdate: !1
304
+ }
305
+ ), ue((e) => e + 1));
306
+ },
307
+ focus: () => t == null ? void 0 : t.commands.focus(),
308
+ getValue: () => t && !t.isDestroyed ? R(t) : ""
248
309
  }),
249
310
  // eslint-disable-next-line react-hooks/exhaustive-deps
250
- [e]
311
+ [t]
251
312
  );
252
- const W = /* @__PURE__ */ m(
253
- pe,
313
+ const de = /* @__PURE__ */ k(
314
+ Me,
254
315
  {
255
- editor: e,
316
+ editor: t,
256
317
  className: (
257
318
  // A host's own surface classes replace the defaults wholesale: custom
258
319
  // colour tokens can't be de-duplicated by tailwind-merge.
259
- re ?? z(
320
+ ae ?? V(
260
321
  "[&_.ProseMirror_p]:m-0",
261
322
  "[&_.ProseMirror_p.is-empty::before]:pointer-events-none [&_.ProseMirror_p.is-empty::before]:float-left [&_.ProseMirror_p.is-empty::before]:h-0 [&_.ProseMirror_p.is-empty::before]:text-placeholder [&_.ProseMirror_p.is-empty::before]:content-[attr(data-placeholder)]",
262
323
  "[&_.ProseMirror-selectednode]:outline-none"
263
324
  )
264
325
  )
265
326
  }
266
- );
267
- return ee ? /* @__PURE__ */ m(
327
+ ), C = /* @__PURE__ */ k(ze.Provider, { value: ce, children: de });
328
+ return se ? /* @__PURE__ */ k(
268
329
  "div",
269
330
  {
270
- onClick: () => e == null ? void 0 : e.commands.focus(),
271
- className: z(
331
+ onClick: () => t == null ? void 0 : t.commands.focus(),
332
+ className: V(
272
333
  "w-full cursor-text rounded-lg bg-primary px-3 py-2 shadow-xs ring-1 ring-inset transition duration-100 ease-linear",
273
- K ? "ring-error_subtle" : A ? "ring-2 ring-brand" : "ring-primary",
274
- K && A && "ring-2 ring-error",
275
- k && "cursor-default bg-disabled_subtle",
276
- te
334
+ A ? "ring-error_subtle" : X ? "ring-2 ring-brand" : "ring-primary",
335
+ A && X && "ring-2 ring-error",
336
+ M && "cursor-default bg-disabled_subtle",
337
+ oe
277
338
  ),
278
- children: W
339
+ children: C
279
340
  }
280
- ) : W;
341
+ ) : C;
281
342
  }
282
343
  );
283
344
  export {
284
- Re as TokenInput,
285
- ge as TokenPill
345
+ Oe as TokenInput,
346
+ Be as TokenPill
286
347
  };
@@ -16,6 +16,8 @@ export interface TokenNodeOptions {
16
16
  getRenderToken: () => (props: TokenRenderProps) => ReactNode;
17
17
  /** Plain-text form of a token, for copy and `editor.getText()`. */
18
18
  getTokenText: () => (value: string) => string;
19
+ /** Classes for the inline wrapper around each rendered token. */
20
+ getWrapperClassName: () => string;
19
21
  }
20
22
  declare module "@tiptap/core" {
21
23
  interface Commands<ReturnType> {
@@ -25,6 +27,11 @@ declare module "@tiptap/core" {
25
27
  };
26
28
  }
27
29
  }
30
+ /**
31
+ * Bumped by TokenInput's `reload()`: node views re-render when the data their
32
+ * renderer reads (labels, a catalog) changes, even though the node did not.
33
+ */
34
+ export declare const TokenRenderVersion: import('react').Context<number>;
28
35
  /** Inline atom node holding one token; deleted as a single unit. */
29
36
  export declare const TokenNode: Node<TokenNodeOptions, any>;
30
37
  //# sourceMappingURL=token-node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"token-node.d.ts","sourceRoot":"","sources":["../../../src/rich-text/token-input/token-node.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAMrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,gBAAgB,KAAK,SAAS,CAAC;IAC7D,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/C;AAED,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,CAAC,eAAe,CAAC,EAAE;YACjB,wCAAwC;YACxC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC;SAC5C,CAAC;KACH;CACF;AAqCD,oEAAoE;AACpE,eAAO,MAAM,SAAS,6BAuEpB,CAAC"}
1
+ {"version":3,"file":"token-node.d.ts","sourceRoot":"","sources":["../../../src/rich-text/token-input/token-node.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAMrD,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,QAAQ,EAAE,OAAO,CAAC;IAClB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAC,KAAK,EAAE,gBAAgB,KAAK,SAAS,CAAC;IAC7D,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,iEAAiE;IACjE,mBAAmB,EAAE,MAAM,MAAM,CAAC;CACnC;AAED,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,CAAC,eAAe,CAAC,EAAE;YACjB,wCAAwC;YACxC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,UAAU,CAAC;SAC5C,CAAC;KACH;CACF;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,iCAAmB,CAAC;AAsCnD,oEAAoE;AACpE,eAAO,MAAM,SAAS,6BAwEpB,CAAC"}
@@ -1,26 +1,29 @@
1
1
  import { jsx as l } from "react/jsx-runtime";
2
2
  import { Node as p, mergeAttributes as m } from "@tiptap/core";
3
3
  import { ReactNodeViewRenderer as c, NodeViewWrapper as f } from "@tiptap/react";
4
+ import { createContext as T, useContext as g } from "react";
4
5
  import { TOKEN_NODE_NAME as a } from "./segments.js";
5
- function T({
6
+ const N = T(0);
7
+ function v({
6
8
  node: e,
7
9
  editor: t,
8
- getPos: n,
10
+ getPos: r,
9
11
  selected: o,
10
- extension: r
12
+ extension: n
11
13
  }) {
12
- const s = r.options, u = String(e.attrs.value ?? ""), d = () => {
14
+ g(N);
15
+ const i = n.options, u = String(e.attrs.value ?? ""), d = () => {
13
16
  if (!t.isEditable) return;
14
- const i = typeof n == "function" ? n() : null;
15
- i != null && t.chain().focus().deleteRange({ from: i, to: i + e.nodeSize }).run();
17
+ const s = typeof r == "function" ? r() : null;
18
+ s != null && t.chain().focus().deleteRange({ from: s, to: s + e.nodeSize }).run();
16
19
  };
17
20
  return /* @__PURE__ */ l(
18
21
  f,
19
22
  {
20
23
  as: "span",
21
- className: "inline-flex align-middle",
24
+ className: i.getWrapperClassName(),
22
25
  "data-type": a,
23
- children: s.getRenderToken()({
26
+ children: i.getRenderToken()({
24
27
  value: u,
25
28
  readOnly: !t.isEditable,
26
29
  selected: o,
@@ -29,7 +32,7 @@ function T({
29
32
  }
30
33
  );
31
34
  }
32
- const k = p.create({
35
+ const C = p.create({
33
36
  name: a,
34
37
  group: "inline",
35
38
  inline: !0,
@@ -38,7 +41,8 @@ const k = p.create({
38
41
  addOptions() {
39
42
  return {
40
43
  getRenderToken: () => () => null,
41
- getTokenText: () => (e) => e
44
+ getTokenText: () => (e) => e,
45
+ getWrapperClassName: () => "inline-flex align-middle"
42
46
  };
43
47
  },
44
48
  addAttributes() {
@@ -65,7 +69,7 @@ const k = p.create({
65
69
  return t ? this.options.getTokenText()(t) : "";
66
70
  },
67
71
  addNodeView() {
68
- return c(T);
72
+ return c(v);
69
73
  },
70
74
  addCommands() {
71
75
  return {
@@ -76,14 +80,15 @@ const k = p.create({
76
80
  return {
77
81
  // Without this, the first Backspace only selects the atom.
78
82
  Backspace: () => this.editor.commands.command(({ state: e, dispatch: t }) => {
79
- const { $from: n, empty: o } = e.selection;
83
+ const { $from: r, empty: o } = e.selection;
80
84
  if (!o) return !1;
81
- const r = n.nodeBefore;
82
- return !r || r.type.name !== this.name ? !1 : (t && t(e.tr.delete(n.pos - r.nodeSize, n.pos)), !0);
85
+ const n = r.nodeBefore;
86
+ return !n || n.type.name !== this.name ? !1 : (t && t(e.tr.delete(r.pos - n.nodeSize, r.pos)), !0);
83
87
  })
84
88
  };
85
89
  }
86
90
  });
87
91
  export {
88
- k as TokenNode
92
+ C as TokenNode,
93
+ N as TokenRenderVersion
89
94
  };