@firecms/core 3.1.0 → 3.2.0-canary.4c3b8f2

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 (191) 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/image-bubble.d.ts +5 -0
  12. package/dist/editor/components/index.d.ts +16 -0
  13. package/dist/editor/components/table-bubble.d.ts +5 -0
  14. package/dist/editor/editor.d.ts +30 -0
  15. package/dist/editor/extensions/HighlightDecorationExtension.d.ts +24 -0
  16. package/dist/editor/extensions/Image/index.d.ts +6 -0
  17. package/dist/editor/extensions/Image.d.ts +6 -0
  18. package/dist/editor/extensions/TextLoadingDecorationExtension.d.ts +16 -0
  19. package/dist/editor/extensions/clipboard.d.ts +7 -0
  20. package/dist/editor/extensions/custom-keymap.d.ts +1 -0
  21. package/dist/editor/extensions/drag-and-drop.d.ts +9 -0
  22. package/dist/editor/hooks/useProseMirror.d.ts +13 -0
  23. package/dist/editor/hooks/useProseMirrorContext.d.ts +9 -0
  24. package/dist/editor/index.d.ts +2 -0
  25. package/dist/editor/markdown.d.ts +5 -0
  26. package/dist/editor/nodeViews/ImageComponent.d.ts +3 -0
  27. package/dist/editor/nodeViews/ReactNodeView.d.ts +29 -0
  28. package/dist/editor/nodeViews/TaskItemComponent.d.ts +3 -0
  29. package/dist/editor/nodeViews/index.d.ts +6 -0
  30. package/dist/editor/plugins/index.d.ts +2 -0
  31. package/dist/editor/plugins/inputrules.d.ts +6 -0
  32. package/dist/editor/plugins/placeholderPlugin.d.ts +3 -0
  33. package/dist/editor/plugins/slashCommandPlugin.d.ts +12 -0
  34. package/dist/editor/schema.d.ts +2 -0
  35. package/dist/editor/selectors/ai-selector.d.ts +0 -0
  36. package/dist/editor/selectors/color-selector.d.ts +10 -0
  37. package/dist/editor/selectors/link-selector.d.ts +8 -0
  38. package/dist/editor/selectors/node-selector.d.ts +15 -0
  39. package/dist/editor/selectors/text-buttons.d.ts +1 -0
  40. package/dist/editor/types.d.ts +5 -0
  41. package/dist/editor/useProseMirror.d.ts +16 -0
  42. package/dist/editor/utils/prosemirror-utils.d.ts +6 -0
  43. package/dist/editor/utils/remove_classes.d.ts +1 -0
  44. package/dist/editor/utils/useDebouncedCallback.d.ts +1 -0
  45. package/dist/form/field_bindings/MarkdownEditorFieldBinding.d.ts +1 -1
  46. package/dist/hooks/index.d.ts +1 -0
  47. package/dist/hooks/useBuildNavigationController.d.ts +0 -1
  48. package/dist/hooks/useCollapsedGroups.d.ts +3 -3
  49. package/dist/hooks/useTranslation.d.ts +17 -0
  50. package/dist/i18n/FireCMSi18nProvider.d.ts +33 -0
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.es.js +12898 -2265
  53. package/dist/index.es.js.map +1 -1
  54. package/dist/index.umd.js +12877 -2264
  55. package/dist/index.umd.js.map +1 -1
  56. package/dist/locales/de.d.ts +2 -0
  57. package/dist/locales/en.d.ts +10 -0
  58. package/dist/locales/es.d.ts +10 -0
  59. package/dist/locales/fr.d.ts +2 -0
  60. package/dist/locales/hi.d.ts +2 -0
  61. package/dist/locales/it.d.ts +2 -0
  62. package/dist/locales/pt.d.ts +7 -0
  63. package/dist/types/customization_controller.d.ts +2 -1
  64. package/dist/types/firecms.d.ts +2 -1
  65. package/dist/types/index.d.ts +1 -0
  66. package/dist/types/navigation.d.ts +2 -2
  67. package/dist/types/plugins.d.ts +7 -0
  68. package/dist/types/storage.d.ts +1 -0
  69. package/dist/types/translations.d.ts +646 -0
  70. package/dist/util/useStorageUploadController.d.ts +10 -1
  71. package/package.json +45 -9
  72. package/src/app/Scaffold.tsx +7 -5
  73. package/src/components/AIIcon.tsx +3 -1
  74. package/src/components/ArrayContainer.tsx +6 -4
  75. package/src/components/ClearFilterSortButton.tsx +6 -3
  76. package/src/components/ConfirmationDialog.tsx +4 -2
  77. package/src/components/DeleteEntityDialog.tsx +10 -7
  78. package/src/components/EntityCollectionTable/fields/TableReferenceField.tsx +6 -3
  79. package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +3 -1
  80. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +3 -2
  81. package/src/components/EntityCollectionView/BoardSortableList.tsx +3 -1
  82. package/src/components/EntityCollectionView/CollectionDataErrorBanner.tsx +43 -0
  83. package/src/components/EntityCollectionView/EntityCollectionBoardView.tsx +16 -43
  84. package/src/components/EntityCollectionView/EntityCollectionCardView.tsx +17 -25
  85. package/src/components/EntityCollectionView/EntityCollectionView.tsx +26 -18
  86. package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +4 -3
  87. package/src/components/EntityCollectionView/EntityCollectionViewStartActions.tsx +4 -2
  88. package/src/components/EntityCollectionView/FiltersDialog.tsx +8 -5
  89. package/src/components/EntityCollectionView/ViewModeToggle.tsx +11 -8
  90. package/src/components/EntityView.tsx +3 -2
  91. package/src/components/ErrorBoundary.tsx +27 -15
  92. package/src/components/HomePage/DefaultHomePage.tsx +19 -13
  93. package/src/components/HomePage/HomePageDnD.tsx +3 -1
  94. package/src/components/HomePage/NavigationGroup.tsx +3 -1
  95. package/src/components/HomePage/RenameGroupDialog.tsx +15 -13
  96. package/src/components/LanguageToggle.tsx +66 -0
  97. package/src/components/NotFoundPage.tsx +5 -3
  98. package/src/components/ReferenceTable/ReferenceSelectionTable.tsx +9 -7
  99. package/src/components/ReferenceWidget.tsx +3 -2
  100. package/src/components/SearchIconsView.tsx +3 -1
  101. package/src/components/SelectableTable/filters/DateTimeFilterField.tsx +11 -0
  102. package/src/components/SelectableTable/filters/ReferenceFilterField.tsx +15 -2
  103. package/src/components/SelectableTable/filters/StringNumberFilterField.tsx +11 -0
  104. package/src/components/UnsavedChangesDialog.tsx +6 -4
  105. package/src/components/VirtualTable/VirtualTable.performance.test.tsx +1 -0
  106. package/src/components/VirtualTable/VirtualTableHeader.tsx +12 -10
  107. package/src/components/common/default_entity_actions.tsx +4 -0
  108. package/src/components/common/useDataSourceTableController.tsx +12 -4
  109. package/src/components/index.tsx +1 -0
  110. package/src/core/DefaultAppBar.tsx +14 -10
  111. package/src/core/DefaultDrawer.tsx +8 -2
  112. package/src/core/DrawerNavigationGroup.tsx +5 -3
  113. package/src/core/EntityEditView.tsx +4 -3
  114. package/src/core/EntityEditViewFormActions.tsx +24 -17
  115. package/src/core/EntitySidePanel.tsx +6 -5
  116. package/src/core/FireCMS.tsx +33 -6
  117. package/src/editor/components/SlashCommandMenu.tsx +516 -0
  118. package/src/editor/components/editor-bubble-item.tsx +32 -0
  119. package/src/editor/components/editor-bubble.tsx +118 -0
  120. package/src/editor/components/image-bubble.tsx +156 -0
  121. package/src/editor/components/index.ts +14 -0
  122. package/src/editor/components/table-bubble.tsx +165 -0
  123. package/src/editor/editor.tsx +455 -0
  124. package/src/editor/extensions/HighlightDecorationExtension.ts +114 -0
  125. package/src/editor/extensions/Image/index.ts +133 -0
  126. package/src/editor/extensions/Image.ts +159 -0
  127. package/src/editor/extensions/TextLoadingDecorationExtension.tsx +107 -0
  128. package/src/editor/extensions/clipboard.ts +72 -0
  129. package/src/editor/extensions/custom-keymap.ts +24 -0
  130. package/src/editor/extensions/drag-and-drop.tsx +480 -0
  131. package/src/editor/hooks/useProseMirror.ts +124 -0
  132. package/src/editor/hooks/useProseMirrorContext.ts +15 -0
  133. package/src/editor/index.ts +2 -0
  134. package/src/editor/markdown.ts +172 -0
  135. package/src/editor/nodeViews/ImageComponent.tsx +20 -0
  136. package/src/editor/nodeViews/ReactNodeView.tsx +89 -0
  137. package/src/editor/nodeViews/TaskItemComponent.tsx +29 -0
  138. package/src/editor/nodeViews/index.ts +35 -0
  139. package/src/editor/plugins/index.ts +58 -0
  140. package/src/editor/plugins/inputrules.ts +82 -0
  141. package/src/editor/plugins/placeholderPlugin.ts +55 -0
  142. package/src/editor/plugins/slashCommandPlugin.ts +61 -0
  143. package/src/editor/schema.ts +240 -0
  144. package/src/editor/selectors/ai-selector.tsx +111 -0
  145. package/src/editor/selectors/color-selector.tsx +200 -0
  146. package/src/editor/selectors/link-selector.tsx +118 -0
  147. package/src/editor/selectors/node-selector.tsx +157 -0
  148. package/src/editor/selectors/text-buttons.tsx +86 -0
  149. package/src/editor/types.ts +6 -0
  150. package/src/editor/useProseMirror.ts +126 -0
  151. package/src/editor/utils/prosemirror-utils.ts +108 -0
  152. package/src/editor/utils/remove_classes.ts +17 -0
  153. package/src/editor/utils/useDebouncedCallback.ts +25 -0
  154. package/src/form/EntityForm.tsx +16 -3
  155. package/src/form/EntityFormActions.tsx +19 -12
  156. package/src/form/PropertyFieldBinding.tsx +3 -2
  157. package/src/form/components/LocalChangesMenu.tsx +13 -13
  158. package/src/form/components/StorageItemPreview.tsx +3 -2
  159. package/src/form/components/StorageUploadProgress.tsx +18 -3
  160. package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +4 -4
  161. package/src/form/field_bindings/BlockFieldBinding.tsx +5 -2
  162. package/src/form/field_bindings/KeyValueFieldBinding.tsx +23 -18
  163. package/src/form/field_bindings/MapFieldBinding.tsx +4 -3
  164. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +33 -19
  165. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -1
  166. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +4 -3
  167. package/src/hooks/index.tsx +1 -0
  168. package/src/hooks/useBuildNavigationController.tsx +45 -18
  169. package/src/hooks/useCollapsedGroups.ts +7 -6
  170. package/src/hooks/useTranslation.ts +31 -0
  171. package/src/i18n/FireCMSi18nProvider.tsx +160 -0
  172. package/src/index.ts +4 -0
  173. package/src/internal/useBuildSideEntityController.tsx +22 -20
  174. package/src/locales/de.ts +691 -0
  175. package/src/locales/en.ts +703 -0
  176. package/src/locales/es.ts +703 -0
  177. package/src/locales/fr.ts +691 -0
  178. package/src/locales/hi.ts +691 -0
  179. package/src/locales/it.ts +691 -0
  180. package/src/locales/pt.ts +700 -0
  181. package/src/preview/components/UrlComponentPreview.tsx +4 -2
  182. package/src/preview/components/UserPreview.tsx +3 -1
  183. package/src/types/customization_controller.tsx +2 -1
  184. package/src/types/firecms.tsx +2 -1
  185. package/src/types/index.ts +1 -0
  186. package/src/types/navigation.ts +2 -2
  187. package/src/types/plugins.tsx +8 -0
  188. package/src/types/properties.ts +1 -0
  189. package/src/types/storage.ts +2 -1
  190. package/src/types/translations.ts +725 -0
  191. package/src/util/useStorageUploadController.tsx +23 -29
