camox 0.3.0 → 0.3.1

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 (69) hide show
  1. package/dist/components/AuthGate.js +2 -1
  2. package/dist/core/components/AddBlockControlBar.js +117 -44
  3. package/dist/core/components/lexical/InlineContentEditable.js +37 -17
  4. package/dist/core/components/lexical/InlineLexicalEditor.js +84 -25
  5. package/dist/core/components/lexical/SelectionBroadcaster.js +84 -47
  6. package/dist/core/components/lexical/SidebarLexicalEditor.js +54 -19
  7. package/dist/core/createBlock.js +1172 -414
  8. package/dist/core/createLayout.js +48 -16
  9. package/dist/core/hooks/useFieldSelection.js +24 -13
  10. package/dist/core/hooks/useIsEditable.js +8 -2
  11. package/dist/core/hooks/useOverlayMessage.js +51 -20
  12. package/dist/features/content/CamoxContent.js +239 -107
  13. package/dist/features/content/components/AssetCard.js +78 -16
  14. package/dist/features/content/components/AssetCardSkeleton.js +11 -4
  15. package/dist/features/content/components/ContentSidebar.js +15 -8
  16. package/dist/features/content/components/UploadDropZone.js +77 -34
  17. package/dist/features/content/components/UploadProgressDrawer.js +201 -58
  18. package/dist/features/metadata/sitemap.js +15 -0
  19. package/dist/features/preview/CamoxPreview.js +447 -179
  20. package/dist/features/preview/components/AddBlockSheet.js +344 -167
  21. package/dist/features/preview/components/AgentChatSheet.js +32 -10
  22. package/dist/features/preview/components/AssetFieldEditor.js +185 -50
  23. package/dist/features/preview/components/AssetLightbox.js +60 -33
  24. package/dist/features/preview/components/AssetPickerGrid.js +203 -71
  25. package/dist/features/preview/components/BlockActionsPopover.js +295 -218
  26. package/dist/features/preview/components/CreatePageSheet.js +3 -3
  27. package/dist/features/preview/components/DebouncedFieldEditor.js +80 -23
  28. package/dist/features/preview/components/EditPageSheet.js +241 -86
  29. package/dist/features/preview/components/ItemFieldsEditor.js +209 -115
  30. package/dist/features/preview/components/LinkFieldEditor.js +351 -153
  31. package/dist/features/preview/components/MultipleAssetFieldEditor.js +245 -92
  32. package/dist/features/preview/components/OverlayTracker.js +58 -23
  33. package/dist/features/preview/components/Overlays.js +85 -43
  34. package/dist/features/preview/components/PageContentSheet.js +18 -18
  35. package/dist/features/preview/components/PageLocationFieldset.js +229 -63
  36. package/dist/features/preview/components/PagePicker.js +27 -27
  37. package/dist/features/preview/components/PageTree.js +921 -319
  38. package/dist/features/preview/components/PeekedBlock.js +173 -63
  39. package/dist/features/preview/components/PreviewPanel.js +271 -148
  40. package/dist/features/preview/components/PreviewSideSheet.js +44 -11
  41. package/dist/features/preview/components/PreviewToolbar.js +262 -59
  42. package/dist/features/preview/components/RepeatableItemsList.js +187 -78
  43. package/dist/features/preview/components/ShikiMarkdown.js +46 -20
  44. package/dist/features/preview/components/TextFormatToolbar.js +81 -23
  45. package/dist/features/preview/components/UnlinkAssetButton.js +161 -40
  46. package/dist/features/preview/components/useUpdateBlockPosition.js +64 -47
  47. package/dist/features/preview/previewStore.d.ts +2 -2
  48. package/dist/features/provider/CamoxProvider.js +69 -21
  49. package/dist/features/provider/actionsStore.d.ts +2 -2
  50. package/dist/features/provider/components/CamoxAppContext.js +15 -5
  51. package/dist/features/provider/components/CommandPalette.js +199 -92
  52. package/dist/features/provider/useAdminShortcuts.js +80 -64
  53. package/dist/features/routes/pageRoute.js +8 -1
  54. package/dist/features/studio/CamoxStudio.js +45 -9
  55. package/dist/features/studio/components/EnvironmentMenu.js +47 -12
  56. package/dist/features/studio/components/Navbar.js +163 -65
  57. package/dist/features/studio/components/ProjectMenu.js +263 -82
  58. package/dist/features/studio/components/UserButton.js +21 -6
  59. package/dist/features/studio/studioStore.d.ts +2 -2
  60. package/dist/features/studio/useTheme.js +128 -74
  61. package/dist/hooks/use-file-upload.js +11 -11
  62. package/dist/hooks/use-marquee-selection.js +121 -74
  63. package/dist/lib/auth.js +95 -51
  64. package/dist/lib/normalized-data.js +103 -30
  65. package/dist/lib/use-project-room.js +55 -22
  66. package/dist/studio.css +2 -2
  67. package/package.json +29 -26
  68. package/dist/lib/auth.d.ts +0 -2130
  69. package/dist/lib/auth.d.ts.map +0 -1
