@alpaca-headless/alpaca-headless-nextjs 1.0.26 → 1.0.128

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 (238) hide show
  1. package/dist/cjs/client-components/ClientLink.js +36 -0
  2. package/dist/cjs/client-components/MultiComponentEditor.js +26 -0
  3. package/dist/cjs/client-components/index.js +19 -0
  4. package/dist/cjs/components/Link.js +1 -1
  5. package/dist/cjs/components/LinkEditor.js +47 -1
  6. package/dist/cjs/components/Picture.js +14 -12
  7. package/dist/cjs/components/PictureEditor.js +22 -18
  8. package/dist/cjs/components/Placeholder.js +51 -9
  9. package/dist/cjs/components/RichText.js +1 -1
  10. package/dist/cjs/components/RichTextEditor.js +17 -2
  11. package/dist/cjs/components/TextEditor.js +15 -3
  12. package/dist/cjs/components/Translate.js +1 -1
  13. package/dist/cjs/{editor → components}/TranslateEditor.js +5 -2
  14. package/dist/cjs/editor/AiPopup.js +33 -0
  15. package/dist/cjs/editor/AiTerminal.js +42 -18
  16. package/dist/cjs/editor/ComponentInfo.js +4 -3
  17. package/dist/cjs/editor/ComponentPalette.js +12 -68
  18. package/dist/cjs/editor/ComponentTree.js +76 -59
  19. package/dist/cjs/editor/ConfirmationDialog.js +31 -0
  20. package/dist/cjs/editor/ContentTree.js +144 -49
  21. package/dist/cjs/editor/Debug.js +12 -2
  22. package/dist/cjs/editor/DialogButtons.js +7 -0
  23. package/dist/cjs/editor/DictionaryEditor.js +14 -8
  24. package/dist/cjs/editor/EditFrame.js +88 -20
  25. package/dist/cjs/editor/EditHistory.js +17 -4
  26. package/dist/cjs/editor/Editor.js +1 -1
  27. package/dist/cjs/editor/EditorClient.js +506 -237
  28. package/dist/cjs/editor/EditorClientHost.js +2 -2
  29. package/dist/cjs/editor/FieldList.js +30 -43
  30. package/dist/cjs/editor/FieldListField.js +75 -0
  31. package/dist/cjs/editor/FloatingToolbar.js +92 -0
  32. package/dist/cjs/editor/GraphQL.js +4 -6
  33. package/dist/cjs/editor/ItemEditor.js +9 -0
  34. package/dist/cjs/editor/ItemInfo.js +17 -0
  35. package/dist/cjs/editor/ItemNameDialog.js +37 -0
  36. package/dist/cjs/editor/LanguageSelector.js +1 -1
  37. package/dist/cjs/editor/LinkEditorDialog.js +67 -0
  38. package/dist/cjs/editor/MainLayout.js +24 -0
  39. package/dist/cjs/editor/MediaSelector.js +44 -13
  40. package/dist/cjs/editor/PictureEditorDialog.js +93 -0
  41. package/dist/cjs/editor/PlaceholderDropZone.js +48 -9
  42. package/dist/cjs/editor/SidebarTabs.js +47 -0
  43. package/dist/cjs/editor/Terminal.js +21 -11
  44. package/dist/cjs/editor/Utils.js +43 -0
  45. package/dist/cjs/editor/VersionSelector.js +1 -1
  46. package/dist/cjs/editor/Workbox.js +41 -0
  47. package/dist/cjs/editor/componentCommands.js +141 -0
  48. package/dist/cjs/editor/contentService.js +45 -3
  49. package/dist/cjs/editor/editContext.js +9 -4
  50. package/dist/cjs/editor/editService.js +187 -3
  51. package/dist/cjs/editor/fieldTypes/CheckboxEditor.js +21 -0
  52. package/dist/cjs/editor/fieldTypes/InternalLinkFieldEditor.js +46 -0
  53. package/dist/cjs/editor/fieldTypes/LinkFieldEditor.js +55 -0
  54. package/dist/cjs/editor/fieldTypes/MultiLineText.js +25 -0
  55. package/dist/cjs/editor/fieldTypes/PictureFieldEditor.js +19 -0
  56. package/dist/cjs/editor/fieldTypes/RichTextEditor.js +9 -4
  57. package/dist/cjs/editor/fieldTypes/SingleLineText.js +12 -4
  58. package/dist/cjs/editor/fieldTypes/TreeListEditor.js +59 -0
  59. package/dist/cjs/editor/ui/Section.js +8 -0
  60. package/dist/cjs/loadRouteData.js +24 -14
  61. package/dist/cjs/middleware/authorization.js +52 -0
  62. package/dist/cjs/middleware/index.js +17 -0
  63. package/dist/editor.css +552 -74
  64. package/dist/primereact/resources/themes/arya-blue/theme.css +103 -91
  65. package/dist/primereact/resources/themes/arya-green/theme.css +103 -91
  66. package/dist/primereact/resources/themes/arya-orange/theme.css +103 -91
  67. package/dist/primereact/resources/themes/arya-purple/theme.css +103 -91
  68. package/dist/primereact/resources/themes/bootstrap4-dark-blue/theme.css +103 -91
  69. package/dist/primereact/resources/themes/bootstrap4-dark-purple/theme.css +103 -91
  70. package/dist/primereact/resources/themes/bootstrap4-light-blue/theme.css +102 -90
  71. package/dist/primereact/resources/themes/bootstrap4-light-purple/theme.css +102 -90
  72. package/dist/primereact/resources/themes/fluent-light/theme.css +103 -91
  73. package/dist/primereact/resources/themes/lara-dark-amber/fonts/Inter-italic.var.woff2 +0 -0
  74. package/dist/primereact/resources/themes/lara-dark-amber/fonts/Inter-roman.var.woff2 +0 -0
  75. package/dist/primereact/resources/themes/lara-dark-amber/theme.css +6049 -0
  76. package/dist/primereact/resources/themes/lara-dark-blue/theme.css +1006 -955
  77. package/dist/primereact/resources/themes/lara-dark-cyan/fonts/Inter-italic.var.woff2 +0 -0
  78. package/dist/primereact/resources/themes/lara-dark-cyan/fonts/Inter-roman.var.woff2 +0 -0
  79. package/dist/primereact/resources/themes/lara-dark-cyan/theme.css +6049 -0
  80. package/dist/primereact/resources/themes/lara-dark-green/fonts/Inter-italic.var.woff2 +0 -0
  81. package/dist/primereact/resources/themes/lara-dark-green/fonts/Inter-roman.var.woff2 +0 -0
  82. package/dist/primereact/resources/themes/lara-dark-green/theme.css +6049 -0
  83. package/dist/primereact/resources/themes/lara-dark-indigo/theme.css +1006 -955
  84. package/dist/primereact/resources/themes/lara-dark-pink/fonts/Inter-italic.var.woff2 +0 -0
  85. package/dist/primereact/resources/themes/lara-dark-pink/fonts/Inter-roman.var.woff2 +0 -0
  86. package/dist/primereact/resources/themes/lara-dark-pink/theme.css +6049 -0
  87. package/dist/primereact/resources/themes/lara-dark-purple/theme.css +1006 -955
  88. package/dist/primereact/resources/themes/lara-dark-teal/theme.css +1006 -955
  89. package/dist/primereact/resources/themes/lara-light-amber/fonts/Inter-italic.var.woff2 +0 -0
  90. package/dist/primereact/resources/themes/lara-light-amber/fonts/Inter-roman.var.woff2 +0 -0
  91. package/dist/primereact/resources/themes/lara-light-amber/theme.css +6041 -0
  92. package/dist/primereact/resources/themes/lara-light-blue/theme.css +842 -799
  93. package/dist/primereact/resources/themes/lara-light-cyan/fonts/Inter-italic.var.woff2 +0 -0
  94. package/dist/primereact/resources/themes/lara-light-cyan/fonts/Inter-roman.var.woff2 +0 -0
  95. package/dist/primereact/resources/themes/lara-light-cyan/theme.css +6041 -0
  96. package/dist/primereact/resources/themes/lara-light-green/fonts/Inter-italic.var.woff2 +0 -0
  97. package/dist/primereact/resources/themes/lara-light-green/fonts/Inter-roman.var.woff2 +0 -0
  98. package/dist/primereact/resources/themes/lara-light-green/theme.css +6041 -0
  99. package/dist/primereact/resources/themes/lara-light-indigo/theme.css +842 -799
  100. package/dist/primereact/resources/themes/lara-light-pink/fonts/Inter-italic.var.woff2 +0 -0
  101. package/dist/primereact/resources/themes/lara-light-pink/fonts/Inter-roman.var.woff2 +0 -0
  102. package/dist/primereact/resources/themes/lara-light-pink/theme.css +6041 -0
  103. package/dist/primereact/resources/themes/lara-light-purple/theme.css +842 -799
  104. package/dist/primereact/resources/themes/lara-light-teal/theme.css +1115 -1072
  105. package/dist/primereact/resources/themes/luna-amber/theme.css +103 -91
  106. package/dist/primereact/resources/themes/luna-blue/theme.css +103 -91
  107. package/dist/primereact/resources/themes/luna-green/theme.css +103 -91
  108. package/dist/primereact/resources/themes/luna-pink/theme.css +103 -91
  109. package/dist/primereact/resources/themes/md-dark-deeppurple/theme.css +147 -135
  110. package/dist/primereact/resources/themes/md-dark-indigo/theme.css +147 -135
  111. package/dist/primereact/resources/themes/md-light-deeppurple/theme.css +147 -135
  112. package/dist/primereact/resources/themes/md-light-indigo/theme.css +147 -135
  113. package/dist/primereact/resources/themes/mdc-dark-deeppurple/theme.css +147 -135
  114. package/dist/primereact/resources/themes/mdc-dark-indigo/theme.css +147 -135
  115. package/dist/primereact/resources/themes/mdc-light-deeppurple/theme.css +147 -135
  116. package/dist/primereact/resources/themes/mdc-light-indigo/theme.css +147 -135
  117. package/dist/primereact/resources/themes/mira/theme.css +108 -91
  118. package/dist/primereact/resources/themes/nano/theme.css +107 -91
  119. package/dist/primereact/resources/themes/nova/theme.css +103 -91
  120. package/dist/primereact/resources/themes/nova-accent/theme.css +103 -91
  121. package/dist/primereact/resources/themes/nova-alt/theme.css +103 -91
  122. package/dist/primereact/resources/themes/rhea/theme.css +103 -91
  123. package/dist/primereact/resources/themes/saga-blue/theme.css +103 -91
  124. package/dist/primereact/resources/themes/saga-green/theme.css +103 -91
  125. package/dist/primereact/resources/themes/saga-orange/theme.css +103 -91
  126. package/dist/primereact/resources/themes/saga-purple/theme.css +103 -91
  127. package/dist/primereact/resources/themes/soho-dark/theme.css +108 -91
  128. package/dist/primereact/resources/themes/soho-light/theme.css +108 -91
  129. package/dist/primereact/resources/themes/vela-blue/theme.css +103 -91
  130. package/dist/primereact/resources/themes/vela-green/theme.css +103 -91
  131. package/dist/primereact/resources/themes/vela-orange/theme.css +103 -91
  132. package/dist/primereact/resources/themes/vela-purple/theme.css +103 -91
  133. package/dist/primereact/resources/themes/viva-dark/theme.css +103 -91
  134. package/dist/primereact/resources/themes/viva-light/theme.css +103 -91
  135. package/package.json +29 -16
  136. package/tailwind.config.js +9 -2
  137. package/types/client-components/ClientLink.d.ts +6 -0
  138. package/types/client-components/MultiComponentEditor.d.ts +10 -0
  139. package/types/client-components/index.d.ts +2 -0
  140. package/types/components/Picture.d.ts +1 -0
  141. package/types/components/Placeholder.d.ts +16 -2
  142. package/types/components/RichTextEditor.d.ts +55 -55
  143. package/types/components/TextEditor.d.ts +54 -54
  144. package/types/editor/AiPopup.d.ts +10 -0
  145. package/types/editor/AiTerminal.d.ts +4 -3
  146. package/types/editor/ComponentPalette.d.ts +3 -4
  147. package/types/editor/ComponentTree.d.ts +1 -1
  148. package/types/editor/ConfirmationDialog.d.ts +19 -0
  149. package/types/editor/ContentTree.d.ts +7 -3
  150. package/types/editor/Debug.d.ts +1 -1
  151. package/types/editor/DialogButtons.d.ts +4 -0
  152. package/types/editor/DictionaryEditor.d.ts +3 -2
  153. package/types/editor/EditFrame.d.ts +4 -3
  154. package/types/editor/EditorClient.d.ts +4 -4
  155. package/types/editor/EditorClientHost.d.ts +4 -3
  156. package/types/editor/FieldListField.d.ts +4 -0
  157. package/types/editor/FloatingToolbar.d.ts +7 -0
  158. package/types/editor/ItemEditor.d.ts +4 -0
  159. package/types/editor/ItemInfo.d.ts +4 -0
  160. package/types/editor/ItemNameDialog.d.ts +10 -0
  161. package/types/editor/LinkEditorDialog.d.ts +15 -0
  162. package/types/editor/MainLayout.d.ts +6 -0
  163. package/types/editor/MediaSelector.d.ts +2 -1
  164. package/types/editor/PictureEditorDialog.d.ts +6 -0
  165. package/types/editor/SidebarTabs.d.ts +8 -0
  166. package/types/editor/Terminal.d.ts +3 -1
  167. package/types/editor/Utils.d.ts +3 -0
  168. package/types/editor/Workbox.d.ts +6 -0
  169. package/types/editor/componentCommands.d.ts +4 -0
  170. package/types/editor/contentService.d.ts +7 -1
  171. package/types/editor/editContext.d.ts +90 -19
  172. package/types/editor/editService.d.ts +9 -1
  173. package/types/editor/fieldTypes/CheckboxEditor.d.ts +4 -0
  174. package/types/editor/fieldTypes/InternalLinkFieldEditor.d.ts +4 -0
  175. package/types/editor/fieldTypes/LinkFieldEditor.d.ts +4 -0
  176. package/types/editor/fieldTypes/MultiLineText.d.ts +4 -0
  177. package/types/editor/fieldTypes/PictureFieldEditor.d.ts +4 -0
  178. package/types/editor/fieldTypes/TreeListEditor.d.ts +4 -0
  179. package/types/editor/ui/Section.d.ts +5 -0
  180. package/types/fieldTypes.d.ts +32 -17
  181. package/types/layoutData.d.ts +34 -9
  182. package/types/loadRouteData.d.ts +34 -5
  183. package/types/mediaProtection.d.ts +1 -0
  184. package/types/middleware/authorization.d.ts +2 -0
  185. package/types/middleware/index.d.ts +1 -0
  186. package/dist/cjs/editor/PageInfo.js +0 -12
  187. package/dist/esm/alpacaContext.js +0 -8
  188. package/dist/esm/components/Error.js +0 -10
  189. package/dist/esm/components/Image.js +0 -32
  190. package/dist/esm/components/Link.js +0 -29
  191. package/dist/esm/components/LinkEditor.js +0 -19
  192. package/dist/esm/components/Picture.js +0 -118
  193. package/dist/esm/components/PictureEditor.js +0 -41
  194. package/dist/esm/components/Placeholder.js +0 -69
  195. package/dist/esm/components/RichText.js +0 -40
  196. package/dist/esm/components/RichTextEditor.js +0 -52
  197. package/dist/esm/components/Slot.js +0 -5
  198. package/dist/esm/components/Text.js +0 -39
  199. package/dist/esm/components/TextEditor.js +0 -38
  200. package/dist/esm/components/Translate.js +0 -10
  201. package/dist/esm/components/index.js +0 -7
  202. package/dist/esm/editor/AiTerminal.js +0 -157
  203. package/dist/esm/editor/ComponentInfo.js +0 -10
  204. package/dist/esm/editor/ComponentPalette.js +0 -72
  205. package/dist/esm/editor/ComponentTree.js +0 -196
  206. package/dist/esm/editor/ContentTree.js +0 -117
  207. package/dist/esm/editor/Debug.js +0 -9
  208. package/dist/esm/editor/DictionaryEditor.js +0 -31
  209. package/dist/esm/editor/EditFrame.js +0 -57
  210. package/dist/esm/editor/EditHistory.js +0 -26
  211. package/dist/esm/editor/Editor.js +0 -23
  212. package/dist/esm/editor/EditorClient.js +0 -477
  213. package/dist/esm/editor/EditorClientHost.js +0 -7
  214. package/dist/esm/editor/FieldList.js +0 -60
  215. package/dist/esm/editor/GraphQL.js +0 -82
  216. package/dist/esm/editor/LanguageSelector.js +0 -17
  217. package/dist/esm/editor/MediaSelector.js +0 -54
  218. package/dist/esm/editor/PageInfo.js +0 -8
  219. package/dist/esm/editor/PlaceholderDropZone.js +0 -50
  220. package/dist/esm/editor/PlaceholderDropZoneHost.js +0 -7
  221. package/dist/esm/editor/Terminal.js +0 -47
  222. package/dist/esm/editor/TranslateEditor.js +0 -21
  223. package/dist/esm/editor/VersionSelector.js +0 -17
  224. package/dist/esm/editor/componentTreeHelper.js +0 -14
  225. package/dist/esm/editor/contentService.js +0 -31
  226. package/dist/esm/editor/editContext.js +0 -5
  227. package/dist/esm/editor/editService.js +0 -139
  228. package/dist/esm/editor/fieldTypes/RichTextEditor.js +0 -15
  229. package/dist/esm/editor/fieldTypes/SingleLineText.js +0 -13
  230. package/dist/esm/editor/index.js +0 -2
  231. package/dist/esm/fieldTypes.js +0 -1
  232. package/dist/esm/graphQLTypes.js +0 -1
  233. package/dist/esm/index.js +0 -7
  234. package/dist/esm/layoutData.js +0 -1
  235. package/dist/esm/loadRouteData.js +0 -123
  236. package/dist/esm/mediaProtection.js +0 -49
  237. package/types/editor/PageInfo.d.ts +0 -4
  238. /package/types/{editor → components}/TranslateEditor.d.ts +0 -0
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ "use client";
3
+ var __rest = (this && this.__rest) || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
6
+ t[p] = s[p];
7
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
8
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
9
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
10
+ t[p[i]] = s[p[i]];
11
+ }
12
+ return t;
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ClientLink = void 0;
19
+ const jsx_runtime_1 = require("react/jsx-runtime");
20
+ const __1 = require("..");
21
+ const LinkEditor_1 = __importDefault(require("../components/LinkEditor"));
22
+ function ClientLink(_a) {
23
+ var { field, children } = _a, props = __rest(_a, ["field", "children"]);
24
+ if (!field)
25
+ return;
26
+ if (field.jsonValue) {
27
+ field = field.jsonValue;
28
+ }
29
+ if (!field.value)
30
+ return;
31
+ const editing = (0, __1.useEditContext)();
32
+ if (editing)
33
+ return ((0, jsx_runtime_1.jsx)(LinkEditor_1.default, Object.assign({ field: field }, props, { children: children })));
34
+ return ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: field.value.url }, props, { children: children })));
35
+ }
36
+ exports.ClientLink = ClientLink;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MultiComponentEditor = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const __1 = require("..");
7
+ function MultiComponentEditor({ component, children, thumbZoom = 0.2, thumbHeight = "150px", thumbWidth = "150px", numComponentsVisibleWhenNotEditing = 1, }) {
8
+ var editContext = (0, __1.useEditContext)();
9
+ if (!editContext)
10
+ return null;
11
+ const style = {
12
+ "--a-mce-thumb-zoom": thumbZoom,
13
+ "--a-mce-thumb-width": thumbWidth,
14
+ "--a-mce-thumb-height": thumbHeight,
15
+ };
16
+ const filterChildCallback = ({ component, index, }) => {
17
+ var _a;
18
+ return index > numComponentsVisibleWhenNotEditing &&
19
+ ((_a = editContext === null || editContext === void 0 ? void 0 : editContext.selection) === null || _a === void 0 ? void 0 : _a.indexOf(component === null || component === void 0 ? void 0 : component.id)) === -1;
20
+ };
21
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "a-mce", style: style, children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex a-mce-items gap-2 flex-wrap items-center", children: [children, (0, jsx_runtime_1.jsx)("div", { onClick: (ev) => {
22
+ editContext === null || editContext === void 0 ? void 0 : editContext.setSelectedForInsertion(component.id);
23
+ ev.stopPropagation();
24
+ }, children: (0, jsx_runtime_1.jsx)("i", { className: "pi pi-plus-circle text-3xl cursor-pointer" }) })] }), (0, jsx_runtime_1.jsx)("div", { className: "a-mce-selected", children: (0, jsx_runtime_1.jsx)(__1.EditFilterChildrenContextProvider, { value: { filterChildCallback }, children: children }) })] }));
25
+ }
26
+ exports.MultiComponentEditor = MultiComponentEditor;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ "use client";
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./ClientLink"), exports);
19
+ __exportStar(require("./MultiComponentEditor"), exports);
@@ -30,7 +30,7 @@ function Link(_a) {
30
30
  return;
31
31
  const editing = (_b = (0, __1.useAlpacaContext)().pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing;
32
32
  if (editing)
33
- return ((0, jsx_runtime_1.jsx)(LinkEditor_1.default, Object.assign({ field: field, children: children }, props)));
33
+ return ((0, jsx_runtime_1.jsx)(LinkEditor_1.default, Object.assign({ field: field }, props, { children: children })));
34
34
  return ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: field.value.url }, props, { children: children })));
