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
@@ -1,5 +1,6 @@
1
1
  import { AuthContext } from "../../../lib/auth.js";
2
2
  import { projectQueries } from "../../../lib/queries.js";
3
+ import { c } from "react/compiler-runtime";
3
4
  import { useQuery } from "@tanstack/react-query";
4
5
  import * as React from "react";
5
6
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -8,100 +9,280 @@ import { ChevronDown, Globe, Settings, Users } from "lucide-react";
8
9
  import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger } from "@camox/ui/dropdown-menu";
9
10
  import { Skeleton } from "@camox/ui/skeleton";
10
11
  //#region src/features/studio/components/ProjectMenu.tsx
11
- var Favicon = ({ size = 16 }) => {
12
+ var Favicon = (t0) => {
13
+ const $ = c(18);
14
+ const { size: t1 } = t0;
15
+ const size = t1 === void 0 ? 16 : t1;
12
16
  const [faviconUrl, setFaviconUrl] = React.useState(null);
13
17
  const [hasError, setHasError] = React.useState(false);
14
- React.useEffect(() => {
15
- const getFaviconUrl = () => {
16
- for (const selector of [
17
- "link[rel=\"icon\"]",
18
- "link[rel=\"shortcut icon\"]",
19
- "link[rel=\"apple-touch-icon\"]"
20
- ]) {
21
- const link = document.querySelector(selector);
22
- if (link?.href) return link.href;
23
- }
24
- return null;
18
+ let t2;
19
+ let t3;
20
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
21
+ t2 = () => {
22
+ setFaviconUrl(_temp());
25
23
  };
26
- setFaviconUrl(getFaviconUrl());
27
- }, []);
28
- if (!faviconUrl || hasError) return /* @__PURE__ */ jsx("div", {
29
- className: "bg-muted flex items-center justify-center rounded-full",
30
- style: {
24
+ t3 = [];
25
+ $[0] = t2;
26
+ $[1] = t3;
27
+ } else {
28
+ t2 = $[0];
29
+ t3 = $[1];
30
+ }
31
+ React.useEffect(t2, t3);
32
+ if (!faviconUrl || hasError) {
33
+ let t4;
34
+ if ($[2] !== size) {
35
+ t4 = {
36
+ height: size,
37
+ width: size
38
+ };
39
+ $[2] = size;
40
+ $[3] = t4;
41
+ } else t4 = $[3];
42
+ const t5 = size * .6;
43
+ const t6 = size * .6;
44
+ let t7;
45
+ if ($[4] !== t5 || $[5] !== t6) {
46
+ t7 = /* @__PURE__ */ jsx(Globe, {
47
+ className: "text-muted-foreground",
48
+ style: {
49
+ height: t5,
50
+ width: t6
51
+ }
52
+ });
53
+ $[4] = t5;
54
+ $[5] = t6;
55
+ $[6] = t7;
56
+ } else t7 = $[6];
57
+ let t8;
58
+ if ($[7] !== t4 || $[8] !== t7) {
59
+ t8 = /* @__PURE__ */ jsx("div", {
60
+ className: "bg-muted flex items-center justify-center rounded-full",
61
+ style: t4,
62
+ children: t7
63
+ });
64
+ $[7] = t4;
65
+ $[8] = t7;
66
+ $[9] = t8;
67
+ } else t8 = $[9];
68
+ return t8;
69
+ }
70
+ let t4;
71
+ if ($[10] !== size) {
72
+ t4 = {
31
73
  height: size,
32
74
  width: size
33
- },
34
- children: /* @__PURE__ */ jsx(Globe, {
35
- className: "text-muted-foreground",
36
- style: {
37
- height: size * .6,
38
- width: size * .6
39
- }
40
- })
41
- });
42
- return /* @__PURE__ */ jsx("div", {
43
- className: "bg-muted flex items-center justify-center overflow-hidden rounded-full",
44
- style: {
45
- height: size,
46
- width: size
47
- },
48
- children: /* @__PURE__ */ jsx("img", {
75
+ };
76
+ $[10] = size;
77
+ $[11] = t4;
78
+ } else t4 = $[11];
79
+ let t5;
80
+ if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
81
+ t5 = () => setHasError(true);
82
+ $[12] = t5;
83
+ } else t5 = $[12];
84
+ let t6;
85
+ if ($[13] !== faviconUrl) {
86
+ t6 = /* @__PURE__ */ jsx("img", {
49
87
  src: faviconUrl,
50
88
  alt: "Favicon",
51
89
  className: "h-full w-full object-cover",
52
- onError: () => setHasError(true)
53
- })
54
- });
90
+ onError: t5
91
+ });
92
+ $[13] = faviconUrl;
93
+ $[14] = t6;
94
+ } else t6 = $[14];
95
+ let t7;
96
+ if ($[15] !== t4 || $[16] !== t6) {
97
+ t7 = /* @__PURE__ */ jsx("div", {
98
+ className: "bg-muted flex items-center justify-center overflow-hidden rounded-full",
99
+ style: t4,
100
+ children: t6
101
+ });
102
+ $[15] = t4;
103
+ $[16] = t6;
104
+ $[17] = t7;
105
+ } else t7 = $[17];
106
+ return t7;
55
107
  };
