@sanity/workflow-studio-plugin 0.5.0 → 0.20.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.
@@ -2,22 +2,6 @@
2
2
 
3
3
  var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), react = require("react"), router = require("sanity/router"), index = require("./index.cjs"), ArrowLeft = require("@sanity/icons/ArrowLeft"), workflowDiagram = require("@sanity/workflow-diagram"), workflowEngine = require("@sanity/workflow-engine"), Add = require("@sanity/icons/Add"), Search = require("@sanity/icons/Search"), Checkmark = require("@sanity/icons/Checkmark"), Close = require("@sanity/icons/Close"), Filter = require("@sanity/icons/Filter"), workflowComponents = require("@sanity/workflow-components"), endOfDay = require("date-fns/endOfDay"), reactDom = require("react-dom"), sanity = require("sanity"), Calendar = require("@sanity/icons/Calendar"), workflowStudio = require("@sanity/workflow-studio");
4
4
 
5
- function SpinnerSlot({busy: busy}) {
6
- /* @__PURE__ */
7
- return jsxRuntime.jsx(ui.Flex, {
8
- align: "center",
9
- flex: "none",
10
- justify: "center",
11
- style: {
12
- width: 19,
13
- height: 19
14
- },
15
- children: busy ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {
16
- muted: !0
17
- }) : null
18
- });
19
- }
20
-
21
5
  function documentRefsOf(instance) {
22
6
  const seen = /* @__PURE__ */ new Map;
23
7
  for (const ref of workflowEngine.entryDocRefs(instance.fields)) seen.has(ref.id) || seen.set(ref.id, ref);
@@ -181,7 +165,7 @@ function DetailHeader({entry: entry, definition: definition, onBack: onBack}) {
181
165
  }) : /* @__PURE__ */ jsxRuntime.jsx(index.AbortedBadge, {
182
166
  instance: instance
183
167
  }),
184
- /* @__PURE__ */ jsxRuntime.jsx(SpinnerSlot, {
168
+ /* @__PURE__ */ jsxRuntime.jsx(index.SpinnerSlot, {
185
169
  busy: !ready || index.isEvaluationStale(entry)
186
170
  }) ]
187
171
  })
