@panneau/actions 5.0.0-alpha.6 → 5.0.0-alpha.8

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.
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { ActionResult, RouteReference } from '@panneau/protocol';
3
- import type { ActionAdapter, ActionDownload, ActionResultContext, ClientActionHandler } from './types';
3
+ import type { ActionAdapter, ActionDownload, ActionResultContext, ClientActionHandler } from './types.js';
4
4
  export interface ActionRunnerProviderProps {
5
5
  /** Runs the actions: a `DataAdapter`, or any object with its action methods. */
6
6
  adapter: ActionAdapter;
@@ -4,6 +4,7 @@ import { buildActionRequest, getLinkTarget, isFinished } from "./request.js";
4
4
  import { describeResult } from "./describe.js";
5
5
  import { ResultsDialog } from "./ResultsDialog.js";
6
6
  import { ActionRunnerContext } from "./context.js";
7
+ import { c } from "react/compiler-runtime";
7
8
  import { useEffect, useEffectEvent, useRef, useState } from "react";
8
9
  import { usePlugins } from "@panneau/core";
9
10
  import { usePanneauIntl, useToast } from "@panneau/ui";
@@ -30,214 +31,355 @@ function openDownload(download) {
30
31
  * redirects and opens downloads. Put it inside `PanneauRoot`, and above the router of an app, so
31
32
  * that runs are followed from page to page. `useActionRunner(resource)` runs an action.
32
33
  */
33
- function ActionRunnerProvider({ adapter, children, onResult, onNavigate = navigateTo, onDownload = openDownload, clientActions, pollInterval = 2e3, locales }) {
34
+ function ActionRunnerProvider(t0) {
35
+ const $ = c(61);
36
+ const { adapter, children, onResult, onNavigate: t1, onDownload: t2, clientActions, pollInterval: t3, locales } = t0;
37
+ const onNavigate = t1 === void 0 ? navigateTo : t1;
38
+ const onDownload = t2 === void 0 ? openDownload : t2;
39
+ const pollInterval = t3 === void 0 ? 2e3 : t3;
34
40
  const intl = usePanneauIntl();
35
41
  const toasts = useToast();
36
42
  const plugins = usePlugins();
37
43
  const [parameters, setParameters] = useState(null);
38
44
  const [client, setClient] = useState(null);
39
45
  const [details, setDetails] = useState(null);
40
- const [runs, setRuns] = useState([]);
41
- const notified = useRef(/* @__PURE__ */ new Set());
42
- const finish = async (resource, target, result) => {
43
- await onResult?.(result, {
44
- resource,
45
- target
46
- });
47
- const content = describeResult(result, target.action.label, intl);
48
- const hasDetails = (result.results ?? []).length > 0;
49
- const download = result.download ?? null;
50
- if (download !== null) onDownload(download);
51
- toasts.show({
52
- ...content,
53
- ...hasDetails ? { action: {
54
- label: intl.formatMessage(messages.details),
55
- onAction: () => setDetails({
56
- label: target.action.label,
57
- result
58
- })
59
- } } : download !== null ? { action: {
60
- label: intl.formatMessage(messages.download),
61
- onAction: () => onDownload(download)
62
- } } : {}
63
- });
64
- const redirect = result.redirect ?? null;
65
- if (redirect !== null) onNavigate(redirect);
66
- };
67
- const follow = (resource_0, target_0, run) => {
68
- setRuns((current) => [...current.filter((entry) => entry.run.id !== run.id), {
69
- run,
70
- resource: resource_0,
71
- target: target_0
72
- }]);
73
- toasts.show({
74
- title: intl.formatMessage(messages.queued, { action: target_0.action.label }),
75
- description: intl.formatMessage(messages.queuedDescription),
76
- tone: "info"
77
- });
78
- };
79
- const ended = async (entry_0) => {
80
- const { run: run_0, resource: resource_1, target: target_1 } = entry_0;
81
- if (notified.current.has(run_0.id)) return;
82
- notified.current.add(run_0.id);
83
- if (run_0.result !== void 0) await finish(resource_1, target_1, run_0.result);
84
- else if (run_0.status === "cancelled") toasts.show({ title: intl.formatMessage(messages.cancelled, { action: target_1.action.label }) });
85
- else if (run_0.status === "failed") toasts.show({
86
- title: intl.formatMessage(messages.failed, { action: target_1.action.label }),
87
- tone: "danger"
88
- });
89
- else toasts.show({
90
- title: intl.formatMessage(messages.done, { action: target_1.action.label }),
91
- tone: "success"
92
- });
93
- };
94
- const execute = async (resource_2, target_2, values = {}) => {
95
- const response = await adapter.runAction(resource_2, target_2.action.id, buildActionRequest(target_2, values));
96
- if (response.run !== void 0) {
97
- follow(resource_2, target_2, response.run);
46
+ let t4;
47
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
48
+ t4 = [];
49
+ $[0] = t4;
50
+ } else t4 = $[0];
51
+ const [runs, setRuns] = useState(t4);
52
+ let t5;
53
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
54
+ t5 = /* @__PURE__ */ new Set();
55
+ $[1] = t5;
56
+ } else t5 = $[1];
57
+ const notified = useRef(t5);
58
+ let t6;
59
+ if ($[2] !== intl || $[3] !== onDownload || $[4] !== onNavigate || $[5] !== onResult || $[6] !== toasts) {
60
+ t6 = async (resource, target, result) => {
61
+ await onResult?.(result, {
62
+ resource,
63
+ target
64
+ });
65
+ const content = describeResult(result, target.action.label, intl);
66
+ const hasDetails = (result.results ?? []).length > 0;
67
+ const download = result.download ?? null;
68
+ if (download !== null) onDownload(download);
69
+ toasts.show({
70
+ ...content,
71
+ ...hasDetails ? { action: {
72
+ label: intl.formatMessage(messages.details),
73
+ onAction: () => setDetails({
74
+ label: target.action.label,
75
+ result
76
+ })
77
+ } } : download !== null ? { action: {
78
+ label: intl.formatMessage(messages.download),
79
+ onAction: () => onDownload(download)
80
+ } } : {}
81
+ });
82
+ const redirect = result.redirect ?? null;
83
+ if (redirect !== null) onNavigate(redirect);
84
+ };
85
+ $[2] = intl;
86
+ $[3] = onDownload;
87
+ $[4] = onNavigate;
88
+ $[5] = onResult;
89
+ $[6] = toasts;
90
+ $[7] = t6;
91
+ } else t6 = $[7];
92
+ const finish = t6;
93
+ let t7;
94
+ if ($[8] !== intl || $[9] !== toasts) {
95
+ t7 = (resource_0, target_0, run) => {
96
+ setRuns((current) => [...current.filter((entry) => entry.run.id !== run.id), {
97
+ run,
98
+ resource: resource_0,
99
+ target: target_0
100
+ }]);
101
+ toasts.show({
102
+ title: intl.formatMessage(messages.queued, { action: target_0.action.label }),
103
+ description: intl.formatMessage(messages.queuedDescription),
104
+ tone: "info"
105
+ });
106
+ };
107
+ $[8] = intl;
108
+ $[9] = toasts;
109
+ $[10] = t7;
110
+ } else t7 = $[10];
111
+ const follow = t7;
112
+ let t8;
113
+ if ($[11] !== finish || $[12] !== intl || $[13] !== toasts) {
114
+ t8 = async (entry_0) => {
115
+ const { run: run_0, resource: resource_1, target: target_1 } = entry_0;
116
+ if (notified.current.has(run_0.id)) return;
117
+ notified.current.add(run_0.id);
118
+ if (run_0.result !== void 0) await finish(resource_1, target_1, run_0.result);
119
+ else if (run_0.status === "cancelled") toasts.show({ title: intl.formatMessage(messages.cancelled, { action: target_1.action.label }) });
120
+ else if (run_0.status === "failed") toasts.show({
121
+ title: intl.formatMessage(messages.failed, { action: target_1.action.label }),
122
+ tone: "danger"
123
+ });
124
+ else toasts.show({
125
+ title: intl.formatMessage(messages.done, { action: target_1.action.label }),
126
+ tone: "success"
127
+ });
128
+ };
129
+ $[11] = finish;
130
+ $[12] = intl;
131
+ $[13] = toasts;
132
+ $[14] = t8;
133
+ } else t8 = $[14];
134
+ const ended = t8;
135
+ let t9;
136
+ if ($[15] !== adapter || $[16] !== finish || $[17] !== follow) {
137
+ t9 = async (resource_2, target_2, t10) => {
138
+ const values = t10 === void 0 ? {} : t10;
139
+ const response = await adapter.runAction(resource_2, target_2.action.id, buildActionRequest(target_2, values));
140
+ if (response.run !== void 0) {
141
+ follow(resource_2, target_2, response.run);
142
+ return {
143
+ status: "queued",
144
+ run: response.run
145
+ };
146
+ }
147
+ await finish(resource_2, target_2, response.result);
98
148
  return {
99
- status: "queued",
100
- run: response.run
149
+ status: "done",
150
+ result: response.result
101
151
  };
102
- }
103
- await finish(resource_2, target_2, response.result);
104
- return {
105
- status: "done",
106
- result: response.result
107
152
  };
108
- };
109
- const run_1 = (resource_3, target_3) => {
110
- const { action } = target_3;
111
- if (action.kind === "link") {
112
- const to = getLinkTarget(target_3);
113
- if (to === null) return Promise.reject(/* @__PURE__ */ new Error(`The action "${action.id}" has no URL or route.`));
114
- onNavigate(to);
115
- return Promise.resolve({
116
- status: "navigated",
117
- to
118
- });
119
- }
120
- if (action.kind === "client") {
121
- const name = action.component ?? "";
122
- const Handler = (clientActions !== void 0 && Object.hasOwn(clientActions, name) ? clientActions[name] : void 0) ?? plugins.actions.get(name);
123
- if (Handler === void 0) return Promise.reject(/* @__PURE__ */ new Error(`No handler for the client action "${action.id}" (${name}).`));
124
- return new Promise((resolve) => setClient({
153
+ $[15] = adapter;
154
+ $[16] = finish;
155
+ $[17] = follow;
156
+ $[18] = t9;
157
+ } else t9 = $[18];
158
+ const execute = t9;
159
+ let t10;
160
+ if ($[19] !== clientActions || $[20] !== execute || $[21] !== onNavigate || $[22] !== plugins) {
161
+ t10 = (resource_3, target_3) => {
162
+ const { action } = target_3;
163
+ if (action.kind === "link") {
164
+ const to = getLinkTarget(target_3);
165
+ if (to === null) return Promise.reject(/* @__PURE__ */ new Error(`The action "${action.id}" has no URL or route.`));
166
+ onNavigate(to);
167
+ return Promise.resolve({
168
+ status: "navigated",
169
+ to
170
+ });
171
+ }
172
+ if (action.kind === "client") {
173
+ const name = action.component ?? "";
174
+ const Handler = (clientActions !== void 0 && Object.hasOwn(clientActions, name) ? clientActions[name] : void 0) ?? plugins.actions.get(name);
175
+ if (Handler === void 0) return Promise.reject(/* @__PURE__ */ new Error(`No handler for the client action "${action.id}" (${name}).`));
176
+ return new Promise((resolve) => setClient({
177
+ resource: resource_3,
178
+ target: target_3,
179
+ resolve,
180
+ Handler
181
+ }));
182
+ }
183
+ if ((action.fields ?? []).length > 0) return new Promise((resolve_0) => setParameters({
125
184
  resource: resource_3,
126
185
  target: target_3,
127
- resolve,
128
- Handler
129
- }));
130
- }
131
- if ((action.fields ?? []).length > 0) return new Promise((resolve_0) => setParameters({
132
- resource: resource_3,
133
- target: target_3,
134
- resolve: resolve_0
135
- }));
136
- return execute(resource_3, target_3);
137
- };
138
- const cancelRun = async (id) => {
139
- if (adapter.cancelActionRun === void 0) throw new Error("The adapter cannot cancel runs.");
140
- await adapter.cancelActionRun(id);
141
- const updated = await adapter.getActionRun(id);
142
- setRuns((current_0) => current_0.map((entry_1) => entry_1.run.id === id ? {
143
- ...entry_1,
144
- run: updated
145
- } : entry_1));
146
- const entry_2 = runs.find((candidate) => candidate.run.id === id);
147
- if (entry_2 !== void 0 && isFinished(updated.status)) await ended({
148
- ...entry_2,
149
- run: updated
150
- });
151
- };
152
- const dismissRun = (id_0) => setRuns((current_1) => current_1.filter((entry_3) => entry_3.run.id !== id_0));
153
- const onRunEnded = useEffectEvent((entry_4) => ended(entry_4));
154
- useEffect(() => {
155
- const active = runs.filter((entry_5) => !isFinished(entry_5.run.status));
156
- if (active.length === 0) return;
157
- let stopped = false;
158
- const timer = setTimeout(() => {
159
- Promise.all(active.map(async (entry_6) => {
160
- try {
161
- const next = await adapter.getActionRun(entry_6.run.id);
162
- if (stopped) return;
163
- setRuns((current_3) => current_3.map((candidate_0) => candidate_0.run.id === next.id ? {
164
- ...candidate_0,
165
- run: next
166
- } : candidate_0));
167
- if (isFinished(next.status)) await onRunEnded({
168
- ...entry_6,
169
- run: next
170
- });
171
- } catch {
172
- if (!stopped) setRuns((current_2) => [...current_2]);
173
- }
186
+ resolve: resolve_0
174
187
  }));
175
- }, pollInterval);
176
- return () => {
177
- stopped = true;
178
- clearTimeout(timer);
188
+ return execute(resource_3, target_3);
179
189
  };
180
- }, [
181
- runs,
182
- adapter,
183
- pollInterval
184
- ]);
185
- const value = {
186
- adapter,
187
- run: run_1,
188
- runs,
189
- cancelRun,
190
- dismissRun
191
- };
192
- const ClientHandler = client?.Handler;
193
- return /* @__PURE__ */ jsxs(ActionRunnerContext, {
194
- value,
195
- children: [
196
- children,
197
- parameters !== null ? /* @__PURE__ */ jsx(ParametersDialog, {
198
- action: parameters.target.action,
199
- count: parameters.target.count,
200
- locales,
201
- onSubmit: (values_0) => execute(parameters.resource, parameters.target, values_0),
202
- onDone: (outcome) => {
203
- setParameters(null);
204
- parameters.resolve(outcome);
205
- },
206
- onCancel: () => {
207
- setParameters(null);
208
- parameters.resolve(false);
209
- }
210
- }) : null,
211
- client !== null && ClientHandler !== void 0 ? /* @__PURE__ */ jsx(ClientHandler, {
212
- action: client.target.action,
213
- resource: client.resource,
214
- target: client.target,
215
- onDone: (result_0) => {
216
- setClient(null);
217
- if (result_0 === void 0) {
218
- client.resolve({
219
- status: "done",
220
- result: {}
190
+ $[19] = clientActions;
191
+ $[20] = execute;
192
+ $[21] = onNavigate;
193
+ $[22] = plugins;
194
+ $[23] = t10;
195
+ } else t10 = $[23];
196
+ const run_1 = t10;
197
+ let t11;
198
+ if ($[24] !== adapter || $[25] !== ended || $[26] !== runs) {
199
+ t11 = async (id) => {
200
+ if (adapter.cancelActionRun === void 0) throw new Error("The adapter cannot cancel runs.");
201
+ await adapter.cancelActionRun(id);
202
+ const updated = await adapter.getActionRun(id);
203
+ setRuns((current_0) => current_0.map((entry_1) => entry_1.run.id === id ? {
204
+ ...entry_1,
205
+ run: updated
206
+ } : entry_1));
207
+ const entry_2 = runs.find((candidate) => candidate.run.id === id);
208
+ if (entry_2 !== void 0 && isFinished(updated.status)) await ended({
209
+ ...entry_2,
210
+ run: updated
211
+ });
212
+ };
213
+ $[24] = adapter;
214
+ $[25] = ended;
215
+ $[26] = runs;
216
+ $[27] = t11;
217
+ } else t11 = $[27];
218
+ const cancelRun = t11;
219
+ let t12;
220
+ if ($[28] === Symbol.for("react.memo_cache_sentinel")) {
221
+ t12 = (id_0) => setRuns((current_1) => current_1.filter((entry_3) => entry_3.run.id !== id_0));
222
+ $[28] = t12;
223
+ } else t12 = $[28];
224
+ const dismissRun = t12;
225
+ let t13;
226
+ if ($[29] !== ended) {
227
+ t13 = (entry_4) => ended(entry_4);
228
+ $[29] = ended;
229
+ $[30] = t13;
230
+ } else t13 = $[30];
231
+ const onRunEnded = useEffectEvent(t13);
232
+ let t14;
233
+ if ($[31] !== adapter || $[32] !== onRunEnded || $[33] !== pollInterval || $[34] !== runs) {
234
+ t14 = () => {
235
+ const active = runs.filter(_temp);
236
+ if (active.length === 0) return;
237
+ let stopped = false;
238
+ const timer = setTimeout(() => {
239
+ Promise.all(active.map(async (entry_6) => {
240
+ try {
241
+ const next = await adapter.getActionRun(entry_6.run.id);
242
+ if (stopped) return;
243
+ setRuns((current_3) => current_3.map((candidate_0) => candidate_0.run.id === next.id ? {
244
+ ...candidate_0,
245
+ run: next
246
+ } : candidate_0));
247
+ if (isFinished(next.status)) await onRunEnded({
248
+ ...entry_6,
249
+ run: next
221
250
  });
222
- return;
251
+ } catch {
252
+ if (!stopped) setRuns(_temp2);
223
253
  }
224
- finish(client.resource, client.target, result_0).then(() => client.resolve({
254
+ }));
255
+ }, pollInterval);
256
+ return () => {
257
+ stopped = true;
258
+ clearTimeout(timer);
259
+ };
260
+ };
261
+ $[31] = adapter;
262
+ $[32] = onRunEnded;
263
+ $[33] = pollInterval;
264
+ $[34] = runs;
265
+ $[35] = t14;
266
+ } else t14 = $[35];
267
+ let t15;
268
+ if ($[36] !== adapter || $[37] !== pollInterval || $[38] !== runs) {
269
+ t15 = [
270
+ runs,
271
+ adapter,
272
+ pollInterval
273
+ ];
274
+ $[36] = adapter;
275
+ $[37] = pollInterval;
276
+ $[38] = runs;
277
+ $[39] = t15;
278
+ } else t15 = $[39];
279
+ useEffect(t14, t15);
280
+ let t16;
281
+ if ($[40] !== adapter || $[41] !== cancelRun || $[42] !== run_1 || $[43] !== runs) {
282
+ t16 = {
283
+ adapter,
284
+ run: run_1,
285
+ runs,
286
+ cancelRun,
287
+ dismissRun
288
+ };
289
+ $[40] = adapter;
290
+ $[41] = cancelRun;
291
+ $[42] = run_1;
292
+ $[43] = runs;
293
+ $[44] = t16;
294
+ } else t16 = $[44];
295
+ const value = t16;
296
+ const ClientHandler = client?.Handler;
297
+ let t17;
298
+ if ($[45] !== execute || $[46] !== locales || $[47] !== parameters) {
299
+ t17 = parameters !== null ? /* @__PURE__ */ jsx(ParametersDialog, {
300
+ action: parameters.target.action,
301
+ count: parameters.target.count,
302
+ locales,
303
+ onSubmit: (values_0) => execute(parameters.resource, parameters.target, values_0),
304
+ onDone: (outcome) => {
305
+ setParameters(null);
306
+ parameters.resolve(outcome);
307
+ },
308
+ onCancel: () => {
309
+ setParameters(null);
310
+ parameters.resolve(false);
311
+ }
312
+ }) : null;
313
+ $[45] = execute;
314
+ $[46] = locales;
315
+ $[47] = parameters;
316
+ $[48] = t17;
317
+ } else t17 = $[48];
318
+ let t18;
319
+ if ($[49] !== ClientHandler || $[50] !== client || $[51] !== finish) {
320
+ t18 = client !== null && ClientHandler !== void 0 ? /* @__PURE__ */ jsx(ClientHandler, {
321
+ action: client.target.action,
322
+ resource: client.resource,
323
+ target: client.target,
324
+ onDone: (result_0) => {
325
+ setClient(null);
326
+ if (result_0 === void 0) {
327
+ client.resolve({
225
328
  status: "done",
226
- result: result_0
227
- }));
228
- },
229
- onCancel: () => {
230
- setClient(null);
231
- client.resolve(false);
329
+ result: {}
330
+ });
331
+ return;
232
332
  }
233
- }) : null,
234
- details !== null ? /* @__PURE__ */ jsx(ResultsDialog, {
235
- label: details.label,
236
- result: details.result,
237
- onClose: () => setDetails(null)
238
- }) : null
239
- ]
240
- });
333
+ finish(client.resource, client.target, result_0).then(() => client.resolve({
334
+ status: "done",
335
+ result: result_0
336
+ }));
337
+ },
338
+ onCancel: () => {
339
+ setClient(null);
340
+ client.resolve(false);
341
+ }
342
+ }) : null;
343
+ $[49] = ClientHandler;
344
+ $[50] = client;
345
+ $[51] = finish;
346
+ $[52] = t18;
347
+ } else t18 = $[52];
348
+ let t19;
349
+ if ($[53] !== details) {
350
+ t19 = details !== null ? /* @__PURE__ */ jsx(ResultsDialog, {
351
+ label: details.label,
352
+ result: details.result,
353
+ onClose: () => setDetails(null)
354
+ }) : null;
355
+ $[53] = details;
356
+ $[54] = t19;
357
+ } else t19 = $[54];
358
+ let t20;
359
+ if ($[55] !== children || $[56] !== t17 || $[57] !== t18 || $[58] !== t19 || $[59] !== value) {
360
+ t20 = /* @__PURE__ */ jsxs(ActionRunnerContext, {
361
+ value,
362
+ children: [
363
+ children,
364
+ t17,
365
+ t18,
366
+ t19
367
+ ]
368
+ });
369
+ $[55] = children;
370
+ $[56] = t17;
371
+ $[57] = t18;
372
+ $[58] = t19;
373
+ $[59] = value;
374
+ $[60] = t20;
375
+ } else t20 = $[60];
376
+ return t20;
377
+ }
378
+ function _temp2(current_2) {
379
+ return [...current_2];
380
+ }
381
+ function _temp(entry_5) {
382
+ return !isFinished(entry_5.run.status);
241
383
  }
242
384
  //#endregion
243
385
  export { ActionRunnerProvider };
@@ -1 +1 @@
1
- {"version":3,"file":"ActionRunnerProvider.js","names":["resource","target","entry","run","resolve","current","id","candidate","values","result"],"sources":["../src/ActionRunnerProvider.tsx"],"sourcesContent":["import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from 'react';\n\nimport { usePlugins } from '@panneau/core';\nimport type { ActionResult, ActionRun, RouteReference } from '@panneau/protocol';\nimport { usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ParametersDialog } from './ParametersDialog';\nimport { ResultsDialog } from './ResultsDialog';\nimport { ActionRunnerContext, type ActionRunnerContextValue } from './context';\nimport { describeResult } from './describe';\nimport { messages } from './messages';\nimport { buildActionRequest, getLinkTarget, isFinished } from './request';\nimport type {\n ActionAdapter,\n ActionDownload,\n ActionOutcome,\n ActionResultContext,\n ActionTarget,\n ClientActionHandler,\n FollowedRun,\n} from './types';\n\nexport interface ActionRunnerProviderProps {\n /** Runs the actions: a `DataAdapter`, or any object with its action methods. */\n adapter: ActionAdapter;\n children?: ReactNode;\n /**\n * Called with every result: of an action that finished at once, and of a queued run when it\n * finishes. Refresh what it changed here. With `@panneau/data/query`:\n * `invalidateActionResult(client, resource, result, target.selection)`.\n */\n onResult?: (result: ActionResult, context: ActionResultContext) => unknown;\n /**\n * Goes to the `redirect` of a result, or to the URL or route of a `link` action. Defaults to\n * `window.location.assign()` for URLs; routes need it.\n */\n onNavigate?: (to: string | RouteReference) => void;\n /** Opens the `download` of a result. Defaults to a link to its URL, clicked. */\n onDownload?: (download: ActionDownload) => void;\n /** Handlers of `client` actions by their `component`, over those of the plugins. */\n clientActions?: Readonly<Record<string, ClientActionHandler>>;\n /** Milliseconds between two checks of a queued run. Defaults to 2000. */\n pollInterval?: number;\n /** Locales of localized parameters. Defaults to the definition's. */\n locales?: readonly string[];\n}\n\ninterface Pending {\n resource: string;\n target: ActionTarget;\n resolve: (outcome: ActionOutcome | false) => void;\n}\n\ninterface ClientPending extends Pending {\n Handler: ClientActionHandler;\n}\n\nfunction navigateTo(to: string | RouteReference) {\n if (typeof to === 'string') {\n window.location.assign(to);\n } else {\n console.warn(\n `[panneau] An action goes to the route \"${to.route}\": give ActionRunnerProvider an onNavigate.`,\n );\n }\n}\n\nfunction openDownload(download: ActionDownload) {\n const link = document.createElement('a');\n link.href = download.url;\n if (download.filename !== undefined) {\n link.download = download.filename;\n }\n link.rel = 'noopener';\n link.hidden = true;\n document.body.append(link);\n link.click();\n link.remove();\n}\n\n/**\n * Runs the actions that lists and forms hand over ([decision 0023]): it asks for their parameters\n * in a dialog, runs them through the adapter, shows their result (a toast, and the items that\n * didn't succeed), follows queued runs until they end, refreshes through `onResult`, follows\n * redirects and opens downloads. Put it inside `PanneauRoot`, and above the router of an app, so\n * that runs are followed from page to page. `useActionRunner(resource)` runs an action.\n */\nexport function ActionRunnerProvider({\n adapter,\n children,\n onResult,\n onNavigate = navigateTo,\n onDownload = openDownload,\n clientActions,\n pollInterval = 2000,\n locales,\n}: ActionRunnerProviderProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const plugins = usePlugins();\n const [parameters, setParameters] = useState<Pending | null>(null);\n const [client, setClient] = useState<ClientPending | null>(null);\n const [details, setDetails] = useState<{ label: string; result: ActionResult } | null>(null);\n const [runs, setRuns] = useState<readonly FollowedRun[]>([]);\n // Runs whose end was already shown, so that a late poll doesn't show it twice.\n const notified = useRef(new Set<string>());\n\n const finish = async (resource: string, target: ActionTarget, result: ActionResult) => {\n await onResult?.(result, { resource, target });\n const content = describeResult(result, target.action.label, intl);\n const hasDetails = (result.results ?? []).length > 0;\n const download = result.download ?? null;\n if (download !== null) {\n onDownload(download);\n }\n toasts.show({\n ...content,\n ...(hasDetails\n ? {\n action: {\n label: intl.formatMessage(messages.details),\n onAction: () => setDetails({ label: target.action.label, result }),\n },\n }\n : download !== null\n ? {\n action: {\n label: intl.formatMessage(messages.download),\n onAction: () => onDownload(download),\n },\n }\n : {}),\n });\n const redirect = result.redirect ?? null;\n if (redirect !== null) {\n onNavigate(redirect);\n }\n };\n\n const follow = (resource: string, target: ActionTarget, run: ActionRun) => {\n setRuns((current) => [\n ...current.filter((entry) => entry.run.id !== run.id),\n { run, resource, target },\n ]);\n toasts.show({\n title: intl.formatMessage(messages.queued, { action: target.action.label }),\n description: intl.formatMessage(messages.queuedDescription),\n tone: 'info',\n });\n };\n\n const ended = async (entry: FollowedRun) => {\n const { run, resource, target } = entry;\n if (notified.current.has(run.id)) {\n return;\n }\n notified.current.add(run.id);\n if (run.result !== undefined) {\n await finish(resource, target, run.result);\n } else if (run.status === 'cancelled') {\n toasts.show({\n title: intl.formatMessage(messages.cancelled, { action: target.action.label }),\n });\n } else if (run.status === 'failed') {\n toasts.show({\n title: intl.formatMessage(messages.failed, { action: target.action.label }),\n tone: 'danger',\n });\n } else {\n toasts.show({\n title: intl.formatMessage(messages.done, { action: target.action.label }),\n tone: 'success',\n });\n }\n };\n\n const execute = async (\n resource: string,\n target: ActionTarget,\n values: Record<string, unknown> = {},\n ): Promise<ActionOutcome> => {\n const response = await adapter.runAction(\n resource,\n target.action.id,\n buildActionRequest(target, values),\n );\n if (response.run !== undefined) {\n follow(resource, target, response.run);\n return { status: 'queued', run: response.run };\n }\n await finish(resource, target, response.result);\n return { status: 'done', result: response.result };\n };\n\n const run = (resource: string, target: ActionTarget): Promise<ActionOutcome | false> => {\n const { action } = target;\n if (action.kind === 'link') {\n const to = getLinkTarget(target);\n if (to === null) {\n return Promise.reject(new Error(`The action \"${action.id}\" has no URL or route.`));\n }\n onNavigate(to);\n return Promise.resolve({ status: 'navigated', to });\n }\n if (action.kind === 'client') {\n const name = action.component ?? '';\n const Handler =\n (clientActions !== undefined && Object.hasOwn(clientActions, name)\n ? clientActions[name]\n : undefined) ?? (plugins.actions.get(name) as ClientActionHandler | undefined);\n if (Handler === undefined) {\n return Promise.reject(\n new Error(`No handler for the client action \"${action.id}\" (${name}).`),\n );\n }\n return new Promise((resolve) => setClient({ resource, target, resolve, Handler }));\n }\n if ((action.fields ?? []).length > 0) {\n return new Promise((resolve) => setParameters({ resource, target, resolve }));\n }\n return execute(resource, target);\n };\n\n const cancelRun = async (id: string) => {\n if (adapter.cancelActionRun === undefined) {\n throw new Error('The adapter cannot cancel runs.');\n }\n await adapter.cancelActionRun(id);\n const updated = await adapter.getActionRun(id);\n setRuns((current) =>\n current.map((entry) => (entry.run.id === id ? { ...entry, run: updated } : entry)),\n );\n const entry = runs.find((candidate) => candidate.run.id === id);\n if (entry !== undefined && isFinished(updated.status)) {\n await ended({ ...entry, run: updated });\n }\n };\n\n const dismissRun = (id: string) =>\n setRuns((current) => current.filter((entry) => entry.run.id !== id));\n\n const onRunEnded = useEffectEvent((entry: FollowedRun) => ended(entry));\n\n // Checks the unfinished runs, one interval after the last change of the runs.\n useEffect(() => {\n const active = runs.filter((entry) => !isFinished(entry.run.status));\n if (active.length === 0) {\n return undefined;\n }\n let stopped = false;\n const timer = setTimeout(() => {\n void Promise.all(\n active.map(async (entry) => {\n try {\n const next = await adapter.getActionRun(entry.run.id);\n if (stopped) {\n return;\n }\n setRuns((current) =>\n current.map((candidate) =>\n candidate.run.id === next.id\n ? { ...candidate, run: next }\n : candidate,\n ),\n );\n if (isFinished(next.status)) {\n await onRunEnded({ ...entry, run: next });\n }\n } catch {\n // Checked again at the next interval.\n if (!stopped) {\n setRuns((current) => [...current]);\n }\n }\n }),\n );\n }, pollInterval);\n return () => {\n stopped = true;\n clearTimeout(timer);\n };\n }, [runs, adapter, pollInterval]);\n\n const value: ActionRunnerContextValue = { adapter, run, runs, cancelRun, dismissRun };\n\n const ClientHandler = client?.Handler;\n return (\n <ActionRunnerContext value={value}>\n {children}\n {parameters !== null ? (\n <ParametersDialog\n action={parameters.target.action}\n count={parameters.target.count}\n locales={locales}\n onSubmit={(values) => execute(parameters.resource, parameters.target, values)}\n onDone={(outcome) => {\n setParameters(null);\n parameters.resolve(outcome);\n }}\n onCancel={() => {\n setParameters(null);\n parameters.resolve(false);\n }}\n />\n ) : null}\n {client !== null && ClientHandler !== undefined ? (\n <ClientHandler\n action={client.target.action}\n resource={client.resource}\n target={client.target}\n onDone={(result) => {\n setClient(null);\n if (result === undefined) {\n client.resolve({ status: 'done', result: {} });\n return;\n }\n void finish(client.resource, client.target, result).then(() =>\n client.resolve({ status: 'done', result }),\n );\n }}\n onCancel={() => {\n setClient(null);\n client.resolve(false);\n }}\n />\n ) : null}\n {details !== null ? (\n <ResultsDialog\n label={details.label}\n result={details.result}\n onClose={() => setDetails(null)}\n />\n ) : null}\n </ActionRunnerContext>\n );\n}\n"],"mappings":";;;;;;;;;;;AAyDA,SAAS,WAAW,IAA6B;CAC7C,IAAI,OAAO,OAAO,UACd,OAAO,SAAS,OAAO,EAAE;MAEzB,QAAQ,KACJ,0CAA0C,GAAG,MAAK,4CACtD;AAER;AAEA,SAAS,aAAa,UAA0B;CAC5C,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,OAAO,SAAS;CACrB,IAAI,SAAS,aAAa,KAAA,GACtB,KAAK,WAAW,SAAS;CAE7B,KAAK,MAAM;CACX,KAAK,SAAS;CACd,SAAS,KAAK,OAAO,IAAI;CACzB,KAAK,MAAM;CACX,KAAK,OAAO;AAChB;;;;;;;;AASA,SAAgB,qBAAqB,EACjC,SACA,UACA,UACA,aAAa,YACb,aAAa,cACb,eACA,eAAe,KACf,WAC0B;CAC1B,MAAM,OAAO,eAAe;CAC5B,MAAM,SAAS,SAAS;CACxB,MAAM,UAAU,WAAW;CAC3B,MAAM,CAAC,YAAY,iBAAiB,SAAyB,IAAI;CACjE,MAAM,CAAC,QAAQ,aAAa,SAA+B,I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,IAAIA,aAAW,KAAA,GAAW;MACtB,OAAO,QAAQ;OAAE,QAAQ;OAAQ,QAAQ,CAAC;MAAE,CAAC;MAC7C;KACJ;KACA,OAAY,OAAO,UAAU,OAAO,QAAQA,QAAM,CAAC,CAAC,WAChD,OAAO,QAAQ;MAAE,QAAQ;MAAQ,QAAAA;KAAO,CAAC,CAC7C;IACJ;IACA,gBAAgB;KACZ,UAAU,IAAI;KACd,OAAO,QAAQ,KAAK;IACxB;GAAE,CAAA,IAEN;GACH,YAAY,OACT,oBAAC,eAAD;IACI,OAAO,QAAQ;IACf,QAAQ,QAAQ;IAChB,eAAe,WAAW,IAAI;GAAE,CAAA,IAEpC;EACa;;AAE7B"}
1
+ {"version":3,"file":"ActionRunnerProvider.js","names":["ReactNode","useEffect","useEffectEvent","useRef","useState","usePlugins","ActionResult","ActionRun","RouteReference","usePanneauIntl","useToast","ParametersDialog","ResultsDialog","ActionRunnerContext","ActionRunnerContextValue","describeResult","messages","buildActionRequest","getLinkTarget","isFinished","ActionAdapter","ActionDownload","ActionOutcome","ActionResultContext","ActionTarget","ClientActionHandler","FollowedRun","ActionRunnerProviderProps","adapter","children","onResult","result","context","onNavigate","to","onDownload","download","clientActions","Readonly","Record","pollInterval","locales","Pending","resource","target","resolve","outcome","ClientPending","Handler","navigateTo","window","location","assign","console","warn","route","openDownload","link","document","createElement","href","url","filename","undefined","rel","hidden","body","append","click","remove","ActionRunnerProvider","t0","$","_c","t1","t2","t3","intl","toasts","plugins","parameters","setParameters","client","setClient","details","setDetails","t4","Symbol","for","runs","setRuns","t5","Set","notified","t6","content","action","label","hasDetails","results","length","show","formatMessage","onAction","redirect","finish","t7","resource_0","target_0","run","current","filter","entry","id","title","queued","description","queuedDescription","tone","follow","t8","entry_0","run_0","resource_1","target_1","has","add","status","cancelled","failed","done","ended","t9","resource_2","target_2","t10","values","response","runAction","execute","resource_3","target_3","kind","Promise","reject","Error","name","component","Object","hasOwn","actions","get","fields","resolve_0","run_1","t11","cancelActionRun","updated","getActionRun","current_0","map","entry_1","entry_2","find","candidate","cancelRun","t12","id_0","current_1","entry_3","dismissRun","t13","entry_4","onRunEnded","t14","active","_temp","stopped","timer","setTimeout","all","entry_6","next","current_3","candidate_0","_temp2","clearTimeout","t15","t16","value","ClientHandler","t17","count","values_0","t18","result_0","then","t19","t20","current_2","entry_5","_c"],"sources":["../src/ActionRunnerProvider.tsx"],"sourcesContent":["import { type ReactNode, useEffect, useEffectEvent, useRef, useState } from 'react';\n\nimport { usePlugins } from '@panneau/core';\nimport type { ActionResult, ActionRun, RouteReference } from '@panneau/protocol';\nimport { usePanneauIntl, useToast } from '@panneau/ui';\n\nimport { ParametersDialog } from './ParametersDialog';\nimport { ResultsDialog } from './ResultsDialog';\nimport { ActionRunnerContext, type ActionRunnerContextValue } from './context';\nimport { describeResult } from './describe';\nimport { messages } from './messages';\nimport { buildActionRequest, getLinkTarget, isFinished } from './request';\nimport type {\n ActionAdapter,\n ActionDownload,\n ActionOutcome,\n ActionResultContext,\n ActionTarget,\n ClientActionHandler,\n FollowedRun,\n} from './types';\n\nexport interface ActionRunnerProviderProps {\n /** Runs the actions: a `DataAdapter`, or any object with its action methods. */\n adapter: ActionAdapter;\n children?: ReactNode;\n /**\n * Called with every result: of an action that finished at once, and of a queued run when it\n * finishes. Refresh what it changed here. With `@panneau/data/query`:\n * `invalidateActionResult(client, resource, result, target.selection)`.\n */\n onResult?: (result: ActionResult, context: ActionResultContext) => unknown;\n /**\n * Goes to the `redirect` of a result, or to the URL or route of a `link` action. Defaults to\n * `window.location.assign()` for URLs; routes need it.\n */\n onNavigate?: (to: string | RouteReference) => void;\n /** Opens the `download` of a result. Defaults to a link to its URL, clicked. */\n onDownload?: (download: ActionDownload) => void;\n /** Handlers of `client` actions by their `component`, over those of the plugins. */\n clientActions?: Readonly<Record<string, ClientActionHandler>>;\n /** Milliseconds between two checks of a queued run. Defaults to 2000. */\n pollInterval?: number;\n /** Locales of localized parameters. Defaults to the definition's. */\n locales?: readonly string[];\n}\n\ninterface Pending {\n resource: string;\n target: ActionTarget;\n resolve: (outcome: ActionOutcome | false) => void;\n}\n\ninterface ClientPending extends Pending {\n Handler: ClientActionHandler;\n}\n\nfunction navigateTo(to: string | RouteReference) {\n if (typeof to === 'string') {\n window.location.assign(to);\n } else {\n console.warn(\n `[panneau] An action goes to the route \"${to.route}\": give ActionRunnerProvider an onNavigate.`,\n );\n }\n}\n\nfunction openDownload(download: ActionDownload) {\n const link = document.createElement('a');\n link.href = download.url;\n if (download.filename !== undefined) {\n link.download = download.filename;\n }\n link.rel = 'noopener';\n link.hidden = true;\n document.body.append(link);\n link.click();\n link.remove();\n}\n\n/**\n * Runs the actions that lists and forms hand over ([decision 0023]): it asks for their parameters\n * in a dialog, runs them through the adapter, shows their result (a toast, and the items that\n * didn't succeed), follows queued runs until they end, refreshes through `onResult`, follows\n * redirects and opens downloads. Put it inside `PanneauRoot`, and above the router of an app, so\n * that runs are followed from page to page. `useActionRunner(resource)` runs an action.\n */\nexport function ActionRunnerProvider({\n adapter,\n children,\n onResult,\n onNavigate = navigateTo,\n onDownload = openDownload,\n clientActions,\n pollInterval = 2000,\n locales,\n}: ActionRunnerProviderProps) {\n const intl = usePanneauIntl();\n const toasts = useToast();\n const plugins = usePlugins();\n const [parameters, setParameters] = useState<Pending | null>(null);\n const [client, setClient] = useState<ClientPending | null>(null);\n const [details, setDetails] = useState<{ label: string; result: ActionResult } | null>(null);\n const [runs, setRuns] = useState<readonly FollowedRun[]>([]);\n // Runs whose end was already shown, so that a late poll doesn't show it twice.\n const notified = useRef(new Set<string>());\n\n const finish = async (resource: string, target: ActionTarget, result: ActionResult) => {\n await onResult?.(result, { resource, target });\n const content = describeResult(result, target.action.label, intl);\n const hasDetails = (result.results ?? []).length > 0;\n const download = result.download ?? null;\n if (download !== null) {\n onDownload(download);\n }\n toasts.show({\n ...content,\n ...(hasDetails\n ? {\n action: {\n label: intl.formatMessage(messages.details),\n onAction: () => setDetails({ label: target.action.label, result }),\n },\n }\n : download !== null\n ? {\n action: {\n label: intl.formatMessage(messages.download),\n onAction: () => onDownload(download),\n },\n }\n : {}),\n });\n const redirect = result.redirect ?? null;\n if (redirect !== null) {\n onNavigate(redirect);\n }\n };\n\n const follow = (resource: string, target: ActionTarget, run: ActionRun) => {\n setRuns((current) => [\n ...current.filter((entry) => entry.run.id !== run.id),\n { run, resource, target },\n ]);\n toasts.show({\n title: intl.formatMessage(messages.queued, { action: target.action.label }),\n description: intl.formatMessage(messages.queuedDescription),\n tone: 'info',\n });\n };\n\n const ended = async (entry: FollowedRun) => {\n const { run, resource, target } = entry;\n if (notified.current.has(run.id)) {\n return;\n }\n notified.current.add(run.id);\n if (run.result !== undefined) {\n await finish(resource, target, run.result);\n } else if (run.status === 'cancelled') {\n toasts.show({\n title: intl.formatMessage(messages.cancelled, { action: target.action.label }),\n });\n } else if (run.status === 'failed') {\n toasts.show({\n title: intl.formatMessage(messages.failed, { action: target.action.label }),\n tone: 'danger',\n });\n } else {\n toasts.show({\n title: intl.formatMessage(messages.done, { action: target.action.label }),\n tone: 'success',\n });\n }\n };\n\n const execute = async (\n resource: string,\n target: ActionTarget,\n values: Record<string, unknown> = {},\n ): Promise<ActionOutcome> => {\n const response = await adapter.runAction(\n resource,\n target.action.id,\n buildActionRequest(target, values),\n );\n if (response.run !== undefined) {\n follow(resource, target, response.run);\n return { status: 'queued', run: response.run };\n }\n await finish(resource, target, response.result);\n return { status: 'done', result: response.result };\n };\n\n const run = (resource: string, target: ActionTarget): Promise<ActionOutcome | false> => {\n const { action } = target;\n if (action.kind === 'link') {\n const to = getLinkTarget(target);\n if (to === null) {\n return Promise.reject(new Error(`The action \"${action.id}\" has no URL or route.`));\n }\n onNavigate(to);\n return Promise.resolve({ status: 'navigated', to });\n }\n if (action.kind === 'client') {\n const name = action.component ?? '';\n const Handler =\n (clientActions !== undefined && Object.hasOwn(clientActions, name)\n ? clientActions[name]\n : undefined) ?? (plugins.actions.get(name) as ClientActionHandler | undefined);\n if (Handler === undefined) {\n return Promise.reject(\n new Error(`No handler for the client action \"${action.id}\" (${name}).`),\n );\n }\n return new Promise((resolve) => setClient({ resource, target, resolve, Handler }));\n }\n if ((action.fields ?? []).length > 0) {\n return new Promise((resolve) => setParameters({ resource, target, resolve }));\n }\n return execute(resource, target);\n };\n\n const cancelRun = async (id: string) => {\n if (adapter.cancelActionRun === undefined) {\n throw new Error('The adapter cannot cancel runs.');\n }\n await adapter.cancelActionRun(id);\n const updated = await adapter.getActionRun(id);\n setRuns((current) =>\n current.map((entry) => (entry.run.id === id ? { ...entry, run: updated } : entry)),\n );\n const entry = runs.find((candidate) => candidate.run.id === id);\n if (entry !== undefined && isFinished(updated.status)) {\n await ended({ ...entry, run: updated });\n }\n };\n\n const dismissRun = (id: string) =>\n setRuns((current) => current.filter((entry) => entry.run.id !== id));\n\n const onRunEnded = useEffectEvent((entry: FollowedRun) => ended(entry));\n\n // Checks the unfinished runs, one interval after the last change of the runs.\n useEffect(() => {\n const active = runs.filter((entry) => !isFinished(entry.run.status));\n if (active.length === 0) {\n return undefined;\n }\n let stopped = false;\n const timer = setTimeout(() => {\n void Promise.all(\n active.map(async (entry) => {\n try {\n const next = await adapter.getActionRun(entry.run.id);\n if (stopped) {\n return;\n }\n setRuns((current) =>\n current.map((candidate) =>\n candidate.run.id === next.id\n ? { ...candidate, run: next }\n : candidate,\n ),\n );\n if (isFinished(next.status)) {\n await onRunEnded({ ...entry, run: next });\n }\n } catch {\n // Checked again at the next interval.\n if (!stopped) {\n setRuns((current) => [...current]);\n }\n }\n }),\n );\n }, pollInterval);\n return () => {\n stopped = true;\n clearTimeout(timer);\n };\n }, [runs, adapter, pollInterval]);\n\n const value: ActionRunnerContextValue = { adapter, run, runs, cancelRun, dismissRun };\n\n const ClientHandler = client?.Handler;\n return (\n <ActionRunnerContext value={value}>\n {children}\n {parameters !== null ? (\n <ParametersDialog\n action={parameters.target.action}\n count={parameters.target.count}\n locales={locales}\n onSubmit={(values) => execute(parameters.resource, parameters.target, values)}\n onDone={(outcome) => {\n setParameters(null);\n parameters.resolve(outcome);\n }}\n onCancel={() => {\n setParameters(null);\n parameters.resolve(false);\n }}\n />\n ) : null}\n {client !== null && ClientHandler !== undefined ? (\n <ClientHandler\n action={client.target.action}\n resource={client.resource}\n target={client.target}\n onDone={(result) => {\n setClient(null);\n if (result === undefined) {\n client.resolve({ status: 'done', result: {} });\n return;\n }\n void finish(client.resource, client.target, result).then(() =>\n client.resolve({ status: 'done', result }),\n );\n }}\n onCancel={() => {\n setClient(null);\n client.resolve(false);\n }}\n />\n ) : null}\n {details !== null ? (\n <ResultsDialog\n label={details.label}\n result={details.result}\n onClose={() => setDetails(null)}\n />\n ) : null}\n </ActionRunnerContext>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAyDA,SAASiD,WAAWf,IAA6B;CAC7C,IAAI,OAAOA,OAAO,UACdgB,OAAOC,SAASC,OAAOlB,EAAE;MAEzBmB,QAAQC,KACJ,0CAA0CpB,GAAGqB,MAAK,4CACtD;AAER;AAEA,SAASC,aAAapB,UAA0B;CAC5C,MAAMqB,OAAOC,SAASC,cAAc,GAAG;CACvCF,KAAKG,OAAOxB,SAASyB;CACrB,IAAIzB,SAAS0B,aAAaC,KAAAA,GACtBN,KAAKrB,WAAWA,SAAS0B;CAE7BL,KAAKO,MAAM;CACXP,KAAKQ,SAAS;CACdP,SAASQ,KAAKC,OAAOV,IAAI;CACzBA,KAAKW,MAAM;CACXX,KAAKY,OAAO;AAChB;;;;;;;;AASA,SAAOC,qBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA8B,MAAA,EAAA7C,SAAAC,UAAAC,UAAAG,YAAAyC,IAAAvC,YAAAwC,IAAAtC,eAAAG,cAAAoC,IAAAnC,YAAA8B;CAIjC,MAAAtC,aAAAyC,OAAAX,KAAAA,IAAAd,aAAAyB;CACA,MAAAvC,aAAAwC,OAAAZ,KAAAA,IAAAP,eAAAmB;CAEA,MAAAnC,eAAAoC,OAAAb,KAA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H,EAAA,MAAA0H;EAAA1H,EAAA,MAAA6H;EAAA7H,EAAA,MAAAqH;EAAArH,EAAA,MAAA8H;CAAA,OAAAA,MAAA9H,EAAA;CAAA,OA9CtB8H;AA8CsB;AAtPvB,SAAAb,OAAAc,WAAA;CAAA,OAwL0C,CAAA,GAAIzF,SAAO;AAAC;AAxLtD,SAAAkE,MAAAwB,SAAA;CAAA,OA8JuC,CAACrL,WAAW6F,QAAKH,IAAIkB,MAAO;AAAC"}
@@ -2,9 +2,9 @@ import ActionRunner_module_default from "./ActionRunner.module.js";
2
2
  import { messages } from "./messages.js";
3
3
  import { isFinished } from "./request.js";
4
4
  import { ActionRunnerContext } from "./context.js";
5
+ import { c } from "react/compiler-runtime";
5
6
  import { use } from "react";
6
7
  import { Button, IconButton, usePanneauIntl } from "@panneau/ui";
7
- import { c } from "react/compiler-runtime";
8
8
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { X } from "lucide-react";
10
10
  import { ProgressBar } from "react-aria-components";
@@ -1 +1 @@
1
- {"version":3,"file":"ActionRuns.js","names":["label","X","status","valueText","_c","styles","_Fragment"],"sources":["../src/ActionRuns.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { use } from 'react';\nimport { ProgressBar } from 'react-aria-components';\n\nimport type { ActionRun } from '@panneau/protocol';\nimport { Button, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { ActionRunnerContext } from './context';\nimport { messages } from './messages';\nimport { isFinished } from './request';\n\nconst STATUS_MESSAGES = {\n queued: messages.runQueued,\n running: messages.runRunning,\n succeeded: messages.runSucceeded,\n partial: messages.runPartial,\n failed: messages.runFailed,\n cancelled: messages.runCancelled,\n} satisfies Record<ActionRun['status'], unknown>;\n\nexport interface ActionRunsProps {\n /** Accessible name of the list. Defaults to \"Actions in progress\". */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * The queued runs that the closest `ActionRunnerProvider` follows: their status and progress, a\n * button to cancel those that haven't finished (when the adapter can), and one to dismiss those\n * that have. For a notification area. Renders nothing without runs.\n */\nexport function ActionRuns({ 'aria-label': ariaLabel, className }: ActionRunsProps) {\n const intl = usePanneauIntl();\n const context = use(ActionRunnerContext);\n if (context === null || context.runs.length === 0) {\n return null;\n }\n const canCancel = context.adapter.cancelActionRun !== undefined;\n return (\n <ul\n aria-label={ariaLabel ?? intl.formatMessage(messages.runs)}\n className={[styles.runs, className].filter(Boolean).join(' ')}\n >\n {context.runs.map(({ run, target }) => {\n const label = target.action.label;\n const finished = isFinished(run.status);\n const status = intl.formatMessage(STATUS_MESSAGES[run.status]);\n return (\n <li key={run.id} className={styles.run}>\n <span className={styles.runLabel}>{label}</span>\n {finished ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.dismissRun, { action: label })}\n onPress={() => context.dismissRun(run.id)}\n />\n ) : canCancel ? (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={intl.formatMessage(messages.cancelRun, {\n action: label,\n })}\n onPress={() => {\n context.cancelRun(run.id).catch(() => undefined);\n }}\n >\n {intl.formatMessage(messages.cancel)}\n </Button>\n ) : (\n <span />\n )}\n {finished ? (\n <span className={styles.runStatus}>{status}</span>\n ) : (\n <ProgressBar\n aria-label={label}\n className={styles.progress}\n value={run.progress}\n maxValue={run.total ?? undefined}\n isIndeterminate={run.total === null || run.total === 0}\n valueLabel={\n run.total !== null && run.total > 0\n ? intl.formatMessage(messages.progress, {\n progress: run.progress,\n total: run.total,\n })\n : status\n }\n >\n {({ percentage, valueText }) => (\n <>\n <span className={styles.runStatus}>{valueText}</span>\n <span className={styles.track}>\n <span\n className={styles.fill}\n style={{ width: `${percentage ?? 100}%` }}\n />\n </span>\n </>\n )}\n </ProgressBar>\n )}\n </li>\n );\n })}\n </ul>\n );\n}\n"],"mappings":";;;;;;;;;;;AAYA,IAAM,kBAAkB;CACpB,QAAQ,SAAS;CACjB,SAAS,SAAS;CAClB,WAAW,SAAS;CACpB,S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A;EAAiB,WAAAA,4BAAM;EACnB,UAAA,oBAAA,QAAA;GACe,WAAAA,4BAAM;GACV,OAAA,EAAA,OAAS,GAAG,cAAA,IAAiB,GAAI;EAAC,CAAA;CAE1C,CAAA,CAAA,EAAA,CAAA;AACR;AArEhC,SAAA,QAAA,CAAA"}
1
+ {"version":3,"file":"ActionRuns.js","names":["X","use","ProgressBar","ActionRun","Button","IconButton","usePanneauIntl","styles","ActionRunnerContext","messages","isFinished","STATUS_MESSAGES","queued","runQueued","running","runRunning","succeeded","runSucceeded","partial","runPartial","failed","runFailed","cancelled","runCancelled","Record","ActionRunsProps","className","ActionRuns","t0","$","_c","ariaLabel","intl","context","runs","length","canCancel","adapter","cancelActionRun","undefined","t1","formatMessage","t2","filter","Boolean","t3","join","t4","map","t5","run","target","label","action","finished","status","id","runLabel","dismissRun","cancelRun","catch","_temp","cancel","runStatus","progress","total","_temp2","percentage","valueText","track","fill","width","_c","styles","_Fragment"],"sources":["../src/ActionRuns.tsx"],"sourcesContent":["import { X } from 'lucide-react';\nimport { use } from 'react';\nimport { ProgressBar } from 'react-aria-components';\n\nimport type { ActionRun } from '@panneau/protocol';\nimport { Button, IconButton, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { ActionRunnerContext } from './context';\nimport { messages } from './messages';\nimport { isFinished } from './request';\n\nconst STATUS_MESSAGES = {\n queued: messages.runQueued,\n running: messages.runRunning,\n succeeded: messages.runSucceeded,\n partial: messages.runPartial,\n failed: messages.runFailed,\n cancelled: messages.runCancelled,\n} satisfies Record<ActionRun['status'], unknown>;\n\nexport interface ActionRunsProps {\n /** Accessible name of the list. Defaults to \"Actions in progress\". */\n 'aria-label'?: string;\n className?: string;\n}\n\n/**\n * The queued runs that the closest `ActionRunnerProvider` follows: their status and progress, a\n * button to cancel those that haven't finished (when the adapter can), and one to dismiss those\n * that have. For a notification area. Renders nothing without runs.\n */\nexport function ActionRuns({ 'aria-label': ariaLabel, className }: ActionRunsProps) {\n const intl = usePanneauIntl();\n const context = use(ActionRunnerContext);\n if (context === null || context.runs.length === 0) {\n return null;\n }\n const canCancel = context.adapter.cancelActionRun !== undefined;\n return (\n <ul\n aria-label={ariaLabel ?? intl.formatMessage(messages.runs)}\n className={[styles.runs, className].filter(Boolean).join(' ')}\n >\n {context.runs.map(({ run, target }) => {\n const label = target.action.label;\n const finished = isFinished(run.status);\n const status = intl.formatMessage(STATUS_MESSAGES[run.status]);\n return (\n <li key={run.id} className={styles.run}>\n <span className={styles.runLabel}>{label}</span>\n {finished ? (\n <IconButton\n icon={X}\n size=\"sm\"\n label={intl.formatMessage(messages.dismissRun, { action: label })}\n onPress={() => context.dismissRun(run.id)}\n />\n ) : canCancel ? (\n <Button\n size=\"sm\"\n variant=\"ghost\"\n aria-label={intl.formatMessage(messages.cancelRun, {\n action: label,\n })}\n onPress={() => {\n context.cancelRun(run.id).catch(() => undefined);\n }}\n >\n {intl.formatMessage(messages.cancel)}\n </Button>\n ) : (\n <span />\n )}\n {finished ? (\n <span className={styles.runStatus}>{status}</span>\n ) : (\n <ProgressBar\n aria-label={label}\n className={styles.progress}\n value={run.progress}\n maxValue={run.total ?? undefined}\n isIndeterminate={run.total === null || run.total === 0}\n valueLabel={\n run.total !== null && run.total > 0\n ? intl.formatMessage(messages.progress, {\n progress: run.progress,\n total: run.total,\n })\n : status\n }\n >\n {({ percentage, valueText }) => (\n <>\n <span className={styles.runStatus}>{valueText}</span>\n <span className={styles.track}>\n <span\n className={styles.fill}\n style={{ width: `${percentage ?? 100}%` }}\n />\n </span>\n </>\n )}\n </ProgressBar>\n )}\n </li>\n );\n })}\n </ul>\n );\n}\n"],"mappings":";;;;;;;;;;;AAYA,IAAMW,kBAAkB;CACpBC,QAAQH,SAASI;CACjBC,SAASL,SAASM;CAClBC,WAAWP,SAASQ;CACpBC,SAAST,SAASU;CAClBC,QAAQX,SAASY;CACjBC,WAAWb,SAASc;AACxB;;;;;;AAaA,SAAOI,WAAAC,IAAA;CAAA,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AA5EN,SAAAiB,OAAAtC,IAAA;CA4D2B,MAAA,EAAAuC,YAAAC,cAAAxC;CAAyB,OACvB,qBAAA8C,UAAA,EAAA,UAAA,CACI,oBAAA,QAAA;EAAiB,WAAAnE,4BAAMwD;EAAaK,UAAAA;CAAiB,CAAA,GACrD,oBAAA,QAAA;EAAiB,WAAA7D,4BAAM8D;EACnB,UAAA,oBAAA,QAAA;GACe,WAAA9D,4BAAM+D;GACV,OAAA,EAAAC,OAAS,GAAGJ,cAAA,IAAiB,GAAI;EAAC,CAAA;CAE1C,CAAA,CAAA,EAAA,CAAA;AACR;AArEhC,SAAAN,QAAA,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import type { Action } from '@panneau/protocol';
2
- import type { ActionOutcome } from './types';
2
+ import type { ActionOutcome } from './types.js';
3
3
  export interface ParametersDialogProps {
4
4
  action: Action;
5
5
  /** How many items the action applies to, for the confirm label. */
@@ -1,7 +1,7 @@
1
1
  import ActionRunner_module_default from "./ActionRunner.module.js";
2
2
  import { messages } from "./messages.js";
3
- import { Button, Dialog, usePanneauIntl } from "@panneau/ui";
4
3
  import { c } from "react/compiler-runtime";
4
+ import { Button, Dialog, usePanneauIntl } from "@panneau/ui";
5
5
  import { Form } from "@panneau/forms";
6
6
  import { jsx } from "react/jsx-runtime";
7
7
  //#region src/ParametersDialog.tsx
@@ -1 +1 @@
1
- {"version":3,"file":"ParametersDialog.js","names":["onCancel","confirmLabel","_c","styles"],"sources":["../src/ParametersDialog.tsx"],"sourcesContent":["import { Form } from '@panneau/forms';\nimport type { Action } from '@panneau/protocol';\nimport { Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { messages } from './messages';\nimport type { ActionOutcome } from './types';\n\nexport interface ParametersDialogProps {\n action: Action;\n /** How many items the action applies to, for the confirm label. */\n count?: number | undefined;\n locales?: readonly string[] | undefined;\n /** Runs the action with the values. A validation error (`422`) shows on the fields. */\n onSubmit: (values: Record<string, unknown>) => Promise<ActionOutcome>;\n onDone: (outcome: ActionOutcome) => void;\n onCancel: () => void;\n}\n\n/**\n * The parameters of an action (`fields`, in its `layout`), in a dialog, with the client validation\n * of forms. The action runs when the form is submitted; errors of the action endpoint (`422`, keyed\n * by paths inside `values`) show on the fields, and other errors in the form.\n */\nexport function ParametersDialog({\n action,\n locales,\n onSubmit,\n onDone,\n onCancel,\n}: ParametersDialogProps) {\n const intl = usePanneauIntl();\n const confirmLabel =\n typeof action.confirm === 'object' && action.confirm.confirmLabel !== undefined\n ? action.confirm.confirmLabel\n : action.label;\n return (\n <Dialog\n isOpen\n onOpenChange={(open) => {\n if (!open) {\n onCancel();\n }\n }}\n title={action.label}\n size=\"md\"\n >\n <Form\n fields={action.fields ?? []}\n layout={action.layout ?? []}\n {...(locales !== undefined ? { locales } : {})}\n aria-label={action.label}\n submitLabel={confirmLabel}\n actions={\n <Button variant=\"secondary\" onPress={onCancel}>\n {intl.formatMessage(messages.cancel)}\n </Button>\n }\n onSubmit={(values) => onSubmit(values)}\n onSubmitted={(outcome) => onDone(outcome as ActionOutcome)}\n guardUnsavedChanges={false}\n showSavedToast={false}\n className={styles.parameters}\n />\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAO,iBAAA,IAAA;CAAA,MAAA,IAAAE,EAAA,EAAA;CAA0B,MAAA,EAAA,QAAA,SAAA,UAAA,QAAA,aAAA;CAO7B,MAAA,OAAa,eAAe;CAC5B,MAAA,eACI,OAAO,OAAM,YAAa,YAAY,OAAM,QAAQ,iBAAkB,KAAA,IAChE,OAAM,QAAQ,eACd,OAAM;CAAO,IAAA;CAAA,IAAA,EAAA,OAAA,UAAA;EAID,MAAA,SAAA;GACV,IAAI,CAAC,MACD,SAAS;EACZ;EACJ,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CACM,MAAA,KAAA,OAAM;CAAM,IAAA;CAAA,IAAA,EAAA,OAAA,OAAA,QAAA;EAIP,KAAA,OA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AAD;GACY,QAAA;GACA,QAAA;GAAmB,GACtB;GACO,cAAA;GACCC,aAAA;GAET,SAAA;GAIM,UAAA;GACG,aAAA;GACQ,qBAAA;GACL,gBAAA;GACL,WAAAE,4BAAM;EAAW,CAAA;EAC9B,EAAA,MAAA,OAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,MAAA,EAAA;CAAA,IAAA;CAAA,IAAA,EAAA,QAAA,OAAA,SAAA,EAAA,QAAA,MAAA,EAAA,QAAA,KAAA;EA1BN,MAAA,oBAAC,QAAD;GACI,QAAA;GACc,cAAA;GAKP,OAAA;GACF,MAAA;GAEL,UAAA;EAVG,CAAA;EA2BE,EAAA,MAAA,OAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,MAAA,EAAA;CAAA,OA3BT;AA2BS"}
1
+ {"version":3,"file":"ParametersDialog.js","names":["Form","Action","Button","Dialog","usePanneauIntl","styles","messages","ActionOutcome","ParametersDialogProps","action","count","locales","onSubmit","values","Record","Promise","onDone","outcome","onCancel","ParametersDialog","t0","$","_c","intl","confirmLabel","confirm","undefined","label","t1","open","t2","t3","fields","t4","layout","t5","t6","t7","formatMessage","cancel","t8","t9","t10","t11","parameters","t12","_c","styles"],"sources":["../src/ParametersDialog.tsx"],"sourcesContent":["import { Form } from '@panneau/forms';\nimport type { Action } from '@panneau/protocol';\nimport { Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { messages } from './messages';\nimport type { ActionOutcome } from './types';\n\nexport interface ParametersDialogProps {\n action: Action;\n /** How many items the action applies to, for the confirm label. */\n count?: number | undefined;\n locales?: readonly string[] | undefined;\n /** Runs the action with the values. A validation error (`422`) shows on the fields. */\n onSubmit: (values: Record<string, unknown>) => Promise<ActionOutcome>;\n onDone: (outcome: ActionOutcome) => void;\n onCancel: () => void;\n}\n\n/**\n * The parameters of an action (`fields`, in its `layout`), in a dialog, with the client validation\n * of forms. The action runs when the form is submitted; errors of the action endpoint (`422`, keyed\n * by paths inside `values`) show on the fields, and other errors in the form.\n */\nexport function ParametersDialog({\n action,\n locales,\n onSubmit,\n onDone,\n onCancel,\n}: ParametersDialogProps) {\n const intl = usePanneauIntl();\n const confirmLabel =\n typeof action.confirm === 'object' && action.confirm.confirmLabel !== undefined\n ? action.confirm.confirmLabel\n : action.label;\n return (\n <Dialog\n isOpen\n onOpenChange={(open) => {\n if (!open) {\n onCancel();\n }\n }}\n title={action.label}\n size=\"md\"\n >\n <Form\n fields={action.fields ?? []}\n layout={action.layout ?? []}\n {...(locales !== undefined ? { locales } : {})}\n aria-label={action.label}\n submitLabel={confirmLabel}\n actions={\n <Button variant=\"secondary\" onPress={onCancel}>\n {intl.formatMessage(messages.cancel)}\n </Button>\n }\n onSubmit={(values) => onSubmit(values)}\n onSubmitted={(outcome) => onDone(outcome as ActionOutcome)}\n guardUnsavedChanges={false}\n showSavedToast={false}\n className={styles.parameters}\n />\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAwBA,SAAOmB,iBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA0B,MAAA,EAAAb,QAAAE,SAAAC,UAAAI,QAAAE,aAAAE;CAO7B,MAAAG,OAAanB,eAAe;CAC5B,MAAAoB,eACI,OAAOf,OAAMgB,YAAa,YAAYhB,OAAMgB,QAAQD,iBAAkBE,KAAAA,IAChEjB,OAAMgB,QAAQD,eACdf,OAAMkB;CAAO,IAAAC;CAAA,IAAAP,EAAA,OAAAH,UAAA;EAIDU,MAAAC,SAAA;GACV,IAAI,CAACA,MACDX,SAAS;EACZ;EACJG,EAAA,KAAAH;EAAAG,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CACM,MAAAS,KAAArB,OAAMkB;CA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;CAAA,OAAAA,MAAArB,EAAA;CAAA,IAAAsB;CAAA,IAAAtB,EAAA,QAAAZ,OAAAkB,SAAAN,EAAA,QAAAG,gBAAAH,EAAA,QAAAqB,OAAArB,EAAA,QAAAU,MAAAV,EAAA,QAAAY,MAAAZ,EAAA,QAAAc,MAAAd,EAAA,QAAAmB,MAAAnB,EAAA,QAAAoB,IAAA;EAZ9DE,MAAA,oBAAC,MAAD;GACY,QAAAZ;GACA,QAAAE;GAAmB,GACtBE;GACO,cAAAC;GACCZ,aAAAA;GAET,SAAAgB;GAIM,UAAAC;GACG,aAAAC;GACQ,qBAAA;GACL,gBAAA;GACL,WAAArC,4BAAMuC;EAAW,CAAA;EAC9BvB,EAAA,MAAAZ,OAAAkB;EAAAN,EAAA,MAAAG;EAAAH,EAAA,MAAAqB;EAAArB,EAAA,MAAAU;EAAAV,EAAA,MAAAY;EAAAZ,EAAA,MAAAc;EAAAd,EAAA,MAAAmB;EAAAnB,EAAA,MAAAoB;EAAApB,EAAA,MAAAsB;CAAA,OAAAA,MAAAtB,EAAA;CAAA,IAAAwB;CAAA,IAAAxB,EAAA,QAAAZ,OAAAkB,SAAAN,EAAA,QAAAO,MAAAP,EAAA,QAAAsB,KAAA;EA1BNE,MAAA,oBAAC,QAAD;GACI,QAAA;GACc,cAAAjB;GAKP,OAAAE;GACF,MAAA;GAELa,UAAAA;EAVG,CAAA;EA2BEtB,EAAA,MAAAZ,OAAAkB;EAAAN,EAAA,MAAAO;EAAAP,EAAA,MAAAsB;EAAAtB,EAAA,MAAAwB;CAAA,OAAAA,MAAAxB,EAAA;CAAA,OA3BTwB;AA2BS"}
@@ -1,8 +1,8 @@
1
1
  import ActionRunner_module_default from "./ActionRunner.module.js";
2
2
  import { messages } from "./messages.js";
3
3
  import { describeItemResult, describeResult } from "./describe.js";
4
- import { Badge, Button, Dialog, usePanneauIntl } from "@panneau/ui";
5
4
  import { c } from "react/compiler-runtime";
5
+ import { Badge, Button, Dialog, usePanneauIntl } from "@panneau/ui";
6
6
  import { jsx, jsxs } from "react/jsx-runtime";
7
7
  //#region src/ResultsDialog.tsx
8
8
  /** The items of a result that didn't succeed, with why: failed with a message, or skipped. */
@@ -1 +1 @@
1
- {"version":3,"file":"ResultsDialog.js","names":["onClose","_c","styles"],"sources":["../src/ResultsDialog.tsx"],"sourcesContent":["import type { ActionResult } from '@panneau/protocol';\nimport { Badge, Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { describeItemResult, describeResult } from './describe';\nimport { messages } from './messages';\n\nexport interface ResultsDialogProps {\n /** The label of the action. */\n label: string;\n result: ActionResult;\n onClose: () => void;\n}\n\n/** The items of a result that didn't succeed, with why: failed with a message, or skipped. */\nexport function ResultsDialog({ label, result, onClose }: ResultsDialogProps) {\n const intl = usePanneauIntl();\n const summary = describeResult(result, label, intl);\n return (\n <Dialog\n isOpen\n onOpenChange={(open) => {\n if (!open) {\n onClose();\n }\n }}\n title={intl.formatMessage(messages.resultsTitle, { action: label })}\n footer={\n <Button variant=\"secondary\" onPress={onClose}>\n {intl.formatMessage(messages.close)}\n </Button>\n }\n >\n <p className={styles.summary}>\n {summary.title}\n {summary.description !== undefined ? ` ${summary.description}` : null}\n </p>\n <ul className={styles.results}>\n {(result.results ?? []).map((entry) => (\n <li key={entry.id} className={styles.result}>\n <span className={styles.resultItem}>\n {intl.formatMessage(messages.item, { id: entry.id })}\n </span>\n <Badge tone={entry.status === 'failed' ? 'danger' : 'neutral'}>\n {intl.formatMessage(\n entry.status === 'failed'\n ? messages.statusFailed\n : messages.statusSkipped,\n )}\n </Badge>\n <span className={styles.resultReason}>\n {describeItemResult(entry, intl)}\n </span>\n </li>\n ))}\n </ul>\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;AAeA,SAAO,cAAA,IAAA;CAAA,MAAA,IAAAC,EAAA,EAAA;CAAuB,MAAA,EAAA,OAAA,QAAA,YAAA;CAC1B,MAAA,OAAa,eAAe;CAAE,IAAA;CAA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EAqCE,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;EAAA,EAAA,MAAA;CAAA,OAAA,MAAA,EAAA;CAAA,OArCT;AAqCS"}
1
+ {"version":3,"file":"ResultsDialog.js","names":["ActionResult","Badge","Button","Dialog","usePanneauIntl","styles","describeItemResult","describeResult","messages","ResultsDialogProps","label","result","onClose","ResultsDialog","t0","$","_c","intl","t1","summary","t2","open","t3","formatMessage","resultsTitle","action","t4","close","t5","t6","description","undefined","t7","title","t8","results","t9","t10","entry","id","resultItem","item","status","statusFailed","statusSkipped","resultReason","map","t11","_c","styles"],"sources":["../src/ResultsDialog.tsx"],"sourcesContent":["import type { ActionResult } from '@panneau/protocol';\nimport { Badge, Button, Dialog, usePanneauIntl } from '@panneau/ui';\n\nimport styles from './ActionRunner.module.css';\nimport { describeItemResult, describeResult } from './describe';\nimport { messages } from './messages';\n\nexport interface ResultsDialogProps {\n /** The label of the action. */\n label: string;\n result: ActionResult;\n onClose: () => void;\n}\n\n/** The items of a result that didn't succeed, with why: failed with a message, or skipped. */\nexport function ResultsDialog({ label, result, onClose }: ResultsDialogProps) {\n const intl = usePanneauIntl();\n const summary = describeResult(result, label, intl);\n return (\n <Dialog\n isOpen\n onOpenChange={(open) => {\n if (!open) {\n onClose();\n }\n }}\n title={intl.formatMessage(messages.resultsTitle, { action: label })}\n footer={\n <Button variant=\"secondary\" onPress={onClose}>\n {intl.formatMessage(messages.close)}\n </Button>\n }\n >\n <p className={styles.summary}>\n {summary.title}\n {summary.description !== undefined ? ` ${summary.description}` : null}\n </p>\n <ul className={styles.results}>\n {(result.results ?? []).map((entry) => (\n <li key={entry.id} className={styles.result}>\n <span className={styles.resultItem}>\n {intl.formatMessage(messages.item, { id: entry.id })}\n </span>\n <Badge tone={entry.status === 'failed' ? 'danger' : 'neutral'}>\n {intl.formatMessage(\n entry.status === 'failed'\n ? messages.statusFailed\n : messages.statusSkipped,\n )}\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BAqB,KAACF,GAAoBY,IAAMT,GAgB3B;EAACtB,EAAA,MAAAE;EAAAF,EAAA,MAAAmB;EAAAnB,EAAA,MAAAqB;CAAA,OAAAA,KAAArB,EAAA;CAAA,IAAAsB;CAAA,IAAAtB,EAAA,QAAAqB,IAAA;EAjBNC,MAAA,oBAAA,MAAA;GAAe,WAAAhC,4BAAM8B;GAChBC,UAAAA;EAiBA,CAAA;EAAArB,EAAA,MAAAqB;EAAArB,EAAA,MAAAsB;CAAA,OAAAA,MAAAtB,EAAA;CAAA,IAAAgC;CAAA,IAAAhC,EAAA,QAAAsB,OAAAtB,EAAA,QAAAK,MAAAL,EAAA,QAAAO,MAAAP,EAAA,QAAAa,MAAAb,EAAA,QAAAiB,IAAA;EApCTe,MAAA,qBAAC,QAAD;GACI,QAAA;GACc,cAAA3B;GAKP,OAAAE;GAEH,QAAAM;GATR,UAAA,CAcII,IAIAK,GAlBG;;EAqCEtB,EAAA,MAAAsB;EAAAtB,EAAA,MAAAK;EAAAL,EAAA,MAAAO;EAAAP,EAAA,MAAAa;EAAAb,EAAA,MAAAiB;EAAAjB,EAAA,MAAAgC;CAAA,OAAAA,MAAAhC,EAAA;CAAA,OArCTgC;AAqCS"}
package/dist/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types';
1
+ import type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types.js';
2
2
  export interface ActionRunnerContextValue {
3
3
  adapter: ActionAdapter;
4
4
  run: (resource: string, target: ActionTarget) => Promise<ActionOutcome | false>;
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types';\n\nexport interface ActionRunnerContextValue {\n adapter: ActionAdapter;\n run: (resource: string, target: ActionTarget) => Promise<ActionOutcome | false>;\n runs: readonly FollowedRun[];\n cancelRun: (id: string) => Promise<void>;\n dismissRun: (id: string) => void;\n}\n\nexport const ActionRunnerContext = createContext<ActionRunnerContextValue | null>(null);\n"],"mappings":";;AAYA,IAAa,sBAAsB,cAA+C,IAAI"}
1
+ {"version":3,"file":"context.js","names":["createContext","ActionAdapter","ActionOutcome","ActionTarget","FollowedRun","ActionRunnerContextValue","adapter","run","resource","target","Promise","runs","cancelRun","id","dismissRun","ActionRunnerContext"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'react';\n\nimport type { ActionAdapter, ActionOutcome, ActionTarget, FollowedRun } from './types';\n\nexport interface ActionRunnerContextValue {\n adapter: ActionAdapter;\n run: (resource: string, target: ActionTarget) => Promise<ActionOutcome | false>;\n runs: readonly FollowedRun[];\n cancelRun: (id: string) => Promise<void>;\n dismissRun: (id: string) => void;\n}\n\nexport const ActionRunnerContext = createContext<ActionRunnerContextValue | null>(null);\n"],"mappings":";;AAYA,IAAae,sBAAsBf,cAA+C,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"file":"describe.js","names":[],"sources":["../src/describe.ts"],"sourcesContent":["import type { IntlShape } from 'react-intl';\n\nimport type { ActionItemResult, ActionResult } from '@panneau/protocol';\nimport type { ToastContent } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getResultCounts } from './request';\n\n/** The toast of a result: its message, or \"done\", the counts, and a tone that says how it went. */\nexport function describeResult(\n result: ActionResult,\n actionLabel: string,\n intl: IntlShape,\n): Omit<ToastContent, 'action'> {\n const { succeeded, failed, skipped } = getResultCounts(result);\n const parts = [\n ...(succeeded !== null && (failed > 0 || skipped > 0)\n ? [intl.formatMessage(messages.succeededCount, { count: succeeded })]\n : []),\n ...(failed > 0 ? [intl.formatMessage(messages.failedCount, { count: failed })] : []),\n ...(skipped > 0 ? [intl.formatMessage(messages.skippedCount, { count: skipped })] : []),\n ];\n const tone: ToastContent['tone'] =\n failed > 0 ? (succeeded === 0 ? 'danger' : 'warning') : skipped > 0 ? 'warning' : 'success';\n return {\n title:\n result.message !== undefined && result.message !== ''\n ? result.message\n : intl.formatMessage(messages.done, { action: actionLabel }),\n ...(parts.length > 0 ? { description: intl.formatList(parts, { type: 'unit' }) } : {}),\n tone,\n };\n}\n\n/** Why an item didn't succeed: its message, or its reason (`forbidden`, `not_found`, `unchanged`). */\nexport function describeItemResult(entry: ActionItemResult, intl: IntlShape): string {\n if (entry.message !== undefined && entry.message !== '') {\n return entry.message;\n }\n switch (entry.reason) {\n case 'forbidden':\n return intl.formatMessage(messages.reasonForbidden);\n case 'not_found':\n return intl.formatMessage(messages.reasonNotFound);\n case 'unchanged':\n return intl.formatMessage(messages.reasonUnchanged);\n default:\n return intl.formatMessage(\n entry.status === 'failed' ? messages.statusFailed : messages.statusSkipped,\n );\n }\n}\n"],"mappings":";;;;AASA,SAAgB,eACZ,QACA,aACA,MAC4B;CAC5B,MAAM,EAAE,WAAW,QAAQ,YAAY,gBAAgB,MAAM;CAC7D,MAAM,QAAQ;EACV,GAAI,cAAc,SAAS,SAAS,KAAK,UAAU,KAC7C,CAAC,KAAK,cAAc,SAAS,gBAAgB,EAAE,OAAO,UAAU,CAAC,CAAC,IAClE,CAAA;EACN,GAAI,SAAS,IAAI,CAAC,KAAK,cAAc,SAAS,aAAa,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAA;EACjF,GAAI,UAAU,IAAI,CAAC,KAAK,cAAc,SAAS,cAAc,EAAE,OAAO,QAAQ,CAAC,CAAC,IAAI,CAAA;CAAG;CAE3F,MAAM,OACF,SAAS,IAAK,cAAc,IAAI,WAAW,YAAa,UAAU,IAAI,YAAY;CACtF,OAAO;EACH,OACI,OAAO,YAAY,KAAA,KAAa,OAAO,YAAY,KAC7C,OAAO,UACP,KAAK,cAAc,SAAS,MAAM,EAAE,QAAQ,YAAY,CAAC;EACnE,GAAI,MAAM,SAAS,IAAI,EAAE,aAAa,KAAK,WAAW,OAAO,EAAE,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC;EACpF;CACJ;AACJ;;AAGA,SAAgB,mBAAmB,OAAyB,MAAyB;CACjF,IAAI,MAAM,YAAY,KAAA,KAAa,MAAM,YAAY,IACjD,OAAO,MAAM;CAEjB,QAAQ,MAAM,QAAd;EACI,KAAK,aACD,OAAO,KAAK,cAAc,SAAS,eAAe;EACtD,KAAK,aACD,OAAO,KAAK,cAAc,SAAS,cAAc;EACrD,KAAK,aACD,OAAO,KAAK,cAAc,SAAS,eAAe;EACtD,SACI,OAAO,KAAK,cACR,MAAM,WAAW,WAAW,SAAS,eAAe,SAAS,aACjE;CACR;AACJ"}
1
+ {"version":3,"file":"describe.js","names":["IntlShape","ActionItemResult","ActionResult","ToastContent","messages","getResultCounts","describeResult","result","actionLabel","intl","Omit","succeeded","failed","skipped","parts","formatMessage","succeededCount","count","failedCount","skippedCount","tone","title","message","undefined","done","action","length","description","formatList","type","describeItemResult","entry","reason","reasonForbidden","reasonNotFound","reasonUnchanged","status","statusFailed","statusSkipped"],"sources":["../src/describe.ts"],"sourcesContent":["import type { IntlShape } from 'react-intl';\n\nimport type { ActionItemResult, ActionResult } from '@panneau/protocol';\nimport type { ToastContent } from '@panneau/ui';\n\nimport { messages } from './messages';\nimport { getResultCounts } from './request';\n\n/** The toast of a result: its message, or \"done\", the counts, and a tone that says how it went. */\nexport function describeResult(\n result: ActionResult,\n actionLabel: string,\n intl: IntlShape,\n): Omit<ToastContent, 'action'> {\n const { succeeded, failed, skipped } = getResultCounts(result);\n const parts = [\n ...(succeeded !== null && (failed > 0 || skipped > 0)\n ? [intl.formatMessage(messages.succeededCount, { count: succeeded })]\n : []),\n ...(failed > 0 ? [intl.formatMessage(messages.failedCount, { count: failed })] : []),\n ...(skipped > 0 ? [intl.formatMessage(messages.skippedCount, { count: skipped })] : []),\n ];\n const tone: ToastContent['tone'] =\n failed > 0 ? (succeeded === 0 ? 'danger' : 'warning') : skipped > 0 ? 'warning' : 'success';\n return {\n title:\n result.message !== undefined && result.message !== ''\n ? result.message\n : intl.formatMessage(messages.done, { action: actionLabel }),\n ...(parts.length > 0 ? { description: intl.formatList(parts, { type: 'unit' }) } : {}),\n tone,\n };\n}\n\n/** Why an item didn't succeed: its message, or its reason (`forbidden`, `not_found`, `unchanged`). */\nexport function describeItemResult(entry: ActionItemResult, intl: IntlShape): string {\n if (entry.message !== undefined && entry.message !== '') {\n return entry.message;\n }\n switch (entry.reason) {\n case 'forbidden':\n return intl.formatMessage(messages.reasonForbidden);\n case 'not_found':\n return intl.formatMessage(messages.reasonNotFound);\n case 'unchanged':\n return intl.formatMessage(messages.reasonUnchanged);\n default:\n return intl.formatMessage(\n entry.status === 'failed' ? messages.statusFailed : messages.statusSkipped,\n );\n }\n}\n"],"mappings":";;;;AASA,SAAgBM,eACZC,QACAC,aACAC,MAC4B;CAC5B,MAAM,EAAEE,WAAWC,QAAQC,YAAYR,gBAAgBE,MAAM;CAC7D,MAAMO,QAAQ;EACV,GAAIH,cAAc,SAASC,SAAS,KAAKC,UAAU,KAC7C,CAACJ,KAAKM,cAAcX,SAASY,gBAAgB,EAAEC,OAAON,UAAU,CAAC,CAAC,IAClE,CAAA;EACN,GAAIC,SAAS,IAAI,CAACH,KAAKM,cAAcX,SAASc,aAAa,EAAED,OAAOL,OAAO,CAAC,CAAC,IAAI,CAAA;EACjF,GAAIC,UAAU,IAAI,CAACJ,KAAKM,cAAcX,SAASe,cAAc,EAAEF,OAAOJ,QAAQ,CAAC,CAAC,IAAI,CAAA;CAAG;CAE3F,MAAMO,OACFR,SAAS,IAAKD,cAAc,IAAI,WAAW,YAAaE,UAAU,IAAI,YAAY;CACtF,OAAO;EACHQ,OACId,OAAOe,YAAYC,KAAAA,KAAahB,OAAOe,YAAY,KAC7Cf,OAAOe,UACPb,KAAKM,cAAcX,SAASoB,MAAM,EAAEC,QAAQjB,YAAY,CAAC;EACnE,GAAIM,MAAMY,SAAS,IAAI,EAAEC,aAAalB,KAAKmB,WAAWd,OAAO,EAAEe,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC;EACpFT;CACJ;AACJ;;AAGA,SAAgBU,mBAAmBC,OAAyBtB,MAAyB;CACjF,IAAIsB,MAAMT,YAAYC,KAAAA,KAAaQ,MAAMT,YAAY,IACjD,OAAOS,MAAMT;CAEjB,QAAQS,MAAMC,QAAd;EACI,KAAK,aACD,OAAOvB,KAAKM,cAAcX,SAAS6B,eAAe;EACtD,KAAK,aACD,OAAOxB,KAAKM,cAAcX,SAAS8B,cAAc;EACrD,KAAK,aACD,OAAOzB,KAAKM,cAAcX,SAAS+B,eAAe;EACtD,SACI,OAAO1B,KAAKM,cACRgB,MAAMK,WAAW,WAAWhC,SAASiC,eAAejC,SAASkC,aACjE;CACR;AACJ"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- export { ActionRunnerProvider, type ActionRunnerProviderProps } from './ActionRunnerProvider';
2
- export { ActionRuns, type ActionRunsProps } from './ActionRuns';
3
- export { ParametersDialog, type ParametersDialogProps } from './ParametersDialog';
4
- export { ResultsDialog, type ResultsDialogProps } from './ResultsDialog';
5
- export { describeItemResult, describeResult } from './describe';
6
- export { type ActionPreview, canPreviewAction, previewAction } from './preview';
7
- export { buildActionRequest, getLinkTarget, getResultCounts } from './request';
8
- export type { ActionAdapter, ActionDownload, ActionOutcome, ActionResultContext, ActionTarget, ClientActionHandler, ClientActionProps, FollowedRun, } from './types';
9
- export { useActionPreview, useActionRunner, useActionRuns } from './useActionRunner';
1
+ export { ActionRunnerProvider, type ActionRunnerProviderProps } from './ActionRunnerProvider.js';
2
+ export { ActionRuns, type ActionRunsProps } from './ActionRuns.js';
3
+ export { ParametersDialog, type ParametersDialogProps } from './ParametersDialog.js';
4
+ export { ResultsDialog, type ResultsDialogProps } from './ResultsDialog.js';
5
+ export { describeItemResult, describeResult } from './describe.js';
6
+ export { type ActionPreview, canPreviewAction, previewAction } from './preview.js';
7
+ export { buildActionRequest, getLinkTarget, getResultCounts } from './request.js';
8
+ export type { ActionAdapter, ActionDownload, ActionOutcome, ActionResultContext, ActionTarget, ClientActionHandler, ClientActionProps, FollowedRun, } from './types.js';
9
+ export { useActionPreview, useActionRunner, useActionRuns } from './useActionRunner.js';
10
10
  //# sourceMappingURL=index.d.ts.map
package/dist/preview.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ActionAdapter, ActionTarget } from './types';
1
+ import type { ActionAdapter, ActionTarget } from './types.js';
2
2
  /** What a dry run of an action told: how many items it would apply to, and skip. */
3
3
  export interface ActionPreview {
4
4
  succeeded: number;
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","names":[],"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,SAAgB,iBAAiB,QAA+B;CAC5D,MAAM,EAAE,QAAQ,cAAc;CAC9B,OACI,OAAO,WAAW,QAClB,OAAO,SAAS,YAChB,cAAc,KAAA,KACd,WAAW;AAEnB;;;;;;AAOA,eAAsB,cAClB,SACA,UACA,QACA,UAAoC,CAAC,GACR;CAC7B,IAAI,CAAC,iBAAiB,MAAM,GACxB,OAAO;CAQX,MAAM,WAAU,MANO,QAAQ,UAC3B,UACA,OAAO,OAAO,IACd;EAAE,WAAW,OAAO;EAAW,QAAQ;CAAK,GAC5C,OACJ,EAAA,CACyB,QAAQ;CACjC,OAAO,YAAY,KAAA,IACb;EAAE,WAAW,QAAQ;EAAW,SAAS,QAAQ;CAAQ,IACzD;AACV"}
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,5 +1,5 @@
1
- import { type ActionPreview } from './preview';
2
- import type { ActionOutcome, ActionTarget, FollowedRun } from './types';
1
+ import { type ActionPreview } from './preview.js';
2
+ import type { ActionOutcome, ActionTarget, FollowedRun } from './types.js';
3
3
  /**
4
4
  * Runs the actions of a resource through the closest `ActionRunnerProvider`. The function takes a
5
5
  * list's `ListActionEvent`, so it is the `onAction` of a list:
@@ -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 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,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;;;;;;;;;AAUA,SAAgB,iBACZ,UACuD;CACvD,MAAM,UAAU,IAAI,mBAAmB;CACvC,IAAI,YAAY,MACZ,MAAM,IAAI,MAAM,gEAAgE;CAEpF,QAAQ,WAAW,cAAc,QAAQ,SAAS,UAAU,MAAM;AACtE;;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.6",
3
+ "version": "5.0.0-alpha.8",
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.6",
41
- "@panneau/data": "5.0.0-alpha.6",
42
- "@panneau/forms": "5.0.0-alpha.6",
43
- "@panneau/intl": "5.0.0-alpha.6",
44
- "@panneau/protocol": "5.0.0-alpha.6",
45
- "@panneau/ui": "5.0.0-alpha.6",
40
+ "@panneau/core": "5.0.0-alpha.8",
41
+ "@panneau/data": "5.0.0-alpha.8",
42
+ "@panneau/forms": "5.0.0-alpha.8",
43
+ "@panneau/intl": "5.0.0-alpha.8",
44
+ "@panneau/protocol": "5.0.0-alpha.8",
45
+ "@panneau/ui": "5.0.0-alpha.8",
46
46
  "lucide-react": "^1.57.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@panneau/lists": "5.0.0-alpha.6"
49
+ "@panneau/lists": "5.0.0-alpha.8"
50
50
  }
51
51
  }