@panneau/actions 5.0.0-alpha.1 → 5.0.0-alpha.10

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.
@@ -0,0 +1,21 @@
1
+ import type { ActionAdapter, ActionTarget } from './types.js';
2
+ /** What a dry run of an action told: how many items it would apply to, and skip. */
3
+ export interface ActionPreview {
4
+ succeeded: number;
5
+ skipped: number;
6
+ }
7
+ /**
8
+ * Whether the backend can say what an action would do before it runs: a `server` action with
9
+ * `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows
10
+ * their abilities.
11
+ */
12
+ export declare function canPreviewAction(target: ActionTarget): boolean;
13
+ /**
14
+ * Asks the backend what an action would do on a query selection, without running it (a dry run,
15
+ * `"dryRun": true` in the request), and resolves with the counts of its summary, or with `null`
16
+ * for an action that can't be previewed (`canPreviewAction()`).
17
+ */
18
+ export declare function previewAction(adapter: Pick<ActionAdapter, 'runAction'>, resource: string, target: ActionTarget, options?: {
19
+ signal?: AbortSignal;
20
+ }): Promise<ActionPreview | null>;
21
+ //# sourceMappingURL=preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAQ9D;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAC/B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,EACzC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GACvC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAc/B"}
@@ -0,0 +1,30 @@
1
+ //#region src/preview.ts
2
+ /**
3
+ * Whether the backend can say what an action would do before it runs: a `server` action with
4
+ * `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows
5
+ * their abilities.
6
+ */
7
+ function canPreviewAction(target) {
8
+ const { action, selection } = target;
9
+ return action.dryRun === true && action.kind === "server" && selection !== void 0 && "query" in selection;
10
+ }
11
+ /**
12
+ * Asks the backend what an action would do on a query selection, without running it (a dry run,
13
+ * `"dryRun": true` in the request), and resolves with the counts of its summary, or with `null`
14
+ * for an action that can't be previewed (`canPreviewAction()`).
15
+ */
16
+ async function previewAction(adapter, resource, target, options = {}) {
17
+ if (!canPreviewAction(target)) return null;
18
+ const summary = (await adapter.runAction(resource, target.action.id, {
19
+ selection: target.selection,
20
+ dryRun: true
21
+ }, options)).result?.summary;
22
+ return summary !== void 0 ? {
23
+ succeeded: summary.succeeded,
24
+ skipped: summary.skipped
25
+ } : null;
26
+ }
27
+ //#endregion
28
+ export { canPreviewAction, previewAction };
29
+
30
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","names":["ActionAdapter","ActionTarget","ActionPreview","succeeded","skipped","canPreviewAction","target","action","selection","dryRun","kind","undefined","previewAction","adapter","Pick","resource","options","signal","AbortSignal","Promise","response","runAction","id","summary","result"],"sources":["../src/preview.ts"],"sourcesContent":["import type { ActionAdapter, ActionTarget } from './types';\n\n/** What a dry run of an action told: how many items it would apply to, and skip. */\nexport interface ActionPreview {\n succeeded: number;\n skipped: number;\n}\n\n/**\n * Whether the backend can say what an action would do before it runs: a `server` action with\n * `dryRun`, on every item matching a query. Selected ids need no dry run, since the list knows\n * their abilities.\n */\nexport function canPreviewAction(target: ActionTarget): boolean {\n const { action, selection } = target;\n return (\n action.dryRun === true &&\n action.kind === 'server' &&\n selection !== undefined &&\n 'query' in selection\n );\n}\n\n/**\n * Asks the backend what an action would do on a query selection, without running it (a dry run,\n * `\"dryRun\": true` in the request), and resolves with the counts of its summary, or with `null`\n * for an action that can't be previewed (`canPreviewAction()`).\n */\nexport async function previewAction(\n adapter: Pick<ActionAdapter, 'runAction'>,\n resource: string,\n target: ActionTarget,\n options: { signal?: AbortSignal } = {},\n): Promise<ActionPreview | null> {\n if (!canPreviewAction(target)) {\n return null;\n }\n const response = await adapter.runAction(\n resource,\n target.action.id,\n { selection: target.selection, dryRun: true },\n options,\n );\n const summary = response.result?.summary;\n return summary !== undefined\n ? { succeeded: summary.succeeded, skipped: summary.skipped }\n : null;\n}\n"],"mappings":";;;;;;AAaA,SAAgBK,iBAAiBC,QAA+B;CAC5D,MAAM,EAAEC,QAAQC,cAAcF;CAC9B,OACIC,OAAOE,WAAW,QAClBF,OAAOG,SAAS,YAChBF,cAAcG,KAAAA,KACd,WAAWH;AAEnB;;;;;;AAOA,eAAsBI,cAClBC,SACAE,UACAT,QACAU,UAAoC,CAAC,GACR;CAC7B,IAAI,CAACX,iBAAiBC,MAAM,GACxB,OAAO;CAQX,MAAMiB,WAAUH,MANOP,QAAQQ,UAC3BN,UACAT,OAAOC,OAAOe,IACd;EAAEd,WAAWF,OAAOE;EAAWC,QAAQ;CAAK,GAC5CO,OACJ,EAAA,CACyBQ,QAAQD;CACjC,OAAOA,YAAYZ,KAAAA,IACb;EAAER,WAAWoB,QAAQpB;EAAWC,SAASmB,QAAQnB;CAAQ,IACzD;AACV"}
package/dist/request.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ActionRequest, ActionResult, RouteReference } from '@panneau/protocol';
2
- import type { ActionTarget } from './types';
2
+ import type { ActionTarget } from './types.js';
3
3
  /** The request of an action: its selection (none for the resource), and its parameter values. */