35
35
  }
36
36
  exports.Link = Link;
@@ -13,10 +13,56 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
+ const react_1 = require("react");
17
+ const LinkEditorDialog_1 = require("../editor/LinkEditorDialog");
18
+ const __1 = require("..");
16
19
  function LinkEditor(_a) {
17
20
  var { field, children } = _a, props = __rest(_a, ["field", "children"]);
21
+ const [showDialog, setShowDialog] = (0, react_1.useState)(false);
22
+ const [link, setLink] = (0, react_1.useState)();
23
+ const editContext = (0, __1.useEditContext)();
24
+ if (!editContext)
25
+ return;
26
+ (0, react_1.useEffect)(() => {
27
+ var _a;
28
+ setLink({
29
+ url: field.value.url,
30
+ target: field.value.target,
31
+ targetItemLongId: field.value.targetItemLongId,
32
+ type: field.value.type,
33
+ itemId: (_a = field.value.targetItemLongId) === null || _a === void 0 ? void 0 : _a.split("/").pop(),
34
+ queryString: field.value.queryString,
35
+ });
36
+ }, [field]);
18
37
  if (!field)
19
38
  return;
20
- return ((0, jsx_runtime_1.jsx)("a", Object.assign({ href: field.value.url }, props, { onClick: (e) => e.preventDefault(), children: children })));
39
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("a", Object.assign({ href: field.value.url }, props, { onClick: (e) => {
40
+ editContext.setFocusedField(field);
41
+ e.preventDefault();
42
+ }, children: [children, " ", (0, jsx_runtime_1.jsx)("i", { onClick: (e) => {
43
+ setShowDialog(true);
44
+ editContext.setFocusedField(field);
45
+ e.preventDefault();
46
+ }, className: "pi pi-link a-cursor-pointer" })] })), showDialog && ((0, jsx_runtime_1.jsx)(LinkEditorDialog_1.LinkEditorDialog, { linkValue: link || { type: "internal" }, onOk: (link) => {
47
+ var _a, _b;
48
+ const xml = link.type == "internal"
49
+ ? '<link linktype="internal" querystring="' +
50
+ ((_a = link.queryString) !== null && _a !== void 0 ? _a : "") +
51
+ '" id="' +
52
+ link.itemId +
53
+ '" target="' +
54
+ link.target +
55
+ '" />'
56
+ : '<link linktype="external" querystring="' +
57
+ ((_b = link.queryString) !== null && _b !== void 0 ? _b : "") +
58
+ ' url="' +
59
+ link.url +
60
+ '" target="' +
61
+ link.target +
62
+ '" />';
63
+ editContext === null || editContext === void 0 ? void 0 : editContext.editField({ field, rawValue: xml });
64
+ editContext === null || editContext === void 0 ? void 0 : editContext.requestRefresh("immediate");
65
+ setShowDialog(false);
66
+ }, onCancel: () => setShowDialog(false) }))] }));
21
67
  }