@@ -0,0 +1,240 @@
1
+ import { Schema, NodeSpec, MarkSpec } from "prosemirror-model";
2
+ import { tableNodes } from "prosemirror-tables";
3
+
4
+ const marks: { [key: string]: MarkSpec } = {
5
+ link: {
6
+ attrs: {
7
+ href: {},
8
+ title: { default: null },
9
+ target: { default: "_blank" },
10
+ },
11
+ inclusive: false,
12
+ parseDOM: [
13
+ {
14
+ tag: "a[href]",
15
+ getAttrs(dom: HTMLElement | string) {
16
+ if (typeof dom === "string") return false;
17
+ return {
18
+ href: dom.getAttribute("href"),
19
+ title: dom.getAttribute("title"),
20
+ target: dom.getAttribute("target") || "_blank",
21
+ };
22
+ },
23
+ },
24
+ ],
25
+ toDOM(node) {
26
+ let { href, title, target } = node.attrs;
27
+ 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];
28
+ },
29
+ },
30
+ bold: {
31
+ parseDOM: [
32
+ { tag: "strong" },
33
+ { tag: "b", getAttrs: (node: HTMLElement | string) => typeof node !== "string" && node.style.fontWeight !== "normal" && null },
34
+ { style: "font-weight=400", clearMark: m => m.type.name === "bold" },
35
+ { style: "font-weight", getAttrs: (value: string | HTMLElement) => typeof value === "string" && /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null },
36
+ ],
37
+ toDOM() { return ["strong", 0]; },
38
+ },
39
+ italic: {
40
+ parseDOM: [{ tag: "i" }, { tag: "em" }, { style: "font-style=italic" }],
41
+ toDOM() { return ["em", 0]; },
42
+ },
43
+ strike: {
44
+ parseDOM: [{ tag: "s" }, { tag: "del" }, { tag: "strike" }, { style: "text-decoration=line-through" }],
45
+ toDOM() { return ["s", 0]; },
46
+ },
47
+ underline: {
48
+ parseDOM: [{ tag: "u" }, { style: "text-decoration=underline" }],
49
+ toDOM() { return ["u", 0]; },
50
+ },
51
+ code: {
52
+ parseDOM: [{ tag: "code" }],
53
+ 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]; },
54
+ },
55
+ textStyle: {
56
+ attrs: { color: { default: null } },
57
+ parseDOM: [
58
+ {
59
+ style: "color",
60
+ getAttrs: (value: string | HTMLElement) => {
61
+ if (typeof value === "string") return { color: value };
62
+ return false;
63
+ },
64
+ },
65
+ ],
66
+ toDOM(mark) {
67
+ let style = "";
68
+ if (mark.attrs.color) style += `color: ${mark.attrs.color};`;
69
+ return ["span", { style }, 0];
70
+ },
71
+ },
72
+ highlight: {
73
+ attrs: { color: { default: null } },
74
+ parseDOM: [
75
+ {
76
+ tag: "mark",
77
+ getAttrs: (dom: HTMLElement | string) => {
78
+ if (typeof dom === "string") return false;
79
+ return { color: dom.style.backgroundColor || dom.getAttribute("data-color") };
80
+ }
81
+ },
82
+ ],
83
+ toDOM(mark) {
84
+ return ["mark", mark.attrs.color ? { style: `background-color: ${mark.attrs.color}; color: inherit;`, "data-color": mark.attrs.color } : {}, 0];
85
+ },
86
+ },
87
+ };
88
+
89
+ const nodes: { [key: string]: NodeSpec } = {
90
+ doc: {
91
+ content: "block+",
92
+ },
93
+ paragraph: {
94
+ content: "inline*",
95
+ group: "block",
96
+ parseDOM: [{ tag: "p" }],
97
+ toDOM() { return ["p", 0]; },
98
+ },
99
+ text: {
100
+ group: "inline",
101
+ },
102
+ blockquote: {
103
+ content: "block+",
104
+ group: "block",
105
+ defining: true,
106
+ parseDOM: [{ tag: "blockquote" }],
107
+ toDOM() { return ["blockquote", { class: "border-l-4 border-primary" }, 0]; },
108
+ },
109
+ heading: {
110
+ attrs: { level: { default: 1 } },
111
+ content: "inline*",
112
+ group: "block",
113
+ defining: true,
114
+ parseDOM: [
115
+ { tag: "h1", attrs: { level: 1 } },
116
+ { tag: "h2", attrs: { level: 2 } },
117
+ { tag: "h3", attrs: { level: 3 } },
118
+ { tag: "h4", attrs: { level: 4 } },
119
+ { tag: "h5", attrs: { level: 5 } },
120
+ { tag: "h6", attrs: { level: 6 } },
121
+ ],
122
+ toDOM(node) { return ["h" + node.attrs.level, 0]; },
123
+ },
124
+ horizontal_rule: {
125
+ group: "block",
126
+ parseDOM: [{ tag: "hr" }],
127
+ toDOM() { return ["hr", { class: "mt-4 mb-6 border-t border-solid border-gray-200 dark:border-gray-800" }]; },
128
+ },
129
+ code_block: {
130
+ content: "text*",
131
+ marks: "",
132
+ group: "block",
133
+ code: true,
134
+ defining: true,
135
+ attrs: { language: { default: null } },
136
+ parseDOM: [
137
+ { tag: "pre", preserveWhitespace: "full" },
138
+ ],
139
+ 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]]; },
140
+ },
141
+ image: {
142
+ inline: false,
143
+ group: "block",
144
+ attrs: {
145
+ src: {},
146
+ alt: { default: null },
147
+ title: { default: null },
148
+ },
149
+ draggable: true,
150
+ parseDOM: [
151
+ {
152
+ tag: "img[src]",
153
+ getAttrs(dom: HTMLElement | string) {
154
+ if (typeof dom === "string") return false;
155
+ return {
156
+ src: dom.getAttribute("src"),
157
+ title: dom.getAttribute("title"),
158
+ alt: dom.getAttribute("alt"),
159
+ };
160
+ },
161
+ },
162
+ ],
163
+ toDOM(node) {
164
+ let { src, alt, title } = node.attrs;
165
+ return ["img", { src, alt, title, class: "rounded-lg max-w-full !m-0" }];
166
+ },
167
+ },
168
+ bullet_list: {
169
+ content: "list_item+",
170
+ group: "block",
171
+ parseDOM: [{ tag: "ul" }],
172
+ toDOM() { return ["ul", { class: "list-disc list-outside leading-3 -mt-2" }, 0]; },
173
+ },
174
+ ordered_list: {
175
+ content: "list_item+",
176
+ group: "block",
177
+ attrs: { order: { default: 1 } },
178
+ parseDOM: [
179
+ {
180
+ tag: "ol",
181
+ getAttrs(dom: HTMLElement | string) {
182
+ if (typeof dom === "string") return false;
183
+ return { order: dom.hasAttribute("start") ? +dom.getAttribute("start")! : 1 };
184
+ },
185
+ },
186
+ ],
187
+ toDOM(node) {
188
+ 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];
189
+ },
190
+ },
191
+ list_item: {
192
+ content: "paragraph block*",
193
+ parseDOM: [{ tag: "li" }],
194
+ toDOM() { return ["li", { class: "leading-normal -mb-2" }, 0]; },
195
+ defining: true,
196
+ },
197
+ task_list: {
198
+ group: "block",
199
+ content: "task_item+",
200
+ parseDOM: [{ tag: 'ul[data-type="taskList"]' }],
201
+ toDOM() { return ["ul", { "data-type": "taskList", class: "not-prose" }, 0]; },
202
+ },
203
+ task_item: {
204
+ content: "paragraph block*",
205
+ defining: true,
206
+ attrs: { checked: { default: false } },
207
+ parseDOM: [
208
+ {
209
+ tag: 'li[data-type="taskItem"]',
210
+ getAttrs(dom: HTMLElement | string) {
211
+ if (typeof dom === "string") return false;
212
+ return { checked: dom.getAttribute("data-checked") === "true" };
213
+ },
214
+ },
215
+ ],
216
+ toDOM(node) {
217
+ return ["li", { "data-type": "taskItem", "data-checked": node.attrs.checked ? "true" : "false", class: "flex items-start my-4" }, 0];
218
+ },
219
+ },
220
+ hard_break: {
221
+ inline: true,
222
+ group: "inline",
223
+ selectable: false,
224
+ parseDOM: [{ tag: "br" }],
225
+ toDOM() { return ["br"]; },
226
+ },
227
+ ...tableNodes({
228
+ tableGroup: "block",
229
+ cellContent: "block+",
230
+ cellAttributes: {
231
+ background: {
232
+ default: null,
233
+ getFromDOM(dom: HTMLElement) { return dom.style.backgroundColor || null },
234
+ setDOMAttr(value: any, attrs: any) { if (value) attrs.style = (attrs.style || "") + `background-color: ${value};` }
235
+ }
236
+ }
237
+ })
238
+ };
239
+
240
+ 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
+ };