@sanity/workbench 0.1.0-alpha.1 → 0.1.0-alpha.2
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/_internal.d.ts +4 -0
- package/dist/_internal.js +1 -1
- package/dist/_internal.js.map +1 -1
- package/package.json +3 -4
- package/src/_exports/_internal.ts +1 -0
- package/src/_internal/render.test.ts +18 -0
- package/src/_internal/render.ts +17 -3
- package/dist/_internal.cjs +0 -38
- package/dist/_internal.cjs.map +0 -1
- package/dist/_internal.d.cts +0 -30
- package/src/env.d.ts +0 -7
package/dist/_internal.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Workbench configuration.
|
|
3
|
+
*
|
|
2
4
|
* @public
|
|
3
5
|
*/
|
|
4
6
|
export declare type Config = undefined;
|
|
@@ -21,6 +23,8 @@ export declare function renderWorkbench(
|
|
|
21
23
|
): Promise<() => void>;
|
|
22
24
|
|
|
23
25
|
/**
|
|
26
|
+
* Options for rendering the workbench.
|
|
27
|
+
*
|
|
24
28
|
* @public
|
|
25
29
|
*/
|
|
26
30
|
export declare interface RenderWorkbenchOptions {
|
package/dist/_internal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createInstance } from "@sanity/federation/runtime";
|
|
2
|
-
const REMOTE_NAME = "workbench-remote", REMOTE_MODULE = "
|
|
2
|
+
const REMOTE_NAME = "workbench-remote", REMOTE_MODULE = "App";
|
|
3
3
|
async function renderWorkbench(rootElement, config, options) {
|
|
4
4
|
if (!rootElement)
|
|
5
5
|
throw new Error("Missing root element to mount application into");
|
package/dist/_internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_internal.js","sources":["../src/_internal/render.ts"],"sourcesContent":["import { createInstance } from \"@sanity/federation/runtime\";\n\
|
|
1
|
+
{"version":3,"file":"_internal.js","sources":["../src/_internal/render.ts"],"sourcesContent":["import { createInstance } from \"@sanity/federation/runtime\";\n\n/**\n * Workbench configuration.\n *\n * @public\n */\nexport type Config = undefined;\n\n/**\n * Options for rendering the workbench.\n *\n * @public\n */\nexport interface RenderWorkbenchOptions {\n reactStrictMode?: boolean;\n}\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\nconst REMOTE_NAME = \"workbench-remote\";\nconst REMOTE_MODULE = \"App\";\n\ninterface RemoteModule {\n render(\n rootElement: HTMLElement,\n config?: Config,\n options?: RenderWorkbenchOptions,\n ): () => void;\n}\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): Promise<() => void> {\n if (!rootElement) {\n throw new Error(\"Missing root element to mount application into\");\n }\n\n const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL;\n\n if (!remoteUrl) {\n throw new Error(\"SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set\");\n }\n\n const mf = createInstance({\n name: \"sanity-workbench\",\n });\n\n mf.registerRemotes([\n {\n name: REMOTE_NAME,\n entry: remoteUrl,\n },\n ]);\n\n let remoteModule: RemoteModule | null;\n try {\n remoteModule = await mf.loadRemote<RemoteModule>(\n `${REMOTE_NAME}/${REMOTE_MODULE}`,\n );\n } catch (error) {\n throw new Error(\n `Failed to load remote workbench module from \"${remoteUrl}\"`,\n { cause: error },\n );\n }\n\n if (!remoteModule || typeof remoteModule.render !== \"function\") {\n throw new Error(\n `Remote module from \"${remoteUrl}\" did not expose a render function`,\n );\n }\n\n return remoteModule.render(rootElement, config, options);\n}\n"],"names":[],"mappings":";AA2BA,MAAM,cAAc,oBACd,gBAAgB;AAqBtB,eAAsB,gBACpB,aACA,QACA,SACqB;AACrB,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,gDAAgD;AAGlE,QAAM,YAAY,YAAY,IAAI;AAElC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAGnE,QAAM,KAAK,eAAe;AAAA,IACxB,MAAM;AAAA,EAAA,CACP;AAED,KAAG,gBAAgB;AAAA,IACjB;AAAA,MACE,MAAM;AAAA,MACN,OAAO;AAAA,IAAA;AAAA,EACT,CACD;AAED,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,GAAG;AAAA,MACtB,GAAG,WAAW,IAAI,aAAa;AAAA,IAAA;AAAA,EAEnC,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gDAAgD,SAAS;AAAA,MACzD,EAAE,OAAO,MAAA;AAAA,IAAM;AAAA,EAEnB;AAEA,MAAI,CAAC,gBAAgB,OAAO,aAAa,UAAW;AAClD,UAAM,IAAI;AAAA,MACR,uBAAuB,SAAS;AAAA,IAAA;AAIpC,SAAO,aAAa,OAAO,aAAa,QAAQ,OAAO;AACzD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/workbench",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "Workbench component for the Sanity Content Operating System",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/sanity-io/workbench/packages/@sanity/workbench#readme",
|
|
@@ -21,14 +21,13 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"exports": {
|
|
23
23
|
"./_internal": {
|
|
24
|
-
"source": "./src/_internal
|
|
25
|
-
"require": "./dist/_internal.cjs",
|
|
24
|
+
"source": "./src/_exports/_internal.ts",
|
|
26
25
|
"default": "./dist/_internal.js"
|
|
27
26
|
},
|
|
28
27
|
"./package.json": "./package.json"
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
31
|
-
"@sanity/federation": "0.1.0-alpha.
|
|
30
|
+
"@sanity/federation": "0.1.0-alpha.2"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@sanity/pkg-utils": "^9.2.3",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../_internal";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { renderWorkbench } from "./render";
|
|
4
|
+
|
|
5
|
+
describe("renderWorkbench", () => {
|
|
6
|
+
it("throws when rootElement is missing", async () => {
|
|
7
|
+
await expect(
|
|
8
|
+
renderWorkbench(null as unknown as HTMLElement),
|
|
9
|
+
).rejects.toThrow("Missing root element to mount application into");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("throws when SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set", async () => {
|
|
13
|
+
const el = document.createElement("div");
|
|
14
|
+
await expect(renderWorkbench(el)).rejects.toThrow(
|
|
15
|
+
"SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set",
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
});
|
package/src/_internal/render.ts
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { createInstance } from "@sanity/federation/runtime";
|
|
2
2
|
|
|
3
|
-
const REMOTE_NAME = "workbench-remote";
|
|
4
|
-
const REMOTE_MODULE = "./App";
|
|
5
|
-
|
|
6
3
|
/**
|
|
4
|
+
* Workbench configuration.
|
|
5
|
+
*
|
|
7
6
|
* @public
|
|
8
7
|
*/
|
|
9
8
|
export type Config = undefined;
|
|
10
9
|
|
|
11
10
|
/**
|
|
11
|
+
* Options for rendering the workbench.
|
|
12
|
+
*
|
|
12
13
|
* @public
|
|
13
14
|
*/
|
|
14
15
|
export interface RenderWorkbenchOptions {
|
|
15
16
|
reactStrictMode?: boolean;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
declare global {
|
|
20
|
+
interface ImportMetaEnv {
|
|
21
|
+
readonly SANITY_INTERNAL_WORKBENCH_REMOTE_URL: string;
|
|
22
|
+
}
|
|
23
|
+
interface ImportMeta {
|
|
24
|
+
readonly env: ImportMetaEnv;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const REMOTE_NAME = "workbench-remote";
|
|
29
|
+
const REMOTE_MODULE = "App";
|
|
30
|
+
|
|
18
31
|
interface RemoteModule {
|
|
19
32
|
render(
|
|
20
33
|
rootElement: HTMLElement,
|
|
@@ -44,6 +57,7 @@ export async function renderWorkbench(
|
|
|
44
57
|
}
|
|
45
58
|
|
|
46
59
|
const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL;
|
|
60
|
+
|
|
47
61
|
if (!remoteUrl) {
|
|
48
62
|
throw new Error("SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set");
|
|
49
63
|
}
|
package/dist/_internal.cjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var runtime = require("@sanity/federation/runtime");
|
|
4
|
-
const REMOTE_NAME = "workbench-remote", REMOTE_MODULE = "./App";
|
|
5
|
-
async function renderWorkbench(rootElement, config, options) {
|
|
6
|
-
if (!rootElement)
|
|
7
|
-
throw new Error("Missing root element to mount application into");
|
|
8
|
-
const remoteUrl = (void 0).SANITY_INTERNAL_WORKBENCH_REMOTE_URL;
|
|
9
|
-
if (!remoteUrl)
|
|
10
|
-
throw new Error("SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set");
|
|
11
|
-
const mf = runtime.createInstance({
|
|
12
|
-
name: "sanity-workbench"
|
|
13
|
-
});
|
|
14
|
-
mf.registerRemotes([
|
|
15
|
-
{
|
|
16
|
-
name: REMOTE_NAME,
|
|
17
|
-
entry: remoteUrl
|
|
18
|
-
}
|
|
19
|
-
]);
|
|
20
|
-
let remoteModule;
|
|
21
|
-
try {
|
|
22
|
-
remoteModule = await mf.loadRemote(
|
|
23
|
-
`${REMOTE_NAME}/${REMOTE_MODULE}`
|
|
24
|
-
);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Failed to load remote workbench module from "${remoteUrl}"`,
|
|
28
|
-
{ cause: error }
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
if (!remoteModule || typeof remoteModule.render != "function")
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Remote module from "${remoteUrl}" did not expose a render function`
|
|
34
|
-
);
|
|
35
|
-
return remoteModule.render(rootElement, config, options);
|
|
36
|
-
}
|
|
37
|
-
exports.renderWorkbench = renderWorkbench;
|
|
38
|
-
//# sourceMappingURL=_internal.cjs.map
|
package/dist/_internal.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_internal.cjs","sources":["../src/_internal/render.ts"],"sourcesContent":["import { createInstance } from \"@sanity/federation/runtime\";\n\nconst REMOTE_NAME = \"workbench-remote\";\nconst REMOTE_MODULE = \"./App\";\n\n/**\n * @public\n */\nexport type Config = undefined;\n\n/**\n * @public\n */\nexport interface RenderWorkbenchOptions {\n reactStrictMode?: boolean;\n}\n\ninterface RemoteModule {\n render(\n rootElement: HTMLElement,\n config?: Config,\n options?: RenderWorkbenchOptions,\n ): () => void;\n}\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): Promise<() => void> {\n if (!rootElement) {\n throw new Error(\"Missing root element to mount application into\");\n }\n\n const remoteUrl = import.meta.env.SANITY_INTERNAL_WORKBENCH_REMOTE_URL;\n if (!remoteUrl) {\n throw new Error(\"SANITY_INTERNAL_WORKBENCH_REMOTE_URL is not set\");\n }\n\n const mf = createInstance({\n name: \"sanity-workbench\",\n });\n\n mf.registerRemotes([\n {\n name: REMOTE_NAME,\n entry: remoteUrl,\n },\n ]);\n\n let remoteModule: RemoteModule | null;\n try {\n remoteModule = await mf.loadRemote<RemoteModule>(\n `${REMOTE_NAME}/${REMOTE_MODULE}`,\n );\n } catch (error) {\n throw new Error(\n `Failed to load remote workbench module from \"${remoteUrl}\"`,\n { cause: error },\n );\n }\n\n if (!remoteModule || typeof remoteModule.render !== \"function\") {\n throw new Error(\n `Remote module from \"${remoteUrl}\" did not expose a render function`,\n );\n }\n\n return remoteModule.render(rootElement, config, options);\n}\n"],"names":["createInstance"],"mappings":";;;AAEA,MAAM,cAAc,oBACd,gBAAgB;AAiCtB,eAAsB,gBACpB,aACA,QACA,SACqB;AACrB,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,gDAAgD;AAGlE,QAAM,YAAY,SAAgB;AAClC,MAAI,CAAC;AACH,UAAM,IAAI,MAAM,iDAAiD;AAGnE,QAAM,KAAKA,QAAAA,eAAe;AAAA,IACxB,MAAM;AAAA,EAAA,CACP;AAED,KAAG,gBAAgB;AAAA,IACjB;AAAA,MACE,MAAM;AAAA,MACN,OAAO;AAAA,IAAA;AAAA,EACT,CACD;AAED,MAAI;AACJ,MAAI;AACF,mBAAe,MAAM,GAAG;AAAA,MACtB,GAAG,WAAW,IAAI,aAAa;AAAA,IAAA;AAAA,EAEnC,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,gDAAgD,SAAS;AAAA,MACzD,EAAE,OAAO,MAAA;AAAA,IAAM;AAAA,EAEnB;AAEA,MAAI,CAAC,gBAAgB,OAAO,aAAa,UAAW;AAClD,UAAM,IAAI;AAAA,MACR,uBAAuB,SAAS;AAAA,IAAA;AAIpC,SAAO,aAAa,OAAO,aAAa,QAAQ,OAAO;AACzD;;"}
|
package/dist/_internal.d.cts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @public
|
|
3
|
-
*/
|
|
4
|
-
export declare type Config = undefined;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a Module Federation instance, loads a remote workbench
|
|
8
|
-
* application, and renders it into the provided root element.
|
|
9
|
-
*
|
|
10
|
-
* @param rootElement - The DOM element to render into
|
|
11
|
-
* @param config - Workbench configuration (reserved for future use)
|
|
12
|
-
* @param options - Rendering options forwarded to the remote
|
|
13
|
-
* @returns A cleanup function that unmounts the remote application
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export declare function renderWorkbench(
|
|
18
|
-
rootElement: HTMLElement,
|
|
19
|
-
config?: Config,
|
|
20
|
-
options?: RenderWorkbenchOptions,
|
|
21
|
-
): Promise<() => void>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export declare interface RenderWorkbenchOptions {
|
|
27
|
-
reactStrictMode?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {};
|