@viewkitjs/views 0.3.0 → 0.5.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 +641 -0
- package/README.md +3 -3
- package/dist/atoms/CommandMenu.d.ts +1 -1
- package/dist/atoms/CommandMenu.js +7 -3
- package/dist/atoms/DrillRows.d.ts +3 -0
- package/dist/atoms/DrillRows.js +25 -0
- package/dist/atoms/PanelRows.d.ts +5 -0
- package/dist/atoms/PanelRows.js +40 -0
- package/dist/atoms/PanelSearch.d.ts +2 -0
- package/dist/atoms/PanelSearch.js +21 -0
- package/dist/atoms/RelationRoles.d.ts +2 -0
- package/dist/atoms/RelationRoles.js +6 -0
- package/dist/atoms/Row.js +2 -1
- package/dist/atoms/RowMenu.js +2 -1
- package/dist/atoms/SelectionSheet.d.ts +3 -0
- package/dist/atoms/SelectionSheet.js +30 -0
- package/dist/atoms/StatusMarker.js +3 -1
- package/dist/atoms/Tag.js +2 -1
- package/dist/atoms/defaults.js +14 -0
- package/dist/atoms/types.d.ts +146 -8
- package/dist/cells/cell-values.js +4 -2
- package/dist/cells/relation-wrap.js +3 -1
- package/dist/contract.d.ts +212 -17
- package/dist/contract.js +208 -6
- package/dist/display/boolean.js +3 -1
- package/dist/display/date.d.ts +1 -1
- package/dist/display/date.js +4 -2
- package/dist/display/format.js +20 -4
- package/dist/display/link.js +4 -3
- package/dist/display/multi-value.js +2 -1
- package/dist/display/percent.js +2 -1
- package/dist/display/phone.js +2 -1
- package/dist/display/range.js +3 -13
- package/dist/display/relation.js +23 -8
- package/dist/display/rich-text.js +2 -1
- package/dist/editors/ChipsEditor.d.ts +5 -1
- package/dist/editors/ChipsEditor.js +15 -2
- package/dist/editors/DateEditor.d.ts +2 -0
- package/dist/editors/DateEditor.js +76 -10
- package/dist/editors/EditorPanel.d.ts +14 -4
- package/dist/editors/EditorPanel.js +21 -4
- package/dist/editors/LocationEditor.js +35 -3
- package/dist/editors/NumberEditor.js +3 -2
- package/dist/editors/RangeEditor.d.ts +8 -0
- package/dist/editors/RangeEditor.js +3 -2
- package/dist/editors/RelationEditor.d.ts +2 -0
- package/dist/editors/RelationEditor.js +16 -2
- package/dist/editors/RelationSetEditor.d.ts +4 -2
- package/dist/editors/RelationSetEditor.js +36 -2
- package/dist/editors/SelectEditor.d.ts +5 -2
- package/dist/editors/SelectEditor.js +31 -4
- package/dist/editors/TextEditor.js +3 -1
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +10 -4
- package/dist/editors/edit-session.d.ts +14 -2
- package/dist/editors/edit-session.js +13 -5
- package/dist/editors/escape-rule.d.ts +12 -0
- package/dist/editors/escape-rule.js +8 -0
- package/dist/editors/open-value.js +2 -1
- package/dist/editors/picker-slot.d.ts +25 -0
- package/dist/editors/picker-slot.js +37 -0
- package/dist/editors/relation-picker.d.ts +44 -0
- package/dist/editors/relation-picker.js +49 -0
- package/dist/editors/relation-source.d.ts +1 -0
- package/dist/editors/relation-source.js +7 -1
- package/dist/field-row/FieldNoteLine.js +2 -1
- package/dist/field-row/FieldRow.js +41 -6
- package/dist/field-row/FieldRowLane.js +3 -1
- package/dist/field-row/editors/RowChipsEditor.js +1 -1
- package/dist/field-row/editors/RowDateEditor.js +1 -1
- package/dist/field-row/editors/RowEditor.js +2 -1
- package/dist/field-row/editors/RowRangeEditor.js +2 -1
- package/dist/field-row/editors/RowRelationEditor.js +2 -2
- package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
- package/dist/field-row/editors/RowSelectEditor.js +2 -2
- package/dist/field-row/editors/RowValueListEditor.js +1 -1
- package/dist/field-row/editors/host.d.ts +3 -0
- package/dist/field-row/editors/row-session.js +4 -1
- package/dist/fields/menus.d.ts +2 -0
- package/dist/fields/range-unit.d.ts +7 -0
- package/dist/fields/range-unit.js +13 -0
- package/dist/figures.d.ts +5 -48
- package/dist/figures.js +1 -63
- package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
- package/dist/grid/chrome/GridAddColumn.js +66 -9
- package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
- package/dist/grid/chrome/GridAggregateMenu.js +33 -4
- package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
- package/dist/grid/chrome/GridCellEditors.js +24 -5
- package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
- package/dist/grid/chrome/GridCellOutline.js +11 -1
- package/dist/grid/chrome/GridChipsEditor.js +1 -1
- package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
- package/dist/grid/chrome/GridColumnColorSection.js +2 -2
- package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDateSection.js +2 -2
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
- package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
- package/dist/grid/chrome/GridColumnMenu.js +62 -24
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
- package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
- package/dist/grid/chrome/GridDateEditor.js +1 -1
- package/dist/grid/chrome/GridFooter.js +7 -48
- package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
- package/dist/grid/chrome/GridGroupMenu.js +28 -13
- package/dist/grid/chrome/GridHeader.d.ts +3 -1
- package/dist/grid/chrome/GridHeader.js +8 -8
- package/dist/grid/chrome/GridNumberEditor.js +3 -24
- package/dist/grid/chrome/GridRangeEditor.js +3 -2
- package/dist/grid/chrome/GridRelationEditor.js +2 -2
- package/dist/grid/chrome/GridRow.d.ts +2 -1
- package/dist/grid/chrome/GridRow.js +13 -37
- package/dist/grid/chrome/GridRowActions.js +2 -1
- package/dist/grid/chrome/GridRowCells.js +9 -4
- package/dist/grid/chrome/GridSelectEditor.js +30 -20
- package/dist/grid/chrome/GridStructure.d.ts +11 -4
- package/dist/grid/chrome/GridStructure.js +19 -7
- package/dist/grid/chrome/GridTable.js +138 -16
- package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
- package/dist/grid/chrome/GridTableSurface.js +13 -6
- package/dist/grid/chrome/GridTextEditor.js +3 -1
- package/dist/grid/chrome/GridValueListEditor.js +1 -1
- package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
- package/dist/grid/chrome/cell-clipboard.js +1 -1
- package/dist/grid/chrome/checks.d.ts +10 -2
- package/dist/grid/chrome/checks.js +17 -11
- package/dist/grid/chrome/column-glyph.d.ts +2 -2
- package/dist/grid/chrome/column-glyph.js +4 -0
- package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
- package/dist/grid/chrome/grid-add-column-items.js +40 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
- package/dist/grid/chrome/grid-cell-classes.js +10 -4
- package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
- package/dist/grid/chrome/grid-column-menu-items.js +263 -0
- package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
- package/dist/grid/chrome/grid-edit-escape.js +12 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
- package/dist/grid/chrome/grid-edit-session.js +14 -1
- package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
- package/dist/grid/chrome/grid-figure-value.js +40 -0
- package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
- package/dist/grid/chrome/grid-fitted-box.js +26 -0
- package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
- package/dist/grid/chrome/grid-group-menu-items.js +75 -0
- package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
- package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
- package/dist/grid/chrome/grid-hover.d.ts +1 -0
- package/dist/grid/chrome/grid-hover.js +13 -1
- package/dist/grid/chrome/grid-lab.d.ts +7 -0
- package/dist/grid/chrome/grid-lab.js +7 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
- package/dist/grid/chrome/grid-menu-focus.js +13 -0
- package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
- package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
- package/dist/grid/chrome/grid-row-props.d.ts +3 -1
- package/dist/grid/chrome/grid-row-window.d.ts +15 -5
- package/dist/grid/chrome/grid-row-window.js +44 -10
- package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
- package/dist/grid/chrome/grid-rows-menu.js +83 -0
- package/dist/grid/chrome/grid-table-props.d.ts +53 -8
- package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
- package/dist/grid/chrome/useGridBandFigures.js +50 -0
- package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
- package/dist/grid/chrome/useGridBoxes.js +22 -0
- package/dist/grid/chrome/useGridColumnLayout.js +29 -4
- package/dist/grid/chrome/useGridKeyboard.js +7 -2
- package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
- package/dist/grid/chrome/useGridPartColumns.js +9 -0
- package/dist/grid/chrome/useGridRangeGestures.js +2 -1
- package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
- package/dist/grid/chrome/useGridRecorder.js +144 -0
- package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
- package/dist/grid/chrome/useGridRowOpener.js +83 -0
- package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
- package/dist/grid/chrome/useGridScrollArea.js +70 -17
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
- package/dist/grid/core/clipboard-model.d.ts +11 -3
- package/dist/grid/core/clipboard-model.js +9 -4
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/editing-controller.d.ts +31 -1
- package/dist/grid/core/editing-controller.js +65 -0
- package/dist/grid/core/grid-recorder.d.ts +111 -0
- package/dist/grid/core/grid-recorder.js +223 -0
- package/dist/grid/core/part-edits.d.ts +18 -0
- package/dist/grid/core/part-edits.js +48 -0
- package/dist/grid/core/pending-reconciliation.js +12 -3
- package/dist/grid/core/refusal-sentence.d.ts +3 -0
- package/dist/grid/core/refusal-sentence.js +15 -0
- package/dist/grid/core/row-opened-from.d.ts +21 -0
- package/dist/grid/core/row-opened-from.js +11 -0
- package/dist/grid/core/useGridEditing.d.ts +16 -2
- package/dist/grid/core/useGridEditing.js +10 -4
- package/dist/grid/core/value-equality.d.ts +19 -1
- package/dist/grid/core/value-equality.js +24 -0
- package/dist/grid/index.d.ts +4 -1
- package/dist/grid/index.js +1 -0
- package/dist/grid/useGridTablePrefs.d.ts +1 -1
- package/dist/grid-lab.d.ts +18 -0
- package/dist/grid-lab.js +16 -0
- package/dist/grouping/sort-groups.d.ts +6 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/reset.d.ts +9 -0
- package/dist/internal/reset.js +1 -0
- package/dist/model/aggregates.d.ts +3 -3
- package/dist/model/aggregates.js +17 -71
- package/dist/model/column-capabilities.d.ts +29 -2
- package/dist/model/column-capabilities.js +27 -3
- package/dist/model/column-filters.js +24 -4
- package/dist/model/column-inspect.d.ts +2 -1
- package/dist/model/column-order.d.ts +2 -2
- package/dist/model/column-schema.d.ts +18 -7
- package/dist/model/column-state.d.ts +9 -20
- package/dist/model/column-state.js +1 -4
- package/dist/model/column-types.d.ts +1 -15
- package/dist/model/column-types.js +1 -1
- package/dist/model/part-columns.d.ts +17 -0
- package/dist/model/part-columns.js +67 -0
- package/dist/model/part-rows.d.ts +3 -10
- package/dist/model/part-rows.js +6 -11
- package/dist/model/part-write.d.ts +11 -0
- package/dist/model/part-write.js +52 -0
- package/dist/model/preferences.d.ts +3 -23
- package/dist/model/preferences.js +1 -17
- package/dist/model/prefs-buckets.d.ts +0 -27
- package/dist/model/prefs-buckets.js +1 -1
- package/dist/model/relation-filters.d.ts +0 -1
- package/dist/model/relation-filters.js +1 -1
- package/dist/model/row-icon.d.ts +5 -9
- package/dist/model/view-rules.d.ts +32 -6
- package/dist/model/view-rules.js +101 -21
- package/dist/provider/ViewsProvider.d.ts +22 -2
- package/dist/provider/ViewsProvider.js +21 -2
- package/dist/provider/components.d.ts +197 -9
- package/dist/provider/context.d.ts +12 -1
- package/dist/provider/desktop.d.ts +3 -0
- package/dist/provider/desktop.js +7 -4
- package/dist/provider/menu-groups.d.ts +3 -2
- package/dist/provider/menu-groups.js +13 -7
- package/dist/provider/missing-slot.d.ts +10 -0
- package/dist/provider/missing-slot.js +15 -0
- package/dist/provider/plain-input.d.ts +3 -2
- package/dist/provider/plain-input.js +3 -1
- package/dist/react.d.ts +3 -2
- package/dist/selection/SelectionBar.d.ts +18 -0
- package/dist/selection/SelectionBar.js +92 -0
- package/dist/selection/SelectionBarPhone.d.ts +3 -0
- package/dist/selection/SelectionBarPhone.js +14 -0
- package/dist/selection/bar-overflow.d.ts +12 -0
- package/dist/selection/bar-overflow.js +42 -0
- package/dist/selection/bar-parts.d.ts +15 -0
- package/dist/selection/bar-parts.js +17 -0
- package/dist/selection/index.d.ts +2 -0
- package/dist/selection/index.js +1 -0
- package/dist/selection/types.d.ts +3 -2
- package/dist/selection/verbs.d.ts +34 -0
- package/dist/selection/verbs.js +1 -0
- package/docs/contract.md +142 -39
- package/docs/getting-started.md +1 -1
- package/docs/guides/atoms.md +32 -4
- package/docs/guides/columns.md +1 -1
- package/docs/guides/display.md +1 -1
- package/docs/guides/editors.md +3 -3
- package/docs/guides/ports.md +1 -1
- package/docs/guides/selection.md +32 -20
- package/docs/guides/the-grid.md +43 -21
- package/docs/guides/the-provider.md +14 -4
- package/docs/index.md +2 -0
- package/docs/install.md +8 -1
- package/docs/reference/editors-date.md +2 -0
- package/docs/reference/editors-panel.md +4 -4
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +3 -3
- package/docs/reference/editors-select.md +1 -1
- package/docs/reference/editors-session.md +3 -2
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/field-row.md +2 -2
- package/docs/reference/grid.md +25 -6
- package/docs/reference/react.md +30 -8
- package/docs/reference/selection.md +10 -2
- package/docs/reference/views.md +42 -36
- package/package.json +22 -3
- package/skills/views/SKILL.md +3 -3
package/dist/display/boolean.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../internal/cx.js";
|
|
4
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
3
5
|
import { useViews } from "../provider/context.js";
|
|
4
6
|
export function renderBoolean(field, value, opts) {
|
|
5
7
|
const truthy = Boolean(value);
|
|
@@ -39,5 +41,5 @@ function renderToggle(child, truthy, field, opts) {
|
|
|
39
41
|
return (_jsx("button", { type: "button", role: "switch", "aria-checked": truthy, "aria-label": field.label, disabled: opts.booleanDisabled, onClick: (event) => {
|
|
40
42
|
event.stopPropagation();
|
|
41
43
|
opts.onToggle?.(!truthy);
|
|
42
|
-
}, className: "flex items-center rounded-sm transition-opacity hover:opacity-80", children: child }));
|
|
44
|
+
}, className: cx(ELEMENT_RESET, "flex items-center rounded-sm transition-opacity hover:opacity-80"), children: child }));
|
|
43
45
|
}
|
package/dist/display/date.d.ts
CHANGED
package/dist/display/date.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { fromDayKey } from "@viewkitjs/fields/query";
|
|
4
5
|
import { cx } from "../internal/cx.js";
|
|
5
6
|
import { useViews } from "../provider/context.js";
|
|
@@ -12,14 +13,15 @@ export function renderDate(field, value, opts) {
|
|
|
12
13
|
function DateValue({ field, value, opts: given, }) {
|
|
13
14
|
const opts = useDisplayOptions(given);
|
|
14
15
|
const { Tooltip } = useViews().components;
|
|
16
|
+
const [pointed, setPointed] = useState(false);
|
|
15
17
|
const withTime = opts.withTime ?? (field.type === "datetime" ? field.format?.withTime : false);
|
|
16
|
-
const cell = (_jsx("span", { className: cx(cellTextClass(opts.wrap), "tabular-nums text-(color:--vk-fg)"), children: formatDateValue(value, opts.dateStyle ?? field.format?.dateStyle, withTime, field.type, opts) }));
|
|
18
|
+
const cell = (_jsx("span", { className: cx(cellTextClass(opts.wrap), "tabular-nums text-(color:--vk-fg)"), onPointerEnter: pointed ? undefined : (event) => event.pointerType !== "touch" && setPointed(true), children: formatDateValue(value, opts.dateStyle ?? field.format?.dateStyle, withTime, field.type, opts) }));
|
|
17
19
|
const d = field.type === "date" && typeof value === "string"
|
|
18
20
|
? fromDayKey(value)
|
|
19
21
|
: value instanceof Date
|
|
20
22
|
? value
|
|
21
23
|
: new Date(String(value));
|
|
22
|
-
if (!d || Number.isNaN(d.getTime()))
|
|
24
|
+
if (!pointed || !d || Number.isNaN(d.getTime()))
|
|
23
25
|
return cell;
|
|
24
26
|
const full = formatDateValue(value, "long", field.type === "datetime", field.type, opts);
|
|
25
27
|
return (_jsx(Tooltip, { content: full, side: "bottom", align: "start", delayMs: 1000, className: "tabular-nums", children: cell }));
|
package/dist/display/format.js
CHANGED
|
@@ -35,8 +35,24 @@ function relative(input, context) {
|
|
|
35
35
|
: daySpan(Math.floor(hours / 24));
|
|
36
36
|
return spanWords(span, diff < 0, context);
|
|
37
37
|
}
|
|
38
|
+
const DATE_FORMATS = new Map();
|
|
39
|
+
const NUMBER_FORMATS = new Map();
|
|
40
|
+
function dateFormat(locale, options) {
|
|
41
|
+
const key = `${locale}|${JSON.stringify(options)}`;
|
|
42
|
+
let format = DATE_FORMATS.get(key);
|
|
43
|
+
if (!format)
|
|
44
|
+
DATE_FORMATS.set(key, (format = new Intl.DateTimeFormat(locale, options)));
|
|
45
|
+
return format;
|
|
46
|
+
}
|
|
47
|
+
function numberFormat(locale, options) {
|
|
48
|
+
const key = `${locale ?? ""}|${JSON.stringify(options)}`;
|
|
49
|
+
let format = NUMBER_FORMATS.get(key);
|
|
50
|
+
if (!format)
|
|
51
|
+
NUMBER_FORMATS.set(key, (format = new Intl.NumberFormat(locale, options)));
|
|
52
|
+
return format;
|
|
53
|
+
}
|
|
38
54
|
function viewerToday(context) {
|
|
39
|
-
const parts =
|
|
55
|
+
const parts = dateFormat("en-US", {
|
|
40
56
|
timeZone: context.timeZone ?? DEFAULT_CONVENTIONS.timeZone,
|
|
41
57
|
year: "numeric",
|
|
42
58
|
month: "numeric",
|
|
@@ -73,7 +89,7 @@ function absoluteDay({ year, month, day }, style, today, context, time) {
|
|
|
73
89
|
return time ? `${date}, ${time}` : date;
|
|
74
90
|
}
|
|
75
91
|
function instantParts(instant, timeZone) {
|
|
76
|
-
const parts =
|
|
92
|
+
const parts = dateFormat("en-GB", {
|
|
77
93
|
timeZone: timeZone ?? DEFAULT_CONVENTIONS.timeZone,
|
|
78
94
|
year: "numeric",
|
|
79
95
|
month: "numeric",
|
|
@@ -95,11 +111,11 @@ export const DEFAULT_FIELD_PRESENTATION = {
|
|
|
95
111
|
number: ({ value, format, decimals, currency, context }) => {
|
|
96
112
|
const style = format?.style ?? "plain";
|
|
97
113
|
if (style === "percent")
|
|
98
|
-
return `${
|
|
114
|
+
return `${numberFormat(context.locale, {
|
|
99
115
|
minimumFractionDigits: decimals ?? 0,
|
|
100
116
|
maximumFractionDigits: decimals ?? 0,
|
|
101
117
|
}).format(value)}%`;
|
|
102
|
-
return
|
|
118
|
+
return numberFormat(context.locale, {
|
|
103
119
|
...(style === "currency" ? { style: "currency", currency: currency ?? "EUR" } : {}),
|
|
104
120
|
minimumFractionDigits: decimals ?? (style === "currency" ? 2 : 0),
|
|
105
121
|
maximumFractionDigits: decimals ?? 2,
|
package/dist/display/link.js
CHANGED
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { linkPlatform } from "@viewkitjs/fields";
|
|
5
5
|
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
6
7
|
import { ViewsContext } from "../provider/context.js";
|
|
7
8
|
import { cellLinkProps } from "./link-click.js";
|
|
8
9
|
import { cellTextClass } from "./text-class.js";
|
|
@@ -20,7 +21,7 @@ function WebAddress({ address, opts }) {
|
|
|
20
21
|
const views = useContext(ViewsContext);
|
|
21
22
|
const label = address.replace(/^https?:\/\//, "");
|
|
22
23
|
const href = webHref(address);
|
|
23
|
-
const link = opts?.slotOwnsClick || href === null ? (_jsx("span", { className: cellTextClass(opts?.wrap), children: label })) : (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: label }));
|
|
24
|
+
const link = opts?.slotOwnsClick || href === null ? (_jsx("span", { className: cellTextClass(opts?.wrap), children: label })) : (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(ELEMENT_RESET, cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: label }));
|
|
24
25
|
const platform = views && href !== null ? linkPlatform(address, views.conventions) : null;
|
|
25
26
|
if (!platform || !views)
|
|
26
27
|
return link;
|
|
@@ -35,7 +36,7 @@ function domainLink(domain, opts) {
|
|
|
35
36
|
const href = webHref(domain);
|
|
36
37
|
if (opts?.slotOwnsClick || href === null)
|
|
37
38
|
return _jsx("span", { className: cellTextClass(opts?.wrap), children: domain });
|
|
38
|
-
return (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: domain }));
|
|
39
|
+
return (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", ...(cellLinkProps(opts) ?? { "data-no-nav": true }), className: cx(ELEMENT_RESET, cellTextClass(opts?.wrap), "text-(color:--vk-fg-brand) hover:underline"), children: domain }));
|
|
39
40
|
}
|
|
40
41
|
export function renderEmail(_field, value, opts) {
|
|
41
42
|
if (Array.isArray(value))
|
|
@@ -50,5 +51,5 @@ function renderEmailAddress(address, opts) {
|
|
|
50
51
|
return (_jsx("a", { href: `mailto:${address}`, ...(cellLinkProps(opts) ?? {
|
|
51
52
|
"data-no-nav": true,
|
|
52
53
|
onClick: (event) => event.stopPropagation(),
|
|
53
|
-
}), className: "text-(color:--vk-fg) underline decoration-dotted decoration-(color:--vk-fg-subtle)/40 decoration-1 underline-offset-[3px] transition-colors hover:decoration-(color:--vk-fg-subtle)/60", children: address }));
|
|
54
|
+
}), className: cx(ELEMENT_RESET, "text-(color:--vk-fg) underline decoration-dotted decoration-(color:--vk-fg-subtle)/40 decoration-1 underline-offset-[3px] transition-colors hover:decoration-(color:--vk-fg-subtle)/60"), children: address }));
|
|
54
55
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useRef, useState } from "react";
|
|
4
4
|
import { cx } from "../internal/cx.js";
|
|
5
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
5
6
|
import { useViews } from "../provider/context.js";
|
|
6
7
|
const VISIBLE_FLAT = 1;
|
|
7
8
|
const VISIBLE_WRAPPED = 3;
|
|
@@ -19,7 +20,7 @@ export function MultiValueCell({ items, details, wrap, title, slotOwnsClick, })
|
|
|
19
20
|
(slotOwnsClick ? (_jsxs("span", { className: "shrink-0 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle)", children: ["+", hidden] })) : (_jsxs("button", { ref: trigger, type: "button", tabIndex: -1, "data-no-nav": true, "aria-label": messages({ key: "views.display.show-all", values: { count: items.length } }), "aria-haspopup": "dialog", "aria-expanded": open, onClick: (event) => {
|
|
20
21
|
event.stopPropagation();
|
|
21
22
|
setOpen((current) => !current);
|
|
22
|
-
}, className: cx("shrink-0 rounded-md [corner-shape:squircle] border border-(color:--vk-border)", "bg-(color:--vk-ground) px-1 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle) shadow-xs", "transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)"), children: ["+", hidden] })))] }));
|
|
23
|
+
}, className: cx(ELEMENT_RESET, "shrink-0 rounded-md [corner-shape:squircle] border border-(color:--vk-border)", "bg-(color:--vk-ground) px-1 text-[10px] leading-[0.9rem] text-(color:--vk-fg-subtle) shadow-xs", "transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)"), children: ["+", hidden] })))] }));
|
|
23
24
|
if (hidden === 0 || slotOwnsClick)
|
|
24
25
|
return content;
|
|
25
26
|
const { Popover } = components;
|
package/dist/display/percent.js
CHANGED
|
@@ -30,7 +30,8 @@ function PercentValue({ field, n, opts: given }) {
|
|
|
30
30
|
? { width: "max-content", minWidth: `min(${figureSlot}, ${figureRoom})`, maxWidth: figureRoom }
|
|
31
31
|
: { width: figureSlot }, children: [figure, _jsx(CellSuffix, { children: "%" })] }));
|
|
32
32
|
if (display === "bar") {
|
|
33
|
-
|
|
33
|
+
const box = `calc(6rem + 0.5rem + ${figureSlot})`;
|
|
34
|
+
return (_jsxs("span", { className: "flex h-lh min-w-0 flex-1 flex-row-reverse flex-wrap content-start items-center gap-x-2 overflow-y-clip", style: { width: box, maxWidth: `min(${box}, 100%)` }, children: [figureNode(true), _jsx("span", { className: "h-1.5 min-w-6 flex-1 overflow-hidden rounded-full bg-(color:--vk-neutral)", "aria-hidden": true, children: _jsx("span", { className: "block h-full bg-(color:--vk-brand)", style: { width: `${clamped}%` } }) })] }));
|
|
34
35
|
}
|
|
35
36
|
return (_jsxs("span", { className: "flex min-w-0 items-center gap-2", children: [_jsx("span", { className: "h-4 w-4 shrink-0 rounded-full", style: {
|
|
36
37
|
background: `conic-gradient(var(--vk-brand) ${clamped}%, var(--vk-neutral) 0)`,
|
package/dist/display/phone.js
CHANGED
|
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { phoneHref, phoneText, readPhone } from "@viewkitjs/fields/phone";
|
|
4
4
|
import { resolveViewsMessage } from "../contract.js";
|
|
5
5
|
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
6
7
|
import { CHIP_INTERACTIVE } from "../internal/chip.js";
|
|
7
8
|
import { cellLinkProps } from "./link-click.js";
|
|
8
9
|
import { cellTextClass } from "./text-class.js";
|
|
@@ -43,5 +44,5 @@ function phoneNode(value, opts) {
|
|
|
43
44
|
return (_jsx("span", { className: cellTextClass(opts?.wrap), ...asTyped, children: text }));
|
|
44
45
|
}
|
|
45
46
|
const owned = cellLinkProps(opts);
|
|
46
|
-
return (_jsx("a", { href: phoneHref(value) ?? undefined, ...(owned ?? { "data-no-nav": true, onClick: (event) => event.stopPropagation() }), className: CHIP_INTERACTIVE, ...asTyped, children: _jsx("span", { className: cx("min-w-0", cellTextClass(opts?.wrap)), children: text }) }));
|
|
47
|
+
return (_jsx("a", { href: phoneHref(value) ?? undefined, ...(owned ?? { "data-no-nav": true, onClick: (event) => event.stopPropagation() }), className: cx(ELEMENT_RESET, CHIP_INTERACTIVE), ...asTyped, children: _jsx("span", { className: cx("min-w-0", cellTextClass(opts?.wrap)), children: text }) }));
|
|
47
48
|
}
|
package/dist/display/range.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { rangeText } from "@viewkitjs/fields";
|
|
4
|
+
import { rangePeriodShort, rangeUnit } from "../fields/range-unit.js";
|
|
4
5
|
import { useViews } from "../provider/context.js";
|
|
5
6
|
import { CellSuffix } from "./format.js";
|
|
6
7
|
import { cellTextClass } from "./text-class.js";
|
|
7
|
-
const PERIOD_SHORT = {
|
|
8
|
-
hour: "/h",
|
|
9
|
-
day: "/day",
|
|
10
|
-
week: "/wk",
|
|
11
|
-
month: "/mo",
|
|
12
|
-
year: "/yr",
|
|
13
|
-
};
|
|
14
8
|
export function renderRange(field, value, opts) {
|
|
15
9
|
return _jsx(RangeValueCell, { field: field, value: value, opts: opts });
|
|
16
10
|
}
|
|
@@ -19,11 +13,7 @@ function RangeValueCell({ field, value, opts, }) {
|
|
|
19
13
|
const text = rangeText(field, value, conventions);
|
|
20
14
|
if (!text)
|
|
21
15
|
return null;
|
|
22
|
-
const unit = field
|
|
23
|
-
|
|
24
|
-
: field.of === "currency"
|
|
25
|
-
? field.code?.fixed
|
|
26
|
-
: field.format?.suffix;
|
|
27
|
-
const period = field.period ? PERIOD_SHORT[field.period] : undefined;
|
|
16
|
+
const unit = rangeUnit(field);
|
|
17
|
+
const period = rangePeriodShort(field);
|
|
28
18
|
return (_jsxs("span", { className: cellTextClass(opts?.wrap), title: text, children: [_jsx("span", { className: "tabular-nums", children: text }), unit && _jsx(CellSuffix, { children: unit }), period && _jsx(CellSuffix, { children: period })] }));
|
|
29
19
|
}
|
package/dist/display/relation.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { orderLinks, relationKinds, resolveRelationValue, } from "@viewkitjs/fields";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { orderLinks, relationKinds, relationRolesOf, resolveRelationValue, } from "@viewkitjs/fields";
|
|
4
4
|
import { CHIP_BASE } from "../internal/chip.js";
|
|
5
5
|
import { useViews } from "../provider/context.js";
|
|
6
6
|
import { EntityChipIdentity } from "./entity-chip.js";
|
|
7
7
|
import { MultiValueCell } from "./multi-value.js";
|
|
8
8
|
import { cellTextClass } from "./text-class.js";
|
|
9
|
+
function roleLabels(field, relation) {
|
|
10
|
+
if (field.cardinality !== "many" || !field.links)
|
|
11
|
+
return [];
|
|
12
|
+
const declared = field.links.roles ?? [];
|
|
13
|
+
return relationRolesOf(relation).map((value) => ({
|
|
14
|
+
value,
|
|
15
|
+
label: declared.find((option) => option.value === value)?.label ?? value,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
function chipTitle(relation, roles) {
|
|
19
|
+
return roles.length ? `${relation.label} · ${roles.map((role) => role.label).join(", ")}` : relation.label;
|
|
20
|
+
}
|
|
9
21
|
export function renderRelation(field, value, opts) {
|
|
10
22
|
if (Array.isArray(value)) {
|
|
11
23
|
const chips = orderLinks(field, value
|
|
@@ -13,17 +25,20 @@ export function renderRelation(field, value, opts) {
|
|
|
13
25
|
.filter((entry) => entry != null));
|
|
14
26
|
if (chips.length === 0)
|
|
15
27
|
return null;
|
|
16
|
-
return (_jsx(MultiValueCell, { items: chips.map((chip) => _jsx(RelationChip, { relation: chip, opts: opts }, `${chip.entity ?? ""}:${chip.id}`)), wrap: !!opts?.wrap, title: chips.map((chip) => chip
|
|
28
|
+
return (_jsx(MultiValueCell, { items: chips.map((chip) => (_jsx(RelationChip, { field: field, relation: chip, opts: opts }, `${chip.entity ?? ""}:${chip.id}`))), wrap: !!opts?.wrap, title: chips.map((chip) => chipTitle(chip, roleLabels(field, chip))).join(", "), slotOwnsClick: opts?.slotOwnsClick }));
|
|
17
29
|
}
|
|
18
30
|
const relation = resolveRelationValue(value, relationKinds(field)[0]);
|
|
19
31
|
if (!relation)
|
|
20
32
|
return null;
|
|
21
|
-
return _jsx(RelationChip, { relation: relation, opts: opts });
|
|
33
|
+
return _jsx(RelationChip, { field: field, relation: relation, opts: opts });
|
|
22
34
|
}
|
|
23
|
-
function RelationChip({ relation, opts }) {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
35
|
+
function RelationChip({ field, relation, opts, }) {
|
|
36
|
+
const views = useViews();
|
|
37
|
+
const Glyph = views.icons.relation;
|
|
38
|
+
const { RelationRoles } = views.atoms;
|
|
39
|
+
const roles = roleLabels(field, relation);
|
|
40
|
+
const chip = (_jsxs(_Fragment, { children: [_jsx(EntityChipIdentity, { label: relation.label, avatarUrl: relation.avatarUrl, iconOverride: relation.icon ?? opts?.entityIcon?.(relation.entity), fallbackIcon: _jsx(Glyph, { className: "h-3 w-3 shrink-0 text-(color:--vk-fg-subtlest)" }), labelClassName: cellTextClass(opts?.wrap) }), roles.length > 0 ? _jsx(RelationRoles, { relation: relation, roles: roles }) : null] }));
|
|
26
41
|
if (opts?.relationWrap)
|
|
27
42
|
return opts.relationWrap(relation, chip);
|
|
28
|
-
return (_jsx("span", { className: CHIP_BASE, title: relation
|
|
43
|
+
return (_jsx("span", { className: CHIP_BASE, title: chipTitle(relation, roles), children: chip }));
|
|
29
44
|
}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useLayoutEffect, useRef, useState } from "react";
|
|
4
4
|
import { markdownFirstLine, markdownPlainText } from "@viewkitjs/fields";
|
|
5
5
|
import { cx } from "../internal/cx.js";
|
|
6
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
6
7
|
import { useViews } from "../provider/context.js";
|
|
7
8
|
import { cellTextClass } from "./text-class.js";
|
|
8
9
|
const FOLDED_PX = 160;
|
|
@@ -30,5 +31,5 @@ function RichTextBlock({ source }) {
|
|
|
30
31
|
return (_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { ref: boxRef, className: cx("relative min-w-0 overflow-hidden", !open && tall && "max-h-40"), children: [_jsx(Markdown, { source: source }), !open && tall && (_jsx("div", { className: "pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-linear-to-t from-(color:--vk-ground) to-transparent" }))] }), tall && (_jsx("button", { type: "button", "data-no-nav": true, onClick: (event) => {
|
|
31
32
|
event.stopPropagation();
|
|
32
33
|
setOpen((was) => !was);
|
|
33
|
-
}, className: "mt-1 text-xs text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)", children: messages({ key: open ? "views.display.show-less" : "views.display.show-more" }) }))] }));
|
|
34
|
+
}, className: cx(ELEMENT_RESET, "mt-1 text-xs text-(color:--vk-fg-subtle) hover:text-(color:--vk-fg)"), children: messages({ key: open ? "views.display.show-less" : "views.display.show-more" }) }))] }));
|
|
34
35
|
}
|
|
@@ -54,11 +54,15 @@ export declare const ChipsEditor: import("react").ForwardRefExoticComponent<{
|
|
|
54
54
|
* added value goes through it on the way in — the same function the route
|
|
55
55
|
* applies, so `Ops Team` and `ops-team` cannot come apart. */
|
|
56
56
|
normalize?: (raw: string) => string;
|
|
57
|
-
/** The core saw a key that means "done" (Escape, Tab, Shift-Tab)
|
|
57
|
+
/** The core saw a key that means "done" (Escape, Tab, Shift-Tab), or an app's own `Picker` said it is done.
|
|
58
|
+
* Its own list's picks never close it. */
|
|
58
59
|
onRequestClose: (reason: CloseReason) => void;
|
|
59
60
|
/** The host's words for this panel (fields' messages); default: the provider's conventions. */
|
|
60
61
|
message?: FieldMessageResolver;
|
|
61
62
|
/** Offer a row that adds the typed text when nothing held or offered is it. Default true; a closed
|
|
62
63
|
* vocabulary passes false, and its search only filters what it offers. */
|
|
63
64
|
creatable?: boolean;
|
|
65
|
+
/** The field's name, for an app's own `Picker` (its list's accessible name). Default: the field's
|
|
66
|
+
* placeholder words. */
|
|
67
|
+
label?: string;
|
|
64
68
|
} & import("react").RefAttributes<ChipsEditorHandle>>;
|
|
@@ -3,14 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
4
4
|
import { sameListValue, } from "@viewkitjs/fields";
|
|
5
5
|
import { useViews } from "../provider/context.js";
|
|
6
|
-
|
|
6
|
+
import { PickerFrame, pickerItemOf, typedPick, usePickerForm } from "./picker-slot.js";
|
|
7
|
+
export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions, resolve, normalize, onRequestClose, message, creatable = true, label }, ref) {
|
|
7
8
|
const [draft, setDraft] = useState(values);
|
|
8
9
|
const [search, setSearch] = useState("");
|
|
9
10
|
const inputRef = useRef(null);
|
|
10
11
|
const draftRef = useRef(values);
|
|
11
12
|
const views = useViews();
|
|
12
13
|
const words = message ?? views.conventions.messages;
|
|
13
|
-
const { Command } = views.components;
|
|
14
|
+
const { Command, Picker } = views.components;
|
|
15
|
+
const form = usePickerForm();
|
|
14
16
|
const { List, RowContent, Tag } = views.atoms;
|
|
15
17
|
const Add = views.icons.add;
|
|
16
18
|
const resolveClose = (reason) => {
|
|
@@ -27,6 +29,8 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
|
|
|
27
29
|
setDraft(next);
|
|
28
30
|
};
|
|
29
31
|
useEffect(() => {
|
|
32
|
+
if (Picker)
|
|
33
|
+
return;
|
|
30
34
|
inputRef.current?.focus({ preventScroll: true });
|
|
31
35
|
}, []);
|
|
32
36
|
const clean = (raw) => (normalize ? normalize(raw) : raw.trim());
|
|
@@ -54,6 +58,15 @@ export const ChipsEditor = forwardRef(function ChipsEditor({ values, suggestions
|
|
|
54
58
|
remove(draft[draft.length - 1]);
|
|
55
59
|
}
|
|
56
60
|
};
|
|
61
|
+
if (Picker) {
|
|
62
|
+
const offered = [...suggestions, ...draft.filter((value) => !suggestions.includes(value))];
|
|
63
|
+
return (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: (event) => {
|
|
64
|
+
if (event.key === "Escape")
|
|
65
|
+
onRequestClose("escape");
|
|
66
|
+
}, children: _jsx(Picker, { label: label ?? words({ key: "chips.add-placeholder" }), items: offered.map((value) => pickerItemOf(resolve(value))), multiple: true, value: draft, onValueChange: (next) => setBoth([...new Set(Array.isArray(next) ? next : [])].filter((value) => value !== "" && (creatable || offered.includes(value)))), onDone: () => onRequestClose("pick"), search: words({ key: "chips.add-placeholder" }), onCreate: creatable
|
|
67
|
+
? (typed) => typedPick(clean(typed), [...draftRef.current, ...suggestions], "")
|
|
68
|
+
: undefined, autoFocus: true, form: form }) }));
|
|
69
|
+
}
|
|
57
70
|
return (_jsxs(Command.Root, { shouldFilter: false, loop: true, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-1 border-b border-(color:--vk-border) px-2 py-2", onMouseDown: (event) => {
|
|
58
71
|
if (event.target === event.currentTarget) {
|
|
59
72
|
event.preventDefault();
|
|
@@ -37,4 +37,6 @@ export declare const DateEditor: import("react").ForwardRefExoticComponent<{
|
|
|
37
37
|
message?: FieldMessageResolver;
|
|
38
38
|
/** The calendar takes the panel's whole width (a phone's sheet), rather than its own. Default false. */
|
|
39
39
|
fill?: boolean;
|
|
40
|
+
/** The field's name, for an app's `DateBody`. Default: the date box's words. */
|
|
41
|
+
label?: string;
|
|
40
42
|
} & import("react").RefAttributes<DateEditorHandle>>;
|
|
@@ -4,8 +4,10 @@ import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "r
|
|
|
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
|
+
import { ELEMENT_RESET } from "../internal/reset.js";
|
|
7
8
|
import { useViews } from "../provider/context.js";
|
|
8
9
|
import { isDesktopNow } from "../provider/desktop.js";
|
|
10
|
+
import { usePickerForm } from "./picker-slot.js";
|
|
9
11
|
const QUICK_DAYS = [
|
|
10
12
|
{ key: "date.today", offset: () => 0 },
|
|
11
13
|
{ key: "date.tomorrow", offset: () => 1 },
|
|
@@ -35,17 +37,29 @@ function readStored(iso) {
|
|
|
35
37
|
const parsed = fromDayKey(iso) ?? new Date(iso);
|
|
36
38
|
return Number.isNaN(parsed.getTime()) ? undefined : parsed;
|
|
37
39
|
}
|
|
40
|
+
function readBodyValue(value) {
|
|
41
|
+
const day = fromDayKey(value.slice(0, 10));
|
|
42
|
+
if (!day)
|
|
43
|
+
return null;
|
|
44
|
+
if (value.length === 10)
|
|
45
|
+
return { day, time: null };
|
|
46
|
+
if (value[10] !== "T")
|
|
47
|
+
return null;
|
|
48
|
+
const time = normalizeTime(value.slice(11));
|
|
49
|
+
return time ? { day, time } : null;
|
|
50
|
+
}
|
|
51
|
+
const DATE_BODY_PICKS = ["today", "tomorrow", "next-monday"];
|
|
38
52
|
function initialHasTime(iso, parsed) {
|
|
39
53
|
if (!iso || !parsed)
|
|
40
54
|
return false;
|
|
41
55
|
return /T/.test(iso);
|
|
42
56
|
}
|
|
43
|
-
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, }, ref) {
|
|
57
|
+
export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional = false, dayOnly = false, clearable = false, seed, focusDate = false, onRequestClose, message, fill = false, label, }, ref) {
|
|
44
58
|
const timeRef = useRef(null);
|
|
45
59
|
const dateRef = useRef(null);
|
|
46
60
|
const views = useViews();
|
|
47
61
|
const words = message ?? views.conventions.messages;
|
|
48
|
-
const { Calendar, Input } = views.components;
|
|
62
|
+
const { Calendar, Input, DateBody } = views.components;
|
|
49
63
|
const { List, Row } = views.atoms;
|
|
50
64
|
const DateGlyph = views.icons.date;
|
|
51
65
|
const TimeGlyph = views.icons.time;
|
|
@@ -61,7 +75,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
61
75
|
? ""
|
|
62
76
|
: "00:00";
|
|
63
77
|
const [timeVal, setTimeVal] = useState(initialTime);
|
|
64
|
-
const [dateVal, setDateVal] = useState(() => seed ??
|
|
78
|
+
const [dateVal, setDateVal] = useState(() => seed ?? (valid ? formatChipDate(valid) : ""));
|
|
65
79
|
const touchedRef = useRef(seed != null);
|
|
66
80
|
const dayRef = useRef(valid);
|
|
67
81
|
const dateTextRef = useRef(dateVal);
|
|
@@ -100,8 +114,8 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
100
114
|
box?.setSelectionRange(seed.length, seed.length);
|
|
101
115
|
}, []);
|
|
102
116
|
const applyDateText = () => {
|
|
103
|
-
const
|
|
104
|
-
const typed = parseDateText(dateTextRef.current,
|
|
117
|
+
const current = dayRef.current ?? valid;
|
|
118
|
+
const typed = parseDateText(dateTextRef.current, (current ?? new Date()).getFullYear());
|
|
105
119
|
if (typed) {
|
|
106
120
|
dayRef.current = typed;
|
|
107
121
|
setDay(typed);
|
|
@@ -109,7 +123,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
109
123
|
writeDateText(formatChipDate(typed));
|
|
110
124
|
return typed;
|
|
111
125
|
}
|
|
112
|
-
writeDateText(formatChipDate(
|
|
126
|
+
writeDateText(current ? formatChipDate(current) : "");
|
|
113
127
|
return undefined;
|
|
114
128
|
};
|
|
115
129
|
const resolveClose = (reason) => {
|
|
@@ -140,18 +154,70 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
140
154
|
if (timeOpen)
|
|
141
155
|
activeTimeRef.current?.scrollIntoView({ block: "center" });
|
|
142
156
|
}, [timeOpen]);
|
|
157
|
+
const tabbingRef = useRef(null);
|
|
143
158
|
const onTabOut = (event) => {
|
|
144
159
|
if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
|
|
145
160
|
return;
|
|
146
161
|
const { first, last } = tabEnds(event.currentTarget);
|
|
147
162
|
const leaving = event.shiftKey ? event.target === first : event.target === last;
|
|
148
|
-
if (!leaving)
|
|
163
|
+
if (!leaving) {
|
|
164
|
+
tabbingRef.current = event.shiftKey ? "shift-tab" : "tab";
|
|
165
|
+
setTimeout(() => (tabbingRef.current = null), 0);
|
|
149
166
|
return;
|
|
167
|
+
}
|
|
150
168
|
event.preventDefault();
|
|
151
169
|
event.stopPropagation();
|
|
152
170
|
onRequestClose(event.shiftKey ? "shift-tab" : "tab");
|
|
153
171
|
};
|
|
154
|
-
|
|
172
|
+
const onTabAway = (event) => {
|
|
173
|
+
const via = tabbingRef.current;
|
|
174
|
+
if (!via)
|
|
175
|
+
return;
|
|
176
|
+
const to = event.relatedTarget;
|
|
177
|
+
if (to && event.currentTarget.contains(to))
|
|
178
|
+
return;
|
|
179
|
+
tabbingRef.current = null;
|
|
180
|
+
onRequestClose(via);
|
|
181
|
+
};
|
|
182
|
+
const form = usePickerForm();
|
|
183
|
+
const bodyStart = !valid ? null : dayOnly || !initialTime ? toYmd(valid) : `${toYmd(valid)}T${initialTime}`;
|
|
184
|
+
const [bodyValue, setBodyValue] = useState(bodyStart);
|
|
185
|
+
if (DateBody) {
|
|
186
|
+
const takeBodyValue = (value) => {
|
|
187
|
+
if (value === null) {
|
|
188
|
+
if (!clearable)
|
|
189
|
+
return;
|
|
190
|
+
clearedRef.current = true;
|
|
191
|
+
setBodyValue(null);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const read = readBodyValue(value);
|
|
195
|
+
if (!read)
|
|
196
|
+
return;
|
|
197
|
+
touchedRef.current = true;
|
|
198
|
+
dayRef.current = read.day;
|
|
199
|
+
setDay(read.day);
|
|
200
|
+
setMonth(read.day);
|
|
201
|
+
writeDateText(formatChipDate(read.day));
|
|
202
|
+
if (read.time)
|
|
203
|
+
writeTime(read.time);
|
|
204
|
+
else if (timeOptional)
|
|
205
|
+
writeTime("");
|
|
206
|
+
const time = dayOnly ? null : (read.time ?? (timeOptional ? null : (normalizeTime(timeTextRef.current) ?? initialTime)));
|
|
207
|
+
setBodyValue(time ? `${toYmd(read.day)}T${time}` : toYmd(read.day));
|
|
208
|
+
};
|
|
209
|
+
const onBodyKey = (event) => {
|
|
210
|
+
if (event.key === "Escape" && !event.altKey && !event.ctrlKey && !event.metaKey) {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
event.stopPropagation();
|
|
213
|
+
onRequestClose("escape");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
onTabOut(event);
|
|
217
|
+
};
|
|
218
|
+
return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose("pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...DATE_BODY_PICKS, "none"] : [...DATE_BODY_PICKS], today: toDayKey(new Date()), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
|
|
219
|
+
}
|
|
220
|
+
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) => {
|
|
155
221
|
touchedRef.current = true;
|
|
156
222
|
writeDateText(e.target.value);
|
|
157
223
|
}, onBlur: applyDateText, onFocus: () => setTimeOpen(false), placeholder: words({ key: "date.placeholder" }), "aria-label": words({ key: "date.label" }), onClick: (e) => e.stopPropagation(), onKeyDown: (e) => {
|
|
@@ -193,11 +259,11 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
|
|
|
193
259
|
writeTime(t);
|
|
194
260
|
setTimeOpen(false);
|
|
195
261
|
timeRef.current?.focus();
|
|
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));
|
|
262
|
+
}, 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));
|
|
197
263
|
}) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: QUICK_DAYS.map((quick) => (_jsx("button", { type: "button", onClick: (e) => {
|
|
198
264
|
e.stopPropagation();
|
|
199
265
|
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) => {
|
|
266
|
+
}, 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.key }) }, quick.key))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
|
|
201
267
|
const d = picked ? fromDayKey(picked) : null;
|
|
202
268
|
if (d)
|
|
203
269
|
chooseDay(d);
|
|
@@ -7,12 +7,15 @@ import type { EditSession } from "./edit-session.js";
|
|
|
7
7
|
* stands. The editor inside never reads which.
|
|
8
8
|
*
|
|
9
9
|
* It owns what each surface's dismissals MEAN, so no host decides them: on a desktop the popover's
|
|
10
|
-
* Escape
|
|
10
|
+
* Escape is the session's, a discard unless the field's type keeps (the session's `escape`), save one from
|
|
11
|
+
* an inner level the editor marked (`EDITOR_INNER_ESCAPE`,
|
|
11
12
|
* which the editor closes itself), its outside press is the editor's own rule, and a focus leaving it
|
|
12
13
|
* closes as a blur; on a phone every way a sheet
|
|
13
|
-
* goes away (a swipe, its backdrop, Escape, the
|
|
14
|
+
* goes away (a swipe, its backdrop, Escape, the ✕) discards, and the ✓ closes as done: the ✕ and ✓
|
|
15
|
+
* stand in the panel's own bar, or in the app's Sheet's head when the provider says `sheetActions: "head"`.
|
|
14
16
|
* 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
|
|
17
|
+
* place, the host's own box draws it, and an editor that draws it itself says so
|
|
18
|
+
* (`editorDrawsRefusal`).
|
|
16
19
|
*
|
|
17
20
|
* The surface is chosen ONCE, when the session opens: a window crossing the desktop width
|
|
18
21
|
* mid-edit keeps the panel it opened in until the session ends.
|
|
@@ -45,6 +48,13 @@ export type EditorPanelProps = {
|
|
|
45
48
|
/** A click inside the popover or the sheet. The sheet keeps every press to itself after this; the
|
|
46
49
|
* popover leaves that to the host (a grid host stops it here). */
|
|
47
50
|
onPanelClick?: (event: ReactMouseEvent<HTMLDivElement>) => void;
|
|
51
|
+
/** The editor draws the session's refusal itself (a range with bands, between its boxes and its
|
|
52
|
+
* bands), so the panel draws none under it. Default false. */
|
|
53
|
+
editorDrawsRefusal?: boolean;
|
|
54
|
+
/** The body saves on its pick (a pick of one), so it needs no ✓: an app's Sheet that draws the
|
|
55
|
+
* panel's buttons in its head (the provider's `sheetActions: "head"`) is handed no `done`. The
|
|
56
|
+
* panel's own bar keeps its ✓. Default false. */
|
|
57
|
+
savesOnPick?: boolean;
|
|
48
58
|
/** The editor, or a function of the surface the panel chose, for a type-in host that draws
|
|
49
59
|
* differently in place (its own refusal, say) than in the sheet. */
|
|
50
60
|
children: ReactNode | ((surface: EditorSurface) => ReactNode);
|
|
@@ -58,4 +68,4 @@ export type EditorPanelProps = {
|
|
|
58
68
|
export declare const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
59
69
|
/** Where the panel opened its editor: the app's popover, its sheet, or where the value stands. */
|
|
60
70
|
export type EditorSurface = "popover" | "sheet" | "in-place";
|
|
61
|
-
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, children, ...popover }: EditorPanelProps): ReactNode;
|
|
71
|
+
export declare function EditorPanel({ session, title, anchor, inPlace, sheetOnPhone, snap, panelData, editorDrawsRefusal, savesOnPick, children, ...popover }: EditorPanelProps): ReactNode;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useLayoutEffect, useState, } from "react";
|
|
3
|
+
import { useLayoutEffect, useRef, useState, } from "react";
|
|
4
4
|
import { useDesktop } from "../provider/desktop.js";
|
|
5
5
|
import { useViews } from "../provider/context.js";
|
|
6
6
|
export const EDITOR_INNER_ESCAPE = "data-vk-inner-escape";
|
|
@@ -8,7 +8,7 @@ function innerEscape(event) {
|
|
|
8
8
|
const target = event.target;
|
|
9
9
|
return target instanceof Element && target.closest(`[${EDITOR_INNER_ESCAPE}]`) !== null;
|
|
10
10
|
}
|
|
11
|
-
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, children, ...popover }) {
|
|
11
|
+
export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPhone = false, snap = "auto", panelData, editorDrawsRefusal = false, savesOnPick = false, children, ...popover }) {
|
|
12
12
|
const views = useViews();
|
|
13
13
|
const { Popover, Sheet, Button } = views.components;
|
|
14
14
|
const Discard = views.icons.close;
|
|
@@ -16,6 +16,7 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
16
16
|
const desktop = useDesktop();
|
|
17
17
|
const [surface] = useState(() => desktop ? (inPlace ? "in-place" : "popover") : inPlace && !sheetOnPhone ? "in-place" : "sheet");
|
|
18
18
|
const { open, close, refusal } = session;
|
|
19
|
+
const escapedRef = useRef(false);
|
|
19
20
|
const editor = typeof children === "function" ? children(surface) : children;
|
|
20
21
|
useLayoutEffect(() => {
|
|
21
22
|
if (surface !== "in-place")
|
|
@@ -25,11 +26,15 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
25
26
|
}, []);
|
|
26
27
|
if (surface === "in-place")
|
|
27
28
|
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
|
+
const reason = refusal && !editorDrawsRefusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: "px-2 pb-2 text-xs text-(color:--vk-danger)", children: refusal })) : null;
|
|
29
30
|
if (surface === "popover") {
|
|
30
31
|
return (_jsxs(Popover, { ...popover, open: open, onOpenChange: (next, details) => {
|
|
31
32
|
if (next || details?.reason === "outside-press")
|
|
32
33
|
return;
|
|
34
|
+
if (details?.reason === "escape-key" && escapedRef.current) {
|
|
35
|
+
escapedRef.current = false;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
33
38
|
if (details?.reason === "focus-out")
|
|
34
39
|
close("blur");
|
|
35
40
|
else
|
|
@@ -37,6 +42,10 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
37
42
|
}, anchor: anchor, onEscape: (event) => {
|
|
38
43
|
if (innerEscape(event))
|
|
39
44
|
return false;
|
|
45
|
+
escapedRef.current = true;
|
|
46
|
+
window.setTimeout(() => {
|
|
47
|
+
escapedRef.current = false;
|
|
48
|
+
}, 0);
|
|
40
49
|
close("escape");
|
|
41
50
|
}, onOutsidePress: () => {
|
|
42
51
|
if (open)
|
|
@@ -44,11 +53,19 @@ export function EditorPanel({ session, title, anchor, inPlace = false, sheetOnPh
|
|
|
44
53
|
}, panelData: { "data-slot": "vk-editor-panel", ...panelData }, children: [editor, reason] }));
|
|
45
54
|
}
|
|
46
55
|
const keep = (event) => event.stopPropagation();
|
|
56
|
+
const discardLabel = views.messages({ key: "views.editors.discard" });
|
|
57
|
+
const saveLabel = views.messages({ key: "views.editors.save" });
|
|
58
|
+
const actions = views.sheetActions === "head"
|
|
59
|
+
? {
|
|
60
|
+
close: { label: discardLabel, onPress: () => close("escape") },
|
|
61
|
+
...(!savesOnPick && { done: { label: saveLabel, onPress: () => close("enter") } }),
|
|
62
|
+
}
|
|
63
|
+
: undefined;
|
|
47
64
|
return (_jsx("span", { className: "contents", onClick: (event) => {
|
|
48
65
|
popover.onPanelClick?.(event);
|
|
49
66
|
event.stopPropagation();
|
|
50
67
|
}, onDoubleClick: keep, onContextMenu: keep, children: _jsx(Sheet, { open: open, onOpenChange: (next) => {
|
|
51
68
|
if (!next)
|
|
52
69
|
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":
|
|
70
|
+
}, title: title, ...(typeof title === "string" || typeof title === "number" ? { label: String(title) } : {}), ...(actions && { actions }), snap: snap, children: _jsxs("div", { "data-slot": "vk-editor-panel", children: [actions ? null : (_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": discardLabel, onClick: () => close("escape"), children: _jsx(Discard, { className: "size-4" }) }), _jsx(Button, { variant: "ghost", size: "icon", "aria-label": saveLabel, onClick: () => close("enter"), children: _jsx(Save, { className: "size-4" }) })] })), editor, reason] }) }) }));
|
|
54
71
|
}
|