orio-ui 1.24.0 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -3
- package/bin/orio-ui.mjs +72 -0
- package/dist/agents/ROUTING.md +140 -0
- package/dist/agents/component-finder.md +142 -0
- package/dist/agents/component-worker.md +152 -0
- package/dist/agents/snippet.md +6 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/AnimatedContainer.USAGE.md +79 -0
- package/dist/runtime/components/Badge.USAGE.md +75 -0
- package/dist/runtime/components/Banner.USAGE.md +52 -0
- package/dist/runtime/components/Button.USAGE.md +78 -0
- package/dist/runtime/components/Button.d.vue.ts +3 -2
- package/dist/runtime/components/Button.vue +19 -11
- package/dist/runtime/components/Button.vue.d.ts +3 -2
- package/dist/runtime/components/Calendar.USAGE.md +59 -0
- package/dist/runtime/components/Calendar.vue +254 -87
- package/dist/runtime/components/Canvas/USAGE.md +73 -0
- package/dist/runtime/components/CheckBox.USAGE.md +63 -0
- package/dist/runtime/components/CheckBox.vue +9 -3
- package/dist/runtime/components/CheckboxGroup.USAGE.md +95 -0
- package/dist/runtime/components/CheckboxGroup.vue +7 -1
- package/dist/runtime/components/ControlElement.USAGE.md +77 -0
- package/dist/runtime/components/ControlElement.d.vue.ts +42 -27
- package/dist/runtime/components/ControlElement.vue +28 -9
- package/dist/runtime/components/ControlElement.vue.d.ts +42 -27
- package/dist/runtime/components/DashedContainer.USAGE.md +65 -0
- package/dist/runtime/components/EmptyState.USAGE.md +65 -0
- package/dist/runtime/components/Form.USAGE.md +102 -0
- package/dist/runtime/components/Icon.USAGE.md +61 -0
- package/dist/runtime/components/Input.USAGE.md +57 -0
- package/dist/runtime/components/Input.vue +13 -3
- package/dist/runtime/components/ListItem.USAGE.md +84 -0
- package/dist/runtime/components/LoadingSpinner.USAGE.md +50 -0
- package/dist/runtime/components/LocaleSwitcher.USAGE.md +73 -0
- package/dist/runtime/components/Modal.USAGE.md +72 -0
- package/dist/runtime/components/NavButton.USAGE.md +80 -0
- package/dist/runtime/components/NavButton.d.vue.ts +0 -1
- package/dist/runtime/components/NavButton.vue +9 -5
- package/dist/runtime/components/NavButton.vue.d.ts +0 -1
- package/dist/runtime/components/NumberInput/Horizontal.USAGE.md +61 -0
- package/dist/runtime/components/NumberInput/Horizontal.vue +7 -2
- package/dist/runtime/components/NumberInput/USAGE.md +74 -0
- package/dist/runtime/components/NumberInput/Vertical.USAGE.md +55 -0
- package/dist/runtime/components/NumberInput/Vertical.vue +7 -2
- package/dist/runtime/components/NumberInput/index.d.vue.ts +0 -2
- package/dist/runtime/components/NumberInput/index.vue +9 -7
- package/dist/runtime/components/NumberInput/index.vue.d.ts +0 -2
- package/dist/runtime/components/Popover.USAGE.md +103 -0
- package/dist/runtime/components/RadioButton.USAGE.md +72 -0
- package/dist/runtime/components/RadioButton.d.vue.ts +0 -2
- package/dist/runtime/components/RadioButton.vue +9 -4
- package/dist/runtime/components/RadioButton.vue.d.ts +0 -2
- package/dist/runtime/components/Selector.USAGE.md +131 -0
- package/dist/runtime/components/Selector.d.vue.ts +1 -0
- package/dist/runtime/components/Selector.vue +10 -4
- package/dist/runtime/components/Selector.vue.d.ts +1 -0
- package/dist/runtime/components/SwitchButton.USAGE.md +62 -0
- package/dist/runtime/components/SwitchButton.d.vue.ts +1 -4
- package/dist/runtime/components/SwitchButton.vue +10 -7
- package/dist/runtime/components/SwitchButton.vue.d.ts +1 -4
- package/dist/runtime/components/Tag.USAGE.md +51 -0
- package/dist/runtime/components/TaggableSelector.USAGE.md +73 -0
- package/dist/runtime/components/TaggableSelector.vue +7 -1
- package/dist/runtime/components/Textarea.USAGE.md +72 -0
- package/dist/runtime/components/Textarea.vue +13 -3
- package/dist/runtime/components/Tooltip.USAGE.md +84 -0
- package/dist/runtime/components/ZoomableContainer.USAGE.md +108 -0
- package/dist/runtime/components/date/Picker.USAGE.md +52 -0
- package/dist/runtime/components/date/Picker.vue +7 -1
- package/dist/runtime/components/date/PickerTrigger.USAGE.md +65 -0
- package/dist/runtime/components/date/PickerTrigger.vue +9 -3
- package/dist/runtime/components/date/RangePicker.USAGE.md +97 -0
- package/dist/runtime/components/date/RangePicker.vue +7 -1
- package/dist/runtime/components/gallery/Carousel.USAGE.md +98 -0
- package/dist/runtime/components/gallery/CarouselPreview.USAGE.md +51 -0
- package/dist/runtime/components/upload/USAGE.md +91 -0
- package/dist/runtime/components/view/Dates.USAGE.md +67 -0
- package/dist/runtime/components/view/KeyBinds.USAGE.md +58 -0
- package/dist/runtime/components/view/Separator.USAGE.md +57 -0
- package/dist/runtime/components/view/Text.USAGE.md +68 -0
- package/dist/runtime/composables/useApi.USAGE.md +64 -0
- package/dist/runtime/composables/useControlSize.USAGE.md +73 -0
- package/dist/runtime/composables/useDecimalFormatter.USAGE.md +72 -0
- package/dist/runtime/composables/useFilter.USAGE.md +120 -0
- package/dist/runtime/composables/useFilter.d.ts +91 -0
- package/dist/runtime/composables/useFilter.js +111 -0
- package/dist/runtime/composables/useFuzzySearch.USAGE.md +68 -0
- package/dist/runtime/composables/useInertia.USAGE.md +80 -0
- package/dist/runtime/composables/useListKeyboard.USAGE.md +97 -0
- package/dist/runtime/composables/useModal.USAGE.md +82 -0
- package/dist/runtime/composables/usePinchZoom.USAGE.md +95 -0
- package/dist/runtime/composables/usePressAndHold.USAGE.md +70 -0
- package/dist/runtime/composables/useRovingGrid.USAGE.md +106 -0
- package/dist/runtime/composables/useRovingGrid.d.ts +35 -0
- package/dist/runtime/composables/useRovingGrid.js +115 -0
- package/dist/runtime/composables/useSound.USAGE.md +74 -0
- package/dist/runtime/composables/useTheme.USAGE.md +76 -0
- package/dist/runtime/composables/useUrlSync.USAGE.md +91 -0
- package/dist/runtime/composables/useValidation.USAGE.md +100 -0
- package/dist/runtime/i18n/en.json +4 -1
- package/dist/runtime/i18n/uk.json +4 -1
- package/package.json +12 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: composable
|
|
3
|
+
category: Composables
|
|
4
|
+
purpose: control size tokens, sizing tokens for form controls, control variant sizing
|
|
5
|
+
short: provide/inject `ControlSize` (sm/md/lg/xl) and read a CSS-var token bag for the active size
|
|
6
|
+
invariants: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# useControlSize — agent-only invariants
|
|
10
|
+
|
|
11
|
+
This composable owns the **CSS variable bag** that maps a `ControlSize`
|
|
12
|
+
(`sm` / `md` / `lg` / `xl`) to concrete padding, font, gap, radius, and
|
|
13
|
+
icon-size tokens. Used internally by ControlElement and friends.
|
|
14
|
+
|
|
15
|
+
## Invariants
|
|
16
|
+
|
|
17
|
+
- **Two exports**: `provideControlSize(size)` and `useControlTokens(explicit?, fallback?)`.
|
|
18
|
+
Most consumers don't need either — ControlElement wires them — but you
|
|
19
|
+
can use them to size custom controls.
|
|
20
|
+
- **Provide key is a module-local `Symbol`** — there is exactly one
|
|
21
|
+
channel per app. `provideControlSize(ref("lg"))` from a parent scopes
|
|
22
|
+
every nested `useControlTokens()` call to that size.
|
|
23
|
+
- **`useControlTokens(explicit, fallback = "md")`** returns:
|
|
24
|
+
- `size: ComputedRef<ControlSize>` — resolved size (explicit ?? injected
|
|
25
|
+
?? fallback).
|
|
26
|
+
- `tokens: ComputedRef<Record<string, string>>` — the CSS-var bag for
|
|
27
|
+
that size. Spread it onto a `style` binding to apply the sizing.
|
|
28
|
+
- **Token keys** include `--control-font-size`, `--control-label-font-size`,
|
|
29
|
+
`--control-py`, `--control-px`, `--control-gap`, `--control-radius`,
|
|
30
|
+
`--control-icon-size`, `--control-inner-block-start`, `--control-inner-block-end`,
|
|
31
|
+
`--control-label-block-start`. Adding new tokens requires extending
|
|
32
|
+
every size in `sizeTokens`.
|
|
33
|
+
- **`sizeTokens` is exported** as the raw record — useful for previews or
|
|
34
|
+
ad-hoc lookups outside Vue.
|
|
35
|
+
|
|
36
|
+
## Gotchas
|
|
37
|
+
|
|
38
|
+
- **`useControlTokens` works outside an `<orio-control-element>`** — it
|
|
39
|
+
falls back to `md` (or the provided fallback) when no provider exists.
|
|
40
|
+
No error is thrown.
|
|
41
|
+
- **The `explicit` argument wins over the injection.** Use it when the
|
|
42
|
+
caller takes an own `size` prop and wants it to override an ambient
|
|
43
|
+
one.
|
|
44
|
+
- **Style binding requires the `tokens` value, not the ref.** Spread it
|
|
45
|
+
on `:style`:
|
|
46
|
+
```vue
|
|
47
|
+
<div :style="tokens">...</div>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick reference — custom control consuming the tokens
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { computed, toRef } from "vue";
|
|
54
|
+
import { useControlTokens } from "../composables/useControlSize";
|
|
55
|
+
import type { ControlSize } from "../components/ControlElement.vue";
|
|
56
|
+
|
|
57
|
+
interface Props { size?: ControlSize }
|
|
58
|
+
const props = defineProps<Props>();
|
|
59
|
+
const { tokens } = useControlTokens(toRef(props, "size"));
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```vue
|
|
63
|
+
<template>
|
|
64
|
+
<div :style="tokens" class="my-control">…</div>
|
|
65
|
+
</template>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Related
|
|
69
|
+
|
|
70
|
+
- `<orio-control-element>` — provides and consumes this composable.
|
|
71
|
+
- `<orio-selector>` — uses `useControlTokens(size)` to size the
|
|
72
|
+
dropdown popover content.
|
|
73
|
+
- Public API reference: `docs/composables/use-control-size.md`.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: composable
|
|
3
|
+
category: Composables
|
|
4
|
+
purpose: locale-aware number formatting, decimal parser, currency-safe parser
|
|
5
|
+
short: parse numeric strings (US or EU separator) and format via Intl.NumberFormat with locale defaults
|
|
6
|
+
invariants: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# useDecimalFormatter — agent-only invariants
|
|
10
|
+
|
|
11
|
+
Returns `{ toNumber, formatDecimal }`. Stateless, no Vue reactivity —
|
|
12
|
+
call it once and reuse the two helpers.
|
|
13
|
+
|
|
14
|
+
## Invariants
|
|
15
|
+
|
|
16
|
+
- **`toNumber(input: string | number)`**:
|
|
17
|
+
- Numbers pass through as-is (non-finite → `null`).
|
|
18
|
+
- Strings are stripped of any character except digits, `,`, `.`, `-`.
|
|
19
|
+
- **Decimal separator auto-detected** by checking the position of the
|
|
20
|
+
last `,` and last `.`:
|
|
21
|
+
- If last `,` is after last `.` → European format. Strip `.` (thousands)
|
|
22
|
+
and convert `,` to `.` (decimal).
|
|
23
|
+
- Otherwise → US format. Strip `,` and keep `.`.
|
|
24
|
+
- Returns `null` for empty / unparseable input.
|
|
25
|
+
- **`formatDecimal(input, options?)`**:
|
|
26
|
+
- `locale`: defaults to `navigator.languages[0] ?? navigator.language`
|
|
27
|
+
on client, `"de-DE"` on server.
|
|
28
|
+
- `decimals`: shortcut that sets both `minimumFractionDigits` and
|
|
29
|
+
`maximumFractionDigits` (default `2`).
|
|
30
|
+
- Explicit `minimumFractionDigits` / `maximumFractionDigits` override
|
|
31
|
+
the `decimals` shortcut.
|
|
32
|
+
- Returns `null` if `toNumber` fails.
|
|
33
|
+
- **Uses `Intl.NumberFormat`** under the hood — output respects the
|
|
34
|
+
locale's group separator and decimal mark.
|
|
35
|
+
|
|
36
|
+
## Gotchas
|
|
37
|
+
|
|
38
|
+
- **Auto-separator detection is heuristic.** `"1,000"` is ambiguous; the
|
|
39
|
+
parser treats it as US (1000), not EU (1.0). For unambiguous behavior,
|
|
40
|
+
strip separators before passing.
|
|
41
|
+
- **No currency symbol handling.** `"$1,234.56"` is stripped to
|
|
42
|
+
`"1234.56"` and parsed. To format as currency, build your own with
|
|
43
|
+
`Intl.NumberFormat(locale, { style: "currency", currency: "USD" })`.
|
|
44
|
+
- **SSR fallback locale is `"de-DE"`**, not `"en-US"`. EU number
|
|
45
|
+
formatting in SSR pre-hydration may surprise US consumers — pass
|
|
46
|
+
`locale` explicitly to avoid hydration mismatches.
|
|
47
|
+
- **Negative numbers**: `-` is allowed in the cleaning regex anywhere in
|
|
48
|
+
the string. `"100-50"` becomes `"100-50"` then `Number("100-50") = NaN`
|
|
49
|
+
→ null. No expression evaluation.
|
|
50
|
+
|
|
51
|
+
## Quick reference
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { useDecimalFormatter } from "../composables/useDecimalFormatter";
|
|
55
|
+
|
|
56
|
+
const { toNumber, formatDecimal } = useDecimalFormatter();
|
|
57
|
+
|
|
58
|
+
toNumber("1.234,56"); // 1234.56 (EU)
|
|
59
|
+
toNumber("1,234.56"); // 1234.56 (US)
|
|
60
|
+
toNumber("abc"); // null
|
|
61
|
+
|
|
62
|
+
formatDecimal(1234.5, { locale: "de-DE" }); // "1.234,50"
|
|
63
|
+
formatDecimal(1234.5, { locale: "en-US" }); // "1,234.50"
|
|
64
|
+
formatDecimal(1234.567, { decimals: 0 }); // "1,235"
|
|
65
|
+
formatDecimal("$1,234.567", { maximumFractionDigits: 1 }); // "1,234.6"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Related
|
|
69
|
+
|
|
70
|
+
- `<orio-number-input>` — uses similar fraction-digit semantics via its
|
|
71
|
+
`decimalPlaces` prop.
|
|
72
|
+
- Public API reference: `docs/composables/use-decimal-formatter.md`.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: composable
|
|
3
|
+
category: Composables
|
|
4
|
+
purpose: named filter group, v-bind bags for pickers, active chips, URL-synced filters, filter state
|
|
5
|
+
short: named filter group with v-bind bags, $-helpers, $active chips, $clearAll, optional URL sync via lazy import
|
|
6
|
+
invariants: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# useFilter — agent-only invariants
|
|
10
|
+
|
|
11
|
+
`useFilter` defines or retrieves a **named filter group** stored in a
|
|
12
|
+
module-level registry. Any component that knows the `id` can read and
|
|
13
|
+
mutate the same reactive state — independent of the component tree.
|
|
14
|
+
|
|
15
|
+
There's a dedicated `use-filter-onboarder` subagent that owns the canonical
|
|
16
|
+
integration patterns. Trigger it for non-trivial setups (filter bars,
|
|
17
|
+
chip rows, URL-synced filters).
|
|
18
|
+
|
|
19
|
+
## Invariants
|
|
20
|
+
|
|
21
|
+
- **Two overloads**:
|
|
22
|
+
- `useFilter(id, config, options?)` — defines a group.
|
|
23
|
+
- `useFilter(id)` — retrieves an existing group. Throws if no group
|
|
24
|
+
by that id has been defined.
|
|
25
|
+
- **Module-level `registry`** — calls with the same `id` return the
|
|
26
|
+
same `FilterGroup` reference. Defining twice warns and returns the
|
|
27
|
+
existing group (the new config is ignored).
|
|
28
|
+
- **`FilterDefinition.value` is both the initial value AND the
|
|
29
|
+
"empty" baseline.** Used to compute `isActive` (deep `!== initial`)
|
|
30
|
+
and to reset via `clear()`.
|
|
31
|
+
- **`structuredClone`** copies the initial values so mutating the
|
|
32
|
+
returned `value` does not mutate the baseline.
|
|
33
|
+
- **`isEqual`** is a hand-rolled deep equality (`===` for primitives,
|
|
34
|
+
recursive for arrays and plain objects). Custom classes / Date /
|
|
35
|
+
Map / Set fall back to `===` → likely a false negative.
|
|
36
|
+
- **Each filter exposes a v-bind bag** via `filters[name]`:
|
|
37
|
+
```ts
|
|
38
|
+
{ modelValue, "onUpdate:modelValue": (v) => state[name] = v }
|
|
39
|
+
```
|
|
40
|
+
Spread on any `v-model`-compatible component:
|
|
41
|
+
`<orio-selector v-bind="filters.category" />`.
|
|
42
|
+
- **`filters.$.<name>`** has helpers per filter: `value`, `initial`,
|
|
43
|
+
`isActive`, `clear()`.
|
|
44
|
+
- **`filters.$active`** is a `ComputedRef<ActiveFilter[]>` — array of
|
|
45
|
+
`{ name, value, clear }` for filters whose value differs from the
|
|
46
|
+
initial. Use for chip rows.
|
|
47
|
+
- **`filters.$clearAll()`** resets every filter to its initial value.
|
|
48
|
+
- **`filters.$state`** is the raw `Ref<Record<string, unknown>>` —
|
|
49
|
+
serialize for API calls or persist externally.
|
|
50
|
+
- **URL sync (`options.url: true`)** lazy-imports `./useUrlSync`. The
|
|
51
|
+
Nuxt `#imports` dep is **not** loaded unless this flag is set,
|
|
52
|
+
keeping `useFilter` runnable in non-Nuxt contexts.
|
|
53
|
+
- **URL-synced watcher lives in a detached `effectScope`** owned by
|
|
54
|
+
the registry, not by the component that defined the group — the
|
|
55
|
+
watcher outlives the defining component.
|
|
56
|
+
- **`disposeFilter(id)`** removes the group and stops its URL-sync
|
|
57
|
+
effect scope. Use in SPAs to clear page-scoped filter groups on
|
|
58
|
+
route change.
|
|
59
|
+
|
|
60
|
+
## Gotchas
|
|
61
|
+
|
|
62
|
+
- **Filter names become top-level URL keys** when `url: true`.
|
|
63
|
+
Collisions across multiple URL-synced groups on the same page
|
|
64
|
+
silently overwrite each other.
|
|
65
|
+
- **`structuredClone` doesn't handle Functions, DOM nodes, or class
|
|
66
|
+
instances** — passing them in `value` will throw at define time.
|
|
67
|
+
- **`$active` recomputes on every state change**, doing a deep
|
|
68
|
+
comparison per filter. For large filter groups with deep objects,
|
|
69
|
+
consider shallow representations.
|
|
70
|
+
- **Lazy URL sync arrives one microtask late** — the initial render
|
|
71
|
+
may flash the default values before the URL values land. Acceptable
|
|
72
|
+
for chips/dropdowns; not for visibly-important first paint.
|
|
73
|
+
- **Retrieving an undefined group throws** — always define first
|
|
74
|
+
somewhere in the tree (layout / page setup) before retrieving in
|
|
75
|
+
children.
|
|
76
|
+
|
|
77
|
+
## Quick reference — define + bind + chips
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const filters = useFilter(
|
|
81
|
+
"appointments",
|
|
82
|
+
{
|
|
83
|
+
category: { value: null as string | null },
|
|
84
|
+
status: { value: [] as string[] },
|
|
85
|
+
dateRange:{ value: { from: null, to: null } as { from: string | null; to: string | null } },
|
|
86
|
+
},
|
|
87
|
+
{ url: true },
|
|
88
|
+
);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```vue
|
|
92
|
+
<template>
|
|
93
|
+
<orio-selector v-bind="filters.category" :options="categories" />
|
|
94
|
+
<orio-taggable-selector v-bind="filters.status" :options="statuses" />
|
|
95
|
+
|
|
96
|
+
<orio-tag
|
|
97
|
+
v-for="active in filters.$active"
|
|
98
|
+
:key="active.name"
|
|
99
|
+
:text="active.name"
|
|
100
|
+
variant="accent"
|
|
101
|
+
/>
|
|
102
|
+
<orio-button v-if="filters.$active.length" @click="filters.$clearAll">
|
|
103
|
+
Clear all
|
|
104
|
+
</orio-button>
|
|
105
|
+
</template>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Quick reference — retrieve elsewhere
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const filters = useFilter("appointments"); // same instance
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Related
|
|
115
|
+
|
|
116
|
+
- `useUrlSync` — lazy-loaded when `url: true`.
|
|
117
|
+
- `use-filter-onboarder` subagent — canonical patterns for filter
|
|
118
|
+
bars, chip rows, URL sync, and splitting filter UI across the page
|
|
119
|
+
tree.
|
|
120
|
+
- Public API reference: `docs/composables/use-filter.md`.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type ComputedRef, type Ref } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Definition of a single filter inside a group.
|
|
4
|
+
*
|
|
5
|
+
* `value` is both the initial value and the "empty" baseline used to compute
|
|
6
|
+
* `isActive` and to reset to via `clear()`.
|
|
7
|
+
*/
|
|
8
|
+
export interface FilterDefinition<Value = unknown> {
|
|
9
|
+
value: Value;
|
|
10
|
+
}
|
|
11
|
+
export type FilterConfig = Record<string, FilterDefinition>;
|
|
12
|
+
export interface FilterOptions {
|
|
13
|
+
/**
|
|
14
|
+
* When true, the group's state is mirrored to URL query params via
|
|
15
|
+
* `useUrlSync`. The dependency is loaded lazily — `useUrlSync` (and its
|
|
16
|
+
* `#imports` use of `useRoute`) is never touched unless this flag is set,
|
|
17
|
+
* keeping `useFilter` runnable outside of a Nuxt context.
|
|
18
|
+
*
|
|
19
|
+
* Filter names become top-level URL keys; avoid colliding names across
|
|
20
|
+
* multiple URL-synced groups on the same page.
|
|
21
|
+
*/
|
|
22
|
+
url?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Bindable prop bag — spread onto any `v-model`-compatible component:
|
|
26
|
+
* `<orio-selector v-bind="filters.category" :options="..." />`
|
|
27
|
+
*/
|
|
28
|
+
export interface FilterBind<Value = unknown> {
|
|
29
|
+
modelValue: Value;
|
|
30
|
+
"onUpdate:modelValue": (value: Value) => void;
|
|
31
|
+
}
|
|
32
|
+
/** Per-filter helpers accessed via `filters.$.<name>`. */
|
|
33
|
+
export interface FilterHelpers<Value = unknown> {
|
|
34
|
+
value: Value;
|
|
35
|
+
initial: Value;
|
|
36
|
+
isActive: boolean;
|
|
37
|
+
clear: () => void;
|
|
38
|
+
}
|
|
39
|
+
export interface ActiveFilter {
|
|
40
|
+
name: string;
|
|
41
|
+
value: unknown;
|
|
42
|
+
clear: () => void;
|
|
43
|
+
}
|
|
44
|
+
export type FilterGroup<Config extends FilterConfig> = {
|
|
45
|
+
[Key in keyof Config]: FilterBind<Config[Key]["value"]>;
|
|
46
|
+
} & {
|
|
47
|
+
$: {
|
|
48
|
+
[Key in keyof Config]: FilterHelpers<Config[Key]["value"]>;
|
|
49
|
+
};
|
|
50
|
+
$active: ComputedRef<ActiveFilter[]>;
|
|
51
|
+
$clearAll: () => void;
|
|
52
|
+
$state: Ref<Record<string, unknown>>;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Define or retrieve a named filter group.
|
|
56
|
+
*
|
|
57
|
+
* Define once anywhere in the page (setup, layout, store). Retrieve the same
|
|
58
|
+
* instance elsewhere by id — any component that knows the id can read and
|
|
59
|
+
* mutate the same reactive state, regardless of where it lives in the tree.
|
|
60
|
+
*
|
|
61
|
+
* @example Define
|
|
62
|
+
* ```ts
|
|
63
|
+
* const filters = useFilter('appointments', {
|
|
64
|
+
* category: { value: null },
|
|
65
|
+
* status: { value: [] as string[] },
|
|
66
|
+
* dateRange: { value: { from: null, to: null } },
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Bind to any v-model component
|
|
71
|
+
* ```vue
|
|
72
|
+
* <orio-selector v-bind="filters.category" :options="categories" />
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Retrieve elsewhere
|
|
76
|
+
* ```ts
|
|
77
|
+
* const filters = useFilter('appointments')
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Mirror to URL (Nuxt only)
|
|
81
|
+
* ```ts
|
|
82
|
+
* const filters = useFilter('appointments', config, { url: true })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function useFilter<Config extends FilterConfig>(id: string, config: Config, options?: FilterOptions): FilterGroup<Config>;
|
|
86
|
+
export declare function useFilter(id: string): FilterGroup<FilterConfig>;
|
|
87
|
+
/**
|
|
88
|
+
* Remove a filter group from the registry. Use in SPAs where filter groups
|
|
89
|
+
* are page-scoped and should not leak between routes.
|
|
90
|
+
*/
|
|
91
|
+
export declare function disposeFilter(id: string): void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
effectScope,
|
|
4
|
+
ref
|
|
5
|
+
} from "vue";
|
|
6
|
+
const registry = /* @__PURE__ */ new Map();
|
|
7
|
+
const urlSyncScopes = /* @__PURE__ */ new Map();
|
|
8
|
+
export function useFilter(id, config, options = {}) {
|
|
9
|
+
const existing = registry.get(id);
|
|
10
|
+
if (existing) {
|
|
11
|
+
if (config) {
|
|
12
|
+
console.warn(
|
|
13
|
+
`[useFilter] group "${id}" is already defined \u2014 ignoring new config.`
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return existing;
|
|
17
|
+
}
|
|
18
|
+
if (!config) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`[useFilter] group "${id}" is not defined. Pass a config on the first call.`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
const initial = {};
|
|
24
|
+
for (const [name, definition] of Object.entries(config)) {
|
|
25
|
+
initial[name] = clone(definition.value);
|
|
26
|
+
}
|
|
27
|
+
const state = ref({ ...initial });
|
|
28
|
+
if (options.url) {
|
|
29
|
+
const scope = effectScope(true);
|
|
30
|
+
urlSyncScopes.set(id, scope);
|
|
31
|
+
void import("./useUrlSync.js").then(({ useUrlSync }) => {
|
|
32
|
+
scope.run(() => useUrlSync(state, Object.keys(config)));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const handle = {};
|
|
36
|
+
const helpers = {};
|
|
37
|
+
for (const name of Object.keys(config)) {
|
|
38
|
+
helpers[name] = {
|
|
39
|
+
get value() {
|
|
40
|
+
return state.value[name];
|
|
41
|
+
},
|
|
42
|
+
get initial() {
|
|
43
|
+
return initial[name];
|
|
44
|
+
},
|
|
45
|
+
get isActive() {
|
|
46
|
+
return !isEqual(state.value[name], initial[name]);
|
|
47
|
+
},
|
|
48
|
+
clear() {
|
|
49
|
+
state.value[name] = clone(initial[name]);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(handle, name, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
value: {
|
|
55
|
+
get modelValue() {
|
|
56
|
+
return state.value[name];
|
|
57
|
+
},
|
|
58
|
+
"onUpdate:modelValue": (value) => {
|
|
59
|
+
state.value[name] = value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
Object.defineProperty(handle, "$", { value: helpers });
|
|
65
|
+
Object.defineProperty(handle, "$active", {
|
|
66
|
+
value: computed(
|
|
67
|
+
() => Object.keys(config).flatMap((name) => {
|
|
68
|
+
const helper = helpers[name];
|
|
69
|
+
return helper.isActive ? [{ name, value: helper.value, clear: helper.clear }] : [];
|
|
70
|
+
})
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(handle, "$clearAll", {
|
|
74
|
+
value: () => {
|
|
75
|
+
for (const name of Object.keys(config)) {
|
|
76
|
+
state.value[name] = clone(initial[name]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(handle, "$state", { value: state });
|
|
81
|
+
registry.set(id, handle);
|
|
82
|
+
return handle;
|
|
83
|
+
}
|
|
84
|
+
export function disposeFilter(id) {
|
|
85
|
+
urlSyncScopes.get(id)?.stop();
|
|
86
|
+
urlSyncScopes.delete(id);
|
|
87
|
+
registry.delete(id);
|
|
88
|
+
}
|
|
89
|
+
function clone(value) {
|
|
90
|
+
if (value === null || typeof value !== "object") return value;
|
|
91
|
+
return structuredClone(value);
|
|
92
|
+
}
|
|
93
|
+
function isEqual(a, b) {
|
|
94
|
+
if (a === b) return true;
|
|
95
|
+
if (a === null || b === null) return false;
|
|
96
|
+
if (typeof a !== typeof b) return false;
|
|
97
|
+
if (typeof a !== "object") return false;
|
|
98
|
+
if (Array.isArray(a)) {
|
|
99
|
+
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
100
|
+
return a.every((item, index) => isEqual(item, b[index]));
|
|
101
|
+
}
|
|
102
|
+
const keysA = Object.keys(a);
|
|
103
|
+
const keysB = Object.keys(b);
|
|
104
|
+
if (keysA.length !== keysB.length) return false;
|
|
105
|
+
return keysA.every(
|
|
106
|
+
(key) => isEqual(
|
|
107
|
+
a[key],
|
|
108
|
+
b[key]
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: composable
|
|
3
|
+
category: Composables
|
|
4
|
+
purpose: fuzzy search, client-side filter, in-memory search, search-as-you-type
|
|
5
|
+
short: typed Fuse.js wrapper that returns a computed list of matched items (strings or objects)
|
|
6
|
+
invariants: false
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# useFuzzySearch — agent-only invariants
|
|
10
|
+
|
|
11
|
+
`useFuzzySearch(dataSource, search, options?)` is a thin wrapper around
|
|
12
|
+
`@vueuse/integrations/useFuse`. It accepts either a `string[]` (no options)
|
|
13
|
+
or a `T[]` of objects (with `FuseOptions<T>`) and returns a `ComputedRef`
|
|
14
|
+
of matches — items only, no scores.
|
|
15
|
+
|
|
16
|
+
## Invariants
|
|
17
|
+
|
|
18
|
+
- **Two overloads**:
|
|
19
|
+
- `useFuzzySearch(dataSource: MaybeRef<string[]>, search: MaybeRef<string>)`
|
|
20
|
+
→ matches against the strings directly.
|
|
21
|
+
- `useFuzzySearch<T>(dataSource: MaybeRef<T[]>, search: MaybeRef<string>, options: FuseOptions<T>)`
|
|
22
|
+
→ matches against keys you specify in `options.keys`.
|
|
23
|
+
- **`matchAllWhenSearchEmpty: true`** is forced — when `search` is `""`,
|
|
24
|
+
the returned list equals the full dataSource. No empty results on
|
|
25
|
+
empty query.
|
|
26
|
+
- **Returns a `ComputedRef`**, so it updates as `search` or `dataSource`
|
|
27
|
+
changes (when passed as refs).
|
|
28
|
+
- **The result is item-only**, not Fuse's `{ item, score }` records.
|
|
29
|
+
Score data is not exposed — if you need it, use `useFuse` directly.
|
|
30
|
+
|
|
31
|
+
## Gotchas
|
|
32
|
+
|
|
33
|
+
- **No debouncing.** Every keystroke runs the match against the full
|
|
34
|
+
dataset. For very large lists (10k+ items) or expensive options,
|
|
35
|
+
debounce `search` upstream.
|
|
36
|
+
- **No highlighting of matched substrings.** Use `useFuse` directly if
|
|
37
|
+
you need the match indices for highlighting.
|
|
38
|
+
- **`MaybeRef` means raw arrays work too** — but they won't be
|
|
39
|
+
reactive. Wrap in `ref` / `computed` if the underlying data changes.
|
|
40
|
+
|
|
41
|
+
## Quick reference — string list
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { ref } from "vue";
|
|
45
|
+
import { useFuzzySearch } from "../composables/useFuzzySearch";
|
|
46
|
+
|
|
47
|
+
const query = ref("");
|
|
48
|
+
const colors = ["red", "green", "blue", "yellow"];
|
|
49
|
+
const matches = useFuzzySearch(colors, query);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick reference — object list
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
interface User { id: string; name: string; email: string }
|
|
56
|
+
const users = ref<User[]>([...]);
|
|
57
|
+
const query = ref("");
|
|
58
|
+
const matches = useFuzzySearch(users, query, {
|
|
59
|
+
keys: ["name", "email"],
|
|
60
|
+
threshold: 0.3,
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Related
|
|
65
|
+
|
|
66
|
+
- `<orio-selector>` — pair with this composable + the `#options-addon`
|
|
67
|
+
slot to build a filterable dropdown.
|
|
68
|
+
- Public API reference: `docs/composables/use-fuzzy-search.md`.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: composable
|
|
3
|
+
category: Composables
|
|
4
|
+
purpose: inertia, momentum decay for gestures, fling-and-decelerate, momentum scroll
|
|
5
|
+
short: post-drag momentum loop that calls a tick callback with decaying velocity each frame
|
|
6
|
+
invariants: true
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# useInertia — agent-only invariants
|
|
10
|
+
|
|
11
|
+
`useInertia(onTick, options?)` runs a `requestAnimationFrame` loop that
|
|
12
|
+
decays velocity by `friction` each frame and calls `onTick(vx, vy)`. The
|
|
13
|
+
consumer applies the delta to its own state (pan offset, scroll, etc.).
|
|
14
|
+
|
|
15
|
+
## Invariants
|
|
16
|
+
|
|
17
|
+
- **`onTick(dx, dy)`** is called every frame while velocity exceeds
|
|
18
|
+
`minVelocity` (default `0.5`). The consumer is responsible for
|
|
19
|
+
applying the delta to its state.
|
|
20
|
+
- **`friction` defaults to `0.92`** — velocity multiplier per frame.
|
|
21
|
+
Lower = quicker decay.
|
|
22
|
+
- **`trackMove(dx, dy)`** must be called on every pointermove during
|
|
23
|
+
the drag — it captures the velocity from the delta and time since
|
|
24
|
+
the last call (`16 / dt` factor to normalize to ~60fps).
|
|
25
|
+
- **`resetTime()`** must be called at drag start (and on
|
|
26
|
+
resume-after-release) so the first `trackMove` doesn't compute a
|
|
27
|
+
velocity from a stale timestamp.
|
|
28
|
+
- **`release()`** must be called on drag end. It starts the inertia
|
|
29
|
+
loop only if:
|
|
30
|
+
- The last `trackMove` was less than 50ms ago, AND
|
|
31
|
+
- The captured velocity exceeds `minVelocity`.
|
|
32
|
+
Otherwise it does nothing — slow / paused releases don't fling.
|
|
33
|
+
- **`stop()`** cancels any in-flight inertia and zeroes velocity. Call
|
|
34
|
+
it on a new pointer-down to interrupt momentum.
|
|
35
|
+
- **Time-gap larger than 100ms in `trackMove` resets velocity to 0** —
|
|
36
|
+
catching a pause mid-drag prevents a stale fling on release.
|
|
37
|
+
|
|
38
|
+
## Gotchas
|
|
39
|
+
|
|
40
|
+
- **The composable owns no DOM**. It's just math + RAF. The consumer
|
|
41
|
+
must wire `trackMove` to `pointermove`, `release` to `pointerup`,
|
|
42
|
+
`stop` to new `pointerdown`, `resetTime` to drag-start.
|
|
43
|
+
- **Velocity units are "pixels per ~16ms frame"** because of the
|
|
44
|
+
`16 / dt` normalization. The `onTick` deltas can be directly applied
|
|
45
|
+
to translate values without further scaling.
|
|
46
|
+
- **No max-velocity clamp.** Very fast flings produce very fast inertia
|
|
47
|
+
— clamp upstream if needed.
|
|
48
|
+
- **No multi-axis independence**: friction is symmetric. To decay axes
|
|
49
|
+
at different rates, scale `dx` / `dy` inside `onTick`.
|
|
50
|
+
|
|
51
|
+
## Quick reference
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { useInertia } from "../composables/useInertia";
|
|
55
|
+
|
|
56
|
+
const tx = ref(0);
|
|
57
|
+
const ty = ref(0);
|
|
58
|
+
|
|
59
|
+
const inertia = useInertia(
|
|
60
|
+
(dx, dy) => {
|
|
61
|
+
tx.value += dx;
|
|
62
|
+
ty.value += dy;
|
|
63
|
+
},
|
|
64
|
+
{ friction: 0.9, minVelocity: 0.3 },
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
function onPointerDown() { inertia.stop(); inertia.resetTime(); }
|
|
68
|
+
function onPointerMove(dx: number, dy: number) {
|
|
69
|
+
tx.value += dx;
|
|
70
|
+
ty.value += dy;
|
|
71
|
+
inertia.trackMove(dx, dy);
|
|
72
|
+
}
|
|
73
|
+
function onPointerUp() { inertia.release(); }
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Related
|
|
77
|
+
|
|
78
|
+
- `<orio-zoomable-container>` — uses this for post-pan momentum.
|
|
79
|
+
- `<orio-canvas>` — same.
|
|
80
|
+
- Public API reference: `docs/composables/use-inertia.md`.
|