@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.
- package/LICENSE +21 -0
- package/dist/_chunks-es/index.js +34 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_internal.d.ts +64 -0
- package/dist/_internal.js +54 -0
- package/dist/_internal.js.map +1 -0
- package/dist/core.d.ts +1617 -0
- package/dist/core.js +779 -0
- package/dist/core.js.map +1 -0
- package/package.json +34 -24
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/core.ts +1 -0
- package/src/_internal/env.ts +32 -0
- package/src/_internal/index.ts +4 -0
- package/src/_internal/render.ts +125 -0
- package/src/core/applications/application-list.ts +104 -0
- package/src/core/applications/application.ts +95 -0
- package/src/core/canvases.ts +91 -0
- package/src/core/config.ts +34 -0
- package/src/core/index.ts +12 -0
- package/src/core/log/index.ts +92 -0
- package/src/core/media-libraries.ts +92 -0
- package/src/core/organizations.ts +115 -0
- package/src/core/projects.ts +114 -0
- package/src/core/shared/urls.ts +129 -0
- package/src/core/user-applications/core-app.ts +131 -0
- package/src/core/user-applications/studios/index.ts +3 -0
- package/src/core/user-applications/studios/schemas.ts +111 -0
- package/src/core/user-applications/studios/studio.ts +504 -0
- package/src/core/user-applications/studios/workspace.ts +147 -0
- package/src/core/user-applications/user-application.ts +181 -0
- package/src/vite-env.d.ts +8 -0
- package/dist/index.cjs +0 -16
- package/dist/index.cjs.map +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/src/index.tsx +0 -35
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sanity.io
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const LEVELS = ["none", "error", "warn", "info", "debug"];
|
|
2
|
+
function createLogger({
|
|
3
|
+
namespace,
|
|
4
|
+
context: baseContext,
|
|
5
|
+
logLevel = "info"
|
|
6
|
+
} = {}) {
|
|
7
|
+
function isLevelEnabled(level) {
|
|
8
|
+
return LEVELS.indexOf(level) <= LEVELS.indexOf(logLevel);
|
|
9
|
+
}
|
|
10
|
+
function logAtLevel(level, message, context) {
|
|
11
|
+
if (!isLevelEnabled(level)) return;
|
|
12
|
+
const merged = baseContext ?? context ? { ...baseContext, ...context } : void 0, args = [
|
|
13
|
+
...namespace ? [`[${namespace}]`] : [],
|
|
14
|
+
message,
|
|
15
|
+
...merged ? [merged] : []
|
|
16
|
+
];
|
|
17
|
+
level === "error" ? console.error(...args) : level === "warn" ? console.warn(...args) : level === "info" ? console.info(...args) : console.debug(...args);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
error: (message, context) => logAtLevel("error", message, context),
|
|
21
|
+
warn: (message, context) => logAtLevel("warn", message, context),
|
|
22
|
+
info: (message, context) => logAtLevel("info", message, context),
|
|
23
|
+
debug: (message, context) => logAtLevel("debug", message, context)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const logger = createLogger({
|
|
27
|
+
namespace: "sanity-workbench",
|
|
28
|
+
logLevel: "debug"
|
|
29
|
+
});
|
|
30
|
+
export {
|
|
31
|
+
createLogger,
|
|
32
|
+
logger
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/core/log/index.ts"],"sourcesContent":["/**\n * Log levels in order of verbosity (least to most)\n * - none: Silent\n * - error: Critical failures that prevent operation\n * - warn: Issues that may cause problems but don't stop execution\n * - info: High-level informational messages (default)\n * - debug: Detailed debugging information (maintainer level)\n * - trace: Very detailed tracing — sets `internal: true` on context\n * @public\n */\nexport type LogLevel = \"none\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\n/**\n * Namespaces organize logs by functional domain.\n * @internal\n */\nexport type LogNamespace = string;\n\ntype LogContext = { [key: string]: unknown };\n\n/**\n * @public\n */\nexport interface Logger {\n error: (message: string, context?: LogContext) => void;\n warn: (message: string, context?: LogContext) => void;\n info: (message: string, context?: LogContext) => void;\n debug: (message: string, context?: LogContext) => void;\n}\n\nconst LEVELS: readonly LogLevel[] = [\"none\", \"error\", \"warn\", \"info\", \"debug\"];\n\ninterface LoggerOptions {\n namespace?: LogNamespace;\n context?: LogContext;\n logLevel?: LogLevel;\n}\n\n/**\n * @public\n */\nexport function createLogger({\n namespace,\n context: baseContext,\n logLevel = \"info\",\n}: LoggerOptions = {}): Logger {\n function isLevelEnabled(level: LogLevel): boolean {\n return LEVELS.indexOf(level) <= LEVELS.indexOf(logLevel);\n }\n\n function logAtLevel(\n level: LogLevel,\n message: string,\n context?: LogContext,\n ): void {\n if (!isLevelEnabled(level)) return;\n\n const merged =\n (baseContext ?? context) ? { ...baseContext, ...context } : undefined;\n const args: unknown[] = [\n ...(namespace ? [`[${namespace}]`] : []),\n message,\n ...(merged ? [merged] : []),\n ];\n\n if (level === \"error\") console.error(...args);\n else if (level === \"warn\") console.warn(...args);\n // oxlint-disable-next-line no-console\n else if (level === \"info\") console.info(...args);\n // oxlint-disable-next-line no-console\n else console.debug(...args);\n }\n\n return {\n error: (message, context) => logAtLevel(\"error\", message, context),\n warn: (message, context) => logAtLevel(\"warn\", message, context),\n info: (message, context) => logAtLevel(\"info\", message, context),\n debug: (message, context) => logAtLevel(\"debug\", message, context),\n };\n}\n\n/**\n * Shared workbench logger instance. Use this from both the workbench host\n * and its remotes so lifecycle and diagnostic logs appear under a single\n * namespace.\n *\n * @public\n */\nexport const logger: Logger = createLogger({\n namespace: \"sanity-workbench\",\n logLevel: \"debug\",\n});\n"],"names":[],"mappings":"AA8BA,MAAM,SAA8B,CAAC,QAAQ,SAAS,QAAQ,QAAQ,OAAO;AAWtE,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA,SAAS;AAAA,EACT,WAAW;AACb,IAAmB,IAAY;AAC7B,WAAS,eAAe,OAA0B;AAChD,WAAO,OAAO,QAAQ,KAAK,KAAK,OAAO,QAAQ,QAAQ;AAAA,EACzD;AAEA,WAAS,WACP,OACA,SACA,SACM;AACN,QAAI,CAAC,eAAe,KAAK,EAAG;AAE5B,UAAM,SACH,eAAe,UAAW,EAAE,GAAG,aAAa,GAAG,QAAA,IAAY,QACxD,OAAkB;AAAA,MACtB,GAAI,YAAY,CAAC,IAAI,SAAS,GAAG,IAAI,CAAA;AAAA,MACrC;AAAA,MACA,GAAI,SAAS,CAAC,MAAM,IAAI,CAAA;AAAA,IAAC;AAGvB,cAAU,UAAS,QAAQ,MAAM,GAAG,IAAI,IACnC,UAAU,SAAQ,QAAQ,KAAK,GAAG,IAAI,IAEtC,UAAU,SAAQ,QAAQ,KAAK,GAAG,IAAI,IAE1C,QAAQ,MAAM,GAAG,IAAI;AAAA,EAC5B;AAEA,SAAO;AAAA,IACL,OAAO,CAAC,SAAS,YAAY,WAAW,SAAS,SAAS,OAAO;AAAA,IACjE,MAAM,CAAC,SAAS,YAAY,WAAW,QAAQ,SAAS,OAAO;AAAA,IAC/D,MAAM,CAAC,SAAS,YAAY,WAAW,QAAQ,SAAS,OAAO;AAAA,IAC/D,OAAO,CAAC,SAAS,YAAY,WAAW,SAAS,SAAS,OAAO;AAAA,EAAA;AAErE;AASO,MAAM,SAAiB,aAAa;AAAA,EACzC,WAAW;AAAA,EACX,UAAU;AACZ,CAAC;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workbench configuration.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare interface Config {
|
|
7
|
+
/**
|
|
8
|
+
* The organization ID to use when rendering the workbench.
|
|
9
|
+
*/
|
|
10
|
+
organizationId?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the API host based on the `__SANITY_STAGING__` build-time flag.
|
|
15
|
+
* If the flag is set to `true`, the staging API host is returned.
|
|
16
|
+
* Otherwise, the production API host is returned.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function getApiHost(): string | undefined;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the current Sanity environment based on the `__SANITY_STAGING__` build-time flag.
|
|
24
|
+
* If the flag is set to `true`, "staging" is returned.
|
|
25
|
+
* Otherwise, "production" is returned.
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function getSanityEnv(): "staging" | "production";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Options for rendering a remote module, such as a user application.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
declare interface RemoteModuleRenderOptions {
|
|
37
|
+
reactStrictMode?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a Module Federation instance, loads a remote workbench
|
|
42
|
+
* application, and renders it into the provided root element.
|
|
43
|
+
*
|
|
44
|
+
* @param rootElement - The DOM element to render into
|
|
45
|
+
* @param config - Workbench configuration (reserved for future use)
|
|
46
|
+
* @param options - Rendering options forwarded to the remote
|
|
47
|
+
* @returns A cleanup function that unmounts the remote application
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare function renderWorkbench(
|
|
52
|
+
rootElement: HTMLElement,
|
|
53
|
+
config?: Config,
|
|
54
|
+
options?: RenderWorkbenchOptions,
|
|
55
|
+
): Promise<() => void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Options for rendering the workbench.
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
export declare interface RenderWorkbenchOptions extends RemoteModuleRenderOptions {}
|
|
63
|
+
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createInstance } from "@sanity/federation/runtime";
|
|
2
|
+
import { log } from "@sanity/federation/runtime/plugins/log";
|
|
3
|
+
import { BehaviorSubject } from "rxjs";
|
|
4
|
+
import { logger } from "./_chunks-es/index.js";
|
|
5
|
+
const REMOTE_NAME = "workbench-remote", REMOTE_MODULE = "App", LOCAL_APPS_HMR_EVENT = "sanity:workbench:local-applications", LOCAL_APPS_HMR_REQUEST = "sanity:workbench:get-local-applications";
|
|
6
|
+
async function renderWorkbench(rootElement, config, options) {
|
|
7
|
+
if (!rootElement)
|
|
8
|
+
throw new Error("Missing root element to mount application into");
|
|
9
|
+
const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL ?? "https://workbench-remote.sanity.dev/mf-manifest.json";
|
|
10
|
+
let remoteModule = await createInstance({
|
|
11
|
+
name: "sanity-workbench",
|
|
12
|
+
plugins: [log(logger.debug)],
|
|
13
|
+
remotes: [
|
|
14
|
+
{
|
|
15
|
+
name: REMOTE_NAME,
|
|
16
|
+
entry: remoteUrl
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}).loadRemote(
|
|
20
|
+
`${REMOTE_NAME}/${REMOTE_MODULE}`
|
|
21
|
+
);
|
|
22
|
+
if (!remoteModule || typeof remoteModule.render != "function")
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Remote module "${REMOTE_NAME}/${REMOTE_MODULE}" did not expose a render function`
|
|
25
|
+
);
|
|
26
|
+
let localApplications, cleanupHmr = () => {
|
|
27
|
+
};
|
|
28
|
+
if (import.meta.hot) {
|
|
29
|
+
const localApps$ = new BehaviorSubject([]), handler = (payload) => {
|
|
30
|
+
localApps$.next(payload.applications);
|
|
31
|
+
};
|
|
32
|
+
import.meta.hot.on(LOCAL_APPS_HMR_EVENT, handler), import.meta.hot.send(LOCAL_APPS_HMR_REQUEST), localApplications = localApps$, cleanupHmr = () => import.meta.hot?.off(LOCAL_APPS_HMR_EVENT, handler);
|
|
33
|
+
}
|
|
34
|
+
const unmount = remoteModule.render(
|
|
35
|
+
rootElement,
|
|
36
|
+
{ config, localApplications },
|
|
37
|
+
options
|
|
38
|
+
);
|
|
39
|
+
return () => {
|
|
40
|
+
cleanupHmr(), unmount();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getApiHost() {
|
|
44
|
+
return getSanityEnv() === "staging" ? "https://api.sanity.work" : "https://api.sanity.io";
|
|
45
|
+
}
|
|
46
|
+
function getSanityEnv() {
|
|
47
|
+
return typeof __SANITY_STAGING__ < "u" && __SANITY_STAGING__ === !0 ? "staging" : "production";
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
getApiHost,
|
|
51
|
+
getSanityEnv,
|
|
52
|
+
renderWorkbench
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=_internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_internal.js","sources":["../src/_internal/render.ts","../src/_internal/env.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { createInstance } from \"@sanity/federation/runtime\";\nimport { log } from \"@sanity/federation/runtime/plugins/log\";\nimport { BehaviorSubject, type Observable } from \"rxjs\";\n\nimport type { Config, RemoteModuleRenderOptions } from \"../core/config\";\nimport { logger } from \"../core/log\";\nimport type { LocalUserApplication } from \"../core/user-applications/user-application\";\n\n/**\n * Options for rendering the workbench.\n *\n * @public\n */\nexport interface RenderWorkbenchOptions extends RemoteModuleRenderOptions {}\n\ndeclare global {\n interface ImportMetaEnv {\n readonly SANITY_INTERNAL_WORKBENCH_REMOTE_URL: string;\n }\n interface ImportMeta {\n readonly env: ImportMetaEnv;\n }\n}\n\ntype RemoteModule<TProps extends any> = {\n render: (\n rootElement: HTMLElement,\n props: TProps,\n options?: RenderWorkbenchOptions,\n ) => () => void;\n};\n\n/**\n * Module defining the remote workbench application.\n *\n * @internal\n */\ntype WorkbenchRemoteModule = RemoteModule<{\n config?: Config;\n localApplications?: Observable<LocalUserApplication[]>;\n}>;\n\nconst REMOTE_NAME = \"workbench-remote\";\nconst REMOTE_MODULE = \"App\";\n\nconst LOCAL_APPS_HMR_EVENT = \"sanity:workbench:local-applications\";\nconst LOCAL_APPS_HMR_REQUEST = \"sanity:workbench:get-local-applications\";\n\n/**\n * Creates a Module Federation instance, loads a remote workbench\n * application, and renders it into the provided root element.\n *\n * @param rootElement - The DOM element to render into\n * @param config - Workbench configuration (reserved for future use)\n * @param options - Rendering options forwarded to the remote\n * @returns A cleanup function that unmounts the remote application\n *\n * @public\n */\nexport async function renderWorkbench(\n rootElement: HTMLElement,\n config?: Config,\n options?: RenderWorkbenchOptions,\n) {\n if (!rootElement) {\n throw new Error(\"Missing root element to mount application into\");\n }\n\n const remoteUrl =\n import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL ??\n \"https://workbench-remote.sanity.dev/mf-manifest.json\";\n\n const mf = createInstance({\n name: \"sanity-workbench\",\n plugins: [log(logger.debug)],\n\n remotes: [\n {\n name: REMOTE_NAME,\n entry: remoteUrl,\n },\n ],\n });\n\n let remoteModule = await mf.loadRemote<WorkbenchRemoteModule>(\n `${REMOTE_NAME}/${REMOTE_MODULE}`,\n );\n\n if (!remoteModule || typeof remoteModule.render !== \"function\") {\n throw new Error(\n `Remote module \"${REMOTE_NAME}/${REMOTE_MODULE}\" did not expose a render function`,\n );\n }\n\n let localApplications = undefined;\n let cleanupHmr = () => {};\n\n if (import.meta.hot) {\n const localApps$ = new BehaviorSubject<LocalUserApplication[]>([]);\n\n const handler = (payload: { applications: LocalUserApplication[] }) => {\n localApps$.next(payload.applications);\n };\n\n import.meta.hot.on(LOCAL_APPS_HMR_EVENT, handler);\n import.meta.hot.send(LOCAL_APPS_HMR_REQUEST);\n\n localApplications = localApps$;\n\n cleanupHmr = () => import.meta.hot?.off(LOCAL_APPS_HMR_EVENT, handler);\n }\n\n const unmount = remoteModule.render(\n rootElement,\n { config, localApplications },\n options,\n );\n\n return () => {\n cleanupHmr();\n unmount();\n };\n}\n","declare const __SANITY_STAGING__: boolean | undefined;\n\n/**\n * Returns the API host based on the `__SANITY_STAGING__` build-time flag.\n * If the flag is set to `true`, the staging API host is returned.\n * Otherwise, the production API host is returned.\n *\n * @internal\n */\nexport function getApiHost(): string | undefined {\n if (getSanityEnv() === \"staging\") {\n return \"https://api.sanity.work\";\n }\n return \"https://api.sanity.io\";\n}\n\n/**\n * Returns the current Sanity environment based on the `__SANITY_STAGING__` build-time flag.\n * If the flag is set to `true`, \"staging\" is returned.\n * Otherwise, \"production\" is returned.\n *\n * @internal\n */\nexport function getSanityEnv(): \"staging\" | \"production\" {\n if (\n typeof __SANITY_STAGING__ !== \"undefined\" &&\n __SANITY_STAGING__ === true\n ) {\n return \"staging\";\n }\n return \"production\";\n}\n"],"names":[],"mappings":";;;;AA4CA,MAAM,cAAc,oBACd,gBAAgB,OAEhB,uBAAuB,uCACvB,yBAAyB;AAa/B,eAAsB,gBACpB,aACA,QACA,SACA;AACA,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,gDAAgD;AAGlE,QAAM,YACJ,YAAY,IAAI,wCAChB;AAcF,MAAI,eAAe,MAZR,eAAe;AAAA,IACxB,MAAM;AAAA,IACN,SAAS,CAAC,IAAI,OAAO,KAAK,CAAC;AAAA,IAE3B,SAAS;AAAA,MACP;AAAA,QACE,MAAM;AAAA,QACN,OAAO;AAAA,MAAA;AAAA,IACT;AAAA,EACF,CACD,EAE2B;AAAA,IAC1B,GAAG,WAAW,IAAI,aAAa;AAAA,EAAA;AAGjC,MAAI,CAAC,gBAAgB,OAAO,aAAa,UAAW;AAClD,UAAM,IAAI;AAAA,MACR,kBAAkB,WAAW,IAAI,aAAa;AAAA,IAAA;AAIlD,MAAI,mBACA,aAAa,MAAM;AAAA,EAAC;AAExB,MAAI,YAAY,KAAK;AACnB,UAAM,aAAa,IAAI,gBAAwC,CAAA,CAAE,GAE3D,UAAU,CAAC,YAAsD;AACrE,iBAAW,KAAK,QAAQ,YAAY;AAAA,IACtC;AAEA,gBAAY,IAAI,GAAG,sBAAsB,OAAO,GAChD,YAAY,IAAI,KAAK,sBAAsB,GAE3C,oBAAoB,YAEpB,aAAa,MAAM,YAAY,KAAK,IAAI,sBAAsB,OAAO;AAAA,EACvE;AAEA,QAAM,UAAU,aAAa;AAAA,IAC3B;AAAA,IACA,EAAE,QAAQ,kBAAA;AAAA,IACV;AAAA,EAAA;AAGF,SAAO,MAAM;AACX,eAAA,GACA,QAAA;AAAA,EACF;AACF;ACnHO,SAAS,aAAiC;AAC/C,SAAI,aAAA,MAAmB,YACd,4BAEF;AACT;AASO,SAAS,eAAyC;AACvD,SACE,OAAO,qBAAuB,OAC9B,uBAAuB,KAEhB,YAEF;AACT;"}
|