22
68
  exports.default = LinkEditor;
@@ -30,22 +30,24 @@ const PictureEditor_1 = require("./PictureEditor");
30
30
  // }
31
31
  // };
32
32
  const Picture = (_a) => {
33
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
34
- var { field, imageParams, sources, defaultVariant, renderJsonLinkedData } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData"]);
33
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
34
+ var { field, imageParams, sources, defaultVariant, renderJsonLinkedData, renderEditButton } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData", "renderEditButton"]);
35
35
  if (!field)
36
36
  return null;
37
37
  if (field.jsonValue) {
38
38
  field = field.jsonValue;
39
39
  }
40
- if ((_b = (0, __1.useAlpacaContext)().pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing)
41
- return (0, jsx_runtime_1.jsx)(PictureEditor_1.PictureEditor, Object.assign({ field: field }, otherProps));
42
- const variants = (_c = field.value) === null || _c === void 0 ? void 0 : _c.variants;
43
- const img = (_e = (_d = field.value) === null || _d === void 0 ? void 0 : _d.variants.find((x) => x.name.toUpperCase() == (defaultVariant === null || defaultVariant === void 0 ? void 0 : defaultVariant.toUpperCase()))) !== null && _e !== void 0 ? _e : (_f = field.value) === null || _f === void 0 ? void 0 : _f.variants[0];
40
+ if (!((_b = field.value) === null || _b === void 0 ? void 0 : _b.variants))
41
+ return;
42
+ if ((_c = (0, __1.useAlpacaContext)().pageContext) === null || _c === void 0 ? void 0 : _c.pageEditing)
43
+ return ((0, jsx_runtime_1.jsx)(PictureEditor_1.PictureEditor, Object.assign({ field: field, renderEditButton: renderEditButton }, otherProps)));
44
+ const variants = (_d = field.value) === null || _d === void 0 ? void 0 : _d.variants;
45
+ const img = (_f = (_e = field.value) === null || _e === void 0 ? void 0 : _e.variants.find((x) => x.name.toUpperCase() == (defaultVariant === null || defaultVariant === void 0 ? void 0 : defaultVariant.toUpperCase()))) !== null && _f !== void 0 ? _f : (_g = field.value) === null || _g === void 0 ? void 0 : _g.variants[0];
44
46
  const attrs = Object.assign({ src: img === null || img === void 0 ? void 0 : img.src }, otherProps);
45
47
  const video = img === null || img === void 0 ? void 0 : img.videoUrl;
46
48
  const videoAttr = Object.assign({ src: video }, otherProps);
47
49
  if (!(sources === null || sources === void 0 ? void 0 : sources.length)) {
48
- return (0, jsx_runtime_1.jsx)("img", Object.assign({}, attrs, { alt: (_g = field.value) === null || _g === void 0 ? void 0 : _g.alt }));
50
+ return (0, jsx_runtime_1.jsx)("img", Object.assign({}, attrs, { alt: (_h = field.value) === null || _h === void 0 ? void 0 : _h.alt }));
49
51
  }
50
52
  else {
51
53
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("picture", { children: [sources === null || sources === void 0 ? void 0 : sources.map((source) => {
@@ -100,21 +102,21 @@ const Picture = (_a) => {
100
102
  }
101
103
  }
102
104
  return ((0, jsx_runtime_1.jsx)("source", { srcSet: srcSet, media: source.media }, source.variant + source.media));
103
- }), (0, jsx_runtime_1.jsx)("img", Object.assign({}, attrs, { alt: (_h = field.value) === null || _h === void 0 ? void 0 : _h.alt }))] }), renderJsonLinkedData && !video ? ((0, jsx_runtime_1.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
105
+ }), (0, jsx_runtime_1.jsx)("img", Object.assign({}, attrs, { alt: (_j = field.value) === null || _j === void 0 ? void 0 : _j.alt }))] }), renderJsonLinkedData && !video ? ((0, jsx_runtime_1.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
104
106
  __html: JSON.stringify({
105
107
  "@context": "http://schema.org",
106
108
  "@type": "ImageObject",
107
109
  image: img === null || img === void 0 ? void 0 : img.src,
108
- description: (_j = field.value) === null || _j === void 0 ? void 0 : _j.alt,
109
- name: (_k = field.value) === null || _k === void 0 ? void 0 : _k.name,
110
+ description: (_k = field.value) === null || _k === void 0 ? void 0 : _k.alt,
111
+ name: (_l = field.value) === null || _l === void 0 ? void 0 : _l.name,
110
112
  }),
111
113
  } })) : null, video && (0, jsx_runtime_1.jsx)("video", Object.assign({}, videoAttr)), renderJsonLinkedData && video ? ((0, jsx_runtime_1.jsx)("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
112
114
  __html: JSON.stringify({
113
115
  "@context": "http://schema.org",
114
116
  "@type": "VideoObject",
115
117
  contentUrl: img === null || img === void 0 ? void 0 : img.src,
116
- description: (_l = field.value) === null || _l === void 0 ? void 0 : _l.alt,
117
- name: (_m = field.value) === null || _m === void 0 ? void 0 : _m.name,
118
+ description: (_m = field.value) === null || _m === void 0 ? void 0 : _m.alt,
119
+ name: (_o = field.value) === null || _o === void 0 ? void 0 : _o.name,
118
120
  }),
119
121
  } })) : null] }));
