@timeax/form-palette 0.0.23 → 0.0.25
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/index.d.mts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +196 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +193 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,8 @@ import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
|
13
13
|
import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group';
|
|
14
14
|
import '@radix-ui/react-toggle';
|
|
15
15
|
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
|
|
16
|
+
import Editor from '@toast-ui/editor';
|
|
17
|
+
import '@toast-ui/editor/dist/toastui-editor.css';
|
|
16
18
|
import * as LabelPrimitive from '@radix-ui/react-label';
|
|
17
19
|
|
|
18
20
|
var __defProp = Object.defineProperty;
|
|
@@ -20623,6 +20625,195 @@ var toggleGroupModule = {
|
|
|
20623
20625
|
tags: ["buttons", "toggle"]
|
|
20624
20626
|
}
|
|
20625
20627
|
};
|
|
20628
|
+
function ShadcnEditorVariant(props) {
|
|
20629
|
+
const {
|
|
20630
|
+
value,
|
|
20631
|
+
onValue,
|
|
20632
|
+
error,
|
|
20633
|
+
disabled,
|
|
20634
|
+
readOnly,
|
|
20635
|
+
required,
|
|
20636
|
+
size,
|
|
20637
|
+
density,
|
|
20638
|
+
className,
|
|
20639
|
+
placeholder = "",
|
|
20640
|
+
height = "400px",
|
|
20641
|
+
previewStyle = "vertical",
|
|
20642
|
+
editType = "wysiwyg",
|
|
20643
|
+
useCommandShortcut = true,
|
|
20644
|
+
format: format2 = "html",
|
|
20645
|
+
toolbar = "default",
|
|
20646
|
+
pastePlainText = false
|
|
20647
|
+
} = props;
|
|
20648
|
+
const mountRef = React10.useRef(null);
|
|
20649
|
+
const editorRef = React10.useRef(null);
|
|
20650
|
+
const formatRef = React10.useRef(format2);
|
|
20651
|
+
const onValueRef = React10.useRef(onValue);
|
|
20652
|
+
const syncingRef = React10.useRef(false);
|
|
20653
|
+
const loadedRef = React10.useRef(false);
|
|
20654
|
+
formatRef.current = format2;
|
|
20655
|
+
onValueRef.current = onValue;
|
|
20656
|
+
const effectiveReadOnly = Boolean(disabled || readOnly);
|
|
20657
|
+
const readContent = React10.useCallback((ed) => {
|
|
20658
|
+
var _a, _b;
|
|
20659
|
+
return formatRef.current === "markdown" ? (_a = ed.getMarkdown()) != null ? _a : "" : (_b = ed.getHTML()) != null ? _b : "";
|
|
20660
|
+
}, []);
|
|
20661
|
+
const emit = React10.useCallback((next) => {
|
|
20662
|
+
var _a;
|
|
20663
|
+
const detail = { source: "user", raw: next };
|
|
20664
|
+
(_a = onValueRef.current) == null ? void 0 : _a.call(onValueRef, next, detail);
|
|
20665
|
+
}, []);
|
|
20666
|
+
const structuralKey = React10.useMemo(() => {
|
|
20667
|
+
const hideModeSwitch = toolbar === "none" || pastePlainText;
|
|
20668
|
+
return JSON.stringify({ toolbar, useCommandShortcut, hideModeSwitch });
|
|
20669
|
+
}, [toolbar, useCommandShortcut, pastePlainText]);
|
|
20670
|
+
React10.useEffect(() => {
|
|
20671
|
+
const el = mountRef.current;
|
|
20672
|
+
if (!el) return;
|
|
20673
|
+
if (editorRef.current) {
|
|
20674
|
+
try {
|
|
20675
|
+
editorRef.current.off("change");
|
|
20676
|
+
} catch {
|
|
20677
|
+
}
|
|
20678
|
+
try {
|
|
20679
|
+
editorRef.current.off("load");
|
|
20680
|
+
} catch {
|
|
20681
|
+
}
|
|
20682
|
+
try {
|
|
20683
|
+
editorRef.current.destroy();
|
|
20684
|
+
} catch {
|
|
20685
|
+
}
|
|
20686
|
+
editorRef.current = null;
|
|
20687
|
+
}
|
|
20688
|
+
loadedRef.current = false;
|
|
20689
|
+
syncingRef.current = true;
|
|
20690
|
+
const hideModeSwitch = toolbar === "none" || pastePlainText;
|
|
20691
|
+
const options = {
|
|
20692
|
+
el,
|
|
20693
|
+
height,
|
|
20694
|
+
initialValue: value != null ? value : "",
|
|
20695
|
+
previewStyle,
|
|
20696
|
+
initialEditType: editType,
|
|
20697
|
+
useCommandShortcut,
|
|
20698
|
+
usageStatistics: false,
|
|
20699
|
+
placeholder,
|
|
20700
|
+
hideModeSwitch,
|
|
20701
|
+
...toolbar === "none" ? { toolbarItems: [] } : Array.isArray(toolbar) ? { toolbarItems: toolbar } : {},
|
|
20702
|
+
events: {
|
|
20703
|
+
load: () => {
|
|
20704
|
+
loadedRef.current = true;
|
|
20705
|
+
syncingRef.current = false;
|
|
20706
|
+
},
|
|
20707
|
+
change: () => {
|
|
20708
|
+
const ed = editorRef.current;
|
|
20709
|
+
if (!ed) return;
|
|
20710
|
+
if (syncingRef.current) return;
|
|
20711
|
+
emit(readContent(ed));
|
|
20712
|
+
}
|
|
20713
|
+
}
|
|
20714
|
+
};
|
|
20715
|
+
editorRef.current = new Editor(options);
|
|
20716
|
+
Promise.resolve().then(() => {
|
|
20717
|
+
syncingRef.current = false;
|
|
20718
|
+
});
|
|
20719
|
+
return () => {
|
|
20720
|
+
const ed = editorRef.current;
|
|
20721
|
+
if (!ed) return;
|
|
20722
|
+
try {
|
|
20723
|
+
ed.off("change");
|
|
20724
|
+
} catch {
|
|
20725
|
+
}
|
|
20726
|
+
try {
|
|
20727
|
+
ed.off("load");
|
|
20728
|
+
} catch {
|
|
20729
|
+
}
|
|
20730
|
+
try {
|
|
20731
|
+
ed.destroy();
|
|
20732
|
+
} catch {
|
|
20733
|
+
}
|
|
20734
|
+
editorRef.current = null;
|
|
20735
|
+
};
|
|
20736
|
+
}, [structuralKey]);
|
|
20737
|
+
React10.useEffect(() => {
|
|
20738
|
+
const ed = editorRef.current;
|
|
20739
|
+
if (!ed) return;
|
|
20740
|
+
if (typeof ed.setHeight === "function") ed.setHeight(height);
|
|
20741
|
+
}, [height]);
|
|
20742
|
+
React10.useEffect(() => {
|
|
20743
|
+
const ed = editorRef.current;
|
|
20744
|
+
if (!ed) return;
|
|
20745
|
+
if (typeof ed.setPlaceholder === "function")
|
|
20746
|
+
ed.setPlaceholder(placeholder);
|
|
20747
|
+
}, [placeholder]);
|
|
20748
|
+
React10.useEffect(() => {
|
|
20749
|
+
const ed = editorRef.current;
|
|
20750
|
+
if (!ed) return;
|
|
20751
|
+
if (typeof ed.changeMode === "function") ed.changeMode(editType);
|
|
20752
|
+
}, [editType]);
|
|
20753
|
+
React10.useEffect(() => {
|
|
20754
|
+
const ed = editorRef.current;
|
|
20755
|
+
if (!ed) return;
|
|
20756
|
+
if (typeof ed.changePreviewStyle === "function")
|
|
20757
|
+
ed.changePreviewStyle(previewStyle);
|
|
20758
|
+
}, [previewStyle]);
|
|
20759
|
+
React10.useEffect(() => {
|
|
20760
|
+
var _a, _b, _c, _d;
|
|
20761
|
+
const ed = editorRef.current;
|
|
20762
|
+
if (!ed) return;
|
|
20763
|
+
const next = value != null ? value : "";
|
|
20764
|
+
syncingRef.current = true;
|
|
20765
|
+
if (format2 === "markdown") {
|
|
20766
|
+
const cur = (_b = (_a = ed.getMarkdown) == null ? void 0 : _a.call(ed)) != null ? _b : "";
|
|
20767
|
+
if (cur !== next) ed.setMarkdown(next, false);
|
|
20768
|
+
} else {
|
|
20769
|
+
const cur = (_d = (_c = ed.getHTML) == null ? void 0 : _c.call(ed)) != null ? _d : "";
|
|
20770
|
+
if (cur !== next) ed.setHTML(next, false);
|
|
20771
|
+
}
|
|
20772
|
+
Promise.resolve().then(() => {
|
|
20773
|
+
syncingRef.current = false;
|
|
20774
|
+
});
|
|
20775
|
+
}, [value, format2]);
|
|
20776
|
+
React10.useEffect(() => {
|
|
20777
|
+
if (!pastePlainText) return;
|
|
20778
|
+
const host = mountRef.current;
|
|
20779
|
+
if (!host) return;
|
|
20780
|
+
const onPaste = (e) => {
|
|
20781
|
+
var _a, _b;
|
|
20782
|
+
e.preventDefault();
|
|
20783
|
+
const text = (_b = (_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain")) != null ? _b : "";
|
|
20784
|
+
const ed = editorRef.current;
|
|
20785
|
+
if (text && ed) ed.insertText(text);
|
|
20786
|
+
};
|
|
20787
|
+
host.addEventListener("paste", onPaste);
|
|
20788
|
+
return () => host.removeEventListener("paste", onPaste);
|
|
20789
|
+
}, [pastePlainText]);
|
|
20790
|
+
return /* @__PURE__ */ jsx(
|
|
20791
|
+
"div",
|
|
20792
|
+
{
|
|
20793
|
+
"data-size": size,
|
|
20794
|
+
"data-density": density,
|
|
20795
|
+
className: cn(
|
|
20796
|
+
"rounded-md border border-input bg-background overflow-hidden",
|
|
20797
|
+
effectiveReadOnly && "opacity-60 pointer-events-none",
|
|
20798
|
+
className
|
|
20799
|
+
),
|
|
20800
|
+
"aria-invalid": error ? true : void 0,
|
|
20801
|
+
"aria-required": required ? true : void 0,
|
|
20802
|
+
children: /* @__PURE__ */ jsx("div", { ref: mountRef })
|
|
20803
|
+
}
|
|
20804
|
+
);
|
|
20805
|
+
}
|
|
20806
|
+
|
|
20807
|
+
// src/variants/core/editor.ts
|
|
20808
|
+
var shadcnEditorVariant = {
|
|
20809
|
+
variant: "editor",
|
|
20810
|
+
Variant: ShadcnEditorVariant,
|
|
20811
|
+
meta: {
|
|
20812
|
+
label: "Editor",
|
|
20813
|
+
description: "Toast UI Editor (vanilla @toast-ui/editor).",
|
|
20814
|
+
tags: ["editor", "rich-text", "markdown", "toast-ui"]
|
|
20815
|
+
}
|
|
20816
|
+
};
|
|
20626
20817
|
|
|
20627
20818
|
// src/variants/index.ts
|
|
20628
20819
|
var variants = [
|
|
@@ -20644,7 +20835,8 @@ var variants = [
|
|
|
20644
20835
|
custom_default,
|
|
20645
20836
|
treeselect_default2,
|
|
20646
20837
|
fileManagerModule,
|
|
20647
|
-
toggleGroupModule
|
|
20838
|
+
toggleGroupModule,
|
|
20839
|
+
shadcnEditorVariant
|
|
20648
20840
|
];
|
|
20649
20841
|
function registerCoreVariants() {
|
|
20650
20842
|
variants.forEach((item) => registerVariant(item));
|