@panneau/core 5.0.0-alpha.2 → 5.0.0-alpha.20
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 +4 -2
- package/dist/commands.d.ts +38 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +22 -0
- package/dist/commands.js.map +1 -0
- package/dist/definition/abilities.d.ts +33 -5
- package/dist/definition/abilities.d.ts.map +1 -1
- package/dist/definition/abilities.js +44 -6
- package/dist/definition/abilities.js.map +1 -1
- package/dist/definition/form.d.ts +8 -3
- package/dist/definition/form.d.ts.map +1 -1
- package/dist/definition/form.js +36 -4
- package/dist/definition/form.js.map +1 -1
- package/dist/definition/itemActions.d.ts +53 -0
- package/dist/definition/itemActions.d.ts.map +1 -0
- package/dist/definition/itemActions.js +64 -0
- package/dist/definition/itemActions.js.map +1 -0
- package/dist/definition/list.d.ts +42 -1
- package/dist/definition/list.d.ts.map +1 -1
- package/dist/definition/list.js +103 -16
- package/dist/definition/list.js.map +1 -1
- package/dist/definition/resource.d.ts +2 -2
- package/dist/definition/resource.js +1 -1
- package/dist/definition/resource.js.map +1 -1
- package/dist/form/form.d.ts +8 -3
- package/dist/form/form.d.ts.map +1 -1
- package/dist/form/form.js +1 -0
- package/dist/form/form.js.map +1 -1
- package/dist/form/messages.d.ts.map +1 -1
- package/dist/form/messages.js +11 -1
- package/dist/form/messages.js.map +1 -1
- package/dist/form/problem.d.ts +1 -1
- package/dist/form/problem.js.map +1 -1
- package/dist/form/selectors.d.ts +1 -1
- package/dist/form/selectors.js.map +1 -1
- package/dist/form/store.d.ts +1 -1
- package/dist/form/store.js.map +1 -1
- package/dist/index.d.ts +23 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/list/calendar.d.ts +15 -0
- package/dist/list/calendar.d.ts.map +1 -0
- package/dist/list/calendar.js +42 -0
- package/dist/list/calendar.js.map +1 -0
- package/dist/list/list.d.ts +40 -3
- package/dist/list/list.d.ts.map +1 -1
- package/dist/list/list.js +152 -16
- package/dist/list/list.js.map +1 -1
- package/dist/list/router.js.map +1 -1
- package/dist/list/viewStore.d.ts +36 -0
- package/dist/list/viewStore.d.ts.map +1 -0
- package/dist/list/viewStore.js +54 -0
- package/dist/list/viewStore.js.map +1 -0
- package/dist/plugins.d.ts +16 -2
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +4 -2
- package/dist/plugins.js.map +1 -1
- package/dist/preview.d.ts +14 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/react/leaveGuards.d.ts +34 -0
- package/dist/react/leaveGuards.d.ts.map +1 -0
- package/dist/react/leaveGuards.js +84 -0
- package/dist/react/leaveGuards.js.map +1 -0
- package/dist/react/provider.d.ts +4 -4
- package/dist/react/provider.js +3 -1
- package/dist/react/provider.js.map +1 -1
- package/dist/react/useForm.d.ts +1 -1
- package/dist/react/useForm.js.map +1 -1
- package/dist/react/useList.d.ts +1 -1
- package/dist/react/useList.js.map +1 -1
- package/dist/values.d.ts +1 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +5 -1
- package/dist/values.js.map +1 -1
- package/dist/widget.d.ts +15 -0
- package/dist/widget.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
export { can, canRunAction, getActionPlacements, isActionAllowedOn, partitionByAction, } from './definition/abilities';
|
|
2
|
-
export { type
|
|
3
|
-
export {
|
|
4
|
-
export { type
|
|
5
|
-
export { type
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export { type
|
|
11
|
-
export { type
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export { type
|
|
15
|
-
export { type
|
|
16
|
-
export { type
|
|
1
|
+
export { can, canRunAction, canUpdateField, canViewField, canViewPage, getActionPlacements, getVisibleFields, isActionAllowedOn, partitionByAction, } from './definition/abilities.js';
|
|
2
|
+
export { type ActionItem, type ItemAction, type ItemActionsOptions, type ItemSurface, fillActionUrl, getItemActions, selectItemActions, } from './definition/itemActions.js';
|
|
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, asksConfirmation, getOpenMode, getResourceActions, groupActions, resolveList, } from './definition/list.js';
|
|
5
|
+
export { type ResolvedResource, type ResourceAbilities, findResource, resolveResource, } from './definition/resource.js';
|
|
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
|
+
export { formatRuleFailure } from './form/messages.js';
|
|
8
|
+
export { getItemValues, getProblem, isItem } from './form/problem.js';
|
|
9
|
+
export { selectErrorCount, selectErrors, selectValue, selectVisible } from './form/selectors.js';
|
|
10
|
+
export { type FormStore, createLocalStore } from './form/store.js';
|
|
11
|
+
export { type List, type ListDefaults, type ListOptions, type ListSelection, type ListState, createList, } from './list/list.js';
|
|
12
|
+
export { currentMonth, getCalendarRange, isMonth, shiftMonth } from './list/calendar.js';
|
|
13
|
+
export { type ListViewState, type ListViewStore, type RememberedView, createStorageViewStore, } from './list/viewStore.js';
|
|
14
|
+
export { type MemoryRouter, type Router, createHistoryRouter, createMemoryRouter, } from './list/router.js';
|
|
15
|
+
export { type Messages, type MessagesLoader, type PanneauPlugin, type PluginComponent, type PluginComponentKind, type PluginRegistry, type Theme, createPluginRegistry, definePlugin, loadMessages, resolveTheme, } from './plugins.js';
|
|
16
|
+
export { type Command, type CommandContext, type CommandSource, getCommands, getSearchableResources, isSearchable, } from './commands.js';
|
|
17
|
+
export { type PreviewProps } from './preview.js';
|
|
18
|
+
export { type WidgetProps } from './widget.js';
|
|
19
|
+
export { type LeaveGuard, type LeaveGuards, LeaveGuardsProvider, type LeaveGuardsProviderProps, createLeaveGuards, useLeaveGuard, useLeaveGuards, } from './react/leaveGuards.js';
|
|
20
|
+
export { PanneauProvider, type PanneauContextValue, type PanneauProviderProps, usePanneau, usePlugins, useResource, } from './react/provider.js';
|
|
21
|
+
export { type UseFormFieldResult, type UseFormResult, useForm, useFormField, } from './react/useForm.js';
|
|
22
|
+
export { type UseListResult, useList } from './react/useList.js';
|
|
23
|
+
export { type Values, isEqual, setValue } from './values.js';
|
|
17
24
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,GAAG,EACH,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,mBAAmB,EACnB,aAAa,EACb,WAAW,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,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,OAAO,EACH,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,UAAU,EACV,gBAAgB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,aAAa,E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E,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { can, canRunAction, getActionPlacements, isActionAllowedOn, partitionByAction } from "./definition/abilities.js";
|
|
1
|
+
import { can, canRunAction, canUpdateField, canViewField, canViewPage, getActionPlacements, getVisibleFields, isActionAllowedOn, partitionByAction } from "./definition/abilities.js";
|
|
2
|
+
import { DEFAULT_CALENDAR_PER_PAGE, DEFAULT_PER_PAGE, asksConfirmation, getOpenMode, getResourceActions, groupActions, resolveList } from "./definition/list.js";
|
|
3
|
+
import { fillActionUrl, getItemActions, selectItemActions } from "./definition/itemActions.js";
|
|
2
4
|
import { getLayoutFieldNames, resolveFields, resolveForm } from "./definition/form.js";
|
|
3
|
-
import { DEFAULT_PER_PAGE, groupActions, resolveList } from "./definition/list.js";
|
|
4
5
|
import { findResource, resolveResource } from "./definition/resource.js";
|
|
5
6
|
import { isEqual, setValue } from "./values.js";
|
|
6
7
|
import { formatRuleFailure } from "./form/messages.js";
|
|
@@ -8,10 +9,14 @@ import { getItemValues, getProblem, isItem } from "./form/problem.js";
|
|
|
8
9
|
import { selectErrorCount, selectErrors, selectValue, selectVisible } from "./form/selectors.js";
|
|
9
10
|
import { createLocalStore } from "./form/store.js";
|
|
10
11
|
import { createForm, getDefaultValues } from "./form/form.js";
|
|
12
|
+
import { currentMonth, getCalendarRange, isMonth, shiftMonth } from "./list/calendar.js";
|
|
13
|
+
import { createStorageViewStore } from "./list/viewStore.js";
|
|
11
14
|
import { createList } from "./list/list.js";
|
|
12
15
|
import { createHistoryRouter, createMemoryRouter } from "./list/router.js";
|
|
13
16
|
import { createPluginRegistry, definePlugin, loadMessages, resolveTheme } from "./plugins.js";
|
|
17
|
+
import { getCommands, getSearchableResources, isSearchable } from "./commands.js";
|
|
18
|
+
import { LeaveGuardsProvider, createLeaveGuards, useLeaveGuard, useLeaveGuards } from "./react/leaveGuards.js";
|
|
14
19
|
import { PanneauProvider, usePanneau, usePlugins, useResource } from "./react/provider.js";
|
|
15
20
|
import { useForm, useFormField } from "./react/useForm.js";
|
|
16
21
|
import { useList } from "./react/useList.js";
|
|
17
|
-
export { DEFAULT_PER_PAGE, PanneauProvider, can, canRunAction, createForm, createHistoryRouter, createList, createLocalStore, createMemoryRouter, createPluginRegistry, definePlugin, findResource, formatRuleFailure, getActionPlacements, getDefaultValues, getItemValues, getLayoutFieldNames, getProblem, groupActions, isActionAllowedOn, isEqual, isItem, loadMessages, partitionByAction, resolveFields, resolveForm, resolveList, resolveResource, resolveTheme, selectErrorCount, selectErrors, selectValue, selectVisible, setValue, useForm, useFormField, 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 };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Whether a value is a month, as the view of a calendar keeps it (`2026-11`). */
|
|
2
|
+
export declare function isMonth(value: unknown): value is string;
|
|
3
|
+
/** The month of a day, in the time zone of the browser (`2026-11`). Defaults to today. */
|
|
4
|
+
export declare function currentMonth(now?: Date): string;
|
|
5
|
+
/** The month `offset` months after another one (`-1` for the previous one). */
|
|
6
|
+
export declare function shiftMonth(month: string, offset: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* The days a calendar asks for to show a month (decision 0044): from 6 days before its first day
|
|
9
|
+
* to 6 days after its last, so that the weeks shown are covered whatever day they start on.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCalendarRange(month: string): {
|
|
12
|
+
from: string;
|
|
13
|
+
to: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/list/calendar.ts"],"names":[],"mappings":"AAYA,kFAAkF;AAClF,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEvD;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,GAAG,GAAE,IAAiB,GAAG,MAAM,CAE3D;AAED,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAS5E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/list/calendar.ts
|
|
2
|
+
var MONTH = /^(\d{4})-(0[1-9]|1[0-2])$/;
|
|
3
|
+
/** Days before and after a month that a calendar asks for: weeks start on any day. */
|
|
4
|
+
var PADDING = 6;
|
|
5
|
+
function pad(value, length = 2) {
|
|
6
|
+
return String(value).padStart(length, "0");
|
|
7
|
+
}
|
|
8
|
+
function toDay(date) {
|
|
9
|
+
return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;
|
|
10
|
+
}
|
|
11
|
+
/** Whether a value is a month, as the view of a calendar keeps it (`2026-11`). */
|
|
12
|
+
function isMonth(value) {
|
|
13
|
+
return typeof value === "string" && MONTH.test(value);
|
|
14
|
+
}
|
|
15
|
+
/** The month of a day, in the time zone of the browser (`2026-11`). Defaults to today. */
|
|
16
|
+
function currentMonth(now = /* @__PURE__ */ new Date()) {
|
|
17
|
+
return `${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}`;
|
|
18
|
+
}
|
|
19
|
+
/** The month `offset` months after another one (`-1` for the previous one). */
|
|
20
|
+
function shiftMonth(month, offset) {
|
|
21
|
+
const [, year = "1970", index = "01"] = MONTH.exec(month) ?? [];
|
|
22
|
+
const date = new Date(Date.UTC(Number(year), Number(index) - 1 + offset, 1));
|
|
23
|
+
return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The days a calendar asks for to show a month (decision 0044): from 6 days before its first day
|
|
27
|
+
* to 6 days after its last, so that the weeks shown are covered whatever day they start on.
|
|
28
|
+
*/
|
|
29
|
+
function getCalendarRange(month) {
|
|
30
|
+
const [, year = "1970", index = "01"] = MONTH.exec(month) ?? [];
|
|
31
|
+
const first = Date.UTC(Number(year), Number(index) - 1, 1);
|
|
32
|
+
const last = Date.UTC(Number(year), Number(index), 0);
|
|
33
|
+
const day = 864e5;
|
|
34
|
+
return {
|
|
35
|
+
from: toDay(/* @__PURE__ */ new Date(first - PADDING * day)),
|
|
36
|
+
to: toDay(new Date(last + PADDING * day))
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { currentMonth, getCalendarRange, isMonth, shiftMonth };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","names":["MONTH","PADDING","pad","value","length","String","padStart","toDay","date","Date","getUTCFullYear","getUTCMonth","getUTCDate","isMonth","test","currentMonth","now","getFullYear","getMonth","shiftMonth","month","offset","year","index","exec","UTC","Number","getCalendarRange","from","to","first","last","day"],"sources":["../../src/list/calendar.ts"],"sourcesContent":["const MONTH = /^(\\d{4})-(0[1-9]|1[0-2])$/;\n/** Days before and after a month that a calendar asks for: weeks start on any day. */\nconst PADDING = 6;\n\nfunction pad(value: number, length = 2): string {\n return String(value).padStart(length, '0');\n}\n\nfunction toDay(date: Date): string {\n return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())}`;\n}\n\n/** Whether a value is a month, as the view of a calendar keeps it (`2026-11`). */\nexport function isMonth(value: unknown): value is string {\n return typeof value === 'string' && MONTH.test(value);\n}\n\n/** The month of a day, in the time zone of the browser (`2026-11`). Defaults to today. */\nexport function currentMonth(now: Date = new Date()): string {\n return `${pad(now.getFullYear(), 4)}-${pad(now.getMonth() + 1)}`;\n}\n\n/** The month `offset` months after another one (`-1` for the previous one). */\nexport function shiftMonth(month: string, offset: number): string {\n const [, year = '1970', index = '01'] = MONTH.exec(month) ?? [];\n const date = new Date(Date.UTC(Number(year), Number(index) - 1 + offset, 1));\n return `${pad(date.getUTCFullYear(), 4)}-${pad(date.getUTCMonth() + 1)}`;\n}\n\n/**\n * The days a calendar asks for to show a month (decision 0044): from 6 days before its first day\n * to 6 days after its last, so that the weeks shown are covered whatever day they start on.\n */\nexport function getCalendarRange(month: string): { from: string; to: string } {\n const [, year = '1970', index = '01'] = MONTH.exec(month) ?? [];\n const first = Date.UTC(Number(year), Number(index) - 1, 1);\n const last = Date.UTC(Number(year), Number(index), 0);\n const day = 86_400_000;\n return {\n from: toDay(new Date(first - PADDING * day)),\n to: toDay(new Date(last + PADDING * day)),\n };\n}\n"],"mappings":";AAAA,IAAMA,QAAQ;;AAEd,IAAMC,UAAU;AAEhB,SAASC,IAAIC,OAAeC,SAAS,GAAW;CAC5C,OAAOC,OAAOF,KAAK,CAAC,CAACG,SAASF,QAAQ,GAAG;AAC7C;AAEA,SAASG,MAAMC,MAAoB;CAC/B,OAAO,GAAGN,IAAIM,KAAKE,eAAe,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|
import type { FilterValue, ListQuery, Selection } from '@panneau/protocol';
|
|
2
|
-
import type { ResolvedList } from '../definition/list';
|
|
3
|
-
import type { Router } from './router';
|
|
2
|
+
import type { ResolvedCalendar, ResolvedList } from '../definition/list.js';
|
|
3
|
+
import type { Router } from './router.js';
|
|
4
|
+
import { type ListViewState, type ListViewStore } from './viewStore.js';
|
|
4
5
|
/**
|
|
5
6
|
* Selected items: some ids, or every item matching the list query (filters and search) except
|
|
6
7
|
* some ids. "All matching" covers the items of every page.
|
|
@@ -15,12 +16,20 @@ export type ListSelection = {
|
|
|
15
16
|
export interface ListState {
|
|
16
17
|
/** The query to fetch: the list's defaults, overridden by the current state. */
|
|
17
18
|
query: ListQuery;
|
|
19
|
+
/** How the items are shown: the layout and the columns, when they aren't the defaults. */
|
|
20
|
+
view: ListViewState;
|
|
18
21
|
selection: ListSelection;
|
|
19
22
|
}
|
|
20
23
|
export interface ListDefaults {
|
|
21
24
|
perPage?: number;
|
|
22
25
|
/** Default sort, as `sort` query values (`['-published_at']`). */
|
|
23
26
|
sort?: string[];
|
|
27
|
+
/** The default layout. */
|
|
28
|
+
layout?: string;
|
|
29
|
+
/** The ids of the columns shown by default, in their order. */
|
|
30
|
+
columns?: string[];
|
|
31
|
+
/** The calendar of the list, for its `calendar` layout (decision 0044). */
|
|
32
|
+
calendar?: ResolvedCalendar | null;
|
|
24
33
|
}
|
|
25
34
|
export interface ListOptions {
|
|
26
35
|
/** A resolved list, for the defaults (`perPage`, `defaultSort`). */
|
|
@@ -31,12 +40,32 @@ export interface ListOptions {
|
|
|
31
40
|
query?: ListQuery;
|
|
32
41
|
/** Keeps the query in the URL. The router's query string wins over `query`. */
|
|
33
42
|
router?: Router | null;
|
|
43
|
+
/**
|
|
44
|
+
* Remembers the view of the list (filters, sort, page size, layout and columns) under `key`,
|
|
45
|
+
* in `store` (the browser's `localStorage` by default), and restores it when the list opens
|
|
46
|
+
* without a query of its own: a URL without any parameter of the list (decision 0042).
|
|
47
|
+
*/
|
|
48
|
+
remember?: {
|
|
49
|
+
key: string;
|
|
50
|
+
store?: ListViewStore;
|
|
51
|
+
} | null;
|
|
34
52
|
}
|
|
35
53
|
/** A headless list: query and selection. React components use `useList()`. */
|
|
36
54
|
export interface List {
|
|
37
55
|
getState(): ListState;
|
|
38
56
|
subscribe(listener: () => void): () => void;
|
|
39
57
|
setPage(page: number): void;
|
|
58
|
+
/**
|
|
59
|
+
* In a list paged with cursors: goes to the page of `nextCursor`, and remembers the cursor of
|
|
60
|
+
* the page it leaves, for `previousPage()`.
|
|
61
|
+
*/
|
|
62
|
+
nextPage(cursor: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* In a list paged with cursors: goes back a page, to `previousCursor` when the backend gives
|
|
65
|
+
* one (`null` for the first page), or else to the page it came from. Without either, it goes
|
|
66
|
+
* to the first page.
|
|
67
|
+
*/
|
|
68
|
+
previousPage(cursor?: string | null): void;
|
|
40
69
|
/** Sets the page size, and goes back to the first page. */
|
|
41
70
|
setPerPage(perPage: number): void;
|
|
42
71
|
/** Sets the sort (`['-published_at', 'title']`), and goes back to the first page. */
|
|
@@ -47,8 +76,16 @@ export interface List {
|
|
|
47
76
|
setFilter(id: string, value: FilterValue | undefined): void;
|
|
48
77
|
/** Sets the search, goes back to the first page, and clears the selection. */
|
|
49
78
|
setSearch(q: string): void;
|
|
50
|
-
/** Removes the page, filters, search and sort: back to the defaults. */
|
|
79
|
+
/** Removes the page, filters, search and sort: back to the defaults. The view stays. */
|
|
51
80
|
resetQuery(): void;
|
|
81
|
+
/** Shows the items in a layout (`cards`). */
|
|
82
|
+
setLayout(layout: string): void;
|
|
83
|
+
/** Shows these columns, by id, in this order. */
|
|
84
|
+
setColumns(ids: readonly string[]): void;
|
|
85
|
+
/** Back to the columns of the definition. */
|
|
86
|
+
resetColumns(): void;
|
|
87
|
+
/** Shows a month in the calendar (`2026-11`). */
|
|
88
|
+
setMonth(month: string): void;
|
|
52
89
|
/** Adds ids to the selection (removes them from the exceptions in "all matching" mode). */
|
|
53
90
|
select(ids: readonly string[]): void;
|
|
54
91
|
/** Removes ids from the selection (adds them to the exceptions in "all matching" mode). */
|
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;
|
|
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,gBAAgB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EACH,KAAK,aAAa,EAClB,KAAK,aAAa,EAGrB,MAAM,aAAa,CAAC;AAErB;;;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,0FAA0F;IAC1F,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,aAAa,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,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AE,MAAM,GAAG,IAAI,CAAC;IAC3B,wFAAwF;IACxF,UAAU,IAAI,IAAI,CAAC;IACnB,6CAA6C;IAC7C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iDAAiD;IACjD,UAAU,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACzC,6CAA6C;IAC7C,YAAY,IAAI,IAAI,CAAC;IACrB,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,2FAA2F;IAC3F,MAAM,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IACvC,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,4DAA4D;IAC5D,iBAAiB,IAAI,IAAI,CAAC;IAC1B,cAAc,IAAI,IAAI,CAAC;IACvB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,gEAAgE;IAChE,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,gFAAgF;IAChF,YAAY,IAAI,SAAS,GAAG,IAAI,CAAC;CACpC;AAgGD,+BAA+B;AAC/B,wBAAgB,UAAU,CAAC,OAAO,GAAE,WAAgB,GAAG,IAAI,CAoT1D"}
|
package/dist/list/list.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { isEqual } from "../values.js";
|
|
2
|
+
import { currentMonth, getCalendarRange, isMonth } from "./calendar.js";
|
|
3
|
+
import { createStorageViewStore } from "./viewStore.js";
|
|
2
4
|
import { fromSearchParams, isFilterRange, toSearchParams } from "@panneau/protocol/runtime";
|
|
3
5
|
//#region src/list/list.ts
|
|
4
6
|
var EMPTY_SELECTION = {
|
|
5
7
|
mode: "ids",
|
|
6
8
|
ids: []
|
|
7
9
|
};
|
|
8
|
-
|
|
10
|
+
/** Back to the first page: page 1, or no cursor. */
|
|
11
|
+
var FIRST_PAGE = {
|
|
12
|
+
page: 1,
|
|
13
|
+
cursor: void 0
|
|
14
|
+
};
|
|
15
|
+
var LIST_PARAM = /^(page|perPage|cursor|sort|q|fields|layout|columns|month|filter\[.+)$/;
|
|
9
16
|
/** Removes the values that are the defaults, so the URL only keeps what the user changed. */
|
|
10
17
|
function normalize(query, defaults) {
|
|
11
18
|
const result = {};
|
|
12
19
|
if (query.page !== void 0 && query.page > 1) result.page = query.page;
|
|
13
20
|
if (query.perPage !== void 0 && query.perPage !== defaults.perPage) result.perPage = query.perPage;
|
|
21
|
+
if (query.cursor !== void 0 && query.cursor !== "") result.cursor = query.cursor;
|
|
14
22
|
if (query.sort !== void 0 && !isEqual(query.sort, defaults.sort)) result.sort = [...query.sort];
|
|
15
23
|
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
24
|
if (Object.keys(filter).length > 0) result.filter = filter;
|
|
@@ -18,23 +26,87 @@ function normalize(query, defaults) {
|
|
|
18
26
|
if (query.fields !== void 0) result.fields = query.fields;
|
|
19
27
|
return result;
|
|
20
28
|
}
|
|
29
|
+
/** Removes the parts of the view that are the defaults. */
|
|
30
|
+
function normalizeView(view, defaults) {
|
|
31
|
+
const result = {};
|
|
32
|
+
if (view.layout !== void 0 && view.layout !== "" && view.layout !== defaults.layout) result.layout = view.layout;
|
|
33
|
+
if (view.columns !== void 0 && view.columns.length > 0 && !isEqual(view.columns, defaults.columns)) result.columns = [...view.columns];
|
|
34
|
+
if (isMonth(view.month) && view.month !== currentMonth()) result.month = view.month;
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function readView(search) {
|
|
38
|
+
const view = {};
|
|
39
|
+
const layout = search.get("layout");
|
|
40
|
+
if (layout !== null) view.layout = layout;
|
|
41
|
+
const columns = search.get("columns");
|
|
42
|
+
if (columns !== null) view.columns = columns.split(",").filter((id) => id !== "");
|
|
43
|
+
const month = search.get("month");
|
|
44
|
+
if (month !== null) view.month = month;
|
|
45
|
+
return view;
|
|
46
|
+
}
|
|
47
|
+
/** What a list remembers of its query: not its page, cursor or search. */
|
|
48
|
+
function rememberedQuery(query) {
|
|
49
|
+
const result = {};
|
|
50
|
+
if (query.filter !== void 0) result.filter = query.filter;
|
|
51
|
+
if (query.sort !== void 0) result.sort = query.sort;
|
|
52
|
+
if (query.perPage !== void 0) result.perPage = query.perPage;
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
21
55
|
/** Creates a headless list. */
|
|
22
56
|
function createList(options = {}) {
|
|
23
57
|
const defaults = {
|
|
24
58
|
perPage: options.defaults?.perPage ?? options.list?.perPage ?? 20,
|
|
25
|
-
sort: options.defaults?.sort ?? options.list?.defaultSort ?? []
|
|
59
|
+
sort: options.defaults?.sort ?? options.list?.defaultSort ?? [],
|
|
60
|
+
calendar: options.defaults?.calendar ?? options.list?.calendar ?? null
|
|
26
61
|
};
|
|
62
|
+
const defaultLayout = options.defaults?.layout ?? options.list?.layouts[0];
|
|
63
|
+
if (defaultLayout !== void 0) defaults.layout = defaultLayout;
|
|
64
|
+
const defaultColumns = options.defaults?.columns ?? options.list?.columns.filter((column) => !column.hidden).map((column) => column.id);
|
|
65
|
+
if (defaultColumns !== void 0) defaults.columns = defaultColumns;
|
|
27
66
|
const router = options.router ?? null;
|
|
28
|
-
const readRouter = () =>
|
|
29
|
-
|
|
67
|
+
const readRouter = () => {
|
|
68
|
+
if (router === null) return {
|
|
69
|
+
query: {},
|
|
70
|
+
view: {}
|
|
71
|
+
};
|
|
72
|
+
const search = new URLSearchParams(router.getSearch());
|
|
73
|
+
return {
|
|
74
|
+
query: normalize(fromSearchParams(search), defaults),
|
|
75
|
+
view: normalizeView(readView(search), defaults)
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const hasListParams = () => router !== null && [...new URLSearchParams(router.getSearch()).keys()].some((key) => LIST_PARAM.test(key));
|
|
79
|
+
const remember = options.remember ?? null;
|
|
80
|
+
const store = remember !== null ? remember.store ?? createStorageViewStore() : null;
|
|
81
|
+
const remembered = remember !== null && store !== null && (router !== null ? !hasListParams() : options.query === void 0) ? store.get(remember.key) : null;
|
|
82
|
+
const initial = router !== null ? readRouter() : null;
|
|
83
|
+
let params = normalize(remembered?.query ?? initial?.query ?? options.query ?? {}, defaults);
|
|
84
|
+
let view = normalizeView(remembered?.view ?? initial?.view ?? {}, defaults);
|
|
85
|
+
let restoring = remembered !== null && router !== null;
|
|
30
86
|
let selection = EMPTY_SELECTION;
|
|
87
|
+
let trail = [];
|
|
88
|
+
const cursors = options.list?.pagination === "cursor";
|
|
89
|
+
const sortQuery = () => params.sort !== void 0 || defaults.sort.length > 0 ? { sort: params.sort ?? defaults.sort } : {};
|
|
90
|
+
const calendarQuery = (calendar) => {
|
|
91
|
+
const { page: _page, cursor: _cursor, perPage: _perPage, ...rest } = params;
|
|
92
|
+
return {
|
|
93
|
+
...rest,
|
|
94
|
+
...sortQuery(),
|
|
95
|
+
perPage: calendar.perPage,
|
|
96
|
+
filter: {
|
|
97
|
+
...params.filter,
|
|
98
|
+
[calendar.filter]: getCalendarRange(view.month ?? currentMonth())
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
};
|
|
31
102
|
const compute = () => ({
|
|
32
|
-
query: {
|
|
103
|
+
query: defaults.calendar !== null && (view.layout ?? defaults.layout) === "calendar" ? calendarQuery(defaults.calendar) : {
|
|
33
104
|
...params,
|
|
34
|
-
page: params.page ?? 1,
|
|
105
|
+
...cursors ? {} : { page: params.page ?? 1 },
|
|
35
106
|
perPage: params.perPage ?? defaults.perPage,
|
|
36
|
-
...
|
|
107
|
+
...sortQuery()
|
|
37
108
|
},
|
|
109
|
+
view,
|
|
38
110
|
selection
|
|
39
111
|
});
|
|
40
112
|
let state = compute();
|
|
@@ -48,16 +120,40 @@ function createList(options = {}) {
|
|
|
48
120
|
const search = new URLSearchParams(router.getSearch());
|
|
49
121
|
[...search.keys()].filter((key) => LIST_PARAM.test(key)).forEach((key) => search.delete(key));
|
|
50
122
|
toSearchParams(params).forEach((value, key) => search.append(key, value));
|
|
123
|
+
if (view.layout !== void 0) search.set("layout", view.layout);
|
|
124
|
+
if (view.columns !== void 0) search.set("columns", view.columns.join(","));
|
|
125
|
+
if (view.month !== void 0) search.set("month", view.month);
|
|
51
126
|
const next = search.toString();
|
|
52
127
|
if (next !== router.getSearch()) router.setSearch(next, { replace });
|
|
53
128
|
};
|
|
129
|
+
const save = () => {
|
|
130
|
+
if (remember === null || store === null) return;
|
|
131
|
+
const query = rememberedQuery(params);
|
|
132
|
+
const { month: _month, ...remembered } = view;
|
|
133
|
+
store.set(remember.key, Object.keys(query).length > 0 || Object.keys(remembered).length > 0 ? {
|
|
134
|
+
query,
|
|
135
|
+
view: remembered
|
|
136
|
+
} : null);
|
|
137
|
+
};
|
|
138
|
+
const setView = (next, { replace = false } = {}) => {
|
|
139
|
+
const normalized = normalizeView(next, defaults);
|
|
140
|
+
if (isEqual(normalized, view)) return;
|
|
141
|
+
view = normalized;
|
|
142
|
+
writeRouter(replace);
|
|
143
|
+
save();
|
|
144
|
+
notify();
|
|
145
|
+
};
|
|
54
146
|
const setParams = (next, { replace = false } = {}) => {
|
|
55
147
|
const normalized = normalize(next, defaults);
|
|
56
148
|
if (isEqual(normalized, params)) return;
|
|
57
149
|
const scopeChanged = !isEqual(normalized.filter, params.filter) || normalized.q !== params.q;
|
|
150
|
+
const { cursor: _next, ...nextQuery } = normalized;
|
|
151
|
+
const { cursor: _current, ...currentQuery } = params;
|
|
152
|
+
if (!isEqual(nextQuery, currentQuery)) trail = [];
|
|
58
153
|
params = normalized;
|
|
59
154
|
if (scopeChanged) selection = EMPTY_SELECTION;
|
|
60
155
|
writeRouter(replace);
|
|
156
|
+
save();
|
|
61
157
|
notify();
|
|
62
158
|
};
|
|
63
159
|
const setSelection = (next) => {
|
|
@@ -66,10 +162,13 @@ function createList(options = {}) {
|
|
|
66
162
|
};
|
|
67
163
|
let unsubscribeRouter = null;
|
|
68
164
|
const onRouterChange = () => {
|
|
69
|
-
|
|
70
|
-
|
|
165
|
+
if (restoring && !hasListParams()) return;
|
|
166
|
+
restoring = false;
|
|
167
|
+
const { query: next, view: nextView } = readRouter();
|
|
168
|
+
if (isEqual(next, params) && isEqual(nextView, view)) return;
|
|
71
169
|
if (!isEqual(next.filter, params.filter) || next.q !== params.q) selection = EMPTY_SELECTION;
|
|
72
170
|
params = next;
|
|
171
|
+
view = nextView;
|
|
73
172
|
notify();
|
|
74
173
|
};
|
|
75
174
|
const list = {
|
|
@@ -81,6 +180,10 @@ function createList(options = {}) {
|
|
|
81
180
|
listeners.add(listener);
|
|
82
181
|
if (router !== null && unsubscribeRouter === null) {
|
|
83
182
|
unsubscribeRouter = router.subscribe(onRouterChange);
|
|
183
|
+
if (restoring) {
|
|
184
|
+
restoring = false;
|
|
185
|
+
writeRouter(true);
|
|
186
|
+
}
|
|
84
187
|
onRouterChange();
|
|
85
188
|
}
|
|
86
189
|
return () => {
|
|
@@ -95,33 +198,50 @@ function createList(options = {}) {
|
|
|
95
198
|
...params,
|
|
96
199
|
page
|
|
97
200
|
}),
|
|
201
|
+
nextPage(cursor) {
|
|
202
|
+
const current = params.cursor ?? null;
|
|
203
|
+
setParams({
|
|
204
|
+
...params,
|
|
205
|
+
cursor
|
|
206
|
+
});
|
|
207
|
+
trail = [...trail, current];
|
|
208
|
+
},
|
|
209
|
+
previousPage(cursor) {
|
|
210
|
+
const back = cursor !== void 0 ? cursor : trail.at(-1) ?? null;
|
|
211
|
+
const rest = trail.slice(0, -1);
|
|
212
|
+
setParams({
|
|
213
|
+
...params,
|
|
214
|
+
cursor: back ?? void 0
|
|
215
|
+
});
|
|
216
|
+
trail = rest;
|
|
217
|
+
},
|
|
98
218
|
setPerPage: (perPage) => setParams({
|
|
99
219
|
...params,
|
|
100
220
|
perPage,
|
|
101
|
-
|
|
221
|
+
...FIRST_PAGE
|
|
102
222
|
}),
|
|
103
223
|
setSort: (sort) => setParams({
|
|
104
224
|
...params,
|
|
105
225
|
sort: [...sort],
|
|
106
|
-
|
|
226
|
+
...FIRST_PAGE
|
|
107
227
|
}),
|
|
108
228
|
toggleSort(field) {
|
|
109
229
|
const sort = state.query.sort ?? [];
|
|
110
230
|
if (sort[0] === field) setParams({
|
|
111
231
|
...params,
|
|
112
232
|
sort: [`-${field}`],
|
|
113
|
-
|
|
233
|
+
...FIRST_PAGE
|
|
114
234
|
});
|
|
115
235
|
else if (sort[0] === `-${field}` && params.sort !== void 0) {
|
|
116
236
|
const { sort: _sort, ...rest } = params;
|
|
117
237
|
setParams({
|
|
118
238
|
...rest,
|
|
119
|
-
|
|
239
|
+
...FIRST_PAGE
|
|
120
240
|
});
|
|
121
241
|
} else setParams({
|
|
122
242
|
...params,
|
|
123
243
|
sort: [field],
|
|
124
|
-
|
|
244
|
+
...FIRST_PAGE
|
|
125
245
|
});
|
|
126
246
|
},
|
|
127
247
|
setFilter(id, value) {
|
|
@@ -132,15 +252,31 @@ function createList(options = {}) {
|
|
|
132
252
|
...filter,
|
|
133
253
|
[id]: value
|
|
134
254
|
},
|
|
135
|
-
|
|
255
|
+
...FIRST_PAGE
|
|
136
256
|
});
|
|
137
257
|
},
|
|
138
258
|
setSearch: (q) => setParams({
|
|
139
259
|
...params,
|
|
140
260
|
q,
|
|
141
|
-
|
|
261
|
+
...FIRST_PAGE
|
|
142
262
|
}, { replace: true }),
|
|
143
263
|
resetQuery: () => setParams({}),
|
|
264
|
+
setLayout: (layout) => setView({
|
|
265
|
+
...view,
|
|
266
|
+
layout
|
|
267
|
+
}),
|
|
268
|
+
setColumns: (ids) => setView({
|
|
269
|
+
...view,
|
|
270
|
+
columns: [...ids]
|
|
271
|
+
}, { replace: true }),
|
|
272
|
+
resetColumns() {
|
|
273
|
+
const { columns: _columns, ...rest } = view;
|
|
274
|
+
setView(rest, { replace: true });
|
|
275
|
+
},
|
|
276
|
+
setMonth: (month) => setView({
|
|
277
|
+
...view,
|
|
278
|
+
month
|
|
279
|
+
}),
|
|
144
280
|
select(ids) {
|
|
145
281
|
if (selection.mode === "all") setSelection({
|
|
146
282
|
mode: "all",
|