@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 CHANGED
@@ -3277,6 +3277,33 @@ interface ShadcnToggleVariantProps extends Pick<VariantBaseProps<string | string
3277
3277
  gap?: number;
3278
3278
  }
3279
3279
 
3280
+ /**
3281
+ * Host app MUST import Toast UI Editor CSS:
3282
+ * import "@toast-ui/editor/dist/toastui-editor.css";
3283
+ */
3284
+ type ToastToolbarItem = "heading" | "bold" | "italic" | "strike" | "hr" | "quote" | "ul" | "ol" | "task" | "indent" | "outdent" | "table" | "image" | "link" | "code" | "codeblock";
3285
+ type EditorFormat = "html" | "markdown";
3286
+ type EditorToolbar = "default" | "none" | ToastToolbarItem[][];
3287
+ interface ShadcnEditorVariantProps extends Pick<VariantBaseProps<string | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "required" | "size" | "density"> {
3288
+ placeholder?: string;
3289
+ height?: string;
3290
+ previewStyle?: "vertical" | "tab";
3291
+ editType?: "wysiwyg" | "markdown";
3292
+ useCommandShortcut?: boolean;
3293
+ /** Which format to store in the form value */
3294
+ format?: EditorFormat;
3295
+ /**
3296
+ * Toolbar config:
3297
+ * - "default" uses Toast UI defaults
3298
+ * - "none" hides tools + mode switch
3299
+ * - array provides toolbarItems
3300
+ */
3301
+ toolbar?: EditorToolbar;
3302
+ /** If true, paste is intercepted and inserted as plain text only */
3303
+ pastePlainText?: boolean;
3304
+ className?: string;
3305
+ }
3306
+
3280
3307
  /**
3281
3308
  * Helper type for a single variant registry entry.
3282
3309
  *
@@ -3331,6 +3358,7 @@ interface Variants<H = unknown> {
3331
3358
  custom: VariantEntry<unknown | undefined, ShadcnCustomVariantProps>;
3332
3359
  treeselect: VariantEntry<string | number | undefined, ShadcnTreeSelectVariantProps>;
3333
3360
  file: VariantEntry<FileLike, ShadcnFileVariantProps>;
3361
+ editor: VariantEntry<string | undefined, ShadcnEditorVariantProps>;
3334
3362
  }
3335
3363
  /**
3336
3364
  * Union of all variant keys.
package/dist/index.d.ts CHANGED
@@ -3277,6 +3277,33 @@ interface ShadcnToggleVariantProps extends Pick<VariantBaseProps<string | string
3277
3277
  gap?: number;
3278
3278
  }
3279
3279
 
3280
+ /**
3281
+ * Host app MUST import Toast UI Editor CSS:
3282
+ * import "@toast-ui/editor/dist/toastui-editor.css";
3283
+ */
3284
+ type ToastToolbarItem = "heading" | "bold" | "italic" | "strike" | "hr" | "quote" | "ul" | "ol" | "task" | "indent" | "outdent" | "table" | "image" | "link" | "code" | "codeblock";
3285
+ type EditorFormat = "html" | "markdown";
3286
+ type EditorToolbar = "default" | "none" | ToastToolbarItem[][];
3287
+ interface ShadcnEditorVariantProps extends Pick<VariantBaseProps<string | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "required" | "size" | "density"> {
3288
+ placeholder?: string;
3289
+ height?: string;
3290
+ previewStyle?: "vertical" | "tab";
3291
+ editType?: "wysiwyg" | "markdown";
3292
+ useCommandShortcut?: boolean;
3293
+ /** Which format to store in the form value */
3294
+ format?: EditorFormat;
3295
+ /**
3296
+ * Toolbar config:
3297
+ * - "default" uses Toast UI defaults
3298
+ * - "none" hides tools + mode switch
3299
+ * - array provides toolbarItems
3300
+ */
3301
+ toolbar?: EditorToolbar;
3302
+ /** If true, paste is intercepted and inserted as plain text only */
3303
+ pastePlainText?: boolean;
3304
+ className?: string;
3305
+ }
3306
+
3280
3307
  /**
3281
3308
  * Helper type for a single variant registry entry.
3282
3309
  *
@@ -3331,6 +3358,7 @@ interface Variants<H = unknown> {
3331
3358
  custom: VariantEntry<unknown | undefined, ShadcnCustomVariantProps>;
3332
3359
  treeselect: VariantEntry<string | number | undefined, ShadcnTreeSelectVariantProps>;
3333
3360
  file: VariantEntry<FileLike, ShadcnFileVariantProps>;
3361
+ editor: VariantEntry<string | undefined, ShadcnEditorVariantProps>;
3334
3362
  }
3335
3363
  /**
3336
3364
  * Union of all variant keys.
package/dist/index.js CHANGED
@@ -14,8 +14,12 @@ var ScrollAreaPrimitive = require('@radix-ui/react-scroll-area');
14
14
  var ToggleGroupPrimitive = require('@radix-ui/react-toggle-group');
15
15
  require('@radix-ui/react-toggle');
16
16
  var TooltipPrimitive = require('@radix-ui/react-tooltip');
17
+ var Editor = require('@toast-ui/editor');
18
+ require('@toast-ui/editor/dist/toastui-editor.css');
17
19
  var LabelPrimitive = require('@radix-ui/react-label');
18
20
 
21
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
22
+
19
23
  function _interopNamespace(e) {
20
24
  if (e && e.__esModule) return e;
21
25
  var n = Object.create(null);
@@ -45,6 +49,7 @@ var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive)
45
49
  var ScrollAreaPrimitive__namespace = /*#__PURE__*/_interopNamespace(ScrollAreaPrimitive);
