@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
|
@@ -2,9 +2,8 @@ import { type CloseReason, type CloseResolution, type FieldMessageResolver } fro
|
|
|
2
2
|
export type DateEditorHandle = {
|
|
3
3
|
/**
|
|
4
4
|
* THE close handshake (lib/fields/close): the host learned that a close
|
|
5
|
-
* happened and asks what it means.
|
|
6
|
-
*
|
|
7
|
-
* not read; it is the host's to distinguish. Pure and idempotent: no state
|
|
5
|
+
* happened and asks what it means. Escape discards; every other reason
|
|
6
|
+
* commits the draft when dirty, else nothing. Pure and idempotent: no state
|
|
8
7
|
* moves, no timer runs, nothing is called back. The host closes its
|
|
9
8
|
* popover, waits its own exit gap, and then applies the answer.
|
|
10
9
|
*/
|
|
@@ -15,11 +14,27 @@ export declare const DateEditor: import("react").ForwardRefExoticComponent<{
|
|
|
15
14
|
initial?: string;
|
|
16
15
|
/** Time chip starts empty and stays out of the commit until set (form
|
|
17
16
|
* mode). Without it, the chip carries the stored time or 00:00 and every
|
|
18
|
-
* commit includes one
|
|
17
|
+
* commit includes one. */
|
|
19
18
|
timeOptional?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
19
|
+
/** A calendar-day field: no time chip, the commit is "YYYY-MM-DD", and a
|
|
20
|
+
* day click or a quick day asks the host to close with `pick`. Default false. */
|
|
21
|
+
dayOnly?: boolean;
|
|
22
|
+
/** The date may be emptied: a Clear row after the calendar, which asks the
|
|
23
|
+
* host to close with `pick` and commits "" (nothing when there was no date). */
|
|
24
|
+
clearable?: boolean;
|
|
25
|
+
/** The text the date box opens with (a character typed on the cell that
|
|
26
|
+
* opened the panel): focused, the caret after it, and read as a typed date. */
|
|
27
|
+
seed?: string;
|
|
28
|
+
/** Put the caret in the date box as the panel opens, without scrolling, so the keyboard is in the panel and Tab
|
|
29
|
+
* walks its controls. Default false: a host whose surface puts focus there itself, or never should (a phone's
|
|
30
|
+
* sheet opens with the keyboard down), leaves it off. A seed focuses the box either way. */
|
|
31
|
+
focusDate?: boolean;
|
|
32
|
+
/** The panel saw a key that means "done" (Enter) or "leave" (Escape), or a
|
|
33
|
+
* pick (`dayOnly`'s day click, the Clear row). It never closes itself — the
|
|
34
|
+
* host closes, then asks `resolveClose`. */
|
|
22
35
|
onRequestClose: (reason: CloseReason) => void;
|
|
23
36
|
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
24
37
|
message?: FieldMessageResolver;
|
|
38
|
+
/** The calendar takes the panel's whole width (a phone's sheet), rather than its own. Default false. */
|
|
39
|
+
fill?: boolean;
|
|
25
40
|
} & import("react").RefAttributes<DateEditorHandle>>;
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
3
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
|
|
4
4
|
import { formatChipDate, normalizeTime, parseDateText, toYmd, } from "@viewkitjs/fields";
|
|
5
5
|
import { fromDayKey, toDayKey } from "@viewkitjs/fields/query";
|
|
6
6
|
import { cx } from "../internal/cx.js";
|
|
7
7
|
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { isDesktopNow } from "../provider/desktop.js";
|
|
9
|
+
const QUICK_DAYS = [
|
|
10
|
+
{ key: "date.today", offset: () => 0 },
|
|
11
|
+
{ key: "date.tomorrow", offset: () => 1 },
|
|
12
|
+
{ key: "date.next-monday", offset: (weekday) => (8 - weekday) % 7 || 7 },
|
|
13
|
+
];
|
|
14
|
+
function quickDay(offset) {
|
|
15
|
+
const now = new Date();
|
|
16
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate() + offset(now.getDay()));
|
|
17
|
+
}
|
|
18
|
+
const FOCUSABLE = "input, select, textarea, button, a[href], [tabindex]";
|
|
19
|
+
function tabEnds(root) {
|
|
20
|
+
const reachable = Array.from(root.querySelectorAll(FOCUSABLE)).filter((element) => element.tabIndex >= 0 &&
|
|
21
|
+
!element.disabled &&
|
|
22
|
+
element.closest("[hidden], [inert]") === null);
|
|
23
|
+
return { first: reachable[0], last: reachable.at(-1) };
|
|
24
|
+
}
|
|
8
25
|
const CALENDAR_START = "1900-01";
|
|
9
26
|
const CALENDAR_END = `${new Date().getFullYear() + 10}-12`;
|
|
10
27
|
const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
|
|
@@ -12,22 +29,29 @@ const TIME_OPTIONS = Array.from({ length: 96 }, (_, i) => {
|
|
|
12
29
|
const mm = String((i % 4) * 15).padStart(2, "0");
|
|
13
30
|
return `${hh}:${mm}`;
|
|
14
31
|
});
|
|
32
|
+
function readStored(iso) {
|
|
33
|
+
if (!iso)
|
|
34
|
+
return undefined;
|
|
35
|
+
const parsed = fromDayKey(iso) ?? new Date(iso);
|
|
36
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
37
|
+
}
|
|
15
38
|
function initialHasTime(iso, parsed) {
|
|
16
39
|
if (!iso || !parsed)
|
|
17
40
|
return false;
|
|
18
41
|
return /T/.test(iso);
|
|
19
42
|
}
|
|
20
|
-
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, onRequestClose, message }, ref) {
|
|
43
|
+
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, }, ref) {
|
|
21
44
|
const timeRef = useRef(null);
|
|
45
|
+
const dateRef = useRef(null);
|
|
22
46
|
const views = useViews();
|
|
23
47
|
const words = message ?? views.conventions.messages;
|
|
24
|
-
const { Calendar } = views.components;
|
|
48
|
+
const { Calendar, Input } = views.components;
|
|
49
|
+
const { List, Row } = views.atoms;
|
|
25
50
|
const DateGlyph = views.icons.date;
|
|
26
51
|
const TimeGlyph = views.icons.time;
|
|
27
52
|
const [timeOpen, setTimeOpen] = useState(false);
|
|
28
53
|
const activeTimeRef = useRef(null);
|
|
29
|
-
const
|
|
30
|
-
const valid = parsed && !Number.isNaN(parsed.getTime()) ? parsed : undefined;
|
|
54
|
+
const valid = readStored(initial);
|
|
31
55
|
const [day, setDay] = useState(valid);
|
|
32
56
|
const [month, setMonth] = useState(valid);
|
|
33
57
|
const hadTime = initialHasTime(initial, valid);
|
|
@@ -37,24 +61,70 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
37
61
|
? ""
|
|
38
62
|
: "00:00";
|
|
39
63
|
const [timeVal, setTimeVal] = useState(initialTime);
|
|
40
|
-
const [dateVal, setDateVal] = useState(() => formatChipDate(valid ?? new Date()));
|
|
41
|
-
const touchedRef = useRef(
|
|
64
|
+
const [dateVal, setDateVal] = useState(() => seed ?? formatChipDate(valid ?? new Date()));
|
|
65
|
+
const touchedRef = useRef(seed != null);
|
|
66
|
+
const dayRef = useRef(valid);
|
|
67
|
+
const dateTextRef = useRef(dateVal);
|
|
68
|
+
const timeTextRef = useRef(timeVal);
|
|
69
|
+
const clearedRef = useRef(false);
|
|
70
|
+
const writeDateText = (text) => {
|
|
71
|
+
clearedRef.current = false;
|
|
72
|
+
dateTextRef.current = text;
|
|
73
|
+
setDateVal(text);
|
|
74
|
+
};
|
|
75
|
+
const writeTime = (text) => {
|
|
76
|
+
clearedRef.current = false;
|
|
77
|
+
timeTextRef.current = text;
|
|
78
|
+
setTimeVal(text);
|
|
79
|
+
};
|
|
80
|
+
const chooseDay = (d) => {
|
|
81
|
+
touchedRef.current = true;
|
|
82
|
+
dayRef.current = d;
|
|
83
|
+
setDay(d);
|
|
84
|
+
setMonth(d);
|
|
85
|
+
writeDateText(formatChipDate(d));
|
|
86
|
+
setTimeOpen(false);
|
|
87
|
+
if (dayOnly) {
|
|
88
|
+
onRequestClose("pick");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (isDesktopNow(views.desktopQuery))
|
|
92
|
+
dateRef.current?.focus({ preventScroll: true });
|
|
93
|
+
};
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (seed == null && !focusDate)
|
|
96
|
+
return;
|
|
97
|
+
const box = dateRef.current;
|
|
98
|
+
box?.focus({ preventScroll: true });
|
|
99
|
+
if (seed != null)
|
|
100
|
+
box?.setSelectionRange(seed.length, seed.length);
|
|
101
|
+
}, []);
|
|
42
102
|
const applyDateText = () => {
|
|
43
|
-
const base =
|
|
44
|
-
const typed = parseDateText(
|
|
103
|
+
const base = dayRef.current ?? valid ?? new Date();
|
|
104
|
+
const typed = parseDateText(dateTextRef.current, base.getFullYear());
|
|
45
105
|
if (typed) {
|
|
106
|
+
dayRef.current = typed;
|
|
46
107
|
setDay(typed);
|
|
47
108
|
setMonth(typed);
|
|
48
|
-
|
|
109
|
+
writeDateText(formatChipDate(typed));
|
|
49
110
|
return typed;
|
|
50
111
|
}
|
|
51
|
-
|
|
112
|
+
writeDateText(formatChipDate(base));
|
|
52
113
|
return undefined;
|
|
53
114
|
};
|
|
54
|
-
const resolveClose = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
115
|
+
const resolveClose = (reason) => {
|
|
116
|
+
if (reason === "escape")
|
|
117
|
+
return { kind: "cancel" };
|
|
118
|
+
if (clearedRef.current)
|
|
119
|
+
return valid ? { kind: "commit", payload: "" } : { kind: "noop" };
|
|
120
|
+
const year = (dayRef.current ?? valid ?? new Date()).getFullYear();
|
|
121
|
+
const typed = parseDateText(dateTextRef.current, year);
|
|
122
|
+
const d = typed ?? dayRef.current ?? valid;
|
|
123
|
+
if (dayOnly) {
|
|
124
|
+
const changed = d != null && (valid ? toYmd(d) !== toYmd(valid) : touchedRef.current);
|
|
125
|
+
return changed && d ? { kind: "commit", payload: toYmd(d) } : { kind: "noop" };
|
|
126
|
+
}
|
|
127
|
+
const time = normalizeTime(timeTextRef.current) ?? (timeOptional ? null : initialTime);
|
|
58
128
|
const timePart = timeOptional ? time : (time ?? initialTime);
|
|
59
129
|
const dirty = d != null &&
|
|
60
130
|
(valid ? toYmd(d) !== toYmd(valid) || (timePart ?? "") !== initialTime : touchedRef.current);
|
|
@@ -70,9 +140,20 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
70
140
|
if (timeOpen)
|
|
71
141
|
activeTimeRef.current?.scrollIntoView({ block: "center" });
|
|
72
142
|
}, [timeOpen]);
|
|
73
|
-
|
|
143
|
+
const onTabOut = (event) => {
|
|
144
|
+
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
|
|
145
|
+
return;
|
|
146
|
+
const { first, last } = tabEnds(event.currentTarget);
|
|
147
|
+
const leaving = event.shiftKey ? event.target === first : event.target === last;
|
|
148
|
+
if (!leaving)
|
|
149
|
+
return;
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
event.stopPropagation();
|
|
152
|
+
onRequestClose(event.shiftKey ? "shift-tab" : "tab");
|
|
153
|
+
};
|
|
154
|
+
return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, children: [_jsxs("div", { className: "flex items-center gap-1.5 border-b border-(color:--vk-border) p-2", children: [_jsxs("div", { className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", children: [_jsx(DateGlyph, { className: "h-3.5 w-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: dateRef, type: "text", value: dateVal, onChange: (e) => {
|
|
74
155
|
touchedRef.current = true;
|
|
75
|
-
|
|
156
|
+
writeDateText(e.target.value);
|
|
76
157
|
}, onBlur: applyDateText, onFocus: () => setTimeOpen(false), placeholder: words({ key: "date.placeholder" }), "aria-label": words({ key: "date.label" }), onClick: (e) => e.stopPropagation(), onKeyDown: (e) => {
|
|
77
158
|
e.stopPropagation();
|
|
78
159
|
if (e.key === "Enter") {
|
|
@@ -82,19 +163,22 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
82
163
|
else if (e.key === "Escape") {
|
|
83
164
|
onRequestClose("escape");
|
|
84
165
|
}
|
|
85
|
-
}, className: "w-0 min-w-0 flex-1 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), _jsxs("div", { className: "relative shrink-0", children: [_jsxs("div", { className: "flex h-8 cursor-text items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", onClick: (e) => {
|
|
166
|
+
}, className: "w-0 min-w-0 flex-1 select-text bg-transparent text-sm tabular-nums text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)" })] }), !dayOnly && (_jsxs("div", { className: "relative shrink-0", children: [_jsxs("div", { className: "flex h-8 cursor-text items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", onClick: (e) => {
|
|
86
167
|
e.stopPropagation();
|
|
87
168
|
setTimeOpen(true);
|
|
88
169
|
timeRef.current?.focus();
|
|
89
|
-
}, children: [_jsx(TimeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }), _jsx(
|
|
170
|
+
}, children: [_jsx(TimeGlyph, { className: "h-3.5 w-3.5 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: timeRef, type: "text", inputMode: "numeric", value: timeVal, onChange: (e) => {
|
|
90
171
|
touchedRef.current = true;
|
|
91
|
-
|
|
172
|
+
writeTime(e.target.value);
|
|
92
173
|
}, onFocus: () => setTimeOpen(true), placeholder: words({ key: "time.placeholder" }), "aria-label": words({ key: "time.label" }), onKeyDown: (e) => {
|
|
93
174
|
e.stopPropagation();
|
|
94
175
|
if (e.key === "Enter") {
|
|
95
176
|
e.preventDefault();
|
|
96
177
|
onRequestClose("enter");
|
|
97
178
|
}
|
|
179
|
+
else if (e.key === "Tab") {
|
|
180
|
+
setTimeOpen(false);
|
|
181
|
+
}
|
|
98
182
|
else if (e.key === "Escape") {
|
|
99
183
|
if (timeOpen)
|
|
100
184
|
setTimeOpen(false);
|
|
@@ -106,17 +190,21 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
106
190
|
return (_jsx("button", { ref: active ? activeTimeRef : undefined, type: "button", onClick: (e) => {
|
|
107
191
|
e.stopPropagation();
|
|
108
192
|
touchedRef.current = true;
|
|
109
|
-
|
|
193
|
+
writeTime(t);
|
|
110
194
|
setTimeOpen(false);
|
|
111
195
|
timeRef.current?.focus();
|
|
112
196
|
}, className: cx("w-full px-3 py-1.5 text-left text-sm tabular-nums hover:bg-(color:--vk-hovered)", active ? "bg-(color:--vk-neutral) font-medium text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: t }, t));
|
|
113
|
-
}) }))] })] }), _jsx(
|
|
197
|
+
}) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: QUICK_DAYS.map((quick) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
chooseDay(quickDay(quick.offset));
|
|
200
|
+
}, className: "h-7 rounded-md bg-(color:--vk-neutral) px-2 text-xs text-(color:--vk-fg-subtle) hover:bg-(color:--vk-neutral-hovered) hover:text-(color:--vk-fg)", children: words({ key: quick.key }) }, quick.key))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
|
|
114
201
|
const d = picked ? fromDayKey(picked) : null;
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
202
|
+
if (d)
|
|
203
|
+
chooseDay(d);
|
|
204
|
+
else if (dayOnly && dayRef.current)
|
|
205
|
+
chooseDay(dayRef.current);
|
|
206
|
+
}, month: month ? toDayKey(month).slice(0, 7) : undefined, onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { className: "border-t border-(color:--vk-border) py-1", children: _jsx(List, { children: _jsx(Row, { size: "compact", tone: "muted", label: words({ key: "date.clear" }), onClick: () => {
|
|
207
|
+
clearedRef.current = true;
|
|
208
|
+
onRequestClose("pick");
|
|
209
|
+
} }) }) }))] }));
|
|
122
210
|
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type CSSProperties, type MouseEvent as ReactMouseEvent, type ReactNode } from "react";
|
|
2
|
+
import type { ViewsAlign, ViewsAnchor, ViewsSheetProps, ViewsSide } from "../provider/components.js";
|
|
3
|
+
import type { EditSession } from "./edit-session.js";
|
|
4
|
+
/**
|
|
5
|
+
* THE EDITOR PANEL — where an editor opens, for every surface: the app's popover on a desktop,
|
|
6
|
+
* the app's sheet on a phone, and nothing at all for a type-in editor that stays where its value
|
|
7
|
+
* stands. The editor inside never reads which.
|
|
8
|
+
*
|
|
9
|
+
* It owns what each surface's dismissals MEAN, so no host decides them: on a desktop the popover's
|
|
10
|
+
* Escape discards (unless it comes from an inner level the editor marked, `EDITOR_INNER_ESCAPE`,
|
|
11
|
+
* which the editor closes itself), its outside press is the editor's own rule, and a focus leaving it
|
|
12
|
+
* closes as a blur; on a phone every way a sheet
|
|
13
|
+
* goes away (a swipe, its backdrop, Escape, the bar's ✕) discards, and the bar's ✓ closes as done.
|
|
14
|
+
* A refusal the host gave stays on screen under the editor, in the popover and the sheet; in
|
|
15
|
+
* place, the host's own box draws it.
|
|
16
|
+
*
|
|
17
|
+
* The surface is chosen ONCE, when the session opens: a window crossing the desktop width
|
|
18
|
+
* mid-edit keeps the panel it opened in until the session ends.
|
|
19
|
+
*/
|
|
20
|
+
export type EditorPanelProps = {
|
|
21
|
+
/** The session the host opened: its `open`, its `close` and its `refusal`. Either mode. */
|
|
22
|
+
session: EditSession;
|
|
23
|
+
/** The field's name: the sheet's title. */
|
|
24
|
+
title: ReactNode;
|
|
25
|
+
/** What the popover opens on, on the desktop. */
|
|
26
|
+
anchor: ViewsAnchor;
|
|
27
|
+
/** A type-in editor: on the desktop its children are drawn where they stand, with no popover. Default false. */
|
|
28
|
+
inPlace?: boolean;
|
|
29
|
+
/** With `inPlace`: on the phone, open the type-in editor in the sheet instead of where it stands.
|
|
30
|
+
* Default false. A picker always opens the sheet on the phone, and ignores this. */
|
|
31
|
+
sheetOnPhone?: boolean;
|
|
32
|
+
/** The sheet's snap hint. Default "auto". */
|
|
33
|
+
snap?: ViewsSheetProps["snap"];
|
|
34
|
+
/** Handed to the popover as they are. */
|
|
35
|
+
side?: ViewsSide;
|
|
36
|
+
align?: ViewsAlign;
|
|
37
|
+
sideOffset?: number;
|
|
38
|
+
alignOffset?: number;
|
|
39
|
+
initialFocus?: boolean;
|
|
40
|
+
chrome?: "panel" | "menu";
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: CSSProperties;
|
|
43
|
+
/** Set on the popover's panel, over `{ "data-slot": "vk-editor-panel" }`. */
|
|
44
|
+
panelData?: Readonly<Record<`data-${string}`, string>>;
|
|
45
|
+
/** A click inside the popover or the sheet. The sheet keeps every press to itself after this; the
|
|
46
|
+
* popover leaves that to the host (a grid host stops it here). */
|
|
47
|
+
onPanelClick?: (event: ReactMouseEvent<HTMLDivElement>) => void;
|
|
48
|
+
/** The editor, or a function of the surface the panel chose, for a type-in host that draws
|
|
49
|
+
* differently in place (its own refusal, say) than in the sheet. */
|
|
50
|
+
children: ReactNode | ((surface: EditorSurface) => ReactNode);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* The mark an editor puts on an inner level of its own (a list it opened from its boxes) while
|
|
54
|
+
* Escape there means "close that level", not "throw the edit away". An app's popover may hear
|
|
55
|
+
* Escape before the editor does (on the document, in the capture phase), so the panel asks: an
|
|
56
|
+
* Escape from inside the mark is left to the editor.
|
|
57
|
+
*/
|
|
58
|
+
export declare const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
59
|
+
/** Where the panel opened its editor: the app's popover, its sheet, or where the value stands. */
|
|
60
|
+
export type EditorSurface = "popover" | "sheet" | "in-place";
|
|
61
|
+
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, children, ...popover }: EditorPanelProps): ReactNode;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect, useState, } from "react";
|
|
4
|
+
import { useDesktop } from "../provider/desktop.js";
|
|
5
|
+
import { useViews } from "../provider/context.js";
|
|
6
|
+
export const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
7
|
+
function innerEscape(event) {
|
|
8
|
+
const target = event.target;
|
|
9
|
+
return target instanceof Element && target.closest(`[${EDITOR_INNER_ESCAPE}]`) !== null;
|
|
10
|
+
}
|
|
11
|
+
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, children, ...popover }) {
|
|
12
|
+
const views = useViews();
|
|
13
|
+
const { Popover, Sheet, Button } = views.components;
|
|
14
|
+
const Discard = views.icons.close;
|
|
15
|
+
const Save = views.icons.check;
|
|
16
|
+
const desktop = useDesktop();
|
|
17
|
+
const [surface] = useState(() => desktop ? (inPlace ? "in-place" : "popover") : inPlace && !sheetOnPhone ? "in-place" : "sheet");
|
|
18
|
+
const { open, close, refusal } = session;
|
|
19
|
+
const editor = typeof children === "function" ? children(surface) : children;
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
if (surface !== "in-place")
|
|
22
|
+
return;
|
|
23
|
+
const box = anchor instanceof HTMLElement ? anchor : anchor && "current" in anchor ? anchor.current : null;
|
|
24
|
+
box?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
25
|
+
}, []);
|
|
26
|
+
if (surface === "in-place")
|
|
27
|
+
return editor;
|
|
28
|
+
const reason = refusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: "px-2 pb-2 text-xs text-(color:--vk-danger)", children: refusal })) : null;
|
|
29
|
+
if (surface === "popover") {
|
|
30
|
+
return (_jsxs(Popover, { ...popover, open: open, onOpenChange: (next, details) => {
|
|
31
|
+
if (next || details?.reason === "outside-press")
|
|
32
|
+
return;
|
|
33
|
+
if (details?.reason === "focus-out")
|
|
34
|
+
close("blur");
|
|
35
|
+
else
|
|
36
|
+
close(details?.reason === "escape-key" ? "escape" : "outside");
|
|
37
|
+
}, anchor: anchor, onEscape: (event) => {
|
|
38
|
+
if (innerEscape(event))
|
|
39
|
+
return false;
|
|
40
|
+
close("escape");
|
|
41
|
+
}, onOutsidePress: () => {
|
|
42
|
+
if (open)
|
|
43
|
+
close("outside");
|
|
44
|
+
}, panelData: { "data-slot": "vk-editor-panel", ...panelData }, children: [editor, reason] }));
|
|
45
|
+
}
|
|
46
|
+
const keep = (event) => event.stopPropagation();
|
|
47
|
+
return (_jsx("span", { className: "contents", onClick: (event) => {
|
|
48
|
+
popover.onPanelClick?.(event);
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
}, onDoubleClick: keep, onContextMenu: keep, children: _jsx(Sheet, { open: open, onOpenChange: (next) => {
|
|
51
|
+
if (!next)
|
|
52
|
+
close("escape");
|
|
53
|
+
}, title: title, snap: snap, children: _jsxs("div", { "data-slot": "vk-editor-panel", children: [_jsxs("div", { "data-slot": "vk-editor-bar", className: "flex items-center justify-between px-2 pb-1", children: [_jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.discard" }), onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": views.messages({ key: "views.editors.save" }), onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] }), editor, reason] }) }) }));
|
|
54
|
+
}
|
|
@@ -18,5 +18,8 @@ export declare const LocationEditor: import("react").ForwardRefExoticComponent<{
|
|
|
18
18
|
initial: LocationValue | null;
|
|
19
19
|
allowEmpty?: boolean;
|
|
20
20
|
conventions?: FieldConventions;
|
|
21
|
+
/** How each part's box is drawn: `bare` for a popover's compact rows, `field` where the boxes stand on their
|
|
22
|
+
* own (a phone's sheet), each in the app's field frame. Default `bare`. */
|
|
23
|
+
chrome?: "bare" | "field";
|
|
21
24
|
onRequestClose: (reason: CloseReason) => void;
|
|
22
25
|
} & import("react").RefAttributes<LocationEditorHandle>>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
3
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
4
4
|
import { COUNTRY_CODES, countryName, LOCATION_PARTS, placeFormat, sameStoredValue, } from "@viewkitjs/fields";
|
|
5
5
|
import { loadRegions, regionLabel } from "@viewkitjs/fields/places";
|
|
6
6
|
import { placeWordKey } from "../contract.js";
|
|
7
7
|
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { EDITOR_INNER_ESCAPE } from "./EditorPanel.js";
|
|
8
9
|
const GENERIC = ["line1", "line2", "postalCode", "city", "region"];
|
|
9
10
|
function folded(text) {
|
|
10
11
|
return text.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
@@ -18,20 +19,26 @@ function draftOf(initial) {
|
|
|
18
19
|
}
|
|
19
20
|
return draft;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
function withFilled(kept, draft) {
|
|
23
|
+
const filled = GENERIC.filter((part) => !kept.has(part) && draft[part]?.trim());
|
|
24
|
+
return filled.length === 0 ? kept : new Set([...kept, ...filled]);
|
|
25
|
+
}
|
|
26
|
+
export const LocationEditor = forwardRef(function LocationEditor({ field, initial, allowEmpty = false, conventions, chrome = "bare", onRequestClose }, ref) {
|
|
22
27
|
const views = useViews();
|
|
23
28
|
const locale = (conventions ?? views.conventions).locale;
|
|
24
29
|
const say = (message) => views.messages(message);
|
|
25
30
|
const { List, RowContent } = views.atoms;
|
|
26
|
-
const { Command } = views.components;
|
|
31
|
+
const { Command, Input } = views.components;
|
|
27
32
|
const boxRef = useRef(null);
|
|
28
33
|
const parts = field.parts ?? LOCATION_PARTS;
|
|
29
34
|
const takesCountry = parts.includes("countryCode");
|
|
30
35
|
const [draft, setDraftState] = useState(() => draftOf(initial));
|
|
31
36
|
const draftRef = useRef(draft);
|
|
37
|
+
const [keptShown, setKeptShown] = useState(() => withFilled(new Set(), draft));
|
|
32
38
|
const setDraft = (next) => {
|
|
33
39
|
draftRef.current = next;
|
|
34
40
|
setDraftState(next);
|
|
41
|
+
setKeptShown((kept) => withFilled(kept, next));
|
|
35
42
|
};
|
|
36
43
|
const country = draft.countryCode?.trim() || null;
|
|
37
44
|
const [choosingCountry, setChoosingCountry] = useState(takesCountry && !country);
|
|
@@ -52,7 +59,6 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
52
59
|
};
|
|
53
60
|
}, [wantsRegions, country]);
|
|
54
61
|
const regionList = regions && regions.country === country && regions.list.length > 0 ? regions.list : null;
|
|
55
|
-
const keptShown = useRef(new Set());
|
|
56
62
|
const lastFocused = useRef(null);
|
|
57
63
|
const rows = useMemo(() => {
|
|
58
64
|
const laidOut = new Set();
|
|
@@ -67,15 +73,13 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
67
73
|
const shown = (part) => {
|
|
68
74
|
if (field.parts)
|
|
69
75
|
return parts.includes(part);
|
|
70
|
-
|
|
71
|
-
keptShown.current.add(part);
|
|
72
|
-
return keptShown.current.has(part);
|
|
76
|
+
return keptShown.has(part);
|
|
73
77
|
};
|
|
74
78
|
for (const part of GENERIC)
|
|
75
79
|
if (!laidOut.has(part) && shown(part))
|
|
76
80
|
lines.push([part]);
|
|
77
81
|
return lines;
|
|
78
|
-
}, [format, parts, field.parts,
|
|
82
|
+
}, [format, parts, field.parts, keptShown]);
|
|
79
83
|
const countries = useMemo(() => COUNTRY_CODES.map((code) => ({ code, name: countryName(code, locale) })).sort((a, b) => a.name.localeCompare(b.name, locale)), [locale]);
|
|
80
84
|
const resolveClose = (reason) => {
|
|
81
85
|
if (reason === "escape")
|
|
@@ -102,8 +106,9 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
102
106
|
const last = lastFocused.current
|
|
103
107
|
? box.querySelector(`[data-place-part="${lastFocused.current}"]`)
|
|
104
108
|
: null;
|
|
105
|
-
(last ?? box.querySelector("[data-place-focus]"))?.focus();
|
|
109
|
+
(last ?? box.querySelector("[data-place-focus]"))?.focus({ preventScroll: true });
|
|
106
110
|
}, [choosingCountry, choosingRegion, regionList]);
|
|
111
|
+
const focusSearch = useCallback((el) => el?.focus({ preventScroll: true }), []);
|
|
107
112
|
const pickCountry = (code) => {
|
|
108
113
|
const current = draftRef.current;
|
|
109
114
|
const next = { ...current, countryCode: code };
|
|
@@ -178,9 +183,15 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
178
183
|
? { "aria-required": true, "data-required": "" }
|
|
179
184
|
: { "data-required": "" }
|
|
180
185
|
: {};
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
186
|
+
const framed = chrome === "field";
|
|
187
|
+
const input = framed
|
|
188
|
+
? "w-24 min-w-0 flex-1 select-text"
|
|
189
|
+
: "h-7 w-24 min-w-0 flex-1 select-text bg-transparent text-(length:--vk-text) text-(color:--vk-fg) outline-hidden";
|
|
190
|
+
const button = framed
|
|
191
|
+
? "h-9 w-24 min-w-0 flex-1 cursor-pointer truncate rounded-md border border-(color:--vk-border) bg-transparent px-3 text-left text-(length:--vk-text) text-(color:--vk-fg) outline-hidden"
|
|
192
|
+
: `${input} cursor-pointer truncate text-left`;
|
|
193
|
+
const line = (box) => (framed ? _jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: box }) : box);
|
|
194
|
+
const search = (value, onChange, placeholder) => (_jsx(Command.Input, { ref: focusSearch, value: value, onValueChange: onChange, placeholder: placeholder, className: "h-9 text-[13px]", onKeyDown: (e) => {
|
|
184
195
|
if (e.key === "Escape") {
|
|
185
196
|
e.stopPropagation();
|
|
186
197
|
if (choosingRegion)
|
|
@@ -213,16 +224,12 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
|
|
|
213
224
|
body = (_jsxs(Command.Root, { shouldFilter: false, loop: true, label: wordOf("region"), children: [search(regionQuery, setRegionQuery, say({ key: "views.editors.place-region-search" })), list(shown.map(({ region, label }) => (_jsx(Command.Item, { value: region.code ?? region.name, onSelect: () => pickRegion(region), chosen: label === draft.region, children: _jsx(RowContent, { size: "compact", label: label, chosen: label === draft.region, chosenTint: false }) }, region.code ?? region.name))))] }));
|
|
214
225
|
}
|
|
215
226
|
else {
|
|
216
|
-
|
|
217
|
-
const focus = () => {
|
|
218
|
-
|
|
219
|
-
return {};
|
|
220
|
-
focusSet = true;
|
|
221
|
-
return { "data-place-focus": "" };
|
|
222
|
-
};
|
|
223
|
-
body = (_jsxs(_Fragment, { children: [takesCountry && country && (_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx("input", { "data-place-control": "", ...focus(), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), className: input }, part))) }, row.join(" "))))] }));
|
|
227
|
+
const focusPart = rows[0]?.[0];
|
|
228
|
+
const focus = (part) => (part === focusPart ? { "data-place-focus": "" } : {});
|
|
229
|
+
body = (_jsxs(_Fragment, { children: [takesCountry && country && line(_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(part), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx(Input, { "data-place-control": "", ...focus(part), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }, part))) }, row.join(" "))))] }));
|
|
224
230
|
}
|
|
225
|
-
|
|
231
|
+
const inner = (choosingRegion && regionList !== null) || (choosingCountry && country !== null);
|
|
232
|
+
return (_jsx("div", { ref: boxRef, ...(inner ? { [EDITOR_INNER_ESCAPE]: "" } : {}), onBlur: blur, onMouseDown: (e) => {
|
|
226
233
|
if (!(e.target instanceof HTMLInputElement))
|
|
227
234
|
e.preventDefault();
|
|
228
235
|
}, className: "flex w-full min-w-0 flex-col gap-1.5", children: body }));
|
|
@@ -18,5 +18,8 @@ export declare const NameEditor: import("react").ForwardRefExoticComponent<{
|
|
|
18
18
|
seed?: string;
|
|
19
19
|
allowEmpty?: boolean;
|
|
20
20
|
conventions?: FieldConventions;
|
|
21
|
+
/** How the boxes are drawn: `bare` in a cell or a popover, `field` where they stand on their own (a phone's
|
|
22
|
+
* sheet), each in the app's field frame. Default `bare`. */
|
|
23
|
+
chrome?: "bare" | "field";
|
|
21
24
|
onRequestClose: (reason: CloseReason) => void;
|
|
22
25
|
} & import("react").RefAttributes<NameEditorHandle>>;
|
|
@@ -12,11 +12,13 @@ const LABELS = {
|
|
|
12
12
|
function fromParts(given, family) {
|
|
13
13
|
return [given.trim(), family.trim()].filter(Boolean).join(" ");
|
|
14
14
|
}
|
|
15
|
-
export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowEmpty = false, onRequestClose }, ref) {
|
|
15
|
+
export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowEmpty = false, chrome = "bare", onRequestClose }, ref) {
|
|
16
16
|
const views = useViews();
|
|
17
|
+
const { Input } = views.components;
|
|
17
18
|
const boxRef = useRef(null);
|
|
19
|
+
const givenRef = useRef(null);
|
|
18
20
|
const refs = {
|
|
19
|
-
given:
|
|
21
|
+
given: givenRef,
|
|
20
22
|
family: useRef(null),
|
|
21
23
|
full: useRef(null),
|
|
22
24
|
};
|
|
@@ -30,10 +32,10 @@ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowE
|
|
|
30
32
|
const [partsEdited, setPartsEdited] = useState(seed !== undefined);
|
|
31
33
|
const full = ownFull || !partsEdited ? typedFull : fromParts(given, family);
|
|
32
34
|
useEffect(() => {
|
|
33
|
-
const el =
|
|
35
|
+
const el = givenRef.current;
|
|
34
36
|
if (!el)
|
|
35
37
|
return;
|
|
36
|
-
el.focus();
|
|
38
|
+
el.focus({ preventScroll: true });
|
|
37
39
|
el.setSelectionRange(el.value.length, el.value.length);
|
|
38
40
|
}, []);
|
|
39
41
|
const resolveClose = (reason) => {
|
|
@@ -70,11 +72,17 @@ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowE
|
|
|
70
72
|
if (!boxRef.current?.contains(e.relatedTarget))
|
|
71
73
|
onRequestClose("blur");
|
|
72
74
|
};
|
|
73
|
-
const input =
|
|
75
|
+
const input = chrome === "field"
|
|
76
|
+
? "w-28 min-w-0 flex-1 select-text"
|
|
77
|
+
: "h-full w-28 min-w-0 flex-1 select-text bg-transparent text-(length:--vk-text) text-(color:--vk-fg) outline-hidden";
|
|
74
78
|
const box = (which, value, onChange) => {
|
|
75
79
|
const label = views.messages({ key: LABELS[which] });
|
|
76
|
-
return (_jsx(
|
|
80
|
+
return (_jsx(Input, { ref: refs[which], value: value, "aria-label": label, placeholder: label, onChange: (e) => onChange(e.target.value), onKeyDown: keys(which), onBlur: blur, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }));
|
|
77
81
|
};
|
|
82
|
+
const fullBox = box("full", full, (next) => {
|
|
83
|
+
setOwnFull(true);
|
|
84
|
+
setTypedFull(next);
|
|
85
|
+
});
|
|
78
86
|
return (_jsxs("span", { ref: boxRef, onMouseDown: (e) => {
|
|
79
87
|
if (!(e.target instanceof HTMLInputElement))
|
|
80
88
|
e.preventDefault();
|
|
@@ -84,8 +92,5 @@ export const NameEditor = forwardRef(function NameEditor({ initial, seed, allowE
|
|
|
84
92
|
}), box("family", family, (next) => {
|
|
85
93
|
setPartsEdited(true);
|
|
86
94
|
setFamily(next);
|
|
87
|
-
})] }),
|
|
88
|
-
setOwnFull(true);
|
|
89
|
-
setTypedFull(next);
|
|
90
|
-
})] }));
|
|
95
|
+
})] }), chrome === "field" ? (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: fullBox })) : (fullBox)] }));
|
|
91
96
|
});
|
|
@@ -36,6 +36,9 @@ export declare const NumberEditor: import("react").ForwardRefExoticComponent<{
|
|
|
36
36
|
unit?: string;
|
|
37
37
|
/** Selectable units — presence makes the chip a picker. */
|
|
38
38
|
unitOptions?: string[];
|
|
39
|
+
/** The currency's code where the field fixes one (`numberEditCode`): drawn beside the amount
|
|
40
|
+
* as a unit is, and never part of the commit. Ignored when `unit` is given. */
|
|
41
|
+
code?: string;
|
|
39
42
|
/** Rounding + initial formatting precision — in the STORED unit. An
|
|
40
43
|
* integer field passes 0 (spec §8.2). */
|
|
41
44
|
decimals?: number;
|