seitu 0.13.0 → 0.14.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/core.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { S as createSubscription, _ as Readable, a as Store, b as Writable, c as SchemaStoreOptions, d as createDebouncedFn, f as Debounced, g as Clearable, h as createComputed, i as createThrottled, l as createSchemaStore, m as Computed, n as createThrottledFn, o as createStore, p as createDebounced, r as Throttled, s as SchemaStore, t as ThrottledFn, u as DebouncedFn, v as Subscribable, x as createReadableSubscription, y as SubscribeOptions } from "./index-ChvHgGIa.mjs";
1
+ import { S as createSubscription, _ as Readable, a as Store, b as Writable, c as SchemaStoreOptions, d as createDebouncedFn, f as Debounced, g as Clearable, h as createComputed, i as createThrottled, l as createSchemaStore, m as Computed, n as createThrottledFn, o as createStore, p as createDebounced, r as Throttled, s as SchemaStore, t as ThrottledFn, u as DebouncedFn, v as Subscribable, x as createReadableSubscription, y as SubscribeOptions } from "./index-Dzu3WPwr.mjs";
2
2
  export { Clearable, Computed, Debounced, DebouncedFn, Readable, SchemaStore, SchemaStoreOptions, Store, Subscribable, SubscribeOptions, Throttled, ThrottledFn, Writable, createComputed, createDebounced, createDebouncedFn, createReadableSubscription, createSchemaStore, createStore, createSubscription, createThrottled, createThrottledFn };
