camox 0.76.0 → 0.77.0

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 (54) hide show
  1. package/dist/core/editing/createEditableBlock.js +1077 -1681
  2. package/dist/core/editing/fieldSlot.js +251 -0
  3. package/dist/core/editing/useFieldSlot.js +159 -0
  4. package/dist/core/layoutContext.d.ts +2 -0
  5. package/dist/core/layoutContext.js +27 -1
  6. package/dist/core/lib/artifactTheme.js +43 -6
  7. package/dist/features/canvas/CanvasPageFrame.js +2 -2
  8. package/dist/features/canvas/CanvasPreviewPageSlot.js +1 -1
  9. package/dist/features/canvas/canvasCameraController.js +595 -0
  10. package/dist/features/canvas/useCanvasCamera.js +141 -587
  11. package/dist/features/canvas/useCanvasFrame.js +1 -1
  12. package/dist/features/page/DerivedPageContent.js +4 -8
  13. package/dist/features/preview/components/AssetLightbox.js +6 -65
  14. package/dist/features/preview/components/CanvasPreview.js +2 -2
  15. package/dist/features/preview/components/Frame.js +3 -3
  16. package/dist/features/preview/components/ItemFieldsEditor.js +376 -460
  17. package/dist/features/preview/components/Overlays.js +4 -9
  18. package/dist/features/preview/components/PreviewPanel.js +3 -3
  19. package/dist/features/preview/components/RemovedBlockPlaceholder.js +2 -2
  20. package/dist/features/preview/components/SelectionEditor.js +285 -339
  21. package/dist/features/preview/components/ZoomableImage.js +105 -0
  22. package/dist/features/preview/components/contentFieldSchema.js +3 -1
  23. package/dist/features/preview/components/useFieldWriter.js +30 -51
  24. package/dist/features/preview/components/useRecordView.js +3 -3
  25. package/dist/features/preview/overlayMessages.js +20 -58
  26. package/dist/features/preview/previewStore.js +6 -123
  27. package/dist/features/preview/repeatableItemPath.js +47 -0
  28. package/dist/features/renderer/RendererApp.js +6 -6
  29. package/dist/features/renderer/RendererFrames.js +2 -2
  30. package/dist/features/renderer/rendererHost.js +1 -1
  31. package/dist/features/routes/pageRuntime.d.ts +2 -8
  32. package/dist/features/routes/pageRuntime.js +21 -105
  33. package/dist/features/runtime/pageApp.js +1 -1
  34. package/dist/features/runtime/pageRead.js +105 -0
  35. package/dist/features/runtime/reader.d.ts +25 -0
  36. package/dist/features/runtime/reader.js +142 -0
  37. package/dist/features/runtime/runtime.d.ts +9 -3
  38. package/dist/features/runtime/runtime.js +608 -776
  39. package/dist/features/sdkBundle/buildSdkBundle.d.ts +5 -0
  40. package/dist/features/sdkBundle/buildSdkBundle.js +9 -3
  41. package/dist/features/studio/components/DraftsSheet.js +124 -65
  42. package/dist/features/studio/components/LocalePicker.js +518 -134
  43. package/dist/features/studio/components/ThreadMessages.js +5 -9
  44. package/dist/features/studio/showInCanvas.js +9 -19
  45. package/dist/features/studio/useEditorSelection.js +8 -19
  46. package/dist/lib/locale-path.js +2 -2
  47. package/dist/lib/queries.js +5 -1
  48. package/dist/package.js +1 -1
  49. package/dist/studio.css +1 -1
  50. package/package.json +4 -4
  51. package/skills/camox/references/artifacts.md +7 -0
  52. package/dist/core/hooks/useFieldSelection.js +0 -67
  53. package/dist/core/hooks/useIsEditable.js +0 -21
  54. package/dist/core/hooks/useOverlayMessage.js +0 -70
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camox",
3
- "version": "0.76.0",
3
+ "version": "0.77.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "camox": "./bin/camox.mjs"
@@ -148,9 +148,9 @@
148
148
  "unhead": "^3.4.3",
149
149
  "yaml": "^2.9.0",
150
150
  "zod": "^4.6.7",
