camox 0.10.1 → 0.12.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/components/lexical/SidebarLexicalEditor.js +14 -41
- package/dist/core/createApp.d.ts +3 -3
- package/dist/core/createBlock.d.ts +19 -15
- package/dist/core/createBlock.js +2 -2
- package/dist/core/lib/contentType.d.ts +18 -13
- package/dist/core/lib/contentType.js +21 -4
- package/dist/features/content/CamoxContent.js +1 -1
- package/dist/features/preview/CamoxPreview.js +3 -3
- package/dist/features/preview/components/AssetFieldEditor.js +1 -1
- package/dist/features/preview/components/EditPageModal.js +1 -1
- package/dist/features/preview/components/PeekedBlock.js +1 -1
- package/dist/features/preview/components/PreviewToolbar.js +1 -1
- package/dist/features/preview/previewStore.js +2 -5
- package/dist/features/provider/CamoxProvider.js +28 -14
- package/dist/features/studio/components/EnvironmentMenu.js +31 -22
- package/dist/features/vite/blockBoilerplate.js +1 -1
- package/dist/features/vite/definitionsSync.js +14 -3
- package/dist/features/vite/vite.js +34 -9
- package/dist/studio.css +1 -1
- package/package.json +10 -4
- package/skills/camox-block/SKILL.md +52 -41
|
@@ -12,42 +12,15 @@ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
|
12
12
|
|
|
13
13
|
//#region src/core/components/lexical/SidebarLexicalEditor.tsx
|
|
14
14
|
function ExternalStateSync(t0) {
|
|
15
|
-
const $ = c(
|
|
15
|
+
const $ = c(5);
|
|
16
16
|
const { value, isSyncingRef } = t0;
|
|
17
17
|
const [editor] = useLexicalComposerContext();
|
|
18
|
-
const isFocusedRef = React.useRef(false);
|
|
19
18
|
let t1;
|
|
20
19
|
let t2;
|
|
21
|
-
if ($[0] !== editor) {
|
|
22
|
-
t1 = () =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
isFocusedRef.current = true;
|
|
26
|
-
};
|
|
27
|
-
const handleBlur = () => {
|
|
28
|
-
isFocusedRef.current = false;
|
|
29
|
-
};
|
|
30
|
-
root.addEventListener("focus", handleFocus);
|
|
31
|
-
root.addEventListener("blur", handleBlur);
|
|
32
|
-
return () => {
|
|
33
|
-
root.removeEventListener("focus", handleFocus);
|
|
34
|
-
root.removeEventListener("blur", handleBlur);
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
t2 = [editor];
|
|
38
|
-
$[0] = editor;
|
|
39
|
-
$[1] = t1;
|
|
40
|
-
$[2] = t2;
|
|
41
|
-
} else {
|
|
42
|
-
t1 = $[1];
|
|
43
|
-
t2 = $[2];
|
|
44
|
-
}
|
|
45
|
-
React.useEffect(t1, t2);
|
|
46
|
-
let t3;
|
|
47
|
-
let t4;
|
|
48
|
-
if ($[3] !== editor || $[4] !== isSyncingRef || $[5] !== value) {
|
|
49
|
-
t3 = () => {
|
|
50
|
-
if (isFocusedRef.current) return;
|
|
20
|
+
if ($[0] !== editor || $[1] !== isSyncingRef || $[2] !== value) {
|
|
21
|
+
t1 = () => {
|
|
22
|
+
const root = editor.getRootElement();
|
|
23
|
+
if (root !== null && root === document.activeElement) return;
|
|
51
24
|
try {
|
|
52
25
|
const normalized = normalizeLexicalState(value);
|
|
53
26
|
const newState = editor.parseEditorState(normalized);
|
|
@@ -55,21 +28,21 @@ function ExternalStateSync(t0) {
|
|
|
55
28
|
editor.setEditorState(newState);
|
|
56
29
|
} catch {}
|
|
57
30
|
};
|
|
58
|
-
|
|
31
|
+
t2 = [
|
|
59
32
|
editor,
|
|
60
33
|
value,
|
|
61
34
|
isSyncingRef
|
|
62
35
|
];
|
|
63
|
-
$[
|
|
64
|
-
$[
|
|
65
|
-
$[
|
|
66
|
-
$[
|
|
67
|
-
$[
|
|
36
|
+
$[0] = editor;
|
|
37
|
+
$[1] = isSyncingRef;
|
|
38
|
+
$[2] = value;
|
|
39
|
+
$[3] = t1;
|
|
40
|
+
$[4] = t2;
|
|
68
41
|
} else {
|
|
69
|
-
|
|
70
|
-
|
|
42
|
+
t1 = $[3];
|
|
43
|
+
t2 = $[4];
|
|
71
44
|
}
|
|
72
|
-
React.useEffect(
|
|
45
|
+
React.useEffect(t1, t2);
|
|
73
46
|
return null;
|
|
74
47
|
}
|
|
75
48
|
function SidebarLexicalEditor({ id, value, onChange, onFocus, onBlur }) {
|
package/dist/core/createApp.d.ts
CHANGED
|
@@ -296,7 +296,7 @@ declare function createApp({
|
|
|
296
296
|
description: string;
|
|
297
297
|
properties: Record<string, _$_sinclair_typebox0.TSchema>;
|
|
298
298
|
required: string[];
|
|
299
|
-
toMarkdown:
|
|
299
|
+
toMarkdown: string[];
|
|
300
300
|
};
|
|
301
301
|
settingsSchema: {
|
|
302
302
|
type: "object";
|
|
@@ -618,7 +618,7 @@ declare function createApp({
|
|
|
618
618
|
description: string;
|
|
619
619
|
properties: Record<string, _$_sinclair_typebox0.TSchema>;
|
|
620
620
|
required: string[];
|
|
621
|
-
toMarkdown:
|
|
621
|
+
toMarkdown: string[];
|
|
622
622
|
};
|
|
623
623
|
settingsSchema: {
|
|
624
624
|
type: "object";
|
|
@@ -804,7 +804,7 @@ declare function createApp({
|
|
|
804
804
|
description: string;
|
|
805
805
|
properties: Record<string, _$_sinclair_typebox0.TSchema>;
|
|
806
806
|
required: string[];
|
|
807
|
-
toMarkdown:
|
|
807
|
+
toMarkdown: string[];
|
|
808
808
|
};
|
|
809
809
|
settingsSchema: {
|
|
810
810
|
type: "object";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EmbedURL,
|
|
1
|
+
import { EmbedURL, FileValue, ImageValue, LinkValue, ToMarkdownBuilder, Type } from "./lib/contentType.js";
|
|
2
2
|
import * as _$_sinclair_typebox0 from "@sinclair/typebox";
|
|
3
3
|
import { Static, TSchema, Type as Type$1 } from "@sinclair/typebox";
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
6
|
|
|
7
7
|
//#region src/core/createBlock.d.ts
|
|
8
|
-
interface CreateBlockOptions<TSchemaShape extends Record<string, TSchema> = Record<string, TSchema>, TSettingsShape extends Record<string, TSchema> = Record<string, TSchema>,
|
|
8
|
+
interface CreateBlockOptions<TSchemaShape extends Record<string, TSchema> = Record<string, TSchema>, TSettingsShape extends Record<string, TSchema> = Record<string, TSchema>, TLayoutOnly extends boolean = false> {
|
|
9
9
|
id: string;
|
|
10
10
|
/**
|
|
11
11
|
* Human-readable title for the block (JSON Schema `title`).
|
|
@@ -26,20 +26,14 @@ interface CreateBlockOptions<TSchemaShape extends Record<string, TSchema> = Reco
|
|
|
26
26
|
* content: {
|
|
27
27
|
* title: Type.String({ default: 'Hello' }),
|
|
28
28
|
* items: Type.RepeatableItem({
|
|
29
|
-
* name: Type.String({ default: 'Item' })
|
|
30
|
-
*
|
|
29
|
+
* content: { name: Type.String({ default: 'Item' }) },
|
|
30
|
+
* minItems: 1,
|
|
31
|
+
* maxItems: 10,
|
|
32
|
+
* toMarkdown: (c) => [c.name],
|
|
33
|
+
* })
|
|
31
34
|
* }
|
|
32
35
|
*/
|
|
33
36
|
content: TSchemaShape;
|
|
34
|
-
/**
|
|
35
|
-
* Template for rendering block content as markdown.
|
|
36
|
-
* Each line is joined with `\n\n`. Use `{{fieldName}}` placeholders for field values.
|
|
37
|
-
* Lines where all placeholders resolve to empty are omitted.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* toMarkdown: ["# {{title}}", "{{description}}", "{{illustration}}", "{{cta}}"]
|
|
41
|
-
*/
|
|
42
|
-
toMarkdown: [ExtractAllPlaceholders<TMarkdown>] extends [Extract<keyof TSchemaShape, string>] ? TMarkdown : readonly [`Invalid toMarkdown placeholder {{${Exclude<ExtractAllPlaceholders<TMarkdown>, Extract<keyof TSchemaShape, string>>}}}`];
|
|
43
37
|
/**
|
|
44
38
|
* Optional schema defining block-level settings (e.g. layout variant, toggles).
|
|
45
39
|
* Settings are not inline-editable; they use Type.Enum() and Type.Boolean().
|
|
@@ -64,6 +58,16 @@ interface CreateBlockOptions<TSchemaShape extends Record<string, TSchema> = Reco
|
|
|
64
58
|
component: React.ComponentType<{
|
|
65
59
|
content: Static<ReturnType<typeof Type$1.Object<TSchemaShape>>>;
|
|
66
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Builder for rendering block content as markdown.
|
|
63
|
+
* `c` is a proxy typed on `content` keys — `c.title`, `c.description`, etc.
|
|
64
|
+
* Each returned entry becomes a paragraph (joined with `\n\n`).
|
|
65
|
+
* Lines where all referenced fields resolve to empty are omitted at render time.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* toMarkdown: (c) => [`# ${c.title}`, c.description, c.illustration, c.cta]
|
|
69
|
+
*/
|
|
70
|
+
toMarkdown: ToMarkdownBuilder<TSchemaShape>;
|
|
67
71
|
}
|
|
68
72
|
interface BlockData<TContent> {
|
|
69
73
|
_id: number;
|
|
@@ -98,7 +102,7 @@ interface RepeatableItemSeed {
|
|
|
98
102
|
content: Record<string, unknown>;
|
|
99
103
|
position: string;
|
|
100
104
|
}
|
|
101
|
-
declare function createBlock<TSchemaShape extends Record<string, TSchema>, TSettingsShape extends Record<string, TSchema> = Record<string, never>,
|
|
105
|
+
declare function createBlock<TSchemaShape extends Record<string, TSchema>, TSettingsShape extends Record<string, TSchema> = Record<string, never>, TLayoutOnly extends boolean = false>(options: CreateBlockOptions<TSchemaShape, TSettingsShape, TLayoutOnly>): {
|
|
102
106
|
Detached: ({
|
|
103
107
|
children
|
|
104
108
|
}: {
|
|
@@ -1103,7 +1107,7 @@ declare function createBlock<TSchemaShape extends Record<string, TSchema>, TSett
|
|
|
1103
1107
|
description: string;
|
|
1104
1108
|
properties: TSchemaShape;
|
|
1105
1109
|
required: string[];
|
|
1106
|
-
toMarkdown:
|
|
1110
|
+
toMarkdown: string[];
|
|
1107
1111
|
};
|
|
1108
1112
|
settingsSchema: {
|
|
1109
1113
|
type: "object";
|
package/dist/core/createBlock.js
CHANGED
|
@@ -10,7 +10,7 @@ import { InlineLexicalEditor } from "./components/lexical/InlineLexicalEditor.js
|
|
|
10
10
|
import { useFieldSelection } from "./hooks/useFieldSelection.js";
|
|
11
11
|
import { useIsEditable } from "./hooks/useIsEditable.js";
|
|
12
12
|
import { useOverlayMessage } from "./hooks/useOverlayMessage.js";
|
|
13
|
-
import { Type } from "./lib/contentType.js";
|
|
13
|
+
import { Type, resolveToMarkdown } from "./lib/contentType.js";
|
|
14
14
|
import { markdownToReactNodes } from "./lib/lexicalReact.js";
|
|
15
15
|
import { c } from "react/compiler-runtime";
|
|
16
16
|
import { Input } from "@camox/ui/input";
|
|
@@ -139,7 +139,7 @@ function createBlock(options) {
|
|
|
139
139
|
description: options.description,
|
|
140
140
|
properties: typeboxSchema.properties,
|
|
141
141
|
required: Object.keys(options.content),
|
|
142
|
-
toMarkdown: options.toMarkdown
|
|
142
|
+
toMarkdown: resolveToMarkdown(options.toMarkdown)
|
|
143
143
|
};
|
|
144
144
|
const settingsTypeboxSchema = options.settings ? Type$1.Object(options.settings) : null;
|
|
145
145
|
const settingsSchema = settingsTypeboxSchema ? {
|
|
@@ -2,8 +2,13 @@ import * as _$_sinclair_typebox0 from "@sinclair/typebox";
|
|
|
2
2
|
import { TArray, TObject, TSchema, TUnsafe } from "@sinclair/typebox";
|
|
3
3
|
|
|
4
4
|
//#region src/core/lib/contentType.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
declare class FieldToken {
|
|
6
|
+
readonly fieldName: string;
|
|
7
|
+
constructor(fieldName: string);
|
|
8
|
+
toString(): string;
|
|
9
|
+
}
|
|
10
|
+
type ContentProxy<TShape extends Record<string, TSchema>> = { [K in keyof TShape & string]: FieldToken };
|
|
11
|
+
type ToMarkdownBuilder<TShape extends Record<string, TSchema>> = (c: ContentProxy<TShape>) => ReadonlyArray<string | FieldToken>;
|
|
7
12
|
declare const EmbedURLBrand: unique symbol;
|
|
8
13
|
type EmbedURL = string & {
|
|
9
14
|
readonly [EmbedURLBrand]: true;
|
|
@@ -88,23 +93,23 @@ declare const Type$1: {
|
|
|
88
93
|
*
|
|
89
94
|
* @example
|
|
90
95
|
* Type.RepeatableItem({
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* },
|
|
96
|
+
* content: {
|
|
97
|
+
* title: Type.String({ default: 'Item' }),
|
|
98
|
+
* description: Type.String({ default: 'Description' }),
|
|
99
|
+
* },
|
|
94
100
|
* minItems: 1,
|
|
95
101
|
* maxItems: 10,
|
|
96
|
-
* title: 'Items'
|
|
102
|
+
* title: 'Items',
|
|
103
|
+
* toMarkdown: (c) => [`### ${c.title}`, c.description],
|
|
97
104
|
* })
|
|
98
105
|
*/
|
|
99
|
-
RepeatableItem: <T extends Record<string, TSchema
|
|
106
|
+
RepeatableItem: <T extends Record<string, TSchema>>(options: {
|
|
107
|
+
content: T;
|
|
100
108
|
minItems: number;
|
|
101
109
|
maxItems: number;
|
|
102
110
|
title?: string;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
} : {
|
|
106
|
-
toMarkdown?: readonly [`Invalid toMarkdown placeholder: "{{${Exclude<ExtractAllPlaceholders<TMarkdown>, Extract<keyof T, string>>}}}"`];
|
|
107
|
-
})) => TArray<TObject<T>>;
|
|
111
|
+
toMarkdown: ToMarkdownBuilder<T>;
|
|
112
|
+
}) => TArray<TObject<T>>;
|
|
108
113
|
/**
|
|
109
114
|
* Creates an enum field with a set of predefined options.
|
|
110
115
|
*
|
|
@@ -164,4 +169,4 @@ declare const Type$1: {
|
|
|
164
169
|
File: typeof _fileType;
|
|
165
170
|
};
|
|
166
171
|
//#endregion
|
|
167
|
-
export { EmbedURL,
|
|
172
|
+
export { EmbedURL, FileValue, ImageValue, LinkValue, ToMarkdownBuilder, Type$1 as Type };
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
|
|
3
3
|
//#region src/core/lib/contentType.ts
|
|
4
|
+
var FieldToken = class {
|
|
5
|
+
constructor(fieldName) {
|
|
6
|
+
this.fieldName = fieldName;
|
|
7
|
+
}
|
|
8
|
+
toString() {
|
|
9
|
+
return `{{${this.fieldName}}}`;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function createContentProxy() {
|
|
13
|
+
return new Proxy({}, { get(_target, prop) {
|
|
14
|
+
if (typeof prop !== "string") return void 0;
|
|
15
|
+
return new FieldToken(prop);
|
|
16
|
+
} });
|
|
17
|
+
}
|
|
18
|
+
function resolveToMarkdown(builder) {
|
|
19
|
+
return builder(createContentProxy()).map((entry) => entry instanceof FieldToken ? entry.toString() : String(entry));
|
|
20
|
+
}
|
|
4
21
|
function _imageType(options) {
|
|
5
22
|
const imageDefault = {
|
|
6
23
|
url: `https://placehold.co/1200x800/f4f4f5/a1a1aa.png?text=${options?.title || "image"}`,
|
|
@@ -79,9 +96,9 @@ const Type$1 = {
|
|
|
79
96
|
fieldType: "String"
|
|
80
97
|
});
|
|
81
98
|
},
|
|
82
|
-
RepeatableItem: (
|
|
99
|
+
RepeatableItem: (options) => {
|
|
83
100
|
if (options.minItems < 1) throw new Error("RepeatableItem requires minItems to be at least 1");
|
|
84
|
-
const objectSchema = Type.Object(
|
|
101
|
+
const objectSchema = Type.Object(options.content);
|
|
85
102
|
const defaultItem = {};
|
|
86
103
|
for (const [key, prop] of Object.entries(objectSchema.properties)) if ("default" in prop) defaultItem[key] = prop.default;
|
|
87
104
|
const defaultArray = Array(options.minItems).fill(null).map(() => ({ ...defaultItem }));
|
|
@@ -91,7 +108,7 @@ const Type$1 = {
|
|
|
91
108
|
default: defaultArray,
|
|
92
109
|
title: options.title,
|
|
93
110
|
fieldType: "RepeatableItem",
|
|
94
|
-
|
|
111
|
+
toMarkdown: resolveToMarkdown(options.toMarkdown)
|
|
95
112
|
});
|
|
96
113
|
},
|
|
97
114
|
Enum: (options) => {
|
|
@@ -148,4 +165,4 @@ const Type$1 = {
|
|
|
148
165
|
};
|
|
149
166
|
|
|
150
167
|
//#endregion
|
|
151
|
-
export { Type$1 as Type };
|
|
168
|
+
export { Type$1 as Type, resolveToMarkdown };
|
|
@@ -203,7 +203,7 @@ const CamoxContent = () => {
|
|
|
203
203
|
let t18;
|
|
204
204
|
if ($[39] !== deleteFiles || $[40] !== selectedIds) {
|
|
205
205
|
t18 = selectedIds.size > 0 && /* @__PURE__ */ jsxs(FloatingToolbar, {
|
|
206
|
-
className: "bottom-4 min-w-xs justify-between gap-4",
|
|
206
|
+
className: "bottom-4 min-w-xs justify-between gap-4 pl-3",
|
|
207
207
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
208
208
|
className: "text-muted-foreground",
|
|
209
209
|
children: [
|
|
@@ -306,7 +306,7 @@ const CamoxPreview = (t0) => {
|
|
|
306
306
|
const actions = [
|
|
307
307
|
{
|
|
308
308
|
id: "enter-presentation-mode",
|
|
309
|
-
label: "
|
|
309
|
+
label: "Hide Camox Studio",
|
|
310
310
|
groupLabel: "Preview",
|
|
311
311
|
checkIfAvailable: () => isAuthenticated && !isPresentationMode,
|
|
312
312
|
execute: _temp4,
|
|
@@ -317,12 +317,12 @@ const CamoxPreview = (t0) => {
|
|
|
317
317
|
},
|
|
318
318
|
{
|
|
319
319
|
id: "exit-presentation-mode",
|
|
320
|
-
label: "
|
|
320
|
+
label: "",
|
|
321
321
|
groupLabel: "Preview",
|
|
322
322
|
checkIfAvailable: () => isAuthenticated && isPresentationMode,
|
|
323
323
|
execute: _temp5,
|
|
324
324
|
shortcut: {
|
|
325
|
-
key: "
|
|
325
|
+
key: "Enter",
|
|
326
326
|
withMeta: true
|
|
327
327
|
}
|
|
328
328
|
},
|
|
@@ -194,7 +194,7 @@ const SingleAssetFieldEditor = (t0) => {
|
|
|
194
194
|
children: [
|
|
195
195
|
/* @__PURE__ */ jsxs("button", {
|
|
196
196
|
type: "button",
|
|
197
|
-
className: "flex min-w-0 flex-1 cursor-zoom-in items-center gap-2 rounded-sm p-1
|
|
197
|
+
className: "flex min-w-0 flex-1 cursor-zoom-in items-center gap-2 rounded-sm p-1",
|
|
198
198
|
onClick: () => setLightboxOpen(true),
|
|
199
199
|
children: [isImage ? /* @__PURE__ */ jsx("div", {
|
|
200
200
|
className: "border-border h-10 w-10 shrink-0 overflow-hidden rounded border",
|
|
@@ -305,7 +305,7 @@ const SearchEnginePreview = (t0) => {
|
|
|
305
305
|
children: [t1, /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
306
306
|
delay: 50,
|
|
307
307
|
render: /* @__PURE__ */ jsx(Info, { className: "text-muted-foreground size-3.5" })
|
|
308
|
-
}), /* @__PURE__ */ jsx(TooltipContent, { children: "Titles are cropped after 60 characters and descriptions after 155, like Google
|
|
308
|
+
}), /* @__PURE__ */ jsx(TooltipContent, { children: "Titles are cropped after 60 characters and descriptions after 155, like on Google Search results." })] })]
|
|
309
309
|
});
|
|
310
310
|
$[1] = t2;
|
|
311
311
|
} else t2 = $[1];
|
|
@@ -88,7 +88,7 @@ const PeekedBlock = (t0) => {
|
|
|
88
88
|
if (e.propertyName !== "grid-template-rows" || e.target !== e.currentTarget) return;
|
|
89
89
|
if (isExpanded) {
|
|
90
90
|
peekedBlockRef.current?.scrollIntoView({
|
|
91
|
-
behavior: "
|
|
91
|
+
behavior: "smooth",
|
|
92
92
|
block: "start"
|
|
93
93
|
});
|
|
94
94
|
return;
|
|
@@ -197,7 +197,7 @@ const PreviewToolbar = () => {
|
|
|
197
197
|
} else t27 = $[44];
|
|
198
198
|
let t28;
|
|
199
199
|
if ($[45] !== t27) {
|
|
200
|
-
t28 = /* @__PURE__ */ jsxs(Tooltip$1.TooltipContent, { children: ["Hide
|
|
200
|
+
t28 = /* @__PURE__ */ jsxs(Tooltip$1.TooltipContent, { children: ["Hide Camox Studio ", t27] });
|
|
201
201
|
$[45] = t27;
|
|
202
202
|
$[46] = t28;
|
|
203
203
|
} else t28 = $[46];
|
|
@@ -43,18 +43,15 @@ const previewStore = createStore({
|
|
|
43
43
|
enterPresentationMode: (context, _, enqueue) => {
|
|
44
44
|
if (context.isPresentationMode) return context;
|
|
45
45
|
enqueue.effect(() => {
|
|
46
|
-
toast("
|
|
46
|
+
toast("Press ⌘ + Enter to restore Camox Studio", { duration: 2500 });
|
|
47
47
|
});
|
|
48
48
|
return {
|
|
49
49
|
...context,
|
|
50
50
|
isPresentationMode: true
|
|
51
51
|
};
|
|
52
52
|
},
|
|
53
|
-
exitPresentationMode: (context
|
|
53
|
+
exitPresentationMode: (context) => {
|
|
54
54
|
if (!context.isPresentationMode) return context;
|
|
55
|
-
enqueue.effect(() => {
|
|
56
|
-
toast("Leaving presentation mode");
|
|
57
|
-
});
|
|
58
55
|
return {
|
|
59
56
|
...context,
|
|
60
57
|
isPresentationMode: false
|
|
@@ -62,7 +62,7 @@ const AuthenticatedCamoxProvider = (t0) => {
|
|
|
62
62
|
return t4;
|
|
63
63
|
};
|
|
64
64
|
const UnauthenticatedCamoxProvider = (t0) => {
|
|
65
|
-
const $ = c(
|
|
65
|
+
const $ = c(16);
|
|
66
66
|
const { children } = t0;
|
|
67
67
|
const signInRedirect = useSignInRedirect();
|
|
68
68
|
const { authenticationUrl } = useAuthContext();
|
|
@@ -70,7 +70,7 @@ const UnauthenticatedCamoxProvider = (t0) => {
|
|
|
70
70
|
if ($[0] !== signInRedirect) {
|
|
71
71
|
t1 = () => {
|
|
72
72
|
const handleKeyDown = (event) => {
|
|
73
|
-
if ((event.metaKey || event.ctrlKey) && event.key === "
|
|
73
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
|
74
74
|
event.preventDefault();
|
|
75
75
|
signInRedirect();
|
|
76
76
|
}
|
|
@@ -112,25 +112,39 @@ const UnauthenticatedCamoxProvider = (t0) => {
|
|
|
112
112
|
t4 = $[7];
|
|
113
113
|
}
|
|
114
114
|
React.useEffect(t3, t4);
|
|
115
|
+
const { theme } = useTheme();
|
|
115
116
|
let t5;
|
|
116
117
|
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
117
|
-
t5 =
|
|
118
|
-
theme: "light",
|
|
119
|
-
position: "bottom-right",
|
|
120
|
-
offset: { bottom: "1rem" }
|
|
121
|
-
});
|
|
118
|
+
t5 = { bottom: "1rem" };
|
|
122
119
|
$[8] = t5;
|
|
123
120
|
} else t5 = $[8];
|
|
124
121
|
let t6;
|
|
125
|
-
if ($[9] !==
|
|
126
|
-
t6 = /* @__PURE__ */
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
if ($[9] !== theme) {
|
|
123
|
+
t6 = /* @__PURE__ */ jsx(Toaster, {
|
|
124
|
+
theme,
|
|
125
|
+
position: "bottom-right",
|
|
126
|
+
offset: t5
|
|
127
|
+
});
|
|
128
|
+
$[9] = theme;
|
|
131
129
|
$[10] = t6;
|
|
132
130
|
} else t6 = $[10];
|
|
133
|
-
|
|
131
|
+
let t7;
|
|
132
|
+
if ($[11] !== children) {
|
|
133
|
+
t7 = /* @__PURE__ */ jsx("div", {
|
|
134
|
+
className: "bg-background min-h-screen",
|
|
135
|
+
children
|
|
136
|
+
});
|
|
137
|
+
$[11] = children;
|
|
138
|
+
$[12] = t7;
|
|
139
|
+
} else t7 = $[12];
|
|
140
|
+
let t8;
|
|
141
|
+
if ($[13] !== t6 || $[14] !== t7) {
|
|
142
|
+
t8 = /* @__PURE__ */ jsxs(Fragment, { children: [t6, t7] });
|
|
143
|
+
$[13] = t6;
|
|
144
|
+
$[14] = t7;
|
|
145
|
+
$[15] = t8;
|
|
146
|
+
} else t8 = $[15];
|
|
147
|
+
return t8;
|
|
134
148
|
};
|
|
135
149
|
function CamoxProvider({ children, camoxApp, authenticationUrl, apiUrl, projectSlug, environmentName }) {
|
|
136
150
|
const authClient = React.useMemo(() => createCamoxAuthClient(apiUrl), [apiUrl]);
|
|
@@ -9,11 +9,12 @@ import { Badge } from "@camox/ui/badge";
|
|
|
9
9
|
|
|
10
10
|
//#region src/features/studio/components/EnvironmentMenu.tsx
|
|
11
11
|
const EnvironmentMenu = () => {
|
|
12
|
-
const $ = c(
|
|
12
|
+
const $ = c(14);
|
|
13
13
|
const [open, setOpen] = React.useState(false);
|
|
14
14
|
const authCtx = React.useContext(AuthContext);
|
|
15
15
|
if (!authCtx?.environmentName) return null;
|
|
16
16
|
const isProduction = authCtx.environmentName === "production";
|
|
17
|
+
const label = isProduction ? "PROD" : "DEV";
|
|
17
18
|
const badgeClassName = isProduction ? "bg-green-100 text-green-800 border border-green-300 hover:bg-green-100 dark:bg-green-900 dark:text-green-300 dark:border-green-700 dark:hover:bg-green-900 font-mono text-xs" : "bg-yellow-100 text-yellow-800 border border-yellow-300 hover:bg-yellow-100 dark:bg-yellow-900 dark:text-yellow-300 dark:border-yellow-700 dark:hover:bg-yellow-900 font-mono text-xs";
|
|
18
19
|
let t0;
|
|
19
20
|
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
@@ -24,14 +25,14 @@ const EnvironmentMenu = () => {
|
|
|
24
25
|
$[0] = t0;
|
|
25
26
|
} else t0 = $[0];
|
|
26
27
|
let t1;
|
|
27
|
-
if ($[1] !==
|
|
28
|
+
if ($[1] !== badgeClassName || $[2] !== label) {
|
|
28
29
|
t1 = /* @__PURE__ */ jsx(Badge, {
|
|
29
30
|
variant: "secondary",
|
|
30
31
|
className: badgeClassName,
|
|
31
|
-
children:
|
|
32
|
+
children: label
|
|
32
33
|
});
|
|
33
|
-
$[1] =
|
|
34
|
-
$[2] =
|
|
34
|
+
$[1] = badgeClassName;
|
|
35
|
+
$[2] = label;
|
|
35
36
|
$[3] = t1;
|
|
36
37
|
} else t1 = $[3];
|
|
37
38
|
let t2;
|
|
@@ -49,7 +50,7 @@ const EnvironmentMenu = () => {
|
|
|
49
50
|
$[6] = t3;
|
|
50
51
|
} else t3 = $[6];
|
|
51
52
|
let t4;
|
|
52
|
-
if ($[7] !== isProduction) {
|
|
53
|
+
if ($[7] !== authCtx.environmentName || $[8] !== isProduction) {
|
|
53
54
|
t4 = /* @__PURE__ */ jsx(PopoverContent, {
|
|
54
55
|
className: "w-96 p-4",
|
|
55
56
|
align: "start",
|
|
@@ -59,30 +60,38 @@ const EnvironmentMenu = () => {
|
|
|
59
60
|
children: isProduction ? /* @__PURE__ */ jsx("p", {
|
|
60
61
|
className: "text-sm",
|
|
61
62
|
children: "You are viewing the production environment."
|
|
62
|
-
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
64
|
+
/* @__PURE__ */ jsx("p", {
|
|
65
|
+
className: "text-sm",
|
|
66
|
+
children: "This environment is your own space to iterate on content and data structures. It won't affect your teammates or production."
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx("p", {
|
|
69
|
+
className: "text-muted-foreground font-mono text-xs",
|
|
70
|
+
children: authCtx.environmentName
|
|
71
|
+
}),
|
|
72
|
+
/* @__PURE__ */ jsx("p", {
|
|
73
|
+
className: "text-muted-foreground text-xs",
|
|
74
|
+
children: "You will be able to pull and push data between environments from here."
|
|
75
|
+
})
|
|
76
|
+
] })
|
|
69
77
|
})
|
|
70
78
|
});
|
|
71
|
-
$[7] =
|
|
72
|
-
$[8] =
|
|
73
|
-
|
|
79
|
+
$[7] = authCtx.environmentName;
|
|
80
|
+
$[8] = isProduction;
|
|
81
|
+
$[9] = t4;
|
|
82
|
+
} else t4 = $[9];
|
|
74
83
|
let t5;
|
|
75
|
-
if ($[
|
|
84
|
+
if ($[10] !== open || $[11] !== t3 || $[12] !== t4) {
|
|
76
85
|
t5 = /* @__PURE__ */ jsxs(Popover, {
|
|
77
86
|
open,
|
|
78
87
|
onOpenChange: setOpen,
|
|
79
88
|
children: [t3, t4]
|
|
80
89
|
});
|
|
81
|
-
$[
|
|
82
|
-
$[
|
|
83
|
-
$[
|
|
84
|
-
$[
|
|
85
|
-
} else t5 = $[
|
|
90
|
+
$[10] = open;
|
|
91
|
+
$[11] = t3;
|
|
92
|
+
$[12] = t4;
|
|
93
|
+
$[13] = t5;
|
|
94
|
+
} else t5 = $[13];
|
|
86
95
|
return t5;
|
|
87
96
|
};
|
|
88
97
|
|
|
@@ -11,8 +11,14 @@ const SYNC_DEBOUNCE_DELAY_MS = 100;
|
|
|
11
11
|
function throwIfSyncAuthError(error) {
|
|
12
12
|
if (error instanceof Error && error.name === "ORPCError" && error.message.toLowerCase().includes("unauthorized")) throw new Error("[camox] Definition sync failed: invalid syncSecret.");
|
|
13
13
|
}
|
|
14
|
+
function isNotFoundError(error) {
|
|
15
|
+
return error instanceof Error && error.name === "ORPCError" && error.message.toLowerCase().includes("not found");
|
|
16
|
+
}
|
|
17
|
+
function throwUnknownEnvironmentError(environmentName) {
|
|
18
|
+
throw new Error(`[camox] Environment "${environmentName}" does not exist. CAMOX_ENV must be "production" or a dev environment previously created by running the dev server while authenticated. Run \`npx camox login\` if needed.`);
|
|
19
|
+
}
|
|
14
20
|
async function syncDefinitionsToApi(options) {
|
|
15
|
-
const { camoxApp, projectSlug, apiUrl, syncSecret, environmentName, logger } = options;
|
|
21
|
+
const { camoxApp, projectSlug, apiUrl, syncSecret, environmentName, autoCreate, logger } = options;
|
|
16
22
|
const client = createServerApiClient(apiUrl, environmentName);
|
|
17
23
|
const blocks = camoxApp.getBlocks();
|
|
18
24
|
const layoutDefinitions = camoxApp.getSerializableLayoutDefinitions();
|
|
@@ -33,13 +39,15 @@ async function syncDefinitionsToApi(options) {
|
|
|
33
39
|
environmentCreated = (await client.blockDefinitions.sync({
|
|
34
40
|
projectSlug,
|
|
35
41
|
syncSecret,
|
|
42
|
+
autoCreate,
|
|
36
43
|
definitions
|
|
37
44
|
})).environmentCreated;
|
|
38
45
|
} catch (error) {
|
|
39
46
|
throwIfSyncAuthError(error);
|
|
47
|
+
if (!autoCreate && isNotFoundError(error)) throwUnknownEnvironmentError(environmentName);
|
|
40
48
|
throw error;
|
|
41
49
|
}
|
|
42
|
-
if (environmentCreated
|
|
50
|
+
if (environmentCreated) logger.info(`[camox] Created empty environment "${environmentName}"`, { timestamp: true });
|
|
43
51
|
logger.info(`[camox] Synced ${definitions.length} block definition${definitions.length === 1 ? "" : "s"}`, { timestamp: true });
|
|
44
52
|
if (layoutDefinitions.length > 0) {
|
|
45
53
|
let layoutSyncResults;
|
|
@@ -47,10 +55,12 @@ async function syncDefinitionsToApi(options) {
|
|
|
47
55
|
layoutSyncResults = await client.layouts.sync({
|
|
48
56
|
projectSlug,
|
|
49
57
|
syncSecret,
|
|
58
|
+
autoCreate,
|
|
50
59
|
layouts: layoutDefinitions
|
|
51
60
|
});
|
|
52
61
|
} catch (error) {
|
|
53
62
|
throwIfSyncAuthError(error);
|
|
63
|
+
if (!autoCreate && isNotFoundError(error)) throwUnknownEnvironmentError(environmentName);
|
|
54
64
|
throw error;
|
|
55
65
|
}
|
|
56
66
|
logger.info(`[camox] Synced ${layoutDefinitions.length} layout${layoutDefinitions.length === 1 ? "" : "s"} to Camox API`, { timestamp: true });
|
|
@@ -119,7 +129,7 @@ async function ssrLoadModule(server, modulePath) {
|
|
|
119
129
|
}
|
|
120
130
|
}
|
|
121
131
|
async function syncDefinitions(server, options) {
|
|
122
|
-
const { projectSlug, syncSecret, apiUrl, environmentName } = options;
|
|
132
|
+
const { projectSlug, syncSecret, apiUrl, environmentName, autoCreate } = options;
|
|
123
133
|
const blocksDir = path.resolve(server.config.root, "src/camox/blocks");
|
|
124
134
|
const client = createServerApiClient(apiUrl, environmentName);
|
|
125
135
|
async function performInitialSync() {
|
|
@@ -136,6 +146,7 @@ async function syncDefinitions(server, options) {
|
|
|
136
146
|
apiUrl,
|
|
137
147
|
syncSecret,
|
|
138
148
|
environmentName,
|
|
149
|
+
autoCreate,
|
|
139
150
|
logger: server.config.logger
|
|
140
151
|
});
|
|
141
152
|
}
|