@@ -1,4 +1,4 @@
1
- import { i as StandardSchemaV1, r as ValidationSchemaOutput, t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { i as StandardSchemaV1, r as ValidationSchemaOutput, t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
2
2
 
3
3
  //#region src/core/subscription.d.ts
4
4
  interface SubscribeOptions {
package/dist/react.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Readable, v as Subscribable } from "./index-ChvHgGIa.mjs";
1
+ import { _ as Readable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
2
  import * as React$1 from "react";
3
3
 
4
4
  //#region src/react/hooks.d.ts
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
2
2
 
3
3
  //#region src/utils/validation.d.ts
4
4
  /**
package/dist/utils.mjs CHANGED
@@ -1,32 +1,2 @@
1
- //#region src/utils/validation.ts
2
- /**
3
- * Repair broken web storage value object if value was object but not all keys are in the default value object.
4
- *
5
- * @returns A new object with the existing keys in the value object that are not in the default value object.
6
- *
7
- * @example
8
- * ```ts
9
- * import { createWebStorageValue } from 'seitu/web'
10
- * import { repairValueObjectWithDefault } from 'seitu/utils'
11
- * import * as z from 'zod'
12
- *
13
- * const value = createWebStorageValue({
14
- * type: 'localStorage',
15
- * schema: z.object({ a: z.number(), b: z.string() }),
16
- * key: 'storage-key',
17
- * defaultValue: { a: 0, b: 'default' },
18
- * onValidationError: repairValueObjectWithDefault,
19
- * })
20
- * value.get() // { a: 0, b: 'default' }
21
- * window.localStorage.setItem('storage-key', JSON.stringify({ a: 1 }))
22
- * value.get() // { a: 1, b: 'default' }
23
- * ```
24
- */
25
- function repairValueObjectWithDefault(props) {
26
- return {
27
- ...props.defaultValue,
28
- ...typeof props.value === "object" && props.value !== null ? Object.fromEntries(Object.entries(props.value).filter(([key, val]) => key in props.defaultValue && typeof val === typeof props.defaultValue[key])) : {}
29
- };
30
- }
31
- //#endregion
1
+ import { t as repairValueObjectWithDefault } from "./validation-B8XxyKZ0.mjs";
32
2
  export { repairValueObjectWithDefault };
@@ -0,0 +1,32 @@
1
+ //#region src/utils/validation.ts
2
+ /**
3
+ * Repair broken web storage value object if value was object but not all keys are in the default value object.
4
+ *
5
+ * @returns A new object with the existing keys in the value object that are not in the default value object.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createWebStorageValue } from 'seitu/web'
10
+ * import { repairValueObjectWithDefault } from 'seitu/utils'
11
+ * import * as z from 'zod'
12
+ *
13
+ * const value = createWebStorageValue({
14
+ * type: 'localStorage',
15
+ * schema: z.object({ a: z.number(), b: z.string() }),
16
+ * key: 'storage-key',
17
+ * defaultValue: { a: 0, b: 'default' },
18
+ * onValidationError: repairValueObjectWithDefault,
19
+ * })
20
+ * value.get() // { a: 0, b: 'default' }
21
+ * window.localStorage.setItem('storage-key', JSON.stringify({ a: 1 }))
22
+ * value.get() // { a: 1, b: 'default' }
23
+ * ```
24
+ */
25
+ function repairValueObjectWithDefault(props) {
26
+ return {
27
+ ...props.defaultValue,
28
+ ...typeof props.value === "object" && props.value !== null ? Object.fromEntries(Object.entries(props.value).filter(([key, val]) => key in props.defaultValue && typeof val === typeof props.defaultValue[key])) : {}
29
+ };
30
+ }
31
+ //#endregion
32
+ export { repairValueObjectWithDefault as t };
package/dist/vue.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as Readable, v as Subscribable } from "./index-ChvHgGIa.mjs";
1
+ import { _ as Readable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
2
  import { MaybeRefOrGetter, ShallowRef } from "vue";
3
3
 
4
4
  //#region src/vue/composables.d.ts
package/dist/web.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { _ as Readable, b as Writable, g as Clearable, v as Subscribable } from "./index-ChvHgGIa.mjs";
2
- import { i as StandardSchemaV1, n as ValidationSchemaObjectErrorProps, t as ValidationSchemaErrorProps } from "./validate-BzLxGOQt.mjs";
1
+ import { _ as Readable, b as Writable, g as Clearable, v as Subscribable } from "./index-Dzu3WPwr.mjs";
2
+ import { i as StandardSchemaV1, n as ValidationSchemaObjectErrorProps, t as ValidationSchemaErrorProps } from "./validate-IWiN_jFZ.mjs";
3
3
 
4
4
  //#region src/web/is-online.d.ts
5
5
  interface IsOnline extends Subscribable<boolean>, Readable<boolean> {}
package/dist/web.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { a as validateSchema, d as createSubscription, o as tryParseJson, u as createReadableSubscription } from "./core-BKImMfak.mjs";
2
+ import { t as repairValueObjectWithDefault } from "./validation-B8XxyKZ0.mjs";
2
3
  //#region src/web/is-online.ts
3
4
  /**
4
5
  * Creates a reactive handle for browser online status.
@@ -378,6 +379,7 @@ function createWebStorage(options) {
378
379
  function createWebStorageValue(options) {
379
380
  const type = "storage" in options ? options.storage["~"].type : options.type;
380
381
  const defaultValue = ("schema" in options ? options.defaultValue : options.storage["~"].getDefaultValue(options.key)) ?? null;
382
+ const isDefaultValueObject = typeof defaultValue === "object" && defaultValue !== null;
381
383
  const { subscribe, notify } = createSubscription({ onFirstSubscribe: () => {
382
384
  const listener = (event) => {
383
385
  if (event.key === options.key) notify();
@@ -404,11 +406,25 @@ function createWebStorageValue(options) {
404
406
  cachedValue = validateSchema(options.schema, parsed, {
405
407
  defaultValue,
406
408
  label: `createWebStorageValue:${options.key}`,
407
- onError: options.onValidationError ? (issues, parsed) => options.onValidationError({
408
- defaultValue,
409
- issues: [...issues],
410
- value: parsed
411
- }) : void 0
409
+ onError: options.onValidationError ? (issues, parsed) => {
410
+ const toReturn = options.onValidationError({
411
+ defaultValue,
412
+ issues: [...issues],
413
+ value: parsed
414
+ });
415
+ if (toReturn === void 0 && isDefaultValueObject) return repairValueObjectWithDefault({
416
+ defaultValue,
417
+ issues: [...issues],
418
+ value: parsed
419
+ });
420
+ return toReturn;
421
+ } : (issues, parsed) => {
422
+ if (isDefaultValueObject) return repairValueObjectWithDefault({
423
+ defaultValue,
424
+ issues: [...issues],
425
+ value: parsed
426
+ });
427
+ }
412
428
  });
413
429
  return cachedValue;
414
430
  } else {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seitu",
3
3
  "displayName": "Seitu",
4
4
  "type": "module",
5
- "version": "0.13.0",
5
+ "version": "0.14.0",
6
6
  "private": false,
7
7
  "author": "Valerii Strilets",
8
8
  "license": "MIT",
@@ -78,14 +78,14 @@
78
78
  "@testing-library/react": "^16.3.2",
79
79
  "@types/react": "^19.2.14",
80
80
  "happy-dom": "^20.9.0",
81
- "react-dom": "^19.2.5",
82
- "tsdown": "^0.21.10",
81
+ "react-dom": "^19.2.6",
82
+ "tsdown": "^0.22.0",
83
83
  "type-fest": "^5.6.0",
84
84
  "typescript": "^6.0.3",
85
- "vite": "^8.0.10",
86
- "vitest": "^4.1.5",
87
- "vue": "^3.5.33",
88
- "zod": "^4.4.1"
85
+ "vite": "^8.0.13",
86
+ "vitest": "^4.1.6",
87
+ "vue": "^3.5.34",
88
+ "zod": "^4.4.3"
89
89
  },
90
90
  "scripts": {
91
91
  "build": "tsdown",