4
4
  export declare function buildActionRequest(target: ActionTarget, values?: Record<string, unknown>): ActionRequest;
5
5
  /** Where a `link` action goes: its `url` with `{id}` replaced, or its `route` with the item's id. */
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","names":[],"sources":["../src/request.ts"],"sourcesContent":["import type { ActionRequest, ActionResult, RouteReference } from '@panneau/protocol';\n\nimport type { ActionTarget } from './types';\n\n/** The request of an action: its selection (none for the resource), and its parameter values. */\nexport function buildActionRequest(\n target: ActionTarget,\n values: Record<string, unknown> = {},\n): ActionRequest {\n if (target.scope === 'item' && target.item !== undefined) {\n return { selection: { ids: [target.item.id] }, values };\n }\n if (target.scope === 'selection' && target.selection !== undefined) {\n return { selection: target.selection, values };\n }\n return { values };\n}\n\n/** Where a `link` action goes: its `url` with `{id}` replaced, or its `route` with the item's id. */\nexport function getLinkTarget(target: ActionTarget): string | RouteReference | null {\n const { action, item } = target;\n if (action.url !== undefined) {\n if (action.url.includes('{id}') && item === undefined) {\n return null;\n }\n return item !== undefined\n ? action.url.replaceAll('{id}', encodeURIComponent(item.id))\n : action.url;\n }\n if (action.route !== undefined) {\n return { route: action.route, params: item !== undefined ? { id: item.id } : {} };\n }\n return null;\n}\n\nconst FINISHED = new Set(['succeeded', 'partial', 'failed', 'cancelled']);\n\n/** Whether a run has finished, successfully or not. */\nexport function isFinished(status: string): boolean {\n return FINISHED.has(status);\n}\n\n/** The counts of a result, from its summary or, without one, from its per-item results. */\nexport function getResultCounts(result: ActionResult): {\n succeeded: number | null;\n failed: number;\n skipped: number;\n} {\n if (result.summary !== undefined) {\n return result.summary;\n }\n const results = result.results ?? [];\n return {\n succeeded: null,\n failed: results.filter((entry) => entry.status === 'failed').length,\n skipped: results.filter((entry) => entry.status === 'skipped').length,\n };\n}\n"],"mappings":";;AAKA,SAAgB,mBACZ,QACA,SAAkC,CAAC,GACtB;CACb,IAAI,OAAO,UAAU,UAAU,OAAO,SAAS,KAAA,GAC3C,OAAO;EAAE,WAAW,EAAE,KAAK,CAAC,OAAO,KAAK,EAAE,EAAE;EAAG;CAAO;CAE1D,IAAI,OAAO,UAAU,eAAe,OAAO,cAAc,KAAA,GACrD,OAAO;EAAE,WAAW,OAAO;EAAW;CAAO;CAEjD,OAAO,EAAE,OAAO;AACpB;;AAGA,SAAgB,cAAc,QAAsD;CAChF,MAAM,EAAE,QAAQ,SAAS;CACzB,IAAI,OAAO,QAAQ,KAAA,GAAW;EAC1B,IAAI,OAAO,IAAI,SAAS,MAAM,KAAK,SAAS,KAAA,GACxC,OAAO;EAEX,OAAO,SAAS,KAAA,IACV,OAAO,IAAI,WAAW,QAAQ,mBAAmB,KAAK,EAAE,CAAC,IACzD,OAAO;CACjB;CACA,IAAI,OAAO,UAAU,KAAA,GACjB,OAAO;EAAE,OAAO,OAAO;EAAO,QAAQ,SAAS,KAAA,IAAY,EAAE,IAAI,KAAK,GAAG,IAAI,CAAC;CAAE;CAEpF,OAAO;AACX;AAEA,IAAM,2BAAW,IAAI,IAAI;CAAC;CAAa;CAAW;CAAU;AAAW,CAAC;;AAGxE,SAAgB,WAAW,QAAyB;CAChD,OAAO,SAAS,IAAI,MAAM;AAC9B;;AAGA,SAAgB,gBAAgB,QAI9B;CACE,IAAI,OAAO,YAAY,KAAA,GACnB,OAAO,OAAO;CAElB,MAAM,UAAU,OAAO,WAAW,CAAA;CAClC,OAAO;EACH,WAAW;EACX,QAAQ,QAAQ,QAAQ,UAAU,MAAM,WAAW,QAAQ,CAAC,CAAC;EAC7D,SAAS,QAAQ,QAAQ,UAAU,MAAM,WAAW,SAAS,CAAC,CAAC;CACnE;AACJ"}
1
+ {"version":3,"file":"request.js","names":["ActionRequest","ActionResult","RouteReference","ActionTarget","buildActionRequest","target","values","Record","scope","item","undefined","selection","ids","id","getLinkTarget","action","url","includes","replaceAll","encodeURIComponent","route","params","FINISHED","Set","isFinished","status","has","getResultCounts","result","succeeded","failed","skipped","summary","results","filter","entry","length"],"sources":["../src/request.ts"],"sourcesContent":["import type { ActionRequest, ActionResult, RouteReference } from '@panneau/protocol';\n\nimport type { ActionTarget } from './types';\n\n/** The request of an action: its selection (none for the resource), and its parameter values. */\nexport function buildActionRequest(\n target: ActionTarget,\n values: Record<string, unknown> = {},\n): ActionRequest {\n if (target.scope === 'item' && target.item !== undefined) {\n return { selection: { ids: [target.item.id] }, values };\n }\n if (target.scope === 'selection' && target.selection !== undefined) {\n return { selection: target.selection, values };\n }\n return { values };\n}\n\n/** Where a `link` action goes: its `url` with `{id}` replaced, or its `route` with the item's id. */\nexport function getLinkTarget(target: ActionTarget): string | RouteReference | null {\n const { action, item } = target;\n if (action.url !== undefined) {\n if (action.url.includes('{id}') && item === undefined) {\n return null;\n }\n return item !== undefined\n ? action.url.replaceAll('{id}', encodeURIComponent(item.id))\n : action.url;\n }\n if (action.route !== undefined) {\n return { route: action.route, params: item !== undefined ? { id: item.id } : {} };\n }\n return null;\n}\n\nconst FINISHED = new Set(['succeeded', 'partial', 'failed', 'cancelled']);\n\n/** Whether a run has finished, successfully or not. */\nexport function isFinished(status: string): boolean {\n return FINISHED.has(status);\n}\n\n/** The counts of a result, from its summary or, without one, from its per-item results. */\nexport function getResultCounts(result: ActionResult): {\n succeeded: number | null;\n failed: number;\n skipped: number;\n} {\n if (result.summary !== undefined) {\n return result.summary;\n }\n const results = result.results ?? [];\n return {\n succeeded: null,\n failed: results.filter((entry) => entry.status === 'failed').length,\n skipped: results.filter((entry) => entry.status === 'skipped').length,\n };\n}\n"],"mappings":";;AAKA,SAAgBI,mBACZC,QACAC,SAAkC,CAAC,GACtB;CACb,IAAID,OAAOG,UAAU,UAAUH,OAAOI,SAASC,KAAAA,GAC3C,OAAO;EAAEC,WAAW,EAAEC,KAAK,CAACP,OAAOI,KAAKI,EAAE,EAAE;EAAGP;CAAO;CAE1D,IAAID,OAAOG,UAAU,eAAeH,OAAOM,cAAcD,KAAAA,GACrD,OAAO;EAAEC,WAAWN,OAAOM;EAAWL;CAAO;CAEjD,OAAO,EAAEA,OAAO;AACpB;;AAGA,SAAgBQ,cAAcT,QAAsD;CAChF,MAAM,EAAEU,QAAQN,SAASJ;CACzB,IAAIU,OAAOC,QAAQN,KAAAA,GAAW;EAC1B,IAAIK,OAAOC,IAAIC,SAAS,MAAM,KAAKR,SAASC,KAAAA,GACxC,OAAO;EAEX,OAAOD,SAASC,KAAAA,IACVK,OAAOC,IAAIE,WAAW,QAAQC,mBAAmBV,KAAKI,EAAE,CAAC,IACzDE,OAAOC;CACjB;CACA,IAAID,OAAOK,UAAUV,KAAAA,GACjB,OAAO;EAAEU,OAAOL,OAAOK;EAAOC,QAAQZ,SAASC,KAAAA,IAAY,EAAEG,IAAIJ,KAAKI,GAAG,IAAI,CAAC;CAAE;CAEpF,OAAO;AACX;AAEA,IAAMS,2BAAW,IAAIC,IAAI;CAAC;CAAa;CAAW;CAAU;AAAW,CAAC;;AAGxE,SAAgBC,WAAWC,QAAyB;CAChD,OAAOH,SAASI,IAAID,MAAM;AAC9B;;AAGA,SAAgBE,gBAAgBC,QAI9B;CACE,IAAIA,OAAOI,YAAYtB,KAAAA,GACnB,OAAOkB,OAAOI;CAElB,MAAMC,UAAUL,OAAOK,WAAW,CAAA;CAClC,OAAO;EACHJ,WAAW;EACXC,QAAQG,QAAQC,QAAQC,UAAUA,MAAMV,WAAW,QAAQ,CAAC,CAACW;EAC7DL,SAASE,QAAQC,QAAQC,UAAUA,MAAMV,WAAW,SAAS,CAAC,CAACW;CACnE;AACJ"}
@@ -1,4 +1,5 @@
1
- import type { ActionOutcome, ActionTarget, FollowedRun } from './types';
1
+ import { type ActionPreview } from './preview.js';
2
+ import type { ActionOutcome, ActionTarget, FollowedRun } from './types.js';
2
3
  /**
3
4
  * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a
4
5
  * list's `ListActionEvent`, so it is the `onAction` of a list:
@@ -12,6 +13,15 @@ import type { ActionOutcome, ActionTarget, FollowedRun } from './types';
12
13
  * user cancelled its parameters (a list then keeps its selection), and rejects when it failed.
13
14
  */
