@firecms/core 3.1.0-canary.24c8270 → 3.1.0-canary.75005e4

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 (180) hide show
  1. package/dist/components/EntityCollectionView/CollectionDataErrorBanner.d.ts +4 -0
  2. package/dist/components/ErrorBoundary.d.ts +3 -1
  3. package/dist/components/HomePage/DefaultHomePage.d.ts +0 -1
  4. package/dist/components/LanguageToggle.d.ts +1 -0
  5. package/dist/components/UnsavedChangesDialog.d.ts +1 -0
  6. package/dist/components/index.d.ts +1 -0
  7. package/dist/core/DrawerNavigationGroup.d.ts +2 -2
  8. package/dist/editor/components/SlashCommandMenu.d.ts +6 -0
  9. package/dist/editor/components/editor-bubble-item.d.ts +8 -0
  10. package/dist/editor/components/editor-bubble.d.ts +8 -0
  11. package/dist/editor/components/index.d.ts +14 -0
  12. package/dist/editor/editor.d.ts +30 -0
  13. package/dist/editor/extensions/HighlightDecorationExtension.d.ts +24 -0
  14. package/dist/editor/extensions/Image/index.d.ts +6 -0
  15. package/dist/editor/extensions/Image.d.ts +6 -0
  16. package/dist/editor/extensions/TextLoadingDecorationExtension.d.ts +16 -0
  17. package/dist/editor/extensions/clipboard.d.ts +7 -0
  18. package/dist/editor/extensions/custom-keymap.d.ts +1 -0
  19. package/dist/editor/extensions/drag-and-drop.d.ts +9 -0
  20. package/dist/editor/hooks/useProseMirror.d.ts +14 -0
  21. package/dist/editor/hooks/useProseMirrorContext.d.ts +9 -0
  22. package/dist/editor/index.d.ts +2 -0
  23. package/dist/editor/markdown.d.ts +5 -0
  24. package/dist/editor/nodeViews/ImageComponent.d.ts +3 -0
  25. package/dist/editor/nodeViews/ReactNodeView.d.ts +29 -0
  26. package/dist/editor/nodeViews/TaskItemComponent.d.ts +3 -0
  27. package/dist/editor/nodeViews/index.d.ts +6 -0
  28. package/dist/editor/plugins/index.d.ts +2 -0
  29. package/dist/editor/plugins/inputrules.d.ts +6 -0
  30. package/dist/editor/plugins/placeholderPlugin.d.ts +3 -0
  31. package/dist/editor/plugins/slashCommandPlugin.d.ts +11 -0
  32. package/dist/editor/schema.d.ts +2 -0
  33. package/dist/editor/selectors/ai-selector.d.ts +0 -0
  34. package/dist/editor/selectors/color-selector.d.ts +10 -0
  35. package/dist/editor/selectors/link-selector.d.ts +8 -0
  36. package/dist/editor/selectors/node-selector.d.ts +15 -0
  37. package/dist/editor/selectors/text-buttons.d.ts +1 -0
  38. package/dist/editor/types.d.ts +5 -0
  39. package/dist/editor/useProseMirror.d.ts +16 -0
  40. package/dist/editor/utils/prosemirror-utils.d.ts +6 -0
  41. package/dist/editor/utils/remove_classes.d.ts +1 -0
  42. package/dist/editor/utils/useDebouncedCallback.d.ts +1 -0
  43. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
  44. package/dist/hooks/index.d.ts +1 -0
  45. package/dist/hooks/useBuildNavigationController.d.ts +0 -1
  46. package/dist/hooks/useCollapsedGroups.d.ts +3 -3
  47. package/dist/hooks/useTranslation.d.ts +17 -0
  48. package/dist/i18n/FireCMSi18nProvider.d.ts +33 -0
  49. package/dist/index.d.ts +4 -0
  50. package/dist/index.es.js +11293 -2142
  51. package/dist/index.es.js.map +1 -1
  52. package/dist/index.umd.js +11274 -2142
  53. package/dist/index.umd.js.map +1 -1
  54. package/dist/locales/de.d.ts +2 -0
  55. package/dist/locales/en.d.ts +10 -0
  56. package/dist/locales/es.d.ts +10 -0
  57. package/dist/locales/fr.d.ts +2 -0
  58. package/dist/locales/hi.d.ts +2 -0
  59. package/dist/locales/it.d.ts +2 -0
  60. package/dist/locales/pt.d.ts +7 -0
  61. package/dist/types/customization_controller.d.ts +2 -1
  62. package/dist/types/firecms.d.ts +2 -1
  63. package/dist/types/index.d.ts +1 -0
  64. package/dist/types/navigation.d.ts +2 -2
  65. package/dist/types/plugins.d.ts +7 -0
  66. package/dist/types/translations.d.ts +646 -0
  67. package/package.json +43 -9
  68. package/src/app/Scaffold.tsx +7 -5
  69. package/src/components/AIIcon.tsx +3 -1
  70. package/src/components/ArrayContainer.tsx +6 -4
  71. package/src/components/ClearFilterSortButton.tsx +6 -3
  72. package/src/components/ConfirmationDialog.tsx +4 -2
  73. package/src/components/DeleteEntityDialog.tsx +10 -7
  74. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +6 -3
  75. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +3 -1
  76. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +3 -2
  77. package/src/components/EntityCollectionView/BoardSortableList.tsx +3 -1
  78. package/src/components/EntityCollectionView/CollectionDataErrorBanner.tsx +43 -0
  79. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +16 -43
  80. package/src/components/EntityCollectionView/EntityCollectionCardView.tsx +17 -25
  81. package/src/components/EntityCollectionView/EntityCollectionView.tsx +26 -18
  82. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +4 -3
  83. package/src/components/EntityCollectionView/EntityCollectionViewStartActions.tsx +4 -2
  84. package/src/components/EntityCollectionView/FiltersDialog.tsx +8 -5
  85. package/src/components/EntityCollectionView/ViewModeToggle.tsx +11 -8
  86. package/src/components/EntityView.tsx +3 -2
  87. package/src/components/ErrorBoundary.tsx +27 -15
  88. package/src/components/HomePage/DefaultHomePage.tsx +19 -13
  89. package/src/components/HomePage/HomePageDnD.tsx +3 -1
  90. package/src/components/HomePage/NavigationGroup.tsx +3 -1
  91. package/src/components/HomePage/RenameGroupDialog.tsx +15 -13
  92. package/src/components/LanguageToggle.tsx +66 -0
  93. package/src/components/NotFoundPage.tsx +5 -3
  94. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +9 -7
  95. package/src/components/ReferenceWidget.tsx +3 -2
  96. package/src/components/SearchIconsView.tsx +3 -1
  97. package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +11 -0
  98. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +15 -2
  99. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +11 -0
  100. package/src/components/UnsavedChangesDialog.tsx +6 -4
  101. package/src/components/VirtualTable/VirtualTable.performance.test.tsx +1 -0
  102. package/src/components/VirtualTable/VirtualTableHeader.tsx +12 -10
  103. package/src/components/common/default_entity_actions.tsx +4 -0
  104. package/src/components/common/useDataSourceTableController.tsx +5 -14
  105. package/src/components/index.tsx +1 -0
  106. package/src/core/DefaultAppBar.tsx +14 -10
  107. package/src/core/DefaultDrawer.tsx +8 -2
  108. package/src/core/DrawerNavigationGroup.tsx +5 -3
  109. package/src/core/EntityEditView.tsx +3 -2
  110. package/src/core/EntityEditViewFormActions.tsx +24 -17
  111. package/src/core/EntitySidePanel.tsx +4 -3
  112. package/src/core/FireCMS.tsx +33 -6
  113. package/src/editor/components/SlashCommandMenu.tsx +348 -0
  114. package/src/editor/components/editor-bubble-item.tsx +32 -0
  115. package/src/editor/components/editor-bubble.tsx +118 -0
  116. package/src/editor/components/index.ts +12 -0
  117. package/src/editor/editor.tsx +307 -0
  118. package/src/editor/extensions/HighlightDecorationExtension.ts +114 -0
  119. package/src/editor/extensions/Image/index.ts +133 -0
  120. package/src/editor/extensions/Image.ts +144 -0
  121. package/src/editor/extensions/TextLoadingDecorationExtension.tsx +107 -0
  122. package/src/editor/extensions/clipboard.ts +72 -0
  123. package/src/editor/extensions/custom-keymap.ts +24 -0
  124. package/src/editor/extensions/drag-and-drop.tsx +472 -0
  125. package/src/editor/hooks/useProseMirror.ts +115 -0
  126. package/src/editor/hooks/useProseMirrorContext.ts +15 -0
  127. package/src/editor/index.ts +2 -0
  128. package/src/editor/markdown.ts +110 -0
  129. package/src/editor/nodeViews/ImageComponent.tsx +20 -0
  130. package/src/editor/nodeViews/ReactNodeView.tsx +89 -0
  131. package/src/editor/nodeViews/TaskItemComponent.tsx +29 -0
  132. package/src/editor/nodeViews/index.ts +35 -0
  133. package/src/editor/plugins/index.ts +55 -0
  134. package/src/editor/plugins/inputrules.ts +82 -0
  135. package/src/editor/plugins/placeholderPlugin.ts +55 -0
  136. package/src/editor/plugins/slashCommandPlugin.ts +49 -0
  137. package/src/editor/schema.ts +228 -0
  138. package/src/editor/selectors/ai-selector.tsx +111 -0
  139. package/src/editor/selectors/color-selector.tsx +200 -0
  140. package/src/editor/selectors/link-selector.tsx +118 -0
  141. package/src/editor/selectors/node-selector.tsx +157 -0
  142. package/src/editor/selectors/text-buttons.tsx +86 -0
  143. package/src/editor/types.ts +6 -0
  144. package/src/editor/useProseMirror.ts +126 -0
  145. package/src/editor/utils/prosemirror-utils.ts +78 -0
  146. package/src/editor/utils/remove_classes.ts +17 -0
  147. package/src/editor/utils/useDebouncedCallback.ts +25 -0
  148. package/src/form/EntityForm.tsx +7 -3
  149. package/src/form/EntityFormActions.tsx +19 -12
  150. package/src/form/PropertyFieldBinding.tsx +3 -2
  151. package/src/form/components/LocalChangesMenu.tsx +13 -13
  152. package/src/form/components/StorageItemPreview.tsx +3 -2
  153. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +4 -4
  154. package/src/form/field_bindings/BlockFieldBinding.tsx +5 -2
  155. package/src/form/field_bindings/KeyValueFieldBinding.tsx +23 -18
  156. package/src/form/field_bindings/MapFieldBinding.tsx +4 -3
  157. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +3 -3
  158. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -1
  159. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +4 -2
  160. package/src/hooks/index.tsx +1 -0
  161. package/src/hooks/useBuildNavigationController.tsx +20 -13
  162. package/src/hooks/useCollapsedGroups.ts +7 -6
  163. package/src/hooks/useTranslation.ts +31 -0
  164. package/src/i18n/FireCMSi18nProvider.tsx +160 -0
  165. package/src/index.ts +4 -0
  166. package/src/locales/de.ts +691 -0
  167. package/src/locales/en.ts +703 -0
  168. package/src/locales/es.ts +703 -0
  169. package/src/locales/fr.ts +691 -0
  170. package/src/locales/hi.ts +691 -0
  171. package/src/locales/it.ts +691 -0
  172. package/src/locales/pt.ts +700 -0
  173. package/src/preview/components/UrlComponentPreview.tsx +4 -2
  174. package/src/preview/components/UserPreview.tsx +3 -1
  175. package/src/types/customization_controller.tsx +2 -1
  176. package/src/types/firecms.tsx +2 -1
  177. package/src/types/index.ts +1 -0
  178. package/src/types/navigation.ts +2 -2
  179. package/src/types/plugins.tsx +8 -0
  180. package/src/types/translations.ts +725 -0
