@meta-1/editor 0.0.27

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.
Files changed (130) hide show
  1. package/README.md +458 -0
  2. package/package.json +100 -0
  3. package/src/editor/constants.tsx +66 -0
  4. package/src/editor/container.css +46 -0
  5. package/src/editor/control/character-count/index.tsx +39 -0
  6. package/src/editor/control/drag-handle/index.tsx +85 -0
  7. package/src/editor/control/drag-handle/use.content.actions.ts +71 -0
  8. package/src/editor/control/drag-handle/use.data.ts +29 -0
  9. package/src/editor/control/drag-handle/use.handle.id.ts +6 -0
  10. package/src/editor/control/index.tsx +35 -0
  11. package/src/editor/editor.css +626 -0
  12. package/src/editor/extension/block-quote-figure/BlockquoteFigure.ts +73 -0
  13. package/src/editor/extension/block-quote-figure/Quote/Quote.ts +31 -0
  14. package/src/editor/extension/block-quote-figure/Quote/index.ts +1 -0
  15. package/src/editor/extension/block-quote-figure/QuoteCaption/QuoteCaption.ts +54 -0
  16. package/src/editor/extension/block-quote-figure/QuoteCaption/index.ts +1 -0
  17. package/src/editor/extension/block-quote-figure/index.ts +1 -0
  18. package/src/editor/extension/document/index.ts +5 -0
  19. package/src/editor/extension/figcaption/Figcaption.ts +90 -0
  20. package/src/editor/extension/figcaption/index.ts +1 -0
  21. package/src/editor/extension/figure/Figure.ts +62 -0
  22. package/src/editor/extension/figure/index.ts +1 -0
  23. package/src/editor/extension/font-size/FontSize.ts +64 -0
  24. package/src/editor/extension/font-size/index.ts +1 -0
  25. package/src/editor/extension/global-drag-handle/clipboard-serializer.ts +28 -0
  26. package/src/editor/extension/global-drag-handle/index.ts +377 -0
  27. package/src/editor/extension/heading/index.ts +13 -0
  28. package/src/editor/extension/horizontal-rule/HorizontalRule.ts +10 -0
  29. package/src/editor/extension/horizontal-rule/index.ts +1 -0
  30. package/src/editor/extension/image/index.ts +5 -0
  31. package/src/editor/extension/image-block/ImageBlock.ts +103 -0
  32. package/src/editor/extension/image-block/components/ImageBlockMenu.tsx +100 -0
  33. package/src/editor/extension/image-block/components/ImageBlockView.tsx +47 -0
  34. package/src/editor/extension/image-block/components/ImageBlockWidth.tsx +40 -0
  35. package/src/editor/extension/image-block/index.ts +1 -0
  36. package/src/editor/extension/image-upload/ImageUpload.ts +58 -0
  37. package/src/editor/extension/image-upload/index.ts +1 -0
  38. package/src/editor/extension/image-upload/view/ImageUpload.tsx +27 -0
  39. package/src/editor/extension/image-upload/view/ImageUploader.tsx +64 -0
  40. package/src/editor/extension/image-upload/view/hooks.ts +109 -0
  41. package/src/editor/extension/image-upload/view/index.tsx +1 -0
  42. package/src/editor/extension/index.ts +30 -0
  43. package/src/editor/extension/link/Link.ts +39 -0
  44. package/src/editor/extension/link/index.ts +1 -0
  45. package/src/editor/extension/multi-column/Column.ts +33 -0
  46. package/src/editor/extension/multi-column/Columns.ts +65 -0
  47. package/src/editor/extension/multi-column/index.ts +2 -0
  48. package/src/editor/extension/multi-column/menus/ColumnsMenu.tsx +82 -0
  49. package/src/editor/extension/multi-column/menus/index.ts +1 -0
  50. package/src/editor/extension/selection/Selection.ts +36 -0
  51. package/src/editor/extension/selection/index.ts +1 -0
  52. package/src/editor/extension/slash-command/MenuList.tsx +145 -0
  53. package/src/editor/extension/slash-command/groups.ts +153 -0
  54. package/src/editor/extension/slash-command/index.ts +277 -0
  55. package/src/editor/extension/slash-command/types.ts +25 -0
  56. package/src/editor/extension/table/Cell.ts +126 -0
  57. package/src/editor/extension/table/Header.ts +89 -0
  58. package/src/editor/extension/table/Row.ts +8 -0
  59. package/src/editor/extension/table/Table.ts +9 -0
  60. package/src/editor/extension/table/index.ts +4 -0
  61. package/src/editor/extension/table/menus/TableColumn/index.tsx +73 -0
  62. package/src/editor/extension/table/menus/TableColumn/utils.ts +38 -0
  63. package/src/editor/extension/table/menus/TableRow/index.tsx +74 -0
  64. package/src/editor/extension/table/menus/TableRow/utils.ts +38 -0
  65. package/src/editor/extension/table/menus/index.tsx +2 -0
  66. package/src/editor/extension/table/utils.ts +258 -0
  67. package/src/editor/extension/task-item/index.ts +1 -0
  68. package/src/editor/extension/task-item/task-item.ts +225 -0
  69. package/src/editor/extension/task-list/index.ts +1 -0
  70. package/src/editor/extension/task-list/task-list.ts +81 -0
  71. package/src/editor/extension/trailing-node/index.ts +1 -0
  72. package/src/editor/extension/trailing-node/trailing-node.ts +70 -0
  73. package/src/editor/extension/unique-id/index.ts +1 -0
  74. package/src/editor/extension/unique-id/uniqueId.ts +123 -0
  75. package/src/editor/hooks.ts +264 -0
  76. package/src/editor/index.tsx +53 -0
  77. package/src/editor/menus/LinkMenu/LinkMenu.tsx +75 -0
  78. package/src/editor/menus/LinkMenu/index.tsx +1 -0
  79. package/src/editor/menus/TextMenu/TextMenu.tsx +193 -0
  80. package/src/editor/menus/TextMenu/components/AIDropdown.tsx +140 -0
  81. package/src/editor/menus/TextMenu/components/ContentTypePicker.tsx +76 -0
  82. package/src/editor/menus/TextMenu/components/EditLinkPopover.tsx +25 -0
  83. package/src/editor/menus/TextMenu/components/FontFamilyPicker.tsx +84 -0
  84. package/src/editor/menus/TextMenu/components/FontSizePicker.tsx +56 -0
  85. package/src/editor/menus/TextMenu/hooks/useTextmenuCommands.ts +96 -0
  86. package/src/editor/menus/TextMenu/hooks/useTextmenuContentTypes.ts +86 -0
  87. package/src/editor/menus/TextMenu/hooks/useTextmenuStates.ts +50 -0
  88. package/src/editor/menus/TextMenu/index.tsx +2 -0
  89. package/src/editor/menus/types.ts +21 -0
  90. package/src/editor/panels/Colorpicker/ColorButton.tsx +35 -0
  91. package/src/editor/panels/Colorpicker/Colorpicker.tsx +67 -0
  92. package/src/editor/panels/Colorpicker/index.tsx +2 -0
  93. package/src/editor/panels/LinkEditorPanel/LinkEditorPanel.tsx +76 -0
  94. package/src/editor/panels/LinkEditorPanel/index.tsx +1 -0
  95. package/src/editor/panels/LinkPreviewPanel/LinkPreviewPanel.tsx +32 -0
  96. package/src/editor/panels/LinkPreviewPanel/index.tsx +1 -0
  97. package/src/editor/panels/index.tsx +3 -0
  98. package/src/editor/types.tsx +38 -0
  99. package/src/editor/ui/Button/Button.tsx +70 -0
  100. package/src/editor/ui/Button/index.tsx +2 -0
  101. package/src/editor/ui/Dropdown/Dropdown.tsx +39 -0
  102. package/src/editor/ui/Dropdown/index.tsx +1 -0
  103. package/src/editor/ui/Icon.tsx +21 -0
  104. package/src/editor/ui/Loader/Loader.tsx +39 -0
  105. package/src/editor/ui/Loader/index.ts +1 -0
  106. package/src/editor/ui/Loader/types.ts +7 -0
  107. package/src/editor/ui/Panel/index.tsx +109 -0
  108. package/src/editor/ui/PopoverMenu.tsx +127 -0
  109. package/src/editor/ui/Spinner/Spinner.tsx +10 -0
  110. package/src/editor/ui/Spinner/index.tsx +1 -0
  111. package/src/editor/ui/Surface.tsx +27 -0
  112. package/src/editor/ui/Textarea/Textarea.tsx +20 -0
  113. package/src/editor/ui/Textarea/index.tsx +1 -0
  114. package/src/editor/ui/Toggle/Toggle.tsx +39 -0
  115. package/src/editor/ui/Toggle/index.tsx +1 -0
  116. package/src/editor/ui/Toolbar.tsx +107 -0
  117. package/src/editor/ui/Tooltip/index.tsx +77 -0
  118. package/src/editor/ui/Tooltip/types.ts +17 -0
  119. package/src/editor/utils/cssVar.ts +14 -0
  120. package/src/editor/utils/getRenderContainer.ts +39 -0
  121. package/src/editor/utils/index.ts +16 -0
  122. package/src/editor/utils/isCustomNodeSelected.ts +47 -0
  123. package/src/editor/utils/isTextSelected.ts +25 -0
  124. package/src/editor/utils/locale.ts +5 -0
  125. package/src/editor/viewer/index.tsx +26 -0
  126. package/src/globals.css +1 -0
  127. package/src/index.ts +7 -0
  128. package/src/locales/en-us.ts +133 -0
  129. package/src/locales/zh-cn.ts +133 -0
  130. package/src/locales/zh-tw.ts +133 -0
