@sanity/workflow-studio 0.1.0
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/index.cjs +37 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sanity, Inc.
|
|
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.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var workflowReact = require("@sanity/workflow-react"), react = require("react"), sanity = require("sanity"), workflowEngine = require("@sanity/workflow-engine");
|
|
4
|
+
function makeStudioObserver(documentStore) {
|
|
5
|
+
const docStore = (id, type, release) => {
|
|
6
|
+
const observable = documentStore.pair.editState(id, type, release);
|
|
7
|
+
let latest;
|
|
8
|
+
return {
|
|
9
|
+
subscribe(onChange) {
|
|
10
|
+
const subscription = observable.subscribe((editState) => {
|
|
11
|
+
latest = resolveEditState(editState), onChange();
|
|
12
|
+
});
|
|
13
|
+
return () => subscription.unsubscribe();
|
|
14
|
+
},
|
|
15
|
+
getSnapshot: () => latest
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
observeInstance: (instanceId) => docStore(instanceId, "workflow.instance", void 0),
|
|
20
|
+
observeDocs: (documents, perspective) => workflowReact.combineDocStores(
|
|
21
|
+
documents.map((ref) => ({
|
|
22
|
+
key: ref.globalDocumentId,
|
|
23
|
+
store: docStore(ref.documentId, ref.type, workflowEngine.contentReleaseName({ ref, perspective }))
|
|
24
|
+
}))
|
|
25
|
+
)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function resolveEditState(editState) {
|
|
29
|
+
if (editState.ready)
|
|
30
|
+
return editState.version ?? editState.draft ?? editState.published;
|
|
31
|
+
}
|
|
32
|
+
function useWorkflowInstance(engine, instanceId, opts) {
|
|
33
|
+
const documentStore = sanity.useDocumentStore(), observer = react.useMemo(() => makeStudioObserver(documentStore), [documentStore]);
|
|
34
|
+
return workflowReact.useWorkflowSession(engine, instanceId, observer, opts);
|
|
35
|
+
}
|
|
36
|
+
exports.useWorkflowInstance = useWorkflowInstance;
|
|
37
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/studio-observer.ts","../src/use-workflow-instance.tsx"],"sourcesContent":["import {contentReleaseName} from '@sanity/workflow-engine'\nimport {\n combineDocStores,\n type DocStore,\n type ObservedDoc,\n type WorkflowObserver,\n} from '@sanity/workflow-react'\nimport type {DocumentStore, EditStateFor} from 'sanity'\n\n/**\n * A {@link WorkflowObserver} backed by Studio's optimistic document store\n * (`documentStore.pair.editState` — a replayed RxJS observable, so a fresh\n * subscriber gets the current value synchronously). Content docs resolve under\n * the perspective's release via the `editState` version arg; instance /\n * ancestor / `system.release` docs read raw. The fan-out/snapshot machinery\n * lives in {@link combineDocStores}.\n */\nexport function makeStudioObserver(documentStore: DocumentStore): WorkflowObserver {\n const docStore = (\n id: string,\n type: string,\n release: string | undefined,\n ): DocStore<ObservedDoc> => {\n const observable = documentStore.pair.editState(id, type, release)\n let latest: ObservedDoc\n return {\n subscribe(onChange) {\n const subscription = observable.subscribe((editState) => {\n latest = resolveEditState(editState)\n onChange()\n })\n return () => subscription.unsubscribe()\n },\n getSnapshot: () => latest,\n }\n }\n return {\n observeInstance: (instanceId) => docStore(instanceId, 'workflow.instance', undefined),\n observeDocs: (documents, perspective) =>\n combineDocStores(\n documents.map((ref) => ({\n key: ref.globalDocumentId,\n store: docStore(ref.documentId, ref.type, contentReleaseName({ref, perspective})),\n })),\n ),\n }\n}\n\n/**\n * Resolve an `editState` emission to a single observed value: `undefined` while\n * not ready (gates the session feed), otherwise the version / draft / published\n * doc in precedence order (`null` when the doc doesn't exist).\n */\nfunction resolveEditState(editState: EditStateFor): ObservedDoc {\n if (!editState.ready) return undefined\n return (editState.version ?? editState.draft ?? editState.published) as ObservedDoc\n}\n","import type {Engine, WorkflowAccessOverride} from '@sanity/workflow-engine'\nimport {useWorkflowSession, type WorkflowInstanceController} from '@sanity/workflow-react'\nimport {useMemo} from 'react'\nimport {useDocumentStore} from 'sanity'\n\nimport {makeStudioObserver} from './studio-observer.ts'\n\n/**\n * Drive a workflow instance reactively from the Studio document store: observes\n * the instance and its watch-set through `documentStore.pair.editState` and\n * feeds the engine's session. Returns `{evaluation, ready, tick, fireAction}`;\n * the consumer decides when to advance. Must render inside Studio source context\n * (so `useDocumentStore` resolves).\n */\nexport function useWorkflowInstance(\n engine: Engine,\n instanceId: string,\n opts?: {access?: WorkflowAccessOverride; grantsFromPath?: string},\n): WorkflowInstanceController {\n const documentStore = useDocumentStore()\n const observer = useMemo(() => makeStudioObserver(documentStore), [documentStore])\n return useWorkflowSession(engine, instanceId, observer, opts)\n}\n"],"names":["combineDocStores","contentReleaseName","useDocumentStore","useMemo","useWorkflowSession"],"mappings":";;;AAiBO,SAAS,mBAAmB,eAAgD;AACjF,QAAM,WAAW,CACf,IACA,MACA,YAC0B;AAC1B,UAAM,aAAa,cAAc,KAAK,UAAU,IAAI,MAAM,OAAO;AACjE,QAAI;AACJ,WAAO;AAAA,MACL,UAAU,UAAU;AAClB,cAAM,eAAe,WAAW,UAAU,CAAC,cAAc;AACvD,mBAAS,iBAAiB,SAAS,GACnC,SAAA;AAAA,QACF,CAAC;AACD,eAAO,MAAM,aAAa,YAAA;AAAA,MAC5B;AAAA,MACA,aAAa,MAAM;AAAA,IAAA;AAAA,EAEvB;AACA,SAAO;AAAA,IACL,iBAAiB,CAAC,eAAe,SAAS,YAAY,qBAAqB,MAAS;AAAA,IACpF,aAAa,CAAC,WAAW,gBACvBA,cAAAA;AAAAA,MACE,UAAU,IAAI,CAAC,SAAS;AAAA,QACtB,KAAK,IAAI;AAAA,QACT,OAAO,SAAS,IAAI,YAAY,IAAI,MAAMC,kCAAmB,EAAC,KAAK,aAAY,CAAC;AAAA,MAAA,EAChF;AAAA,IAAA;AAAA,EACJ;AAEN;AAOA,SAAS,iBAAiB,WAAsC;AAC9D,MAAK,UAAU;AACf,WAAQ,UAAU,WAAW,UAAU,SAAS,UAAU;AAC5D;AC1CO,SAAS,oBACd,QACA,YACA,MAC4B;AAC5B,QAAM,gBAAgBC,wBAAA,GAChB,WAAWC,MAAAA,QAAQ,MAAM,mBAAmB,aAAa,GAAG,CAAC,aAAa,CAAC;AACjF,SAAOC,cAAAA,mBAAmB,QAAQ,YAAY,UAAU,IAAI;AAC9D;;"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Engine } from "@sanity/workflow-engine";
|
|
2
|
+
import type { WorkflowAccessOverride } from "@sanity/workflow-engine";
|
|
3
|
+
import { WorkflowInstanceController } from "@sanity/workflow-react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Drive a workflow instance reactively from the Studio document store: observes
|
|
7
|
+
* the instance and its watch-set through `documentStore.pair.editState` and
|
|
8
|
+
* feeds the engine's session. Returns `{evaluation, ready, tick, fireAction}`;
|
|
9
|
+
* the consumer decides when to advance. Must render inside Studio source context
|
|
10
|
+
* (so `useDocumentStore` resolves).
|
|
11
|
+
*/
|
|
12
|
+
export declare function useWorkflowInstance(
|
|
13
|
+
engine: Engine,
|
|
14
|
+
instanceId: string,
|
|
15
|
+
opts?: {
|
|
16
|
+
access?: WorkflowAccessOverride;
|
|
17
|
+
grantsFromPath?: string;
|
|
18
|
+
},
|
|
19
|
+
): WorkflowInstanceController;
|
|
20
|
+
|
|
21
|
+
export { WorkflowInstanceController };
|
|
22
|
+
|
|
23
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Engine } from "@sanity/workflow-engine";
|
|
2
|
+
import type { WorkflowAccessOverride } from "@sanity/workflow-engine";
|
|
3
|
+
import { WorkflowInstanceController } from "@sanity/workflow-react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Drive a workflow instance reactively from the Studio document store: observes
|
|
7
|
+
* the instance and its watch-set through `documentStore.pair.editState` and
|
|
8
|
+
* feeds the engine's session. Returns `{evaluation, ready, tick, fireAction}`;
|
|
9
|
+
* the consumer decides when to advance. Must render inside Studio source context
|
|
10
|
+
* (so `useDocumentStore` resolves).
|
|
11
|
+
*/
|
|
12
|
+
export declare function useWorkflowInstance(
|
|
13
|
+
engine: Engine,
|
|
14
|
+
instanceId: string,
|
|
15
|
+
opts?: {
|
|
16
|
+
access?: WorkflowAccessOverride;
|
|
17
|
+
grantsFromPath?: string;
|
|
18
|
+
},
|
|
19
|
+
): WorkflowInstanceController;
|
|
20
|
+
|
|
21
|
+
export { WorkflowInstanceController };
|
|
22
|
+
|
|
23
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { combineDocStores, useWorkflowSession } from "@sanity/workflow-react";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { useDocumentStore } from "sanity";
|
|
4
|
+
import { contentReleaseName } from "@sanity/workflow-engine";
|
|
5
|
+
function makeStudioObserver(documentStore) {
|
|
6
|
+
const docStore = (id, type, release) => {
|
|
7
|
+
const observable = documentStore.pair.editState(id, type, release);
|
|
8
|
+
let latest;
|
|
9
|
+
return {
|
|
10
|
+
subscribe(onChange) {
|
|
11
|
+
const subscription = observable.subscribe((editState) => {
|
|
12
|
+
latest = resolveEditState(editState), onChange();
|
|
13
|
+
});
|
|
14
|
+
return () => subscription.unsubscribe();
|
|
15
|
+
},
|
|
16
|
+
getSnapshot: () => latest
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
observeInstance: (instanceId) => docStore(instanceId, "workflow.instance", void 0),
|
|
21
|
+
observeDocs: (documents, perspective) => combineDocStores(
|
|
22
|
+
documents.map((ref) => ({
|
|
23
|
+
key: ref.globalDocumentId,
|
|
24
|
+
store: docStore(ref.documentId, ref.type, contentReleaseName({ ref, perspective }))
|
|
25
|
+
}))
|
|
26
|
+
)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function resolveEditState(editState) {
|
|
30
|
+
if (editState.ready)
|
|
31
|
+
return editState.version ?? editState.draft ?? editState.published;
|
|
32
|
+
}
|
|
33
|
+
function useWorkflowInstance(engine, instanceId, opts) {
|
|
34
|
+
const documentStore = useDocumentStore(), observer = useMemo(() => makeStudioObserver(documentStore), [documentStore]);
|
|
35
|
+
return useWorkflowSession(engine, instanceId, observer, opts);
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
useWorkflowInstance
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/studio-observer.ts","../src/use-workflow-instance.tsx"],"sourcesContent":["import {contentReleaseName} from '@sanity/workflow-engine'\nimport {\n combineDocStores,\n type DocStore,\n type ObservedDoc,\n type WorkflowObserver,\n} from '@sanity/workflow-react'\nimport type {DocumentStore, EditStateFor} from 'sanity'\n\n/**\n * A {@link WorkflowObserver} backed by Studio's optimistic document store\n * (`documentStore.pair.editState` — a replayed RxJS observable, so a fresh\n * subscriber gets the current value synchronously). Content docs resolve under\n * the perspective's release via the `editState` version arg; instance /\n * ancestor / `system.release` docs read raw. The fan-out/snapshot machinery\n * lives in {@link combineDocStores}.\n */\nexport function makeStudioObserver(documentStore: DocumentStore): WorkflowObserver {\n const docStore = (\n id: string,\n type: string,\n release: string | undefined,\n ): DocStore<ObservedDoc> => {\n const observable = documentStore.pair.editState(id, type, release)\n let latest: ObservedDoc\n return {\n subscribe(onChange) {\n const subscription = observable.subscribe((editState) => {\n latest = resolveEditState(editState)\n onChange()\n })\n return () => subscription.unsubscribe()\n },\n getSnapshot: () => latest,\n }\n }\n return {\n observeInstance: (instanceId) => docStore(instanceId, 'workflow.instance', undefined),\n observeDocs: (documents, perspective) =>\n combineDocStores(\n documents.map((ref) => ({\n key: ref.globalDocumentId,\n store: docStore(ref.documentId, ref.type, contentReleaseName({ref, perspective})),\n })),\n ),\n }\n}\n\n/**\n * Resolve an `editState` emission to a single observed value: `undefined` while\n * not ready (gates the session feed), otherwise the version / draft / published\n * doc in precedence order (`null` when the doc doesn't exist).\n */\nfunction resolveEditState(editState: EditStateFor): ObservedDoc {\n if (!editState.ready) return undefined\n return (editState.version ?? editState.draft ?? editState.published) as ObservedDoc\n}\n","import type {Engine, WorkflowAccessOverride} from '@sanity/workflow-engine'\nimport {useWorkflowSession, type WorkflowInstanceController} from '@sanity/workflow-react'\nimport {useMemo} from 'react'\nimport {useDocumentStore} from 'sanity'\n\nimport {makeStudioObserver} from './studio-observer.ts'\n\n/**\n * Drive a workflow instance reactively from the Studio document store: observes\n * the instance and its watch-set through `documentStore.pair.editState` and\n * feeds the engine's session. Returns `{evaluation, ready, tick, fireAction}`;\n * the consumer decides when to advance. Must render inside Studio source context\n * (so `useDocumentStore` resolves).\n */\nexport function useWorkflowInstance(\n engine: Engine,\n instanceId: string,\n opts?: {access?: WorkflowAccessOverride; grantsFromPath?: string},\n): WorkflowInstanceController {\n const documentStore = useDocumentStore()\n const observer = useMemo(() => makeStudioObserver(documentStore), [documentStore])\n return useWorkflowSession(engine, instanceId, observer, opts)\n}\n"],"names":[],"mappings":";;;;AAiBO,SAAS,mBAAmB,eAAgD;AACjF,QAAM,WAAW,CACf,IACA,MACA,YAC0B;AAC1B,UAAM,aAAa,cAAc,KAAK,UAAU,IAAI,MAAM,OAAO;AACjE,QAAI;AACJ,WAAO;AAAA,MACL,UAAU,UAAU;AAClB,cAAM,eAAe,WAAW,UAAU,CAAC,cAAc;AACvD,mBAAS,iBAAiB,SAAS,GACnC,SAAA;AAAA,QACF,CAAC;AACD,eAAO,MAAM,aAAa,YAAA;AAAA,MAC5B;AAAA,MACA,aAAa,MAAM;AAAA,IAAA;AAAA,EAEvB;AACA,SAAO;AAAA,IACL,iBAAiB,CAAC,eAAe,SAAS,YAAY,qBAAqB,MAAS;AAAA,IACpF,aAAa,CAAC,WAAW,gBACvB;AAAA,MACE,UAAU,IAAI,CAAC,SAAS;AAAA,QACtB,KAAK,IAAI;AAAA,QACT,OAAO,SAAS,IAAI,YAAY,IAAI,MAAM,mBAAmB,EAAC,KAAK,aAAY,CAAC;AAAA,MAAA,EAChF;AAAA,IAAA;AAAA,EACJ;AAEN;AAOA,SAAS,iBAAiB,WAAsC;AAC9D,MAAK,UAAU;AACf,WAAQ,UAAU,WAAW,UAAU,SAAS,UAAU;AAC5D;AC1CO,SAAS,oBACd,QACA,YACA,MAC4B;AAC5B,QAAM,gBAAgB,iBAAA,GAChB,WAAW,QAAQ,MAAM,mBAAmB,aAAa,GAAG,CAAC,aAAa,CAAC;AACjF,SAAO,mBAAmB,QAAQ,YAAY,UAAU,IAAI;AAC9D;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanity/workflow-studio",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React adapter that drives the @sanity/workflow-engine reactive session from the Sanity Studio document store.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sanity",
|
|
7
|
+
"sanity-io",
|
|
8
|
+
"studio",
|
|
9
|
+
"workflow",
|
|
10
|
+
"workflows"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/sanity-io/workflows/tree/main/packages/workflow-studio#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/sanity-io/workflows/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/sanity-io/workflows.git",
|
|
21
|
+
"directory": "packages/workflow-studio"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"require": "./dist/index.cjs",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "restricted"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@sanity/workflow-react": "0.1.0",
|
|
44
|
+
"@sanity/workflow-engine": "0.2.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@sanity/pkg-utils": "^10.5.2",
|
|
48
|
+
"@types/react": "^19.2.17",
|
|
49
|
+
"react": "^19.2.7",
|
|
50
|
+
"sanity": "^5.30.0",
|
|
51
|
+
"vitest": "^4.1.8"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": "^19.2.7",
|
|
55
|
+
"sanity": "^5.30.0"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=20"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "pkg-utils build --clean",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:watch": "vitest",
|
|
64
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
65
|
+
}
|
|
66
|
+
}
|