@sanity/workbench 0.0.1-alpha.0 → 0.1.0-alpha.10

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 (37) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_chunks-es/index.js +34 -0
  3. package/dist/_chunks-es/index.js.map +1 -0
  4. package/dist/_internal.d.ts +64 -0
  5. package/dist/_internal.js +54 -0
  6. package/dist/_internal.js.map +1 -0
  7. package/dist/core.d.ts +1617 -0
  8. package/dist/core.js +779 -0
  9. package/dist/core.js.map +1 -0
  10. package/package.json +34 -24
  11. package/src/_exports/_internal.ts +1 -0
  12. package/src/_exports/core.ts +1 -0
  13. package/src/_internal/env.ts +32 -0
  14. package/src/_internal/index.ts +4 -0
  15. package/src/_internal/render.ts +125 -0
  16. package/src/core/applications/application-list.ts +104 -0
  17. package/src/core/applications/application.ts +95 -0
  18. package/src/core/canvases.ts +91 -0
  19. package/src/core/config.ts +34 -0
  20. package/src/core/index.ts +12 -0
  21. package/src/core/log/index.ts +92 -0
  22. package/src/core/media-libraries.ts +92 -0
  23. package/src/core/organizations.ts +115 -0
  24. package/src/core/projects.ts +114 -0
  25. package/src/core/shared/urls.ts +129 -0
  26. package/src/core/user-applications/core-app.ts +131 -0
  27. package/src/core/user-applications/studios/index.ts +3 -0
  28. package/src/core/user-applications/studios/schemas.ts +111 -0
  29. package/src/core/user-applications/studios/studio.ts +504 -0
  30. package/src/core/user-applications/studios/workspace.ts +147 -0
  31. package/src/core/user-applications/user-application.ts +181 -0
  32. package/src/vite-env.d.ts +8 -0
  33. package/dist/index.cjs +0 -16
  34. package/dist/index.cjs.map +0 -1
  35. package/dist/index.js +0 -18
  36. package/dist/index.js.map +0 -1
  37. package/src/index.tsx +0 -35
