laif-ds 1.1.2 → 1.1.3

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,207 +1,231 @@
1
1
  "use client";
2
- import { jsx as r, jsxs as t, Fragment as p } from "react/jsx-runtime";
3
- import { ListNode as H, ListItemNode as D } from "../../node_modules/@lexical/list/dist/LexicalList.prod.js";
4
- import { TRANSFORMERS as U, $convertToMarkdownString as _, $convertFromMarkdownString as z } from "../../node_modules/@lexical/markdown/dist/LexicalMarkdown.prod.js";
5
- import { CheckListPlugin as Q } from "../../node_modules/@lexical/react/dist/LexicalCheckListPlugin.prod.js";
6
- import { ClearEditorPlugin as K } from "../../node_modules/@lexical/react/dist/LexicalClearEditorPlugin.prod.js";
7
- import { LexicalComposer as W } from "../../node_modules/@lexical/react/dist/LexicalComposer.prod.js";
8
- import { useLexicalComposerContext as q } from "../../node_modules/@lexical/react/dist/LexicalComposerContext.prod.js";
9
- import { LexicalErrorBoundary as G } from "../../node_modules/@lexical/react/dist/LexicalErrorBoundary.prod.js";
10
- import { HistoryPlugin as J } from "../../node_modules/@lexical/react/dist/LexicalHistoryPlugin.prod.js";
11
- import { ListPlugin as X } from "../../node_modules/@lexical/react/dist/LexicalListPlugin.prod.js";
12
- import { OnChangePlugin as Y } from "../../node_modules/@lexical/react/dist/LexicalOnChangePlugin.prod.js";
13
- import { RichTextPlugin as Z } from "../../node_modules/@lexical/react/dist/LexicalRichTextPlugin.prod.js";
14
- import { HeadingNode as V, QuoteNode as rr } from "../../node_modules/@lexical/rich-text/dist/LexicalRichText.prod.js";
15
- import { ParagraphNode as g, TextNode as h, $nodesOfType as or, $getRoot as b } from "../../node_modules/lexical/dist/Lexical.prod.js";
16
- import { useState as er, useMemo as tr, useEffect as ir } from "react";
17
- import { ContentEditable as nr } from "../editor/editor-ui/content-editable.js";
18
- import { MentionNode as w } from "../editor/nodes/mention-node.js";
19
- import { ActionsPlugin as lr } from "../editor/plugins/actions/actions-plugin.js";
20
- import { ClearEditorActionPlugin as ar } from "../editor/plugins/actions/clear-editor-plugin.js";
21
- import { CounterCharacterPlugin as sr } from "../editor/plugins/actions/counter-character-plugin.js";
22
- import { MENTION_TRANSFORMER as mr, MentionPlugin as cr, collectMentions as dr } from "../editor/plugins/mention-plugin.js";
23
- import { FormatBulletedList as fr } from "../editor/plugins/toolbar/block-format/format-bulleted-list.js";
24
- import { FormatCheckList as pr } from "../editor/plugins/toolbar/block-format/format-check-list.js";
25
- import { FormatHeading as ur } from "../editor/plugins/toolbar/block-format/format-heading.js";
26
- import { FormatNumberedList as gr } from "../editor/plugins/toolbar/block-format/format-numbered-list.js";
27
- import { FormatParagraph as hr } from "../editor/plugins/toolbar/block-format/format-paragraph.js";
28
- import { FormatQuote as br } from "../editor/plugins/toolbar/block-format/format-quote.js";
29
- import { BlockFormatDropDown as xr } from "../editor/plugins/toolbar/block-format-toolbar-plugin.js";
30
- import { FontFormatToolbarPlugin as d } from "../editor/plugins/toolbar/font-format-toolbar-plugin.js";
31
- import { MentionInsertToolbarPlugin as Nr } from "../editor/plugins/toolbar/mention-insert-toolbar-plugin.js";
32
- import { ToolbarPlugin as u } from "../editor/plugins/toolbar/toolbar-plugin.js";
33
- import { editorTheme as vr } from "../editor/themes/editor-theme.js";
34
- import { TooltipProvider as Er } from "./tooltip.js";
35
- import { HistoryToolbarPlugin as Fr } from "../editor/plugins/toolbar/history-toolbar-plugin.js";
36
- import { cn as Cr } from "../../lib/utils.js";
37
- const Pr = "Start typing...", yr = {
2
+ import { jsx as r, jsxs as n, Fragment as u } from "react/jsx-runtime";
3
+ import { LinkNode as U } from "../../node_modules/@lexical/link/dist/LexicalLink.prod.js";
4
+ import { ListNode as _, ListItemNode as Q } from "../../node_modules/@lexical/list/dist/LexicalList.prod.js";
5
+ import { TRANSFORMERS as K, $convertToMarkdownString as W, $convertFromMarkdownString as Z } from "../../node_modules/@lexical/markdown/dist/LexicalMarkdown.prod.js";
6
+ import { CheckListPlugin as q } from "../../node_modules/@lexical/react/dist/LexicalCheckListPlugin.prod.js";
7
+ import { ClearEditorPlugin as G } from "../../node_modules/@lexical/react/dist/LexicalClearEditorPlugin.prod.js";
8
+ import { LexicalComposer as J } from "../../node_modules/@lexical/react/dist/LexicalComposer.prod.js";
9
+ import { useLexicalComposerContext as L } from "../../node_modules/@lexical/react/dist/LexicalComposerContext.prod.js";
10
+ import { LexicalErrorBoundary as X } from "../../node_modules/@lexical/react/dist/LexicalErrorBoundary.prod.js";
11
+ import { HistoryPlugin as Y } from "../../node_modules/@lexical/react/dist/LexicalHistoryPlugin.prod.js";
12
+ import { ListPlugin as V } from "../../node_modules/@lexical/react/dist/LexicalListPlugin.prod.js";
13
+ import { OnChangePlugin as rr } from "../../node_modules/@lexical/react/dist/LexicalOnChangePlugin.prod.js";
14
+ import { RichTextPlugin as or } from "../../node_modules/@lexical/react/dist/LexicalRichTextPlugin.prod.js";
15
+ import { HeadingNode as er, QuoteNode as tr } from "../../node_modules/@lexical/rich-text/dist/LexicalRichText.prod.js";
16
+ import { ParagraphNode as g, TextNode as h, $nodesOfType as ir, $getRoot as N } from "../../node_modules/lexical/dist/Lexical.prod.js";
17
+ import { forwardRef as nr, useState as lr, useMemo as ar, useImperativeHandle as sr, useEffect as mr } from "react";
18
+ import { ContentEditable as cr } from "../editor/editor-ui/content-editable.js";
19
+ import { MentionNode as k } from "../editor/nodes/mention-node.js";
20
+ import { ActionsPlugin as dr } from "../editor/plugins/actions/actions-plugin.js";
21
+ import { ClearEditorActionPlugin as pr } from "../editor/plugins/actions/clear-editor-plugin.js";
22
+ import { CounterCharacterPlugin as fr } from "../editor/plugins/actions/counter-character-plugin.js";
23
+ import { MENTION_TRANSFORMER as ur, MentionPlugin as gr, collectMentions as hr } from "../editor/plugins/mention-plugin.js";
24
+ import { FormatBulletedList as Nr } from "../editor/plugins/toolbar/block-format/format-bulleted-list.js";
25
+ import { FormatCheckList as br } from "../editor/plugins/toolbar/block-format/format-check-list.js";
26
+ import { FormatHeading as vr } from "../editor/plugins/toolbar/block-format/format-heading.js";
27
+ import { FormatNumberedList as xr } from "../editor/plugins/toolbar/block-format/format-numbered-list.js";
28
+ import { FormatParagraph as Er } from "../editor/plugins/toolbar/block-format/format-paragraph.js";
29
+ import { FormatQuote as Fr } from "../editor/plugins/toolbar/block-format/format-quote.js";
30
+ import { BlockFormatDropDown as Pr } from "../editor/plugins/toolbar/block-format-toolbar-plugin.js";
31
+ import { FontFormatToolbarPlugin as m } from "../editor/plugins/toolbar/font-format-toolbar-plugin.js";
32
+ import { LinkToolbarPlugin as yr, $insertLink as Rr } from "../editor/plugins/toolbar/link-toolbar-plugin.js";
33
+ import { MentionInsertToolbarPlugin as Cr } from "../editor/plugins/toolbar/mention-insert-toolbar-plugin.js";
34
+ import { ToolbarPlugin as f } from "../editor/plugins/toolbar/toolbar-plugin.js";
35
+ import { editorTheme as Tr } from "../editor/themes/editor-theme.js";
36
+ import { TooltipProvider as kr } from "./tooltip.js";
37
+ import { HistoryToolbarPlugin as wr } from "../editor/plugins/toolbar/history-toolbar-plugin.js";
38
+ import { cn as Lr } from "../../lib/utils.js";
39
+ const Sr = "Start typing...", Ar = {
38
40
  format: ["underline"],
39
41
  tag: "++",
40
42
  type: "text-format"
41
- }, S = [
42
- ...U,
43
- yr
44
- ], Tr = (o) => o.replace(/<u>(.*?)<\/u>/g, "++$1++"), Rr = (o) => o.replace(/\+\+(.+?)\+\+/g, "<u>$1</u>");
45
- function wr({
43
+ }, w = [
44
+ ...K,
45
+ Ar
46
+ ], Mr = (o) => o.replace(/<u>(.*?)<\/u>/g, "++$1++"), $r = (o) => o.replace(/\+\+(.+?)\+\+/g, "<u>$1</u>");
47
+ function Ir({
48
+ handleRef: o
49
+ }) {
50
+ const [e] = L();
51
+ return sr(
52
+ o,
53
+ () => ({
54
+ insertLink: (t, a) => {
55
+ e.focus(), e.update(() => Rr(t, a));
56
+ }
57
+ }),
58
+ [e]
59
+ ), null;
60
+ }
61
+ function Or({
46
62
  defaultValue: o,
47
- onlyMarkdown: a,
48
- transformers: n
63
+ onlyMarkdown: e,
64
+ transformers: t
49
65
  }) {
50
- const [s] = q();
51
- return ir(() => {
52
- o && s.update(() => {
53
- a ? z(
54
- Tr(o),
55
- n
56
- ) : b().append(
66
+ const [a] = L();
67
+ return mr(() => {
68
+ o && a.update(() => {
69
+ e ? Z(
70
+ Mr(o),
71
+ t
72
+ ) : N().append(
57
73
  new g().append(new h(o))
58
74
  );
59
- const m = b();
60
- (m.getFirstChild() ?? m).selectStart();
75
+ const c = N();
76
+ (c.getFirstChild() ?? c).selectStart();
61
77
  });
62
- }, [s, o, a, n]), null;
78
+ }, [a, o, e, t]), null;
63
79
  }
64
- function co({
80
+ function Hr({
65
81
  defaultValue: o,
66
- onMarkdownEdit: a,
67
- onValueChange: n,
68
- plugins: s = [],
69
- toolbars: m = [],
70
- placeholder: L = Pr,
71
- onlyMarkdown: x = !0,
72
- className: M = "rounded-lg border border-d-border",
73
- wrpClassName: A = "",
74
- mentions: c,
75
- mentionTrigger: N = "@"
76
- }) {
77
- const [, k] = er(null), l = c !== void 0, v = tr(
78
- () => l ? [mr, ...S] : S,
79
- [l]
82
+ onMarkdownEdit: e,
83
+ onValueChange: t,
84
+ plugins: a = [],
85
+ toolbars: c = [],
86
+ placeholder: S = Sr,
87
+ onlyMarkdown: b = !0,
88
+ className: A = "rounded-lg border border-d-border",
89
+ wrpClassName: M = "",
90
+ mentions: d,
91
+ mentionTrigger: v = "@"
92
+ }, $) {
93
+ const [, I] = lr(null), s = d !== void 0, x = ar(
94
+ () => s ? [ur, ...w] : w,
95
+ [s]
80
96
  ), O = {
81
97
  namespace: "AppEditor",
82
- theme: vr,
98
+ theme: Tr,
83
99
  nodes: [
84
- V,
100
+ er,
85
101
  g,
86
102
  h,
87
- rr,
88
- H,
89
- D,
90
- ...l ? [w] : []
103
+ tr,
104
+ _,
105
+ Q,
106
+ // TRANSFORMERS includes the Markdown LINK transformer, which needs this
107
+ // node to import `[text](url)` from `defaultValue`.
108
+ U,
109
+ ...s ? [k] : []
91
110
  ],
92
- onError: (e) => {
93
- console.error(e);
111
+ onError: (i) => {
112
+ console.error(i);
94
113
  },
95
- ...o && !x ? {
114
+ ...o && !b ? {
96
115
  editorState: () => {
97
- b().append(
116
+ N().append(
98
117
  new g().append(new h(o))
99
118
  );
100
119
  }
101
120
  } : {}
102
- }, E = (e) => s.includes(e), f = (e) => m.includes(e), F = E("clear"), C = E("counter"), P = f("block-format"), $ = f("font-format"), y = f("history");
103
- return /* @__PURE__ */ r("div", { className: Cr("bg-d-background flex h-96 flex-col", A), children: /* @__PURE__ */ r(W, { initialConfig: O, children: /* @__PURE__ */ t(Er, { children: [
121
+ }, E = (i) => a.includes(i), p = (i) => c.includes(i), F = E("clear"), P = E("counter"), y = p("block-format"), H = p("font-format"), R = p("history"), j = p("link");
122
+ return /* @__PURE__ */ r("div", { className: Lr("bg-d-background flex h-96 flex-col", M), children: /* @__PURE__ */ r(J, { initialConfig: O, children: /* @__PURE__ */ n(kr, { children: [
123
+ /* @__PURE__ */ r(Ir, { handleRef: $ }),
104
124
  o && /* @__PURE__ */ r(
105
- wr,
125
+ Or,
106
126
  {
107
127
  defaultValue: o,
108
- onlyMarkdown: x,
109
- transformers: v
128
+ onlyMarkdown: b,
129
+ transformers: x
110
130
  }
111
131
  ),
112
- l && /* @__PURE__ */ r(cr, { source: c, trigger: N }),
113
- /* @__PURE__ */ t("div", { className: "border-d-border flex items-center border-b", children: [
114
- y && /* @__PURE__ */ r(u, { children: () => /* @__PURE__ */ r("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: /* @__PURE__ */ r(Fr, {}) }) }),
115
- P && /* @__PURE__ */ r(u, { children: () => /* @__PURE__ */ r(p, { children: /* @__PURE__ */ r("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: /* @__PURE__ */ t(xr, { children: [
116
- /* @__PURE__ */ r(hr, {}),
117
- /* @__PURE__ */ r(ur, { levels: ["h1", "h2", "h3"] }),
118
- /* @__PURE__ */ r(gr, {}),
119
- /* @__PURE__ */ r(fr, {}),
120
- /* @__PURE__ */ r(pr, {}),
121
- /* @__PURE__ */ r(br, {})
132
+ s && /* @__PURE__ */ r(gr, { source: d, trigger: v }),
133
+ /* @__PURE__ */ n("div", { className: "border-d-border flex items-center border-b", children: [
134
+ R && /* @__PURE__ */ r(f, { children: () => /* @__PURE__ */ r("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: /* @__PURE__ */ r(wr, {}) }) }),
135
+ y && /* @__PURE__ */ r(f, { children: () => /* @__PURE__ */ r(u, { children: /* @__PURE__ */ r("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: /* @__PURE__ */ n(Pr, { children: [
136
+ /* @__PURE__ */ r(Er, {}),
137
+ /* @__PURE__ */ r(vr, { levels: ["h1", "h2", "h3"] }),
138
+ /* @__PURE__ */ r(xr, {}),
139
+ /* @__PURE__ */ r(Nr, {}),
140
+ /* @__PURE__ */ r(br, {}),
141
+ /* @__PURE__ */ r(Fr, {})
122
142
  ] }) }) }) }),
123
- $ && /* @__PURE__ */ r(u, { children: () => /* @__PURE__ */ t("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: [
124
- /* @__PURE__ */ r(d, { format: "bold" }),
125
- /* @__PURE__ */ r(d, { format: "italic" }),
126
- /* @__PURE__ */ r(d, { format: "underline" }),
127
- /* @__PURE__ */ r(d, { format: "strikethrough" }),
128
- l && /* @__PURE__ */ r(
129
- Nr,
143
+ H && /* @__PURE__ */ r(f, { children: () => /* @__PURE__ */ n("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: [
144
+ /* @__PURE__ */ r(m, { format: "bold" }),
145
+ /* @__PURE__ */ r(m, { format: "italic" }),
146
+ /* @__PURE__ */ r(m, { format: "underline" }),
147
+ /* @__PURE__ */ r(m, { format: "strikethrough" }),
148
+ /* @__PURE__ */ r(m, { format: "code" }),
149
+ s && /* @__PURE__ */ r(
150
+ Cr,
130
151
  {
131
- trigger: N ?? "@"
152
+ trigger: v ?? "@"
132
153
  }
133
154
  )
134
- ] }) })
155
+ ] }) }),
156
+ j && /* @__PURE__ */ r(f, { children: () => /* @__PURE__ */ r("div", { className: "vertical-align-middle sticky top-0 z-10 flex gap-2 overflow-auto p-1", children: /* @__PURE__ */ r(yr, {}) }) })
135
157
  ] }),
136
- /* @__PURE__ */ t("div", { className: "relative flex min-h-0 w-full flex-1 flex-col", children: [
137
- y && /* @__PURE__ */ r(J, {}),
158
+ /* @__PURE__ */ n("div", { className: "relative flex min-h-0 w-full flex-1 flex-col", children: [
159
+ R && /* @__PURE__ */ r(Y, {}),
138
160
  /* @__PURE__ */ r(
139
- Z,
161
+ or,
140
162
  {
141
- ErrorBoundary: G,
163
+ ErrorBoundary: X,
142
164
  contentEditable: /* @__PURE__ */ r(
143
165
  "div",
144
166
  {
145
- ref: k,
167
+ ref: I,
146
168
  className: "flex min-h-0 w-full flex-1 overflow-auto",
147
169
  children: /* @__PURE__ */ r(
148
- nr,
170
+ cr,
149
171
  {
150
- placeholder: L,
151
- className: `border-d-border w-full rounded-none border-b ${M}`
172
+ placeholder: S,
173
+ className: `border-d-border w-full rounded-none border-b ${A}`
152
174
  }
153
175
  )
154
176
  }
155
177
  )
156
178
  }
157
179
  ),
158
- P && /* @__PURE__ */ t(p, { children: [
159
- /* @__PURE__ */ r(X, {}),
160
- /* @__PURE__ */ r(Q, {})
180
+ y && /* @__PURE__ */ n(u, { children: [
181
+ /* @__PURE__ */ r(V, {}),
182
+ /* @__PURE__ */ r(q, {})
161
183
  ] }),
162
- (F || C) && /* @__PURE__ */ r(lr, { children: /* @__PURE__ */ t("div", { className: "clear-both flex items-center justify-between gap-2 p-1", children: [
184
+ (F || P) && /* @__PURE__ */ r(dr, { children: /* @__PURE__ */ n("div", { className: "clear-both flex items-center justify-between gap-2 p-1", children: [
163
185
  /* @__PURE__ */ r("div", { className: "flex flex-1 justify-start" }),
164
- /* @__PURE__ */ r("div", { children: C && /* @__PURE__ */ r(sr, { charset: "UTF-16" }) }),
165
- /* @__PURE__ */ r("div", { className: "flex flex-1 justify-end gap-2", children: F && /* @__PURE__ */ t(p, { children: [
166
- /* @__PURE__ */ r(ar, {}),
167
- /* @__PURE__ */ r(K, {})
186
+ /* @__PURE__ */ r("div", { children: P && /* @__PURE__ */ r(fr, { charset: "UTF-16" }) }),
187
+ /* @__PURE__ */ r("div", { className: "flex flex-1 justify-end gap-2", children: F && /* @__PURE__ */ n(u, { children: [
188
+ /* @__PURE__ */ r(pr, {}),
189
+ /* @__PURE__ */ r(G, {})
168
190
  ] }) })
169
191
  ] }) })
170
192
  ] }),
171
193
  /* @__PURE__ */ r(
172
- Y,
194
+ rr,
173
195
  {
174
196
  ignoreSelectionChange: !0,
175
- onChange: (e) => {
176
- if (!n && !a) return;
177
- const T = Rr(
178
- e.read(() => _(v))
197
+ onChange: (i) => {
198
+ if (!t && !e) return;
199
+ const C = $r(
200
+ i.read(() => W(x))
179
201
  );
180
- if (!n) {
181
- a?.(T);
202
+ if (!t) {
203
+ e?.(C);
182
204
  return;
183
205
  }
184
- let R = [];
185
- if (l) {
186
- const I = e.read(
187
- () => dr(or(w))
188
- ), j = Array.isArray(c) ? c : [], B = new Map(
189
- j.map((i) => [String(i.id), i])
206
+ let T = [];
207
+ if (s) {
208
+ const B = i.read(
209
+ () => hr(ir(k))
210
+ ), z = Array.isArray(d) ? d : [], D = new Map(
211
+ z.map((l) => [String(l.id), l])
190
212
  );
191
- R = I.map(
192
- (i) => B.get(String(i.id)) ?? {
193
- id: i.id,
194
- label: i.label,
195
- value: i.value
213
+ T = B.map(
214
+ (l) => D.get(String(l.id)) ?? {
215
+ id: l.id,
216
+ label: l.label,
217
+ value: l.value
196
218
  }
197
219
  );
198
220
  }
199
- n(T, { mentions: R });
221
+ t(C, { mentions: T });
200
222
  }
201
223
  }
202
224
  )
203
225
  ] }) }) });
204
226
  }
227
+ const jr = nr(Hr);
228
+ jr.displayName = "AppEditor";
205
229
  export {
206
- co as AppEditor
230
+ jr as AppEditor
207
231
  };
package/dist/index.d.ts CHANGED
@@ -310,7 +310,7 @@ export declare interface AppDialogProps extends Omit<DialogContentProps, "title"
310
310
  preventClose?: "overlay" | "all";
311
311
  }
312
312
 
313
- export declare function AppEditor({ defaultValue, onMarkdownEdit, onValueChange, plugins, toolbars, placeholder, onlyMarkdown, className, wrpClassName, mentions, mentionTrigger, }: AppEditorProps): JSX.Element;
313
+ export declare const AppEditor: ForwardRefExoticComponent<AppEditorProps & RefAttributes<AppEditorHandle>>;
314
314
 
315
315
  /** Metadata emitted alongside the markdown on every change. */
316
316
  export declare interface AppEditorChangeMeta {
@@ -318,6 +318,16 @@ export declare interface AppEditorChangeMeta {
318
318
  mentions: MentionItem[];
319
319
  }
320
320
 
321
+ /** Imperative API exposed through the `ref` of `AppEditor`. */
322
+ export declare interface AppEditorHandle {
323
+ /**
324
+ * Inserts a hyperlink at the caret (or at the end of the text when the editor
325
+ * has no selection) and leaves the caret right after it. Serializes to
326
+ * `[text](url)`; `text` defaults to the URL itself.
327
+ */
328
+ insertLink: (url: string, text?: string) => void;
329
+ }
330
+
321
331
  export declare type AppEditorPlugin = "clear" | "counter";
322
332
 
323
333
  export declare interface AppEditorProps {
@@ -352,7 +362,7 @@ export declare interface AppEditorProps {
352
362
  mentionTrigger?: string;
353
363
  }
354
364
 
355
- export declare type AppEditorToolbar = "block-format" | "font-format" | "history";
365
+ export declare type AppEditorToolbar = "block-format" | "font-format" | "history" | "link";
356
366
 
357
367
  export declare const AppForm: <TFormValues extends FieldValues = FieldValues, TAsyncOption = unknown>({ items, cols, form, submitText, onSubmit, isSubmitting, showSubmitButton, }: AppFormProps<TFormValues, TAsyncOption>) => JSX.Element;
358
368