@stonecrop/stonecrop 0.50.1 → 0.51.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/dist/stonecrop.d.ts +18 -7
- package/dist/stonecrop.js +24 -8
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
package/dist/stonecrop.d.ts
CHANGED
|
@@ -432,7 +432,11 @@ export declare class Doctype {
|
|
|
432
432
|
* Returns the transitions available from a given workflow state, derived from the
|
|
433
433
|
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
434
434
|
*
|
|
435
|
-
*
|
|
435
|
+
* A record not created yet is in no state: given `null`, only the actions that can run on it
|
|
436
|
+
* are listed (`isActionAllowedOnNewRecord`), and since none of them moves it, each has a
|
|
437
|
+
* `targetState` of `''`.
|
|
438
|
+
*
|
|
439
|
+
* @param currentState - The state name to read transitions from, or `null` for a record not created yet
|
|
436
440
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
437
441
|
*
|
|
438
442
|
* @example
|
|
@@ -443,7 +447,7 @@ export declare class Doctype {
|
|
|
443
447
|
*
|
|
444
448
|
* @public
|
|
445
449
|
*/
|
|
446
|
-
getAvailableTransitions(currentState: string): Array<{
|
|
450
|
+
getAvailableTransitions(currentState: string | null): Array<{
|
|
447
451
|
name: string;
|
|
448
452
|
targetState: string;
|
|
449
453
|
}>;
|
|
@@ -455,7 +459,9 @@ export declare class Doctype {
|
|
|
455
459
|
*
|
|
456
460
|
* Only meaningful for WorkflowMeta format; XState workflows have no Commands.
|
|
457
461
|
*
|
|
458
|
-
* @param currentState - The record's current state, used to honor a Command's `allowedStates
|
|
462
|
+
* @param currentState - The record's current state, used to honor a Command's `allowedStates`,
|
|
463
|
+
* or `null` for a record not created yet, which lists the Commands that can run on one
|
|
464
|
+
* (`isActionAllowedOnNewRecord`)
|
|
459
465
|
* @returns Array of command descriptors with `name`
|
|
460
466
|
*
|
|
461
467
|
* @example
|
|
@@ -466,7 +472,7 @@ export declare class Doctype {
|
|
|
466
472
|
*
|
|
467
473
|
* @public
|
|
468
474
|
*/
|
|
469
|
-
getAvailableCommands(currentState?: string): Array<{
|
|
475
|
+
getAvailableCommands(currentState?: string | null): Array<{
|
|
470
476
|
name: string;
|
|
471
477
|
}>;
|
|
472
478
|
/**
|
|
@@ -2214,16 +2220,21 @@ export declare class Stonecrop {
|
|
|
2214
2220
|
* Determine the current workflow state for a record.
|
|
2215
2221
|
*
|
|
2216
2222
|
* Reads the record's `status` field from the HST store. If the field is absent or
|
|
2217
|
-
* empty the
|
|
2223
|
+
* empty the workflow's first listed state (an XState workflow's `initial`) is used as the fallback,
|
|
2218
2224
|
* giving callers a reliable state name without having to duplicate that logic.
|
|
2219
2225
|
*
|
|
2226
|
+
* A record not created yet ({@link DRAFT_RECORD_ID}) is in no state, as the server guard
|
|
2227
|
+
* treats it: pass the `null` returned to `Doctype.getAvailableTransitions` and
|
|
2228
|
+
* `Doctype.getAvailableCommands` to list the actions that can run on it.
|
|
2229
|
+
*
|
|
2220
2230
|
* @param doctype - The doctype slug or Doctype instance
|
|
2221
2231
|
* @param recordId - The record identifier
|
|
2222
|
-
* @returns The current state name, or an empty string if
|
|
2232
|
+
* @returns The current state name, `null` for a record not created yet, or an empty string if
|
|
2233
|
+
* the doctype has no workflow
|
|
2223
2234
|
*
|
|
2224
2235
|
* @public
|
|
2225
2236
|
*/
|
|
2226
|
-
getRecordState(doctype: string | Doctype, recordId: string): string;
|
|
2237
|
+
getRecordState(doctype: string | Doctype, recordId: string): string | null;
|
|
2227
2238
|
/**
|
|
2228
2239
|
* Collect a record payload with all nested doctype fields from HST
|
|
2229
2240
|
* @param doctype - The doctype metadata
|
package/dist/stonecrop.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useRouter } from "vue-router";
|
|
|
2
2
|
import { defineStore, storeToRefs } from "pinia";
|
|
3
3
|
import { computed, getCurrentInstance, inject, nextTick, onMounted, provide, reactive, ref, watch } from "vue";
|
|
4
4
|
import { useLocalStorage, useMagicKeys, whenever } from "@vueuse/core";
|
|
5
|
-
import { componentCategory, componentLinkExpansion, flattenFields, getRecordIdField, getRecordIdentity, isActionAllowedInState, normalizeFieldKind, resolveLinkRenderMode, toSlug } from "@stonecrop/schema";
|
|
5
|
+
import { componentCategory, componentLinkExpansion, flattenFields, getRecordIdField, getRecordIdentity, isActionAllowedInState, isActionAllowedOnNewRecord, normalizeFieldKind, resolveLinkRenderMode, toSlug } from "@stonecrop/schema";
|
|
6
6
|
import { List } from "immutable";
|
|
7
7
|
import { resolvedFieldsToColumns } from "@stonecrop/aform";
|
|
8
8
|
//#region src/client-handler.ts
|
|
@@ -1735,12 +1735,17 @@ var Stonecrop = class Stonecrop {
|
|
|
1735
1735
|
* Determine the current workflow state for a record.
|
|
1736
1736
|
*
|
|
1737
1737
|
* Reads the record's `status` field from the HST store. If the field is absent or
|
|
1738
|
-
* empty the
|
|
1738
|
+
* empty the workflow's first listed state (an XState workflow's `initial`) is used as the fallback,
|
|
1739
1739
|
* giving callers a reliable state name without having to duplicate that logic.
|
|
1740
1740
|
*
|
|
1741
|
+
* A record not created yet ({@link DRAFT_RECORD_ID}) is in no state, as the server guard
|
|
1742
|
+
* treats it: pass the `null` returned to `Doctype.getAvailableTransitions` and
|
|
1743
|
+
* `Doctype.getAvailableCommands` to list the actions that can run on it.
|
|
1744
|
+
*
|
|
1741
1745
|
* @param doctype - The doctype slug or Doctype instance
|
|
1742
1746
|
* @param recordId - The record identifier
|
|
1743
|
-
* @returns The current state name, or an empty string if
|
|
1747
|
+
* @returns The current state name, `null` for a record not created yet, or an empty string if
|
|
1748
|
+
* the doctype has no workflow
|
|
1744
1749
|
*
|
|
1745
1750
|
* @public
|
|
1746
1751
|
*/
|
|
@@ -1748,6 +1753,7 @@ var Stonecrop = class Stonecrop {
|
|
|
1748
1753
|
const slug = typeof doctype === "string" ? doctype : doctype.slug;
|
|
1749
1754
|
const meta = this.registry.getDoctype(slug);
|
|
1750
1755
|
if (!meta?.workflow) return "";
|
|
1756
|
+
if (isDraftRecordId(recordId)) return null;
|
|
1751
1757
|
const status = this.getRecordById(slug, recordId)?.get("status");
|
|
1752
1758
|
const workflow = meta.workflow;
|
|
1753
1759
|
let initialState;
|
|
@@ -2800,7 +2806,11 @@ var Doctype = class Doctype {
|
|
|
2800
2806
|
* Returns the transitions available from a given workflow state, derived from the
|
|
2801
2807
|
* doctype's workflow configuration. Supports both XState format and WorkflowMeta format.
|
|
2802
2808
|
*
|
|
2803
|
-
*
|
|
2809
|
+
* A record not created yet is in no state: given `null`, only the actions that can run on it
|
|
2810
|
+
* are listed (`isActionAllowedOnNewRecord`), and since none of them moves it, each has a
|
|
2811
|
+
* `targetState` of `''`.
|
|
2812
|
+
*
|
|
2813
|
+
* @param currentState - The state name to read transitions from, or `null` for a record not created yet
|
|
2804
2814
|
* @returns Array of transition descriptors with `name` and `targetState`
|
|
2805
2815
|
*
|
|
2806
2816
|
* @example
|
|
@@ -2815,16 +2825,20 @@ var Doctype = class Doctype {
|
|
|
2815
2825
|
const workflow = this.workflow;
|
|
2816
2826
|
if (!workflow) return [];
|
|
2817
2827
|
if (Array.isArray(workflow.states)) {
|
|
2818
|
-
if (!workflow.states.includes(currentState)) return [];
|
|
2819
2828
|
const actions = workflow.actions;
|
|
2820
2829
|
if (!actions) return [];
|
|
2830
|
+
if (currentState === null) return Object.entries(actions).filter(([, actionDef]) => !actionDef.stateless && isActionAllowedOnNewRecord(actionDef)).map(([name]) => ({
|
|
2831
|
+
name,
|
|
2832
|
+
targetState: ""
|
|
2833
|
+
}));
|
|
2834
|
+
if (!workflow.states.includes(currentState)) return [];
|
|
2821
2835
|
return Object.entries(actions).filter(([, actionDef]) => !actionDef.stateless && isActionAllowedInState(actionDef, currentState)).map(([name, actionDef]) => ({
|
|
2822
2836
|
name,
|
|
2823
2837
|
targetState: actionDef.nextState ?? currentState
|
|
2824
2838
|
}));
|
|
2825
2839
|
}
|
|
2826
2840
|
const states = workflow.states;
|
|
2827
|
-
if (!states) return [];
|
|
2841
|
+
if (!states || currentState === null) return [];
|
|
2828
2842
|
const stateConfig = states[currentState];
|
|
2829
2843
|
if (!stateConfig?.on) return [];
|
|
2830
2844
|
return Object.entries(stateConfig.on).map(([name, target]) => ({
|
|
@@ -2840,7 +2854,9 @@ var Doctype = class Doctype {
|
|
|
2840
2854
|
*
|
|
2841
2855
|
* Only meaningful for WorkflowMeta format; XState workflows have no Commands.
|
|
2842
2856
|
*
|
|
2843
|
-
* @param currentState - The record's current state, used to honor a Command's `allowedStates
|
|
2857
|
+
* @param currentState - The record's current state, used to honor a Command's `allowedStates`,
|
|
2858
|
+
* or `null` for a record not created yet, which lists the Commands that can run on one
|
|
2859
|
+
* (`isActionAllowedOnNewRecord`)
|
|
2844
2860
|
* @returns Array of command descriptors with `name`
|
|
2845
2861
|
*
|
|
2846
2862
|
* @example
|
|
@@ -2856,7 +2872,7 @@ var Doctype = class Doctype {
|
|
|
2856
2872
|
if (!workflow) return [];
|
|
2857
2873
|
const actions = workflow.actions;
|
|
2858
2874
|
if (!actions) return [];
|
|
2859
|
-
return Object.entries(actions).filter(([, actionDef]) => actionDef.stateless === true && isActionAllowedInState(actionDef, currentState ?? "")).map(([name]) => ({ name }));
|
|
2875
|
+
return Object.entries(actions).filter(([, actionDef]) => actionDef.stateless === true && (currentState === null ? isActionAllowedOnNewRecord(actionDef) : isActionAllowedInState(actionDef, currentState ?? ""))).map(([name]) => ({ name }));
|
|
2860
2876
|
}
|
|
2861
2877
|
/**
|
|
2862
2878
|
* Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
|