camox 0.48.0 → 0.52.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.
- package/dist/core/createApp.d.ts +1 -0
- package/dist/core/createApp.js +1 -0
- package/dist/core/editing/contentEdits.js +78 -0
- package/dist/core/editing/createEditableBlock.js +277 -311
- package/dist/core/layoutContext.d.ts +1 -0
- package/dist/core/lib/contentType.js +2 -2
- package/dist/core/recordItem.js +3 -3
- package/dist/features/canvas/CamoxCanvas.js +15 -15
- package/dist/features/canvas/CanvasLoadingScreen.js +15 -11
- package/dist/features/canvas/CanvasPageFrame.js +81 -87
- package/dist/features/canvas/CanvasPreviewPageSlot.js +1 -1
- package/dist/features/canvas/DerivedPagePathInput.js +12 -12
- package/dist/features/canvas/canvasOverlayGeometry.js +1 -1
- package/dist/features/canvas/canvasStore.js +2 -2
- package/dist/features/canvas/sidebar/CanvasInspector.js +1 -1
- package/dist/features/canvas/sidebar/CuratedPageInspector.js +1 -1
- package/dist/features/canvas/sidebar/LayoutPageBlocks.js +23 -31
- package/dist/features/canvas/useCanvasCamera.js +1 -1
- package/dist/features/canvas/useDiscoveredPreviewPaths.js +16 -9
- package/dist/features/content/ContentAssets.js +84 -88
- package/dist/features/page/CuratedPageContent.js +1 -1
- package/dist/features/preview/CamoxPreview.d.ts +8 -4
- package/dist/features/preview/CamoxPreview.js +258 -443
- package/dist/features/preview/EditablePageContent.js +244 -2
- package/dist/features/preview/EditablePageExperience.js +19 -13
- package/dist/features/preview/components/AddBlockSheet.js +55 -15
- package/dist/features/preview/components/BlockActionsPopover.js +23 -51
- package/dist/features/preview/components/BlockPeek.js +66 -0
- package/dist/features/preview/components/BlockThumbnail.js +134 -119
- package/dist/features/preview/components/CanvasPreview.js +1 -1
- package/dist/features/preview/components/CreatePageModal.js +150 -156
- package/dist/features/preview/components/FieldToolbar.js +1 -1
- package/dist/features/preview/components/Frame.js +27 -4
- package/dist/features/preview/components/MobilePreviewDrawer.js +6 -9
- package/dist/features/preview/components/PageInfo.js +161 -126
- package/dist/features/preview/components/PagePicker.js +2 -2
- package/dist/features/preview/components/PageTree.js +174 -190
- package/dist/features/preview/components/PreviewPanel.js +13 -67
- package/dist/features/preview/components/PreviewToolbar.js +1 -1
- package/dist/features/preview/components/ReferenceFieldEditor.js +4 -4
- package/dist/features/preview/components/ReferenceListFieldEditor.js +4 -4
- package/dist/features/preview/components/RemovedBlockPlaceholder.js +37 -70
- package/dist/features/preview/components/RepeatableItemsList.js +1 -1
- package/dist/features/preview/components/SelectionEditor.js +248 -256
- package/dist/features/preview/components/StudioEditingFallback.js +22 -26
- package/dist/features/preview/components/useFieldWriter.js +19 -19
- package/dist/features/preview/components/useRecordView.js +105 -147
- package/dist/features/preview/components/useRepeatableItemActions.js +0 -2
- package/dist/features/preview/pageRecord.js +30 -24
- package/dist/features/preview/previewConstants.js +2 -8
- package/dist/features/preview/previewStore.js +2 -0
- package/dist/features/preview/studioNotice.js +20 -0
- package/dist/features/preview/usePreviewViewportActions.js +1 -1
- package/dist/features/provider/AuthenticatedCamoxProvider.js +47 -31
- package/dist/features/provider/components/CommandPalette.js +2 -5
- package/dist/features/provider/signInShortcut.js +1 -2
- package/dist/features/provider/useAdminShortcuts.js +47 -53
- package/dist/features/renderer/RendererApp.js +542 -0
- package/dist/features/renderer/RendererFrames.js +450 -0
- package/dist/features/renderer/definitionAnswers.js +26 -0
- package/dist/features/renderer/protocol.js +35 -0
- package/dist/features/renderer/rendererHost.js +249 -0
- package/dist/features/renderer/studioConnection.js +186 -0
- package/dist/features/routes/pageRuntime.d.ts +2 -1
- package/dist/features/routes/pageRuntime.js +34 -22
- package/dist/features/runtime/RuntimeChrome.js +2 -5
- package/dist/features/runtime/assetPrefix.js +14 -0
- package/dist/features/runtime/breadcrumbs.js +1 -1
- package/dist/features/runtime/editingFallback.js +4 -8
- package/dist/features/runtime/livePages.js +1 -1
- package/dist/features/runtime/pageApp.js +57 -83
- package/dist/features/runtime/pageClient.js +1 -1
- package/dist/features/runtime/pageNavigation.js +3 -2
- package/dist/features/runtime/publicCache.js +95 -0
- package/dist/features/runtime/publishingDraft.js +23 -0
- package/dist/features/runtime/rendererClient.d.ts +8 -0
- package/dist/features/runtime/rendererClient.js +77 -0
- package/dist/features/runtime/runtime.d.ts +22 -3
- package/dist/features/runtime/runtime.js +209 -96
- package/dist/features/runtime/runtimeRoutes.d.ts +2 -0
- package/dist/features/runtime/runtimeRoutes.js +2 -0
- package/dist/features/runtime/worker.d.ts +14 -1
- package/dist/features/runtime/worker.js +34 -4
- package/dist/features/settings/AnalyticsSettings.js +622 -0
- package/dist/features/settings/CamoxSettings.js +95 -0
- package/dist/features/settings/FaviconSettings.js +254 -0
- package/dist/features/settings/ProjectNameSettings.js +145 -0
- package/dist/features/settings/SettingsPart.js +73 -0
- package/dist/features/settings/SocialProfilesSettings.js +245 -0
- package/dist/features/settings/useProjectMutation.js +61 -0
- package/dist/features/studio/FollowAgentProvider.js +10 -10
- package/dist/features/studio/components/DraftsControl.js +136 -131
- package/dist/features/studio/components/LocalePicker.js +178 -174
- package/dist/features/studio/components/Navbar.js +107 -66
- package/dist/features/studio/components/ProjectMenu.js +119 -171
- package/dist/features/studio/components/ReviewDraftSheet.js +1151 -991
- package/dist/features/studio/components/ThreadMessages.js +100 -65
- package/dist/features/studio/components/UserButton.js +2 -2
- package/dist/features/studio/routes.js +3 -1
- package/dist/features/studio/showInCanvas.js +129 -0
- package/dist/features/vite/definitionsSync.js +5 -6
- package/dist/features/vite/hostedChecks.js +127 -0
- package/dist/features/vite/runtimeDev.js +58 -17
- package/dist/features/vite/staticAssetHeaders.js +52 -0
- package/dist/features/vite/vite.d.ts +1 -1
- package/dist/features/vite/vite.js +49 -9
- package/dist/hooks/use-page-destinations.js +10 -10
- package/dist/lib/api-client-server.d.ts +1 -1
- package/dist/lib/api-client.d.ts +2 -1
- package/dist/lib/draft-scope.d.ts +1 -0
- package/dist/lib/locale-path.d.ts +3 -11
- package/dist/lib/locale-path.js +3 -27
- package/dist/lib/queries.js +7 -1
- package/dist/lib/revisions.js +20 -0
- package/dist/lib/shortcuts.js +29 -0
- package/dist/lib/studio-definitions.js +160 -0
- package/dist/lib/studio-reads.d.ts +1 -0
- package/dist/lib/studio-reads.js +65 -21
- package/dist/lib/use-project-room.js +16 -10
- package/dist/lib/utils.js +1 -104
- package/dist/package.js +1 -1
- package/dist/studio.css +1 -1
- package/package.json +9 -4
- package/skills/camox/SKILL.md +4 -0
- package/skills/camox/references/artifacts.md +1 -1
- package/dist/features/studio/components/FaviconDialog.js +0 -318
- package/dist/features/studio/components/SocialProfilesDialog.js +0 -342
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import { useDraftScope } from "../../lib/draft-scope.js";
|
|
2
|
+
import { ViewLocaleContext } from "../../lib/view-locale-context.js";
|
|
3
|
+
import { useLocation, useNavigate } from "../navigation/navigation.js";
|
|
4
|
+
import { runtimePath } from "../runtime/navigationTarget.js";
|
|
5
|
+
import { useStudioCache } from "../../lib/studio-reads.js";
|
|
6
|
+
import { ArtifactStudioContext, ArtifactsRunContext } from "../../core/hooks/useArtifactHost.js";
|
|
7
|
+
import { EditableSurfaceContext } from "../../core/hooks/useIsEditable.js";
|
|
8
|
+
import { RevisionsContext } from "../../lib/revisions.js";
|
|
9
|
+
import { CanvasWorkspaceContext } from "../canvas/canvasZoom.js";
|
|
10
|
+
import { PreviewEditingOwnerContext } from "../preview/previewSelection.js";
|
|
11
|
+
import { showNotice } from "../preview/studioNotice.js";
|
|
12
|
+
import { RENDERER_DOCUMENT_PATH, STUDIO_HANDLE_KEY } from "./protocol.js";
|
|
13
|
+
import { createRendererHost } from "./rendererHost.js";
|
|
14
|
+
import { c } from "react/compiler-runtime";
|
|
15
|
+
import * as React from "react";
|
|
16
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
18
|
+
|
|
19
|
+
//#region src/features/renderer/RendererFrames.tsx
|
|
20
|
+
/** The Website Section's renderer host. `RendererFramesProvider` provides it. */
|
|
21
|
+
const RendererHostContext = React.createContext(null);
|
|
22
|
+
/** The Website Section's renderer host, once it exists: null before, and outside the section. */
|
|
23
|
+
function useRendererHost() {
|
|
24
|
+
return React.use(RendererHostContext);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* What the renderer frame's code answers `question`, asked again whenever another renderer
|
|
28
|
+
* connects (a draft move or a reload): undefined until it answers, without a renderer, or
|
|
29
|
+
* without a question.
|
|
30
|
+
*/
|
|
31
|
+
function useRendererAnswer(question) {
|
|
32
|
+
const $ = c(12);
|
|
33
|
+
const host = useRendererHost();
|
|
34
|
+
let t0;
|
|
35
|
+
if ($[0] !== question) {
|
|
36
|
+
t0 = question ? JSON.stringify(question) : null;
|
|
37
|
+
$[0] = question;
|
|
38
|
+
$[1] = t0;
|
|
39
|
+
} else t0 = $[1];
|
|
40
|
+
const json = t0;
|
|
41
|
+
const connections = React.useRef(0);
|
|
42
|
+
let t1;
|
|
43
|
+
if ($[2] !== host) {
|
|
44
|
+
t1 = (listener) => host ? host.subscribe(() => {
|
|
45
|
+
connections.current = connections.current + 1;
|
|
46
|
+
listener();
|
|
47
|
+
}) : _temp;
|
|
48
|
+
$[2] = host;
|
|
49
|
+
$[3] = t1;
|
|
50
|
+
} else t1 = $[3];
|
|
51
|
+
const subscribe = t1;
|
|
52
|
+
let t2;
|
|
53
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
54
|
+
t2 = () => connections.current;
|
|
55
|
+
$[4] = t2;
|
|
56
|
+
} else t2 = $[4];
|
|
57
|
+
const connection = React.useSyncExternalStore(subscribe, t2);
|
|
58
|
+
const [answer, setAnswer] = React.useState();
|
|
59
|
+
let t3;
|
|
60
|
+
if ($[5] !== host || $[6] !== json) {
|
|
61
|
+
t3 = () => {
|
|
62
|
+
if (!host || !json) return;
|
|
63
|
+
let current = true;
|
|
64
|
+
host.ask(JSON.parse(json)).then((value) => current && setAnswer({
|
|
65
|
+
asked: json,
|
|
66
|
+
value
|
|
67
|
+
}), () => current && setAnswer({
|
|
68
|
+
asked: json,
|
|
69
|
+
value: void 0
|
|
70
|
+
}));
|
|
71
|
+
return () => {
|
|
72
|
+
current = false;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
$[5] = host;
|
|
76
|
+
$[6] = json;
|
|
77
|
+
$[7] = t3;
|
|
78
|
+
} else t3 = $[7];
|
|
79
|
+
let t4;
|
|
80
|
+
if ($[8] !== connection || $[9] !== host || $[10] !== json) {
|
|
81
|
+
t4 = [
|
|
82
|
+
host,
|
|
83
|
+
json,
|
|
84
|
+
connection
|
|
85
|
+
];
|
|
86
|
+
$[8] = connection;
|
|
87
|
+
$[9] = host;
|
|
88
|
+
$[10] = json;
|
|
89
|
+
$[11] = t4;
|
|
90
|
+
} else t4 = $[11];
|
|
91
|
+
React.useEffect(t3, t4);
|
|
92
|
+
return answer && answer.asked === json ? answer.value : void 0;
|
|
93
|
+
}
|
|
94
|
+
function _temp() {}
|
|
95
|
+
/**
|
|
96
|
+
* The Website Section's renderer frame: one hidden frame loading the renderer document of the
|
|
97
|
+
* draft the studio views, which renders every page the section's frames show (ADR 0023).
|
|
98
|
+
*
|
|
99
|
+
* A renderer shows one draft. Moving to another loads another renderer document, with a cache
|
|
100
|
+
* of its own. A draft the studio's first content write starts is Live plus that write, so the
|
|
101
|
+
* renderer showing Live enters it instead. Each new revision of the draft shown loads it again:
|
|
102
|
+
* the studio keeps the Canvas position and selection, and tells the new renderer.
|
|
103
|
+
*/
|
|
104
|
+
function RendererFramesProvider(t0) {
|
|
105
|
+
const $ = c(27);
|
|
106
|
+
const { runtimeBasePath, children } = t0;
|
|
107
|
+
const queryClient = useQueryClient();
|
|
108
|
+
const studioCache = useStudioCache();
|
|
109
|
+
const draftScope = useDraftScope();
|
|
110
|
+
const [host, setHost] = React.useState(null);
|
|
111
|
+
let t1;
|
|
112
|
+
let t2;
|
|
113
|
+
if ($[0] !== draftScope || $[1] !== queryClient || $[2] !== studioCache) {
|
|
114
|
+
t1 = () => {
|
|
115
|
+
const created = createRendererHost({
|
|
116
|
+
studioCache,
|
|
117
|
+
draftScope,
|
|
118
|
+
queryClient,
|
|
119
|
+
notify: showNotice
|
|
120
|
+
});
|
|
121
|
+
setHost(created);
|
|
122
|
+
return () => created.close();
|
|
123
|
+
};
|
|
124
|
+
t2 = [
|
|
125
|
+
studioCache,
|
|
126
|
+
draftScope,
|
|
127
|
+
queryClient
|
|
128
|
+
];
|
|
129
|
+
$[0] = draftScope;
|
|
130
|
+
$[1] = queryClient;
|
|
131
|
+
$[2] = studioCache;
|
|
132
|
+
$[3] = t1;
|
|
133
|
+
$[4] = t2;
|
|
134
|
+
} else {
|
|
135
|
+
t1 = $[3];
|
|
136
|
+
t2 = $[4];
|
|
137
|
+
}
|
|
138
|
+
React.useEffect(t1, t2);
|
|
139
|
+
let t3;
|
|
140
|
+
if ($[5] !== draftScope || $[6] !== runtimeBasePath) {
|
|
141
|
+
t3 = () => draftScope.hrefFor(runtimePath(RENDERER_DOCUMENT_PATH, runtimeBasePath));
|
|
142
|
+
$[5] = draftScope;
|
|
143
|
+
$[6] = runtimeBasePath;
|
|
144
|
+
$[7] = t3;
|
|
145
|
+
} else t3 = $[7];
|
|
146
|
+
const documentUrl = t3;
|
|
147
|
+
const [source, setSource] = React.useState(documentUrl);
|
|
148
|
+
let t4;
|
|
149
|
+
let t5;
|
|
150
|
+
if ($[8] !== documentUrl || $[9] !== draftScope) {
|
|
151
|
+
t4 = () => draftScope.subscribe((t6) => {
|
|
152
|
+
const { move } = t6;
|
|
153
|
+
if (move !== "started") setSource(documentUrl());
|
|
154
|
+
});
|
|
155
|
+
t5 = [draftScope, documentUrl];
|
|
156
|
+
$[8] = documentUrl;
|
|
157
|
+
$[9] = draftScope;
|
|
158
|
+
$[10] = t4;
|
|
159
|
+
$[11] = t5;
|
|
160
|
+
} else {
|
|
161
|
+
t4 = $[10];
|
|
162
|
+
t5 = $[11];
|
|
163
|
+
}
|
|
164
|
+
React.useEffect(t4, t5);
|
|
165
|
+
const [loads, setLoads] = React.useState(0);
|
|
166
|
+
const revisions = React.use(RevisionsContext);
|
|
167
|
+
let t6;
|
|
168
|
+
let t7;
|
|
169
|
+
if ($[12] !== draftScope || $[13] !== revisions) {
|
|
170
|
+
t6 = () => revisions?.subscribe((t8) => {
|
|
171
|
+
const { draftId } = t8;
|
|
172
|
+
if (draftId === draftScope.current()) setLoads(_temp2);
|
|
173
|
+
});
|
|
174
|
+
t7 = [revisions, draftScope];
|
|
175
|
+
$[12] = draftScope;
|
|
176
|
+
$[13] = revisions;
|
|
177
|
+
$[14] = t6;
|
|
178
|
+
$[15] = t7;
|
|
179
|
+
} else {
|
|
180
|
+
t6 = $[14];
|
|
181
|
+
t7 = $[15];
|
|
182
|
+
}
|
|
183
|
+
React.useEffect(t6, t7);
|
|
184
|
+
let t8;
|
|
185
|
+
if ($[16] !== host) {
|
|
186
|
+
t8 = (frame) => {
|
|
187
|
+
if (frame && host) frame[STUDIO_HANDLE_KEY] = host.handle;
|
|
188
|
+
};
|
|
189
|
+
$[16] = host;
|
|
190
|
+
$[17] = t8;
|
|
191
|
+
} else t8 = $[17];
|
|
192
|
+
const connect = t8;
|
|
193
|
+
let t9;
|
|
194
|
+
if ($[18] !== connect || $[19] !== host || $[20] !== loads || $[21] !== source) {
|
|
195
|
+
t9 = host && /* @__PURE__ */ jsx("iframe", {
|
|
196
|
+
ref: connect,
|
|
197
|
+
src: source,
|
|
198
|
+
hidden: true,
|
|
199
|
+
title: "Website renderer",
|
|
200
|
+
"data-camox-renderer": true
|
|
201
|
+
}, `${source}#${loads}`);
|
|
202
|
+
$[18] = connect;
|
|
203
|
+
$[19] = host;
|
|
204
|
+
$[20] = loads;
|
|
205
|
+
$[21] = source;
|
|
206
|
+
$[22] = t9;
|
|
207
|
+
} else t9 = $[22];
|
|
208
|
+
let t10;
|
|
209
|
+
if ($[23] !== children || $[24] !== host || $[25] !== t9) {
|
|
210
|
+
t10 = /* @__PURE__ */ jsxs(RendererHostContext, {
|
|
211
|
+
value: host,
|
|
212
|
+
children: [children, t9]
|
|
213
|
+
});
|
|
214
|
+
$[23] = children;
|
|
215
|
+
$[24] = host;
|
|
216
|
+
$[25] = t9;
|
|
217
|
+
$[26] = t10;
|
|
218
|
+
} else t10 = $[26];
|
|
219
|
+
return t10;
|
|
220
|
+
}
|
|
221
|
+
function _temp2(count) {
|
|
222
|
+
return count + 1;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Where the renderer renders a page, inside one of the Website Section's frames: the place a
|
|
226
|
+
* frame used to render the page itself. What the frame around it says (its owner, whether it is
|
|
227
|
+
* editable, its Canvas workspace, location and locale) tells the renderer how to render it.
|
|
228
|
+
*/
|
|
229
|
+
function RendererSlot(t0) {
|
|
230
|
+
const $ = c(43);
|
|
231
|
+
const { pathname, derivedLayoutId, resting: t1, onRendered, onFailed } = t0;
|
|
232
|
+
const resting = t1 === void 0 ? false : t1;
|
|
233
|
+
const host = useRendererHost();
|
|
234
|
+
const frameId = React.useId();
|
|
235
|
+
const [slot, setSlot] = React.useState(null);
|
|
236
|
+
const owner = React.use(PreviewEditingOwnerContext);
|
|
237
|
+
const editable = React.use(EditableSurfaceContext);
|
|
238
|
+
const artifactsRun = React.use(ArtifactsRunContext);
|
|
239
|
+
const artifactStudio = React.use(ArtifactStudioContext);
|
|
240
|
+
const workspace = React.use(CanvasWorkspaceContext);
|
|
241
|
+
const locale = React.use(ViewLocaleContext);
|
|
242
|
+
const { href } = useLocation();
|
|
243
|
+
const navigate = useNavigate();
|
|
244
|
+
const workspaceKey = workspace?.workspaceKey;
|
|
245
|
+
let t2;
|
|
246
|
+
if ($[0] !== derivedLayoutId) {
|
|
247
|
+
t2 = derivedLayoutId && { derivedLayoutId };
|
|
248
|
+
$[0] = derivedLayoutId;
|
|
249
|
+
$[1] = t2;
|
|
250
|
+
} else t2 = $[1];
|
|
251
|
+
let t3;
|
|
252
|
+
if ($[2] !== workspaceKey) {
|
|
253
|
+
t3 = workspaceKey === void 0 ? null : { workspaceKey };
|
|
254
|
+
$[2] = workspaceKey;
|
|
255
|
+
$[3] = t3;
|
|
256
|
+
} else t3 = $[3];
|
|
257
|
+
let t4;
|
|
258
|
+
if ($[4] !== artifactStudio || $[5] !== artifactsRun || $[6] !== editable || $[7] !== href || $[8] !== locale || $[9] !== owner || $[10] !== pathname || $[11] !== resting || $[12] !== t2 || $[13] !== t3) {
|
|
259
|
+
t4 = {
|
|
260
|
+
pathname,
|
|
261
|
+
href,
|
|
262
|
+
...t2,
|
|
263
|
+
owner,
|
|
264
|
+
locale,
|
|
265
|
+
editable,
|
|
266
|
+
artifactsRun,
|
|
267
|
+
artifactStudio,
|
|
268
|
+
resting,
|
|
269
|
+
canvas: t3
|
|
270
|
+
};
|
|
271
|
+
$[4] = artifactStudio;
|
|
272
|
+
$[5] = artifactsRun;
|
|
273
|
+
$[6] = editable;
|
|
274
|
+
$[7] = href;
|
|
275
|
+
$[8] = locale;
|
|
276
|
+
$[9] = owner;
|
|
277
|
+
$[10] = pathname;
|
|
278
|
+
$[11] = resting;
|
|
279
|
+
$[12] = t2;
|
|
280
|
+
$[13] = t3;
|
|
281
|
+
$[14] = t4;
|
|
282
|
+
} else t4 = $[14];
|
|
283
|
+
const target = useSameJson(t4);
|
|
284
|
+
let t5;
|
|
285
|
+
if ($[15] !== navigate || $[16] !== onFailed || $[17] !== onRendered || $[18] !== workspace) {
|
|
286
|
+
t5 = {
|
|
287
|
+
onRendered,
|
|
288
|
+
onFailed,
|
|
289
|
+
navigate,
|
|
290
|
+
workspace
|
|
291
|
+
};
|
|
292
|
+
$[15] = navigate;
|
|
293
|
+
$[16] = onFailed;
|
|
294
|
+
$[17] = onRendered;
|
|
295
|
+
$[18] = workspace;
|
|
296
|
+
$[19] = t5;
|
|
297
|
+
} else t5 = $[19];
|
|
298
|
+
const latest = React.useRef(t5);
|
|
299
|
+
let t6;
|
|
300
|
+
if ($[20] !== navigate || $[21] !== onFailed || $[22] !== onRendered || $[23] !== workspace) {
|
|
301
|
+
t6 = () => {
|
|
302
|
+
latest.current = {
|
|
303
|
+
onRendered,
|
|
304
|
+
onFailed,
|
|
305
|
+
navigate,
|
|
306
|
+
workspace
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
$[20] = navigate;
|
|
310
|
+
$[21] = onFailed;
|
|
311
|
+
$[22] = onRendered;
|
|
312
|
+
$[23] = workspace;
|
|
313
|
+
$[24] = t6;
|
|
314
|
+
} else t6 = $[24];
|
|
315
|
+
React.useLayoutEffect(t6);
|
|
316
|
+
let t7;
|
|
317
|
+
if ($[25] === Symbol.for("react.memo_cache_sentinel")) {
|
|
318
|
+
t7 = () => ({
|
|
319
|
+
rendered: () => latest.current.onRendered?.(),
|
|
320
|
+
failed: (message) => latest.current.onFailed?.(message),
|
|
321
|
+
navigate: (to) => void latest.current.navigate({ to }),
|
|
322
|
+
reveal: (element, immediate) => latest.current.workspace?.reveal(element, immediate)
|
|
323
|
+
});
|
|
324
|
+
$[25] = t7;
|
|
325
|
+
} else t7 = $[25];
|
|
326
|
+
const [hears] = React.useState(t7);
|
|
327
|
+
let t8;
|
|
328
|
+
let t9;
|
|
329
|
+
if ($[26] !== frameId || $[27] !== hears || $[28] !== host || $[29] !== slot || $[30] !== target) {
|
|
330
|
+
t8 = () => {
|
|
331
|
+
if (host && slot) host.show(frameId, slot, target, hears);
|
|
332
|
+
};
|
|
333
|
+
t9 = [
|
|
334
|
+
host,
|
|
335
|
+
slot,
|
|
336
|
+
frameId,
|
|
337
|
+
target,
|
|
338
|
+
hears
|
|
339
|
+
];
|
|
340
|
+
$[26] = frameId;
|
|
341
|
+
$[27] = hears;
|
|
342
|
+
$[28] = host;
|
|
343
|
+
$[29] = slot;
|
|
344
|
+
$[30] = target;
|
|
345
|
+
$[31] = t8;
|
|
346
|
+
$[32] = t9;
|
|
347
|
+
} else {
|
|
348
|
+
t8 = $[31];
|
|
349
|
+
t9 = $[32];
|
|
350
|
+
}
|
|
351
|
+
React.useLayoutEffect(t8, t9);
|
|
352
|
+
let t10;
|
|
353
|
+
let t11;
|
|
354
|
+
if ($[33] !== frameId || $[34] !== host || $[35] !== slot) {
|
|
355
|
+
t10 = () => {
|
|
356
|
+
if (!host || !slot) return;
|
|
357
|
+
return () => host.hide(frameId);
|
|
358
|
+
};
|
|
359
|
+
t11 = [
|
|
360
|
+
host,
|
|
361
|
+
slot,
|
|
362
|
+
frameId
|
|
363
|
+
];
|
|
364
|
+
$[33] = frameId;
|
|
365
|
+
$[34] = host;
|
|
366
|
+
$[35] = slot;
|
|
367
|
+
$[36] = t10;
|
|
368
|
+
$[37] = t11;
|
|
369
|
+
} else {
|
|
370
|
+
t10 = $[36];
|
|
371
|
+
t11 = $[37];
|
|
372
|
+
}
|
|
373
|
+
React.useLayoutEffect(t10, t11);
|
|
374
|
+
const status = useRendererStatus(host);
|
|
375
|
+
let t12;
|
|
376
|
+
if ($[38] === Symbol.for("react.memo_cache_sentinel")) {
|
|
377
|
+
t12 = /* @__PURE__ */ jsx("div", {
|
|
378
|
+
ref: setSlot,
|
|
379
|
+
"data-camox-renderer-slot": true,
|
|
380
|
+
style: { display: "contents" }
|
|
381
|
+
});
|
|
382
|
+
$[38] = t12;
|
|
383
|
+
} else t12 = $[38];
|
|
384
|
+
let t13;
|
|
385
|
+
if ($[39] !== status) {
|
|
386
|
+
t13 = status === "updating" && /* @__PURE__ */ jsx("div", {
|
|
387
|
+
role: "status",
|
|
388
|
+
"data-camox-renderer-updating": true,
|
|
389
|
+
style: NOTICE_STYLE,
|
|
390
|
+
children: "Updating the preview…"
|
|
391
|
+
});
|
|
392
|
+
$[39] = status;
|
|
393
|
+
$[40] = t13;
|
|
394
|
+
} else t13 = $[40];
|
|
395
|
+
let t14;
|
|
396
|
+
if ($[41] !== t13) {
|
|
397
|
+
t14 = /* @__PURE__ */ jsxs(Fragment, { children: [t12, t13] });
|
|
398
|
+
$[41] = t13;
|
|
399
|
+
$[42] = t14;
|
|
400
|
+
} else t14 = $[42];
|
|
401
|
+
return t14;
|
|
402
|
+
}
|
|
403
|
+
/** What the studio says in a frame in place of its page, in the frame's own document. */
|
|
404
|
+
const NOTICE_STYLE = {
|
|
405
|
+
padding: "24px",
|
|
406
|
+
fontFamily: "system-ui, sans-serif",
|
|
407
|
+
fontSize: "14px",
|
|
408
|
+
color: "#71717a"
|
|
409
|
+
};
|
|
410
|
+
/** Where the renderer frame of `host` is: null without a host. */
|
|
411
|
+
function useRendererStatus(host) {
|
|
412
|
+
const $ = c(4);
|
|
413
|
+
let t0;
|
|
414
|
+
if ($[0] !== host) {
|
|
415
|
+
t0 = (listener) => host?.subscribeStatus(listener) ?? _temp3;
|
|
416
|
+
$[0] = host;
|
|
417
|
+
$[1] = t0;
|
|
418
|
+
} else t0 = $[1];
|
|
419
|
+
const subscribe = t0;
|
|
420
|
+
let t1;
|
|
421
|
+
if ($[2] !== host) {
|
|
422
|
+
t1 = () => host?.status() ?? null;
|
|
423
|
+
$[2] = host;
|
|
424
|
+
$[3] = t1;
|
|
425
|
+
} else t1 = $[3];
|
|
426
|
+
const status = t1;
|
|
427
|
+
return React.useSyncExternalStore(subscribe, status, status);
|
|
428
|
+
}
|
|
429
|
+
function _temp3() {}
|
|
430
|
+
/** `value`, kept while it says the same, so a re-render doesn't show the frame again. */
|
|
431
|
+
function useSameJson(value) {
|
|
432
|
+
const $ = c(4);
|
|
433
|
+
let t0;
|
|
434
|
+
if ($[0] !== value) {
|
|
435
|
+
t0 = JSON.stringify(value);
|
|
436
|
+
$[0] = value;
|
|
437
|
+
$[1] = t0;
|
|
438
|
+
} else t0 = $[1];
|
|
439
|
+
const json = t0;
|
|
440
|
+
let t1;
|
|
441
|
+
if ($[2] !== json) {
|
|
442
|
+
t1 = JSON.parse(json);
|
|
443
|
+
$[2] = json;
|
|
444
|
+
$[3] = t1;
|
|
445
|
+
} else t1 = $[3];
|
|
446
|
+
return t1;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
//#endregion
|
|
450
|
+
export { RendererFramesProvider, RendererHostContext, RendererSlot, useRendererAnswer, useRendererHost, useRendererStatus };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { curatedLayoutContext } from "../../core/layoutContext.js";
|
|
2
|
+
|
|
3
|
+
//#region src/features/renderer/definitionAnswers.ts
|
|
4
|
+
/** The block of `type` in the draft's code, loading it if it is lazy. */
|
|
5
|
+
async function blockOfCode(camoxApp, type) {
|
|
6
|
+
const block = camoxApp.getBlockById(type);
|
|
7
|
+
if (block || !camoxApp.canLoadMoreBlocks()) return block;
|
|
8
|
+
return camoxApp.loadBlock(type);
|
|
9
|
+
}
|
|
10
|
+
async function answerFromCode(camoxApp, question) {
|
|
11
|
+
switch (question.type) {
|
|
12
|
+
case "initialBundle": return (await blockOfCode(camoxApp, question.blockType))?._internal.getInitialBundle() ?? null;
|
|
13
|
+
case "pageTitle": {
|
|
14
|
+
const layout = camoxApp.getLayoutById(question.layoutId);
|
|
15
|
+
if (!layout) return null;
|
|
16
|
+
const { page, projectName, locale } = question;
|
|
17
|
+
return layout._internal.toTitle(curatedLayoutContext({
|
|
18
|
+
page,
|
|
19
|
+
projectName
|
|
20
|
+
}, locale));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { answerFromCode, blockOfCode };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RUNTIME_ROUTE_PATHS } from "../runtime/runtimeRoutes.js";
|
|
2
|
+
import { version } from "../../package.js";
|
|
3
|
+
|
|
4
|
+
//#region src/features/renderer/protocol.ts
|
|
5
|
+
/** The SDK version this side of the protocol was built with. Both sides must share it. */
|
|
6
|
+
const SDK_VERSION = version;
|
|
7
|
+
/** The property of the renderer frame's element that holds the studio's {@link StudioHandle}. */
|
|
8
|
+
const STUDIO_HANDLE_KEY = "__camoxStudio";
|
|
9
|
+
/** The runtime route that serves the renderer document. */
|
|
10
|
+
const RENDERER_DOCUMENT_PATH = RUNTIME_ROUTE_PATHS.renderer;
|
|
11
|
+
/**
|
|
12
|
+
* An inbox that handles each message later, in order, apart from the call that delivered it: the
|
|
13
|
+
* sender never runs the receiver's code, and never sees its errors. `onError` hears them.
|
|
14
|
+
*/
|
|
15
|
+
function deferredInbox(handle, onError = (error) => console.error("Camox: the renderer frame's protocol failed to handle a message.", error)) {
|
|
16
|
+
const queue = [];
|
|
17
|
+
let scheduled = false;
|
|
18
|
+
const drain = () => {
|
|
19
|
+
scheduled = false;
|
|
20
|
+
for (const message of queue.splice(0)) try {
|
|
21
|
+
handle(message);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
onError(error);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return (message) => {
|
|
27
|
+
queue.push(message);
|
|
28
|
+
if (scheduled) return;
|
|
29
|
+
scheduled = true;
|
|
30
|
+
queueMicrotask(drain);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
export { RENDERER_DOCUMENT_PATH, SDK_VERSION, STUDIO_HANDLE_KEY, deferredInbox };
|