@alpaca-headless/alpaca-headless-nextjs 1.0.246 → 1.0.253

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 (115) hide show
  1. package/dist/editor.css +0 -4
  2. package/dist/esm/Editor.js +13 -0
  3. package/dist/esm/client-components/ClientLink.js +2 -1
  4. package/dist/esm/client-components/MultiComponentEditor.js +1 -1
  5. package/dist/esm/components/Image.js +1 -1
  6. package/dist/esm/components/Link.js +3 -5
  7. package/dist/esm/components/Picture.js +3 -4
  8. package/dist/esm/components/PictureEditor.js +1 -1
  9. package/dist/esm/components/PictureEditorWrapper.js +1 -0
  10. package/dist/esm/components/Placeholder.js +114 -90
  11. package/dist/esm/components/RichText.js +2 -3
  12. package/dist/esm/components/Slot.js +2 -2
  13. package/dist/esm/components/Text.js +2 -3
  14. package/dist/esm/components/Translate.js +4 -7
  15. package/dist/esm/components/TranslateEditorWrapper.js +7 -0
  16. package/dist/esm/editor/ContentTree.js +10 -4
  17. package/dist/esm/editor/DictionaryEditor.js +1 -1
  18. package/dist/esm/editor/EditFrame.js +1 -1
  19. package/dist/esm/editor/EditorClient.js +27 -15
  20. package/dist/esm/editor/EditorClientHost.js +2 -2
  21. package/dist/esm/editor/FieldList.js +2 -2
  22. package/dist/esm/editor/FieldListField.js +13 -64
  23. package/dist/esm/editor/FieldListFieldWithFallbacks.js +79 -0
  24. package/dist/esm/editor/PictureEditorDialog.js +1 -1
  25. package/dist/esm/editor/PlaceholderDropZone.js +1 -1
  26. package/dist/esm/editor/PreviewClient.js +1 -0
  27. package/dist/esm/editor/ai/AiPopup.js +2 -2
  28. package/dist/esm/editor/ai/AiTerminal.js +17 -5
  29. package/dist/esm/editor/ai/EditorAiTerminal.js +5 -0
  30. package/dist/esm/editor/component-designer/ComponentDesigner.js +7 -0
  31. package/dist/esm/editor/component-designer/ComponentDesignerAiTerminal.js +5 -0
  32. package/dist/esm/editor/component-designer/ComponentDesignerMenu.js +39 -0
  33. package/dist/esm/editor/component-designer/ComponentPreview.js +20 -0
  34. package/dist/esm/editor/component-designer/ComponentRenderingEditor.js +38 -0
  35. package/dist/esm/editor/component-designer/ComponentSelectionTree.js +56 -0
  36. package/dist/esm/editor/component-designer/componentDesignerContext.js +22 -0
  37. package/dist/esm/editor/config/config.js +81 -15
  38. package/dist/esm/editor/config/types.js +1 -0
  39. package/dist/esm/editor/fieldTypes/CheckboxEditor.js +1 -1
  40. package/dist/esm/editor/fieldTypes/DropLinkEditor.js +1 -1
  41. package/dist/esm/editor/fieldTypes/MultiLineText.js +1 -1
  42. package/dist/esm/editor/fieldTypes/RawEditor.js +1 -1
  43. package/dist/esm/editor/fieldTypes/RichTextEditorComponent.js +1 -1
  44. package/dist/esm/editor/fieldTypes/SingleLineText.js +2 -4
  45. package/dist/esm/editor/fieldTypes/TreeListEditor.js +1 -1
  46. package/dist/esm/editor/menubar/Menu.js +1 -1
  47. package/dist/esm/editor/services/aiService.js +20 -0
  48. package/dist/esm/editor/services/componentDesignerService.js +23 -0
  49. package/dist/esm/editor/services/contentService.js +2 -4
  50. package/dist/esm/editor/services/editService.js +1 -35
  51. package/dist/esm/editor/services/serviceHelper.js +45 -0
  52. package/dist/esm/editor/sidebar/ComponentPalette.js +1 -1
  53. package/dist/esm/editor/sidebar/MainContentTree.js +3 -3
  54. package/dist/esm/editor/sidebar/Sidebar.js +1 -1
  55. package/dist/esm/editor/sidebar/SidebarView.js +17 -13
  56. package/dist/esm/editor/sidebar/Workbox.js +1 -1
  57. package/dist/esm/editor/{ItemNameDialog.js → ui/ItemNameDialog.js} +3 -2
  58. package/dist/esm/index.js +3 -2
  59. package/dist/esm/loadRouteData.js +1 -22
  60. package/dist/esm/middleware/handleRequest.js +1 -1
  61. package/dist/esm/public.js +10 -0
  62. package/dist/esm/renderContext.js +49 -0
  63. package/dist/esm/renderings.js +87 -0
  64. package/dist/esm/translate.js +7 -0
  65. package/package.json +2 -1
  66. package/types/Editor.d.ts +9 -0
  67. package/types/components/Image.d.ts +2 -0
  68. package/types/components/Link.d.ts +3 -2
  69. package/types/components/LockedFieldIndicator.d.ts +1 -1
  70. package/types/components/Picture.d.ts +2 -1
  71. package/types/components/Placeholder.d.ts +5 -8
  72. package/types/components/RichText.d.ts +3 -1
  73. package/types/components/Slot.d.ts +3 -1
  74. package/types/components/Text.d.ts +3 -1
  75. package/types/components/Translate.d.ts +3 -1
  76. package/types/components/TranslateEditorWrapper.d.ts +3 -0
  77. package/types/editor/ContentTree.d.ts +2 -1
  78. package/types/editor/ContextMenu.d.ts +1 -1
  79. package/types/editor/EditorClient.d.ts +5 -6
  80. package/types/editor/EditorClientHost.d.ts +5 -8
  81. package/types/editor/FieldListField.d.ts +3 -1
  82. package/types/editor/FieldListFieldWithFallbacks.d.ts +8 -0
  83. package/types/editor/PreviewClient.d.ts +1 -0
  84. package/types/editor/ai/EditorAiTerminal.d.ts +4 -0
  85. package/types/editor/component-designer/ComponentDesigner.d.ts +1 -0
  86. package/types/editor/component-designer/ComponentDesignerAiTerminal.d.ts +1 -0
  87. package/types/editor/component-designer/ComponentDesignerMenu.d.ts +1 -0
  88. package/types/editor/component-designer/ComponentPreview.d.ts +1 -0
  89. package/types/editor/component-designer/ComponentRenderingEditor.d.ts +2 -0
  90. package/types/editor/component-designer/ComponentSelectionTree.d.ts +1 -0
  91. package/types/editor/component-designer/componentDesignerContext.d.ts +14 -0
  92. package/types/editor/config/config.d.ts +1 -1
  93. package/types/editor/{Editor.d.ts → config/types.d.ts} +7 -10
  94. package/types/editor/editContext.d.ts +5 -3
  95. package/types/editor/services/aiService.d.ts +8 -0
  96. package/types/editor/services/componentDesignerService.d.ts +2 -0
  97. package/types/editor/services/contentService.d.ts +1 -1
  98. package/types/editor/services/editService.d.ts +2 -6
  99. package/types/editor/services/serviceHelper.d.ts +7 -0
  100. package/types/editor/sidebar/MainContentTree.d.ts +2 -2
  101. package/types/editor/sidebar/Sidebar.d.ts +1 -1
  102. package/types/editor/sidebar/SidebarView.d.ts +1 -1
  103. package/types/editor/{ItemNameDialog.d.ts → ui/ItemNameDialog.d.ts} +1 -0
  104. package/types/index.d.ts +4 -2
  105. package/types/loadRouteData.d.ts +1 -0
  106. package/types/public.d.ts +12 -0
  107. package/types/renderContext.d.ts +41 -0
  108. package/types/renderings.d.ts +7 -0
  109. package/types/servertypes.d.ts +2 -0
  110. package/types/translate.d.ts +2 -0
  111. package/dist/esm/alpacaContext.js +0 -16
  112. package/dist/esm/editor/Editor.js +0 -15
  113. package/dist/esm/editor/index.js +0 -4
  114. package/types/alpacaContext.d.ts +0 -31
  115. package/types/editor/index.d.ts +0 -4
