@panneau/core 5.0.0-alpha.16 → 5.0.0-alpha.18

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 CHANGED
@@ -28,7 +28,7 @@ function EditPage({ item, onSave }) {
28
28
 
29
29
  ## Plugins
30
30
 
31
- `definePlugin()` declares what a plugin adds, keyed by the names the definition uses: `fields`, `displays`, `listLayouts`, `actions` (handlers of `client` actions), `pages`, `widgets`, `components` (layout nodes), `locales` and `themes`.
31
+ `definePlugin()` declares what a plugin adds, keyed by the names the definition uses: `fields`, `displays`, `listLayouts`, `actions` (handlers of `client` actions), `pages`, `widgets`, `components` (layout nodes), `locales` and `themes`. A widget of a plugin gets `WidgetProps`: the widget, its data from `GET /dashboard/widgets/{widget}`, and the definition; the dashboard draws its card, skeleton and error ([decision 0064](../../docs/decisions/0064-dashboard-widgets.md)).
32
32
 
33
33
  `resolveTheme(definition.theme, registry.themes)` returns the theme of the admin: the themes of plugins that the definition's theme `extends`, by id, then its own tokens, tones and variants. `Theme` is the theme of `@panneau/ui` as plain data, the `Theme` schema of `@panneau/protocol`.
34
34
 
@@ -53,6 +53,12 @@ export interface ResolvedList {
53
53
  export declare const DEFAULT_PER_PAGE = 20;
54
54
  /** How many items a calendar asks for a month, without its own `perPage`. */
55
55
  export declare const DEFAULT_CALENDAR_PER_PAGE = 100;
56
+ /**
57
+ * Whether running an action asks first (decisions 0017 and 0063): its `confirm`, when it sets one;
58
+ * otherwise, for an `undoable` action, only above `UNDO_LIMIT` items or for a queued one, which
59
+ * can't be undone. `count` is the number of items, from the selection or a dry run.
60
+ */
61
+ export declare function asksConfirmation(action: Action, count?: number): boolean;
56
62
  /** Groups the actions the user can run by placement. */
57
63
  export declare function groupActions(actions: readonly Action[]): Record<ActionPlacement, Action[]>;
58
64
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/definition/list.ts"],"names":[],"mappings":"AAAA,OAAO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,EAAE,MAAM,EAAE,CAAC,CAM1F;AAkBD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE,CAwB/D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,CA4D5D"}
@@ -1,5 +1,5 @@
1
1
  import { canRunAction, canUpdateField, canViewField, getActionPlacements } from "./abilities.js";
2
- import { BUILT_IN_ITEM_ACTIONS, isBuiltInItemAction } from "@panneau/protocol/runtime";
2
+ import { BUILT_IN_ITEM_ACTIONS, UNDO_LIMIT, isBuiltInItemAction } from "@panneau/protocol/runtime";
3
3
  //#region src/definition/list.ts
4
4
  /** Fields shown when the list declares no columns. */
5
5
  var DEFAULT_COLUMN_COUNT = 4;
@@ -16,6 +16,15 @@ function columnsFromFields(resource) {
16
16
  const fields = resource.fields.filter((field) => !NON_COLUMN_TYPES.has(field.type) && canViewField(field));
17
17
  return (title !== void 0 ? [...fields.filter((field) => field.name === title), ...fields.filter((field) => field.name !== title)] : fields).slice(0, DEFAULT_COLUMN_COUNT).map((field) => ({ field: field.name }));
18
18
  }
19
+ /**
20
+ * Whether running an action asks first (decisions 0017 and 0063): its `confirm`, when it sets one;
21
+ * otherwise, for an `undoable` action, only above `UNDO_LIMIT` items or for a queued one, which
22
+ * can't be undone. `count` is the number of items, from the selection or a dry run.
23
+ */
24
+ function asksConfirmation(action, count = 1) {
25
+ if (action.confirm !== void 0) return action.confirm !== false;
26
+ return action.undoable === true && (count > UNDO_LIMIT || action.queued === true);
27
+ }
19
28
  /** Groups the actions the user can run by placement. */
20
29
  function groupActions(actions) {
21
30
  const groups = {
@@ -75,10 +84,16 @@ function getResourceActions(resource) {
75
84
  const declared = resource.actions ?? [];
76
85
  return [...(resource.itemActions ?? BUILT_IN_ITEM_ACTIONS).filter((id, index, all) => isBuiltInItemAction(id) && all.indexOf(id) === index && !(id === "show" && getOpenMode(resource) === "edit")).map((id) => {
77
86
  const replacement = declared.find((action) => action.id === id);
78
- return replacement !== void 0 ? {
79
- ...BUILT_IN_ITEM_ACTION_DEFINITIONS[id],
87
+ if (replacement === void 0) return BUILT_IN_ITEM_ACTION_DEFINITIONS[id];
88
+ const { confirm, ...builtIn } = BUILT_IN_ITEM_ACTION_DEFINITIONS[id];
89
+ return replacement.undoable === true ? {
90
+ ...builtIn,
80
91
  ...replacement
81
- } : BUILT_IN_ITEM_ACTION_DEFINITIONS[id];
92
+ } : {
93
+ ...builtIn,
94
+ ...confirm !== void 0 ? { confirm } : {},
95
+ ...replacement
96
+ };
82
97
  }), ...declared.filter((action) => !isBuiltInItemAction(action.id))];
83
98
  }
84
99
  /**
@@ -141,6 +156,6 @@ function resolveList(resource) {
141
156
  };
142
157
  }
143
158
  //#endregion
144
- export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, getOpenMode, getResourceActions, groupActions, resolveList };
159
+ export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, asksConfirmation, getOpenMode, getResourceActions, groupActions, resolveList };
145
160
 
146
161
  //# sourceMappingURL=list.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","names":["Action","ActionPlacement","Column","Field","Filter","Resource","BUILT_IN_ITEM_ACTIONS","BuiltInItemAction","isBuiltInItemAction","canRunAction","canUpdateField","canViewField","getActionPlacements","ResolvedColumn","id","field","label","display","sortable","width","align","hidden","hideable","ResolvedCalendar","filter","perPage","ResolvedList","columns","filters","sorts","defaultSort","search","layouts","perPageOptions","pagination","inlineEdit","selectable","actions","Record","calendar","DEFAULT_COLUMN_COUNT","NON_COLUMN_TYPES","Set","DEFAULT_PER_PAGE","DEFAULT_CALENDAR_PER_PAGE","columnsFromFields","resource","title","itemTitle","fields","has","type","ordered","undefined","name","slice","map","groupActions","groups","row","toolbar","form","menu","forEach","action","placement","push","BUILT_IN_ITEM_ACTION_DEFINITIONS","Readonly","show","kind","scope","edit","duplicate","delete","destructive","confirm","dryRun","getResourceActions","declared","ids","itemActions","index","all","indexOf","getOpenMode","replacement","find","open","resolveList","list","Map","sort","declaredColumns","column","get","resolved","includes","hasSelectionAction","some","split","part"],"sources":["../../src/definition/list.ts"],"sourcesContent":["import type { Action, ActionPlacement, Column, Field, Filter, Resource } from '@panneau/protocol';\nimport {\n BUILT_IN_ITEM_ACTIONS,\n type BuiltInItemAction,\n isBuiltInItemAction,\n} from '@panneau/protocol/runtime';\n\nimport { canRunAction, canUpdateField, canViewField, getActionPlacements } from './abilities';\n\n/** A column ready to render. */\nexport interface ResolvedColumn {\n /** The column id: its `id`, or the name of its field. */\n id: string;\n /** The field shown, when the column shows one. */\n field: Field | null;\n label: string;\n /** How the value is displayed: the column's display, the field's, or the field type. */\n display: string | null;\n sortable: boolean;\n width?: number | string;\n align?: 'start' | 'center' | 'end';\n /** Not shown until the user shows it (decision 0042). */\n hidden: boolean;\n /** Whether the user can hide it. */\n hideable: boolean;\n}\n\n/** The calendar of a list (decision 0044). */\nexport interface ResolvedCalendar {\n /** The `date` or `datetime` field each item is shown on the day of. */\n field: string;\n /** The id of the `date-range` filter the calendar asks for a month through. */\n filter: string;\n /** How many items the calendar asks for a month. */\n perPage: number;\n}\n\n/** A list ready to render. */\nexport interface ResolvedList {\n columns: ResolvedColumn[];\n filters: Filter[];\n /** Fields the list can be sorted by. */\n sorts: string[];\n /** The default sort, as `sort` query values (`['-published_at', 'title']`). */\n defaultSort: string[];\n /** Whether the list can be searched (`q`). */\n search: boolean;\n /** List layouts, the first one being the default. */\n layouts: string[];\n perPage: number;\n perPageOptions: number[];\n /** `pages` (numbered, with a total), or `cursor`: the list follows the cursors of its pages. */\n pagination: 'pages' | 'cursor';\n /** Fields editable in the list. */\n inlineEdit: string[];\n /** Whether items can be selected: the list allows it and a selection action exists. */\n selectable: boolean;\n /** Actions the user can run, by placement. */\n actions: Record<ActionPlacement, Action[]>;\n /** The calendar of the list, for its `calendar` layout, or `null`. */\n calendar: ResolvedCalendar | null;\n}\n\n/** Fields shown when the list declares no columns. */\nconst DEFAULT_COLUMN_COUNT = 4;\nconst NON_COLUMN_TYPES = new Set(['group', 'repeater', 'richtext']);\n\nexport const DEFAULT_PER_PAGE = 20;\n\n/** How many items a calendar asks for a month, without its own `perPage`. */\nexport const DEFAULT_CALENDAR_PER_PAGE = 100;\n\nfunction columnsFromFields(resource: Resource): Column[] {\n const title = resource.itemTitle;\n const fields = resource.fields.filter(\n (field) => !NON_COLUMN_TYPES.has(field.type) && canViewField(field),\n );\n const ordered =\n title !== undefined\n ? [\n ...fields.filter((field) => field.name === title),\n ...fields.filter((field) => field.name !== title),\n ]\n : fields;\n return ordered.slice(0, DEFAULT_COLUMN_COUNT).map((field) => ({ field: field.name }));\n}\n\n/** Groups the actions the user can run by placement. */\nexport function groupActions(actions: readonly Action[]): Record<ActionPlacement, Action[]> {\n const groups: Record<ActionPlacement, Action[]> = { row: [], toolbar: [], form: [], menu: [] };\n actions.filter(canRunAction).forEach((action) => {\n getActionPlacements(action).forEach((placement) => groups[placement].push(action));\n });\n return groups;\n}\n\n/** The built-in item actions, as the client shows them when a resource doesn't replace them. */\nconst BUILT_IN_ITEM_ACTION_DEFINITIONS: Readonly<Record<BuiltInItemAction, Action>> = {\n show: { id: 'show', kind: 'link', scope: ['item'], placement: ['row', 'form'] },\n edit: { id: 'edit', kind: 'link', scope: ['item'], placement: ['row', 'form'] },\n duplicate: { id: 'duplicate', kind: 'server', scope: ['item'], placement: ['menu', 'form'] },\n delete: {\n id: 'delete',\n kind: 'server',\n scope: ['item', 'selection'],\n placement: ['menu', 'toolbar', 'form'],\n destructive: true,\n confirm: true,\n dryRun: true,\n },\n};\n\n/**\n * The actions of a resource (decision 0040): its built-in item actions (`show`, `edit`,\n * `duplicate`, `delete`, or those of its `itemActions`, in their order), then the actions it\n * declares. A declared action with the id of a built-in one replaces it, at its place, with the\n * built-in one's placement, confirmation, `destructive` and `dryRun` when it doesn't set them, and\n * is left out with it when `itemActions` doesn't list it. With `\"open\": \"edit\"`, `show` is left out: it\n * would go to the edit form too. Abilities of the items then hide what they don't allow.\n */\nexport function getResourceActions(resource: Resource): Action[] {\n const declared = resource.actions ?? [];\n const ids = (resource.itemActions ?? BUILT_IN_ITEM_ACTIONS).filter(\n (id, index, all): id is BuiltInItemAction =>\n isBuiltInItemAction(id) &&\n all.indexOf(id) === index &&\n !(id === 'show' && getOpenMode(resource) === 'edit'),\n );\n return [\n ...ids.map((id): Action => {\n const replacement = declared.find((action) => action.id === id);\n // What the declared action doesn't set (placement, confirmation, dry runs) is the\n // built-in one's.\n return replacement !== undefined\n ? { ...BUILT_IN_ITEM_ACTION_DEFINITIONS[id], ...replacement }\n : BUILT_IN_ITEM_ACTION_DEFINITIONS[id];\n }),\n ...declared.filter((action) => !isBuiltInItemAction(action.id)),\n ];\n}\n\n/**\n * Where the title of an item goes (`open` of the resource, decision 0040): `panel`, the show route\n * with the item's details next to the list, or `edit`, its form. A value it doesn't know is `panel`.\n */\nexport function getOpenMode(resource: Resource): 'panel' | 'edit' {\n return resource.open === 'edit' ? 'edit' : 'panel';\n}\n\n/**\n * Resolves the list of a resource. Without columns, it shows the item title and the next fields\n * (up to four, skipping groups, repeaters and rich text). Fields the current user can't see\n * (`abilities.view: false`) have no column, sort or inline editing, and those they can't edit\n * aren't edited inline (decision 0046).\n */\nexport function resolveList(resource: Resource): ResolvedList {\n const list = resource.list ?? {};\n const fields = new Map(resource.fields.map((field) => [field.name, field]));\n const hidden = new Set(\n resource.fields.filter((field) => !canViewField(field)).map((field) => field.name),\n );\n const sorts = (list.sorts ?? []).filter((sort) => !hidden.has(sort));\n const declaredColumns = (list.columns ?? columnsFromFields(resource)).filter(\n (column) => column.field === undefined || !hidden.has(column.field),\n );\n const columns = declaredColumns.map((column): ResolvedColumn => {\n const field = column.field !== undefined ? (fields.get(column.field) ?? null) : null;\n const id = column.id ?? column.field ?? '';\n const resolved: ResolvedColumn = {\n id,\n field,\n label: column.label ?? field?.label ?? id,\n display: column.display ?? field?.display ?? field?.type ?? null,\n sortable:\n column.sortable ?? (column.field !== undefined && sorts.includes(column.field)),\n hidden: column.hidden === true && column.hideable !== false,\n hideable: column.hideable !== false,\n };\n if (column.width !== undefined) {\n resolved.width = column.width;\n }\n if (column.align !== undefined) {\n resolved.align = column.align;\n }\n return resolved;\n });\n const actions = groupActions(getResourceActions(resource));\n const hasSelectionAction = getResourceActions(resource).some(\n (action) => action.scope.includes('selection') && canRunAction(action),\n );\n return {\n columns,\n filters: list.filters ?? [],\n sorts,\n defaultSort: (list.defaultSort ?? '').split(',').filter((part) => part !== ''),\n search: list.search ?? false,\n layouts: list.layouts ?? ['table'],\n perPage: list.perPage ?? DEFAULT_PER_PAGE,\n perPageOptions: list.perPageOptions ?? [],\n pagination: list.pagination ?? 'pages',\n inlineEdit: (list.inlineEdit ?? []).filter((name) => {\n const field = fields.get(name);\n return field === undefined || canUpdateField(field);\n }),\n selectable: (list.selectable ?? true) && hasSelectionAction,\n actions,\n calendar:\n list.calendar !== undefined\n ? {\n field: list.calendar.field,\n filter: list.calendar.filter ?? list.calendar.field,\n perPage: list.calendar.perPage ?? DEFAULT_CALENDAR_PER_PAGE,\n }\n : null,\n };\n}\n"],"mappings":";;;;AAgEA,IAAMwC,uBAAuB;AAC7B,IAAMC,mCAAmB,IAAIC,IAAI;CAAC;CAAS;CAAY;AAAU,CAAC;AAElE,IAAaC,mBAAmB;;AAGhC,IAAaC,4BAA4B;AAEzC,SAASC,kBAAkBC,UAA8B;CACrD,MAAMC,QAAQD,SAASE;CACvB,MAAMC,SAASH,SAASG,OAAOzB,QAC1BT,UAAU,CAAC0B,iBAAiBS,IAAInC,MAAMoC,IAAI,KAAKxC,aAAaI,KAAK,CACtE;CAQA,QANIgC,UAAUM,KAAAA,IACJ,CACI,GAAGJ,OAAOzB,QAAQT,UAAUA,MAAMuC,SAASP,KA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AAKnD,aAAac,KAAAA,IACZ;GACItC,OAAO2E,KAAKnD,SAASxB;GACrBS,QAAQkE,KAAKnD,SAASf,UAAUkE,KAAKnD,SAASxB;GAC9CU,SAASiE,KAAKnD,SAASd,WAAAA;EAC3B,IACA;CACd;AACJ"}
1
+ {"version":3,"file":"list.js","names":["Action","ActionPlacement","Column","Field","Filter","Resource","BUILT_IN_ITEM_ACTIONS","BuiltInItemAction","UNDO_LIMIT","isBuiltInItemAction","canRunAction","canUpdateField","canViewField","getActionPlacements","ResolvedColumn","id","field","label","display","sortable","width","align","hidden","hideable","ResolvedCalendar","filter","perPage","ResolvedList","columns","filters","sorts","defaultSort","search","layouts","perPageOptions","pagination","inlineEdit","selectable","actions","Record","calendar","DEFAULT_COLUMN_COUNT","NON_COLUMN_TYPES","Set","DEFAULT_PER_PAGE","DEFAULT_CALENDAR_PER_PAGE","columnsFromFields","resource","title","itemTitle","fields","has","type","ordered","undefined","name","slice","map","asksConfirmation","action","count","confirm","undoable","queued","groupActions","groups","row","toolbar","form","menu","forEach","placement","push","BUILT_IN_ITEM_ACTION_DEFINITIONS","Readonly","show","kind","scope","edit","duplicate","delete","destructive","dryRun","getResourceActions","declared","ids","itemActions","index","all","indexOf","getOpenMode","replacement","find","builtIn","open","resolveList","list","Map","sort","declaredColumns","column","get","resolved","includes","hasSelectionAction","some","split","part"],"sources":["../../src/definition/list.ts"],"sourcesContent":["import type { Action, ActionPlacement, Column, Field, Filter, Resource } from '@panneau/protocol';\nimport {\n BUILT_IN_ITEM_ACTIONS,\n type BuiltInItemAction,\n UNDO_LIMIT,\n isBuiltInItemAction,\n} from '@panneau/protocol/runtime';\n\nimport { canRunAction, canUpdateField, canViewField, getActionPlacements } from './abilities';\n\n/** A column ready to render. */\nexport interface ResolvedColumn {\n /** The column id: its `id`, or the name of its field. */\n id: string;\n /** The field shown, when the column shows one. */\n field: Field | null;\n label: string;\n /** How the value is displayed: the column's display, the field's, or the field type. */\n display: string | null;\n sortable: boolean;\n width?: number | string;\n align?: 'start' | 'center' | 'end';\n /** Not shown until the user shows it (decision 0042). */\n hidden: boolean;\n /** Whether the user can hide it. */\n hideable: boolean;\n}\n\n/** The calendar of a list (decision 0044). */\nexport interface ResolvedCalendar {\n /** The `date` or `datetime` field each item is shown on the day of. */\n field: string;\n /** The id of the `date-range` filter the calendar asks for a month through. */\n filter: string;\n /** How many items the calendar asks for a month. */\n perPage: number;\n}\n\n/** A list ready to render. */\nexport interface ResolvedList {\n columns: ResolvedColumn[];\n filters: Filter[];\n /** Fields the list can be sorted by. */\n sorts: string[];\n /** The default sort, as `sort` query values (`['-published_at', 'title']`). */\n defaultSort: string[];\n /** Whether the list can be searched (`q`). */\n search: boolean;\n /** List layouts, the first one being the default. */\n layouts: string[];\n perPage: number;\n perPageOptions: number[];\n /** `pages` (numbered, with a total), or `cursor`: the list follows the cursors of its pages. */\n pagination: 'pages' | 'cursor';\n /** Fields editable in the list. */\n inlineEdit: string[];\n /** Whether items can be selected: the list allows it and a selection action exists. */\n selectable: boolean;\n /** Actions the user can run, by placement. */\n actions: Record<ActionPlacement, Action[]>;\n /** The calendar of the list, for its `calendar` layout, or `null`. */\n calendar: ResolvedCalendar | null;\n}\n\n/** Fields shown when the list declares no columns. */\nconst DEFAULT_COLUMN_COUNT = 4;\nconst NON_COLUMN_TYPES = new Set(['group', 'repeater', 'richtext']);\n\nexport const DEFAULT_PER_PAGE = 20;\n\n/** How many items a calendar asks for a month, without its own `perPage`. */\nexport const DEFAULT_CALENDAR_PER_PAGE = 100;\n\nfunction columnsFromFields(resource: Resource): Column[] {\n const title = resource.itemTitle;\n const fields = resource.fields.filter(\n (field) => !NON_COLUMN_TYPES.has(field.type) && canViewField(field),\n );\n const ordered =\n title !== undefined\n ? [\n ...fields.filter((field) => field.name === title),\n ...fields.filter((field) => field.name !== title),\n ]\n : fields;\n return ordered.slice(0, DEFAULT_COLUMN_COUNT).map((field) => ({ field: field.name }));\n}\n\n/**\n * Whether running an action asks first (decisions 0017 and 0063): its `confirm`, when it sets one;\n * otherwise, for an `undoable` action, only above `UNDO_LIMIT` items or for a queued one, which\n * can't be undone. `count` is the number of items, from the selection or a dry run.\n */\nexport function asksConfirmation(action: Action, count = 1): boolean {\n if (action.confirm !== undefined) {\n return action.confirm !== false;\n }\n return action.undoable === true && (count > UNDO_LIMIT || action.queued === true);\n}\n\n/** Groups the actions the user can run by placement. */\nexport function groupActions(actions: readonly Action[]): Record<ActionPlacement, Action[]> {\n const groups: Record<ActionPlacement, Action[]> = { row: [], toolbar: [], form: [], menu: [] };\n actions.filter(canRunAction).forEach((action) => {\n getActionPlacements(action).forEach((placement) => groups[placement].push(action));\n });\n return groups;\n}\n\n/** The built-in item actions, as the client shows them when a resource doesn't replace them. */\nconst BUILT_IN_ITEM_ACTION_DEFINITIONS: Readonly<Record<BuiltInItemAction, Action>> = {\n show: { id: 'show', kind: 'link', scope: ['item'], placement: ['row', 'form'] },\n edit: { id: 'edit', kind: 'link', scope: ['item'], placement: ['row', 'form'] },\n duplicate: { id: 'duplicate', kind: 'server', scope: ['item'], placement: ['menu', 'form'] },\n delete: {\n id: 'delete',\n kind: 'server',\n scope: ['item', 'selection'],\n placement: ['menu', 'toolbar', 'form'],\n destructive: true,\n confirm: true,\n dryRun: true,\n },\n};\n\n/**\n * The actions of a resource (decision 0040): its built-in item actions (`show`, `edit`,\n * `duplicate`, `delete`, or those of its `itemActions`, in their order), then the actions it\n * declares. A declared action with the id of a built-in one replaces it, at its place, with the\n * built-in one's placement, confirmation, `destructive` and `dryRun` when it doesn't set them, and\n * is left out with it when `itemActions` doesn't list it. With `\"open\": \"edit\"`, `show` is left out: it\n * would go to the edit form too. Abilities of the items then hide what they don't allow.\n */\nexport function getResourceActions(resource: Resource): Action[] {\n const declared = resource.actions ?? [];\n const ids = (resource.itemActions ?? BUILT_IN_ITEM_ACTIONS).filter(\n (id, index, all): id is BuiltInItemAction =>\n isBuiltInItemAction(id) &&\n all.indexOf(id) === index &&\n !(id === 'show' && getOpenMode(resource) === 'edit'),\n );\n return [\n ...ids.map((id): Action => {\n const replacement = declared.find((action) => action.id === id);\n // What the declared action doesn't set (placement, confirmation, dry runs) is the\n // built-in one's. An undoable one doesn't take the built-in confirmation (decision\n // 0063): \"Undo\" replaces it.\n if (replacement === undefined) {\n return BUILT_IN_ITEM_ACTION_DEFINITIONS[id];\n }\n const { confirm, ...builtIn } = BUILT_IN_ITEM_ACTION_DEFINITIONS[id];\n return replacement.undoable === true\n ? { ...builtIn, ...replacement }\n : { ...builtIn, ...(confirm !== undefined ? { confirm } : {}), ...replacement };\n }),\n ...declared.filter((action) => !isBuiltInItemAction(action.id)),\n ];\n}\n\n/**\n * Where the title of an item goes (`open` of the resource, decision 0040): `panel`, the show route\n * with the item's details next to the list, or `edit`, its form. A value it doesn't know is `panel`.\n */\nexport function getOpenMode(resource: Resource): 'panel' | 'edit' {\n return resource.open === 'edit' ? 'edit' : 'panel';\n}\n\n/**\n * Resolves the list of a resource. Without columns, it shows the item title and the next fields\n * (up to four, skipping groups, repeaters and rich text). Fields the current user can't see\n * (`abilities.view: false`) have no column, sort or inline editing, and those they can't edit\n * aren't edited inline (decision 0046).\n */\nexport function resolveList(resource: Resource): ResolvedList {\n const list = resource.list ?? {};\n const fields = new Map(resource.fields.map((field) => [field.name, field]));\n const hidden = new Set(\n resource.fields.filter((field) => !canViewField(field)).map((field) => field.name),\n );\n const sorts = (list.sorts ?? []).filter((sort) => !hidden.has(sort));\n const declaredColumns = (list.columns ?? columnsFromFields(resource)).filter(\n (column) => column.field === undefined || !hidden.has(column.field),\n );\n const columns = declaredColumns.map((column): ResolvedColumn => {\n const field = column.field !== undefined ? (fields.get(column.field) ?? null) : null;\n const id = column.id ?? column.field ?? '';\n const resolved: ResolvedColumn = {\n id,\n field,\n label: column.label ?? field?.label ?? id,\n display: column.display ?? field?.display ?? field?.type ?? null,\n sortable:\n column.sortable ?? (column.field !== undefined && sorts.includes(column.field)),\n hidden: column.hidden === true && column.hideable !== false,\n hideable: column.hideable !== false,\n };\n if (column.width !== undefined) {\n resolved.width = column.width;\n }\n if (column.align !== undefined) {\n resolved.align = column.align;\n }\n return resolved;\n });\n const actions = groupActions(getResourceActions(resource));\n const hasSelectionAction = getResourceActions(resource).some(\n (action) => action.scope.includes('selection') && canRunAction(action),\n );\n return {\n columns,\n filters: list.filters ?? [],\n sorts,\n defaultSort: (list.defaultSort ?? '').split(',').filter((part) => part !== ''),\n search: list.search ?? false,\n layouts: list.layouts ?? ['table'],\n perPage: list.perPage ?? DEFAULT_PER_PAGE,\n perPageOptions: list.perPageOptions ?? [],\n pagination: list.pagination ?? 'pages',\n inlineEdit: (list.inlineEdit ?? []).filter((name) => {\n const field = fields.get(name);\n return field === undefined || canUpdateField(field);\n }),\n selectable: (list.selectable ?? true) && hasSelectionAction,\n actions,\n calendar:\n list.calendar !== undefined\n ? {\n field: list.calendar.field,\n filter: list.calendar.filter ?? list.calendar.field,\n perPage: list.calendar.perPage ?? DEFAULT_CALENDAR_PER_PAGE,\n }\n : null,\n };\n}\n"],"mappings":";;;;AAiEA,IAAMyC,uBAAuB;AAC7B,IAAMC,mCAAmB,IAAIC,IAAI;CAAC;CAAS;CAAY;AAAU,CAAC;AAElE,IAAaC,mBAAmB;;AAGhC,IAAaC,4BAA4B;AAEzC,SAASC,kBAAkBC,UAA8B;CACrD,MAAMC,QAAQD,SAASE;CACvB,MAAMC,SAASH,SAASG,OAAOzB,QAC1BT,UAAU,CAAC0B,iBAAiBS,IAAInC,MAAMoC,IAAI,KAAKxC,aAAaI,KAAK,CACtE;CAQA,QANIgC,UAAUM,KAAAA,IACJ,CACI,GAAGJ,OAAOzB,QAAQT,UAAUA,MAAMuC,SAASP,KAAK,GAChD,GAAGE,OAAOzB,QAAQT,UAAUA,MAAMuC,SAASP,KAAK,CAAC,IAErDE,OAAAA,CACKM,MAAM,GAAGf,oBAAoB,CAAC,CAACgB,KAAKzC,WAAW,EAAEA,OAAOA,MAAMuC,KAAK,EAAE;AACxF;;;;;;AAOA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,SAAS;GACjD,MAAMvC,QAAQkC,OAAOmD,IAAI9C,IAAI;GAC7B,OAAOvC,UAAUsC,KAAAA,KAAa3C,eAAeK,KAAK;EACtD,CAAC;EACDqB,aAAa2D,KAAK3D,cAAc,SAASmE;EACzClE;EACAE,UACIwD,KAAKxD,aAAac,KAAAA,IACZ;GACItC,OAAOgF,KAAKxD,SAASxB;GACrBS,QAAQuE,KAAKxD,SAASf,UAAUuE,KAAKxD,SAASxB;GAC9CU,SAASsE,KAAKxD,SAASd,WAAAA;EAC3B,IACA;CACd;AACJ"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { can, canRunAction, canUpdateField, canViewField, canViewPage, getActionPlacements, getVisibleFields, isActionAllowedOn, partitionByAction, } from './definition/abilities.js';
2
2
  export { type ActionItem, type ItemAction, type ItemActionsOptions, type ItemSurface, fillActionUrl, getItemActions, selectItemActions, } from './definition/itemActions.js';
3
3
  export { type FormMode, type ResolveFormOptions, type ResolvedForm, getLayoutFieldNames, resolveFields, resolveForm, } from './definition/form.js';
4
- export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, type ResolvedCalendar, type ResolvedColumn, type ResolvedList, getOpenMode, getResourceActions, groupActions, resolveList, } from './definition/list.js';
4
+ export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, type ResolvedCalendar, type ResolvedColumn, type ResolvedList, asksConfirmation, getOpenMode, getResourceActions, groupActions, resolveList, } from './definition/list.js';
5
5
  export { type ResolvedResource, type ResourceAbilities, findResource, resolveResource, } from './definition/resource.js';
6
6
  export { type Form, type FormConflict, type FormOptions, type FormState, type FormStatus, type GetErrorsOptions, type SubmitContext, type SubmitResult, type UpdatableFormOptions, createForm, getDefaultValues, } from './form/form.js';
7
7
  export { formatRuleFailure } from './form/messages.js';
@@ -15,6 +15,7 @@ export { type MemoryRouter, type Router, createHistoryRouter, createMemoryRouter
15
15
  export { type Messages, type MessagesLoader, type PanneauPlugin, type PluginComponent, type PluginComponentKind, type PluginRegistry, type Theme, createPluginRegistry, definePlugin, loadMessages, resolveTheme, } from './plugins.js';
16
16
  export { type Command, type CommandContext, type CommandSource, getCommands, getSearchableResources, isSearchable, } from './commands.js';
17
17
  export { type PreviewProps } from './preview.js';
18
+ export { type WidgetProps } from './widget.js';
18
19
  export { type LeaveGuard, type LeaveGuards, LeaveGuardsProvider, type LeaveGuardsProviderProps, createLeaveGuards, useLeaveGuard, useLeaveGuards, } from './react/leaveGuards.js';
19
20
  export { PanneauProvider, type PanneauContextValue, type PanneauProviderProps, usePanneau, usePlugins, useResource, } from './react/provider.js';
20
21
  export { type UseFormFieldResult, type UseFormResult, useForm, useFormField, } from './react/useForm.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,GAAG,EACH,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,aAAa,EACb,cAAc,EACd,iBAAiB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,mBAAmB,EACnB,aAAa,EACb,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,YAAY,EACZ,eAAe,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAA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ACtB,YAAY,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EACH,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,aAAa,EACb,cAAc,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACH,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,UAAU,EACV,UAAU,EACV,WAAW,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,OAAO,EACP,YAAY,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,GAAG,EACH,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,WAAW,EAChB,aAAa,EACb,cAAc,EACd,iBAAiB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,mBAAmB,EACnB,aAAa,EACb,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,gBAAgB,EAChB,WAAW,EACX,kBA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AAK,EACV,oBAAoB,EACpB,YAAY,EACZ,YAAY,EACZ,YAAY,GACf,MAAM,WAAW,CAAC;AACnB,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,WAAW,EACX,sBAAsB,EACtB,YAAY,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EACH,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,iBAAiB,EACjB,aAAa,EACb,cAAc,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACH,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,UAAU,EACV,UAAU,EACV,WAAW,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,OAAO,EACP,YAAY,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,KAAK,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { can, canRunAction, canUpdateField, canViewField, canViewPage, getActionPlacements, getVisibleFields, isActionAllowedOn, partitionByAction } from "./definition/abilities.js";
2
- import { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, getOpenMode, getResourceActions, groupActions, resolveList } from "./definition/list.js";
2
+ import { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, asksConfirmation, getOpenMode, getResourceActions, groupActions, resolveList } from "./definition/list.js";
3
3
  import { fillActionUrl, getItemActions, selectItemActions } from "./definition/itemActions.js";
4
4
  import { getLayoutFieldNames, resolveFields, resolveForm } from "./definition/form.js";
5
5
  import { findResource, resolveResource } from "./definition/resource.js";
@@ -19,4 +19,4 @@ import { LeaveGuardsProvider, createLeaveGuards, useLeaveGuard, useLeaveGuards }
19
19
  import { PanneauProvider, usePanneau, usePlugins, useResource } from "./react/provider.js";
20
20
  import { useForm, useFormField } from "./react/useForm.js";
21
21
  import { useList } from "./react/useList.js";
22
- export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, LeaveGuardsProvider, PanneauProvider, can, canRunAction, canUpdateField, canViewField, canViewPage, createForm, createHistoryRouter, createLeaveGuards, createList, createLocalStore, createMemoryRouter, createPluginRegistry, createStorageViewStore, currentMonth, definePlugin, fillActionUrl, findResource, formatRuleFailure, getActionPlacements, getCalendarRange, getCommands, getDefaultValues, getItemActions, getItemValues, getLayoutFieldNames, getOpenMode, getProblem, getResourceActions, getSearchableResources, getVisibleFields, groupActions, isActionAllowedOn, isEqual, isItem, isMonth, isSearchable, loadMessages, partitionByAction, resolveFields, resolveForm, resolveList, resolveResource, resolveTheme, selectErrorCount, selectErrors, selectItemActions, selectValue, selectVisible, setValue, shiftMonth, useForm, useFormField, useLeaveGuard, useLeaveGuards, useList, usePanneau, usePlugins, useResource };
22
+ export { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, LeaveGuardsProvider, PanneauProvider, asksConfirmation, can, canRunAction, canUpdateField, canViewField, canViewPage, createForm, createHistoryRouter, createLeaveGuards, createList, createLocalStore, createMemoryRouter, createPluginRegistry, createStorageViewStore, currentMonth, definePlugin, fillActionUrl, findResource, formatRuleFailure, getActionPlacements, getCalendarRange, getCommands, getDefaultValues, getItemActions, getItemValues, getLayoutFieldNames, getOpenMode, getProblem, getResourceActions, getSearchableResources, getVisibleFields, groupActions, isActionAllowedOn, isEqual, isItem, isMonth, isSearchable, loadMessages, partitionByAction, resolveFields, resolveForm, resolveList, resolveResource, resolveTheme, selectErrorCount, selectErrors, selectItemActions, selectValue, selectVisible, setValue, shiftMonth, useForm, useFormField, useLeaveGuard, useLeaveGuards, useList, usePanneau, usePlugins, useResource };
package/dist/plugins.d.ts CHANGED
@@ -28,7 +28,10 @@ export interface PanneauPlugin {
28
28
  actions?: Record<string, PluginComponent>;
29
29
  /** Pages, by component name (`dashboard`). */
30
30
  pages?: Record<string, PluginComponent>;
31
- /** Dashboard widgets, by widget type (`stat`). */
31
+ /**
32
+ * Dashboard widgets, by widget type (`map`). They get `WidgetProps`. The built-in types
33
+ * (`stat`, `series`, `list`) stay built in: the `dashboard` page is what a plugin replaces.
34
+ */
32
35
  widgets?: Record<string, PluginComponent>;
33
36
  /** Layout node components, for `component` nodes of form layouts. */
34
37
  components?: Record<string, PluginComponent>;
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,sFAAsF;AACtF,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB;;;GAGG;AAEH,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEjD,oDAAoD;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,kFAAkF;AAClF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,GAAG;IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,CAAC;AAE1F,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC1B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,C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AAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkB9F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,eAAe,GAAG,SAAS,EAClC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,KAAK,CAWP"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":["ComponentType","DefinitionTheme","Theme","mergeThemes","CommandSource","PluginComponent","Messages","Record","MessagesLoader","Promise","default","PanneauPlugin","id","fields","displays","listLayouts","actions","pages","widgets","components","previews","commands","locales","themes","PluginComponentKind","COMPONENT_KINDS","PluginRegistry","plugins","ReadonlyMap","definePlugin","plugin","createPluginRegistry","ids","Set","forEach","has","Error","add","Object","fromEntries","map","kind","Map","flatMap","entries","locale","loader","set","get","undefined","loadMessages","registry","language","split","loaders","loaded","all","result","assign","resolveTheme","theme","colorScheme","_colorScheme","extends","own","extended","found","console","warn"],"sources":["../src/plugins.ts"],"sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DefinitionTheme, Theme } from '@panneau/protocol';\nimport { mergeThemes } from '@panneau/protocol/runtime';\n\nimport type { CommandSource } from './commands';\n\n/** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */\nexport type { Theme };\n\n/**\n * A component provided by a plugin. Its props are defined by the package that renders it (fields,\n * lists, app), so the registry stores it as given.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\nexport type PluginComponent = ComponentType<any>;\n\n/** UI messages of a locale, keyed by message id. */\nexport type Messages = Record<string, string>;\n\n/** Messages, or a function that loads them (`() => import('./lang/fr.json')`). */\nexport type MessagesLoader = Messages | (() => Promise<Messages | { default: Messages }>);\n\n/** What a plugin adds to Panneau. Every part is keyed by the name the definition uses. */\nexport interface PanneauPlugin {\n /** Unique id of the plugin. */\n id: string;\n /** Field components, by field type (`text`, `page-slug`). */\n fields?: Record<string, PluginComponent>;\n /** Components that display a value in lists, by display (`date`, `page-slug`). */\n displays?: Record<string, PluginComponent>;\n /** List layouts, by id (`table`, `cards`). */\n listLayouts?: Record<string, PluginComponent>;\n /** Handlers of `client` actions, by the action's `component`. */\n actions?: Record<string, PluginComponent>;\n /** Pages, by component name (`dashboard`). */\n pages?: Record<string, PluginComponent>;\n /** Dashboard widgets, by widget type (`stat`). */\n widgets?: Record<string, PluginComponent>;\n /** Layout node components, for `component` nodes of form layouts. */\n components?: Record<string, PluginComponent>;\n /**\n * Previews of items, by name, for resources whose `features.preview` is a `component`\n * (`{ \"mode\": \"component\", \"component\": \"page\" }`). They get `PreviewProps`.\n */\n previews?: Record<string, PluginComponent>;\n /** Commands of the \"Go to…\" palette, or a function that makes them for the definition. */\n commands?: CommandSource;\n /** UI messages, by locale. Messages of later plugins override earlier ones. */\n locales?: Record<string, MessagesLoader>;\n /** Themes, by id, that the theme of the definition can extend. */\n themes?: Record<string, Theme>;\n}\n\n/** The kinds of components a plugin can provide. */\nexport type PluginComponentKind =\n | 'fields'\n | 'displays'\n | 'listLayouts'\n | 'actions'\n | 'pages'\n | 'widgets'\n | 'components'\n | 'previews';\n\nconst COMPONENT_KINDS: PluginComponentKind[] = [\n 'fields',\n 'displays',\n 'listLayouts',\n 'actions',\n 'pages',\n 'widgets',\n 'components',\n 'previews',\n];\n\n/** Everything the plugins provide, merged. A later plugin overrides an earlier one. */\nexport interface PluginRegistry {\n /** The plugins, in order. */\n plugins: readonly PanneauPlugin[];\n fields: ReadonlyMap<string, PluginComponent>;\n displays: ReadonlyMap<string, PluginComponent>;\n listLayouts: ReadonlyMap<string, PluginComponent>;\n actions: ReadonlyMap<string, PluginComponent>;\n pages: ReadonlyMap<string, PluginComponent>;\n widgets: ReadonlyMap<string, PluginComponent>;\n components: ReadonlyMap<string, PluginComponent>;\n previews: ReadonlyMap<string, PluginComponent>;\n /** The commands of the plugins, in plugin order: `getCommands()` makes them. */\n commands: readonly CommandSource[];\n /** Message loaders of each locale, in plugin order. */\n locales: ReadonlyMap<string, readonly MessagesLoader[]>;\n themes: ReadonlyMap<string, Theme>;\n}\n\n/** Declares a plugin. It returns the plugin as is, with its type checked. */\nexport function definePlugin(plugin: PanneauPlugin): PanneauPlugin {\n return plugin;\n}\n\n/**\n * Merges plugins into a registry. Later plugins override the components and themes of earlier\n * ones, so a project can replace a built-in field. Plugin ids must be unique.\n */\nexport function createPluginRegistry(plugins: readonly PanneauPlugin[]): PluginRegistry {\n const ids = new Set<string>();\n plugins.forEach((plugin) => {\n if (ids.has(plugin.id)) {\n throw new Error(`Two plugins have the id \\`${plugin.id}\\`.`);\n }\n ids.add(plugin.id);\n });\n const components = Object.fromEntries(\n COMPONENT_KINDS.map((kind) => [\n kind,\n new Map(plugins.flatMap((plugin) => Object.entries(plugin[kind] ?? {}))),\n ]),\n ) as Record<PluginComponentKind, Map<string, PluginComponent>>;\n const locales = new Map<string, MessagesLoader[]>();\n plugins.forEach((plugin) =>\n Object.entries(plugin.locales ?? {}).forEach(([locale, loader]) => {\n locales.set(locale, [...(locales.get(locale) ?? []), loader]);\n }),\n );\n return {\n plugins: [...plugins],\n ...components,\n locales,\n themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {}))),\n commands: plugins.flatMap((plugin) =>\n plugin.commands !== undefined ? [plugin.commands] : [],\n ),\n };\n}\n\n/**\n * Loads the messages of a locale from every plugin that provides it, merged in plugin order. A\n * regional locale (`fr-CA`) falls back to its language (`fr`) for missing messages.\n */\nexport async function loadMessages(registry: PluginRegistry, locale: string): Promise<Messages> {\n const language = locale.split('-')[0] ?? locale;\n const loaders = [\n ...(language !== locale ? (registry.locales.get(language) ?? []) : []),\n ...(registry.locales.get(locale) ?? []),\n ];\n const loaded = await Promise.all(\n loaders.map(async (loader) => {\n if (typeof loader !== 'function') {\n return loader;\n }\n const result = await loader();\n return 'default' in result && typeof result.default === 'object'\n ? (result.default as Messages)\n : (result as Messages);\n }),\n );\n return Object.assign({}, ...loaded) as Messages;\n}\n\n/**\n * The theme of the admin: the themes of plugins that the definition's theme extends, in order, then\n * the definition's own tokens, tones and variants. An id no plugin registers is skipped, with a\n * warning.\n */\nexport function resolveTheme(\n theme: DefinitionTheme | undefined,\n themes: ReadonlyMap<string, Theme>,\n): Theme {\n const { colorScheme: _colorScheme, extends: ids, ...own } = theme ?? {};\n const extended = (typeof ids === 'string' ? [ids] : (ids ?? [])).flatMap((id) => {\n const found = themes.get(id);\n if (found === undefined) {\n console.warn(`[panneau] No plugin registers the theme \"${id}\".`);\n return [];\n }\n return [found];\n });\n return mergeThemes(...extended, own);\n}\n"],"mappings":";;AAiEA,IAAMyB,kBAAyC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAU;;AAuBd,SAAgBI,aAAaC,QAAsC;CAC/D,OAAOA;AACX;;;;;AAMA,SAAgBC,qBAAqBJ,SAAmD;CACpF,MAAMK,sBAAM,IAAIC,IAAY;CAC5BN,QAAQO,SAASJ,WAAW;EACxB,IAAIE,IAAIG,IAAIL,OAAOlB,EAAE,GACjB,MAAM,IAAIwB,MAAM,6BAA6BN,OAAOlB,GAAE,IAAK;EAE/DoB,IAAIK,IAAIP,OAAOlB,EAAE;CACrB,CAAC;CACD,MAAMO,aAAamB,OAAOC,YACtBd,gBAAgBe,KAAKC,SAAS,CAC1BA,MACA,IAAIC,IAAIf,QAAQgB,SAASb,WAAWQ,OAAOM,QAAQd,OAAOW,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3E,CACL;CACA,MAAMnB,0BAAU,IAAIoB,IAA8B;CAClDf,QAAQO,SAASJ,WACbQ,OAAOM,QAAQd,OAAOR,WAAW,CAAC,CAAC,CAAC,CAACY,SAAS,CAACW,QAAQC,YAAY;EAC/DxB,QAAQyB,IAAIF,QAAQ,CAAC,GAAIvB,QAAQ0B,IAAIH,MAAM,KAAK,CAAA,GAAKC,MAAM,CAAC;CAChE,CAAC,CACL;CACA,OAAO;EACHnB,SAAS,CAAC,GAAGA,OAAO;EACpB,GAAGR;EACHG;EACAC,QAAQ,IA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"plugins.js","names":["ComponentType","DefinitionTheme","Theme","mergeThemes","CommandSource","PluginComponent","Messages","Record","MessagesLoader","Promise","default","PanneauPlugin","id","fields","displays","listLayouts","actions","pages","widgets","components","previews","commands","locales","themes","PluginComponentKind","COMPONENT_KINDS","PluginRegistry","plugins","ReadonlyMap","definePlugin","plugin","createPluginRegistry","ids","Set","forEach","has","Error","add","Object","fromEntries","map","kind","Map","flatMap","entries","locale","loader","set","get","undefined","loadMessages","registry","language","split","loaders","loaded","all","result","assign","resolveTheme","theme","colorScheme","_colorScheme","extends","own","extended","found","console","warn"],"sources":["../src/plugins.ts"],"sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DefinitionTheme, Theme } from '@panneau/protocol';\nimport { mergeThemes } from '@panneau/protocol/runtime';\n\nimport type { CommandSource } from './commands';\n\n/** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */\nexport type { Theme };\n\n/**\n * A component provided by a plugin. Its props are defined by the package that renders it (fields,\n * lists, app), so the registry stores it as given.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\nexport type PluginComponent = ComponentType<any>;\n\n/** UI messages of a locale, keyed by message id. */\nexport type Messages = Record<string, string>;\n\n/** Messages, or a function that loads them (`() => import('./lang/fr.json')`). */\nexport type MessagesLoader = Messages | (() => Promise<Messages | { default: Messages }>);\n\n/** What a plugin adds to Panneau. Every part is keyed by the name the definition uses. */\nexport interface PanneauPlugin {\n /** Unique id of the plugin. */\n id: string;\n /** Field components, by field type (`text`, `page-slug`). */\n fields?: Record<string, PluginComponent>;\n /** Components that display a value in lists, by display (`date`, `page-slug`). */\n displays?: Record<string, PluginComponent>;\n /** List layouts, by id (`table`, `cards`). */\n listLayouts?: Record<string, PluginComponent>;\n /** Handlers of `client` actions, by the action's `component`. */\n actions?: Record<string, PluginComponent>;\n /** Pages, by component name (`dashboard`). */\n pages?: Record<string, PluginComponent>;\n /**\n * Dashboard widgets, by widget type (`map`). They get `WidgetProps`. The built-in types\n * (`stat`, `series`, `list`) stay built in: the `dashboard` page is what a plugin replaces.\n */\n widgets?: Record<string, PluginComponent>;\n /** Layout node components, for `component` nodes of form layouts. */\n components?: Record<string, PluginComponent>;\n /**\n * Previews of items, by name, for resources whose `features.preview` is a `component`\n * (`{ \"mode\": \"component\", \"component\": \"page\" }`). They get `PreviewProps`.\n */\n previews?: Record<string, PluginComponent>;\n /** Commands of the \"Go to…\" palette, or a function that makes them for the definition. */\n commands?: CommandSource;\n /** UI messages, by locale. Messages of later plugins override earlier ones. */\n locales?: Record<string, MessagesLoader>;\n /** Themes, by id, that the theme of the definition can extend. */\n themes?: Record<string, Theme>;\n}\n\n/** The kinds of components a plugin can provide. */\nexport type PluginComponentKind =\n | 'fields'\n | 'displays'\n | 'listLayouts'\n | 'actions'\n | 'pages'\n | 'widgets'\n | 'components'\n | 'previews';\n\nconst COMPONENT_KINDS: PluginComponentKind[] = [\n 'fields',\n 'displays',\n 'listLayouts',\n 'actions',\n 'pages',\n 'widgets',\n 'components',\n 'previews',\n];\n\n/** Everything the plugins provide, merged. A later plugin overrides an earlier one. */\nexport interface PluginRegistry {\n /** The plugins, in order. */\n plugins: readonly PanneauPlugin[];\n fields: ReadonlyMap<string, PluginComponent>;\n displays: ReadonlyMap<string, PluginComponent>;\n listLayouts: ReadonlyMap<string, PluginComponent>;\n actions: ReadonlyMap<string, PluginComponent>;\n pages: ReadonlyMap<string, PluginComponent>;\n widgets: ReadonlyMap<string, PluginComponent>;\n components: ReadonlyMap<string, PluginComponent>;\n previews: ReadonlyMap<string, PluginComponent>;\n /** The commands of the plugins, in plugin order: `getCommands()` makes them. */\n commands: readonly CommandSource[];\n /** Message loaders of each locale, in plugin order. */\n locales: ReadonlyMap<string, readonly MessagesLoader[]>;\n themes: ReadonlyMap<string, Theme>;\n}\n\n/** Declares a plugin. It returns the plugin as is, with its type checked. */\nexport function definePlugin(plugin: PanneauPlugin): PanneauPlugin {\n return plugin;\n}\n\n/**\n * Merges plugins into a registry. Later plugins override the components and themes of earlier\n * ones, so a project can replace a built-in field. Plugin ids must be unique.\n */\nexport function createPluginRegistry(plugins: readonly PanneauPlugin[]): PluginRegistry {\n const ids = new Set<string>();\n plugins.forEach((plugin) => {\n if (ids.has(plugin.id)) {\n throw new Error(`Two plugins have the id \\`${plugin.id}\\`.`);\n }\n ids.add(plugin.id);\n });\n const components = Object.fromEntries(\n COMPONENT_KINDS.map((kind) => [\n kind,\n new Map(plugins.flatMap((plugin) => Object.entries(plugin[kind] ?? {}))),\n ]),\n ) as Record<PluginComponentKind, Map<string, PluginComponent>>;\n const locales = new Map<string, MessagesLoader[]>();\n plugins.forEach((plugin) =>\n Object.entries(plugin.locales ?? {}).forEach(([locale, loader]) => {\n locales.set(locale, [...(locales.get(locale) ?? []), loader]);\n }),\n );\n return {\n plugins: [...plugins],\n ...components,\n locales,\n themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {}))),\n commands: plugins.flatMap((plugin) =>\n plugin.commands !== undefined ? [plugin.commands] : [],\n ),\n };\n}\n\n/**\n * Loads the messages of a locale from every plugin that provides it, merged in plugin order. A\n * regional locale (`fr-CA`) falls back to its language (`fr`) for missing messages.\n */\nexport async function loadMessages(registry: PluginRegistry, locale: string): Promise<Messages> {\n const language = locale.split('-')[0] ?? locale;\n const loaders = [\n ...(language !== locale ? (registry.locales.get(language) ?? []) : []),\n ...(registry.locales.get(locale) ?? []),\n ];\n const loaded = await Promise.all(\n loaders.map(async (loader) => {\n if (typeof loader !== 'function') {\n return loader;\n }\n const result = await loader();\n return 'default' in result && typeof result.default === 'object'\n ? (result.default as Messages)\n : (result as Messages);\n }),\n );\n return Object.assign({}, ...loaded) as Messages;\n}\n\n/**\n * The theme of the admin: the themes of plugins that the definition's theme extends, in order, then\n * the definition's own tokens, tones and variants. An id no plugin registers is skipped, with a\n * warning.\n */\nexport function resolveTheme(\n theme: DefinitionTheme | undefined,\n themes: ReadonlyMap<string, Theme>,\n): Theme {\n const { colorScheme: _colorScheme, extends: ids, ...own } = theme ?? {};\n const extended = (typeof ids === 'string' ? [ids] : (ids ?? [])).flatMap((id) => {\n const found = themes.get(id);\n if (found === undefined) {\n console.warn(`[panneau] No plugin registers the theme \"${id}\".`);\n return [];\n }\n return [found];\n });\n return mergeThemes(...extended, own);\n}\n"],"mappings":";;AAoEA,IAAMyB,kBAAyC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAU;;AAuBd,SAAgBI,aAAaC,QAAsC;CAC/D,OAAOA;AACX;;;;;AAMA,SAAgBC,qBAAqBJ,SAAmD;CACpF,MAAMK,sBAAM,IAAIC,IAAY;CAC5BN,QAAQO,SAASJ,WAAW;EACxB,IAAIE,IAAIG,IAAIL,OAAOlB,EAAE,GACjB,MAAM,IAAIwB,MAAM,6BAA6BN,OAAOlB,GAAE,IAAK;EAE/DoB,IAAIK,IAAIP,OAAOlB,EAAE;CACrB,CAAC;CACD,MAAMO,aAAamB,OAAOC,YACtBd,gBAAgBe,KAAKC,SAAS,CAC1BA,MACA,IAAIC,IAAIf,QAAQgB,SAASb,WAAWQ,OAAOM,QAAQd,OAAOW,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3E,CACL;CACA,MAAMnB,0BAAU,IAAIoB,IAA8B;CAClDf,QAAQO,SAASJ,WACbQ,OAAOM,QAAQd,OAAOR,WAAW,CAAC,CAAC,CAAC,CAACY,SAAS,CAACW,QAAQC,YAAY;EAC/DxB,QAAQyB,IAAIF,QAAQ,CAAC,GAAIvB,QAAQ0B,IAAIH,MAAM,KAAK,CAAA,GAAKC,MAAM,CAAC;CAChE,CAAC,CACL;CACA,OAAO;EACHnB,SAAS,CAAC,GAAGA,OAAO;EACpB,GAAGR;EACHG;EACAC,QAAQ,IAAImB,IAAIf,QAAQgB,SAASb,WAAWQ,OAAOM,QAAQd,OAAOP,UAAU,CAAC,CAAC,CAAC,CAAC;EAChFF,UAAUM,QAAQgB,SAASb,WACvBA,OAAOT,aAAa4B,KAAAA,IAAY,CAACnB,OAAOT,QAAQ,IAAI,CAAA,CACxD;CACJ;AACJ;;;;;AAMA,eAAsB6B,aAAaC,UAA0BN,QAAmC;CAC5F,MAAMO,WAAWP,OAAOQ,MAAM,GAAG,CAAC,CAAC,MAAMR;CACzC,MAAMS,UAAU,CACZ,GAAIF,aAAaP,SAAUM,SAAS7B,QAAQ0B,IAAII,QAAQ,KAAK,CAAA,IAAM,CAAA,GACnE,GAAID,SAAS7B,QAAQ0B,IAAIH,MAAM,KAAK,CAAA,CAAG;CAE3C,MAAMU,SAAS,MAAM9C,QAAQ+C,IACzBF,QAAQd,IAAI,OAAOM,WAAW;EAC1B,IAAI,OAAOA,WAAW,YAClB,OAAOA;EAEX,MAAMW,SAAS,MAAMX,OAAO;EAC5B,OAAO,aAAaW,UAAU,OAAOA,OAAO/C,YAAY,WACjD+C,OAAO/C,UACP+C;CACX,CAAC,CACL;CACA,OAAOnB,OAAOoB,OAAO,CAAC,GAAG,GAAGH,MAAM;AACtC;;;;;;AAOA,SAAgBI,aACZC,OACArC,QACK;CACL,MAAM,EAAEsC,aAAaC,cAAcC,SAAS/B,KAAK,GAAGgC,QAAQJ,SAAS,CAAC;CACtE,MAAMK,YAAY,OAAOjC,QAAQ,WAAW,CAACA,GAAG,IAAKA,OAAO,CAAA,EAAA,CAAKW,SAAS/B,OAAO;EAC7E,MAAMsD,QAAQ3C,OAAOyB,IAAIpC,EAAE;EAC3B,IAAIsD,UAAUjB,KAAAA,GAAW;GACrBkB,QAAQC,KAAK,4CAA4CxD,GAAE,GAAI;GAC/D,OAAO,CAAA;EACX;EACA,OAAO,CAACsD,KAAK;CACjB,CAAC;CACD,OAAO/D,YAAY,GAAG8D,UAAUD,GAAG;AACvC"}
@@ -0,0 +1,15 @@
1
+ import type { Definition, Widget } from '@panneau/protocol';
2
+ /**
3
+ * Props of a widget of a plugin (the `widgets` of a plugin), for a widget of the dashboard whose
4
+ * `type` it provides (decision 0064). The dashboard gets the data from
5
+ * `GET /dashboard/widgets/{widget}` and draws the frame, the label, the skeleton, the error with
6
+ * its retry, and nothing on a `403`: the component draws the data.
7
+ */
8
+ export interface WidgetProps {
9
+ /** The widget, as declared in the definition: its `settings` are the plugin's own. */
10
+ widget: Widget;
11
+ /** The data of the widget, in the shape the plugin's backend gives it. */
12
+ data: unknown;
13
+ definition: Definition;
14
+ }
15
+ //# sourceMappingURL=widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IACxB,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;CAC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/core",
3
- "version": "5.0.0-alpha.16",
3
+ "version": "5.0.0-alpha.18",
4
4
  "description": "The engine of Panneau: plugin registry, definition to forms and lists, form and list state, with React hooks. No UI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "react": "^19.2.0"
34
34
  },
35
35
  "dependencies": {
36
- "@panneau/protocol": "5.0.0-alpha.16"
36
+ "@panneau/protocol": "5.0.0-alpha.18"
37
37
  }
38
38
  }