120
122
  }
@@ -17,29 +17,33 @@ const jsx_runtime_1 = require("react/jsx-runtime");
17
17
  const react_1 = require("react");
18
18
  const Picture_1 = require("./Picture");
19
19
  const __1 = require("..");
20
- const MediaSelector_1 = require("../editor/MediaSelector");
21
- const dialog_1 = require("primereact/dialog");
20
+ const PictureEditorDialog_1 = require("../editor/PictureEditorDialog");
22
21
  const PictureEditor = (_a) => {
23
22
  var _b, _c;
24
- var { field, imageParams, sources, defaultVariant, renderJsonLinkedData } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData"]);
23
+ var { field, imageParams, sources, defaultVariant, renderEditButton } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderEditButton"]);
25
24
  const editContext = (0, __1.useEditContext)();
26
- const [mediaSelectorVisible, setMediaSelectorVisible] = (0, react_1.useState)(false);
27
25
  const [editorVisible, setEditorVisible] = (0, react_1.useState)(false);
28
- const [selectedVariant, setSelectedVariant] = (0, react_1.useState)();
29
26
  if (!editContext)
30
27
  return;
31
- function imageSelected(imageId) {
32
- const value = (field === null || field === void 0 ? void 0 : field.value) || {};
33
- if (!selectedVariant)
34
- return;
35
- selectedVariant.mediaId = imageId;
36
- console.log(imageId);
37
- console.log(JSON.stringify(value));
38
- if (field)
39
- editContext === null || editContext === void 0 ? void 0 : editContext.editField(field, JSON.stringify(value), false);
40
- }
41
- console.log(JSON.stringify(field));
42
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MediaSelector_1.MediaSelector, { visible: mediaSelectorVisible, onHide: () => setMediaSelectorVisible(false), onMediaSelected: imageSelected }), (0, jsx_runtime_1.jsx)(dialog_1.Dialog, { header: "Edit picture", visible: editorVisible, style: { width: "50vw" }, onHide: () => setEditorVisible(false), children: (0, jsx_runtime_1.jsx)("div", { className: "a-flex a-gap-1", children: (_c = (_b = field === null || field === void 0 ? void 0 : field.value) === null || _b === void 0 ? void 0 : _b.variants) === null || _c === void 0 ? void 0 : _c.map((variant) => ((0, jsx_runtime_1.jsxs)("div", { onClick: () => setSelectedVariant(variant), children: [(0, jsx_runtime_1.jsxs)("div", { className: "a-h-24 a-w-24 a-border a-relative" +
43
- (selectedVariant == variant ? " a-shadow-xl " : ""), children: [variant.src && (0, jsx_runtime_1.jsx)("img", { src: variant.src }), (0, jsx_runtime_1.jsx)("div", { className: "a-absolute a-top-0 a-right-0 ", children: (0, jsx_runtime_1.jsx)("i", { className: "pi pi-pencil a-m-1 a-cursor-pointer", onClick: () => setMediaSelectorVisible(true) }) })] }, variant.name), (0, jsx_runtime_1.jsx)("div", { children: variant.name }), (0, jsx_runtime_1.jsx)("div", { children: variant.aspectRatioText })] }))) }) }), (0, jsx_runtime_1.jsxs)("span", Object.assign({}, otherProps, { onClick: () => setEditorVisible(true), children: ["PICTURE", (0, jsx_runtime_1.jsx)(Picture_1.Picture, { field: field, imageParams: imageParams, sources: sources })] }))] }));
28
+ const editFrameContext = (0, __1.useEditFrameContext)();
29
+ if (!editFrameContext)
30
+ return;
31
+ (0, react_1.useEffect)(() => {
32
+ if (renderEditButton && editFrameContext.componentId === (field === null || field === void 0 ? void 0 : field.item.id)) {
33
+ editFrameContext.setCustomButtons([
34
+ ...editFrameContext.customButtons,
35
+ {
36
+ icon: "pi pi-image",
37
+ onClick: () => setEditorVisible(true),
38
+ tooltip: "Edit " + (field === null || field === void 0 ? void 0 : field.name),
39
+ },
40
+ ]);
41
+ }
42
+ }, []);
43
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("span", Object.assign({}, otherProps, { onClick: (e) => {
44
+ if (editFrameContext.isSelected && !e.ctrlKey && !e.altKey)
45
+ setEditorVisible(true);
46
+ editContext.setFocusedField(field);
47
+ }, className: "a-cursor-pointer", children: [(0, jsx_runtime_1.jsx)(Picture_1.Picture, { field: field, imageParams: imageParams, sources: sources }), !((_c = (_b = field === null || field === void 0 ? void 0 : field.value) === null || _b === void 0 ? void 0 : _b.variants) === null || _c === void 0 ? void 0 : _c.find((x) => x.src)) && ((0, jsx_runtime_1.jsx)("div", { className: "pi pi-image a-text-6xl a-text-gray-300" }))] })), editorVisible && ((0, jsx_runtime_1.jsx)(PictureEditorDialog_1.PictureEditorDialog, { field: field, onCancel: () => setEditorVisible(false), onOk: () => setEditorVisible(false) }))] }));
44
48
  };