@@ -0,0 +1,25 @@
1
+ import { isTextSelection } from "@tiptap/core";
2
+ import type { Editor } from "@tiptap/react";
3
+
4
+ export const isTextSelected = ({ editor }: { editor: Editor }) => {
5
+ const {
6
+ state: {
7
+ doc,
8
+ selection,
9
+ selection: { empty, from, to },
10
+ },
11
+ } = editor;
12
+
13
+ // Sometime check for `empty` is not enough.
14
+ // Doubleclick an empty paragraph returns a node size of 2.
15
+ // So we check also for an empty text size.
16
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(selection);
17
+
18
+ if (empty || isEmptyTextBlock || !editor.isEditable) {
19
+ return false;
20
+ }
21
+
22
+ return true;
23
+ };
24
+
25
+ export default isTextSelected;
@@ -0,0 +1,5 @@
1
+ import i18next from "i18next";
2
+
3
+ export const i18n = (key: string) => {
4
+ return i18next.t(key, { ns: "editor" });
5
+ };
@@ -0,0 +1,26 @@
1
+ import "../container.css";
2
+ import "../editor.css";
3
+ import type { FC } from "react";
4
+ import { EditorContent } from "@tiptap/react";
5
+
6
+ import { useEditor } from "../hooks";
7
+
8
+ export type ContentViewerProps = {
9
+ value?: string;
10
+ onChange?: (value: string) => void;
11
+ };
12
+
13
+ export const ContentViewer: FC<ContentViewerProps> = (props) => {
14
+ const { value, onChange } = props;
15
+ const [editor] = useEditor({
16
+ value,
17
+ editable: false,
18
+ onReadOnlyChange: onChange,
19
+ });
20
+
21
+ return (
22
+ <div className="editor-container">
23
+ <EditorContent className="editor" editor={editor} />
24
+ </div>
25
+ );
26
+ };
@@ -0,0 +1 @@
1
+ @import "@meta-1/design/theme.css";
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export type { EditorEvents } from "@tiptap/core";
2
+
3
+ export type { EditorProps, EditorRef } from "./editor";
4
+ export { Editor } from "./editor";
5
+ export * from "./editor/hooks";
6
+ export type { ContentViewerProps } from "./editor/viewer";
7
+ export { ContentViewer } from "./editor/viewer";
@@ -0,0 +1,133 @@
1
+ export default {
2
+ default: "默认",
3
+ fontSize: {
4
+ mini: "极小",
5
+ small: "小",
6
+ normal: "默认",
7
+ large: "大",
8
+ huge: "超大",
9
+ },
10
+ placeholder: {
11
+ default: "输入 / 快速插入",
12
+ quoteCaption: "请输入引用作者",
13
+ quote: "请输入引用内容",
14
+ },
15
+ dragHandle: {
16
+ actions: {
17
+ clear: "清空格式",
18
+ duplicate: "复制",
19
+ delete: "删除",
20
+ },
21
+ },
22
+ imageBlock: {
23
+ align: {
24
+ left: "左对齐",
25
+ center: "居中",
26
+ right: "右对齐",
27
+ },
28
+ },
29
+ imageUpload: {
30
+ draggedInside: "拖拽图片到这里",
31
+ draggedInsideDefault: "拖动到此处",
32
+ button: "上传图片",
33
+ },
34
+ slashCommand: {
35
+ group: {
36
+ format: "格式",
37
+ insert: "插入",
38
+ },
39
+ heading1: {
40
+ title: "标题一",
41
+ description: "高优先级部分标题",
42
+ },
43
+ heading2: {
44
+ title: "标题二",
45
+ description: "中等优先级部分标题",
46
+ },
47
+ heading3: {
48
+ title: "标题三",
49
+ description: "低优先级部分标题",
50
+ },
51
+ bulletList: {
52
+ title: "无序列表",
53
+ description: "创建一个无序列表",
54
+ },
55
+ numberedList: {
56
+ title: "有序列表",
57
+ description: "创建一个有序列表",
58
+ },
59
+ taskList: {
60
+ title: "任务列表",
61
+ description: "创建一个任务列表",
62
+ },
63
+ blockquote: {
64
+ title: "引用",
65
+ description: "引用内容",
66
+ },
67
+ codeBlock: {
68
+ title: "代码块",
69
+ description: "带语法高亮代码块",
70
+ },
71
+ table: {
72
+ title: "表格",
73
+ description: "创建一个表格",
74
+ },
75
+ image: {
76
+ title: "图片",
77
+ description: "插入图片",
78
+ },
79
+ horizontalRule: {
80
+ title: "分割线",
81
+ description: "插入分割线",
82
+ },
83
+ },
84
+ tableColumnMenu: {
85
+ onAddColumnBefore: "左边插入",
86
+ onAddColumnAfter: "右边插入",
87
+ onDeleteColumn: "删除",
88
+ onAddRowBefore: "上方插入",
89
+ onAddRowAfter: "下方插入",
90
+ onDeleteRow: "删除",
91
+ },
92
+ textMenu: {
93
+ editLink: "设置链接",
94
+ hierarchy: "内容",
95
+ paragraph: "正文",
96
+ heading1: "标题一",
97
+ heading2: "标题二",
98
+ heading3: "标题三",
99
+ lists: "列表",
100
+ bulletList: "无序列表",
101
+ orderedList: "有序列表",
102
+ ListTodo: "任务列表",
103
+ bold: "加粗",
104
+ italic: "斜体",
105
+ underline: "下划线",
106
+ strikethrough: "删除线",
107
+ code: "代码",
108
+ codeBlock: "代码块",
109
+ highlighter: "背景色",
110
+ color: "文字颜色",
111
+ more: "更多设置",
112
+ subscript: "下标",
113
+ superscript: "上标",
114
+ alignLeft: "左对齐",
115
+ alignCenter: "居中对齐",
116
+ alignRight: "右对齐",
117
+ alignJustify: "两端对齐",
118
+ },
119
+ colorPicker: {
120
+ undo: "还原默认颜色",
121
+ },
122
+ panel: {
123
+ linkEditor: {
124
+ input: "请输入链接地址",
125
+ submit: "确认",
126
+ newTab: "新标签页打开",
127
+ },
128
+ linkPreview: {
129
+ edit: "编辑链接",
130
+ delete: "删除链接",
131
+ },
132
+ },
133
+ };
@@ -0,0 +1,133 @@
1
+ export default {
2
+ default: "默认",
3
+ fontSize: {
4
+ mini: "极小",
5
+ small: "小",
6
+ normal: "默认",
7
+ large: "大",
8
+ huge: "超大",
9
+ },
10
+ placeholder: {
11
+ default: "输入 / 快速插入",
12
+ quoteCaption: "请输入引用作者",
13
+ quote: "请输入引用内容",
14
+ },
15
+ dragHandle: {
16
+ actions: {
17
+ clear: "清空格式",
18
+ duplicate: "复制",
19
+ delete: "删除",
20
+ },
21
+ },
22
+ imageBlock: {
23
+ align: {
24
+ left: "左对齐",
25
+ center: "居中",
26
+ right: "右对齐",
27
+ },
28
+ },
29
+ imageUpload: {
30
+ draggedInside: "拖拽图片到这里",
31
+ draggedInsideDefault: "拖动到此处",
32
+ button: "上传图片",
33
+ },
34
+ slashCommand: {
35
+ group: {
36
+ format: "格式",
37
+ insert: "插入",
38
+ },
39
+ heading1: {
40
+ title: "标题一",
41
+ description: "高优先级部分标题",
42
+ },
43
+ heading2: {
44
+ title: "标题二",
45
+ description: "中等优先级部分标题",
46
+ },
47
+ heading3: {
48
+ title: "标题三",
49
+ description: "低优先级部分标题",
50
+ },
51
+ bulletList: {
52
+ title: "无序列表",
53
+ description: "创建一个无序列表",
54
+ },
55
+ numberedList: {
56
+ title: "有序列表",
57
+ description: "创建一个有序列表",
58
+ },
59
+ taskList: {
60
+ title: "任务列表",
61
+ description: "创建一个任务列表",
62
+ },
63
+ blockquote: {
64
+ title: "引用",
65
+ description: "引用内容",
66
+ },
67
+ codeBlock: {
68
+ title: "代码块",
69
+ description: "带语法高亮代码块",
70
+ },
71
+ table: {
72
+ title: "表格",
73
+ description: "创建一个表格",
74
+ },
75
+ image: {
76
+ title: "图片",
77
+ description: "插入图片",
78
+ },
79
+ horizontalRule: {
80
+ title: "分割线",
81
+ description: "插入分割线",
82
+ },
83
+ },
84
+ tableColumnMenu: {
85
+ onAddColumnBefore: "左边插入",
86
+ onAddColumnAfter: "右边插入",
87
+ onDeleteColumn: "删除",
88
+ onAddRowBefore: "上方插入",
89
+ onAddRowAfter: "下方插入",
90
+ onDeleteRow: "删除",
91
+ },
92
+ textMenu: {
93
+ editLink: "设置链接",
94
+ hierarchy: "内容",
95
+ paragraph: "正文",
96
+ heading1: "标题一",
97
+ heading2: "标题二",
98
+ heading3: "标题三",
99
+ lists: "列表",
100
+ bulletList: "无序列表",
101
+ orderedList: "有序列表",
102
+ ListTodo: "任务列表",
103
+ bold: "加粗",
104
+ italic: "斜体",
105
+ underline: "下划线",
106
+ strikethrough: "删除线",
107
+ code: "代码",
108
+ codeBlock: "代码块",
109
+ highlighter: "背景色",
110
+ color: "文字颜色",
111
+ more: "更多设置",
112
+ subscript: "下标",
113
+ superscript: "上标",
114
+ alignLeft: "左对齐",
115
+ alignCenter: "居中对齐",
116
+ alignRight: "右对齐",
117
+ alignJustify: "两端对齐",
118
+ },
119
+ colorPicker: {
120
+ undo: "还原默认颜色",
121
+ },
122
+ panel: {
123
+ linkEditor: {
124
+ input: "请输入链接地址",
125
+ submit: "确认",
126
+ newTab: "新标签页打开",
127
+ },
128
+ linkPreview: {
129
+ edit: "编辑链接",
130
+ delete: "删除链接",
131
+ },
132
+ },
133
+ };
@@ -0,0 +1,133 @@
1
+ export default {
2
+ default: "默认",
3
+ fontSize: {
4
+ mini: "极小",
5
+ small: "小",
6
+ normal: "默认",
7
+ large: "大",
8
+ huge: "超大",
9
+ },
10
+ placeholder: {
11
+ default: "输入 / 快速插入",
12
+ quoteCaption: "请输入引用作者",
13
+ quote: "请输入引用内容",
14
+ },
15
+ dragHandle: {
16
+ actions: {
17
+ clear: "清空格式",
18
+ duplicate: "复制",
19
+ delete: "删除",
20
+ },
21
+ },
22
+ imageBlock: {
23
+ align: {
24
+ left: "左对齐",
25
+ center: "居中",
26
+ right: "右对齐",
27
+ },
28
+ },
29
+ imageUpload: {
30
+ draggedInside: "拖拽图片到这里",
31
+ draggedInsideDefault: "拖动到此处",
32
+ button: "上传图片",
33
+ },
34
+ slashCommand: {
35
+ group: {
36
+ format: "格式",
37
+ insert: "插入",
38
+ },
39
+ heading1: {
40
+ title: "标题一",
41
+ description: "高优先级部分标题",
42
+ },
43
+ heading2: {
44
+ title: "标题二",
45
+ description: "中等优先级部分标题",
46
+ },
47
+ heading3: {
48
+ title: "标题三",
49
+ description: "低优先级部分标题",
50
+ },
51
+ bulletList: {
52
+ title: "无序列表",
53
+ description: "创建一个无序列表",
54
+ },
55
+ numberedList: {
56
+ title: "有序列表",
57
+ description: "创建一个有序列表",
58
+ },
59
+ taskList: {
60
+ title: "任务列表",
61
+ description: "创建一个任务列表",
62
+ },
63
+ blockquote: {
64
+ title: "引用",
65
+ description: "引用内容",
66
+ },
67
+ codeBlock: {
68
+ title: "代码块",
69
+ description: "带语法高亮代码块",
70
+ },
71
+ table: {
72
+ title: "表格",
73
+ description: "创建一个表格",
74
+ },
75
+ image: {
76
+ title: "图片",
77
+ description: "插入图片",
78
+ },
79
+ horizontalRule: {
80
+ title: "分割线",
81
+ description: "插入分割线",
82
+ },
83
+ },
84
+ tableColumnMenu: {
85
+ onAddColumnBefore: "左边插入",
86
+ onAddColumnAfter: "右边插入",
87
+ onDeleteColumn: "删除",
88
+ onAddRowBefore: "上方插入",
89
+ onAddRowAfter: "下方插入",
90
+ onDeleteRow: "删除",
91
+ },
92
+ textMenu: {
93
+ editLink: "设置链接",
94
+ hierarchy: "内容",
95
+ paragraph: "正文",
96
+ heading1: "标题一",
97
+ heading2: "标题二",
98
+ heading3: "标题三",
99
+ lists: "列表",
100
+ bulletList: "无序列表",
101
+ orderedList: "有序列表",
102
+ ListTodo: "任务列表",
103
+ bold: "加粗",
104
+ italic: "斜体",
105
+ underline: "下划线",
106
+ strikethrough: "删除线",
107
+ code: "代码",
108
+ codeBlock: "代码块",
109
+ highlighter: "背景色",
110
+ color: "文字颜色",
111
+ more: "更多设置",
112
+ subscript: "下标",
113
+ superscript: "上标",
114
+ alignLeft: "左对齐",
115
+ alignCenter: "居中对齐",
116
+ alignRight: "右对齐",
117
+ alignJustify: "两端对齐",
118
+ },
119
+ colorPicker: {
120
+ undo: "还原默认颜色",
121
+ },
122
+ panel: {
123
+ linkEditor: {
124
+ input: "请输入链接地址",
125
+ submit: "确认",
126
+ newTab: "新标签页打开",
127
+ },
128
+ linkPreview: {
129
+ edit: "编辑链接",
130
+ delete: "删除链接",
131
+ },
132
+ },
133
+ };