151
- "@camox/api-contract": "0.76.0",
152
- "@camox/cli": "0.76.0",
153
- "@camox/ui": "0.76.0"
151
+ "@camox/api-contract": "0.77.0",
152
+ "@camox/ui": "0.77.0",
153
+ "@camox/cli": "0.77.0"
154
154
  },
155
155
  "devDependencies": {
156
156
  "@earendil-works/pi-ai": "1.3.0",
@@ -55,6 +55,13 @@ The source is content, not code: set it as the artifact field's value, like any
55
55
  </script>
56
56
  ```
57
57
 
58
+ - **Mark what stays as it is in every locale with `translate="no"`.** Camox translates an artifact's words into each of the website's locales, everything but its scripts and styles. It leaves alone every element marked `translate="no"` (the HTML attribute), with everything inside it: put it on the names of products, the UI labels of a product the artifact depicts (an English-only app shows its English labels in every locale), and code. Text a script writes is never translated.
59
+
60
+ ```html
61
+ <h2>Publish in one click</h2>
62
+ <div class="toolbar" translate="no"><button>Publish</button><span>Online</span></div>
63
+ ```
64
+
58
65
  - **A meaningful `<title>`.** It names the frame for screen readers and is the artifact's Markdown Representation. Without one, the artifact is called "Untitled artifact", and `blocks create` and `blocks edit` return a warning.
59
66
  - **Motion that plays on its own goes through the Timeline** (`camox.timeline`, below): no CSS animations, CSS transitions, Web Animations or timers that move the artifact by themselves. CSS transitions stay fine for feedback to a visitor's hover or press, and so do libraries you can drive from `render(t)`.
60
67
  - **Respect `prefers-reduced-motion`.** The Timeline does it for you (it shows its poster). For any other motion, such as a hover transition, use the native media query, in CSS (`@media (prefers-reduced-motion: reduce)`) and in scripts (`matchMedia`), by stopping or simplifying it.
@@ -1,67 +0,0 @@
1
- import { previewStore, samePlacement, selectionBlockId, selectionForOwner } from "../../features/preview/previewStore.js";
2
- import { PreviewEditingOwnerContext } from "../../features/preview/previewSelection.js";
3
- import { c } from "react/compiler-runtime";
4
- import { useContext } from "react";
5
- import { useSelector } from "@xstate/store-react";
6
-
7
- //#region src/core/hooks/useFieldSelection.ts
8
- /**
9
- * Returns whether the given field is currently selected based on the normalized selection state.
10
- *
11
- * Matches when the selection points to this exact field (type + name + optional repeatable item).
12
- */
13
- function useFieldSelection(blockId, fieldName, fieldType, repeatableItemId) {
14
- const $ = c(6);
15
- const owner = useContext(PreviewEditingOwnerContext);
16
- let t0;
17
- if ($[0] !== blockId || $[1] !== fieldName || $[2] !== fieldType || $[3] !== owner || $[4] !== repeatableItemId) {
18
- t0 = (state) => {
19
- const sel = selectionForOwner(state.context, owner);
20
- if (!sel || selectionBlockId(sel) !== blockId) return false;
21
- if (sel.type === "block-field") {
22
- if (repeatableItemId) return false;
23
- return sel.fieldType === fieldType && sel.fieldName === fieldName;
24
- }
25
- if (sel.type === "item-field") {
26
- if (!repeatableItemId) return false;
27
- return sel.itemId === repeatableItemId && sel.fieldType === fieldType && sel.fieldName === fieldName;
28
- }
29
- return false;
30
- };
31
- $[0] = blockId;
32
- $[1] = fieldName;
33
- $[2] = fieldType;
34
- $[3] = owner;
35
- $[4] = repeatableItemId;
36
- $[5] = t0;
37
- } else t0 = $[5];
38
- return useSelector(previewStore, t0);
39
- }
40
- /**
41
- * Returns whether the placed record, or one of its record fields when `recordFieldName` is
42
- * given, is selected. Matches only this placement, so other placements of the same record
43
- * stay unselected.
44
- */
45
- function useRecordSelection(placement, recordFieldName) {
46
- const $ = c(4);
47
- const owner = useContext(PreviewEditingOwnerContext);
48
- let t0;
49
- if ($[0] !== owner || $[1] !== placement || $[2] !== recordFieldName) {
50
- t0 = (state) => {
51
- const sel = selectionForOwner(state.context, owner);
52
- if (!placement || !sel) return false;
53
- if (sel.type !== "record" && sel.type !== "record-field") return false;
54
- if (!samePlacement(sel, placement)) return false;
55
- if (recordFieldName === void 0) return sel.type === "record";
56
- return sel.type === "record-field" && sel.recordFieldName === recordFieldName;
57
- };
58
- $[0] = owner;
59
- $[1] = placement;
60
- $[2] = recordFieldName;
61
- $[3] = t0;
62
- } else t0 = $[3];
63
- return useSelector(previewStore, t0);
64
- }
65
-
66
- //#endregion
67
- export { useFieldSelection, useRecordSelection };
@@ -1,21 +0,0 @@
1
- import { useIsAuthenticated } from "../../lib/auth.js";
2
- import { previewStore, selectIsCanvasShown } from "../../features/preview/previewStore.js";
3
- import * as React from "react";
4
- import { useSelector } from "@xstate/store-react";
5
-
6
- //#region src/core/hooks/useIsEditable.ts
7
- /**
8
- * Whether the surrounding frame offers editing while the Canvas shows. Only the selected
9
- * Page's frame does: the others render as the site does, so a click on them only selects
10
- * the Page. Frames keep the editing runtime either way, so toggling never remounts the page.
11
- */
12
- const EditableSurfaceContext = React.createContext(true);
13
- function useIsEditable() {
14
- const isAuthenticated = useIsAuthenticated();
15
- const isCanvasShown = useSelector(previewStore, selectIsCanvasShown);
16
- const surface = React.use(EditableSurfaceContext);
17
- return isAuthenticated && isCanvasShown && surface;
18
- }
19
-
20
- //#endregion
21
- export { EditableSurfaceContext, useIsEditable };
@@ -1,70 +0,0 @@
1
- import { isOverlayMessage } from "../../features/preview/overlayMessages.js";
2
- import { c } from "react/compiler-runtime";
3
- import * as React from "react";
4
-
5
- //#region src/core/hooks/useOverlayMessage.ts
6
- /**
7
- * Listens for a pair of overlay start/end messages on the iframe window and
8
- * returns whether the "active" (start) state is currently on.
9
- *
10
- * Skips setup when `enabled` is false, `iframeWindow` is null, or any value in
11
- * `match` is undefined.
12
- */
13
- function useOverlayMessage(iframeWindow, enabled, startType, endType, match) {
14
- const $ = c(9);
15
- const [active, setActive] = React.useState(false);
16
- let t0;
17
- if ($[0] !== match) {
18
- t0 = JSON.stringify(match);
19
- $[0] = match;
20
- $[1] = t0;
21
- } else t0 = $[1];
22
- const matchJson = t0;
23
- let t1;
24
- let t2;
25
- if ($[2] !== enabled || $[3] !== endType || $[4] !== iframeWindow || $[5] !== matchJson || $[6] !== startType) {
26
- t1 = () => {
27
- if (!enabled || !iframeWindow) return;
28
- const matchEntries = Object.entries(JSON.parse(matchJson));
29
- if (matchEntries.some(_temp)) return;
30
- const handleMessage = (event) => {
31
- if (!isOverlayMessage(event.data)) return;
32
- const data = event.data;
33
- if (data.type !== startType && data.type !== endType) return;
34
- if (!matchEntries.every((t3) => {
35
- const [k, v_0] = t3;
36
- return data[k] === v_0;
37
- })) return;
38
- setActive(data.type === startType);
39
- };
40
- iframeWindow.addEventListener("message", handleMessage);
41
- return () => iframeWindow.removeEventListener("message", handleMessage);
42
- };
43
- t2 = [
44
- enabled,
45
- iframeWindow,
46
- startType,
47
- endType,
48
- matchJson
49
- ];
50
- $[2] = enabled;
51
- $[3] = endType;
52
- $[4] = iframeWindow;
53
- $[5] = matchJson;
54
- $[6] = startType;
55
- $[7] = t1;
56
- $[8] = t2;
57
- } else {
58
- t1 = $[7];
59
- t2 = $[8];
60
- }
61
- React.useEffect(t1, t2);
62
- return active;
63
- }
64
- function _temp(t0) {
65
- const [, v] = t0;
66
- return v === void 0;
67
- }
68
-
69
- //#endregion
70
- export { useOverlayMessage };