@alpaca-editor/core 1.0.0 → 1.0.3764-editor-mono

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 (223) hide show
  1. package/dist/client-components/api.js +6 -0
  2. package/dist/client-components/index.js +36 -0
  3. package/dist/components/ActionButton.js +9 -0
  4. package/dist/components/Error.js +28 -0
  5. package/dist/config/config.js +654 -0
  6. package/dist/config/types.js +2 -0
  7. package/dist/editor/ComponentInfo.js +31 -0
  8. package/dist/editor/ConfirmationDialog.js +32 -0
  9. package/dist/editor/ContentTree.js +406 -0
  10. package/dist/editor/ContextMenu.js +117 -0
  11. package/dist/editor/Editor.js +55 -0
  12. package/dist/editor/EditorWarning.js +13 -0
  13. package/dist/editor/EditorWarnings.js +24 -0
  14. package/dist/editor/FieldEditorPopup.js +24 -0
  15. package/dist/editor/FieldHistory.js +40 -0
  16. package/dist/editor/FieldList.js +63 -0
  17. package/dist/editor/FieldListField.js +164 -0
  18. package/dist/editor/FieldListFieldWithFallbacks.js +114 -0
  19. package/dist/editor/FloatingToolbar.js +92 -0
  20. package/dist/editor/ImageEditor.js +55 -0
  21. package/dist/editor/InsertMenu.js +164 -0
  22. package/dist/editor/ItemInfo.js +30 -0
  23. package/dist/editor/LinkEditorDialog.js +89 -0
  24. package/dist/editor/MainLayout.js +46 -0
  25. package/dist/editor/NewEditorClient.js +9 -0
  26. package/dist/editor/PictureCropper.js +332 -0
  27. package/dist/editor/PictureEditor.js +104 -0
  28. package/dist/editor/PictureEditorDialog.js +194 -0
  29. package/dist/editor/ScrollingContentTree.js +30 -0
  30. package/dist/editor/Terminal.js +109 -0
  31. package/dist/editor/Titlebar.js +11 -0
  32. package/dist/editor/ai/AiPopup.js +25 -0
  33. package/dist/editor/ai/AiResponseMessage.js +24 -0
  34. package/dist/editor/ai/AiTerminal.js +241 -0
  35. package/dist/editor/ai/AiToolCall.js +18 -0
  36. package/dist/editor/ai/EditorAiTerminal.js +9 -0
  37. package/dist/editor/ai/editorAiContext.js +14 -0
  38. package/dist/editor/client/DialogContext.js +29 -0
  39. package/dist/editor/client/EditorClient.js +1336 -0
  40. package/dist/editor/client/GenericDialog.js +27 -0
  41. package/dist/editor/client/editContext.js +59 -0
  42. package/dist/editor/client/helpers.js +31 -0
  43. package/dist/editor/client/itemsRepository.js +255 -0
  44. package/dist/editor/client/operations.js +398 -0
  45. package/dist/editor/client/pageModelBuilder.js +129 -0
  46. package/dist/editor/commands/commands.js +2 -0
  47. package/dist/editor/commands/componentCommands.js +277 -0
  48. package/dist/editor/commands/createVersionCommand.js +26 -0
  49. package/dist/editor/commands/deleteVersionCommand.js +55 -0
  50. package/dist/editor/commands/itemCommands.js +134 -0
  51. package/dist/editor/commands/localizeItem/LocalizeItemDialog.js +94 -0
  52. package/dist/editor/commands/undo.js +32 -0
  53. package/dist/editor/component-designer/ComponentDesigner.js +58 -0
  54. package/dist/editor/component-designer/ComponentDesignerAiTerminal.js +9 -0
  55. package/dist/editor/component-designer/ComponentDesignerMenu.js +67 -0
  56. package/dist/editor/component-designer/ComponentEditor.js +59 -0
  57. package/dist/editor/component-designer/ComponentRenderingCodeEditor.js +16 -0
  58. package/dist/editor/component-designer/ComponentRenderingEditor.js +71 -0
  59. package/dist/editor/component-designer/ComponentsDropdown.js +22 -0
  60. package/dist/editor/component-designer/PlaceholdersEditor.js +70 -0
  61. package/dist/editor/component-designer/RenderingsDropdown.js +25 -0
  62. package/dist/editor/component-designer/TemplateEditor.js +144 -0
  63. package/dist/editor/component-designer/aiContext.js +18 -0
  64. package/dist/editor/componentTreeHelper.js +97 -0
  65. package/dist/editor/control-center/ControlCenterMenu.js +59 -0
  66. package/dist/editor/control-center/IndexOverview.js +27 -0
  67. package/dist/editor/control-center/IndexSettings.js +106 -0
  68. package/dist/editor/control-center/Status.js +7 -0
  69. package/dist/editor/editor-warnings/ItemLocked.js +40 -0
  70. package/dist/editor/editor-warnings/NoLanguageWriteAccess.js +16 -0
  71. package/dist/editor/editor-warnings/NoWorkflowWriteAccess.js +16 -0
  72. package/dist/editor/editor-warnings/NoWriteAccess.js +14 -0
  73. package/dist/editor/editor-warnings/ValidationErrors.js +27 -0
  74. package/dist/editor/field-types/AttachmentEditor.js +7 -0
  75. package/dist/editor/field-types/CheckboxEditor.js +32 -0
  76. package/dist/editor/field-types/DropLinkEditor.js +51 -0
  77. package/dist/editor/field-types/DropListEditor.js +58 -0
  78. package/dist/editor/field-types/ImageFieldEditor.js +36 -0
  79. package/dist/editor/field-types/InternalLinkFieldEditor.js +64 -0
  80. package/dist/editor/field-types/LinkFieldEditor.js +58 -0
  81. package/dist/editor/field-types/MultiLineText.js +35 -0
  82. package/dist/editor/field-types/PictureFieldEditor.js +59 -0
  83. package/dist/editor/field-types/RawEditor.js +33 -0
  84. package/dist/editor/field-types/ReactQuill.js +366 -0
  85. package/dist/editor/field-types/RichTextEditor.js +46 -0
  86. package/dist/editor/field-types/RichTextEditorComponent.js +72 -0
  87. package/dist/editor/field-types/SingleLineText.js +92 -0
  88. package/dist/editor/field-types/TreeListEditor.js +137 -0
  89. package/dist/editor/fieldTypes.js +2 -0
  90. package/dist/editor/media-selector/AiImageSearch.js +110 -0
  91. package/dist/editor/media-selector/AiImageSearchPrompt.js +58 -0
  92. package/dist/editor/media-selector/MediaSelector.js +11 -0
  93. package/dist/editor/media-selector/Preview.js +9 -0
  94. package/dist/editor/media-selector/Thumbnails.js +11 -0
  95. package/dist/editor/media-selector/TreeSelector.js +171 -0
  96. package/dist/editor/media-selector/UploadZone.js +80 -0
  97. package/dist/editor/menubar/ActionsMenu.js +33 -0
  98. package/dist/editor/menubar/ActiveUsers.js +13 -0
  99. package/dist/editor/menubar/ApproveAndPublish.js +13 -0
  100. package/dist/editor/menubar/BrowseHistory.js +14 -0
  101. package/dist/editor/menubar/ItemLanguageVersion.js +36 -0
  102. package/dist/editor/menubar/LanguageSelector.js +33 -0
  103. package/dist/editor/menubar/Menu.js +65 -0
  104. package/dist/editor/menubar/NavButtons.js +43 -0
  105. package/dist/editor/menubar/PageSelector.js +50 -0
  106. package/dist/editor/menubar/PageViewerControls.js +37 -0
  107. package/dist/editor/menubar/Separator.js +8 -0
  108. package/dist/editor/menubar/SiteInfo.js +26 -0
  109. package/dist/editor/menubar/User.js +18 -0
  110. package/dist/editor/menubar/VersionSelector.js +49 -0
  111. package/dist/editor/page-editor-chrome/CommentHighlighting.js +214 -0
  112. package/dist/editor/page-editor-chrome/CommentHighlightings.js +17 -0
  113. package/dist/editor/page-editor-chrome/FieldActionIndicator.js +27 -0
  114. package/dist/editor/page-editor-chrome/FieldActionIndicators.js +15 -0
  115. package/dist/editor/page-editor-chrome/FieldEditedIndicator.js +27 -0
  116. package/dist/editor/page-editor-chrome/FieldEditedIndicators.js +15 -0
  117. package/dist/editor/page-editor-chrome/FrameMenu.js +178 -0
  118. package/dist/editor/page-editor-chrome/FrameMenus.js +24 -0
  119. package/dist/editor/page-editor-chrome/InlineEditor.js +101 -0
  120. package/dist/editor/page-editor-chrome/LockedFieldIndicator.js +35 -0
  121. package/dist/editor/page-editor-chrome/NoLayout.js +21 -0
  122. package/dist/editor/page-editor-chrome/PageEditorChrome.js +65 -0
  123. package/dist/editor/page-editor-chrome/PictureEditorOverlay.js +109 -0
  124. package/dist/editor/page-editor-chrome/PlaceholderDropZone.js +82 -0
  125. package/dist/editor/page-editor-chrome/PlaceholderDropZones.js +147 -0
  126. package/dist/editor/page-viewer/DeviceToolbar.js +21 -0
  127. package/dist/editor/page-viewer/EditorForm.js +130 -0
  128. package/dist/editor/page-viewer/MiniMap.js +257 -0
  129. package/dist/editor/page-viewer/PageViewer.js +64 -0
  130. package/dist/editor/page-viewer/PageViewerFrame.js +696 -0
  131. package/dist/editor/page-viewer/pageViewContext.js +117 -0
  132. package/dist/editor/pageModel.js +2 -0
  133. package/dist/editor/picture-shared.js +28 -0
  134. package/dist/editor/reviews/Comment.js +112 -0
  135. package/dist/editor/reviews/Comments.js +24 -0
  136. package/dist/editor/reviews/PreviewInfo.js +13 -0
  137. package/dist/editor/reviews/Reviews.js +165 -0
  138. package/dist/editor/reviews/reviewCommands.js +44 -0
  139. package/dist/editor/reviews/useReviews.js +48 -0
  140. package/dist/editor/services/aiService.js +99 -0
  141. package/dist/editor/services/componentDesignerService.js +79 -0
  142. package/dist/editor/services/contentService.js +104 -0
  143. package/dist/editor/services/editService.js +322 -0
  144. package/dist/editor/services/indexService.js +25 -0
  145. package/dist/editor/services/reviewsService.js +43 -0
  146. package/dist/editor/services/serviceHelper.js +67 -0
  147. package/dist/editor/services/systemService.js +7 -0
  148. package/dist/editor/services/translationService.js +15 -0
  149. package/dist/editor/services-server/api.js +119 -0
  150. package/dist/editor/services-server/graphQL.js +56 -0
  151. package/dist/editor/sidebar/ComponentPalette.js +55 -0
  152. package/dist/editor/sidebar/ComponentTree.js +362 -0
  153. package/dist/editor/sidebar/Debug.js +60 -0
  154. package/dist/editor/sidebar/DictionaryEditor.js +160 -0
  155. package/dist/editor/sidebar/EditHistory.js +74 -0
  156. package/dist/editor/sidebar/GraphQL.js +115 -0
  157. package/dist/editor/sidebar/Insert.js +24 -0
  158. package/dist/editor/sidebar/MainContentTree.js +52 -0
  159. package/dist/editor/sidebar/Performance.js +34 -0
  160. package/dist/editor/sidebar/Sessions.js +31 -0
  161. package/dist/editor/sidebar/Sidebar.js +15 -0
  162. package/dist/editor/sidebar/SidebarView.js +76 -0
  163. package/dist/editor/sidebar/Translations.js +160 -0
  164. package/dist/editor/sidebar/Validation.js +52 -0
  165. package/dist/editor/sidebar/ViewSelector.js +15 -0
  166. package/dist/editor/sidebar/Workbox.js +80 -0
  167. package/dist/editor/ui/CenteredMessage.js +7 -0
  168. package/dist/editor/ui/CopyToClipboardButton.js +17 -0
  169. package/dist/editor/ui/DialogButtons.js +7 -0
  170. package/dist/editor/ui/Icons.js +75 -0
  171. package/dist/editor/ui/ItemNameDialog.js +45 -0
  172. package/dist/editor/ui/ItemNameDialogNew.js +61 -0
  173. package/dist/editor/ui/ItemSearch.js +93 -0
  174. package/dist/editor/ui/PerfectTree.js +223 -0
  175. package/dist/editor/ui/Section.js +12 -0
  176. package/dist/editor/ui/SimpleIconButton.js +11 -0
  177. package/dist/editor/ui/SimpleMenu.js +9 -0
  178. package/dist/editor/ui/SimpleTable.js +11 -0
  179. package/dist/editor/ui/SimpleTabs.js +21 -0
  180. package/dist/editor/ui/SimpleToolbar.js +7 -0
  181. package/dist/editor/ui/Spinner.js +7 -0
  182. package/dist/editor/ui/Splitter.js +187 -0
  183. package/dist/editor/ui/StackedPanels.js +69 -0
  184. package/dist/editor/ui/Toolbar.js +7 -0
  185. package/dist/editor/utils/id-helper.js +7 -0
  186. package/dist/editor/utils/insertOptions.js +45 -0
  187. package/dist/editor/utils/itemutils.js +25 -0
  188. package/dist/editor/utils/useMemoDebug.js +20 -0
  189. package/dist/editor/utils.js +328 -0
  190. package/dist/editor/views/CompareView.js +147 -0
  191. package/dist/editor/views/EditView.js +17 -0
  192. package/dist/editor/views/ItemEditor.js +24 -0
  193. package/dist/editor/views/SingleEditView.js +25 -0
  194. package/dist/index.js +22 -0
  195. package/dist/page-wizard/PageWizard.js +62 -0
  196. package/dist/page-wizard/SelectWizard.js +43 -0
  197. package/dist/page-wizard/WizardSteps.js +71 -0
  198. package/dist/page-wizard/service.js +26 -0
  199. package/dist/page-wizard/startPageWizardCommand.js +23 -0
  200. package/dist/page-wizard/steps/BuildPageStep.js +138 -0
  201. package/dist/page-wizard/steps/CollectStep.js +124 -0
  202. package/dist/page-wizard/steps/ComponentTypesSelector.js +211 -0
  203. package/dist/page-wizard/steps/Components.js +94 -0
  204. package/dist/page-wizard/steps/CreatePage.js +142 -0
  205. package/dist/page-wizard/steps/CreatePageAndLayoutStep.js +230 -0
  206. package/dist/page-wizard/steps/EditButton.js +7 -0
  207. package/dist/page-wizard/steps/FieldEditor.js +30 -0
  208. package/dist/page-wizard/steps/Generate.js +11 -0
  209. package/dist/page-wizard/steps/ImagesStep.js +159 -0
  210. package/dist/page-wizard/steps/LayoutStep.js +120 -0
  211. package/dist/page-wizard/steps/SelectStep.js +150 -0
  212. package/dist/page-wizard/steps/schema.js +140 -0
  213. package/dist/page-wizard/steps/usePageCreator.js +194 -0
  214. package/dist/splash-screen/NewPage.js +131 -0
  215. package/dist/splash-screen/SectionHeadline.js +9 -0
  216. package/dist/splash-screen/SplashScreen.js +81 -0
  217. package/dist/tour/Tour.js +321 -0
  218. package/dist/tour/default-tour.js +231 -0
  219. package/dist/tour/preview-tour.js +93 -0
  220. package/dist/tsconfig.build.tsbuildinfo +1 -0
  221. package/dist/types.js +2 -0
  222. package/package.json +1 -1
  223. package/src/editor/sidebar/ComponentTree.tsx +512 -512
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MultiLineText = MultiLineText;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const inputtextarea_1 = require("primereact/inputtextarea");
7
+ const editContext_1 = require("../client/editContext");
8
+ const react_1 = require("react");
9
+ function MultiLineText({ field, readOnly, updateFieldValue, }) {
10
+ const editContextRef = (0, editContext_1.useEditContextRef)();
11
+ const inputRef = (0, react_1.useRef)(null);
12
+ const fieldItem = field.descriptor.item;
13
+ const [value, setValue] = (0, react_1.useState)(field.value);
14
+ const modifiedFieldsContext = (0, editContext_1.useModifiedFieldsContext)();
15
+ const modifiedField = modifiedFieldsContext?.modifiedFields.find((x) => x.fieldId === field.id &&
16
+ x.item.id === fieldItem.id &&
17
+ x.item.language === fieldItem.language &&
18
+ x.item.version === fieldItem.version);
19
+ (0, react_1.useEffect)(() => {
20
+ if (inputRef.current !== document.activeElement) {
21
+ if (field.isHistoric)
22
+ setValue(field.value);
23
+ else
24
+ setValue(modifiedField?.value ?? field.value);
25
+ }
26
+ }, [field.value, modifiedFieldsContext?.modifiedFields]);
27
+ if (!editContextRef.current)
28
+ return;
29
+ if (!fieldItem)
30
+ return;
31
+ return ((0, jsx_runtime_1.jsx)(inputtextarea_1.InputTextarea, { ref: inputRef, value: value, disabled: readOnly, className: "p-2 focus-shadow text-sm", style: { width: "100%" }, rows: 12, onChange: (e) => {
32
+ setValue(e.target.value);
33
+ updateFieldValue(e.target.value);
34
+ } }, fieldItem.id + field.id + fieldItem.language + fieldItem.version));
35
+ }
@@ -0,0 +1,59 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PictureFieldEditor = PictureFieldEditor;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const editContext_1 = require("../client/editContext");
7
+ const inputtext_1 = require("primereact/inputtext");
8
+ const PictureEditor_1 = require("../PictureEditor");
9
+ const react_1 = require("react");
10
+ const SimpleIconButton_1 = require("../ui/SimpleIconButton");
11
+ function PictureFieldEditor({ field, readOnly, }) {
12
+ const editContext = (0, editContext_1.useEditContext)();
13
+ const [altText, setAltText] = (0, react_1.useState)("");
14
+ if (!field || !editContext)
15
+ return;
16
+ var item = field.descriptor.item;
17
+ (0, react_1.useEffect)(() => {
18
+ setAltText(field.value?.alt || "");
19
+ }, [field.value?.alt]);
20
+ if (field.value?.error) {
21
+ return (0, jsx_runtime_1.jsx)("div", { children: field.value?.error });
22
+ }
23
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "flex gap-2 h-full focus-shadow flex-wrap", children: field?.value?.variants?.map((variant) => ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsxs)("div", { className: "h-48 w-48 border border-gray-300 relative cursor-pointer flex justify-center items-center", children: [variant.src && (0, jsx_runtime_1.jsx)("img", { src: variant.thumbSrc }), !readOnly && ((0, jsx_runtime_1.jsx)(PictureEditor_1.PictureEditor, { field: field, variantName: variant.name }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-1", children: [(0, jsx_runtime_1.jsx)("div", { className: "text-xs", children: variant.name }), (0, jsx_runtime_1.jsx)("div", { className: "text-xs", children: variant.aspectRatioLockText })] }), variant.videoUrl && ((0, jsx_runtime_1.jsxs)("div", { className: "text-xs", children: ["Video: ", variant.videoUrl, (0, jsx_runtime_1.jsx)(SimpleIconButton_1.SimpleIconButton, { onClick: () => {
24
+ const raw = field.rawValue
25
+ ? JSON.parse(field?.rawValue)
26
+ : { Variants: [] };
27
+ if (!raw.Variants)
28
+ return;
29
+ let rawVariant = raw.Variants.find((v) => v.Name === variant.name);
30
+ if (rawVariant) {
31
+ rawVariant.VideoId = undefined;
32
+ }
33
+ else {
34
+ rawVariant = {
35
+ Name: variant.name,
36
+ VideoId: undefined,
37
+ };
38
+ raw.Variants.push(rawVariant);
39
+ }
40
+ editContext.operations.editField({
41
+ field: field.descriptor,
42
+ rawValue: JSON.stringify(raw),
43
+ refresh: "immediate",
44
+ });
45
+ }, icon: "pi pi-trash", label: "Remove" })] }))] }, variant.name))) }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-1", children: "Alt Text" }), (0, jsx_runtime_1.jsx)(inputtext_1.InputText, { value: altText, disabled: readOnly, className: "p-2 focus-shadow text-sm", style: { width: "100%" }, onChange: (e) => {
46
+ setAltText(e.target.value);
47
+ const raw = field?.rawValue
48
+ ? JSON.parse(field?.rawValue)
49
+ : { Variants: [] };
50
+ raw.AltText = e.target.value;
51
+ if (field.value)
52
+ field.value.alt = e.target.value;
53
+ editContext.operations.editField({
54
+ field: field.descriptor,
55
+ rawValue: JSON.stringify(raw),
56
+ refresh: "waitForQuietPeriod",
57
+ });
58
+ } }, item.id + field.id + item.language + item.version)] })] }));
59
+ }
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RawEditor = RawEditor;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const inputtextarea_1 = require("primereact/inputtextarea");
7
+ const editContext_1 = require("../client/editContext");
8
+ const react_1 = require("react");
9
+ const use_debounce_1 = require("use-debounce");
10
+ function RawEditor({ field, readOnly, }) {
11
+ const editContext = (0, editContext_1.useEditContext)();
12
+ const inputRef = (0, react_1.useRef)(null);
13
+ if (!editContext)
14
+ return;
15
+ const [value, setValue] = (0, react_1.useState)(field.rawValue);
16
+ (0, react_1.useEffect)(() => {
17
+ if (inputRef.current !== document.activeElement)
18
+ setValue(field.rawValue);
19
+ }, [field.rawValue]);
20
+ const debouncedSetFieldvalue = (0, use_debounce_1.useDebouncedCallback)((value) => {
21
+ editContext.operations.editField({
22
+ field: field.descriptor,
23
+ rawValue: value,
24
+ refresh: "waitForQuietPeriod",
25
+ });
26
+ }, 200);
27
+ const fieldItem = field.descriptor.item;
28
+ return ((0, jsx_runtime_1.jsx)(inputtextarea_1.InputTextarea, { ref: inputRef, value: value || "", disabled: readOnly, className: "p-2 focus-shadow text-sm", style: { width: "100%" }, rows: 12, onChange: (e) => {
29
+ setValue(e.target.value);
30
+ debouncedSetFieldvalue(e.target.value);
31
+ // field.value = e.target.value;
32
+ } }, fieldItem.id + field.id + fieldItem.language + fieldItem.version));
33
+ }
@@ -0,0 +1,366 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReactQuill = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ /*
9
+ React-Quill
10
+ https://github.com/zenoamaro/react-quill
11
+ */
12
+ const react_1 = __importDefault(require("react"));
13
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
14
+ const quill_1 = __importDefault(require("quill"));
15
+ class ReactQuill extends react_1.default.Component {
16
+ constructor(props) {
17
+ super(props);
18
+ /*
19
+ Changing one of these props should cause a full re-render and a
20
+ re-instantiation of the Quill editor.
21
+ */
22
+ this.dirtyProps = [
23
+ "modules",
24
+ "formats",
25
+ "bounds",
26
+ "theme",
27
+ "children",
28
+ ];
29
+ /*
30
+ Changing one of these props should cause a regular update. These are mostly
31
+ props that act on the container, rather than the quillized editing area.
32
+ */
33
+ this.cleanProps = [
34
+ "id",
35
+ "className",
36
+ "style",
37
+ "placeholder",
38
+ "tabIndex",
39
+ "onChange",
40
+ "onChangeSelection",
41
+ "onFocus",
42
+ "onBlur",
43
+ "onKeyPress",
44
+ "onKeyDown",
45
+ "onKeyUp",
46
+ ];
47
+ this.state = {
48
+ generation: 0,
49
+ };
50
+ /*
51
+ Tracks the internal selection of the Quill editor
52
+ */
53
+ this.selection = null;
54
+ this.editingAreaRef = react_1.default.createRef();
55
+ this.onEditorChange = (eventName, rangeOrDelta,
56
+ //oldRangeOrDelta: Range | DeltaStatic,
57
+ source) => {
58
+ if (eventName === "text-change") {
59
+ this.onEditorChangeText?.(this.editor.root.innerHTML, rangeOrDelta, source, this.unprivilegedEditor);
60
+ }
61
+ else if (eventName === "selection-change") {
62
+ this.onEditorChangeSelection?.(rangeOrDelta, source, this.unprivilegedEditor);
63
+ }
64
+ };
65
+ const value = this.isControlled() ? props.value : props.defaultValue;
66
+ this.value = value ?? "";
67
+ }
68
+ validateProps(props) {
69
+ if (react_1.default.Children.count(props.children) > 1)
70
+ throw new Error("The Quill editing area can only be composed of a single React element.");
71
+ if (react_1.default.Children.count(props.children)) {
72
+ const child = react_1.default.Children.only(props.children);
73
+ if (child?.type === "textarea")
74
+ throw new Error("Quill does not support editing on a <textarea>. Use a <div> instead.");
75
+ }
76
+ if (this.lastDeltaChangeSet && props.value === this.lastDeltaChangeSet)
77
+ throw new Error("You are passing the `delta` object from the `onChange` event back " +
78
+ "as `value`. You most probably want `editor.getContents()` instead. " +
79
+ "See: https://github.com/zenoamaro/react-quill#using-deltas");
80
+ }
81
+ shouldComponentUpdate(nextProps, nextState) {
82
+ this.validateProps(nextProps);
83
+ // If the editor hasn't been instantiated yet, or the component has been
84
+ // regenerated, we already know we should update.
85
+ if (!this.editor || this.state.generation !== nextState.generation) {
86
+ return true;
87
+ }
88
+ // Handle value changes in-place
89
+ if ("value" in nextProps) {
90
+ const prevContents = this.getEditorContents();
91
+ const nextContents = nextProps.value ?? "";
92
+ // NOTE: Seeing that Quill is missing a way to prevent edits, we have to
93
+ // settle for a hybrid between controlled and uncontrolled mode. We
94
+ // can't prevent the change, but we'll still override content
95
+ // whenever `value` differs from current state.
96
+ // NOTE: Comparing an HTML string and a Quill Delta will always trigger a
97
+ // change, regardless of whether they represent the same document.
98
+ if (!this.isEqualValue(nextContents, prevContents)) {
99
+ this.setEditorContents(this.editor, nextContents);
100
+ }
101
+ }
102
+ // Handle read-only changes in-place
103
+ if (nextProps.readOnly !== this.props.readOnly) {
104
+ this.setEditorReadOnly(this.editor, nextProps.readOnly);
105
+ }
106
+ // Clean and Dirty props require a render
107
+ return [...this.cleanProps, ...this.dirtyProps].some((prop) => {
108
+ return !(0, isEqual_1.default)(nextProps[prop], this.props[prop]);
109
+ });
110
+ }
111
+ shouldComponentRegenerate(nextProps) {
112
+ // Whenever a `dirtyProp` changes, the editor needs reinstantiation.
113
+ return this.dirtyProps.some((prop) => {
114
+ return !(0, isEqual_1.default)(nextProps[prop], this.props[prop]);
115
+ });
116
+ }
117
+ componentDidMount() {
118
+ this.instantiateEditor();
119
+ this.setEditorContents(this.editor, this.getEditorContents());
120
+ }
121
+ componentWillUnmount() {
122
+ this.destroyEditor();
123
+ }
124
+ componentDidUpdate(prevProps, prevState) {
125
+ // If we're changing one of the `dirtyProps`, the entire Quill Editor needs
126
+ // to be re-instantiated. Regenerating the editor will cause the whole tree,
127
+ // including the container, to be cleaned up and re-rendered from scratch.
128
+ // Store the contents so they can be restored later.
129
+ if (this.editor && this.shouldComponentRegenerate(prevProps)) {
130
+ const delta = this.editor.getContents();
131
+ const selection = this.editor.getSelection();
132
+ this.regenerationSnapshot = { delta, selection };
133
+ this.setState({ generation: this.state.generation + 1 });
134
+ this.destroyEditor();
135
+ }
136
+ // The component has been regenerated, so it must be re-instantiated, and
137
+ // its content must be restored to the previous values from the snapshot.
138
+ if (this.state.generation !== prevState.generation) {
139
+ const { delta, selection } = this.regenerationSnapshot;
140
+ delete this.regenerationSnapshot;
141
+ this.instantiateEditor();
142
+ const editor = this.editor;
143
+ editor.setContents(delta);
144
+ postpone(() => this.setEditorSelection(editor, selection));
145
+ }
146
+ }
147
+ instantiateEditor() {
148
+ if (this.editor) {
149
+ this.hookEditor(this.editor);
150
+ }
151
+ else {
152
+ this.editor = this.createEditor(this.getEditingArea(), this.getEditorConfig());
153
+ }
154
+ }
155
+ destroyEditor() {
156
+ if (!this.editor)
157
+ return;
158
+ this.unhookEditor(this.editor);
159
+ }
160
+ /*
161
+ We consider the component to be controlled if `value` is being sent in props.
162
+ */
163
+ isControlled() {
164
+ return "value" in this.props;
165
+ }
166
+ getEditorConfig() {
167
+ return {
168
+ bounds: this.props.bounds,
169
+ formats: this.props.formats,
170
+ modules: this.props.modules,
171
+ placeholder: this.props.placeholder,
172
+ readOnly: this.props.readOnly,
173
+ scrollingContainer: this.props.scrollingContainer,
174
+ tabIndex: this.props.tabIndex,
175
+ theme: this.props.theme,
176
+ };
177
+ }
178
+ getEditor() {
179
+ if (!this.editor)
180
+ throw new Error("Accessing non-instantiated editor");
181
+ return this.editor;
182
+ }
183
+ /**
184
+ Creates an editor on the given element. The editor will be passed the
185
+ configuration, have its events bound,
186
+ */
187
+ createEditor(element, config) {
188
+ const editor = new quill_1.default(element, config);
189
+ if (config.tabIndex != null) {
190
+ this.setEditorTabIndex(editor, config.tabIndex);
191
+ }
192
+ this.hookEditor(editor);
193
+ return editor;
194
+ }
195
+ hookEditor(editor) {
196
+ // Expose the editor on change events via a weaker, unprivileged proxy
197
+ // object that does not allow accidentally modifying editor state.
198
+ this.unprivilegedEditor = this.makeUnprivilegedEditor(editor);
199
+ // Using `editor-change` allows picking up silent updates, like selection
200
+ // changes on typing.
201
+ editor.on("editor-change", this.onEditorChange);
202
+ }
203
+ unhookEditor(editor) {
204
+ editor.off("editor-change", this.onEditorChange);
205
+ }
206
+ getEditorContents() {
207
+ return this.value;
208
+ }
209
+ getEditorSelection() {
210
+ return this.selection;
211
+ }
212
+ /*
213
+ True if the value is a Delta instance or a Delta look-alike.
214
+ */
215
+ isDelta(value) {
216
+ return value && value.ops;
217
+ }
218
+ /*
219
+ Special comparison function that knows how to compare Deltas.
220
+ */
221
+ isEqualValue(value, nextValue) {
222
+ if (this.isDelta(value) && this.isDelta(nextValue)) {
223
+ return (0, isEqual_1.default)(value.ops, nextValue.ops);
224
+ }
225
+ else {
226
+ return (0, isEqual_1.default)(value, nextValue);
227
+ }
228
+ }
229
+ /*
230
+ Replace the contents of the editor, but keep the previous selection hanging
231
+ around so that the cursor won't move.
232
+ */
233
+ setEditorContents(editor, value) {
234
+ this.value = value;
235
+ //const sel = this.getEditorSelection();
236
+ if (typeof value === "string") {
237
+ editor.setContents(editor.clipboard.convert({ html: value }));
238
+ }
239
+ else {
240
+ editor.setContents(value);
241
+ }
242
+ // THIS STEALS FOCUS!
243
+ // postpone(() => this.setEditorSelection(editor, sel));
244
+ }
245
+ setEditorSelection(editor, range) {
246
+ this.selection = range;
247
+ if (range) {
248
+ // Validate bounds before applying.
249
+ const length = editor.getLength();
250
+ range.index = Math.max(0, Math.min(range.index, length - 1));
251
+ range.length = Math.max(0, Math.min(range.length, length - 1 - range.index));
252
+ editor.setSelection(range);
253
+ }
254
+ }
255
+ setEditorTabIndex(editor, tabIndex) {
256
+ if (editor?.scroll?.domNode) {
257
+ editor.scroll.domNode.tabIndex = tabIndex;
258
+ }
259
+ }
260
+ setEditorReadOnly(editor, value) {
261
+ if (value) {
262
+ editor.disable();
263
+ }
264
+ else {
265
+ editor.enable();
266
+ }
267
+ }
268
+ /*
269
+ Returns a weaker, unprivileged proxy object that only exposes read-only
270
+ accessors found on the editor instance, without any state-modifying methods.
271
+ */
272
+ makeUnprivilegedEditor(editor) {
273
+ const e = editor;
274
+ return {
275
+ getHTML: () => e.root.innerHTML,
276
+ getLength: e.getLength.bind(e),
277
+ getText: e.getText.bind(e),
278
+ getContents: e.getContents.bind(e),
279
+ getSelection: e.getSelection.bind(e),
280
+ getBounds: e.getBounds.bind(e),
281
+ };
282
+ }
283
+ getEditingArea() {
284
+ if (!this.editingAreaRef.current) {
285
+ throw new Error("Editing area is not available");
286
+ }
287
+ return this.editingAreaRef.current;
288
+ }
289
+ /*
290
+ Renders an editor area, unless it has been provided one to clone.
291
+ */
292
+ renderEditingArea() {
293
+ const { children, preserveWhitespace } = this.props;
294
+ const { generation } = this.state;
295
+ if (react_1.default.Children.count(children)) {
296
+ return react_1.default.cloneElement(react_1.default.Children.only(children), {
297
+ ref: this.editingAreaRef,
298
+ });
299
+ }
300
+ return preserveWhitespace ? ((0, jsx_runtime_1.jsx)("pre", { ref: this.editingAreaRef }, generation)) : ((0, jsx_runtime_1.jsx)("div", { ref: this.editingAreaRef }, generation));
301
+ }
302
+ render() {
303
+ return ((0, jsx_runtime_1.jsx)("div", { id: this.props.id, style: this.props.style, className: `quill ${this.props.className ?? ""}`, onKeyPress: this.props.onKeyPress, onKeyDownCapture: this.props.onKeyDown, onKeyUp: this.props.onKeyUp, children: this.renderEditingArea() }, this.state.generation));
304
+ }
305
+ onEditorChangeText(value, delta, source, editor) {
306
+ if (!this.editor)
307
+ return;
308
+ // We keep storing the same type of value as what the user gives us,
309
+ // so that value comparisons will be more stable and predictable.
310
+ const nextContents = this.isDelta(this.value)
311
+ ? editor.getContents()
312
+ : editor.getHTML();
313
+ if (nextContents !== this.getEditorContents()) {
314
+ // Taint this `delta` object, so we can recognize whether the user
315
+ // is trying to send it back as `value`, preventing a likely loop.
316
+ this.lastDeltaChangeSet = delta;
317
+ this.value = nextContents;
318
+ this.props.onChange?.(value, delta, source, editor);
319
+ }
320
+ }
321
+ onEditorChangeSelection(nextSelection, source, editor) {
322
+ if (!this.editor)
323
+ return;
324
+ const currentSelection = this.getEditorSelection();
325
+ const hasGainedFocus = !currentSelection && nextSelection;
326
+ const hasLostFocus = currentSelection && !nextSelection;
327
+ if ((0, isEqual_1.default)(nextSelection, currentSelection))
328
+ return;
329
+ this.selection = nextSelection;
330
+ this.props.onChangeSelection?.(nextSelection, source, editor);
331
+ if (hasGainedFocus) {
332
+ this.props.onFocus?.(nextSelection, source, editor);
333
+ }
334
+ else if (hasLostFocus) {
335
+ this.props.onBlur?.(currentSelection, source, editor);
336
+ }
337
+ }
338
+ focus() {
339
+ if (!this.editor)
340
+ return;
341
+ this.editor.focus();
342
+ }
343
+ blur() {
344
+ if (!this.editor)
345
+ return;
346
+ this.selection = null;
347
+ this.editor.blur();
348
+ }
349
+ }
350
+ exports.ReactQuill = ReactQuill;
351
+ ReactQuill.displayName = "React Quill";
352
+ /*
353
+ Export Quill to be able to call `register`
354
+ */
355
+ ReactQuill.Quill = quill_1.default;
356
+ ReactQuill.defaultProps = {
357
+ theme: "snow",
358
+ modules: {},
359
+ readOnly: false,
360
+ };
361
+ /*
362
+ Small helper to execute a function in the next micro-tick.
363
+ */
364
+ function postpone(fn) {
365
+ Promise.resolve().then(fn);
366
+ }
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.RichTextEditor = RichTextEditor;
41
+ const jsx_runtime_1 = require("react/jsx-runtime");
42
+ const dynamic_1 = __importDefault(require("next/dynamic"));
43
+ const RichTextEditorComponent = (0, dynamic_1.default)(() => Promise.resolve().then(() => __importStar(require("./RichTextEditorComponent"))).then((dnd) => dnd.RichTextEditorComponent), { ssr: false });
44
+ function RichTextEditor({ field, readOnly, }) {
45
+ return (0, jsx_runtime_1.jsx)(RichTextEditorComponent, { field: field, readOnly: readOnly });
46
+ }
@@ -0,0 +1,72 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RichTextEditorComponent = RichTextEditorComponent;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const editContext_1 = require("../client/editContext");
7
+ const use_debounce_1 = require("use-debounce");
8
+ const react_1 = require("react");
9
+ const ReactQuill_1 = require("./ReactQuill");
10
+ require("react-quill-new/dist/quill.snow.css");
11
+ const utils_1 = require("primereact/utils");
12
+ function RichTextEditorComponent({ field, readOnly, }) {
13
+ const editContextRef = (0, editContext_1.useEditContextRef)();
14
+ const modifiedFieldsContext = (0, editContext_1.useModifiedFieldsContext)();
15
+ const state = (0, react_1.useRef)({ focus: false });
16
+ const inputRef = (0, react_1.useRef)(null);
17
+ if (!editContextRef.current)
18
+ return;
19
+ const [value, setValue] = (0, react_1.useState)(field.value);
20
+ const fieldItem = field.descriptor.item;
21
+ if (!fieldItem)
22
+ return;
23
+ const modifiedField = modifiedFieldsContext?.modifiedFields.find((x) => x.fieldId === field.id &&
24
+ x.item.id === fieldItem.id &&
25
+ x.item.language === fieldItem.language &&
26
+ x.item.version === fieldItem.version);
27
+ (0, react_1.useEffect)(() => {
28
+ if (!state.current.focus ||
29
+ !document.activeElement?.classList.contains("ql-editor")) {
30
+ if (field.isHistoric)
31
+ setValue(field.value);
32
+ else
33
+ setValue(modifiedField?.value ?? field.value);
34
+ }
35
+ }, [field.value, modifiedFieldsContext?.modifiedFields]);
36
+ const debouncedSetFieldvalue = (0, use_debounce_1.useThrottledCallback)((value) => {
37
+ editContextRef.current?.operations.editField({
38
+ field: field.descriptor,
39
+ value: value,
40
+ refresh: "none",
41
+ });
42
+ }, editContextRef.current?.configuration.debounceFieldEditsInterval);
43
+ const handleChange = (newValue) => {
44
+ if (newValue === "<p><br></p>" && !field.value)
45
+ return;
46
+ if (newValue !== value && state.current.focus && !readOnly) {
47
+ setValue(newValue);
48
+ debouncedSetFieldvalue(newValue);
49
+ }
50
+ };
51
+ return (
52
+ // Primereact 10.6.6: - Editor takes focus on value change
53
+ // <Editor
54
+ // className="focus-shadow"
55
+ // key={fieldItem.id + field.id + fieldItem.language + fieldItem.version}
56
+ // disabled={readOnly}
57
+ // value={value}
58
+ // style={{ width: "100%" }}
59
+ // // onTextChange={(e) => {
60
+ // // const val = e.htmlValue ?? "";
61
+ // // setValue(val);
62
+ // // debouncedSetFieldvalue(val);
63
+ // // }}
64
+ // />
65
+ (0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.classNames)(readOnly ? "bg-gray-100" : "bg-white", "focus-shadow"), children: (0, jsx_runtime_1.jsx)(ReactQuill_1.ReactQuill, { ref: inputRef, theme: "snow", value: value, onChange: handleChange, onFocus: () => {
66
+ setTimeout(() => {
67
+ state.current.focus = true;
68
+ }, 101);
69
+ }, onBlur: () => {
70
+ state.current.focus = false;
71
+ }, readOnly: readOnly }) }));
72
+ }