bitboss-ui 3.0.0-beta.72 → 3.0.0-beta.74
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 +4 -2
- package/bin/bitboss-ui-mcp.mjs +101 -3
- package/bin/bitboss-ui.mjs +6 -1
- package/bin/cli.mjs +34 -7
- package/dist/ai/BbBadge.md +4 -4
- package/dist/ai/BbCalendar.md +4 -3
- package/dist/ai/BbColorPalette.md +8 -9
- package/dist/ai/BbConfirmPortal.md +1 -1
- package/dist/ai/BbDatePicker.md +4 -3
- package/dist/ai/BbDialog.md +17 -4
- package/dist/ai/BbDropdown.md +23 -10
- package/dist/ai/BbDropdownButton.md +2 -2
- package/dist/ai/BbForm.md +11 -7
- package/dist/ai/BbHoverCardPortal.md +1 -1
- package/dist/ai/BbNumberInput.md +5 -3
- package/dist/ai/BbPopoverPortal.md +1 -1
- package/dist/ai/BbTable.md +43 -19
- package/dist/ai/BbTimePicker.md +4 -3
- package/dist/ai/BbToastPortal.md +1 -1
- package/dist/ai/changelog.json +60 -4
- package/dist/ai/components.json +56 -20
- package/dist/ai/guides/design-tokens.md +20 -0
- package/dist/ai/guides/eslint-rules.md +1 -1
- package/dist/ai/guides/inertia-helpers.md +613 -53
- package/dist/ai/guides/migration/adoption-checklist.md +5 -5
- package/dist/ai/guides/migration/components/use-confirm.md +4 -1
- package/dist/ai/guides/migration/v2-to-v3.md +24 -0
- package/dist/ai/guides/migration/v3-beta-tooling.md +3 -0
- package/dist/ai/guides/preset-components.md +15 -2
- package/dist/ai/guides/reporting.md +49 -0
- package/dist/ai/helpers/inertia/manifest.json +33 -38
- package/dist/ai/helpers/inertia/useHasChanged.ts +25 -37
- package/dist/ai/helpers/inertia/useQuery.ts +24 -6
- package/dist/ai/helpers/inertia/utils.ts +552 -3
- package/dist/ai/index.md +1 -0
- package/dist/ai/manifest/components/BbAlert.tree.json +1 -1
- package/dist/ai/manifest/components/BbCalendar.json +2 -2
- package/dist/ai/manifest/components/BbColorPalette.json +3 -3
- package/dist/ai/manifest/components/BbConfirm.removed.json +4 -4
- package/dist/ai/manifest/components/BbConfirmPortal.json +1 -1
- package/dist/ai/manifest/components/BbConfirmPortal.removed.json +2 -2
- package/dist/ai/manifest/components/BbDatePicker.json +3 -3
- package/dist/ai/manifest/components/BbDialog.tree.json +5 -1
- package/dist/ai/manifest/components/BbDropdown.json +3 -3
- package/dist/ai/manifest/components/BbDropdown.tree.json +3 -2
- package/dist/ai/manifest/components/BbDropdownButton.json +2 -2
- package/dist/ai/manifest/components/BbForm.json +1 -1
- package/dist/ai/manifest/components/BbHoverCard.json +1 -1
- package/dist/ai/manifest/components/BbHoverCardPortal.json +1 -1
- package/dist/ai/manifest/components/BbNumberInput.json +1 -1
- package/dist/ai/manifest/components/BbPopover.json +1 -1
- package/dist/ai/manifest/components/BbPopoverPortal.json +1 -1
- package/dist/ai/manifest/components/BbSelectPopover.json +1 -1
- package/dist/ai/manifest/components/BbTable.tree.json +12 -6
- package/dist/ai/manifest/components/BbTimePicker.json +3 -3
- package/dist/ai/manifest/components/BbToast.removed.json +1 -1
- package/dist/ai/manifest/components/BbToastPortal.json +1 -1
- package/dist/ai/manifest/components/CommonPopover.json +1 -1
- package/dist/ai/manifest/index.json +2 -2
- package/dist/ai/manifest/meta.json +36 -0
- package/dist/ai/manifest/types.advanced.json +81 -80
- package/dist/ai/manifest/types.api.json +66 -65
- package/dist/ai/manifest/types.wrapper.json +155 -118
- package/dist/ai/recipes/inertia/layout-scaffold.md +3 -1
- package/dist/ai/recipes/nuxt/layout-scaffold.md +3 -1
- package/dist/ai/recipes/vue/layout-scaffold.md +3 -1
- package/dist/ai/source/BbAlert.md +16 -4
- package/dist/ai/source/BbAvatar.md +2 -0
- package/dist/ai/source/BbBreadcrumbs.md +4 -1
- package/dist/ai/source/BbCalendar.md +22 -12
- package/dist/ai/source/BbColorPalette.md +41 -12
- package/dist/ai/source/BbConfirm.md +7 -0
- package/dist/ai/source/BbConfirmPortal.md +9 -4
- package/dist/ai/source/BbDatePicker.md +53 -22
- package/dist/ai/source/BbDatePickerInput.md +32 -8
- package/dist/ai/source/BbDialog.md +31 -1
- package/dist/ai/source/BbDropdown.md +52 -24
- package/dist/ai/source/BbDropdownGroup.md +17 -21
- package/dist/ai/source/BbForm.md +80 -6
- package/dist/ai/source/BbHoverCard.md +7 -0
- package/dist/ai/source/BbHoverCardPortal.md +9 -5
- package/dist/ai/source/BbNumberInput.md +5 -6
- package/dist/ai/source/BbOffCanvas.md +34 -1
- package/dist/ai/source/BbPopover.md +7 -0
- package/dist/ai/source/BbPopoverPortal.md +9 -5
- package/dist/ai/source/BbRadio.md +4 -3
- package/dist/ai/source/BbRadioGroup.md +7 -5
- package/dist/ai/source/BbTable.md +54 -6
- package/dist/ai/source/BbTag.md +10 -3
- package/dist/ai/source/BbTimePicker.md +50 -15
- package/dist/ai/source/BbTimePickerInput.md +30 -7
- package/dist/ai/source/BbToast.md +14 -0
- package/dist/ai/source/BbToastPortal.md +16 -4
- package/dist/ai/source/CommonFieldInput.md +11 -5
- package/dist/ai/source/CommonPopover.md +4 -1
- package/dist/components/BbAlert/BbAlert.vue_vue_type_script_setup_true_lang.js +31 -26
- package/dist/components/BbBreadcrumbs/BbBreadcrumbs.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/BbCalendar/BbCalendar.vue.d.ts +1 -1
- package/dist/components/BbCalendar/BbCalendar.vue_vue_type_script_setup_true_lang.js +235 -234
- package/dist/components/BbCalendar/types.d.ts +2 -2
- package/dist/components/BbCalendar/useDayjsLocale.js +11 -8
- package/dist/components/BbColorPalette/BbColorPalette.vue_vue_type_script_setup_true_lang.js +197 -192
- package/dist/components/BbColorPalette/types.d.ts +1 -1
- package/dist/components/BbConfirm/BbConfirmPortal.vue.d.ts +2 -4
- package/dist/components/BbConfirm/types.d.ts +5 -0
- package/dist/components/BbDatePicker/BbDatePicker.vue.d.ts +1 -1
- package/dist/components/BbDatePicker/BbDatePicker.vue_vue_type_script_setup_true_lang.js +145 -139
- package/dist/components/BbDatePicker/types.d.ts +2 -2
- package/dist/components/BbDatePickerInput/BbDatePickerInput.vue_vue_type_script_setup_true_lang.js +337 -335
- package/dist/components/BbDialog/BbDialog.vue_vue_type_script_setup_true_lang.js +253 -245
- package/dist/components/BbDialog/leaveGhost.js +33 -0
- package/dist/components/BbDialog/overlayActions.js +34 -20
- package/dist/components/BbDropdown/BbDropdown.vue_vue_type_script_setup_true_lang.js +11 -3
- package/dist/components/BbDropdown/BbDropdownList.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/components/BbDropdown/DropdownPipelineResolver.vue_vue_type_script_setup_true_lang.js +119 -120
- package/dist/components/BbDropdown/types.d.ts +8 -17
- package/dist/components/BbForm/BbForm.vue.d.ts +2 -21
- package/dist/components/BbForm/BbForm.vue_vue_type_script_setup_true_lang.js +229 -227
- package/dist/components/BbForm/types.d.ts +31 -0
- package/dist/components/BbHoverCard/BbHoverCardPortal.vue.d.ts +2 -5
- package/dist/components/BbHoverCard/types.d.ts +5 -0
- package/dist/components/BbNumberInput/BbNumberInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/BbNumberInput/numberDisplay.js +102 -106
- package/dist/components/BbNumberInput/types.d.ts +4 -3
- package/dist/components/BbOffCanvas/BbOffCanvas.vue_vue_type_script_setup_true_lang.js +385 -377
- package/dist/components/BbPopover/BbPopoverPortal.vue.d.ts +2 -5
- package/dist/components/BbPopover/types.d.ts +5 -0
- package/dist/components/BbRadio/types.d.ts +4 -3
- package/dist/components/BbRadioGroup/BbRadioGroup.vue_vue_type_script_setup_true_lang.js +10 -12
- package/dist/components/BbTable/BbTable.vue_vue_type_script_setup_true_lang.js +231 -231
- package/dist/components/BbTable/BbTableDataRow.js +96 -96
- package/dist/components/BbTag/BbTag.vue_vue_type_script_setup_true_lang.js +9 -3
- package/dist/components/BbTimePicker/BbTimePicker.vue.d.ts +1 -1
- package/dist/components/BbTimePicker/BbTimePicker.vue_vue_type_script_setup_true_lang.js +106 -100
- package/dist/components/BbTimePicker/types.d.ts +2 -2
- package/dist/components/BbTimePickerInput/BbTimePickerInput.vue_vue_type_script_setup_true_lang.js +214 -213
- package/dist/components/BbToast/BbToastPortal.vue.d.ts +2 -4
- package/dist/components/BbToast/types.d.ts +5 -0
- package/dist/components/CommonFieldInput/CommonFieldInput.vue_vue_type_script_setup_true_lang.js +36 -36
- package/dist/components/CommonPopover/CommonPopover.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/components/CommonTimeSelector/useMeridiem.js +6 -6
- package/dist/composables/formSubmitLock.js +2 -1
- package/dist/composables/overlayRegistry.js +52 -42
- package/dist/composables/useActiveInactiveState.js +8 -4
- package/dist/composables/useBbDialog.js +5 -5
- package/dist/composables/useOwnModel.js +16 -0
- package/dist/composables/useSegmentedFields.js +31 -20
- package/dist/deprecation/ai-deprecations.json.js +1 -1
- package/dist/i18n/currencyDigits.js +58 -0
- package/dist/i18n/regionDates.js +250 -0
- package/dist/i18n/regionHints.js +30 -41
- package/dist/index.d.ts +34 -30
- package/dist/llms-full.txt +874 -136
- package/dist/llms.txt +3 -1
- package/dist/styles.css +2 -2
- package/dist/types/ActionButton.d.ts +3 -1
- package/dist/types/CommonProps.d.ts +8 -0
- package/dist/utilities/functions/hash.js +123 -3
- package/dist/utilities/functions/isEqual.js +69 -3
- package/dist/utils/versionCheck.js +1 -1
- package/dist/vite-plugin.d.ts +2 -1
- package/dist/vite.js +8 -5
- package/llms.txt +3 -1
- package/package.json +2 -3
- package/scripts/README.md +43 -43
- package/scripts/lib/adoption-checklist.json +6 -5
- package/scripts/lib/agent-manifest.mjs +33 -6
- package/scripts/lib/agent-setup.mjs +54 -6
- package/scripts/lib/cldr-pins.ts +182 -0
- package/scripts/lib/engines-include.d.mts +5 -0
- package/scripts/lib/engines-include.mjs +40 -0
- package/scripts/lib/eslint-plugin.mjs +8 -2
- package/scripts/lib/helpers-add.mjs +21 -2
- package/scripts/lib/hidden-label-placeholder.mjs +25 -5
- package/scripts/lib/idiom-scan.mjs +30 -3
- package/scripts/lib/legacy-agent-files.json +152 -0
- package/scripts/lib/mcp-config.mjs +74 -7
- package/scripts/lib/portal-names.mjs +78 -8
- package/scripts/lib/release-results.mjs +153 -6
- package/scripts/lib/report.mjs +340 -0
- package/scripts/lib/run-beat.mjs +14 -0
- package/scripts/lib/run-records.mjs +313 -0
- package/scripts/lib/selector-log.mjs +98 -0
- package/scripts/lib/ticket-beat.mjs +30 -0
- package/scripts/lib/validate-bb-markup.mjs +17 -2
|
@@ -93,21 +93,22 @@ explicitly rather than relying on them being hoisted through `bitboss-ui`'s own
|
|
|
93
93
|
`dependencies`, which breaks under pnpm and Yarn PnP:
|
|
94
94
|
|
|
95
95
|
```
|
|
96
|
-
npm i @vueuse/core
|
|
96
|
+
npm i @vueuse/core query-string
|
|
97
97
|
npm i -D @inertiajs/core
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
`@vueuse/core` backs every keyed context's `injectLocal`/`provideLocal`
|
|
101
101
|
(`usePaginatedResponseContext`, `useTableSelectionContext`, `useTableContext`,
|
|
102
|
-
`usePageShellContext`) and `useDeleteCmd`/`useScreenSizes`; `
|
|
103
|
-
powers the `isEqual` hash-comparison utility below; `query-string` backs
|
|
102
|
+
`usePageShellContext`) and `useDeleteCmd`/`useScreenSizes`; `query-string` backs
|
|
104
103
|
`useQuery`/`useRouteQuery`/`useQueryObject`; `@inertiajs/core` is a type-only
|
|
105
104
|
import (`PageProps`, `VisitOptions`, in the URL and context helpers) that `@inertiajs/vue3`
|
|
106
105
|
does not re-export, so a strict pnpm app fails to type-check without it. Install
|
|
107
106
|
the version your `@inertiajs/vue3` runs on (`add` prints it pinned, e.g.
|
|
108
107
|
`@inertiajs/core@3.1.1`): a newer core's visit types do not match. The
|
|
109
108
|
helpers' shared types, tiny utilities and words are three files of the
|
|
110
|
-
folder, `types.ts`, `utils.ts` and `messages.ts`, below.
|
|
109
|
+
folder, `types.ts`, `utils.ts` and `messages.ts`, below. `utils.ts` carries a
|
|
110
|
+
copy of bitboss-ui's exact `isEqual` and `hash` (the package exports
|
|
111
|
+
components, not utilities).
|
|
111
112
|
|
|
112
113
|
## Shared types and utilities
|
|
113
114
|
|
|
@@ -149,7 +150,7 @@ hand-built `{ data, meta }`. Pass whichever your controller has, as is — see
|
|
|
149
150
|
```ts
|
|
150
151
|
// inertia-helpers/utils.ts
|
|
151
152
|
// micro-utilities the helpers share
|
|
152
|
-
import {
|
|
153
|
+
import { toRaw } from 'vue';
|
|
153
154
|
|
|
154
155
|
export const isNil = (value: unknown): value is null | undefined =>
|
|
155
156
|
value === null || value === undefined;
|
|
@@ -162,8 +163,557 @@ export const isEmpty = (value: unknown): boolean =>
|
|
|
162
163
|
|
|
163
164
|
export const noop = (): void => undefined;
|
|
164
165
|
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
/*
|
|
167
|
+
* EXACT deep equality, the same as bitboss-ui's own. Never a hash: the
|
|
168
|
+
* object-code hash it replaced folded a number to int32 (2400 === 2400.5,
|
|
169
|
+
* 0.1 === 0.2), so a decimal-only change read as "unchanged".
|
|
170
|
+
*
|
|
171
|
+
* - Primitives: `Object.is` (NaN equals NaN, 0 and -0 differ).
|
|
172
|
+
* - Vue proxies are read raw; the same reference is equal.
|
|
173
|
+
* - Arrays by index; plain objects by own enumerable keys (order aside, a key
|
|
174
|
+
* holding `undefined` is still a key); Dates by time; Maps and Sets by content.
|
|
175
|
+
* - Files: the same file, or one with the same name, size, type and
|
|
176
|
+
* lastModified (a re-read of the same pick).
|
|
177
|
+
* - Class instances: the same constructor, then a primitive `valueOf()`
|
|
178
|
+
* (dayjs, Decimal …), else a custom `toString()` when there are no fields
|
|
179
|
+
* (URL, Temporal …), else their fields.
|
|
180
|
+
* - Cycles: a pair already being compared counts as equal.
|
|
181
|
+
*
|
|
182
|
+
* `hash` below agrees: equal values give the same key.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
type Seen = { xs: object[]; ys: object[] };
|
|
186
|
+
|
|
187
|
+
const isPlainProto = (proto: object | null) =>
|
|
188
|
+
proto === null || Object.getPrototypeOf(proto) === null;
|
|
189
|
+
|
|
190
|
+
export const isEqual = (a: unknown, b: unknown): boolean => equal(a, b, null);
|
|
191
|
+
|
|
192
|
+
const equal = (a: unknown, b: unknown, seen: Seen | null): boolean => {
|
|
193
|
+
if (Object.is(a, b)) return true;
|
|
194
|
+
if (
|
|
195
|
+
a === null ||
|
|
196
|
+
b === null ||
|
|
197
|
+
typeof a !== 'object' ||
|
|
198
|
+
typeof b !== 'object'
|
|
199
|
+
)
|
|
200
|
+
return false;
|
|
201
|
+
|
|
202
|
+
const x = toRaw(a);
|
|
203
|
+
const y = toRaw(b);
|
|
204
|
+
if (x === y) return true;
|
|
205
|
+
if (seen === null) seen = { xs: [], ys: [] };
|
|
206
|
+
const { xs, ys } = seen;
|
|
207
|
+
for (let i = 0; i < xs.length; i++)
|
|
208
|
+
if (xs[i] === x && ys[i] === y) return true;
|
|
209
|
+
xs.push(x);
|
|
210
|
+
ys.push(y);
|
|
211
|
+
try {
|
|
212
|
+
return equalObjects(x, y, seen);
|
|
213
|
+
} finally {
|
|
214
|
+
xs.pop();
|
|
215
|
+
ys.pop();
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const equalObjects = (x: object, y: object, seen: Seen): boolean => {
|
|
220
|
+
if (Array.isArray(x)) {
|
|
221
|
+
if (!Array.isArray(y) || x.length !== y.length) return false;
|
|
222
|
+
const other = y as unknown[];
|
|
223
|
+
for (let i = 0; i < x.length; i++)
|
|
224
|
+
if (!equal(x[i], other[i], seen)) return false;
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (Array.isArray(y)) return false;
|
|
228
|
+
|
|
229
|
+
const px = Object.getPrototypeOf(x) as object | null;
|
|
230
|
+
const py = Object.getPrototypeOf(y) as object | null;
|
|
231
|
+
const plainX = px === Object.prototype || px === null;
|
|
232
|
+
const plainY = py === Object.prototype || py === null;
|
|
233
|
+
if (plainX && plainY) return equalFields(x, y, seen);
|
|
234
|
+
if (plainX !== plainY || px !== py) {
|
|
235
|
+
// Plain objects from two realms (or a null-prototype one) still compare.
|
|
236
|
+
return isPlainProto(px) && isPlainProto(py)
|
|
237
|
+
? equalFields(x, y, seen)
|
|
238
|
+
: false;
|
|
239
|
+
}
|
|
240
|
+
// Same prototype from here on; a foreign realm's plain objects land here too.
|
|
241
|
+
if (isPlainProto(px)) return equalFields(x, y, seen);
|
|
242
|
+
|
|
243
|
+
if (x instanceof Date) return Object.is(x.getTime(), (y as Date).getTime());
|
|
244
|
+
if (x instanceof Map) return equalMaps(x, y as Map<unknown, unknown>, seen);
|
|
245
|
+
if (x instanceof Set) return equalSets(x, y as Set<unknown>, seen);
|
|
246
|
+
if (typeof Blob !== 'undefined' && x instanceof Blob) {
|
|
247
|
+
const f = x as File;
|
|
248
|
+
const g = y as File;
|
|
249
|
+
return (
|
|
250
|
+
f.name === g.name &&
|
|
251
|
+
f.size === g.size &&
|
|
252
|
+
f.type === g.type &&
|
|
253
|
+
f.lastModified === g.lastModified
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const p = primitiveValueOf(x);
|
|
258
|
+
if (p) {
|
|
259
|
+
const q = primitiveValueOf(y);
|
|
260
|
+
return !!q && Object.is(p.value, q.value);
|
|
261
|
+
}
|
|
262
|
+
if (Object.keys(x).length === 0 && Object.keys(y).length === 0) {
|
|
263
|
+
const text = customText(x);
|
|
264
|
+
if (text !== undefined) return text === customText(y);
|
|
265
|
+
}
|
|
266
|
+
return equalFields(x, y, seen);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const equalFields = (x: object, y: object, seen: Seen) => {
|
|
270
|
+
const keys = Object.keys(x);
|
|
271
|
+
if (keys.length !== Object.keys(y).length) return false;
|
|
272
|
+
for (const key of keys) {
|
|
273
|
+
if (!Object.prototype.hasOwnProperty.call(y, key)) return false;
|
|
274
|
+
if (
|
|
275
|
+
!equal(
|
|
276
|
+
(x as Record<string, unknown>)[key],
|
|
277
|
+
(y as Record<string, unknown>)[key],
|
|
278
|
+
seen
|
|
279
|
+
)
|
|
280
|
+
)
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const equalMaps = (
|
|
287
|
+
x: Map<unknown, unknown>,
|
|
288
|
+
y: Map<unknown, unknown>,
|
|
289
|
+
seen: Seen
|
|
290
|
+
) => {
|
|
291
|
+
if (x.size !== y.size) return false;
|
|
292
|
+
const unmatched = [...y.entries()];
|
|
293
|
+
for (const [key, value] of x) {
|
|
294
|
+
const at = y.has(key)
|
|
295
|
+
? unmatched.findIndex(([k]) => k === key || Object.is(k, key))
|
|
296
|
+
: unmatched.findIndex(([k]) => equal(k, key, seen));
|
|
297
|
+
const match = at === -1 ? undefined : unmatched[at];
|
|
298
|
+
if (!match || !equal(value, match[1], seen)) return false;
|
|
299
|
+
unmatched.splice(at, 1);
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const equalSets = (x: Set<unknown>, y: Set<unknown>, seen: Seen) => {
|
|
305
|
+
if (x.size !== y.size) return false;
|
|
306
|
+
const unmatched = [...y];
|
|
307
|
+
for (const member of x) {
|
|
308
|
+
const at = y.has(member)
|
|
309
|
+
? unmatched.findIndex((m) => m === member || Object.is(m, member))
|
|
310
|
+
: unmatched.findIndex((m) => equal(m, member, seen));
|
|
311
|
+
if (at === -1) return false;
|
|
312
|
+
unmatched.splice(at, 1);
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/*
|
|
318
|
+
* A key for any value, the same as bitboss-ui's own: a 96-bit digest of an
|
|
319
|
+
* EXACT encoding (numbers by their IEEE-754 bits, strings by length + text,
|
|
320
|
+
* objects by sorted own keys, Maps and Sets by sorted content, Dates by time,
|
|
321
|
+
* Files by name/size/type/lastModified, value objects by `valueOf()`).
|
|
322
|
+
* Numbers, booleans, null and short id-safe strings are spelled out exactly.
|
|
323
|
+
* Equal values (by `isEqual`) give the same key; useHasChanged keeps one as
|
|
324
|
+
* its baseline.
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
// Structural tags of the word stream. The encoding is prefix-free: a tag
|
|
328
|
+
// fixes how its payload words are counted (numbers are two words, strings
|
|
329
|
+
// are length-prefixed, arrays/objects/maps/sets are count-prefixed), so two
|
|
330
|
+
// different values can only key alike through the 96-bit finish.
|
|
331
|
+
const T_UNDEFINED = 0x100;
|
|
332
|
+
const T_NULL = 0x101;
|
|
333
|
+
const T_TRUE = 0x102;
|
|
334
|
+
const T_FALSE = 0x103;
|
|
335
|
+
const T_NUMBER = 0x104;
|
|
336
|
+
const T_BIGINT = 0x105;
|
|
337
|
+
const T_STRING = 0x106;
|
|
338
|
+
const T_SYMBOL = 0x107;
|
|
339
|
+
const T_FUNCTION = 0x108;
|
|
340
|
+
const T_ARRAY = 0x109;
|
|
341
|
+
const T_DATE = 0x10a;
|
|
342
|
+
const T_MAP = 0x10b;
|
|
343
|
+
const T_SET = 0x10c;
|
|
344
|
+
const T_BLOB = 0x10d;
|
|
345
|
+
const T_OBJECT = 0x10e;
|
|
346
|
+
const T_CLASS = 0x10f;
|
|
347
|
+
const T_CYCLE = 0x110;
|
|
348
|
+
const T_VALUE_OF = 0x111;
|
|
349
|
+
const T_TO_STRING = 0x112;
|
|
350
|
+
const T_ENTRY = 0x113;
|
|
351
|
+
|
|
352
|
+
type Lanes = [number, number, number, number];
|
|
353
|
+
|
|
354
|
+
const start = (): Lanes => [
|
|
355
|
+
0x243f6a88 | 0,
|
|
356
|
+
0x85a308d3 | 0,
|
|
357
|
+
0x13198a2e | 0,
|
|
358
|
+
0x03707344 | 0,
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
const mix = (s: Lanes, w: number) => {
|
|
362
|
+
s[0] = Math.imul(s[0] ^ w, 2654435761);
|
|
363
|
+
s[0] = (s[0] << 13) | (s[0] >>> 19);
|
|
364
|
+
s[1] = Math.imul(s[1] ^ w, 1597334677);
|
|
365
|
+
s[1] = (s[1] << 17) | (s[1] >>> 15);
|
|
366
|
+
s[2] = Math.imul(s[2] ^ w, 2246822519);
|
|
367
|
+
s[2] = (s[2] << 19) | (s[2] >>> 13);
|
|
368
|
+
s[3] = Math.imul(s[3] ^ w, 3266489917);
|
|
369
|
+
s[3] = (s[3] << 23) | (s[3] >>> 9);
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
const mix2 = (s: Lanes, w1: number, w2: number) => {
|
|
373
|
+
let a = s[0];
|
|
374
|
+
let b = s[1];
|
|
375
|
+
let c = s[2];
|
|
376
|
+
let d = s[3];
|
|
377
|
+
a = Math.imul(a ^ w1, 2654435761);
|
|
378
|
+
a = (a << 13) | (a >>> 19);
|
|
379
|
+
b = Math.imul(b ^ w1, 1597334677);
|
|
380
|
+
b = (b << 17) | (b >>> 15);
|
|
381
|
+
c = Math.imul(c ^ w1, 2246822519);
|
|
382
|
+
c = (c << 19) | (c >>> 13);
|
|
383
|
+
d = Math.imul(d ^ w1, 3266489917);
|
|
384
|
+
d = (d << 23) | (d >>> 9);
|
|
385
|
+
a = Math.imul(a ^ w2, 2654435761);
|
|
386
|
+
a = (a << 13) | (a >>> 19);
|
|
387
|
+
b = Math.imul(b ^ w2, 1597334677);
|
|
388
|
+
b = (b << 17) | (b >>> 15);
|
|
389
|
+
c = Math.imul(c ^ w2, 2246822519);
|
|
390
|
+
c = (c << 19) | (c >>> 13);
|
|
391
|
+
d = Math.imul(d ^ w2, 3266489917);
|
|
392
|
+
d = (d << 23) | (d >>> 9);
|
|
393
|
+
s[0] = a;
|
|
394
|
+
s[1] = b;
|
|
395
|
+
s[2] = c;
|
|
396
|
+
s[3] = d;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// Packed string feed: two UTF-16 units per word. `head` is a word mixed
|
|
400
|
+
// before the length (a type tag) or -1 to mix the length only (object keys).
|
|
401
|
+
const mixString = (s: Lanes, head: number, text: string) => {
|
|
402
|
+
let a = s[0];
|
|
403
|
+
let b = s[1];
|
|
404
|
+
let c = s[2];
|
|
405
|
+
let d = s[3];
|
|
406
|
+
if (head !== -1) {
|
|
407
|
+
a = Math.imul(a ^ head, 2654435761);
|
|
408
|
+
a = (a << 13) | (a >>> 19);
|
|
409
|
+
b = Math.imul(b ^ head, 1597334677);
|
|
410
|
+
b = (b << 17) | (b >>> 15);
|
|
411
|
+
c = Math.imul(c ^ head, 2246822519);
|
|
412
|
+
c = (c << 19) | (c >>> 13);
|
|
413
|
+
d = Math.imul(d ^ head, 3266489917);
|
|
414
|
+
d = (d << 23) | (d >>> 9);
|
|
415
|
+
}
|
|
416
|
+
const n = text.length;
|
|
417
|
+
a = Math.imul(a ^ n, 2654435761);
|
|
418
|
+
a = (a << 13) | (a >>> 19);
|
|
419
|
+
b = Math.imul(b ^ n, 1597334677);
|
|
420
|
+
b = (b << 17) | (b >>> 15);
|
|
421
|
+
c = Math.imul(c ^ n, 2246822519);
|
|
422
|
+
c = (c << 19) | (c >>> 13);
|
|
423
|
+
d = Math.imul(d ^ n, 3266489917);
|
|
424
|
+
d = (d << 23) | (d >>> 9);
|
|
425
|
+
let i = 0;
|
|
426
|
+
for (; i + 1 < n; i += 2) {
|
|
427
|
+
const w = text.charCodeAt(i) | (text.charCodeAt(i + 1) << 16);
|
|
428
|
+
a = Math.imul(a ^ w, 2654435761);
|
|
429
|
+
a = (a << 13) | (a >>> 19);
|
|
430
|
+
b = Math.imul(b ^ w, 1597334677);
|
|
431
|
+
b = (b << 17) | (b >>> 15);
|
|
432
|
+
c = Math.imul(c ^ w, 2246822519);
|
|
433
|
+
c = (c << 19) | (c >>> 13);
|
|
434
|
+
d = Math.imul(d ^ w, 3266489917);
|
|
435
|
+
d = (d << 23) | (d >>> 9);
|
|
436
|
+
}
|
|
437
|
+
if (i < n) {
|
|
438
|
+
const w = text.charCodeAt(i);
|
|
439
|
+
a = Math.imul(a ^ w, 2654435761);
|
|
440
|
+
a = (a << 13) | (a >>> 19);
|
|
441
|
+
b = Math.imul(b ^ w, 1597334677);
|
|
442
|
+
b = (b << 17) | (b >>> 15);
|
|
443
|
+
c = Math.imul(c ^ w, 2246822519);
|
|
444
|
+
c = (c << 19) | (c >>> 13);
|
|
445
|
+
d = Math.imul(d ^ w, 3266489917);
|
|
446
|
+
d = (d << 23) | (d >>> 9);
|
|
447
|
+
}
|
|
448
|
+
s[0] = a;
|
|
449
|
+
s[1] = b;
|
|
450
|
+
s[2] = c;
|
|
451
|
+
s[3] = d;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// A double by its bit pattern: exact for every finite/infinite value, -0
|
|
455
|
+
// apart from 0 as `Object.is` has it, every NaN payload mapped to one
|
|
456
|
+
// canonical pattern (Object.is(NaN, NaN)). The words are read
|
|
457
|
+
// little-endian whatever the host, so server and client agree.
|
|
458
|
+
const bits = new DataView(new ArrayBuffer(8));
|
|
459
|
+
const lowWord = (n: number) => {
|
|
460
|
+
bits.setFloat64(0, n, true);
|
|
461
|
+
return bits.getUint32(0, true);
|
|
462
|
+
};
|
|
463
|
+
/** The high word of the double `lowWord` last read. */
|
|
464
|
+
const highWord = () => bits.getUint32(4, true);
|
|
465
|
+
|
|
466
|
+
const mixNumber = (s: Lanes, n: number) => {
|
|
467
|
+
if (n !== n) return mix2(s, 0, 0x7ff80000);
|
|
468
|
+
const lo = lowWord(n);
|
|
469
|
+
return mix2(s, lo | 0, highWord() | 0);
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
const fmix32 = (h: number) => {
|
|
473
|
+
h ^= h >>> 16;
|
|
474
|
+
h = Math.imul(h, 0x85ebca6b);
|
|
475
|
+
h ^= h >>> 13;
|
|
476
|
+
h = Math.imul(h, 0xc2b2ae35);
|
|
477
|
+
h ^= h >>> 16;
|
|
478
|
+
return h >>> 0;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// 96 bits out: three lanes, each cross-folded with a neighbour so no lane's
|
|
482
|
+
// state reaches the key unmixed with the others.
|
|
483
|
+
const finishWords = (s: Lanes): [number, number, number] => [
|
|
484
|
+
fmix32(s[0] ^ s[3]),
|
|
485
|
+
fmix32(s[1] ^ s[0]),
|
|
486
|
+
fmix32(s[2] ^ s[1]),
|
|
487
|
+
];
|
|
488
|
+
|
|
489
|
+
/** A 32-bit word as 8 hex digits. */
|
|
490
|
+
const hexWord = (w: number) => (w >>> 0).toString(16).padStart(8, '0');
|
|
491
|
+
|
|
492
|
+
/** A primitive `valueOf()` of a value object (dayjs, Decimal …), else `undefined`. */
|
|
493
|
+
const primitiveValueOf = (o: object): { value: unknown } | undefined => {
|
|
494
|
+
const valueOf = (o as { valueOf?: unknown }).valueOf;
|
|
495
|
+
if (typeof valueOf !== 'function' || valueOf === Object.prototype.valueOf)
|
|
496
|
+
return undefined;
|
|
497
|
+
try {
|
|
498
|
+
const value = valueOf.call(o);
|
|
499
|
+
if (value !== o && (value === null || typeof value !== 'object'))
|
|
500
|
+
return { value };
|
|
501
|
+
} catch {
|
|
502
|
+
// Temporal and friends throw on valueOf: fall through.
|
|
503
|
+
}
|
|
504
|
+
return undefined;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
/** `o`'s text through a custom `toString` (URL, Temporal …), else `undefined`. */
|
|
508
|
+
const customText = (o: object): string | undefined => {
|
|
509
|
+
const toString = (o as { toString?: unknown }).toString;
|
|
510
|
+
return typeof toString === 'function' &&
|
|
511
|
+
toString !== Object.prototype.toString
|
|
512
|
+
? (toString as (this: object) => string).call(o)
|
|
513
|
+
: undefined;
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const encode = (s: Lanes, value: unknown, stack: object[]): void => {
|
|
517
|
+
switch (typeof value) {
|
|
518
|
+
case 'undefined':
|
|
519
|
+
return mix(s, T_UNDEFINED);
|
|
520
|
+
case 'boolean':
|
|
521
|
+
return mix(s, value ? T_TRUE : T_FALSE);
|
|
522
|
+
case 'number':
|
|
523
|
+
mix(s, T_NUMBER);
|
|
524
|
+
return mixNumber(s, value);
|
|
525
|
+
case 'bigint':
|
|
526
|
+
return mixString(s, T_BIGINT, String(value));
|
|
527
|
+
case 'string':
|
|
528
|
+
return mixString(s, T_STRING, value);
|
|
529
|
+
case 'symbol':
|
|
530
|
+
return mixString(s, T_SYMBOL, String(value.description));
|
|
531
|
+
case 'function':
|
|
532
|
+
// By source text, as before: two closures of one factory key alike.
|
|
533
|
+
return mixString(s, T_FUNCTION, String(value));
|
|
534
|
+
}
|
|
535
|
+
if (value === null) return mix(s, T_NULL);
|
|
536
|
+
|
|
537
|
+
const o = toRaw(value as object);
|
|
538
|
+
const depth = stack.indexOf(o);
|
|
539
|
+
if (depth !== -1) return mix2(s, T_CYCLE, depth);
|
|
540
|
+
stack.push(o);
|
|
541
|
+
try {
|
|
542
|
+
encodeObject(s, o, stack);
|
|
543
|
+
} finally {
|
|
544
|
+
stack.pop();
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const encodeFields = (s: Lanes, o: object, stack: object[]) => {
|
|
549
|
+
const keys = Object.keys(o).sort();
|
|
550
|
+
mix(s, keys.length);
|
|
551
|
+
for (const key of keys) {
|
|
552
|
+
mixString(s, -1, key);
|
|
553
|
+
encode(s, (o as Record<string, unknown>)[key], stack);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// Map/Set members are digested apart and mixed back in sorted order, so
|
|
558
|
+
// iteration order cannot change the key.
|
|
559
|
+
const compareWords = (
|
|
560
|
+
a: [number, number, number],
|
|
561
|
+
b: [number, number, number]
|
|
562
|
+
) =>
|
|
563
|
+
a[0] !== b[0]
|
|
564
|
+
? a[0] < b[0]
|
|
565
|
+
? -1
|
|
566
|
+
: 1
|
|
567
|
+
: a[1] !== b[1]
|
|
568
|
+
? a[1] < b[1]
|
|
569
|
+
? -1
|
|
570
|
+
: 1
|
|
571
|
+
: a[2] < b[2]
|
|
572
|
+
? -1
|
|
573
|
+
: a[2] > b[2]
|
|
574
|
+
? 1
|
|
575
|
+
: 0;
|
|
576
|
+
|
|
577
|
+
const mixSortedDigests = (
|
|
578
|
+
s: Lanes,
|
|
579
|
+
digests: Array<[number, number, number]>
|
|
580
|
+
) => {
|
|
581
|
+
digests.sort(compareWords);
|
|
582
|
+
for (const d of digests) {
|
|
583
|
+
mix(s, d[0] | 0);
|
|
584
|
+
mix2(s, d[1] | 0, d[2] | 0);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const encodeObject = (s: Lanes, o: object, stack: object[]) => {
|
|
589
|
+
if (Array.isArray(o)) {
|
|
590
|
+
mix2(s, T_ARRAY, o.length);
|
|
591
|
+
for (const item of o) encode(s, item, stack);
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const proto = Object.getPrototypeOf(o);
|
|
595
|
+
if (proto === Object.prototype || proto === null) {
|
|
596
|
+
mix(s, T_OBJECT);
|
|
597
|
+
return encodeFields(s, o, stack);
|
|
598
|
+
}
|
|
599
|
+
if (o instanceof Date) {
|
|
600
|
+
mix(s, T_DATE);
|
|
601
|
+
return mixNumber(s, o.getTime());
|
|
602
|
+
}
|
|
603
|
+
if (o instanceof Map) {
|
|
604
|
+
mix2(s, T_MAP, o.size);
|
|
605
|
+
const digests: Array<[number, number, number]> = [];
|
|
606
|
+
for (const [k, v] of o) {
|
|
607
|
+
const sub = start();
|
|
608
|
+
mix(sub, T_ENTRY);
|
|
609
|
+
encode(sub, k, stack);
|
|
610
|
+
encode(sub, v, stack);
|
|
611
|
+
digests.push(finishWords(sub));
|
|
612
|
+
}
|
|
613
|
+
return mixSortedDigests(s, digests);
|
|
614
|
+
}
|
|
615
|
+
if (o instanceof Set) {
|
|
616
|
+
mix2(s, T_SET, o.size);
|
|
617
|
+
const digests: Array<[number, number, number]> = [];
|
|
618
|
+
for (const member of o) {
|
|
619
|
+
const sub = start();
|
|
620
|
+
encode(sub, member, stack);
|
|
621
|
+
digests.push(finishWords(sub));
|
|
622
|
+
}
|
|
623
|
+
return mixSortedDigests(s, digests);
|
|
624
|
+
}
|
|
625
|
+
if (typeof Blob !== 'undefined' && o instanceof Blob) {
|
|
626
|
+
mix(s, T_BLOB);
|
|
627
|
+
encode(s, (o as File).name ?? null, stack);
|
|
628
|
+
encode(s, o.size, stack);
|
|
629
|
+
encode(s, o.type, stack);
|
|
630
|
+
encode(s, (o as File).lastModified ?? null, stack);
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (isPlainProto(proto)) {
|
|
634
|
+
// A plain object from another realm.
|
|
635
|
+
mix(s, T_OBJECT);
|
|
636
|
+
return encodeFields(s, o, stack);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// A class instance: its constructor's name, then its value.
|
|
640
|
+
mix(s, T_CLASS);
|
|
641
|
+
mixString(s, -1, String(o.constructor?.name ?? ''));
|
|
642
|
+
const primitive = primitiveValueOf(o);
|
|
643
|
+
if (primitive) {
|
|
644
|
+
mix(s, T_VALUE_OF);
|
|
645
|
+
return encode(s, primitive.value, stack);
|
|
646
|
+
}
|
|
647
|
+
const text = Object.keys(o).length === 0 ? customText(o) : undefined;
|
|
648
|
+
if (text !== undefined) {
|
|
649
|
+
mix(s, T_TO_STRING);
|
|
650
|
+
return encode(s, text, stack);
|
|
651
|
+
}
|
|
652
|
+
return encodeFields(s, o, stack);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const digestOf = (value: unknown) => {
|
|
656
|
+
const s = start();
|
|
657
|
+
encode(s, value, []);
|
|
658
|
+
const words = finishWords(s);
|
|
659
|
+
return hexWord(words[0]) + hexWord(words[1]) + hexWord(words[2]);
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
// A short string of id characters is its own key (`s` + the text).
|
|
663
|
+
const isShortIdSafe = (text: string) => {
|
|
664
|
+
if (text.length > 64) return false;
|
|
665
|
+
for (let i = 0; i < text.length; i++) {
|
|
666
|
+
const c = text.charCodeAt(i);
|
|
667
|
+
if (
|
|
668
|
+
!(
|
|
669
|
+
(c >= 48 && c <= 57) ||
|
|
670
|
+
(c >= 65 && c <= 90) ||
|
|
671
|
+
(c >= 97 && c <= 122) ||
|
|
672
|
+
c === 95 ||
|
|
673
|
+
c === 45
|
|
674
|
+
)
|
|
675
|
+
)
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
return true;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// A number's key: a safe integer spelled out (`42`, `m7` for -7), anything
|
|
682
|
+
// else (decimals, ±Infinity, NaN, -0, huge integers) as `x` + its 64 IEEE-754
|
|
683
|
+
// bits in hex, high word first, NaN canonical. Both forms are exact, and no
|
|
684
|
+
// `String(n)` runs for a decimal (the costly part of a decimal key).
|
|
685
|
+
const numberKey = (n: number) => {
|
|
686
|
+
if (Number.isSafeInteger(n) && !Object.is(n, -0))
|
|
687
|
+
return n >= 0 ? String(n) : `m${String(-n)}`;
|
|
688
|
+
if (n !== n) return 'x7ff8000000000000';
|
|
689
|
+
const lo = lowWord(n);
|
|
690
|
+
return `x${hexWord(highWord())}${hexWord(lo)}`;
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* The key of `value`: `prefix` + a type tag + the value itself for numbers,
|
|
695
|
+
* booleans, null, undefined, bigints and short id-safe strings (exact, so
|
|
696
|
+
* those never collide); + `h` and a 96-bit digest of the exact encoding for
|
|
697
|
+
* everything else.
|
|
698
|
+
*/
|
|
699
|
+
export const hash = (value: unknown, prefix = 'bb'): string => {
|
|
700
|
+
switch (typeof value) {
|
|
701
|
+
case 'number':
|
|
702
|
+
return `${prefix}n${numberKey(value)}`;
|
|
703
|
+
case 'boolean':
|
|
704
|
+
return `${prefix}${value ? 't' : 'f'}`;
|
|
705
|
+
case 'undefined':
|
|
706
|
+
return `${prefix}u`;
|
|
707
|
+
case 'bigint':
|
|
708
|
+
return `${prefix}g${String(value).replace('-', 'm')}`;
|
|
709
|
+
case 'string':
|
|
710
|
+
if (isShortIdSafe(value)) return `${prefix}s${value}`;
|
|
711
|
+
break;
|
|
712
|
+
default:
|
|
713
|
+
if (value === null) return `${prefix}z`;
|
|
714
|
+
}
|
|
715
|
+
return `${prefix}h${digestOf(value)}`;
|
|
716
|
+
};
|
|
167
717
|
|
|
168
718
|
export const isPlainObject = (
|
|
169
719
|
value: unknown
|
|
@@ -716,10 +1266,16 @@ import { shallowRef } from 'vue';
|
|
|
716
1266
|
/**
|
|
717
1267
|
* How arrays sit in the query string, for every helper that reads or writes
|
|
718
1268
|
* it: `tags=a,b`, what Spatie QueryBuilder parses. Change it here, once —
|
|
719
|
-
* a reader and a writer that disagree turn an array into a string.
|
|
1269
|
+
* a reader and a writer that disagree turn an array into a string. Under
|
|
1270
|
+
* `'bracket'` (`tags[]=a&tags[]=b`, what Laravel's `array` rule validates),
|
|
1271
|
+
* Laravel's own indexed `tags[0]=a&tags[1]=b` (in `page.url` and pager
|
|
1272
|
+
* links) reads as the same array, and a write to `tags` replaces either form.
|
|
720
1273
|
*/
|
|
721
1274
|
export const QUERY_ARRAY_FORMAT = 'comma';
|
|
722
1275
|
|
|
1276
|
+
/** A `[]` or `[0]` suffix, raw or percent-encoded: `tags[]`, `tags%5B0%5D`. */
|
|
1277
|
+
const ARRAY_SUFFIX = /(?:\[|%5B)\d*(?:\]|%5D)$/i;
|
|
1278
|
+
|
|
723
1279
|
/** A URL's parts. The first `?` starts the query; a `#` ends it. */
|
|
724
1280
|
export const splitUrl = (url: string) => {
|
|
725
1281
|
const hashAt = url.indexOf('#');
|
|
@@ -776,7 +1332,10 @@ export const withQuery = (
|
|
|
776
1332
|
.split('&')
|
|
777
1333
|
.filter(Boolean)
|
|
778
1334
|
.flatMap((part) => {
|
|
779
|
-
|
|
1335
|
+
// `tags[]` and `tags[0]` are `tags`: a write owns every part of its key.
|
|
1336
|
+
const key = decodeKey(
|
|
1337
|
+
(part.split('=')[0] ?? '').replace(ARRAY_SUFFIX, '')
|
|
1338
|
+
);
|
|
780
1339
|
if (!(key in changes)) return [part];
|
|
781
1340
|
if (written.has(key)) return [];
|
|
782
1341
|
written.add(key);
|
|
@@ -835,10 +1394,19 @@ export const parseQuery = (
|
|
|
835
1394
|
if (!query) return {};
|
|
836
1395
|
// `qs.parse` decodes once. An encoded comma separates too: Laravel's pager
|
|
837
1396
|
// links write `a%2Cb`, which PHP decodes to `a,b` before Spatie splits it.
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1397
|
+
if (arrayFormat === 'comma')
|
|
1398
|
+
return qs.parse(query.replace(/%2C/gi, ','), { arrayFormat });
|
|
1399
|
+
if (arrayFormat !== 'bracket') return qs.parse(query, { arrayFormat });
|
|
1400
|
+
// Laravel's indexed `tags[0]=a&tags[1]=b` reads as `tags[]=a&tags[]=b`.
|
|
1401
|
+
const unindexed = query
|
|
1402
|
+
.split('&')
|
|
1403
|
+
.map((part) => {
|
|
1404
|
+
const at = part.indexOf('=');
|
|
1405
|
+
const key = at < 0 ? part : part.slice(0, at);
|
|
1406
|
+
return key.replace(ARRAY_SUFFIX, '[]') + (at < 0 ? '' : part.slice(at));
|
|
1407
|
+
})
|
|
1408
|
+
.join('&');
|
|
1409
|
+
return qs.parse(unindexed, { arrayFormat });
|
|
842
1410
|
};
|
|
843
1411
|
|
|
844
1412
|
export const useQuery = ({
|
|
@@ -1227,6 +1795,9 @@ results are never hidden on an out-of-range page.
|
|
|
1227
1795
|
|
|
1228
1796
|
Arrays are written in the one `QUERY_ARRAY_FORMAT` of `useQuery.ts` (`comma`:
|
|
1229
1797
|
`tags=a,b`, what Spatie QueryBuilder parses), the same one `useQuery` reads.
|
|
1798
|
+
Set it to `'bracket'` for `tags[]=a&tags[]=b`, what Laravel's `array` rule
|
|
1799
|
+
validates: Laravel's own indexed `tags[0]=a` (in `page.url` and pager links)
|
|
1800
|
+
then reads as the same array, and a write replaces either form.
|
|
1230
1801
|
To send server-shaped keys (`filter[status]`) or reshape values, pass a getter
|
|
1231
1802
|
that builds them: `useQueryObject(() => ({ 'filter[status]': f.status }))`.
|
|
1232
1803
|
|
|
@@ -2631,65 +3202,54 @@ export const usePromiseRouter = (defaults: VisitOptions = {}) => {
|
|
|
2631
3202
|
Deep dirty-checking against a snapshot baseline — for edit screens whose
|
|
2632
3203
|
state is not a single Inertia form (multiple forms, ad-hoc refs). For a
|
|
2633
3204
|
single `usePromiseForm`, prefer the built-in `form.isDirty`. The baseline is
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
3205
|
+
an exact key of each value (the same `hash` bitboss-ui keys rows with), so a
|
|
3206
|
+
cents-only edit (1450 → 1450.5) counts, Dates, Sets, Maps, `undefined` and
|
|
3207
|
+
NaN compare as they are, and a `File` by its name, size, type and date, so
|
|
3208
|
+
picking another file over a picked one counts.
|
|
2637
3209
|
|
|
2638
3210
|
```ts
|
|
2639
3211
|
// inertia-helpers/useHasChanged.ts
|
|
2640
|
-
import {
|
|
2641
|
-
import {
|
|
2642
|
-
import { computed, ref, toValue, type WatchSource } from 'vue';
|
|
3212
|
+
import { hash } from './utils';
|
|
3213
|
+
import { computed, ref, toValue, watch, type WatchSource } from 'vue';
|
|
2643
3214
|
|
|
2644
3215
|
export function useHasChanged<T extends WatchSource<unknown>[]>(
|
|
2645
3216
|
dependencies: T
|
|
2646
3217
|
) {
|
|
2647
3218
|
/*
|
|
2648
|
-
* The baseline is
|
|
2649
|
-
* values a form holds: a JSON round-trip turns a Date into a string, a
|
|
2650
|
-
* Set or Map into `{}`, drops `undefined` (and throws on a bare one),
|
|
2651
|
-
* an untouched form read as changed; `structuredClone` throws on Vue
|
|
2652
|
-
* `
|
|
2653
|
-
*
|
|
2654
|
-
*
|
|
2655
|
-
*
|
|
2656
|
-
* over a picked one counts as a change.
|
|
3219
|
+
* The baseline is an exact KEY (`hash`), not a copy. A copy has to survive
|
|
3220
|
+
* the values a form holds: a JSON round-trip turns a Date into a string, a
|
|
3221
|
+
* File, Set or Map into `{}`, drops `undefined` (and throws on a bare one),
|
|
3222
|
+
* so an untouched form read as changed; `structuredClone` throws on Vue
|
|
3223
|
+
* proxies. `hash` reads straight through a proxy and encodes every value
|
|
3224
|
+
* exactly: numbers to the last bit (2400 is not 2400.5), Dates by time,
|
|
3225
|
+
* Sets / Maps by content, Files by name, size, type and date, `undefined`
|
|
3226
|
+
* and NaN apart.
|
|
2657
3227
|
*/
|
|
2658
|
-
const snapshot = (dep: WatchSource<unknown>) =>
|
|
2659
|
-
hash(withFileFingerprints(toValue(dep)));
|
|
3228
|
+
const snapshot = (dep: WatchSource<unknown>) => hash(toValue(dep));
|
|
2660
3229
|
|
|
2661
|
-
const baselines = ref<
|
|
3230
|
+
const baselines = ref<string[]>(dependencies.map(snapshot));
|
|
2662
3231
|
|
|
2663
3232
|
/** Re-baseline (call after a successful save). */
|
|
2664
3233
|
const takeSnapshot = (): void => {
|
|
2665
3234
|
baselines.value = dependencies.map(snapshot);
|
|
2666
3235
|
};
|
|
2667
3236
|
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
3237
|
+
/*
|
|
3238
|
+
* `hash` reads values raw, so it subscribes to nothing: a deep watch
|
|
3239
|
+
* bumps `edits` on every change, and that is what re-runs `hasChanged`.
|
|
3240
|
+
*/
|
|
3241
|
+
const edits = ref(0);
|
|
3242
|
+
watch(dependencies, () => edits.value++, { deep: true, flush: 'sync' });
|
|
3243
|
+
|
|
3244
|
+
const hasChanged = computed(() => {
|
|
3245
|
+
void edits.value;
|
|
3246
|
+
return dependencies.some(
|
|
3247
|
+
(dep, index) => snapshot(dep) !== baselines.value[index]
|
|
3248
|
+
);
|
|
3249
|
+
});
|
|
2671
3250
|
|
|
2672
3251
|
return { hasChanged, takeSnapshot };
|
|
2673
3252
|
}
|
|
2674
|
-
|
|
2675
|
-
const withFileFingerprints = (value: unknown): unknown =>
|
|
2676
|
-
value instanceof Blob
|
|
2677
|
-
? [
|
|
2678
|
-
value.size,
|
|
2679
|
-
value.type,
|
|
2680
|
-
(value as Partial<File>).name,
|
|
2681
|
-
(value as Partial<File>).lastModified,
|
|
2682
|
-
]
|
|
2683
|
-
: Array.isArray(value)
|
|
2684
|
-
? value.map(withFileFingerprints)
|
|
2685
|
-
: isPlainObject(value)
|
|
2686
|
-
? Object.fromEntries(
|
|
2687
|
-
Object.entries(value).map(([key, item]) => [
|
|
2688
|
-
key,
|
|
2689
|
-
withFileFingerprints(item),
|
|
2690
|
-
])
|
|
2691
|
-
)
|
|
2692
|
-
: value;
|
|
2693
3253
|
```
|
|
2694
3254
|
|
|
2695
3255
|
### useConfirmOnRouteLeave
|