@@ -16,7 +16,7 @@ import { ProgressSpinner } from "primereact/progressspinner";
16
16
  import { Toast } from "primereact/toast";
17
17
  import { BlockUI } from "primereact/blockui";
18
18
  import { ConfirmDialog } from "primereact/confirmdialog";
19
- import { EditContextProvider, } from ".";
19
+ import { EditContextProvider } from "./editContext";
20
20
  import { useRouter, useSearchParams, usePathname } from "next/navigation";
21
21
  import { findComponent, getComponentById } from "./componentTreeHelper";
22
22
  import { executeRedo, executeUndo, executeEditOperation, createVersion, executeWorkflowCommand, executeFieldAction, validateItems, connectSocket, lockField, lockItems, unlockItems, getEditHistory, releaseFieldLocks, } from "./services/editService";
@@ -36,8 +36,12 @@ import { FieldEditorPopup } from "./FieldEditorPopup";
36
36
  import { Sidebar } from "./sidebar/Sidebar";
37
37
  import { Menu } from "./menubar/Menu";
38
38
  import { AiPopup } from "./ai/AiPopup";
39
- export function EditorClient({ page, dictionaryObject, editData, children, configuration, }) {
40
- var _a, _b;
39
+ import { getComponentDesignerContext } from "./component-designer/componentDesignerContext";
40
+ export function EditorClient({ context, children, configuration, }) {
41
+ var _a, _b, _c;
42
+ const page = context.page;
43
+ const dictionaryObject = context.dictionary;
44
+ //const editData = context.ed;
41
45
  const router = useRouter();
42
46
  const pathname = usePathname();
43
47
  const searchParams = useSearchParams();
@@ -47,10 +51,10 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
47
51
  const [dictionary, setDictionary] = useState(dictionaryObject);
48
52
  const [unresolvedDictionaryKeys, setUnresolvedDictionaryKeys] = useState([]);
49
53
  const [refreshCompletedFlag, setRefreshCompletedFlag] = useState(false);
54
+ const [editOperationExecutedFlag, setEditOperationExecutedFlag] = useState(false);
50
55
  //const [refreshing, setRefreshing] = useState(false);
51
56
  const [updateContentEditingFields, setUpdateContentEditingFields] = useState(false);
52
57
  const [dragObject, setDragObject] = useState();
53
- const [refreshTimer, setRefreshTimer] = useState();
54
58
  const [mediaResolver, setMediaResolver] = useState();
55
59
  const [mediaSelectorVisible, setMediaSelectorVisible] = useState(false);
56
60
  const [selectedMediaIdPath, setSelectedMediaIdPath] = useState("");
@@ -216,7 +220,7 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
216
220
  switchVersion(itemToLoad.version);
217
221
  return;
218
222
  }
219
- const result = yield getItem(itemToLoad, sessionId);
223
+ const result = yield getItem(itemToLoad);
220
224
  setSecondaryItem(result);
221
225
  setSelection([]);
222
226
  setEditHistory([]);
@@ -234,7 +238,7 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
234
238
  header: "Not logged in",
235
239
  message: "You are not logged in anymore. Proceed to login page?",
236
240
  accept: () => {
237
- window.location.href = editData.loginUrl;
241
+ //window.location.href = editData.loginUrl;
238
242
  },
239
243
  });
240
244
  showErrorToast(result);
@@ -278,16 +282,17 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
278
282
  requestRefresh(currentEditOperation.refreshAfterQuietPeriod
279
283
  ? "waitForQuietPeriod"
280
284
  : "immediate");
285
+ setEditOperationExecutedFlag((state) => !state);
281
286
  }
282
287
  });
283
288
  sync();
284
289
  }, [currentEditOperation]);
