viewkitjs 0.34.0 → 0.35.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 +110 -0
- package/package.json +1 -1
- package/views/README.md +1 -1
- package/views/dist/atoms/Avatar.js +2 -1
- package/views/dist/atoms/RelationChip.d.ts +2 -0
- package/views/dist/atoms/RelationChip.js +5 -0
- package/views/dist/atoms/RowMenu.d.ts +1 -1
- package/views/dist/atoms/RowMenu.js +15 -3
- package/views/dist/atoms/defaults.js +2 -0
- package/views/dist/atoms/types.d.ts +40 -4
- package/views/dist/cells/relation-wrap.js +9 -2
- package/views/dist/contract.d.ts +9 -6
- package/views/dist/contract.js +4 -2
- package/views/dist/controls/avatar/avatar-mark.d.ts +4 -0
- package/views/dist/controls/avatar/avatar-mark.js +5 -0
- package/views/dist/controls/avatar/avatar.d.ts +7 -4
- package/views/dist/controls/avatar/avatar.js +10 -4
- package/views/dist/controls/avatar/looks.d.ts +1 -1
- package/views/dist/controls/avatar/looks.js +3 -0
- package/views/dist/controls/avatar/record-mark.d.ts +16 -0
- package/views/dist/controls/avatar/record-mark.js +13 -0
- package/views/dist/controls/avatar/tokens.d.ts +12 -0
- package/views/dist/controls/avatar/tokens.js +3 -0
- package/views/dist/controls/avatar.css +54 -17
- package/views/dist/controls/bulk-bar/bulk-bar.js +4 -5
- package/views/dist/controls/bulk-bar/map-selection-bar.js +2 -1
- package/views/dist/controls/compound-editor/compound-editor.d.ts +3 -0
- package/views/dist/controls/compound-editor/map-parts-body.d.ts +1 -1
- package/views/dist/controls/compound-editor/map-parts-body.js +6 -1
- package/views/dist/controls/compound-editor/name-parts.js +2 -1
- package/views/dist/controls/compound-editor/place-parts.js +2 -2
- package/views/dist/controls/compound-editor/range-parts.js +10 -9
- package/views/dist/controls/customize/customize.d.ts +14 -5
- package/views/dist/controls/customize/customize.js +11 -14
- package/views/dist/controls/customize/map-customize-body.js +12 -11
- package/views/dist/controls/customize/words.d.ts +3 -3
- package/views/dist/controls/filter-editor/filter-editor.d.ts +2 -0
- package/views/dist/controls/filter-editor/filter-editor.js +4 -6
- package/views/dist/controls/filter-editor/parts.d.ts +1 -1
- package/views/dist/controls/filter-editor/parts.js +4 -4
- package/views/dist/controls/index.d.ts +1 -1
- package/views/dist/controls/internal/map-panel-controls.js +9 -5
- package/views/dist/controls/internal/panel-controls.d.ts +27 -3
- package/views/dist/controls/internal/panel-controls.js +141 -12
- package/views/dist/controls/links-editor/links-editor.js +5 -7
- package/views/dist/controls/links-editor/map-links-body.d.ts +1 -1
- package/views/dist/controls/links-editor/map-links-body.js +5 -1
- package/views/dist/controls/menu/menu.d.ts +3 -0
- package/views/dist/controls/menu/menu.js +2 -1
- package/views/dist/controls/picker/map-fields-body.d.ts +2 -2
- package/views/dist/controls/picker/map-fields-body.js +5 -1
- package/views/dist/controls/picker/map-picker.d.ts +8 -3
- package/views/dist/controls/picker/map-picker.js +14 -3
- package/views/dist/controls/picker/picker.js +11 -8
- package/views/dist/controls/picker/rows.d.ts +7 -2
- package/views/dist/controls/quick-filters/map-quick-filters-body.js +2 -1
- package/views/dist/controls/quick-filters/quick-filters.js +4 -4
- package/views/dist/controls/quick-filters/reminder.js +2 -2
- package/views/dist/controls/quick-filters/rules.d.ts +4 -1
- package/views/dist/controls/quick-filters/words.d.ts +2 -0
- package/views/dist/controls/quick-filters/words.js +1 -0
- package/views/dist/controls/select/select.d.ts +3 -0
- package/views/dist/controls/select/select.js +9 -3
- package/views/dist/controls/sort-editor/sort-editor.d.ts +2 -0
- package/views/dist/controls/sort-editor/sort-editor.js +4 -5
- package/views/dist/controls/toolbar/toolbar.d.ts +25 -12
- package/views/dist/controls/toolbar/toolbar.js +15 -20
- package/views/dist/controls/toolbar.css +0 -5
- package/views/dist/controls/tooltip/map-tooltip.d.ts +1 -1
- package/views/dist/controls/tooltip/map-tooltip.js +4 -2
- package/views/dist/controls/values-editor/map-values-body.d.ts +1 -2
- package/views/dist/controls/values-editor/map-values-body.js +5 -1
- package/views/dist/controls/values-editor/values-editor.js +8 -7
- package/views/dist/display/option-badges.d.ts +16 -0
- package/views/dist/display/option-badges.js +11 -0
- package/views/dist/display/relation-link.d.ts +12 -0
- package/views/dist/display/relation-link.js +17 -0
- package/views/dist/display/relation.d.ts +1 -1
- package/views/dist/display/relation.js +10 -3
- package/views/dist/display/select.js +1 -8
- package/views/dist/editors/EditorPanel.js +1 -1
- package/views/dist/editors/RangeEditor.d.ts +3 -0
- package/views/dist/editors/RangeEditor.js +2 -2
- package/views/dist/editors/SelectEditor.d.ts +2 -2
- package/views/dist/editors/SelectEditor.js +1 -1
- package/views/dist/editors/TextEditor.js +4 -2
- package/views/dist/editors/ValueListEditor.js +2 -1
- package/views/dist/field-row/FieldRow.js +32 -5
- package/views/dist/field-row/editors/RowRangeEditor.js +2 -1
- package/views/dist/grid/chrome/GridAddColumn.js +9 -6
- package/views/dist/grid/chrome/GridCellEditors.js +1 -1
- package/views/dist/grid/chrome/GridCellOutline.d.ts +3 -1
- package/views/dist/grid/chrome/GridCellOutline.js +16 -6
- package/views/dist/grid/chrome/GridChipsEditor.js +3 -2
- package/views/dist/grid/chrome/GridColumnMenu.js +7 -4
- package/views/dist/grid/chrome/GridFooter.d.ts +4 -1
- package/views/dist/grid/chrome/GridFooter.js +4 -4
- package/views/dist/grid/chrome/GridGroupMenu.js +39 -14
- package/views/dist/grid/chrome/GridHeader.d.ts +1 -1
- package/views/dist/grid/chrome/GridHeader.js +1 -2
- package/views/dist/grid/chrome/GridRangeEditor.d.ts +4 -1
- package/views/dist/grid/chrome/GridRangeEditor.js +2 -2
- package/views/dist/grid/chrome/GridRow.js +5 -3
- package/views/dist/grid/chrome/GridRowActions.d.ts +4 -1
- package/views/dist/grid/chrome/GridRowActions.js +2 -2
- package/views/dist/grid/chrome/GridRowCells.js +3 -2
- package/views/dist/grid/chrome/GridStructure.js +1 -1
- package/views/dist/grid/chrome/GridTable.js +32 -20
- package/views/dist/grid/chrome/checks.d.ts +1 -1
- package/views/dist/grid/chrome/checks.js +4 -1
- package/views/dist/grid/chrome/grid-cell-classes.d.ts +6 -2
- package/views/dist/grid/chrome/grid-cell-classes.js +10 -5
- package/views/dist/grid/chrome/grid-hover.d.ts +10 -2
- package/views/dist/grid/chrome/grid-hover.js +14 -4
- package/views/dist/grid/chrome/grid-row-props.d.ts +4 -0
- package/views/dist/grid/chrome/grid-rows-menu.js +9 -4
- package/views/dist/grid/chrome/grid-table-props.d.ts +10 -2
- package/views/dist/grid/grid.css +6 -0
- package/views/dist/grid/looks.d.ts +3 -1
- package/views/dist/grid/looks.js +10 -4
- package/views/dist/list/layer.d.ts +8 -0
- package/views/dist/list/layer.js +7 -0
- package/views/dist/list/store.d.ts +1 -1
- package/views/dist/list/toolbar.js +44 -19
- package/views/dist/list/views.js +1 -0
- package/views/dist/panels/availability.d.ts +5 -0
- package/views/dist/panels/availability.js +4 -5
- package/views/dist/panels/customize-body.d.ts +4 -0
- package/views/dist/panels/customize-body.js +13 -11
- package/views/dist/panels/model.d.ts +9 -4
- package/views/dist/panels/react/customize-body.js +5 -2
- package/views/dist/panels/react/customize.d.ts +5 -0
- package/views/dist/panels/react/filter/FilterEditor.d.ts +6 -0
- package/views/dist/panels/react/filter/FilterEditor.js +7 -0
- package/views/dist/panels/react/quick/QuickFiltersPanel.d.ts +3 -1
- package/views/dist/panels/react/quick/QuickFiltersPanel.js +7 -3
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +4 -1
- package/views/dist/panels/react/toolbar/Toolbar.d.ts +11 -1
- package/views/dist/panels/react/toolbar/Toolbar.js +16 -6
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +6 -1
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +12 -5
- package/views/dist/panels/react/toolbar/ToolbarFilters.d.ts +7 -3
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +18 -8
- package/views/dist/panels/react/toolbar/ToolbarOptions.d.ts +6 -1
- package/views/dist/panels/react/toolbar/ToolbarOptions.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
- package/views/dist/panels/react/toolbar/ToolbarSave.d.ts +3 -1
- package/views/dist/panels/react/toolbar/ToolbarSave.js +5 -4
- package/views/dist/panels/react/toolbar/ToolbarSort.d.ts +7 -1
- package/views/dist/panels/react/toolbar/ToolbarSort.js +6 -3
- package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +3 -0
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +4 -4
- package/views/dist/panels/react/views-row/ViewPicker.js +13 -5
- package/views/dist/panels/react.d.ts +1 -1
- package/views/dist/panels/settings/layout.js +6 -38
- package/views/dist/panels/toolbar/page-resets.d.ts +17 -0
- package/views/dist/panels/toolbar/page-resets.js +62 -0
- package/views/dist/panels/toolbar/same-item.d.ts +7 -0
- package/views/dist/panels/toolbar/same-item.js +9 -0
- package/views/dist/panels/view-state.d.ts +4 -0
- package/views/dist/provider/ViewsProvider.d.ts +9 -4
- package/views/dist/provider/ViewsProvider.js +13 -2
- package/views/dist/provider/components.d.ts +27 -5
- package/views/dist/provider/components.js +1 -1
- package/views/dist/react.d.ts +1 -1
- package/views/dist/styles.css +98 -23
- package/views/dist/styles.unlayered.css +98 -23
- package/views/docs/contract.md +38 -25
- package/views/docs/controls/avatar.md +3 -0
- package/views/docs/controls/bulk-bar.md +3 -1
- package/views/docs/controls/compound-editor.md +2 -0
- package/views/docs/controls/customize.md +1 -1
- package/views/docs/controls/filter-editor.md +1 -1
- package/views/docs/controls/links-editor.md +2 -0
- package/views/docs/controls/pane.md +1 -1
- package/views/docs/controls/picker.md +2 -0
- package/views/docs/controls/quick-filters.md +1 -1
- package/views/docs/controls/text-editor.md +1 -1
- package/views/docs/controls/values-editor.md +2 -0
- package/views/docs/guides/atoms.md +54 -3
- package/views/docs/guides/display.md +1 -1
- package/views/docs/guides/looks.md +1 -1
- package/views/docs/guides/the-grid.md +4 -2
- package/views/docs/guides/the-provider.md +2 -2
- package/views/docs/index.md +2 -2
- package/views/docs/install.md +198 -104
- package/views/docs/reference/controls.md +17 -15
- package/views/docs/reference/editors-range.md +1 -1
- package/views/docs/reference/field-row.md +1 -1
- package/views/docs/reference/grid.md +2 -1
- package/views/docs/reference/list.md +2 -2
- package/views/docs/reference/looks.md +5 -5
- package/views/docs/reference/panels-react.md +13 -12
- package/views/docs/reference/panels.md +4 -4
- package/views/docs/reference/react.md +10 -8
- package/views/docs/reference/views.md +2 -2
- package/views/docs/reshaping.md +22 -6
- package/views/skills/views/SKILL.md +2 -2
|
@@ -16,16 +16,17 @@ The components map hands the package your primitives: a button, a popover, a men
|
|
|
16
16
|
- `CommandMenu`: a `command` cell's verbs.
|
|
17
17
|
- `RelationLink`: where a relation chip goes.
|
|
18
18
|
- `RelationRoles`: a link's roles, inside its chip after the record's name.
|
|
19
|
+
- `RelationChip`: a mentioned record, every relation ViewKit draws, where the provider's `panelControls` names `RelationChip`. The default draws ViewKit's own chip.
|
|
19
20
|
- `CellMore`: the "+N" after a cell's shown values, inside `data-slot="vk-cell-more"`. ViewKit's own keeps its frame; yours draws inside a bare button, so your count tag stands there alone.
|
|
20
21
|
- `Loading`: a wait, the whole list reloading or more rows arriving.
|
|
21
22
|
- `LoadMore`: how a list asks for its next page.
|
|
22
23
|
- `PlatformMark`: a link's platform mark, drawn before the link.
|
|
23
24
|
- `RowMenu`: the row's right-click menu.
|
|
24
|
-
- `Avatar`: a person's or a record's picture, in a user's, a relation's and an actor's chip, and before the name when the list hands a row's picture
|
|
25
|
+
- `Avatar`: a person's or a record's picture, in a user's, a relation's and an actor's chip, and before the name when the list hands a row's picture; and every record's mark ViewKit's panels draw, where the provider's `panelControls` names `Avatar`. The default draws the picture, else the glyph the chip would draw.
|
|
25
26
|
- `ChoiceRow`, `CheckRow`, `RadioRow`, `DirectionButton`, `MenuRow`, `ToggleRow` and `PanelSearch`: the rows the panels (`/panels`) draw with, a value row, a tick row, a one-of-a-set row, a sort's direction arrow, a drill-in row, a switch row and a panel's text box.
|
|
26
27
|
- `Pill`: one option of a row of pills, the views row's (`/panels/react`) and any tab row's.
|
|
27
28
|
- `RangeCalendar`: the filter panel's month, a day or a range in ISO days. The default is your components map's one-day `Calendar` on the end being picked, and paints no range; hand your own to paint one.
|
|
28
|
-
- `ToolbarButton`: the toolbar's button (`/panels/react`), a glyph in a circle with its word for a dress that shows words, a count that becomes a ✕ badge when it can clear what it counts, and a dot. Hand your own to give the toolbar your buttons' look.
|
|
29
|
+
- `ToolbarButton`: the toolbar's button (`/panels/react`), a glyph in a circle with its word for a dress that shows words, a count that becomes a ✕ badge when it can clear what it counts, and a dot. Hand your own to give the toolbar your buttons' look. `CONTROL_ATOMS.ToolbarButton`, the kit's, draws the count as a count, never that ✕: under it, a part's filters clear from their own panel.
|
|
29
30
|
|
|
30
31
|
The names are `ATOM_NAMES` from `viewkitjs/views`, and the defaults hold exactly those.
|
|
31
32
|
|
|
@@ -146,6 +147,42 @@ const roleTags = renderToStaticMarkup(
|
|
|
146
147
|
assert.ok(roleTags.includes("<em>Champion</em>"));
|
|
147
148
|
```
|
|
148
149
|
|
|
150
|
+
## A mentioned record
|
|
151
|
+
|
|
152
|
+
The rule: ViewKit places a mentioned record and hands its data; your app draws it (VK-1053). Every relation ViewKit draws is one: a table's cell (one and many, and the +N list), a field row's value (Record details), `renderFieldValue` (a highlight) and a user field's chip. Name `RelationChip` in the provider's `panelControls`, beside your own `RelationChip` atom, and each is yours, handed `ViewsRelationChipProps`:
|
|
153
|
+
|
|
154
|
+
- `relation`: the record, its `id`, `label`, `entity` (its kind as your app names it, `user` for a member) and `avatarUrl`.
|
|
155
|
+
- `roles`: a link's roles in order, each its `value` and `label`, on a `many` relation that declares `links`; else none.
|
|
156
|
+
- `size`: `chip` in a table's cell or a highlight, `row` in a field row.
|
|
157
|
+
- `render`: the host's link, where it has one. Draw your chip through it, handing it your element's props, and it draws the host's element with them: a cell whose host opens its relations a bare `<button data-slot="vk-relation-link" data-no-nav>` whose press opens the record, your `RelationLink` or a host's `relationWrap` around a `<span>` holding them. Absent for an inert fact, and where the host's own element owns the click. ViewKit never makes one up.
|
|
158
|
+
- `fallback`: ViewKit's own chip as it would draw it there, link included, for a kind yours doesn't dress.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import type { ViewsRelationChipProps } from "viewkitjs/views/react";
|
|
162
|
+
|
|
163
|
+
function AppRelationChip({ relation, roles, size, render, fallback }: ViewsRelationChipProps) {
|
|
164
|
+
// A kind with no chip of yours: ViewKit's own, as it would have drawn it.
|
|
165
|
+
if (relation.entity === "automation") return <>{fallback}</>;
|
|
166
|
+
const props = {
|
|
167
|
+
className: size === "row" ? "record-chip record-chip-lg" : "record-chip",
|
|
168
|
+
children: (
|
|
169
|
+
<>
|
|
170
|
+
{relation.label}
|
|
171
|
+
{roles.length > 0 ? <em> · {roles.map((role) => role.label).join(", ")}</em> : null}
|
|
172
|
+
</>
|
|
173
|
+
),
|
|
174
|
+
};
|
|
175
|
+
return render ? render(props) : <span {...props} />;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const acmeMention = renderToStaticMarkup(
|
|
179
|
+
<AppRelationChip relation={{ id: "c1", label: "Acme", entity: "company" }} roles={[]} size="chip" fallback={null} />
|
|
180
|
+
);
|
|
181
|
+
assert.ok(acmeMention.includes('class="record-chip"'));
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Hand it with `atoms={{ RelationChip: AppRelationChip }}` and `panelControls={["RelationChip"]}`. Handed without that name, it draws nowhere, so an app that hands its atoms and names nothing sees no change; without it, or with ViewKit's own atom (which draws its `fallback`), every place draws ViewKit's chip exactly as before. A typed Select's chip is not one of them: a control stands without the provider, and your own Select draws your own mark ([A person's or a record's picture](#a-persons-or-a-records-picture)).
|
|
185
|
+
|
|
149
186
|
## A link's platform mark
|
|
150
187
|
|
|
151
188
|
A `url` value is drawn as a link, its scheme left off the label. When the link's address names a platform (LinkedIn, GitHub and the rest fields knows, plus any your conventions add with `defineConventions({ platforms })`), the display draws `PlatformMark` before it with that `LinkPlatform`: its `key` says which, its `name` what to call it. A link no platform claims is a website (`key: "website"`). The default draws nothing, so a link looks plain, and the package ships no brand art: a mark is yours to draw.
|
|
@@ -196,6 +233,20 @@ function AppAvatar({ label, avatarUrl, kind, size, fallback }: ViewsAvatarProps)
|
|
|
196
233
|
|
|
197
234
|
In your app it is your own Avatar component, its tone read from the label. What wraps the chip still owns its click (`RelationLink`), so an avatar only paints. A picture that fails to load is yours to catch: the default falls back to the glyph.
|
|
198
235
|
|
|
236
|
+
### Inside ViewKit's panels
|
|
237
|
+
|
|
238
|
+
The rule: anything ViewKit draws on screen by itself takes your own where you hand it, and ViewKit hands it data only (VK-1044). The panels draw a record's mark too: the Picker's rows, the links editor's, the bulk bar's choices, the quick filters' values and their reminder's. Name `Avatar` in the provider's `panelControls` and each is your `Avatar`, handed the record's `label`, its `avatarUrl`, its `kind` as your app names it (a deal stays a deal, not a person) and the panel's size in pixels: 20 on a computer's rows, 24 on a phone's, 40 in a phone's Picker. Its `fallback` is ViewKit's own Avatar, which a kind your atom doesn't dress can hand back.
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
declare const CONTROLS_MAP: ViewsComponents; // CONTROLS, from viewkitjs/views/controls
|
|
242
|
+
|
|
243
|
+
export function ViewsWithYourAvatar({ children }: { children: ReactNode }) {
|
|
244
|
+
return <ViewsProvider components={CONTROLS_MAP} atoms={{ Avatar: AppAvatar }} panelControls={["Avatar"]}>{children}</ViewsProvider>;
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
An `Avatar` handed without that name keeps to the chips and names above, so an atom built for `chip` and `glyph` alone never meets a number. Without it, or with ViewKit's own atom, the panels draw ViewKit's designed Avatar exactly as before. A typed Select's chip draws a mark again at its own size: ViewKit's Avatar at 16 by itself, yours at `chip` where its item says `avatar: true`.
|
|
249
|
+
|
|
199
250
|
## A command cell's verbs
|
|
200
251
|
|
|
201
252
|
A `command` field offers verbs instead of an editor: moving a deal to Lost asks for a reason, so the cell opens your verbs rather than a picker. The cell draws the trigger (the value with a chevron, a chevron alone where the value is empty, or a chevron beside a value that is already a control, such as a record's chip or a link; a member's chip is drawn inside the trigger) and hands it to `CommandMenu` with `trigger`, `items`, `align` and `label`, the field's name. Each item has a `label`, an optional `icon`, its `onClick`, `destructive` and `disabled` flags, and a `disabledReason` for a disabled one; while the record loads, every verb arrives disabled, with your reason or else "Wait for current data before editing" (`views.menus.loading`). The default names your components map's `Menu` after the field ("Actions for Stage"), anchors it on the trigger and keeps the click off the row, so opening the verbs neither selects the cell nor opens the row. Swap it when your app has its own action menu, or a sheet on a phone. [The contract](../contract.md#a-command-field) says how a command field is declared.
|
|
@@ -206,7 +257,7 @@ A `command` field offers verbs instead of an editor: moving a deal to Lost asks
|
|
|
206
257
|
|
|
207
258
|
The default opens your `Menu` at the pointer on a right-click, or from the row's ⋯ (`data-slot="vk-grid-row-more"`). On a touch screen a long-press opens nothing: the ⋯ is the way in there. Its Delete asks first, through the `confirm` port, with the message `views.menus.row-delete-confirm` and the row's `deleteLabel` as the `subject`; an app that hands no `confirm` gets the browser's own where your components map holds no `PortsHost`, ViewKit's alert dialog where it does (`CONTROLS`), and a confirm that rejects or throws counts as no. A delete that then rejects leaves the row where it was and says so through the toast port's `error`, with `views.menus.row-delete-failed`. [Ports](ports.md) covers `confirm` and the toast.
|
|
208
259
|
|
|
209
|
-
Swap it for a menu of your own, or for a long-press that selects: `onToggleSelect`, there from the first render wherever rows can be selected, flips the selection of the row last pressed. With `GridTable`'s `phonePicking` on, a call that answers a long press still held ticks the pressed row once with the grid's own, never flipping it back; with no press held it flips the row last pressed, as without the option. The default doesn't use it. The default opens your `Menu` at the pointer, so make your `Menu` a popover: one drawn in the page flow would draw after the section's rows.
|
|
260
|
+
Swap it for a menu of your own, or for a long-press that selects: `onToggleSelect`, there from the first render wherever rows can be selected, flips the selection of the row last pressed. With `GridTable`'s `phonePicking` on, a call that answers a long press still held ticks the pressed row once with the grid's own, never flipping it back; with no press held it flips the row last pressed, as without the option. The default doesn't use it. Call `onOpenChange(true)` as your menu opens and `onOpenChange(false)` as it closes, as the default does, and the grid keeps the row it opened on lit meanwhile, its tint and its ⋯ shown though the pointer has moved onto the menu. The default opens your `Menu` at the pointer, so make your `Menu` a popover: one drawn in the page flow would draw after the section's rows.
|
|
210
261
|
|
|
211
262
|
## Waits
|
|
212
263
|
|
|
@@ -76,7 +76,7 @@ assert.equal(DISPLAY_CORES.date, DISPLAY_CORES.datetime);
|
|
|
76
76
|
- **date** and **datetime**: in the reader's `dateStyle`, else the field's, else `short`; an instant shows its time unless `withTime` says `false`, the options' answer winning over the field's (`timeShown`), and only an instant has a time. Hovering for a second shows the full date (and time, for an instant) through your components map's `Tooltip`, so a relative "3d ago" can be pinned to a moment. A value that doesn't parse draws as its own text.
|
|
77
77
|
- **boolean**: four looks, the field's `format.style`. `checkbox` (the default) draws the `TickBox` atom, and `icon` your `booleanIcon(on)`; either becomes a real switch only when you hand `onToggle`, and is a plain glyph otherwise. `text` draws the option's label for the value, or the package's words. `marker` draws only when true, as the `StatusMarker` atom with your `marker` words, `markerReason` and `onResolve`.
|
|
78
78
|
- **select**, **status** and **multiselect**: a select is a category and draws the `Tag` atom in its colour (a reader's `optionColors` first, then the option's declared colour, then one derived from the value). A status is a state and draws the `StatusBadge` atom in its option's slot. A multiselect draws a tag per value, through the several-values layout. A value no option names draws as the raw value, muted, with a hover saying it is not an option, unless you hand a `labelFallback`; an open (`custom-values`) vocabulary's values are their own labels. An option's `icon` is drawn through your `AppIcon`.
|
|
79
|
-
- **relation** and **user**: a chip, the record's avatar when it has one, else your `entityIcon(kind)`, else the relation glyph, then its label, then, on a `many` relation that declares `links`, the link's roles, drawn by the `RelationRoles` atom ([atoms](atoms.md)). Where it goes is yours (`relationWrap`); without one the chip is inert. Several draw through the several-values layout, the lead link first. A user is drawn as a relation to a member, so the two never differ.
|
|
79
|
+
- **relation** and **user**: a chip, the record's avatar when it has one, else your `entityIcon(kind)`, else the relation glyph, then its label, then, on a `many` relation that declares `links`, the link's roles, drawn by the `RelationRoles` atom ([atoms](atoms.md)). Where it goes is yours (`relationWrap`); without one the chip is inert. Several draw through the several-values layout, the lead link first. A user is drawn as a relation to a member, so the two never differ. Where the provider's `panelControls` names `RelationChip`, your own atom draws the chip, handed its data, its size and the host's link ([atoms](atoms.md), A mentioned record).
|
|
80
80
|
- **url**, **domain**, **email** and **phone**: a url is a link with its scheme off the label, its platform's mark before it (the [`PlatformMark` atom](atoms.md)); a value that is no safe web address draws as text. A domain links to its site and reads no platform from it. An email is a `mailto:` link to the address alone: text stored after it (`?cc=…`, a second address) is never part of the link, and a value that holds no address draws as text. A phone is written in its international form, as its country writes it for a viewer in that country (the conventions' `region`) and internationally for anyone else, its extension after it, and dialled through a `tel:` link; a phone stored as typed draws as its text and is marked `data-as-typed`, still a link to its digits, and as text alone when it holds no digit to dial. Every phone's value is the part `data-slot="vk-phone"`, its link or its text. Several values of one of these draw the main one first, as many as fit, then a count.
|
|
81
81
|
- **location**: in a cell, its city and its country; with `wrap: "full"`, the whole place. The country is named in the viewer's language.
|
|
82
82
|
- **name**: the full name as written, else the given and family names, else `nameFallback`, else nothing.
|
|
@@ -22,7 +22,7 @@ console.log(frame["data-grid-columns"], props.verticalBorders, props.fillWidth);
|
|
|
22
22
|
|
|
23
23
|
A pick its option doesn't have (one saved by an older version, say) wears the option's default, so saved picks never break a grid. Where the picks live on the page rather than in your state, `gridLookWornOf(element)` reads them back from the closest frame.
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
Fifteen of the grid's options are read by its code. Twelve become its props through `gridLookProps`; three you wire yourself, as the Showcase does: `more` (`"pages"`: hand `GridTable` its `pages`), `figures` (`"value"`: the footer's figure words through your provider's messages) and `wait` (`"kept"`: hand the components map a `RowsWait`). The other twelve (the header's words, the rows' lines, the pinned edge, picked rows and cells, the cells' frames, names and phones, and `offer`, the footer's "+ Add calculation" under the pointer or at rest) are its look stylesheet's alone: `viewkitjs/views/grid.css`, already inside the ready stylesheet (`viewkitjs/views/styles.css`). An app that imports ViewKit's stylesheets one by one adds it after ViewKit's own classes:
|
|
26
26
|
|
|
27
27
|
```css
|
|
28
28
|
@import "viewkitjs/views/grid.css";
|
|
@@ -398,13 +398,15 @@ The columns' widths, order and visibility travel as `columnState`, a `ListColumn
|
|
|
398
398
|
|
|
399
399
|
With `parts`, a name, a place or a range offers a column per part beside its whole column: a place's country, region, city and postal code, a name's given and family names, a range's low and high ends. Each starts hidden; "+ Add column" lists a field with parts as one group beside your `Menu`, holding the field (when hidden) and its hidden parts, its count as `detail`, as Attio's does, on a phone too. A part column's id is `partKey(columnId, part)`, the key its Filter row has when your panels pass `parts: true`, so that row filters what the column shows; its sort value is `partKey(fieldKey, part)`, which `parsePartKey` turns into a sort's `fieldKey` and `by`. It reads and copies its part, and it edits and pastes as its part, in a box of its own: text for a name's part and a place's region, city and postal code, a number for a range's end, and the select over every country by name, searchable, for a place's country. A paste or a fill into a country cell takes a country's name, in the app's names language (the conventions' `language`), its locale or English, or its code. A part is locked, refused and read-only as its whole is, and it may be emptied unless its whole declares `clearable: false`; emptying the last part is judged by the field. A box refuses a value the whole field would refuse, such as a range's low end above its high end, and stays open with the field's reason. Your `onCellCommit` and `onCellsCommit` receive the whole column's id and the whole value with that part replaced, so a place keeps its other parts, a range its other end and a name its other part. A name's full name follows its given or family name only when it was empty or exactly the two joined by a space; "Nagy Imre" is kept. A place's other country clears its region and its code, and another region clears its code. A paste over two parts of one field in one row lands as one edit of the whole, and a part edit made while the field's earlier ones are still in flight builds on them. Like every composite value's, the commit goes without a pending overlay; the refetch repaints. Escape in a part's box follows the box's own type, text or number, not the field's, so `escape={{ name: "keep" }}` on the provider does not reach a given name's box. A place field limited to some `parts` offers part columns only for those. Its menu offers no Group row. Keep part columns out of your panels: they belong to the grid, and your panels take the columns you declare.
|
|
400
400
|
|
|
401
|
-
`gridProps` also carries the per-person switches: `verticalBorders
|
|
401
|
+
`gridProps` also carries the per-person switches: `verticalBorders` (the lines between the columns: the last column's closes the table, the footer draws them too and a line under itself, and the header draws them where you hand `headerVerticalBorders`), `showRowIcon` (the `rowIcon` you declare, in the title cell), `freezeIdentity` (every column through the title pinned at the left edge; on by default, on the bare grid and in `LIST_VIEW_PREF_DEFAULTS` alike, so start your prefs with `gridFreezeIdentity: false` to open it unpinned), `alwaysCheckboxes` and `scale`, the density. Every row is one height, and a cell's text stays on one line.
|
|
402
|
+
|
|
403
|
+
A row tints under the pointer. `rowHighlight="active"` tints the active row instead, alone: the row a person last pressed, or the picked cell's row, so the keyboard moves it too. It carries `data-active`, keeps its tint through a press outside the grid, and no row tints under the pointer; the row's box, ⋯ and the name's actions still show there. The grid's look picks it as Row highlight (`highlight`).
|
|
402
404
|
|
|
403
405
|
`fillWidth` is your app's choice, not a preference `gridProps` carries. On, the columns share the grid's whole width: each grows in proportion to its own width and never gets narrower than it, the header, the rows, the footer and a group's head alike, and while any column grows "+ Add column" stands right after the last one. A table already wider than the grid draws and scrolls sideways as it does without it. A column with a width set, by the person's resize or by the view, keeps it while the others take the rest, and a double-click on its edge clears a width the person set, giving it back its share; a column that declares `grid.maxWidth` keeps its own width. When no column can grow, the space after the last one stays empty, as without the option.
|
|
404
406
|
|
|
405
407
|
## Figures
|
|
406
408
|
|
|
407
|
-
Each column's footer shows one figure: the person's pick from what the column offers (sum, average, min, max and count for a number, count, filled and unique for the rest), else the column's `defaultAggregate`. Pass `aggregates`, the picks by column id, and `onAggregateChange`, which makes each footer cell a picker. On a `viewBacked` list only a column with a field can change its pick. With neither `onAggregateChange` nor a `renderAggregate` of your own, the grid draws no footer. `renderAggregate(columnId, group)` draws a footer cell yourself, with no label.
|
|
409
|
+
Each column's footer shows one figure: the person's pick from what the column offers (sum, average, min, max and count for a number, count, filled and unique for the rest), else the column's `defaultAggregate`. Pass `aggregates`, the picks by column id, and `onAggregateChange`, which makes each footer cell a picker. On a `viewBacked` list only a column with a field can change its pick. With neither `onAggregateChange` nor a `renderAggregate` of your own, the grid draws no footer. An empty cell that can pick a figure offers one ("Calculate", `views.grid.figure-pick`) under the pointer; the grid's look shows it in every empty cell at rest under Add calculation (`offer`), or wear `data-grid-offer="always"` on a frame round the grid. `renderAggregate(columnId, group)` draws a footer cell yourself, with no label.
|
|
408
410
|
|
|
409
411
|
The footer stands after the last row and scrolls with the rows. `pinFooter` pins it at the foot of the grid's scroll area instead, as a phone's table keeps its count in sight: the rows pass under it, it paints `--vk-ground` while they do (and carries `data-stuck` then; at rest it shows what the grid stands on), it stands `--vk-scroll-inset-bottom` above the edge (so what your app floats there doesn't cover it) and, while rows are selected, a step above the bar your `renderBar` draws, measured where it stands (on a phone the rows then end at the footer's bottom, so nothing of them shows in that step or round the bar): on the foot when it draws none, and the last row clears the bar the same way, pinned footer or not. The grid finds the bar in its frame, where it places what `renderBar` returns, or ViewKit's own `SelectionBar` wherever it is portalled; a bar of yours portalled out of the frame isn't seen. An ungrouped grid's footer stands at the foot even when its rows don't fill the area, and in pages it stands just above the pager. A grouped grid's footers each pin while their group's rows run past the foot, and close their group otherwise. Arrowing to a row never leaves it under the footer.
|
|
410
412
|
|
|
@@ -96,9 +96,9 @@ export function ViewsWithYourControls({ children }: { children: ReactNode }) {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
`panelControls` takes `true` (all
|
|
99
|
+
`panelControls` takes `true` (all nine) or the names you want (`["Button", "Select"]`). The sort and filter panels then draw every button, box that picks, menu, popover and text box with yours (VK-1013), and so do the group editor, Customize, the views list and view menu (with the Modal they open, and on a phone the Delete question: on a computer it goes to your `confirm` port), the quick filters' search, the filter bar's typed value and date and every head a panel draws itself on a phone, its ✕, ‹ and ✓ (VK-1014), and the text, number and date editors, each button, popover and one-line box, with `Calendar` their date's month in place of its own head and days (VK-1021), and so do the Picker wherever a ViewKit body holds it, the name and place parts and the values and links editors (VK-1022), and the bulk bar (`CONTROLS.SelectionBar`): its verbs, Delete, More, the pill's ✕ and Actions your Button, still the stops of its Toolbar (forward the `ref` your Button is handed, or the arrows skip it), More's and a group's rows your Menu, a field's list in your Popover on a computer; its count, its Toast, a phone's field sheet and Delete's question stay ViewKit's, the question's buttons yours (VK-1023). Inside a box group of ViewKit's (a date's line, a phone number's digits, Customize's and the quick filters' searches) your Input is handed `chrome="bare"`, the group drawing the frame; a box that grows over lines, a search list's box, the Number field and a duration's box stay ViewKit's ([reshaping](../reshaping.md)). Each is handed the map's props, never ViewKit's own look: your Button a `variant` from what it is (an outlined Add sort `outline`, a quiet × `ghost` at `size="icon"`), its icon and words as its children, `aria-disabled` where it can't be used but keeps its focus; your Select its rows, value and pick, `open` and `onOpenChange`, the search's words; your Menu its rows as data, opened at the button that opens it; your Popover its anchor, its close and its `label`; your Input its typing as `onChange`, in your field's frame (`chrome="field"`). Inside a ViewKit field (the name and place parts) your Input or Select is handed the `id` its label names; your Menu is handed a menu's groups, its actions and choices one level in, and its links; a popover ViewKit opens from its own button it opens itself, at your Button, and a button that is busy (the Picker's Add while it adds) comes with `aria-busy`. Each part's name rides with it as `data-slot` and `data-key`, so your control and your stylesheet meet on one name. Name `Avatar` and every record's mark the panels draw (the Picker's rows, the links editor's, the bulk bar's choices, the quick filters' values and their reminder's) is your `atoms.Avatar`, handed its data and a size in pixels ([atoms](atoms.md#a-persons-or-a-records-picture), VK-1044); an `Avatar` atom you hand without naming it draws only the chips and names it always drew. Name `RelationChip` and every mentioned record ViewKit draws (a table's cell, a field row's value, `renderFieldValue`) is your `atoms.RelationChip`, handed its data, its size and the host's link ([atoms](atoms.md#a-mentioned-record), VK-1053); handed without naming it, it draws nowhere. A control of `CONTROLS`' stays ViewKit's whatever `panelControls` says. A `Select` of your own that `panelControls` doesn't name is never drawn, and ViewKit says so once in development.
|
|
100
100
|
|
|
101
|
-
Still ViewKit's inside the panels: the
|
|
101
|
+
Name `Tooltip` and the panels' tooltips are yours, handed their words, side and, for a reason something can't be used, `reason` (VK-1015); under `Input`, the filter's number and range boxes are your Input too, a decimal box whose typing ViewKit reads as a number by your conventions (VK-1018). Still ViewKit's inside the panels: the Picker's search box and its rows (the field lists, the views list's rows; its buttons and menus are yours, VK-1022), the menu rows of ViewKit's own menus, Radio, Toggle, the quick filters' values, the sort's grip, and the head ViewKit's own `Sheet` draws (Customize's and the views list's on a phone): hand your own `Sheet` and the panels draw their heads with your Button. A filter rule's value box is named by what holds it (`vk-filter-value`), not on the box your Select or Input draws. A button's busy state (`loading`: a Save, a Delete, the Picker's Add) comes as `aria-busy` and `aria-disabled` (VK-1022); ViewKit takes no second press.
|
|
102
102
|
|
|
103
103
|
### An adapter over Radix
|
|
104
104
|
|
package/views/docs/index.md
CHANGED
|
@@ -6,8 +6,8 @@ Every example on these pages is compiled and run against the packed package befo
|
|
|
6
6
|
|
|
7
7
|
## Start here
|
|
8
8
|
|
|
9
|
-
- [
|
|
10
|
-
- [
|
|
9
|
+
- [Install](install.md): the six steps an app writes for a whole list, the four things it shapes, and your theme
|
|
10
|
+
- [Getting started](getting-started.md): a grid by hand: fields bound to your rows, columns, your primitives, the provider and the grid
|
|
11
11
|
|
|
12
12
|
## Guides
|
|
13
13
|
|
package/views/docs/install.md
CHANGED
|
@@ -1,106 +1,200 @@
|
|
|
1
1
|
# Install
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
3
|
+
A whole list (its toolbar, grid, saved views, edits and undo, on a computer and a phone) is the six steps below, and
|
|
4
|
+
nothing else. ViewKit's own test app runs exactly this at `/proof`: 115 lines in seven files (`test-app/app/proof/` and
|
|
5
|
+
its root layout, in the repository), which CI holds under 150 and installs into a fresh app from the packed package.
|
|
6
|
+
|
|
7
|
+
## 1. Pin it
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add viewkitjs zod @base-ui/react @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
One package holds the fields, the views and the server's part; `react` and `react-dom` 19 are peers your app has.
|
|
14
|
+
`@base-ui/react` (1.6 or later) is what `CONTROLS`, ViewKit's default controls, stand on. The dnd-kit packages draw
|
|
15
|
+
what drags; `viewkitjs/views/list` loads them with `import()`, so your bundler may want them even for `fetchSource`
|
|
16
|
+
alone. ESM only, Node 20 or later. The server's part reads Postgres through your own client (`pg` in the proof).
|
|
17
|
+
|
|
18
|
+
## 2. Import the stylesheet
|
|
19
|
+
|
|
20
|
+
```css
|
|
21
|
+
@import "viewkitjs/views/styles.css";
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
In your root layout: the whole look, with no Tailwind. [Your theme](#your-theme) makes the colours yours.
|
|
25
|
+
|
|
26
|
+
## 3. Mount the provider
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
"use client";
|
|
30
|
+
import type { ReactNode } from "react";
|
|
31
|
+
import { CONTROLS } from "viewkitjs/views/controls";
|
|
32
|
+
import { ViewsProvider } from "viewkitjs/views/react";
|
|
33
|
+
|
|
34
|
+
export function Views({ children }: { children: ReactNode }) {
|
|
35
|
+
return <ViewsProvider components={CONTROLS}>{children}</ViewsProvider>;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Once, above every list. `CONTROLS` fills every control and carries its atoms (`CONTROL_ATOMS`); the icons, the ports
|
|
40
|
+
and the conventions (`en-US`, `UTC`) have defaults.
|
|
41
|
+
|
|
42
|
+
## 4. Define the fields
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { defineFields, defineIndex } from "viewkitjs/fields";
|
|
46
|
+
|
|
47
|
+
export const DEAL_FIELDS = defineFields({
|
|
48
|
+
entity: "deal",
|
|
49
|
+
identity: "name",
|
|
50
|
+
fields: {
|
|
51
|
+
name: { type: "text", label: "Name", required: true },
|
|
52
|
+
stage: { type: "status", label: "Stage", options: [{ value: "new", label: "New", slot: "pending" }, { value: "won", label: "Won", slot: "success" }] },
|
|
53
|
+
seats: { type: "number", label: "Seats", validation: { integer: true } },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export type Deal = { id: string; name: string; stage: string; seats: number };
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The browser and the server read the same fields. Every field is a column, in this order, bound by its key.
|
|
61
|
+
|
|
62
|
+
## 5. Draw the list
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { List, fetchSource, type ListChange } from "viewkitjs/views/list";
|
|
66
|
+
|
|
67
|
+
const deals = fetchSource<Deal>("/api/deals/list");
|
|
68
|
+
|
|
69
|
+
async function save({ id, values }: ListChange<Deal>) {
|
|
70
|
+
const answer = await fetch(`/api/deals/${id}`, { method: "PATCH", body: JSON.stringify(values) });
|
|
71
|
+
if (!answer.ok) throw new Error("The deal wasn't saved.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function Deals() {
|
|
75
|
+
return <List id="deals" fields={DEAL_FIELDS} source={deals} save={save} />;
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`source` asks your server a page at a time; `rows` takes rows you already hold. `save`, your own route, is one call per
|
|
80
|
+
record: a throw takes the edit back. Without it the list is read-only.
|
|
81
|
+
|
|
82
|
+
## 6. Answer it on the server
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { EVERY_FIELD, listHandler, sql, type Run } from "viewkitjs/postgres";
|
|
86
|
+
import { buildFieldMap, type AppStorage } from "viewkitjs/postgres/definitions";
|
|
87
|
+
|
|
88
|
+
// Your connection (`pg`'s Pool) and your session, where the proof reads a cookie.
|
|
89
|
+
declare const pool: { query(text: string, values: unknown[]): Promise<{ rows: Record<string, unknown>[] }> };
|
|
90
|
+
declare function workspaceOf(): Promise<string | null>;
|
|
91
|
+
|
|
92
|
+
const storage: AppStorage = { defaults: { keyStored: "text" }, kinds: { deal: { table: "deals", key: "id", softDelete: null } } };
|
|
93
|
+
const run: Run = async (query) => (await pool.query(query.text, [...query.values])).rows;
|
|
94
|
+
|
|
95
|
+
// app/api/deals/list/route.ts
|
|
96
|
+
export const POST = listHandler({
|
|
97
|
+
map: buildFieldMap({ index: defineIndex([{ entity: "deal", identity: "name", fields: DEAL_FIELDS }]), storage, kind: "deal" }).map,
|
|
98
|
+
run,
|
|
99
|
+
access: async () => {
|
|
100
|
+
const workspace = await workspaceOf();
|
|
101
|
+
if (!workspace) return null; // 401
|
|
102
|
+
return { access: { deal: (row) => sql`${row.column("workspace")} = ${workspace}` }, readable: EVERY_FIELD };
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
One route answers every request the list makes. `access` is read per request from your own session: which rows of each
|
|
108
|
+
table, and which fields, the reader may read ([Answering a list's requests](../../postgres/docs/guides/list-handler.md)).
|
|
109
|
+
|
|
110
|
+
## What an app writes
|
|
111
|
+
|
|
112
|
+
| What | Required | The rest, each optional |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `<ViewsProvider>` | `components`, `children` | [The provider](guides/the-provider.md) |
|
|
115
|
+
| `<List>` | `id`, `fields`, `rows` or `source` | [The ready List](reference/list.md#the-ready-list) |
|
|
116
|
+
| `listHandler` | `map`, `run`, `access` | [Answering a list's requests](../../postgres/docs/guides/list-handler.md) |
|
|
117
|
+
|
|
118
|
+
## The four things an app shapes
|
|
119
|
+
|
|
120
|
+
**Every size and colour.** Each is a `--vk-*` token with a default: the colours below, and each control's sizes, radii,
|
|
121
|
+
gaps, shadows and timings on its own page ([the controls' tokens](contract.md#the-controls-tokens)). The toolbar's line
|
|
122
|
+
reads `--vk-toolbar-line-py`, `--vk-toolbar-line-gap` and `--vk-toolbar-line-w`, and a phone list's foot
|
|
123
|
+
`--vk-toolbar-foot`. Each piece's options and looks are on [Looks](guides/looks.md). Every part ViewKit draws has a
|
|
124
|
+
public name, its `data-slot` (and a part's `data-key`), and every state a data attribute ([Slots](contract.md#slots),
|
|
125
|
+
[States](contract.md#states)): your stylesheet dresses any of them alone.
|
|
126
|
+
|
|
127
|
+
**Its own controls.** Hand your own over ViewKit's, keeping its atoms:
|
|
128
|
+
`components={{ ...CONTROLS, Button: YourButton }} atoms={CONTROL_ATOMS}`. A map spread from `CONTROLS` carries none
|
|
129
|
+
of its atoms (your own `atoms` lie over `CONTROL_ATOMS`), and in development the provider says so once. `panelControls`
|
|
130
|
+
names which of `Button`, `Select`, `Menu`, `Popover`, `Input` and `Calendar` the panels and the field editors draw with
|
|
131
|
+
yours ([your own controls inside the panels](guides/the-provider.md#your-own-controls-inside-the-panels)). A toolbar
|
|
132
|
+
part takes its own `button` or `className` through `toolbarParts`, and ⋯ its own through `overflow`
|
|
133
|
+
([Parts as data](reference/list.md#parts-as-data)).
|
|
134
|
+
|
|
135
|
+
**Each menu's and panel's content and order.** Every menu is data: `menus={{ column: (items, ctx) => items }}`, with
|
|
136
|
+
`menu.drop`, `menu.rename`, `menu.add` and `menu.move` over its items' public keys; the proof reshapes the column menu
|
|
137
|
+
that way ([Menus as data](reference/list.md#menus-as-data)). Each panel's body is a control of the map (`CustomizeBody`,
|
|
138
|
+
`SortBody`, `FilterBody`, …), yours to replace ([The components map](contract.md#the-components-map)).
|
|
139
|
+
|
|
140
|
+
**The layout.** `toolbarParts` places each toolbar part on its line and side, with its words, and its panel where you
|
|
141
|
+
want it. `customizeIn: "pane"` opens Customize in a pane at the list's right edge. For another arrangement, `ListRoot`
|
|
142
|
+
holds the list's state and ViewKit's parts (`ListToolbar`, `ListGrid`, `ListBulkBar`) stand where you put them;
|
|
143
|
+
`ListSlot` and `ListFill` draw one outside the list's tree, in your page's header ([A list's root](reference/list.md#a-lists-root)).
|
|
144
|
+
|
|
145
|
+
## Your theme
|
|
146
|
+
|
|
147
|
+
The stylesheet's rules sit in `components › viewkit`, a layer inside `components`, and the file declares Tailwind's
|
|
148
|
+
order (`theme, base, components, utilities`), so your components rules and utilities win over ViewKit's whatever the
|
|
149
|
+
order you import in. Its reset touches only ViewKit's elements and what your components draw inside them, in
|
|
150
|
+
`base › viewkit`, under your own base styles. The defaults are the Outright look, light, and dark under `.dark` or
|
|
151
|
+
`[data-theme="dark"]`. ViewKit's classes still carry Tailwind's names (`h-8`, `rounded-md`): where your own Tailwind
|
|
152
|
+
writes one, yours wins on ViewKit's element too, until each piece moves to its own `vk-*` classes.
|
|
153
|
+
|
|
154
|
+
An app whose reset or styles sit in no layer (Tailwind 3, a plain CSS reset) imports
|
|
155
|
+
`viewkitjs/views/styles.unlayered.css` instead: only ViewKit's classes sit outside any layer; its reset stays in
|
|
156
|
+
`base › viewkit`, its `--vk-*` defaults in `components › viewkit`, and Tailwind's fallbacks for browsers without
|
|
157
|
+
`@property` in `properties`, so your own reset and colours still win. It declares no layer order: a Tailwind 4 app takes
|
|
158
|
+
`styles.css`.
|
|
159
|
+
|
|
160
|
+
**Make the colours yours (optional).** Declare the colours in no layer, or in a layer above `components`. On stock shadcn
|
|
161
|
+
tokens:
|
|
162
|
+
|
|
163
|
+
```css
|
|
164
|
+
:root {
|
|
165
|
+
--vk-fg: var(--foreground);
|
|
166
|
+
--vk-fg-subtle: var(--muted-foreground);
|
|
167
|
+
--vk-fg-subtlest: var(--muted-foreground);
|
|
168
|
+
--vk-fg-brand: var(--primary);
|
|
169
|
+
--vk-fg-selected: var(--primary);
|
|
170
|
+
--vk-fg-on-brand: var(--primary-foreground);
|
|
171
|
+
--vk-ground: var(--background);
|
|
172
|
+
--vk-overlay: var(--popover);
|
|
173
|
+
--vk-hovered: var(--accent);
|
|
174
|
+
--vk-pressed: var(--accent);
|
|
175
|
+
--vk-neutral: var(--muted);
|
|
176
|
+
--vk-neutral-hovered: var(--accent);
|
|
177
|
+
--vk-brand: var(--primary);
|
|
178
|
+
--vk-brand-subtlest: color-mix(in oklab, var(--primary) 12%, var(--background));
|
|
179
|
+
--vk-danger: var(--destructive);
|
|
180
|
+
--vk-danger-subtlest: color-mix(in oklab, var(--destructive) 12%, var(--background));
|
|
181
|
+
--vk-border: var(--border);
|
|
182
|
+
--vk-border-subtle: var(--border);
|
|
183
|
+
--vk-border-bold: var(--ring);
|
|
184
|
+
--vk-border-brand: var(--primary);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`.dark` needs nothing more. The status and category hues (`--vk-success`, `--vk-label-blue`, …) are optional
|
|
189
|
+
([Tokens](contract.md#tokens)); `--vk-gutter`, onto your pages' side padding, lines the grid's rows up with them.
|
|
190
|
+
|
|
191
|
+
**Or let your Tailwind compile it.** A Tailwind 4 app can draw ViewKit on its own scale: leave the import out and add,
|
|
192
|
+
to the stylesheet that imports Tailwind, `@source "../../node_modules/viewkitjs/views";` (the path from where it sits),
|
|
193
|
+
then `@import "viewkitjs/views/grid.css";` after Tailwind for the grid's look. Every button, input and link ViewKit
|
|
194
|
+
draws resets itself, so no base reset is needed. Nothing then declares ViewKit's tokens for you: the colour block above
|
|
195
|
+
is required, the grid's look tokens (`VK_GRID_TOKENS`) and, with `CONTROLS`, every one of the controls' tokens
|
|
196
|
+
(`VK_CONTROL_TOKENS`: spacing, type, radii, motion, shadows, the status tints), which the controls read with no
|
|
197
|
+
fallback. Their defaults are the `:where(:root)` blocks of `viewkitjs/views/styles.css`: copy them, or the controls
|
|
198
|
+
draw unstyled.
|
|
199
|
+
|
|
200
|
+
From here, [getting started](getting-started.md) builds a grid by hand, from the provider up.
|