@@ -7,6 +7,7 @@ import { AssetLightbox } from "./AssetLightbox.js";
7
7
  import { AssetPickerGrid } from "./AssetPickerGrid.js";
8
8
  import { UnlinkAssetButton } from "./UnlinkAssetButton.js";
9
9
  import { AssetActionButtons } from "./AssetFieldEditor.js";
10
+ import { c } from "react/compiler-runtime";
10
11
  import { useQuery } from "@tanstack/react-query";
11
12
  import * as React from "react";
12
13
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -17,62 +18,184 @@ import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
17
18
  import { SortableContext, sortableKeyboardCoordinates, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
18
19
  import { CSS } from "@dnd-kit/utilities";
19
20
  //#region src/features/preview/components/MultipleAssetFieldEditor.tsx
20
- var SortableAssetItem = ({ asset, assetType, onRemove, onAssetOpen }) => {
21
- const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: String(asset._fileId) });
22
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("div", {
23
- ref: setNodeRef,
24
- style: {
25
- transform: CSS.Transform.toString(transform),
21
+ var SortableAssetItem = (t0) => {
22
+ const $ = c(42);
23
+ const { asset, assetType, onRemove, onAssetOpen } = t0;
24
+ const t1 = String(asset._fileId);
25
+ let t2;
26
+ if ($[0] !== t1) {
27
+ t2 = { id: t1 };
28
+ $[0] = t1;
29
+ $[1] = t2;
30
+ } else t2 = $[1];
31
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable(t2);
32
+ let t3;
33
+ if ($[2] !== transform) {
34
+ t3 = CSS.Transform.toString(transform);
35
+ $[2] = transform;
36
+ $[3] = t3;
37
+ } else t3 = $[3];
38
+ const t4 = isDragging ? .5 : 1;
39
+ let t5;
40
+ if ($[4] !== t3 || $[5] !== t4 || $[6] !== transition) {
41
+ t5 = {
42
+ transform: t3,
26
43
  transition,
27
- opacity: isDragging ? .5 : 1
28
- },
29
- className: cn("flex flex-row items-center gap-2 px-1 py-1 max-w-full rounded-lg text-foreground transition-none group", !isDragging && "hover:bg-accent/75"),
30
- children: [
31
- /* @__PURE__ */ jsx(Button, {
32
- type: "button",
33
- variant: "ghost",
34
- size: "icon-sm",
35
- className: "text-muted-foreground hover:text-foreground flex shrink-0 cursor-grab active:cursor-grabbing",
36
- ...attributes,
37
- ...listeners,
38
- children: /* @__PURE__ */ jsx(GripVertical, { className: "h-4 w-4" })
39
- }),
40
- /* @__PURE__ */ jsxs("button", {
41
- type: "button",
42
- className: "flex min-w-0 flex-1 cursor-zoom-in items-center gap-2",
43
- onClick: () => onAssetOpen(asset),
44
- children: [assetType === "Image" ? /* @__PURE__ */ jsx("div", {
45
- className: "border-border h-12 w-12 shrink-0 overflow-hidden rounded border",
46
- children: /* @__PURE__ */ jsx("img", {
47
- src: asset.url,
48
- alt: asset.alt || asset.filename,
49
- className: "h-full w-full object-cover"
50
- })
51
- }) : /* @__PURE__ */ jsx("div", {
52
- className: "border-border bg-muted flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded border",
53
- children: /* @__PURE__ */ jsx(FileIcon, { className: "text-muted-foreground h-6 w-6" })
54
- }), /* @__PURE__ */ jsx("p", {
55
- className: "flex-1 truncate text-left text-sm",
56
- title: asset.filename,
57
- children: asset.filename || "Untitled"
58
- })]
59
- }),
60
- /* @__PURE__ */ jsx(UnlinkAssetButton, {
61
- fileId: asset._fileId,
62
- onUnlink: () => onRemove(asset._fileId),
63
- className: "hidden group-focus-within:flex group-hover:flex"
44
+ opacity: t4
45
+ };
46
+ $[4] = t3;
47
+ $[5] = t4;
48
+ $[6] = transition;
49
+ $[7] = t5;
50
+ } else t5 = $[7];
51
+ const style = t5;
52
+ const t6 = !isDragging && "hover:bg-accent/75";
53
+ let t7;
54
+ if ($[8] !== t6) {
55
+ t7 = cn("flex flex-row items-center gap-2 px-1 py-1 max-w-full rounded-lg text-foreground transition-none group", t6);
56
+ $[8] = t6;
57
+ $[9] = t7;
58
+ } else t7 = $[9];
59
+ let t8;
60
+ if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
61
+ t8 = /* @__PURE__ */ jsx(GripVertical, { className: "h-4 w-4" });
62
+ $[10] = t8;
63
+ } else t8 = $[10];
64
+ let t9;
65
+ if ($[11] !== attributes || $[12] !== listeners) {
66
+ t9 = /* @__PURE__ */ jsx(Button, {
67
+ type: "button",
68
+ variant: "ghost",
69
+ size: "icon-sm",
70
+ className: "text-muted-foreground hover:text-foreground flex shrink-0 cursor-grab active:cursor-grabbing",
71
+ ...attributes,
72
+ ...listeners,
73
+ children: t8
74
+ });
75
+ $[11] = attributes;
76
+ $[12] = listeners;
77
+ $[13] = t9;
78
+ } else t9 = $[13];
79
+ let t10;
80
+ if ($[14] !== asset || $[15] !== onAssetOpen) {
81
+ t10 = () => onAssetOpen(asset);
82
+ $[14] = asset;
83
+ $[15] = onAssetOpen;
84
+ $[16] = t10;
85
+ } else t10 = $[16];
86
+ let t11;
87
+ if ($[17] !== asset.alt || $[18] !== asset.filename || $[19] !== asset.url || $[20] !== assetType) {
88
+ t11 = assetType === "Image" ? /* @__PURE__ */ jsx("div", {
89
+ className: "border-border h-12 w-12 shrink-0 overflow-hidden rounded border",
90
+ children: /* @__PURE__ */ jsx("img", {
91
+ src: asset.url,
92
+ alt: asset.alt || asset.filename,
93
+ className: "h-full w-full object-cover"
64
94
  })
65
- ]
66
- }) });
95
+ }) : /* @__PURE__ */ jsx("div", {
96
+ className: "border-border bg-muted flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded border",
97
+ children: /* @__PURE__ */ jsx(FileIcon, { className: "text-muted-foreground h-6 w-6" })
98
+ });
99
+ $[17] = asset.alt;
100
+ $[18] = asset.filename;
101
+ $[19] = asset.url;
102
+ $[20] = assetType;
103
+ $[21] = t11;
104
+ } else t11 = $[21];
105
+ const t12 = asset.filename || "Untitled";
106
+ let t13;
107
+ if ($[22] !== asset.filename || $[23] !== t12) {
108
+ t13 = /* @__PURE__ */ jsx("p", {
109
+ className: "flex-1 truncate text-left text-sm",
110
+ title: asset.filename,
111
+ children: t12
112
+ });
113
+ $[22] = asset.filename;
114
+ $[23] = t12;
115
+ $[24] = t13;
116
+ } else t13 = $[24];
117
+ let t14;
118
+ if ($[25] !== t10 || $[26] !== t11 || $[27] !== t13) {
119
+ t14 = /* @__PURE__ */ jsxs("button", {
120
+ type: "button",
121
+ className: "flex min-w-0 flex-1 cursor-zoom-in items-center gap-2",
122
+ onClick: t10,
123
+ children: [t11, t13]
124
+ });
125
+ $[25] = t10;
126
+ $[26] = t11;
127
+ $[27] = t13;
128
+ $[28] = t14;
129
+ } else t14 = $[28];
130
+ let t15;
131
+ if ($[29] !== asset._fileId || $[30] !== onRemove) {
132
+ t15 = () => onRemove(asset._fileId);
133
+ $[29] = asset._fileId;
134
+ $[30] = onRemove;
135
+ $[31] = t15;
136
+ } else t15 = $[31];
137
+ let t16;
138
+ if ($[32] !== asset._fileId || $[33] !== t15) {
139
+ t16 = /* @__PURE__ */ jsx(UnlinkAssetButton, {
140
+ fileId: asset._fileId,
141
+ onUnlink: t15,
142
+ className: "hidden group-focus-within:flex group-hover:flex"
143
+ });
144
+ $[32] = asset._fileId;
145
+ $[33] = t15;
146
+ $[34] = t16;
147
+ } else t16 = $[34];
148
+ let t17;
149
+ if ($[35] !== setNodeRef || $[36] !== style || $[37] !== t14 || $[38] !== t16 || $[39] !== t7 || $[40] !== t9) {
150
+ t17 = /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("div", {
151
+ ref: setNodeRef,
152
+ style,
153
+ className: t7,
154
+ children: [
155
+ t9,
156
+ t14,
157
+ t16
158
+ ]
159
+ }) });
160
+ $[35] = setNodeRef;
161
+ $[36] = style;
162
+ $[37] = t14;
163
+ $[38] = t16;
164
+ $[39] = t7;
165
+ $[40] = t9;
166
+ $[41] = t17;
167
+ } else t17 = $[41];
168
+ return t17;
67
169
  };