45
49
  exports.PictureEditor = PictureEditor;
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Placeholder = void 0;
16
+ const react_1 = require("react");
16
17
  const jsx_runtime_1 = require("react/jsx-runtime");
17
18
  const EditFrame_1 = require("../editor/EditFrame");
18
19
  const __1 = require("..");
@@ -20,7 +21,8 @@ const PlaceholderDropZoneHost_1 = require("../editor/PlaceholderDropZoneHost");
20
21
  const Slot_1 = __importDefault(require("./Slot"));
21
22
  const react_error_boundary_1 = require("react-error-boundary");
22
23
  const Error_1 = require("./Error");
23
- function Placeholder({ name, content, }) {
24
+ const react_2 = __importDefault(require("react"));
25
+ function Placeholder({ name, content, tag, className, mapComponent, getComponentProps, }) {
24
26
  return __awaiter(this, void 0, void 0, function* () {
25
27
  const data = yield content;
26
28
  if (!data || !("placeholders" in data))
@@ -30,9 +32,13 @@ function Placeholder({ name, content, }) {
30
32
  return;
31
33
  const context = (0, __1.useAlpacaContext)();
32
34
  const loader = context.componentModuleLoader;
33
- const promises = placeholderData === null || placeholderData === void 0 ? void 0 : placeholderData.components.map((component) => __awaiter(this, void 0, void 0, function* () {
35
+ const promises = placeholderData === null || placeholderData === void 0 ? void 0 : placeholderData.components.filter((c) => c.visible).map((component) => __awaiter(this, void 0, void 0, function* () {
34
36
  if (component.componentType == "Slot")
35
- return { Component: Slot_1.default, data: component, parent: data };
37
+ return {
38
+ Component: Slot_1.default,
39
+ data: component,
40
+ parent: data,
41
+ };
36
42
  let module = null;
37
43
  try {
38
44
  module = yield loader(component.componentType);
@@ -47,21 +53,57 @@ function Placeholder({ name, content, }) {
47
53
  Component: ComponentNotFound,
48
54
  };
49
55
  }
50
- return { parent: data, data: component, Component: module.default };
56
+ return {
57
+ parent: data,
58
+ data: component,
59
+ Component: module.default,
60
+ };
51
61
  }));
52
62
  const components = yield Promise.all(promises);
63
+ function wrap(children) {
64
+ if (!tag)
65
+ return children;
66
+ if (context.pageContext.pageEditing || components.length > 0) {
67
+ return react_2.default.createElement(tag, { className }, children);
68
+ }
69
+ }
70
+ const mappedComponents = mapComponent
71
+ ? components.map(({ Component, data, parent }, index) => ({
72
+ Component: mapComponent({
73
+ Component,
74
+ data: data,
75
+ index,
76
+ }),
77
+ data,
78
+ parent,
79
+ }))
80
+ : components;
81
+ const componentsWithProps = mappedComponents.map(({ Component, data, parent }, index) => {
82
+ var props = getComponentProps
83
+ ? getComponentProps({ component: data, index })
84
+ : { component: data, index };
85
+ return { Component, props, data, parent };
86
+ });
53
87
  if (context.pageContext.pageEditing) {
54
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [components.map(({ Component, data, parent }, index) => {
88
+ let phIndex = 0;
89
+ return wrap((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [componentsWithProps.map(({ Component, props, data, parent }) => {
55
90
  try {
56
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PlaceholderDropZoneHost_1.PlaceholderDropZoneHost, { parentName: parent === null || parent === void 0 ? void 0 : parent.name, placeholder: placeholderData, index: index + 1 }), (0, jsx_runtime_1.jsx)(EditFrame_1.EditFrame, { componentId: data.id, children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: Error_1.ErrorFallbackWithDetails, children: (0, jsx_runtime_1.jsx)(Component, { component: data }) }) }, data.id)] }));
91
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(!data.hostingPageItem ||
92
+ data.componentType == "Slot") && ((0, jsx_runtime_1.jsx)(PlaceholderDropZoneHost_1.PlaceholderDropZoneHost, { parentName: parent === null || parent === void 0 ? void 0 : parent.name, placeholder: placeholderData, index: phIndex++ }, data.id + "_zone" + phIndex)), (0, jsx_runtime_1.jsx)(EditFrame_1.EditFrame, { componentId: data.id, index: phIndex, children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: Error_1.ErrorFallbackWithDetails, children: (0, jsx_runtime_1.jsx)(Component, Object.assign({}, props)) }) }, data.id)] }));
57
93
  }
58
94
  catch (e) {
59
95
  return ((0, jsx_runtime_1.jsxs)("div", { children: ["Error rendering component ", data.name, ": ", e.message] }));
60
96
  }
61
- }), (0, jsx_runtime_1.jsx)(PlaceholderDropZoneHost_1.PlaceholderDropZoneHost, { parentName: data === null || data === void 0 ? void 0 : data.name, placeholder: placeholderData, index: components.length + 1 })] }));
97
+ }), (!data.hostingPageItem ||
98
+ data.componentType == "Slot") && ((0, jsx_runtime_1.jsx)(PlaceholderDropZoneHost_1.PlaceholderDropZoneHost, { parentName: data === null || data === void 0 ? void 0 : data.name, placeholder: placeholderData, index: phIndex++ }, data.id + "_zone" + phIndex))] }));
62
99
  }
