@vizejs/composable 0.810.0 → 0.812.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/dist/abort-signal.mjs +0 -62
- package/dist/active-element.mjs +0 -11
- package/dist/animate.mjs +0 -19
- package/dist/async-resource.mjs +0 -17
- package/dist/battery.mjs +0 -13
- package/dist/breakpoints.mjs +0 -24
- package/dist/capability.mjs +0 -12
- package/dist/{catalog-BRX-Wg8B.mjs → catalog-CcpCnLjb.mjs} +0 -14
- package/dist/catalog.mjs +1 -1
- package/dist/color-mode.mjs +0 -23
- package/dist/computed-with-control.mjs +0 -22
- package/dist/create-event-hook.mjs +0 -27
- package/dist/create-global-state.mjs +0 -23
- package/dist/create-shared-composable.mjs +0 -23
- package/dist/device-motion.mjs +0 -11
- package/dist/device-orientation.mjs +0 -23
- package/dist/device-pixel-ratio.mjs +0 -11
- package/dist/disposal-scope.mjs +0 -25
- package/dist/document-visibility.mjs +0 -14
- package/dist/draggable.mjs +0 -14
- package/dist/element-bounding.mjs +0 -14
- package/dist/element-by-point.mjs +0 -10
- package/dist/element-hover.mjs +0 -13
- package/dist/element-target.mjs +0 -30
- package/dist/focus.mjs +0 -23
- package/dist/fps.mjs +0 -12
- package/dist/geolocation.mjs +0 -14
- package/dist/i18n.mjs +0 -86
- package/dist/icu-message.mjs +0 -58
- package/dist/idle.mjs +0 -16
- package/dist/index.mjs +2 -2
- package/dist/infinite-scroll.mjs +0 -16
- package/dist/intersection-observer.mjs +0 -27
- package/dist/locale.mjs +0 -20
- package/dist/magic-keys.mjs +0 -35
- package/dist/math.mjs +0 -37
- package/dist/media-query.mjs +0 -29
- package/dist/mouse-in-element.mjs +0 -12
- package/dist/mouse.mjs +0 -12
- package/dist/mutation-observer.mjs +0 -15
- package/dist/network.mjs +0 -24
- package/dist/on-click-outside.mjs +0 -16
- package/dist/on-key-stroke.mjs +0 -33
- package/dist/on-long-press.mjs +0 -14
- package/dist/on-start-typing.mjs +0 -23
- package/dist/page-leave.mjs +0 -11
- package/dist/parent-element.mjs +0 -9
- package/dist/pinch.mjs +0 -14
- package/dist/pointer-lock.mjs +0 -23
- package/dist/pointer.mjs +0 -18
- package/dist/preferences.mjs +0 -31
- package/dist/preferred-languages.mjs +0 -13
- package/dist/ref-auto-reset.mjs +0 -24
- package/dist/ref-debounced.mjs +0 -22
- package/dist/ref-default.mjs +0 -21
- package/dist/resize-observer.mjs +0 -31
- package/dist/resolver.mjs +1 -58
- package/dist/retry-async.mjs +0 -25
- package/dist/retry-delay.mjs +0 -23
- package/dist/scope.mjs +0 -14
- package/dist/screen-orientation.mjs +0 -15
- package/dist/scroll-lock.mjs +0 -14
- package/dist/scroll.mjs +0 -27
- package/dist/standard-schema.mjs +0 -31
- package/dist/swipe.mjs +0 -36
- package/dist/temporal.mjs +0 -30
- package/dist/text-selection.mjs +0 -15
- package/dist/textarea-autosize.mjs +0 -13
- package/dist/to-reactive.mjs +0 -20
- package/dist/transition.mjs +0 -7
- package/dist/until.mjs +0 -25
- package/dist/use-array.mjs +0 -52
- package/dist/use-barcode-detector.mjs +0 -25
- package/dist/use-bluetooth.mjs +0 -27
- package/dist/use-broadcast-channel.mjs +0 -30
- package/dist/use-builtin-ai.mjs +0 -68
- package/dist/use-clipboard.mjs +0 -27
- package/dist/use-compression-stream.mjs +0 -78
- package/dist/use-contact-picker.mjs +0 -22
- package/dist/use-cookie.mjs +0 -63
- package/dist/use-countdown.mjs +0 -22
- package/dist/use-counter.mjs +0 -29
- package/dist/use-css-var.mjs +0 -28
- package/dist/use-date-format.mjs +0 -48
- package/dist/use-date-time-format.mjs +0 -22
- package/dist/use-debounced.mjs +0 -39
- package/dist/use-display-media.mjs +0 -22
- package/dist/use-display-names.mjs +0 -19
- package/dist/use-document-title.mjs +0 -25
- package/dist/use-drop-zone.mjs +0 -36
- package/dist/use-event-source.mjs +0 -25
- package/dist/use-eye-dropper.mjs +0 -19
- package/dist/use-favicon.mjs +0 -23
- package/dist/use-fetch.mjs +0 -27
- package/dist/use-field.mjs +0 -27
- package/dist/use-file-dialog.mjs +0 -21
- package/dist/{use-form-A4j_h14D.mjs → use-form-BZqwMs6k.mjs} +0 -68
- package/dist/use-form-field-props.mjs +0 -57
- package/dist/use-form.mjs +1 -1
- package/dist/use-fullscreen.mjs +0 -23
- package/dist/use-gamepad.mjs +0 -50
- package/dist/use-hid.mjs +0 -25
- package/dist/use-history.mjs +0 -43
- package/dist/use-id-generator.mjs +0 -21
- package/dist/use-image.mjs +0 -22
- package/dist/use-indexed-db.mjs +0 -39
- package/dist/use-interval.mjs +0 -28
- package/dist/use-list-format.mjs +0 -18
- package/dist/use-machine.mjs +0 -34
- package/dist/use-map.mjs +0 -28
- package/dist/use-media-controls.mjs +0 -28
- package/dist/use-mounted.mjs +0 -18
- package/dist/use-navigation-api.mjs +0 -27
- package/dist/use-notification.mjs +0 -24
- package/dist/use-number-format.mjs +0 -23
- package/dist/use-object-url.mjs +0 -22
- package/dist/use-offset-pagination.mjs +0 -18
- package/dist/use-payment-request.mjs +0 -25
- package/dist/use-performance-observer.mjs +0 -27
- package/dist/use-permission.mjs +0 -26
- package/dist/use-plural-rules.mjs +0 -21
- package/dist/use-push-subscription.mjs +0 -28
- package/dist/use-queue.mjs +0 -29
- package/dist/use-raf-fn.mjs +0 -23
- package/dist/use-relative-time-format.mjs +0 -35
- package/dist/use-request-idle-callback.mjs +0 -42
- package/dist/use-route-query.mjs +0 -17
- package/dist/use-scheduler-post-task.mjs +0 -27
- package/dist/use-screen-details.mjs +0 -42
- package/dist/use-script-tag.mjs +0 -28
- package/dist/use-segmenter.mjs +0 -20
- package/dist/use-serial.mjs +0 -24
- package/dist/use-service-worker.mjs +0 -27
- package/dist/use-set.mjs +0 -23
- package/dist/use-share.mjs +0 -23
- package/dist/use-sorted-locale.mjs +0 -20
- package/dist/use-speech-recognition.mjs +0 -24
- package/dist/use-speech-synthesis.mjs +0 -26
- package/dist/use-stack.mjs +0 -27
- package/dist/use-storage-estimate.mjs +0 -41
- package/dist/use-storage.mjs +0 -68
- package/dist/use-style-tag.mjs +0 -22
- package/dist/use-supported.mjs +0 -17
- package/dist/use-throttled.mjs +0 -46
- package/dist/use-time-ago.mjs +0 -22
- package/dist/use-toggle.mjs +0 -19
- package/dist/use-url-hash.mjs +0 -28
- package/dist/use-url-search-params.mjs +0 -99
- package/dist/use-usb.mjs +0 -23
- package/dist/use-user-activation.mjs +0 -22
- package/dist/use-user-media.mjs +0 -50
- package/dist/use-vibrate.mjs +0 -21
- package/dist/use-view-transition.mjs +0 -22
- package/dist/use-visual-viewport.mjs +0 -25
- package/dist/use-wake-lock.mjs +0 -21
- package/dist/use-web-authn.mjs +0 -61
- package/dist/use-web-locks.mjs +0 -25
- package/dist/use-web-midi.mjs +0 -22
- package/dist/use-web-vitals.mjs +0 -41
- package/dist/use-websocket.mjs +0 -27
- package/dist/use-worker-fn.mjs +0 -37
- package/dist/virtual-list.mjs +0 -14
- package/dist/whenever.mjs +0 -21
- package/dist/window-size.mjs +0 -12
- package/package.json +2 -2
- package/registry/registry.json +1 -1
package/dist/use-eye-dropper.mjs
CHANGED
|
@@ -11,25 +11,6 @@ function browserEyeDropper() {
|
|
|
11
11
|
function isAbort(error) {
|
|
12
12
|
return typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* Pick a color from anywhere on screen with the EyeDropper API.
|
|
16
|
-
*
|
|
17
|
-
* `open` resolves to a discriminated {@link EyeDropperResult}; dismissing
|
|
18
|
-
* the picker (Escape) or aborting via `signal` yields `"cancelled"`.
|
|
19
|
-
* The composable holds no resources beyond an open picker, which the
|
|
20
|
-
* caller controls through `signal`.
|
|
21
|
-
*
|
|
22
|
-
* Server rendering: `supported` is false and `sRGBHex` is `initialValue`.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const { open, sRGBHex, supported } = useEyeDropper();
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param options Capability and initial color.
|
|
30
|
-
* @default options {}
|
|
31
|
-
* @returns Picker state and the open action.
|
|
32
|
-
*/
|
|
33
14
|
function useEyeDropper(options = {}) {
|
|
34
15
|
const sRGBHex = ref(options.initialValue ?? "");
|
|
35
16
|
const picking = ref(false);
|
package/dist/use-favicon.mjs
CHANGED
|
@@ -14,29 +14,6 @@ function browserFaviconHost() {
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Bind the page favicon to reactive state.
|
|
19
|
-
*
|
|
20
|
-
* Every `<link>` whose `rel` contains `rel` (`icon`, `shortcut icon`,
|
|
21
|
-
* `apple-touch-icon`, …) gets `baseUrl + icon` as its `href`; when none
|
|
22
|
-
* exists, one `<link rel="icon">` is created. Accepts a writable ref (used
|
|
23
|
-
* as-is), a getter (followed), a plain string, or nothing (an owned ref).
|
|
24
|
-
*
|
|
25
|
-
* Server rendering: this is a client-only side effect. The document is
|
|
26
|
-
* never touched on the server, and `icon` keeps its given value; emit the
|
|
27
|
-
* initial `<link rel="icon">` through the application's head manager.
|
|
28
|
-
* Watchers are released with the owning reactive scope; the last icon stays.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```ts
|
|
32
|
-
* const { icon } = useFavicon(() => (unread.value ? "/unread.svg" : "/icon.svg"));
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @param icon Reactive icon source.
|
|
36
|
-
* @param options Base URL, relation, and capability.
|
|
37
|
-
* @default options {}
|
|
38
|
-
* @returns The icon ref and support flag.
|
|
39
|
-
*/
|
|
40
17
|
function useFavicon(icon, options = {}) {
|
|
41
18
|
const baseUrl = options.baseUrl ?? "";
|
|
42
19
|
const rel = options.rel ?? "icon";
|
package/dist/use-fetch.mjs
CHANGED
|
@@ -30,33 +30,6 @@ function assertTimeout(timeoutMs) {
|
|
|
30
30
|
if (timeoutMs === void 0) return;
|
|
31
31
|
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw new RangeError(`[VIZE_COMPOSE_FETCH_INVALID_TIMEOUT] timeoutMs must be a finite non-negative number; received ${String(timeoutMs)}`);
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Reactive, abortable, retrying `fetch` with typed decoding and interceptors.
|
|
35
|
-
*
|
|
36
|
-
* Latest wins: starting an execution aborts the pending one, which then
|
|
37
|
-
* settles as `"superseded"` without touching state. The pending request is
|
|
38
|
-
* aborted when the owning reactive scope stops; outside a scope the caller
|
|
39
|
-
* owns `abort()`. Automatic execution (initial and on reactive URL/`init`
|
|
40
|
-
* changes) only happens in a browser or with an explicit `fetch`, so server
|
|
41
|
-
* rendering performs no I/O unless you `await execute()` in
|
|
42
|
-
* `onServerPrefetch`; state then holds `initialData` and status `"idle"`.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const id = ref(1);
|
|
47
|
-
* const { data, error } = useFetch(() => `/api/users/${id.value}`, {
|
|
48
|
-
* validate: isUser,
|
|
49
|
-
* retry: 2,
|
|
50
|
-
* timeoutMs: 5_000,
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @param url Reactive URL; `null`/`undefined` keeps the resource idle.
|
|
55
|
-
* @param options Decoding, retry, timeout, and interceptor options.
|
|
56
|
-
* @default options {}
|
|
57
|
-
* @throws {RangeError} `[VIZE_COMPOSE_FETCH_INVALID_TIMEOUT]` for an invalid timeout.
|
|
58
|
-
* @returns Reactive state and controls.
|
|
59
|
-
*/
|
|
60
33
|
function useFetch(url, options = {}) {
|
|
61
34
|
assertTimeout(options.timeoutMs);
|
|
62
35
|
const data = shallowRef(options.initialData);
|
package/dist/use-field.mjs
CHANGED
|
@@ -15,33 +15,6 @@ function sameValue(left, right) {
|
|
|
15
15
|
const rightKeys = Object.keys(right);
|
|
16
16
|
return leftKeys.length === rightKeys.length && leftKeys.every((key) => sameValue(Reflect.get(left, key), Reflect.get(right, key)));
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* A standalone validated field, independent of any form.
|
|
20
|
-
*
|
|
21
|
-
* Rules may be plain (a)synchronous validators or Standard Schema v1
|
|
22
|
-
* validators (anything with a `~standard` property). A newer validation
|
|
23
|
-
* aborts older ones through their `signal`, and stale results are ignored.
|
|
24
|
-
* With `validateOn: "change"` validation runs after each value change,
|
|
25
|
-
* never during setup, so server-rendered markup matches the first client
|
|
26
|
-
* render. For multi-field state use `useForm`.
|
|
27
|
-
*
|
|
28
|
-
* Server rendering: pure state; nothing validates during setup. Pending
|
|
29
|
-
* validations are aborted when the owning scope stops.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* const email = useField("", {
|
|
34
|
-
* name: "email",
|
|
35
|
-
* rules: [(value) => (value.includes("@") ? undefined : "Invalid email")],
|
|
36
|
-
* });
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @typeParam Value Field value, inferred from `initialValue`.
|
|
40
|
-
* @param initialValue Initial value, or a factory returning it.
|
|
41
|
-
* @param options Rules, trigger, and name.
|
|
42
|
-
* @default options {}
|
|
43
|
-
* @returns Field state and actions.
|
|
44
|
-
*/
|
|
45
18
|
function useField(initialValue, options = {}) {
|
|
46
19
|
const createInitial = () => initialValue instanceof Function ? initialValue() : structuredClone(toRaw(initialValue));
|
|
47
20
|
let initial = createInitial();
|
package/dist/use-file-dialog.mjs
CHANGED
|
@@ -4,27 +4,6 @@ import { shallowRef, toValue } from "vue";
|
|
|
4
4
|
function browserFileDialogHost() {
|
|
5
5
|
return typeof window === "undefined" ? void 0 : window.document;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Open the native file picker without rendering an input.
|
|
9
|
-
*
|
|
10
|
-
* A detached `<input type="file">` is created lazily on the first `open`
|
|
11
|
-
* (never during setup or server rendering), configured from reactive
|
|
12
|
-
* options plus per-call overrides, and observed for `change` and `cancel`.
|
|
13
|
-
* The selection is exposed as a readonly `File[]`. Listeners are removed
|
|
14
|
-
* when the owning reactive scope stops.
|
|
15
|
-
*
|
|
16
|
-
* Server rendering: `files` is `initialFiles` and `open` returns false.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const { files, open, onChange } = useFileDialog({ accept: "image/*" });
|
|
21
|
-
* onChange((selection) => upload(selection));
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param options Dialog settings, initial selection, and capability.
|
|
25
|
-
* @default options {}
|
|
26
|
-
* @returns Selection state and dialog actions.
|
|
27
|
-
*/
|
|
28
7
|
function useFileDialog(options = {}) {
|
|
29
8
|
const files = shallowRef(options.initialFiles ?? null);
|
|
30
9
|
const changeHandlers = /* @__PURE__ */ new Set();
|
|
@@ -2,20 +2,17 @@ import { tryOnScopeDispose } from "./scope.mjs";
|
|
|
2
2
|
import { validateStandardSchema } from "./standard-schema.mjs";
|
|
3
3
|
import { computed, ref, shallowRef, toRaw, toValue, triggerRef } from "vue";
|
|
4
4
|
//#region src/form-value-paths.ts
|
|
5
|
-
/** Whether a value is a plain object or an array that a path may descend into. */
|
|
6
5
|
function isContainer(value) {
|
|
7
6
|
if (Array.isArray(value)) return true;
|
|
8
7
|
if (typeof value !== "object" || value === null) return false;
|
|
9
8
|
const prototype = Object.getPrototypeOf(value);
|
|
10
9
|
return prototype === Object.prototype || prototype === null;
|
|
11
10
|
}
|
|
12
|
-
/** Keys that reach an object's prototype chain instead of its own data. */
|
|
13
11
|
const prototypeKeys = new Set([
|
|
14
12
|
"__proto__",
|
|
15
13
|
"constructor",
|
|
16
14
|
"prototype"
|
|
17
15
|
]);
|
|
18
|
-
/** Split a dotted path; undefined when a segment names the prototype chain. */
|
|
19
16
|
function splitPath(path) {
|
|
20
17
|
if (path === "") return [];
|
|
21
18
|
const keys = path.split(".");
|
|
@@ -30,7 +27,6 @@ function writeChild(container, key, value) {
|
|
|
30
27
|
if (Array.isArray(container)) container[Number(key)] = value;
|
|
31
28
|
else container[key] = value;
|
|
32
29
|
}
|
|
33
|
-
/** Read a dotted path. */
|
|
34
30
|
function readPath(root, path) {
|
|
35
31
|
const keys = splitPath(path);
|
|
36
32
|
if (keys === void 0) return void 0;
|
|
@@ -41,7 +37,6 @@ function readPath(root, path) {
|
|
|
41
37
|
}
|
|
42
38
|
return current;
|
|
43
39
|
}
|
|
44
|
-
/** Write a dotted path, creating intermediate containers. */
|
|
45
40
|
function writePath(root, path, value) {
|
|
46
41
|
const keys = splitPath(path);
|
|
47
42
|
const last = keys?.at(-1);
|
|
@@ -61,13 +56,6 @@ function writePath(root, path, value) {
|
|
|
61
56
|
}
|
|
62
57
|
//#endregion
|
|
63
58
|
//#region src/form-dirty.ts
|
|
64
|
-
/**
|
|
65
|
-
* Dirty-field comparison for `useForm`.
|
|
66
|
-
*
|
|
67
|
-
* Equality matches the form's own deep compare (dates by instant, arrays by
|
|
68
|
-
* item, plain objects by own keys). Prototype-bearing values are leaves.
|
|
69
|
-
*/
|
|
70
|
-
/** Whether two form values are the same, ignoring object identity. */
|
|
71
59
|
function valuesEqual(left, right) {
|
|
72
60
|
if (Object.is(left, right)) return true;
|
|
73
61
|
if (left instanceof Date && right instanceof Date) return left.getTime() === right.getTime();
|
|
@@ -85,12 +73,6 @@ function blankDirty(value) {
|
|
|
85
73
|
if (isContainer(value)) return Object.keys(value).length === 0;
|
|
86
74
|
return false;
|
|
87
75
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Nested dirty flags of `current` against `previous`.
|
|
90
|
-
*
|
|
91
|
-
* Equal objects become `{}`, equal arrays become `[]`, and equal leaves
|
|
92
|
-
* become `undefined` so callers can omit them.
|
|
93
|
-
*/
|
|
94
76
|
function dirtyFieldsOf(current, previous) {
|
|
95
77
|
if (valuesEqual(current, previous)) {
|
|
96
78
|
if (Array.isArray(current)) return [];
|
|
@@ -155,12 +137,6 @@ function mergeKept(base, current, previous) {
|
|
|
155
137
|
}
|
|
156
138
|
return current;
|
|
157
139
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Reset values that keep user edits.
|
|
160
|
-
*
|
|
161
|
-
* Fields equal to `previous` take `base`. Dirty leaves, added keys, and
|
|
162
|
-
* array-length edits keep `current`. A removed key stays removed.
|
|
163
|
-
*/
|
|
164
140
|
function valuesKeepingDirty(base, current, previous) {
|
|
165
141
|
return mergeKept(base, current, previous);
|
|
166
142
|
}
|
|
@@ -178,7 +154,6 @@ function unknownMessages(result) {
|
|
|
178
154
|
if (!Array.isArray(result)) return [];
|
|
179
155
|
return result.filter((message) => typeof message === "string" && message !== "");
|
|
180
156
|
}
|
|
181
|
-
/** Rewrite `${arrayPath}.${index}…` keys through an index mapping (undefined drops). */
|
|
182
157
|
function remapKeys(entries, arrayPath, mapIndex) {
|
|
183
158
|
const prefix = `${arrayPath}.`;
|
|
184
159
|
const result = [];
|
|
@@ -200,48 +175,6 @@ function remapKeys(entries, arrayPath, mapIndex) {
|
|
|
200
175
|
}
|
|
201
176
|
return result;
|
|
202
177
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Fully typed form state with validation, field arrays, and submission.
|
|
205
|
-
*
|
|
206
|
-
* The value type is inferred from `initialValues`; every path is a
|
|
207
|
-
* template-literal key, so `field("address.city")` returns controls whose
|
|
208
|
-
* `value` is typed as the city's type and misspelled paths do not compile.
|
|
209
|
-
* Validation combines a Standard Schema v1 validator (Zod, Valibot, ArkType,
|
|
210
|
-
* … via the `~standard` protocol), a whole-form validator, and per-field
|
|
211
|
-
* validators; all may be asynchronous. A newer validation aborts older ones
|
|
212
|
-
* through their `signal` and their results are discarded, so a slow check
|
|
213
|
-
* can never overwrite fresher errors. `criteriaMode: "first"` keeps one
|
|
214
|
-
* message per path, in source order: schema, form validator, field validator.
|
|
215
|
-
* `dirtyFields` mirrors edited branches, `watch` reads one path, and
|
|
216
|
-
* `setError` updates a single path. `disabled` ignores writes and submission.
|
|
217
|
-
* `reset` can keep dirty values, errors, touched fields, the submit count,
|
|
218
|
-
* or the success flag.
|
|
219
|
-
*
|
|
220
|
-
* This composable owns the *values*. `@vizejs/ui/form` owns accessible
|
|
221
|
-
* error presentation (error summaries, focus management, native constraint
|
|
222
|
-
* validation); feed {@link FormControls.errors} into it to render them.
|
|
223
|
-
*
|
|
224
|
-
* Server rendering: pure state, no host access; validation never runs
|
|
225
|
-
* automatically during setup, so server and client render the same markup.
|
|
226
|
-
* Pending validations are aborted when the owning scope stops.
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* const form = useForm({
|
|
231
|
-
* initialValues: { name: "", address: { city: "" }, tags: [] as string[] },
|
|
232
|
-
* validators: { name: (name) => (name ? undefined : "Required") },
|
|
233
|
-
* onSubmit: (values) => api.save(values),
|
|
234
|
-
* });
|
|
235
|
-
* const city = form.field("address.city"); // city.value: Ref<string>
|
|
236
|
-
* const tags = form.fieldArray("tags");
|
|
237
|
-
* tags.append("vue");
|
|
238
|
-
* ```
|
|
239
|
-
*
|
|
240
|
-
* @typeParam Values Form values, inferred from `initialValues`.
|
|
241
|
-
* @typeParam Output Submitted value, inferred from `schema` (defaults to `Values`).
|
|
242
|
-
* @param options Initial values, validators, triggers, and submit handler.
|
|
243
|
-
* @returns Form state and actions.
|
|
244
|
-
*/
|
|
245
178
|
function useForm(options) {
|
|
246
179
|
const createInitial = () => typeof options.initialValues === "function" ? options.initialValues() : cloneValue(options.initialValues);
|
|
247
180
|
let initial = createInitial();
|
|
@@ -283,7 +216,6 @@ function useForm(options) {
|
|
|
283
216
|
errors.value = next;
|
|
284
217
|
};
|
|
285
218
|
const readFieldValidator = (path) => validators.find(([candidate]) => candidate === path)?.[1];
|
|
286
|
-
/** Collect every error source; resolves to errors keyed by path. */
|
|
287
219
|
const collectErrors = async (signal) => {
|
|
288
220
|
const snapshot = values.value;
|
|
289
221
|
const schemaMessages = Object.create(null);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { computed, toValue } from "vue";
|
|
2
2
|
//#region src/use-form-field-props.ts
|
|
3
|
-
/** Derive the default control id for a path. */
|
|
4
3
|
function formFieldId(path, idPrefix = "field") {
|
|
5
4
|
const segment = path.replace(/[^A-Za-z0-9_-]+/g, "-");
|
|
6
5
|
return segment.length === 0 ? idPrefix : `${idPrefix}-${segment}`;
|
|
@@ -9,37 +8,6 @@ function readFlag(source, fallback) {
|
|
|
9
8
|
const value = source === void 0 ? void 0 : toValue(source);
|
|
10
9
|
return typeof value === "boolean" ? value : fallback;
|
|
11
10
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Bind one `useForm` field to accessible field markup and any `v-model` control.
|
|
14
|
-
*
|
|
15
|
-
* Returns ids, ARIA relations (`fieldProps`), label/description/error props,
|
|
16
|
-
* and `modelProps` whose shapes match `@vizejs/ui`'s Field contracts
|
|
17
|
-
* structurally, so the bridge lives here without a runtime dependency on the
|
|
18
|
-
* UI package. Ids are derived from the path, so server and client agree
|
|
19
|
-
* without any instance-local id sequence.
|
|
20
|
-
*
|
|
21
|
-
* Server rendering: pure derived state, no host access. Cleanup: none needed
|
|
22
|
-
* beyond the owning form.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```vue
|
|
26
|
-
* <script setup lang="ts">
|
|
27
|
-
* const form = useForm({ initialValues: { address: { city: "" } } });
|
|
28
|
-
* const city = useFormFieldProps(form, "address.city");
|
|
29
|
-
* <\/script>
|
|
30
|
-
* <template>
|
|
31
|
-
* <label v-bind="city.labelProps.value">City</label>
|
|
32
|
-
* <TextInput v-bind="city.controlProps.value" />
|
|
33
|
-
* <p v-if="city.invalid.value" v-bind="city.errorMessageProps.value">{{ city.errorMessage.value }}</p>
|
|
34
|
-
* </template>
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param form Controls returned by `useForm`.
|
|
38
|
-
* @param path Typed dotted path.
|
|
39
|
-
* @param options Id, relation, and error-visibility options.
|
|
40
|
-
* @default options {}
|
|
41
|
-
* @returns Typed bindings for the field.
|
|
42
|
-
*/
|
|
43
11
|
function useFormFieldProps(form, path, options = {}) {
|
|
44
12
|
const field = form.field(path);
|
|
45
13
|
const showErrors = options.showErrors ?? "touched";
|
|
@@ -93,13 +61,6 @@ function useFormFieldProps(form, path, options = {}) {
|
|
|
93
61
|
}))
|
|
94
62
|
};
|
|
95
63
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Convert form errors into ui `FormFieldError` entries (`{ name, message, path }`),
|
|
98
|
-
* one per message, so `@vizejs/ui` `Field` components match them by `name`.
|
|
99
|
-
*
|
|
100
|
-
* @param errors `form.errors.value`.
|
|
101
|
-
* @returns Entries in record order; the form-level `""` path has an empty `path`.
|
|
102
|
-
*/
|
|
103
64
|
function toFormFieldErrors(errors) {
|
|
104
65
|
return Object.entries(errors).flatMap(([name, messages]) => {
|
|
105
66
|
const path = name.length === 0 ? [] : name.split(".").map((segment) => /^\d+$/.test(segment) ? Number(segment) : segment);
|
|
@@ -110,24 +71,6 @@ function toFormFieldErrors(errors) {
|
|
|
110
71
|
}));
|
|
111
72
|
});
|
|
112
73
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Derive `@vizejs/ui` `ErrorSummary` fields from a `useForm` instance.
|
|
115
|
-
*
|
|
116
|
-
* Each invalid path becomes `{ id, message, label? }` pointing at the control
|
|
117
|
-
* id that {@link useFormFieldProps} assigns, in `order` then error order.
|
|
118
|
-
*
|
|
119
|
-
* Server rendering: pure derived state. Cleanup: none.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```vue
|
|
123
|
-
* <ErrorSummary :fields="summary" heading="Fix these fields" />
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* @param form Controls returned by `useForm`.
|
|
127
|
-
* @param options Id, label, ordering, and visibility options.
|
|
128
|
-
* @default options {}
|
|
129
|
-
* @returns Summary fields, empty until errors should be shown.
|
|
130
|
-
*/
|
|
131
74
|
function useFormErrorSummaryFields(form, options = {}) {
|
|
132
75
|
const order = options.order ?? [];
|
|
133
76
|
const ids = options.ids ?? {};
|
package/dist/use-form.mjs
CHANGED
package/dist/use-fullscreen.mjs
CHANGED
|
@@ -8,29 +8,6 @@ function browserFullscreenHost() {
|
|
|
8
8
|
function currentElement(host) {
|
|
9
9
|
return host.fullscreenElement ?? host.webkitFullscreenElement ?? null;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Enter, exit, and observe fullscreen for an element.
|
|
13
|
-
*
|
|
14
|
-
* Supports the standard Fullscreen API and the WebKit-prefixed variant.
|
|
15
|
-
* `isFullscreen` is true only while *this* target is the fullscreen element
|
|
16
|
-
* and follows `fullscreenchange`, so pressing Escape is reflected. Listeners
|
|
17
|
-
* are removed when the owning scope stops; with `autoExit` the target also
|
|
18
|
-
* leaves fullscreen then.
|
|
19
|
-
*
|
|
20
|
-
* Server rendering: `supported` and `isFullscreen` are false and nothing is
|
|
21
|
-
* requested.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const player = useTemplateRef<HTMLElement>("player");
|
|
26
|
-
* const { toggle, isFullscreen } = useFullscreen(player);
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @param target Reactive element; defaults to the document element.
|
|
30
|
-
* @param options Capability, navigation UI, and exit policy.
|
|
31
|
-
* @default options {}
|
|
32
|
-
* @returns Fullscreen state and actions.
|
|
33
|
-
*/
|
|
34
11
|
function useFullscreen(target, options = {}) {
|
|
35
12
|
const isFullscreen = ref(false);
|
|
36
13
|
const resolveHost = () => options.host === void 0 ? browserFullscreenHost() : toValue(options.host) ?? void 0;
|
package/dist/use-gamepad.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { tryOnScopeDispose } from "./scope.mjs";
|
|
|
2
2
|
import { useRafFn } from "./use-raf-fn.mjs";
|
|
3
3
|
import { computed, hasInjectionContext, readonly, shallowReadonly, shallowRef, toValue, watch, watchPostEffect } from "vue";
|
|
4
4
|
//#region src/use-gamepad.ts
|
|
5
|
-
/** Button indices of the W3C "standard" gamepad mapping. */
|
|
6
5
|
const standardGamepadButtons = {
|
|
7
6
|
faceBottom: 0,
|
|
8
7
|
faceRight: 1,
|
|
@@ -22,7 +21,6 @@ const standardGamepadButtons = {
|
|
|
22
21
|
dpadRight: 15,
|
|
23
22
|
home: 16
|
|
24
23
|
};
|
|
25
|
-
/** Axis indices of the W3C "standard" gamepad mapping. */
|
|
26
24
|
const standardGamepadAxes = {
|
|
27
25
|
leftStickX: 0,
|
|
28
26
|
leftStickY: 1,
|
|
@@ -42,12 +40,6 @@ function isAxisBinding(binding) {
|
|
|
42
40
|
function checkIndex(index, key) {
|
|
43
41
|
if (!Number.isInteger(index) || index < 0) throw invalidMapping(`"${key}" index must be a non-negative integer; received ${index}`);
|
|
44
42
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Copy a live pad into an immutable {@link GamepadSnapshot}.
|
|
47
|
-
*
|
|
48
|
-
* @param pad Live `Gamepad` (or compatible) object.
|
|
49
|
-
* @returns The copied state.
|
|
50
|
-
*/
|
|
51
43
|
function snapshotGamepad(pad) {
|
|
52
44
|
return {
|
|
53
45
|
id: pad.id,
|
|
@@ -64,22 +56,6 @@ function snapshotGamepad(pad) {
|
|
|
64
56
|
vibration: pad.vibrationActuator != null
|
|
65
57
|
};
|
|
66
58
|
}
|
|
67
|
-
/**
|
|
68
|
-
* Derive typed named state from a snapshot. Missing buttons read as released
|
|
69
|
-
* and missing axes as `0`; axis dead zones are applied and rescaled.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```ts
|
|
73
|
-
* const state = mapGamepad(pad, { jump: { button: 0 }, moveX: { axis: 0, deadzone: 0.1 } });
|
|
74
|
-
* state.jump.pressed; state.moveX; // boolean, number
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @param snapshot Copied pad state.
|
|
78
|
-
* @param mapping Named button and axis bindings.
|
|
79
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_GAMEPAD_INVALID_MAPPING` for a
|
|
80
|
-
* negative or fractional index or a dead zone outside `[0, 1)`.
|
|
81
|
-
* @returns State keyed like `mapping`.
|
|
82
|
-
*/
|
|
83
59
|
function mapGamepad(snapshot, mapping) {
|
|
84
60
|
const result = {};
|
|
85
61
|
for (const [key, binding] of Object.entries(mapping)) if (isAxisBinding(binding)) {
|
|
@@ -100,32 +76,6 @@ function mapGamepad(snapshot, mapping) {
|
|
|
100
76
|
}
|
|
101
77
|
return result;
|
|
102
78
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Track connected gamepads as immutable snapshots, polled on animation
|
|
105
|
-
* frames, with optional typed named bindings.
|
|
106
|
-
*
|
|
107
|
-
* Pads are re-read every frame while active and on `gamepadconnected` /
|
|
108
|
-
* `gamepaddisconnected`; `gamepads` is replaced only when a pad's timestamp
|
|
109
|
-
* or connection changed. Entries are plain copies, so they are safe to keep
|
|
110
|
-
* or serialize. The frame loop and listeners stop with the owning reactive
|
|
111
|
-
* scope; outside a scope call `pause()`.
|
|
112
|
-
*
|
|
113
|
-
* Server rendering: no frames or listeners, `supported` is false and
|
|
114
|
-
* `gamepads` is empty.
|
|
115
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
116
|
-
* renders this server state first.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```ts
|
|
120
|
-
* const { gamepads } = useGamepad({ mapping: { jump: { button: 0 }, moveX: { axis: 0, deadzone: 0.1 } } });
|
|
121
|
-
* const player = computed(() => gamepads.value[0]?.mapped);
|
|
122
|
-
* ```
|
|
123
|
-
*
|
|
124
|
-
* @param options Host, mapping, and scheduler.
|
|
125
|
-
* @default options {}
|
|
126
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_GAMEPAD_INVALID_MAPPING` for an invalid mapping.
|
|
127
|
-
* @returns Pad state and polling controls.
|
|
128
|
-
*/
|
|
129
79
|
function useGamepad(options = {}) {
|
|
130
80
|
const gamepads = shallowRef([]);
|
|
131
81
|
const error = shallowRef(void 0);
|
package/dist/use-hid.mjs
CHANGED
|
@@ -22,31 +22,6 @@ function describe(device) {
|
|
|
22
22
|
opened: device.opened
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Talk to human-interface devices with the WebHID API.
|
|
27
|
-
*
|
|
28
|
-
* `devices` lists granted devices as plain snapshots and follows the host's
|
|
29
|
-
* `connect` / `disconnect` events. Devices opened through `open()` forward
|
|
30
|
-
* `inputreport` events to `onInputReport`. Every action resolves to a
|
|
31
|
-
* boolean or value and records failures in `error`. Report listeners are
|
|
32
|
-
* removed and opened devices closed when the owning reactive scope stops;
|
|
33
|
-
* outside a scope call `close()` per device.
|
|
34
|
-
*
|
|
35
|
-
* Server rendering: `supported` is false and `devices` is empty.
|
|
36
|
-
* Inside a component the host is resolved after mounting, so hydration
|
|
37
|
-
* renders this server state first.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const hid = useHID({ onInputReport: ({ reportId, data }) => read(reportId, data) });
|
|
42
|
-
* const [device] = await hid.requestDevice([{ vendorId: 0x054c }]);
|
|
43
|
-
* if (device) await hid.open(device);
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @param options Host and input report callback.
|
|
47
|
-
* @default options {}
|
|
48
|
-
* @returns HID state and actions.
|
|
49
|
-
*/
|
|
50
25
|
function useHID(options = {}) {
|
|
51
26
|
const devices = shallowRef([]);
|
|
52
27
|
const error = shallowRef(void 0);
|
package/dist/use-history.mjs
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
1
|
import { tryOnScopeDispose } from "./scope.mjs";
|
|
2
2
|
import { computed, shallowRef, watch } from "vue";
|
|
3
3
|
//#region src/use-history.ts
|
|
4
|
-
/**
|
|
5
|
-
* Record bounded undo/redo history over the writes of a ref.
|
|
6
|
-
*
|
|
7
|
-
* Recording is shallow and identity-based, matching Vue's own change
|
|
8
|
-
* detection: assignments to `source.value` are recorded (observed with
|
|
9
|
-
* `flush: "sync"`, so every synchronous write counts), writes that are
|
|
10
|
-
* `Object.is`-equal to the current value are not changes, and in-place
|
|
11
|
-
* mutations of object values are invisible — pair mutable values with
|
|
12
|
-
* {@link UseHistoryOptions.clone} and reassign. Undoing and redoing restore
|
|
13
|
-
* values through `clone` as well, so snapshots never share identity with the
|
|
14
|
-
* live value unless the default identity clone is kept. When a
|
|
15
|
-
* user-provided `clone` throws, the failed operation leaves history
|
|
16
|
-
* unchanged and the error propagates.
|
|
17
|
-
*
|
|
18
|
-
* Safe during server rendering: no browser globals are read and no timers
|
|
19
|
-
* start. Cleanup rule: when the owning reactive scope stops, recording stops
|
|
20
|
-
* and every retained snapshot is released, so `undo`/`redo` return `false`
|
|
21
|
-
* afterwards; call inside an active scope, or the watcher lives as long as
|
|
22
|
-
* the source.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const text = shallowRef("");
|
|
27
|
-
* const { undo, redo, batch } = useHistory(text);
|
|
28
|
-
* text.value = "a";
|
|
29
|
-
* batch(() => {
|
|
30
|
-
* text.value = "ab";
|
|
31
|
-
* text.value = "abc";
|
|
32
|
-
* });
|
|
33
|
-
* undo(); // text.value === "a" (the batch is one step)
|
|
34
|
-
* redo(); // text.value === "abc"
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param source Ref whose writes are recorded.
|
|
38
|
-
* @param options Retention bound and snapshot cloning.
|
|
39
|
-
* @default options {}
|
|
40
|
-
* @throws `RangeError` tagged `VIZE_COMPOSE_HISTORY_INVALID_CAPACITY` when
|
|
41
|
-
* the capacity is not an integer greater than zero.
|
|
42
|
-
* @throws `Error` tagged `VIZE_COMPOSE_HISTORY_IN_BATCH` when `undo`,
|
|
43
|
-
* `redo`, or `clear` is called inside {@link HistoryControls.batch}, where
|
|
44
|
-
* stack movement would corrupt the pending group.
|
|
45
|
-
* @returns Reactive undo/redo state and controls.
|
|
46
|
-
*/
|
|
47
4
|
function useHistory(source, options = {}) {
|
|
48
5
|
const capacity = options.capacity ?? 100;
|
|
49
6
|
if (!Number.isInteger(capacity) || capacity < 1) throw new RangeError(`[VIZE_COMPOSE_HISTORY_INVALID_CAPACITY] capacity must be an integer greater than zero; received ${String(capacity)}`);
|
|
@@ -3,27 +3,6 @@ import { hasInjectionContext, useId } from "vue";
|
|
|
3
3
|
function sanitize(part) {
|
|
4
4
|
return part.replaceAll(/[^\w-]/g, "-");
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Create an SSR-stable id factory for one component.
|
|
8
|
-
*
|
|
9
|
-
* Each call to the returned function yields
|
|
10
|
-
* `<prefix>-<seed>-<hint>-<n>` with a per-generator counter, so as long as
|
|
11
|
-
* ids are generated in the same order on the server and the client (for
|
|
12
|
-
* example during `setup`), the markup hydrates without mismatches. The seed
|
|
13
|
-
* comes from Vue's `useId()` inside components, which is itself stable across
|
|
14
|
-
* SSR and hydration; outside components pass an explicit `seed`. Characters
|
|
15
|
-
* outside `[A-Za-z0-9_-]` are replaced so ids are valid in selectors.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const nextId = useIdGenerator({ prefix: "field" });
|
|
20
|
-
* const inputId = nextId("input"); // "field-v-0-input-0"
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param options Prefix and seed.
|
|
24
|
-
* @default options {}
|
|
25
|
-
* @returns The id factory.
|
|
26
|
-
*/
|
|
27
6
|
function useIdGenerator(options = {}) {
|
|
28
7
|
const seed = options.seed ?? (hasInjectionContext() ? useId() : "root");
|
|
29
8
|
const base = `${sanitize(options.prefix ?? "vize")}-${sanitize(seed)}`;
|
package/dist/use-image.mjs
CHANGED
|
@@ -17,28 +17,6 @@ function applySource(image, source) {
|
|
|
17
17
|
if (source.srcset !== void 0) image.srcset = source.srcset;
|
|
18
18
|
image.src = source.src;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
21
|
-
* Preload an image and track its loading state.
|
|
22
|
-
*
|
|
23
|
-
* A detached image is created for every source; the newest load wins, and
|
|
24
|
-
* superseded images have their listeners removed and their `src` cleared so
|
|
25
|
-
* the browser can abort the download. Use it to show a placeholder until
|
|
26
|
-
* the real image is decoded, or to validate URLs before rendering them.
|
|
27
|
-
*
|
|
28
|
-
* Server rendering: no image is created and `status` stays `"idle"`. The
|
|
29
|
-
* pending load is cancelled when the owning reactive scope stops.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* const { ready } = useImage(() => ({ src: avatarUrl.value }));
|
|
34
|
-
* // <img v-if="ready" :src="avatarUrl"> <Skeleton v-else />
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @param source Reactive image attributes.
|
|
38
|
-
* @param options Timing and capability.
|
|
39
|
-
* @default options {}
|
|
40
|
-
* @returns Image state and actions.
|
|
41
|
-
*/
|
|
42
20
|
function useImage(source, options = {}) {
|
|
43
21
|
const status = ref("idle");
|
|
44
22
|
const image = shallowRef(void 0);
|