56
108
  var ProjectMenu = () => {
109
+ const $ = c(39);
57
110
  const authCtx = React.useContext(AuthContext);
58
- const { data: project } = useQuery(projectQueries.getBySlug(authCtx.projectSlug));
59
- if (!project) return /* @__PURE__ */ jsxs("div", {
60
- className: "flex h-9 min-w-[150px] items-center gap-2 px-4",
61
- children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-4 rounded-full" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-3 flex-1" })]
62
- });
63
- return /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
64
- asChild: true,
65
- children: /* @__PURE__ */ jsxs(Button, {
66
- variant: "ghost",
67
- children: [/* @__PURE__ */ jsxs("div", {
68
- className: "flex items-center gap-2",
69
- children: [/* @__PURE__ */ jsx(Favicon, { size: 16 }), /* @__PURE__ */ jsx("span", {
70
- className: "select-none",
71
- children: project.name
72
- })]
73
- }), /* @__PURE__ */ jsx(ChevronDown, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })]
74
- })
75
- }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
76
- className: "w-72",
77
- align: "start",
78
- side: "bottom",
79
- children: [
80
- /* @__PURE__ */ jsxs(DropdownMenuItem, {
81
- onSelect: () => {
82
- if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/${project.slug}/overview`, "_blank");
83
- },
84
- children: [/* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" }), "Project settings"]
85
- }),
86
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
87
- /* @__PURE__ */ jsx(DropdownMenuLabel, {
88
- className: "text-muted-foreground text-xs font-normal",
89
- children: project.organizationSlug
90
- }),
91
- /* @__PURE__ */ jsxs(DropdownMenuItem, {
92
- onSelect: () => {
93
- if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/team?tab=members`, "_blank");
94
- },
95
- children: [/* @__PURE__ */ jsx(Users, { className: "mr-2 h-4 w-4" }), "Team members"]
96
- }),
97
- /* @__PURE__ */ jsxs(DropdownMenuItem, {
98
- onSelect: () => {
99
- if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/team?tab=settings`, "_blank");
100
- },
101
- children: [/* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" }), "Team settings"]
111
+ let t0;
112
+ if ($[0] !== authCtx.projectSlug) {
113
+ t0 = projectQueries.getBySlug(authCtx.projectSlug);
114
+ $[0] = authCtx.projectSlug;
115
+ $[1] = t0;
116
+ } else t0 = $[1];
117
+ const { data: project } = useQuery(t0);
118
+ if (!project) {
119
+ let t1;
120
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
121
+ t1 = /* @__PURE__ */ jsxs("div", {
122
+ className: "flex h-9 min-w-[150px] items-center gap-2 px-4",
123
+ children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-4 rounded-full" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-3 flex-1" })]
124
+ });
125
+ $[2] = t1;
126
+ } else t1 = $[2];
127
+ return t1;
128
+ }
129
+ let t1;
130
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
131
+ t1 = /* @__PURE__ */ jsx(Favicon, { size: 16 });
132
+ $[3] = t1;
133
+ } else t1 = $[3];
134
+ let t2;
135
+ if ($[4] !== project.name) {
136
+ t2 = /* @__PURE__ */ jsxs("div", {
137
+ className: "flex items-center gap-2",
138
+ children: [t1, /* @__PURE__ */ jsx("span", {
139
+ className: "select-none",
140
+ children: project.name
141
+ })]
142
+ });
143
+ $[4] = project.name;
144
+ $[5] = t2;
145
+ } else t2 = $[5];
146
+ let t3;
147
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
148
+ t3 = /* @__PURE__ */ jsx(ChevronDown, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" });
149
+ $[6] = t3;
150
+ } else t3 = $[6];
151
+ let t4;
152
+ if ($[7] !== t2) {
153
+ t4 = /* @__PURE__ */ jsx(DropdownMenuTrigger, {
154
+ asChild: true,
155
+ children: /* @__PURE__ */ jsxs(Button, {
156
+ variant: "ghost",
157
+ children: [t2, t3]
102
158
  })
103
- ]
104
- })] });
159
+ });
160
+ $[7] = t2;
161
+ $[8] = t4;
162
+ } else t4 = $[8];
163
+ let t5;
164
+ if ($[9] !== authCtx || $[10] !== project.organizationSlug || $[11] !== project.slug) {
165
+ t5 = () => {
166
+ if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/${project.slug}/overview`, "_blank");
167
+ };
168
+ $[9] = authCtx;
169
+ $[10] = project.organizationSlug;
170
+ $[11] = project.slug;
171
+ $[12] = t5;
172
+ } else t5 = $[12];
173
+ let t6;
174
+ if ($[13] === Symbol.for("react.memo_cache_sentinel")) {
175
+ t6 = /* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" });
176
+ $[13] = t6;
177
+ } else t6 = $[13];
178
+ let t7;
179
+ if ($[14] !== t5) {
180
+ t7 = /* @__PURE__ */ jsxs(DropdownMenuItem, {
181
+ onSelect: t5,
182
+ children: [t6, "Project settings"]
183
+ });
184
+ $[14] = t5;
185
+ $[15] = t7;
186
+ } else t7 = $[15];
187
+ let t8;
188
+ if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
189
+ t8 = /* @__PURE__ */ jsx(DropdownMenuSeparator, {});
190
+ $[16] = t8;
191
+ } else t8 = $[16];
192
+ let t9;
193
+ if ($[17] !== project.organizationSlug) {
194
+ t9 = /* @__PURE__ */ jsx(DropdownMenuLabel, {
195
+ className: "text-muted-foreground text-xs font-normal",
196
+ children: project.organizationSlug
197
+ });
198
+ $[17] = project.organizationSlug;
199
+ $[18] = t9;
200
+ } else t9 = $[18];
201
+ let t10;
202
+ if ($[19] !== authCtx || $[20] !== project.organizationSlug) {
203
+ t10 = () => {
204
+ if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/team?tab=members`, "_blank");
205
+ };
206
+ $[19] = authCtx;
207
+ $[20] = project.organizationSlug;
208
+ $[21] = t10;
209
+ } else t10 = $[21];
210
+ let t11;
211
+ if ($[22] === Symbol.for("react.memo_cache_sentinel")) {
212
+ t11 = /* @__PURE__ */ jsx(Users, { className: "mr-2 h-4 w-4" });
213
+ $[22] = t11;
214
+ } else t11 = $[22];
215
+ let t12;
216
+ if ($[23] !== t10) {
217
+ t12 = /* @__PURE__ */ jsxs(DropdownMenuItem, {
218
+ onSelect: t10,
219
+ children: [t11, "Team members"]
220
+ });
221
+ $[23] = t10;
222
+ $[24] = t12;
223
+ } else t12 = $[24];
224
+ let t13;
225
+ if ($[25] !== authCtx || $[26] !== project.organizationSlug) {
226
+ t13 = () => {
227
+ if (authCtx) window.open(`${authCtx.authenticationUrl}/dashboard/${project.organizationSlug}/team?tab=settings`, "_blank");
228
+ };
229
+ $[25] = authCtx;
230
+ $[26] = project.organizationSlug;
231
+ $[27] = t13;
232
+ } else t13 = $[27];
233
+ let t14;
234
+ if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
235
+ t14 = /* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" });
236
+ $[28] = t14;
237
+ } else t14 = $[28];
238
+ let t15;
239
+ if ($[29] !== t13) {
240
+ t15 = /* @__PURE__ */ jsxs(DropdownMenuItem, {
241
+ onSelect: t13,
242
+ children: [t14, "Team settings"]
243
+ });
244
+ $[29] = t13;
245
+ $[30] = t15;
246
+ } else t15 = $[30];
247
+ let t16;
248
+ if ($[31] !== t12 || $[32] !== t15 || $[33] !== t7 || $[34] !== t9) {
249
+ t16 = /* @__PURE__ */ jsxs(DropdownMenuContent, {
250
+ className: "w-72",
251
+ align: "start",
252
+ side: "bottom",
253
+ children: [
254
+ t7,
255
+ t8,
256
+ t9,
257
+ t12,
258
+ t15
259
+ ]
260
+ });
261
+ $[31] = t12;
262
+ $[32] = t15;
263
+ $[33] = t7;
264
+ $[34] = t9;
265
+ $[35] = t16;
266
+ } else t16 = $[35];
267
+ let t17;
268
+ if ($[36] !== t16 || $[37] !== t4) {
269
+ t17 = /* @__PURE__ */ jsxs(DropdownMenu, { children: [t4, t16] });
270
+ $[36] = t16;
271
+ $[37] = t4;
272
+ $[38] = t17;
273
+ } else t17 = $[38];
274
+ return t17;
105
275
  };
276
+ function _temp() {
277
+ for (const selector of [
278
+ "link[rel=\"icon\"]",
279
+ "link[rel=\"shortcut icon\"]",
280
+ "link[rel=\"apple-touch-icon\"]"
281
+ ]) {
282
+ const link = document.querySelector(selector);
283
+ if (link?.href) return link.href;
284
+ }
285
+ return null;
286
+ }
106
287
  //#endregion
107
288
  export { ProjectMenu };
@@ -1,5 +1,6 @@
1
1
  import { AuthContext, useAuthState } from "../../../lib/auth.js";
2
2
  import { useTheme } from "../useTheme.js";
3
+ import { c } from "react/compiler-runtime";
3
4
  import { useContext } from "react";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
6
  import { Button } from "@camox/ui/button";
@@ -8,14 +9,28 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel,
8
9
  import { Avatar, AvatarFallback, AvatarImage } from "@camox/ui/avatar";
9
10
  //#region src/features/studio/components/UserButton.tsx
10
11
  var UserButton = () => {
12
+ const $ = c(3);
11
13
  const { isAuthenticated, isLoading } = useAuthState();
12
14
  const { setTheme } = useTheme();
13
- if (!isAuthenticated || isLoading) return /* @__PURE__ */ jsx(Button, {
14
- variant: "outline",
15
- size: "icon",
16
- children: /* @__PURE__ */ jsx(User, { className: "h-4 w-4" })
17
- });
18
- return /* @__PURE__ */ jsx(AuthenticatedUserButton, { setTheme });
15
+ if (!isAuthenticated || isLoading) {
16
+ let t0;
17
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
18
+ t0 = /* @__PURE__ */ jsx(Button, {
19
+ variant: "outline",
20
+ size: "icon",
21
+ children: /* @__PURE__ */ jsx(User, { className: "h-4 w-4" })
22
+ });
23
+ $[0] = t0;
24
+ } else t0 = $[0];
25
+ return t0;
26
+ }
27
+ let t0;
28
+ if ($[1] !== setTheme) {
29
+ t0 = /* @__PURE__ */ jsx(AuthenticatedUserButton, { setTheme });
30
+ $[1] = setTheme;
31
+ $[2] = t0;
32
+ } else t0 = $[2];
33
+ return t0;
19
34
  };
20
35
  function AuthenticatedUserButton({ setTheme }) {
21
36
  const authCtx = useContext(AuthContext);
@@ -2,7 +2,7 @@ interface StudioContext {
2
2
  isCommandPaletteOpen: boolean;
3
3
  commandPalettePages: string[];
4
4
  }
5
- export declare const studioStore: import('@xstate/store').Store<StudioContext, import('@xstate/store').ExtractEvents<{
5
+ export declare const studioStore: import('@xstate/store').Store<StudioContext, {
6
6
  openCommandPalette: unknown;
7
7
  closeCommandPalette: unknown;
8
8
  toggleCommandPalette: unknown;
@@ -10,7 +10,7 @@ export declare const studioStore: import('@xstate/store').Store<StudioContext, i
10
10
  page: string;
11
11
  };
12
12
  popCommandPalettePage: unknown;
13
- }>, {
13
+ }, {
14
14
  type: string;
15
15
  }>;
16
16
  export {};
@@ -1,87 +1,141 @@
1
1
  import { actionsStore } from "../provider/actionsStore.js";
2
+ import { c } from "react/compiler-runtime";
2
3
  import * as React from "react";
3
4
  //#region src/features/studio/useTheme.ts
4
5
  function useTheme() {
5
- const [theme, setTheme] = React.useState(() => {
6
- if (typeof window !== "undefined") return localStorage.getItem("theme") || "system";
7
- return "system";
8
- });
9
- const applyTheme = (themeToApply) => {
10
- const root = window.document.documentElement;
11
- root.classList.remove("light", "dark");
12
- root.classList.add(themeToApply);
13
- };
14
- React.useEffect(() => {
15
- const root = window.document.documentElement;
16
- root.classList.remove("light", "dark");
17
- if (theme === "system") {
18
- const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
19
- const updateSystemTheme = () => {
20
- applyTheme(mediaQuery.matches ? "dark" : "light");
21
- };
22
- updateSystemTheme();
23
- mediaQuery.addEventListener("change", updateSystemTheme);
24
- return () => mediaQuery.removeEventListener("change", updateSystemTheme);
25
- }
26
- root.classList.add(theme);
27
- }, [theme]);
28
- React.useEffect(() => {
29
- localStorage.setItem("theme", theme);
30
- }, [theme]);
31
- return {
32
- theme,
33
- setTheme
34
- };
6
+ const $ = c(8);
7
+ const [theme, setTheme] = React.useState(_temp);
8
+ const applyTheme = _temp2;
9
+ let t0;
10
+ let t1;
11
+ if ($[0] !== theme) {
12
+ t0 = () => {
13
+ const root_0 = window.document.documentElement;
14
+ root_0.classList.remove("light", "dark");
15
+ if (theme === "system") {
16
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
17
+ const updateSystemTheme = () => {
18
+ applyTheme(mediaQuery.matches ? "dark" : "light");
19
+ };
20
+ updateSystemTheme();
21
+ mediaQuery.addEventListener("change", updateSystemTheme);
22
+ return () => mediaQuery.removeEventListener("change", updateSystemTheme);
23
+ }
24
+ root_0.classList.add(theme);
25
+ };
26
+ t1 = [theme];
27
+ $[0] = theme;
28
+ $[1] = t0;
29
+ $[2] = t1;
30
+ } else {
31
+ t0 = $[1];
32
+ t1 = $[2];
33
+ }
34
+ React.useEffect(t0, t1);
35
+ let t2;
36
+ let t3;
37
+ if ($[3] !== theme) {
38
+ t2 = () => {
39
+ localStorage.setItem("theme", theme);
40
+ };
41
+ t3 = [theme];
42
+ $[3] = theme;
43
+ $[4] = t2;
44
+ $[5] = t3;
45
+ } else {
46
+ t2 = $[4];
47
+ t3 = $[5];
48
+ }
49
+ React.useEffect(t2, t3);
50
+ let t4;
51
+ if ($[6] !== theme) {
52
+ t4 = {
53
+ theme,
54
+ setTheme
55
+ };
56
+ $[6] = theme;
57
+ $[7] = t4;
58
+ } else t4 = $[7];
59
+ return t4;
60
+ }
61
+ function _temp2(themeToApply) {
62
+ const root = window.document.documentElement;
63
+ root.classList.remove("light", "dark");
64
+ root.classList.add(themeToApply);
65
+ }
66
+ function _temp() {
67
+ if (typeof window !== "undefined") return localStorage.getItem("theme") || "system";
68
+ return "system";
35
69
  }
36
70
  function useThemeActions() {
71
+ const $ = c(4);
37
72
  const { theme, setTheme } = useTheme();
38
- React.useEffect(() => {
39
- const pageId = "change-theme";
40
- const actions = [
41
- {
42
- id: pageId,
43
- label: "Change theme",
44
- groupLabel: "Studio",
45
- checkIfAvailable: () => true,
46
- hasChildren: true,
47
- execute: () => {}
48
- },
49
- {
50
- id: "switch-to-light-theme",
51
- parentActionId: pageId,
52
- label: "Switch to light theme",
53
- groupLabel: "Studio",
54
- checkIfAvailable: () => theme !== "light",
55
- execute: () => setTheme("light")
56
- },
57
- {
58
- id: "switch-to-dark-theme",
59
- parentActionId: pageId,
60
- label: "Switch to dark theme",
61
- groupLabel: "Studio",
62
- checkIfAvailable: () => theme !== "dark",
63
- execute: () => setTheme("dark")
64
- },
65
- {
66
- id: "switch-to-system-theme",
67
- parentActionId: pageId,
68
- label: "Switch to system theme",
69
- groupLabel: "Studio",
70
- checkIfAvailable: () => theme !== "system",
71
- execute: () => setTheme("system")
72
- }
73
- ];
74
- actionsStore.send({
75
- type: "registerManyActions",
76
- actions
77
- });
78
- return () => {
73
+ let t0;
74
+ let t1;
75
+ if ($[0] !== setTheme || $[1] !== theme) {
76
+ t0 = () => {
77
+ const actions = [
78
+ {
79
+ id: "change-theme",
80
+ label: "Change theme",
81
+ groupLabel: "Studio",
82
+ checkIfAvailable: _temp3,
83
+ hasChildren: true,
84
+ execute: _temp4
85
+ },
86
+ {
87
+ id: "switch-to-light-theme",
88
+ parentActionId: "change-theme",
89
+ label: "Switch to light theme",
90
+ groupLabel: "Studio",
91
+ checkIfAvailable: () => theme !== "light",
92
+ execute: () => setTheme("light")
93
+ },
94
+ {
95
+ id: "switch-to-dark-theme",
96
+ parentActionId: "change-theme",
97
+ label: "Switch to dark theme",
98
+ groupLabel: "Studio",
99
+ checkIfAvailable: () => theme !== "dark",
100
+ execute: () => setTheme("dark")
101
+ },
102
+ {
103
+ id: "switch-to-system-theme",
104
+ parentActionId: "change-theme",
105
+ label: "Switch to system theme",
106
+ groupLabel: "Studio",
107
+ checkIfAvailable: () => theme !== "system",
108
+ execute: () => setTheme("system")
109
+ }
110
+ ];
79
111
  actionsStore.send({
80
- type: "unregisterManyActions",
81
- ids: actions.map((a) => a.id)
112
+ type: "registerManyActions",
113
+ actions
82
114
  });
115
+ return () => {
116
+ actionsStore.send({
117
+ type: "unregisterManyActions",
118
+ ids: actions.map(_temp5)
119
+ });
120
+ };
83
121
  };
84
- }, [theme, setTheme]);
122
+ t1 = [theme, setTheme];
123
+ $[0] = setTheme;
124
+ $[1] = theme;
125
+ $[2] = t0;
126
+ $[3] = t1;
127
+ } else {
128
+ t0 = $[2];
129
+ t1 = $[3];
130
+ }
131
+ React.useEffect(t0, t1);
132
+ }
133
+ function _temp5(a) {
134
+ return a.id;
135
+ }
136
+ function _temp4() {}
137
+ function _temp3() {
138
+ return true;
85
139
  }
86
140
  //#endregion
87
141
  export { useTheme, useThemeActions };