@viewkitjs/views 0.1.0 → 0.3.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 +767 -1
- package/README.md +92 -41
- package/dist/atoms/LoadMore.js +11 -1
- package/dist/atoms/Row.js +1 -1
- package/dist/atoms/RowMenu.d.ts +1 -1
- package/dist/atoms/RowMenu.js +20 -6
- package/dist/atoms/types.d.ts +4 -4
- package/dist/cells/cell-format.d.ts +3 -3
- package/dist/cells/cell-title.d.ts +1 -2
- package/dist/cells/cell-title.js +2 -2
- package/dist/cells/cell-values.js +6 -3
- package/dist/contract.d.ts +79 -8
- package/dist/contract.js +55 -8
- package/dist/display/converted.d.ts +19 -0
- package/dist/display/converted.js +12 -0
- package/dist/display/format.d.ts +16 -1
- package/dist/display/format.js +10 -1
- package/dist/display/index.d.ts +2 -1
- package/dist/display/index.js +2 -1
- package/dist/display/link-click.d.ts +11 -0
- package/dist/display/link-click.js +3 -0
- package/dist/display/link.js +12 -6
- package/dist/display/location.d.ts +4 -3
- package/dist/display/location.js +12 -5
- package/dist/display/multi-value.d.ts +1 -1
- package/dist/display/multi-value.js +1 -1
- package/dist/display/options.d.ts +8 -2
- package/dist/display/percent.js +10 -3
- package/dist/display/phone.d.ts +2 -1
- package/dist/display/phone.js +11 -2
- package/dist/display/relation.js +1 -1
- package/dist/editors/ChipsEditor.d.ts +9 -4
- package/dist/editors/ChipsEditor.js +7 -3
- package/dist/editors/DateEditor.d.ts +21 -6
- package/dist/editors/DateEditor.js +118 -30
- package/dist/editors/EditorPanel.d.ts +61 -0
- package/dist/editors/EditorPanel.js +54 -0
- package/dist/editors/LocationEditor.d.ts +3 -0
- package/dist/editors/LocationEditor.js +28 -21
- package/dist/editors/NameEditor.d.ts +3 -0
- package/dist/editors/NameEditor.js +15 -10
- package/dist/editors/NumberEditor.d.ts +3 -0
- package/dist/editors/NumberEditor.js +7 -7
- package/dist/editors/RangeEditor.d.ts +16 -1
- package/dist/editors/RangeEditor.js +22 -6
- package/dist/editors/RelationEditor.d.ts +13 -28
- package/dist/editors/RelationEditor.js +17 -40
- package/dist/editors/RelationSetEditor.d.ts +53 -0
- package/dist/editors/RelationSetEditor.js +112 -0
- package/dist/editors/SelectEditor.d.ts +21 -3
- package/dist/editors/SelectEditor.js +55 -9
- package/dist/editors/TextEditor.d.ts +51 -0
- package/dist/editors/TextEditor.js +81 -0
- package/dist/editors/ValueListEditor.d.ts +5 -2
- package/dist/editors/ValueListEditor.js +11 -9
- package/dist/editors/edit-cores.d.ts +13 -10
- package/dist/editors/edit-cores.js +7 -6
- package/dist/editors/edit-session.d.ts +21 -11
- package/dist/editors/edit-session.js +19 -5
- package/dist/editors/keep-inside.d.ts +12 -0
- package/dist/editors/keep-inside.js +20 -0
- package/dist/editors/open-value.d.ts +21 -0
- package/dist/editors/open-value.js +36 -0
- package/dist/editors/open-values.d.ts +4 -0
- package/dist/editors/open-values.js +7 -0
- package/dist/editors/relation-kinds.d.ts +7 -0
- package/dist/editors/relation-kinds.js +21 -0
- package/dist/editors/relation-panel.d.ts +69 -0
- package/dist/editors/relation-panel.js +40 -0
- package/dist/field-row/FieldNoteLine.d.ts +14 -0
- package/dist/field-row/FieldNoteLine.js +14 -0
- package/dist/field-row/FieldRow.d.ts +73 -0
- package/dist/field-row/FieldRow.js +157 -0
- package/dist/field-row/FieldRowLane.d.ts +19 -0
- package/dist/field-row/FieldRowLane.js +11 -0
- package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
- package/dist/field-row/editors/RowChipsEditor.js +25 -0
- package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
- package/dist/field-row/editors/RowDateEditor.js +18 -0
- package/dist/field-row/editors/RowEditor.d.ts +39 -0
- package/dist/field-row/editors/RowEditor.js +64 -0
- package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
- package/dist/field-row/editors/RowNameEditor.js +15 -0
- package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
- package/dist/field-row/editors/RowNumberEditor.js +18 -0
- package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
- package/dist/field-row/editors/RowPlaceEditor.js +18 -0
- package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
- package/dist/field-row/editors/RowRangeEditor.js +15 -0
- package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
- package/dist/field-row/editors/RowRelationEditor.js +77 -0
- package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
- package/dist/field-row/editors/RowSelectEditor.js +23 -0
- package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
- package/dist/field-row/editors/RowTextEditor.js +16 -0
- package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
- package/dist/field-row/editors/RowValueListEditor.js +21 -0
- package/dist/field-row/editors/host.d.ts +59 -0
- package/dist/field-row/editors/host.js +1 -0
- package/dist/field-row/editors/row-session.d.ts +49 -0
- package/dist/field-row/editors/row-session.js +49 -0
- package/dist/field-row/index.d.ts +5 -0
- package/dist/field-row/index.js +5 -0
- package/dist/field-row/row-target.d.ts +20 -0
- package/dist/field-row/row-target.js +3 -0
- package/dist/field-row/useFieldWrite.d.ts +45 -0
- package/dist/field-row/useFieldWrite.js +190 -0
- package/dist/field-row/useRowSettlement.d.ts +33 -0
- package/dist/field-row/useRowSettlement.js +23 -0
- package/dist/fields/binding.d.ts +7 -2
- package/dist/fields/binding.js +13 -6
- package/dist/fields/currency.d.ts +0 -10
- package/dist/fields/currency.js +0 -14
- package/dist/fields/edit-core-types.d.ts +9 -9
- package/dist/fields/edit-core-types.js +6 -6
- package/dist/fields/money.d.ts +6 -0
- package/dist/fields/money.js +11 -0
- package/dist/fields/number-edit.d.ts +6 -0
- package/dist/fields/number-edit.js +4 -0
- package/dist/fields/prepare-write.js +6 -1
- package/dist/fields/relation-source-types.d.ts +12 -0
- package/dist/fields/write-target.d.ts +50 -0
- package/dist/fields/write-target.js +10 -0
- package/dist/filters/filter-model.d.ts +0 -1
- package/dist/filters/registry.d.ts +3 -36
- package/dist/filters/registry.js +0 -38
- package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
- package/dist/grid/chrome/GridAddColumn.js +29 -0
- package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
- package/dist/grid/chrome/GridAggregateMenu.js +29 -0
- package/dist/grid/chrome/GridCellEditors.d.ts +71 -0
- package/dist/grid/chrome/GridCellEditors.js +126 -0
- package/dist/grid/chrome/GridCellOutline.d.ts +49 -0
- package/dist/grid/chrome/GridCellOutline.js +16 -0
- package/dist/grid/chrome/GridChipsEditor.d.ts +38 -0
- package/dist/grid/chrome/GridChipsEditor.js +35 -0
- package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
- package/dist/grid/chrome/GridColumnColorSection.js +40 -0
- package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
- package/dist/grid/chrome/GridColumnDateSection.js +23 -0
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
- package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
- package/dist/grid/chrome/GridColumnMenu.js +103 -0
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
- package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
- package/dist/grid/chrome/GridColumnSortSection.js +16 -0
- package/dist/grid/chrome/GridDateEditor.d.ts +34 -0
- package/dist/grid/chrome/GridDateEditor.js +19 -0
- package/dist/grid/chrome/GridFlyout.d.ts +44 -0
- package/dist/grid/chrome/GridFlyout.js +80 -0
- package/dist/grid/chrome/GridFooter.d.ts +33 -0
- package/dist/grid/chrome/GridFooter.js +85 -0
- package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
- package/dist/grid/chrome/GridGroupMenu.js +64 -0
- package/dist/grid/chrome/GridHeader.d.ts +66 -0
- package/dist/grid/chrome/GridHeader.js +42 -0
- package/dist/grid/chrome/GridLongTextEditor.d.ts +55 -0
- package/dist/grid/chrome/GridLongTextEditor.js +69 -0
- package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
- package/dist/grid/chrome/GridMenuRow.js +15 -0
- package/dist/grid/chrome/GridNameEditor.d.ts +24 -0
- package/dist/grid/chrome/GridNameEditor.js +21 -0
- package/dist/grid/chrome/GridNumberEditor.d.ts +49 -0
- package/dist/grid/chrome/GridNumberEditor.js +51 -0
- package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
- package/dist/grid/chrome/GridPlaceEditor.js +22 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +30 -0
- package/dist/grid/chrome/GridRangeEditor.js +21 -0
- package/dist/grid/chrome/GridRelationEditor.d.ts +45 -0
- package/dist/grid/chrome/GridRelationEditor.js +92 -0
- package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
- package/dist/grid/chrome/GridResizeHandle.js +19 -0
- package/dist/grid/chrome/GridRow.d.ts +31 -0
- package/dist/grid/chrome/GridRow.js +179 -0
- package/dist/grid/chrome/GridRowActions.d.ts +32 -0
- package/dist/grid/chrome/GridRowActions.js +25 -0
- package/dist/grid/chrome/GridRowCells.d.ts +4 -0
- package/dist/grid/chrome/GridRowCells.js +128 -0
- package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
- package/dist/grid/chrome/GridRowGlyph.js +13 -0
- package/dist/grid/chrome/GridSelectEditor.d.ts +33 -0
- package/dist/grid/chrome/GridSelectEditor.js +43 -0
- package/dist/grid/chrome/GridStructure.d.ts +47 -0
- package/dist/grid/chrome/GridStructure.js +41 -0
- package/dist/grid/chrome/GridTable.d.ts +4 -0
- package/dist/grid/chrome/GridTable.js +192 -0
- package/dist/grid/chrome/GridTableSurface.d.ts +52 -0
- package/dist/grid/chrome/GridTableSurface.js +15 -0
- package/dist/grid/chrome/GridTextEditor.d.ts +45 -0
- package/dist/grid/chrome/GridTextEditor.js +38 -0
- package/dist/grid/chrome/GridValueListEditor.d.ts +30 -0
- package/dist/grid/chrome/GridValueListEditor.js +19 -0
- package/dist/grid/chrome/StuckMarker.d.ts +16 -0
- package/dist/grid/chrome/StuckMarker.js +34 -0
- package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
- package/dist/grid/chrome/cell-clipboard.js +28 -0
- package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
- package/dist/grid/chrome/cell-cut-off.js +20 -0
- package/dist/grid/chrome/cells.d.ts +21 -0
- package/dist/grid/chrome/cells.js +19 -0
- package/dist/grid/chrome/checks.d.ts +32 -0
- package/dist/grid/chrome/checks.js +32 -0
- package/dist/grid/chrome/column-glyph.d.ts +14 -0
- package/dist/grid/chrome/column-glyph.js +44 -0
- package/dist/grid/chrome/editors.d.ts +9 -0
- package/dist/grid/chrome/editors.js +10 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +53 -0
- package/dist/grid/chrome/grid-cell-classes.js +32 -0
- package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
- package/dist/grid/chrome/grid-cell-link.js +9 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
- package/dist/grid/chrome/grid-edit-session.js +118 -0
- package/dist/grid/chrome/grid-hover.d.ts +60 -0
- package/dist/grid/chrome/grid-hover.js +81 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
- package/dist/grid/chrome/grid-menu-focus.js +93 -0
- package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
- package/dist/grid/chrome/grid-menu-search.js +7 -0
- package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
- package/dist/grid/chrome/grid-row-menu-key.js +36 -0
- package/dist/grid/chrome/grid-row-props.d.ts +143 -0
- package/dist/grid/chrome/grid-row-props.js +1 -0
- package/dist/grid/chrome/grid-row-window.d.ts +61 -0
- package/dist/grid/chrome/grid-row-window.js +212 -0
- package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
- package/dist/grid/chrome/grid-scroll-owner.js +75 -0
- package/dist/grid/chrome/grid-styles.d.ts +40 -0
- package/dist/grid/chrome/grid-styles.js +9 -0
- package/dist/grid/chrome/grid-table-props.d.ts +172 -0
- package/dist/grid/chrome/grid-table-props.js +1 -0
- package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
- package/dist/grid/chrome/useGridBatchApi.js +35 -0
- package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
- package/dist/grid/chrome/useGridColumnLayout.js +206 -0
- package/dist/grid/chrome/useGridFocus.d.ts +45 -0
- package/dist/grid/chrome/useGridFocus.js +122 -0
- package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
- package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +64 -0
- package/dist/grid/chrome/useGridKeyboard.js +450 -0
- package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
- package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
- package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
- package/dist/grid/chrome/useGridRailReveal.js +67 -0
- package/dist/grid/chrome/useGridRangeActions.d.ts +51 -0
- package/dist/grid/chrome/useGridRangeActions.js +195 -0
- package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
- package/dist/grid/chrome/useGridRangeGestures.js +237 -0
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +37 -0
- package/dist/grid/chrome/useGridRowContextMenu.js +153 -0
- package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -0
- package/dist/grid/chrome/useGridScaleStyles.js +28 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
- package/dist/grid/chrome/useGridScrollArea.js +65 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +78 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +249 -0
- package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
- package/dist/grid/chrome/useGridTableSelection.js +55 -0
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
- package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
- package/dist/grid/core/clipboard-model.d.ts +83 -0
- package/dist/grid/core/clipboard-model.js +291 -0
- package/dist/grid/core/column-values.d.ts +27 -0
- package/dist/grid/core/column-values.js +76 -0
- package/dist/grid/core/commit-model.d.ts +41 -0
- package/dist/grid/core/commit-model.js +3 -0
- package/dist/grid/core/coordinates.d.ts +48 -0
- package/dist/grid/core/coordinates.js +27 -0
- package/dist/grid/core/edge-scroll.d.ts +21 -0
- package/dist/grid/core/edge-scroll.js +23 -0
- package/dist/grid/core/edit-values.d.ts +9 -0
- package/dist/grid/core/edit-values.js +1 -0
- package/dist/grid/core/editing-controller.d.ts +60 -0
- package/dist/grid/core/editing-controller.js +266 -0
- package/dist/grid/core/editing-model.d.ts +87 -0
- package/dist/grid/core/editing-model.js +148 -0
- package/dist/grid/core/flat-rows.d.ts +35 -0
- package/dist/grid/core/flat-rows.js +20 -0
- package/dist/grid/core/grid-aria.d.ts +27 -0
- package/dist/grid/core/grid-aria.js +39 -0
- package/dist/grid/core/grid-focus.d.ts +54 -0
- package/dist/grid/core/grid-focus.js +148 -0
- package/dist/grid/core/grid-scale.d.ts +14 -0
- package/dist/grid/core/grid-scale.js +8 -0
- package/dist/grid/core/nav.d.ts +94 -0
- package/dist/grid/core/nav.js +92 -0
- package/dist/grid/core/pending-reconciliation.d.ts +53 -0
- package/dist/grid/core/pending-reconciliation.js +51 -0
- package/dist/grid/core/range-model.d.ts +25 -0
- package/dist/grid/core/range-model.js +59 -0
- package/dist/grid/core/row-window.d.ts +40 -0
- package/dist/grid/core/row-window.js +43 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +101 -0
- package/dist/grid/core/spreadsheet-operations.js +280 -0
- package/dist/grid/core/useGridEditing.d.ts +46 -0
- package/dist/grid/core/useGridEditing.js +93 -0
- package/dist/grid/core/useGridRange.d.ts +20 -0
- package/dist/grid/core/useGridRange.js +24 -0
- package/dist/grid/core/value-equality.d.ts +54 -0
- package/dist/grid/core/value-equality.js +80 -0
- package/dist/grid/index.d.ts +18 -0
- package/dist/grid/index.js +5 -0
- package/dist/grid/useGridTablePrefs.d.ts +49 -0
- package/dist/grid/useGridTablePrefs.js +99 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/viewport.d.ts +3 -0
- package/dist/internal/viewport.js +15 -0
- package/dist/model/column-capabilities.d.ts +3 -2
- package/dist/model/column-capabilities.js +28 -8
- package/dist/model/column-from.js +3 -0
- package/dist/model/column-inspect.d.ts +10 -2
- package/dist/model/column-inspect.js +9 -0
- package/dist/model/column-schema.d.ts +6 -1
- package/dist/model/column-state.d.ts +1 -1
- package/dist/model/column-types.d.ts +3 -1
- package/dist/model/column-types.js +1 -1
- package/dist/model/density.js +3 -3
- package/dist/model/filter-capabilities.d.ts +1 -1
- package/dist/model/filter-capabilities.js +1 -1
- package/dist/model/index.d.ts +4 -6
- package/dist/model/index.js +0 -1
- package/dist/model/preferences.d.ts +7 -7
- package/dist/model/preferences.js +0 -1
- package/dist/model/prefs-buckets.d.ts +0 -1
- package/dist/model/prefs-buckets.js +0 -3
- package/dist/model/render-count.d.ts +6 -0
- package/dist/model/render-count.js +11 -0
- package/dist/provider/ViewsProvider.d.ts +6 -2
- package/dist/provider/ViewsProvider.js +12 -2
- package/dist/provider/components.d.ts +35 -9
- package/dist/provider/components.js +4 -2
- package/dist/provider/context.d.ts +8 -4
- package/dist/provider/desktop.d.ts +9 -0
- package/dist/provider/desktop.js +22 -0
- package/dist/provider/menu-groups.d.ts +8 -0
- package/dist/provider/menu-groups.js +38 -0
- package/dist/provider/plain-input.d.ts +8 -0
- package/dist/provider/plain-input.js +5 -0
- package/dist/provider/ports.d.ts +22 -0
- package/dist/provider/ports.js +1 -0
- package/dist/react.d.ts +3 -2
- package/dist/react.js +1 -0
- package/dist/selection/SelectCheckbox.d.ts +3 -1
- package/dist/selection/SelectCheckbox.js +2 -2
- package/dist/selection/useCheckDragSelect.js +6 -5
- package/docs/contract.md +202 -72
- package/docs/getting-started.md +250 -0
- package/docs/guides/atoms.md +245 -0
- package/docs/guides/cells.md +302 -0
- package/docs/guides/columns.md +413 -0
- package/docs/guides/display.md +204 -0
- package/docs/guides/editors.md +462 -0
- package/docs/guides/ports.md +246 -0
- package/docs/guides/selection.md +270 -0
- package/docs/guides/the-grid.md +696 -0
- package/docs/guides/the-provider.md +448 -0
- package/docs/index.md +52 -0
- package/docs/install.md +9 -47
- package/docs/reference/cells.md +28 -0
- package/docs/reference/display.md +44 -0
- package/docs/reference/editors-chips.md +6 -0
- package/docs/reference/editors-date.md +6 -0
- package/docs/reference/editors-location.md +10 -0
- package/docs/reference/editors-name.md +6 -0
- package/docs/reference/editors-number.md +11 -0
- package/docs/reference/editors-open-values.md +10 -0
- package/docs/reference/editors-panel.md +12 -0
- package/docs/reference/editors-range.md +6 -0
- package/docs/reference/editors-relation.md +12 -0
- package/docs/reference/editors-select.md +9 -0
- package/docs/reference/editors-session.md +11 -0
- package/docs/reference/editors-text.md +9 -0
- package/docs/reference/editors-value-list.md +6 -0
- package/docs/reference/editors.md +5 -0
- package/docs/reference/field-row.md +16 -0
- package/docs/reference/grid.md +39 -0
- package/docs/reference/react.md +89 -0
- package/docs/reference/selection.md +33 -0
- package/docs/reference/views.md +622 -0
- package/package.json +27 -4
- package/skills/views/SKILL.md +20 -5
- package/dist/filters/types.d.ts +0 -27
- package/dist/filters/types.js +0 -1
- package/dist/model/filter-pushdown.d.ts +0 -106
- package/dist/model/filter-pushdown.js +0 -147
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RowHostProps } from "./host.js";
|
|
2
|
+
/**
|
|
3
|
+
* The FIELD ROW's hosts around the shared relation cores — search the candidates the binding carries and pick: a
|
|
4
|
+
* popover on a desktop with the caret in its search, the sheet on a phone, which opens on the list with the keyboard
|
|
5
|
+
* down until the search is tapped (`EditorPanel`). A relation holding several records edits its set and its lead with
|
|
6
|
+
* the list open, and leaves as one change; one that holds one link replaces it.
|
|
7
|
+
*
|
|
8
|
+
* ## What a pick saves
|
|
9
|
+
*
|
|
10
|
+
* What the row STORES, worked out by the field (`relationStoredOf`): a bare id, a ref with the picked record's kind
|
|
11
|
+
* where the field stores refs, or the whole set with its lead. A member field saves the id alone.
|
|
12
|
+
*
|
|
13
|
+
* ## Why this host derives the stored link itself
|
|
14
|
+
*
|
|
15
|
+
* A relation binding's `editRead` is usually ABSENT, and that is the grid's answer rather than an oversight: the grid
|
|
16
|
+
* opens its editor on the DISPLAY value, the resolved `{ id, label }` object. So the row accepts ANY shape — a bare id,
|
|
17
|
+
* a stored ref `{ kind, id }`, a resolved value, or a list of them — and reads the links off it, rather than the
|
|
18
|
+
* bindings being changed for the row's convenience.
|
|
19
|
+
*/
|
|
20
|
+
export declare function RowRelationEditor<Row>(props: RowHostProps<Row, "relation" | "user">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { relationIdOf, relationKey, relationKinds, relationLinksOf, relationStoredOf, } from "@viewkitjs/fields";
|
|
5
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
6
|
+
import { RelationEditor, RelationSetEditor, } from "../../editors/RelationEditor.js";
|
|
7
|
+
import { useKnownKinds } from "../../editors/relation-kinds.js";
|
|
8
|
+
import { useViews } from "../../provider/context.js";
|
|
9
|
+
import { OPTION_ROW_INSET } from "./host.js";
|
|
10
|
+
import { useRowEditSession } from "./row-session.js";
|
|
11
|
+
export function RowRelationEditor(props) {
|
|
12
|
+
const { field } = props;
|
|
13
|
+
if (field.type === "relation" && field.cardinality === "many")
|
|
14
|
+
return _jsx(RowRelationSetEditor, { ...props, field: field });
|
|
15
|
+
return _jsx(RowRelationOneEditor, { ...props });
|
|
16
|
+
}
|
|
17
|
+
function useKindGlyph(field, kindIcon) {
|
|
18
|
+
const { components, icons } = useViews();
|
|
19
|
+
const named = kindIcon?.(field.type === "user" ? "user" : relationKinds(field)[0]);
|
|
20
|
+
const TypeGlyph = field.type === "user" ? icons.user : icons.relation;
|
|
21
|
+
return named ? (_jsx(components.AppIcon, { name: named, className: "h-3.5 w-3.5" })) : (_jsx(TypeGlyph, { className: "h-3.5 w-3.5" }));
|
|
22
|
+
}
|
|
23
|
+
function RowRelationOneEditor({ binding, field, initial, anchor, onAttempt, onClose, message, kindIcon, }) {
|
|
24
|
+
const editorRef = useRef(null);
|
|
25
|
+
const anchorRef = useRef(null);
|
|
26
|
+
const kindGlyph = useKindGlyph(field, kindIcon);
|
|
27
|
+
const [candidates, kindOf] = useKnownKinds(binding.relation ?? { kind: "static", items: [] });
|
|
28
|
+
const { session, close, sheet } = useRowEditSession({
|
|
29
|
+
editorRef,
|
|
30
|
+
onAttempt,
|
|
31
|
+
onClose,
|
|
32
|
+
mapPayload: (id) => {
|
|
33
|
+
if (field.type !== "relation")
|
|
34
|
+
return id;
|
|
35
|
+
const kind = id == null ? undefined : kindOf(id);
|
|
36
|
+
return relationStoredOf(field, id == null ? [] : [{ id, ...(kind !== undefined ? { kind } : {}) }]);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
if (!binding.relation)
|
|
40
|
+
return null;
|
|
41
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(RelationEditor, { ref: editorRef, candidates: candidates, initial: relationIdOf(initial), clearable: !!field.nullable, kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
42
|
+
}
|
|
43
|
+
function RowRelationSetEditor({ binding, field, initial, shown, anchor, onAttempt, onClose, message, kindIcon, }) {
|
|
44
|
+
const editorRef = useRef(null);
|
|
45
|
+
const anchorRef = useRef(null);
|
|
46
|
+
const kindGlyph = useKindGlyph(field, kindIcon);
|
|
47
|
+
const { session, close, sheet } = useRowEditSession({
|
|
48
|
+
editorRef,
|
|
49
|
+
onAttempt,
|
|
50
|
+
onClose,
|
|
51
|
+
mapPayload: (links) => relationStoredOf(field, links),
|
|
52
|
+
});
|
|
53
|
+
const candidates = binding.relation;
|
|
54
|
+
if (!candidates)
|
|
55
|
+
return null;
|
|
56
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-64 z-90", children: _jsx(RelationSetEditor, { ref: editorRef, candidates: candidates, initial: setItems(field, initial, shown, candidates), lead: field.links?.primary === "flag", kindGlyph: kindGlyph, focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
57
|
+
}
|
|
58
|
+
function setItems(field, initial, shown, candidates) {
|
|
59
|
+
const labels = new Map();
|
|
60
|
+
if (candidates.kind === "static")
|
|
61
|
+
for (const item of candidates.items)
|
|
62
|
+
labels.set(item.id, { label: item.label, icon: item.icon });
|
|
63
|
+
for (const item of Array.isArray(shown) ? shown : [shown]) {
|
|
64
|
+
const id = relationKey(item);
|
|
65
|
+
const label = item?.label;
|
|
66
|
+
if (id != null && typeof label === "string")
|
|
67
|
+
labels.set(id, { ...labels.get(id), label });
|
|
68
|
+
}
|
|
69
|
+
return relationLinksOf(field, initial).map((link) => {
|
|
70
|
+
const known = labels.get(link.id);
|
|
71
|
+
return {
|
|
72
|
+
...link,
|
|
73
|
+
label: known?.label ?? link.id,
|
|
74
|
+
...(known?.icon != null ? { icon: known.icon } : {}),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type RowHostProps } from "./host.js";
|
|
2
|
+
/**
|
|
3
|
+
* The FIELD ROW's host around the shared `SelectEditor` — the same panel the
|
|
4
|
+
* grid cell and the form field open, anchored over the row's value instead of a
|
|
5
|
+
* cell rect or a trigger: a popover on a desktop, the sheet on a phone
|
|
6
|
+
* (`EditorPanel`).
|
|
7
|
+
*
|
|
8
|
+
* What lives here is only what the surface owns: the anchor and the shape of
|
|
9
|
+
* the payload the panel hands back. The rows, the draft, and what a close
|
|
10
|
+
* MEANS for a select — a pick commits, everything else discards — are the
|
|
11
|
+
* core's, in one component for every surface.
|
|
12
|
+
*/
|
|
13
|
+
export declare function RowSelectEditor<Row>({ field, initial, anchor, onAttempt, onClose, message, }: RowHostProps<Row, "select" | "status">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useRef } from "react";
|
|
4
|
+
import { isOpenVocabulary } from "@viewkitjs/fields";
|
|
5
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
6
|
+
import { useOpenValues } from "../../editors/open-values.js";
|
|
7
|
+
import { SelectEditor, pickerOptionsFromField, } from "../../editors/SelectEditor.js";
|
|
8
|
+
import { OPTION_ROW_INSET } from "./host.js";
|
|
9
|
+
import { useRowEditSession } from "./row-session.js";
|
|
10
|
+
export function RowSelectEditor({ field, initial, anchor, onAttempt, onClose, message, }) {
|
|
11
|
+
const editorRef = useRef(null);
|
|
12
|
+
const anchorRef = useRef(null);
|
|
13
|
+
const known = useOpenValues(field);
|
|
14
|
+
const current = typeof initial === "string" ? initial : null;
|
|
15
|
+
const options = useMemo(() => pickerOptionsFromField(field, { extraValues: known, current }), [field, known, current]);
|
|
16
|
+
const { session, close, sheet } = useRowEditSession({
|
|
17
|
+
editorRef,
|
|
18
|
+
onAttempt,
|
|
19
|
+
onClose,
|
|
20
|
+
mapPayload: (payload) => (payload === "" ? null : payload),
|
|
21
|
+
});
|
|
22
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", alignOffset: -OPTION_ROW_INSET, sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-56 z-90", children: _jsx(SelectEditor, { ref: editorRef, options: options, initial: current, clearable: !!field.nullable, creatable: isOpenVocabulary(field), focusSearch: !sheet, onRequestClose: close, message: message }) })] }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RowHostProps } from "./host.js";
|
|
2
|
+
/**
|
|
3
|
+
* The FIELD ROW's host around the `TextEditor`, the one editor for a
|
|
4
|
+
* `text`, a `url`, a `domain`, an `email`, a `phone` and a `rich_text` (typed as
|
|
5
|
+
* its markdown). In place: the box replaces the value where it sits, on
|
|
6
|
+
* every width; a record's row never opens a sheet for typing.
|
|
7
|
+
*
|
|
8
|
+
* The editor owns what a close means: the text tidied (trimmed; rich text only
|
|
9
|
+
* at its edges), an unchanged value a noop, so opening a row to read it never
|
|
10
|
+
* writes, and each type's own phone keyboard. Enter and blur close; Escape
|
|
11
|
+
* throws the edit away. A `long` text is a paragraph, where Enter is a newline
|
|
12
|
+
* and ⌘/Ctrl+Enter closes. The row's session asks whether the answer may
|
|
13
|
+
* close: a refused one keeps the box open with its draft and its reason under it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function RowTextEditor<Row>({ field, initial, onAttempt, onClose, }: RowHostProps<Row, "text" | "url" | "domain" | "email" | "phone" | "rich_text">): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { phoneText } from "@viewkitjs/fields";
|
|
5
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
6
|
+
import { TextEditor } from "../../editors/TextEditor.js";
|
|
7
|
+
import { cx } from "../../internal/cx.js";
|
|
8
|
+
import { RowRefusal, useRowEditSession } from "./row-session.js";
|
|
9
|
+
export function RowTextEditor({ field, initial, onAttempt, onClose, }) {
|
|
10
|
+
const editorRef = useRef(null);
|
|
11
|
+
const anchorRef = useRef(null);
|
|
12
|
+
const baseline = field.type === "phone" ? phoneText(initial, null) : typeof initial === "string" ? initial : "";
|
|
13
|
+
const long = (field.type === "text" && !!field.format?.long) || field.type === "rich_text";
|
|
14
|
+
const { session, close } = useRowEditSession({ editorRef, inPlace: true, onAttempt, onClose });
|
|
15
|
+
return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(TextEditor, { ref: editorRef, type: field.type, multiline: long, initial: baseline, label: field.label, rows: long ? 4 : undefined, maxLines: long ? 4 : undefined, onRequestClose: close, className: cx("w-full min-w-0 bg-transparent text-sm text-(color:--vk-fg) outline-hidden rounded-md px-2 -mx-2 py-1 -my-1", "ring-1 ring-(color:--vk-border) focus:ring-(color:--vk-border-brand)", long && "resize-y") }), _jsx(RowRefusal, { text: session.refusal })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MultipleType } from "@viewkitjs/fields";
|
|
2
|
+
import type { RowHostProps } from "./host.js";
|
|
3
|
+
/** Several values edit in the list editor; one edits in the row's own text box. */
|
|
4
|
+
export declare function RowListOrText<Row>(props: RowHostProps<Row, MultipleType>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
5
|
+
import { ValueListEditor } from "../../editors/ValueListEditor.js";
|
|
6
|
+
import { RowTextEditor } from "./RowTextEditor.js";
|
|
7
|
+
import { useRowEditSession } from "./row-session.js";
|
|
8
|
+
function RowValueListEditor({ field, binding, row, initial, anchor, onAttempt, onClose, }) {
|
|
9
|
+
const editorRef = useRef(null);
|
|
10
|
+
const anchorRef = useRef(null);
|
|
11
|
+
const { session, close } = useRowEditSession({ editorRef, onAttempt, onClose });
|
|
12
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, className: "block min-w-0", children: anchor }), _jsx(EditorPanel, { session: session, title: field.label, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, chrome: "menu", className: "w-96 max-w-[calc(100vw-2rem)] z-90", children: (surface) => {
|
|
13
|
+
const editor = (_jsx(ValueListEditor, { ref: editorRef, field: field, initial: initial, labels: binding.labels !== false, allowEmpty: true, region: binding.region?.(row), openLinks: surface === "sheet", onRequestClose: close }));
|
|
14
|
+
return _jsx("div", { className: surface === "sheet" ? "px-4 pb-4" : "p-1.5", children: editor });
|
|
15
|
+
} })] }));
|
|
16
|
+
}
|
|
17
|
+
export function RowListOrText(props) {
|
|
18
|
+
if ("multiple" in props.field && props.field.multiple)
|
|
19
|
+
return _jsx(RowValueListEditor, { ...props });
|
|
20
|
+
return _jsx(RowTextEditor, { ...props });
|
|
21
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { CloseResolution, FieldDefOf, FieldMessageResolver, FieldType } from "@viewkitjs/fields";
|
|
3
|
+
import type { FieldBinding } from "../../fields/binding.js";
|
|
4
|
+
/**
|
|
5
|
+
* WHAT A ROW HOST IS — the contract every editor in this folder is built to.
|
|
6
|
+
*
|
|
7
|
+
* Its own module rather than a corner of `RowEditor`: the dispatcher imports
|
|
8
|
+
* every host, so a host reaching back for its props type would close a
|
|
9
|
+
* cycle. `import type` erases at runtime and the cycle would be harmless, but
|
|
10
|
+
* a rule that only holds when you know which imports are types is not a rule
|
|
11
|
+
* anyone can apply while reading.
|
|
12
|
+
*/
|
|
13
|
+
export type RowEditorProps<Row> = {
|
|
14
|
+
binding: FieldBinding<Row>;
|
|
15
|
+
row: Row;
|
|
16
|
+
/** The stored value the editor opens on. */
|
|
17
|
+
initial: unknown;
|
|
18
|
+
/**
|
|
19
|
+
* The row's DISPLAY value, as drawn — what an ANCHORED host keeps on screen
|
|
20
|
+
* under its popover. The grid keeps a cell's content under its editor for
|
|
21
|
+
* the same reason: a row that goes blank for the whole session reads as the
|
|
22
|
+
* value having been deleted, not as it being edited. An INLINE host (number,
|
|
23
|
+
* text) replaces the value with its input and never draws this.
|
|
24
|
+
*/
|
|
25
|
+
anchor: ReactNode;
|
|
26
|
+
/** The row's DISPLAY value, as read: a relation's resolved values, whose labels a set of records opens on. */
|
|
27
|
+
shown?: unknown;
|
|
28
|
+
/** The figure the row showed, when its host read the record's amount in another currency: a money host names
|
|
29
|
+
* it under the amount it opens on, which is the record's own. */
|
|
30
|
+
conversion?: ReactNode;
|
|
31
|
+
/** Ask the row whether this answer may close the session. A refused commit
|
|
32
|
+
* is nonterminal: the host keeps its draft and guard open for correction. */
|
|
33
|
+
onAttempt: (resolution: CloseResolution<unknown>) => RowEditorAttempt;
|
|
34
|
+
/** The accepted answer has finished the host's visual close; `RowClosed` says what the row does next. */
|
|
35
|
+
onClose: (closed: RowClosed) => void;
|
|
36
|
+
message?: FieldMessageResolver;
|
|
37
|
+
/** The app's own icon name for a record kind (`AppIcon`'s name), or undefined: the glyph a
|
|
38
|
+
* relation's candidates wear. Unanswered, they wear the field type's glyph. */
|
|
39
|
+
kindIcon?: (kind: string) => string | undefined;
|
|
40
|
+
};
|
|
41
|
+
/** What a host's close tells its row. */
|
|
42
|
+
export type RowClosed = {
|
|
43
|
+
/** The edit ended from the keys or a pick, off a sheet: the row takes the focus back on its own button, so the
|
|
44
|
+
* next Tab moves on from it. */
|
|
45
|
+
focusBack: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type RowEditorAttempt = {
|
|
48
|
+
accepted: true;
|
|
49
|
+
} | {
|
|
50
|
+
accepted: false;
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
53
|
+
/** A host's props: the row's, plus the narrowed field it is bound to. */
|
|
54
|
+
export type RowHostProps<Row, K extends FieldType> = RowEditorProps<Row> & {
|
|
55
|
+
field: FieldDefOf<K>;
|
|
56
|
+
};
|
|
57
|
+
/** The inset of a picker's option row: an anchored host pulls its popover back by it, so the badge
|
|
58
|
+
* in the list sits directly under the identical badge on the row. */
|
|
59
|
+
export declare const OPTION_ROW_INSET = 14;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const OPTION_ROW_INSET = 14;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
import type { CloseReason, CloseResolution } from "@viewkitjs/fields";
|
|
3
|
+
import { type EditSession } from "../../editors/edit-session.js";
|
|
4
|
+
import type { RowEditorProps } from "./host.js";
|
|
5
|
+
/**
|
|
6
|
+
* THE FIELD ROW'S EDIT SESSION — the package's session in its admitted mode, as every row host opens it.
|
|
7
|
+
*
|
|
8
|
+
* The row asks whether an answer may close: a value refused on the spot keeps the editor open, and the session hands
|
|
9
|
+
* back its reason for `EditorPanel` (or an in-place host's own line) to show. What is the row's here, and the same for
|
|
10
|
+
* every host:
|
|
11
|
+
*
|
|
12
|
+
* - the surface, read once when the session opens, as `EditorPanel` reads it: a picker opens in the sheet below the
|
|
13
|
+
* desktop width, and a type-in stays in its box on every width;
|
|
14
|
+
* - the sheet's longer exit gap, so the answer reports after the sheet has slid away, not mid-slide;
|
|
15
|
+
* - in a sheet a blur closes nothing, because a tap on the bar's ✕ or ✓ blurs the box first;
|
|
16
|
+
* - off a sheet, an accepted close from the keys or a pick tells the row to take the focus back (`RowClosed`). The
|
|
17
|
+
* editor held the focus, or the row's button did before the editor took its place, and either is gone once it
|
|
18
|
+
* closes: the focus fell to the page and the next Tab started again from the top. A popover's blur is a Tab out of
|
|
19
|
+
* it, so it counts too; in place a blur is a press elsewhere, and an outside press, which leave the focus where
|
|
20
|
+
* they put it.
|
|
21
|
+
*/
|
|
22
|
+
/** The gap a row waits after its sheet closes before it reports: a sheet slides away for about half a second. */
|
|
23
|
+
export declare const ROW_SHEET_EXIT_MS = 500;
|
|
24
|
+
type ResolvableHandle<P> = {
|
|
25
|
+
resolveClose: (reason: CloseReason) => CloseResolution<P>;
|
|
26
|
+
};
|
|
27
|
+
export type RowEditSessionArgs<P> = {
|
|
28
|
+
editorRef: RefObject<ResolvableHandle<P> | null>;
|
|
29
|
+
/** Reshapes a commit before it is judged and written (a select's "" becoming null). */
|
|
30
|
+
mapPayload?: (payload: P) => unknown;
|
|
31
|
+
/** A type-in that stays in its box on every width: no sheet, and nothing animates out. */
|
|
32
|
+
inPlace?: boolean;
|
|
33
|
+
onAttempt: RowEditorProps<unknown>["onAttempt"];
|
|
34
|
+
onClose: RowEditorProps<unknown>["onClose"];
|
|
35
|
+
};
|
|
36
|
+
export type RowEditSession = {
|
|
37
|
+
/** For `EditorPanel`: its popover's and its sheet's closes. */
|
|
38
|
+
session: EditSession;
|
|
39
|
+
/** For the editor's `onRequestClose`: its own keys and its blur. */
|
|
40
|
+
close: (reason: CloseReason) => void;
|
|
41
|
+
/** The edit opened in the sheet: a picker on a screen that was not a desktop when it opened. */
|
|
42
|
+
sheet: boolean;
|
|
43
|
+
};
|
|
44
|
+
export declare function useRowEditSession<P>({ editorRef, mapPayload, inPlace, onAttempt, onClose, }: RowEditSessionArgs<P>): RowEditSession;
|
|
45
|
+
/** An in-place host's refusal, under its box: in a popover or a sheet `EditorPanel` draws it instead. */
|
|
46
|
+
export declare function RowRefusal({ text }: {
|
|
47
|
+
text: string | null;
|
|
48
|
+
}): ReactNode;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { useDesktop } from "../../provider/desktop.js";
|
|
6
|
+
export const ROW_SHEET_EXIT_MS = 500;
|
|
7
|
+
const RETURNS_FOCUS = new Set(["tab", "shift-tab", "escape", "enter", "pick"]);
|
|
8
|
+
export function useRowEditSession({ editorRef, mapPayload, inPlace = false, onAttempt, onClose, }) {
|
|
9
|
+
const desktop = useDesktop();
|
|
10
|
+
const [sheet] = useState(() => !inPlace && !desktop);
|
|
11
|
+
const reasonRef = useRef(null);
|
|
12
|
+
const closedRef = useRef({ focusBack: false });
|
|
13
|
+
const session = useAnchoredEditSession({
|
|
14
|
+
editorRef,
|
|
15
|
+
mapPayload,
|
|
16
|
+
onAttempt: (resolution) => {
|
|
17
|
+
const reason = reasonRef.current;
|
|
18
|
+
const attempt = onAttempt(resolution);
|
|
19
|
+
if (attempt.accepted) {
|
|
20
|
+
closedRef.current = {
|
|
21
|
+
focusBack: !sheet && reason !== null && (RETURNS_FOCUS.has(reason) || (reason === "blur" && !inPlace)),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return attempt;
|
|
25
|
+
},
|
|
26
|
+
onClose: () => onClose(closedRef.current),
|
|
27
|
+
exitMs: inPlace ? 0 : sheet ? ROW_SHEET_EXIT_MS : undefined,
|
|
28
|
+
});
|
|
29
|
+
const ask = (reason) => {
|
|
30
|
+
reasonRef.current = reason;
|
|
31
|
+
try {
|
|
32
|
+
session.close(reason);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
reasonRef.current = null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const close = (reason) => {
|
|
39
|
+
if (sheet && reason === "blur")
|
|
40
|
+
return;
|
|
41
|
+
ask(reason);
|
|
42
|
+
};
|
|
43
|
+
return { session: { ...session, close: ask }, close, sheet };
|
|
44
|
+
}
|
|
45
|
+
export function RowRefusal({ text }) {
|
|
46
|
+
if (!text)
|
|
47
|
+
return null;
|
|
48
|
+
return (_jsx("p", { role: "alert", className: "mt-1 text-xs text-(color:--vk-danger)", children: text }));
|
|
49
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { FieldRow, type FieldRowProps } from "./FieldRow.js";
|
|
2
|
+
export { useFieldWrite, FieldWriteRefusal, type FieldWriteOptions, type EditTiming, } from "./useFieldWrite.js";
|
|
3
|
+
export { FieldWriteReconciliationRequired, type EntityWriteReceipt, type EntityWriteTarget, type FieldWriteAdmission, type FieldWriteAdmissionGuard, type LockedResolver, type FieldNote, } from "../fields/write-target.js";
|
|
4
|
+
export { RowEditor, ROW_HOSTS } from "./editors/RowEditor.js";
|
|
5
|
+
export type { RowClosed, RowEditorProps, RowEditorAttempt, RowHostProps } from "./editors/host.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { FieldRow } from "./FieldRow.js";
|
|
3
|
+
export { useFieldWrite, FieldWriteRefusal, } from "./useFieldWrite.js";
|
|
4
|
+
export { FieldWriteReconciliationRequired, } from "../fields/write-target.js";
|
|
5
|
+
export { RowEditor, ROW_HOSTS } from "./editors/RowEditor.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The field row's click target box: the value's own footprint, padded out and
|
|
3
|
+
* pulled back by the same amount, so a hover shows a pill without moving the
|
|
4
|
+
* text.
|
|
5
|
+
*
|
|
6
|
+
* `min-h-7` is what keeps an EMPTY row's target the same size as a filled
|
|
7
|
+
* one's, and the number is not arbitrary: the box is `border-box`, so a
|
|
8
|
+
* min-height has to cover the padding too. One line of `leading-5` (20px) plus
|
|
9
|
+
* `py-1` top and bottom (8px) is 28px — `h-7`. `min-h-5` looks like "one line"
|
|
10
|
+
* and is 12px of content once the padding is taken out, which is why an empty
|
|
11
|
+
* row's hover came up visibly short of its neighbours'.
|
|
12
|
+
*/
|
|
13
|
+
export declare const FIELD_ROW_TARGET = "-mx-2 -my-1 flex min-h-7 w-[calc(100%+1rem)] min-w-0 items-center rounded-md px-2 py-1 text-left transition-colors hover:bg-(color:--vk-hovered)";
|
|
14
|
+
/** The same target sharing its line with a control beside it (a link's open action): it pulls back on its left
|
|
15
|
+
* only and takes the room the control leaves. */
|
|
16
|
+
export declare const FIELD_ROW_TARGET_BESIDE = "-ml-2 -my-1 flex min-h-7 min-w-0 flex-1 items-center rounded-md px-2 py-1 text-left transition-colors hover:bg-(color:--vk-hovered)";
|
|
17
|
+
/** The target laid UNDER a value whose own links and buttons must stay outside it (a rich text): an empty button
|
|
18
|
+
* filling the value's footprint, padded out by the same amount as the target. The value's layer above it lets a
|
|
19
|
+
* press on its text through, and its own links and buttons take theirs. */
|
|
20
|
+
export declare const FIELD_ROW_TARGET_UNDER = "absolute -inset-x-2 -inset-y-1 rounded-md transition-colors hover:bg-(color:--vk-hovered)";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export const FIELD_ROW_TARGET = "-mx-2 -my-1 flex min-h-7 w-[calc(100%+1rem)] min-w-0 items-center rounded-md px-2 py-1 text-left transition-colors hover:bg-(color:--vk-hovered)";
|
|
2
|
+
export const FIELD_ROW_TARGET_BESIDE = "-ml-2 -my-1 flex min-h-7 min-w-0 flex-1 items-center rounded-md px-2 py-1 text-left transition-colors hover:bg-(color:--vk-hovered)";
|
|
3
|
+
export const FIELD_ROW_TARGET_UNDER = "absolute -inset-x-2 -inset-y-1 rounded-md transition-colors hover:bg-(color:--vk-hovered)";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { FieldConventions } from "@viewkitjs/fields";
|
|
2
|
+
import type { FieldBinding } from "../fields/binding.js";
|
|
3
|
+
import type { EntityWriteTarget, FieldWriteAdmissionGuard, FieldWriteAdmission, LockedResolver } from "../fields/write-target.js";
|
|
4
|
+
/** Follows one edit from its commit to the paint: a host's own performance log. */
|
|
5
|
+
export type EditTiming = {
|
|
6
|
+
/** A step reached: "saved", "refreshed". */
|
|
7
|
+
mark(step: string): void;
|
|
8
|
+
/** The edit is over and its value drawn. */
|
|
9
|
+
painted(): void;
|
|
10
|
+
/** The edit failed. */
|
|
11
|
+
failed(): void;
|
|
12
|
+
};
|
|
13
|
+
export type FieldWriteOptions<Row> = {
|
|
14
|
+
row: Row;
|
|
15
|
+
rowId: string;
|
|
16
|
+
bindings: Record<string, FieldBinding<Row>>;
|
|
17
|
+
write: EntityWriteTarget<Row>;
|
|
18
|
+
refresh: () => void | Promise<void>;
|
|
19
|
+
locked?: LockedResolver;
|
|
20
|
+
/** Reject preview-only or replaced-identity writes before dispatch. */
|
|
21
|
+
admit?: FieldWriteAdmissionGuard;
|
|
22
|
+
/** The resolver every sentence here goes through, and the id and decimal rules the acceptance
|
|
23
|
+
* gates hold a commit to. Default: the provider's conventions. */
|
|
24
|
+
conventions?: FieldConventions;
|
|
25
|
+
/** A failed save's own sentence, when the server worded one ("A person with this email already
|
|
26
|
+
* exists"): it follows the failure in the toast, and the row shows it as the refusal it is.
|
|
27
|
+
* Default: no failure carries one. */
|
|
28
|
+
refusalOf?: (error: unknown) => string | undefined;
|
|
29
|
+
/** Follows each edit from its commit to the paint, named `<noun> <fieldKey> drawer edit`. */
|
|
30
|
+
timing?: (label: string) => EditTiming;
|
|
31
|
+
};
|
|
32
|
+
export declare class FieldWriteRefusal extends Error {
|
|
33
|
+
constructor(message: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The field row's write path — the same contract the grid's cell commit keeps:
|
|
37
|
+
* the binding maps the commit to a body or refuses with a reason; the target
|
|
38
|
+
* sends it; a failure THROWS so the row rolls its optimistic value back. A
|
|
39
|
+
* hook of its own, so a host that writes one field outside a panel (a record's
|
|
40
|
+
* hero) goes through the same queue, admission and toasts.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useFieldWrite<Row>({ row, rowId, bindings, write, refresh, locked, admit, conventions: given, refusalOf, timing, }: FieldWriteOptions<Row>): {
|
|
43
|
+
commit: (fieldKey: string, value: unknown) => FieldWriteAdmission<Row>;
|
|
44
|
+
row: Row;
|
|
45
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { prepareFieldWrite } from "../fields/prepare-write.js";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
import { FieldWriteReconciliationRequired } from "../fields/write-target.js";
|
|
6
|
+
const NO_TIMING = { mark() { }, painted() { }, failed() { } };
|
|
7
|
+
export class FieldWriteRefusal extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "FieldWriteRefusal";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function useFieldWrite({ row, rowId, bindings, write, refresh, locked, admit, conventions: given, refusalOf, timing, }) {
|
|
14
|
+
const views = useViews();
|
|
15
|
+
const conventions = given ?? views.conventions;
|
|
16
|
+
const toast = views.ports.toast;
|
|
17
|
+
const message = conventions.messages;
|
|
18
|
+
const session = useMemo(() => ({
|
|
19
|
+
active: true,
|
|
20
|
+
rowId,
|
|
21
|
+
input: row,
|
|
22
|
+
row,
|
|
23
|
+
bindings,
|
|
24
|
+
locked,
|
|
25
|
+
admit,
|
|
26
|
+
write,
|
|
27
|
+
refresh,
|
|
28
|
+
conventions,
|
|
29
|
+
message,
|
|
30
|
+
toast,
|
|
31
|
+
refusalOf,
|
|
32
|
+
timing,
|
|
33
|
+
pending: new Set(),
|
|
34
|
+
tail: Promise.resolve(),
|
|
35
|
+
}), [rowId]);
|
|
36
|
+
const [confirmed, setConfirmed] = useState(() => ({
|
|
37
|
+
input: row,
|
|
38
|
+
row,
|
|
39
|
+
}));
|
|
40
|
+
const current = confirmed.input === row ? confirmed.row : row;
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (session.reconciliationInput && session.reconciliationInput !== row) {
|
|
43
|
+
session.reconciliationInput = undefined;
|
|
44
|
+
session.reconciliationWarning = undefined;
|
|
45
|
+
}
|
|
46
|
+
session.active = true;
|
|
47
|
+
session.input = row;
|
|
48
|
+
session.row = current;
|
|
49
|
+
session.bindings = bindings;
|
|
50
|
+
session.locked = locked;
|
|
51
|
+
session.admit = admit;
|
|
52
|
+
session.write = write;
|
|
53
|
+
session.refresh = refresh;
|
|
54
|
+
session.conventions = conventions;
|
|
55
|
+
session.message = message;
|
|
56
|
+
session.toast = toast;
|
|
57
|
+
session.refusalOf = refusalOf;
|
|
58
|
+
session.timing = timing;
|
|
59
|
+
if (confirmed.input !== row)
|
|
60
|
+
setConfirmed({ input: row, row });
|
|
61
|
+
return () => {
|
|
62
|
+
session.active = false;
|
|
63
|
+
};
|
|
64
|
+
}, [
|
|
65
|
+
admit,
|
|
66
|
+
bindings,
|
|
67
|
+
confirmed.input,
|
|
68
|
+
conventions,
|
|
69
|
+
current,
|
|
70
|
+
locked,
|
|
71
|
+
message,
|
|
72
|
+
refresh,
|
|
73
|
+
refusalOf,
|
|
74
|
+
row,
|
|
75
|
+
session,
|
|
76
|
+
timing,
|
|
77
|
+
toast,
|
|
78
|
+
write,
|
|
79
|
+
]);
|
|
80
|
+
const publish = useCallback((receipt) => {
|
|
81
|
+
session.row = receipt.row;
|
|
82
|
+
if (session.active)
|
|
83
|
+
setConfirmed({ input: session.input, row: receipt.row });
|
|
84
|
+
return receipt;
|
|
85
|
+
}, [session]);
|
|
86
|
+
const commit = useCallback((fieldKey, value) => {
|
|
87
|
+
const admissionRefusal = session.admit?.() ?? undefined;
|
|
88
|
+
if (admissionRefusal)
|
|
89
|
+
return { accepted: false, reason: admissionRefusal };
|
|
90
|
+
if (session.reconciliationWarning) {
|
|
91
|
+
return { accepted: false, reason: session.reconciliationWarning };
|
|
92
|
+
}
|
|
93
|
+
if (session.pending.has(fieldKey)) {
|
|
94
|
+
return { accepted: false, reason: session.message({ key: "field.already-saving" }) };
|
|
95
|
+
}
|
|
96
|
+
const binding = session.bindings[fieldKey];
|
|
97
|
+
if (!binding)
|
|
98
|
+
return { accepted: false, reason: session.message({ key: "field.unavailable" }) };
|
|
99
|
+
const refusal = session.locked?.(fieldKey) ?? undefined;
|
|
100
|
+
const prepared = prepareFieldWrite(binding, session.row, value, {
|
|
101
|
+
writable: !refusal,
|
|
102
|
+
refusal,
|
|
103
|
+
conventions: session.conventions,
|
|
104
|
+
});
|
|
105
|
+
if (!prepared.ok)
|
|
106
|
+
return { accepted: false, reason: prepared.reason };
|
|
107
|
+
const queued = session.pending.size > 0;
|
|
108
|
+
session.pending.add(fieldKey);
|
|
109
|
+
const run = session.tail
|
|
110
|
+
.catch(() => undefined)
|
|
111
|
+
.then(async () => {
|
|
112
|
+
let body = prepared.body;
|
|
113
|
+
let claimed = prepared.settlement;
|
|
114
|
+
if (queued) {
|
|
115
|
+
const queuedAdmissionRefusal = session.admit?.() ?? undefined;
|
|
116
|
+
if (queuedAdmissionRefusal)
|
|
117
|
+
throw new FieldWriteRefusal(queuedAdmissionRefusal);
|
|
118
|
+
const currentBinding = session.bindings[fieldKey];
|
|
119
|
+
const currentRefusal = session.locked?.(fieldKey) ?? undefined;
|
|
120
|
+
if (!currentBinding)
|
|
121
|
+
throw new FieldWriteRefusal(session.message({ key: "field.unavailable" }));
|
|
122
|
+
const currentPrepared = prepareFieldWrite(currentBinding, session.row, value, {
|
|
123
|
+
writable: !currentRefusal,
|
|
124
|
+
refusal: currentRefusal,
|
|
125
|
+
conventions: session.conventions,
|
|
126
|
+
});
|
|
127
|
+
if (!currentPrepared.ok)
|
|
128
|
+
throw new FieldWriteRefusal(currentPrepared.reason);
|
|
129
|
+
body = currentPrepared.body;
|
|
130
|
+
claimed = currentPrepared.settlement;
|
|
131
|
+
}
|
|
132
|
+
const perf = session.timing?.(`${session.write.noun} ${fieldKey} drawer edit`) ?? NO_TIMING;
|
|
133
|
+
let receipt;
|
|
134
|
+
try {
|
|
135
|
+
const saved = await session.write.save(session.rowId, body);
|
|
136
|
+
const settlement = saved.settlement ?? claimed;
|
|
137
|
+
receipt = settlement === "requested" ? { ...saved, settlement } : saved;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
perf.failed();
|
|
141
|
+
if (error instanceof FieldWriteReconciliationRequired) {
|
|
142
|
+
session.reconciliationInput = session.input;
|
|
143
|
+
session.reconciliationWarning = error.warning;
|
|
144
|
+
session.toast.warning(error.warning);
|
|
145
|
+
try {
|
|
146
|
+
await session.refresh();
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (!(error instanceof FieldWriteRefusal)) {
|
|
152
|
+
const failed = session.message({
|
|
153
|
+
key: "save.failed",
|
|
154
|
+
values: { noun: session.write.noun },
|
|
155
|
+
});
|
|
156
|
+
const sentence = session.refusalOf?.(error);
|
|
157
|
+
session.toast.error(sentence ? `${failed}: ${sentence}` : failed);
|
|
158
|
+
if (sentence)
|
|
159
|
+
throw new FieldWriteRefusal(sentence);
|
|
160
|
+
}
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
publish(receipt);
|
|
164
|
+
perf.mark("saved");
|
|
165
|
+
perf.painted();
|
|
166
|
+
if (receipt.warning)
|
|
167
|
+
session.toast.warning(receipt.warning);
|
|
168
|
+
try {
|
|
169
|
+
void Promise.resolve(session.refresh())
|
|
170
|
+
.then(() => perf.mark("refreshed"))
|
|
171
|
+
.catch(() => {
|
|
172
|
+
session.toast.warning(session.message({
|
|
173
|
+
key: "save.refresh-failed",
|
|
174
|
+
values: { noun: session.write.noun },
|
|
175
|
+
}));
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
session.toast.warning(session.message({ key: "save.refresh-failed", values: { noun: session.write.noun } }));
|
|
180
|
+
}
|
|
181
|
+
return receipt;
|
|
182
|
+
});
|
|
183
|
+
session.tail = run.then(() => undefined, () => undefined);
|
|
184
|
+
const completion = run.finally(() => {
|
|
185
|
+
session.pending.delete(fieldKey);
|
|
186
|
+
});
|
|
187
|
+
return { accepted: true, completion };
|
|
188
|
+
}, [publish, session]);
|
|
189
|
+
return { commit, row: current };
|
|
190
|
+
}
|