@stonecrop/stonecrop 0.55.2 → 0.56.1
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 +16 -3
- package/dist/stonecrop.js +37 -7
- package/dist/stonecrop.js.map +1 -1
- package/package.json +4 -4
package/dist/stonecrop.d.ts
CHANGED
|
@@ -55,7 +55,8 @@ export declare type ActionEventPayload = {
|
|
|
55
55
|
/** The declared action name (e.g. 'SAVE', 'SUBMIT', 'APPROVE') */
|
|
56
56
|
name: string;
|
|
57
57
|
doctype: string;
|
|
58
|
-
|
|
58
|
+
/** Absent for an action raised on a list, which has no record. */
|
|
59
|
+
recordId?: string;
|
|
59
60
|
/** Snapshot of the form data at the time the action was triggered */
|
|
60
61
|
data: Record<string, any>;
|
|
61
62
|
};
|
|
@@ -91,8 +92,8 @@ export declare interface ActionFailure {
|
|
|
91
92
|
action: string;
|
|
92
93
|
/** Slug of the doctype the action was raised on. */
|
|
93
94
|
doctype: string;
|
|
94
|
-
/** Record the action was raised against; the `new` route segment for an unsaved record. */
|
|
95
|
-
recordId
|
|
95
|
+
/** Record the action was raised against; the `new` route segment for an unsaved record; absent on a list. */
|
|
96
|
+
recordId?: string;
|
|
96
97
|
/** The thrown value, present only when the failure was a throw rather than a refused dispatch. */
|
|
97
98
|
cause?: unknown;
|
|
98
99
|
}
|
|
@@ -480,6 +481,18 @@ export declare class Doctype {
|
|
|
480
481
|
getAvailableCommands(currentState?: string | null): Array<{
|
|
481
482
|
name: string;
|
|
482
483
|
}>;
|
|
484
|
+
/**
|
|
485
|
+
* Returns every action this doctype's workflow declares, in declaration order, whatever its kind
|
|
486
|
+
* or state. A list shows these, since a list has no record whose state could narrow them. An
|
|
487
|
+
* XState workflow declares none.
|
|
488
|
+
*
|
|
489
|
+
* @returns Array of action descriptors with `name`
|
|
490
|
+
*
|
|
491
|
+
* @public
|
|
492
|
+
*/
|
|
493
|
+
getActions(): Array<{
|
|
494
|
+
name: string;
|
|
495
|
+
}>;
|
|
483
496
|
/**
|
|
484
497
|
* Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
|
|
485
498
|
* client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
|
package/dist/stonecrop.js
CHANGED
|
@@ -2315,7 +2315,8 @@ function useClientAction(options = {}) {
|
|
|
2315
2315
|
}
|
|
2316
2316
|
/**
|
|
2317
2317
|
* Handle a Desktop `@action` event: run the action's `clientHandler` if present,
|
|
2318
|
-
* else dispatch to the server handler.
|
|
2318
|
+
* else dispatch to the server handler. An action raised with no record, as a list's is,
|
|
2319
|
+
* runs only through its `clientHandler`.
|
|
2319
2320
|
*/
|
|
2320
2321
|
async function run(payload) {
|
|
2321
2322
|
const sc = stonecrop.value;
|
|
@@ -2323,6 +2324,28 @@ function useClientAction(options = {}) {
|
|
|
2323
2324
|
const { name, doctype: doctypeSlug, recordId, data } = payload;
|
|
2324
2325
|
const clientHandler = (sc.registry.getDoctype(doctypeSlug)?.workflow)?.actions?.[name]?.clientHandler;
|
|
2325
2326
|
try {
|
|
2327
|
+
const graphql = { query(query, variables) {
|
|
2328
|
+
const client = sc.getClient();
|
|
2329
|
+
if (!client?.query) return Promise.reject(/* @__PURE__ */ new Error("The configured data client does not support graphql.query"));
|
|
2330
|
+
return client.query(query, variables);
|
|
2331
|
+
} };
|
|
2332
|
+
const prefillDraft = (target, values) => sc.registry.prefillDraft(target, values);
|
|
2333
|
+
if (recordId === void 0) {
|
|
2334
|
+
if (!clientHandler) {
|
|
2335
|
+
onError({
|
|
2336
|
+
message: `Action "${name}" has no script, so it cannot run on a list.`,
|
|
2337
|
+
action: name,
|
|
2338
|
+
doctype: doctypeSlug
|
|
2339
|
+
});
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
await executeClientHandler(clientHandler, {
|
|
2343
|
+
router: resolveRouter(),
|
|
2344
|
+
graphql,
|
|
2345
|
+
prefillDraft
|
|
2346
|
+
});
|
|
2347
|
+
return;
|
|
2348
|
+
}
|
|
2326
2349
|
if (!clientHandler) {
|
|
2327
2350
|
const result = await dispatchAndWriteback(doctypeSlug, recordId, data, name);
|
|
2328
2351
|
if (!result.success) onError({
|
|
@@ -2335,12 +2358,6 @@ function useClientAction(options = {}) {
|
|
|
2335
2358
|
}
|
|
2336
2359
|
const record = sc.getRecordById(doctypeSlug, recordId)?.get("") ?? data;
|
|
2337
2360
|
const runAction = (action, extra) => dispatchAndWriteback(doctypeSlug, recordId, data, action, extra);
|
|
2338
|
-
const graphql = { query(query, variables) {
|
|
2339
|
-
const client = sc.getClient();
|
|
2340
|
-
if (!client?.query) return Promise.reject(/* @__PURE__ */ new Error("The configured data client does not support graphql.query"));
|
|
2341
|
-
return client.query(query, variables);
|
|
2342
|
-
} };
|
|
2343
|
-
const prefillDraft = (target, values) => sc.registry.prefillDraft(target, values);
|
|
2344
2361
|
await executeClientHandler(clientHandler, {
|
|
2345
2362
|
router: resolveRouter(),
|
|
2346
2363
|
record,
|
|
@@ -2904,6 +2921,19 @@ var Doctype = class Doctype {
|
|
|
2904
2921
|
return Object.entries(actions).filter(([, actionDef]) => actionDef.stateless === true && (currentState === null ? isActionAllowedOnNewRecord(actionDef) : isActionAllowedInState(actionDef, currentState ?? ""))).map(([name]) => ({ name }));
|
|
2905
2922
|
}
|
|
2906
2923
|
/**
|
|
2924
|
+
* Returns every action this doctype's workflow declares, in declaration order, whatever its kind
|
|
2925
|
+
* or state. A list shows these, since a list has no record whose state could narrow them. An
|
|
2926
|
+
* XState workflow declares none.
|
|
2927
|
+
*
|
|
2928
|
+
* @returns Array of action descriptors with `name`
|
|
2929
|
+
*
|
|
2930
|
+
* @public
|
|
2931
|
+
*/
|
|
2932
|
+
getActions() {
|
|
2933
|
+
const actions = this.workflow?.actions;
|
|
2934
|
+
return Object.keys(actions ?? {}).map((name) => ({ name }));
|
|
2935
|
+
}
|
|
2936
|
+
/**
|
|
2907
2937
|
* Returns the field-validation **triggers** declared on this doctype's workflow (advisory,
|
|
2908
2938
|
* client-side). Keyed by trigger name. Returns undefined when the workflow is absent, is an
|
|
2909
2939
|
* XState machine (no triggers), or simply declares none.
|