@editorcn/editor 0.4.0 → 0.4.2

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/README.md CHANGED
@@ -1,87 +1,87 @@
1
- # @editorcn/editor
2
-
3
- A **toolbar-style** rich text editor built on [Tiptap](https://tiptap.dev/) with shadcn/ui design tokens. Part of the [editorcn](https://editorcn.vercel.app) editor suite.
4
-
5
- ## Features
6
-
7
- - Compound component API (`RichTextEditor`, `RichTextEditor.Toolbar`, `RichTextEditor.Content`, etc.)
8
- - 20+ built-in toolbar controls (Bold, H1, Link, Undo, etc.)
9
- - Sticky toolbar with configurable control groups
10
- - Fully typed with TypeScript
11
- - Extensible via Tiptap extensions
12
- - Built with shadcn/ui CSS variables — matches your theme
13
-
14
- ## Installation
15
-
16
- ### npm
17
-
18
- ```bash
19
- npm install @editorcn/editor @tiptap/react @tiptap/pm @tiptap/starter-kit @tiptap/extension-link
20
- ```
21
-
22
- > **Tiptap v3 required.** `@editorcn/editor` is built against Tiptap **v3**. Make sure your `@tiptap/*` packages are on v3, and import `BubbleMenu`/`FloatingMenu` from `@tiptap/react/menus` (not the `@tiptap/react` root) if you use them directly.
23
-
24
- ### shadcn registry
25
-
26
- ```bash
27
- npx shadcn@latest add @editorcn/editor
28
- ```
29
-
30
- Make sure your `components.json` includes the editorcn registry:
31
-
32
- ```json
33
- {
34
- "registries": {
35
- "@editorcn": "https://editorcn.vercel.app/r/{name}.json"
36
- }
37
- }
38
- ```
39
-
40
- ## Usage
41
-
42
- ```tsx
43
- "use client";
44
-
45
- import { useEditor } from "@tiptap/react";
46
- import { StarterKit } from "@tiptap/starter-kit";
47
- import { Underline } from "@tiptap/extension-underline";
48
- import { RichTextEditor, Link } from "@editorcn/editor";
49
- import "@editorcn/editor/style.css";
50
-
51
- export function MyEditor() {
52
- const editor = useEditor({
53
- extensions: [StarterKit, Link, Underline],
54
- content: "<p>Start typing...</p>",
55
- });
56
-
57
- return (
58
- <RichTextEditor editor={editor}>
59
- <RichTextEditor.Toolbar sticky>
60
- <RichTextEditor.ControlsGroup>
61
- <RichTextEditor.Bold />
62
- <RichTextEditor.Italic />
63
- <RichTextEditor.Underline />
64
- </RichTextEditor.ControlsGroup>
65
- <RichTextEditor.ControlsGroup>
66
- <RichTextEditor.H1 />
67
- <RichTextEditor.H2 />
68
- <RichTextEditor.H3 />
69
- </RichTextEditor.ControlsGroup>
70
- <RichTextEditor.ControlsGroup>
71
- <RichTextEditor.Undo />
72
- <RichTextEditor.Redo />
73
- </RichTextEditor.ControlsGroup>
74
- </RichTextEditor.Toolbar>
75
- <RichTextEditor.Content />
76
- </RichTextEditor>
77
- );
78
- }
79
- ```
80
-
81
- ## Documentation
82
-
83
- Full API reference at [editorcn.vercel.app/docs/editor](https://editorcn.vercel.app/docs/editor).
84
-
85
- ## License
86
-
87
- MIT
1
+ # @editorcn/editor
2
+
3
+ A **toolbar-style** rich text editor built on [Tiptap](https://tiptap.dev/) with shadcn/ui design tokens. Part of the [editorcn](https://www.rtecn.space) editor suite.
4
+
5
+ ## Features
6
+
7
+ - Compound component API (`RichTextEditor`, `RichTextEditor.Toolbar`, `RichTextEditor.Content`, etc.)
8
+ - 20+ built-in toolbar controls (Bold, H1, Link, Undo, etc.)
9
+ - Sticky toolbar with configurable control groups
10
+ - Fully typed with TypeScript
11
+ - Extensible via Tiptap extensions
12
+ - Built with shadcn/ui CSS variables — matches your theme
13
+
14
+ ## Installation
15
+
16
+ ### npm
17
+
18
+ ```bash
19
+ npm install @editorcn/editor @tiptap/react @tiptap/pm @tiptap/starter-kit @tiptap/extension-link
20
+ ```
21
+
22
+ > **Tiptap v3 required.** `@editorcn/editor` is built against Tiptap **v3**. Make sure your `@tiptap/*` packages are on v3, and import `BubbleMenu`/`FloatingMenu` from `@tiptap/react/menus` (not the `@tiptap/react` root) if you use them directly.
23
+
24
+ ### shadcn registry
25
+
26
+ ```bash
27
+ npx shadcn@latest add @editorcn/editor
28
+ ```
29
+
30
+ Make sure your `components.json` includes the editorcn registry:
31
+
32
+ ```json
33
+ {
34
+ "registries": {
35
+ "@editorcn": "https://www.rtecn.space/r/{name}.json"
36
+ }
37
+ }
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ```tsx
43
+ "use client";
44
+
45
+ import { useEditor } from "@tiptap/react";
46
+ import { StarterKit } from "@tiptap/starter-kit";
47
+ import { Underline } from "@tiptap/extension-underline";
48
+ import { RichTextEditor, Link } from "@editorcn/editor";
49
+ import "@editorcn/editor/style.css";
50
+
51
+ export function MyEditor() {
52
+ const editor = useEditor({
53
+ extensions: [StarterKit, Link, Underline],
54
+ content: "<p>Start typing...</p>",
55
+ });
56
+
57
+ return (
58
+ <RichTextEditor editor={editor}>
59
+ <RichTextEditor.Toolbar sticky>
60
+ <RichTextEditor.ControlsGroup>
61
+ <RichTextEditor.Bold />
62
+ <RichTextEditor.Italic />
63
+ <RichTextEditor.Underline />
64
+ </RichTextEditor.ControlsGroup>
65
+ <RichTextEditor.ControlsGroup>
66
+ <RichTextEditor.H1 />
67
+ <RichTextEditor.H2 />
68
+ <RichTextEditor.H3 />
69
+ </RichTextEditor.ControlsGroup>
70
+ <RichTextEditor.ControlsGroup>
71
+ <RichTextEditor.Undo />
72
+ <RichTextEditor.Redo />
73
+ </RichTextEditor.ControlsGroup>
74
+ </RichTextEditor.Toolbar>
75
+ <RichTextEditor.Content />
76
+ </RichTextEditor>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ## Documentation
82
+
83
+ Full API reference at [www.rtecn.space/docs/editor](https://www.rtecn.space/docs/editor).
84
+
85
+ ## License
86
+
87
+ MIT
package/dist/index.cjs CHANGED
@@ -139,7 +139,7 @@ var DialogContent = ({
139
139
  {
140
140
  "data-slot": "dialog-content",
141
141
  className: cn(
142
- "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-none bg-popover p-4 text-xs/relaxed text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm 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",
142
+ "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-5 text-xs/relaxed text-popover-foreground shadow-[0_8px_30px_-12px_rgb(0_0_0/0.15)] ring-1 ring-border/60 duration-100 outline-none sm:max-w-sm 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",
143
143
  className
144
144
  ),
145
145
  ...props,
@@ -265,7 +265,7 @@ var PopoverContent = ({
265
265
  {
266
266
  "data-slot": "popover-content",
267
267
  className: cn(
268
- "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-none bg-popover p-2.5 text-xs text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 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",
268
+ "z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-xs text-popover-foreground shadow-[0_8px_30px_-12px_rgb(0_0_0/0.15)] ring-1 ring-border/60 outline-hidden duration-100 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",
269
269
  className
270
270
  ),
271
271
  ...props
@@ -548,7 +548,7 @@ var import_toggle = require("@base-ui/react/toggle");
548
548
  var import_class_variance_authority2 = require("class-variance-authority");
549
549
  var import_jsx_runtime15 = require("react/jsx-runtime");
550
550
  var toggleVariants = (0, import_class_variance_authority2.cva)(
551
- "group/toggle inline-flex items-center justify-center gap-1 rounded-none text-xs font-medium whitespace-nowrap transition-all outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
551
+ "group/toggle inline-flex items-center justify-center gap-1 rounded-md text-xs font-medium whitespace-nowrap transition-all outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
552
552
  {
553
553
  defaultVariants: {
554
554
  size: "default",
@@ -558,7 +558,7 @@ var toggleVariants = (0, import_class_variance_authority2.cva)(
558
558
  size: {
559
559
  default: "h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
560
560
  lg: "h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
561
- sm: "h-7 min-w-7 rounded-none px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5"
561
+ sm: "h-7 min-w-7 px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5"
562
562
  },
563
563
  variant: {
564
564
  default: "bg-transparent",
@@ -618,13 +618,13 @@ var TooltipContent = ({
618
618
  {
619
619
  "data-slot": "tooltip-content",
620
620
  className: cn(
621
- "z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-none bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 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-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-none data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 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",
621
+ "z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-2 py-1 text-xs text-background has-data-[slot=kbd]:pr-1.5 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-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 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",
622
622
  className
623
623
  ),
624
624
  ...props,
625
625
  children: [
626
626
  children,
627
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_tooltip.Tooltip.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-none bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" })
627
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_tooltip.Tooltip.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-left-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-right-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" })
628
628
  ]
629
629
  }
630
630
  )
@@ -910,7 +910,8 @@ var textItems = [
910
910
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M6 4h8a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" }),
911
911
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M6 12h9a4 4 0 0 1 4 4 4 4 0 0 1-4 4H6z" })
912
912
  ] }) }),
913
- isActive: (s) => s.isBold
913
+ isActive: (s) => s.isBold,
914
+ mark: "bold"
914
915
  },
915
916
  {
916
917
  command: (e) => e.chain().focus().toggleItalic().run(),
@@ -919,7 +920,8 @@ var textItems = [
919
920
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("line", { x1: "14", y1: "20", x2: "5", y2: "20" }),
920
921
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("line", { x1: "15", y1: "4", x2: "9", y2: "20" })
921
922
  ] }) }),
922
- isActive: (s) => s.isItalic
923
+ isActive: (s) => s.isItalic,
924
+ mark: "italic"
923
925
  },
924
926
  {
925
927
  command: (e) => e.chain().focus().toggleUnderline().run(),
@@ -927,7 +929,8 @@ var textItems = [
927
929
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }),
928
930
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("line", { x1: "4", y1: "20", x2: "20", y2: "20" })
929
931
  ] }) }),
930
- isActive: (s) => s.isUnderline
932
+ isActive: (s) => s.isUnderline,
933
+ mark: "underline"
931
934
  },
932
935
  {
933
936
  command: (e) => e.chain().focus().toggleStrike().run(),
@@ -936,7 +939,8 @@ var textItems = [
936
939
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("path", { d: "M14.5 14.6a3.5 3.5 0 0 1-2.9 5.4H8" }),
937
940
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("line", { x1: "4", y1: "12", x2: "20", y2: "12" })
938
941
  ] }) }),
