@sanity/workbench 0.1.0-alpha.7 → 0.1.0-alpha.8
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/_chunks-es/index.js +6 -1
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_internal.js +3 -8
- package/dist/_internal.js.map +1 -1
- package/dist/core.d.ts +582 -24
- package/dist/core.js +207 -105
- package/dist/core.js.map +1 -1
- package/package.json +3 -1
- package/src/_internal/render.test.ts +46 -14
- package/src/_internal/render.ts +4 -11
- package/src/core/__tests__/__fixtures__.ts +8 -11
- package/src/core/applications/application-list.test.ts +1 -1
- package/src/core/applications/application-list.ts +1 -1
- package/src/core/applications/local-application.test.ts +3 -3
- package/src/core/applications/local-application.ts +6 -2
- package/src/core/canvases.ts +1 -1
- package/src/core/index.ts +1 -1
- package/src/core/log/index.ts +12 -0
- package/src/core/media-libraries.ts +1 -1
- package/src/core/user-applications/core-app.test.ts +110 -25
- package/src/core/user-applications/core-app.ts +66 -10
- package/src/core/user-applications/studios/index.ts +3 -0
- package/src/core/user-applications/studios/schemas.test.ts +113 -0
- package/src/core/user-applications/studios/schemas.ts +106 -0
- package/src/core/user-applications/{studio.test.ts → studios/studio.test.ts} +106 -37
- package/src/core/user-applications/{studio.ts → studios/studio.ts} +56 -214
- package/src/core/user-applications/studios/workspace.ts +143 -0
- package/src/core/user-applications/user-application.test.ts +7 -8
- package/src/core/user-applications/user-application.ts +36 -5
package/dist/_chunks-es/index.js
CHANGED
|
@@ -23,7 +23,12 @@ function createLogger({
|
|
|
23
23
|
debug: (message, context) => logAtLevel("debug", message, context)
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
const logger = createLogger({
|
|
27
|
+
namespace: "sanity-workbench",
|
|
28
|
+
logLevel: "debug"
|
|
29
|
+
});
|
|
26
30
|
export {
|
|
27
|
-
createLogger
|
|
31
|
+
createLogger,
|
|
32
|
+
logger
|
|
28
33
|
};
|
|
29
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +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"],"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;"}
|
|
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;"}
|
package/dist/_internal.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { createInstance } from "@sanity/federation/runtime";
|
|
2
2
|
import { log } from "@sanity/federation/runtime/plugins/log";
|
|
3
3
|
import { BehaviorSubject } from "rxjs";
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
namespace: "sanity-workbench",
|
|
7
|
-
logLevel: "debug"
|
|
8
|
-
}), REMOTE_NAME = "workbench-remote", REMOTE_MODULE = "App", LOCAL_APPS_HMR_EVENT = "sanity:workbench:local-applications", LOCAL_APPS_HMR_REQUEST = "sanity:workbench:get-local-applications";
|
|
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";
|
|
9
6
|
async function renderWorkbench(rootElement, config, options) {
|
|
10
7
|
if (!rootElement)
|
|
11
8
|
throw new Error("Missing root element to mount application into");
|
|
12
|
-
const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL;
|
|
13
|
-
if (!remoteUrl)
|
|
14
|
-
throw new Error("SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set");
|
|
9
|
+
const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL ?? "https://workbench-remote.sanity.dev/mf-manifest.json";
|
|
15
10
|
let remoteModule = await createInstance({
|
|
16
11
|
name: "sanity-workbench",
|
|
17
12
|
plugins: [log(logger.debug)],
|
package/dist/_internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_internal.js","sources":["../src/_internal/render.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 { LocalApplicationData } from \"../core/applications/local-application\";\nimport type { Config, RemoteModuleRenderOptions } from \"../core/config\";\nimport {
|
|
1
|
+
{"version":3,"file":"_internal.js","sources":["../src/_internal/render.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 { LocalApplicationData } from \"../core/applications/local-application\";\nimport type { Config, RemoteModuleRenderOptions } from \"../core/config\";\nimport { logger } from \"../core/log\";\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<LocalApplicationData[]>;\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<LocalApplicationData[]>([]);\n\n const handler = (payload: { applications: LocalApplicationData[] }) => {\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"],"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;"}
|