@panneau/core 5.0.0-alpha.4 → 5.0.0-alpha.41

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.
Files changed (78) hide show
  1. package/README.md +5 -3
  2. package/dist/commands.d.ts +38 -0
  3. package/dist/commands.d.ts.map +1 -0
  4. package/dist/commands.js +22 -0
  5. package/dist/commands.js.map +1 -0
  6. package/dist/definition/abilities.d.ts +33 -5
  7. package/dist/definition/abilities.d.ts.map +1 -1
  8. package/dist/definition/abilities.js +44 -6
  9. package/dist/definition/abilities.js.map +1 -1
  10. package/dist/definition/form.d.ts +16 -7
  11. package/dist/definition/form.d.ts.map +1 -1
  12. package/dist/definition/form.js +39 -6
  13. package/dist/definition/form.js.map +1 -1
  14. package/dist/definition/itemActions.d.ts +53 -0
  15. package/dist/definition/itemActions.d.ts.map +1 -0
  16. package/dist/definition/itemActions.js +64 -0
  17. package/dist/definition/itemActions.js.map +1 -0
  18. package/dist/definition/list.d.ts +43 -1
  19. package/dist/definition/list.d.ts.map +1 -1
  20. package/dist/definition/list.js +104 -16
  21. package/dist/definition/list.js.map +1 -1
  22. package/dist/definition/resource.d.ts +3 -2
  23. package/dist/definition/resource.d.ts.map +1 -1
  24. package/dist/definition/resource.js +3 -2
  25. package/dist/definition/resource.js.map +1 -1
  26. package/dist/form/form.d.ts +8 -3
  27. package/dist/form/form.d.ts.map +1 -1
  28. package/dist/form/form.js +1 -0
  29. package/dist/form/form.js.map +1 -1
  30. package/dist/form/messages.d.ts.map +1 -1
  31. package/dist/form/messages.js +11 -1
  32. package/dist/form/messages.js.map +1 -1
  33. package/dist/form/problem.d.ts +1 -1
  34. package/dist/form/problem.js.map +1 -1
  35. package/dist/form/selectors.d.ts +1 -1
  36. package/dist/form/selectors.js.map +1 -1
  37. package/dist/form/store.d.ts +1 -1
  38. package/dist/form/store.js.map +1 -1
  39. package/dist/index.d.ts +23 -16
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +8 -3
  42. package/dist/list/calendar.d.ts +15 -0
  43. package/dist/list/calendar.d.ts.map +1 -0
  44. package/dist/list/calendar.js +42 -0
  45. package/dist/list/calendar.js.map +1 -0
  46. package/dist/list/list.d.ts +40 -3
  47. package/dist/list/list.d.ts.map +1 -1
  48. package/dist/list/list.js +152 -16
  49. package/dist/list/list.js.map +1 -1
  50. package/dist/list/router.js.map +1 -1
  51. package/dist/list/viewStore.d.ts +36 -0
  52. package/dist/list/viewStore.d.ts.map +1 -0
  53. package/dist/list/viewStore.js +54 -0
  54. package/dist/list/viewStore.js.map +1 -0
  55. package/dist/plugins.d.ts +22 -2
  56. package/dist/plugins.d.ts.map +1 -1
  57. package/dist/plugins.js +5 -2
  58. package/dist/plugins.js.map +1 -1
  59. package/dist/preview.d.ts +14 -0
  60. package/dist/preview.d.ts.map +1 -0
  61. package/dist/react/leaveGuards.d.ts +34 -0
  62. package/dist/react/leaveGuards.d.ts.map +1 -0
  63. package/dist/react/leaveGuards.js +84 -0
  64. package/dist/react/leaveGuards.js.map +1 -0
  65. package/dist/react/provider.d.ts +4 -4
  66. package/dist/react/provider.js +3 -1
  67. package/dist/react/provider.js.map +1 -1
  68. package/dist/react/useForm.d.ts +1 -1
  69. package/dist/react/useForm.js.map +1 -1
  70. package/dist/react/useList.d.ts +1 -1
  71. package/dist/react/useList.js.map +1 -1
  72. package/dist/values.d.ts +1 -1
  73. package/dist/values.d.ts.map +1 -1
  74. package/dist/values.js +5 -1
  75. package/dist/values.js.map +1 -1
  76. package/dist/widget.d.ts +15 -0
  77. package/dist/widget.d.ts.map +1 -0
  78. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","names":[],"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,IAAM,kBAAiC;CAAE,MAAM;CAAO,KAAK,CAAA;AAAG;AAC9D,IAAM,aAAa;;AAGnB,SAAS,UAAU,OAAkB,UAA6C;CAC9E,MAAM,SAAoB,CAAC;CAC3B,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,OAAO,GACzC,OAAO,OAAO,MAAM;CAExB,IAAI,MAAM,YAAY,KAAA,KAAa,MAAM,YAAY,SAAS,SAC1D,OAAO,UAAU,MAAM;CAE3B,IAAI,MAAM,SAAS,KAAA,KAAa,CAAC,QAAQ,MAAM,MAAM,SAAS,IAAI,GAC9D,OAAO,OAAO,CAAC,GAA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Params","ResolvedCalendar","ResolvedList","isEqual","currentMonth","getCalendarRange","isMonth","Router","ListViewState","ListViewStore","RememberedView","createStorageViewStore","ListSelection","mode","ids","except","ListState","query","view","selection","ListDefaults","perPage","sort","layout","columns","calendar","ListOptions","list","defaults","router","remember","key","store","List","getState","subscribe","listener","setPage","page","nextPage","cursor","previousPage","setPerPage","setSort","toggleSort","field","setFilter","id","value","setSearch","q","resetQuery","setLayout","setColumns","resetColumns","setMonth","month","select","deselect","toggle","selectAllMatching","clearSelection","isSelected","getSelectedCount","total","getSelection","EMPTY_SELECTION","FIRST_PAGE","undefined","LIST_PARAM","Defaults","Required","Pick","normalize","result","filter","Object","fromEntries","entries","Array","isArray","length","keys","fields","normalizeView","readView","search","URLSearchParams","get","split","rememberedQuery","createList","options","defaultSort","defaultLayout","layouts","defaultColumns","column","hidden","map","readRouter","getSearch","hasListParams","some","test","remembered","initial","params","restoring","trail","cursors","pagination","sortQuery","calendarQuery","_page","_cursor","_perPage","rest","compute","state","listeners","Set","notify","forEach","writeRouter","replace","delete","append","set","join","next","toString","save","_month","setView","normalized","setParams","scopeChanged","_next","nextQuery","_current","currentQuery","setSelection","unsubscribeRouter","onRouterChange","nextView","add","size","current","back","at","slice","_sort","_removed","_columns","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 { ResolvedCalendar, ResolvedList } from '../definition/list';\nimport { isEqual } from '../values';\nimport { currentMonth, getCalendarRange, isMonth } from './calendar';\nimport type { Router } from './router';\nimport {\n type ListViewState,\n type ListViewStore,\n type RememberedView,\n createStorageViewStore,\n} from './viewStore';\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 /** How the items are shown: the layout and the columns, when they aren't the defaults. */\n view: ListViewState;\n selection: ListSelection;\n}\n\nexport interface ListDefaults {\n perPage?: number;\n /** Default sort, as `sort` query values (`['-published_at']`). */\n sort?: string[];\n /** The default layout. */\n layout?: string;\n /** The ids of the columns shown by default, in their order. */\n columns?: string[];\n /** The calendar of the list, for its `calendar` layout (decision 0044). */\n calendar?: ResolvedCalendar | null;\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 * Remembers the view of the list (filters, sort, page size, layout and columns) under `key`,\n * in `store` (the browser's `localStorage` by default), and restores it when the list opens\n * without a query of its own: a URL without any parameter of the list (decision 0042).\n */\n remember?: { key: string; store?: ListViewStore } | 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. The view stays. */\n resetQuery(): void;\n /** Shows the items in a layout (`cards`). */\n setLayout(layout: string): void;\n /** Shows these columns, by id, in this order. */\n setColumns(ids: readonly string[]): void;\n /** Back to the columns of the definition. */\n resetColumns(): void;\n /** Shows a month in the calendar (`2026-11`). */\n setMonth(month: string): 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|layout|columns|month|filter\\[.+)$/;\n\ntype Defaults = Required<Pick<ListDefaults, 'perPage' | 'sort'>> &\n Pick<ListDefaults, 'layout' | 'columns'> & { calendar: ResolvedCalendar | null };\n\n/** Removes the values that are the defaults, so the URL only keeps what the user changed. */\nfunction normalize(query: ListQuery, defaults: Defaults): 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/** Removes the parts of the view that are the defaults. */\nfunction normalizeView(view: ListViewState, defaults: Defaults): ListViewState {\n const result: ListViewState = {};\n if (view.layout !== undefined && view.layout !== '' && view.layout !== defaults.layout) {\n result.layout = view.layout;\n }\n if (\n view.columns !== undefined &&\n view.columns.length > 0 &&\n !isEqual(view.columns, defaults.columns)\n ) {\n result.columns = [...view.columns];\n }\n if (isMonth(view.month) && view.month !== currentMonth()) {\n result.month = view.month;\n }\n return result;\n}\n\nfunction readView(search: URLSearchParams): ListViewState {\n const view: ListViewState = {};\n const layout = search.get('layout');\n if (layout !== null) {\n view.layout = layout;\n }\n const columns = search.get('columns');\n if (columns !== null) {\n view.columns = columns.split(',').filter((id) => id !== '');\n }\n const month = search.get('month');\n if (month !== null) {\n view.month = month;\n }\n return view;\n}\n\n/** What a list remembers of its query: not its page, cursor or search. */\nfunction rememberedQuery(query: ListQuery): RememberedView['query'] {\n const result: RememberedView['query'] = {};\n if (query.filter !== undefined) {\n result.filter = query.filter;\n }\n if (query.sort !== undefined) {\n result.sort = query.sort;\n }\n if (query.perPage !== undefined) {\n result.perPage = query.perPage;\n }\n return result;\n}\n\n/** Creates a headless list. */\nexport function createList(options: ListOptions = {}): List {\n const defaults: Defaults = {\n perPage: options.defaults?.perPage ?? options.list?.perPage ?? 20,\n sort: options.defaults?.sort ?? options.list?.defaultSort ?? [],\n calendar: options.defaults?.calendar ?? options.list?.calendar ?? null,\n };\n const defaultLayout = options.defaults?.layout ?? options.list?.layouts[0];\n if (defaultLayout !== undefined) {\n defaults.layout = defaultLayout;\n }\n const defaultColumns =\n options.defaults?.columns ??\n options.list?.columns.filter((column) => !column.hidden).map((column) => column.id);\n if (defaultColumns !== undefined) {\n defaults.columns = defaultColumns;\n }\n const router = options.router ?? null;\n const readRouter = (): { query: ListQuery; view: ListViewState } => {\n if (router === null) {\n return { query: {}, view: {} };\n }\n const search = new URLSearchParams(router.getSearch());\n return {\n query: normalize(fromSearchParams(search), defaults),\n view: normalizeView(readView(search), defaults),\n };\n };\n const hasListParams = (): boolean =>\n router !== null &&\n [...new URLSearchParams(router.getSearch()).keys()].some((key) => LIST_PARAM.test(key));\n\n const remember = options.remember ?? null;\n const store = remember !== null ? (remember.store ?? createStorageViewStore()) : null;\n // A list that opens without a query of its own shows the view it remembers.\n const remembered =\n remember !== null &&\n store !== null &&\n (router !== null ? !hasListParams() : options.query === undefined)\n ? store.get(remember.key)\n : null;\n\n const initial = router !== null ? readRouter() : null;\n let params: ListQuery = normalize(\n remembered?.query ?? initial?.query ?? options.query ?? {},\n defaults,\n );\n let view: ListViewState = normalizeView(remembered?.view ?? initial?.view ?? {}, defaults);\n // The remembered view is written to the URL once the list is subscribed to: not while it\n // renders.\n let restoring = remembered !== null && router !== null;\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 sortQuery = (): Pick<ListQuery, 'sort'> =>\n params.sort !== undefined || defaults.sort.length > 0\n ? { sort: params.sort ?? defaults.sort }\n : {};\n // In the calendar, a month: the days around it through its filter, instead of a page.\n const calendarQuery = (calendar: ResolvedCalendar): ListQuery => {\n const { page: _page, cursor: _cursor, perPage: _perPage, ...rest } = params;\n return {\n ...rest,\n ...sortQuery(),\n perPage: calendar.perPage,\n filter: {\n ...params.filter,\n [calendar.filter]: getCalendarRange(view.month ?? currentMonth()),\n },\n };\n };\n const compute = (): ListState => ({\n query:\n defaults.calendar !== null && (view.layout ?? defaults.layout) === 'calendar'\n ? calendarQuery(defaults.calendar)\n : {\n ...params,\n ...(cursors ? {} : { page: params.page ?? 1 }),\n perPage: params.perPage ?? defaults.perPage,\n ...sortQuery(),\n },\n view,\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 if (view.layout !== undefined) {\n search.set('layout', view.layout);\n }\n if (view.columns !== undefined) {\n search.set('columns', view.columns.join(','));\n }\n if (view.month !== undefined) {\n search.set('month', view.month);\n }\n const next = search.toString();\n if (next !== router.getSearch()) {\n router.setSearch(next, { replace });\n }\n };\n\n // Only what the user changes is remembered: not the view of a link they opened.\n const save = () => {\n if (remember === null || store === null) {\n return;\n }\n const query = rememberedQuery(params);\n // A calendar opens on the current month.\n const { month: _month, ...remembered } = view;\n store.set(\n remember.key,\n Object.keys(query).length > 0 || Object.keys(remembered).length > 0\n ? { query, view: remembered }\n : null,\n );\n };\n\n const setView = (next: ListViewState, { replace = false } = {}) => {\n const normalized = normalizeView(next, defaults);\n if (isEqual(normalized, view)) {\n return;\n }\n view = normalized;\n writeRouter(replace);\n save();\n notify();\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 save();\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 // Until the remembered view is in the URL, the bare URL doesn't replace it.\n if (restoring && !hasListParams()) {\n return;\n }\n restoring = false;\n const { query: next, view: nextView } = readRouter();\n if (isEqual(next, params) && isEqual(nextView, view)) {\n return;\n }\n if (!isEqual(next.filter, params.filter) || next.q !== params.q) {\n selection = EMPTY_SELECTION;\n }\n params = next;\n view = nextView;\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 if (restoring) {\n // Replacing the entry: Back doesn't go through the bare URL.\n restoring = false;\n writeRouter(true);\n }\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 setLayout: (layout) => setView({ ...view, layout }),\n setColumns: (ids) => setView({ ...view, columns: [...ids] }, { replace: true }),\n resetColumns() {\n const { columns: _columns, ...rest } = view;\n setView(rest, { replace: true });\n },\n setMonth: (month) => setView({ ...view, month }),\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":";;;;;AA6GA,IAAMuE,kBAAiC;CAAErD,MAAM;CAAOC,KAAK,CAAA;AAAG;;AAE9D,IAAMqD,aAAa;CAAE7B,MAAM;CAAGE,QAAQ4B,KAAAA;AAAU;AAChD,IAAMC,aAAa;;AAMnB,SAASI,UAAUxD,OAAkBW,UAA+B;CAChE,MAAM8C,SAAoB,CAAC;CAC3B,IAAIzD,MAAMqB,SAAS8B,KAAAA,KAAanD,MAAMqB,OAAO,GACzCoC,OAAOpC,OAAOrB,MAAMqB;CAExB,IAAIrB,M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,KAAK+B,SAAS,CAACX,EAAE,CAAC;QAElBpB,KAAK8B,OAAO,CAACV,EAAE,CAAC;EAExB;EACAa,yBAAyBkF,aAAa;GAAEjI,MAAM;GAAOE,QAAQ,CAAA;EAAG,CAAC;EACjE8C,sBAAsBiF,aAAa5E,eAAe;EAClDJ,aAAaf,OACT5B,UAAUN,SAAS,QAAQ,CAACM,UAAUJ,OAAO4I,SAAS5G,EAAE,IAAI5B,UAAUL,IAAI6I,SAAS5G,EAAE;EACzFgB,mBAAmBC,UACf7C,UAAUN,SAAS,QACb+I,KAAKC,IAAI,GAAG7F,QAAQ7C,UAAUJ,OAAOkE,MAAM,IAC3C9D,UAAUL,IAAImE;EACxBhB,eAAe;GACX,IAAI9C,UAAUN,SAAS,OACnB,OAAOM,UAAUL,IAAImE,SAAS,IAAI,EAAEnE,KAAK,CAAC,GAAGK,UAAUL,GAAG,EAAE,IAAI;GAEpE,MAAMG,QAA0D,CAAC;GACjE,IAAI0F,OAAOhC,WAAWP,KAAAA,GAClBnD,MAAM0D,SAASgC,OAAOhC;GAE1B,IAAIgC,OAAOzD,MAAMkB,KAAAA,GACbnD,MAAMiC,IAAIyD,OAAOzD;GAErB,OAAO/B,UAAUJ,OAAOkE,SAAS,IAC3B;IAAEhE;IAAOF,QAAQ,CAAC,GAAGI,UAAUJ,MAAM;GAAE,IACvC,EAAEE,MAAM;EAClB;CACJ;CACA,OAAOU;AACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"router.js","names":[],"sources":["../../src/list/router.ts"],"sourcesContent":["/**\n * The part of a router that lists need: read and write the query string, and know when it\n * changes (back and forward). An app adapts its own router to it.\n */\nexport interface Router {\n /** The current query string, without `?`. */\n getSearch(): string;\n /** Navigates to the same path with another query string. `replace` doesn't add a history entry. */\n setSearch(search: string, options?: { replace?: boolean }): void;\n /** Calls `listener` when the query string changes. Returns a function that unsubscribes. */\n subscribe(listener: () => void): () => void;\n}\n\n/** A router over `window.history` and `window.location`. */\nexport function createHistoryRouter(target: Window = window): Router {\n const listeners = new Set<() => void>();\n const notify = () => listeners.forEach((listener) => listener());\n return {\n getSearch: () => target.location.search.replace(/^\\?/, ''),\n setSearch(search, { replace = false } = {}) {\n const url = `${target.location.pathname}${search !== '' ? `?${search}` : ''}${target.location.hash}`;\n if (replace) {\n target.history.replaceState(target.history.state, '', url);\n } else {\n target.history.pushState(target.history.state, '', url);\n }\n notify();\n },\n subscribe(listener) {\n listeners.add(listener);\n target.addEventListener('popstate', listener);\n return () => {\n listeners.delete(listener);\n target.removeEventListener('popstate', listener);\n };\n },\n };\n}\n\n/** A router that keeps the query string in memory, for tests and embedded lists. */\nexport interface MemoryRouter extends Router {\n /** Query strings of the history entries, the last one being the current one. */\n history: string[];\n /** Goes back to the previous entry, like the browser's back button. */\n back(): void;\n}\n\n/** Creates a router that keeps the query string in memory. */\nexport function createMemoryRouter(initialSearch = ''): MemoryRouter {\n const history = [initialSearch];\n const listeners = new Set<() => void>();\n const notify = () => listeners.forEach((listener) => listener());\n return {\n history,\n getSearch: () => history.at(-1) ?? '',\n back() {\n if (history.length > 1) {\n history.pop();\n notify();\n }\n },\n setSearch(search, { replace = false } = {}) {\n if (replace) {\n history[history.length - 1] = search;\n } else {\n history.push(search);\n }\n notify();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"],"mappings":";;AAcA,SAAgB,oBAAoB,SAAiB,QAAgB;CACjE,MAAM,4BAAY,IAAI,IAAgB;CACtC,MAAM,eAAe,UAAU,SAAS,aAAa,SAAS,CAAC;CAC/D,OAAO;EACH,iBAAiB,OAAO,SAAS,OAAO,QAAQ,OAAO,EAAE;EACzD,UAAU,QAAQ,EAAE,UAAU,UAAU,CAAC,GAAG;GACxC,MAAM,MAAM,GAAG,OAAO,SAAS,WAAW,WAAW,KAAK,IAAI,WAAW,KAAK,OAAO,SAAS;GAC9F,IAAI,SACA,OAAO,QAAQ,aAAa,OAAO,QAAQ,OAAO,IAAI,GAAG;QAEzD,OAAO,QAAQ,UAAU,OAAO,QAAQ,OAAO,IAAI,GAAG;GAE1D,OAAO;EACX;EACA,UAAU,UAAU;GAChB,UAAU,IAAI,QAAQ;GACtB,OAAO,iBAAiB,YAAY,QAAQ;GAC5C,aAAa;IACT,UAAU,OAAO,QAAQ;IACzB,OAAO,oBAAoB,YAAY,QAAQ;GACnD;EACJ;CACJ;AACJ;;AAWA,SAAgB,mBAAmB,gBAAgB,IAAkB;CACjE,MAAM,UAAU,CAAC,aAAa;CAC9B,MAAM,4BAAY,IAAI,IAAgB;CACtC,MAAM,eAAe,UAAU,SAAS,aAAa,SAAS,CAAC;CAC/D,OAAO;EACH;EACA,iBAAiB,QAAQ,GAAG,EAAE,KAAK;EACnC,OAAO;GACH,IAAI,QAAQ,SAAS,GAAG;IACpB,QAAQ,IAAI;IACZ,OAAO;GACX;EACJ;EACA,UAAU,QAAQ,EAAE,UAAU,UAAU,CAAC,GAAG;GACxC,IAAI,SACA,QAAQ,QAAQ,SAAS,KAAK;QAE9B,QAAQ,KAAK,MAAM;GAEvB,OAAO;EACX;EACA,UAAU,UAAU;GAChB,UAAU,IAAI,QAAQ;GACtB,aAAa;IACT,UAAU,OAAO,QAAQ;GAC7B;EACJ;CACJ;AACJ"}
1
+ {"version":3,"file":"router.js","names":["Router","getSearch","setSearch","search","options","replace","subscribe","listener","createHistoryRouter","target","Window","window","listeners","Set","notify","forEach","location","url","pathname","hash","history","replaceState","state","pushState","add","addEventListener","delete","removeEventListener","MemoryRouter","back","createMemoryRouter","initialSearch","at","length","pop","push"],"sources":["../../src/list/router.ts"],"sourcesContent":["/**\n * The part of a router that lists need: read and write the query string, and know when it\n * changes (back and forward). An app adapts its own router to it.\n */\nexport interface Router {\n /** The current query string, without `?`. */\n getSearch(): string;\n /** Navigates to the same path with another query string. `replace` doesn't add a history entry. */\n setSearch(search: string, options?: { replace?: boolean }): void;\n /** Calls `listener` when the query string changes. Returns a function that unsubscribes. */\n subscribe(listener: () => void): () => void;\n}\n\n/** A router over `window.history` and `window.location`. */\nexport function createHistoryRouter(target: Window = window): Router {\n const listeners = new Set<() => void>();\n const notify = () => listeners.forEach((listener) => listener());\n return {\n getSearch: () => target.location.search.replace(/^\\?/, ''),\n setSearch(search, { replace = false } = {}) {\n const url = `${target.location.pathname}${search !== '' ? `?${search}` : ''}${target.location.hash}`;\n if (replace) {\n target.history.replaceState(target.history.state, '', url);\n } else {\n target.history.pushState(target.history.state, '', url);\n }\n notify();\n },\n subscribe(listener) {\n listeners.add(listener);\n target.addEventListener('popstate', listener);\n return () => {\n listeners.delete(listener);\n target.removeEventListener('popstate', listener);\n };\n },\n };\n}\n\n/** A router that keeps the query string in memory, for tests and embedded lists. */\nexport interface MemoryRouter extends Router {\n /** Query strings of the history entries, the last one being the current one. */\n history: string[];\n /** Goes back to the previous entry, like the browser's back button. */\n back(): void;\n}\n\n/** Creates a router that keeps the query string in memory. */\nexport function createMemoryRouter(initialSearch = ''): MemoryRouter {\n const history = [initialSearch];\n const listeners = new Set<() => void>();\n const notify = () => listeners.forEach((listener) => listener());\n return {\n history,\n getSearch: () => history.at(-1) ?? '',\n back() {\n if (history.length > 1) {\n history.pop();\n notify();\n }\n },\n setSearch(search, { replace = false } = {}) {\n if (replace) {\n history[history.length - 1] = search;\n } else {\n history.push(search);\n }\n notify();\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n}\n"],"mappings":";;AAcA,SAAgBQ,oBAAoBC,SAAiBE,QAAgB;CACjE,MAAMC,4BAAY,IAAIC,IAAgB;CACtC,MAAMC,eAAeF,UAAUG,SAASR,aAAaA,SAAS,CAAC;CAC/D,OAAO;EACHN,iBAAiBQ,OAAOO,SAASb,OAAOE,QAAQ,OAAO,EAAE;EACzDH,UAAUC,QAAQ,EAAEE,UAAU,UAAU,CAAC,GAAG;GACxC,MAAMY,MAAM,GAAGR,OAAOO,SAASE,WAAWf,WAAW,KAAK,IAAIA,WAAW,KAAKM,OAAOO,SAASG;GAC9F,IAAId,SACAI,OAAOW,QAAQC,aAAaZ,OAAOW,QAAQE,OAAO,IAAIL,GAAG;QAEzDR,OAAOW,QAAQG,UAAUd,OAAOW,QAAQE,OAAO,IAAIL,GAAG;GAE1DH,OAAO;EACX;EACAR,UAAUC,UAAU;GAChBK,UAAUY,IAAIjB,QAAQ;GACtBE,OAAOgB,iBAAiB,YAAYlB,QAAQ;GAC5C,aAAa;IACTK,UAAUc,OAAOnB,QAAQ;IACzBE,OAAOkB,oBAAoB,YAAYpB,QAAQ;GACnD;EACJ;CACJ;AACJ;;AAWA,SAAgBuB,mBAAmBC,gBAAgB,IAAkB;CACjE,MAAMX,UAAU,CAACW,aAAa;CAC9B,MAAMnB,4BAAY,IAAIC,IAAgB;CACtC,MAAMC,eAAeF,UAAUG,SAASR,aAAaA,SAAS,CAAC;CAC/D,OAAO;EACHa;EACAnB,iBAAiBmB,QAAQY,GAAG,EAAE,KAAK;EACnCH,OAAO;GACH,IAAIT,QAAQa,SAAS,GAAG;IACpBb,QAAQc,IAAI;IACZpB,OAAO;GACX;EACJ;EACAZ,UAAUC,QAAQ,EAAEE,UAAU,UAAU,CAAC,GAAG;GACxC,IAAIA,SACAe,QAAQA,QAAQa,SAAS,KAAK9B;QAE9BiB,QAAQe,KAAKhC,MAAM;GAEvBW,OAAO;EACX;EACAR,UAAUC,UAAU;GAChBK,UAAUY,IAAIjB,QAAQ;GACtB,aAAa;IACTK,UAAUc,OAAOnB,QAAQ;GAC7B;EACJ;CACJ;AACJ"}
@@ -0,0 +1,36 @@
1
+ import type { ListQuery } from '@panneau/protocol';
2
+ /**
3
+ * The view of a list: how it shows its items, not what it fetches (decision 0042). Each part is
4
+ * left out while it is the list's default.
5
+ */
6
+ export interface ListViewState {
7
+ /** The layout chosen (`cards`). */
8
+ layout?: string;
9
+ /** The ids of the columns shown, in their order. */
10
+ columns?: string[];
11
+ /** The month a calendar shows (`2026-11`), when it isn't the current one. Not remembered. */
12
+ month?: string;
13
+ }
14
+ /**
15
+ * What a list remembers of its last view: the filters, sort and page size of its query (not its
16
+ * page, cursor or search), and its view.
17
+ */
18
+ export interface RememberedView {
19
+ query: Pick<ListQuery, 'filter' | 'sort' | 'perPage'>;
20
+ view: ListViewState;
21
+ }
22
+ /**
23
+ * Where lists remember their view, by key. `createStorageViewStore()` keeps them in the browser.
24
+ * Reading is synchronous: a list restores its view before its first fetch.
25
+ */
26
+ export interface ListViewStore {
27
+ get(key: string): RememberedView | null;
28
+ /** Saves the view of a list, or forgets it with `null`. */
29
+ set(key: string, view: RememberedView | null): void;
30
+ }
31
+ /**
32
+ * A store of list views in the browser's `localStorage` (or another `Storage`). Storage that is
33
+ * blocked (private windows, site data settings) or full only means views aren't remembered.
34
+ */
35
+ export declare function createStorageViewStore(storage?: () => Storage | null): ListViewStore;
36
+ //# sourceMappingURL=viewStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewStore.d.ts","sourceRoot":"","sources":["../../src/list/viewStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,mCAAmC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,6FAA6F;IAC7F,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC,CAAC;IACtD,IAAI,EAAE,aAAa,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IACxC,2DAA2D;IAC3D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;CACvD;AA2CD;;;GAGG;AACH,wBAAgB,sBAAsB,CAClC,OAAO,GAAE,MAAM,OAAO,GAAG,IAAqB,GAC/C,aAAa,CAsBf"}
@@ -0,0 +1,54 @@
1
+ //#region src/list/viewStore.ts
2
+ var PREFIX = "panneau:list:";
3
+ function isRecord(value) {
4
+ return value !== null && typeof value === "object" && !Array.isArray(value);
5
+ }
6
+ function isStringArray(value) {
7
+ return Array.isArray(value) && value.every((part) => typeof part === "string");
8
+ }
9
+ /** Reads a stored view, leaving out what isn't one. */
10
+ function parseView(value) {
11
+ if (!isRecord(value) || !isRecord(value.query) || !isRecord(value.view)) return null;
12
+ const { filter, sort, perPage } = value.query;
13
+ const { layout, columns } = value.view;
14
+ const query = {};
15
+ if (isRecord(filter)) query.filter = filter;
16
+ if (isStringArray(sort)) query.sort = sort;
17
+ if (typeof perPage === "number" && Number.isInteger(perPage) && perPage > 0) query.perPage = perPage;
18
+ const view = {};
19
+ if (typeof layout === "string" && layout !== "") view.layout = layout;
20
+ if (isStringArray(columns) && columns.length > 0) view.columns = columns;
21
+ return {
22
+ query,
23
+ view
24
+ };
25
+ }
26
+ function defaultStorage() {
27
+ return typeof window !== "undefined" ? window.localStorage : null;
28
+ }
29
+ /**
30
+ * A store of list views in the browser's `localStorage` (or another `Storage`). Storage that is
31
+ * blocked (private windows, site data settings) or full only means views aren't remembered.
32
+ */
33
+ function createStorageViewStore(storage = defaultStorage) {
34
+ return {
35
+ get(key) {
36
+ try {
37
+ const stored = storage()?.getItem(`${PREFIX}${key}`) ?? null;
38
+ return stored !== null ? parseView(JSON.parse(stored)) : null;
39
+ } catch {
40
+ return null;
41
+ }
42
+ },
43
+ set(key, view) {
44
+ try {
45
+ if (view === null) storage()?.removeItem(`${PREFIX}${key}`);
46
+ else storage()?.setItem(`${PREFIX}${key}`, JSON.stringify(view));
47
+ } catch {}
48
+ }
49
+ };
50
+ }
51
+ //#endregion
52
+ export { createStorageViewStore };
53
+
54
+ //# sourceMappingURL=viewStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewStore.js","names":["ListQuery","ListViewState","layout","columns","month","RememberedView","query","Pick","view","ListViewStore","get","key","set","PREFIX","isRecord","value","Record","Array","isArray","isStringArray","every","part","parseView","filter","sort","perPage","NonNullable","Number","isInteger","length","defaultStorage","Storage","window","localStorage","createStorageViewStore","storage","stored","getItem","JSON","parse","removeItem","setItem","stringify"],"sources":["../../src/list/viewStore.ts"],"sourcesContent":["import type { ListQuery } from '@panneau/protocol';\n\n/**\n * The view of a list: how it shows its items, not what it fetches (decision 0042). Each part is\n * left out while it is the list's default.\n */\nexport interface ListViewState {\n /** The layout chosen (`cards`). */\n layout?: string;\n /** The ids of the columns shown, in their order. */\n columns?: string[];\n /** The month a calendar shows (`2026-11`), when it isn't the current one. Not remembered. */\n month?: string;\n}\n\n/**\n * What a list remembers of its last view: the filters, sort and page size of its query (not its\n * page, cursor or search), and its view.\n */\nexport interface RememberedView {\n query: Pick<ListQuery, 'filter' | 'sort' | 'perPage'>;\n view: ListViewState;\n}\n\n/**\n * Where lists remember their view, by key. `createStorageViewStore()` keeps them in the browser.\n * Reading is synchronous: a list restores its view before its first fetch.\n */\nexport interface ListViewStore {\n get(key: string): RememberedView | null;\n /** Saves the view of a list, or forgets it with `null`. */\n set(key: string, view: RememberedView | null): void;\n}\n\nconst PREFIX = 'panneau:list:';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isStringArray(value: unknown): value is string[] {\n return Array.isArray(value) && value.every((part) => typeof part === 'string');\n}\n\n/** Reads a stored view, leaving out what isn't one. */\nfunction parseView(value: unknown): RememberedView | null {\n if (!isRecord(value) || !isRecord(value.query) || !isRecord(value.view)) {\n return null;\n }\n const { filter, sort, perPage } = value.query;\n const { layout, columns } = value.view;\n const query: RememberedView['query'] = {};\n if (isRecord(filter)) {\n query.filter = filter as NonNullable<ListQuery['filter']>;\n }\n if (isStringArray(sort)) {\n query.sort = sort;\n }\n if (typeof perPage === 'number' && Number.isInteger(perPage) && perPage > 0) {\n query.perPage = perPage;\n }\n const view: ListViewState = {};\n if (typeof layout === 'string' && layout !== '') {\n view.layout = layout;\n }\n if (isStringArray(columns) && columns.length > 0) {\n view.columns = columns;\n }\n return { query, view };\n}\n\nfunction defaultStorage(): Storage | null {\n return typeof window !== 'undefined' ? window.localStorage : null;\n}\n\n/**\n * A store of list views in the browser's `localStorage` (or another `Storage`). Storage that is\n * blocked (private windows, site data settings) or full only means views aren't remembered.\n */\nexport function createStorageViewStore(\n storage: () => Storage | null = defaultStorage,\n): ListViewStore {\n return {\n get(key) {\n try {\n const stored = storage()?.getItem(`${PREFIX}${key}`) ?? null;\n return stored !== null ? parseView(JSON.parse(stored)) : null;\n } catch {\n return null;\n }\n },\n set(key, view) {\n try {\n if (view === null) {\n storage()?.removeItem(`${PREFIX}${key}`);\n } else {\n storage()?.setItem(`${PREFIX}${key}`, JSON.stringify(view));\n }\n } catch {\n // The view then lasts until the page is reloaded.\n }\n },\n };\n}\n"],"mappings":";AAkCA,IAAMa,SAAS;AAEf,SAASC,SAASC,OAAkD;CAChE,OAAOA,UAAU,QAAQ,OAAOA,UAAU,YAAY,CAACE,MAAMC,QAAQH,KAAK;AAC9E;AAEA,SAASI,cAAcJ,OAAmC;CACtD,OAAOE,MAAMC,QAAQH,KAAK,KAAKA,MAAMK,OAAOC,SAAS,OAAOA,SAAS,QAAQ;AACjF;;AAGA,SAASC,UAAUP,OAAuC;CACtD,IAAI,CAACD,SAASC,KAAK,KAAK,CAACD,SAASC,MAAMT,KAAK,KAAK,CAACQ,SAASC,MAAMP,IAAI,GAClE,OAAO;CAEX,MAAM,EAAEe,QAAQC,MAAMC,YAAYV,MAAMT;CACxC,MAAM,EAAEJ,QAAQC,YAAYY,MAAMP;CAClC,MAAMF,QAAiC,CAAC;CACxC,IAAIQ,SAASS,MAAM,GACfjB,MAAMiB,SAASA;CAEnB,IAAIJ,cAAcK,IAAI,GAClBlB,MAAMkB,OAAOA;CAEjB,IAAI,OAAOC,YAAY,YAAYE,OAAOC,UAAUH,OAAO,KAAKA,UAAU,GACtEnB,MAAMmB,UAAUA;CAEpB,MAAMjB,OAAsB,CAAC;CAC7B,IAAI,OAAON,WAAW,YAAYA,WAAW,IACzCM,KAAKN,SAASA;CAElB,IAAIiB,cAAchB,OAAO,KAAKA,QAAQ0B,SAAS,GAC3CrB,KAAKL,UAAUA;CAEnB,OAAO;EAAEG;EAAOE;CAAK;AACzB;AAEA,SAASsB,iBAAiC;CACtC,OAAO,OAAOE,WAAW,cAAcA,OAAOC,eAAe;AACjE;;;;;AAMA,SAAgBC,uBACZC,UAAgCL,gBACnB;CACb,OAAO;EACHpB,IAAIC,KAAK;GACL,IAAI;IACA,MAAMyB,SAASD,QAAQ,CAAC,EAAEE,QAAQ,GAAGxB,SAASF,KAAK,KAAK;IACxD,OAAOyB,WAAW,OAAOd,UAAUgB,KAAKC,MAAMH,MAAM,CAAC,IAAI;GAC7D,QAAQ;IACJ,OAAO;GACX;EACJ;EACAxB,IAAID,KAAKH,MAAM;GACX,IAAI;IACA,IAAIA,SAAS,MACT2B,QAAQ,CAAC,EAAEK,WAAW,GAAG3B,SAASF,KAAK;SAEvCwB,QAAQ,CAAC,EAAEM,QAAQ,GAAG5B,SAASF,OAAO2B,KAAKI,UAAUlC,IAAI,CAAC;GAElE,QAAQ,CACJ;EAER;CACJ;AACJ"}
package/dist/plugins.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ComponentType } from 'react';
2
2
  import type { DefinitionTheme, Theme } from '@panneau/protocol';
3
+ import type { CommandSource } from './commands.js';
3
4
  /** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */
4
5
  export type { Theme };
5
6
  /**
@@ -27,17 +28,32 @@ export interface PanneauPlugin {
27
28
  actions?: Record<string, PluginComponent>;
28
29
  /** Pages, by component name (`dashboard`). */
29
30
  pages?: Record<string, PluginComponent>;
30
- /** Dashboard widgets, by widget type (`stat`). */
31
+ /**
32
+ * Dashboard widgets, by widget type (`map`). They get `WidgetProps`. The built-in types
33
+ * (`stat`, `series`, `list`) stay built in: the `dashboard` page is what a plugin replaces.
34
+ */
31
35
  widgets?: Record<string, PluginComponent>;
32
36
  /** Layout node components, for `component` nodes of form layouts. */
33
37
  components?: Record<string, PluginComponent>;
38
+ /**
39
+ * Panels of the sidebar of forms, by name, for `sidebar` nodes with a `panel` (decision 0075).
40
+ * They get `FormPanelProps` of `@panneau/forms`. A later plugin overrides a built-in panel.
41
+ */
42
+ panels?: Record<string, PluginComponent>;
43
+ /**
44
+ * Previews of items, by name, for resources whose `features.preview` is a `component`
45
+ * (`{ "mode": "component", "component": "page" }`). They get `PreviewProps`.
46
+ */
47
+ previews?: Record<string, PluginComponent>;
48
+ /** Commands of the "Go to…" palette, or a function that makes them for the definition. */
49
+ commands?: CommandSource;
34
50
  /** UI messages, by locale. Messages of later plugins override earlier ones. */
35
51
  locales?: Record<string, MessagesLoader>;
36
52
  /** Themes, by id, that the theme of the definition can extend. */
37
53
  themes?: Record<string, Theme>;
38
54
  }
39
55
  /** The kinds of components a plugin can provide. */
40
- export type PluginComponentKind = 'fields' | 'displays' | 'listLayouts' | 'actions' | 'pages' | 'widgets' | 'components';
56
+ export type PluginComponentKind = 'fields' | 'displays' | 'listLayouts' | 'actions' | 'pages' | 'widgets' | 'components' | 'panels' | 'previews';
41
57
  /** Everything the plugins provide, merged. A later plugin overrides an earlier one. */
42
58
  export interface PluginRegistry {
43
59
  /** The plugins, in order. */
@@ -49,6 +65,10 @@ export interface PluginRegistry {
49
65
  pages: ReadonlyMap<string, PluginComponent>;
50
66
  widgets: ReadonlyMap<string, PluginComponent>;
51
67
  components: ReadonlyMap<string, PluginComponent>;
68
+ panels: ReadonlyMap<string, PluginComponent>;
69
+ previews: ReadonlyMap<string, PluginComponent>;
70
+ /** The commands of the plugins, in plugin order: `getCommands()` makes them. */
71
+ commands: readonly CommandSource[];
52
72
  /** Message loaders of each locale, in plugin order. */
53
73
  locales: ReadonlyMap<string, readonly MessagesLoader[]>;
54
74
  themes: ReadonlyMap<string, Theme>;
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGhE,sFAAsF;AACtF,YAAY,EAAE,KAAK,EAAE,CAAC;AAEtB;;;GAGG;AAEH,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAEjD,oDAAoD;AACpD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,kFAAkF;AAClF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,GAAG;IAAE,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC,CAAC;AAE1F,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC1B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC3C,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC1C,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CA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,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC5C,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC9C,UAAU,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC7C,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC/C,gFAAgF;IAChF,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,uDAAuD;IACvD,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC,CAAC;IACxD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CACtC;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAEjE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,aAAa,EAAE,GAAG,cAAc,CA6BtF;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAkB9F;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,eAAe,GAAG,SAAS,EAClC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GACnC,KAAK,CAWP"}
package/dist/plugins.js CHANGED
@@ -7,7 +7,9 @@ var COMPONENT_KINDS = [
7
7
  "actions",
8
8
  "pages",
9
9
  "widgets",
10
- "components"
10
+ "components",
11
+ "panels",
12
+ "previews"
11
13
  ];
12
14
  /** Declares a plugin. It returns the plugin as is, with its type checked. */
13
15
  function definePlugin(plugin) {
@@ -32,7 +34,8 @@ function createPluginRegistry(plugins) {
32
34
  plugins: [...plugins],
33
35
  ...components,
34
36
  locales,
35
- themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {})))
37
+ themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {}))),
38
+ commands: plugins.flatMap((plugin) => plugin.commands !== void 0 ? [plugin.commands] : [])
36
39
  };