14
15
  export declare function useActionRunner(resource: string): (target: ActionTarget) => Promise<ActionOutcome | false>;
16
+ /**
17
+ * Asks the backend how many items of a query selection an action would skip, before the list
18
+ * confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:
19
+ *
20
+ * ```tsx
21
+ * <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />
22
+ * ```
23
+ */
24
+ export declare function useActionPreview(resource: string): (target: ActionTarget) => Promise<ActionPreview | null>;
15
25
  /** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */
16
26
  export declare function useActionRuns(): {
17
27
  runs: readonly FollowedRun[];
@@ -1 +1 @@
1
- {"version":3,"file":"useActionRunner.d.ts","sourceRoot":"","sources":["../src/useActionRunner.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAM1D;AAED,wFAAwF;AACxF,wBAAgB,aAAa,IAAI;IAC7B,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAMA"}
1
+ {"version":3,"file":"useActionRunner.d.ts","sourceRoot":"","sources":["../src/useActionRunner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAM1D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC5B,QAAQ,EAAE,MAAM,GACjB,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAMzD;AAED,wFAAwF;AACxF,wBAAgB,aAAa,IAAI;IAC7B,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IAC7B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAMA"}
@@ -1,4 +1,5 @@
1
1
  import { ActionRunnerContext } from "./context.js";
2
+ import { previewAction } from "./preview.js";
2
3
  import { use } from "react";
3
4
  //#region src/useActionRunner.ts
4
5
  /**
@@ -18,6 +19,19 @@ function useActionRunner(resource) {
18
19
  if (context === null) throw new Error("useActionRunner() must be used inside <ActionRunnerProvider>.");
19
20
  return (target) => context.run(resource, target);
20
21
  }
22
+ /**
23
+ * Asks the backend how many items of a query selection an action would skip, before the list
24
+ * confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:
25
+ *
26
+ * ```tsx
27
+ * <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />
28
+ * ```
29
+ */
30
+ function useActionPreview(resource) {
31
+ const context = use(ActionRunnerContext);
32
+ if (context === null) throw new Error("useActionPreview() must be used inside <ActionRunnerProvider>.");
33
+ return (target) => previewAction(context.adapter, resource, target);
34
+ }
21
35
  /** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */
22
36
  function useActionRuns() {
23
37
  const context = use(ActionRunnerContext);
@@ -29,6 +43,6 @@ function useActionRuns() {
29
43
  };
30
44
  }
31
45
  //#endregion
32
- export { useActionRunner, useActionRuns };
46
+ export { useActionPreview, useActionRunner, useActionRuns };
33
47
 
34
48
  //# sourceMappingURL=useActionRunner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useActionRunner.js","names":[],"sources":["../src/useActionRunner.ts"],"sourcesContent":["import { use } from 'react';\n\nimport { ActionRunnerContext } from './context';\nimport type { ActionOutcome, ActionTarget, FollowedRun } from './types';\n\n/**\n * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a\n * list's `ListActionEvent`, so it is the `onAction` of a list:\n *\n * ```tsx\n * const runAction = useActionRunner('pages');\n * <ListView list={list} items={items} actions={actions} onAction={runAction} />\n * ```\n *\n * It resolves once the action has run, has been queued or has navigated, with `false` when the\n * user cancelled its parameters (a list then keeps its selection), and rejects when it failed.\n */\nexport function useActionRunner(\n resource: string,\n): (target: ActionTarget) => Promise<ActionOutcome | false> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRunner() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => context.run(resource, target);\n}\n\n/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */\nexport function useActionRuns(): {\n runs: readonly FollowedRun[];\n cancel: (id: string) => Promise<void>;\n dismiss: (id: string) => void;\n} {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRuns() must be used inside <ActionRunnerProvider>.');\n }\n return { runs: context.runs, cancel: context.cancelRun, dismiss: context.dismissRun };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,SAAgB,gBACZ,UACwD;CACxD,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,+DAA+D;CAEnF,QAAQ,WAAW,QAAQ,IAAI,UAAU,MAAM;AACnD;;AAGA,SAAgB,gBAId;CACE,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,6DAA6D;CAEjF,OAAO;EAAE,MAAM,QAAQ;EAAM,QAAQ,QAAQ;EAAW,SAAS,QAAQ;CAAW;AACxF"}
1
+ {"version":3,"file":"useActionRunner.js","names":["use","ActionRunnerContext","ActionPreview","previewAction","ActionOutcome","ActionTarget","FollowedRun","useActionRunner","resource","target","Promise","context","Error","run","useActionPreview","adapter","useActionRuns","runs","cancel","id","dismiss","cancelRun","dismissRun"],"sources":["../src/useActionRunner.ts"],"sourcesContent":["import { use } from 'react';\n\nimport { ActionRunnerContext } from './context';\nimport { type ActionPreview, previewAction } from './preview';\nimport type { ActionOutcome, ActionTarget, FollowedRun } from './types';\n\n/**\n * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a\n * list's `ListActionEvent`, so it is the `onAction` of a list:\n *\n * ```tsx\n * const runAction = useActionRunner('pages');\n * <ListView list={list} items={items} actions={actions} onAction={runAction} />\n * ```\n *\n * It resolves once the action has run, has been queued or has navigated, with `false` when the\n * user cancelled its parameters (a list then keeps its selection), and rejects when it failed.\n */\nexport function useActionRunner(\n resource: string,\n): (target: ActionTarget) => Promise<ActionOutcome | false> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRunner() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => context.run(resource, target);\n}\n\n/**\n * Asks the backend how many items of a query selection an action would skip, before the list\n * confirms it (a dry run, for actions with `dryRun`). It is the `previewAction` of a list:\n *\n * ```tsx\n * <ListView onAction={useActionRunner('pages')} previewAction={useActionPreview('pages')} … />\n * ```\n */\nexport function useActionPreview(\n resource: string,\n): (target: ActionTarget) => Promise<ActionPreview | null> {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionPreview() must be used inside <ActionRunnerProvider>.');\n }\n return (target) => previewAction(context.adapter, resource, target);\n}\n\n/** The queued runs of the closest `ActionRunnerProvider`, to cancel or dismiss them. */\nexport function useActionRuns(): {\n runs: readonly FollowedRun[];\n cancel: (id: string) => Promise<void>;\n dismiss: (id: string) => void;\n} {\n const context = use(ActionRunnerContext);\n if (context === null) {\n throw new Error('useActionRuns() must be used inside <ActionRunnerProvider>.');\n }\n return { runs: context.runs, cancel: context.cancelRun, dismiss: context.dismissRun };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgBO,gBACZC,UACwD;CACxD,MAAMG,UAAUX,IAAIC,mBAAmB;CACvC,IAAIU,YAAY,MACZ,MAAM,IAAIC,MAAM,+DAA+D;CAEnF,QAAQH,WAAWE,QAAQE,IAAIL,UAAUC,MAAM;AACnD;;;;;;;;;AAUA,SAAgBK,iBACZN,UACuD;CACvD,MAAMG,UAAUX,IAAIC,mBAAmB;CACvC,IAAIU,YAAY,MACZ,MAAM,IAAIC,MAAM,gEAAgE;CAEpF,QAAQH,WAAWN,cAAcQ,QAAQI,SAASP,UAAUC,MAAM;AACtE;;AAGA,SAAgBO,gBAId;CACE,MAAML,UAAUX,IAAIC,mBAAmB;CACvC,IAAIU,YAAY,MACZ,MAAM,IAAIC,MAAM,6DAA6D;CAEjF,OAAO;EAAEK,MAAMN,QAAQM;EAAMC,QAAQP,QAAQU;EAAWD,SAAST,QAAQW;CAAW;AACxF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/actions",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.10",
4
4
  "description": "Runs the actions of lists and forms: parameters in a dialog, the action through a data adapter, its result, and queued runs.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,9 +24,9 @@
24
24
  "dist"
25
25
  ],
26
26
  "scripts": {
27
- "build": "vite build && tsc -p tsconfig.build.json",
27
+ "build": "vite build && node ../../scripts/declarations.js",
28
28
  "typecheck": "tsc --noEmit",
29
- "api": "tsc -p tsconfig.build.json && node ../../scripts/api-report.js"
29
+ "api": "node ../../scripts/declarations.js && node ../../scripts/api-report.js"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
@@ -37,15 +37,15 @@
37
37
  "react-intl": "^12.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@panneau/core": "5.0.0-alpha.1",
41
- "@panneau/data": "5.0.0-alpha.1",
42
- "@panneau/forms": "5.0.0-alpha.1",
43
- "@panneau/intl": "5.0.0-alpha.1",
44
- "@panneau/protocol": "5.0.0-alpha.1",
45
- "@panneau/ui": "5.0.0-alpha.1",
40
+ "@panneau/core": "5.0.0-alpha.10",
41
+ "@panneau/data": "5.0.0-alpha.10",
42
+ "@panneau/forms": "5.0.0-alpha.10",
43
+ "@panneau/intl": "5.0.0-alpha.10",
44
+ "@panneau/protocol": "5.0.0-alpha.10",
45
+ "@panneau/ui": "5.0.0-alpha.10",
46
46
  "lucide-react": "^1.57.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@panneau/lists": "5.0.0-alpha.1"
49
+ "@panneau/lists": "5.0.0-alpha.10"
50
50
  }
51
51
  }