63
100
  else
64
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: components.map(({ Component, data }) => ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: Error_1.ErrorFallback, children: (0, jsx_runtime_1.jsx)(Component, { component: data }) }) }))) }));
101
+ return wrap((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: mappedComponents.map(({ Component, data }, index) => {
102
+ var props = getComponentProps
103
+ ? getComponentProps({ component: data, index })
104
+ : { component: data, index };
105
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: Error_1.ErrorFallback, children: (0, react_1.createElement)(Component, Object.assign({}, props, { key: data.id })) }, data.id) }));
106
+ }) }));
65
107
  });
66
108
  }
67
109
  exports.Placeholder = Placeholder;
@@ -72,5 +114,5 @@ function ComponentNotFound({ component }) {
72
114
  fontSize: 18,
73
115
  padding: 10,
74
116
  border: "3px solid red",
75
- }, children: ["Component not found: ", component.name, " "] }));
117
+ }, children: ["Component not found: ", component.name] }));
76
118
  }
@@ -38,7 +38,7 @@ function RichText(_a) {
38
38
  }
39
39
  const internalProps = Object.assign(Object.assign({}, props), { dangerouslySetInnerHTML: {
40
40
  __html: field.value,
41
- }, editable: editable, contentEditable: true, "data-test": "test", placeholder: "[" + field.name + "]" });
41
+ } });
42
42
  if ((0, __1.useAlpacaContext)().pageContext.pageEditing)
