@viewkitjs/views 0.0.0-stage → 0.1.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 +420 -0
- package/LICENSE.md +7 -0
- package/README.md +50 -2
- package/dist/atoms/CommandMenu.d.ts +2 -0
- package/dist/atoms/CommandMenu.js +20 -0
- package/dist/atoms/List.d.ts +2 -0
- package/dist/atoms/List.js +6 -0
- package/dist/atoms/LoadMore.d.ts +2 -0
- package/dist/atoms/LoadMore.js +25 -0
- package/dist/atoms/Loading.d.ts +2 -0
- package/dist/atoms/Loading.js +7 -0
- package/dist/atoms/PlatformMark.d.ts +2 -0
- package/dist/atoms/PlatformMark.js +4 -0
- package/dist/atoms/RelationLink.d.ts +2 -0
- package/dist/atoms/RelationLink.js +6 -0
- package/dist/atoms/Row.d.ts +3 -0
- package/dist/atoms/Row.js +30 -0
- package/dist/atoms/RowMenu.d.ts +2 -0
- package/dist/atoms/RowMenu.js +101 -0
- package/dist/atoms/StatusBadge.d.ts +2 -0
- package/dist/atoms/StatusBadge.js +7 -0
- package/dist/atoms/StatusMarker.d.ts +2 -0
- package/dist/atoms/StatusMarker.js +19 -0
- package/dist/atoms/Tag.d.ts +2 -0
- package/dist/atoms/Tag.js +13 -0
- package/dist/atoms/TickBox.d.ts +2 -0
- package/dist/atoms/TickBox.js +8 -0
- package/dist/atoms/defaults.d.ts +2 -0
- package/dist/atoms/defaults.js +27 -0
- package/dist/atoms/tones.d.ts +5 -0
- package/dist/atoms/tones.js +28 -0
- package/dist/atoms/types.d.ts +178 -0
- package/dist/atoms/types.js +3 -0
- package/dist/cells/cell-format.d.ts +138 -0
- package/dist/cells/cell-format.js +16 -0
- package/dist/cells/cell-title.d.ts +17 -0
- package/dist/cells/cell-title.js +8 -0
- package/dist/cells/cell-values.d.ts +28 -0
- package/dist/cells/cell-values.js +87 -0
- package/dist/cells/index.d.ts +4 -0
- package/dist/cells/index.js +4 -0
- package/dist/cells/legacy-field.d.ts +52 -0
- package/dist/cells/legacy-field.js +164 -0
- package/dist/cells/relation-wrap.d.ts +3 -0
- package/dist/cells/relation-wrap.js +24 -0
- package/dist/cells/use-cell-format.d.ts +5 -0
- package/dist/cells/use-cell-format.js +10 -0
- package/dist/contract.d.ts +431 -0
- package/dist/contract.js +663 -0
- package/dist/display/actor.d.ts +4 -0
- package/dist/display/actor.js +26 -0
- package/dist/display/boolean.d.ts +18 -0
- package/dist/display/boolean.js +43 -0
- package/dist/display/breakdown.d.ts +15 -0
- package/dist/display/breakdown.js +32 -0
- package/dist/display/currency.d.ts +9 -0
- package/dist/display/currency.js +29 -0
- package/dist/display/date.d.ts +12 -0
- package/dist/display/date.js +26 -0
- package/dist/display/display-cores.d.ts +31 -0
- package/dist/display/display-cores.js +57 -0
- package/dist/display/entity-chip.d.ts +26 -0
- package/dist/display/entity-chip.js +9 -0
- package/dist/display/format.d.ts +51 -0
- package/dist/display/format.js +181 -0
- package/dist/display/index.d.ts +8 -0
- package/dist/display/index.js +7 -0
- package/dist/display/link.d.ts +29 -0
- package/dist/display/link.js +48 -0
- package/dist/display/location.d.ts +7 -0
- package/dist/display/location.js +15 -0
- package/dist/display/multi-value.d.ts +18 -0
- package/dist/display/multi-value.js +28 -0
- package/dist/display/name.d.ts +6 -0
- package/dist/display/name.js +14 -0
- package/dist/display/number.d.ts +11 -0
- package/dist/display/number.js +27 -0
- package/dist/display/options.d.ts +153 -0
- package/dist/display/options.js +1 -0
- package/dist/display/percent.d.ts +4 -0
- package/dist/display/percent.js +33 -0
- package/dist/display/phone.d.ts +10 -0
- package/dist/display/phone.js +38 -0
- package/dist/display/range.d.ts +6 -0
- package/dist/display/range.js +29 -0
- package/dist/display/relation.d.ts +4 -0
- package/dist/display/relation.js +29 -0
- package/dist/display/rich-text.d.ts +10 -0
- package/dist/display/rich-text.js +34 -0
- package/dist/display/select.d.ts +6 -0
- package/dist/display/select.js +38 -0
- package/dist/display/text-class.d.ts +23 -0
- package/dist/display/text-class.js +5 -0
- package/dist/display/text.d.ts +19 -0
- package/dist/display/text.js +8 -0
- package/dist/display/use-display-options.d.ts +2 -0
- package/dist/display/use-display-options.js +14 -0
- package/dist/display/user.d.ts +11 -0
- package/dist/display/user.js +10 -0
- package/dist/display/value-list.d.ts +10 -0
- package/dist/display/value-list.js +12 -0
- package/dist/display/viewer.d.ts +4 -0
- package/dist/display/viewer.js +11 -0
- package/dist/display/web-href.d.ts +8 -0
- package/dist/display/web-href.js +12 -0
- package/dist/editors/ChipsEditor.d.ts +59 -0
- package/dist/editors/ChipsEditor.js +73 -0
- package/dist/editors/DateEditor.d.ts +25 -0
- package/dist/editors/DateEditor.js +122 -0
- package/dist/editors/LocationEditor.d.ts +22 -0
- package/dist/editors/LocationEditor.js +229 -0
- package/dist/editors/NameEditor.d.ts +22 -0
- package/dist/editors/NameEditor.js +91 -0
- package/dist/editors/NumberEditor.d.ts +67 -0
- package/dist/editors/NumberEditor.js +86 -0
- package/dist/editors/RangeEditor.d.ts +22 -0
- package/dist/editors/RangeEditor.js +70 -0
- package/dist/editors/RelationEditor.d.ts +65 -0
- package/dist/editors/RelationEditor.js +64 -0
- package/dist/editors/SelectEditor.d.ts +72 -0
- package/dist/editors/SelectEditor.js +59 -0
- package/dist/editors/ValueListEditor.d.ts +38 -0
- package/dist/editors/ValueListEditor.js +217 -0
- package/dist/editors/edit-cores.d.ts +83 -0
- package/dist/editors/edit-cores.js +38 -0
- package/dist/editors/edit-session.d.ts +74 -0
- package/dist/editors/edit-session.js +35 -0
- package/dist/editors/open-values.d.ts +28 -0
- package/dist/editors/open-values.js +26 -0
- package/dist/editors/relation-source.d.ts +66 -0
- package/dist/editors/relation-source.js +102 -0
- package/dist/fields/binding.d.ts +87 -0
- package/dist/fields/binding.js +117 -0
- package/dist/fields/currency.d.ts +92 -0
- package/dist/fields/currency.js +55 -0
- package/dist/fields/denomination.d.ts +42 -0
- package/dist/fields/denomination.js +11 -0
- package/dist/fields/edit-core-types.d.ts +40 -0
- package/dist/fields/edit-core-types.js +29 -0
- package/dist/fields/format-knobs.d.ts +34 -0
- package/dist/fields/format-knobs.js +36 -0
- package/dist/fields/menus.d.ts +28 -0
- package/dist/fields/menus.js +1 -0
- package/dist/fields/money.d.ts +59 -0
- package/dist/fields/money.js +77 -0
- package/dist/fields/number-edit.d.ts +11 -0
- package/dist/fields/number-edit.js +17 -0
- package/dist/fields/prepare-write.d.ts +55 -0
- package/dist/fields/prepare-write.js +67 -0
- package/dist/fields/relation-source-types.d.ts +54 -0
- package/dist/fields/relation-source-types.js +1 -0
- package/dist/figures.d.ts +52 -0
- package/dist/figures.js +63 -0
- package/dist/filters/date-filter.d.ts +2 -0
- package/dist/filters/date-filter.js +1 -0
- package/dist/filters/filter-model.d.ts +177 -0
- package/dist/filters/filter-model.js +41 -0
- package/dist/filters/number-filter.d.ts +2 -0
- package/dist/filters/number-filter.js +1 -0
- package/dist/filters/range-filter.d.ts +2 -0
- package/dist/filters/range-filter.js +1 -0
- package/dist/filters/registry.d.ts +136 -0
- package/dist/filters/registry.js +46 -0
- package/dist/filters/relation-filter.d.ts +16 -0
- package/dist/filters/relation-filter.js +53 -0
- package/dist/filters/text-filter.d.ts +2 -0
- package/dist/filters/text-filter.js +1 -0
- package/dist/filters/types.d.ts +27 -0
- package/dist/filters/types.js +1 -0
- package/dist/grouping/sort-groups.d.ts +18 -0
- package/dist/grouping/sort-groups.js +33 -0
- package/dist/grouping/types.d.ts +10 -0
- package/dist/grouping/types.js +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -0
- package/dist/internal/chip.d.ts +4 -0
- package/dist/internal/chip.js +3 -0
- package/dist/internal/cx.d.ts +3 -0
- package/dist/internal/cx.js +3 -0
- package/dist/model/aggregates.d.ts +59 -0
- package/dist/model/aggregates.js +186 -0
- package/dist/model/card-density.d.ts +8 -0
- package/dist/model/card-density.js +10 -0
- package/dist/model/card-layout.d.ts +85 -0
- package/dist/model/card-layout.js +90 -0
- package/dist/model/column-capabilities.d.ts +162 -0
- package/dist/model/column-capabilities.js +233 -0
- package/dist/model/column-filters.d.ts +106 -0
- package/dist/model/column-filters.js +321 -0
- package/dist/model/column-format.d.ts +103 -0
- package/dist/model/column-format.js +1 -0
- package/dist/model/column-from.d.ts +28 -0
- package/dist/model/column-from.js +160 -0
- package/dist/model/column-inspect.d.ts +18 -0
- package/dist/model/column-inspect.js +6 -0
- package/dist/model/column-knobs.d.ts +20 -0
- package/dist/model/column-knobs.js +16 -0
- package/dist/model/column-money.d.ts +13 -0
- package/dist/model/column-money.js +27 -0
- package/dist/model/column-order.d.ts +36 -0
- package/dist/model/column-order.js +68 -0
- package/dist/model/column-schema.d.ts +335 -0
- package/dist/model/column-schema.js +1 -0
- package/dist/model/column-sort.d.ts +17 -0
- package/dist/model/column-sort.js +11 -0
- package/dist/model/column-state.d.ts +77 -0
- package/dist/model/column-state.js +95 -0
- package/dist/model/column-types.d.ts +109 -0
- package/dist/model/column-types.js +50 -0
- package/dist/model/column-warnings.d.ts +44 -0
- package/dist/model/column-warnings.js +24 -0
- package/dist/model/density.d.ts +3 -0
- package/dist/model/density.js +13 -0
- package/dist/model/field-type-of.d.ts +21 -0
- package/dist/model/field-type-of.js +11 -0
- package/dist/model/filter-capabilities.d.ts +1 -0
- package/dist/model/filter-capabilities.js +1 -0
- package/dist/model/filter-pushdown.d.ts +106 -0
- package/dist/model/filter-pushdown.js +147 -0
- package/dist/model/index.d.ts +40 -0
- package/dist/model/index.js +21 -0
- package/dist/model/part-rows.d.ts +28 -0
- package/dist/model/part-rows.js +40 -0
- package/dist/model/preferences.d.ts +151 -0
- package/dist/model/preferences.js +84 -0
- package/dist/model/prefs-buckets.d.ts +173 -0
- package/dist/model/prefs-buckets.js +71 -0
- package/dist/model/relation-filters.d.ts +45 -0
- package/dist/model/relation-filters.js +78 -0
- package/dist/model/render-count.d.ts +2 -0
- package/dist/model/render-count.js +24 -0
- package/dist/model/row-icon.d.ts +23 -0
- package/dist/model/row-icon.js +5 -0
- package/dist/model/view-rules.d.ts +73 -0
- package/dist/model/view-rules.js +216 -0
- package/dist/provider/ViewsProvider.d.ts +26 -0
- package/dist/provider/ViewsProvider.js +12 -0
- package/dist/provider/components.d.ts +222 -0
- package/dist/provider/components.js +3 -0
- package/dist/provider/context.d.ts +19 -0
- package/dist/provider/context.js +10 -0
- package/dist/provider/icons.d.ts +6 -0
- package/dist/provider/icons.js +1 -0
- package/dist/provider/ports.d.ts +35 -0
- package/dist/provider/ports.js +8 -0
- package/dist/react.d.ts +9 -0
- package/dist/react.js +4 -0
- package/dist/selection/SelectCheckbox.d.ts +17 -0
- package/dist/selection/SelectCheckbox.js +11 -0
- package/dist/selection/index.d.ts +7 -0
- package/dist/selection/index.js +6 -0
- package/dist/selection/model.d.ts +55 -0
- package/dist/selection/model.js +86 -0
- package/dist/selection/row-click.d.ts +35 -0
- package/dist/selection/row-click.js +20 -0
- package/dist/selection/types.d.ts +17 -0
- package/dist/selection/types.js +1 -0
- package/dist/selection/useCheckDragSelect.d.ts +61 -0
- package/dist/selection/useCheckDragSelect.js +165 -0
- package/dist/selection/useListSelection.d.ts +39 -0
- package/dist/selection/useListSelection.js +48 -0
- package/dist/selection/useListSelectionShortcuts.d.ts +6 -0
- package/dist/selection/useListSelectionShortcuts.js +14 -0
- package/dist/selection/useRestIntent.d.ts +18 -0
- package/dist/selection/useRestIntent.js +35 -0
- package/docs/contract.md +453 -0
- package/docs/install.md +105 -0
- package/docs/reshaping.md +19 -0
- package/package.json +114 -3
- package/skills/views/SKILL.md +87 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
3
|
+
import { type GridCellOptions } from "./cell-format.js";
|
|
4
|
+
/**
|
|
5
|
+
* THE ADAPTER — a column, its row, and the user's overrides, handed to the
|
|
6
|
+
* shared display cores.
|
|
7
|
+
*
|
|
8
|
+
* This file used to BE the renderer: one exhaustive switch, one house treatment
|
|
9
|
+
* per column type. Every one of those treatments now lives in
|
|
10
|
+
* the display, keyed by STORAGE type rather than by column type, so
|
|
11
|
+
* the grid, the board, the calendar and (next) the detail panel draw a value
|
|
12
|
+
* the same way instead of four times. What is left here is the translation, and
|
|
13
|
+
* it is only three sentences long:
|
|
14
|
+
*
|
|
15
|
+
* 1. the value — the pending override, else the column's accessor;
|
|
16
|
+
* 2. the field — the module's registry def, else one synthesized from the
|
|
17
|
+
* column (`legacyFieldFromColumn`);
|
|
18
|
+
* 3. the options — what a field cannot know, which is everything the ROW and
|
|
19
|
+
* the USER contribute.
|
|
20
|
+
*
|
|
21
|
+
* `title` is a column ROLE, not a storage type (see `cell-title.tsx`): its cell
|
|
22
|
+
* is the list's, and only a figure's or a moment's identity reaches a core for
|
|
23
|
+
* its content (`identityContent`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function renderTypedCellValue<Row>(col: ListColumn<Row>, row: Row, opts?: GridCellOptions): ReactNode;
|
|
26
|
+
/** An identity's value without the title cell — for a host that draws the name in its own chrome
|
|
27
|
+
* (the rows look's phone card). Empty draws nothing, as every typed cell does. */
|
|
28
|
+
export declare function renderIdentityValue<Row>(col: ListColumn<Row>, row: Row, opts?: GridCellOptions): ReactNode;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { valueTypeOf } from "@viewkitjs/fields";
|
|
4
|
+
import { renderFieldValue } from "../display/display-cores.js";
|
|
5
|
+
import { columnLabel } from "../model/column-capabilities.js";
|
|
6
|
+
import { prettifyOptionValue } from "../model/column-state.js";
|
|
7
|
+
import { useViews } from "../provider/context.js";
|
|
8
|
+
import { renderTitleCell } from "./cell-title.js";
|
|
9
|
+
import { resolveRowCurrency } from "./cell-format.js";
|
|
10
|
+
import { legacyFieldFromColumn } from "./legacy-field.js";
|
|
11
|
+
import { listRelationWrap } from "./relation-wrap.js";
|
|
12
|
+
export function renderTypedCellValue(col, row, opts) {
|
|
13
|
+
const value = opts?.valueOverride !== undefined ? opts.valueOverride : col.accessor?.(row);
|
|
14
|
+
if (col.type !== "boolean" &&
|
|
15
|
+
!hasNameFallback(col, row) &&
|
|
16
|
+
(value == null || value === "" || (Array.isArray(value) && value.length === 0))) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (!col.type)
|
|
20
|
+
return null;
|
|
21
|
+
if (col.type === "title")
|
|
22
|
+
return renderTitleCell(col, row, identityContent(col, row, value, opts), opts);
|
|
23
|
+
const field = col.field ?? legacyFieldFromColumn(col);
|
|
24
|
+
const cell = renderFieldValue(field, value, displayOptionsFor(col, row, opts));
|
|
25
|
+
if (col.command && opts?.commandItems?.length) {
|
|
26
|
+
return _jsx(CommandCell, { col: col, cell: cell, items: opts.commandItems });
|
|
27
|
+
}
|
|
28
|
+
return cell;
|
|
29
|
+
}
|
|
30
|
+
const TITLE_THROUGH_CORE = new Set(["number", "percent", "currency", "date", "datetime", "name"]);
|
|
31
|
+
function identityContent(col, row, value, opts) {
|
|
32
|
+
return col.field && TITLE_THROUGH_CORE.has(valueTypeOf(col.field))
|
|
33
|
+
? renderFieldValue(col.field, value, displayOptionsFor(col, row, opts))
|
|
34
|
+
: String(value);
|
|
35
|
+
}
|
|
36
|
+
export function renderIdentityValue(col, row, opts) {
|
|
37
|
+
const value = opts?.valueOverride !== undefined ? opts.valueOverride : col.accessor?.(row);
|
|
38
|
+
if ((value == null || value === "") && !hasNameFallback(col, row))
|
|
39
|
+
return null;
|
|
40
|
+
return identityContent(col, row, value, opts);
|
|
41
|
+
}
|
|
42
|
+
function hasNameFallback(col, row) {
|
|
43
|
+
return !!col.field && valueTypeOf(col.field) === "name" && !!col.nameFallback?.(row);
|
|
44
|
+
}
|
|
45
|
+
const CONTROL_VALUES = new Set([
|
|
46
|
+
"relation",
|
|
47
|
+
"user",
|
|
48
|
+
"url",
|
|
49
|
+
"email",
|
|
50
|
+
"phone",
|
|
51
|
+
"domain",
|
|
52
|
+
]);
|
|
53
|
+
function CommandCell({ col, cell, items, }) {
|
|
54
|
+
const { atoms, icons } = useViews();
|
|
55
|
+
const { CommandMenu } = atoms;
|
|
56
|
+
const Chevron = icons.chevronDown;
|
|
57
|
+
const verbs = items.map((item) => ({ ...item }));
|
|
58
|
+
if (CONTROL_VALUES.has(col.type)) {
|
|
59
|
+
return (_jsxs("span", { className: "flex min-w-0 items-center gap-1", children: [cell, _jsx(CommandMenu, { items: verbs, align: "start", trigger: _jsx("button", { type: "button", "aria-label": columnLabel(col), className: "shrink-0 -m-1 p-1", children: _jsx(Chevron, { className: "h-3 w-3 opacity-60" }) }) })] }));
|
|
60
|
+
}
|
|
61
|
+
return (_jsx(CommandMenu, { items: verbs, align: "start", trigger: _jsxs("button", { type: "button", "aria-label": columnLabel(col), className: "flex min-w-0 items-center gap-1 text-left", children: [cell, _jsx(Chevron, { className: "h-3 w-3 opacity-60" })] }) }));
|
|
62
|
+
}
|
|
63
|
+
function displayOptionsFor(col, row, opts) {
|
|
64
|
+
const resolved = resolveRowCurrency(col, row, opts);
|
|
65
|
+
return {
|
|
66
|
+
presentation: opts?.presentation,
|
|
67
|
+
viewer: opts?.viewer,
|
|
68
|
+
optionColors: opts?.optionColors,
|
|
69
|
+
labelFallback: col.field ? undefined : prettifyOptionValue,
|
|
70
|
+
dateStyle: opts?.dateStyle,
|
|
71
|
+
durationStyle: opts?.durationStyle,
|
|
72
|
+
decimals: opts?.decimals,
|
|
73
|
+
currency: resolved?.currency,
|
|
74
|
+
nameFallback: col.nameFallback?.(row) ?? undefined,
|
|
75
|
+
withTime: opts?.withTime,
|
|
76
|
+
percentDisplay: opts?.percentDisplay,
|
|
77
|
+
wrap: opts?.wrap,
|
|
78
|
+
booleanIcon: col.format?.icon,
|
|
79
|
+
marker: col.marker,
|
|
80
|
+
markerReason: opts?.markerReason,
|
|
81
|
+
onResolve: opts?.onResolve,
|
|
82
|
+
onToggle: opts?.onToggle,
|
|
83
|
+
entityIcon: opts?.entityIcon,
|
|
84
|
+
slotOwnsClick: opts?.slotOwnsClick,
|
|
85
|
+
relationWrap: listRelationWrap(opts),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { renderIdentityValue, renderTypedCellValue } from "./cell-values.js";
|
|
2
|
+
export { formatDate, formatNumber, resolveRowCurrency, type GridCellOptions } from "./cell-format.js";
|
|
3
|
+
export { useCellFormat } from "./use-cell-format.js";
|
|
4
|
+
export { legacyFieldFromColumn, legacyNumberLikeFormat } from "./legacy-field.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { renderIdentityValue, renderTypedCellValue } from "./cell-values.js";
|
|
2
|
+
export { formatDate, formatNumber, resolveRowCurrency } from "./cell-format.js";
|
|
3
|
+
export { useCellFormat } from "./use-cell-format.js";
|
|
4
|
+
export { legacyFieldFromColumn, legacyNumberLikeFormat } from "./legacy-field.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type CurrencyFormat, type FieldDef, type NumberFormat } from "@viewkitjs/fields";
|
|
2
|
+
import type { NumberLikeFormat } from "../display/options.js";
|
|
3
|
+
import type { ListColumn } from "../model/column-schema.js";
|
|
4
|
+
import type { ListColumnFormat } from "../model/column-format.js";
|
|
5
|
+
/**
|
|
6
|
+
* A COLUMN THAT PREDATES THE REGISTRY, READ AS A FIELD.
|
|
7
|
+
*
|
|
8
|
+
* `columnFrom` turns a field into a column; this is the other direction, for the
|
|
9
|
+
* hundreds of columns no module has bound yet. It exists so there is ONE
|
|
10
|
+
* rendering path rather than two: the adapter hands every column a `FieldDef`,
|
|
11
|
+
* and the display cores read the value's type, vocabulary and format off that
|
|
12
|
+
* def whether a registry wrote it or this file did.
|
|
13
|
+
*
|
|
14
|
+
* DISPLAY ONLY. The synthesized def carries what a core reads and nothing else —
|
|
15
|
+
* no write policy, no validation, no `normalize`. A column's editability is
|
|
16
|
+
* still the column's own answer (`gridColumnHasEditor`), because a def invented
|
|
17
|
+
* here has no binding behind it and nothing to commit through.
|
|
18
|
+
*
|
|
19
|
+
* The mapping is the IDENTITY on the type: `ListColumnType` is the value-type
|
|
20
|
+
* vocabulary plus the one role, so every arm below returns the def of the same
|
|
21
|
+
* name. The bridge's job is filling what a field REQUIRES and a column never
|
|
22
|
+
* had to declare — a label, a status option's slot, a select's empty
|
|
23
|
+
* vocabulary, a currency's code. The one arm that cannot be symmetric:
|
|
24
|
+
* - `title` throws. It is a column ROLE (this cell opens the row), not a
|
|
25
|
+
* storage type, so the list keeps drawing it and never asks for a def.
|
|
26
|
+
*/
|
|
27
|
+
export declare function legacyFieldFromColumn<Row>(col: ListColumn<Row>): FieldDef;
|
|
28
|
+
/**
|
|
29
|
+
* A NUMBER field's format — plain or duration. Percent and currency are types,
|
|
30
|
+
* so they leave through `legacyFieldFromColumn`'s own arms and never reach
|
|
31
|
+
* here.
|
|
32
|
+
*
|
|
33
|
+
* ONE cast, and it is `signed` / `signedTone` on a duration: `NumberFormat`
|
|
34
|
+
* declares them on the plain variant only, while a list column may pair them
|
|
35
|
+
* with any style. The readers reach those knobs through `in` checks, so a
|
|
36
|
+
* variant carrying them reads correctly; it is the union that cannot spell it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function legacyNumberFormat(format: ListColumnFormat | undefined): NumberFormat | undefined;
|
|
39
|
+
/** A CURRENCY field's format: the knobs minus the code, which is `code.fixed`. */
|
|
40
|
+
export declare function legacyCurrencyFormat(format: ListColumnFormat | undefined): CurrencyFormat;
|
|
41
|
+
/**
|
|
42
|
+
* The column's number format in the DISPLAY layer's wider vocabulary — the one
|
|
43
|
+
* shape `formatNumberValue` prints, percent and currency included. Read off
|
|
44
|
+
* the column's TYPE (a bound column's field, a field-less column's own), so a
|
|
45
|
+
* percent or currency column prints as one whatever its `format` says.
|
|
46
|
+
*
|
|
47
|
+
* Exported because `cell-format.ts` needs this translation for the three
|
|
48
|
+
* consumers that hold a column rather than a field (the footer aggregates and
|
|
49
|
+
* the column menu's two live previews) — one mapping, so a cell and its own
|
|
50
|
+
* column total can never print the same number two ways.
|
|
51
|
+
*/
|
|
52
|
+
export declare function legacyNumberLikeFormat(col: ListColumn<never>): NumberLikeFormat | undefined;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { FieldDefinitionError, } from "@viewkitjs/fields";
|
|
2
|
+
import { columnLabel } from "../model/column-capabilities.js";
|
|
3
|
+
import { prettifyOptionValue } from "../model/column-state.js";
|
|
4
|
+
import { fieldTypeOf } from "../model/field-type-of.js";
|
|
5
|
+
export function legacyFieldFromColumn(col) {
|
|
6
|
+
const base = { key: col.id, label: columnLabel(col) };
|
|
7
|
+
if (!col.type) {
|
|
8
|
+
throw new FieldDefinitionError(col.id, "has no column type, so there is no storage type to synthesize a field from");
|
|
9
|
+
}
|
|
10
|
+
switch (col.type) {
|
|
11
|
+
case "title":
|
|
12
|
+
throw new FieldDefinitionError(col.id, "a title is a column ROLE, not a storage type — the list draws it and synthesizes no field");
|
|
13
|
+
case "text":
|
|
14
|
+
return { ...base, type: "text", ...(col.format?.long && { format: { long: true } }) };
|
|
15
|
+
case "url":
|
|
16
|
+
return { ...base, type: "url", ...(col.multiple && { multiple: true }) };
|
|
17
|
+
case "domain":
|
|
18
|
+
return { ...base, type: "domain", ...(col.multiple && { multiple: true }) };
|
|
19
|
+
case "email":
|
|
20
|
+
return { ...base, type: "email", ...(col.multiple && { multiple: true }) };
|
|
21
|
+
case "relation":
|
|
22
|
+
return {
|
|
23
|
+
...base,
|
|
24
|
+
type: "relation",
|
|
25
|
+
relation: { kind: (col.relation?.entity ?? "") },
|
|
26
|
+
};
|
|
27
|
+
case "select":
|
|
28
|
+
return { ...base, type: "select", options: optionsOf(col.options) };
|
|
29
|
+
case "status":
|
|
30
|
+
return { ...base, type: "status", options: statusOptionsOf(col.options) };
|
|
31
|
+
case "multiselect":
|
|
32
|
+
return {
|
|
33
|
+
...base,
|
|
34
|
+
type: "multiselect",
|
|
35
|
+
vocabulary: "custom-values",
|
|
36
|
+
...(col.options && { options: optionsOf(col.options) }),
|
|
37
|
+
};
|
|
38
|
+
case "boolean": {
|
|
39
|
+
const options = booleanOptions(col.options);
|
|
40
|
+
return {
|
|
41
|
+
...base,
|
|
42
|
+
type: "boolean",
|
|
43
|
+
...(col.format?.booleanDisplay && { format: { style: col.format.booleanDisplay } }),
|
|
44
|
+
...(options && { options }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case "date":
|
|
48
|
+
return {
|
|
49
|
+
...base,
|
|
50
|
+
type: "date",
|
|
51
|
+
...(col.format?.dateStyle && { format: { dateStyle: col.format.dateStyle } }),
|
|
52
|
+
};
|
|
53
|
+
case "datetime": {
|
|
54
|
+
const format = dateFormatOf(col.format);
|
|
55
|
+
return { ...base, type: "datetime", ...(format && { format }) };
|
|
56
|
+
}
|
|
57
|
+
case "percent":
|
|
58
|
+
return {
|
|
59
|
+
...base,
|
|
60
|
+
type: "percent",
|
|
61
|
+
...((col.format?.decimals !== undefined || col.format?.percentDisplay) && {
|
|
62
|
+
format: {
|
|
63
|
+
...(col.format?.decimals !== undefined && { decimals: col.format.decimals }),
|
|
64
|
+
...(col.format?.percentDisplay && { display: col.format.percentDisplay }),
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
case "currency":
|
|
69
|
+
return {
|
|
70
|
+
...base,
|
|
71
|
+
type: "currency",
|
|
72
|
+
code: { fixed: col.format?.currency ?? "EUR" },
|
|
73
|
+
format: legacyCurrencyFormat(col.format),
|
|
74
|
+
};
|
|
75
|
+
case "user":
|
|
76
|
+
return { ...base, type: "user" };
|
|
77
|
+
case "phone":
|
|
78
|
+
return { ...base, type: "phone", ...(col.multiple && { multiple: true }) };
|
|
79
|
+
case "location":
|
|
80
|
+
return { ...base, type: "location" };
|
|
81
|
+
case "name":
|
|
82
|
+
return { ...base, type: "name" };
|
|
83
|
+
case "actor":
|
|
84
|
+
return { ...base, type: "actor" };
|
|
85
|
+
case "rich_text":
|
|
86
|
+
return { ...base, type: "rich_text" };
|
|
87
|
+
case "range":
|
|
88
|
+
return { ...base, type: "range", of: "number" };
|
|
89
|
+
case "number": {
|
|
90
|
+
const format = legacyNumberFormat(col.format);
|
|
91
|
+
return { ...base, type: "number", ...(format && { format }) };
|
|
92
|
+
}
|
|
93
|
+
default: {
|
|
94
|
+
const unhandled = col.type;
|
|
95
|
+
throw new FieldDefinitionError(col.id, `has an unmapped column type (${String(unhandled)}) — no field can be synthesized from it`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function optionsOf(options) {
|
|
100
|
+
return (options ?? []).map((option) => ({
|
|
101
|
+
...option,
|
|
102
|
+
label: option.label ?? prettifyOptionValue(option.value),
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
function statusOptionsOf(options) {
|
|
106
|
+
return optionsOf(options).map((option) => ({ ...option, slot: option.slot ?? "muted" }));
|
|
107
|
+
}
|
|
108
|
+
function booleanOptions(options) {
|
|
109
|
+
const on = options?.find((option) => option.value === "true");
|
|
110
|
+
const off = options?.find((option) => option.value === "false");
|
|
111
|
+
if (!on && !off)
|
|
112
|
+
return undefined;
|
|
113
|
+
return [
|
|
114
|
+
{ ...on, value: "true", label: on?.label ?? "Yes" },
|
|
115
|
+
{ ...off, value: "false", label: off?.label ?? "No" },
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
function dateFormatOf(format) {
|
|
119
|
+
const out = {
|
|
120
|
+
...(format?.dateStyle && { dateStyle: format.dateStyle }),
|
|
121
|
+
...(format?.withTime !== undefined && { withTime: format.withTime }),
|
|
122
|
+
};
|
|
123
|
+
return Object.keys(out).length ? out : undefined;
|
|
124
|
+
}
|
|
125
|
+
function numberKnobs(format) {
|
|
126
|
+
return {
|
|
127
|
+
...(format.decimals !== undefined && { decimals: format.decimals }),
|
|
128
|
+
...(format.suffix !== undefined && { suffix: format.suffix }),
|
|
129
|
+
...(format.signed !== undefined && { signed: format.signed }),
|
|
130
|
+
...(format.signedTone !== undefined && { signedTone: format.signedTone }),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function legacyNumberFormat(format) {
|
|
134
|
+
if (!format)
|
|
135
|
+
return undefined;
|
|
136
|
+
const knobs = numberKnobs(format);
|
|
137
|
+
if (format.style === "duration") {
|
|
138
|
+
return {
|
|
139
|
+
...knobs,
|
|
140
|
+
style: "duration",
|
|
141
|
+
...(format.unit && { unit: format.unit }),
|
|
142
|
+
...(format.durationStyle && { durationStyle: format.durationStyle }),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return { ...knobs, style: "plain" };
|
|
146
|
+
}
|
|
147
|
+
export function legacyCurrencyFormat(format) {
|
|
148
|
+
return format ? numberKnobs(format) : {};
|
|
149
|
+
}
|
|
150
|
+
export function legacyNumberLikeFormat(col) {
|
|
151
|
+
const format = col.format;
|
|
152
|
+
switch (fieldTypeOf(col)) {
|
|
153
|
+
case "percent":
|
|
154
|
+
return { style: "percent", ...(format ? numberKnobs(format) : {}) };
|
|
155
|
+
case "currency":
|
|
156
|
+
return {
|
|
157
|
+
style: "currency",
|
|
158
|
+
currency: format?.currency ?? "EUR",
|
|
159
|
+
...(format ? numberKnobs(format) : {}),
|
|
160
|
+
};
|
|
161
|
+
default:
|
|
162
|
+
return legacyNumberFormat(format);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CHIP_INTERACTIVE } from "../internal/chip.js";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
export function listRelationWrap(opts) {
|
|
6
|
+
if (opts?.slotOwnsClick)
|
|
7
|
+
return undefined;
|
|
8
|
+
const onOpenRelation = opts?.onOpenRelation;
|
|
9
|
+
if (onOpenRelation) {
|
|
10
|
+
return function openRelationWrap(relation, chip) {
|
|
11
|
+
return (_jsx("button", { type: "button", "data-no-nav": true, title: relation.label, onClick: (event) => {
|
|
12
|
+
event.stopPropagation();
|
|
13
|
+
onOpenRelation(relation);
|
|
14
|
+
}, className: CHIP_INTERACTIVE, children: chip }));
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return function appRelationWrap(relation, chip) {
|
|
18
|
+
return _jsx(AppRelationLink, { relation: relation, children: chip });
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function AppRelationLink({ relation, children }) {
|
|
22
|
+
const { RelationLink } = useViews().atoms;
|
|
23
|
+
return _jsx(RelationLink, { relation: relation, children: children });
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { DEFAULT_FIELD_PRESENTATION } from "../display/format.js";
|
|
4
|
+
import { viewerFrom } from "../display/viewer.js";
|
|
5
|
+
import { useViews } from "../provider/context.js";
|
|
6
|
+
export function useCellFormat() {
|
|
7
|
+
const { conventions, messages, presentation } = useViews();
|
|
8
|
+
const applied = useMemo(() => presentation?.(DEFAULT_FIELD_PRESENTATION), [presentation]);
|
|
9
|
+
return { viewer: viewerFrom(conventions, messages), presentation: applied };
|
|
10
|
+
}
|