@editorcn/editor 0.4.0 → 0.4.1

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://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
package/dist/index.cjs CHANGED
@@ -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
  );