viewkitjs 0.26.0 → 0.28.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 +95 -0
- package/MIGRATION.md +122 -7
- package/package.json +1 -1
- package/views/dist/cells/cell-format.d.ts +3 -1
- package/views/dist/cells/cell-format.js +2 -2
- package/views/dist/cells/use-cell-format.d.ts +8 -1
- package/views/dist/cells/use-cell-format.js +13 -2
- package/views/dist/contract.d.ts +240 -3
- package/views/dist/contract.js +238 -0
- package/views/dist/controls/alert/alert.d.ts +46 -0
- package/views/dist/controls/alert/alert.js +11 -0
- package/views/dist/controls/alert/looks.d.ts +4 -0
- package/views/dist/controls/alert/looks.js +19 -0
- package/views/dist/controls/alert/tokens.d.ts +92 -0
- package/views/dist/controls/alert/tokens.js +25 -0
- package/views/dist/controls/alert-dialog/alert-dialog.d.ts +50 -0
- package/views/dist/controls/alert-dialog/alert-dialog.js +67 -0
- package/views/dist/controls/alert-dialog/confirm.d.ts +13 -0
- package/views/dist/controls/alert-dialog/confirm.js +11 -0
- package/views/dist/controls/alert-dialog/looks.d.ts +4 -0
- package/views/dist/controls/alert-dialog/looks.js +17 -0
- package/views/dist/controls/alert-dialog/tokens.d.ts +119 -0
- package/views/dist/controls/alert-dialog/tokens.js +32 -0
- package/views/dist/controls/alert-dialog.css +95 -0
- package/views/dist/controls/alert.css +51 -0
- package/views/dist/controls/collapsible/collapsible.d.ts +39 -0
- package/views/dist/controls/collapsible/collapsible.js +18 -0
- package/views/dist/controls/collapsible/looks.d.ts +4 -0
- package/views/dist/controls/collapsible/looks.js +5 -0
- package/views/dist/controls/collapsible/map-collapse.d.ts +2 -0
- package/views/dist/controls/collapsible/map-collapse.js +6 -0
- package/views/dist/controls/collapsible/tokens.d.ts +68 -0
- package/views/dist/controls/collapsible/tokens.js +19 -0
- package/views/dist/controls/collapsible.css +83 -0
- package/views/dist/controls/compound-editor/map-parts-body.js +2 -1
- package/views/dist/controls/compound-editor/name-parts.js +10 -2
- package/views/dist/controls/compound-editor/place-parts.js +5 -1
- package/views/dist/controls/compound-editor/place.d.ts +2 -1
- package/views/dist/controls/compound-editor/place.js +2 -0
- package/views/dist/controls/controls.d.ts +17 -0
- package/views/dist/controls/controls.js +17 -0
- package/views/dist/controls/date-editor/date-editor.d.ts +2 -1
- package/views/dist/controls/date-editor/map-calendar.js +3 -1
- package/views/dist/controls/filter-editor/filter-editor.d.ts +56 -0
- package/views/dist/controls/filter-editor/filter-editor.js +208 -0
- package/views/dist/controls/filter-editor/how.d.ts +23 -0
- package/views/dist/controls/filter-editor/how.js +13 -0
- package/views/dist/controls/filter-editor/map-filter-body.d.ts +18 -0
- package/views/dist/controls/filter-editor/map-filter-body.js +164 -0
- package/views/dist/controls/filter-editor/map-rules.d.ts +85 -0
- package/views/dist/controls/filter-editor/map-rules.js +273 -0
- package/views/dist/controls/filter-editor/parts.d.ts +46 -0
- package/views/dist/controls/filter-editor/parts.js +75 -0
- package/views/dist/controls/filter-editor/rules.d.ts +104 -0
- package/views/dist/controls/filter-editor/rules.js +148 -0
- package/views/dist/controls/filter-editor/tokens.d.ts +83 -0
- package/views/dist/controls/filter-editor/tokens.js +23 -0
- package/views/dist/controls/filter-editor/words.d.ts +59 -0
- package/views/dist/controls/filter-editor/words.js +40 -0
- package/views/dist/controls/filter-editor.css +124 -0
- package/views/dist/controls/group-editor/group-editor.d.ts +56 -0
- package/views/dist/controls/group-editor/group-editor.js +126 -0
- package/views/dist/controls/group-editor/map-group-body.d.ts +19 -0
- package/views/dist/controls/group-editor/map-group-body.js +106 -0
- package/views/dist/controls/group-editor/rules.d.ts +48 -0
- package/views/dist/controls/group-editor/rules.js +41 -0
- package/views/dist/controls/group-editor/tokens.d.ts +15 -0
- package/views/dist/controls/group-editor/tokens.js +6 -0
- package/views/dist/controls/group-editor/words.d.ts +39 -0
- package/views/dist/controls/group-editor/words.js +21 -0
- package/views/dist/controls/group-editor.css +20 -0
- package/views/dist/controls/index.d.ts +35 -1
- package/views/dist/controls/index.js +35 -1
- package/views/dist/controls/internal/editor-parts.d.ts +47 -0
- package/views/dist/controls/internal/editor-parts.js +48 -0
- package/views/dist/controls/internal/step-return.d.ts +9 -0
- package/views/dist/controls/internal/step-return.js +27 -0
- package/views/dist/controls/links-editor/links-editor.d.ts +80 -0
- package/views/dist/controls/links-editor/links-editor.js +329 -0
- package/views/dist/controls/links-editor/links.d.ts +62 -0
- package/views/dist/controls/links-editor/links.js +50 -0
- package/views/dist/controls/links-editor/map-links-body.d.ts +10 -0
- package/views/dist/controls/links-editor/map-links-body.js +74 -0
- package/views/dist/controls/links-editor/tokens.d.ts +71 -0
- package/views/dist/controls/links-editor/tokens.js +20 -0
- package/views/dist/controls/links-editor/words.d.ts +56 -0
- package/views/dist/controls/links-editor/words.js +33 -0
- package/views/dist/controls/links-editor.css +132 -0
- package/views/dist/controls/menu-list/menu-list.d.ts +17 -2
- package/views/dist/controls/menu-list/menu-list.js +25 -16
- package/views/dist/controls/modal/looks.d.ts +4 -0
- package/views/dist/controls/modal/looks.js +25 -0
- package/views/dist/controls/modal/modal.d.ts +69 -0
- package/views/dist/controls/modal/modal.js +62 -0
- package/views/dist/controls/modal/tokens.d.ts +192 -0
- package/views/dist/controls/modal/tokens.js +50 -0
- package/views/dist/controls/modal.css +130 -0
- package/views/dist/controls/notice/notice.d.ts +49 -0
- package/views/dist/controls/notice/notice.js +35 -0
- package/views/dist/controls/notice/tokens.d.ts +99 -0
- package/views/dist/controls/notice/tokens.js +27 -0
- package/views/dist/controls/notice.css +100 -0
- package/views/dist/controls/number-editor/format.d.ts +31 -0
- package/views/dist/controls/number-editor/format.js +79 -0
- package/views/dist/controls/number-editor/looks.d.ts +14 -0
- package/views/dist/controls/number-editor/looks.js +17 -0
- package/views/dist/controls/number-editor/map-number-body.d.ts +16 -0
- package/views/dist/controls/number-editor/map-number-body.js +57 -0
- package/views/dist/controls/number-editor/number-editor.d.ts +72 -0
- package/views/dist/controls/number-editor/number-editor.js +202 -0
- package/views/dist/controls/number-editor/tokens.d.ts +28 -0
- package/views/dist/controls/number-editor/tokens.js +9 -0
- package/views/dist/controls/number-editor/words.d.ts +23 -0
- package/views/dist/controls/number-editor/words.js +13 -0
- package/views/dist/controls/number-editor.css +37 -0
- package/views/dist/controls/number-field/number-field.js +57 -5
- package/views/dist/controls/pane/looks.d.ts +4 -0
- package/views/dist/controls/pane/looks.js +11 -0
- package/views/dist/controls/pane/pane.d.ts +63 -0
- package/views/dist/controls/pane/pane.js +98 -0
- package/views/dist/controls/pane/state.d.ts +14 -0
- package/views/dist/controls/pane/state.js +7 -0
- package/views/dist/controls/pane/tokens.d.ts +79 -0
- package/views/dist/controls/pane/tokens.js +22 -0
- package/views/dist/controls/pane.css +104 -0
- package/views/dist/controls/picker/rows.d.ts +4 -2
- package/views/dist/controls/picker/rows.js +4 -3
- package/views/dist/controls/radio/radio.d.ts +33 -0
- package/views/dist/controls/radio/radio.js +19 -0
- package/views/dist/controls/radio/tokens.d.ts +127 -0
- package/views/dist/controls/radio/tokens.js +34 -0
- package/views/dist/controls/radio.css +104 -0
- package/views/dist/controls/sort-editor/map-sort-body.d.ts +9 -0
- package/views/dist/controls/sort-editor/map-sort-body.js +81 -0
- package/views/dist/controls/sort-editor/rules.d.ts +48 -0
- package/views/dist/controls/sort-editor/rules.js +24 -0
- package/views/dist/controls/sort-editor/sort-editor.d.ts +58 -0
- package/views/dist/controls/sort-editor/sort-editor.js +180 -0
- package/views/dist/controls/sort-editor/tokens.d.ts +79 -0
- package/views/dist/controls/sort-editor/tokens.js +22 -0
- package/views/dist/controls/sort-editor/words.d.ts +48 -0
- package/views/dist/controls/sort-editor/words.js +25 -0
- package/views/dist/controls/sort-editor.css +96 -0
- package/views/dist/controls/text-editor/phone-number.d.ts +4 -0
- package/views/dist/controls/text-editor/phone-number.js +20 -0
- package/views/dist/controls/text-editor/text-editor.js +2 -19
- package/views/dist/controls/toast/toast.d.ts +75 -0
- package/views/dist/controls/toast/toast.js +99 -0
- package/views/dist/controls/toast/tokens.d.ts +100 -0
- package/views/dist/controls/toast/tokens.js +27 -0
- package/views/dist/controls/toast.css +93 -0
- package/views/dist/controls/tokens.js +30 -0
- package/views/dist/controls/values-editor/looks.d.ts +16 -0
- package/views/dist/controls/values-editor/looks.js +19 -0
- package/views/dist/controls/values-editor/map-values-body.d.ts +12 -0
- package/views/dist/controls/values-editor/map-values-body.js +71 -0
- package/views/dist/controls/values-editor/tokens.d.ts +132 -0
- package/views/dist/controls/values-editor/tokens.js +35 -0
- package/views/dist/controls/values-editor/values-editor.d.ts +62 -0
- package/views/dist/controls/values-editor/values-editor.js +441 -0
- package/views/dist/controls/values-editor/values.d.ts +71 -0
- package/views/dist/controls/values-editor/values.js +59 -0
- package/views/dist/controls/values-editor/words.d.ts +50 -0
- package/views/dist/controls/values-editor/words.js +29 -0
- package/views/dist/controls/values-editor.css +207 -0
- package/views/dist/controls/views-list/looks.d.ts +13 -0
- package/views/dist/controls/views-list/looks.js +12 -0
- package/views/dist/controls/views-list/map-views-list-body.d.ts +19 -0
- package/views/dist/controls/views-list/map-views-list-body.js +65 -0
- package/views/dist/controls/views-list/rules.d.ts +72 -0
- package/views/dist/controls/views-list/rules.js +4 -0
- package/views/dist/controls/views-list/tokens.d.ts +11 -0
- package/views/dist/controls/views-list/tokens.js +5 -0
- package/views/dist/controls/views-list/views-list.d.ts +44 -0
- package/views/dist/controls/views-list/views-list.js +57 -0
- package/views/dist/controls/views-list/words.d.ts +22 -0
- package/views/dist/controls/views-list/words.js +3 -0
- package/views/dist/controls/views-list.css +8 -0
- package/views/dist/display/date.js +2 -2
- package/views/dist/display/format.js +10 -2
- package/views/dist/display/options.d.ts +3 -1
- package/views/dist/display/use-display-options.d.ts +3 -0
- package/views/dist/display/use-display-options.js +10 -2
- package/views/dist/display/viewer.d.ts +1 -1
- package/views/dist/display/viewer.js +1 -1
- package/views/dist/editors/DateEditor.js +11 -9
- package/views/dist/editors/NumberEditor.js +3 -1
- package/views/dist/editors/relation-panel.js +7 -1
- package/views/dist/editors/relation-picker.d.ts +2 -1
- package/views/dist/editors/relation-picker.js +4 -3
- package/views/dist/editors/relation-source.d.ts +4 -1
- package/views/dist/editors/relation-source.js +5 -2
- package/views/dist/field-row/editors/RowNumberEditor.js +2 -2
- package/views/dist/fields/number-edit.d.ts +6 -0
- package/views/dist/fields/number-edit.js +8 -1
- package/views/dist/grid/chrome/GridCellEditors.js +3 -3
- package/views/dist/grid/chrome/GridColumnDateSection.d.ts +4 -3
- package/views/dist/grid/chrome/GridColumnDateSection.js +4 -4
- package/views/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/views/dist/grid/chrome/GridColumnMenu.js +6 -4
- package/views/dist/grid/chrome/GridDateEditor.d.ts +3 -1
- package/views/dist/grid/chrome/GridDateEditor.js +2 -1
- package/views/dist/grid/chrome/GridFooter.js +2 -2
- package/views/dist/grid/chrome/grid-column-menu-items.js +4 -2
- package/views/dist/grid/chrome/useGridBandFigures.js +2 -2
- package/views/dist/grid/chrome/useGridFittedWidths.d.ts +3 -0
- package/views/dist/grid/chrome/useGridFittedWidths.js +9 -3
- package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
- package/views/dist/grid/chrome/useGridKeyboard.js +5 -2
- package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -1
- package/views/dist/grid/core/commit-model.d.ts +7 -0
- package/views/dist/grid/core/commit-model.js +5 -1
- package/views/dist/grid/core/editing-controller.js +10 -2
- package/views/dist/grid/core/editing-model.js +3 -7
- package/views/dist/grid/core/undo-owner.d.ts +6 -0
- package/views/dist/grid/core/undo-owner.js +13 -0
- package/views/dist/grid/core/useGridEditing.d.ts +2 -0
- package/views/dist/grid/core/useGridEditing.js +4 -0
- package/views/dist/looks/index.d.ts +8 -0
- package/views/dist/looks/index.js +8 -0
- package/views/dist/looks/pieces.js +16 -0
- package/views/dist/panels/model.d.ts +6 -1
- package/views/dist/panels/react/customize-body.d.ts +4 -2
- package/views/dist/panels/react/customize-body.js +3 -3
- package/views/dist/panels/react/customize.js +4 -2
- package/views/dist/panels/react/filter/FilterEditor.js +2 -2
- package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +8 -2
- package/views/dist/panels/react/filter/PhoneFilterEditor.js +9 -6
- package/views/dist/panels/react/filter/filter-body.d.ts +8 -5
- package/views/dist/panels/react/filter/filter-body.js +17 -6
- package/views/dist/panels/react/filter/filter-part-body.d.ts +4 -1
- package/views/dist/panels/react/filter/filter-part-body.js +3 -1
- package/views/dist/panels/react/panel-sheet.d.ts +5 -1
- package/views/dist/panels/react/panel-sheet.js +6 -2
- package/views/dist/panels/react/panel-step.d.ts +12 -0
- package/views/dist/panels/react/panel-step.js +26 -0
- package/views/dist/panels/react/sort/SortEditor.d.ts +4 -0
- package/views/dist/panels/react/sort/SortEditor.js +5 -2
- package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -0
- package/views/dist/panels/react/toolbar/ReadyToolbar.js +84 -2
- package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +16 -0
- package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +49 -0
- package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +3 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.d.ts +4 -1
- package/views/dist/panels/react/toolbar/ToolbarFilters.js +36 -21
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +4 -1
- package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +2 -2
- package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
- package/views/dist/panels/react/toolbar/ToolbarSortPill.js +15 -6
- package/views/dist/panels/react/toolbar/panel-part.d.ts +5 -1
- package/views/dist/panels/react/toolbar/panel-part.js +2 -2
- package/views/dist/panels/react/toolbar/use-filter-add.d.ts +16 -0
- package/views/dist/panels/react/toolbar/use-filter-add.js +32 -0
- package/views/dist/panels/react.d.ts +1 -0
- package/views/dist/panels/react.js +1 -0
- package/views/dist/panels/settings/filter-groups.js +35 -1
- package/views/dist/panels/settings/group-buckets.js +1 -0
- package/views/dist/provider/ViewsProvider.d.ts +7 -1
- package/views/dist/provider/ViewsProvider.js +23 -3
- package/views/dist/provider/components.d.ts +34 -4
- package/views/dist/provider/moment.d.ts +6 -0
- package/views/dist/provider/moment.js +10 -0
- package/views/dist/styles.css +1276 -51
- package/views/dist/styles.unlayered.css +1277 -51
- package/views/docs/contract.md +23 -15
- package/views/docs/controls/alert-dialog.md +37 -0
- package/views/docs/controls/alert.md +30 -0
- package/views/docs/controls/collapsible.md +22 -0
- package/views/docs/controls/filter-editor.md +28 -0
- package/views/docs/controls/group-editor.md +11 -0
- package/views/docs/controls/links-editor.md +25 -0
- package/views/docs/controls/modal.md +55 -0
- package/views/docs/controls/notice.md +32 -0
- package/views/docs/controls/number-editor.md +12 -0
- package/views/docs/controls/pane.md +25 -0
- package/views/docs/controls/radio.md +39 -0
- package/views/docs/controls/sort-editor.md +27 -0
- package/views/docs/controls/toast.md +32 -0
- package/views/docs/controls/values-editor.md +40 -0
- package/views/docs/controls/views-list.md +8 -0
- package/views/docs/guides/cells.md +1 -1
- package/views/docs/guides/display.md +1 -1
- package/views/docs/guides/the-grid.md +1 -1
- package/views/docs/guides/the-provider.md +19 -0
- package/views/docs/reference/cells.md +2 -2
- package/views/docs/reference/controls.md +326 -8
- package/views/docs/reference/display.md +2 -2
- package/views/docs/reference/editors-relation.md +1 -1
- package/views/docs/reference/looks.md +20 -3
- package/views/docs/reference/panels-react.md +7 -6
- package/views/docs/reference/panels.md +1 -1
- package/views/docs/reference/react.md +8 -8
- package/views/docs/reference/views.md +1 -0
|
@@ -52,6 +52,8 @@ function numberFormat(locale, options) {
|
|
|
52
52
|
return format;
|
|
53
53
|
}
|
|
54
54
|
function viewerToday(context) {
|
|
55
|
+
if (!context.now)
|
|
56
|
+
return null;
|
|
55
57
|
const parts = dateFormat("en-US", {
|
|
56
58
|
timeZone: context.timeZone ?? DEFAULT_CONVENTIONS.timeZone,
|
|
57
59
|
year: "numeric",
|
|
@@ -85,7 +87,7 @@ function absoluteDay({ year, month, day }, style, today, context, time) {
|
|
|
85
87
|
? `${pad2(day)}/${pad2(month)}/${year}`
|
|
86
88
|
: style === "long"
|
|
87
89
|
? `${day} ${name("long")} ${year}`
|
|
88
|
-
: `${pad2(day)} ${name("short")}${year === today
|
|
90
|
+
: `${pad2(day)} ${name("short")}${year === today?.year ? "" : ` ${year}`}`;
|
|
89
91
|
return time ? `${date}, ${time}` : date;
|
|
90
92
|
}
|
|
91
93
|
function instantParts(instant, timeZone) {
|
|
@@ -176,7 +178,13 @@ export function formatDateValue(value, dateStyle, withTime, kind = "datetime", o
|
|
|
176
178
|
const { implementation, context } = presentation(opts);
|
|
177
179
|
const day = typeof value === "string" ? value : toDayKey(d);
|
|
178
180
|
let out;
|
|
179
|
-
if (style === "relative") {
|
|
181
|
+
if (style === "relative" && !context.now) {
|
|
182
|
+
out =
|
|
183
|
+
kind === "date"
|
|
184
|
+
? implementation.calendarDay({ day, style: "short", context })
|
|
185
|
+
: implementation.instant({ instant: d, style: "short", withTime: true, context });
|
|
186
|
+
}
|
|
187
|
+
else if (style === "relative") {
|
|
180
188
|
out =
|
|
181
189
|
kind === "date"
|
|
182
190
|
? implementation.relativeCalendarDay({ day, context })
|
|
@@ -52,7 +52,9 @@ export type FieldViewerContext = {
|
|
|
52
52
|
timeZone?: string;
|
|
53
53
|
/** The viewer's country, from the conventions: a phone of that country is written as at home. */
|
|
54
54
|
region?: string;
|
|
55
|
-
|
|
55
|
+
/** The moment relative dates count from: the provider's. Absent before the provider has one (`ViewsProvider`'s
|
|
56
|
+
* `now`, or its one read after mount): a date that needs it draws its full form. */
|
|
57
|
+
now?: Date;
|
|
56
58
|
/** Fields' own words (`time.ago`). Default: fields' English. */
|
|
57
59
|
fieldMessages?: FieldMessageResolver;
|
|
58
60
|
/** The views package's words (`views.display.*`). Default: the package's English. */
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { DisplayOptions } from "./options.js";
|
|
2
|
+
/** For a value that draws no date: its viewer carries no moment, so a minute's read of the clock doesn't redraw it. */
|
|
2
3
|
export declare function useDisplayOptions(opts: DisplayOptions | undefined): DisplayOptions;
|
|
4
|
+
/** For a date: its viewer counts from the provider's moment, and redraws when it moves. */
|
|
5
|
+
export declare function useDateDisplayOptions(opts: DisplayOptions | undefined): DisplayOptions;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { useViews } from "../provider/context.js";
|
|
4
|
+
import { useMoment } from "../provider/moment.js";
|
|
4
5
|
import { DEFAULT_FIELD_PRESENTATION } from "./format.js";
|
|
5
6
|
import { viewerFrom } from "./viewer.js";
|
|
6
|
-
|
|
7
|
+
function useDisplayOptionsAt(opts, now) {
|
|
7
8
|
const { conventions, messages, presentation } = useViews();
|
|
8
9
|
const appPresentation = useMemo(() => presentation?.(DEFAULT_FIELD_PRESENTATION), [presentation]);
|
|
10
|
+
const viewer = useMemo(() => viewerFrom(conventions, messages, now), [conventions, messages, now]);
|
|
9
11
|
return {
|
|
10
12
|
...opts,
|
|
11
13
|
presentation: opts?.presentation ?? appPresentation,
|
|
12
|
-
viewer: opts?.viewer ??
|
|
14
|
+
viewer: opts?.viewer ?? viewer,
|
|
13
15
|
};
|
|
14
16
|
}
|
|
17
|
+
export function useDisplayOptions(opts) {
|
|
18
|
+
return useDisplayOptionsAt(opts, null);
|
|
19
|
+
}
|
|
20
|
+
export function useDateDisplayOptions(opts) {
|
|
21
|
+
return useDisplayOptionsAt(opts, useMoment());
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FieldConventions } from "viewkitjs/fields";
|
|
2
2
|
import { type ViewsMessageResolver } from "../contract.js";
|
|
3
3
|
import type { FieldViewerContext } from "./options.js";
|
|
4
|
-
export declare function viewerFrom(conventions: FieldConventions, messages?: ViewsMessageResolver, now?: Date): FieldViewerContext;
|
|
4
|
+
export declare function viewerFrom(conventions: FieldConventions, messages?: ViewsMessageResolver, now?: Date | null): FieldViewerContext;
|
|
@@ -5,7 +5,7 @@ export function viewerFrom(conventions, messages = resolveViewsMessage, now = ne
|
|
|
5
5
|
language: conventions.language,
|
|
6
6
|
timeZone: conventions.timeZone,
|
|
7
7
|
...(conventions.region ? { region: conventions.region } : {}),
|
|
8
|
-
now,
|
|
8
|
+
...(now ? { now } : {}),
|
|
9
9
|
fieldMessages: conventions.messages,
|
|
10
10
|
messages,
|
|
11
11
|
};
|
|
@@ -6,6 +6,7 @@ import { fromDayKey, toDayKey } from "viewkitjs/fields/query";
|
|
|
6
6
|
import { cx } from "../internal/cx.js";
|
|
7
7
|
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
8
8
|
import { useViews } from "../provider/context.js";
|
|
9
|
+
import { useMoment } from "../provider/moment.js";
|
|
9
10
|
import { isDesktopNow } from "../provider/desktop.js";
|
|
10
11
|
import { usePickerForm } from "./picker-slot.js";
|
|
11
12
|
import { tabbable, tabEnds } from "./tab-ends.js";
|
|
@@ -16,11 +17,11 @@ const QUICK_DAYS = {
|
|
|
16
17
|
"next-monday": { key: "date.next-monday", offset: (weekday) => (8 - weekday) % 7 || 7 },
|
|
17
18
|
"in-a-week": { key: "date.in-a-week", offset: () => 7 },
|
|
18
19
|
};
|
|
19
|
-
function todayOf(timeZone) {
|
|
20
|
-
return fromDayKey(todayIn(timeZone));
|
|
20
|
+
function todayOf(timeZone, now) {
|
|
21
|
+
return fromDayKey(todayIn(timeZone, now));
|
|
21
22
|
}
|
|
22
|
-
function quickDay(offset, timeZone) {
|
|
23
|
-
const today = todayOf(timeZone);
|
|
23
|
+
function quickDay(offset, timeZone, now) {
|
|
24
|
+
const today = todayOf(timeZone, now);
|
|
24
25
|
return new Date(today.getFullYear(), today.getMonth(), today.getDate() + offset(today.getDay()));
|
|
25
26
|
}
|
|
26
27
|
const CALENDAR_START = "1900-01";
|
|
@@ -65,6 +66,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
65
66
|
const timeRef = useRef(null);
|
|
66
67
|
const dateRef = useRef(null);
|
|
67
68
|
const views = useViews();
|
|
69
|
+
const now = useMoment() ?? undefined;
|
|
68
70
|
const words = message ?? views.conventions.messages;
|
|
69
71
|
const { Calendar, Input, DateBody } = views.components;
|
|
70
72
|
const { List, Row } = views.atoms;
|
|
@@ -125,7 +127,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
125
127
|
}, []);
|
|
126
128
|
const applyDateText = () => {
|
|
127
129
|
const current = dayRef.current ?? valid;
|
|
128
|
-
const typed = parseDateText(dateTextRef.current, (current ?? todayOf(timeZone)).getFullYear());
|
|
130
|
+
const typed = parseDateText(dateTextRef.current, (current ?? todayOf(timeZone, now)).getFullYear());
|
|
129
131
|
if (typed) {
|
|
130
132
|
dayRef.current = typed;
|
|
131
133
|
setDay(typed);
|
|
@@ -141,7 +143,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
141
143
|
return { kind: "cancel" };
|
|
142
144
|
if (clearedRef.current)
|
|
143
145
|
return valid ? { kind: "commit", payload: "" } : { kind: "noop" };
|
|
144
|
-
const year = (dayRef.current ?? valid ?? todayOf(timeZone)).getFullYear();
|
|
146
|
+
const year = (dayRef.current ?? valid ?? todayOf(timeZone, now)).getFullYear();
|
|
145
147
|
const typed = parseDateText(dateTextRef.current, year);
|
|
146
148
|
const d = typed ?? dayRef.current ?? valid;
|
|
147
149
|
if (dayOnly) {
|
|
@@ -239,7 +241,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
239
241
|
}
|
|
240
242
|
onTabOut(event);
|
|
241
243
|
};
|
|
242
|
-
return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onPointerDownCapture: () => (enteredRef.current = false), onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose(enteredRef.current ? "enter" : "pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...quickPicks, "none"] : [...quickPicks], today: todayIn(timeZone), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
|
|
244
|
+
return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onPointerDownCapture: () => (enteredRef.current = false), onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose(enteredRef.current ? "enter" : "pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...quickPicks, "none"] : [...quickPicks], today: todayIn(timeZone, now), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
|
|
243
245
|
}
|
|
244
246
|
return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, onBlurCapture: onTabAway, 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) => {
|
|
245
247
|
touchedRef.current = true;
|
|
@@ -286,14 +288,14 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
286
288
|
}, className: cx(ELEMENT_RESET, "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));
|
|
287
289
|
}) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: quickPicks.map((pick) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
288
290
|
e.stopPropagation();
|
|
289
|
-
chooseDay(quickDay(QUICK_DAYS[pick].offset, timeZone));
|
|
291
|
+
chooseDay(quickDay(QUICK_DAYS[pick].offset, timeZone, now));
|
|
290
292
|
}, className: cx(ELEMENT_RESET, "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_DAYS[pick].key }) }, pick))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
|
|
291
293
|
const d = picked ? fromDayKey(picked) : null;
|
|
292
294
|
if (d)
|
|
293
295
|
chooseDay(d);
|
|
294
296
|
else if (dayOnly && dayRef.current)
|
|
295
297
|
chooseDay(dayRef.current);
|
|
296
|
-
}, month: toDayKey(month ?? todayOf(timeZone)).slice(0, 7), onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { ref: clearRef, 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: () => {
|
|
298
|
+
}, month: toDayKey(month ?? todayOf(timeZone, now)).slice(0, 7), onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { ref: clearRef, 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: () => {
|
|
297
299
|
clearedRef.current = true;
|
|
298
300
|
onRequestClose("pick");
|
|
299
301
|
} }) }) }))] }));
|
|
@@ -5,6 +5,7 @@ import { parseNumber, roundTo, } from "viewkitjs/fields";
|
|
|
5
5
|
import { durationUnitToMs, formatDurationInput, msToDurationUnit, parseDurationInput, } from "viewkitjs/fields/query";
|
|
6
6
|
import { cx } from "../internal/cx.js";
|
|
7
7
|
import { BodyFrame } from "./BodyFrame.js";
|
|
8
|
+
import { useBodyStep } from "./body-step.js";
|
|
8
9
|
import { numberBodyKind, numberChange, resolveNumberBody } from "./number-body.js";
|
|
9
10
|
import { openingNumberText, stepDelta, stepKey, steppedNumber, writeStep } from "./number-step.js";
|
|
10
11
|
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
@@ -20,6 +21,7 @@ export const NumberEditor = forwardRef(function NumberEditor({ boxClassName, ini
|
|
|
20
21
|
const { Popover, Input } = views.components;
|
|
21
22
|
const NumberBody = durationUnit ? undefined : views.components.NumberBody;
|
|
22
23
|
const { List, Row } = views.atoms;
|
|
24
|
+
const onStepChange = useBodyStep();
|
|
23
25
|
useEffect(() => {
|
|
24
26
|
const el = inputRef.current;
|
|
25
27
|
if (!el)
|
|
@@ -85,7 +87,7 @@ export const NumberEditor = forwardRef(function NumberEditor({ boxClassName, ini
|
|
|
85
87
|
setDraft(changed);
|
|
86
88
|
}, onDone: () => onRequestClose("enter"), check: check
|
|
87
89
|
? (value, next) => check(value == null || !Number.isFinite(value) ? value : round(value), next !== undefined && units?.includes(next) ? next : draftRef.current.unit)
|
|
88
|
-
: EVERY_VALUE_READS, decimals: decimals, ...(min !== undefined ? { min } : {}), ...(max !== undefined ? { max } : {}), locale: cv.locale, ...(cv.decimal ? { decimal: cv.decimal } : {}), empty: allowEmpty, align: align, ...(seed !== undefined ? { typed: seed } : {}), autoFocus: true, form: form }) }));
|
|
90
|
+
: EVERY_VALUE_READS, decimals: decimals, ...(min !== undefined ? { min } : {}), ...(max !== undefined ? { max } : {}), locale: cv.locale, ...(cv.decimal ? { decimal: cv.decimal } : {}), empty: allowEmpty, align: align, ...(seed !== undefined ? { typed: seed } : {}), autoFocus: true, form: form, ...(onStepChange && { onStepChange }) }) }));
|
|
89
91
|
}
|
|
90
92
|
return (_jsxs("span", { className: "flex h-full w-full min-w-0 items-center gap-1.5", children: [_jsx(Input, { ref: inputRef, defaultValue: seed ?? initialText, inputMode: durationUnit ? "text" : "decimal", onKeyDown: (e) => {
|
|
91
93
|
e.stopPropagation();
|
|
@@ -36,5 +36,11 @@ export function RelationPanel({ candidates, query, onQueryChange, searchRef, onS
|
|
|
36
36
|
: (value, search) => {
|
|
37
37
|
const label = rows.find((candidate) => candidate.id === value)?.label ?? labels?.get(value) ?? "";
|
|
38
38
|
return label.toLowerCase().includes(search.toLowerCase()) ? 1 : 0;
|
|
39
|
-
}, children: [_jsx(Command.Input, { ref: searchRef, placeholder: words({ key: "editor.search" }), className: "h-9 text-(length:--vk-input-text,13px)", value: query, onValueChange: onQueryChange, onKeyDown:
|
|
39
|
+
}, children: [_jsx(Command.Input, { ref: searchRef, placeholder: words({ key: "editor.search" }), className: "h-9 text-(length:--vk-input-text,13px)", value: query, onValueChange: onQueryChange, onKeyDown: (event) => {
|
|
40
|
+
if (remote && page.searching && event.key === "Enter") {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
onSearchKeyDown?.(event);
|
|
45
|
+
} }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [remote ? (status && (_jsx("div", { role: "status", className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: status }))) : (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [before?.({ glyphs, glyph }), shown.map((candidate) => (_jsx(Command.Item, { value: candidate.id, onSelect: () => onSelect(candidate), chosen: isChosen(candidate.id), children: _jsx(RowContent, { size: "compact", leading: glyph(candidate.icon ?? kindGlyph), leadingLane: glyphs, label: candidate.label, description: candidate.sublabel, trailing: candidate.badge ? (_jsx("span", { className: "ml-2 shrink-0 rounded-sm border border-(color:--vk-border) px-1.5 py-0.5 text-(length:--vk-caption-text,10px) font-medium uppercase tracking-wide text-(color:--vk-fg-subtle)", children: candidate.badge })) : undefined, chosen: isChosen(candidate.id), chosenTint: false }) }, candidate.id)))] }) }), paging && _jsx(EndOfListSentinel, { onReveal: page.loadMore }), moreStatus && (_jsx("div", { role: "status", className: "py-3 text-center text-xs text-(color:--vk-fg-subtle)", children: moreStatus }))] }), creates && creates.length > 0 && (_jsx("div", { className: "border-t border-(color:--vk-border)", children: creates.map((create, index) => (_jsx(Row, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: create.label(query.trim()), onClick: () => onCreate(create, query.trim()) }, index))) }))] }));
|
|
40
46
|
}
|
|
@@ -11,7 +11,8 @@ export type RelationHeld = {
|
|
|
11
11
|
};
|
|
12
12
|
/** What a relation's list hands the app's body, worked out once for its `Picker` and its `LinksBody`: the rows (held
|
|
13
13
|
* records first, while they match the query), the ids it handed out, a handed id's candidate, the page's states and
|
|
14
|
-
* the host's create rows as actions. ViewKit filters a static source and fetches a remote one.
|
|
14
|
+
* the host's create rows as actions. ViewKit filters a static source and fetches a remote one. While a remote list searches,
|
|
15
|
+
* the rows are the held records that match alone: no row of the last answer is handed, so none can be picked. */
|
|
15
16
|
export declare function useRelationRows({ candidates, query, held, kindGlyph, creates, onCreate, }: {
|
|
16
17
|
candidates: RelationSource;
|
|
17
18
|
query: string;
|
|
@@ -9,7 +9,8 @@ export function useRelationRows({ candidates, query, held, kindGlyph, creates, o
|
|
|
9
9
|
const Add = views.icons.add;
|
|
10
10
|
const remote = candidates.kind === "remote";
|
|
11
11
|
const page = useRemotePage(candidates, query);
|
|
12
|
-
const
|
|
12
|
+
const searching = remote && page.searching;
|
|
13
|
+
const rows = candidates.kind === "static" ? candidates.items.filter((candidate) => matches(candidate.label, query)) : searching ? [] : page.items;
|
|
13
14
|
const heldIds = new Set(held.map((record) => record.id));
|
|
14
15
|
const shownHeld = held.filter((record) => matches(record.label, query));
|
|
15
16
|
const byId = new Map();
|
|
@@ -34,9 +35,9 @@ export function useRelationRows({ candidates, query, held, kindGlyph, creates, o
|
|
|
34
35
|
items,
|
|
35
36
|
handed: new Set([...items.map((item) => item.value), ...heldIds]),
|
|
36
37
|
found: (id) => byId.get(id),
|
|
37
|
-
doing: !remote ? undefined :
|
|
38
|
+
doing: !remote ? undefined : searching ? "searching" : page.failed && page.items.length === 0 ? "failed" : undefined,
|
|
38
39
|
onRetry: remote && page.failed && page.items.length === 0 ? page.retry : undefined,
|
|
39
|
-
onMore: remote && !page.exhausted && page.items.length > 0 ? page.loadMore : undefined,
|
|
40
|
+
onMore: remote && !searching && !page.exhausted && page.items.length > 0 ? page.loadMore : undefined,
|
|
40
41
|
actions: creates?.map((create, index) => ({
|
|
41
42
|
key: `create-${index}`,
|
|
42
43
|
label: create.label(trimmed),
|
|
@@ -21,8 +21,11 @@ export type RemotePage = {
|
|
|
21
21
|
/** Every row of every page loaded for the current query, in order. Kept on
|
|
22
22
|
* screen while the next query's first page loads. */
|
|
23
23
|
items: RelationCandidate[];
|
|
24
|
-
/** The
|
|
24
|
+
/** The list on screen isn't the answer to the query typed: from the keystroke, through the debounce and the first
|
|
25
|
+
* page's request (VK-821). Its rows are the last query's meanwhile, so nothing may be taken from them. */
|
|
25
26
|
searching: boolean;
|
|
27
|
+
/** The query whose first page was last asked; null before any. Required: every page state carries it. */
|
|
28
|
+
asked: string | null;
|
|
26
29
|
/** A LATER page is in flight — the rows stay, a line appears under them. */
|
|
27
30
|
loadingMore: boolean;
|
|
28
31
|
/** The last request failed. A first page's failure clears the rows; a later
|
|
@@ -5,6 +5,7 @@ export const RELATION_SEARCH_DEBOUNCE_MS = 200;
|
|
|
5
5
|
export const RELATION_PAGE_SIZE = 20;
|
|
6
6
|
const EMPTY = {
|
|
7
7
|
items: [],
|
|
8
|
+
asked: null,
|
|
8
9
|
loadingMore: false,
|
|
9
10
|
failed: false,
|
|
10
11
|
offset: 0,
|
|
@@ -35,12 +36,14 @@ export function useRemotePage(source, query) {
|
|
|
35
36
|
searching: !append,
|
|
36
37
|
loadingMore: append,
|
|
37
38
|
failed: false,
|
|
39
|
+
asked: append ? previous.asked : nextQuery,
|
|
38
40
|
}));
|
|
39
41
|
search(nextQuery, controller.signal, offset).then((items) => {
|
|
40
42
|
if (controller.signal.aborted)
|
|
41
43
|
return;
|
|
42
44
|
setPage((previous) => ({
|
|
43
45
|
items: append ? [...previous.items, ...items] : items,
|
|
46
|
+
asked: previous.asked,
|
|
44
47
|
searching: false,
|
|
45
48
|
loadingMore: false,
|
|
46
49
|
failed: false,
|
|
@@ -74,7 +77,7 @@ export function useRemotePage(source, query) {
|
|
|
74
77
|
}, [remote, query, run]);
|
|
75
78
|
const loadMore = useCallback(() => {
|
|
76
79
|
const current = pageRef.current;
|
|
77
|
-
if (!remote || current.searching || current.loadingMore || current.exhausted)
|
|
80
|
+
if (!remote || current.searching || current.loadingMore || current.exhausted || queryRef.current !== current.asked)
|
|
78
81
|
return;
|
|
79
82
|
run(queryRef.current, current.offset);
|
|
80
83
|
}, [remote, run]);
|
|
@@ -84,7 +87,7 @@ export function useRemotePage(source, query) {
|
|
|
84
87
|
abortRef.current?.abort();
|
|
85
88
|
run(queryRef.current, 0);
|
|
86
89
|
}, [remote, run]);
|
|
87
|
-
return { ...page, loadMore, retry };
|
|
90
|
+
return { ...page, searching: remote && (page.searching || query !== page.asked), loadMore, retry };
|
|
88
91
|
}
|
|
89
92
|
export function EndOfListSentinel({ onReveal }) {
|
|
90
93
|
const ref = useRef(null);
|
|
@@ -6,7 +6,7 @@ import { ConversionLine } from "../../display/converted.js";
|
|
|
6
6
|
import { EditorPanel } from "../../editors/EditorPanel.js";
|
|
7
7
|
import { NumberEditor } from "../../editors/NumberEditor.js";
|
|
8
8
|
import { numberBounds } from "../../editors/number-body.js";
|
|
9
|
-
import { durationUnitOf, numberEditCode, numberEditDecimals } from "../../fields/number-edit.js";
|
|
9
|
+
import { durationUnitOf, numberEditCode, numberEditDecimals, numberEditInitial } from "../../fields/number-edit.js";
|
|
10
10
|
import { useViews } from "../../provider/context.js";
|
|
11
11
|
import { ROW_BOX_FRAME } from "./row-frame.js";
|
|
12
12
|
import { RowRefusal, useRowEditSession } from "./row-session.js";
|
|
@@ -23,7 +23,7 @@ export function RowNumberEditor({ binding, row, field, initial, conversion, onAt
|
|
|
23
23
|
const read = acceptFieldCommit(field, { value, ...(unit === undefined ? {} : { unit }) }, { conventions, unitOptions });
|
|
24
24
|
return read.ok ? null : read.reason;
|
|
25
25
|
};
|
|
26
|
-
return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(NumberEditor, { ref: editorRef, boxClassName: ROW_BOX_FRAME, initial:
|
|
26
|
+
return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(NumberEditor, { ref: editorRef, boxClassName: ROW_BOX_FRAME, initial: numberEditInitial(initial), unit: binding.unit?.read(row), unitOptions: unitOptions, code: binding.unit ? undefined : numberEditCode(field), decimals: decimals, durationUnit: durationUnit, allowEmpty: !!field.nullable, align: "start", conventions: conventions, ...numberBounds(field), ...(body
|
|
27
27
|
? {
|
|
28
28
|
type: field.type,
|
|
29
29
|
label: field.label,
|
|
@@ -15,3 +15,9 @@ export declare function numberEditDecimals(field: FieldDef): number;
|
|
|
15
15
|
export declare function numberEditCode(field: FieldDef): string | undefined;
|
|
16
16
|
/** The unit a duration field STORES (spec §8.4) — `undefined` for anything else. */
|
|
17
17
|
export declare function durationUnitOf(field: FieldDef): DurationUnit | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* What a number editor opens on: the number, or a stored decimal's text read as one (`"120.50"` → 120.5, a
|
|
20
|
+
* `storage: "decimal"` field's row value, VK-817); anything else is empty (NaN). The text is read for drawing the
|
|
21
|
+
* box, never for arithmetic: the save still goes through the field's own write.
|
|
22
|
+
*/
|
|
23
|
+
export declare function numberEditInitial(value: unknown): number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isIntegerField, presentedDef, valueTypeOf, } from "viewkitjs/fields";
|
|
1
|
+
import { isIntegerField, numberOfDecimalText, presentedDef, valueTypeOf, } from "viewkitjs/fields";
|
|
2
2
|
export function numberEditDecimals(field) {
|
|
3
3
|
if (isIntegerField(field))
|
|
4
4
|
return 0;
|
|
@@ -19,3 +19,10 @@ export function durationUnitOf(field) {
|
|
|
19
19
|
? (def.format.unit ?? "ms")
|
|
20
20
|
: undefined;
|
|
21
21
|
}
|
|
22
|
+
export function numberEditInitial(value) {
|
|
23
|
+
if (typeof value === "number")
|
|
24
|
+
return value;
|
|
25
|
+
if (typeof value === "string")
|
|
26
|
+
return numberOfDecimalText(value) ?? Number.NaN;
|
|
27
|
+
return Number.NaN;
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
import { numberEditCode, numberEditDecimals } from "../../fields/number-edit.js";
|
|
4
|
+
import { numberEditCode, numberEditDecimals, numberEditInitial } from "../../fields/number-edit.js";
|
|
5
5
|
import { numberBounds } from "../../editors/number-body.js";
|
|
6
6
|
import { convertedFromOf } from "../../fields/money.js";
|
|
7
7
|
import { renderTypedCellValue } from "../../cells/cell-values.js";
|
|
@@ -53,7 +53,7 @@ function InlineEditor({ ctx }) {
|
|
|
53
53
|
const durationUnit = col.format?.style === "duration" ? (col.format.unit ?? "ms") : undefined;
|
|
54
54
|
const field = col.field ?? legacyFieldFromColumn(col);
|
|
55
55
|
const valueType = valueTypeOf(field);
|
|
56
|
-
return (_jsx(GridNumberEditor, { title: col.header, initial:
|
|
56
|
+
return (_jsx(GridNumberEditor, { title: col.header, initial: numberEditInitial(baseline), seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, code: col.editUnit ? undefined : numberEditCode(field), type: valueType === "currency" || valueType === "percent" ? valueType : "number", bounds: numberBounds(field), decimals: integer ? 0 : (ctx.decimals ?? fallback), durationUnit: durationUnit, allowEmpty: !!col.clearable, unitLeft: col.align === "right", conversion: convertedFromOf(col, row) ? renderTypedCellValue(col, row, { decimals: ctx.decimals }) : undefined, refuse: (payload) => refusal(payload, cellPrevPayload(col, baseline, col.editUnit?.value(row))), onCommit: (payload) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline, col.editUnit?.value(row)), payload, { overlay: gridFigureDrawsAtOnce(col, row, payload) ? "figure" : false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
57
57
|
}
|
|
58
58
|
if (ctx.editorKind === "range") {
|
|
59
59
|
const def = col.field?.type === "range" ? col.field : undefined;
|
|
@@ -128,7 +128,7 @@ function AnchoredEditor({ ctx }) {
|
|
|
128
128
|
? gridClearRefusal(col, ctx.listConfig, messages)
|
|
129
129
|
: refusal(ymd, cellPrevPayload(col, baseline)), onCommit: (ymd) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline), ymd, ymd === "" || gridDateDrawsAtOnce(col)
|
|
130
130
|
? undefined
|
|
131
|
-
: { overlay: false }), onCancel: onCancel, onTab: ctx.onTab }));
|
|
131
|
+
: { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
132
132
|
}
|
|
133
133
|
return null;
|
|
134
134
|
}
|
|
@@ -2,9 +2,10 @@ import type { ListColumn } from "../../model/column-schema.js";
|
|
|
2
2
|
import type { ListDateStyle } from "../../model/column-format.js";
|
|
3
3
|
import { type GridFlyouts } from "./GridFlyout.js";
|
|
4
4
|
export declare const DATE_STYLES: ListDateStyle[];
|
|
5
|
-
/** The live sample beside each style: a few days
|
|
6
|
-
*
|
|
7
|
-
|
|
5
|
+
/** The live sample beside each style: a few days before the provider's moment, so Relative reads as a real "3d ago"
|
|
6
|
+
* rather than the "now" it would say of the moment it opened. None before the provider has a moment: the clock is
|
|
7
|
+
* never read while drawing. */
|
|
8
|
+
export declare const sampleDate: (now: Date | undefined) => Date | null;
|
|
8
9
|
/**
|
|
9
10
|
* The date-column row in the header menu — one Format row whose flyout holds
|
|
10
11
|
* the styles (each beside a live sample) and, on a date-time, Show time —
|
|
@@ -8,15 +8,15 @@ import { useViews } from "../../provider/context.js";
|
|
|
8
8
|
import { GridFlyoutRow } from "./GridFlyout.js";
|
|
9
9
|
import { GridMenuSeparator, KnobGlyph } from "./GridMenuRow.js";
|
|
10
10
|
export const DATE_STYLES = ["short", "long", "numeric", "relative"];
|
|
11
|
-
export const sampleDate = () => new Date(
|
|
11
|
+
export const sampleDate = (now) => now ? new Date(now.getTime() - 3 * 86_400_000) : null;
|
|
12
12
|
export function GridColumnDateSection({ column, dateStyle, onDateStyleChange, showTime, onShowTimeChange, flyouts, onClose, }) {
|
|
13
13
|
const activeDateStyle = dateStyle ?? column.format?.dateStyle ?? "short";
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const { viewer, presentation } = useCellFormat();
|
|
15
|
+
const sample = sampleDate(viewer.now);
|
|
16
16
|
const { atoms, messages } = useViews();
|
|
17
17
|
const { Row } = atoms;
|
|
18
18
|
const styleLabel = (style) => messages({ key: "views.menus.date-style", values: { style } });
|
|
19
|
-
return (_jsxs(GridFlyoutRow, { id: "date-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDateStyle), leading: _jsx(KnobGlyph, { name: "calendar" }), children: [DATE_STYLES.map((style) => (_jsx(Row, { chosen: activeDateStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: formatDate(sample, column, style, false, viewer) }), onClick: () => {
|
|
19
|
+
return (_jsxs(GridFlyoutRow, { id: "date-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDateStyle), leading: _jsx(KnobGlyph, { name: "calendar" }), children: [DATE_STYLES.map((style) => (_jsx(Row, { chosen: activeDateStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: sample && formatDate(sample, column, style, false, viewer, presentation) }), onClick: () => {
|
|
20
20
|
onDateStyleChange(fieldKeyOf(column), style);
|
|
21
21
|
onClose();
|
|
22
22
|
} }, style))), onShowTimeChange && temporalKindOf(column) === "datetime" && (_jsxs(_Fragment, { children: [_jsx(GridMenuSeparator, {}), _jsx(Row, { chosen: !!showTime, label: messages({ key: "views.menus.show-time" }), onClick: () => onShowTimeChange(fieldKeyOf(column), !showTime) })] }))] }));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { fieldKeyOf } from "../../model/view-rules.js";
|
|
4
4
|
import { formatNumber } from "./cells.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
|
|
6
6
|
import { useViews } from "../../provider/context.js";
|
|
7
7
|
import { GridFlyoutRow } from "./GridFlyout.js";
|
|
8
8
|
import { KnobGlyph } from "./GridMenuRow.js";
|
|
@@ -10,7 +10,7 @@ export const DURATION_STYLES = ["adaptive", "clock", "units"];
|
|
|
10
10
|
export const DURATION_SAMPLE_MS = 5_904_000;
|
|
11
11
|
export function GridColumnDurationSection({ column, durationStyle, onDurationStyleChange, flyouts, onClose, }) {
|
|
12
12
|
const activeDurationStyle = durationStyle ?? column.format?.durationStyle ?? "adaptive";
|
|
13
|
-
const cellFormat =
|
|
13
|
+
const cellFormat = useUndatedCellFormat();
|
|
14
14
|
const { atoms, messages } = useViews();
|
|
15
15
|
const { Row } = atoms;
|
|
16
16
|
const styleLabel = (style) => messages({ key: "views.menus.duration-style", values: { style } });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { cloneElement, useState, } from "react";
|
|
3
|
+
import { cloneElement, use, useState, } from "react";
|
|
4
4
|
import { columnLabel } from "../../model/column-capabilities.js";
|
|
5
5
|
import { columnKnobs } from "../../model/column-knobs.js";
|
|
6
|
-
import {
|
|
6
|
+
import { cellFormatAt, useUndatedCellFormat } from "../../cells/use-cell-format.js";
|
|
7
7
|
import { useViews } from "../../provider/context.js";
|
|
8
|
+
import { MomentContext } from "../../provider/moment.js";
|
|
8
9
|
import { columnMenuGates, gridColumnMenuItems } from "./grid-column-menu-items.js";
|
|
9
10
|
import { GridColumnColorSection } from "./GridColumnColorSection.js";
|
|
10
11
|
import { GridColumnDateSection } from "./GridColumnDateSection.js";
|
|
@@ -30,7 +31,8 @@ export function GridColumnMenu({ column, values, viewBacked = false, sort, group
|
|
|
30
31
|
const [anchor, setAnchor] = useState(null);
|
|
31
32
|
const menuFocus = useGridMenuFocus(open, anchor);
|
|
32
33
|
const press = useGridMenuPress(open);
|
|
33
|
-
const cellFormat =
|
|
34
|
+
const cellFormat = useUndatedCellFormat();
|
|
35
|
+
const moment = open ? use(MomentContext) : null;
|
|
34
36
|
const { atoms, components, icons, messages, menus } = useViews();
|
|
35
37
|
const { Popover, Menu } = components;
|
|
36
38
|
const { List } = atoms;
|
|
@@ -74,7 +76,7 @@ export function GridColumnMenu({ column, values, viewBacked = false, sort, group
|
|
|
74
76
|
if (!offers)
|
|
75
77
|
return _jsx(_Fragment, { children: children });
|
|
76
78
|
const items = open
|
|
77
|
-
? gridColumnMenuItems(column, { ...offer, optionColors, dateStyle, showTime, durationStyle, percentDisplay, numberFormat, onHide, appItems }, gates, { messages, icons, cellFormat, close })
|
|
79
|
+
? gridColumnMenuItems(column, { ...offer, optionColors, dateStyle, showTime, durationStyle, percentDisplay, numberFormat, onHide, appItems }, gates, { messages, icons, cellFormat: cellFormatAt(cellFormat, moment), close })
|
|
78
80
|
: [];
|
|
79
81
|
const menuTrigger = cloneElement(children, {
|
|
80
82
|
ref: setAnchor,
|
|
@@ -15,7 +15,7 @@ export declare function dayColumnKeepsBrowserClock<Row>(col: ListColumn<Row>): b
|
|
|
15
15
|
* payload is the day. The column's Show-time setting is display only. A cleared
|
|
16
16
|
* date commits "", which the app's write maps to its empty value.
|
|
17
17
|
*/
|
|
18
|
-
export declare function GridDateEditor({ title, initial, dayOnly, browserClock, clearable, seed, refuse, onCommit, onCancel, onTab, }: {
|
|
18
|
+
export declare function GridDateEditor({ title, initial, dayOnly, browserClock, clearable, seed, refuse, onCommit, onCancel, onTab, onEnter, }: {
|
|
19
19
|
/** The field's name: the sheet's title on a phone. */
|
|
20
20
|
title: ReactNode;
|
|
21
21
|
/** The stored value (ISO string) — selects the day + opening month. */
|
|
@@ -38,4 +38,6 @@ export declare function GridDateEditor({ title, initial, dayOnly, browserClock,
|
|
|
38
38
|
refuse?: (value: string) => string | null;
|
|
39
39
|
/** After a Tab out of the panel saves: move to the next cell, or the one before on Shift-Tab. */
|
|
40
40
|
onTab?: (backwards: boolean) => void;
|
|
41
|
+
/** After an Enter saves: move one row down, as a text or number cell does. */
|
|
42
|
+
onEnter?: () => void;
|
|
41
43
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,7 +10,7 @@ import { useGridEditSession } from "./grid-edit-session.js";
|
|
|
10
10
|
export function dayColumnKeepsBrowserClock(col) {
|
|
11
11
|
return col.field?.type !== "date" && temporalKindOf(col) === "date";
|
|
12
12
|
}
|
|
13
|
-
export function GridDateEditor({ title, initial, dayOnly = false, browserClock = false, clearable = false, seed, refuse, onCommit, onCancel, onTab, }) {
|
|
13
|
+
export function GridDateEditor({ title, initial, dayOnly = false, browserClock = false, clearable = false, seed, refuse, onCommit, onCancel, onTab, onEnter, }) {
|
|
14
14
|
const editorRef = useRef(null);
|
|
15
15
|
const anchorRef = useRef(null);
|
|
16
16
|
const place = useGridBodyPlace("date", anchorRef);
|
|
@@ -21,6 +21,7 @@ export function GridDateEditor({ title, initial, dayOnly = false, browserClock =
|
|
|
21
21
|
onCommit: (value) => onCommit(value),
|
|
22
22
|
onCancel,
|
|
23
23
|
onTab,
|
|
24
|
+
onEnter,
|
|
24
25
|
});
|
|
25
26
|
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, align: "start", sideOffset: place, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-auto", children: _jsx(EditorClockContext.Provider, { value: browserClock ? "browser" : "conventions", children: _jsx(DateEditor, { ref: editorRef, label: typeof title === "string" ? title : undefined, initial: initial, dayOnly: dayOnly, clearable: clearable, seed: seed, focusDate: !sheet, onRequestClose: close }) }) })] }));
|
|
26
27
|
}
|
|
@@ -4,7 +4,7 @@ import { cx } from "../../internal/cx.js";
|
|
|
4
4
|
import { CellSuffix } from "../../display/format.js";
|
|
5
5
|
import { aggregateLabel, aggregateOptions, resolveAggregateKind } from "../../model/aggregates.js";
|
|
6
6
|
import { DEFAULT_DISPLAY_CURRENCY } from "../../fields/currency.js";
|
|
7
|
-
import {
|
|
7
|
+
import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
|
|
8
8
|
import { gridFigureValue } from "./grid-figure-value.js";
|
|
9
9
|
import { useViews } from "../../provider/context.js";
|
|
10
10
|
import { GridAggregateMenu } from "./GridAggregateMenu.js";
|
|
@@ -18,7 +18,7 @@ export function gridFooterShown({ interactive, hostCells, }) {
|
|
|
18
18
|
}
|
|
19
19
|
export function GridFooter({ group, columns, selecting, aggregates, numberFormats, renderAggregate, onAggregateChange, viewBacked = false, frozenCount = 0, frozenLeft, continuation, defaultCurrency = DEFAULT_DISPLAY_CURRENCY, pageOnly = false, pin, ariaRowIndex, ariaLevel, ariaColOffset = 0, }) {
|
|
20
20
|
const interactive = !!onAggregateChange;
|
|
21
|
-
const cellFormat =
|
|
21
|
+
const cellFormat = useUndatedCellFormat();
|
|
22
22
|
const { messages } = useViews();
|
|
23
23
|
const hostCells = columns.map((column) => renderAggregate?.(column.id, group) ?? null);
|
|
24
24
|
const sourced = group.figures
|
|
@@ -140,7 +140,7 @@ export function gridColumnMenuItems(column, props, gates, deps) {
|
|
|
140
140
|
if (gates.canDate) {
|
|
141
141
|
const active = props.dateStyle ?? column.format?.dateStyle ?? "short";
|
|
142
142
|
const word = (style) => messages({ key: "views.menus.date-style", values: { style } });
|
|
143
|
-
const sample = sampleDate();
|
|
143
|
+
const sample = sampleDate(cellFormat.viewer.now);
|
|
144
144
|
knobs.push({
|
|
145
145
|
key: "date-format",
|
|
146
146
|
label: messages({ key: "views.menus.format" }),
|
|
@@ -150,7 +150,9 @@ export function gridColumnMenuItems(column, props, gates, deps) {
|
|
|
150
150
|
children: DATE_STYLES.map((style) => ({
|
|
151
151
|
key: `date-format:${style}`,
|
|
152
152
|
label: word(style),
|
|
153
|
-
detail:
|
|
153
|
+
detail: sample
|
|
154
|
+
? formatDate(sample, column, style, false, cellFormat.viewer, cellFormat.presentation)
|
|
155
|
+
: undefined,
|
|
154
156
|
checked: active === style,
|
|
155
157
|
onSelect: then(() => props.onDateStyleChange(key, style)),
|
|
156
158
|
})),
|
|
@@ -3,11 +3,11 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { columnLabel } from "../../model/column-capabilities.js";
|
|
4
4
|
import { DEFAULT_DISPLAY_CURRENCY } from "../../fields/currency.js";
|
|
5
5
|
import { CellSuffix } from "../../display/format.js";
|
|
6
|
-
import {
|
|
6
|
+
import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
|
|
7
7
|
import { gridFigureValue } from "./grid-figure-value.js";
|
|
8
8
|
const words = (label) => typeof label === "string" || typeof label === "number" ? String(label) : undefined;
|
|
9
9
|
export function useGridBandFigures(figures, { columns, numberFormats, defaultCurrency = DEFAULT_DISPLAY_CURRENCY, renderAggregate, }) {
|
|
10
|
-
const cellFormat =
|
|
10
|
+
const cellFormat = useUndatedCellFormat();
|
|
11
11
|
const drawn = [];
|
|
12
12
|
for (const figure of figures ?? []) {
|
|
13
13
|
if ("render" in figure) {
|
|
@@ -17,6 +17,9 @@ export declare const GridFitContext: import("react").Context<(() => void) | null
|
|
|
17
17
|
* A grid drawn where nothing is laid out (under a box `hidden` or `display: none` takes out of the page) reads every
|
|
18
18
|
* box at 0: it keeps none of those reads, and fits once it is laid out, when its size first changes.
|
|
19
19
|
*
|
|
20
|
+
* A date column waits for the provider's moment: until it is read its values draw in full ("15 Feb 2026"), then short
|
|
21
|
+
* ("15 Feb"), so it is fitted in the commit that draws them as they stay.
|
|
22
|
+
*
|
|
20
23
|
* `skip`: columns left at their default (on a phone, the pinned ones). `fit` runs after the grid's own commits and,
|
|
21
24
|
* through `GridFitContext`, after each group's.
|
|
22
25
|
*/
|