37
40
  }
38
41
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":[],"sources":["../src/plugins.ts"],"sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DefinitionTheme, Theme } from '@panneau/protocol';\nimport { mergeThemes } from '@panneau/protocol/runtime';\n\n/** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */\nexport type { Theme };\n\n/**\n * A component provided by a plugin. Its props are defined by the package that renders it (fields,\n * lists, app), so the registry stores it as given.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\nexport type PluginComponent = ComponentType<any>;\n\n/** UI messages of a locale, keyed by message id. */\nexport type Messages = Record<string, string>;\n\n/** Messages, or a function that loads them (`() => import('./lang/fr.json')`). */\nexport type MessagesLoader = Messages | (() => Promise<Messages | { default: Messages }>);\n\n/** What a plugin adds to Panneau. Every part is keyed by the name the definition uses. */\nexport interface PanneauPlugin {\n /** Unique id of the plugin. */\n id: string;\n /** Field components, by field type (`text`, `page-slug`). */\n fields?: Record<string, PluginComponent>;\n /** Components that display a value in lists, by display (`date`, `page-slug`). */\n displays?: Record<string, PluginComponent>;\n /** List layouts, by id (`table`, `cards`). */\n listLayouts?: Record<string, PluginComponent>;\n /** Handlers of `client` actions, by the action's `component`. */\n actions?: Record<string, PluginComponent>;\n /** Pages, by component name (`dashboard`). */\n pages?: Record<string, PluginComponent>;\n /** Dashboard widgets, by widget type (`stat`). */\n widgets?: Record<string, PluginComponent>;\n /** Layout node components, for `component` nodes of form layouts. */\n components?: Record<string, PluginComponent>;\n /** UI messages, by locale. Messages of later plugins override earlier ones. */\n locales?: Record<string, MessagesLoader>;\n /** Themes, by id, that the theme of the definition can extend. */\n themes?: Record<string, Theme>;\n}\n\n/** The kinds of components a plugin can provide. */\nexport type PluginComponentKind =\n 'fields' | 'displays' | 'listLayouts' | 'actions' | 'pages' | 'widgets' | 'components';\n\nconst COMPONENT_KINDS: PluginComponentKind[] = [\n 'fields',\n 'displays',\n 'listLayouts',\n 'actions',\n 'pages',\n 'widgets',\n 'components',\n];\n\n/** Everything the plugins provide, merged. A later plugin overrides an earlier one. */\nexport interface PluginRegistry {\n /** The plugins, in order. */\n plugins: readonly PanneauPlugin[];\n fields: ReadonlyMap<string, PluginComponent>;\n displays: ReadonlyMap<string, PluginComponent>;\n listLayouts: ReadonlyMap<string, PluginComponent>;\n actions: ReadonlyMap<string, PluginComponent>;\n pages: ReadonlyMap<string, PluginComponent>;\n widgets: ReadonlyMap<string, PluginComponent>;\n components: ReadonlyMap<string, PluginComponent>;\n /** Message loaders of each locale, in plugin order. */\n locales: ReadonlyMap<string, readonly MessagesLoader[]>;\n themes: ReadonlyMap<string, Theme>;\n}\n\n/** Declares a plugin. It returns the plugin as is, with its type checked. */\nexport function definePlugin(plugin: PanneauPlugin): PanneauPlugin {\n return plugin;\n}\n\n/**\n * Merges plugins into a registry. Later plugins override the components and themes of earlier\n * ones, so a project can replace a built-in field. Plugin ids must be unique.\n */\nexport function createPluginRegistry(plugins: readonly PanneauPlugin[]): PluginRegistry {\n const ids = new Set<string>();\n plugins.forEach((plugin) => {\n if (ids.has(plugin.id)) {\n throw new Error(`Two plugins have the id \\`${plugin.id}\\`.`);\n }\n ids.add(plugin.id);\n });\n const components = Object.fromEntries(\n COMPONENT_KINDS.map((kind) => [\n kind,\n new Map(plugins.flatMap((plugin) => Object.entries(plugin[kind] ?? {}))),\n ]),\n ) as Record<PluginComponentKind, Map<string, PluginComponent>>;\n const locales = new Map<string, MessagesLoader[]>();\n plugins.forEach((plugin) =>\n Object.entries(plugin.locales ?? {}).forEach(([locale, loader]) => {\n locales.set(locale, [...(locales.get(locale) ?? []), loader]);\n }),\n );\n return {\n plugins: [...plugins],\n ...components,\n locales,\n themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {}))),\n };\n}\n\n/**\n * Loads the messages of a locale from every plugin that provides it, merged in plugin order. A\n * regional locale (`fr-CA`) falls back to its language (`fr`) for missing messages.\n */\nexport async function loadMessages(registry: PluginRegistry, locale: string): Promise<Messages> {\n const language = locale.split('-')[0] ?? locale;\n const loaders = [\n ...(language !== locale ? (registry.locales.get(language) ?? []) : []),\n ...(registry.locales.get(locale) ?? []),\n ];\n const loaded = await Promise.all(\n loaders.map(async (loader) => {\n if (typeof loader !== 'function') {\n return loader;\n }\n const result = await loader();\n return 'default' in result && typeof result.default === 'object'\n ? (result.default as Messages)\n : (result as Messages);\n }),\n );\n return Object.assign({}, ...loaded) as Messages;\n}\n\n/**\n * The theme of the admin: the themes of plugins that the definition's theme extends, in order, then\n * the definition's own tokens, tones and variants. An id no plugin registers is skipped, with a\n * warning.\n */\nexport function resolveTheme(\n theme: DefinitionTheme | undefined,\n themes: ReadonlyMap<string, Theme>,\n): Theme {\n const { colorScheme: _colorScheme, extends: ids, ...own } = theme ?? {};\n const extended = (typeof ids === 'string' ? [ids] : (ids ?? [])).flatMap((id) => {\n const found = themes.get(id);\n if (found === undefined) {\n console.warn(`[panneau] No plugin registers the theme \"${id}\".`);\n return [];\n }\n return [found];\n });\n return mergeThemes(...extended, own);\n}\n"],"mappings":";;AAiDA,IAAM,kBAAyC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;AAAY;;AAoBhB,SAAgB,aAAa,QAAsC;CAC/D,OAAO;AACX;;;;;AAMA,SAAgB,qBAAqB,SAAmD;CACpF,MAAM,sBAAM,IAAI,IAAY;CAC5B,QAAQ,SAAS,WAAW;EACxB,IAAI,IAAI,IAAI,OAAO,EAAE,GACjB,MAAM,IAAI,MAAM,6BAA6B,OAAO,GAAE,IAAK;EAE/D,IAAI,IAAI,OAAO,EAAE;CACrB,CAAC;CACD,MAAM,aAAa,OAAO,YACtB,gBAAgB,KAAK,SAAS,CAC1B,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;EAC3B,IAAI,UAAU,KAAA,GAAW;GACrB,QAAQ,KAAK,4CAA4C,GAAE,GAAI;GAC/D,OAAO,CAAA;EACX;EACA,OAAO,CAAC,KAAK;CACjB,CAAC;CACD,OAAO,YAAY,GAAG,UAAU,GAAG;AACvC"}
1
+ {"version":3,"file":"plugins.js","names":["ComponentType","DefinitionTheme","Theme","mergeThemes","CommandSource","PluginComponent","Messages","Record","MessagesLoader","Promise","default","PanneauPlugin","id","fields","displays","listLayouts","actions","pages","widgets","components","panels","previews","commands","locales","themes","PluginComponentKind","COMPONENT_KINDS","PluginRegistry","plugins","ReadonlyMap","definePlugin","plugin","createPluginRegistry","ids","Set","forEach","has","Error","add","Object","fromEntries","map","kind","Map","flatMap","entries","locale","loader","set","get","undefined","loadMessages","registry","language","split","loaders","loaded","all","result","assign","resolveTheme","theme","colorScheme","_colorScheme","extends","own","extended","found","console","warn"],"sources":["../src/plugins.ts"],"sourcesContent":["import type { ComponentType } from 'react';\n\nimport type { DefinitionTheme, Theme } from '@panneau/protocol';\nimport { mergeThemes } from '@panneau/protocol/runtime';\n\nimport type { CommandSource } from './commands';\n\n/** A theme of `@panneau/ui`, as plain data: what plugins register (decision 0024). */\nexport type { Theme };\n\n/**\n * A component provided by a plugin. Its props are defined by the package that renders it (fields,\n * lists, app), so the registry stores it as given.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\nexport type PluginComponent = ComponentType<any>;\n\n/** UI messages of a locale, keyed by message id. */\nexport type Messages = Record<string, string>;\n\n/** Messages, or a function that loads them (`() => import('./lang/fr.json')`). */\nexport type MessagesLoader = Messages | (() => Promise<Messages | { default: Messages }>);\n\n/** What a plugin adds to Panneau. Every part is keyed by the name the definition uses. */\nexport interface PanneauPlugin {\n /** Unique id of the plugin. */\n id: string;\n /** Field components, by field type (`text`, `page-slug`). */\n fields?: Record<string, PluginComponent>;\n /** Components that display a value in lists, by display (`date`, `page-slug`). */\n displays?: Record<string, PluginComponent>;\n /** List layouts, by id (`table`, `cards`). */\n listLayouts?: Record<string, PluginComponent>;\n /** Handlers of `client` actions, by the action's `component`. */\n actions?: Record<string, PluginComponent>;\n /** Pages, by component name (`dashboard`). */\n pages?: Record<string, PluginComponent>;\n /**\n * Dashboard widgets, by widget type (`map`). They get `WidgetProps`. The built-in types\n * (`stat`, `series`, `list`) stay built in: the `dashboard` page is what a plugin replaces.\n */\n widgets?: Record<string, PluginComponent>;\n /** Layout node components, for `component` nodes of form layouts. */\n components?: Record<string, PluginComponent>;\n /**\n * Panels of the sidebar of forms, by name, for `sidebar` nodes with a `panel` (decision 0075).\n * They get `FormPanelProps` of `@panneau/forms`. A later plugin overrides a built-in panel.\n */\n panels?: Record<string, PluginComponent>;\n /**\n * Previews of items, by name, for resources whose `features.preview` is a `component`\n * (`{ \"mode\": \"component\", \"component\": \"page\" }`). They get `PreviewProps`.\n */\n previews?: Record<string, PluginComponent>;\n /** Commands of the \"Go to…\" palette, or a function that makes them for the definition. */\n commands?: CommandSource;\n /** UI messages, by locale. Messages of later plugins override earlier ones. */\n locales?: Record<string, MessagesLoader>;\n /** Themes, by id, that the theme of the definition can extend. */\n themes?: Record<string, Theme>;\n}\n\n/** The kinds of components a plugin can provide. */\nexport type PluginComponentKind =\n | 'fields'\n | 'displays'\n | 'listLayouts'\n | 'actions'\n | 'pages'\n | 'widgets'\n | 'components'\n | 'panels'\n | 'previews';\n\nconst COMPONENT_KINDS: PluginComponentKind[] = [\n 'fields',\n 'displays',\n 'listLayouts',\n 'actions',\n 'pages',\n 'widgets',\n 'components',\n 'panels',\n 'previews',\n];\n\n/** Everything the plugins provide, merged. A later plugin overrides an earlier one. */\nexport interface PluginRegistry {\n /** The plugins, in order. */\n plugins: readonly PanneauPlugin[];\n fields: ReadonlyMap<string, PluginComponent>;\n displays: ReadonlyMap<string, PluginComponent>;\n listLayouts: ReadonlyMap<string, PluginComponent>;\n actions: ReadonlyMap<string, PluginComponent>;\n pages: ReadonlyMap<string, PluginComponent>;\n widgets: ReadonlyMap<string, PluginComponent>;\n components: ReadonlyMap<string, PluginComponent>;\n panels: ReadonlyMap<string, PluginComponent>;\n previews: ReadonlyMap<string, PluginComponent>;\n /** The commands of the plugins, in plugin order: `getCommands()` makes them. */\n commands: readonly CommandSource[];\n /** Message loaders of each locale, in plugin order. */\n locales: ReadonlyMap<string, readonly MessagesLoader[]>;\n themes: ReadonlyMap<string, Theme>;\n}\n\n/** Declares a plugin. It returns the plugin as is, with its type checked. */\nexport function definePlugin(plugin: PanneauPlugin): PanneauPlugin {\n return plugin;\n}\n\n/**\n * Merges plugins into a registry. Later plugins override the components and themes of earlier\n * ones, so a project can replace a built-in field. Plugin ids must be unique.\n */\nexport function createPluginRegistry(plugins: readonly PanneauPlugin[]): PluginRegistry {\n const ids = new Set<string>();\n plugins.forEach((plugin) => {\n if (ids.has(plugin.id)) {\n throw new Error(`Two plugins have the id \\`${plugin.id}\\`.`);\n }\n ids.add(plugin.id);\n });\n const components = Object.fromEntries(\n COMPONENT_KINDS.map((kind) => [\n kind,\n new Map(plugins.flatMap((plugin) => Object.entries(plugin[kind] ?? {}))),\n ]),\n ) as Record<PluginComponentKind, Map<string, PluginComponent>>;\n const locales = new Map<string, MessagesLoader[]>();\n plugins.forEach((plugin) =>\n Object.entries(plugin.locales ?? {}).forEach(([locale, loader]) => {\n locales.set(locale, [...(locales.get(locale) ?? []), loader]);\n }),\n );\n return {\n plugins: [...plugins],\n ...components,\n locales,\n themes: new Map(plugins.flatMap((plugin) => Object.entries(plugin.themes ?? {}))),\n commands: plugins.flatMap((plugin) =>\n plugin.commands !== undefined ? [plugin.commands] : [],\n ),\n };\n}\n\n/**\n * Loads the messages of a locale from every plugin that provides it, merged in plugin order. A\n * regional locale (`fr-CA`) falls back to its language (`fr`) for missing messages.\n */\nexport async function loadMessages(registry: PluginRegistry, locale: string): Promise<Messages> {\n const language = locale.split('-')[0] ?? locale;\n const loaders = [\n ...(language !== locale ? (registry.locales.get(language) ?? []) : []),\n ...(registry.locales.get(locale) ?? []),\n ];\n const loaded = await Promise.all(\n loaders.map(async (loader) => {\n if (typeof loader !== 'function') {\n return loader;\n }\n const result = await loader();\n return 'default' in result && typeof result.default === 'object'\n ? (result.default as Messages)\n : (result as Messages);\n }),\n );\n return Object.assign({}, ...loaded) as Messages;\n}\n\n/**\n * The theme of the admin: the themes of plugins that the definition's theme extends, in order, then\n * the definition's own tokens, tones and variants. An id no plugin registers is skipped, with a\n * warning.\n */\nexport function resolveTheme(\n theme: DefinitionTheme | undefined,\n themes: ReadonlyMap<string, Theme>,\n): Theme {\n const { colorScheme: _colorScheme, extends: ids, ...own } = theme ?? {};\n const extended = (typeof ids === 'string' ? [ids] : (ids ?? [])).flatMap((id) => {\n const found = themes.get(id);\n if (found === undefined) {\n console.warn(`[panneau] No plugin registers the theme \"${id}\".`);\n return [];\n }\n return [found];\n });\n return mergeThemes(...extended, own);\n}\n"],"mappings":";;AA0EA,IAAM0B,kBAAyC;CAC3C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AAAU;;AAwBd,SAAgBI,aAAaC,QAAsC;CAC/D,OAAOA;AACX;;;;;AAMA,SAAgBC,qBAAqBJ,SAAmD;CACpF,MAAMK,sBAAM,IAAIC,IAAY;CAC5BN,QAAQO,SAASJ,WAAW;EACxB,IAAIE,IAAIG,IAAIL,OAAOnB,EAAE,GACjB,MAAM,IAAIyB,MAAM,6BAA6BN,OAAOnB,GAAE,IAAK;EAE/DqB,IAAIK,IAAIP,OAAOnB,EAAE;CACrB,CAAC;CACD,MAAMO,aAAaoB,OAAOC,YACtBd,gBAAgBe,KAAKC,SAAS,CAC1BA,MACA,IAAIC,IAAIf,QAAQgB,SAASb,WAAWQ,OAAOM,QAAQd,OAAOW,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3E,CACL;CACA,MAAMnB,0BAAU,IAAIoB,IAA8B;CAClDf,QAAQO,SAASJ,WACbQ,OAAOM,QAAQd,OAAOR,WAAW,CAAC,CAAC,CAAC,CAACY,SA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rC,EAAE;EAC3B,IAAIuD,UAAUjB,KAAAA,GAAW;GACrBkB,QAAQC,KAAK,4CAA4CzD,GAAE,GAAI;GAC/D,OAAO,CAAA;EACX;EACA,OAAO,CAACuD,KAAK;CACjB,CAAC;CACD,OAAOhE,YAAY,GAAG+D,UAAUD,GAAG;AACvC"}
@@ -0,0 +1,14 @@
1
+ import type { Item, Resource } from '@panneau/protocol';
2
+ /**
3
+ * Props of a preview component (the `previews` of a plugin), for a resource whose
4
+ * `features.preview` is `{ "mode": "component", "component": "<name>" }`. It renders the item as
5
+ * the site would, or anything richer than its values: blocks, partials, charts.
6
+ */
7
+ export interface PreviewProps {
8
+ /** The item: as saved, or with the unsaved values of a form. */
9
+ item: Item;
10
+ resource: Resource;
11
+ /** The locale of the content to show, for localized values. */
12
+ locale: string;
13
+ }
14
+ //# sourceMappingURL=preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IACzB,gEAAgE;IAChE,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,34 @@
1
+ import { type ReactNode } from 'react';
2
+ /** Asks whether the user may leave: resolves `true` to leave, `false` to stay. */
3
+ export type LeaveGuard = () => Promise<boolean>;
4
+ /**
5
+ * What guards in-app navigation: forms with unsaved changes add a guard while they are dirty,
6
+ * and the router asks them before it leaves the page.
7
+ */
8
+ export interface LeaveGuards {
9
+ /** Adds a guard. Returns a function that removes it. */
10
+ add(guard: LeaveGuard): () => void;
11
+ /** Whether a guard would ask: leaving now needs a confirmation. */
12
+ isBlocking(): boolean;
13
+ /** Asks each guard in turn. Resolves `true` when every one lets the user leave. */
14
+ confirmLeave(): Promise<boolean>;
15
+ }
16
+ /** Creates the guards of an app, for `LeaveGuardsProvider`. */
17
+ export declare function createLeaveGuards(): LeaveGuards;
18
+ export interface LeaveGuardsProviderProps {
19
+ guards: LeaveGuards;
20
+ children?: ReactNode;
21
+ }
22
+ /**
23
+ * Gives the guards of the app's router to the forms below it, so that leaving a page with unsaved
24
+ * changes asks first. Without it, forms only guard closing and reloading the page.
25
+ */
26
+ export declare function LeaveGuardsProvider({ guards, children }: LeaveGuardsProviderProps): import("react").JSX.Element;
27
+ /** The guards of the closest `LeaveGuardsProvider`, or `null`. */
28
+ export declare function useLeaveGuards(): LeaveGuards | null;
29
+ /**
30
+ * Adds `guard` to the guards of the closest `LeaveGuardsProvider` while `active` is true, such
31
+ * as while a form has unsaved changes. The latest `guard` is the one asked.
32
+ */
33
+ export declare function useLeaveGuard(active: boolean, guard: LeaveGuard): void;
34
+ //# sourceMappingURL=leaveGuards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaveGuards.d.ts","sourceRoot":"","sources":["../../src/react/leaveGuards.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAyC,MAAM,OAAO,CAAC;AAE9E,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,wDAAwD;IACxD,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,IAAI,CAAC;IACnC,mEAAmE;IACnE,UAAU,IAAI,OAAO,CAAC;IACtB,mFAAmF;IACnF,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC;AAED,+DAA+D;AAC/D,wBAAgB,iBAAiB,IAAI,WAAW,CAmB/C;AAID,MAAM,WAAW,wBAAwB;IACrC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,wBAAwB,+BAEjF;AAED,kEAAkE;AAClE,wBAAgB,cAAc,IAAI,WAAW,GAAG,IAAI,CAEnD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAYtE"}
@@ -0,0 +1,84 @@
1
+ import { c } from "react/compiler-runtime";
2
+ import { createContext, use, useEffect, useRef } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/react/leaveGuards.tsx
5
+ /** Creates the guards of an app, for `LeaveGuardsProvider`. */
6
+ function createLeaveGuards() {
7
+ const guards = /* @__PURE__ */ new Set();
8
+ return {
9
+ add(guard) {
10
+ guards.add(guard);
11
+ return () => {
12
+ guards.delete(guard);
13
+ };
14
+ },
15
+ isBlocking: () => guards.size > 0,
16
+ async confirmLeave() {
17
+ for (const guard of [...guards]) if (!await guard()) return false;
18
+ return true;
19
+ }
20
+ };
21
+ }
22
+ var LeaveGuardsContext = createContext(null);
23
+ /**
24
+ * Gives the guards of the app's router to the forms below it, so that leaving a page with unsaved
25
+ * changes asks first. Without it, forms only guard closing and reloading the page.
26
+ */
27
+ function LeaveGuardsProvider(t0) {
28
+ const $ = c(3);
29
+ const { guards, children } = t0;
30
+ let t1;
31
+ if ($[0] !== children || $[1] !== guards) {
32
+ t1 = /* @__PURE__ */ jsx(LeaveGuardsContext, {
33
+ value: guards,
34
+ children
35
+ });
36
+ $[0] = children;
37
+ $[1] = guards;
38
+ $[2] = t1;
39
+ } else t1 = $[2];
40
+ return t1;
41
+ }
42
+ /** The guards of the closest `LeaveGuardsProvider`, or `null`. */
43
+ function useLeaveGuards() {
44
+ return use(LeaveGuardsContext);
45
+ }
46
+ /**
47
+ * Adds `guard` to the guards of the closest `LeaveGuardsProvider` while `active` is true, such
48
+ * as while a form has unsaved changes. The latest `guard` is the one asked.
49
+ */
50
+ function useLeaveGuard(active, guard) {
51
+ const $ = c(6);
52
+ const guards = useLeaveGuards();
53
+ const latest = useRef(guard);
54
+ let t0;
55
+ if ($[0] !== guard) {
56
+ t0 = () => {
57
+ latest.current = guard;
58
+ };
59
+ $[0] = guard;
60
+ $[1] = t0;
61
+ } else t0 = $[1];
62
+ useEffect(t0);
63
+ let t1;
64
+ let t2;
65
+ if ($[2] !== active || $[3] !== guards) {
66
+ t1 = () => {
67
+ if (!active || guards === null) return;
68
+ return guards.add(() => latest.current());
69
+ };
70
+ t2 = [active, guards];
71
+ $[2] = active;
72
+ $[3] = guards;
73
+ $[4] = t1;
74
+ $[5] = t2;
75
+ } else {
76
+ t1 = $[4];
77
+ t2 = $[5];
78
+ }
79
+ useEffect(t1, t2);
80
+ }
81
+ //#endregion
82
+ export { LeaveGuardsProvider, createLeaveGuards, useLeaveGuard, useLeaveGuards };
83
+
84
+ //# sourceMappingURL=leaveGuards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaveGuards.js","names":["ReactNode","createContext","use","useEffect","useRef","LeaveGuard","Promise","LeaveGuards","add","guard","isBlocking","confirmLeave","createLeaveGuards","guards","Set","delete","size","LeaveGuardsContext","LeaveGuardsProviderProps","children","LeaveGuardsProvider","t0","$","_c","t1","useLeaveGuards","useLeaveGuard","active","latest","current","t2","_c"],"sources":["../../src/react/leaveGuards.tsx"],"sourcesContent":["import { type ReactNode, createContext, use, useEffect, useRef } from 'react';\n\n/** Asks whether the user may leave: resolves `true` to leave, `false` to stay. */\nexport type LeaveGuard = () => Promise<boolean>;\n\n/**\n * What guards in-app navigation: forms with unsaved changes add a guard while they are dirty,\n * and the router asks them before it leaves the page.\n */\nexport interface LeaveGuards {\n /** Adds a guard. Returns a function that removes it. */\n add(guard: LeaveGuard): () => void;\n /** Whether a guard would ask: leaving now needs a confirmation. */\n isBlocking(): boolean;\n /** Asks each guard in turn. Resolves `true` when every one lets the user leave. */\n confirmLeave(): Promise<boolean>;\n}\n\n/** Creates the guards of an app, for `LeaveGuardsProvider`. */\nexport function createLeaveGuards(): LeaveGuards {\n const guards = new Set<LeaveGuard>();\n return {\n add(guard) {\n guards.add(guard);\n return () => {\n guards.delete(guard);\n };\n },\n isBlocking: () => guards.size > 0,\n async confirmLeave() {\n for (const guard of [...guards]) {\n if (!(await guard())) {\n return false;\n }\n }\n return true;\n },\n };\n}\n\nconst LeaveGuardsContext = createContext<LeaveGuards | null>(null);\n\nexport interface LeaveGuardsProviderProps {\n guards: LeaveGuards;\n children?: ReactNode;\n}\n\n/**\n * Gives the guards of the app's router to the forms below it, so that leaving a page with unsaved\n * changes asks first. Without it, forms only guard closing and reloading the page.\n */\nexport function LeaveGuardsProvider({ guards, children }: LeaveGuardsProviderProps) {\n return <LeaveGuardsContext value={guards}>{children}</LeaveGuardsContext>;\n}\n\n/** The guards of the closest `LeaveGuardsProvider`, or `null`. */\nexport function useLeaveGuards(): LeaveGuards | null {\n return use(LeaveGuardsContext);\n}\n\n/**\n * Adds `guard` to the guards of the closest `LeaveGuardsProvider` while `active` is true, such\n * as while a form has unsaved changes. The latest `guard` is the one asked.\n */\nexport function useLeaveGuard(active: boolean, guard: LeaveGuard): void {\n const guards = useLeaveGuards();\n const latest = useRef(guard);\n useEffect(() => {\n latest.current = guard;\n });\n useEffect(() => {\n if (!active || guards === null) {\n return undefined;\n }\n return guards.add(() => latest.current());\n }, [active, guards]);\n}\n"],"mappings":";;;;;AAmBA,SAAgBY,oBAAiC;CAC7C,MAAMC,yBAAS,IAAIC,IAAgB;CACnC,OAAO;EACHN,IAAIC,OAAO;GACPI,OAAOL,IAAIC,KAAK;GAChB,aAAa;IACTI,OAAOE,OAAON,KAAK;GACvB;EACJ;EACAC,kBAAkBG,OAAOG,OAAO;EAChC,MAAML,eAAe;GACjB,KAAK,MAAMF,SAAS,CAAC,GAAGI,MAAM,GAC1B,IAAI,CAAE,MAAMJ,MAAM,GACd,OAAO;GAGf,OAAO;EACX;CACJ;AACJ;AAEA,IAAMQ,qBAAqBhB,cAAkC,IAAI;;;;;AAWjE,SAAOmB,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAA6B,MAAA,EAAAV,QAAAM,aAAAE;CAA8C,IAAAG;CAAA,IAAAF,EAAA,OAAAH,YAAAG,EAAA,OAAAT,QAAA;EACvEW,KAAA,oBAAC,oBAAD;GAA2BX,OAAAA;GAASM;EAAjB,CAAA;EAA+CG,EAAA,KAAAH;EAAAG,EAAA,KAAAT;EAAAS,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OAAlEE;AAAkE;;AAI7E,SAAgBC,iBAAqC;CACjD,OAAOvB,IAAIe,kBAAkB;AACjC;;;;;AAMA,SAAOS,cAAAC,QAAAlB,OAAA;CAAA,MAAAa,IAAAC,EAAA,CAAA;CACH,MAAAV,SAAeY,eAAe;CAC9B,MAAAG,SAAexB,OAAOK,KAAK;CAAE,IAAAY;CAAA,IAAAC,EAAA,OAAAb,OAAA;EACnBY,WAAA;GACNO,OAAMC,UAAWpB;EAAH;EACjBa,EAAA,KAAAb;EAAAa,EAAA,KAAAD;CAAA,OAAAA,KAAAC,EAAA;CAFDnB,UAAUkB,EAET;CAAC,IAAAG;CAAA,IAAAM;CAAA,IAAAR,EAAA,OAAAK,UAAAL,EAAA,OAAAT,QAAA;EACQW,WAAA;GACN,IAAI,CAACG,UAAUd,WAAW,MAAI;GAE7B,OACMA,OAAML,UAAWoB,OAAMC,QAAS,CAAC;EAAC;EAC1CC,KAAA,CAACH,QAAQd,MAAM;EAACS,EAAA,KAAAK;EAAAL,EAAA,KAAAT;EAAAS,EAAA,KAAAE;EAAAF,EAAA,KAAAQ;CAAA,OAAA;EAAAN,KAAAF,EAAA;EAAAQ,KAAAR,EAAA;CAAA;CALnBnB,UAAUqB,IAKPM,EAAgB;AAAC"}
@@ -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;
@@ -9,7 +9,9 @@ var PanneauContext = createContext(null);
9
9
  * Provides plugins, the definition and the router to the hooks of `@panneau/core`. Providers can
