@krak-stack/registry 0.10.18 → 0.10.20
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/CHANGELOG.md +31 -0
- package/README.md +18 -0
- package/dist/components/ui/code-block.js +7 -7
- package/dist/components/ui/copy-button.js +7 -7
- package/dist/components/ui/copy-value.d.ts +4 -1
- package/dist/components/ui/copy-value.js +49 -16
- package/dist/components/ui/data-table.d.ts +3 -3
- package/dist/components/ui/data-table.js +23 -17
- package/dist/components/ui/editing-locale-switcher.js +7 -7
- package/dist/components/ui/effect-form.js +8 -8
- package/dist/components/ui/email-composer.js +871 -0
- package/dist/components/ui/email-editor.d.ts +3 -1
- package/dist/components/ui/email-editor.js +294 -471
- package/dist/components/ui/error-component.js +7 -7
- package/dist/components/ui/form.d.ts +7 -7
- package/dist/components/ui/form.js +18 -14
- package/dist/components/ui/icon-input.js +1 -1
- package/dist/components/ui/map-menu.d.ts +1 -1
- package/dist/components/ui/map-menu.js +183 -60
- package/dist/components/ui/pagination.js +7 -7
- package/dist/components/ui/phone-number-input.js +1 -1
- package/dist/components/ui/rich-text-editor.d.ts +15 -13
- package/dist/components/ui/rich-text-editor.js +280 -661
- package/dist/components/ui/select-with-custom-input.js +7 -7
- package/dist/components/ui/select.js +159 -0
- package/dist/components/ui/timezone-select.js +1 -1
- package/dist/components/ui/virtualized-combobox.js +1 -1
- package/dist/lib/docs.js +7 -7
- package/dist/lib/email-composer/index.js +110 -0
- package/dist/lib/email-composer/schema.js +13 -0
- package/dist/lib/email-document/legacy-rich-text/editor.d.ts +70 -0
- package/dist/lib/email-document/legacy-rich-text/schema.d.ts +65 -0
- package/dist/lib/email-document/legacy-rich-text/tiptap.d.ts +39 -0
- package/dist/lib/email-document/model.d.ts +1 -1
- package/dist/lib/email-document/model.js +2 -2
- package/dist/lib/email-document/render.js +2 -2
- package/dist/lib/email-document/schema.js +1 -1
- package/dist/lib/rich-text/model.js +79 -111
- package/dist/lib/rich-text/schema.d.ts +5 -55
- package/dist/lib/rich-text/schema.js +17 -36
- package/dist/lib/rich-text/tiptap.d.ts +12 -0
- package/dist/services/agent/client/index.js +7 -7
- package/dist/services/events/client/audit-log-table.js +23 -17
- package/dist/services/webhooks/client/delivery-table.js +30 -24
- package/package.json +24 -1
- package/dist/lib/rich-text/dom.d.ts +0 -40
- /package/dist/lib/{rich-text → email-document/legacy-rich-text}/model.d.ts +0 -0
|
@@ -4,7 +4,7 @@ import { Popover } from "@base-ui/react/popover";
|
|
|
4
4
|
import {
|
|
5
5
|
useId as useId3,
|
|
6
6
|
useMemo,
|
|
7
|
-
useRef as
|
|
7
|
+
useRef as useRef3,
|
|
8
8
|
useState as useState4
|
|
9
9
|
} from "react";
|
|
10
10
|
import {
|
|
@@ -106,7 +106,7 @@ function SelectTrigger({
|
|
|
106
106
|
return /* @__PURE__ */ jsxs(SelectPrimitive.Trigger, {
|
|
107
107
|
"data-slot": "select-trigger",
|
|
108
108
|
"data-size": size,
|
|
109
|
-
className: cn("flex w-fit items-center justify-between gap-1.5 rounded-md border
|
|
109
|
+
className: cn("border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex w-fit items-center justify-between gap-1.5 rounded-md border bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
|
|
110
110
|
...props,
|
|
111
111
|
children: [
|
|
112
112
|
children,
|
|
@@ -123,9 +123,9 @@ function SelectContent({
|
|
|
123
123
|
children,
|
|
124
124
|
side = "bottom",
|
|
125
125
|
sideOffset = 4,
|
|
126
|
-
align = "
|
|
126
|
+
align = "start",
|
|
127
127
|
alignOffset = 0,
|
|
128
|
-
alignItemWithTrigger =
|
|
128
|
+
alignItemWithTrigger = false,
|
|
129
129
|
...props
|
|
130
130
|
}) {
|
|
131
131
|
return /* @__PURE__ */ jsx3(SelectPrimitive.Portal, {
|
|
@@ -139,7 +139,7 @@ function SelectContent({
|
|
|
139
139
|
children: /* @__PURE__ */ jsxs(SelectPrimitive.Popup, {
|
|
140
140
|
"data-slot": "select-content",
|
|
141
141
|
"data-align-trigger": alignItemWithTrigger,
|
|
142
|
-
className: cn("
|
|
142
|
+
className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md shadow-md ring-1 duration-100 data-[align-trigger=true]:animate-none", className),
|
|
143
143
|
...props,
|
|
144
144
|
children: [
|
|
145
145
|
/* @__PURE__ */ jsx3(SelectScrollUpButton, {}),
|
|
@@ -159,7 +159,7 @@ function SelectItem({
|
|
|
159
159
|
}) {
|
|
160
160
|
return /* @__PURE__ */ jsxs(SelectPrimitive.Item, {
|
|
161
161
|
"data-slot": "select-item",
|
|
162
|
-
className: cn("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none
|
|
162
|
+
className: cn("focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className),
|
|
163
163
|
...props,
|
|
164
164
|
children: [
|
|
165
165
|
/* @__PURE__ */ jsx3(SelectPrimitive.ItemText, {
|
|
@@ -183,7 +183,7 @@ function SelectScrollUpButton({
|
|
|
183
183
|
}) {
|
|
184
184
|
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollUpArrow, {
|
|
185
185
|
"data-slot": "select-scroll-up-button",
|
|
186
|
-
className: cn("top-0 z-10 flex w-full cursor-default items-center justify-center
|
|
186
|
+
className: cn("bg-popover top-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
187
187
|
...props,
|
|
188
188
|
children: /* @__PURE__ */ jsx3(ChevronUpIcon, {})
|
|
189
189
|
});
|
|
@@ -194,7 +194,7 @@ function SelectScrollDownButton({
|
|
|
194
194
|
}) {
|
|
195
195
|
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollDownArrow, {
|
|
196
196
|
"data-slot": "select-scroll-down-button",
|
|
197
|
-
className: cn("bottom-0 z-10 flex w-full cursor-default items-center justify-center
|
|
197
|
+
className: cn("bg-popover bottom-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
198
198
|
...props,
|
|
199
199
|
children: /* @__PURE__ */ jsx3(ChevronDownIcon, {})
|
|
200
200
|
});
|
|
@@ -652,13 +652,15 @@ var ListItem = ({
|
|
|
652
652
|
});
|
|
653
653
|
};
|
|
654
654
|
|
|
655
|
-
// ../../src/
|
|
656
|
-
import { Schema as Schema4 } from "effect";
|
|
655
|
+
// ../../src/lib/email-document/legacy-rich-text/editor.tsx
|
|
656
|
+
import { Option as Option2, Schema as Schema4 } from "effect";
|
|
657
|
+
import { EditorContent, useEditor } from "@tiptap/react";
|
|
658
|
+
import { EditorState } from "@tiptap/pm/state";
|
|
659
|
+
import { closeHistory } from "@tiptap/pm/history";
|
|
657
660
|
import {
|
|
658
661
|
useEffect as useEffect3,
|
|
659
662
|
useEffectEvent as useEffectEvent3,
|
|
660
663
|
useId as useId2,
|
|
661
|
-
useRef as useRef3,
|
|
662
664
|
useState as useState3
|
|
663
665
|
} from "react";
|
|
664
666
|
import {
|
|
@@ -727,10 +729,10 @@ function DropdownMenuItem({
|
|
|
727
729
|
});
|
|
728
730
|
}
|
|
729
731
|
|
|
730
|
-
// ../../src/
|
|
732
|
+
// ../../src/lib/email-document/legacy-rich-text/editor.tsx
|
|
731
733
|
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
732
734
|
|
|
733
|
-
// ../../src/lib/rich-text/schema.ts
|
|
735
|
+
// ../../src/lib/email-document/legacy-rich-text/schema.ts
|
|
734
736
|
import { Schema } from "effect";
|
|
735
737
|
var RichTextLink = Schema.String.check(Schema.isMaxLength(2000), Schema.makeFilter((value) => {
|
|
736
738
|
if (/[\s\p{Cc}\\{}]/u.test(value))
|
|
@@ -776,13 +778,15 @@ var RichTextVariable = Schema.Struct({
|
|
|
776
778
|
sample: Schema.String
|
|
777
779
|
}).annotate({ identifier: "RichTextVariable" });
|
|
778
780
|
|
|
779
|
-
// ../../src/lib/rich-text/
|
|
781
|
+
// ../../src/lib/email-document/legacy-rich-text/tiptap.ts
|
|
782
|
+
import { Extension, Node } from "@tiptap/core";
|
|
783
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
784
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
785
|
+
import { Option, Schema as Schema3 } from "effect";
|
|
786
|
+
|
|
787
|
+
// ../../src/lib/email-document/legacy-rich-text/model.ts
|
|
780
788
|
import { Schema as Schema2 } from "effect";
|
|
781
789
|
var sameMarks = Schema2.toEquivalence(RichTextMarks);
|
|
782
|
-
var emptyRichText = () => ({
|
|
783
|
-
version: 1,
|
|
784
|
-
blocks: [{ type: "paragraph", content: [] }]
|
|
785
|
-
});
|
|
786
790
|
var richTextFromString = (text) => ({
|
|
787
791
|
version: 1,
|
|
788
792
|
blocks: text.split(/\r\n?|\n/).map((line) => ({
|
|
@@ -792,223 +796,174 @@ var richTextFromString = (text) => ({
|
|
|
792
796
|
});
|
|
793
797
|
var richTextPlainText = (value, variables) => value.blocks.map((block) => block.content.map((inline) => inline.type === "text" ? inline.text : variables?.[inline.key] ?? `{{${inline.key}}}`).join("")).join(`
|
|
794
798
|
`);
|
|
795
|
-
var units = (value) => value.blocks.flatMap((block, index) => [
|
|
796
|
-
...index ? [{ type: "break", next: block.type }] : [],
|
|
797
|
-
...block.content.flatMap((inline) => inline.type === "text" ? inline.text.split("").map((text) => ({ ...inline, text })) : [inline])
|
|
798
|
-
]);
|
|
799
|
-
var fromUnits = (content, first) => {
|
|
800
|
-
const blocks = [{ type: first, content: [] }];
|
|
801
|
-
for (const unit of content) {
|
|
802
|
-
if (unit.type === "break") {
|
|
803
|
-
blocks.push({ type: unit.next, content: [] });
|
|
804
|
-
continue;
|
|
805
|
-
}
|
|
806
|
-
const target = blocks.at(-1);
|
|
807
|
-
if (!target)
|
|
808
|
-
continue;
|
|
809
|
-
const previous = target.content.at(-1);
|
|
810
|
-
if (unit.type === "text" && previous?.type === "text" && sameMarks(previous.marks ?? {}, unit.marks ?? {})) {
|
|
811
|
-
target.content[target.content.length - 1] = {
|
|
812
|
-
...previous,
|
|
813
|
-
text: previous.text + unit.text
|
|
814
|
-
};
|
|
815
|
-
} else
|
|
816
|
-
target.content.push(unit);
|
|
817
|
-
}
|
|
818
|
-
return { version: 1, blocks };
|
|
819
|
-
};
|
|
820
|
-
var replaceRichText = (value, selection, inserted) => {
|
|
821
|
-
const content = units(value);
|
|
822
|
-
const from = Math.max(0, Math.min(selection.from, content.length));
|
|
823
|
-
const to = Math.max(from, Math.min(selection.to, content.length));
|
|
824
|
-
const additions = inserted.type === "text" ? inserted.text.replace(/\r\n?/g, `
|
|
825
|
-
`).split("").map((text) => text === `
|
|
826
|
-
` ? { type: "break", next: "paragraph" } : { type: "text", text, marks: inserted.marks }) : [inserted];
|
|
827
|
-
const next = fromUnits([...content.slice(0, from), ...additions, ...content.slice(to)], value.blocks[0]?.type ?? "paragraph");
|
|
828
|
-
const position = from + additions.length;
|
|
829
|
-
return { value: next, selection: { from: position, to: position } };
|
|
830
|
-
};
|
|
831
|
-
var formatRichText = (value, selection, mark, setting) => fromUnits(units(value).map((unit, index) => {
|
|
832
|
-
if (unit.type === "break" || index < selection.from || index >= selection.to)
|
|
833
|
-
return unit;
|
|
834
|
-
const marks = { ...unit.marks, [mark]: setting };
|
|
835
|
-
return { ...unit, marks };
|
|
836
|
-
}), value.blocks[0]?.type ?? "paragraph");
|
|
837
|
-
var setRichTextBlock = (value, selection, type) => {
|
|
838
|
-
let offset = 0;
|
|
839
|
-
return {
|
|
840
|
-
...value,
|
|
841
|
-
blocks: value.blocks.map((block) => {
|
|
842
|
-
const start = offset;
|
|
843
|
-
offset += block.content.reduce((size, inline) => size + (inline.type === "text" ? inline.text.length : 1), 0) + 1;
|
|
844
|
-
return selection.from < offset && selection.to >= start ? { ...block, type } : block;
|
|
845
|
-
})
|
|
846
|
-
};
|
|
847
|
-
};
|
|
848
|
-
var richTextMarksAt = (value, position) => {
|
|
849
|
-
const content = units(value);
|
|
850
|
-
const unit = content[Math.max(0, position - 1)];
|
|
851
|
-
return unit && unit.type !== "break" ? unit.marks ?? {} : {};
|
|
852
|
-
};
|
|
853
799
|
|
|
854
|
-
// ../../src/lib/rich-text/
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
})
|
|
862
|
-
|
|
863
|
-
const result = [];
|
|
864
|
-
const points = [{ node: root, offset: 0 }];
|
|
865
|
-
let current;
|
|
866
|
-
const begin = (type, point) => {
|
|
867
|
-
if (current)
|
|
868
|
-
result.push(current);
|
|
869
|
-
if (result.length)
|
|
870
|
-
points.push(point);
|
|
871
|
-
else
|
|
872
|
-
points[0] = point;
|
|
873
|
-
current = { type, content: [] };
|
|
874
|
-
};
|
|
875
|
-
const append = (inline, point) => {
|
|
876
|
-
if (!current)
|
|
877
|
-
begin("paragraph", point);
|
|
878
|
-
const previous = current?.content.at(-1);
|
|
879
|
-
if (inline.type === "text" && previous?.type === "text" && sameMarks2(inline.marks ?? {}, previous.marks ?? {})) {
|
|
880
|
-
if (current)
|
|
881
|
-
current.content[current.content.length - 1] = {
|
|
882
|
-
...previous,
|
|
883
|
-
text: previous.text + inline.text
|
|
884
|
-
};
|
|
885
|
-
} else
|
|
886
|
-
current?.content.push(inline);
|
|
887
|
-
points.push(point);
|
|
888
|
-
};
|
|
889
|
-
const visit = (node, inherited = {}, kind = "paragraph") => {
|
|
890
|
-
if (node instanceof Text) {
|
|
891
|
-
if (!current)
|
|
892
|
-
begin(kind, { node, offset: 0 });
|
|
893
|
-
for (let index = 0;index < node.data.length; index++)
|
|
894
|
-
append({ type: "text", text: node.data[index] ?? "", marks: inherited }, { node, offset: index + 1 });
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
if (!(node instanceof HTMLElement) || ["SCRIPT", "STYLE", "IFRAME"].includes(node.tagName))
|
|
898
|
-
return;
|
|
899
|
-
const key = node.dataset.richVariable;
|
|
900
|
-
if (key) {
|
|
901
|
-
const variable = { type: "variable", key, marks: inherited };
|
|
902
|
-
append(variable, pointAfter(node));
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
const href = node.getAttribute("href");
|
|
906
|
-
const marks = {
|
|
907
|
-
bold: inherited.bold,
|
|
908
|
-
italic: inherited.italic,
|
|
909
|
-
underline: inherited.underline,
|
|
910
|
-
href: inherited.href
|
|
911
|
-
};
|
|
912
|
-
if (["B", "STRONG"].includes(node.tagName) || node.style.fontWeight === "700")
|
|
913
|
-
marks.bold = true;
|
|
914
|
-
if (["I", "EM"].includes(node.tagName) || node.style.fontStyle === "italic")
|
|
915
|
-
marks.italic = true;
|
|
916
|
-
if (node.tagName === "U" || node.style.textDecoration.includes("underline"))
|
|
917
|
-
marks.underline = true;
|
|
918
|
-
if (href && Schema3.is(RichTextLink)(href))
|
|
919
|
-
marks.href = href;
|
|
920
|
-
const type = node.dataset.richKind === "bullet" ? "bullet" : node.dataset.richKind === "numbered" ? "numbered" : /^H[123]$/.test(node.tagName) ? "heading" : node.tagName === "LI" ? node.parentElement?.tagName === "OL" ? "numbered" : "bullet" : kind;
|
|
921
|
-
const isBlock = blocks.has(node.tagName);
|
|
922
|
-
const container = isBlock && [...node.children].some((child) => blocks.has(child.tagName));
|
|
923
|
-
if (isBlock && !container)
|
|
924
|
-
begin(type, { node, offset: 0 });
|
|
925
|
-
if (node.tagName === "BR") {
|
|
926
|
-
if (node.nextSibling)
|
|
927
|
-
begin(kind, pointAfter(node));
|
|
928
|
-
return;
|
|
800
|
+
// ../../src/lib/email-document/legacy-rich-text/tiptap.ts
|
|
801
|
+
var toTiptapDocument = (value, singleLine = false) => {
|
|
802
|
+
const blocks = singleLine ? [
|
|
803
|
+
{
|
|
804
|
+
type: "paragraph",
|
|
805
|
+
content: value.blocks.flatMap((block, index) => [
|
|
806
|
+
...index ? [{ type: "text", text: " " }] : [],
|
|
807
|
+
...block.content.map((inline) => inline.type === "text" ? { type: "text", text: inline.text.replace(/[\r\n]+/g, " ") } : { type: "variable", key: inline.key })
|
|
808
|
+
])
|
|
929
809
|
}
|
|
930
|
-
|
|
931
|
-
|
|
810
|
+
] : value.blocks;
|
|
811
|
+
return {
|
|
812
|
+
type: "doc",
|
|
813
|
+
content: blocks.map((block) => ({
|
|
814
|
+
type: "paragraph",
|
|
815
|
+
attrs: { kind: block.type },
|
|
816
|
+
content: block.content.filter((inline) => inline.type !== "text" || inline.text.length > 0).map((inline) => {
|
|
817
|
+
const marks = [];
|
|
818
|
+
if (inline.marks?.bold)
|
|
819
|
+
marks.push({ type: "bold" });
|
|
820
|
+
if (inline.marks?.italic)
|
|
821
|
+
marks.push({ type: "italic" });
|
|
822
|
+
if (inline.marks?.underline)
|
|
823
|
+
marks.push({ type: "underline" });
|
|
824
|
+
if (inline.marks?.href)
|
|
825
|
+
marks.push({ type: "link", attrs: { href: inline.marks.href } });
|
|
826
|
+
return inline.type === "text" ? { type: "text", text: inline.text, marks } : { type: "variable", attrs: { key: inline.key }, marks };
|
|
827
|
+
})
|
|
828
|
+
}))
|
|
932
829
|
};
|
|
933
|
-
for (const child of root.childNodes)
|
|
934
|
-
visit(child);
|
|
935
|
-
if (current)
|
|
936
|
-
result.push(current);
|
|
937
|
-
const value = Option.getOrUndefined(Schema3.decodeOption(RichTextDocument)({
|
|
938
|
-
version: 1,
|
|
939
|
-
blocks: result.length ? result : emptyRichText().blocks
|
|
940
|
-
}));
|
|
941
|
-
return { value, points };
|
|
942
830
|
};
|
|
943
|
-
var
|
|
944
|
-
const
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
831
|
+
var fromTiptapDocument = (doc) => {
|
|
832
|
+
const blocks = [];
|
|
833
|
+
doc.forEach((block) => {
|
|
834
|
+
const content = [];
|
|
835
|
+
block.forEach((inline) => {
|
|
836
|
+
let marks = {};
|
|
837
|
+
for (const mark of inline.marks) {
|
|
838
|
+
if (mark.type.name === "bold")
|
|
839
|
+
marks = { ...marks, bold: true };
|
|
840
|
+
if (mark.type.name === "italic")
|
|
841
|
+
marks = { ...marks, italic: true };
|
|
842
|
+
if (mark.type.name === "underline")
|
|
843
|
+
marks = { ...marks, underline: true };
|
|
844
|
+
if (mark.type.name === "link")
|
|
845
|
+
marks = { ...marks, href: mark.attrs.href };
|
|
846
|
+
}
|
|
847
|
+
const value = inline.isText ? { type: "text", text: inline.text } : { type: inline.type.name, key: inline.attrs.key };
|
|
848
|
+
content.push(Object.keys(marks).length ? { ...value, marks } : value);
|
|
955
849
|
});
|
|
956
|
-
|
|
957
|
-
};
|
|
958
|
-
|
|
959
|
-
const focus = position(selection.focusNode, selection.focusOffset);
|
|
960
|
-
return { from: Math.min(anchor, focus), to: Math.max(anchor, focus) };
|
|
850
|
+
blocks.push({ type: block.attrs.kind, content });
|
|
851
|
+
});
|
|
852
|
+
return Schema3.decodeUnknownOption(RichTextDocument)({ version: 1, blocks });
|
|
961
853
|
};
|
|
962
|
-
var
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
if (!start || !end)
|
|
854
|
+
var SingleLineDocument = RichTextDocument.check(Schema3.makeFilter((value) => value.blocks.length === 1 && value.blocks.every((block) => block.type === "paragraph" && block.content.every((inline) => !inline.marks && (inline.type !== "text" || !/[\r\n]/.test(inline.text)))))).annotate({ identifier: "SingleLineRichTextDocument" });
|
|
855
|
+
var richTextExtensions = ({
|
|
856
|
+
singleLine = false,
|
|
857
|
+
maxLength = () => {
|
|
967
858
|
return;
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
859
|
+
},
|
|
860
|
+
variables = () => [],
|
|
861
|
+
onInvalid = () => {}
|
|
862
|
+
} = {}) => [
|
|
863
|
+
StarterKit.configure({
|
|
864
|
+
blockquote: false,
|
|
865
|
+
bulletList: false,
|
|
866
|
+
code: false,
|
|
867
|
+
codeBlock: false,
|
|
868
|
+
dropcursor: false,
|
|
869
|
+
gapcursor: false,
|
|
870
|
+
hardBreak: false,
|
|
871
|
+
heading: false,
|
|
872
|
+
horizontalRule: false,
|
|
873
|
+
listItem: false,
|
|
874
|
+
listKeymap: false,
|
|
875
|
+
orderedList: false,
|
|
876
|
+
paragraph: false,
|
|
877
|
+
strike: false,
|
|
878
|
+
trailingNode: false,
|
|
879
|
+
bold: singleLine ? false : {},
|
|
880
|
+
italic: singleLine ? false : {},
|
|
881
|
+
underline: singleLine ? false : {},
|
|
882
|
+
link: singleLine ? false : {
|
|
883
|
+
openOnClick: false,
|
|
884
|
+
autolink: false,
|
|
885
|
+
linkOnPaste: false,
|
|
886
|
+
isAllowedUri: (url) => Schema3.is(RichTextLink)(url),
|
|
887
|
+
HTMLAttributes: { class: "underline" }
|
|
888
|
+
},
|
|
889
|
+
undoRedo: { depth: 100 }
|
|
890
|
+
}),
|
|
891
|
+
Node.create({
|
|
892
|
+
name: "paragraph",
|
|
893
|
+
group: "block",
|
|
894
|
+
content: "inline*",
|
|
895
|
+
marks: singleLine ? "" : "_",
|
|
896
|
+
addAttributes: () => ({ kind: { default: "paragraph" } }),
|
|
897
|
+
parseHTML: () => [{ tag: "p" }],
|
|
898
|
+
renderHTML: ({ node }) => {
|
|
899
|
+
const kind = Schema3.decodeUnknownSync(RichTextBlockKind)(node.attrs.kind);
|
|
900
|
+
if (kind === "heading")
|
|
901
|
+
return ["h2", { class: "text-xl font-semibold" }, 0];
|
|
902
|
+
return [
|
|
903
|
+
"div",
|
|
904
|
+
{
|
|
905
|
+
"data-rich-kind": kind,
|
|
906
|
+
style: kind === "bullet" || kind === "numbered" ? `display:list-item;margin-left:1.5em;list-style-type:${kind === "bullet" ? "disc" : "decimal"}` : null
|
|
907
|
+
},
|
|
908
|
+
0
|
|
909
|
+
];
|
|
910
|
+
},
|
|
911
|
+
addKeyboardShortcuts() {
|
|
912
|
+
return {
|
|
913
|
+
Enter: () => {
|
|
914
|
+
if (singleLine)
|
|
915
|
+
return true;
|
|
916
|
+
const { $from } = this.editor.state.selection;
|
|
917
|
+
if (!$from.parent.content.size && $from.parent.attrs.kind !== "paragraph")
|
|
918
|
+
return this.editor.commands.updateAttributes("paragraph", {
|
|
919
|
+
kind: "paragraph"
|
|
920
|
+
});
|
|
921
|
+
return this.editor.commands.splitBlock();
|
|
922
|
+
},
|
|
923
|
+
"Shift-Enter": () => singleLine || this.editor.commands.splitBlock()
|
|
924
|
+
};
|
|
982
925
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
span
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
926
|
+
}),
|
|
927
|
+
Node.create({
|
|
928
|
+
name: "variable",
|
|
929
|
+
group: "inline",
|
|
930
|
+
inline: true,
|
|
931
|
+
atom: true,
|
|
932
|
+
selectable: true,
|
|
933
|
+
addAttributes: () => ({ key: { default: null } }),
|
|
934
|
+
renderText: ({ node }) => `{{${node.attrs.key}}}`,
|
|
935
|
+
renderHTML: ({ node }) => {
|
|
936
|
+
const key = Schema3.decodeUnknownSync(Schema3.String)(node.attrs.key);
|
|
937
|
+
return [
|
|
938
|
+
"span",
|
|
939
|
+
{
|
|
940
|
+
"data-rich-variable": key,
|
|
941
|
+
contenteditable: "false",
|
|
942
|
+
class: "inline-block rounded bg-indigo-50 px-1.5 font-mono text-[0.85em] text-indigo-800 select-all"
|
|
943
|
+
},
|
|
944
|
+
`{{${variables().find((variable) => variable.key === key)?.label ?? key}}}`
|
|
945
|
+
];
|
|
1003
946
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
947
|
+
}),
|
|
948
|
+
Extension.create({
|
|
949
|
+
name: "richTextValidation",
|
|
950
|
+
addProseMirrorPlugins: () => [
|
|
951
|
+
new Plugin({
|
|
952
|
+
filterTransaction: (transaction) => {
|
|
953
|
+
if (!transaction.docChanged)
|
|
954
|
+
return true;
|
|
955
|
+
const decoded = fromTiptapDocument(transaction.doc);
|
|
956
|
+
const limit = maxLength();
|
|
957
|
+
const valid = Option.isSome(decoded) && (!singleLine || Schema3.is(SingleLineDocument)(decoded.value)) && (limit === undefined || richTextPlainText(decoded.value).length <= limit);
|
|
958
|
+
onInvalid?.(!valid);
|
|
959
|
+
return valid;
|
|
960
|
+
}
|
|
961
|
+
})
|
|
962
|
+
]
|
|
963
|
+
})
|
|
964
|
+
];
|
|
1010
965
|
|
|
1011
|
-
// ../../src/
|
|
966
|
+
// ../../src/lib/email-document/legacy-rich-text/editor.tsx
|
|
1012
967
|
import { jsx as jsx7, jsxs as jsxs4, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
1013
968
|
var labels2 = {
|
|
1014
969
|
en: {
|
|
@@ -1052,7 +1007,7 @@ var labels2 = {
|
|
|
1052
1007
|
cancel: "Annuler"
|
|
1053
1008
|
}
|
|
1054
1009
|
};
|
|
1055
|
-
var
|
|
1010
|
+
var externalReplacementMeta = "krakstackExternalReplacement";
|
|
1056
1011
|
var ToolButton = ({
|
|
1057
1012
|
label,
|
|
1058
1013
|
children,
|
|
@@ -1142,203 +1097,132 @@ var RichTextEditor = ({
|
|
|
1142
1097
|
...messages?.[locale.split("-")[0] ?? locale],
|
|
1143
1098
|
...messages?.[locale]
|
|
1144
1099
|
};
|
|
1145
|
-
const root = useRef3(null);
|
|
1146
|
-
const model = useRef3(value);
|
|
1147
|
-
const composing = useRef3(false);
|
|
1148
|
-
const selected = useRef3({ from: 0, to: 0 });
|
|
1149
|
-
const history = useRef3([
|
|
1150
|
-
{ value, selection: { from: 0, to: 0 } }
|
|
1151
|
-
]);
|
|
1152
|
-
const cursor = useRef3(0);
|
|
1153
|
-
const [marks, setMarks] = useState3({});
|
|
1154
|
-
const pendingMarks = useRef3(null);
|
|
1155
1100
|
const [error, setError] = useState3(false);
|
|
1156
1101
|
const [linkOpen, setLinkOpen] = useState3(false);
|
|
1157
1102
|
const [link, setLink] = useState3("");
|
|
1158
1103
|
const [linkError, setLinkError] = useState3(false);
|
|
1159
1104
|
const [revision, setRevision] = useState3(0);
|
|
1160
|
-
const [historyState, setHistoryState] = useState3({
|
|
1161
|
-
undo: false,
|
|
1162
|
-
redo: false
|
|
1163
|
-
});
|
|
1164
1105
|
const id = useId2();
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1106
|
+
const getMaxLength = useEffectEvent3(() => maxLength);
|
|
1107
|
+
const getVariables = useEffectEvent3(() => variables);
|
|
1108
|
+
const editor = useEditor({
|
|
1109
|
+
immediatelyRender: false,
|
|
1110
|
+
extensions: richTextExtensions({
|
|
1111
|
+
singleLine,
|
|
1112
|
+
maxLength: () => getMaxLength(),
|
|
1113
|
+
variables: () => getVariables(),
|
|
1114
|
+
onInvalid: setError
|
|
1115
|
+
}),
|
|
1116
|
+
content: toTiptapDocument(value, singleLine),
|
|
1117
|
+
editable: !disabled,
|
|
1118
|
+
onTransaction: ({ transaction }) => {
|
|
1119
|
+
const replacement = transaction.getMeta(externalReplacementMeta) === true;
|
|
1120
|
+
if (replacement) {
|
|
1121
|
+
setError(false);
|
|
1122
|
+
setLinkOpen(false);
|
|
1123
|
+
}
|
|
1124
|
+
if (replacement || transaction.docChanged || transaction.selectionSet || transaction.storedMarksSet)
|
|
1125
|
+
setRevision((current) => current + 1);
|
|
1126
|
+
},
|
|
1127
|
+
onUpdate: ({ editor }) => {
|
|
1128
|
+
const next = fromTiptapDocument(editor.state.doc);
|
|
1129
|
+
if (Option2.isSome(next)) {
|
|
1130
|
+
onChange(next.value);
|
|
1131
|
+
}
|
|
1132
|
+
},
|
|
1133
|
+
editorProps: {
|
|
1134
|
+
attributes: {
|
|
1135
|
+
role: "textbox",
|
|
1136
|
+
"aria-label": label,
|
|
1137
|
+
"aria-multiline": String(!singleLine),
|
|
1138
|
+
"aria-disabled": String(!!disabled),
|
|
1139
|
+
"aria-describedby": error ? `${id}-error` : "",
|
|
1140
|
+
class: `focus-visible:ring-ring ${singleLine ? "min-h-10" : "min-h-32"} px-4 py-3 ${contentStyle?.fontSize === undefined ? "text-sm" : ""} ${contentStyle?.lineHeight === undefined ? "leading-relaxed" : ""} outline-none focus-visible:ring-2 focus-visible:ring-inset [&>div]:min-h-[1.5em]`
|
|
1141
|
+
},
|
|
1142
|
+
handlePaste: (view, event) => {
|
|
1143
|
+
event.preventDefault();
|
|
1144
|
+
if (disabled)
|
|
1145
|
+
return true;
|
|
1146
|
+
const text = event.clipboardData?.getData("text/plain") ?? "";
|
|
1147
|
+
const lines = (singleLine ? text.replace(/[\r\n]+/g, " ") : text.replace(/\r\n?/g, `
|
|
1148
|
+
`)).split(`
|
|
1149
|
+
`);
|
|
1150
|
+
const nodes = lines.map((line) => view.state.schema.nodes.paragraph.create({ kind: "paragraph" }, line ? view.state.schema.text(line) : undefined));
|
|
1151
|
+
const doc = view.state.schema.topNodeType.create(null, nodes);
|
|
1152
|
+
view.dispatch(view.state.tr.replaceSelection(doc.slice(1, doc.content.size - 1)));
|
|
1153
|
+
return true;
|
|
1154
|
+
},
|
|
1155
|
+
handleDrop: () => true,
|
|
1156
|
+
handleClick: (_view, _position, event) => {
|
|
1157
|
+
if (event.target instanceof HTMLElement && event.target.closest("a")) {
|
|
1158
|
+
event.preventDefault();
|
|
1159
|
+
return true;
|
|
1160
|
+
}
|
|
1161
|
+
return false;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}, [singleLine]);
|
|
1165
|
+
const marks = {
|
|
1166
|
+
bold: editor?.isActive("bold"),
|
|
1167
|
+
italic: editor?.isActive("italic"),
|
|
1168
|
+
underline: editor?.isActive("underline"),
|
|
1169
|
+
href: editor?.getAttributes("link").href
|
|
1170
|
+
};
|
|
1171
|
+
const historyState = {
|
|
1172
|
+
undo: editor?.can().undo() ?? false,
|
|
1173
|
+
redo: editor?.can().redo() ?? false
|
|
1177
1174
|
};
|
|
1178
1175
|
const focusEditor = () => {
|
|
1179
|
-
|
|
1180
|
-
if (element) {
|
|
1181
|
-
element.focus();
|
|
1182
|
-
restoreRichTextSelection(element, selected.current);
|
|
1183
|
-
}
|
|
1176
|
+
editor?.view.focus();
|
|
1184
1177
|
return false;
|
|
1185
1178
|
};
|
|
1186
|
-
const commit = (next, range, write = true, record = true) => {
|
|
1187
|
-
const element = root.current;
|
|
1188
|
-
if (!element || disabled)
|
|
1189
|
-
return;
|
|
1190
|
-
const original = next;
|
|
1191
|
-
if (singleLine) {
|
|
1192
|
-
next = {
|
|
1193
|
-
version: 1,
|
|
1194
|
-
blocks: [
|
|
1195
|
-
{
|
|
1196
|
-
type: "paragraph",
|
|
1197
|
-
content: next.blocks.flatMap((block, index) => [
|
|
1198
|
-
...index ? [{ type: "text", text: " " }] : [],
|
|
1199
|
-
...block.content.map((inline) => inline.type === "variable" ? { type: "variable", key: inline.key } : {
|
|
1200
|
-
type: "text",
|
|
1201
|
-
text: inline.text.replace(/[\r\n]+/g, " ")
|
|
1202
|
-
})
|
|
1203
|
-
])
|
|
1204
|
-
}
|
|
1205
|
-
]
|
|
1206
|
-
};
|
|
1207
|
-
if (!equivalent(original, next))
|
|
1208
|
-
write = true;
|
|
1209
|
-
}
|
|
1210
|
-
if (!Schema4.is(RichTextDocument)(next) || maxLength !== undefined && richTextPlainText(next).length > maxLength) {
|
|
1211
|
-
setError(true);
|
|
1212
|
-
writeRichTextDOM(element, model.current, variables);
|
|
1213
|
-
element.focus();
|
|
1214
|
-
restoreRichTextSelection(element, selected.current);
|
|
1215
|
-
return;
|
|
1216
|
-
}
|
|
1217
|
-
setError(false);
|
|
1218
|
-
if (record && !equivalent(model.current, next)) {
|
|
1219
|
-
history.current[cursor.current] = {
|
|
1220
|
-
value: model.current,
|
|
1221
|
-
selection: selected.current
|
|
1222
|
-
};
|
|
1223
|
-
history.current = [
|
|
1224
|
-
...history.current.slice(0, cursor.current + 1),
|
|
1225
|
-
{ value: next, selection: range }
|
|
1226
|
-
].slice(-100);
|
|
1227
|
-
cursor.current = history.current.length - 1;
|
|
1228
|
-
}
|
|
1229
|
-
model.current = next;
|
|
1230
|
-
selected.current = range;
|
|
1231
|
-
if (write) {
|
|
1232
|
-
writeRichTextDOM(element, next, variables);
|
|
1233
|
-
element.focus();
|
|
1234
|
-
restoreRichTextSelection(element, range);
|
|
1235
|
-
}
|
|
1236
|
-
setRevision((current) => current + 1);
|
|
1237
|
-
setHistoryState({
|
|
1238
|
-
undo: cursor.current > 0,
|
|
1239
|
-
redo: cursor.current < history.current.length - 1
|
|
1240
|
-
});
|
|
1241
|
-
onChange(next);
|
|
1242
|
-
};
|
|
1243
1179
|
const travel = (direction) => {
|
|
1244
|
-
|
|
1245
|
-
const snapshot = history.current[index];
|
|
1246
|
-
if (!snapshot || index === cursor.current)
|
|
1180
|
+
if (disabled)
|
|
1247
1181
|
return;
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
const insert = (inline) => {
|
|
1253
|
-
const result = replaceRichText(model.current, selection(), inline);
|
|
1254
|
-
commit(result.value, result.selection);
|
|
1182
|
+
if (direction < 0)
|
|
1183
|
+
editor?.chain().focus().undo().run();
|
|
1184
|
+
else
|
|
1185
|
+
editor?.chain().focus().redo().run();
|
|
1255
1186
|
};
|
|
1256
1187
|
const format = (mark) => {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
...pendingMarks.current ?? richTextMarksAt(model.current, range.to),
|
|
1260
|
-
[mark]: !marks[mark]
|
|
1261
|
-
};
|
|
1262
|
-
setMarks(next);
|
|
1263
|
-
if (range.from === range.to) {
|
|
1264
|
-
pendingMarks.current = next;
|
|
1265
|
-
root.current?.focus();
|
|
1266
|
-
} else
|
|
1267
|
-
commit(formatRichText(model.current, range, mark, next[mark]), range);
|
|
1188
|
+
if (!disabled)
|
|
1189
|
+
editor?.chain().focus().toggleMark(mark).run();
|
|
1268
1190
|
};
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
if (!element || composing.current)
|
|
1191
|
+
const insertVariable = (key) => {
|
|
1192
|
+
if (disabled || !editor)
|
|
1272
1193
|
return;
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
commit(parsed.value, range, false);
|
|
1277
|
-
else {
|
|
1278
|
-
setError(true);
|
|
1279
|
-
writeRichTextDOM(element, model.current, variables);
|
|
1280
|
-
restoreRichTextSelection(element, selected.current);
|
|
1281
|
-
}
|
|
1194
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
1195
|
+
editor.chain().insertContent({ type: "variable", attrs: { key } }).run();
|
|
1196
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
1282
1197
|
};
|
|
1283
|
-
|
|
1284
|
-
if (
|
|
1198
|
+
useEffect3(() => {
|
|
1199
|
+
if (!editor)
|
|
1285
1200
|
return;
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
insert({
|
|
1295
|
-
type: "text",
|
|
1296
|
-
text: event.inputType === "insertText" ? event.data ?? "" : `
|
|
1297
|
-
`,
|
|
1298
|
-
marks: pendingMarks.current ?? richTextMarksAt(model.current, range.to)
|
|
1299
|
-
});
|
|
1300
|
-
} else if (event.inputType === "formatBold" || event.inputType === "formatItalic" || event.inputType === "formatUnderline") {
|
|
1301
|
-
event.preventDefault();
|
|
1302
|
-
if (!singleLine)
|
|
1303
|
-
format(event.inputType === "formatBold" ? "bold" : event.inputType === "formatItalic" ? "italic" : "underline");
|
|
1201
|
+
const incoming = editor.schema.nodeFromJSON(toTiptapDocument(value, singleLine));
|
|
1202
|
+
if (!editor.state.doc.eq(incoming)) {
|
|
1203
|
+
editor.view.updateState(EditorState.create({
|
|
1204
|
+
schema: editor.schema,
|
|
1205
|
+
doc: incoming,
|
|
1206
|
+
plugins: editor.state.plugins
|
|
1207
|
+
}));
|
|
1208
|
+
editor.view.dispatch(editor.state.tr.setMeta(externalReplacementMeta, true));
|
|
1304
1209
|
}
|
|
1305
|
-
});
|
|
1210
|
+
}, [editor, value, singleLine]);
|
|
1306
1211
|
useEffect3(() => {
|
|
1307
|
-
|
|
1308
|
-
if (!element)
|
|
1309
|
-
return;
|
|
1310
|
-
const listener = (event) => beforeInput(event);
|
|
1311
|
-
element.addEventListener("beforeinput", listener);
|
|
1312
|
-
return () => element.removeEventListener("beforeinput", listener);
|
|
1313
|
-
}, []);
|
|
1314
|
-
const remember = useEffectEvent3(() => {
|
|
1315
|
-
const element = root.current;
|
|
1316
|
-
if (!element || document.activeElement !== element || composing.current)
|
|
1212
|
+
if (!editor)
|
|
1317
1213
|
return;
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
if (previous.from !== range.from || previous.to !== range.to)
|
|
1321
|
-
pendingMarks.current = null;
|
|
1322
|
-
setMarks(pendingMarks.current ?? richTextMarksAt(model.current, range.to));
|
|
1323
|
-
});
|
|
1324
|
-
useEffect3(() => {
|
|
1325
|
-
document.addEventListener("selectionchange", remember);
|
|
1326
|
-
return () => document.removeEventListener("selectionchange", remember);
|
|
1327
|
-
}, []);
|
|
1214
|
+
editor.setEditable(!disabled, false);
|
|
1215
|
+
}, [editor, disabled]);
|
|
1328
1216
|
useEffect3(() => {
|
|
1329
|
-
|
|
1330
|
-
if (!element || composing.current)
|
|
1217
|
+
if (!editor)
|
|
1331
1218
|
return;
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
writeRichTextDOM(element, value, variables);
|
|
1338
|
-
setRevision((current) => current + 1);
|
|
1339
|
-
setHistoryState({ undo: false, redo: false });
|
|
1219
|
+
for (const chip of editor.view.dom.querySelectorAll("[data-rich-variable]")) {
|
|
1220
|
+
const key = chip.getAttribute("data-rich-variable");
|
|
1221
|
+
const text = `{{${variables.find((variable) => variable.key === key)?.label ?? key}}}`;
|
|
1222
|
+
if (chip.textContent !== text)
|
|
1223
|
+
chip.textContent = text;
|
|
1340
1224
|
}
|
|
1341
|
-
}, [
|
|
1225
|
+
}, [editor, variables]);
|
|
1342
1226
|
return /* @__PURE__ */ jsxs4("div", {
|
|
1343
1227
|
"data-slot": "rich-text-editor",
|
|
1344
1228
|
className: `bg-background text-foreground overflow-hidden rounded-xl border ${className ?? ""}`,
|
|
@@ -1369,29 +1253,22 @@ var RichTextEditor = ({
|
|
|
1369
1253
|
}),
|
|
1370
1254
|
/* @__PURE__ */ jsxs4(Select, {
|
|
1371
1255
|
disabled,
|
|
1372
|
-
|
|
1256
|
+
value: editor?.getAttributes("paragraph").kind ?? "paragraph",
|
|
1373
1257
|
items: [
|
|
1374
1258
|
{ value: "paragraph", label: copy.paragraph },
|
|
1375
1259
|
{ value: "heading", label: copy.heading },
|
|
1376
1260
|
{ value: "bullet", label: copy.bullet },
|
|
1377
1261
|
{ value: "numbered", label: copy.numbered }
|
|
1378
1262
|
],
|
|
1379
|
-
onOpenChange: (open) => {
|
|
1380
|
-
if (open)
|
|
1381
|
-
selection();
|
|
1382
|
-
},
|
|
1383
1263
|
onValueChange: (value) => {
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
commit(setRichTextBlock(model.current, range, type), range);
|
|
1264
|
+
if (!disabled && value)
|
|
1265
|
+
editor?.chain().focus().updateAttributes("paragraph", { kind: value }).run();
|
|
1387
1266
|
},
|
|
1388
1267
|
children: [
|
|
1389
1268
|
/* @__PURE__ */ jsx7(SelectTrigger, {
|
|
1390
1269
|
size: "sm",
|
|
1391
1270
|
"aria-label": copy.paragraph,
|
|
1392
1271
|
className: "max-w-40 text-xs",
|
|
1393
|
-
onPointerDown: selection,
|
|
1394
|
-
onFocus: selection,
|
|
1395
1272
|
children: /* @__PURE__ */ jsx7(SelectValue, {})
|
|
1396
1273
|
}),
|
|
1397
1274
|
/* @__PURE__ */ jsxs4(SelectContent, {
|
|
@@ -1445,7 +1322,6 @@ var RichTextEditor = ({
|
|
|
1445
1322
|
disabled,
|
|
1446
1323
|
pressed: linkOpen || !!marks.href,
|
|
1447
1324
|
onClick: () => {
|
|
1448
|
-
selection();
|
|
1449
1325
|
setLink(marks.href ?? "");
|
|
1450
1326
|
setLinkError(false);
|
|
1451
1327
|
setLinkOpen(!linkOpen);
|
|
@@ -1455,15 +1331,9 @@ var RichTextEditor = ({
|
|
|
1455
1331
|
]
|
|
1456
1332
|
}) : null,
|
|
1457
1333
|
variables.length ? /* @__PURE__ */ jsxs4(DropdownMenu, {
|
|
1458
|
-
onOpenChange: (open) => {
|
|
1459
|
-
if (open)
|
|
1460
|
-
selection();
|
|
1461
|
-
},
|
|
1462
1334
|
children: [
|
|
1463
1335
|
/* @__PURE__ */ jsxs4(DropdownMenuTrigger, {
|
|
1464
1336
|
disabled,
|
|
1465
|
-
onPointerDown: selection,
|
|
1466
|
-
onFocus: selection,
|
|
1467
1337
|
render: /* @__PURE__ */ jsx7(Button, {
|
|
1468
1338
|
type: "button",
|
|
1469
1339
|
variant: "outline",
|
|
@@ -1486,7 +1356,7 @@ var RichTextEditor = ({
|
|
|
1486
1356
|
align: "end",
|
|
1487
1357
|
finalFocus: focusEditor,
|
|
1488
1358
|
children: variables.map((variable) => /* @__PURE__ */ jsx7(DropdownMenuItem, {
|
|
1489
|
-
onClick: () =>
|
|
1359
|
+
onClick: () => insertVariable(variable.key),
|
|
1490
1360
|
children: variable.label
|
|
1491
1361
|
}, variable.key))
|
|
1492
1362
|
})
|
|
@@ -1518,7 +1388,7 @@ var RichTextEditor = ({
|
|
|
1518
1388
|
setLinkError(true);
|
|
1519
1389
|
return;
|
|
1520
1390
|
}
|
|
1521
|
-
|
|
1391
|
+
editor?.chain().focus().setLink({ href: link }).run();
|
|
1522
1392
|
setLinkOpen(false);
|
|
1523
1393
|
},
|
|
1524
1394
|
children: copy.apply
|
|
@@ -1529,7 +1399,7 @@ var RichTextEditor = ({
|
|
|
1529
1399
|
variant: "outline",
|
|
1530
1400
|
disabled,
|
|
1531
1401
|
onClick: () => {
|
|
1532
|
-
|
|
1402
|
+
editor?.chain().focus().unsetLink().run();
|
|
1533
1403
|
setLinkOpen(false);
|
|
1534
1404
|
setLinkError(false);
|
|
1535
1405
|
},
|
|
@@ -1554,56 +1424,9 @@ var RichTextEditor = ({
|
|
|
1554
1424
|
}) : null
|
|
1555
1425
|
]
|
|
1556
1426
|
}) : null,
|
|
1557
|
-
/* @__PURE__ */ jsx7(
|
|
1558
|
-
|
|
1559
|
-
style: contentStyle
|
|
1560
|
-
role: "textbox",
|
|
1561
|
-
"aria-label": label,
|
|
1562
|
-
"aria-multiline": !singleLine,
|
|
1563
|
-
"aria-disabled": disabled,
|
|
1564
|
-
"aria-describedby": error ? `${id}-error` : undefined,
|
|
1565
|
-
contentEditable: !disabled,
|
|
1566
|
-
suppressContentEditableWarning: true,
|
|
1567
|
-
className: `focus-visible:ring-ring ${singleLine ? "min-h-10" : "min-h-32"} px-4 py-3 text-sm leading-relaxed outline-none focus-visible:ring-2 focus-visible:ring-inset [&>div]:min-h-[1.5em]`,
|
|
1568
|
-
onInput: syncInput,
|
|
1569
|
-
onKeyUp: selection,
|
|
1570
|
-
onPointerUp: selection,
|
|
1571
|
-
onBlur: selection,
|
|
1572
|
-
onCompositionStart: () => {
|
|
1573
|
-
composing.current = true;
|
|
1574
|
-
},
|
|
1575
|
-
onCompositionEnd: () => {
|
|
1576
|
-
composing.current = false;
|
|
1577
|
-
syncInput();
|
|
1578
|
-
},
|
|
1579
|
-
onPaste: (event) => {
|
|
1580
|
-
event.preventDefault();
|
|
1581
|
-
const text = event.clipboardData.getData("text/plain");
|
|
1582
|
-
insert({
|
|
1583
|
-
type: "text",
|
|
1584
|
-
text: singleLine ? text.replace(/[\r\n]+/g, " ") : text
|
|
1585
|
-
});
|
|
1586
|
-
},
|
|
1587
|
-
onDrop: (event) => event.preventDefault(),
|
|
1588
|
-
onClick: (event) => {
|
|
1589
|
-
if (event.target instanceof HTMLElement && event.target.closest("a"))
|
|
1590
|
-
event.preventDefault();
|
|
1591
|
-
},
|
|
1592
|
-
onKeyDown: (event) => {
|
|
1593
|
-
if (event.nativeEvent.isComposing)
|
|
1594
|
-
return;
|
|
1595
|
-
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
|
|
1596
|
-
const key = event.key.toLowerCase();
|
|
1597
|
-
if (["b", "i", "u", "z", "y"].includes(key)) {
|
|
1598
|
-
event.preventDefault();
|
|
1599
|
-
if (key === "z" || key === "y")
|
|
1600
|
-
travel(key === "y" || event.shiftKey ? 1 : -1);
|
|
1601
|
-
else if (!singleLine)
|
|
1602
|
-
format(key === "b" ? "bold" : key === "i" ? "italic" : "underline");
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
},
|
|
1606
|
-
children: initial
|
|
1427
|
+
/* @__PURE__ */ jsx7(EditorContent, {
|
|
1428
|
+
editor,
|
|
1429
|
+
style: contentStyle
|
|
1607
1430
|
}),
|
|
1608
1431
|
error ? /* @__PURE__ */ jsx7("p", {
|
|
1609
1432
|
id: `${id}-error`,
|
|
@@ -2029,8 +1852,8 @@ var EmailEditor = ({
|
|
|
2029
1852
|
const [active, setActive] = useState4(value.elements.find((element) => element.type === "text")?.id ?? null);
|
|
2030
1853
|
const selected = value.elements.find((element) => element.id === active);
|
|
2031
1854
|
const [view, setView] = useState4("design");
|
|
2032
|
-
const canvas =
|
|
2033
|
-
const elementSurfaces =
|
|
1855
|
+
const canvas = useRef3(null);
|
|
1856
|
+
const elementSurfaces = useRef3(new Map);
|
|
2034
1857
|
const [settingsOpen, setSettingsOpen] = useState4(false);
|
|
2035
1858
|
const settingsAnchor = useMemo(() => settingsOpen ? {
|
|
2036
1859
|
get contextElement() {
|