285
290
  const ensureLock = (field) => __awaiter(this, void 0, void 0, function* () {
286
- var _c;
291
+ var _d;
287
292
  if (!field || !field.item)
288
293
  return;
289
294
  const result = yield lockField(field.item, field.fieldId, sessionId);
290
- const status = yield ((_c = result.response) === null || _c === void 0 ? void 0 : _c.json());
295
+ const status = yield ((_d = result.response) === null || _d === void 0 ? void 0 : _d.json());
291
296
  if (status.success) {
292
297
  const existingField = getLiveFieldIfExists(field);
293
298
  if (!existingField)
@@ -365,6 +370,11 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
365
370
  loadHistory(page);
366
371
  sendClientInfo();
367
372
  }, [page]);
373
+ useEffect(() => {
374
+ if (searchParams.get("fullscreen")) {
375
+ setFullscreen(true);
376
+ }
377
+ }, []);
368
378
  function loadHistory(item) {
369
379
  return __awaiter(this, void 0, void 0, function* () {
370
380
  const operations = yield getEditHistory(item);
@@ -372,13 +382,13 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
372
382
  });
373
383
  }
374
384
  const requestRefresh = (mode) => {
385
+ const refreshTimer = globalThis.editorRefreshTimer;
375
386
  const doRefresh = () => {
376
- clearTimeout(refreshTimer);
377
387
  //setRefreshing(true);
378
388
  if (secondaryItem)
379
389
  loadItem(secondaryItem);
380
390
  router.refresh();
381
- setRefreshTimer(undefined);
391
+ globalThis.editorRefreshTimer = undefined;
382
392
  };
383
393
  if (mode === "immediate") {
384
394
  console.log("Immediate refresh requested");
@@ -390,14 +400,14 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
390
400
  clearTimeout(refreshTimer);
391
401
  }
392
402
  if (!refreshTimer || mode === "waitForQuietPeriod") {
393
- setRefreshTimer(setTimeout(() => {
403
+ globalThis.editorRefreshTimer = setTimeout(() => {
394
404
  console.log("refreshing");
395
405
  doRefresh();
396
- }, mode === "waitForQuietPeriod" ? 1200 : 700));
406
+ }, mode === "waitForQuietPeriod" ? 1200 : 700);
397
407
  }
398
408
  };
399
409
  useEffect(() => {
400
- if (fullscreen)
410
+ if (fullscreen && !searchParams.get("fullscreen"))
401
411
  setShowFullscreenHint(true);
402
412
  }, [fullscreen]);
403
413
  // function requestPageLock(page: Item) {
@@ -641,6 +651,7 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
641
651
  }
642
652
  const editContext = {
643
653
  configuration,
654
+ currentEditOperation,
644
655
  item: centerPanelView == "form" ? secondaryItem || page : page,
645
656
  renderedPage: children,
646
657
  sessionId: sessionId,
@@ -659,6 +670,7 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
659
670
  setDictionary,
660
671
  requestRefresh,
661
672
  refreshCompletedFlag,
673
+ editOperationExecutedFlag,
662
674
  unresolvedDictionaryKeys,
663
675
  setUnresolvedDictionaryKeys,
664
676
  updateContentEditingFields,
@@ -821,7 +833,6 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
821
833
  yield releaseFieldLocks(sessionId);
822
834
  }),
823
835
  executeWorkflowCommand: executeWorkflowCommandAndRefresh,