10
10
  * be nested: a nested provider adds its plugins to those of its parent.
11
11
  */
12
- function PanneauProvider({ plugins = [], definition, router, children }) {
12
+ function PanneauProvider(t0) {
13
+ const { plugins: t1, definition, router, children } = t0;
14
+ const plugins = t1 === void 0 ? [] : t1;
13
15
  const parent = use(PanneauContext);
14
16
  const pluginList = [...parent?.pluginList ?? [], ...plugins];
15
17
  const value = {
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","names":["_c"],"sources":["../../src/react/provider.tsx"],"sourcesContent":["import { type ReactNode, createContext, use } from 'react';\n\nimport type { Definition } from '@panneau/protocol';\n\nimport { type ResolveFormOptions } from '../definition/form';\nimport { type ResolvedResource, findResource, resolveResource } from '../definition/resource';\nimport type { Router } from '../list/router';\nimport { type PanneauPlugin, type PluginRegistry, createPluginRegistry } from '../plugins';\n\n/** What `PanneauProvider` gives to the hooks below it. */\nexport interface PanneauContextValue {\n plugins: PluginRegistry;\n /** The plugins as passed, including those of parent providers. */\n pluginList: readonly PanneauPlugin[];\n definition: Definition | null;\n router: Router | null;\n}\n\nconst PanneauContext = createContext<PanneauContextValue | null>(null);\n\nexport interface PanneauProviderProps {\n /** Plugins, added after those of a parent provider (so they override them). */\n plugins?: readonly PanneauPlugin[];\n /** The definition, for `useResource()`. Defaults to the parent provider's. */\n definition?: Definition | null;\n /** The router that lists keep their query in. Defaults to the parent provider's. */\n router?: Router | null;\n children?: ReactNode;\n}\n\n/**\n * Provides plugins, the definition and the router to the hooks of `@panneau/core`. Providers can\n * be nested: a nested provider adds its plugins to those of its parent.\n */\nexport function PanneauProvider({\n plugins = [],\n definition,\n router,\n children,\n}: PanneauProviderProps) {\n const parent = use(PanneauContext);\n const pluginList = [...(parent?.pluginList ?? []), ...plugins];\n const value: PanneauContextValue = {\n plugins: createPluginRegistry(pluginList),\n pluginList,\n definition: definition === undefined ? (parent?.definition ?? null) : definition,\n router: router === undefined ? (parent?.router ?? null) : router,\n };\n return <PanneauContext value={value}>{children}</PanneauContext>;\n}\n\nconst EMPTY: PanneauContextValue = {\n plugins: createPluginRegistry([]),\n pluginList: [],\n definition: null,\n router: null,\n};\n\n/** The context of the closest `PanneauProvider`, or an empty one without a provider. */\nexport function usePanneau(): PanneauContextValue {\n return use(PanneauContext) ?? EMPTY;\n}\n\n/** The plugins of the closest `PanneauProvider`, merged. */\nexport function usePlugins(): PluginRegistry {\n return usePanneau().plugins;\n}\n\n/**\n * A resource of the definition, with its form, list and abilities resolved. Throws when there is\n * no definition or no such resource.\n */\nexport function useResource(id: string, formOptions?: ResolveFormOptions): ResolvedResource {\n const { definition } = usePanneau();\n if (definition === null) {\n throw new Error('useResource() needs a definition: pass one to <PanneauProvider>.');\n }\n const resource = findResource(definition, id);\n if (resource === undefined) {\n throw new Error(`The definition has no resource \\`${id}\\`.`);\n }\n return resolveResource(resource, formOptions);\n}\n"],"mappings":";;;;;;AAkBA,IAAM,iBAAiB,cAA0C,IAAI;;;;;AAgBrE,SAAgB,gBAAgB,EAC5B,UAAU,CAAA,GACV,YACA,QACA,YACqB;CACrB,MAAM,SAAS,IAAI,cAAc;CACjC,MAAM,aAAa,CAAC,GAAI,QAAQ,cAAc,CAAA,GAAK,GAAG,OAAO;CAC7D,MAAM,QAA6B;EAC/B,SAAS,qBAAqB,UAAU;EACxC;EACA,YAAY,eAAe,KAAA,IAAa,QAAQ,cAAc,OAAQ;EACtE,QAAQ,WAAW,KAAA,IAAa,QAAQ,UAAU,OAAQ;CAC9D;CACA,OAAO,oBAAC,gBAAD;EAAuB;EAAQ;CAAyB,CAAA;AACnE;AAEA,IAAM,QAA6B;CAC/B,SAAS,qBAAqB,CAAA,CAAE;CAChC,YAAY,CAAA;CACZ,YAAY;CACZ,QAAQ;AACZ;;AAGA,SAAgB,aAAkC;CAC9C,OAAO,IAAI,cAAc,KAAK;AAClC;;AAGA,SAAO,aAAA;CAAA,OACI,WAAW,CAAC,CAAA;AAAQ;;;;;AAO/B,SAAO,YAAA,IAAA,aAAA;CAAA,MAAA,IAAAA,EAAA,CAAA;CACH,MAAA,EAAA,eAAuB,WAAW;CAClC,IAAI,eAAe,MACf,MAAM,IAAI,MAAM,kEAAkE;CACrF,IAAA;CAAA,IAAA,EAAA,OAAA,cAAA,EAAA,OAAA,eAAA,EAAA,OAAA,IAAA;EACD,MAAA,WAAiB,aAAa,YAAY,EAAE;EAC5C,IAAI,aAAa,KAAA,GACb,MAAM,IAAI,MAAM,oCAAoC,GAAE,IAAK;EAExD,KAAA,gBAAgB,UAAU,WAAW;EAAC,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;EAAA,EAAA,KAAA;CAAA,OAAA,KAAA,EAAA;CAAA,OAAtC;AAAsC"}
1
+ {"version":3,"file":"provider.js","names":["ReactNode","createContext","use","Definition","ResolveFormOptions","ResolvedResource","findResource","resolveResource","Router","PanneauPlugin","PluginRegistry","createPluginRegistry","PanneauContextValue","plugins","pluginList","definition","router","PanneauContext","PanneauProviderProps","children","PanneauProvider","t0","t1","undefined","parent","value","EMPTY","usePanneau","usePlugins","useResource","id","formOptions","$","_c","Error","resource","_c"],"sources":["../../src/react/provider.tsx"],"sourcesContent":["import { type ReactNode, createContext, use } from 'react';\n\nimport type { Definition } from '@panneau/protocol';\n\nimport { type ResolveFormOptions } from '../definition/form';\nimport { type ResolvedResource, findResource, resolveResource } from '../definition/resource';\nimport type { Router } from '../list/router';\nimport { type PanneauPlugin, type PluginRegistry, createPluginRegistry } from '../plugins';\n\n/** What `PanneauProvider` gives to the hooks below it. */\nexport interface PanneauContextValue {\n plugins: PluginRegistry;\n /** The plugins as passed, including those of parent providers. */\n pluginList: readonly PanneauPlugin[];\n definition: Definition | null;\n router: Router | null;\n}\n\nconst PanneauContext = createContext<PanneauContextValue | null>(null);\n\nexport interface PanneauProviderProps {\n /** Plugins, added after those of a parent provider (so they override them). */\n plugins?: readonly PanneauPlugin[];\n /** The definition, for `useResource()`. Defaults to the parent provider's. */\n definition?: Definition | null;\n /** The router that lists keep their query in. Defaults to the parent provider's. */\n router?: Router | null;\n children?: ReactNode;\n}\n\n/**\n * Provides plugins, the definition and the router to the hooks of `@panneau/core`. Providers can\n * be nested: a nested provider adds its plugins to those of its parent.\n */\nexport function PanneauProvider({\n plugins = [],\n definition,\n router,\n children,\n}: PanneauProviderProps) {\n const parent = use(PanneauContext);\n const pluginList = [...(parent?.pluginList ?? []), ...plugins];\n const value: PanneauContextValue = {\n plugins: createPluginRegistry(pluginList),\n pluginList,\n definition: definition === undefined ? (parent?.definition ?? null) : definition,\n router: router === undefined ? (parent?.router ?? null) : router,\n };\n return <PanneauContext value={value}>{children}</PanneauContext>;\n}\n\nconst EMPTY: PanneauContextValue = {\n plugins: createPluginRegistry([]),\n pluginList: [],\n definition: null,\n router: null,\n};\n\n/** The context of the closest `PanneauProvider`, or an empty one without a provider. */\nexport function usePanneau(): PanneauContextValue {\n return use(PanneauContext) ?? EMPTY;\n}\n\n/** The plugins of the closest `PanneauProvider`, merged. */\nexport function usePlugins(): PluginRegistry {\n return usePanneau().plugins;\n}\n\n/**\n * A resource of the definition, with its form, list and abilities resolved. Throws when there is\n * no definition or no such resource.\n */\nexport function useResource(id: string, formOptions?: ResolveFormOptions): ResolvedResource {\n const { definition } = usePanneau();\n if (definition === null) {\n throw new Error('useResource() needs a definition: pass one to <PanneauProvider>.');\n }\n const resource = findResource(definition, id);\n if (resource === undefined) {\n throw new Error(`The definition has no resource \\`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