@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,17 @@
|
|
|
1
|
+
type SelectCheckboxProps = {
|
|
2
|
+
checked: boolean;
|
|
3
|
+
/** When true the checkbox is pinned visible; otherwise it reveals on the gutter zone hover. */
|
|
4
|
+
revealed: boolean;
|
|
5
|
+
/** `shift` is true when the click was a shift-click (range select). */
|
|
6
|
+
onChange: (next: boolean, shift: boolean) => void;
|
|
7
|
+
"aria-label"?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Row selection checkbox: the app's checkbox (in the portal, its neutral selection skin).
|
|
12
|
+
* Reveals only while the surrounding gutter hover-zone (`group/selzone`, set by the lane that
|
|
13
|
+
* holds it) is hovered — not the whole row — and reads the shift key off the press that changed
|
|
14
|
+
* it, for range selection.
|
|
15
|
+
*/
|
|
16
|
+
export declare function SelectCheckbox({ checked, revealed, onChange, className, "aria-label": ariaLabel, }: SelectCheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../internal/cx.js";
|
|
4
|
+
import { useViews } from "../provider/context.js";
|
|
5
|
+
export function SelectCheckbox({ checked, revealed, onChange, className, "aria-label": ariaLabel, }) {
|
|
6
|
+
const { Checkbox } = useViews().components;
|
|
7
|
+
return (_jsx(Checkbox, { checked: checked, "aria-label": ariaLabel, onCheckedChange: (next, details) => onChange(next, pressedWithShift(details?.event)), className: cx("opacity-0 group-hover/selzone:opacity-100", revealed && "opacity-100", checked && "opacity-100", className) }));
|
|
8
|
+
}
|
|
9
|
+
function pressedWithShift(event) {
|
|
10
|
+
return event !== undefined && "shiftKey" in event && event.shiftKey === true;
|
|
11
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ListBatchApi, ListSelectionConfig } from "./types.js";
|
|
2
|
+
export { SelectCheckbox } from "./SelectCheckbox.js";
|
|
3
|
+
export { useCheckDragSelect, ROW_CHECK_ATTR } from "./useCheckDragSelect.js";
|
|
4
|
+
export { preventShiftTextSelect, selectFromClick, ROW_INTERACTIVE_SELECTOR, ROW_NO_TEXT_SELECT, ROW_OPEN_STOP_SELECTOR, } from "./row-click.js";
|
|
5
|
+
export { REST_INTENT_MS, useRestIntent } from "./useRestIntent.js";
|
|
6
|
+
export { useListSelection, type SelectionRetention, type UseListSelectionResult } from "./useListSelection.js";
|
|
7
|
+
export { useEscapeToClear } from "./useListSelectionShortcuts.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SelectCheckbox } from "./SelectCheckbox.js";
|
|
2
|
+
export { useCheckDragSelect, ROW_CHECK_ATTR } from "./useCheckDragSelect.js";
|
|
3
|
+
export { preventShiftTextSelect, selectFromClick, ROW_INTERACTIVE_SELECTOR, ROW_NO_TEXT_SELECT, ROW_OPEN_STOP_SELECTOR, } from "./row-click.js";
|
|
4
|
+
export { REST_INTENT_MS, useRestIntent } from "./useRestIntent.js";
|
|
5
|
+
export { useListSelection } from "./useListSelection.js";
|
|
6
|
+
export { useEscapeToClear } from "./useListSelectionShortcuts.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type SelectionRetention = "ordered" | "external";
|
|
2
|
+
export type SelectionContext = {
|
|
3
|
+
orderedIds: readonly string[];
|
|
4
|
+
retention: SelectionRetention;
|
|
5
|
+
resetKey?: string;
|
|
6
|
+
};
|
|
7
|
+
export type SelectionState = {
|
|
8
|
+
selectedIds: Set<string>;
|
|
9
|
+
anchorId: string | null;
|
|
10
|
+
orderKey: string;
|
|
11
|
+
retention: SelectionRetention;
|
|
12
|
+
resetKey?: string;
|
|
13
|
+
};
|
|
14
|
+
export type SelectionAction = {
|
|
15
|
+
type: "reconcile";
|
|
16
|
+
context: SelectionContext;
|
|
17
|
+
} | {
|
|
18
|
+
type: "toggle";
|
|
19
|
+
id: string;
|
|
20
|
+
next?: boolean;
|
|
21
|
+
context: SelectionContext;
|
|
22
|
+
} | {
|
|
23
|
+
type: "toggle-range";
|
|
24
|
+
id: string;
|
|
25
|
+
context: SelectionContext;
|
|
26
|
+
} | {
|
|
27
|
+
type: "toggle-many";
|
|
28
|
+
ids: readonly string[];
|
|
29
|
+
context: SelectionContext;
|
|
30
|
+
} | {
|
|
31
|
+
type: "select-all";
|
|
32
|
+
context: SelectionContext;
|
|
33
|
+
} | {
|
|
34
|
+
type: "clear";
|
|
35
|
+
context: SelectionContext;
|
|
36
|
+
} | {
|
|
37
|
+
type: "set-selected";
|
|
38
|
+
ids: readonly string[];
|
|
39
|
+
context: SelectionContext;
|
|
40
|
+
};
|
|
41
|
+
export declare function createSelectionState(context: SelectionContext): SelectionState;
|
|
42
|
+
/**
|
|
43
|
+
* Reconciles stored selection against the current visual order.
|
|
44
|
+
*
|
|
45
|
+
* `ordered` is the safe default for ordinary lists: ids that disappear from the
|
|
46
|
+
* current order are removed. `external` is reserved for query-wide or modal
|
|
47
|
+
* selections whose selected ids intentionally outlive the currently loaded or
|
|
48
|
+
* filtered rows. In both modes, a range anchor must remain visible to be valid.
|
|
49
|
+
*/
|
|
50
|
+
export declare function reconcileSelection(state: SelectionState, context: SelectionContext): SelectionState;
|
|
51
|
+
export declare function selectionReducer(state: SelectionState, action: SelectionAction): SelectionState;
|
|
52
|
+
export declare function getSelectionSummary(selectedIds: ReadonlySet<string>, orderedIds: readonly string[]): {
|
|
53
|
+
allSelected: boolean;
|
|
54
|
+
someSelected: boolean;
|
|
55
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function orderKey(orderedIds) {
|
|
2
|
+
return JSON.stringify(orderedIds);
|
|
3
|
+
}
|
|
4
|
+
export function createSelectionState(context) {
|
|
5
|
+
return {
|
|
6
|
+
selectedIds: new Set(),
|
|
7
|
+
anchorId: null,
|
|
8
|
+
orderKey: orderKey(context.orderedIds),
|
|
9
|
+
retention: context.retention,
|
|
10
|
+
resetKey: context.resetKey,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function reconcileSelection(state, context) {
|
|
14
|
+
const nextOrderKey = orderKey(context.orderedIds);
|
|
15
|
+
if (state.resetKey !== context.resetKey) {
|
|
16
|
+
return createSelectionState(context);
|
|
17
|
+
}
|
|
18
|
+
if (state.orderKey === nextOrderKey && state.retention === context.retention)
|
|
19
|
+
return state;
|
|
20
|
+
const orderedSet = new Set(context.orderedIds);
|
|
21
|
+
const selectedIds = context.retention === "external"
|
|
22
|
+
? state.selectedIds
|
|
23
|
+
: new Set([...state.selectedIds].filter((id) => orderedSet.has(id)));
|
|
24
|
+
return {
|
|
25
|
+
selectedIds,
|
|
26
|
+
anchorId: state.anchorId && orderedSet.has(state.anchorId) ? state.anchorId : null,
|
|
27
|
+
orderKey: nextOrderKey,
|
|
28
|
+
retention: context.retention,
|
|
29
|
+
resetKey: context.resetKey,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function selectionReducer(state, action) {
|
|
33
|
+
const current = reconcileSelection(state, action.context);
|
|
34
|
+
switch (action.type) {
|
|
35
|
+
case "reconcile":
|
|
36
|
+
return current;
|
|
37
|
+
case "toggle": {
|
|
38
|
+
const selectedIds = new Set(current.selectedIds);
|
|
39
|
+
const shouldSelect = action.next ?? !selectedIds.has(action.id);
|
|
40
|
+
if (shouldSelect)
|
|
41
|
+
selectedIds.add(action.id);
|
|
42
|
+
else
|
|
43
|
+
selectedIds.delete(action.id);
|
|
44
|
+
return { ...current, selectedIds, anchorId: action.id };
|
|
45
|
+
}
|
|
46
|
+
case "toggle-range": {
|
|
47
|
+
const selectedIds = new Set(current.selectedIds);
|
|
48
|
+
const from = current.anchorId ? action.context.orderedIds.indexOf(current.anchorId) : -1;
|
|
49
|
+
const to = action.context.orderedIds.indexOf(action.id);
|
|
50
|
+
if (from === -1 || to === -1) {
|
|
51
|
+
selectedIds.add(action.id);
|
|
52
|
+
return { ...current, selectedIds };
|
|
53
|
+
}
|
|
54
|
+
const [lo, hi] = from <= to ? [from, to] : [to, from];
|
|
55
|
+
for (let index = lo; index <= hi; index += 1) {
|
|
56
|
+
selectedIds.add(action.context.orderedIds[index]);
|
|
57
|
+
}
|
|
58
|
+
return { ...current, selectedIds };
|
|
59
|
+
}
|
|
60
|
+
case "toggle-many": {
|
|
61
|
+
const selectedIds = new Set(current.selectedIds);
|
|
62
|
+
const allSelected = action.ids.length > 0 && action.ids.every((id) => selectedIds.has(id));
|
|
63
|
+
for (const id of action.ids) {
|
|
64
|
+
if (allSelected)
|
|
65
|
+
selectedIds.delete(id);
|
|
66
|
+
else
|
|
67
|
+
selectedIds.add(id);
|
|
68
|
+
}
|
|
69
|
+
return { ...current, selectedIds };
|
|
70
|
+
}
|
|
71
|
+
case "select-all":
|
|
72
|
+
return { ...current, selectedIds: new Set(action.context.orderedIds) };
|
|
73
|
+
case "clear":
|
|
74
|
+
return { ...current, selectedIds: new Set(), anchorId: null };
|
|
75
|
+
case "set-selected":
|
|
76
|
+
return { ...current, selectedIds: new Set(action.ids), anchorId: null };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function getSelectionSummary(selectedIds, orderedIds) {
|
|
80
|
+
const selectedOrderedCount = orderedIds.reduce((count, id) => count + Number(selectedIds.has(id)), 0);
|
|
81
|
+
const allSelected = orderedIds.length > 0 && selectedOrderedCount === orderedIds.length;
|
|
82
|
+
return {
|
|
83
|
+
allSelected,
|
|
84
|
+
someSelected: selectedOrderedCount > 0 && !allSelected,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MouseEvent } from "react";
|
|
2
|
+
import type { UseListSelectionResult } from "./useListSelection.js";
|
|
3
|
+
/**
|
|
4
|
+
* Modifier-click selection for a list row. Cmd/Ctrl-click toggles the row;
|
|
5
|
+
* Shift-click extends the range. Returns `true` when it handled a modifier
|
|
6
|
+
* click — the caller should then `return` before opening the drawer.
|
|
7
|
+
*
|
|
8
|
+
* onClick={(e) => {
|
|
9
|
+
* // ...existing guards (data-action-menu, links, etc.)...
|
|
10
|
+
* if (selectFromClick(e, id, sel)) return;
|
|
11
|
+
* openDrawer(...);
|
|
12
|
+
* }}
|
|
13
|
+
*/
|
|
14
|
+
export declare function selectFromClick(e: MouseEvent, id: string, sel: Pick<UseListSelectionResult, "toggle" | "toggleRange">): boolean;
|
|
15
|
+
/** `onMouseDown` guard that stops shift-click from triggering native text selection. */
|
|
16
|
+
export declare function preventShiftTextSelect(e: MouseEvent): void;
|
|
17
|
+
/**
|
|
18
|
+
* A row click lands on something genuinely interactive → that control handles it
|
|
19
|
+
* (in BOTH normal and selection mode). A click anywhere else opens the row, or
|
|
20
|
+
* toggles it while selecting. Deliberately NOT `[data-action-menu]` — bailing on a
|
|
21
|
+
* wrapper (often full-width) created dead zones in the padding around a control.
|
|
22
|
+
*/
|
|
23
|
+
export declare const ROW_INTERACTIVE_SELECTOR: string;
|
|
24
|
+
/**
|
|
25
|
+
* Regions that should NOT open the row (e.g. the trailing kebab/meta gutter) but
|
|
26
|
+
* SHOULD still toggle selection when the list is in selection mode — so the whole
|
|
27
|
+
* row is a selection target except for real interactive controls. Checked AFTER
|
|
28
|
+
* the selection-mode toggle, so it only gates the open. Apply tightly.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ROW_OPEN_STOP_SELECTOR = "[data-row-stop]";
|
|
31
|
+
/**
|
|
32
|
+
* Class for selectable list rows — disables native text selection and the iOS
|
|
33
|
+
* long-press callout, so long-press-to-select doesn't also highlight text.
|
|
34
|
+
*/
|
|
35
|
+
export declare const ROW_NO_TEXT_SELECT = "select-none [-webkit-touch-callout:none]";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function selectFromClick(e, id, sel) {
|
|
2
|
+
if (e.metaKey || e.ctrlKey) {
|
|
3
|
+
sel.toggle(id);
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
if (e.shiftKey) {
|
|
7
|
+
sel.toggleRange(id);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export function preventShiftTextSelect(e) {
|
|
13
|
+
if (e.shiftKey)
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
}
|
|
16
|
+
export const ROW_INTERACTIVE_SELECTOR = 'a, button, input, select, textarea, label, [role="button"], [role="switch"], ' +
|
|
17
|
+
'[role="checkbox"], [role="menuitem"], [role="tab"], [contenteditable="true"], ' +
|
|
18
|
+
"[data-popover-trigger], [data-no-nav]";
|
|
19
|
+
export const ROW_OPEN_STOP_SELECTOR = "[data-row-stop]";
|
|
20
|
+
export const ROW_NO_TEXT_SELECT = "select-none [-webkit-touch-callout:none]";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { SelectionRetention, UseListSelectionResult } from "./useListSelection.js";
|
|
3
|
+
/** Batch-write capability supplied by a renderer with an editing model. */
|
|
4
|
+
export type ListBatchApi = {
|
|
5
|
+
setColumnValue: (rowIds: string[], columnId: string, value: unknown) => Promise<boolean>;
|
|
6
|
+
};
|
|
7
|
+
/** View-neutral multi-select contract shared by List and Table renderers. */
|
|
8
|
+
export type ListSelectionConfig = {
|
|
9
|
+
/** Visual order used by range selection and select-all. */
|
|
10
|
+
orderedIds?: string[];
|
|
11
|
+
/** Keep ids outside the current visual order only for query-wide selection. */
|
|
12
|
+
retention?: SelectionRetention;
|
|
13
|
+
/** Selection clears whenever this view/filter identity changes. */
|
|
14
|
+
resetKey: string;
|
|
15
|
+
/** Render the floating bar, optionally with the active renderer's batch API. */
|
|
16
|
+
renderBar: (sel: UseListSelectionResult, batch?: ListBatchApi) => ReactNode;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent, type RefObject } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Marker attribute on a row's checkbox lane. The drag recognises its starting
|
|
4
|
+
* point by this rather than by the checkbox element itself, so the whole lane
|
|
5
|
+
* is grabbable — which is what you actually aim at once the lane goes opaque
|
|
6
|
+
* during a selection.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ROW_CHECK_ATTR = "data-row-check";
|
|
9
|
+
/**
|
|
10
|
+
* Drag down the checkbox lane to select a run of rows (Sheets / Notion).
|
|
11
|
+
*
|
|
12
|
+
* The gesture is a RANGE from the anchor to the row under the pointer, not a
|
|
13
|
+
* one-way paint. Everything between them takes a single value, decided once
|
|
14
|
+
* from the row you started on (`!isSelected(anchor)`) — so a drag that begins
|
|
15
|
+
* on an unselected row selects, and one that begins on a selected row clears.
|
|
16
|
+
* Deciding per row instead would flip rows back off the moment you crossed them
|
|
17
|
+
* twice.
|
|
18
|
+
*
|
|
19
|
+
* Dragging BACK shrinks the range: rows that fall outside it are restored to
|
|
20
|
+
* whatever they were before the drag touched them, which is why `original`
|
|
21
|
+
* exists. Without that, retreating would leave a trail of rows you'd already
|
|
22
|
+
* changed your mind about — the exact complaint that motivated this.
|
|
23
|
+
*
|
|
24
|
+
* The anchor is painted only after the 4px threshold, so a plain click is still
|
|
25
|
+
* a plain click and the checkbox's own handler owns it. Once the drag is real,
|
|
26
|
+
* the click that follows pointerup is swallowed by the caller (`consumeDrag`) —
|
|
27
|
+
* otherwise the checkbox would toggle the anchor a second time and undo the
|
|
28
|
+
* first row of the drag.
|
|
29
|
+
*
|
|
30
|
+
* Past the scroller's edge the drag keeps going: a rAF loop scrolls the
|
|
31
|
+
* container and re-hit-tests the row under the (now stationary) pointer, so
|
|
32
|
+
* the range keeps extending without the mouse moving.
|
|
33
|
+
*
|
|
34
|
+
* Mouse only: on touch, a vertical drag from the gutter is a scroll, and there
|
|
35
|
+
* is no way to tell the two apart in time.
|
|
36
|
+
*/
|
|
37
|
+
export declare function useCheckDragSelect({ enabled, rootRef, rowIds, rowIdOf, isSelected, setRowSelected, }: {
|
|
38
|
+
/** The list is selectable. When false the hook never arms. */
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
/** Container the drag stays within — rows outside it are ignored. */
|
|
41
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Row ids in VISIBLE order — the span between anchor and pointer is a slice
|
|
44
|
+
* of this. Must exclude rows the user can't see (collapsed groups), or
|
|
45
|
+
* dragging past a collapsed group would silently select its contents.
|
|
46
|
+
*/
|
|
47
|
+
rowIds: string[];
|
|
48
|
+
/**
|
|
49
|
+
* What a row's `data-row-id` attribute resolves to in `rowIds`' id space.
|
|
50
|
+
* The grid writes a composite `group␟record` key there (one record can be
|
|
51
|
+
* drawn under several groups), while selection is keyed by record — without
|
|
52
|
+
* this the anchor never matches and the drag selects nothing.
|
|
53
|
+
*/
|
|
54
|
+
rowIdOf?: (attr: string) => string;
|
|
55
|
+
isSelected: (id: string) => boolean;
|
|
56
|
+
/** Set one row's membership explicitly (never a toggle — see above). */
|
|
57
|
+
setRowSelected: (id: string, next: boolean) => void;
|
|
58
|
+
}): {
|
|
59
|
+
tryArm: (e: ReactPointerEvent) => boolean;
|
|
60
|
+
consumeDrag: () => boolean;
|
|
61
|
+
};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef, } from "react";
|
|
3
|
+
export const ROW_CHECK_ATTR = "data-row-check";
|
|
4
|
+
const EDGE_PX = 40;
|
|
5
|
+
const MAX_STEP_PX = 24;
|
|
6
|
+
function verticalScrollerOf(root) {
|
|
7
|
+
let node = root;
|
|
8
|
+
while (node && node !== document.body) {
|
|
9
|
+
const oy = getComputedStyle(node).overflowY;
|
|
10
|
+
if ((oy === "auto" || oy === "scroll") && node.scrollHeight > node.clientHeight)
|
|
11
|
+
return node;
|
|
12
|
+
node = node.parentElement;
|
|
13
|
+
}
|
|
14
|
+
return (document.scrollingElement ?? document.documentElement);
|
|
15
|
+
}
|
|
16
|
+
function edgeStep(y, scroller) {
|
|
17
|
+
const isDocument = scroller === document.scrollingElement || scroller === document.documentElement;
|
|
18
|
+
const top = isDocument ? 0 : scroller.getBoundingClientRect().top;
|
|
19
|
+
const bottom = isDocument ? window.innerHeight : scroller.getBoundingClientRect().bottom;
|
|
20
|
+
if (y < top + EDGE_PX)
|
|
21
|
+
return -Math.min(MAX_STEP_PX, Math.ceil((top + EDGE_PX - y) / 4));
|
|
22
|
+
if (y > bottom - EDGE_PX)
|
|
23
|
+
return Math.min(MAX_STEP_PX, Math.ceil((y - (bottom - EDGE_PX)) / 4));
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
export function useCheckDragSelect({ enabled, rootRef, rowIds, rowIdOf = (attr) => attr, isSelected, setRowSelected, }) {
|
|
27
|
+
const dragRef = useRef(null);
|
|
28
|
+
const draggedRef = useRef(false);
|
|
29
|
+
const isSelectedRef = useRef(isSelected);
|
|
30
|
+
const setRowSelectedRef = useRef(setRowSelected);
|
|
31
|
+
const rowIdsRef = useRef(rowIds);
|
|
32
|
+
const rowIdOfRef = useRef(rowIdOf);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
isSelectedRef.current = isSelected;
|
|
35
|
+
setRowSelectedRef.current = setRowSelected;
|
|
36
|
+
rowIdsRef.current = rowIds;
|
|
37
|
+
rowIdOfRef.current = rowIdOf;
|
|
38
|
+
});
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!enabled)
|
|
41
|
+
return;
|
|
42
|
+
let raf = null;
|
|
43
|
+
let scroller = null;
|
|
44
|
+
const applyRange = (d, headId) => {
|
|
45
|
+
const ids = rowIdsRef.current;
|
|
46
|
+
const a = ids.indexOf(d.rowId);
|
|
47
|
+
const h = ids.indexOf(headId);
|
|
48
|
+
if (a < 0 || h < 0)
|
|
49
|
+
return;
|
|
50
|
+
const inRange = new Set(ids.slice(Math.min(a, h), Math.max(a, h) + 1));
|
|
51
|
+
for (const [id, was] of d.original) {
|
|
52
|
+
if (inRange.has(id))
|
|
53
|
+
continue;
|
|
54
|
+
setRowSelectedRef.current(id, was);
|
|
55
|
+
d.original.delete(id);
|
|
56
|
+
}
|
|
57
|
+
for (const id of inRange) {
|
|
58
|
+
if (d.original.has(id))
|
|
59
|
+
continue;
|
|
60
|
+
d.original.set(id, isSelectedRef.current(id));
|
|
61
|
+
setRowSelectedRef.current(id, d.value);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const hitTest = (d) => {
|
|
65
|
+
const el = document.elementFromPoint(d.lastX, d.lastY);
|
|
66
|
+
const rowEl = el?.closest?.("[data-row-id]");
|
|
67
|
+
if (!rowEl || !rootRef.current?.contains(rowEl))
|
|
68
|
+
return;
|
|
69
|
+
const attr = rowEl.getAttribute("data-row-id");
|
|
70
|
+
if (attr)
|
|
71
|
+
applyRange(d, rowIdOfRef.current(attr));
|
|
72
|
+
};
|
|
73
|
+
const stopScrolling = () => {
|
|
74
|
+
if (raf != null)
|
|
75
|
+
cancelAnimationFrame(raf);
|
|
76
|
+
raf = null;
|
|
77
|
+
scroller = null;
|
|
78
|
+
};
|
|
79
|
+
const tick = () => {
|
|
80
|
+
raf = null;
|
|
81
|
+
const d = dragRef.current;
|
|
82
|
+
if (!d?.active || !scroller)
|
|
83
|
+
return;
|
|
84
|
+
const step = edgeStep(d.lastY, scroller);
|
|
85
|
+
if (step === 0)
|
|
86
|
+
return;
|
|
87
|
+
const before = scroller.scrollTop;
|
|
88
|
+
scroller.scrollTop = before + step;
|
|
89
|
+
if (scroller.scrollTop === before)
|
|
90
|
+
return;
|
|
91
|
+
hitTest(d);
|
|
92
|
+
raf = requestAnimationFrame(tick);
|
|
93
|
+
};
|
|
94
|
+
const maybeScroll = (d) => {
|
|
95
|
+
if (!scroller && rootRef.current)
|
|
96
|
+
scroller = verticalScrollerOf(rootRef.current);
|
|
97
|
+
if (!scroller || raf != null)
|
|
98
|
+
return;
|
|
99
|
+
if (edgeStep(d.lastY, scroller) !== 0)
|
|
100
|
+
raf = requestAnimationFrame(tick);
|
|
101
|
+
};
|
|
102
|
+
const onMove = (e) => {
|
|
103
|
+
const d = dragRef.current;
|
|
104
|
+
if (!d)
|
|
105
|
+
return;
|
|
106
|
+
d.lastX = e.clientX;
|
|
107
|
+
d.lastY = e.clientY;
|
|
108
|
+
if (!d.active) {
|
|
109
|
+
if (Math.abs(e.clientY - d.startY) < 4 && Math.abs(e.clientX - d.startX) < 4)
|
|
110
|
+
return;
|
|
111
|
+
d.active = true;
|
|
112
|
+
draggedRef.current = true;
|
|
113
|
+
document.body.style.userSelect = "none";
|
|
114
|
+
applyRange(d, d.rowId);
|
|
115
|
+
}
|
|
116
|
+
hitTest(d);
|
|
117
|
+
maybeScroll(d);
|
|
118
|
+
};
|
|
119
|
+
const onUp = () => {
|
|
120
|
+
const d = dragRef.current;
|
|
121
|
+
dragRef.current = null;
|
|
122
|
+
stopScrolling();
|
|
123
|
+
if (d?.active)
|
|
124
|
+
document.body.style.userSelect = "";
|
|
125
|
+
};
|
|
126
|
+
window.addEventListener("pointermove", onMove);
|
|
127
|
+
window.addEventListener("pointerup", onUp);
|
|
128
|
+
return () => {
|
|
129
|
+
stopScrolling();
|
|
130
|
+
window.removeEventListener("pointermove", onMove);
|
|
131
|
+
window.removeEventListener("pointerup", onUp);
|
|
132
|
+
};
|
|
133
|
+
}, [enabled, rootRef]);
|
|
134
|
+
const tryArm = useCallback((e) => {
|
|
135
|
+
if (!enabled || e.button !== 0 || e.pointerType !== "mouse")
|
|
136
|
+
return false;
|
|
137
|
+
const target = e.target;
|
|
138
|
+
if (!target.closest(`[${ROW_CHECK_ATTR}]`))
|
|
139
|
+
return false;
|
|
140
|
+
const rowEl = target.closest("[data-row-id]");
|
|
141
|
+
const attr = rowEl?.getAttribute("data-row-id");
|
|
142
|
+
if (!attr)
|
|
143
|
+
return false;
|
|
144
|
+
const rowId = rowIdOfRef.current(attr);
|
|
145
|
+
draggedRef.current = false;
|
|
146
|
+
dragRef.current = {
|
|
147
|
+
startX: e.clientX,
|
|
148
|
+
startY: e.clientY,
|
|
149
|
+
lastX: e.clientX,
|
|
150
|
+
lastY: e.clientY,
|
|
151
|
+
rowId,
|
|
152
|
+
value: !isSelectedRef.current(rowId),
|
|
153
|
+
active: false,
|
|
154
|
+
original: new Map(),
|
|
155
|
+
};
|
|
156
|
+
return true;
|
|
157
|
+
}, [enabled]);
|
|
158
|
+
const consumeDrag = useCallback(() => {
|
|
159
|
+
if (!draggedRef.current)
|
|
160
|
+
return false;
|
|
161
|
+
draggedRef.current = false;
|
|
162
|
+
return true;
|
|
163
|
+
}, []);
|
|
164
|
+
return { tryArm, consumeDrag };
|
|
165
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type SelectionRetention } from "./model.js";
|
|
2
|
+
export type { SelectionRetention } from "./model.js";
|
|
3
|
+
export type UseListSelectionResult = {
|
|
4
|
+
selectedIds: Set<string>;
|
|
5
|
+
count: number;
|
|
6
|
+
isSelected: (id: string) => boolean;
|
|
7
|
+
/** Toggle one id. When `next` is omitted, flips current membership. Sets the range anchor. */
|
|
8
|
+
toggle: (id: string, next?: boolean) => void;
|
|
9
|
+
/** Shift-click: additively select the range anchor→id over the current visual order. */
|
|
10
|
+
toggleRange: (id: string) => void;
|
|
11
|
+
/** Group toggle: select all `ids` unless they're already all selected, then deselect them. */
|
|
12
|
+
toggleMany: (ids: string[]) => void;
|
|
13
|
+
/** Select every currently-ordered id. */
|
|
14
|
+
selectAll: () => void;
|
|
15
|
+
/** Empty the selection and reset the anchor. */
|
|
16
|
+
clear: () => void;
|
|
17
|
+
setSelected: (ids: string[]) => void;
|
|
18
|
+
/** True when every ordered id is selected (and there is at least one). */
|
|
19
|
+
allSelected: boolean;
|
|
20
|
+
/** True when some — but not all — ordered ids are selected (indeterminate). */
|
|
21
|
+
someSelected: boolean;
|
|
22
|
+
anchorId: string | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Headless multi-select state for list pages. Generalizes the per-page
|
|
26
|
+
* `Set<string>` selection pattern used by Tasks
|
|
27
|
+
* (the portal's Tasks page) and adds a range anchor for
|
|
28
|
+
* shift-click.
|
|
29
|
+
*
|
|
30
|
+
* `orderedIds` must be the ids in current *visual* order (post filter+sort+group
|
|
31
|
+
* flatten) so range-select and select-all/indeterminate honor exactly what's on
|
|
32
|
+
* screen. `retention="external"` is an explicit escape hatch for query-wide or
|
|
33
|
+
* filtered-modal selection where selected ids may intentionally be offscreen.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useListSelection({ orderedIds, retention, resetKey, }: {
|
|
36
|
+
orderedIds: string[];
|
|
37
|
+
retention?: SelectionRetention;
|
|
38
|
+
resetKey?: string;
|
|
39
|
+
}): UseListSelectionResult;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useReducer } from "react";
|
|
3
|
+
import { useViews } from "../provider/context.js";
|
|
4
|
+
import { createSelectionState, getSelectionSummary, reconcileSelection, selectionReducer, } from "./model.js";
|
|
5
|
+
export function useListSelection({ orderedIds, retention = "ordered", resetKey, }) {
|
|
6
|
+
const context = useMemo(() => ({ orderedIds, retention, resetKey }), [orderedIds, retention, resetKey]);
|
|
7
|
+
const { haptics } = useViews().ports;
|
|
8
|
+
const [storedState, dispatch] = useReducer(selectionReducer, context, createSelectionState);
|
|
9
|
+
const state = useMemo(() => reconcileSelection(storedState, context), [storedState, context]);
|
|
10
|
+
if (state !== storedState) {
|
|
11
|
+
dispatch({ type: "reconcile", context });
|
|
12
|
+
}
|
|
13
|
+
const { selectedIds, anchorId } = state;
|
|
14
|
+
const isSelected = useCallback((id) => selectedIds.has(id), [selectedIds]);
|
|
15
|
+
const toggle = useCallback((id, next) => {
|
|
16
|
+
haptics.selection();
|
|
17
|
+
dispatch({ type: "toggle", id, next, context });
|
|
18
|
+
}, [context, haptics]);
|
|
19
|
+
const toggleRange = useCallback((id) => {
|
|
20
|
+
haptics.selection();
|
|
21
|
+
dispatch({ type: "toggle-range", id, context });
|
|
22
|
+
}, [context, haptics]);
|
|
23
|
+
const toggleMany = useCallback((ids) => {
|
|
24
|
+
haptics.selection();
|
|
25
|
+
dispatch({ type: "toggle-many", ids, context });
|
|
26
|
+
}, [context, haptics]);
|
|
27
|
+
const selectAll = useCallback(() => {
|
|
28
|
+
haptics.impact("medium");
|
|
29
|
+
dispatch({ type: "select-all", context });
|
|
30
|
+
}, [context, haptics]);
|
|
31
|
+
const clear = useCallback(() => dispatch({ type: "clear", context }), [context]);
|
|
32
|
+
const setSelected = useCallback((ids) => dispatch({ type: "set-selected", ids, context }), [context]);
|
|
33
|
+
const { allSelected, someSelected } = useMemo(() => getSelectionSummary(selectedIds, orderedIds), [orderedIds, selectedIds]);
|
|
34
|
+
return {
|
|
35
|
+
selectedIds,
|
|
36
|
+
count: selectedIds.size,
|
|
37
|
+
isSelected,
|
|
38
|
+
toggle,
|
|
39
|
+
toggleRange,
|
|
40
|
+
toggleMany,
|
|
41
|
+
selectAll,
|
|
42
|
+
clear,
|
|
43
|
+
setSelected,
|
|
44
|
+
allSelected,
|
|
45
|
+
someSelected,
|
|
46
|
+
anchorId,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clears the current selection when Escape is pressed, but only while a
|
|
3
|
+
* selection is active. Mirrors the keydown effect used by the Tasks page
|
|
4
|
+
* (src/app/(app)/[workspace]/command/tasks/page.tsx).
|
|
5
|
+
*/
|
|
6
|
+
export declare function useEscapeToClear(active: boolean, clear: () => void): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
export function useEscapeToClear(active, clear) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!active)
|
|
6
|
+
return;
|
|
7
|
+
function onKeyDown(e) {
|
|
8
|
+
if (e.key === "Escape")
|
|
9
|
+
clear();
|
|
10
|
+
}
|
|
11
|
+
window.addEventListener("keydown", onKeyDown);
|
|
12
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
13
|
+
}, [active, clear]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type PointerEvent } from "react";
|
|
2
|
+
/** How long a mouse rests on a row before its record is read. TanStack Router waits 50 ms and instant.page
|
|
3
|
+
* 65 ms; a list row is a large target, which wastes more reads at that pace. */
|
|
4
|
+
export declare const REST_INTENT_MS = 100;
|
|
5
|
+
/**
|
|
6
|
+
* A MOUSE THAT RESTS ON A ROW IS ABOUT TO OPEN IT: `onRest` runs once the pointer has stayed over the row's
|
|
7
|
+
* openable part for `REST_INTENT_MS`, so the record's read is under way before the click. A finger has no rest:
|
|
8
|
+
* on a phone the press still starts the read. Moving off first starts nothing; a mouse with a button held (a drag
|
|
9
|
+
* passing over) starts nothing; a row reads at most once per visit of the pointer; content portaled out of the row
|
|
10
|
+
* (a menu it opened) is no part of it.
|
|
11
|
+
*
|
|
12
|
+
* `accepts` gets the element under the pointer and the row itself, so a row wrapped in a control of its own (a
|
|
13
|
+
* board's sortable shell) can bound its test to what lies inside it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useRestIntent(onRest: (() => void) | undefined, accepts?: (target: Element, row: Element) => boolean): {
|
|
16
|
+
onPointerOver: (event: PointerEvent<Element>) => void;
|
|
17
|
+
onPointerLeave: () => void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
3
|
+
export const REST_INTENT_MS = 100;
|
|
4
|
+
const ANYWHERE = () => true;
|
|
5
|
+
export function useRestIntent(onRest, accepts = ANYWHERE) {
|
|
6
|
+
const timer = useRef(null);
|
|
7
|
+
const fired = useRef(false);
|
|
8
|
+
const cancel = useCallback(() => {
|
|
9
|
+
if (timer.current !== null)
|
|
10
|
+
clearTimeout(timer.current);
|
|
11
|
+
timer.current = null;
|
|
12
|
+
}, []);
|
|
13
|
+
useEffect(() => cancel, [cancel]);
|
|
14
|
+
const onPointerOver = useCallback((event) => {
|
|
15
|
+
if (!onRest || event.pointerType !== "mouse" || event.buttons !== 0 || fired.current)
|
|
16
|
+
return;
|
|
17
|
+
const target = event.target;
|
|
18
|
+
if (!event.currentTarget.contains(target) || !accepts(target, event.currentTarget)) {
|
|
19
|
+
cancel();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (timer.current !== null)
|
|
23
|
+
return;
|
|
24
|
+
timer.current = setTimeout(() => {
|
|
25
|
+
timer.current = null;
|
|
26
|
+
fired.current = true;
|
|
27
|
+
onRest();
|
|
28
|
+
}, REST_INTENT_MS);
|
|
29
|
+
}, [onRest, accepts, cancel]);
|
|
30
|
+
const onPointerLeave = useCallback(() => {
|
|
31
|
+
cancel();
|
|
32
|
+
fired.current = false;
|
|
33
|
+
}, [cancel]);
|
|
34
|
+
return { onPointerOver, onPointerLeave };
|
|
35
|
+
}
|