@@ -404,7 +388,7 @@ function datesOf(state) {
404
388
 
405
389
  function spawnOrigins(instances) {
406
390
  const origins = /* @__PURE__ */ new Map;
407
- for (const parent of instances) for (const row of parent.subworkflows ?? []) origins.set(workflowEngine.extractDocumentId(row.ref.id), {
391
+ for (const parent of instances) for (const row of parent.subworkflows ?? []) origins.set(workflowEngine.toBareId(row.ref.id), {
408
392
  parent: parent,
409
393
  activityName: row.activity,
410
394
  cohortStage: row.cohortStage
@@ -414,7 +398,7 @@ function spawnOrigins(instances) {
414
398
 
415
399
  function rootOf(instance, byId) {
416
400
  const rootRef = instance.ancestors[0];
417
- return rootRef ? byId.get(workflowEngine.extractDocumentId(rootRef.id)) ?? instance : instance;
401
+ return rootRef ? byId.get(workflowEngine.toBareId(rootRef.id)) ?? instance : instance;
418
402
  }
419
403
 
420
404
  function taskRowsOf(args) {
@@ -1088,7 +1072,7 @@ function DocumentField({documents: documents, activeIds: activeIds, onToggle: on
1088
1072
  if (documents.length === 0) return null;
1089
1073
  const rows = documents.map(doc => ({
1090
1074
  key: doc.id,
1091
- text: `${titles.get(doc.id) ?? ""} ${doc.type} ${workflowEngine.extractDocumentId(doc.id)}`,
1075
+ text: `${titles.get(doc.id) ?? ""} ${doc.type} ${workflowEngine.toBareId(doc.id)}`,
1092
1076
  node: /* @__PURE__ */ jsxRuntime.jsx(index.DocRefFace, {
1093
1077
  gdr: doc
1094
1078
  })
@@ -1173,7 +1157,7 @@ function useDocumentChipLabels(documentIds, documents) {
1173
1157
  const schema = sanity.useSchema(), activeDocs = documents.filter(doc => documentIds.includes(doc.id)), {titles: titles, resolved: resolved} = useDocPreviewTitles(activeDocs), labels = /* @__PURE__ */ new Map;
1174
1158
  for (const doc of activeDocs) {
1175
1159
  if (!resolved.has(doc.id)) continue;
1176
- const label = titles.get(doc.id) ?? schemaTypeTitle(schema, doc.type) ?? workflowEngine.extractDocumentId(doc.id);
1160
+ const label = titles.get(doc.id) ?? schemaTypeTitle(schema, doc.type) ?? workflowEngine.toBareId(doc.id);
1177
1161
  labels.set(doc.id, label);
1178
1162
  }
1179
1163
  return labels;
@@ -1300,6 +1284,28 @@ function ActivityDateControl({instanceId: instanceId, state: state, dates: dates
1300
1284
  });
1301
1285
  }
1302
1286
 
1287
+ const PREWARM_MARGIN = "600px 0px";
1288
+
1289
+ function useNearViewport() {
1290
+ const [element, setElement] = react.useState(null), [near, setNear] = react.useState(!1);
1291
+ return react.useEffect(() => {
1292
+ if (element === null) return;
1293
+ if (typeof IntersectionObserver > "u") {
1294
+ setNear(!0);
1295
+ return;
1296
+ }
1297
+ const observer = new IntersectionObserver(entries => {
1298
+ setNear(entries.at(-1)?.isIntersecting ?? !1);
1299
+ }, {
1300
+ rootMargin: PREWARM_MARGIN
1301
+ });
1302
+ return observer.observe(element), () => observer.disconnect();
1303
+ }, [ element ]), {
1304
+ ref: setElement,
1305
+ near: near
1306
+ };
1307
+ }
1308
+
1303
1309
  function RefChips({refs: refs, max: max = 2}) {
1304
1310
  if (refs.length === 0) return null;
1305
1311
  const shown = refs.slice(0, max), overflow = refs.length - shown.length;
@@ -1329,7 +1335,7 @@ function TaskGroupList({groups: groups, onOpenTask: onOpenTask, onOpenWorkflow:
1329
1335
  children: [ groups.withDocuments.map(group => /* @__PURE__ */ jsxRuntime.jsx(index.CollapsibleBand, {
1330
1336
  background: !0,
1331
1337
  sticky: !0,
1332
- title: workflowEngine.extractDocumentId(group.document.id),
1338
+ title: workflowEngine.toBareId(group.document.id),
1333
1339
  header: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, {
1334
1340
  align: "center",
1335
1341
  flex: "none",
@@ -1452,22 +1458,27 @@ function TaskRows({rows: rows, onOpenTask: onOpenTask, showTerminalActions: show
1452
1458
  }
1453
1459
 
1454
1460
  function TaskActivityRow({row: row, onOpen: onOpen, showTerminalActions: showTerminalActions}) {
1455
- const entry = index.useWorkflowInstanceEntry(row.instanceId), render = taskRowRender(row, entry);
1461
+ const {ref: ref, near: near} = useNearViewport(), entry = index.useWorkflowInstanceEntry(row.instanceId, {
1462
+ evaluate: near
1463
+ }), render = taskRowRender(row, entry);
1456
1464
  /* @__PURE__ */
1457
- return jsxRuntime.jsx(index.StaleLock, {
1458
- stale: render.stale,
1459
- children: /* @__PURE__ */ jsxRuntime.jsx(index.ActivityRow, {
1460
- assignState: render.assignState,
1461
- assigneeIds: render.assigneeIds,
1462
- dateControl: /* @__PURE__ */ jsxRuntime.jsx(ActivityDateControl, {
1463
- dates: render.dates,
1465
+ return jsxRuntime.jsx(ui.Box, {
1466
+ ref: ref,
1467
+ children: /* @__PURE__ */ jsxRuntime.jsx(index.StaleLock, {
1468
+ stale: render.stale,
1469
+ children: /* @__PURE__ */ jsxRuntime.jsx(index.ActivityRow, {
1470
+ assignState: render.assignState,
1471
+ assigneeIds: render.assigneeIds,
1472
+ dateControl: /* @__PURE__ */ jsxRuntime.jsx(ActivityDateControl, {
1473
+ dates: render.dates,
1474
+ instanceId: row.instanceId,
1475
+ state: render.dateState
1476
+ }),
1477
+ face: render.face,
1464
1478
  instanceId: row.instanceId,
1465
- state: render.dateState
1466
- }),
1467
- face: render.face,
1468
- instanceId: row.instanceId,
1469
- onOpen: onOpen,
1470
- terminalActions: showTerminalActions ? render.terminalActions : []
1479
+ onOpen: onOpen,
1480
+ terminalActions: showTerminalActions ? render.terminalActions : []
1481
+ })
1471
1482
  })
1472
1483
  });
1473
1484
  }