46
50
  var ToggleGroupPrimitive__namespace = /*#__PURE__*/_interopNamespace(ToggleGroupPrimitive);
47
51
  var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
52
+ var Editor__default = /*#__PURE__*/_interopDefault(Editor);
48
53
  var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespace(LabelPrimitive);
49
54
 
50
55
  var __defProp = Object.defineProperty;
@@ -20655,6 +20660,195 @@ var toggleGroupModule = {
20655
20660
  tags: ["buttons", "toggle"]
20656
20661
  }
20657
20662
  };
20663
+ function ShadcnEditorVariant(props) {
20664
+ const {
20665
+ value,
20666
+ onValue,
20667
+ error,
20668
+ disabled,
20669
+ readOnly,
20670
+ required,
20671
+ size,
20672
+ density,
20673
+ className,
20674
+ placeholder = "",
20675
+ height = "400px",
20676
+ previewStyle = "vertical",
20677
+ editType = "wysiwyg",
20678
+ useCommandShortcut = true,
20679
+ format: format2 = "html",
20680
+ toolbar = "default",
20681
+ pastePlainText = false
20682
+ } = props;
20683
+ const mountRef = React10__namespace.useRef(null);
20684
+ const editorRef = React10__namespace.useRef(null);
20685
+ const formatRef = React10__namespace.useRef(format2);
20686
+ const onValueRef = React10__namespace.useRef(onValue);
20687
+ const syncingRef = React10__namespace.useRef(false);
20688
+ const loadedRef = React10__namespace.useRef(false);
20689
+ formatRef.current = format2;
20690
+ onValueRef.current = onValue;
20691
+ const effectiveReadOnly = Boolean(disabled || readOnly);
20692
+ const readContent = React10__namespace.useCallback((ed) => {
20693
+ var _a, _b;
20694
+ return formatRef.current === "markdown" ? (_a = ed.getMarkdown()) != null ? _a : "" : (_b = ed.getHTML()) != null ? _b : "";
20695
+ }, []);
20696
+ const emit = React10__namespace.useCallback((next) => {
20697
+ var _a;
20698
+ const detail = { source: "user", raw: next };
20699
+ (_a = onValueRef.current) == null ? void 0 : _a.call(onValueRef, next, detail);
20700
+ }, []);
20701
+ const structuralKey = React10__namespace.useMemo(() => {
20702
+ const hideModeSwitch = toolbar === "none" || pastePlainText;
20703
+ return JSON.stringify({ toolbar, useCommandShortcut, hideModeSwitch });
20704
+ }, [toolbar, useCommandShortcut, pastePlainText]);
20705
+ React10__namespace.useEffect(() => {
20706
+ const el = mountRef.current;
20707
+ if (!el) return;
20708
+ if (editorRef.current) {
20709
+ try {
20710
+ editorRef.current.off("change");
20711
+ } catch {
20712
+ }
20713
+ try {
20714
+ editorRef.current.off("load");
20715
+ } catch {
20716
+ }
20717
+ try {
20718
+ editorRef.current.destroy();
20719
+ } catch {
20720
+ }
20721
+ editorRef.current = null;
20722
+ }
20723
+ loadedRef.current = false;
20724
+ syncingRef.current = true;
20725
+ const hideModeSwitch = toolbar === "none" || pastePlainText;
20726
+ const options = {
20727
+ el,
20728
+ height,
20729
+ initialValue: value != null ? value : "",
20730
+ previewStyle,
20731
+ initialEditType: editType,
20732
+ useCommandShortcut,
20733
+ usageStatistics: false,
20734
+ placeholder,
20735
+ hideModeSwitch,
20736
+ ...toolbar === "none" ? { toolbarItems: [] } : Array.isArray(toolbar) ? { toolbarItems: toolbar } : {},
20737
+ events: {
20738
+ load: () => {
20739
+ loadedRef.current = true;
20740
+ syncingRef.current = false;
20741
+ },
20742
+ change: () => {
20743
+ const ed = editorRef.current;
20744
+ if (!ed) return;
20745
+ if (syncingRef.current) return;
20746
+ emit(readContent(ed));
20747
+ }
20748
+ }
20749
+ };
20750
+ editorRef.current = new Editor__default.default(options);
20751
+ Promise.resolve().then(() => {
20752
+ syncingRef.current = false;
20753
+ });
20754
+ return () => {
20755
+ const ed = editorRef.current;
20756
+ if (!ed) return;
20757
+ try {
20758
+ ed.off("change");
20759
+ } catch {
20760
+ }
20761
+ try {
20762
+ ed.off("load");
20763
+ } catch {
20764
+ }
20765
+ try {
20766
+ ed.destroy();
20767
+ } catch {
20768
+ }
20769
+ editorRef.current = null;
20770
+ };
20771
+ }, [structuralKey]);
20772
+ React10__namespace.useEffect(() => {
20773
+ const ed = editorRef.current;
20774
+ if (!ed) return;
20775
+ if (typeof ed.setHeight === "function") ed.setHeight(height);
20776
+ }, [height]);
20777
+ React10__namespace.useEffect(() => {
20778
+ const ed = editorRef.current;
20779
+ if (!ed) return;
20780
+ if (typeof ed.setPlaceholder === "function")
20781
+ ed.setPlaceholder(placeholder);
20782
+ }, [placeholder]);
20783
+ React10__namespace.useEffect(() => {
20784
+ const ed = editorRef.current;
20785
+ if (!ed) return;
20786
+ if (typeof ed.changeMode === "function") ed.changeMode(editType);
20787
+ }, [editType]);
20788
+ React10__namespace.useEffect(() => {
20789
+ const ed = editorRef.current;
20790
+ if (!ed) return;
20791
+ if (typeof ed.changePreviewStyle === "function")
20792
+ ed.changePreviewStyle(previewStyle);
20793
+ }, [previewStyle]);
20794
+ React10__namespace.useEffect(() => {
20795
+ var _a, _b, _c, _d;
20796
+ const ed = editorRef.current;
20797
+ if (!ed) return;
20798
+ const next = value != null ? value : "";
20799
+ syncingRef.current = true;
20800
+ if (format2 === "markdown") {
20801
+ const cur = (_b = (_a = ed.getMarkdown) == null ? void 0 : _a.call(ed)) != null ? _b : "";
20802
+ if (cur !== next) ed.setMarkdown(next, false);
20803
+ } else {
20804
+ const cur = (_d = (_c = ed.getHTML) == null ? void 0 : _c.call(ed)) != null ? _d : "";
20805
+ if (cur !== next) ed.setHTML(next, false);
20806
+ }
20807
+ Promise.resolve().then(() => {
20808
+ syncingRef.current = false;
20809
+ });
20810
+ }, [value, format2]);
20811
+ React10__namespace.useEffect(() => {
20812
+ if (!pastePlainText) return;
20813
+ const host = mountRef.current;
20814
+ if (!host) return;
20815
+ const onPaste = (e) => {
20816
+ var _a, _b;
20817
+ e.preventDefault();
20818
+ const text = (_b = (_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain")) != null ? _b : "";
20819
+ const ed = editorRef.current;
20820
+ if (text && ed) ed.insertText(text);
20821
+ };
20822
+ host.addEventListener("paste", onPaste);
20823
+ return () => host.removeEventListener("paste", onPaste);
20824
+ }, [pastePlainText]);
20825
+ return /* @__PURE__ */ jsxRuntime.jsx(
20826
+ "div",
20827
+ {
20828
+ "data-size": size,
20829
+ "data-density": density,
20830
+ className: cn(
20831
+ "rounded-md border border-input bg-background overflow-hidden",
20832
+ effectiveReadOnly && "opacity-60 pointer-events-none",
20833
+ className
20834
+ ),
20835
+ "aria-invalid": error ? true : void 0,
20836
+ "aria-required": required ? true : void 0,
20837
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: mountRef })
20838
+ }
20839
+ );
20840
+ }
20841
+
20842
+ // src/variants/core/editor.ts
20843
+ var shadcnEditorVariant = {
20844
+ variant: "editor",
20845
+ Variant: ShadcnEditorVariant,
20846
+ meta: {
20847
+ label: "Editor",
20848
+ description: "Toast UI Editor (vanilla @toast-ui/editor).",
20849
+ tags: ["editor", "rich-text", "markdown", "toast-ui"]
20850
+ }
20851
+ };
20658
20852
 
20659
20853
  // src/variants/index.ts
20660
20854
  var variants = [
@@ -20676,7 +20870,8 @@ var variants = [
20676
20870
  custom_default,
20677
20871
  treeselect_default2,
20678
20872
  fileManagerModule,
20679
- toggleGroupModule
20873
+ toggleGroupModule,
20874
+ shadcnEditorVariant
20680
20875
  ];
20681
20876
  function registerCoreVariants() {
20682
20877
  variants.forEach((item) => registerVariant(item));