@@ -0,0 +1,181 @@
1
+ // eslint-disable-next-line no-restricted-imports
2
+ import type { Resource as ProtocolResource } from "@sanity/message-protocol";
3
+ import { z } from "zod";
4
+
5
+ import {
6
+ AbstractApplication,
7
+ type AbstractApplicationType,
8
+ } from "../applications/application";
9
+ import type { CoreAppUserApplicationManifest } from "./core-app";
10
+ import type { ClientManifest } from "./studios/schemas";
11
+
12
+ /**
13
+ * User application ID schema, branded for type safety.
14
+ * @public
15
+ */
16
+ export const UserApplicationId = z
17
+ .string()
18
+ .nonempty()
19
+ .brand("UserApplicationId");
20
+
21
+ /**
22
+ * User application ID type, branded for type safety.
23
+ * @public
24
+ */
25
+ export type UserApplicationId = z.output<typeof UserApplicationId>;
26
+
27
+ /**
28
+ * Validates and brands a string as a UserApplicationId.
29
+ * @public
30
+ */
31
+ export function brandUserApplicationId(id: string): UserApplicationId {
32
+ return UserApplicationId.parse(id);
33
+ }
34
+
35
+ const LocalUserApplicationBase = z.object({
36
+ host: z.string(),
37
+ port: z.number(),
38
+ /** The `deployment.appId` from the application's `sanity.cli.ts`, when set. */
39
+ id: z.string().optional(),
40
+ });
41
+
42
+ /**
43
+ * Raw data for a local application discovered by the CLI dev server.
44
+ *
45
+ * The CLI forwards the full studio or app manifest so the workbench can
46
+ * derive icons, titles, workspaces and schema references the same way it
47
+ * does for deployed applications. The manifest shape is discriminated on
48
+ * `type`: studios receive a `ClientManifest`, core apps a `CoreAppUserApplicationManifest`.
49
+ *
50
+ * When set on a `UserApplication`, `isLocal` is `true` and `url`/`isFederated`
51
+ * honour the local dev-server instead of the deployed application's host.
52
+ *
53
+ * @public
54
+ */
55
+ export const LocalUserApplication = z.discriminatedUnion("type", [
56
+ LocalUserApplicationBase.extend({
57
+ type: z.literal("studio"),
58
+ manifest: z.custom<ClientManifest>().optional(),
59
+ }),
60
+ LocalUserApplicationBase.extend({
61
+ type: z.literal("coreApp"),
62
+ manifest: z.custom<CoreAppUserApplicationManifest>().optional(),
63
+ }),
64
+ ]);
65
+
66
+ /**
67
+ * @public
68
+ */
69
+ export type LocalUserApplication = z.output<typeof LocalUserApplication>;
70
+
71
+ /**
72
+ * @public
73
+ */
74
+ export const UserApplicationBase = z.object({
75
+ id: UserApplicationId,
76
+ appHost: z.string(),
77
+ urlType: z.enum(["internal", "external"]),
78
+ createdAt: z.string(),
79
+ updatedAt: z.string(),
80
+ dashboardStatus: z.enum(["default", "disabled"]),
81
+ });
82
+
83
+ /**
84
+ * @public
85
+ */
86
+ export type UserApplicationBase = z.output<typeof UserApplicationBase>;
87
+
88
+ /**
89
+ * @public
90
+ */
91
+ export const ActiveDeployment = z.object({
92
+ id: z.string(),
93
+ version: z.string(),
94
+ isActiveDeployment: z.boolean(),
95
+ userApplicationId: z.string(),
96
+ isAutoUpdating: z.boolean(),
97
+ size: z.number(),
98
+ deployedAt: z.string(),
99
+ deployedBy: z.string(),
100
+ createdAt: z.string(),
101
+ updatedAt: z.string(),
102
+ });
103
+
104
+ /**
105
+ * @public
106
+ */
107
+ export abstract class UserApplication<
108
+ TUserApplication extends UserApplicationBase,
109
+ TType extends Extract<AbstractApplicationType, "coreApp" | "studio">,
110
+ TProtocolResource extends ProtocolResource = Extract<
111
+ ProtocolResource,
112
+ { type: TType }
113
+ >,
114
+ > extends AbstractApplication<TType, TProtocolResource> {
115
+ readonly application: TUserApplication;
116
+
117
+ readonly id: UserApplicationId;
118
+
119
+ /**
120
+ * For local applications (`isLocal === true`), the deployed application
121
+ * that shares the same `id` — if one was passed at construction. `null`
122
+ * for deployed applications or when no remote twin was provided.
123
+ */
124
+ readonly remoteApplication: this | null;
125
+
126
+ readonly #isLocal: boolean;
127
+
128
+ constructor(
129
+ application: TUserApplication,
130
+ type: TType,
131
+ options: {
132
+ isLocal?: boolean;
133
+ remoteApplication?: UserApplication<
134
+ TUserApplication,
135
+ TType,
136
+ TProtocolResource
137
+ > | null;
138
+ } = {},
139
+ ) {
140
+ super(type);
141
+ this.application = application;
142
+ this.id = brandUserApplicationId(application.id);
143
+ this.#isLocal = options.isLocal ?? false;
144
+ this.remoteApplication =
145
+ (options.remoteApplication as this | undefined) ?? null;
146
+ }
147
+
148
+ abstract get subtitle(): string | undefined;
149
+
150
+ /**
151
+ * Local dev servers are rendered as federated remotes; deployed applications
152
+ * are rendered in an iframe.
153
+ */
154
+ get isFederated(): boolean {
155
+ return this.isLocal;
156
+ }
157
+
158
+ override get isLocal(): boolean {
159
+ return this.#isLocal;
160
+ }
161
+
162
+ /**
163
+ * @returns A fully resolved URL instance for the application.
164
+ * For internal applications, constructs a URL using the Sanity studio domain
165
+ * pattern resolved from the environment at the consuming app's build time.
166
+ * For external applications (including local dev servers), returns the
167
+ * provided app host as a URL.
168
+ */
169
+ get url(): URL {
170
+ if (this.application.urlType === "internal") {
171
+ if (import.meta.env.VITE_SANITY_ENV === "production") {
172
+ return new URL(`https://${this.application.appHost}.sanity.studio`);
173
+ }
174
+ return new URL(
175
+ `https://${this.application.appHost}.studio.${import.meta.env.VITE_SANITY_DOMAIN}`,
176
+ );
177
+ }
178
+
179
+ return new URL(this.application.appHost);
180
+ }
181
+ }
@@ -0,0 +1,8 @@
1
+ interface ImportMetaEnv {
2
+ readonly VITE_SANITY_ENV: "production" | "staging";
3
+ readonly VITE_SANITY_DOMAIN: "sanity.work" | "sanity.io";
4
+ }
5
+
6
+ interface ImportMeta {
7
+ readonly env: ImportMetaEnv;
8
+ }
package/dist/index.cjs DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), react = require("react"), client = require("react-dom/client");
4
- function Workbench(_props) {
5
- return /* @__PURE__ */ jsxRuntime.jsx("h1", { children: "Hello World" });
6
- }
7
- function renderWorkbench(rootElement, config, options) {
8
- if (!rootElement)
9
- throw new Error("Missing root element to mount application into");
10
- const root = client.createRoot(rootElement), workbench = /* @__PURE__ */ jsxRuntime.jsx(Workbench, { config });
11
- return root.render(
12
- options?.reactStrictMode ? /* @__PURE__ */ jsxRuntime.jsx(react.StrictMode, { children: workbench }) : workbench
13
- ), () => root.unmount();
14
- }
15
- exports.renderWorkbench = renderWorkbench;
16
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.tsx"],"sourcesContent":["import { StrictMode } from \"react\";\nimport { createRoot } from \"react-dom/client\";\n\ninterface WorkbenchProps {\n config: undefined;\n}\n\nfunction Workbench(_props: WorkbenchProps) {\n return <h1>Hello World</h1>;\n}\n\ninterface RenderWorkbenchOptions {\n reactStrictMode: boolean;\n}\n\nexport function renderWorkbench(\n rootElement: HTMLElement,\n config: Config,\n options?: RenderWorkbenchOptions,\n): () => void {\n if (!rootElement) {\n throw new Error(\"Missing root element to mount application into\");\n }\n\n const root = createRoot(rootElement);\n const workbench = <Workbench config={config} />;\n\n root.render(\n options?.reactStrictMode ? <StrictMode>{workbench}</StrictMode> : workbench,\n );\n\n return () => root.unmount();\n}\n\nexport type Config = WorkbenchProps[\"config\"];\n"],"names":["jsx","createRoot","StrictMode"],"mappings":";;;AAOA,SAAS,UAAU,QAAwB;AACzC,SAAOA,2BAAAA,IAAC,QAAG,UAAA,cAAA,CAAW;AACxB;AAMO,SAAS,gBACd,aACA,QACA,SACY;AACZ,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,gDAAgD;AAGlE,QAAM,OAAOC,OAAAA,WAAW,WAAW,GAC7B,YAAYD,+BAAC,aAAU,QAAgB;AAE7C,SAAA,KAAK;AAAA,IACH,SAAS,kBAAkBA,+BAACE,MAAAA,YAAA,EAAY,qBAAU,IAAgB;AAAA,EAAA,GAG7D,MAAM,KAAK,QAAA;AACpB;;"}
package/dist/index.js DELETED
@@ -1,18 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { StrictMode } from "react";
3
- import { createRoot } from "react-dom/client";
4
- function Workbench(_props) {
5
- return /* @__PURE__ */ jsx("h1", { children: "Hello World" });
6
- }
7
- function renderWorkbench(rootElement, config, options) {
8
- if (!rootElement)
9
- throw new Error("Missing root element to mount application into");
10
- const root = createRoot(rootElement), workbench = /* @__PURE__ */ jsx(Workbench, { config });
11
- return root.render(
12
- options?.reactStrictMode ? /* @__PURE__ */ jsx(StrictMode, { children: workbench }) : workbench
13
- ), () => root.unmount();
14
- }
15
- export {
16
- renderWorkbench
17
- };
18
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import { StrictMode } from \"react\";\nimport { createRoot } from \"react-dom/client\";\n\ninterface WorkbenchProps {\n config: undefined;\n}\n\nfunction Workbench(_props: WorkbenchProps) {\n return <h1>Hello World</h1>;\n}\n\ninterface RenderWorkbenchOptions {\n reactStrictMode: boolean;\n}\n\nexport function renderWorkbench(\n rootElement: HTMLElement,\n config: Config,\n options?: RenderWorkbenchOptions,\n): () => void {\n if (!rootElement) {\n throw new Error(\"Missing root element to mount application into\");\n }\n\n const root = createRoot(rootElement);\n const workbench = <Workbench config={config} />;\n\n root.render(\n options?.reactStrictMode ? <StrictMode>{workbench}</StrictMode> : workbench,\n );\n\n return () => root.unmount();\n}\n\nexport type Config = WorkbenchProps[\"config\"];\n"],"names":[],"mappings":";;;AAOA,SAAS,UAAU,QAAwB;AACzC,SAAO,oBAAC,QAAG,UAAA,cAAA,CAAW;AACxB;AAMO,SAAS,gBACd,aACA,QACA,SACY;AACZ,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,gDAAgD;AAGlE,QAAM,OAAO,WAAW,WAAW,GAC7B,YAAY,oBAAC,aAAU,QAAgB;AAE7C,SAAA,KAAK;AAAA,IACH,SAAS,kBAAkB,oBAAC,YAAA,EAAY,qBAAU,IAAgB;AAAA,EAAA,GAG7D,MAAM,KAAK,QAAA;AACpB;"}
package/src/index.tsx DELETED
@@ -1,35 +0,0 @@
1
- import { StrictMode } from "react";
2
- import { createRoot } from "react-dom/client";
3
-
4
- interface WorkbenchProps {
5
- config: undefined;
6
- }
7
-
8
- function Workbench(_props: WorkbenchProps) {
9
- return <h1>Hello World</h1>;
10
- }
11
-
12
- interface RenderWorkbenchOptions {
13
- reactStrictMode: boolean;
14
- }
15
-
16
- export function renderWorkbench(
17
- rootElement: HTMLElement,
18
- config: Config,
19
- options?: RenderWorkbenchOptions,
20
- ): () => void {
21
- if (!rootElement) {
22
- throw new Error("Missing root element to mount application into");
23
- }
24
-
25
- const root = createRoot(rootElement);
26
- const workbench = <Workbench config={config} />;
27
-
28
- root.render(
29
- options?.reactStrictMode ? <StrictMode>{workbench}</StrictMode> : workbench,
30
- );
31
-
32
- return () => root.unmount();
33
- }
34
-
35
- export type Config = WorkbenchProps["config"];