43
43
  return (0, jsx_runtime_1.jsx)(RichTextEditor_1.RichTextEditor, Object.assign({ field: field, tag: tag }, props));
44
44
  return react_1.default.createElement(tag || "div", Object.assign(props, internalProps));
@@ -48,6 +48,8 @@ function RichTextEditor(_a) {
48
48
  const { updateContentEditingFields } = editContext;
49
49
  const liveField = editContext.getLiveField(field);
50
50
  (0, react_1.useEffect)(() => {
51
+ if (!liveField)
52
+ return;
51
53
  if (editedValue != liveField.value &&
52
54
  "<p>" + editedValue + "</p>" != liveField.value) {
53
55
  // console.log(
@@ -55,15 +57,23 @@ function RichTextEditor(_a) {
55
57
  // );
56
58
  setValue(liveField.value);
57
59
  }
58
- }, [liveField.value]);
60
+ }, [liveField === null || liveField === void 0 ? void 0 : liveField.value]);
59
61
  (0, react_1.useEffect)(() => {
62
+ if (!liveField)
63
+ return;
60
64
  setValue(liveField.value); // Otherwise react would not update the field after the refresh
61
65
  }, [updateContentEditingFields]);
66
+ (0, react_1.useEffect)(() => {
67
+ if (liveField) {
68
+ setValue(field.value);
69
+ liveField.value = field.value;
70
+ }
71
+ }, [field]);
62
72
  const setFieldValue = (val) => {
63
73
  if (val != editedValue) {
64
74
  setEditedValue(val);
65
75
  if (editContext)
66
- editContext.editField(field, val, true);
76
+ editContext.editField({ field, value: val, refresh: "none" });
67
77
  }
68
78
  };