68
- var MultipleAssetFieldEditor = ({ fieldName, assetType, currentData, onFieldChange }) => {
170
+ var MultipleAssetFieldEditor = (t0) => {
171
+ const $ = c(15);
172
+ const { fieldName, assetType, currentData, onFieldChange } = t0;
69
173
  const contentKey = assetType === "Image" ? "image" : "file";
70
174
  const isImage = assetType === "Image";
71
175
  const fileInputRef = React.useRef(null);
72
176
  const projectSlug = useProjectSlug();
73
- const { data: project } = useQuery(projectQueries.getBySlug(projectSlug));
74
- const items = (currentData[fieldName] ?? []).map((item) => item[contentKey]).filter((a) => !!a?.url);
75
- const toStorageFormat = (assets) => assets.map((a) => ({ [contentKey]: { _fileId: a._fileId } }));
177
+ let t1;
178
+ if ($[0] !== projectSlug) {
179
+ t1 = projectQueries.getBySlug(projectSlug);
180
+ $[0] = projectSlug;
181
+ $[1] = t1;
182
+ } else t1 = $[1];
183
+ const { data: project } = useQuery(t1);
184
+ const rawItems = currentData[fieldName] ?? [];
185
+ let t2;
186
+ if ($[2] !== contentKey) {
187
+ t2 = (item) => item[contentKey];
188
+ $[2] = contentKey;
189
+ $[3] = t2;
190
+ } else t2 = $[3];
191
+ const items = rawItems.map(t2).filter(_temp);
192
+ let t3;
193
+ if ($[4] !== contentKey) {
194
+ t3 = (assets) => assets.map((a_0) => ({ [contentKey]: { _fileId: a_0._fileId } }));
195
+ $[4] = contentKey;
196
+ $[5] = t3;
197
+ } else t3 = $[5];
198
+ const toStorageFormat = t3;
76
199
  const addFileId = (fileId) => {
77
200
  onFieldChange(fieldName, [...toStorageFormat(items), { [contentKey]: { _fileId: fileId } }]);
78
201
  };
@@ -84,69 +207,99 @@ var MultipleAssetFieldEditor = ({ fieldName, assetType, currentData, onFieldChan
84
207
  });
85
208
  const [pickerOpen, setPickerOpen] = React.useState(false);
86
209
  const [lightboxAsset, setLightboxAsset] = React.useState(null);
87
- const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }));
210
+ let t4;
211
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
212
+ t4 = { coordinateGetter: sortableKeyboardCoordinates };
213
+ $[6] = t4;
214
+ } else t4 = $[6];
215
+ const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, t4));
88
216
  const handleDragEnd = (event) => {
89
217
  const { active, over } = event;
90
218
  if (!over || active.id === over.id) return;
91
- const oldIndex = items.findIndex((a) => String(a._fileId) === active.id);
92
- const newIndex = items.findIndex((a) => String(a._fileId) === over.id);
219
+ const oldIndex = items.findIndex((a_1) => String(a_1._fileId) === active.id);
220
+ const newIndex = items.findIndex((a_2) => String(a_2._fileId) === over.id);
93
221
  if (oldIndex === -1 || newIndex === -1) return;
94
222
  const reordered = [...items];
95
223
  const [moved] = reordered.splice(oldIndex, 1);
96
224
  reordered.splice(newIndex, 0, moved);
97
225
  onFieldChange(fieldName, toStorageFormat(reordered));
98
226
  };
