@panneau/core 5.0.0-alpha.7 → 5.0.0-alpha.9
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/dist/definition/list.d.ts +2 -0
- package/dist/definition/list.d.ts.map +1 -1
- package/dist/definition/list.js +1 -0
- package/dist/definition/list.js.map +1 -1
- package/dist/definition/resource.d.ts +2 -2
- package/dist/form/form.d.ts +3 -3
- package/dist/form/problem.d.ts +1 -1
- package/dist/form/selectors.d.ts +1 -1
- package/dist/form/store.d.ts +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/list/list.d.ts +13 -2
- package/dist/list/list.d.ts.map +1 -1
- package/dist/list/list.js +37 -9
- package/dist/list/list.js.map +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/react/provider.d.ts +4 -4
- package/dist/react/useForm.d.ts +1 -1
- package/dist/react/useList.d.ts +1 -1
- package/package.json +4 -4
|
@@ -26,6 +26,8 @@ export interface ResolvedList {
|
|
|
26
26
|
layouts: string[];
|
|
27
27
|
perPage: number;
|
|
28
28
|
perPageOptions: number[];
|
|
29
|
+
/** `pages` (numbered, with a total), or `cursor`: the list follows the cursors of its pages. */
|
|
30
|
+
pagination: 'pages' | 'cursor';
|
|
29
31
|
/** Fields editable in the list. */
|
|
30
32
|
inlineEdit: string[];
|
|
31
33
|
/** Whether items can be selected: the list allows it and a selection action exists. */
|
|
@@ -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;AAIlG,gCAAgC;AAChC,MAAM,WAAW,cAAc;IAC3B,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,kDAAkD;IAClD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,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-59,6 +59,7 @@ function resolveList(resource) {
|
|
|
59
59
|
layouts: list.layouts ?? ["table"],
|
|
60
60
|
perPage: list.perPage ?? 20,
|
|
61
61
|
perPageOptions: list.perPageOptions ?? [],
|
|
62
|
+
pagination: list.pagination ?? "pages",
|
|
62
63
|
inlineEdit: list.inlineEdit ?? [],
|
|
63
64
|
selectable: (list.selectable ?? true) && hasSelectionAction,
|
|
64
65
|
actions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","names":["Action","ActionPlacement","Column","Field","Filter","Resource","canRunAction","getActionPlacements","ResolvedColumn","id","field","label","display","sortable","width","align","ResolvedList","columns","filters","sorts","defaultSort","search","layouts","perPage","perPageOptions","inlineEdit","selectable","actions","Record","DEFAULT_COLUMN_COUNT","NON_COLUMN_TYPES","Set","DEFAULT_PER_PAGE","columnsFromFields","resource","title","itemTitle","fields","filter","has","type","ordered","undefined","name","slice","map","groupActions","groups","row","toolbar","form","menu","forEach","action","placement","push","resolveList","list","Map","column","get","resolved","includes","hasSelectionAction","some","scope","split","part"],"sources":["../../src/definition/list.ts"],"sourcesContent":["import type { Action, ActionPlacement, Column, Field, Filter, Resource } from '@panneau/protocol';\n\nimport { canRunAction, 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}\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 /** 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}\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\nfunction columnsFromFields(resource: Resource): Column[] {\n const title = resource.itemTitle;\n const fields = resource.fields.filter((field) => !NON_COLUMN_TYPES.has(field.type));\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/**\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).\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 sorts = list.sorts ?? [];\n const columns = (list.columns ?? columnsFromFields(resource)).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 };\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(resource.actions ?? []);\n const hasSelectionAction = (resource.actions ?? []).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 inlineEdit: list.inlineEdit ?? [],\n selectable: (list.selectable ?? true) && hasSelectionAction,\n actions,\n };\n}\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"list.js","names":["Action","ActionPlacement","Column","Field","Filter","Resource","canRunAction","getActionPlacements","ResolvedColumn","id","field","label","display","sortable","width","align","ResolvedList","columns","filters","sorts","defaultSort","search","layouts","perPage","perPageOptions","pagination","inlineEdit","selectable","actions","Record","DEFAULT_COLUMN_COUNT","NON_COLUMN_TYPES","Set","DEFAULT_PER_PAGE","columnsFromFields","resource","title","itemTitle","fields","filter","has","type","ordered","undefined","name","slice","map","groupActions","groups","row","toolbar","form","menu","forEach","action","placement","push","resolveList","list","Map","column","get","resolved","includes","hasSelectionAction","some","scope","split","part"],"sources":["../../src/definition/list.ts"],"sourcesContent":["import type { Action, ActionPlacement, Column, Field, Filter, Resource } from '@panneau/protocol';\n\nimport { canRunAction, 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}\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}\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\nfunction columnsFromFields(resource: Resource): Column[] {\n const title = resource.itemTitle;\n const fields = resource.fields.filter((field) => !NON_COLUMN_TYPES.has(field.type));\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/**\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).\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 sorts = list.sorts ?? [];\n const columns = (list.columns ?? columnsFromFields(resource)).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 };\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(resource.actions ?? []);\n const hasSelectionAction = (resource.actions ?? []).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 ?? [],\n selectable: (list.selectable ?? true) && hasSelectionAction,\n actions,\n };\n}\n"],"mappings":";;;AA2CA,IAAM8B,uBAAuB;AAC7B,IAAMC,mCAAmB,IAAIC,IAAI;CAAC;CAAS;CAAY;AAAU,CAAC;AAElE,IAAaC,mBAAmB;AAEhC,SAASC,kBAAkBC,UAA8B;CACrD,MAAMC,QAAQD,SAASE;CACvB,MAAMC,SAASH,SAASG,OAAOC,QAAQ7B,UAAU,CAACqB,iBAAiBS,IAAI9B,MAAM+B,IAAI,CAAC;CAQlF,QANIL,UAAUO,KAAAA,IACJ,CACI,GAAGL,OAAOC,QAAQ7B,UAAUA,MAAMkC,SAASR,KAAK,GAChD,GAAGE,OAAOC,QAAQ7B,UAAUA,MAAMkC,SAASR,KAAK,CAAC,IAErDE,OAAAA,CACKO,MAAM,GAAGf,oBAAoB,CAAC,CAACgB,KAAKpC,WAAW,EAAEA,OAAOA,MAAMkC,KAAK,EAAE;AACxF;;AAGA,SAAgBG,aAAanB,SAA+D;CACxF,MAAMoB,SAA4C;EAAEC,KAAK,CAAA;EAAIC,SAAS,CAAA;EAAIC,MAAM,CAAA;EAAIC,MAAM,CAAA;CAAG;CAC7FxB,QAAQW,OAAOjC,YAAY,CAAC,CAAC+C,SAASC,WAAW;EAC7C/C,oBAAoB+C,MAAM,CAAC,CAACD,SAASE,cAAcP,OAAOO,UAAU,CAACC,KAAKF,MAAM,CAAC;CACrF,CAAC;CACD,OAAON;AACX;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C,KAAKrC,UAAU;EACvBC,SAASoC,KAAKpC,WAAW,CAAC,OAAO;EACjCC,SAASmC,KAAKnC,WAAAA;EACdC,gBAAgBkC,KAAKlC,kBAAkB,CAAA;EACvCC,YAAYiC,KAAKjC,cAAc;EAC/BC,YAAYgC,KAAKhC,cAAc,CAAA;EAC/BC,aAAa+B,KAAK/B,cAAc,SAASqC;EACzCpC;CACJ;AACJ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Definition, Resource } from '@panneau/protocol';
|
|
2
|
-
import { type ResolveFormOptions, type ResolvedForm } from './form';
|
|
3
|
-
import { type ResolvedList } from './list';
|
|
2
|
+
import { type ResolveFormOptions, type ResolvedForm } from './form.js';
|
|
3
|
+
import { type ResolvedList } from './list.js';
|
|
4
4
|
/** What the current user can do with a resource as a whole. */
|
|
5
5
|
export interface ResourceAbilities {
|
|
6
6
|
viewAny: boolean;
|
package/dist/form/form.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Condition, Field, Item, RuleFailure } from '@panneau/protocol';
|
|
2
|
-
import type { FormMode } from '../definition/form';
|
|
3
|
-
import { type Values } from '../values';
|
|
4
|
-
import { type FormStore } from './store';
|
|
2
|
+
import type { FormMode } from '../definition/form.js';
|
|
3
|
+
import { type Values } from '../values.js';
|
|
4
|
+
import { type FormStore } from './store.js';
|
|
5
5
|
/**
|
|
6
6
|
* - `idle`: nothing submitted yet, or after a reset;
|
|
7
7
|
* - `submitting`: waiting for `onSubmit`;
|
package/dist/form/problem.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Item, Problem } from '@panneau/protocol';
|
|
2
|
-
import type { Values } from '../values';
|
|
2
|
+
import type { Values } from '../values.js';
|
|
3
3
|
/**
|
|
4
4
|
* The problem details carried by an error: the error itself when it is a problem, or its
|
|
5
5
|
* `problem` property, as on the errors of `@panneau/data`. A custom adapter only needs to throw
|
package/dist/form/selectors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Condition } from '@panneau/protocol';
|
|
2
|
-
import type { FormState, GetErrorsOptions } from './form';
|
|
2
|
+
import type { FormState, GetErrorsOptions } from './form.js';
|
|
3
3
|
/** The value at a dot path (`title.fr`). */
|
|
4
4
|
export declare function selectValue(state: FormState, path: string): unknown;
|
|
5
5
|
/** Errors at a path, and with `nested` at the paths inside it (`title.fr` for `title`). */
|
package/dist/form/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Values } from '../values';
|
|
1
|
+
import { type Values } from '../values.js';
|
|
2
2
|
/**
|
|
3
3
|
* Where the values of a form live. The form only reads and writes values through this interface,
|
|
4
4
|
* so a shared store (Yjs, in `@panneau/collab`) can replace the local one. Errors, touched fields
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export { can, canRunAction, getActionPlacements, isActionAllowedOn, partitionByAction, } from './definition/abilities';
|
|
2
|
-
export { type FormMode, type ResolveFormOptions, type ResolvedForm, getLayoutFieldNames, resolveFields, resolveForm, } from './definition/form';
|
|
3
|
-
export { DEFAULT_PER_PAGE, type ResolvedColumn, type ResolvedList, groupActions, resolveList, } from './definition/list';
|
|
4
|
-
export { type ResolvedResource, type ResourceAbilities, findResource, resolveResource, } from './definition/resource';
|
|
5
|
-
export { type Form, type FormConflict, type FormOptions, type FormState, type FormStatus, type GetErrorsOptions, type SubmitContext, type SubmitResult, type UpdatableFormOptions, createForm, getDefaultValues, } from './form/form';
|
|
6
|
-
export { formatRuleFailure } from './form/messages';
|
|
7
|
-
export { getItemValues, getProblem, isItem } from './form/problem';
|
|
8
|
-
export { selectErrorCount, selectErrors, selectValue, selectVisible } from './form/selectors';
|
|
9
|
-
export { type FormStore, createLocalStore } from './form/store';
|
|
10
|
-
export { type List, type ListDefaults, type ListOptions, type ListSelection, type ListState, createList, } from './list/list';
|
|
11
|
-
export { type MemoryRouter, type Router, createHistoryRouter, createMemoryRouter, } from './list/router';
|
|
12
|
-
export { type Messages, type MessagesLoader, type PanneauPlugin, type PluginComponent, type PluginComponentKind, type PluginRegistry, type Theme, createPluginRegistry, definePlugin, loadMessages, resolveTheme, } from './plugins';
|
|
13
|
-
export { type Command, type CommandContext, type CommandSource, getCommands, getSearchableResources, isSearchable, } from './commands';
|
|
14
|
-
export { type PreviewProps } from './preview';
|
|
15
|
-
export { type LeaveGuard, type LeaveGuards, LeaveGuardsProvider, type LeaveGuardsProviderProps, createLeaveGuards, useLeaveGuard, useLeaveGuards, } from './react/leaveGuards';
|
|
16
|
-
export { PanneauProvider, type PanneauContextValue, type PanneauProviderProps, usePanneau, usePlugins, useResource, } from './react/provider';
|
|
17
|
-
export { type UseFormFieldResult, type UseFormResult, useForm, useFormField, } from './react/useForm';
|
|
18
|
-
export { type UseListResult, useList } from './react/useList';
|
|
19
|
-
export { type Values, isEqual, setValue } from './values';
|
|
1
|
+
export { can, canRunAction, getActionPlacements, isActionAllowedOn, partitionByAction, } from './definition/abilities.js';
|
|
2
|
+
export { type FormMode, type ResolveFormOptions, type ResolvedForm, getLayoutFieldNames, resolveFields, resolveForm, } from './definition/form.js';
|
|
3
|
+
export { DEFAULT_PER_PAGE, type ResolvedColumn, type ResolvedList, groupActions, resolveList, } from './definition/list.js';
|
|
4
|
+
export { type ResolvedResource, type ResourceAbilities, findResource, resolveResource, } from './definition/resource.js';
|
|
5
|
+
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';
|
|
6
|
+
export { formatRuleFailure } from './form/messages.js';
|
|
7
|
+
export { getItemValues, getProblem, isItem } from './form/problem.js';
|
|
8
|
+
export { selectErrorCount, selectErrors, selectValue, selectVisible } from './form/selectors.js';
|
|
9
|
+
export { type FormStore, createLocalStore } from './form/store.js';
|
|
10
|
+
export { type List, type ListDefaults, type ListOptions, type ListSelection, type ListState, createList, } from './list/list.js';
|
|
11
|
+
export { type MemoryRouter, type Router, createHistoryRouter, createMemoryRouter, } from './list/router.js';
|
|
12
|
+
export { type Messages, type MessagesLoader, type PanneauPlugin, type PluginComponent, type PluginComponentKind, type PluginRegistry, type Theme, createPluginRegistry, definePlugin, loadMessages, resolveTheme, } from './plugins.js';
|
|
13
|
+
export { type Command, type CommandContext, type CommandSource, getCommands, getSearchableResources, isSearchable, } from './commands.js';
|
|
14
|
+
export { type PreviewProps } from './preview.js';
|
|
15
|
+
export { type LeaveGuard, type LeaveGuards, LeaveGuardsProvider, type LeaveGuardsProviderProps, createLeaveGuards, useLeaveGuard, useLeaveGuards, } from './react/leaveGuards.js';
|
|
16
|
+
export { PanneauProvider, type PanneauContextValue, type PanneauProviderProps, usePanneau, usePlugins, useResource, } from './react/provider.js';
|
|
17
|
+
export { type UseFormFieldResult, type UseFormResult, useForm, useFormField, } from './react/useForm.js';
|
|
18
|
+
export { type UseListResult, useList } from './react/useList.js';
|
|
19
|
+
export { type Values, isEqual, setValue } from './values.js';
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/list/list.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FilterValue, ListQuery, Selection } from '@panneau/protocol';
|
|
2
|
-
import type { ResolvedList } from '../definition/list';
|
|
3
|
-
import type { Router } from './router';
|
|
2
|
+
import type { ResolvedList } from '../definition/list.js';
|
|
3
|
+
import type { Router } from './router.js';
|
|
4
4
|
/**
|
|
5
5
|
* Selected items: some ids, or every item matching the list query (filters and search) except
|
|
6
6
|
* some ids. "All matching" covers the items of every page.
|
|
@@ -37,6 +37,17 @@ export interface List {
|
|
|
37
37
|
getState(): ListState;
|
|
38
38
|
subscribe(listener: () => void): () => void;
|
|
39
39
|
setPage(page: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* In a list paged with cursors: goes to the page of `nextCursor`, and remembers the cursor of
|
|
42
|
+
* the page it leaves, for `previousPage()`.
|
|
43
|
+
*/
|
|
44
|
+
nextPage(cursor: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* In a list paged with cursors: goes back a page, to `previousCursor` when the backend gives
|
|
47
|
+
* one (`null` for the first page), or else to the page it came from. Without either, it goes
|
|
48
|
+
* to the first page.
|
|
49
|
+
*/
|
|
50
|
+
previousPage(cursor?: string | null): void;
|
|
40
51
|
/** Sets the page size, and goes back to the first page. */
|
|
41
52
|
setPerPage(perPage: number): void;
|
|
42
53
|
/** Sets the sort (`['-published_at', 'title']`), and goes back to the first page. */
|
package/dist/list/list.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/list/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEzF,MAAM,WAAW,SAAS;IACtB,gFAAgF;IAChF,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,aAAa,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IACxB,oEAAoE;IACpE,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,mDAAmD;IACnD,KAAK,CAAC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or. */
|
|
9
|
+
var FIRST_PAGE = {
|
|
10
|
+
page: 1,
|
|
11
|
+
cursor: void 0
|
|
12
|
+
};
|
|
13
|
+
var LIST_PARAM = /^(page|perPage|cursor|sort|q|fields|filter\[.+)$/;
|
|
9
14
|
/** Removes the values that are the defaults, so the URL only keeps what the user changed. */
|
|
10
15
|
function normalize(query, defaults) {
|
|
11
16
|
const result = {};
|
|
12
17
|
if (query.page !== void 0 && query.page > 1) result.page = query.page;
|
|
13
18
|
if (query.perPage !== void 0 && query.perPage !== defaults.perPage) result.perPage = query.perPage;
|
|
19
|
+
if (query.cursor !== void 0 && query.cursor !== "") result.cursor = query.cursor;
|
|
14
20
|
if (query.sort !== void 0 && !isEqual(query.sort, defaults.sort)) result.sort = [...query.sort];
|
|
15
21
|
const filter = Object.fromEntries(Object.entries(query.filter ?? {}).filter(([, value]) => value !== "" && !(Array.isArray(value) && value.length === 0) && !(isFilterRange(value) && Object.keys(value).length === 0)));
|
|
16
22
|
if (Object.keys(filter).length > 0) result.filter = filter;
|
|
@@ -28,10 +34,12 @@ function createList(options = {}) {
|
|
|
28
34
|
const readRouter = () => router !== null ? normalize(fromSearchParams(new URLSearchParams(router.getSearch())), defaults) : {};
|
|
29
35
|
let params = router !== null ? readRouter() : normalize(options.query ?? {}, defaults);
|
|
30
36
|
let selection = EMPTY_SELECTION;
|
|
37
|
+
let trail = [];
|
|
38
|
+
const cursors = options.list?.pagination === "cursor";
|
|
31
39
|
const compute = () => ({
|
|
32
40
|
query: {
|
|
33
41
|
...params,
|
|
34
|
-
page: params.page ?? 1,
|
|
42
|
+
...cursors ? {} : { page: params.page ?? 1 },
|
|
35
43
|
perPage: params.perPage ?? defaults.perPage,
|
|
36
44
|
...params.sort !== void 0 || defaults.sort.length > 0 ? { sort: params.sort ?? defaults.sort } : {}
|
|
37
45
|
},
|
|
@@ -55,6 +63,9 @@ function createList(options = {}) {
|
|
|
55
63
|
const normalized = normalize(next, defaults);
|
|
56
64
|
if (isEqual(normalized, params)) return;
|
|
57
65
|
const scopeChanged = !isEqual(normalized.filter, params.filter) || normalized.q !== params.q;
|
|
66
|
+
const { cursor: _next, ...nextQuery } = normalized;
|
|
67
|
+
const { cursor: _current, ...currentQuery } = params;
|
|
68
|
+
if (!isEqual(nextQuery, currentQuery)) trail = [];
|
|
58
69
|
params = normalized;
|
|
59
70
|
if (scopeChanged) selection = EMPTY_SELECTION;
|
|
60
71
|
writeRouter(replace);
|
|
@@ -95,33 +106,50 @@ function createList(options = {}) {
|
|
|
95
106
|
...params,
|
|
96
107
|
page
|
|
97
108
|
}),
|
|
109
|
+
nextPage(cursor) {
|
|
110
|
+
const current = params.cursor ?? null;
|
|
111
|
+
setParams({
|
|
112
|
+
...params,
|
|
113
|
+
cursor
|
|
114
|
+
});
|
|
115
|
+
trail = [...trail, current];
|
|
116
|
+
},
|
|
117
|
+
previousPage(cursor) {
|
|
118
|
+
const back = cursor !== void 0 ? cursor : trail.at(-1) ?? null;
|
|
119
|
+
const rest = trail.slice(0, -1);
|
|
120
|
+
setParams({
|
|
121
|
+
...params,
|
|
122
|
+
cursor: back ?? void 0
|
|
123
|
+
});
|
|
124
|
+
trail = rest;
|
|
125
|
+
},
|
|
98
126
|
setPerPage: (perPage) => setParams({
|
|
99
127
|
...params,
|
|
100
128
|
perPage,
|
|
101
|
-
|
|
129
|
+
...FIRST_PAGE
|
|
102
130
|
}),
|
|
103
131
|
setSort: (sort) => setParams({
|
|
104
132
|
...params,
|
|
105
133
|
sort: [...sort],
|
|
106
|
-
|
|
134
|
+
...FIRST_PAGE
|
|
107
135
|
}),
|
|
108
136
|
toggleSort(field) {
|
|
109
137
|
const sort = state.query.sort ?? [];
|
|
110
138
|
if (sort[0] === field) setParams({
|
|
111
139
|
...params,
|
|
112
140
|
sort: [`-${field}`],
|
|
113
|
-
|
|
141
|
+
...FIRST_PAGE
|
|
114
142
|
});
|
|
115
143
|
else if (sort[0] === `-${field}` && params.sort !== void 0) {
|
|
116
144
|
const { sort: _sort, ...rest } = params;
|
|
117
145
|
setParams({
|
|
118
146
|
...rest,
|
|
119
|
-
|
|
147
|
+
...FIRST_PAGE
|
|
120
148
|
});
|
|
121
149
|
} else setParams({
|
|
122
150
|
...params,
|
|
123
151
|
sort: [field],
|
|
124
|
-
|
|
152
|
+
...FIRST_PAGE
|
|
125
153
|
});
|
|
126
154
|
},
|
|
127
155
|
setFilter(id, value) {
|
|
@@ -132,13 +160,13 @@ function createList(options = {}) {
|
|
|
132
160
|
...filter,
|
|
133
161
|
[id]: value
|
|
134
162
|
},
|
|
135
|
-
|
|
163
|
+
...FIRST_PAGE
|
|
136
164
|
});
|
|
137
165
|
},
|
|
138
166
|
setSearch: (q) => setParams({
|
|
139
167
|
...params,
|
|
140
168
|
q,
|
|
141
|
-
|
|
169
|
+
...FIRST_PAGE
|
|
142
170
|
}, { replace: true }),
|
|
143
171
|
resetQuery: () => setParams({}),
|
|
144
172
|
select(ids) {
|
package/dist/list/list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","names":["FilterValue","ListQuery","Selection","fromSearchParams","isFilterRange","toSearchParams","ResolvedList","isEqual","Router","ListSelection","mode","ids","except","ListState","query","selection","ListDefaults","perPage","sort","ListOptions","list","defaults","router","List","getState","subscribe","listener","setPage","page","setPerPage","setSort","toggleSort","field","setFilter","id","value","setSearch","q","resetQuery","select","deselect","toggle","selectAllMatching","clearSelection","isSelected","getSelectedCount","total","getSelection","EMPTY_SELECTION","LIST_PARAM","normalize","Required","result","undefined","filter","Object","fromEntries","entries","Array","isArray","length","keys","fields","createList","options","defaultSort","readRouter","URLSearchParams","getSearch","params","compute","state","listeners","Set","notify","forEach","writeRouter","replace","search","key","test","delete","append","next","toString","setParams","normalized","scopeChanged","setSelection","unsubscribeRouter","onRouterChange","add","size","_sort","rest","_removed","includes","Math","max","Record"],"sources":["../../src/list/list.ts"],"sourcesContent":["import type { FilterValue, ListQuery, Selection } from '@panneau/protocol';\nimport { fromSearchParams, isFilterRange, toSearchParams } from '@panneau/protocol/runtime';\n\nimport type { ResolvedList } from '../definition/list';\nimport { isEqual } from '../values';\nimport type { Router } from './router';\n\n/**\n * Selected items: some ids, or every item matching the list query (filters and search) except\n * some ids. \"All matching\" covers the items of every page.\n */\nexport type ListSelection =\n { mode: 'ids'; ids: readonly string[] } | { mode: 'all'; except: readonly string[] };\n\nexport interface ListState {\n /** The query to fetch: the list's defaults, overridden by the current state. */\n query: ListQuery;\n selection: ListSelection;\n}\n\nexport interface ListDefaults {\n perPage?: number;\n /** Default sort, as `sort` query values (`['-published_at']`). */\n sort?: string[];\n}\n\nexport interface ListOptions {\n /** A resolved list, for the defaults (`perPage`, `defaultSort`). */\n list?: ResolvedList;\n /** Defaults, over those of `list`. Default values are not written to the URL. */\n defaults?: ListDefaults;\n /** The starting query, when there is no router. */\n query?: ListQuery;\n /** Keeps the query in the URL. The router's query string wins over `query`. */\n router?: Router | null;\n}\n\n/** A headless list: query and selection. React components use `useList()`. */\nexport interface List {\n getState(): ListState;\n subscribe(listener: () => void): () => void;\n setPage(page: number): void;\n /** Sets the page size, and goes back to the first page. */\n setPerPage(perPage: number): void;\n /** Sets the sort (`['-published_at', 'title']`), and goes back to the first page. */\n setSort(sort: readonly string[]): void;\n /** Sorts by a field: ascending, then descending, then back to the default sort. */\n toggleSort(field: string): void;\n /** Sets or removes (`undefined`) a filter, goes back to the first page, and clears the selection. */\n setFilter(id: string, value: FilterValue | undefined): void;\n /** Sets the search, goes back to the first page, and clears the selection. */\n setSearch(q: string): void;\n /** Removes the page, filters, search and sort: back to the defaults. */\n resetQuery(): void;\n /** Adds ids to the selection (removes them from the exceptions in \"all matching\" mode). */\n select(ids: readonly string[]): void;\n /** Removes ids from the selection (adds them to the exceptions in \"all matching\" mode). */\n deselect(ids: readonly string[]): void;\n toggle(id: string): void;\n /** Selects every item matching the query, on every page. */\n selectAllMatching(): void;\n clearSelection(): void;\n isSelected(id: string): boolean;\n /** How many items are selected, given the total of the list. */\n getSelectedCount(total: number): number;\n /** The selection to send with an action, or `null` when nothing is selected. */\n getSelection(): Selection | null;\n}\n\nconst EMPTY_SELECTION: ListSelection = { mode: 'ids', ids: [] };\nconst LIST_PARAM = /^(page|perPage|sort|q|fields|filter\\[.+)$/;\n\n/** Removes the values that are the defaults, so the URL only keeps what the user changed. */\nfunction normalize(query: ListQuery, defaults: Required<ListDefaults>): ListQuery {\n const result: ListQuery = {};\n if (query.page !== undefined && query.page > 1) {\n result.page = query.page;\n }\n if (query.perPage !== undefined && query.perPage !== defaults.perPage) {\n result.perPage = query.perPage;\n }\n if (query.sort !== undefined && !isEqual(query.sort, defaults.sort)) {\n result.sort = [...query.sort];\n }\n const filter = Object.fromEntries(\n Object.entries(query.filter ?? {}).filter(\n ([, value]) =>\n value !== '' &&\n !(Array.isArray(value) && value.length === 0) &&\n !(isFilterRange(value) && Object.keys(value).length === 0),\n ),\n );\n if (Object.keys(filter).length > 0) {\n result.filter = filter;\n }\n if (query.q !== undefined && query.q !== '') {\n result.q = query.q;\n }\n if (query.fields !== undefined) {\n result.fields = query.fields;\n }\n return result;\n}\n\n/** Creates a headless list. */\nexport function createList(options: ListOptions = {}): List {\n const defaults: Required<ListDefaults> = {\n perPage: options.defaults?.perPage ?? options.list?.perPage ?? 20,\n sort: options.defaults?.sort ?? options.list?.defaultSort ?? [],\n };\n const router = options.router ?? null;\n const readRouter = (): ListQuery =>\n router !== null\n ? normalize(fromSearchParams(new URLSearchParams(router.getSearch())), defaults)\n : {};\n\n let params: ListQuery =\n router !== null ? readRouter() : normalize(options.query ?? {}, defaults);\n let selection: ListSelection = EMPTY_SELECTION;\n\n const compute = (): ListState => ({\n query: {\n ...params,\n page: params.page ?? 1,\n perPage: params.perPage ?? defaults.perPage,\n ...(params.sort !== undefined || defaults.sort.length > 0\n ? { sort: params.sort ?? defaults.sort }\n : {}),\n },\n selection,\n });\n\n let state = compute();\n const listeners = new Set<() => void>();\n const notify = () => {\n state = compute();\n listeners.forEach((listener) => listener());\n };\n\n const writeRouter = (replace: boolean) => {\n if (router === null) {\n return;\n }\n const search = new URLSearchParams(router.getSearch());\n [...search.keys()]\n .filter((key) => LIST_PARAM.test(key))\n .forEach((key) => search.delete(key));\n toSearchParams(params).forEach((value, key) => search.append(key, value));\n const next = search.toString();\n if (next !== router.getSearch()) {\n router.setSearch(next, { replace });\n }\n };\n\n const setParams = (next: ListQuery, { replace = false } = {}) => {\n const normalized = normalize(next, defaults);\n if (isEqual(normalized, params)) {\n return;\n }\n const scopeChanged =\n !isEqual(normalized.filter, params.filter) || normalized.q !== params.q;\n params = normalized;\n if (scopeChanged) {\n selection = EMPTY_SELECTION;\n }\n writeRouter(replace);\n notify();\n };\n\n const setSelection = (next: ListSelection) => {\n selection = next;\n notify();\n };\n\n let unsubscribeRouter: (() => void) | null = null;\n const onRouterChange = () => {\n const next = readRouter();\n if (isEqual(next, params)) {\n return;\n }\n if (!isEqual(next.filter, params.filter) || next.q !== params.q) {\n selection = EMPTY_SELECTION;\n }\n params = next;\n notify();\n };\n\n const list: List = {\n getState() {\n if (router !== null && unsubscribeRouter === null) {\n onRouterChange();\n }\n return state;\n },\n subscribe(listener) {\n listeners.add(listener);\n if (router !== null && unsubscribeRouter === null) {\n unsubscribeRouter = router.subscribe(onRouterChange);\n onRouterChange();\n }\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0 && unsubscribeRouter !== null) {\n unsubscribeRouter();\n unsubscribeRouter = null;\n }\n };\n },\n setPage: (page) => setParams({ ...params, page }),\n setPerPage: (perPage) => setParams({ ...params, perPage, page: 1 }),\n setSort: (sort) => setParams({ ...params, sort: [...sort], page: 1 }),\n toggleSort(field) {\n const sort = state.query.sort ?? [];\n if (sort[0] === field) {\n setParams({ ...params, sort: [`-${field}`], page: 1 });\n } else if (sort[0] === `-${field}` && params.sort !== undefined) {\n const { sort: _sort, ...rest } = params;\n setParams({ ...rest, page: 1 });\n } else {\n setParams({ ...params, sort: [field], page: 1 });\n }\n },\n setFilter(id, value) {\n const { [id]: _removed, ...filter } = params.filter ?? {};\n setParams({\n ...params,\n filter: value === undefined ? filter : { ...filter, [id]: value },\n page: 1,\n });\n },\n setSearch: (q) => setParams({ ...params, q, page: 1 }, { replace: true }),\n resetQuery: () => setParams({}),\n select(ids) {\n if (selection.mode === 'all') {\n setSelection({\n mode: 'all',\n except: selection.except.filter((id) => !ids.includes(id)),\n });\n } else {\n setSelection({ mode: 'ids', ids: [...new Set([...selection.ids, ...ids])] });\n }\n },\n deselect(ids) {\n if (selection.mode === 'all') {\n setSelection({ mode: 'all', except: [...new Set([...selection.except, ...ids])] });\n } else {\n setSelection({ mode: 'ids', ids: selection.ids.filter((id) => !ids.includes(id)) });\n }\n },\n toggle(id) {\n if (list.isSelected(id)) {\n list.deselect([id]);\n } else {\n list.select([id]);\n }\n },\n selectAllMatching: () => setSelection({ mode: 'all', except: [] }),\n clearSelection: () => setSelection(EMPTY_SELECTION),\n isSelected: (id) =>\n selection.mode === 'all' ? !selection.except.includes(id) : selection.ids.includes(id),\n getSelectedCount: (total) =>\n selection.mode === 'all'\n ? Math.max(0, total - selection.except.length)\n : selection.ids.length,\n getSelection() {\n if (selection.mode === 'ids') {\n return selection.ids.length > 0 ? { ids: [...selection.ids] } : null;\n }\n const query: { filter?: Record<string, unknown>; q?: string } = {};\n if (params.filter !== undefined) {\n query.filter = params.filter;\n }\n if (params.q !== undefined) {\n query.q = params.q;\n }\n return selection.except.length > 0\n ? { query, except: [...selection.except] }\n : { query };\n },\n };\n return list;\n}\n"],"mappings":";;;AAqEA,IAAMgD,kBAAiC;CAAEtC,MAAM;CAAOC,KAAK,CAAA;AAAG;AAC9D,IAAMsC,aAAa;;AAGnB,SAASC,UAAUpC,OAAkBO,UAA6C;CAC9E,MAAM+B,SAAoB,CAAC;CAC3B,IAAItC,MAAMc,SAASyB,KAAAA,KAAavC,MAAMc,OAAO,GACzCwB,OAAOxB,OAAOd,MAAMc;CAExB,IAAId,MAAMG,YAAYoC,KAAAA,KAAavC,MAAMG,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,CAAC;QAElBd,KAAKmB,OAAO,CAACL,EAAE,CAAC;EAExB;EACAQ,yBAAyB8C,aAAa;GAAE9E,MAAM;GAAOE,QAAQ,CAAA;EAAG,CAAC;EACjE+B,sBAAsB6C,aAAaxC,eAAe;EAClDJ,aAAaV,OACTnB,UAAUL,SAAS,QAAQ,CAACK,UAAUH,OAAOoF,SAAS9D,EAAE,IAAInB,UAAUJ,IAAIqF,SAAS9D,EAAE;EACzFW,mBAAmBC,UACf/B,UAAUL,SAAS,QACbuF,KAAKC,IAAI,GAAGpD,QAAQ/B,UAAUH,OAAOgD,MAAM,IAC3C7C,UAAUJ,IAAIiD;EACxBb,eAAe;GACX,IAAIhC,UAAUL,SAAS,OACnB,OAAOK,UAAUJ,IAAIiD,SAAS,IAAI,EAAEjD,KAAK,CAAC,GAAGI,UAAUJ,GAAG,EAAE,IAAI;GAEpE,MAAMG,QAA0D,CAAC;GACjE,IAAIuD,OAAOf,WAAWD,KAAAA,GAClBvC,MAAMwC,SAASe,OAAOf;GAE1B,IAAIe,OAAOhC,MAAMgB,KAAAA,GACbvC,MAAMuB,IAAIgC,OAAOhC;GAErB,OAAOtB,UAAUH,OAAOgD,SAAS,IAC3B;IAAE9C;IAAOF,QAAQ,CAAC,GAAGG,UAAUH,MAAM;GAAE,IACvC,EAAEE,MAAM;EAClB;CACJ;CACA,OAAOM;AACX"}
|
|
1
|
+
{"version":3,"file":"list.js","names":["FilterValue","ListQuery","Selection","fromSearchParams","isFilterRange","toSearchParams","ResolvedList","isEqual","Router","ListSelection","mode","ids","except","ListState","query","selection","ListDefaults","perPage","sort","ListOptions","list","defaults","router","List","getState","subscribe","listener","setPage","page","nextPage","cursor","previousPage","setPerPage","setSort","toggleSort","field","setFilter","id","value","setSearch","q","resetQuery","select","deselect","toggle","selectAllMatching","clearSelection","isSelected","getSelectedCount","total","getSelection","EMPTY_SELECTION","FIRST_PAGE","undefined","LIST_PARAM","normalize","Required","result","filter","Object","fromEntries","entries","Array","isArray","length","keys","fields","createList","options","defaultSort","readRouter","URLSearchParams","getSearch","params","trail","cursors","pagination","compute","state","listeners","Set","notify","forEach","writeRouter","replace","search","key","test","delete","append","next","toString","setParams","normalized","scopeChanged","_next","nextQuery","_current","currentQuery","setSelection","unsubscribeRouter","onRouterChange","add","size","current","back","at","rest","slice","_sort","_removed","includes","Math","max","Record"],"sources":["../../src/list/list.ts"],"sourcesContent":["import type { FilterValue, ListQuery, Selection } from '@panneau/protocol';\nimport { fromSearchParams, isFilterRange, toSearchParams } from '@panneau/protocol/runtime';\n\nimport type { ResolvedList } from '../definition/list';\nimport { isEqual } from '../values';\nimport type { Router } from './router';\n\n/**\n * Selected items: some ids, or every item matching the list query (filters and search) except\n * some ids. \"All matching\" covers the items of every page.\n */\nexport type ListSelection =\n { mode: 'ids'; ids: readonly string[] } | { mode: 'all'; except: readonly string[] };\n\nexport interface ListState {\n /** The query to fetch: the list's defaults, overridden by the current state. */\n query: ListQuery;\n selection: ListSelection;\n}\n\nexport interface ListDefaults {\n perPage?: number;\n /** Default sort, as `sort` query values (`['-published_at']`). */\n sort?: string[];\n}\n\nexport interface ListOptions {\n /** A resolved list, for the defaults (`perPage`, `defaultSort`). */\n list?: ResolvedList;\n /** Defaults, over those of `list`. Default values are not written to the URL. */\n defaults?: ListDefaults;\n /** The starting query, when there is no router. */\n query?: ListQuery;\n /** Keeps the query in the URL. The router's query string wins over `query`. */\n router?: Router | null;\n}\n\n/** A headless list: query and selection. React components use `useList()`. */\nexport interface List {\n getState(): ListState;\n subscribe(listener: () => void): () => void;\n setPage(page: number): void;\n /**\n * In a list paged with cursors: goes to the page of `nextCursor`, and remembers the cursor of\n * the page it leaves, for `previousPage()`.\n */\n nextPage(cursor: string): void;\n /**\n * In a list paged with cursors: goes back a page, to `previousCursor` when the backend gives\n * one (`null` for the first page), or else to the page it came from. Without either, it goes\n * to the first page.\n */\n previousPage(cursor?: string | null): void;\n /** Sets the page size, and goes back to the first page. */\n setPerPage(perPage: number): void;\n /** Sets the sort (`['-published_at', 'title']`), and goes back to the first page. */\n setSort(sort: readonly string[]): void;\n /** Sorts by a field: ascending, then descending, then back to the default sort. */\n toggleSort(field: string): void;\n /** Sets or removes (`undefined`) a filter, goes back to the first page, and clears the selection. */\n setFilter(id: string, value: FilterValue | undefined): void;\n /** Sets the search, goes back to the first page, and clears the selection. */\n setSearch(q: string): void;\n /** Removes the page, filters, search and sort: back to the defaults. */\n resetQuery(): void;\n /** Adds ids to the selection (removes them from the exceptions in \"all matching\" mode). */\n select(ids: readonly string[]): void;\n /** Removes ids from the selection (adds them to the exceptions in \"all matching\" mode). */\n deselect(ids: readonly string[]): void;\n toggle(id: string): void;\n /** Selects every item matching the query, on every page. */\n selectAllMatching(): void;\n clearSelection(): void;\n isSelected(id: string): boolean;\n /** How many items are selected, given the total of the list. */\n getSelectedCount(total: number): number;\n /** The selection to send with an action, or `null` when nothing is selected. */\n getSelection(): Selection | null;\n}\n\nconst EMPTY_SELECTION: ListSelection = { mode: 'ids', ids: [] };\n/** Back to the first page: page 1, or no cursor. */\nconst FIRST_PAGE = { page: 1, cursor: undefined };\nconst LIST_PARAM = /^(page|perPage|cursor|sort|q|fields|filter\\[.+)$/;\n\n/** Removes the values that are the defaults, so the URL only keeps what the user changed. */\nfunction normalize(query: ListQuery, defaults: Required<ListDefaults>): ListQuery {\n const result: ListQuery = {};\n if (query.page !== undefined && query.page > 1) {\n result.page = query.page;\n }\n if (query.perPage !== undefined && query.perPage !== defaults.perPage) {\n result.perPage = query.perPage;\n }\n if (query.cursor !== undefined && query.cursor !== '') {\n result.cursor = query.cursor;\n }\n if (query.sort !== undefined && !isEqual(query.sort, defaults.sort)) {\n result.sort = [...query.sort];\n }\n const filter = Object.fromEntries(\n Object.entries(query.filter ?? {}).filter(\n ([, value]) =>\n value !== '' &&\n !(Array.isArray(value) && value.length === 0) &&\n !(isFilterRange(value) && Object.keys(value).length === 0),\n ),\n );\n if (Object.keys(filter).length > 0) {\n result.filter = filter;\n }\n if (query.q !== undefined && query.q !== '') {\n result.q = query.q;\n }\n if (query.fields !== undefined) {\n result.fields = query.fields;\n }\n return result;\n}\n\n/** Creates a headless list. */\nexport function createList(options: ListOptions = {}): List {\n const defaults: Required<ListDefaults> = {\n perPage: options.defaults?.perPage ?? options.list?.perPage ?? 20,\n sort: options.defaults?.sort ?? options.list?.defaultSort ?? [],\n };\n const router = options.router ?? null;\n const readRouter = (): ListQuery =>\n router !== null\n ? normalize(fromSearchParams(new URLSearchParams(router.getSearch())), defaults)\n : {};\n\n let params: ListQuery =\n router !== null ? readRouter() : normalize(options.query ?? {}, defaults);\n let selection: ListSelection = EMPTY_SELECTION;\n // The cursors of the pages before this one, as `nextPage()` followed them.\n let trail: (string | null)[] = [];\n\n // A list paged with cursors has no page numbers: its query has a cursor, after the first page.\n const cursors = options.list?.pagination === 'cursor';\n const compute = (): ListState => ({\n query: {\n ...params,\n ...(cursors ? {} : { page: params.page ?? 1 }),\n perPage: params.perPage ?? defaults.perPage,\n ...(params.sort !== undefined || defaults.sort.length > 0\n ? { sort: params.sort ?? defaults.sort }\n : {}),\n },\n selection,\n });\n\n let state = compute();\n const listeners = new Set<() => void>();\n const notify = () => {\n state = compute();\n listeners.forEach((listener) => listener());\n };\n\n const writeRouter = (replace: boolean) => {\n if (router === null) {\n return;\n }\n const search = new URLSearchParams(router.getSearch());\n [...search.keys()]\n .filter((key) => LIST_PARAM.test(key))\n .forEach((key) => search.delete(key));\n toSearchParams(params).forEach((value, key) => search.append(key, value));\n const next = search.toString();\n if (next !== router.getSearch()) {\n router.setSearch(next, { replace });\n }\n };\n\n const setParams = (next: ListQuery, { replace = false } = {}) => {\n const normalized = normalize(next, defaults);\n if (isEqual(normalized, params)) {\n return;\n }\n const scopeChanged =\n !isEqual(normalized.filter, params.filter) || normalized.q !== params.q;\n // Another query starts its pages over.\n const { cursor: _next, ...nextQuery } = normalized;\n const { cursor: _current, ...currentQuery } = params;\n if (!isEqual(nextQuery, currentQuery)) {\n trail = [];\n }\n params = normalized;\n if (scopeChanged) {\n selection = EMPTY_SELECTION;\n }\n writeRouter(replace);\n notify();\n };\n\n const setSelection = (next: ListSelection) => {\n selection = next;\n notify();\n };\n\n let unsubscribeRouter: (() => void) | null = null;\n const onRouterChange = () => {\n const next = readRouter();\n if (isEqual(next, params)) {\n return;\n }\n if (!isEqual(next.filter, params.filter) || next.q !== params.q) {\n selection = EMPTY_SELECTION;\n }\n params = next;\n notify();\n };\n\n const list: List = {\n getState() {\n if (router !== null && unsubscribeRouter === null) {\n onRouterChange();\n }\n return state;\n },\n subscribe(listener) {\n listeners.add(listener);\n if (router !== null && unsubscribeRouter === null) {\n unsubscribeRouter = router.subscribe(onRouterChange);\n onRouterChange();\n }\n return () => {\n listeners.delete(listener);\n if (listeners.size === 0 && unsubscribeRouter !== null) {\n unsubscribeRouter();\n unsubscribeRouter = null;\n }\n };\n },\n setPage: (page) => setParams({ ...params, page }),\n nextPage(cursor) {\n const current = params.cursor ?? null;\n setParams({ ...params, cursor });\n trail = [...trail, current];\n },\n previousPage(cursor) {\n const back = cursor !== undefined ? cursor : (trail.at(-1) ?? null);\n const rest = trail.slice(0, -1);\n setParams({ ...params, cursor: back ?? undefined });\n trail = rest;\n },\n setPerPage: (perPage) => setParams({ ...params, perPage, ...FIRST_PAGE }),\n setSort: (sort) => setParams({ ...params, sort: [...sort], ...FIRST_PAGE }),\n toggleSort(field) {\n const sort = state.query.sort ?? [];\n if (sort[0] === field) {\n setParams({ ...params, sort: [`-${field}`], ...FIRST_PAGE });\n } else if (sort[0] === `-${field}` && params.sort !== undefined) {\n const { sort: _sort, ...rest } = params;\n setParams({ ...rest, ...FIRST_PAGE });\n } else {\n setParams({ ...params, sort: [field], ...FIRST_PAGE });\n }\n },\n setFilter(id, value) {\n const { [id]: _removed, ...filter } = params.filter ?? {};\n setParams({\n ...params,\n filter: value === undefined ? filter : { ...filter, [id]: value },\n ...FIRST_PAGE,\n });\n },\n setSearch: (q) => setParams({ ...params, q, ...FIRST_PAGE }, { replace: true }),\n resetQuery: () => setParams({}),\n select(ids) {\n if (selection.mode === 'all') {\n setSelection({\n mode: 'all',\n except: selection.except.filter((id) => !ids.includes(id)),\n });\n } else {\n setSelection({ mode: 'ids', ids: [...new Set([...selection.ids, ...ids])] });\n }\n },\n deselect(ids) {\n if (selection.mode === 'all') {\n setSelection({ mode: 'all', except: [...new Set([...selection.except, ...ids])] });\n } else {\n setSelection({ mode: 'ids', ids: selection.ids.filter((id) => !ids.includes(id)) });\n }\n },\n toggle(id) {\n if (list.isSelected(id)) {\n list.deselect([id]);\n } else {\n list.select([id]);\n }\n },\n selectAllMatching: () => setSelection({ mode: 'all', except: [] }),\n clearSelection: () => setSelection(EMPTY_SELECTION),\n isSelected: (id) =>\n selection.mode === 'all' ? !selection.except.includes(id) : selection.ids.includes(id),\n getSelectedCount: (total) =>\n selection.mode === 'all'\n ? Math.max(0, total - selection.except.length)\n : selection.ids.length,\n getSelection() {\n if (selection.mode === 'ids') {\n return selection.ids.length > 0 ? { ids: [...selection.ids] } : null;\n }\n const query: { filter?: Record<string, unknown>; q?: string } = {};\n if (params.filter !== undefined) {\n query.filter = params.filter;\n }\n if (params.q !== undefined) {\n query.q = params.q;\n }\n return selection.except.length > 0\n ? { query, except: [...selection.except] }\n : { query };\n },\n };\n return list;\n}\n"],"mappings":";;;AAgFA,IAAMmD,kBAAiC;CAAEzC,MAAM;CAAOC,KAAK,CAAA;AAAG;;AAE9D,IAAMyC,aAAa;CAAExB,MAAM;CAAGE,QAAQuB,KAAAA;AAAU;AAChD,IAAMC,aAAa;;AAGnB,SAASC,UAAUzC,OAAkBO,UAA6C;CAC9E,MAAMoC,SAAoB,CAAC;CAC3B,IAAI3C,MAAMc,SAASyB,KAAAA,KAAavC,MAAMc,OAAO,GACzC6B,OAAO7B,OAAOd,MAAMc;CAExB,IAAId,MAAMG,YAAYoC,KAAAA,KAAavC,MAAMG,YAAYI,SAASJ,SAC1DwC,OAAOxC,UAAUH,MAAMG;CAE3B,IAAIH,MA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,UAAUJ,GAAG,EAAE,IAAI;GAEpE,MAAMG,QAA0D,CAAC;GACjE,IAAI2D,OAAOf,WAAWL,KAAAA,GAClBvC,MAAM4C,SAASe,OAAOf;GAE1B,IAAIe,OAAOjC,MAAMa,KAAAA,GACbvC,MAAM0B,IAAIiC,OAAOjC;GAErB,OAAOzB,UAAUH,OAAOoD,SAAS,IAC3B;IAAElD;IAAOF,QAAQ,CAAC,GAAGG,UAAUH,MAAM;GAAE,IACvC,EAAEE,MAAM;EAClB;CACJ;CACA,OAAOM;AACX"}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentType } from 'react';
|
|
2
2
|
import type { DefinitionTheme, Theme } from '@panneau/protocol';
|
|
3
|
-
import type { CommandSource } from './commands';
|
|
3
|
+
import type { CommandSource } from './commands.js';
|
|
4
4
|
/** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */
|
|
5
5
|
export type { Theme };
|
|
6
6
|
/**
|
package/dist/react/provider.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { Definition } from '@panneau/protocol';
|
|
3
|
-
import { type ResolveFormOptions } from '../definition/form';
|
|
4
|
-
import { type ResolvedResource } from '../definition/resource';
|
|
5
|
-
import type { Router } from '../list/router';
|
|
6
|
-
import { type PanneauPlugin, type PluginRegistry } from '../plugins';
|
|
3
|
+
import { type ResolveFormOptions } from '../definition/form.js';
|
|
4
|
+
import { type ResolvedResource } from '../definition/resource.js';
|
|
5
|
+
import type { Router } from '../list/router.js';
|
|
6
|
+
import { type PanneauPlugin, type PluginRegistry } from '../plugins.js';
|
|
7
7
|
/** What `PanneauProvider` gives to the hooks below it. */
|
|
8
8
|
export interface PanneauContextValue {
|
|
9
9
|
plugins: PluginRegistry;
|
package/dist/react/useForm.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Form, type FormOptions, type FormState } from '../form/form';
|
|
1
|
+
import { type Form, type FormOptions, type FormState } from '../form/form.js';
|
|
2
2
|
export interface UseFormResult extends FormState {
|
|
3
3
|
/** The form, to change values, submit, reset or resolve a conflict. */
|
|
4
4
|
form: Form;
|
package/dist/react/useList.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type List, type ListOptions, type ListState } from '../list/list';
|
|
1
|
+
import { type List, type ListOptions, type ListState } from '../list/list.js';
|
|
2
2
|
export interface UseListResult extends ListState {
|
|
3
3
|
/** The list, to change the query and the selection. */
|
|
4
4
|
list: List;
|
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.9",
|
|
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",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"build": "vite build &&
|
|
25
|
+
"build": "vite build && node ../../scripts/declarations.js",
|
|
26
26
|
"typecheck": "tsc --noEmit",
|
|
27
|
-
"api": "
|
|
27
|
+
"api": "node ../../scripts/declarations.js && node ../../scripts/api-report.js"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
@@ -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.9"
|
|
37
37
|
}
|
|
38
38
|
}
|