viewkitjs 0.31.0 → 0.33.0
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/CHANGELOG.md +198 -0
- package/MIGRATION.md +40 -6
- package/README.md +1 -1
- package/fields/dist/index.d.ts +1 -1
- package/fields/dist/index.js +1 -1
- package/fields/dist/query/evaluate.d.ts +7 -0
- package/fields/dist/query/exact-number.d.ts +8 -2
- package/fields/dist/query/exact-number.js +14 -1
- package/fields/dist/query/index.d.ts +2 -0
- package/fields/dist/query/index.js +2 -0
- package/fields/dist/query/list-request.d.ts +148 -0
- package/fields/dist/query/list-request.js +125 -0
- package/fields/dist/query/saved-view.d.ts +15 -0
- package/fields/dist/query/saved-view.js +11 -0
- package/fields/dist/query/settings.d.ts +9 -0
- package/fields/dist/query/settings.js +9 -0
- package/fields/dist/query/sort.js +13 -10
- package/fields/dist/registry.js +5 -1
- package/fields/dist/types.d.ts +4 -1
- package/fields/dist/zod.d.ts +5 -0
- package/fields/dist/zod.js +10 -1
- package/fields/docs/guides/contact-values.md +12 -0
- package/fields/docs/guides/field-types.md +1 -1
- package/fields/docs/guides/queries.md +3 -1
- package/fields/docs/reference/fields.md +1 -0
- package/fields/docs/reference/query.md +66 -0
- package/package.json +5 -1
- package/postgres/README.md +1 -0
- package/postgres/dist/check.js +4 -1
- package/postgres/dist/definitions/formula-forms.js +3 -1
- package/postgres/dist/definitions/money.js +2 -1
- package/postgres/dist/handler.d.ts +53 -0
- package/postgres/dist/handler.js +211 -0
- package/postgres/dist/ids.d.ts +1 -1
- package/postgres/dist/ids.js +19 -1
- package/postgres/dist/index.d.ts +1 -0
- package/postgres/dist/index.js +1 -0
- package/postgres/dist/limits.d.ts +3 -1
- package/postgres/dist/limits.js +1 -1
- package/postgres/dist/list-fields.d.ts +10 -0
- package/postgres/dist/list-fields.js +36 -0
- package/postgres/dist/page.js +6 -3
- package/postgres/dist/readable.d.ts +4 -0
- package/postgres/dist/readable.js +4 -0
- package/postgres/dist/refusals.d.ts +9 -2
- package/postgres/dist/refusals.js +6 -0
- package/postgres/dist/rules.d.ts +15 -1
- package/postgres/dist/rules.js +16 -0
- package/postgres/dist/sort.js +7 -2
- package/postgres/docs/guides/definitions.md +1 -1
- package/postgres/docs/guides/field-map.md +3 -3
- package/postgres/docs/guides/list-handler.md +99 -0
- package/postgres/docs/index.md +1 -0
- package/postgres/docs/reference/definitions.md +1 -1
- package/postgres/docs/reference/postgres.md +12 -4
- package/views/README.md +2 -2
- package/views/dist/atoms/RowMenu.d.ts +7 -0
- package/views/dist/atoms/RowMenu.js +18 -16
- package/views/dist/atoms/ToolbarButton.d.ts +1 -1
- package/views/dist/atoms/ToolbarButton.js +4 -3
- package/views/dist/atoms/carried.d.ts +5 -0
- package/views/dist/atoms/carried.js +7 -0
- package/views/dist/atoms/frame-parts.d.ts +6 -0
- package/views/dist/atoms/frame-parts.js +15 -0
- package/views/dist/atoms/types.d.ts +19 -7
- package/views/dist/cells/cell-title.d.ts +3 -1
- package/views/dist/cells/cell-title.js +2 -2
- package/views/dist/cells/cell-values.js +2 -2
- package/views/dist/contract.d.ts +56 -11
- package/views/dist/contract.js +148 -0
- package/views/dist/controls/alert-dialog/alert-dialog.js +2 -1
- package/views/dist/controls/atoms.d.ts +2 -0
- package/views/dist/controls/atoms.js +2 -0
- package/views/dist/controls/avatar/avatar.d.ts +3 -3
- package/views/dist/controls/avatar/avatar.js +1 -1
- package/views/dist/controls/avatar/tokens.d.ts +44 -0
- package/views/dist/controls/avatar/tokens.js +11 -0
- package/views/dist/controls/avatar.css +22 -5
- package/views/dist/controls/button/map-button.js +2 -0
- package/views/dist/controls/checkbox/checkbox.d.ts +3 -2
- package/views/dist/controls/checkbox/checkbox.js +2 -2
- package/views/dist/controls/choice/tokens.d.ts +0 -4
- package/views/dist/controls/choice/tokens.js +0 -1
- package/views/dist/controls/choice.css +3 -3
- package/views/dist/controls/compound-editor/compound-editor.d.ts +1 -1
- package/views/dist/controls/compound-editor/name-parts.js +4 -4
- package/views/dist/controls/compound-editor/place-parts.js +19 -19
- package/views/dist/controls/compound-editor/range-parts.js +14 -14
- package/views/dist/controls/compound-editor/row.d.ts +3 -1
- package/views/dist/controls/compound-editor/row.js +2 -2
- package/views/dist/controls/controls.d.ts +8 -0
- package/views/dist/controls/controls.js +12 -2
- package/views/dist/controls/customize/customize.js +37 -35
- package/views/dist/controls/customize/map-customize-body.d.ts +2 -0
- package/views/dist/controls/customize/map-customize-body.js +5 -1
- package/views/dist/controls/date-editor/date-days.js +2 -2
- package/views/dist/controls/date-editor/date-editor.js +18 -18
- package/views/dist/controls/date-editor/date-parts.js +6 -6
- package/views/dist/controls/date-editor/map-calendar.js +1 -1
- package/views/dist/controls/date-editor.css +2 -2
- package/views/dist/controls/field/field.d.ts +22 -4
- package/views/dist/controls/field/field.js +63 -5
- package/views/dist/controls/field/tokens.d.ts +4 -0
- package/views/dist/controls/field/tokens.js +1 -0
- package/views/dist/controls/field.css +41 -16
- package/views/dist/controls/filter-editor/block.d.ts +2 -2
- package/views/dist/controls/filter-editor/block.js +5 -5
- package/views/dist/controls/filter-editor/filter-editor.js +31 -33
- package/views/dist/controls/filter-editor/how.d.ts +3 -1
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +1 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +7 -3
- package/views/dist/controls/filter-editor/map-rules.js +1 -1
- package/views/dist/controls/filter-editor/parts.js +2 -1
- package/views/dist/controls/glyphs/glyphs.d.ts +10 -0
- package/views/dist/controls/glyphs/glyphs.js +173 -0
- package/views/dist/controls/group-editor/group-editor.js +15 -13
- package/views/dist/controls/index.d.ts +4 -1
- package/views/dist/controls/index.js +3 -1
- package/views/dist/controls/input/input.js +6 -3
- package/views/dist/controls/input/map-input.js +2 -0
- package/views/dist/controls/input/tokens.d.ts +4 -0
- package/views/dist/controls/input/tokens.js +1 -0
- package/views/dist/controls/input.css +31 -3
- package/views/dist/controls/internal/editor-parts.js +1 -1
- package/views/dist/controls/internal/icons.js +10 -0
- package/views/dist/controls/internal/keep-focus.d.ts +2 -0
- package/views/dist/controls/internal/keep-focus.js +17 -0
- package/views/dist/controls/internal/map-panel-controls.d.ts +8 -0
- package/views/dist/controls/internal/map-panel-controls.js +20 -0
- package/views/dist/controls/internal/panel-controls.d.ts +50 -0
- package/views/dist/controls/internal/panel-controls.js +197 -0
- package/views/dist/controls/internal/part-slot.d.ts +12 -0
- package/views/dist/controls/internal/part-slot.js +5 -0
- package/views/dist/controls/internal/watch-frame.d.ts +2 -0
- package/views/dist/controls/internal/watch-frame.js +33 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +1 -1
- package/views/dist/controls/links-editor/links-editor.js +27 -27
- package/views/dist/controls/markdown/map-markdown.d.ts +4 -0
- package/views/dist/controls/markdown/map-markdown.js +5 -0
- package/views/dist/controls/menu/map-menu.d.ts +2 -2
- package/views/dist/controls/menu/map-menu.js +15 -12
- package/views/dist/controls/menu/menu.d.ts +2 -0
- package/views/dist/controls/menu/menu.js +3 -3
- package/views/dist/controls/menu-list/menu-list.d.ts +17 -4
- package/views/dist/controls/menu-list/menu-list.js +27 -25
- package/views/dist/controls/modal/modal.js +5 -1
- package/views/dist/controls/notice/notice.d.ts +3 -1
- package/views/dist/controls/notice/notice.js +2 -2
- package/views/dist/controls/number-editor/number-editor.d.ts +1 -1
- package/views/dist/controls/number-editor/number-editor.js +13 -13
- package/views/dist/controls/number-field/number-field.js +5 -3
- package/views/dist/controls/pane/pane.d.ts +4 -2
- package/views/dist/controls/pane/pane.js +6 -5
- package/views/dist/controls/phone-header/header-bar.d.ts +5 -1
- package/views/dist/controls/phone-header/header-bar.js +2 -2
- package/views/dist/controls/phone-header.css +11 -1
- package/views/dist/controls/picker/map-picker.js +3 -0
- package/views/dist/controls/picker/picker.d.ts +16 -0
- package/views/dist/controls/picker/picker.js +61 -40
- package/views/dist/controls/picker/rows.d.ts +4 -0
- package/views/dist/controls/picker.css +2 -0
- package/views/dist/controls/popover/map-popover.d.ts +1 -1
- package/views/dist/controls/popover/map-popover.js +4 -2
- package/views/dist/controls/popover/popover.js +2 -1
- package/views/dist/controls/quick-filters/quick-filters.js +4 -4
- package/views/dist/controls/radio/radio.d.ts +8 -3
- package/views/dist/controls/radio/radio.js +22 -5
- package/views/dist/controls/radio/tokens.d.ts +44 -0
- package/views/dist/controls/radio/tokens.js +11 -0
- package/views/dist/controls/radio.css +79 -1
- package/views/dist/controls/select/map-select.d.ts +3 -0
- package/views/dist/controls/select/map-select.js +8 -0
- package/views/dist/controls/select/select.d.ts +7 -0
- package/views/dist/controls/select/select.js +12 -6
- package/views/dist/controls/select/tokens.d.ts +8 -0
- package/views/dist/controls/select/tokens.js +2 -0
- package/views/dist/controls/select.css +17 -0
- package/views/dist/controls/setting-row/looks.d.ts +1 -1
- package/views/dist/controls/setting-row/looks.js +9 -4
- package/views/dist/controls/setting-row/setting-row.d.ts +45 -10
- package/views/dist/controls/setting-row/setting-row.js +82 -15
- package/views/dist/controls/setting-row/tokens.d.ts +74 -2
- package/views/dist/controls/setting-row/tokens.js +19 -1
- package/views/dist/controls/setting-row.css +135 -14
- package/views/dist/controls/sheet/bottom-sheet.d.ts +14 -2
- package/views/dist/controls/sheet/bottom-sheet.js +6 -3
- package/views/dist/controls/sheet/map-sheet.js +1 -1
- package/views/dist/controls/sheet.css +4 -1
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +1 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +7 -3
- package/views/dist/controls/sort-editor/sort-editor.js +25 -26
- package/views/dist/controls/sort-editor.css +13 -2
- package/views/dist/controls/switch-row/tokens.d.ts +0 -12
- package/views/dist/controls/switch-row/tokens.js +0 -3
- package/views/dist/controls/switch-row.css +3 -7
- package/views/dist/controls/switch.css +17 -7
- package/views/dist/controls/tag/tag.d.ts +3 -1
- package/views/dist/controls/tag/tag.js +2 -2
- package/views/dist/controls/tag/tokens.d.ts +4 -0
- package/views/dist/controls/tag/tokens.js +1 -0
- package/views/dist/controls/tag-field/tag-field.d.ts +5 -1
- package/views/dist/controls/tag-field/tag-field.js +11 -5
- package/views/dist/controls/tag-field/tokens.d.ts +16 -0
- package/views/dist/controls/tag-field/tokens.js +4 -0
- package/views/dist/controls/tag-field.css +19 -0
- package/views/dist/controls/tag.css +2 -0
- package/views/dist/controls/text-editor/text-editor.d.ts +1 -1
- package/views/dist/controls/text-editor/text-editor.js +8 -8
- package/views/dist/controls/toolbar/toolbar.d.ts +15 -3
- package/views/dist/controls/toolbar/toolbar.js +22 -15
- package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +14 -0
- package/views/dist/controls/toolbar-button/atom-toolbar-button.js +52 -0
- package/views/dist/controls/toolbar-button/toolbar-button.d.ts +1 -1
- package/views/dist/controls/toolbar-button/toolbar-button.js +2 -3
- package/views/dist/controls/toolbar-button.css +4 -0
- package/views/dist/controls/toolbar.css +5 -0
- package/views/dist/controls/values-editor/values-editor.d.ts +1 -1
- package/views/dist/controls/values-editor/values-editor.js +22 -22
- package/views/dist/controls/views-list/map-view-menu.d.ts +3 -0
- package/views/dist/controls/views-list/map-view-menu.js +25 -0
- package/views/dist/controls/views-list/map-views-list-body.d.ts +28 -1
- package/views/dist/controls/views-list/map-views-list-body.js +39 -21
- package/views/dist/controls/views-list/rules.d.ts +2 -0
- package/views/dist/controls/views-list/view-menu.d.ts +7 -0
- package/views/dist/controls/views-list/view-menu.js +33 -29
- package/views/dist/controls/views-list/views-list.js +4 -4
- package/views/dist/controls/views-list/words.d.ts +2 -0
- package/views/dist/controls/views-list/words.js +1 -1
- package/views/dist/editors/EditorPanel.js +3 -2
- package/views/dist/editors/edit-session.js +2 -5
- package/views/dist/field-row/FieldRow.d.ts +4 -2
- package/views/dist/field-row/FieldRow.js +80 -20
- package/views/dist/field-row/FieldRowLane.d.ts +7 -2
- package/views/dist/field-row/FieldRowLane.js +4 -3
- package/views/dist/field-row/editors/RowEditor.d.ts +12 -0
- package/views/dist/field-row/editors/RowEditor.js +31 -1
- package/views/dist/field-row/editors/RowValueListEditor.d.ts +5 -1
- package/views/dist/field-row/editors/RowValueListEditor.js +4 -1
- package/views/dist/field-row/field-row-button.d.ts +5 -0
- package/views/dist/field-row/field-row-button.js +2 -0
- package/views/dist/fields/binding.d.ts +3 -2
- package/views/dist/fields/binding.js +38 -5
- package/views/dist/fields/money.d.ts +5 -2
- package/views/dist/fields/money.js +14 -2
- package/views/dist/grid/chrome/GridColumnMenu.d.ts +4 -2
- package/views/dist/grid/chrome/GridColumnMenu.js +3 -2
- package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -1
- package/views/dist/grid/chrome/GridGroupMenu.js +4 -3
- package/views/dist/grid/chrome/GridHeader.d.ts +4 -1
- package/views/dist/grid/chrome/GridHeader.js +2 -2
- package/views/dist/grid/chrome/GridRow.js +6 -5
- package/views/dist/grid/chrome/GridRowCells.js +6 -9
- package/views/dist/grid/chrome/GridStructure.d.ts +4 -1
- package/views/dist/grid/chrome/GridStructure.js +4 -4
- package/views/dist/grid/chrome/GridTable.js +9 -3
- package/views/dist/grid/chrome/cell-clipboard.d.ts +4 -2
- package/views/dist/grid/chrome/cell-clipboard.js +2 -2
- package/views/dist/grid/chrome/cells.js +3 -1
- package/views/dist/grid/chrome/grid-column-menu-items.js +1 -1
- package/views/dist/grid/chrome/grid-row-menu-items.d.ts +27 -3
- package/views/dist/grid/chrome/grid-row-menu-items.js +93 -7
- package/views/dist/grid/chrome/grid-row-props.d.ts +7 -2
- package/views/dist/grid/chrome/grid-rows-menu.js +34 -6
- package/views/dist/grid/chrome/grid-table-props.d.ts +38 -7
- package/views/dist/grid/chrome/useGridBatchApi.d.ts +3 -1
- package/views/dist/grid/chrome/useGridBatchApi.js +4 -2
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +7 -2
- package/views/dist/grid/chrome/useGridKeyboard.js +43 -14
- package/views/dist/grid/chrome/useGridPendingReconciliation.js +1 -2
- package/views/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -1
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +20 -7
- package/views/dist/grid/core/clipboard-model.d.ts +3 -1
- package/views/dist/grid/core/clipboard-model.js +9 -8
- package/views/dist/grid/core/commit-model.d.ts +20 -2
- package/views/dist/grid/core/editing-controller.d.ts +21 -0
- package/views/dist/grid/core/editing-controller.js +194 -42
- package/views/dist/grid/core/editing-model.d.ts +3 -0
- package/views/dist/grid/core/editing-model.js +3 -0
- package/views/dist/grid/core/edits-sink.d.ts +19 -0
- package/views/dist/grid/core/edits-sink.js +2 -0
- package/views/dist/grid/core/save-path.d.ts +24 -0
- package/views/dist/grid/core/save-path.js +122 -0
- package/views/dist/grid/core/spreadsheet-operations.d.ts +3 -0
- package/views/dist/grid/core/spreadsheet-operations.js +24 -1
- package/views/dist/grid/core/useGridEditing.d.ts +5 -0
- package/views/dist/grid/core/useGridEditing.js +6 -0
- package/views/dist/grid/index.d.ts +3 -2
- package/views/dist/grid/index.js +1 -0
- package/views/dist/internal/field-rows.d.ts +26 -0
- package/views/dist/internal/field-rows.js +8 -0
- package/views/dist/internal/page-close.d.ts +7 -0
- package/views/dist/internal/page-close.js +43 -0
- package/views/dist/list/answer.d.ts +40 -0
- package/views/dist/list/answer.js +43 -0
- package/views/dist/list/browser-views-store.d.ts +10 -0
- package/views/dist/list/browser-views-store.js +182 -0
- package/views/dist/list/bulk-bar.d.ts +7 -0
- package/views/dist/list/bulk-bar.js +10 -0
- package/views/dist/list/columns.d.ts +24 -0
- package/views/dist/list/columns.js +27 -0
- package/views/dist/list/edits.d.ts +19 -0
- package/views/dist/list/edits.js +56 -0
- package/views/dist/list/grid.d.ts +11 -0
- package/views/dist/list/grid.js +76 -0
- package/views/dist/list/index.d.ts +36 -0
- package/views/dist/list/index.js +11 -0
- package/views/dist/list/link.d.ts +8 -0
- package/views/dist/list/link.js +78 -0
- package/views/dist/list/list.d.ts +70 -0
- package/views/dist/list/list.js +14 -0
- package/views/dist/list/menu.d.ts +31 -0
- package/views/dist/list/menu.js +76 -0
- package/views/dist/list/parts.d.ts +6 -0
- package/views/dist/list/parts.js +66 -0
- package/views/dist/list/registry.d.ts +11 -0
- package/views/dist/list/registry.js +31 -0
- package/views/dist/list/root-base.d.ts +46 -0
- package/views/dist/list/root-base.js +137 -0
- package/views/dist/list/root.d.ts +41 -0
- package/views/dist/list/root.js +168 -0
- package/views/dist/list/slot.d.ts +14 -0
- package/views/dist/list/slot.js +22 -0
- package/views/dist/list/source-answers.d.ts +39 -0
- package/views/dist/list/source-answers.js +225 -0
- package/views/dist/list/source.d.ts +11 -0
- package/views/dist/list/source.js +31 -0
- package/views/dist/list/store.d.ts +119 -0
- package/views/dist/list/store.js +146 -0
- package/views/dist/list/toolbar.d.ts +7 -0
- package/views/dist/list/toolbar.js +371 -0
- package/views/dist/list/views-axis.d.ts +5 -0
- package/views/dist/list/views-axis.js +98 -0
- package/views/dist/list/views-store.d.ts +41 -0
- package/views/dist/list/views-store.js +1 -0
- package/views/dist/list/views.d.ts +72 -0
- package/views/dist/list/views.js +411 -0
- package/views/dist/model/column-capabilities.d.ts +13 -0
- package/views/dist/model/column-capabilities.js +23 -2
- package/views/dist/model/column-schema.d.ts +11 -1
- package/views/dist/model/preferences.js +1 -1
- package/views/dist/model/prefs-buckets.js +1 -1
- package/views/dist/model/view-rules.js +1 -0
- package/views/dist/panels/index.d.ts +3 -1
- package/views/dist/panels/index.js +1 -0
- package/views/dist/panels/model.d.ts +2 -0
- package/views/dist/panels/react/customize-body.js +1 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +47 -4
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +6 -326
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +17 -2
- package/views/dist/panels/react/toolbar/Toolbar.js +43 -23
- package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarAsideFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -4
- package/views/dist/panels/react/toolbar/ToolbarButton.js +7 -1
- package/views/dist/panels/react/toolbar/ToolbarFilter.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarNew.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +2 -2
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +3 -1
- package/views/dist/panels/react/toolbar/ToolbarSearch.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSort.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
- package/views/dist/panels/react/toolbar/context.d.ts +20 -3
- package/views/dist/panels/react/toolbar/context.js +3 -1
- package/views/dist/panels/react/toolbar/panel-part.d.ts +4 -1
- package/views/dist/panels/react/toolbar/panel-part.js +5 -3
- package/views/dist/panels/react/views-row/FoldingViewRow.d.ts +1 -1
- package/views/dist/panels/react/views-row/FoldingViewRow.js +15 -4
- package/views/dist/panels/react/views-row/PillGroup.d.ts +5 -2
- package/views/dist/panels/react/views-row/PillGroup.js +16 -7
- package/views/dist/panels/react/views-row/ViewPicker.js +2 -12
- package/views/dist/panels/react/views-row/ViewPickerRow.d.ts +4 -2
- package/views/dist/panels/react/views-row/ViewPickerRow.js +9 -5
- package/views/dist/panels/react.d.ts +2 -2
- package/views/dist/panels/settings/filter-groups.js +6 -1
- package/views/dist/panels/toolbar/edit-view.d.ts +7 -1
- package/views/dist/panels/toolbar/edit-view.js +14 -0
- package/views/dist/panels/toolbar/model.d.ts +5 -0
- package/views/dist/panels/toolbar/model.js +7 -3
- package/views/dist/panels/view-state.d.ts +5 -3
- package/views/dist/panels/views-row/model.d.ts +19 -2
- package/views/dist/panels/views-row/model.js +14 -0
- package/views/dist/provider/ViewsProvider.d.ts +21 -8
- package/views/dist/provider/ViewsProvider.js +40 -5
- package/views/dist/provider/components.d.ts +102 -2
- package/views/dist/provider/components.js +1 -1
- package/views/dist/provider/context.d.ts +6 -2
- package/views/dist/provider/context.js +1 -1
- package/views/dist/provider/own-control.d.ts +4 -0
- package/views/dist/provider/own-control.js +7 -0
- package/views/dist/provider/ports.d.ts +19 -12
- package/views/dist/provider/ports.js +69 -1
- package/views/dist/provider/select-items.d.ts +3 -0
- package/views/dist/provider/select-items.js +6 -0
- package/views/dist/react.d.ts +4 -2
- package/views/dist/react.js +2 -0
- package/views/dist/styles.css +503 -136
- package/views/dist/styles.unlayered.css +503 -136
- package/views/docs/contract.md +292 -34
- package/views/docs/controls/avatar.md +11 -0
- package/views/docs/controls/choice.md +0 -1
- package/views/docs/controls/compound-editor.md +4 -0
- package/views/docs/controls/customize.md +6 -0
- package/views/docs/controls/date-editor.md +4 -0
- package/views/docs/controls/field.md +7 -0
- package/views/docs/controls/filter-editor.md +8 -0
- package/views/docs/controls/group-editor.md +6 -0
- package/views/docs/controls/input.md +5 -0
- package/views/docs/controls/links-editor.md +4 -0
- package/views/docs/controls/menu-list.md +8 -0
- package/views/docs/controls/menu.md +4 -0
- package/views/docs/controls/notice.md +4 -0
- package/views/docs/controls/number-editor.md +4 -0
- package/views/docs/controls/pane.md +4 -0
- package/views/docs/controls/picker.md +8 -0
- package/views/docs/controls/quick-filters.md +6 -0
- package/views/docs/controls/radio.md +20 -1
- package/views/docs/controls/select.md +10 -0
- package/views/docs/controls/setting-row.md +18 -0
- package/views/docs/controls/sheet.md +4 -0
- package/views/docs/controls/sort-editor.md +8 -0
- package/views/docs/controls/switch-row.md +0 -3
- package/views/docs/controls/tag-field.md +4 -0
- package/views/docs/controls/tag.md +1 -0
- package/views/docs/controls/text-editor.md +4 -0
- package/views/docs/controls/values-editor.md +4 -0
- package/views/docs/controls/views-list.md +6 -0
- package/views/docs/getting-started.md +2 -2
- package/views/docs/guides/atoms.md +2 -2
- package/views/docs/guides/columns.md +1 -1
- package/views/docs/guides/ports.md +1 -1
- package/views/docs/guides/the-grid.md +36 -9
- package/views/docs/guides/the-provider.md +22 -3
- package/views/docs/index.md +1 -0
- package/views/docs/reference/controls.md +41 -29
- package/views/docs/reference/editors-session.md +1 -1
- package/views/docs/reference/field-row.md +9 -1
- package/views/docs/reference/grid.md +15 -9
- package/views/docs/reference/list.md +357 -0
- package/views/docs/reference/looks.md +1 -1
- package/views/docs/reference/panels-react.md +17 -12
- package/views/docs/reference/panels.md +8 -5
- package/views/docs/reference/react.md +24 -16
- package/views/docs/reference/views.md +10 -6
- package/views/docs/reshaping.md +6 -1
- package/views/skills/views/SKILL.md +9 -6
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type ListRow } from "viewkitjs/fields/query";
|
|
3
|
+
import type { ListSave } from "../grid/core/commit-model.js";
|
|
4
|
+
import type { QuickFiltersConfig } from "../panels/quick/model.js";
|
|
5
|
+
import type { ListSource } from "./source.js";
|
|
6
|
+
import { type ListColumnsOverride, type ListFieldsRegistry } from "./columns.js";
|
|
7
|
+
import { type ListRootModes } from "./root-base.js";
|
|
8
|
+
export { useList, useListPanel, useListStore } from "./root-base.js";
|
|
9
|
+
export type { ListViewsOptions } from "./root-base.js";
|
|
10
|
+
/** What the root holds of a list's data, in either mode. */
|
|
11
|
+
export type ListData<Row extends ListRow = ListRow> = {
|
|
12
|
+
/** The list's fields (`defineFields`): its columns and, in store mode, its default settings. */
|
|
13
|
+
fields?: ListFieldsRegistry;
|
|
14
|
+
/** The rows, held by the app; the root filters, sorts and groups them. Needs `fields`. */
|
|
15
|
+
rows?: readonly Row[];
|
|
16
|
+
/** Where the rows come from instead: one list request in, its answer out (`fetchSource`, or a server action). Whether
|
|
17
|
+
* there is one is read as the list mounts; each request goes to the one handed last. One whose narrowing changes
|
|
18
|
+
* (another company's deals) wants a `key` on the list, so it starts again. Needs `fields`. */
|
|
19
|
+
source?: ListSource<Row>;
|
|
20
|
+
/** A source's page: how many rows each request asks for. Default 50, held between 1 and 1000. */
|
|
21
|
+
pageSize?: number;
|
|
22
|
+
/** The quick filters the toolbar draws: their hold narrows the rows (in memory and from a source). */
|
|
23
|
+
quickFilters?: QuickFiltersConfig;
|
|
24
|
+
/** Columns changed by their field's key. */
|
|
25
|
+
columns?: ListColumnsOverride<Row>;
|
|
26
|
+
/** One save per record (`ListSave`, viewkitjs/views/grid). None: a read-only list. */
|
|
27
|
+
save?: ListSave<Row>;
|
|
28
|
+
/** `edit: false`: every cell read-only, as with no `save`. `share: false`: no "Save for everyone" (store mode). */
|
|
29
|
+
can?: {
|
|
30
|
+
edit?: boolean;
|
|
31
|
+
share?: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** The list root's props: its id, and either its settings and layer as the app holds them (memory mode: what
|
|
35
|
+
* `useListSettingsState` returns, with the shared view), or no settings, and the root keeps them through a store. A
|
|
36
|
+
* root keeps the mode it mounted in. Either way, the toolbar's `sortFilter` and `bar`, and the list's data. */
|
|
37
|
+
export type ListRootProps<Row extends ListRow = ListRow> = {
|
|
38
|
+
id: string;
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
} & ListData<Row> & ListRootModes;
|
|
41
|
+
export declare function ListRoot<Row extends ListRow = ListRow>({ fields, rows, source, pageSize, quickFilters, columns, save, can, children, ...base }: ListRootProps<Row>): ReactNode;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createElement, useContext, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
3
|
+
import { presentedDef } from "viewkitjs/fields";
|
|
4
|
+
import { bucketRuleFor, } from "viewkitjs/fields/query";
|
|
5
|
+
import { ViewsContext } from "../provider/context.js";
|
|
6
|
+
import { deriveGridSelectValues } from "../grid/core/column-values.js";
|
|
7
|
+
import { createListAnswers, requestSettingsOf } from "./source-answers.js";
|
|
8
|
+
import { answerInMemory } from "./answer.js";
|
|
9
|
+
import { columnsOf } from "./columns.js";
|
|
10
|
+
import { ListCommitsContext, ListEditsSinkContext, useListCommits, useListEditsSink } from "./edits.js";
|
|
11
|
+
import { ListRootBase, useList, useListStore } from "./root-base.js";
|
|
12
|
+
export { useList, useListPanel, useListStore } from "./root-base.js";
|
|
13
|
+
export function ListRoot({ fields, rows, source, pageSize, quickFilters, columns, save, can, children, ...base }) {
|
|
14
|
+
const [defaults] = useState(() => base.settings === undefined && base.defaults === undefined && fields ? columnsOf(fields, columns, false).defaults : undefined);
|
|
15
|
+
return createElement(ListRootBase, { ...base, ...(defaults && { defaults }), ...(can?.share === false && { share: false }) }, createElement((RootData), { fields, rows, source, pageSize, quickFilters, columns, save, can }, children));
|
|
16
|
+
}
|
|
17
|
+
function RootData({ fields, rows, source, pageSize, quickFilters, columns: overrides, save, can, children, }) {
|
|
18
|
+
const store = useListStore();
|
|
19
|
+
const settings = useList((s) => s.view.settings);
|
|
20
|
+
const conventions = useContext(ViewsContext)?.conventions;
|
|
21
|
+
const writable = !!save && can?.edit !== false;
|
|
22
|
+
const hold = quickFilters?.hold;
|
|
23
|
+
const sourced = useSourceAnswers(store, source, pageSize, settings, hold, fields, conventions);
|
|
24
|
+
const { bindings, ...data } = useListData(fields, sourced ? undefined : rows, overrides, settings, conventions, writable, hold);
|
|
25
|
+
const parts = useSourceParts(store, sourced?.answers ?? null, quickFilters, fields, settings, sourced?.state.total ?? null);
|
|
26
|
+
const holdKey = JSON.stringify(hold?.length ? hold : null);
|
|
27
|
+
const heldKey = useRef(holdKey);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (heldKey.current === holdKey)
|
|
30
|
+
return;
|
|
31
|
+
heldKey.current = holdKey;
|
|
32
|
+
store.get().select([]);
|
|
33
|
+
}, [store, holdKey]);
|
|
34
|
+
const fromSource = useMemo(() => (sourced && data.columns ? withParts(sourced.state, data.columns, parts) : null), [sourced, data.columns, parts]);
|
|
35
|
+
store.syncData(fromSource ? { ...data, answer: fromSource } : data);
|
|
36
|
+
useLayoutEffect(() => store.flush());
|
|
37
|
+
const commits = useListCommits(save, writable, bindings);
|
|
38
|
+
const sink = useListEditsSink(store);
|
|
39
|
+
return createElement(ListCommitsContext.Provider, { value: commits }, createElement(ListEditsSinkContext.Provider, { value: sink }, children));
|
|
40
|
+
}
|
|
41
|
+
function useListData(fields, rows, overrides, settings, conventions, writable, hold) {
|
|
42
|
+
const of = useMemo(() => (fields ? columnsOf(fields, overrides, writable) : null), [fields, overrides, writable]);
|
|
43
|
+
const answer = useMemo(() => (fields && rows && of ? answerInMemory(rows, settings, fields, of.columns, conventions, of.bindings, hold) : null), [fields, rows, of, settings, conventions, hold]);
|
|
44
|
+
return useMemo(() => ({
|
|
45
|
+
columns: (of?.columns ?? null),
|
|
46
|
+
answer: answer,
|
|
47
|
+
bindings: of?.bindings ?? null,
|
|
48
|
+
}), [of, answer]);
|
|
49
|
+
}
|
|
50
|
+
function useSourceAnswers(store, source, pageSize, settings, hold, fields, conventions) {
|
|
51
|
+
const toast = useContext(ViewsContext)?.ports.toast.error;
|
|
52
|
+
const latest = useRef({ source, toast, fields, conventions });
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
latest.current = { source, toast, fields, conventions };
|
|
55
|
+
});
|
|
56
|
+
const [, changed] = useReducer((n) => n + 1, 0);
|
|
57
|
+
const [answers] = useState(() => (source ? answersOver(latest, pageSize, changed) : null));
|
|
58
|
+
useLayoutEffect(() => {
|
|
59
|
+
answers?.ask(settings, hold);
|
|
60
|
+
}, [answers, settings, hold]);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
if (!answers)
|
|
63
|
+
return;
|
|
64
|
+
store.wire({ loadMore: answers.loadMore, loadGroup: answers.loadGroup });
|
|
65
|
+
return () => store.wire({ loadMore: undefined, loadGroup: undefined });
|
|
66
|
+
}, [answers, store]);
|
|
67
|
+
const state = answers?.state();
|
|
68
|
+
return useMemo(() => (answers && state ? { state, answers } : null), [answers, state]);
|
|
69
|
+
}
|
|
70
|
+
function answersOver(latest, pageSize, changed) {
|
|
71
|
+
return createListAnswers({
|
|
72
|
+
source: (request) => latest.current.source(request),
|
|
73
|
+
...(pageSize !== undefined && { pageSize }),
|
|
74
|
+
onChange: changed,
|
|
75
|
+
onError: (message) => latest.current.toast?.(message),
|
|
76
|
+
nameGroup: (group, key) => groupName(latest.current.fields, latest.current.conventions, group, key),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function groupName(fields, conventions, group, key) {
|
|
80
|
+
const field = fields?.[group.fieldKey];
|
|
81
|
+
if (!field)
|
|
82
|
+
return null;
|
|
83
|
+
return bucketRuleFor(field, group.by)?.labelOf(presentedDef(field), key, group.granularity, conventions) ?? null;
|
|
84
|
+
}
|
|
85
|
+
const FILTER_PANELS = new Set(["filter", "filter-add", "options"]);
|
|
86
|
+
const NO_VALUES = {};
|
|
87
|
+
function useSourceParts(store, answers, quickFilters, fields, settings, total) {
|
|
88
|
+
const views = useList((s) => s.views);
|
|
89
|
+
const open = useList((s) => s.panels.open);
|
|
90
|
+
const show = settings.showCounts !== false;
|
|
91
|
+
const [viewCounts, setViewCounts] = useState(null);
|
|
92
|
+
const [holdCounts, setHoldCounts] = useState(null);
|
|
93
|
+
const [values, setValues] = useState(NO_VALUES);
|
|
94
|
+
const totalRef = useRef(total);
|
|
95
|
+
useLayoutEffect(() => {
|
|
96
|
+
totalRef.current = total;
|
|
97
|
+
});
|
|
98
|
+
useLayoutEffect(() => {
|
|
99
|
+
if (!answers)
|
|
100
|
+
return;
|
|
101
|
+
store.wire({
|
|
102
|
+
selectAll: () => {
|
|
103
|
+
const before = store.get().selection;
|
|
104
|
+
const pending = { ids: [], all: true, count: totalRef.current?.count ?? null };
|
|
105
|
+
store.patch({ selection: pending });
|
|
106
|
+
void answers.ids().then((ids) => {
|
|
107
|
+
if (ids)
|
|
108
|
+
return store.get().select(ids);
|
|
109
|
+
if (store.get().selection === pending)
|
|
110
|
+
store.patch({ selection: before });
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
return () => store.wire({ selectAll: undefined });
|
|
115
|
+
}, [answers, store]);
|
|
116
|
+
const hold = quickFilters?.hold;
|
|
117
|
+
const asked = JSON.stringify([requestSettingsOf(settings), hold?.length ? hold : null]);
|
|
118
|
+
const askedViews = JSON.stringify([{ ...requestSettingsOf(settings), filter: null }, hold?.length ? hold : null]);
|
|
119
|
+
const viewsList = views?.ready ? views.list : null;
|
|
120
|
+
const viewsKey = JSON.stringify(viewsList?.map((v) => [v.id, v.settings.filter]) ?? []);
|
|
121
|
+
useLayoutEffect(() => {
|
|
122
|
+
const counted = JSON.parse(viewsKey);
|
|
123
|
+
if (!answers || counted.length === 0 || !show)
|
|
124
|
+
return;
|
|
125
|
+
let current = true;
|
|
126
|
+
void answers.viewCounts(counted.map(([id, filter]) => ({ id, filter }))).then((counts) => {
|
|
127
|
+
if (current)
|
|
128
|
+
setViewCounts(counts);
|
|
129
|
+
});
|
|
130
|
+
return () => void (current = false);
|
|
131
|
+
}, [answers, viewsKey, show, askedViews]);
|
|
132
|
+
const quickKeys = (quickFilters?.fields ?? []).map((f) => f.key).join("\n");
|
|
133
|
+
const quickOpen = open === "quick";
|
|
134
|
+
useLayoutEffect(() => {
|
|
135
|
+
if (!answers || !quickOpen || quickKeys === "")
|
|
136
|
+
return;
|
|
137
|
+
let current = true;
|
|
138
|
+
void answers.counts("hold", quickKeys.split("\n")).then((counts) => {
|
|
139
|
+
if (current && counts)
|
|
140
|
+
setHoldCounts(Object.fromEntries(Object.entries(counts).map(([key, c]) => [key, c.counts])));
|
|
141
|
+
});
|
|
142
|
+
return () => void (current = false);
|
|
143
|
+
}, [answers, quickOpen, quickKeys, asked]);
|
|
144
|
+
const filterOpen = open !== null && FILTER_PANELS.has(open);
|
|
145
|
+
const textKeys = Object.values(fields ?? {}).filter((field) => field.type === "text").map((field) => field.key).join("\n");
|
|
146
|
+
useLayoutEffect(() => {
|
|
147
|
+
if (!answers || !filterOpen || textKeys === "")
|
|
148
|
+
return;
|
|
149
|
+
let current = true;
|
|
150
|
+
const keys = textKeys.split("\n");
|
|
151
|
+
void Promise.all(keys.map((key) => answers.values(key).then((answer) => [key, answer?.values ?? []]))).then((pairs) => {
|
|
152
|
+
if (current)
|
|
153
|
+
setValues(Object.fromEntries(pairs));
|
|
154
|
+
});
|
|
155
|
+
return () => void (current = false);
|
|
156
|
+
}, [answers, filterOpen, textKeys, asked]);
|
|
157
|
+
return useMemo(() => ({ viewCounts: show ? viewCounts : null, holdCounts, values }), [show, viewCounts, holdCounts, values]);
|
|
158
|
+
}
|
|
159
|
+
function withParts(answer, columns, parts) {
|
|
160
|
+
const rows = answer.groups.flatMap((group) => group.items);
|
|
161
|
+
const inHand = deriveGridSelectValues(columns, rows);
|
|
162
|
+
return {
|
|
163
|
+
...answer,
|
|
164
|
+
viewCounts: parts.viewCounts,
|
|
165
|
+
holdCounts: parts.holdCounts,
|
|
166
|
+
filterValues: { ...answer.filterValues, selectValues: { ...inHand, ...parts.values } },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type ListSlotProps = {
|
|
3
|
+
name: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
};
|
|
6
|
+
export type ListFillProps = {
|
|
7
|
+
name: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
/** Where the fills of this name draw: a `div` (`data-slot="vk-list-slot"`, `data-name`). One slot per name under a
|
|
11
|
+
* provider: a later one takes the fills from an earlier. */
|
|
12
|
+
export declare function ListSlot({ name, className }: ListSlotProps): ReactNode;
|
|
13
|
+
/** What it holds, drawn in the `ListSlot` of its name; nothing while none stands. */
|
|
14
|
+
export declare function ListFill({ name, children }: ListFillProps): ReactNode;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useContext, useSyncExternalStore } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { ListRegistryContext } from "./registry.js";
|
|
6
|
+
function useRegistry(part) {
|
|
7
|
+
const registry = useContext(ListRegistryContext);
|
|
8
|
+
if (!registry)
|
|
9
|
+
throw new Error(`${part} needs a ViewsProvider around it`);
|
|
10
|
+
return registry;
|
|
11
|
+
}
|
|
12
|
+
export function ListSlot({ name, className }) {
|
|
13
|
+
const registry = useRegistry("ListSlot");
|
|
14
|
+
const ref = useCallback((element) => (element ? registry.addSlot(name, element) : undefined), [registry, name]);
|
|
15
|
+
return _jsx("div", { ref: ref, "data-slot": "vk-list-slot", "data-name": name, className: className });
|
|
16
|
+
}
|
|
17
|
+
export function ListFill({ name, children }) {
|
|
18
|
+
const registry = useRegistry("ListFill");
|
|
19
|
+
const read = () => registry.slot(name) ?? null;
|
|
20
|
+
const element = useSyncExternalStore(registry.subscribe, read, () => null);
|
|
21
|
+
return element ? createPortal(children, element) : null;
|
|
22
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type FilterTree, type ListAnswerOf, type ListHold, type ListRequestSettings, type ListRow, type ListSettings } from "viewkitjs/fields/query";
|
|
2
|
+
import type { ListAnswerState } from "./answer.js";
|
|
3
|
+
import type { ListSource } from "./source.js";
|
|
4
|
+
export type ListAnswersController<Row extends ListRow> = {
|
|
5
|
+
/** The settings (and quick filters' hold) the rows answer; a change to their request parts asks again. */
|
|
6
|
+
ask: (settings: ListSettings, hold: ListHold | undefined) => void;
|
|
7
|
+
/** The next page of the ungrouped list; nothing while one is out or there is none. */
|
|
8
|
+
loadMore: () => void;
|
|
9
|
+
/** The next page of one group (its first, where its rows weren't sent); nothing while one is out or there is none. */
|
|
10
|
+
loadGroup: (key: string) => void;
|
|
11
|
+
/** Every matching row's id (the `ids` part); null on a refusal, a throw, or an answer a newer ask has outrun. */
|
|
12
|
+
ids: () => Promise<string[] | null>;
|
|
13
|
+
/** Counts of a quick filter's or the filter's values (the `counts` part). */
|
|
14
|
+
counts: (of: "filter" | "hold", fields: readonly string[]) => Promise<ListAnswerOf<"counts">["counts"] | null>;
|
|
15
|
+
/** One field's values and their labels (the `values` part). */
|
|
16
|
+
values: (field: string) => Promise<{
|
|
17
|
+
values: string[];
|
|
18
|
+
labels: Record<string, string>;
|
|
19
|
+
} | null>;
|
|
20
|
+
/** Each view's count under its own filter (the `view-counts` part). */
|
|
21
|
+
viewCounts: (views: readonly {
|
|
22
|
+
id: string;
|
|
23
|
+
filter: FilterTree;
|
|
24
|
+
}[]) => Promise<Record<string, number> | null>;
|
|
25
|
+
state: () => ListAnswerState<Row>;
|
|
26
|
+
};
|
|
27
|
+
/** The settings' parts a request carries: the filter, the sorts and the group, the search where there is one, and the
|
|
28
|
+
* row order where the settings hold one. */
|
|
29
|
+
export declare function requestSettingsOf(settings: ListSettings): ListRequestSettings;
|
|
30
|
+
export declare function createListAnswers<Row extends ListRow>(o: {
|
|
31
|
+
source: ListSource<Row>;
|
|
32
|
+
pageSize?: number;
|
|
33
|
+
/** Told after each change of `state()`. */
|
|
34
|
+
onChange: () => void;
|
|
35
|
+
/** A source that threw or rejected, or answered another part, in words a person reads. */
|
|
36
|
+
onError: (message: string) => void;
|
|
37
|
+
/** A group's name where the source sent none: the grouped field's label for its key, or null. */
|
|
38
|
+
nameGroup?: (group: NonNullable<ListRequestSettings["group"]>, key: string) => string | null;
|
|
39
|
+
}): ListAnswersController<Row>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { answerFor, isRefused, LIST_REQUEST_LIMITS, LIST_SETTINGS_DEFAULTS, LIST_REQUEST_VERSION, } from "viewkitjs/fields/query";
|
|
2
|
+
const OPTIONAL_PARTS = ["rowOrderMode", "itemPositions"];
|
|
3
|
+
export function requestSettingsOf(settings) {
|
|
4
|
+
const out = { filter: settings.filter, sorts: settings.sorts, group: settings.group };
|
|
5
|
+
if (settings.search?.trim())
|
|
6
|
+
out.search = settings.search;
|
|
7
|
+
for (const key of OPTIONAL_PARTS)
|
|
8
|
+
if (settings[key] !== undefined)
|
|
9
|
+
out[key] = settings[key];
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
const pageSizeOf = (size) => Math.min(LIST_REQUEST_LIMITS.pageSize, Math.max(1, Math.floor(Number.isFinite(size) ? size : 50)));
|
|
13
|
+
const messageOf = (error) => error instanceof Error ? error.message : String(error);
|
|
14
|
+
const NO_FILTER_VALUES = { selectValues: {}, relationValues: {} };
|
|
15
|
+
export function createListAnswers(o) {
|
|
16
|
+
const size = pageSizeOf(o.pageSize);
|
|
17
|
+
let generation = 0;
|
|
18
|
+
let asked = null;
|
|
19
|
+
let base = {
|
|
20
|
+
version: LIST_REQUEST_VERSION,
|
|
21
|
+
settings: requestSettingsOf(LIST_SETTINGS_DEFAULTS),
|
|
22
|
+
};
|
|
23
|
+
let rows = [];
|
|
24
|
+
let next = null;
|
|
25
|
+
let moreOut = false;
|
|
26
|
+
let groups = null;
|
|
27
|
+
let groupedBy = null;
|
|
28
|
+
let total = null;
|
|
29
|
+
let refused = null;
|
|
30
|
+
let landed = 0;
|
|
31
|
+
let first = false;
|
|
32
|
+
let shown = null;
|
|
33
|
+
const changed = () => {
|
|
34
|
+
shown = null;
|
|
35
|
+
o.onChange();
|
|
36
|
+
};
|
|
37
|
+
const send = async (request) => {
|
|
38
|
+
let answer;
|
|
39
|
+
try {
|
|
40
|
+
answer = await o.source(request);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
o.onError(messageOf(error));
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return answerFor(request, answer);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
o.onError(messageOf(error));
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const tracked = async (request, land, after) => {
|
|
55
|
+
const at = generation;
|
|
56
|
+
changed();
|
|
57
|
+
const answer = await send(request);
|
|
58
|
+
if (at !== generation)
|
|
59
|
+
return;
|
|
60
|
+
if (answer)
|
|
61
|
+
land(answer);
|
|
62
|
+
after?.();
|
|
63
|
+
changed();
|
|
64
|
+
};
|
|
65
|
+
const ask = (settings, hold) => {
|
|
66
|
+
const parts = requestSettingsOf(settings);
|
|
67
|
+
const held = hold?.length ? hold : null;
|
|
68
|
+
const key = JSON.stringify([parts, held]);
|
|
69
|
+
if (key === asked)
|
|
70
|
+
return;
|
|
71
|
+
asked = key;
|
|
72
|
+
generation += 1;
|
|
73
|
+
first = true;
|
|
74
|
+
base = { version: LIST_REQUEST_VERSION, settings: parts, ...(held && { hold: held }) };
|
|
75
|
+
moreOut = false;
|
|
76
|
+
const at = generation;
|
|
77
|
+
void tracked({ ...base, part: "rows", page: { size } }, (answer) => {
|
|
78
|
+
landed = at;
|
|
79
|
+
groupedBy = parts.group;
|
|
80
|
+
if (isRefused(answer)) {
|
|
81
|
+
refused = answer.refused.message;
|
|
82
|
+
rows = [];
|
|
83
|
+
next = null;
|
|
84
|
+
groups = null;
|
|
85
|
+
total = null;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
refused = null;
|
|
89
|
+
total = answer.total;
|
|
90
|
+
if (answer.groups) {
|
|
91
|
+
rows = [];
|
|
92
|
+
next = null;
|
|
93
|
+
groups = answer.groups.map((g) => ({
|
|
94
|
+
key: g.key,
|
|
95
|
+
label: g.label,
|
|
96
|
+
count: g.count,
|
|
97
|
+
hidden: g.hidden,
|
|
98
|
+
rows: g.rows,
|
|
99
|
+
next: g.next ?? null,
|
|
100
|
+
out: false,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
groups = null;
|
|
105
|
+
rows = answer.rows;
|
|
106
|
+
next = answer.next;
|
|
107
|
+
}
|
|
108
|
+
}, () => {
|
|
109
|
+
first = false;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const loadMore = () => {
|
|
113
|
+
if (landed !== generation || groups || next === null || moreOut)
|
|
114
|
+
return;
|
|
115
|
+
moreOut = true;
|
|
116
|
+
void tracked({ ...base, part: "rows", page: { size, after: next } }, (answer) => {
|
|
117
|
+
if (isRefused(answer)) {
|
|
118
|
+
refused = answer.refused.message;
|
|
119
|
+
next = null;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
rows = [...rows, ...answer.rows];
|
|
123
|
+
next = answer.next;
|
|
124
|
+
}, () => {
|
|
125
|
+
moreOut = false;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
const loadGroup = (key) => {
|
|
129
|
+
const group = landed === generation ? groups?.find((g) => g.key === key) : undefined;
|
|
130
|
+
if (!group || group.out || (group.rows !== undefined && group.next === null))
|
|
131
|
+
return;
|
|
132
|
+
group.out = true;
|
|
133
|
+
void tracked({
|
|
134
|
+
...base,
|
|
135
|
+
part: "group",
|
|
136
|
+
group: { key },
|
|
137
|
+
page: { size, after: group.rows === undefined ? null : group.next },
|
|
138
|
+
}, (answer) => {
|
|
139
|
+
if (isRefused(answer)) {
|
|
140
|
+
refused = answer.refused.message;
|
|
141
|
+
group.next = null;
|
|
142
|
+
group.rows ??= [];
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (answer.key !== key) {
|
|
146
|
+
o.onError(`answered group ${answer.key} to a group ${key} request`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
group.rows = [...(group.rows ?? []), ...answer.rows];
|
|
150
|
+
group.next = answer.next;
|
|
151
|
+
}, () => {
|
|
152
|
+
group.out = false;
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const once = async (request) => {
|
|
156
|
+
const answer = await send(request);
|
|
157
|
+
return answer && !isRefused(answer) ? answer : null;
|
|
158
|
+
};
|
|
159
|
+
const labelOf = (g) => g.label ?? (groupedBy && o.nameGroup?.(groupedBy, g.key)) ?? null;
|
|
160
|
+
const state = () => {
|
|
161
|
+
if (shown)
|
|
162
|
+
return shown;
|
|
163
|
+
const current = landed === generation;
|
|
164
|
+
const drawn = groups
|
|
165
|
+
? groups
|
|
166
|
+
.filter((g) => !g.hidden)
|
|
167
|
+
.map((g) => ({ key: g.key, label: labelOf(g), items: g.rows ?? [] }))
|
|
168
|
+
: [{ key: "all", label: null, items: rows }];
|
|
169
|
+
shown = {
|
|
170
|
+
groups: drawn,
|
|
171
|
+
grouped: !!groups,
|
|
172
|
+
groupHeads: (groups ?? []).map((g) => ({
|
|
173
|
+
key: g.key,
|
|
174
|
+
label: labelOf(g) ?? g.key,
|
|
175
|
+
count: g.count,
|
|
176
|
+
hidden: g.hidden,
|
|
177
|
+
})),
|
|
178
|
+
ids: drawn.flatMap((g) => g.items.map((row) => row.id)),
|
|
179
|
+
total,
|
|
180
|
+
filterValues: NO_FILTER_VALUES,
|
|
181
|
+
loading: first,
|
|
182
|
+
refused,
|
|
183
|
+
paged: true,
|
|
184
|
+
viewCounts: null,
|
|
185
|
+
holdCounts: null,
|
|
186
|
+
more: {
|
|
187
|
+
rows: current && !groups && next !== null,
|
|
188
|
+
groups: Object.fromEntries((groups ?? []).map((g) => [g.key, current && g.count > 0 && (g.rows === undefined || g.next !== null)])),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
return shown;
|
|
192
|
+
};
|
|
193
|
+
return {
|
|
194
|
+
ask,
|
|
195
|
+
loadMore,
|
|
196
|
+
loadGroup,
|
|
197
|
+
ids: async () => {
|
|
198
|
+
const at = generation;
|
|
199
|
+
const answer = await send({ ...base, part: "ids" });
|
|
200
|
+
if (!answer || at !== generation)
|
|
201
|
+
return null;
|
|
202
|
+
if (isRefused(answer)) {
|
|
203
|
+
o.onError(answer.refused.message);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return answer.ids;
|
|
207
|
+
},
|
|
208
|
+
counts: async (of, fields) => (await once({
|
|
209
|
+
...base,
|
|
210
|
+
part: "counts",
|
|
211
|
+
counts: { of, fields: [...fields] },
|
|
212
|
+
}))?.counts ?? null,
|
|
213
|
+
values: async (field) => {
|
|
214
|
+
const answer = await once({ ...base, part: "values", field });
|
|
215
|
+
return answer ? { values: answer.values, labels: answer.labels } : null;
|
|
216
|
+
},
|
|
217
|
+
viewCounts: async (views) => (await once({
|
|
218
|
+
...base,
|
|
219
|
+
settings: { ...base.settings, filter: LIST_SETTINGS_DEFAULTS.filter },
|
|
220
|
+
part: "view-counts",
|
|
221
|
+
views: views.map((v) => ({ id: v.id, filter: v.filter })),
|
|
222
|
+
}))?.counts ?? null,
|
|
223
|
+
state,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ListAnswer, type ListRequest, type ListRow } from "viewkitjs/fields/query";
|
|
2
|
+
/** Where a list's rows come from: one request in, its answer out. A refusal is an answer (`isRefused`), never a
|
|
3
|
+
* throw; a throw is a failure the list can only report. One argument, so a server action is a source as it stands. */
|
|
4
|
+
export type ListSource<Row extends ListRow = ListRow> = (request: ListRequest) => Promise<ListAnswer<Row>>;
|
|
5
|
+
/**
|
|
6
|
+
* A source that POSTs each request as JSON to `url` and reads the answer. `init` is handed to `fetch` (its headers
|
|
7
|
+
* kept, `content-type` set to JSON). A 2xx answer, or a 400 holding a refusal, is checked with `listAnswerSchema` and
|
|
8
|
+
* `answerFor` and handed back; any other status throws, naming it, as does an answer that is no list answer or an
|
|
9
|
+
* answer to another part.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fetchSource<Row extends ListRow = ListRow>(url: string | URL, init?: Omit<RequestInit, "method" | "body">): ListSource<Row>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { answerFor, listAnswerSchema } from "viewkitjs/fields/query";
|
|
2
|
+
export function fetchSource(url, init) {
|
|
3
|
+
const at = `the list source at ${String(url)}`;
|
|
4
|
+
return async (request) => {
|
|
5
|
+
const headers = new Headers(init?.headers);
|
|
6
|
+
headers.set("content-type", "application/json");
|
|
7
|
+
if (!headers.has("accept"))
|
|
8
|
+
headers.set("accept", "application/json");
|
|
9
|
+
const response = await fetch(url, { ...init, method: "POST", headers, body: JSON.stringify(request) });
|
|
10
|
+
if (!response.ok && response.status !== 400)
|
|
11
|
+
throw new Error(`${at} answered ${response.status}`);
|
|
12
|
+
let body;
|
|
13
|
+
try {
|
|
14
|
+
body = await response.json();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
throw new Error(`${at} answered ${response.status} with no JSON`);
|
|
18
|
+
}
|
|
19
|
+
const read = listAnswerSchema.safeParse(body);
|
|
20
|
+
if (!read.success)
|
|
21
|
+
throw new Error(`${at} answered no list answer: ${read.error.issues[0]?.message ?? "unreadable"}`);
|
|
22
|
+
if (!response.ok && !("refused" in read.data))
|
|
23
|
+
throw new Error(`${at} answered ${response.status}`);
|
|
24
|
+
try {
|
|
25
|
+
return answerFor(request, read.data);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new Error(`${at} ${error.message}`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|