99
- const handleRemove = (fileId) => {
100
- onFieldChange(fieldName, toStorageFormat(items.filter((a) => a._fileId !== fileId)));
227
+ const handleRemove = (fileId_0) => {
228
+ onFieldChange(fieldName, toStorageFormat(items.filter((a_3) => a_3._fileId !== fileId_0)));
101
229
  };
102
230
  const handleSelectMultiple = (files) => {
103
231
  onFieldChange(fieldName, [...toStorageFormat(items), ...files.map((f) => ({ [contentKey]: { _fileId: f.id } }))]);
104
232
  setPickerOpen(false);
105
233
  };
106
- return /* @__PURE__ */ jsxs(UploadDropZone, {
107
- onDrop: uploadFiles,
108
- children: [pickerOpen ? /* @__PURE__ */ jsx(AssetPickerGrid, {
109
- assetType,
110
- mode: "multiple",
111
- onSelectSingle: () => {},
112
- onSelectMultiple: handleSelectMultiple,
113
- onClose: () => setPickerOpen(false)
114
- }) : /* @__PURE__ */ jsxs("div", {
115
- className: "space-y-4 px-4 py-4",
116
- children: [items.length > 0 && /* @__PURE__ */ jsx(DndContext, {
117
- sensors,
118
- collisionDetection: closestCenter,
119
- onDragEnd: handleDragEnd,
120
- modifiers: [restrictToVerticalAxis],
121
- children: /* @__PURE__ */ jsx(SortableContext, {
122
- items: items.map((a) => String(a._fileId)),
123
- strategy: verticalListSortingStrategy,
124
- children: /* @__PURE__ */ jsx("ul", {
125
- className: "flex flex-col gap-1",
126
- children: items.map((asset) => /* @__PURE__ */ jsx(SortableAssetItem, {
127
- asset,
128
- assetType,
129
- onRemove: handleRemove,
130
- onAssetOpen: setLightboxAsset
131
- }, asset._fileId))
132
- })
234
+ const T0 = UploadDropZone;
235
+ const t5 = pickerOpen ? /* @__PURE__ */ jsx(AssetPickerGrid, {
236
+ assetType,
237
+ mode: "multiple",
238
+ onSelectSingle: _temp2,
239
+ onSelectMultiple: handleSelectMultiple,
240
+ onClose: () => setPickerOpen(false)
241
+ }) : /* @__PURE__ */ jsxs("div", {
242
+ className: "space-y-4 px-4 py-4",
243
+ children: [items.length > 0 && /* @__PURE__ */ jsx(DndContext, {
244
+ sensors,
245
+ collisionDetection: closestCenter,
246
+ onDragEnd: handleDragEnd,
247
+ modifiers: [restrictToVerticalAxis],
248
+ children: /* @__PURE__ */ jsx(SortableContext, {
249
+ items: items.map(_temp3),
250
+ strategy: verticalListSortingStrategy,
251
+ children: /* @__PURE__ */ jsx("ul", {
252
+ className: "flex flex-col gap-1",
253
+ children: items.map((asset) => /* @__PURE__ */ jsx(SortableAssetItem, {
254
+ asset,
255
+ assetType,
256
+ onRemove: handleRemove,
257
+ onAssetOpen: setLightboxAsset
258
+ }, asset._fileId))
133
259
  })
134
- }), /* @__PURE__ */ jsx(AssetActionButtons, {
135
- isImage,
136
- multiple: true,
137
- fileInputRef,
138
- onPickerOpen: () => setPickerOpen(true),
139
- onFilesSelected: uploadFiles,
140
- uploads
141
- })]
142
- }), lightboxAsset && /* @__PURE__ */ jsx(AssetLightbox, {
260
+ })
261
+ }), /* @__PURE__ */ jsx(AssetActionButtons, {
262
+ isImage,
263
+ multiple: true,
264
+ fileInputRef,
265
+ onPickerOpen: () => setPickerOpen(true),
266
+ onFilesSelected: uploadFiles,
267
+ uploads
268
+ })]
269
+ });
270
+ let t6;
271
+ if ($[7] !== lightboxAsset || $[8] !== setLightboxAsset) {
272
+ t6 = lightboxAsset && /* @__PURE__ */ jsx(AssetLightbox, {
143
273
  open: !!lightboxAsset,
144
274
  onOpenChange: (open) => {
145
275
  if (!open) setLightboxAsset(null);
146
276
  },
147
277
  fileId: lightboxAsset._fileId
148
- })]
149
- });
278
+ });
279
+ $[7] = lightboxAsset;
280
+ $[8] = setLightboxAsset;
281
+ $[9] = t6;
282
+ } else t6 = $[9];
283
+ let t7;
284
+ if ($[10] !== T0 || $[11] !== t5 || $[12] !== t6 || $[13] !== uploadFiles) {
285
+ t7 = /* @__PURE__ */ jsxs(T0, {
286
+ onDrop: uploadFiles,
287
+ children: [t5, t6]
288
+ });
289
+ $[10] = T0;
290
+ $[11] = t5;
291
+ $[12] = t6;
292
+ $[13] = uploadFiles;
293
+ $[14] = t7;
294
+ } else t7 = $[14];
295
+ return t7;
150
296
  };
297
+ function _temp(a) {
298
+ return !!a?.url;
299
+ }
300
+ function _temp2() {}
301
+ function _temp3(a_4) {
302
+ return String(a_4._fileId);
303
+ }
151
304
  //#endregion
152
305
  export { MultipleAssetFieldEditor };
@@ -1,5 +1,6 @@
1
1
  import { previewStore } from "../previewStore.js";
2
2
  import { isOverlayMessage } from "../overlayMessages.js";
3
+ import { c } from "react/compiler-runtime";
3
4
  import { useFrame } from "@camox/ui/frame";
4
5
  import { useSelector } from "@xstate/store/react";
5
6
  import * as React from "react";
@@ -9,33 +10,67 @@ import * as React from "react";
9
10
  * Listening for focus commands from parent (for sidebar-triggered focus)
10
11
  */
11
12
  var OverlayTracker = () => {
13
+ const $ = c(8);
12
14
  const { window: iframeWindow } = useFrame();
13
- const isPageContentSheetOpen = useSelector(previewStore, (state) => state.context.isPageContentSheetOpen);
14
- const isAddBlockSheetOpen = useSelector(previewStore, (state) => state.context.isAddBlockSheetOpen);
15
- React.useEffect(() => {
16
- if (!iframeWindow || !isAddBlockSheetOpen) return;
17
- const handleClick = () => {
18
- previewStore.send({ type: "exitPeekedBlock" });
15
+ const isPageContentSheetOpen = useSelector(previewStore, _temp);
16
+ const isAddBlockSheetOpen = useSelector(previewStore, _temp2);
17
+ let t0;
18
+ let t1;
19
+ if ($[0] !== iframeWindow || $[1] !== isAddBlockSheetOpen) {
20
+ t0 = () => {
21
+ if (!iframeWindow || !isAddBlockSheetOpen) return;
22
+ const handleClick = _temp3;
23
+ iframeWindow.document.addEventListener("click", handleClick);
24
+ return () => iframeWindow.document.removeEventListener("click", handleClick);
19
25
  };
20
- iframeWindow.document.addEventListener("click", handleClick);
21
- return () => iframeWindow.document.removeEventListener("click", handleClick);
22
- }, [iframeWindow, isAddBlockSheetOpen]);
23
- React.useEffect(() => {
24
- if (!iframeWindow) return;
25
- const handleMessage = (event) => {
26
- if (!isOverlayMessage(event.data)) return;
27
- const { type } = event.data;
28
- if (type === "CAMOX_FOCUS_FIELD") {
29
- if (isPageContentSheetOpen) return;
30
- const { fieldId } = event.data;
31
- const element = iframeWindow.document.querySelector(`[data-camox-field-id="${fieldId}"]`);
32
- if (element) element.focus();
33
- }
26
+ t1 = [iframeWindow, isAddBlockSheetOpen];
27
+ $[0] = iframeWindow;
28
+ $[1] = isAddBlockSheetOpen;
29
+ $[2] = t0;
30
+ $[3] = t1;
31
+ } else {
32
+ t0 = $[2];
33
+ t1 = $[3];
34
+ }
35
+ React.useEffect(t0, t1);
36
+ let t2;
37
+ let t3;
38
+ if ($[4] !== iframeWindow || $[5] !== isPageContentSheetOpen) {
39
+ t2 = () => {
40
+ if (!iframeWindow) return;
41
+ const handleMessage = (event) => {
42
+ if (!isOverlayMessage(event.data)) return;
43
+ const { type } = event.data;
44
+ if (type === "CAMOX_FOCUS_FIELD") {
45
+ if (isPageContentSheetOpen) return;
46
+ const { fieldId } = event.data;
47
+ const element = iframeWindow.document.querySelector(`[data-camox-field-id="${fieldId}"]`);
48
+ if (element) element.focus();
49
+ }
50
+ };
51
+ iframeWindow.addEventListener("message", handleMessage);
52
+ return () => iframeWindow.removeEventListener("message", handleMessage);
34
53
  };
35
- iframeWindow.addEventListener("message", handleMessage);
36
- return () => iframeWindow.removeEventListener("message", handleMessage);
37
- }, [iframeWindow, isPageContentSheetOpen]);
54
+ t3 = [iframeWindow, isPageContentSheetOpen];
55
+ $[4] = iframeWindow;
56
+ $[5] = isPageContentSheetOpen;
57
+ $[6] = t2;
58
+ $[7] = t3;
59
+ } else {
60
+ t2 = $[6];
61
+ t3 = $[7];
62
+ }
63
+ React.useEffect(t2, t3);
38
64
  return null;
39
65
  };
66
+ function _temp(state) {
67
+ return state.context.isPageContentSheetOpen;
68
+ }
69
+ function _temp2(state_0) {
70
+ return state_0.context.isAddBlockSheetOpen;
71
+ }
72
+ function _temp3() {
73
+ previewStore.send({ type: "exitPeekedBlock" });
74
+ }
40
75
  //#endregion
41
76
  export { OverlayTracker };
@@ -2,58 +2,100 @@ import { previewStore } from "../previewStore.js";
2
2
  import { isOverlayMessage } from "../overlayMessages.js";
3
3
  import { usePageBlocks } from "../../../lib/normalized-data.js";
4
4
  import { usePreviewedPage } from "../CamoxPreview.js";
5
+ import { c } from "react/compiler-runtime";
5
6
  import { useSelector } from "@xstate/store/react";
6
7
  import * as React from "react";
7
8
  //#region src/features/preview/components/Overlays.tsx
8
- var Overlays = ({ iframeElement }) => {
9
- const isPageContentSheetOpen = useSelector(previewStore, (state) => state.context.isPageContentSheetOpen);
10
- const selection = useSelector(previewStore, (state) => state.context.selection);
11
- const peekedBlock = useSelector(previewStore, (state) => state.context.peekedBlock);
9
+ var Overlays = (t0) => {
10
+ const $ = c(14);
11
+ const { iframeElement } = t0;
12
+ const isPageContentSheetOpen = useSelector(previewStore, _temp);
13
+ const selection = useSelector(previewStore, _temp2);
14
+ const peekedBlock = useSelector(previewStore, _temp3);
12
15
  const page = usePreviewedPage();
13
16
  const { pageBlocks } = usePageBlocks(page);
14
- React.useEffect(() => {
15
- const handleMessage = (event) => {
16
- if (!isOverlayMessage(event.data)) return;
17
- const message = event.data;
18
- if (message.type === "CAMOX_ADD_BLOCK_REQUEST") {
19
- const { blockPosition, insertPosition } = message;
20
- let afterPosition = null;
21
- if (message.afterPosition !== void 0) afterPosition = message.afterPosition;
22
- else if (insertPosition === "after") afterPosition = blockPosition;
23
- else {
24
- const blockIndex = pageBlocks.findIndex((b) => b.position === blockPosition);
25
- if (blockIndex > 0) afterPosition = pageBlocks[blockIndex - 1].position ?? null;
26
- else if (blockIndex === 0) afterPosition = "";
17
+ let t1;
18
+ if ($[0] !== pageBlocks) {
19
+ t1 = () => {
20
+ const handleMessage = (event) => {
21
+ if (!isOverlayMessage(event.data)) return;
22
+ const message = event.data;
23
+ if (message.type === "CAMOX_ADD_BLOCK_REQUEST") {
24
+ const { blockPosition, insertPosition } = message;
25
+ let afterPosition = null;
26
+ if (message.afterPosition !== void 0) afterPosition = message.afterPosition;
27
+ else if (insertPosition === "after") afterPosition = blockPosition;
28
+ else {
29
+ const blockIndex = pageBlocks.findIndex((b) => b.position === blockPosition);
30
+ if (blockIndex > 0) afterPosition = pageBlocks[blockIndex - 1].position ?? null;
31
+ else if (blockIndex === 0) afterPosition = "";
32
+ }
33
+ previewStore.send({
34
+ type: "openAddBlockSheet",
35
+ afterPosition
36
+ });
27
37
  }
28
- previewStore.send({
29
- type: "openAddBlockSheet",
30
- afterPosition
31
- });
32
- }
38
+ };
39
+ window.addEventListener("message", handleMessage);
40
+ return () => window.removeEventListener("message", handleMessage);
33
41
  };
34
- window.addEventListener("message", handleMessage);
35
- return () => window.removeEventListener("message", handleMessage);
36
- }, [page]);
37
- React.useEffect(() => {
38
- if (isPageContentSheetOpen) return;
39
- if (peekedBlock) return;
40
- if (!selection) return;
41
- if (selection.type !== "block-field" && selection.type !== "item-field") return;
42
- if (selection.fieldType !== "String") return;
43
- const blockId = selection.blockId;
44
- const fieldName = selection.fieldName;
45
- const message = {
46
- type: "CAMOX_FOCUS_FIELD",
47
- fieldId: selection.type === "item-field" ? `${blockId}__${selection.itemId}__${fieldName}` : `${blockId}__${fieldName}`
42
+ $[0] = pageBlocks;
43
+ $[1] = t1;
44
+ } else t1 = $[1];
45
+ let t2;
46
+ if ($[2] !== page) {
47
+ t2 = [page];
48
+ $[2] = page;
49
+ $[3] = t2;
50
+ } else t2 = $[3];
51
+ React.useEffect(t1, t2);
52
+ let t3;
53
+ if ($[4] !== iframeElement?.contentWindow || $[5] !== isPageContentSheetOpen || $[6] !== peekedBlock || $[7] !== selection) {
54
+ t3 = () => {
55
+ if (isPageContentSheetOpen) return;
56
+ if (peekedBlock) return;
57
+ if (!selection) return;
58
+ if (selection.type !== "block-field" && selection.type !== "item-field") return;
59
+ if (selection.fieldType !== "String") return;
60
+ const blockId = selection.blockId;
61
+ const fieldName = selection.fieldName;
62
+ const message_0 = {
63
+ type: "CAMOX_FOCUS_FIELD",
64
+ fieldId: selection.type === "item-field" ? `${blockId}__${selection.itemId}__${fieldName}` : `${blockId}__${fieldName}`
65
+ };
66
+ iframeElement?.contentWindow?.postMessage(message_0, "*");
48
67
  };
49
- iframeElement?.contentWindow?.postMessage(message, "*");
50
- }, [
51
- selection,
52
- isPageContentSheetOpen,
53
- peekedBlock,
54
- iframeElement
55
- ]);
68
+ $[4] = iframeElement?.contentWindow;
69
+ $[5] = isPageContentSheetOpen;
70
+ $[6] = peekedBlock;
71
+ $[7] = selection;
72
+ $[8] = t3;
73
+ } else t3 = $[8];
74
+ let t4;
75
+ if ($[9] !== iframeElement || $[10] !== isPageContentSheetOpen || $[11] !== peekedBlock || $[12] !== selection) {
76
+ t4 = [
77
+ selection,
78
+ isPageContentSheetOpen,
79
+ peekedBlock,
80
+ iframeElement
81
+ ];
82
+ $[9] = iframeElement;
83
+ $[10] = isPageContentSheetOpen;
84
+ $[11] = peekedBlock;
85
+ $[12] = selection;
86
+ $[13] = t4;
87
+ } else t4 = $[13];
88
+ React.useEffect(t3, t4);
56
89
  return null;
57
90
  };
91
+ function _temp(state) {
92
+ return state.context.isPageContentSheetOpen;
93
+ }
94
+ function _temp2(state_0) {
95
+ return state_0.context.selection;
96
+ }
97
+ function _temp3(state_1) {
98
+ return state_1.context.peekedBlock;
99
+ }
58
100
  //#endregion
59
101
  export { Overlays };