@@ -0,0 +1,228 @@
1
+ import { Schema, NodeSpec, MarkSpec } from "prosemirror-model";
2
+
3
+ const marks: { [key: string]: MarkSpec } = {
4
+ link: {
5
+ attrs: {
6
+ href: {},
7
+ title: { default: null },
8
+ target: { default: "_blank" },
9
+ },
10
+ inclusive: false,
11
+ parseDOM: [
12
+ {
13
+ tag: "a[href]",
14
+ getAttrs(dom: HTMLElement | string) {
15
+ if (typeof dom === "string") return false;
16
+ return {
17
+ href: dom.getAttribute("href"),
18
+ title: dom.getAttribute("title"),
19
+ target: dom.getAttribute("target") || "_blank",
20
+ };
21
+ },
22
+ },
23
+ ],
24
+ toDOM(node) {
25
+ let { href, title, target } = node.attrs;
26
+ return ["a", { href, title, target, class: "text-surface-700 dark:text-surface-accent-200 underline underline-offset-[3px] hover:text-primary transition-colors cursor-pointer" }, 0];
27
+ },
28
+ },
29
+ bold: {
30
+ parseDOM: [
31
+ { tag: "strong" },
32
+ { tag: "b", getAttrs: (node: HTMLElement | string) => typeof node !== "string" && node.style.fontWeight !== "normal" && null },
33
+ { style: "font-weight=400", clearMark: m => m.type.name === "bold" },
34
+ { style: "font-weight", getAttrs: (value: string | HTMLElement) => typeof value === "string" && /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null },
35
+ ],
36
+ toDOM() { return ["strong", 0]; },
37
+ },
38
+ italic: {
39
+ parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style=italic" }],
40
+ toDOM() { return ["em", 0]; },
41
+ },
42
+ strike: {
43
+ parseDOM: [{ tag: "s" }, { tag: "del" }, { tag: "strike" }, { style: "text-decoration=line-through" }],
44
+ toDOM() { return ["s", 0]; },
45
+ },
46
+ underline: {
47
+ parseDOM: [{ tag: "u" }, { style: "text-decoration=underline" }],
48
+ toDOM() { return ["u", 0]; },
49
+ },
50
+ code: {
51
+ parseDOM: [{ tag: "code" }],
52
+ toDOM() { return ["code", { class: "rounded-md bg-surface-accent-50 dark:bg-surface-700 px-1.5 py-1 font-mono font-medium", spellcheck: "false" }, 0]; },
53
+ },
54
+ textStyle: {
55
+ attrs: { color: { default: null } },
56
+ parseDOM: [
57
+ {
58
+ style: "color",
59
+ getAttrs: (value: string | HTMLElement) => {
60
+ if (typeof value === "string") return { color: value };
61
+ return false;
62
+ },
63
+ },
64
+ ],
65
+ toDOM(mark) {
66
+ let style = "";
67
+ if (mark.attrs.color) style += `color: ${mark.attrs.color};`;
68
+ return ["span", { style }, 0];
69
+ },
70
+ },
71
+ highlight: {
72
+ attrs: { color: { default: null } },
73
+ parseDOM: [
74
+ {
75
+ tag: "mark",
76
+ getAttrs: (dom: HTMLElement | string) => {
77
+ if (typeof dom === "string") return false;
78
+ return { color: dom.style.backgroundColor || dom.getAttribute("data-color") };
79
+ }
80
+ },
81
+ ],
82
+ toDOM(mark) {
83
+ return ["mark", mark.attrs.color ? { style: `background-color: ${mark.attrs.color}; color: inherit;`, "data-color": mark.attrs.color } : {}, 0];
84
+ },
85
+ },
86
+ };
87
+
88
+ const nodes: { [key: string]: NodeSpec } = {
89
+ doc: {
90
+ content: "block+",
91
+ },
92
+ paragraph: {
93
+ content: "inline*",
94
+ group: "block",
95
+ parseDOM: [{ tag: "p" }],
96
+ toDOM() { return ["p", 0]; },
97
+ },
98
+ text: {
99
+ group: "inline",
100
+ },
101
+ blockquote: {
102
+ content: "block+",
103
+ group: "block",
104
+ defining: true,
105
+ parseDOM: [{ tag: "blockquote" }],
106
+ toDOM() { return ["blockquote", { class: "border-l-4 border-primary" }, 0]; },
107
+ },
108
+ heading: {
109
+ attrs: { level: { default: 1 } },
110
+ content: "inline*",
111
+ group: "block",
112
+ defining: true,
113
+ parseDOM: [
114
+ { tag: "h1", attrs: { level: 1 } },
115
+ { tag: "h2", attrs: { level: 2 } },
116
+ { tag: "h3", attrs: { level: 3 } },
117
+ { tag: "h4", attrs: { level: 4 } },
118
+ { tag: "h5", attrs: { level: 5 } },
119
+ { tag: "h6", attrs: { level: 6 } },
120
+ ],
121
+ toDOM(node) { return ["h" + node.attrs.level, 0]; },
122
+ },
123
+ horizontal_rule: {
124
+ group: "block",
125
+ parseDOM: [{ tag: "hr" }],
126
+ toDOM() { return ["hr", { class: "mt-4 mb-6 border-t border-solid border-gray-200 dark:border-gray-800" }]; },
127
+ },
128
+ code_block: {
129
+ content: "text*",
130
+ marks: "",
131
+ group: "block",
132
+ code: true,
133
+ defining: true,
134
+ attrs: { language: { default: null } },
135
+ parseDOM: [
136
+ { tag: "pre", preserveWhitespace: "full" },
137
+ ],
138
+ toDOM(node) { return ["pre", { class: "rounded bg-blue-50 dark:bg-surface-700 border border-solid border-gray-200 dark:border-gray-800 p-5 font-mono font-medium" }, ["code", 0]]; },
139
+ },
140
+ image: {
141
+ inline: false,
142
+ group: "block",
143
+ attrs: {
144
+ src: {},
145
+ alt: { default: null },
146
+ title: { default: null },
147
+ },
148
+ draggable: true,
149
+ parseDOM: [
150
+ {
151
+ tag: "img[src]",
152
+ getAttrs(dom: HTMLElement | string) {
153
+ if (typeof dom === "string") return false;
154
+ return {
155
+ src: dom.getAttribute("src"),
156
+ title: dom.getAttribute("title"),
157
+ alt: dom.getAttribute("alt"),
158
+ };
159
+ },
160
+ },
161
+ ],
162
+ toDOM(node) {
163
+ let { src, alt, title } = node.attrs;
164
+ return ["img", { src, alt, title, class: "rounded-lg max-w-full !m-0" }];
165
+ },
166
+ },
167
+ bullet_list: {
168
+ content: "list_item+",
169
+ group: "block",
170
+ parseDOM: [{ tag: "ul" }],
171
+ toDOM() { return ["ul", { class: "list-disc list-outside leading-3 -mt-2" }, 0]; },
172
+ },
173
+ ordered_list: {
174
+ content: "list_item+",
175
+ group: "block",
176
+ attrs: { order: { default: 1 } },
177
+ parseDOM: [
178
+ {
179
+ tag: "ol",
180
+ getAttrs(dom: HTMLElement | string) {
181
+ if (typeof dom === "string") return false;
182
+ return { order: dom.hasAttribute("start") ? +dom.getAttribute("start")! : 1 };
183
+ },
184
+ },
185
+ ],
186
+ toDOM(node) {
187
+ return node.attrs.order === 1 ? ["ol", { class: "list-decimal list-outside leading-3 -mt-2" }, 0] : ["ol", { start: node.attrs.order, class: "list-decimal list-outside leading-3 -mt-2" }, 0];
188
+ },
189
+ },
190
+ list_item: {
191
+ content: "paragraph block*",
192
+ parseDOM: [{ tag: "li" }],
193
+ toDOM() { return ["li", { class: "leading-normal -mb-2" }, 0]; },
194
+ defining: true,
195
+ },
196
+ task_list: {
197
+ group: "block",
198
+ content: "task_item+",
199
+ parseDOM: [{ tag: 'ul[data-type="taskList"]' }],
200
+ toDOM() { return ["ul", { "data-type": "taskList", class: "not-prose" }, 0]; },
201
+ },
202
+ task_item: {
203
+ content: "paragraph block*",
204
+ defining: true,
205
+ attrs: { checked: { default: false } },
206
+ parseDOM: [
207
+ {
208
+ tag: 'li[data-type="taskItem"]',
209
+ getAttrs(dom: HTMLElement | string) {
210
+ if (typeof dom === "string") return false;
211
+ return { checked: dom.getAttribute("data-checked") === "true" };
212
+ },
213
+ },
214
+ ],
215
+ toDOM(node) {
216
+ return ["li", { "data-type": "taskItem", "data-checked": node.attrs.checked ? "true" : "false", class: "flex items-start my-4" }, 0];
217
+ },
218
+ },
219
+ hard_break: {
220
+ inline: true,
221
+ group: "inline",
222
+ selectable: false,
223
+ parseDOM: [{ tag: "br" }],
224
+ toDOM() { return ["br"]; },
225
+ },
226
+ };
227
+
228
+ export const schema = new Schema({ nodes, marks });
@@ -0,0 +1,111 @@
1
+ // "use client";
2
+ //
3
+ // import {
4
+ // Command,
5
+ // CommandGroup,
6
+ // CommandInput,
7
+ // CommandItem,
8
+ // } from "@/components/tailwind/ui/command";
9
+ //
10
+ // import { useCompletion } from "ai/react";
11
+ // import { toast } from "sonner";
12
+ // import { useEditor } from "novel";
13
+ // import { getPrevText } from "./extensions";
14
+ // import { useState } from "react";
15
+ //
16
+ // const options = [
17
+ // {
18
+ // value: "improve",
19
+ // label: "Improve writing",
20
+ // },
21
+ // {
22
+ // value: "continue",
23
+ // label: "Continue writing",
24
+ // },
25
+ // {
26
+ // value: "fix",
27
+ // label: "Fix grammar",
28
+ // },
29
+ // {
30
+ // value: "sorter",
31
+ // label: "Make shorter",
32
+ // },
33
+ // {
34
+ // value: "longer",
35
+ // label: "Make longer",
36
+ // },
37
+ // ];
38
+ //
39
+ // //TODO: I think it makes more sense to create a custom Tiptap extension for this functionality https://tiptap.dev/docs/editor/ai/introduction
40
+ //
41
+ // interface AISelectorProps {
42
+ // open: boolean;
43
+ // onOpenChange: (open: boolean) => void;
44
+ // }
45
+ //
46
+ // export function AISelector({ open, onOpenChange }: AISelectorProps) {
47
+ // const { editor } = useEditor();
48
+ // const [extraPrompt, setExtraPrompt] = useState("");
49
+ //
50
+ // const { completion, complete } = useCompletion({
51
+ // // id: "novel",
52
+ // api: "/api/generate",
53
+ // onResponse: (response) => {
54
+ // if (response.status === 429) {
55
+ // toast.error("You have reached your request limit for the day.");
56
+ // return;
57
+ // }
58
+ // },
59
+ //
60
+ // onError: (e) => {
61
+ // toast.error(e.message);
62
+ // },
63
+ // });
64
+ //
65
+ // return (
66
+ // <div
67
+ // className="w-full"
68
+ // onBlur={() => {
69
+ // editor.chain().unsetHighlight().run();
70
+ // }}
71
+ // >
72
+ // <Command>
73
+ // {completion && (
74
+ // <p className="w-full whitespace-pre-wrap p-2 px-4 text-sm">
75
+ // {completion}
76
+ // </p>
77
+ // )}
78
+ //
79
+ // <CommandInput
80
+ // onFocus={() => {
81
+ // editor.chain().setHighlight({ color: "#c1ecf970" }).run();
82
+ // }}
83
+ // value={extraPrompt}
84
+ // onValueChange={setExtraPrompt}
85
+ // autoFocus
86
+ // placeholder="Ask AI to edit or generate..."
87
+ // className="w-[400px]"
88
+ // />
89
+ // <CommandGroup>
90
+ // {options.map((option) => (
91
+ // <CommandItem
92
+ // className="px-4"
93
+ // key={option.value}
94
+ // value={option.value}
95
+ // onSelect={(option) => {
96
+ // if (option === "continue") {
97
+ // getPrevText(editor, {
98
+ // chars: 5000,
99
+ // });
100
+ // complete(editor.getText());
101
+ // }
102
+ // }}
103
+ // >
104
+ // {option.label}
105
+ // </CommandItem>
106
+ // ))}
107
+ // </CommandGroup>
108
+ // </Command>
109
+ // </div>
110
+ // );
111
+ // }
@@ -0,0 +1,200 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import { EditorBubbleItem } from "../components";
3
+ import { Button, CheckIcon, KeyboardArrowDownIcon, Popover } from "@firecms/ui";
4
+ import { useProseMirrorContext } from "../hooks/useProseMirrorContext";
5
+ import { isMarkActive, getMarkAttributes, setMark, unsetMark } from "../utils/prosemirror-utils";
6
+ import { schema } from "../schema";
7
+
8
+ export interface BubbleColorMenuItem {
9
+ name: string;
10
+ color: string;
11
+ }
12
+
13
+ const TEXT_COLORS: BubbleColorMenuItem[] = [
14
+ {
15
+ name: "Default",
16
+ color: "black",
17
+ },
18
+ {
19
+ name: "Purple",
20
+ color: "#9333EA",
21
+ },
22
+ {
23
+ name: "Red",
24
+ color: "#E00000",
25
+ },
26
+ {
27
+ name: "Yellow",
28
+ color: "#EAB308",
29
+ },
30
+ {
31
+ name: "Blue",
32
+ color: "#2563EB",
33
+ },
34
+ {
35
+ name: "Green",
36
+ color: "#008A00",
37
+ },
38
+ {
39
+ name: "Orange",
40
+ color: "#FFA500",
41
+ },
42
+ {
43
+ name: "Pink",
44
+ color: "#BA4081",
45
+ },
46
+ {
47
+ name: "Gray",
48
+ color: "#A8A29E",
49
+ },
50
+ ];
51
+
52
+ const HIGHLIGHT_COLORS: BubbleColorMenuItem[] = [
53
+ {
54
+ name: "Default",
55
+ color: "inherit",
56
+ },
57
+ {
58
+ name: "Purple",
59
+ color: "#9333EA",
60
+ },
61
+ {
62
+ name: "Red",
63
+ color: "#E00000",
64
+ },
65
+ {
66
+ name: "Yellow",
67
+ color: "#EAB308",
68
+ },
69
+ {
70
+ name: "Blue",
71
+ color: "#2563EB",
72
+ },
73
+ {
74
+ name: "Green",
75
+ color: "#008A00",
76
+ },
77
+ {
78
+ name: "Orange",
79
+ color: "#FFA500",
80
+ },
81
+ {
82
+ name: "Pink",
83
+ color: "#BA4081",
84
+ },
85
+ {
86
+ name: "Gray",
87
+ color: "#A8A29E",
88
+ },
89
+ ];
90
+
91
+ interface ColorSelectorProps {
92
+ open: boolean;
93
+ onOpenChange: (open: boolean) => void;
94
+ }
95
+
96
+ export const ColorSelector = ({
97
+ open,
98
+ onOpenChange
99
+ }: ColorSelectorProps) => {
100
+
101
+ const { state, view } = useProseMirrorContext();
102
+
103
+ if (!state || !view) return null;
104
+
105
+ const currentTextColor = getMarkAttributes(state, schema.marks.textStyle).color;
106
+ const currentHighlightColor = getMarkAttributes(state, schema.marks.highlight).color;
107
+
108
+ const activeColorItem = TEXT_COLORS.find(({ color }) => color === currentTextColor);
109
+ const activeHighlightItem = HIGHLIGHT_COLORS.find(({ color }) => color === currentHighlightColor);
110
+
111
+ return (
112
+ <Popover
113
+ sideOffset={5}
114
+ align={"start"}
115
+ className="my-1 flex max-h-80 w-48 flex-col overflow-hidden overflow-y-auto rounded border p-1 shadow"
116
+ trigger={
117
+ <Button className="gap-2 rounded-none" variant="text" color={"text"}>
118
+ <span
119
+ className="rounded px-1"
120
+ style={{
121
+ color: activeColorItem?.color,
122
+ backgroundColor: activeHighlightItem?.color,
123
+ }}
124
+ >
125
+ A
126
+ </span>
127
+ <KeyboardArrowDownIcon size={"small"} />
128
+ </Button>}
129
+ modal={true} open={open} onOpenChange={onOpenChange}>
130
+
131
+
132
+ <div className="flex flex-col">
133
+ <div className="my-1 px-2 text-sm font-semibold text-surface-400 dark:text-surface-400">
134
+ Color
135
+ </div>
136
+ {TEXT_COLORS.map(({
137
+ name,
138
+ color
139
+ }, index) => (
140
+ <EditorBubbleItem
141
+ key={index}
142
+ onSelect={() => {
143
+ unsetMark(schema.marks.textStyle)(view.state, view.dispatch);
144
+ if (name !== "Default") {
145
+ setMark(schema.marks.textStyle, { color })(view.state, view.dispatch);
146
+ }
147
+ view.focus();
148
+ }}
149
+ className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-surface-100 hover:dark:bg-surface-700"
150
+ >
151
+ <div className="flex items-center gap-2">
152
+ <div
153
+ className="rounded border px-2 py-px font-medium"
154
+ style={{ color }}
155
+ >
156
+ A
157
+ </div>
158
+ <span>{name}</span>
159
+ </div>
160
+ </EditorBubbleItem>
161
+ ))}
162
+ </div>
163
+ <div>
164
+ <div className="my-1 px-2 text-sm font-semibold text-surface-400 dark:text-surface-400">
165
+ Background
166
+ </div>
167
+ {HIGHLIGHT_COLORS.map(({
168
+ name,
169
+ color
170
+ }, index) => (
171
+ <EditorBubbleItem
172
+ key={index}
173
+ onSelect={() => {
174
+ unsetMark(schema.marks.highlight)(view.state, view.dispatch);
175
+ if (name !== "Default") {
176
+ setMark(schema.marks.highlight, { color })(view.state, view.dispatch);
177
+ }
178
+ view.focus();
179
+ }}
180
+ className="flex cursor-pointer items-center justify-between px-2 py-1 text-sm hover:bg-surface-100 hover:dark:bg-surface-700"
181
+ >
182
+ <div className="flex items-center gap-2">
183
+ <div
184
+ className="rounded border px-2 py-px font-medium"
185
+ style={{ backgroundColor: color }}
186
+ >
187
+ A
188
+ </div>
189
+ <span>{name}</span>
190
+ </div>
191
+ {currentHighlightColor === color && (
192
+ <CheckIcon className="h-4 w-4" />
193
+ )}
194
+ </EditorBubbleItem>
195
+ ))}
196
+ </div>
197
+
198
+ </Popover>
199
+ );
200
+ };
@@ -0,0 +1,118 @@
1
+ import { useEffect, useRef, } from "react";
2
+ import { Button, CheckIcon, cls, DeleteIcon, focusedDisabled, Popover } from "@firecms/ui";
3
+ import { useTranslation } from "../../hooks/useTranslation";
4
+ import { useProseMirrorContext } from "../hooks/useProseMirrorContext";
5
+ import { getMarkAttributes, isMarkActive, setMark, unsetMark } from "../utils/prosemirror-utils";
6
+ import { schema } from "../schema";
7
+
8
+ export function isValidUrl(url: string) {
9
+ try {
10
+ new URL(url);
11
+ return true;
12
+ } catch (e) {
13
+ return false;
14
+ }
15
+ }
16
+
17
+ export function getUrlFromString(str: string) {
18
+ if (isValidUrl(str)) return str;
19
+ try {
20
+ if (str.includes(".") && !str.includes(" ")) {
21
+ return new URL(`https://${str}`).toString();
22
+ }
23
+ return null;
24
+ } catch (e) {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ interface LinkSelectorProps {
30
+ open: boolean;
31
+ onOpenChange: (open: boolean) => void;
32
+ }
33
+
34
+ export const LinkSelector = ({
35
+ open,
36
+ onOpenChange
37
+ }: LinkSelectorProps) => {
38
+ const inputRef = useRef<HTMLInputElement>(null);
39
+ const { state, view } = useProseMirrorContext();
40
+ const { t } = useTranslation();
41
+
42
+ // Autofocus on input by default
43
+ useEffect(() => {
44
+ if (open && inputRef.current) {
45
+ inputRef.current.focus();
46
+ }
47
+ }, [open]);
48
+
49
+ if (!state || !view) return null;
50
+
51
+ const handleSubmit = (e: any) => {
52
+ e.preventDefault();
53
+ const value = inputRef.current?.value;
54
+ if (!value) return;
55
+ const url = getUrlFromString(value);
56
+ if (url) {
57
+ setMark(schema.marks.link, { href: url })(view.state, view.dispatch);
58
+ view.focus();
59
+ onOpenChange(false);
60
+ }
61
+ };
62
+
63
+ const handleRemoveLink = () => {
64
+ unsetMark(schema.marks.link)(view.state, view.dispatch);
65
+ view.focus();
66
+ onOpenChange(false);
67
+ };
68
+
69
+ const isActive = isMarkActive(state, schema.marks.link);
70
+ const href = getMarkAttributes(state, schema.marks.link).href || "";
71
+
72
+ return (
73
+ <Popover modal={true}
74
+ open={open}
75
+ onOpenChange={onOpenChange}
76
+ trigger={<Button variant="text"
77
+ type="button"
78
+ className="gap-2 rounded-none"
79
+ color={"text"}>
80
+ <p className={cls("underline decoration-stone-400 underline-offset-4", {
81
+ "text-blue-500": isActive,
82
+ })}>
83
+ {t("editor_link")}
84
+ </p>
85
+ </Button>}>
86
+ <form
87
+ onSubmit={handleSubmit}
88
+ className="flex p-1 gap-1"
89
+ >
90
+ <input
91
+ ref={inputRef}
92
+ autoFocus={open}
93
+ placeholder={t("editor_paste_or_type_link")}
94
+ defaultValue={href}
95
+ className={cls("text-surface-900 dark:text-white flex-grow bg-transparent p-1 text-sm outline-none", focusedDisabled)} />
96
+
97
+ {href ? (
98
+ <Button
99
+ size={"small"}
100
+ variant="text"
101
+ type="button"
102
+ color={"text"}
103
+ className="flex items-center"
104
+ onClick={handleRemoveLink}
105
+ >
106
+ <DeleteIcon size="small" />
107
+ </Button>
108
+ ) : (
109
+ <Button size={"small"}
110
+ type="submit"
111
+ variant={"text"}>
112
+ <CheckIcon size="small" />
113
+ </Button>
114
+ )}
115
+ </form>
116
+ </Popover>
117
+ );
118
+ };