69
79
  const eventHandler = (0, react_1.useCallback)((e) => {
@@ -72,6 +82,11 @@ function RichTextEditor(_a) {
72
82
  return (0, react_1.useMemo)(() => {
73
83
  const properies = Object.assign(Object.assign({}, props), { contentEditable: true, suppressContentEditableWarning: true, onInput: eventHandler, placeholder: "[" + field.name + "]", dangerouslySetInnerHTML: {
74
84
  __html: value,
85
+ }, onFocus: () => {
86
+ editContext.setFocusedField(field);
87
+ }, onClick: () => {
88
+ if (!field.canWrite || !field.hasLock)
89
+ editContext.setFocusedField(field);
75
90
  } });
76
91
  return react_1.default.createElement(tag || "div", properies);
77
92
  }, [value]);
@@ -48,17 +48,29 @@ function TextEditor(_a) {
48
48
  const { updateContentEditingFields } = editContext;
49
49
  const liveField = editContext.getLiveField(field);
50
50
  (0, react_1.useEffect)(() => {
51
+ if (!liveField)
52
+ return;
51
53
  if (editedValue != liveField.value)
52
54
  setValue(liveField.value);
53
- }, [liveField.value]);
55
+ }, [liveField === null || liveField === void 0 ? void 0 : liveField.value]);
54
56
  (0, react_1.useEffect)(() => {
57
+ if (liveField) {
58
+ setValue(field.value);
59
+ liveField.value = field.value;
60
+ }
61
+ }, [field]);
62
+ (0, react_1.useEffect)(() => {
63
+ if (!liveField)
64
+ return;
55
65
  setValue(liveField.value); // Otherwise react would not update the field after the refresh
56
66
  }, [updateContentEditingFields]);
57
- const properies = Object.assign(Object.assign({}, props), { contentEditable: true, suppressContentEditableWarning: true, onInput: (e) => setFieldValue(e.currentTarget.textContent), placeholder: "[" + field.name + "]" });
67
+ const properies = Object.assign(Object.assign({}, props), { contentEditable: true, suppressContentEditableWarning: true, onInput: (e) => setFieldValue(e.currentTarget.textContent), placeholder: "[" + field.name + "]", onFocus: () => {
68
+ editContext.setFocusedField(field);
69
+ } });
58
70
  const setFieldValue = (val) => {
59
71
  setEditedValue(val);
60
72
  if (editContext)
61
- editContext.editField(field, val, true);
73
+ editContext.editField({ field, value: val, refresh: "none" });
62
74
  };
63
75
  return react_1.default.createElement(tag || "div", properies, value);
64
76
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Translate = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const __1 = require("..");
6
- const TranslateEditor_1 = require("../editor/TranslateEditor");
6
+ const TranslateEditor_1 = require("./TranslateEditor");
7
7
  function Translate({ text }) {
8
8
  const context = (0, __1.useAlpacaContext)();
9
9
  const dictionary = context.dictionary;
@@ -5,6 +5,7 @@ exports.TranslateEditor = void 0;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("react");
7
7
  const __1 = require("..");
8
+ const TextEditor_1 = require("./TextEditor");
8
9
  function TranslateEditor({ text }) {
9
10
  const context = (0, __1.useEditContext)();
10
11
  if (!context || !context.dictionary)
@@ -13,13 +14,15 @@ function TranslateEditor({ text }) {
13
14
  (0, react_1.useEffect)(() => {
14
15
  if (Object.keys(dictionary).indexOf(text) < 0 &&
15
16
  context.unresolvedDictionaryKeys.indexOf(text) < 0) {
16
- console.log("Pushing...");
17
17
  context.setUnresolvedDictionaryKeys([
18
18
  ...context.unresolvedDictionaryKeys,
19
19
  text,
20
20
  ]);
21
21
  }
22
22
  }, []);
23
- return (dictionary[text] || ((0, jsx_runtime_1.jsx)("span", { className: "a-p-1 a-ring-2 a-ring-red-500", children: text })));
23
+ if (dictionary[text]) {
24
+ return (0, jsx_runtime_1.jsx)(TextEditor_1.TextEditor, { field: dictionary[text] });
25
+ }
26
+ return ((0, jsx_runtime_1.jsx)("span", { className: "a-p-1 a-ring-2 a-ring-red-500", onClick: () => console.log("create dictionary entry"), children: text }));
24
27
  }
25
28
  exports.TranslateEditor = TranslateEditor;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ "use client";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.AiPopup = void 0;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const overlaypanel_1 = require("primereact/overlaypanel");
7
+ const AiTerminal_1 = require("./AiTerminal");
8
+ const button_1 = require("primereact/button");
9
+ const react_1 = require("react");
10
+ const __1 = require("..");
11
+ exports.AiPopup = (0, react_1.forwardRef)((props, ref) => {
12
+ const overlayRef = (0, react_1.useRef)(null);
13
+ const [operations, setOperations] = (0, react_1.useState)([]);
14
+ const editContext = (0, __1.useEditContext)();
15
+ (0, react_1.useImperativeHandle)(ref, () => ({
16
+ show: (ev) => {
17
+ var _a;
18
+ setOperations([]);
19
+ (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.toggle(ev);
20
+ },
21
+ close: () => {
22
+ var _a;
23
+ (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.hide();
24
+ },
25
+ }));
26
+ return ((0, jsx_runtime_1.jsx)(overlaypanel_1.OverlayPanel, { ref: overlayRef, children: (0, jsx_runtime_1.jsxs)("div", { className: "a-w-96 a-h-96 a-flex a-flex-col a-gap-2", children: [(0, jsx_runtime_1.jsx)(AiTerminal_1.AiTerminal, { selection: [props.componentId], newEditOperations: (ops) => setOperations([...operations, ...ops]) }), operations.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "a-text-xs", children: [operations.length, " changes"] })), (0, jsx_runtime_1.jsxs)("div", { className: "a-flex a-gap-4 a-justify-end", children: [!operations.length && ((0, jsx_runtime_1.jsx)(button_1.Button, { label: "Close", onClick: () => { var _a; return (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.hide(); }, size: "small" })), operations.length > 0 && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, { icon: "pi pi-check", severity: "success", label: "Accept", onClick: () => { var _a; return (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.hide(); }, size: "small" }), (0, jsx_runtime_1.jsx)(button_1.Button, { icon: "pi pi-times", severity: "danger", label: "Reject", onClick: () => {
27
+ var _a;
28
+ if (operations.length > 0) {
29
+ editContext === null || editContext === void 0 ? void 0 : editContext.undo(operations.length);
30
+ (_a = overlayRef.current) === null || _a === void 0 ? void 0 : _a.hide();
31
+ }
32
+ }, size: "small" })] }))] })] }) }));
33
+ });