@viewkitjs/views 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +571 -0
- package/README.md +5 -3
- package/dist/atoms/LoadMore.js +11 -1
- package/dist/atoms/RowMenu.js +5 -2
- package/dist/cells/cell-format.d.ts +3 -3
- package/dist/cells/cell-title.d.ts +1 -2
- package/dist/cells/cell-title.js +2 -2
- package/dist/cells/cell-values.js +6 -3
- package/dist/contract.d.ts +50 -9
- package/dist/contract.js +33 -5
- package/dist/display/converted.d.ts +19 -0
- package/dist/display/converted.js +12 -0
- package/dist/display/index.d.ts +1 -0
- package/dist/display/index.js +1 -0
- package/dist/display/link-click.d.ts +11 -0
- package/dist/display/link-click.js +3 -0
- package/dist/display/link.js +7 -3
- package/dist/display/multi-value.d.ts +1 -1
- package/dist/display/multi-value.js +1 -1
- package/dist/display/options.d.ts +7 -1
- package/dist/display/phone.js +3 -1
- package/dist/editors/ChipsEditor.d.ts +9 -4
- package/dist/editors/ChipsEditor.js +6 -2
- package/dist/editors/DateEditor.d.ts +21 -6
- package/dist/editors/DateEditor.js +118 -30
- package/dist/editors/EditorPanel.d.ts +61 -0
- package/dist/editors/EditorPanel.js +54 -0
- package/dist/editors/LocationEditor.d.ts +3 -0
- package/dist/editors/LocationEditor.js +14 -6
- package/dist/editors/NameEditor.d.ts +3 -0
- package/dist/editors/NameEditor.js +11 -7
- package/dist/editors/NumberEditor.d.ts +3 -0
- package/dist/editors/NumberEditor.js +6 -6
- package/dist/editors/RangeEditor.d.ts +16 -1
- package/dist/editors/RangeEditor.js +21 -5
- package/dist/editors/RelationEditor.d.ts +13 -28
- package/dist/editors/RelationEditor.js +17 -40
- package/dist/editors/RelationSetEditor.d.ts +53 -0
- package/dist/editors/RelationSetEditor.js +112 -0
- package/dist/editors/SelectEditor.d.ts +21 -3
- package/dist/editors/SelectEditor.js +55 -9
- package/dist/editors/TextEditor.d.ts +51 -0
- package/dist/editors/TextEditor.js +81 -0
- package/dist/editors/ValueListEditor.d.ts +3 -0
- package/dist/editors/ValueListEditor.js +4 -2
- package/dist/editors/edit-cores.d.ts +12 -9
- package/dist/editors/edit-cores.js +7 -6
- package/dist/editors/edit-session.d.ts +21 -11
- package/dist/editors/edit-session.js +19 -5
- package/dist/editors/keep-inside.d.ts +12 -0
- package/dist/editors/keep-inside.js +20 -0
- package/dist/editors/open-value.d.ts +21 -0
- package/dist/editors/open-value.js +36 -0
- package/dist/editors/open-values.d.ts +4 -0
- package/dist/editors/open-values.js +7 -0
- package/dist/editors/relation-kinds.d.ts +7 -0
- package/dist/editors/relation-kinds.js +21 -0
- package/dist/editors/relation-panel.d.ts +69 -0
- package/dist/editors/relation-panel.js +40 -0
- package/dist/field-row/FieldNoteLine.d.ts +14 -0
- package/dist/field-row/FieldNoteLine.js +14 -0
- package/dist/field-row/FieldRow.d.ts +73 -0
- package/dist/field-row/FieldRow.js +157 -0
- package/dist/field-row/FieldRowLane.d.ts +19 -0
- package/dist/field-row/FieldRowLane.js +11 -0
- package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
- package/dist/field-row/editors/RowChipsEditor.js +25 -0
- package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
- package/dist/field-row/editors/RowDateEditor.js +18 -0
- package/dist/field-row/editors/RowEditor.d.ts +39 -0
- package/dist/field-row/editors/RowEditor.js +64 -0
- package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
- package/dist/field-row/editors/RowNameEditor.js +15 -0
- package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
- package/dist/field-row/editors/RowNumberEditor.js +18 -0
- package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
- package/dist/field-row/editors/RowPlaceEditor.js +18 -0
- package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
- package/dist/field-row/editors/RowRangeEditor.js +15 -0
- package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
- package/dist/field-row/editors/RowRelationEditor.js +77 -0
- package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
- package/dist/field-row/editors/RowSelectEditor.js +23 -0
- package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
- package/dist/field-row/editors/RowTextEditor.js +16 -0
- package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
- package/dist/field-row/editors/RowValueListEditor.js +21 -0
- package/dist/field-row/editors/host.d.ts +59 -0
- package/dist/field-row/editors/host.js +1 -0
- package/dist/field-row/editors/row-session.d.ts +49 -0
- package/dist/field-row/editors/row-session.js +49 -0
- package/dist/field-row/index.d.ts +5 -0
- package/dist/field-row/index.js +5 -0
- package/dist/field-row/row-target.d.ts +20 -0
- package/dist/field-row/row-target.js +3 -0
- package/dist/field-row/useFieldWrite.d.ts +45 -0
- package/dist/field-row/useFieldWrite.js +190 -0
- package/dist/field-row/useRowSettlement.d.ts +33 -0
- package/dist/field-row/useRowSettlement.js +23 -0
- package/dist/fields/binding.d.ts +6 -1
- package/dist/fields/binding.js +13 -6
- package/dist/fields/edit-core-types.d.ts +9 -9
- package/dist/fields/edit-core-types.js +6 -6
- package/dist/fields/money.d.ts +5 -0
- package/dist/fields/money.js +10 -0
- package/dist/fields/number-edit.d.ts +6 -0
- package/dist/fields/number-edit.js +4 -0
- package/dist/fields/prepare-write.js +6 -1
- package/dist/fields/relation-source-types.d.ts +12 -0
- package/dist/fields/write-target.d.ts +50 -0
- package/dist/fields/write-target.js +10 -0
- package/dist/grid/chrome/GridAddColumn.js +1 -1
- package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
- package/dist/grid/chrome/GridAggregateMenu.js +8 -6
- package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
- package/dist/grid/chrome/GridCellEditors.js +87 -16
- package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
- package/dist/grid/chrome/GridCellOutline.js +2 -7
- package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
- package/dist/grid/chrome/GridChipsEditor.js +21 -26
- package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
- package/dist/grid/chrome/GridColumnMenu.js +7 -3
- package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
- package/dist/grid/chrome/GridDateEditor.js +13 -25
- package/dist/grid/chrome/GridFooter.d.ts +12 -2
- package/dist/grid/chrome/GridFooter.js +10 -6
- package/dist/grid/chrome/GridGroupMenu.js +20 -13
- package/dist/grid/chrome/GridHeader.d.ts +9 -4
- package/dist/grid/chrome/GridHeader.js +15 -10
- package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
- package/dist/grid/chrome/GridLongTextEditor.js +16 -74
- package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
- package/dist/grid/chrome/GridNameEditor.js +12 -27
- package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
- package/dist/grid/chrome/GridNumberEditor.js +46 -20
- package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
- package/dist/grid/chrome/GridPlaceEditor.js +22 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
- package/dist/grid/chrome/GridRangeEditor.js +16 -20
- package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
- package/dist/grid/chrome/GridRelationEditor.js +86 -24
- package/dist/grid/chrome/GridRow.d.ts +7 -1
- package/dist/grid/chrome/GridRow.js +57 -14
- package/dist/grid/chrome/GridRowActions.js +1 -1
- package/dist/grid/chrome/GridRowCells.js +18 -23
- package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
- package/dist/grid/chrome/GridSelectEditor.js +21 -27
- package/dist/grid/chrome/GridStructure.d.ts +9 -10
- package/dist/grid/chrome/GridStructure.js +10 -14
- package/dist/grid/chrome/GridTable.js +97 -30
- package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
- package/dist/grid/chrome/GridTableSurface.js +12 -3
- package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
- package/dist/grid/chrome/GridTextEditor.js +35 -37
- package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
- package/dist/grid/chrome/GridValueListEditor.js +10 -27
- package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
- package/dist/grid/chrome/cell-cut-off.js +20 -0
- package/dist/grid/chrome/cells.js +1 -2
- package/dist/grid/chrome/checks.d.ts +2 -5
- package/dist/grid/chrome/checks.js +15 -5
- package/dist/grid/chrome/editors.d.ts +1 -1
- package/dist/grid/chrome/editors.js +1 -1
- package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
- package/dist/grid/chrome/grid-cell-classes.js +10 -8
- package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
- package/dist/grid/chrome/grid-cell-link.js +9 -0
- package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
- package/dist/grid/chrome/grid-edit-session.js +118 -0
- package/dist/grid/chrome/grid-hover.d.ts +60 -0
- package/dist/grid/chrome/grid-hover.js +81 -0
- package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
- package/dist/grid/chrome/grid-menu-focus.js +93 -0
- package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
- package/dist/grid/chrome/grid-row-menu-key.js +36 -0
- package/dist/grid/chrome/grid-row-props.d.ts +16 -4
- package/dist/grid/chrome/grid-row-window.d.ts +61 -0
- package/dist/grid/chrome/grid-row-window.js +212 -0
- package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
- package/dist/grid/chrome/grid-scroll-owner.js +75 -0
- package/dist/grid/chrome/grid-styles.d.ts +4 -1
- package/dist/grid/chrome/grid-styles.js +1 -0
- package/dist/grid/chrome/grid-table-props.d.ts +2 -3
- package/dist/grid/chrome/useGridFocus.d.ts +45 -0
- package/dist/grid/chrome/useGridFocus.js +122 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
- package/dist/grid/chrome/useGridKeyboard.js +214 -38
- package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
- package/dist/grid/chrome/useGridRangeActions.js +17 -10
- package/dist/grid/chrome/useGridRangeGestures.js +68 -21
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
- package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
- package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
- package/dist/grid/chrome/useGridScaleStyles.js +6 -7
- package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
- package/dist/grid/chrome/useGridScrollArea.js +65 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
- package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
- package/dist/grid/core/clipboard-model.d.ts +2 -0
- package/dist/grid/core/clipboard-model.js +1 -1
- package/dist/grid/core/commit-model.d.ts +7 -0
- package/dist/grid/core/edge-scroll.d.ts +21 -0
- package/dist/grid/core/edge-scroll.js +23 -0
- package/dist/grid/core/editing-controller.d.ts +2 -1
- package/dist/grid/core/editing-controller.js +35 -9
- package/dist/grid/core/editing-model.d.ts +9 -0
- package/dist/grid/core/editing-model.js +12 -0
- package/dist/grid/core/flat-rows.d.ts +35 -0
- package/dist/grid/core/flat-rows.js +20 -0
- package/dist/grid/core/grid-aria.d.ts +27 -0
- package/dist/grid/core/grid-aria.js +39 -0
- package/dist/grid/core/grid-focus.d.ts +54 -0
- package/dist/grid/core/grid-focus.js +148 -0
- package/dist/grid/core/nav.d.ts +2 -2
- package/dist/grid/core/pending-reconciliation.d.ts +3 -0
- package/dist/grid/core/pending-reconciliation.js +5 -3
- package/dist/grid/core/row-window.d.ts +40 -0
- package/dist/grid/core/row-window.js +43 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
- package/dist/grid/core/spreadsheet-operations.js +33 -6
- package/dist/grid/core/useGridEditing.d.ts +3 -0
- package/dist/grid/core/useGridEditing.js +6 -3
- package/dist/grid/core/value-equality.d.ts +23 -1
- package/dist/grid/core/value-equality.js +46 -0
- package/dist/grid/useGridTablePrefs.d.ts +0 -1
- package/dist/grid/useGridTablePrefs.js +1 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/viewport.d.ts +0 -2
- package/dist/internal/viewport.js +0 -14
- package/dist/model/column-capabilities.d.ts +2 -1
- package/dist/model/column-capabilities.js +28 -8
- package/dist/model/column-from.js +3 -0
- package/dist/model/column-inspect.d.ts +10 -2
- package/dist/model/column-inspect.js +9 -0
- package/dist/model/column-schema.d.ts +6 -1
- package/dist/model/column-types.d.ts +3 -1
- package/dist/model/column-types.js +1 -1
- package/dist/model/preferences.d.ts +0 -4
- package/dist/model/preferences.js +0 -1
- package/dist/model/prefs-buckets.d.ts +0 -1
- package/dist/model/prefs-buckets.js +0 -3
- package/dist/model/render-count.d.ts +6 -0
- package/dist/model/render-count.js +11 -0
- package/dist/provider/ViewsProvider.d.ts +5 -1
- package/dist/provider/ViewsProvider.js +9 -3
- package/dist/provider/components.d.ts +19 -1
- package/dist/provider/components.js +4 -2
- package/dist/provider/context.d.ts +5 -2
- package/dist/provider/desktop.d.ts +9 -0
- package/dist/provider/desktop.js +22 -0
- package/dist/provider/plain-input.d.ts +8 -0
- package/dist/provider/plain-input.js +5 -0
- package/dist/react.d.ts +2 -1
- package/dist/react.js +1 -0
- package/dist/selection/SelectCheckbox.d.ts +3 -1
- package/dist/selection/SelectCheckbox.js +2 -2
- package/dist/selection/useCheckDragSelect.js +6 -5
- package/docs/contract.md +93 -35
- package/docs/guides/atoms.md +1 -1
- package/docs/guides/cells.md +2 -2
- package/docs/guides/columns.md +3 -2
- package/docs/guides/display.md +1 -0
- package/docs/guides/editors.md +71 -13
- package/docs/guides/the-grid.md +32 -13
- package/docs/guides/the-provider.md +3 -1
- package/docs/index.md +3 -1
- package/docs/install.md +1 -1
- package/docs/reference/cells.md +1 -1
- package/docs/reference/display.md +3 -1
- package/docs/reference/editors-chips.md +2 -2
- package/docs/reference/editors-date.md +3 -3
- package/docs/reference/editors-location.md +1 -1
- package/docs/reference/editors-number.md +1 -1
- package/docs/reference/editors-open-values.md +1 -0
- package/docs/reference/editors-panel.md +12 -0
- package/docs/reference/editors-range.md +1 -1
- package/docs/reference/editors-relation.md +6 -3
- package/docs/reference/editors-select.md +3 -2
- package/docs/reference/editors-session.md +4 -2
- package/docs/reference/editors-text.md +9 -0
- package/docs/reference/editors-value-list.md +1 -1
- package/docs/reference/editors.md +2 -2
- package/docs/reference/field-row.md +16 -0
- package/docs/reference/grid.md +3 -3
- package/docs/reference/react.md +8 -5
- package/docs/reference/views.md +36 -15
- package/package.json +23 -4
- package/skills/views/SKILL.md +4 -4
- package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
- package/dist/grid/chrome/useGridScrollSync.js +0 -176
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { requestedSettlementTitle, } from "@viewkitjs/fields";
|
|
4
|
+
export function useRowSettlement(row) {
|
|
5
|
+
const [mark, setMark] = useState(null);
|
|
6
|
+
if (mark && row === mark.row && !mark.seen)
|
|
7
|
+
setMark({ row, seen: true });
|
|
8
|
+
else if (mark && row !== mark.row && mark.seen)
|
|
9
|
+
setMark(null);
|
|
10
|
+
const settle = useCallback((receipt) => {
|
|
11
|
+
setMark(receipt.settlement === "requested" ? { row: receipt.row, seen: false } : null);
|
|
12
|
+
}, []);
|
|
13
|
+
const requested = !!mark && (row === mark.row || !mark.seen);
|
|
14
|
+
return { requested, settle };
|
|
15
|
+
}
|
|
16
|
+
export function settlementAttributes(requested, provenance, conventions) {
|
|
17
|
+
return requested
|
|
18
|
+
? {
|
|
19
|
+
"data-settlement": "requested",
|
|
20
|
+
title: requestedSettlementTitle(provenance, conventions),
|
|
21
|
+
}
|
|
22
|
+
: {};
|
|
23
|
+
}
|
package/dist/fields/binding.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type FieldDef, type FieldPatch } from "@viewkitjs/fields";
|
|
2
|
-
import type { RelationSource } from "./relation-source-types.js";
|
|
2
|
+
import type { RelationCellCreate, RelationSource } from "./relation-source-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* How a field reads and writes on ONE entity's row (docs/guides/columns.md) — the three
|
|
5
5
|
* identities kept apart: the field's `key` (semantic), the binding (this row),
|
|
@@ -54,8 +54,13 @@ export type FieldBinding<Row, D extends FieldDef = FieldDef> = {
|
|
|
54
54
|
/** A per-row money field: the row's currency and the registry's set — the
|
|
55
55
|
* number core's unit chip is a picker only with this. */
|
|
56
56
|
unit?: FieldUnit<Row>;
|
|
57
|
+
/** The record's country, where a phone typed without its country code is read; absent, the conventions' region
|
|
58
|
+
* reads it. */
|
|
59
|
+
region?: (row: Row) => string | null | undefined;
|
|
57
60
|
/** A writable relation's candidates — static (preloaded) or remote (a search). */
|
|
58
61
|
relation?: RelationSource;
|
|
62
|
+
/** A relation's create row: the app's form for a record not in the list, linked when it saves. */
|
|
63
|
+
create?: RelationCellCreate;
|
|
59
64
|
/** The app's own icon name for this field, drawn by the app's AppIcon; the type's glyph when absent. */
|
|
60
65
|
icon?: string;
|
|
61
66
|
/** This row keeps only the values of a `multiple` field (a plain list column): its editor offers no label box.
|
package/dist/fields/binding.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { editedThroughField, isMultipleType, renamedName,
|
|
1
|
+
import { editedThroughField, isMultipleType, renamedName, valueTypeOf, } from "@viewkitjs/fields";
|
|
2
2
|
export function fieldHistory(adapter) {
|
|
3
3
|
return adapter;
|
|
4
4
|
}
|
|
@@ -33,16 +33,20 @@ export function checkBinding(binding) {
|
|
|
33
33
|
}
|
|
34
34
|
if (field.type === "formula" && field.ratio && !binding.ratio)
|
|
35
35
|
fail("a ratio formula binds ratio — the two readers the footer sums");
|
|
36
|
-
if (binding.labels !== undefined &&
|
|
36
|
+
if (binding.labels !== undefined &&
|
|
37
|
+
!(isMultipleType(field.type) && "multiple" in field && field.multiple))
|
|
37
38
|
fail("only a field holding several values keeps or drops labels");
|
|
38
39
|
if (binding.ratio && !(field.type === "formula" && field.ratio))
|
|
39
40
|
fail("only a ratio formula carries ratio readers");
|
|
40
41
|
if (binding.write && field.type === "relation" && !binding.relation) {
|
|
41
42
|
fail("a writable relation needs candidates");
|
|
42
43
|
}
|
|
43
|
-
if (binding.
|
|
44
|
-
fail("a
|
|
45
|
-
|
|
44
|
+
if (binding.create && field.type === "user")
|
|
45
|
+
fail("a member is invited, not created");
|
|
46
|
+
if (binding.create && field.type !== "relation")
|
|
47
|
+
fail("only a relation field takes a create row");
|
|
48
|
+
if (binding.create && !binding.write)
|
|
49
|
+
fail("a create row links what it creates: bind a write");
|
|
46
50
|
}
|
|
47
51
|
export function bindField(field, spec) {
|
|
48
52
|
const binding = Object.freeze({ ...spec, field });
|
|
@@ -81,7 +85,10 @@ export function bindFields(registry, specs) {
|
|
|
81
85
|
write: (row, commit) => {
|
|
82
86
|
const value = storedRead(row);
|
|
83
87
|
const shown = name.read(row);
|
|
84
|
-
const same = empty(value) &&
|
|
88
|
+
const same = empty(value) &&
|
|
89
|
+
typeof commit === "string" &&
|
|
90
|
+
!empty(shown) &&
|
|
91
|
+
commit.trim() === String(shown).trim();
|
|
85
92
|
return storedWrite(row, same ? value : commit);
|
|
86
93
|
},
|
|
87
94
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { FieldType } from "@viewkitjs/fields";
|
|
2
2
|
/**
|
|
3
|
-
* WHICH TYPES
|
|
3
|
+
* WHICH TYPES HAVE AN EDITOR OF THEIR OWN — the fact, without the editors.
|
|
4
4
|
*
|
|
5
5
|
* `EDIT_CORES` (edit-cores.ts) binds a React component to each type, so asking
|
|
6
|
-
* it a yes/no question costs importing
|
|
6
|
+
* it a yes/no question costs importing every editor. The list MODEL asks
|
|
7
7
|
* exactly that question (`column-warnings.ts`) and must stay view-neutral: with
|
|
8
8
|
* the question answered from `EDIT_CORES`, every module that read a column
|
|
9
9
|
* capability loaded the date picker. `edit-cores.ts` proves at compile time
|
|
@@ -20,21 +20,21 @@ export declare const EDIT_CORE_TYPES: {
|
|
|
20
20
|
readonly number: true;
|
|
21
21
|
readonly percent: true;
|
|
22
22
|
readonly currency: true;
|
|
23
|
-
readonly text:
|
|
24
|
-
readonly url:
|
|
25
|
-
readonly domain:
|
|
26
|
-
readonly email:
|
|
27
|
-
readonly phone:
|
|
23
|
+
readonly text: true;
|
|
24
|
+
readonly url: true;
|
|
25
|
+
readonly domain: true;
|
|
26
|
+
readonly email: true;
|
|
27
|
+
readonly phone: true;
|
|
28
28
|
readonly boolean: false;
|
|
29
29
|
readonly location: true;
|
|
30
30
|
readonly name: true;
|
|
31
31
|
readonly actor: false;
|
|
32
|
-
readonly rich_text:
|
|
32
|
+
readonly rich_text: true;
|
|
33
33
|
readonly range: true;
|
|
34
34
|
readonly lookup: false;
|
|
35
35
|
readonly rollup: false;
|
|
36
36
|
readonly formula: false;
|
|
37
37
|
};
|
|
38
|
-
/** Whether this type
|
|
38
|
+
/** Whether this type has an editor of its own — the question a host asks before it
|
|
39
39
|
* wires an editor it may not need. */
|
|
40
40
|
export declare function hasEditCore(type: FieldType): boolean;
|
|
@@ -9,16 +9,16 @@ export const EDIT_CORE_TYPES = {
|
|
|
9
9
|
number: true,
|
|
10
10
|
percent: true,
|
|
11
11
|
currency: true,
|
|
12
|
-
text:
|
|
13
|
-
url:
|
|
14
|
-
domain:
|
|
15
|
-
email:
|
|
16
|
-
phone:
|
|
12
|
+
text: true,
|
|
13
|
+
url: true,
|
|
14
|
+
domain: true,
|
|
15
|
+
email: true,
|
|
16
|
+
phone: true,
|
|
17
17
|
boolean: false,
|
|
18
18
|
location: true,
|
|
19
19
|
name: true,
|
|
20
20
|
actor: false,
|
|
21
|
-
rich_text:
|
|
21
|
+
rich_text: true,
|
|
22
22
|
range: true,
|
|
23
23
|
lookup: false,
|
|
24
24
|
rollup: false,
|
package/dist/fields/money.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ export declare function readMoneyColumns<Row, C extends MoneyColumn<Row>>(column
|
|
|
54
54
|
/** The reading in force on a money column; `undefined` for a column that
|
|
55
55
|
* carries no money declaration. */
|
|
56
56
|
export declare function moneyReadingOf<Row>(column: MoneyColumn<Row>): MoneyReading | undefined;
|
|
57
|
+
/** The currency a row's figure was converted FROM, when the column shows it converted: the row's own code, for a
|
|
58
|
+
* money column read in a currency other than Original, over a row that draws a figure (it has rates) and stores
|
|
59
|
+
* another currency than the reading's. Null otherwise. What every surface marks with ≈, and what a money editor
|
|
60
|
+
* names under the record's own amount it opens on. */
|
|
61
|
+
export declare function convertedFromOf<Row>(column: MoneyColumn<Row>, row: Row): string | null;
|
|
57
62
|
/** The code the CELL draws for this row — a converted column's one code, a
|
|
58
63
|
* per-row column's row code, `undefined` for a column with no denomination.
|
|
59
64
|
* Never the `COLUMN_WIDE_CODE` sentinel. */
|
package/dist/fields/money.js
CHANGED
|
@@ -68,6 +68,16 @@ export function moneyReadingOf(column) {
|
|
|
68
68
|
return undefined;
|
|
69
69
|
return column.money.opensOn === "default" ? undefined : column.money.opensOn;
|
|
70
70
|
}
|
|
71
|
+
export function convertedFromOf(column, row) {
|
|
72
|
+
const money = column.money;
|
|
73
|
+
const reading = money ? moneyReadingOf(column) : undefined;
|
|
74
|
+
if (!money || !reading || reading === ORIGINAL_READING)
|
|
75
|
+
return null;
|
|
76
|
+
if (typeof column.accessor?.(row) !== "number")
|
|
77
|
+
return null;
|
|
78
|
+
const code = money.code(row);
|
|
79
|
+
return code && code !== reading ? code : null;
|
|
80
|
+
}
|
|
71
81
|
export function shownCodeOf(column, row) {
|
|
72
82
|
if (!column.field || valueTypeOf(column.field) !== "currency")
|
|
73
83
|
return undefined;
|
|
@@ -7,5 +7,11 @@ import { type DurationUnit, type FieldDef } from "@viewkitjs/fields";
|
|
|
7
7
|
* money and plain numbers two.
|
|
8
8
|
*/
|
|
9
9
|
export declare function numberEditDecimals(field: FieldDef): number;
|
|
10
|
+
/**
|
|
11
|
+
* The code a money field's amount is typed in when the field fixes one (`code: { fixed }`), which
|
|
12
|
+
* its editor draws beside the amount; `undefined` for any other field, a money field whose
|
|
13
|
+
* currency is per record included: its chip shows the record's own.
|
|
14
|
+
*/
|
|
15
|
+
export declare function numberEditCode(field: FieldDef): string | undefined;
|
|
10
16
|
/** The unit a duration field STORES (spec §8.4) — `undefined` for anything else. */
|
|
11
17
|
export declare function durationUnitOf(field: FieldDef): DurationUnit | undefined;
|
|
@@ -9,6 +9,10 @@ export function numberEditDecimals(field) {
|
|
|
9
9
|
return declared;
|
|
10
10
|
return valueTypeOf(field) === "percent" ? 0 : 2;
|
|
11
11
|
}
|
|
12
|
+
export function numberEditCode(field) {
|
|
13
|
+
const def = presentedDef(field);
|
|
14
|
+
return def.type === "currency" && "fixed" in def.code ? def.code.fixed : undefined;
|
|
15
|
+
}
|
|
12
16
|
export function durationUnitOf(field) {
|
|
13
17
|
const def = presentedDef(field);
|
|
14
18
|
return def.type === "number" && def.format?.style === "duration"
|
|
@@ -17,10 +17,15 @@ export function prepareFieldWrite(binding, row, commit, surface = {}) {
|
|
|
17
17
|
return { ok: false, reason: refused };
|
|
18
18
|
const cv = surface.conventions ?? DEFAULT_CONVENTIONS;
|
|
19
19
|
const message = cv.messages;
|
|
20
|
-
const
|
|
20
|
+
const keeps = binding.field.type === "phone" ||
|
|
21
|
+
binding.field.type === "url" ||
|
|
22
|
+
binding.field.type === "multiselect" ||
|
|
23
|
+
binding.field.type === "relation";
|
|
24
|
+
const stored = keeps ? (binding.editRead ?? binding.read)(row) : undefined;
|
|
21
25
|
const accepted = acceptFieldCommit(binding.field, commit, {
|
|
22
26
|
unitOptions: binding.unit?.options,
|
|
23
27
|
conventions: cv,
|
|
28
|
+
region: binding.region?.(row),
|
|
24
29
|
stored,
|
|
25
30
|
});
|
|
26
31
|
if (!accepted.ok)
|
|
@@ -52,3 +52,15 @@ export type RelationSource = {
|
|
|
52
52
|
* early or asks one pointless question at the end of it. */
|
|
53
53
|
pageSize?: number;
|
|
54
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* A create row an app hands a relation, for "it isn't in the list yet": the row's words, and what it does. A click
|
|
57
|
+
* closes the picker and calls `onCreate` with the trimmed query; the app opens its own form with it, and when the
|
|
58
|
+
* form saves, calls `link` with the new record's id (and its kind, on a field of several kinds). The surface then
|
|
59
|
+
* links it to the value it was created from, as a change of its own.
|
|
60
|
+
*/
|
|
61
|
+
export type RelationCellCreate = {
|
|
62
|
+
/** The row's words; receives the trimmed query. */
|
|
63
|
+
label: (query: string) => string;
|
|
64
|
+
/** Opens the app's form with the trimmed query; `link` links the record it saves. */
|
|
65
|
+
onCreate: (query: string, link: (id: string, kind?: string) => void) => void;
|
|
66
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { FieldSettlement } from "@viewkitjs/fields";
|
|
2
|
+
/** A sentence that explains a value, and optionally the source it rests on. */
|
|
3
|
+
export type FieldNote = {
|
|
4
|
+
text: string;
|
|
5
|
+
quote?: string | null;
|
|
6
|
+
};
|
|
7
|
+
/** The authoritative result of one acknowledged entity write. A warning may
|
|
8
|
+
* describe a secondary/remote outcome without withdrawing the confirmed row;
|
|
9
|
+
* `settlement: "requested"` says the row holds the value but the provider that
|
|
10
|
+
* owns it has not accepted it yet — the row draws that, not a toast. */
|
|
11
|
+
export type EntityWriteReceipt<Row> = {
|
|
12
|
+
row: Row;
|
|
13
|
+
warning?: string;
|
|
14
|
+
settlement?: FieldSettlement;
|
|
15
|
+
};
|
|
16
|
+
type FieldWriteReconciliationOutcome = "saved-unconfirmed" | "uncertain";
|
|
17
|
+
/**
|
|
18
|
+
* The mutation may have reached durable storage, but no authoritative row is
|
|
19
|
+
* available yet. Callers must not turn that into a fabricated receipt or a
|
|
20
|
+
* generic "nothing saved" error; the current record has to be reconciled
|
|
21
|
+
* before another affected write is admitted.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FieldWriteReconciliationRequired extends Error {
|
|
24
|
+
readonly outcome: FieldWriteReconciliationOutcome;
|
|
25
|
+
readonly warning: string;
|
|
26
|
+
constructor(outcome: FieldWriteReconciliationOutcome, warning: string);
|
|
27
|
+
}
|
|
28
|
+
/** Where a commit goes. Success is explicit and carries the canonical row; a
|
|
29
|
+
* fulfilled `void` can never be mistaken for confirmed data. `refresh` is the
|
|
30
|
+
* HOST's, not the target's — a drawer invalidates its query, a page revalidates
|
|
31
|
+
* the router. */
|
|
32
|
+
export type EntityWriteTarget<Row> = {
|
|
33
|
+
save: (rowId: string, body: Record<string, unknown>) => Promise<EntityWriteReceipt<Row>>;
|
|
34
|
+
/** Singular noun for toasts ("deal"). */
|
|
35
|
+
noun: string;
|
|
36
|
+
};
|
|
37
|
+
/** Synchronous admission is separate from asynchronous save settlement. */
|
|
38
|
+
export type FieldWriteAdmission<Row> = {
|
|
39
|
+
accepted: false;
|
|
40
|
+
reason: string;
|
|
41
|
+
} | {
|
|
42
|
+
accepted: true;
|
|
43
|
+
completion: Promise<EntityWriteReceipt<Row>>;
|
|
44
|
+
};
|
|
45
|
+
/** A field key → the reason it is locked on this surface, or null. A host's column locks
|
|
46
|
+
* arrive this way, so the row never reads the list's configuration. */
|
|
47
|
+
export type LockedResolver = (fieldKey: string) => string | null;
|
|
48
|
+
/** A lifecycle-owned admission boundary independent of field permissions. */
|
|
49
|
+
export type FieldWriteAdmissionGuard = () => string | null;
|
|
50
|
+
export {};
|
|
@@ -20,7 +20,7 @@ export function GridAddColumn({ columns }) {
|
|
|
20
20
|
anchor?.focus({ preventScroll: true });
|
|
21
21
|
};
|
|
22
22
|
const focusSearch = useCallback((el) => el?.focus({ preventScroll: true }), []);
|
|
23
|
-
return (_jsxs(_Fragment, { children: [_jsxs("button", { ref: setAnchor, type: "button", "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => (open ? close() : setOpen(true)), className: cx("flex h-full w-(--vk-tail-w) min-w-0 max-w-full flex-none items-center gap-1.5 px-(--vk-px) text-(length:--vk-head-text) hover:bg-(color:--vk-hovered)", open ? "bg-(color:--vk-pressed) text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: [_jsx(Add, { className: "h-(--vk-head-glyph) w-(--vk-head-glyph) shrink-0 opacity-70" }), _jsx("span", { className: "truncate", children: messages({ key: "views.grid.add-column" }) })] }), _jsx(Popover, { open: open, onOpenChange: (next, details) => (next ? setOpen(true) : close(details?.reason)), anchor: anchor, side: "bottom", align: "end", sideOffset: 4, chrome: "menu", initialFocus: false, className: "flex w-60 flex-col", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsxs(Command.Root, { shouldFilter: false, loop: true, label: messages({ key: "views.menus.add-column-search" }), children: [_jsx("div", { className: "flex h-10 shrink-0 items-center border-b border-(color:--vk-border)", children: _jsx(Command.Input, { chrome: "bare", value: query, onValueChange: setQuery, placeholder: messages({ key: "views.menus.add-column-search" }), ref: focusSearch, className: "h-full min-w-0 flex-1 bg-transparent px-3.5 text-base text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest) md:text-sm" }) }), _jsx(Command.List, { className: "max-h-80 min-h-0 overflow-y-auto overscroll-contain", children: _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [rows.map((item) => (_jsx(Command.Item, { value: item.id, onSelect: () => {
|
|
23
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { ref: setAnchor, type: "button", tabIndex: -1, "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => (open ? close() : setOpen(true)), className: cx("flex h-full w-(--vk-tail-w) min-w-0 max-w-full flex-none items-center gap-1.5 px-(--vk-px) text-(length:--vk-head-text) hover:bg-(color:--vk-hovered)", open ? "bg-(color:--vk-pressed) text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: [_jsx(Add, { className: "h-(--vk-head-glyph) w-(--vk-head-glyph) shrink-0 opacity-70" }), _jsx("span", { className: "truncate", children: messages({ key: "views.grid.add-column" }) })] }), _jsx(Popover, { open: open, onOpenChange: (next, details) => (next ? setOpen(true) : close(details?.reason)), anchor: anchor, side: "bottom", align: "end", sideOffset: 4, chrome: "menu", initialFocus: false, className: "flex w-60 flex-col", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsxs(Command.Root, { shouldFilter: false, loop: true, label: messages({ key: "views.menus.add-column-search" }), children: [_jsx("div", { className: "flex h-10 shrink-0 items-center border-b border-(color:--vk-border)", children: _jsx(Command.Input, { chrome: "bare", value: query, onValueChange: setQuery, placeholder: messages({ key: "views.menus.add-column-search" }), ref: focusSearch, className: "h-full min-w-0 flex-1 bg-transparent px-3.5 text-base text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest) md:text-sm" }) }), _jsx(Command.List, { className: "max-h-80 min-h-0 overflow-y-auto overscroll-contain", children: _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [rows.map((item) => (_jsx(Command.Item, { value: item.id, onSelect: () => {
|
|
24
24
|
columns.onToggleHidden(item.id, false);
|
|
25
25
|
close("item-press");
|
|
26
26
|
}, children: _jsx(RowContent, { label: item.label, leading: _jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-(color:--vk-fg-subtle)", children: item.icon }) }) }, item.id))), rows.length === 0 && (_jsx("p", { className: "px-2 py-2 text-sm text-(color:--vk-fg-subtle)", children: wanted
|
|
@@ -4,7 +4,7 @@ import type { ListAggregateKind, ListColumn } from "../../model/column-schema.js
|
|
|
4
4
|
type TriggerProps = {
|
|
5
5
|
ref?: Ref<HTMLElement>;
|
|
6
6
|
onClick?: (event: ReactMouseEvent<HTMLElement>) => void;
|
|
7
|
-
role?: "button";
|
|
7
|
+
role?: "button" | "gridcell";
|
|
8
8
|
"aria-haspopup"?: "dialog";
|
|
9
9
|
"aria-expanded"?: boolean;
|
|
10
10
|
};
|
|
@@ -3,9 +3,11 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { cloneElement, useState, } from "react";
|
|
4
4
|
import { aggregateLabel, aggregateOptions } from "../../model/aggregates.js";
|
|
5
5
|
import { useViews } from "../../provider/context.js";
|
|
6
|
+
import { gridMenuArrows, useGridMenuFocus } from "./grid-menu-focus.js";
|
|
6
7
|
export function GridAggregateMenu({ column, options, current, onChange, align, children, }) {
|
|
7
8
|
const [open, setOpen] = useState(false);
|
|
8
9
|
const [anchor, setAnchor] = useState(null);
|
|
10
|
+
useGridMenuFocus(open, anchor);
|
|
9
11
|
const { atoms, components, messages } = useViews();
|
|
10
12
|
const { Popover } = components;
|
|
11
13
|
const { List, Row } = atoms;
|
|
@@ -15,13 +17,13 @@ export function GridAggregateMenu({ column, options, current, onChange, align, c
|
|
|
15
17
|
children.props.onClick?.(event);
|
|
16
18
|
setOpen((was) => !was);
|
|
17
19
|
},
|
|
18
|
-
role: "button",
|
|
20
|
+
role: children.props.role ?? "button",
|
|
19
21
|
"aria-haspopup": "dialog",
|
|
20
22
|
"aria-expanded": open,
|
|
21
23
|
});
|
|
22
|
-
return (_jsxs(_Fragment, { children: [trigger, _jsx(Popover, { open: open, onOpenChange: setOpen, anchor: anchor, side: "bottom", align: align, sideOffset: 4, chrome: "menu", panelData: { "data-slot": "vk-grid-aggregate-menu" }, className: "w-40", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsx(List, { children: (options ?? aggregateOptions(column)).map((kind) => (_jsx(Row, { chosen: kind === current, label: aggregateLabel(kind, messages), onClick: () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
return (_jsxs(_Fragment, { children: [trigger, _jsx(Popover, { open: open, onOpenChange: setOpen, anchor: anchor, side: "bottom", align: align, sideOffset: 4, chrome: "menu", panelData: { "data-slot": "vk-grid-aggregate-menu" }, className: "w-40", onOutsidePress: (event) => (anchor?.contains(event.target) ? false : undefined), children: _jsx("div", { onKeyDown: gridMenuArrows, children: _jsx(List, { children: (options ?? aggregateOptions(column)).map((kind) => (_jsx(Row, { chosen: kind === current, label: aggregateLabel(kind, messages), onClick: () => {
|
|
25
|
+
setOpen(false);
|
|
26
|
+
if (kind !== current)
|
|
27
|
+
onChange(kind);
|
|
28
|
+
} }, kind))) }) }) })] }));
|
|
27
29
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { GridEditorId } from "../../model/column-types.js";
|
|
3
|
+
import { type ListSettingsConfig } from "../../model/column-capabilities.js";
|
|
3
4
|
import type { ListColumn, ListSelectColor } from "../../model/column-schema.js";
|
|
4
5
|
/** Everything an editor needs about the cell it is mounting into. */
|
|
5
6
|
export type GridCellEditorContext<Row> = {
|
|
@@ -15,6 +16,9 @@ export type GridCellEditorContext<Row> = {
|
|
|
15
16
|
baseline: unknown;
|
|
16
17
|
/** Type-to-replace seed: the character that opened this editor, or null. */
|
|
17
18
|
editSeed?: string | null;
|
|
19
|
+
/** The text was cut off in its cell when it opened: it shows whole in the panel over the cell
|
|
20
|
+
* (`gridTextOpensBox`), editable or read-only. Default false. */
|
|
21
|
+
whole?: boolean;
|
|
18
22
|
decimals?: number;
|
|
19
23
|
selectValues?: string[];
|
|
20
24
|
optionColors?: Record<string, ListSelectColor>;
|
|
@@ -22,6 +26,9 @@ export type GridCellEditorContext<Row> = {
|
|
|
22
26
|
* candidates with it, so a row in the list carries the same icon the cell
|
|
23
27
|
* will show once it is picked. */
|
|
24
28
|
entityIcon?: (kind: string | undefined) => ReactNode;
|
|
29
|
+
/** The list's settings, read when the editor closes: a column locked while its editor was open
|
|
30
|
+
* keeps the editor open with the lock's sentence. */
|
|
31
|
+
listConfig?: ListSettingsConfig;
|
|
25
32
|
onCommitCell: (row: Row, rowId: string, columnId: string, prev: unknown, next: unknown, opts?: {
|
|
26
33
|
overlay?: boolean;
|
|
27
34
|
}) => void;
|
|
@@ -1,55 +1,126 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
-
import { numberEditDecimals } from "../../fields/number-edit.js";
|
|
5
|
-
import {
|
|
4
|
+
import { numberEditCode, numberEditDecimals } from "../../fields/number-edit.js";
|
|
5
|
+
import { convertedFromOf } from "../../fields/money.js";
|
|
6
|
+
import { renderTypedCellValue } from "../../cells/cell-values.js";
|
|
7
|
+
import { legacyFieldFromColumn } from "../../cells/legacy-field.js";
|
|
8
|
+
import { isOpenableType } from "../../editors/open-value.js";
|
|
9
|
+
import { isIntegerField, isMultipleType, isNameValue, isRangeValue, phoneText, rangeDecimals, relationIdOf, relationKey, relationLinksOf, relationStoredOf, valueTypeOf, } from "@viewkitjs/fields";
|
|
6
10
|
import { GridNameEditor } from "./GridNameEditor.js";
|
|
11
|
+
import { GridPlaceEditor } from "./GridPlaceEditor.js";
|
|
7
12
|
import { GridValueListEditor } from "./GridValueListEditor.js";
|
|
8
13
|
import { cellPrevPayload } from "./cell-clipboard.js";
|
|
9
|
-
import { GridChipsEditor, GridDateEditor, GridLongTextEditor, GridNumberEditor, GridRangeEditor, GridRelationEditor, GridSelectEditor, GridTextEditor, } from "./editors.js";
|
|
10
|
-
import {
|
|
14
|
+
import { GridChipsEditor, GridDateEditor, GridLongTextEditor, GridNumberEditor, GridRangeEditor, GridRelationEditor, GridRelationSetEditor, GridSelectEditor, GridTextEditor, } from "./editors.js";
|
|
15
|
+
import { gridTextEditorType } from "./GridTextEditor.js";
|
|
16
|
+
import { gridTextOpensBox, isLongTextColumn } from "../../model/column-inspect.js";
|
|
17
|
+
import { gridClearRefusal, gridColumnEffectiveClearable, gridColumnLocked, gridEditRefusal, gridNormalizeWrite, } from "../../model/column-capabilities.js";
|
|
18
|
+
import { useViews } from "../../provider/context.js";
|
|
11
19
|
import { gridRelationSource } from "../../model/column-types.js";
|
|
20
|
+
function useCellRefusal(col, listConfig, region) {
|
|
21
|
+
const { conventions, messages } = useViews();
|
|
22
|
+
return (next, prev) => {
|
|
23
|
+
if (gridColumnLocked(col, listConfig))
|
|
24
|
+
return gridEditRefusal(col, listConfig, conventions, messages) ?? null;
|
|
25
|
+
const result = gridNormalizeWrite(col, next, conventions, { messages, stored: prev, region });
|
|
26
|
+
return result.ok ? null : result.reason;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
12
29
|
export function GridCellInlineEditor({ ctx }) {
|
|
13
30
|
const { row, rowId, col, baseline, onCommitCell, onCancel, onTab, onEnter } = ctx;
|
|
31
|
+
const refusal = useCellRefusal(col, ctx.listConfig, col.region?.(row));
|
|
14
32
|
if (ctx.editorKind === "number") {
|
|
15
33
|
const integer = col.field ? isIntegerField(col.field) : false;
|
|
16
34
|
const fallback = col.field ? numberEditDecimals(col.field) : (col.format?.decimals ?? 2);
|
|
17
35
|
const durationUnit = col.format?.style === "duration" ? (col.format.unit ?? "ms") : undefined;
|
|
18
|
-
return (_jsx(GridNumberEditor, { initial: typeof baseline === "number" ? baseline : Number.NaN, seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, decimals: integer ? 0 : (ctx.decimals ?? fallback), durationUnit: durationUnit, allowEmpty: !!col.clearable, unitLeft: col.align === "right", onCommit: (payload) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline, col.editUnit?.value(row)), payload, { overlay: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
36
|
+
return (_jsx(GridNumberEditor, { title: col.header, initial: typeof baseline === "number" ? baseline : Number.NaN, seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, code: col.editUnit ? undefined : numberEditCode(col.field ?? legacyFieldFromColumn(col)), 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: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
19
37
|
}
|
|
20
38
|
if (ctx.editorKind === "range") {
|
|
21
39
|
const def = col.field?.type === "range" ? col.field : undefined;
|
|
22
|
-
return (_jsx(GridRangeEditor, { initial: isRangeValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, decimals: def ? rangeDecimals(def) : 0, allowEmpty: !!col.clearable, suffix: def?.of === "percent" ? "%" : def?.of === "currency" ? def.code?.fixed : undefined, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
40
|
+
return (_jsx(GridRangeEditor, { title: col.header, initial: isRangeValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, decimals: def ? rangeDecimals(def) : 0, allowEmpty: !!col.clearable, suffix: def?.of === "percent" ? "%" : def?.of === "currency" ? def.code?.fixed : undefined, bands: def?.presets, refuse: (payload) => refusal(payload, baseline), onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
23
41
|
}
|
|
24
|
-
if (ctx.editorKind === "text" && !
|
|
25
|
-
|
|
42
|
+
if (ctx.editorKind === "text" && !gridTextOpensBox(col, !!ctx.whole)) {
|
|
43
|
+
const phone = col.type === "phone";
|
|
44
|
+
const stored = phone ? phoneText(baseline, null) : String(baseline ?? "");
|
|
45
|
+
return (_jsx(GridTextEditor, { initial: stored, seed: ctx.editSeed ?? undefined, type: gridTextEditorType(col.type), title: col.header, strong: col.type === "title", open: isOpenableType(col.type) && baseline != null && baseline !== ""
|
|
46
|
+
? { type: col.type, value: baseline }
|
|
47
|
+
: undefined, refuse: (value) => refusal(value, phone ? baseline : stored), onCommit: (value) => onCommitCell(row, rowId, col.id, phone ? baseline : stored, value), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
|
|
26
48
|
}
|
|
27
49
|
return null;
|
|
28
50
|
}
|
|
29
51
|
export function GridCellAnchoredEditor({ ctx, }) {
|
|
30
52
|
const { row, rowId, col, baseline, onCommitCell, onCancel } = ctx;
|
|
53
|
+
const region = col.region?.(row);
|
|
54
|
+
const refusal = useCellRefusal(col, ctx.listConfig, region);
|
|
55
|
+
const { messages } = useViews();
|
|
31
56
|
const relationSource = useMemo(() => gridRelationSource(col, ctx.entityIcon), [col, ctx.entityIcon]);
|
|
32
|
-
if (ctx.editorKind === "text" &&
|
|
33
|
-
|
|
57
|
+
if (ctx.editorKind === "text" && gridTextOpensBox(col, !!ctx.whole)) {
|
|
58
|
+
const paragraph = isLongTextColumn(col);
|
|
59
|
+
return (_jsx(GridLongTextEditor, { paragraph: paragraph, type: paragraph ? undefined : gridTextEditorType(col.type), initial: String(baseline ?? ""), seed: ctx.editSeed ?? undefined, readOnly: ctx.readOnly, markdown: col.type === "rich_text", title: col.header, refuse: (value) => refusal(value, String(baseline ?? "")), onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
34
60
|
}
|
|
35
61
|
if (ctx.editorKind === "select") {
|
|
36
|
-
return (_jsx(GridSelectEditor, { column: col, values: ctx.selectValues ?? (col.options ?? []).map((o) => o.value), current: String(baseline ?? ""), optionColors: ctx.optionColors, onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel }));
|
|
62
|
+
return (_jsx(GridSelectEditor, { column: col, title: col.header, values: ctx.selectValues ?? (col.options ?? []).map((o) => o.value), current: String(baseline ?? ""), clearable: !!col.clearable, seed: ctx.editSeed ?? undefined, optionColors: ctx.optionColors, refuse: (value) => refusal(value, String(baseline ?? "")), onCommit: (value) => onCommitCell(row, rowId, col.id, String(baseline ?? ""), value), onCancel: onCancel }));
|
|
37
63
|
}
|
|
38
64
|
if (ctx.editorKind === "chips") {
|
|
39
65
|
const current = Array.isArray(baseline) ? baseline.map(String) : [];
|
|
40
|
-
return (_jsx(GridChipsEditor, { column: col, values: current, suggestions: ctx.selectValues ?? (col.options ?? []).map((option) => option.value), optionColors: ctx.optionColors, onCommit: (next) => onCommitCell(row, rowId, col.id, current, next), onCancel: onCancel }));
|
|
66
|
+
return (_jsx(GridChipsEditor, { column: col, title: col.header, values: current, suggestions: ctx.selectValues ?? (col.options ?? []).map((option) => option.value), optionColors: ctx.optionColors, refuse: (next) => refusal(next, current), onCommit: (next) => onCommitCell(row, rowId, col.id, current, next), onCancel: onCancel, onTab: ctx.onTab }));
|
|
41
67
|
}
|
|
42
68
|
if (ctx.editorKind === "relation") {
|
|
43
|
-
|
|
69
|
+
const field = col.field?.type === "relation" ? col.field : undefined;
|
|
70
|
+
const create = field ? col.relation?.create : undefined;
|
|
71
|
+
const prev = field ? storedPrev(field, baseline) : relationIdOf(baseline);
|
|
72
|
+
const write = (next, from = prev) => onCommitCell(row, rowId, col.id, from, next, { overlay: false });
|
|
73
|
+
if (field?.cardinality === "many") {
|
|
74
|
+
const stored = (links) => relationStoredOf(field, links);
|
|
75
|
+
return (_jsx(GridRelationSetEditor, { title: col.header, candidates: relationSource, current: relationSetItems(field, baseline, col.accessor?.(row), relationSource, ctx.entityIcon, col.relation?.entity), lead: field.links?.primary === "flag", seed: ctx.editSeed ?? undefined, create: create, refuse: (links) => refusal(stored(links), prev), onCommit: (links) => write(stored(links)), onLink: (base, added) => write(stored([...base, added]), stored(base)), onCancel: onCancel, onTab: ctx.onTab }));
|
|
76
|
+
}
|
|
77
|
+
const one = (id, kind) => field
|
|
78
|
+
? relationStoredOf(field, id == null ? [] : [{ id, ...(kind !== undefined ? { kind } : {}) }])
|
|
79
|
+
: id;
|
|
80
|
+
return (_jsx(GridRelationEditor, { title: col.header, candidates: relationSource, current: relationIdOf(baseline), clearable: !!col.clearable, seed: ctx.editSeed ?? undefined, create: create, refuse: (id, kind) => refusal(one(id, kind), prev), onCommit: (id, kind) => write(one(id, kind)), onLink: (id, kind) => write(one(id, kind)), onCancel: onCancel }));
|
|
44
81
|
}
|
|
45
82
|
if (ctx.editorKind === "name") {
|
|
46
|
-
return (_jsx(GridNameEditor, { initial: isNameValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, allowEmpty: !!col.clearable, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
83
|
+
return (_jsx(GridNameEditor, { title: col.header, initial: isNameValue(baseline) ? baseline : null, seed: ctx.editSeed ?? undefined, allowEmpty: !!col.clearable, onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
47
84
|
}
|
|
48
85
|
if (ctx.editorKind === "values" && col.field && isMultipleType(col.field.type)) {
|
|
49
|
-
return (_jsx(GridValueListEditor, { field: col.field, initial: baseline, labels: col.labels !== false, allowEmpty:
|
|
86
|
+
return (_jsx(GridValueListEditor, { field: col.field, title: col.header, initial: baseline, labels: col.labels !== false, region: region, allowEmpty: true, refuse: (payload) => payload == null && !gridColumnEffectiveClearable(col, ctx.listConfig)
|
|
87
|
+
? gridClearRefusal(col, ctx.listConfig, messages)
|
|
88
|
+
: refusal(payload, baseline), onCommit: (payload) => onCommitCell(row, rowId, col.id, baseline, payload, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
89
|
+
}
|
|
90
|
+
if (ctx.editorKind === "place" && col.field && valueTypeOf(col.field) === "location") {
|
|
91
|
+
const initial = baseline && typeof baseline === "object" && !Array.isArray(baseline)
|
|
92
|
+
? baseline
|
|
93
|
+
: null;
|
|
94
|
+
return (_jsx(GridPlaceEditor, { field: col.field, title: col.header, initial: initial, refuse: (place) => place === null && !gridColumnEffectiveClearable(col, ctx.listConfig)
|
|
95
|
+
? gridClearRefusal(col, ctx.listConfig, messages)
|
|
96
|
+
: refusal(place, baseline), onCommit: (place) => onCommitCell(row, rowId, col.id, baseline, place, { overlay: false }), onCancel: onCancel, onTab: ctx.onTab, onEnter: ctx.onEnter }));
|
|
50
97
|
}
|
|
51
98
|
if (ctx.editorKind === "date") {
|
|
52
|
-
return (_jsx(GridDateEditor, { initial: String(baseline ?? "") || undefined, dayOnly: col.field?.type === "date",
|
|
99
|
+
return (_jsx(GridDateEditor, { title: col.header, initial: String(baseline ?? "") || undefined, dayOnly: col.field?.type === "date", clearable: gridColumnEffectiveClearable(col, ctx.listConfig), seed: ctx.editSeed ?? undefined, refuse: (ymd) => ymd === "" && !gridColumnEffectiveClearable(col, ctx.listConfig)
|
|
100
|
+
? gridClearRefusal(col, ctx.listConfig, messages)
|
|
101
|
+
: refusal(ymd, cellPrevPayload(col, baseline)), onCommit: (ymd) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline), ymd, ymd === "" ? undefined : { overlay: false }), onCancel: onCancel, onTab: ctx.onTab }));
|
|
53
102
|
}
|
|
54
103
|
return null;
|
|
55
104
|
}
|
|
105
|
+
function storedPrev(field, baseline) {
|
|
106
|
+
const shown = Array.isArray(baseline)
|
|
107
|
+
? baseline.some((item) => relationKey(item) != null)
|
|
108
|
+
: relationKey(baseline) != null;
|
|
109
|
+
return shown ? relationStoredOf(field, relationLinksOf(field, baseline)) : baseline;
|
|
110
|
+
}
|
|
111
|
+
function relationSetItems(field, baseline, shown, source, entityIcon, defaultKind) {
|
|
112
|
+
const labels = new Map();
|
|
113
|
+
if (source.kind === "static")
|
|
114
|
+
for (const item of source.items)
|
|
115
|
+
labels.set(item.id, { label: item.label, icon: item.icon });
|
|
116
|
+
for (const item of Array.isArray(shown) ? shown : [shown]) {
|
|
117
|
+
const id = relationKey(item);
|
|
118
|
+
if (id != null)
|
|
119
|
+
labels.set(id, { ...labels.get(id), label: item.label });
|
|
120
|
+
}
|
|
121
|
+
return relationLinksOf(field, baseline).map((link) => {
|
|
122
|
+
const known = labels.get(link.id);
|
|
123
|
+
const icon = known?.icon ?? entityIcon?.(link.kind ?? defaultKind);
|
|
124
|
+
return { ...link, label: known?.label ?? link.id, ...(icon != null ? { icon } : {}) };
|
|
125
|
+
});
|
|
126
|
+
}
|