@pibit.ai/cure-design-system 0.6.50 → 0.6.52
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.
- package/dist/_virtual/index.js +3 -2
- package/dist/_virtual/index2.js +5 -3
- package/dist/_virtual/index3.js +2 -5
- package/dist/node_modules/eventemitter3/index.js +1 -1
- package/dist/node_modules/react-is/index.js +1 -1
- package/dist/node_modules/recharts/es6/util/Events.js +1 -1
- package/dist/node_modules/recharts/es6/util/ReactUtils.js +1 -1
- package/dist/node_modules/use-sync-external-store/shim/index.js +1 -1
- package/dist/patterns/filters/status-filter-dropdown.d.ts.map +1 -1
- package/dist/patterns/filters/status-filter-dropdown.js +73 -65
- package/dist/rich-text/index.d.ts +1 -0
- package/dist/rich-text/index.d.ts.map +1 -1
- package/dist/rich-text/index.js +34 -26
- package/dist/rich-text/token-input/index.d.ts +5 -0
- package/dist/rich-text/token-input/index.d.ts.map +1 -0
- package/dist/rich-text/token-input/segments.d.ts +27 -0
- package/dist/rich-text/token-input/segments.d.ts.map +1 -0
- package/dist/rich-text/token-input/segments.js +48 -0
- package/dist/rich-text/token-input/token-input.d.ts +96 -0
- package/dist/rich-text/token-input/token-input.d.ts.map +1 -0
- package/dist/rich-text/token-input/token-input.js +286 -0
- package/dist/rich-text/token-input/token-node.d.ts +30 -0
- package/dist/rich-text/token-input/token-node.d.ts.map +1 -0
- package/dist/rich-text/token-input/token-node.js +89 -0
- package/dist/rich-text/token-input/token-suggestion.d.ts +37 -0
- package/dist/rich-text/token-input/token-suggestion.d.ts.map +1 -0
- package/dist/rich-text/token-input/token-suggestion.js +110 -0
- package/dist/styles/components.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-input.d.ts","sourceRoot":"","sources":["../../../src/rich-text/token-input/token-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,K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ACtE,iBAAiB,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD;AAQD,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,IAAI,EACJ,IAAgB,EAChB,QAAQ,GACT,EAAE,YAAY,GAAG;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,2CAevC;AAID;;;;GAIG;AACH,eAAO,MAAM,UAAU,8GAmUtB,CAAC"}
|
|
@@ -0,0 +1,286 @@
|
|
|
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 = {
|
|
11
|
+
neutral: "border-secondary bg-primary text-secondary",
|
|
12
|
+
brand: "border-utility-brand-200 bg-utility-brand-50 text-utility-brand-700",
|
|
13
|
+
error: "border-utility-error-200 bg-utility-error-50 text-utility-error-700"
|
|
14
|
+
};
|
|
15
|
+
function ge({
|
|
16
|
+
label: x,
|
|
17
|
+
icon: i,
|
|
18
|
+
tone: b = "neutral",
|
|
19
|
+
selected: f
|
|
20
|
+
}) {
|
|
21
|
+
return /* @__PURE__ */ ie(
|
|
22
|
+
"span",
|
|
23
|
+
{
|
|
24
|
+
className: z(
|
|
25
|
+
"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"
|
|
28
|
+
),
|
|
29
|
+
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 })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const I = (x) => x.replace(/\r\n|\r|\n/g, ""), Re = le(
|
|
37
|
+
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
|
|
78
|
+
});
|
|
79
|
+
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
|
|
94
|
+
};
|
|
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(
|
|
96
|
+
() => [
|
|
97
|
+
me.configure({
|
|
98
|
+
bold: !1,
|
|
99
|
+
blockquote: !1,
|
|
100
|
+
bulletList: !1,
|
|
101
|
+
code: !1,
|
|
102
|
+
codeBlock: !1,
|
|
103
|
+
heading: !1,
|
|
104
|
+
horizontalRule: !1,
|
|
105
|
+
italic: !1,
|
|
106
|
+
link: !1,
|
|
107
|
+
orderedList: !1,
|
|
108
|
+
strike: !1,
|
|
109
|
+
underline: !1,
|
|
110
|
+
listItem: !1,
|
|
111
|
+
listKeymap: !1
|
|
112
|
+
}),
|
|
113
|
+
fe.configure({ placeholder: v ?? "" }),
|
|
114
|
+
ye.configure({
|
|
115
|
+
getRenderToken: () => o.current.renderToken ?? ((t) => {
|
|
116
|
+
var n, r;
|
|
117
|
+
return /* @__PURE__ */ m(
|
|
118
|
+
ge,
|
|
119
|
+
{
|
|
120
|
+
...((r = (n = o.current).getTokenDisplay) == null ? void 0 : r.call(n, t.value)) ?? {
|
|
121
|
+
label: t.value
|
|
122
|
+
},
|
|
123
|
+
selected: t.selected
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}),
|
|
127
|
+
getTokenText: () => O
|
|
128
|
+
}),
|
|
129
|
+
...y != null && y.length ? [
|
|
130
|
+
ke(y, (t) => {
|
|
131
|
+
J.current = t;
|
|
132
|
+
})
|
|
133
|
+
] : [],
|
|
134
|
+
...C ?? []
|
|
135
|
+
],
|
|
136
|
+
// Extensions are fixed for the editor's lifetime, like the original inputs.
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
[]
|
|
139
|
+
), e = de({
|
|
140
|
+
immediatelyRender: !1,
|
|
141
|
+
editable: !k,
|
|
142
|
+
extensions: oe,
|
|
143
|
+
content: E(f(i)),
|
|
144
|
+
editorProps: {
|
|
145
|
+
attributes: ne ?? {
|
|
146
|
+
class: "w-full outline-none text-sm text-primary"
|
|
147
|
+
},
|
|
148
|
+
handleDOMEvents: {
|
|
149
|
+
focus: (t, n) => {
|
|
150
|
+
var r, s;
|
|
151
|
+
return G(!0), (s = (r = o.current).onFocus) == null || s.call(r, n), !1;
|
|
152
|
+
},
|
|
153
|
+
blur: (t, n) => {
|
|
154
|
+
var r, s;
|
|
155
|
+
return G(!1), (s = (r = o.current).onBlur) == null || s.call(r, n), !1;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
clipboardTextSerializer: (t, n) => {
|
|
159
|
+
const { from: r, to: s } = n.state.selection;
|
|
160
|
+
return xe(n.state.doc, r, s, O);
|
|
161
|
+
},
|
|
162
|
+
handlePaste: (t, n) => {
|
|
163
|
+
var $;
|
|
164
|
+
n.preventDefault();
|
|
165
|
+
const r = o.current;
|
|
166
|
+
let s = (($ = n.clipboardData) == null ? void 0 : $.getData("text/plain")) || "";
|
|
167
|
+
if (!s || !r.preservePastedNewlines && (s = I(s), !s))
|
|
168
|
+
return !0;
|
|
169
|
+
const { from: a, to: p } = t.state.selection, X = {
|
|
170
|
+
docText: t.state.doc.textBetween(
|
|
171
|
+
0,
|
|
172
|
+
t.state.doc.content.size,
|
|
173
|
+
"",
|
|
174
|
+
""
|
|
175
|
+
),
|
|
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)
|
|
182
|
+
if (l.type === "token")
|
|
183
|
+
c.push({ token: l.value });
|
|
184
|
+
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 });
|
|
188
|
+
}
|
|
189
|
+
const N = Y.chain().focus();
|
|
190
|
+
for (const l of c)
|
|
191
|
+
if ("token" in l)
|
|
192
|
+
N.insertToken(l.token);
|
|
193
|
+
else {
|
|
194
|
+
let u = g ? g(l.text, X) : l.text;
|
|
195
|
+
r.preservePastedNewlines || (u = I(u)), u && N.insertContent(u);
|
|
196
|
+
}
|
|
197
|
+
return N.run(), !0;
|
|
198
|
+
}
|
|
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;
|
|
201
|
+
},
|
|
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(
|
|
207
|
+
0,
|
|
208
|
+
t.state.doc.content.size,
|
|
209
|
+
"",
|
|
210
|
+
""
|
|
211
|
+
),
|
|
212
|
+
textBefore: t.state.doc.textBetween(0, n, "", ""),
|
|
213
|
+
raw: s
|
|
214
|
+
});
|
|
215
|
+
return p === s ? !1 : (p && t.dispatch(t.state.tr.insertText(p, n, r)), !0);
|
|
216
|
+
},
|
|
217
|
+
handleKeyDown: (t, n) => {
|
|
218
|
+
var s, a;
|
|
219
|
+
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;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
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)), {
|
|
226
|
+
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));
|
|
235
|
+
};
|
|
236
|
+
return e.on("update", t), () => {
|
|
237
|
+
e.off("update", t);
|
|
238
|
+
};
|
|
239
|
+
}, [e]), ue(
|
|
240
|
+
se,
|
|
241
|
+
() => ({
|
|
242
|
+
editor: e,
|
|
243
|
+
insertToken: (t) => {
|
|
244
|
+
e == null || e.chain().focus().insertToken(t).run();
|
|
245
|
+
},
|
|
246
|
+
focus: () => e == null ? void 0 : e.commands.focus(),
|
|
247
|
+
getValue: () => e && !e.isDestroyed ? M(e) : ""
|
|
248
|
+
}),
|
|
249
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
250
|
+
[e]
|
|
251
|
+
);
|
|
252
|
+
const W = /* @__PURE__ */ m(
|
|
253
|
+
pe,
|
|
254
|
+
{
|
|
255
|
+
editor: e,
|
|
256
|
+
className: (
|
|
257
|
+
// A host's own surface classes replace the defaults wholesale: custom
|
|
258
|
+
// colour tokens can't be de-duplicated by tailwind-merge.
|
|
259
|
+
re ?? z(
|
|
260
|
+
"[&_.ProseMirror_p]:m-0",
|
|
261
|
+
"[&_.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
|
+
"[&_.ProseMirror-selectednode]:outline-none"
|
|
263
|
+
)
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
return ee ? /* @__PURE__ */ m(
|
|
268
|
+
"div",
|
|
269
|
+
{
|
|
270
|
+
onClick: () => e == null ? void 0 : e.commands.focus(),
|
|
271
|
+
className: z(
|
|
272
|
+
"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
|
|
277
|
+
),
|
|
278
|
+
children: W
|
|
279
|
+
}
|
|
280
|
+
) : W;
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
export {
|
|
284
|
+
Re as TokenInput,
|
|
285
|
+
ge as TokenPill
|
|
286
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { TOKEN_NODE_NAME } from './segments';
|
|
4
|
+
export interface TokenRenderProps {
|
|
5
|
+
/** The token's value, as produced by `parse` (e.g. a field path). */
|
|
6
|
+
value: string;
|
|
7
|
+
/** True when the editor is read-only. */
|
|
8
|
+
readOnly: boolean;
|
|
9
|
+
/** True when the token is the selected node. */
|
|
10
|
+
selected: boolean;
|
|
11
|
+
/** Removes this token from the document. */
|
|
12
|
+
remove: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface TokenNodeOptions {
|
|
15
|
+
/** Read at render time so the latest app renderer is always used. */
|
|
16
|
+
getRenderToken: () => (props: TokenRenderProps) => ReactNode;
|
|
17
|
+
/** Plain-text form of a token, for copy and `editor.getText()`. */
|
|
18
|
+
getTokenText: () => (value: string) => string;
|
|
19
|
+
}
|
|
20
|
+
declare module "@tiptap/core" {
|
|
21
|
+
interface Commands<ReturnType> {
|
|
22
|
+
[TOKEN_NODE_NAME]: {
|
|
23
|
+
/** Inserts a token at the selection. */
|
|
24
|
+
insertToken: (value: string) => ReturnType;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Inline atom node holding one token; deleted as a single unit. */
|
|
29
|
+
export declare const TokenNode: Node<TokenNodeOptions, any>;
|
|
30
|
+
//# sourceMappingURL=token-node.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import { Node as p, mergeAttributes as m } from "@tiptap/core";
|
|
3
|
+
import { ReactNodeViewRenderer as c, NodeViewWrapper as f } from "@tiptap/react";
|
|
4
|
+
import { TOKEN_NODE_NAME as a } from "./segments.js";
|
|
5
|
+
function T({
|
|
6
|
+
node: e,
|
|
7
|
+
editor: t,
|
|
8
|
+
getPos: n,
|
|
9
|
+
selected: o,
|
|
10
|
+
extension: r
|
|
11
|
+
}) {
|
|
12
|
+
const s = r.options, u = String(e.attrs.value ?? ""), d = () => {
|
|
13
|
+
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();
|
|
16
|
+
};
|
|
17
|
+
return /* @__PURE__ */ l(
|
|
18
|
+
f,
|
|
19
|
+
{
|
|
20
|
+
as: "span",
|
|
21
|
+
className: "inline-flex align-middle",
|
|
22
|
+
"data-type": a,
|
|
23
|
+
children: s.getRenderToken()({
|
|
24
|
+
value: u,
|
|
25
|
+
readOnly: !t.isEditable,
|
|
26
|
+
selected: o,
|
|
27
|
+
remove: d
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const k = p.create({
|
|
33
|
+
name: a,
|
|
34
|
+
group: "inline",
|
|
35
|
+
inline: !0,
|
|
36
|
+
atom: !0,
|
|
37
|
+
selectable: !0,
|
|
38
|
+
addOptions() {
|
|
39
|
+
return {
|
|
40
|
+
getRenderToken: () => () => null,
|
|
41
|
+
getTokenText: () => (e) => e
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
addAttributes() {
|
|
45
|
+
return {
|
|
46
|
+
value: {
|
|
47
|
+
default: null,
|
|
48
|
+
parseHTML: (e) => e.getAttribute("data-value"),
|
|
49
|
+
renderHTML: (e) => e.value ? { "data-value": e.value } : {}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
parseHTML() {
|
|
54
|
+
return [{ tag: `span[data-type="${a}"]` }];
|
|
55
|
+
},
|
|
56
|
+
renderHTML({ node: e, HTMLAttributes: t }) {
|
|
57
|
+
return [
|
|
58
|
+
"span",
|
|
59
|
+
m({ "data-type": a }, t),
|
|
60
|
+
String(e.attrs.value ?? "")
|
|
61
|
+
];
|
|
62
|
+
},
|
|
63
|
+
renderText({ node: e }) {
|
|
64
|
+
const t = e.attrs.value;
|
|
65
|
+
return t ? this.options.getTokenText()(t) : "";
|
|
66
|
+
},
|
|
67
|
+
addNodeView() {
|
|
68
|
+
return c(T);
|
|
69
|
+
},
|
|
70
|
+
addCommands() {
|
|
71
|
+
return {
|
|
72
|
+
insertToken: (e) => ({ commands: t }) => t.insertContent({ type: this.name, attrs: { value: e } })
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
addKeyboardShortcuts() {
|
|
76
|
+
return {
|
|
77
|
+
// Without this, the first Backspace only selects the atom.
|
|
78
|
+
Backspace: () => this.editor.commands.command(({ state: e, dispatch: t }) => {
|
|
79
|
+
const { $from: n, empty: o } = e.selection;
|
|
80
|
+
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);
|
|
83
|
+
})
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
export {
|
|
88
|
+
k as TokenNode
|
|
89
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export interface TokenSuggestionItem {
|
|
4
|
+
/** Inserted as the token's value. */
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface TokenSuggestionTrigger {
|
|
11
|
+
/** Character(s) that open the menu, e.g. "/", "{{" or "@". */
|
|
12
|
+
char: string;
|
|
13
|
+
/** Items for the text typed after the trigger; filter as you see fit. */
|
|
14
|
+
items: (query: string) => TokenSuggestionItem[] | Promise<TokenSuggestionItem[]>;
|
|
15
|
+
/** Let the query contain spaces. @default false */
|
|
16
|
+
allowSpaces?: boolean;
|
|
17
|
+
/** Characters allowed right before the trigger. @default [" "] plus line start */
|
|
18
|
+
allowedPrefixes?: string[] | null;
|
|
19
|
+
/** Message when nothing matches. @default "No matches" */
|
|
20
|
+
emptyMessage?: string;
|
|
21
|
+
}
|
|
22
|
+
interface ListProps {
|
|
23
|
+
items: TokenSuggestionItem[];
|
|
24
|
+
emptyMessage: string;
|
|
25
|
+
onSelect: (item: TokenSuggestionItem) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface TokenSuggestionListHandle {
|
|
28
|
+
onKeyDown: (event: KeyboardEvent) => boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare const TokenSuggestionList: import('react').ForwardRefExoticComponent<ListProps & import('react').RefAttributes<TokenSuggestionListHandle>>;
|
|
31
|
+
/**
|
|
32
|
+
* One Suggestion plugin per trigger. `onOpenChange` reports whether any menu is
|
|
33
|
+
* showing, so TokenInput lets Enter through to the menu in single-line fields.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createTokenSuggestionExtension(triggers: TokenSuggestionTrigger[], onOpenChange: (open: boolean) => void): Extension<any, any>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=token-suggestion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-suggestion.d.ts","sourceRoot":"","sources":["../../../src/rich-text/token-input/token-suggestion.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,sBAAsB;IACrC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,yEAAyE;IACzE,KAAK,EAAE,CACL,KAAK,EAAE,MAAM,KACV,mBAAmB,EAAE,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAC5D,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAClC,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,SAAS;IACjB,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;CAC9C;AAED,eAAO,MAAM,mBAAmB,iHAqE9B,CAAC;AAGH;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,sBAAsB,EAAE,EAClC,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,uBAmFtC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as i, jsxs as u } from "react/jsx-runtime";
|
|
2
|
+
import { Extension as d } from "@tiptap/core";
|
|
3
|
+
import { PluginKey as f } from "@tiptap/pm/state";
|
|
4
|
+
import { ReactRenderer as y } from "@tiptap/react";
|
|
5
|
+
import g from "@tiptap/suggestion";
|
|
6
|
+
import { forwardRef as h, useState as w, useEffect as x, useImperativeHandle as k } from "react";
|
|
7
|
+
import R from "tippy.js";
|
|
8
|
+
import { cx as b } from "../../utils/cn.js";
|
|
9
|
+
const m = h(({ items: o, emptyMessage: s, onSelect: l }, c) => {
|
|
10
|
+
const [t, r] = w(0);
|
|
11
|
+
return x(() => r(0), [o]), k(c, () => ({
|
|
12
|
+
onKeyDown: (n) => o.length ? n.key === "ArrowDown" ? (r((e) => (e + 1) % o.length), !0) : n.key === "ArrowUp" ? (r((e) => (e + o.length - 1) % o.length), !0) : n.key === "Enter" || n.key === "Tab" ? (l(o[t]), !0) : !1 : !1
|
|
13
|
+
})), /* @__PURE__ */ i(
|
|
14
|
+
"div",
|
|
15
|
+
{
|
|
16
|
+
role: "listbox",
|
|
17
|
+
"aria-label": "Suggestions",
|
|
18
|
+
className: "max-h-64 min-w-56 overflow-y-auto rounded-lg bg-primary p-1 shadow-lg ring-1 ring-secondary",
|
|
19
|
+
onMouseDown: (n) => n.preventDefault(),
|
|
20
|
+
children: o.length === 0 ? /* @__PURE__ */ i("div", { className: "px-2.5 py-2 text-sm text-tertiary", children: s }) : o.map((n, e) => /* @__PURE__ */ u(
|
|
21
|
+
"div",
|
|
22
|
+
{
|
|
23
|
+
role: "option",
|
|
24
|
+
"aria-selected": e === t,
|
|
25
|
+
onMouseEnter: () => r(e),
|
|
26
|
+
onClick: () => l(n),
|
|
27
|
+
className: b(
|
|
28
|
+
"flex cursor-pointer items-center gap-2 rounded-md px-2.5 py-2 text-sm",
|
|
29
|
+
e === t ? "bg-primary_hover" : ""
|
|
30
|
+
),
|
|
31
|
+
children: [
|
|
32
|
+
n.icon && /* @__PURE__ */ i("span", { className: "flex size-4 shrink-0 items-center text-fg-quaternary", children: n.icon }),
|
|
33
|
+
/* @__PURE__ */ u("span", { className: "min-w-0 flex-1", children: [
|
|
34
|
+
/* @__PURE__ */ i("span", { className: "block truncate font-medium text-secondary", children: n.label }),
|
|
35
|
+
n.description && /* @__PURE__ */ i("span", { className: "block truncate text-xs text-tertiary", children: n.description })
|
|
36
|
+
] })
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
`${n.value}-${e}`
|
|
40
|
+
))
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
m.displayName = "TokenSuggestionList";
|
|
45
|
+
function T(o, s) {
|
|
46
|
+
return d.create({
|
|
47
|
+
name: "tokenSuggestion",
|
|
48
|
+
addProseMirrorPlugins() {
|
|
49
|
+
return o.map(
|
|
50
|
+
(l, c) => g({
|
|
51
|
+
editor: this.editor,
|
|
52
|
+
char: l.char,
|
|
53
|
+
pluginKey: new f(`tokenSuggestion${c}`),
|
|
54
|
+
allowSpaces: l.allowSpaces ?? !1,
|
|
55
|
+
allowedPrefixes: l.allowedPrefixes === void 0 ? [" "] : l.allowedPrefixes,
|
|
56
|
+
items: ({ query: t }) => l.items(t),
|
|
57
|
+
command: ({ editor: t, range: r, props: n }) => {
|
|
58
|
+
t.chain().focus().deleteRange(r).insertToken(n.value).run();
|
|
59
|
+
},
|
|
60
|
+
render: () => {
|
|
61
|
+
let t = null, r = null;
|
|
62
|
+
const n = (e) => ({
|
|
63
|
+
items: e.items,
|
|
64
|
+
emptyMessage: l.emptyMessage ?? "No matches",
|
|
65
|
+
onSelect: (a) => e.command(a)
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
onStart: (e) => {
|
|
69
|
+
s(!0), t = new y(m, {
|
|
70
|
+
props: n(e),
|
|
71
|
+
editor: e.editor
|
|
72
|
+
}), e.clientRect && (r = R(document.body, {
|
|
73
|
+
getReferenceClientRect: () => {
|
|
74
|
+
var a;
|
|
75
|
+
return ((a = e.clientRect) == null ? void 0 : a.call(e)) ?? new DOMRect();
|
|
76
|
+
},
|
|
77
|
+
appendTo: () => document.body,
|
|
78
|
+
content: t.element,
|
|
79
|
+
showOnCreate: !0,
|
|
80
|
+
interactive: !0,
|
|
81
|
+
trigger: "manual",
|
|
82
|
+
placement: "bottom-start"
|
|
83
|
+
}));
|
|
84
|
+
},
|
|
85
|
+
onUpdate: (e) => {
|
|
86
|
+
t == null || t.updateProps(n(e)), r == null || r.setProps({
|
|
87
|
+
getReferenceClientRect: () => {
|
|
88
|
+
var a;
|
|
89
|
+
return ((a = e.clientRect) == null ? void 0 : a.call(e)) ?? new DOMRect();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
onKeyDown: ({ event: e }) => {
|
|
94
|
+
var a;
|
|
95
|
+
return e.key === "Escape" ? (r == null || r.hide(), !0) : ((a = t == null ? void 0 : t.ref) == null ? void 0 : a.onKeyDown(e)) ?? !1;
|
|
96
|
+
},
|
|
97
|
+
onExit: () => {
|
|
98
|
+
s(!1), r == null || r.destroy(), t == null || t.destroy(), r = null, t = null;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
m as TokenSuggestionList,
|
|
109
|
+
T as createTokenSuggestionExtension
|
|
110
|
+
};
|