939
- isActive: (s) => s.isStrike
942
+ isActive: (s) => s.isStrike,
943
+ mark: "strike"
940
944
  },
941
945
  {
942
946
  command: (e) => e.chain().focus().toggleCode().run(),
@@ -944,9 +948,11 @@ var textItems = [
944
948
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("polyline", { points: "16 18 22 12 16 6" }),
945
949
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("polyline", { points: "8 6 2 12 8 18" })
946
950
  ] }) }),
947
- isActive: (s) => s.isCode
951
+ isActive: (s) => s.isCode,
952
+ mark: "code"
948
953
  }
949
954
  ];
955
+ var getTextItems = (editor) => textItems.filter((item) => Boolean(editor.schema.marks[item.mark]));
950
956
  var TextButtons = ({ editor }) => {
951
957
  const editorState = useEditorState(
952
958
  editor,
@@ -959,7 +965,7 @@ var TextButtons = ({ editor }) => {
959
965
  }),
960
966
  shallowEqual
961
967
  );
962
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RteButtonGroup, { children: textItems.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
968
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RteButtonGroup, { children: getTextItems(editor).map((item) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
963
969
  RteButton,
964
970
  {
965
971
  active: item.isActive(editorState),
@@ -967,7 +973,7 @@ var TextButtons = ({ editor }) => {
967
973
  onClick: () => item.command(editor),
968
974
  children: item.icon
969
975
  },
970
- i
976
+ item.mark
971
977
  )) });
972
978
  };
973
979
 
@@ -996,6 +1002,13 @@ var BubbleMenu = ({ editor }) => {
996
1002
  if (!editor) {
997
1003
  return null;
998
1004
  }
1005
+ const hasText = getTextItems(editor).length > 0;
1006
+ const hasColor = editor.extensionManager.extensions.some(
1007
+ (ext) => ext.name === "color" || ext.name === "highlight"
1008
+ );
1009
+ if (!(hasText || hasColor)) {
1010
+ return null;
1011
+ }
999
1012
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1000
1013
  import_menus.BubbleMenu,
1001
1014
  {
@@ -1003,9 +1016,9 @@ var BubbleMenu = ({ editor }) => {
1003
1016
  options: { offset: 8, placement: "top" },
1004
1017
  shouldShow,
1005
1018
  children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "rte-bubble-menu", children: [
1006
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(TextButtons, { editor }),
1007
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(RteSeparator, {}),
1008
- /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ColorSelector, { editor })
1019
+ hasText && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(TextButtons, { editor }),
1020
+ hasText && hasColor && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(RteSeparator, {}),
1021
+ hasColor && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(ColorSelector, { editor })
1009
1022
  ] })
1010
1023
  }
1011
1024
  );