@panneau/actions 5.0.0-alpha.1 → 5.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/ActionRunner.css +14 -14
- package/dist/ActionRunner.module.js +13 -13
- package/dist/ActionRunnerProvider.d.ts +1 -1
- package/dist/ActionRunnerProvider.d.ts.map +1 -1
- package/dist/ActionRunnerProvider.js +334 -191
- package/dist/ActionRunnerProvider.js.map +1 -1
- package/dist/ActionRuns.d.ts.map +1 -1
- package/dist/ActionRuns.js +3 -2
- package/dist/ActionRuns.js.map +1 -1
- package/dist/ParametersDialog.d.ts +1 -1
- package/dist/ParametersDialog.d.ts.map +1 -1
- package/dist/ParametersDialog.js +99 -79
- package/dist/ParametersDialog.js.map +1 -1
- package/dist/ResultsDialog.js +1 -1
- package/dist/ResultsDialog.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js.map +1 -1
- package/dist/describe.js.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/preview.d.ts +21 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +30 -0
- package/dist/preview.js.map +1 -0
- package/dist/request.d.ts +1 -1
- package/dist/request.js.map +1 -1
- package/dist/useActionRunner.d.ts +11 -1
- package/dist/useActionRunner.d.ts.map +1 -1
- package/dist/useActionRunner.js +15 -1
- package/dist/useActionRunner.js.map +1 -1
- package/package.json +10 -10
|
@@ -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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ACL;EACJ,GAAG,YAAY;EACf,aAAa;GACT,UAAU;GACV,aAAa,KAAK;EACtB;CACJ,GAAG;EAAC;EAAM;EAAS;CAAY,CAAC;CAEhC,MAAM,QAAkC;EAAE;EAAS,KAAAF;EAAK;EAAM;EAAW;CAAW;CAEpF,MAAM,gBAAgB,QAAQ;CAC9B,OACI,qBAAC,qBAAD;EAA4B;EAA5B,UAAA;GACK;GACA,eAAe,OACZ,oBAAC,kBAAD;IACI,QAAQ,WAAW,OAAO;IAC1B,OAAO,WAAW,OAAO;IAChB;IACT,WAAWK,aAAW,QAAQ,WAAW,UAAU,WAAW,QAAQA,QAAM;IAC5E,SAAS,YAAY;KACjB,cAAc,IAAI;KAClB,WAAW,QAAQ,OAAO;IAC9B;IACA,gBAAgB;KACZ,cAAc,IAAI;KAClB,WAAW,QAAQ,KAAK;IAC5B;GAAE,CAAA,IAEN;GACH,WAAW,QAAQ,kBAAkB,KAAA,IAClC,oBAAC,eAAD;IACI,QAAQ,OAAO,OAAO;IACtB,UAAU,OAAO;IACjB,QAAQ,OAAO;IACf,SAASC,aAAW;KAChB,UAAU,IAAI;KACd,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","getActionLabel","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","hasDetails","results","length","show","label","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 { getActionLabel } from '@panneau/intl';\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, getActionLabel(target.action, intl), 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: () =>\n setDetails({ label: getActionLabel(target.action, intl), 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, {\n action: getActionLabel(target.action, intl),\n }),\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, {\n action: getActionLabel(target.action, intl),\n }),\n });\n } else if (run.status === 'failed') {\n toasts.show({\n title: intl.formatMessage(messages.failed, {\n action: getActionLabel(target.action, intl),\n }),\n tone: 'danger',\n });\n } else {\n toasts.show({\n title: intl.formatMessage(messages.done, {\n action: getActionLabel(target.action, intl),\n }),\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={()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Runs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRuns.d.ts","sourceRoot":"","sources":["../src/ActionRuns.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ActionRuns.d.ts","sourceRoot":"","sources":["../src/ActionRuns.tsx"],"names":[],"mappings":"AAsBA,MAAM,WAAW,eAAe;IAC5B,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,eAAe,sCA8EjF"}
|
package/dist/ActionRuns.js
CHANGED
|
@@ -2,9 +2,10 @@ 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";
|
|
7
|
+
import { getActionLabel } from "@panneau/intl";
|
|
6
8
|
import { Button, IconButton, usePanneauIntl } from "@panneau/ui";
|
|
7
|
-
import { c } from "react/compiler-runtime";
|
|
8
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import { X } from "lucide-react";
|
|
10
11
|
import { ProgressBar } from "react-aria-components";
|
|
@@ -47,7 +48,7 @@ function ActionRuns(t0) {
|
|
|
47
48
|
if ($[5] !== canCancel || $[6] !== context || $[7] !== intl) {
|
|
48
49
|
t4 = context.runs.map((t5) => {
|
|
49
50
|
const { run, target } = t5;
|
|
50
|
-
const label = target.action
|
|
51
|
+
const label = getActionLabel(target.action, intl);
|
|
51
52
|
const finished = isFinished(run.status);
|
|
52
53
|
const status = intl.formatMessage(STATUS_MESSAGES[run.status]);
|
|
53
54
|
return /* @__PURE__ */ jsxs("li", {
|
package/dist/ActionRuns.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionRuns.js","names":["label","
|
|
1
|
+
{"version":3,"file":"ActionRuns.js","names":["X","use","ProgressBar","getActionLabel","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 { getActionLabel } from '@panneau/intl';\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 = getActionLabel(target.action, intl);\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":";;;;;;;;;;;;AAaA,IAAMY,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,MAAAC,IAAAC,EAAA,EAAA;CAAoB,MAAA,EAAA,cAAAC,WAAAL,cAAAE;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,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParametersDialog.d.ts","sourceRoot":"","sources":["../src/ParametersDialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ParametersDialog.d.ts","sourceRoot":"","sources":["../src/ParametersDialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAKhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,MAAM,WAAW,qBAAqB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,uFAAuF;IACvF,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IACtE,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,EAC7B,MAAM,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,QAAQ,GACX,EAAE,qBAAqB,+BAoCvB"}
|
package/dist/ParametersDialog.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
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 { getActionLabel } from "@panneau/intl";
|
|
5
|
+
import { Button, Dialog, usePanneauIntl } from "@panneau/ui";
|
|
5
6
|
import { Form } from "@panneau/forms";
|
|
6
7
|
import { jsx } from "react/jsx-runtime";
|
|
7
8
|
//#region src/ParametersDialog.tsx
|
|
@@ -11,107 +12,126 @@ import { jsx } from "react/jsx-runtime";
|
|
|
11
12
|
* by paths inside `values`) show on the fields, and other errors in the form.
|
|
12
13
|
*/
|
|
13
14
|
function ParametersDialog(t0) {
|
|
14
|
-
const $ = c(
|
|
15
|
+
const $ = c(39);
|
|
15
16
|
const { action, locales, onSubmit, onDone, onCancel } = t0;
|
|
16
17
|
const intl = usePanneauIntl();
|
|
17
|
-
const confirmLabel = typeof action.confirm === "object" && action.confirm.confirmLabel !== void 0 ? action.confirm.confirmLabel : action.label;
|
|
18
18
|
let t1;
|
|
19
|
-
if ($[0] !==
|
|
20
|
-
t1 = (
|
|
19
|
+
if ($[0] !== action || $[1] !== intl) {
|
|
20
|
+
t1 = typeof action.confirm === "object" && action.confirm.confirmLabel !== void 0 ? action.confirm.confirmLabel : getActionLabel(action, intl);
|
|
21
|
+
$[0] = action;
|
|
22
|
+
$[1] = intl;
|
|
23
|
+
$[2] = t1;
|
|
24
|
+
} else t1 = $[2];
|
|
25
|
+
const confirmLabel = t1;
|
|
26
|
+
let t2;
|
|
27
|
+
if ($[3] !== onCancel) {
|
|
28
|
+
t2 = (open) => {
|
|
21
29
|
if (!open) onCancel();
|
|
22
30
|
};
|
|
23
|
-
$[
|
|
24
|
-
$[
|
|
25
|
-
} else
|
|
26
|
-
const t2 = action.label;
|
|
31
|
+
$[3] = onCancel;
|
|
32
|
+
$[4] = t2;
|
|
33
|
+
} else t2 = $[4];
|
|
27
34
|
let t3;
|
|
28
|
-
if ($[
|
|
29
|
-
t3 = action
|
|
30
|
-
$[
|
|
31
|
-
$[
|
|
32
|
-
|
|
35
|
+
if ($[5] !== action || $[6] !== intl) {
|
|
36
|
+
t3 = getActionLabel(action, intl);
|
|
37
|
+
$[5] = action;
|
|
38
|
+
$[6] = intl;
|
|
39
|
+
$[7] = t3;
|
|
40
|
+
} else t3 = $[7];
|
|
33
41
|
let t4;
|
|
34
|
-
if ($[
|
|
35
|
-
t4 = action.
|
|
36
|
-
$[
|
|
37
|
-
$[
|
|
38
|
-
} else t4 = $[
|
|
42
|
+
if ($[8] !== action.fields) {
|
|
43
|
+
t4 = action.fields ?? [];
|
|
44
|
+
$[8] = action.fields;
|
|
45
|
+
$[9] = t4;
|
|
46
|
+
} else t4 = $[9];
|
|
39
47
|
let t5;
|
|
40
|
-
if ($[
|
|
41
|
-
t5 =
|
|
42
|
-
$[
|
|
43
|
-
$[
|
|
44
|
-
} else t5 = $[
|
|
45
|
-
|
|
48
|
+
if ($[10] !== action.layout) {
|
|
49
|
+
t5 = action.layout ?? [];
|
|
50
|
+
$[10] = action.layout;
|
|
51
|
+
$[11] = t5;
|
|
52
|
+
} else t5 = $[11];
|
|
53
|
+
let t6;
|
|
54
|
+
if ($[12] !== locales) {
|
|
55
|
+
t6 = locales !== void 0 ? { locales } : {};
|
|
56
|
+
$[12] = locales;
|
|
57
|
+
$[13] = t6;
|
|
58
|
+
} else t6 = $[13];
|
|
46
59
|
let t7;
|
|
47
|
-
if ($[
|
|
48
|
-
t7 = intl
|
|
49
|
-
$[
|
|
50
|
-
$[
|
|
51
|
-
|
|
60
|
+
if ($[14] !== action || $[15] !== intl) {
|
|
61
|
+
t7 = getActionLabel(action, intl);
|
|
62
|
+
$[14] = action;
|
|
63
|
+
$[15] = intl;
|
|
64
|
+
$[16] = t7;
|
|
65
|
+
} else t7 = $[16];
|
|
52
66
|
let t8;
|
|
53
|
-
if ($[
|
|
54
|
-
t8 =
|
|
67
|
+
if ($[17] !== intl) {
|
|
68
|
+
t8 = intl.formatMessage(messages.cancel);
|
|
69
|
+
$[17] = intl;
|
|
70
|
+
$[18] = t8;
|
|
71
|
+
} else t8 = $[18];
|
|
72
|
+
let t9;
|
|
73
|
+
if ($[19] !== onCancel || $[20] !== t8) {
|
|
74
|
+
t9 = /* @__PURE__ */ jsx(Button, {
|
|
55
75
|
variant: "secondary",
|
|
56
76
|
onPress: onCancel,
|
|
57
|
-
children:
|
|
77
|
+
children: t8
|
|
58
78
|
});
|
|
59
|
-
$[
|
|
60
|
-
$[
|
|
61
|
-
$[
|
|
62
|
-
} else
|
|
63
|
-
let t9;
|
|
64
|
-
if ($[13] !== onSubmit) {
|
|
65
|
-
t9 = (values) => onSubmit(values);
|
|
66
|
-
$[13] = onSubmit;
|
|
67
|
-
$[14] = t9;
|
|
68
|
-
} else t9 = $[14];
|
|
79
|
+
$[19] = onCancel;
|
|
80
|
+
$[20] = t8;
|
|
81
|
+
$[21] = t9;
|
|
82
|
+
} else t9 = $[21];
|
|
69
83
|
let t10;
|
|
70
|
-
if ($[
|
|
71
|
-
t10 = (
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
} else t10 = $[
|
|
84
|
+
if ($[22] !== onSubmit) {
|
|
85
|
+
t10 = (values) => onSubmit(values);
|
|
86
|
+
$[22] = onSubmit;
|
|
87
|
+
$[23] = t10;
|
|
88
|
+
} else t10 = $[23];
|
|
75
89
|
let t11;
|
|
76
|
-
if ($[
|
|
77
|
-
t11 =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
if ($[24] !== onDone) {
|
|
91
|
+
t11 = (outcome) => onDone(outcome);
|
|
92
|
+
$[24] = onDone;
|
|
93
|
+
$[25] = t11;
|
|
94
|
+
} else t11 = $[25];
|
|
95
|
+
let t12;
|
|
96
|
+
if ($[26] !== confirmLabel || $[27] !== t10 || $[28] !== t11 || $[29] !== t4 || $[30] !== t5 || $[31] !== t6 || $[32] !== t7 || $[33] !== t9) {
|
|
97
|
+
t12 = /* @__PURE__ */ jsx(Form, {
|
|
98
|
+
fields: t4,
|
|
99
|
+
layout: t5,
|
|
100
|
+
...t6,
|
|
101
|
+
"aria-label": t7,
|
|
82
102
|
submitLabel: confirmLabel,
|
|
83
|
-
actions:
|
|
84
|
-
onSubmit:
|
|
85
|
-
onSubmitted:
|
|
103
|
+
actions: t9,
|
|
104
|
+
onSubmit: t10,
|
|
105
|
+
onSubmitted: t11,
|
|
86
106
|
guardUnsavedChanges: false,
|
|
87
107
|
showSavedToast: false,
|
|
88
108
|
className: ActionRunner_module_default.parameters
|
|
89
109
|
});
|
|
90
|
-
$[
|
|
91
|
-
$[
|
|
92
|
-
$[
|
|
93
|
-
$[
|
|
94
|
-
$[
|
|
95
|
-
$[
|
|
96
|
-
$[
|
|
97
|
-
$[
|
|
98
|
-
$[
|
|
99
|
-
} else
|
|
100
|
-
let
|
|
101
|
-
if ($[
|
|
102
|
-
|
|
110
|
+
$[26] = confirmLabel;
|
|
111
|
+
$[27] = t10;
|
|
112
|
+
$[28] = t11;
|
|
113
|
+
$[29] = t4;
|
|
114
|
+
$[30] = t5;
|
|
115
|
+
$[31] = t6;
|
|
116
|
+
$[32] = t7;
|
|
117
|
+
$[33] = t9;
|
|
118
|
+
$[34] = t12;
|
|
119
|
+
} else t12 = $[34];
|
|
120
|
+
let t13;
|
|
121
|
+
if ($[35] !== t12 || $[36] !== t2 || $[37] !== t3) {
|
|
122
|
+
t13 = /* @__PURE__ */ jsx(Dialog, {
|
|
103
123
|
isOpen: true,
|
|
104
|
-
onOpenChange:
|
|
105
|
-
title:
|
|
124
|
+
onOpenChange: t2,
|
|
125
|
+
title: t3,
|
|
106
126
|
size: "md",
|
|
107
|
-
children:
|
|
127
|
+
children: t12
|
|
108
128
|
});
|
|
109
|
-
$[
|
|
110
|
-
$[
|
|
111
|
-
$[
|
|
112
|
-
$[
|
|
113
|
-
} else
|
|
114
|
-
return
|
|
129
|
+
$[35] = t12;
|
|
130
|
+
$[36] = t2;
|
|
131
|
+
$[37] = t3;
|
|
132
|
+
$[38] = t13;
|
|
133
|
+
} else t13 = $[38];
|
|
134
|
+
return t13;
|
|
115
135
|
}
|
|
116
136
|
//#endregion
|
|
117
137
|
export { ParametersDialog };
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"ParametersDialog.js","names":["Form","getActionLabel","Action","Button","Dialog","usePanneauIntl","styles","messages","ActionOutcome","ParametersDialogProps","action","count","locales","onSubmit","values","Record","Promise","onDone","outcome","onCancel","ParametersDialog","t0","$","_c","intl","t1","confirm","confirmLabel","undefined","t2","open","t3","t4","fields","t5","layout","t6","t7","t8","formatMessage","cancel","t9","t10","t11","t12","parameters","t13","_c","styles"],"sources":["../src/ParametersDialog.tsx"],"sourcesContent":["import { Form } from '@panneau/forms';\nimport { getActionLabel } from '@panneau/intl';\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 : getActionLabel(action, intl);\n return (\n <Dialog\n isOpen\n onOpenChange={(open) => {\n if (!open) {\n onCancel();\n }\n }}\n title={getActionLabel(action, intl)}\n size=\"md\"\n >\n <Form\n fields={action.fields ?? []}\n layout={action.layout ?? []}\n {...(locales !== undefined ? { locales } : {})}\n aria-label={getActionLabel(action, intl)}\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":";;;;;;;;;;;;;AAyBA,SAAOoB,iBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA0B,MAAA,EAAAb,QAAAE,SAAAC,UAAAI,QAAAE,aAAAE;CAO7B,MAAAG,OAAanB,eAAe;CAAE,IAAAoB;CAAA,IAAAH,EAAA,OAAAZ,UAAAY,EAAA,OAAAE,MAAA;EAE1BC,KAAA,OAAOf,OAAMgB,YAAa,YAAYhB,OAAMgB,QAAQC,iBAAkBC,KAAAA,IAChElB,OAAMgB,QAAQC,eACd1B,eAAeS,QAAQc,IAAI;EAACF,EAAA,KAAAZ;EAAAY,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CAHtC,MAAAK,eACIF;CAEmC,IAAAI;CAAA,IAAAP,EAAA,OAAAH,UAAA;EAIjBU,MAAAC,SAAA;GACV,IAAI,CAACA,MACDX,SAAS;EACZ;EACJG,EAAA,KAAAH;EAAAG,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,IAAAS;CAAA,IAAAT,EAAA,OAAAZ,UAAAY,EAAA,OAAAE,MAAA;EACMO,KAAA9B,eAAeS,QAAQc,IAAI;EAACF,EAAA,KAAAZ;EAAAY,EAAA,KAAAE;EAAAF,EAAA,KAAAS;CAAA,OAAAA,KAAAT,EAAA;CAAA,IAAAU;CAAA,IAAAV,EAAA,OAAAZ,OAAAuB,QAAA;EAIvBD,KAAAtB,OAAMuB,UAAN,CAAA;EAAmBX,EAAA,KAAAZ,OAAAuB;EAAAX,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAAA,IAAAY;CAAA,IAAAZ,EAAA,QAAAZ,OAAAyB,QAAA;EACnBD,KAAAxB,OAAMyB,UAAN,CAAA;EAAmBb,EAAA,MAA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B,OAAArB,EAAA,QAAAU,MAAAV,EAAA,QAAAY,MAAAZ,EAAA,QAAAc,MAAAd,EAAA,QAAAe,MAAAf,EAAA,QAAAmB,IAAA;EAZ9DG,MAAA,oBAAC,MAAD;GACY,QAAAZ;GACA,QAAAE;GAAmB,GACtBE;GACO,cAAAC;GACCV,aAAAA;GAET,SAAAc;GAIM,UAAAC;GACG,aAAAC;GACQ,qBAAA;GACL,gBAAA;GACL,WAAArC,4BAAMuC;EAAW,CAAA;EAC9BvB,EAAA,MAAAK;EAAAL,EAAA,MAAAoB;EAAApB,EAAA,MAAAqB;EAAArB,EAAA,MAAAU;EAAAV,EAAA,MAAAY;EAAAZ,EAAA,MAAAc;EAAAd,EAAA,MAAAe;EAAAf,EAAA,MAAAmB;EAAAnB,EAAA,MAAAsB;CAAA,OAAAA,MAAAtB,EAAA;CAAA,IAAAwB;CAAA,IAAAxB,EAAA,QAAAsB,OAAAtB,EAAA,QAAAO,MAAAP,EAAA,QAAAS,IAAA;EA1BNe,MAAA,oBAAC,QAAD;GACI,QAAA;GACc,cAAAjB;GAKP,OAAAE;GACF,MAAA;GAELa,UAAAA;EAVG,CAAA;EA2BEtB,EAAA,MAAAsB;EAAAtB,EAAA,MAAAO;EAAAP,EAAA,MAAAS;EAAAT,EAAA,MAAAwB;CAAA,OAAAA,MAAAxB,EAAA;CAAA,OA3BTwB;AA2BS"}
|
package/dist/ResultsDialog.js
CHANGED
|
@@ -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,
|
|
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 )}\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,SAAOa,cAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAuB,MAAA,EAAAN,OAAAC,QAAAC,YAAAE;CAC1B,MAAAG,OAAab,eAAe;CAAE,IAAAc;CAAA,IAAAH,EAAA,OAAAE,QAAAF,EAAA,OAAAL,SAAAK,EAAA,OAAAJ,QAA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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>;
|
package/dist/context.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/describe.js.map
CHANGED
|
@@ -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,
|
|
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,9 +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 {
|
|
7
|
-
export
|
|
8
|
-
export {
|
|
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';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,KAAK,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC/E,YAAY,EACR,aAAa,EACb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,5 +4,6 @@ import { describeItemResult, describeResult } from "./describe.js";
|
|
|
4
4
|
import { ResultsDialog } from "./ResultsDialog.js";
|
|
5
5
|
import { ActionRunnerProvider } from "./ActionRunnerProvider.js";
|
|
6
6
|
import { ActionRuns } from "./ActionRuns.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { canPreviewAction, previewAction } from "./preview.js";
|
|
8
|
+
import { useActionPreview, useActionRunner, useActionRuns } from "./useActionRunner.js";
|
|
9
|
+
export { ActionRunnerProvider, ActionRuns, ParametersDialog, ResultsDialog, buildActionRequest, canPreviewAction, describeItemResult, describeResult, getLinkTarget, getResultCounts, previewAction, useActionPreview, useActionRunner, useActionRuns };
|