@panneau/core 5.0.0-alpha.18 → 5.0.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/definition/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAU,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/definition/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAU,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAWlG,gCAAgC;AAChC,MAAM,WAAW,cAAc;IAC3B,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,kDAAkD;IAClD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IACnC,yDAAyD;IACzD,MAAM,EAAE,OAAO,CAAC;IAChB,oCAAoC;IACpC,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,8CAA8C;AAC9C,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1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@@
|
|
|
1
1
|
import { canRunAction, canUpdateField, canViewField, getActionPlacements } from "./abilities.js";
|
|
2
|
-
import { BUILT_IN_ITEM_ACTIONS, UNDO_LIMIT, isBuiltInItemAction } from "@panneau/protocol/runtime";
|
|
2
|
+
import { BUILT_IN_ITEM_ACTIONS, UNDO_LIMIT, getNestedShape, 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;
|
|
6
|
-
var NON_COLUMN_TYPES = /* @__PURE__ */ new Set([
|
|
7
|
-
"group",
|
|
8
|
-
"repeater",
|
|
9
|
-
"richtext"
|
|
10
|
-
]);
|
|
6
|
+
var NON_COLUMN_TYPES = /* @__PURE__ */ new Set(["richtext"]);
|
|
11
7
|
var DEFAULT_PER_PAGE = 20;
|
|
12
8
|
/** How many items a calendar asks for a month, without its own `perPage`. */
|
|
13
9
|
var DEFAULT_CALENDAR_PER_PAGE = 100;
|
|
14
10
|
function columnsFromFields(resource) {
|
|
15
11
|
const title = resource.itemTitle;
|
|
16
|
-
const fields = resource.fields.filter((field) => !NON_COLUMN_TYPES.has(field.type) && canViewField(field));
|
|
12
|
+
const fields = resource.fields.filter((field) => !NON_COLUMN_TYPES.has(field.type) && getNestedShape(field) === null && canViewField(field));
|
|
17
13
|
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
14
|
}
|
|
19
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
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,SAAgBG,iBAAiBC,QAAgBC,QAAQ,GAAY;CACjE,IAAID,OAAOE,YAAYP,KAAAA,GACnB,OAAOK,OAAOE,YAAY;CAE9B,OAAOF,OAAOG,aAAa,SAASF,QAAQpD,cAAcmD,OAAOI,WAAW;AAChF;;AAGA,SAAgBC,aAAa1B,SAA+D;CACxF,MAAM2B,SAA4C;EAAEC,KAAK,CAAA;EAAIC,SAAS,CAAA;EAAIC,MAAM,CAAA;EAAIC,MAAM,CAAA;CAAG;CAC7F/B,QAAQb,OAAOf,YAAY,CAAC,CAAC4D,SAASX,WAAW;EAC7C9C,oBA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js","names":["Action","ActionPlacement","Column","Field","Filter","Resource","BUILT_IN_ITEM_ACTIONS","BuiltInItemAction","UNDO_LIMIT","getNestedShape","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 getNestedShape,\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(['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) =>\n !NON_COLUMN_TYPES.has(field.type) &&\n getNestedShape(field) === null &&\n 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":";;;;AAkEA,IAAM0C,uBAAuB;AAC7B,IAAMC,mCAAmB,IAAIC,IAAI,CAAC,UAAU,CAAC;AAE7C,IAAaC,mBAAmB;;AAGhC,IAAaC,4BAA4B;AAEzC,SAASC,kBAAkBC,UAA8B;CACrD,MAAMC,QAAQD,SAASE;CACvB,MAAMC,SAASH,SAASG,OAAOzB,QAC1BT,UACG,CAAC0B,iBAAiBS,IAAInC,MAAMoC,IAAI,KAChC5C,eAAeQ,KAAK,MAAM,QAC1BJ,aAAaI,KAAK,CAC1B;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,SAAgBG,iBAAiBC,QAAgBC,QAAQ,GAAY;CACjE,IAAID,OAAOE,YAAYP,KAAAA,GACnB,OAAOK,OAAOE,YAAY;CAE9B,OAAOF,OAAOG,aAAa,SAASF,QAAQr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,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/core",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.19",
|
|
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.
|
|
36
|
+
"@panneau/protocol": "5.0.0-alpha.19"
|
|
37
37
|
}
|
|
38
38
|
}
|