824
- editData,
825
836
  duplicateComponents: ({ componentIds, parent, placeholderName, }) => {
826
837
  const op = {
827
838
  type: "duplicate-components",
@@ -868,9 +879,10 @@ export function EditorClient({ page, dictionaryObject, editData, children, confi
868
879
  setFullscreen,
869
880
  editorContainerRef,
870
881
  },
882
+ componentDesignerContext: getComponentDesignerContext(),
871
883
  };
872
884
  const spinner = _jsx(ProgressSpinner, {});
873
- return (_jsx(EditContextProvider, { value: editContext, children: fullscreen ? (_jsxs("div", { onMouseMoveCapture: () => setTimeout(() => setShowFullscreenHint(false), 600), children: [children, showFullscreenHint && (_jsx("div", { className: "a-fixed a-left-1/2 a-top-3 a-transform \r\n -a-translate-x-1/2 a-p-12 a-bg-gray-200", children: "Press Ctrl + F11 to exit fullscreen mode" }))] })) : (_jsxs(_Fragment, { children: [_jsx(Toast, { ref: toast }), _jsxs(PrimeReactProvider, { children: [_jsx(ConfirmationDialog, { ref: confirmationDialogRef }), _jsx(ConfirmDialog, {}), _jsxs(BlockUI, { blocked: false, template: spinner, children: [_jsx(EditContextMenu, { ref: contextMenuRef }), _jsx(Menu, {}), _jsx(MainLayout, { content: ((_a = configuration.chrome.editor.centerPanelViews.find((x) => x.name === centerPanelView)) === null || _a === void 0 ? void 0 : _a.content) || "Unknown view " + centerPanelView, leftSidebar: _jsx(Sidebar, { views: (_b = configuration.chrome.editor.views) !== null && _b !== void 0 ? _b : [] }) })] }), _jsx(MediaSelector, { visible: mediaSelectorVisible, onHide: () => setMediaSelectorVisible(false), onMediaSelected: onMediaSelect, selectedIdPath: selectedMediaIdPath }), _jsx(PublishDialog, { visible: showPublishDialog, onHide: () => setShowPublishDialog(false), page: page,
885
+ return (_jsx(EditContextProvider, { value: editContext, children: fullscreen ? (_jsxs("div", { onMouseMoveCapture: () => setTimeout(() => setShowFullscreenHint(false), 600), children: [children, showFullscreenHint && (_jsx("div", { className: "a-fixed a-left-1/2 a-top-3 a-transform \r\n -a-translate-x-1/2 a-p-12 a-bg-gray-200", children: "Press Ctrl + F11 to exit fullscreen mode" }))] })) : (_jsxs(_Fragment, { children: [_jsx(Toast, { ref: toast }), _jsxs(PrimeReactProvider, { children: [_jsx(ConfirmationDialog, { ref: confirmationDialogRef }), _jsx(ConfirmDialog, {}), _jsxs(BlockUI, { blocked: false, template: spinner, children: [_jsx(EditContextMenu, { ref: contextMenuRef }), (_a = view.menuBar) !== null && _a !== void 0 ? _a : _jsx(Menu, {}), _jsx(MainLayout, { content: ((_b = configuration.chrome.editor.centerPanelViews.find((x) => x.name === centerPanelView)) === null || _b === void 0 ? void 0 : _b.content) || "Unknown view " + centerPanelView, leftSidebar: _jsx(Sidebar, { views: (_c = configuration.chrome.editor.views) !== null && _c !== void 0 ? _c : [] }) })] }), _jsx(MediaSelector, { visible: mediaSelectorVisible, onHide: () => setMediaSelectorVisible(false), onMediaSelected: onMediaSelect, selectedIdPath: selectedMediaIdPath }), _jsx(PublishDialog, { visible: showPublishDialog, onHide: () => setShowPublishDialog(false), page: page,
874
886
  // lockItems={lockItemsAndRefresh}
875
887
  // unlockItems={unlockItemsAndRefresh}
876
888
  executeWorkflowCommand: executeWorkflowCommandAndRefresh }), _jsx(AiPopup, { ref: aiPopupRef }), _jsx(FieldEditorPopup, { ref: fieldEditorPopupRef })] })] })) }));
@@ -3,10 +3,10 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
3
  import dynamic from "next/dynamic";
4
4
  import { configuration } from "./config/config";
5
5
  const EditorClient = dynamic(() => import("./EditorClient").then((dnd) => dnd.EditorClient), { ssr: false });
6
- export function EditorClientHost({ content, dictionaryObject, children, edit, clientBuilder, }) {
6
+ export function EditorClientHost({ context, clientBuilder, children, }) {
7
7
  const ClientBuilder = clientBuilder;
8
8
  const buildClient = (configuration) => {
9
- return (_jsx(EditorClient, { page: content, dictionaryObject: dictionaryObject, editData: edit, configuration: configuration, children: _jsx(_Fragment, { children: children }) }));
9
+ return (_jsx(EditorClient, { context: context, configuration: configuration, children: _jsx(_Fragment, { children: children }) }));
10
10
  };
11
11
  if (!ClientBuilder)
12
12
  return buildClient(configuration);
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from "react";
4
- import FieldListField from "./FieldListField";
5
4
  import { Section } from "./ui/Section";
6
5
  import { useEditContext } from "./editContext";
6
+ import { FieldListFieldWithFallbacks } from "./FieldListFieldWithFallbacks";
7
7
  export function FieldList({ fields, sections, validators, filter, simplified, }) {
8
8
  const editContext = useEditContext();
9
9
  const [liveFields, setLiveFields] = useState();
@@ -39,7 +39,7 @@ export function FieldList({ fields, sections, validators, filter, simplified, })
39
39
  sectionList.sort((a, b) => a[0]._editor.sectionSortOrder - b[0]._editor.sectionSortOrder);
40
40
  function getSectionFields(fields) {
41
41
  fields.sort((a, b) => a.sortOrder - b.sortOrder);
42
- return fields.map((field) => (_jsx(FieldListField, { field: field, simplified: simplified, validators: validators.filter((x) => x.fieldId === field.id) }, field.id)));
42
+ return fields.map((field) => (_jsx(FieldListFieldWithFallbacks, { field: field, simplified: simplified, validators: validators.filter((x) => x.fieldId === field.id) }, field.id)));
43
43
  }
44
44
  return (_jsx("div", { className: "a-h-fill-available", children: sectionList
45
45
  .map((x) => { var _a; return (_a = x[0]._editor) === null || _a === void 0 ? void 0 : _a.section; })
@@ -9,67 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { Tooltip } from "primereact/tooltip";
12
- import { useEditContext } from ".";
13
- import { useEffect, useRef, useState } from "react";
12
+ import { useEditContext } from "./editContext";
13
+ import { useRef, useState } from "react";
14
14
  import { WizardIcon } from "./ui/Icons";
15
15
  import { OverlayPanel } from "primereact/overlaypanel";
16
- import { loadFallbackChain } from "./services/editService";
17
- export default function FieldListField({ field, validators, simplified, title, }) {
18
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
16
+ export default function FieldListField({ field, validators, simplified, title, isFocusedField, showFallbackButton, }) {
17
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
19
18
  const editContext = useEditContext();
20
19
  if (!editContext)
21
20
  return;
22
- const ref = useRef(null);
23
21
  const fieldItem = field._editor.descriptor.item;
24
- const isFocusedField = ((_a = editContext === null || editContext === void 0 ? void 0 : editContext.focusedField) === null || _a === void 0 ? void 0 : _a.fieldId) === field.id &&
25
- editContext.focusedField.item.id === fieldItem.id &&
26
- editContext.focusedField.item.language === fieldItem.language;
27
22
  const [showRawValue, setShowRawValue] = useState(false);
28
23
  const generatorsOverlay = useRef(null);
29
- const [fallbackChain, setFallbackChain] = useState();
30
- const [showFallback, setShowFallback] = useState(false);
31
- useEffect(() => {
32
- var _a;
33
- if (ref.current && isFocusedField) {
34
- ref.current.scrollIntoView({
35
- behavior: "smooth",
36
- block: "center",
37
- inline: "center",
38
- });
39
- if ((_a = liveField._editor) === null || _a === void 0 ? void 0 : _a.isFallback) {
40
- loadFallback();
41
- }
42
- }
43
- }, [editContext.focusedField]);
44
- function loadFallback() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const chain = yield loadFallbackChain(field._editor.descriptor);
47
- const liveChain = chain.map((x) => editContext.getLiveField(x));
48
- setFallbackChain(liveChain);
49
- });
50
- }
51
- useEffect(() => {
52
- if (ref.current && isFocusedField) {
53
- ref.current.scrollIntoView({
54
- behavior: "smooth",
55
- block: "center",
56
- inline: "center",
57
- });
58
- }
59
- }, [editContext.focusedField]);
60
24
  const liveField = editContext.getLiveField(field);
61
- useEffect(() => {
62
- var _a;
63
- if ((_a = liveField._editor) === null || _a === void 0 ? void 0 : _a.isFallback) {
64
- editContext.requestRefresh("waitForQuietPeriod");
65
- }
66
- }, [fallbackChain === null || fallbackChain === void 0 ? void 0 : fallbackChain.map((x) => x.value).join("")]);
67
25
  function editButtonClicked(x) {
68
26
  return __awaiter(this, void 0, void 0, function* () {
69
27
  editContext === null || editContext === void 0 ? void 0 : editContext.triggerFieldAction(field, x);
70
28
  });
71
29
  }
72
- let classNames = "[&:not(:first-child)]:a-mt-5 a-flex a-items-stretch";
30
+ let classNames = " a-flex a-items-stretch";
73
31
  if (isFocusedField)
74
32
  classNames += " a-focused-field ";
75
33
  let validationBarClassNames = undefined;
@@ -84,10 +42,10 @@ export default function FieldListField({ field, validators, simplified, title, }
84
42
  });
85
43
  if ((executingAction === null || executingAction === void 0 ? void 0 : executingAction.state) == "running")
86
44
  classNames += " a-executing-action ";
87
- const isLocked = (((_b = liveField._editor) === null || _b === void 0 ? void 0 : _b.lockedBy) &&
88
- ((_d = (_c = liveField._editor) === null || _c === void 0 ? void 0 : _c.lockedBy) === null || _d === void 0 ? void 0 : _d.sessionId) != editContext.sessionId) ||
45
+ const isLocked = (((_a = liveField._editor) === null || _a === void 0 ? void 0 : _a.lockedBy) &&
46
+ ((_c = (_b = liveField._editor) === null || _b === void 0 ? void 0 : _b.lockedBy) === null || _c === void 0 ? void 0 : _c.sessionId) != editContext.sessionId) ||
89
47
  false;
90
- const isReadOnly = !((_e = field._editor) === null || _e === void 0 ? void 0 : _e.canWrite) || isLocked;
48
+ const isReadOnly = !((_d = field._editor) === null || _d === void 0 ? void 0 : _d.canWrite) || isLocked;
91
49
  const renderButtons = () => {
92
50
  var _a, _b, _c, _d;
93
51
  if (((_b = (_a = field._editor) === null || _a === void 0 ? void 0 : _a.buttons) === null || _b === void 0 ? void 0 : _b.length) || 0 > 0)
@@ -103,24 +61,15 @@ export default function FieldListField({ field, validators, simplified, title, }
103
61
  }, children: [x.icon && _jsx("i", { className: x.icon + " a-mr-2 a-text-xs" }), x.label] }, x.id))) })] }));
104
62
  return null;
105
63
  };
106
- return (_jsxs("div", { ref: ref, className: classNames, onClick: () => {
107
- var _a;
108
- editContext.setFocusedField((_a = field._editor) === null || _a === void 0 ? void 0 : _a.descriptor, true);
109
- }, children: [validationBarClassNames && (_jsxs(_Fragment, { children: [_jsx("div", { className: validationBarClassNames, id: "validation_" + field.id }), _jsx(Tooltip, { target: "#validation_" + field.id, children: validators
64
+ return (_jsxs("div", { className: classNames, children: [validationBarClassNames && (_jsxs(_Fragment, { children: [_jsx("div", { className: validationBarClassNames, id: "validation_" + field.id }), _jsx(Tooltip, { target: "#validation_" + field.id, children: validators
110
65
  .filter((x) => x.result > 1)
111
- .map((x) => (_jsx("div", { children: x.message }, x.validator))) })] })), _jsxs("div", { className: "a-flex-1", children: [_jsxs("div", { className: "a-flex a-justify-between", children: [_jsx("label", { className: "a-font-bold a-block a-mb-1 a-text-sm", children: title || ((_f = field._editor) === null || _f === void 0 ? void 0 : _f.name) }), _jsxs("div", { className: "a-flex a-gap-2", children: [renderButtons(), isLocked && (_jsxs("div", { className: "a-text-xs a-bg-pink-400 a-text-white a-p-1", children: ["locked by ", (_h = (_g = liveField._editor) === null || _g === void 0 ? void 0 : _g.lockedBy) === null || _h === void 0 ? void 0 : _h.user.name] }))] })] }), isFocusedField && (_jsxs("div", { className: "a-flex a-gap-3 a-gap-y-1 a-flex-wrap", children: [!((_j = field._editor) === null || _j === void 0 ? void 0 : _j.isFallback) &&
112
- ((_k = liveField._editor) === null || _k === void 0 ? void 0 : _k.rawValue) !== null ? (_jsxs("button", { className: "a-text-xs a-p-0 ", onClick: () => {
66
+ .map((x) => (_jsx("div", { children: x.message }, x.validator))) })] })), _jsxs("div", { className: "a-flex-1", children: [_jsxs("div", { className: "a-flex a-justify-between", children: [_jsx("label", { className: "a-font-bold a-block a-mb-1 a-text-sm", children: title || ((_e = field._editor) === null || _e === void 0 ? void 0 : _e.name) }), _jsxs("div", { className: "a-flex a-gap-2", children: [renderButtons(), isLocked && (_jsxs("div", { className: "a-text-xs a-bg-pink-400 a-text-white a-p-1", children: ["locked by ", (_g = (_f = liveField._editor) === null || _f === void 0 ? void 0 : _f.lockedBy) === null || _g === void 0 ? void 0 : _g.user.name] }))] })] }), isFocusedField && (_jsxs("div", { className: "a-flex a-gap-3 a-gap-y-1 a-flex-wrap", children: [!((_h = field._editor) === null || _h === void 0 ? void 0 : _h.isFallback) &&
67
+ ((_j = liveField._editor) === null || _j === void 0 ? void 0 : _j.rawValue) !== null ? (_jsxs("button", { className: "a-text-xs a-p-0 ", onClick: () => {
113
68
  editContext === null || editContext === void 0 ? void 0 : editContext.editField({ field: field, rawValue: null });
114
- }, children: ["Reset", " "] })) : (_jsxs("button", { className: "a-text-xs a-p-0", onClick: () => setShowFallback(!showFallback), children: [_jsx("i", { className: "a-text-xs pi " +
115
- (showFallback ? "pi-check-square" : "pi-stop") }), " ", "Fallback"] })), !simplified && (_jsxs("button", { className: "a-text-xs a-p-0", onClick: () => {
69
+ }, children: ["Reset", " "] })) : (showFallbackButton), !simplified && (_jsxs("button", { className: "a-text-xs a-p-0", onClick: () => {
116
70
  setShowRawValue(!showRawValue);
117
71
  }, children: [_jsx("i", { className: "a-text-xs pi " +
118
- (showRawValue ? "pi-check-square" : "pi-stop") }), " ", "Raw"] }))] })), (executingAction === null || executingAction === void 0 ? void 0 : executingAction.message) && (_jsx("div", { className: "a-text-xs a-p-0 a-mt-1 a-mb-1", children: executingAction === null || executingAction === void 0 ? void 0 : executingAction.message })), _jsx("div", { className: "a-text-xs a-p-0 a-mt-1", children: getFieldEditor(liveField, showRawValue, isReadOnly, editContext.configuration) }), liveField._editor.isFallback && isFocusedField && showFallback && (_jsxs("div", { children: [_jsx("div", { className: "a-text-center a-relative a-top-3.5", children: _jsx("i", { className: "pi pi-arrow-up a-text-xl a-font-bold a-text-blue-300 a-fallback-arrow-animation" }) }), fallbackChain &&
119
- fallbackChain.map((x, i) => {
120
- var _a, _b;
121
- return (_jsx("div", { className: "a-ml-3", children: _jsx(FieldListField, { field: x, validators: validators, simplified: true, title: _jsxs("div", { className: "a-text-xs", children: [(_a = x._editor) === null || _a === void 0 ? void 0 : _a.name, " (", x._editor.descriptor.item.language, ")", x._editor.descriptor.item.id !=
122
- ((_b = liveField._editor) === null || _b === void 0 ? void 0 : _b.descriptor.item.id) && (_jsxs("span", { className: "a-text-gray-400", children: ["- Item: ", x._editor.descriptor.item.id] }))] }) }, i) }));
123
- })] }))] })] }, field.id +
72
+ (showRawValue ? "pi-check-square" : "pi-stop") }), " ", "Raw"] }))] })), (executingAction === null || executingAction === void 0 ? void 0 : executingAction.message) && (_jsx("div", { className: "a-text-xs a-p-0 a-mt-1 a-mb-1", children: executingAction === null || executingAction === void 0 ? void 0 : executingAction.message })), _jsx("div", { className: "a-text-xs a-p-0 a-mt-1", children: getFieldEditor(liveField, showRawValue, isReadOnly, editContext.configuration) })] })] }, field.id +
124
73
  "_" +
125
74
  fieldItem.id +
126
75
  "_" +
@@ -0,0 +1,79 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { useEffect, useRef, useState } from "react";
12
+ import FieldListField from "./FieldListField";
13
+ import { useEditContext } from "./editContext";
14
+ import { loadFallbackChain } from "./services/editService";
15
+ export function FieldListFieldWithFallbacks({ field, validators, simplified, title, }) {
16
+ var _a;
17
+ const [showFallback, setShowFallback] = useState(false);
18
+ const [fallbackChain, setFallbackChain] = useState();
19
+ const ref = useRef(null);
20
+ const editContext = useEditContext();
21
+ if (!editContext)
22
+ return;
23
+ const liveField = editContext.getLiveField(field);
24
+ function isEditFieldOp(op) {
25
+ return (op === null || op === void 0 ? void 0 : op.type) === "edit-field";
26
+ }
27
+ function loadFallback(init) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const chain = yield loadFallbackChain(field._editor.descriptor);
30
+ const liveChain = chain.map((x) => editContext.getLiveField(x));
31
+ const currentEditOp = editContext.currentEditOperation;
32
+ liveChain.forEach((x, i) => {
33
+ if (init ||
34
+ !isEditFieldOp(currentEditOp) ||
35
+ currentEditOp.fieldId !== x.id ||
36
+ currentEditOp.item.id !== x._editor.descriptor.item.id ||
37
+ currentEditOp.item.language !== x._editor.descriptor.item.language) {
38
+ x._editor = chain[i]._editor;
39
+ x.value = chain[i].value;
40
+ x.jsonValue = chain[i].jsonValue;
41
+ }
42
+ });
43
+ setFallbackChain(liveChain);
44
+ });
45
+ }
46
+ const fieldItem = field._editor.descriptor.item;
47
+ const isFocusedField = ((_a = editContext === null || editContext === void 0 ? void 0 : editContext.focusedField) === null || _a === void 0 ? void 0 : _a.fieldId) === field.id &&
48
+ editContext.focusedField.item.id === fieldItem.id &&
49
+ editContext.focusedField.item.language === fieldItem.language;
50
+ useEffect(() => {
51
+ var _a;
52
+ if (ref.current && isFocusedField) {
53
+ ref.current.scrollIntoView({
54
+ behavior: "smooth",
55
+ block: "center",
56
+ inline: "center",
57
+ });
58
+ if ((_a = liveField._editor) === null || _a === void 0 ? void 0 : _a.isFallback) {
59
+ loadFallback(true);
60
+ }
61
+ }
62
+ }, [editContext.focusedField]);
63
+ useEffect(() => {
64
+ var _a;
65
+ if (((_a = liveField._editor) === null || _a === void 0 ? void 0 : _a.isFallback) && isFocusedField) {
66
+ loadFallback(false);
67
+ }
68
+ }, [editContext.editOperationExecutedFlag, editContext.refreshCompletedFlag]);
69
+ const showFallbackButton = (_jsxs("button", { className: "a-text-xs a-p-0", onClick: () => setShowFallback(!showFallback), children: [_jsx("i", { className: "a-text-xs pi " + (showFallback ? "pi-check-square" : "pi-stop") }), " ", "Fallback"] }));
70
+ return (_jsxs("div", { ref: ref, className: "[&:not(:first-child)]:a-mt-5", onClick: () => {
71
+ var _a;
72
+ editContext.setFocusedField((_a = field._editor) === null || _a === void 0 ? void 0 : _a.descriptor, true);
73
+ }, children: [_jsx(FieldListField, { field: field, validators: validators, simplified: simplified, title: title, isFocusedField: isFocusedField, showFallbackButton: showFallbackButton }), liveField._editor.isFallback && isFocusedField && showFallback && (_jsx(_Fragment, { children: fallbackChain &&
74
+ fallbackChain.slice(1).map((x, i) => {
75
+ var _a, _b;
76
+ return (_jsxs("div", { className: "a-ml-3", children: [_jsx("div", { className: "a-text-center", children: _jsx("i", { className: "pi pi-arrow-up a-text-xl a-font-bold a-text-blue-300 a-fallback-arrow-animation a-relative a-top-3" }) }), _jsx(FieldListField, { field: x, validators: validators, simplified: true, isFocusedField: true, title: _jsxs("div", { className: "a-text-xs", children: [(_a = x._editor) === null || _a === void 0 ? void 0 : _a.name, " (", x._editor.descriptor.item.language, ")", x._editor.descriptor.item.id !=
77
+ ((_b = liveField._editor) === null || _b === void 0 ? void 0 : _b.descriptor.item.id) && (_jsxs("span", { className: "a-text-gray-400", children: ["- Item: ", x._editor.descriptor.item.id] }))] }) }, i)] }, i));
78
+ }) }))] }, field.id));
79
+ }
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
11
  import { Dialog } from "primereact/dialog";
12
- import { useEditContext } from ".";
12
+ import { useEditContext } from "./editContext";
13
13
  import { useCallback, useEffect, useState } from "react";
14
14
  import { Button } from "primereact/button";
15
15
  import DialogButtons from "./DialogButtons";
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { ProgressBar } from "primereact/progressbar";
5
- import { useEditContext } from ".";
5
+ import { useEditContext } from "./editContext";
6
6
  import { classNames } from "primereact/utils";
7
7
  import ReactDOM from "react-dom";
8
8
  import { useOutlineContext } from "./Outline";
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { PreviewContextProvider } from "./previewContext";
3
+ import "../../editor.css";
3
4
  export function PreviewClient({ children }) {
4
5
  return (_jsxs(PreviewContextProvider, { value: {}, children: [children, _jsxs("div", { className: "a-fixed a-right-2 a-bottom-1 a-text-opacity-50 a-cursor-default a-text-xs a-flex a-items-center a-text-gray-500 a-gap-2", children: [_jsx("i", { className: "pi pi-eye a-text-gray-100" }), " Preview"] })] }));
5
6
  }
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { OverlayPanel } from "primereact/overlaypanel";
4
- import { AiTerminal } from "./AiTerminal";
5
4
  import { Button } from "primereact/button";
6
5
  import { forwardRef, useImperativeHandle, useRef } from "react";
6
+ import { EditorAiTerminal } from "./EditorAiTerminal";
7
7
  export const AiPopup = forwardRef((_, ref) => {
8
8
  const overlayRef = useRef(null);
9
9
  //const [components, setComponents] = useState<ComponentData[]>([]); // [componentId, componentId, ...]
@@ -18,7 +18,7 @@ export const AiPopup = forwardRef((_, ref) => {
18
18
  (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.hide();
19
19
  },
20
20
  }));
21
- return (_jsx(OverlayPanel, { ref: overlayRef, children: _jsx("div", { className: "a-w-96 a-h-96 a-flex a-flex-col a-gap-2", onClick: (ev) => ev.stopPropagation(), children: _jsx(AiTerminal
21
+ return (_jsx(OverlayPanel, { ref: overlayRef, children: _jsx("div", { className: "a-w-96 a-h-96 a-flex a-flex-col a-gap-2", onClick: (ev) => ev.stopPropagation(), children: _jsx(EditorAiTerminal
22
22
  //selection={components?.map((x) => x.id)}
23
23
  //newEditOperations={(ops) => setOperations([...operations, ...ops])}
24
24
  , {
@@ -15,10 +15,11 @@ import { useRouter, useSearchParams } from "next/navigation";
15
15
  import { Terminal } from "../Terminal";
16
16
  import { useEditContext } from "../editContext";
17
17
  import { Dropdown } from "primereact/dropdown";
18
- import { getSelectedText } from "../utils";
18
+ import { getItemDescriptor, getSelectedText } from "../utils";
19
19
  import Cookies from "universal-cookie";
20
20
  import { WizardIcon } from "../ui/Icons";
21
21
  import { AiResponseMessage } from "./AiResponseMessage";
22
+ import { loadAiConfig } from "../services/aiService";
22
23
  export function AiTerminal({ closeButton }) {
23
24
  const searchParams = useSearchParams();
24
25
  const editContext = useEditContext();
@@ -29,7 +30,17 @@ export function AiTerminal({ closeButton }) {
29
30
  const [response, setResponse] = useState();
30
31
  const [model, setModel] = useState("gpt-3.5-turbo-0125");
31
32
  const [prompt, setPrompt] = useState("");
33
+ const [config, setConfig] = useState();
32
34
  const selection = editContext.selection;
35
+ useEffect(() => {
36
+ function fetchConfig() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const config = yield loadAiConfig(getItemDescriptor(editContext.page));
39
+ setConfig(config);
40
+ });
41
+ }
42
+ fetchConfig();
43
+ }, []);
33
44
  const messagesRef = useRef(messages);
34
45
  useEffect(() => {
35
46
  messagesRef.current = messages;
@@ -111,10 +122,11 @@ export function AiTerminal({ closeButton }) {
111
122
  setResponse(undefined);
112
123
  }, infobar: (response === null || response === void 0 ? void 0 : response.numInputTokens) && (_jsxs("div", { className: "a-text-gray-400 a-text-right", style: { fontSize: "10px" }, children: ["Tokens in: ", response === null || response === void 0 ? void 0 : response.numInputTokens, " out:", " ", response === null || response === void 0 ? void 0 : response.numOutputTokens, " ", response === null || response === void 0 ? void 0 : response.state, " "] })), prompt: prompt, setPrompt: setPrompt, statusbar: _jsxs("div", { className: "a-flex a-items-center a-justify-between a-gap-1", children: [_jsxs("a", { className: "a-text-xs a-text-blue-300 a-cursor-pointer a-flex a-items-center a-gap-1", onClick: () => {
113
124
  setShowPredefined(!showPredefined);
114
- }, children: [_jsx(WizardIcon, { className: "a-w-5 a-h-5" }), "Predefined prompts"] }), showPredefined && (_jsx("div", { className: "a-absolute a-right-0 a-left-0 a-bottom-8 a-text-sm a-overflow-y-auto a-bg-white a-p-3 a-pb-1 a-flex a-flex-col a-gap-1 ", children: editContext.editData.aiPrompts.map((p, index) => (_jsx("div", { className: "a-p-1.5 a-mb-1 a-border a-border-gray-200 a-rounded-lg a-cursor-pointer a-text-gray-700 a-text-xs", onClick: () => {
115
- setPrompt(p.prompt);
116
- setShowPredefined(false);
117
- }, children: p.title }, index))) }))] }), toolbar: _jsxs("div", { className: "a-flex a-items-center", children: [_jsx(Dropdown, { className: "a-text-sm", value: model, onChange: (e) => setModel(e.value), options: [
125
+ }, children: [_jsx(WizardIcon, { className: "a-w-5 a-h-5" }), "Predefined prompts"] }), showPredefined && (_jsx("div", { className: "a-absolute a-right-0 a-left-0 a-bottom-8 a-text-sm a-overflow-y-auto a-bg-white a-p-3 a-pb-1 a-flex a-flex-col a-gap-1 ", children: config &&
126
+ config.prompts.map((p, index) => (_jsx("div", { className: "a-p-1.5 a-mb-1 a-border a-border-gray-200 a-rounded-lg a-cursor-pointer a-text-gray-700 a-text-xs", onClick: () => {
127
+ setPrompt(p.prompt);
128
+ setShowPredefined(false);
129
+ }, children: p.title }, index))) }))] }), toolbar: _jsxs("div", { className: "a-flex a-items-center", children: [_jsx(Dropdown, { className: "a-text-sm", value: model, onChange: (e) => setModel(e.value), options: [
118
130
  "gpt-3.5-turbo-0125",
119
131
  "gpt-4-0125-preview",
120
132
  "gpt-3.5-turbo-1106",
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AiTerminal } from "./AiTerminal";
3
+ export function EditorAiTerminal({ closeButton, }) {
4
+ return _jsx(AiTerminal, { closeButton: closeButton });
5
+ }
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ComponentPreview } from "./ComponentPreview";
3
+ import { ComponentRenderingEditor } from "./ComponentRenderingEditor";
4
+ import { Splitter, SplitterPanel } from "primereact/splitter";
5
+ export function ComponentDesigner() {
6
+ return (_jsxs(Splitter, { className: "a-h-full", children: [_jsx(SplitterPanel, { children: _jsx(ComponentRenderingEditor, {}) }), _jsx(SplitterPanel, { children: _jsx(ComponentPreview, {}) })] }));
7
+ }
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AiTerminal } from "../ai/AiTerminal";
3
+ export function ComponentDesignerAiTerminal() {
4
+ return _jsx(AiTerminal, {});
5
+ }
@@ -0,0 +1,39 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { Menubar } from "primereact/menubar";
12
+ import { useComponentDesignerContext } from "./componentDesignerContext";
13
+ import { createNewComponent } from "../services/componentDesignerService";
14
+ import ItemNameDialog from "../ui/ItemNameDialog";
15
+ import { useRef } from "react";
16
+ export function ComponentDesignerMenu() {
17
+ const context = useComponentDesignerContext();
18
+ if (!context)
19
+ return;
20
+ const menuItems = [
21
+ {
22
+ label: "New Component",
23
+ icon: "pi pi-fw pi-plus",
24
+ command: () => createNew(),
25
+ disabled: !context.componentRenderingFolder,
26
+ },
27
+ ];
28
+ const itemNameDialogRef = useRef(null);
29
+ const createNew = () => __awaiter(this, void 0, void 0, function* () {
30
+ var _a;
31
+ (_a = itemNameDialogRef.current) === null || _a === void 0 ? void 0 : _a.show({
32
+ title: "Choose component name",
33
+ accept: (name) => __awaiter(this, void 0, void 0, function* () {
34
+ yield createNewComponent(context.componentRenderingFolder, name);
35
+ }),
36
+ });
37
+ });
38
+ return (_jsxs(_Fragment, { children: [_jsx(Menubar, { model: menuItems, className: "a-p-1 a-text-sm a-rounded-none a-border-0 a-border-b a-bg-gray-50" }), _jsx(ItemNameDialog, { ref: itemNameDialogRef })] }));
39
+ }
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { usePathname } from "next/navigation";
3
+ import { useComponentDesignerContext } from "./componentDesignerContext";
4
+ import { useEffect, useState } from "react";
5
+ import { useEditContext } from "../editContext";
6
+ export function ComponentPreview() {
7
+ const context = useComponentDesignerContext();
8
+ const editContext = useEditContext();
9
+ if (!context)
10
+ return null;
11
+ const pathname = usePathname();
12
+ // State to hold the iframe src URL
13
+ const [iframeSrc, setIframeSrc] = useState("");
14
+ useEffect(() => {
15
+ var _a;
16
+ const newSrc = `${pathname}?itemid=${(_a = context.sampleItem) === null || _a === void 0 ? void 0 : _a.id}&language=en&mode=edit&codeVersion=${Date.now()}&fullscreen=true`;
17
+ setIframeSrc(newSrc);
18
+ }, [editContext === null || editContext === void 0 ? void 0 : editContext.editOperationExecutedFlag]);
19
+ return (_jsx("iframe", { className: "a-w-full a-h-full", src: iframeSrc, title: "Component Preview" }));
20
+ }
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import dynamic from "next/dynamic";
3
+ import "@uiw/react-textarea-code-editor/dist.css";
4
+ import { useEffect } from "react";
5
+ import { useComponentDesignerContext } from "./componentDesignerContext";
6
+ import { useEditContext } from "../editContext";
7
+ const CodeEditor = dynamic(() => import("@uiw/react-textarea-code-editor").then((mod) => mod.default), { ssr: false });
8
+ export function ComponentRenderingEditor() {
9
+ const context = useComponentDesignerContext();
10
+ if (!context)
11
+ return null;
12
+ const editContext = useEditContext();
13
+ if (!editContext)
14
+ return null;
15
+ useEffect(() => {
16
+ var _a, _b, _c;
17
+ context.setCode(((_c = (_b = (_a = context.componentRenderingItem) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.value) || "");
18
+ }, [context.componentRenderingItem]);
19
+ useEffect(() => {
20
+ const timeout = setTimeout(() => {
21
+ if (context.componentRenderingItem) {
22
+ context.componentRenderingItem.fields.code.value = context.code;
23
+ editContext.editField({
24
+ field: context.componentRenderingItem.fields.code,
25
+ value: context.code,
26
+ });
27
+ }
28
+ }, 600);
29
+ return () => clearTimeout(timeout);
30
+ }, [context.code]);
31
+ if (!context.componentRenderingItem)
32
+ return null;
33
+ return (_jsx("div", { children: _jsx(CodeEditor, { value: context.code, language: "js", placeholder: "Please enter TSX code.", onChange: (evn) => context.setCode(evn.target.value), padding: 15, style: {
34
+ fontSize: 12,
35
+ backgroundColor: "#f5f5f5",
36
+ fontFamily: "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace",
37
+ } }) }));
38
+ }