@regle/schemas 1.21.7 → 1.22.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/schemas v1.21.7
2
+ * @regle/schemas v1.22.0
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/schemas v1.21.7
2
+ * @regle/schemas v1.22.0
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -152,9 +152,13 @@ function cloneDeep(obj, dep = 0) {
152
152
  *
153
153
  * @param objectRef A ref of object
154
154
  * @param isDisabled A ref to check if the object is disabled
155
+ * @param onAccess A callback called before each proxy operation
155
156
  */
156
- function toReactive(objectRef, isDisabled) {
157
- if (!isRef(objectRef)) return reactive(objectRef);
157
+ function toReactive(objectRef, isDisabled, onAccess) {
158
+ if (!isRef(objectRef)) {
159
+ onAccess?.();
160
+ return reactive(objectRef);
161
+ }
158
162
  const firstRun = ref(false);
159
163
  if (getCurrentInstance()) onMounted(async () => {
160
164
  await nextTick();
@@ -164,27 +168,33 @@ function toReactive(objectRef, isDisabled) {
164
168
  });
165
169
  return reactive(new Proxy({}, {
166
170
  get(_, p, receiver) {
171
+ onAccess?.();
167
172
  if (isDisabled.value && p !== `$value` && firstRun.value) return Reflect.get(_, p, receiver);
168
173
  if (objectRef.value === void 0) return void 0;
169
174
  return unref(Reflect.get(objectRef.value, p, receiver));
170
175
  },
171
176
  set(_, p, value) {
177
+ onAccess?.();
172
178
  if (isRef(objectRef.value[p]) && !isRef(value)) objectRef.value[p].value = value;
173
179
  else objectRef.value[p] = value;
174
180
  return true;
175
181
  },
176
182
  deleteProperty(_, p) {
183
+ onAccess?.();
177
184
  return Reflect.deleteProperty(objectRef.value, p);
178
185
  },
179
186
  has(_, p) {
187
+ onAccess?.();
180
188
  if (objectRef.value === void 0) return false;
181
189
  return Reflect.has(objectRef.value, p);
182
190
  },
183
191
  ownKeys() {
192
+ onAccess?.();
184
193
  if (objectRef.value === void 0) return [];
185
194
  return Object.keys(objectRef.value);
186
195
  },
187
196
  getOwnPropertyDescriptor() {
197
+ onAccess?.();
188
198
  return {
189
199
  enumerable: true,
190
200
  configurable: true
@@ -350,8 +360,11 @@ function createUseRegleSchemaComposable(params) {
350
360
  const { processedState, isSingleField, initialState, originalState } = createSchemaState(state);
351
361
  const customErrors = ref({});
352
362
  const previousIssues = ref([]);
363
+ const attachedScopes = /* @__PURE__ */ new Set();
364
+ let isSchemaRuntimeEnabled = false;
353
365
  let schemaScope;
354
366
  let runner;
367
+ let unwatchDisabled;
355
368
  function createRunner() {
356
369
  return createSchemaValidationRunner({
357
370
  processedState,
@@ -379,34 +392,52 @@ function createUseRegleSchemaComposable(params) {
379
392
  schemaScope?.stop();
380
393
  schemaScope = void 0;
381
394
  }
382
- startSchemaRuntime();
383
- const unwatchDisabled = watch(() => toValue(resolvedOptions.disabled), (disabled) => {
384
- if (disabled) stopSchemaRuntime();
385
- else startSchemaRuntime();
386
- });
387
- if (toValue(resolvedOptions.disabled)) nextTick().then(() => {
395
+ function startManagedSchemaRuntime() {
396
+ if (isSchemaRuntimeEnabled) return;
397
+ isSchemaRuntimeEnabled = true;
398
+ startSchemaRuntime();
399
+ unwatchDisabled = watch(() => toValue(resolvedOptions.disabled), (disabled) => {
400
+ if (disabled) stopSchemaRuntime();
401
+ else startSchemaRuntime();
402
+ });
403
+ if (toValue(resolvedOptions.disabled)) nextTick().then(() => {
404
+ stopSchemaRuntime();
405
+ });
406
+ }
407
+ function stopManagedSchemaRuntime() {
408
+ if (!isSchemaRuntimeEnabled) return;
409
+ isSchemaRuntimeEnabled = false;
410
+ unwatchDisabled?.();
411
+ unwatchDisabled = void 0;
388
412
  stopSchemaRuntime();
389
- });
413
+ }
390
414
  let regle;
391
415
  const onValidate = async () => {
392
416
  try {
393
417
  const result = await (runner ?? createRunner()).computeErrors(true);
394
- regle?.value?.$touch();
418
+ regle?.regle.value?.$touch();
395
419
  return {
396
420
  valid: !result.issues?.length,
397
421
  data: processedState.value,
398
- errors: regle?.value?.$errors,
422
+ errors: regle?.regle.value?.$errors,
399
423
  issues: customErrors.value
400
424
  };
401
425
  } catch (e) {
402
426
  return Promise.reject(e);
403
427
  }
404
428
  };
405
- if (getCurrentScope()) onScopeDispose(() => {
406
- unwatchDisabled();
407
- stopSchemaRuntime();
408
- });
429
+ function bindSchemaToCurrentScope() {
430
+ const currentScope = getCurrentScope();
431
+ if (!currentScope || attachedScopes.has(currentScope)) return;
432
+ if (!isSchemaRuntimeEnabled) startManagedSchemaRuntime();
433
+ attachedScopes.add(currentScope);
434
+ onScopeDispose(() => {
435
+ attachedScopes.delete(currentScope);
436
+ if (!attachedScopes.size) stopManagedSchemaRuntime();
437
+ });
438
+ }
409
439
  const isDisabled = computed(() => toValue(resolvedOptions.disabled) ?? false);
440
+ startManagedSchemaRuntime();
410
441
  regle = useRootStorage({
411
442
  scopeRules: computed(() => ({})),
412
443
  state: processedState,
@@ -419,7 +450,11 @@ function createUseRegleSchemaComposable(params) {
419
450
  onValidate,
420
451
  overrides
421
452
  });
422
- return { r$: toReactive(regle, isDisabled) };
453
+ bindSchemaToCurrentScope();
454
+ return { r$: toReactive(regle.regle, isDisabled, () => {
455
+ bindSchemaToCurrentScope();
456
+ regle?.bindToCurrentScope();
457
+ }) };
423
458
  }
424
459
  return useRegleSchema;
425
460
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @regle/schemas v1.21.7
2
+ * @regle/schemas v1.22.0
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
6
6
 
7
- import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,effectScope as r,getCurrentInstance as i,getCurrentScope as a,isRef as o,nextTick as s,onMounted as c,onScopeDispose as l,reactive as u,ref as d,toValue as f,unref as p,watch as m}from"vue";function h(e){return e?.constructor?.name==`File`}function g(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;y(a);for(var o;o=i.shift();)if(y(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],x(e.$each[o])&&(e.$each[o]={}),e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={$self:n}:isNaN(parseInt(a))?Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n:(e.$each??=[],e.$each[a]=(e.$each[a]??=[]).concat(n)),!0}function v(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function y(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function b(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function x(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):h(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:g(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function S(e){let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}function C(e,t=0){if(t>20)return e;let n=e,r={}.toString.call(e).slice(8,-1);if(r==`Set`&&(n=new Set([...e].map(e=>C(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[C(e[0]),C(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,S(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=C(e[r],t++)}return n}function w(e,t){if(!o(e))return u(e);let n=d(!1);return i()&&c(async()=>{await s(),typeof window<`u`&&window.requestAnimationFrame(()=>{n.value=!0})}),u(new Proxy({},{get(r,i,a){if(t.value&&i!==`$value`&&n.value)return Reflect.get(r,i,a);if(e.value!==void 0)return p(Reflect.get(e.value,i,a))},set(t,n,r){return o(e.value[n])&&!o(r)?e.value[n].value=r:e.value[n]=r,!0},deleteProperty(t,n){return Reflect.deleteProperty(e.value,n)},has(t,n){return e.value===void 0?!1:Reflect.has(e.value,n)},ownKeys(){return e.value===void 0?[]:Object.keys(e.value)},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}}}))}function T(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function E(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function D(e){let t=e.path?.at(-1),n=typeof t==`object`?typeof t.key==`string`:typeof t==`string`,r=e.path?.findLastIndex(e=>typeof e==`object`?typeof e.key==`number`:typeof e==`number`);if(!(!n&&r===-1)&&r!=null){let t=e.path?.slice(0,r+1);return{...e,path:t}}}function O(e,t){let n=T(e),r=e.path?.[e.path.length-1],i=typeof r==`object`?r.key:r;return{isArray:(typeof r==`object`&&`value`in r?Array.isArray(r.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(v(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function k(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&g(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=E(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&E(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>T(e)===T(n))&&t.push(n);return t},[]):[]:e}function A(e,t,n,r=!1){return k(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function j({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=D(e);if(t){let r=v(n.value,T(t));Object.defineProperty(e,`$currentArrayValue`,{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=k(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=O(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{_(a,t,[n],e)}),t.value=e}else t.value=[];return a}function M(e){let t=o(e)?e:d(e);return{processedState:t,isSingleField:n(()=>!g(t.value)),initialState:d(g(t.value)?{...C(t.value)}:C(t.value)),originalState:g(t.value)?{...C(t.value)}:C(t.value)}}function N({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=m([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&d()},{deep:!0})}function u(){c?.(),c=void 0}async function d(c=!1){let d=t()[`~standard`].validate(e.value);return d instanceof Promise&&(d=await d),n.value?r.value=A(d.issues??[],i,f(a.rewardEarly),c):r.value=j({result:d,previousIssues:i,processedState:e,rewardEarly:f(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),g(e.value)?e.value=b(e.value,d.value):e.value=d.value,l()),d}return{computeErrors:d,defineWatchState:l,stopWatching:u}}function P(e){let{options:i,shortcuts:o,overrides:c}=e??{};function u(e,u,h){if(!p(u)?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);let{syncState:g={onUpdate:!1,onValidate:!1},..._}=h??{},{onUpdate:v=!1,onValidate:y=!1}=g,b={...i,..._},{processedState:x,isSingleField:S,initialState:C,originalState:T}=M(e),E=d({}),D=d([]),O,k;function A(){return N({processedState:x,getSchema:()=>p(u),isSingleField:S,customErrors:E,previousIssues:D,resolvedOptions:b,syncOnUpdate:v,syncOnValidate:y})}function j(){O?.stop(),O=r(),O.run(()=>{k=A(),k.defineWatchState(),k.computeErrors()})}function P(){k?.stopWatching(),k=void 0,O?.stop(),O=void 0}j();let F=m(()=>f(b.disabled),e=>{e?P():j()});f(b.disabled)&&s().then(()=>{P()});let I,L=async()=>{try{let e=await(k??A()).computeErrors(!0);return I?.value?.$touch(),{valid:!e.issues?.length,data:x.value,errors:I?.value?.$errors,issues:E.value}}catch(e){return Promise.reject(e)}};a()&&l(()=>{F(),P()});let R=n(()=>f(b.disabled)??!1);return I=t({scopeRules:n(()=>({})),state:x,options:b,schemaErrors:E,initialState:C,originalState:T,shortcuts:o,schemaMode:!0,onValidate:L,overrides:c}),{r$:w(I,R)}}return u}const F=P();function I(e,t){return e}function L(){function e(e,t){return t}return e}const R=L();function z({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:P({options:e,shortcuts:t,overrides:n}),inferSchema:L()}}const B=t=>{let{customStore:n,customUseRegle:r=F,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:V,useScopedRegle:H}=e({customUseRegle:F}),U=V,W=H;export{B as createScopedUseRegleSchema,z as defineRegleSchemaConfig,R as inferSchema,U as useCollectSchemaScope,F as useRegleSchema,W as useScopedRegleSchema,I as withDeps};
7
+ import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,effectScope as r,getCurrentInstance as i,getCurrentScope as a,isRef as o,nextTick as s,onMounted as c,onScopeDispose as l,reactive as u,ref as d,toValue as f,unref as p,watch as m}from"vue";function h(e){return e?.constructor?.name==`File`}function g(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;y(a);for(var o;o=i.shift();)if(y(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],x(e.$each[o])&&(e.$each[o]={}),e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={$self:n}:isNaN(parseInt(a))?Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n:(e.$each??=[],e.$each[a]=(e.$each[a]??=[]).concat(n)),!0}function v(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function y(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function b(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function x(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):h(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:g(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function S(e){let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}function C(e,t=0){if(t>20)return e;let n=e,r={}.toString.call(e).slice(8,-1);if(r==`Set`&&(n=new Set([...e].map(e=>C(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[C(e[0]),C(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,S(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=C(e[r],t++)}return n}function w(e,t,n){if(!o(e))return n?.(),u(e);let r=d(!1);return i()&&c(async()=>{await s(),typeof window<`u`&&window.requestAnimationFrame(()=>{r.value=!0})}),u(new Proxy({},{get(i,a,o){if(n?.(),t.value&&a!==`$value`&&r.value)return Reflect.get(i,a,o);if(e.value!==void 0)return p(Reflect.get(e.value,a,o))},set(t,r,i){return n?.(),o(e.value[r])&&!o(i)?e.value[r].value=i:e.value[r]=i,!0},deleteProperty(t,r){return n?.(),Reflect.deleteProperty(e.value,r)},has(t,r){return n?.(),e.value===void 0?!1:Reflect.has(e.value,r)},ownKeys(){return n?.(),e.value===void 0?[]:Object.keys(e.value)},getOwnPropertyDescriptor(){return n?.(),{enumerable:!0,configurable:!0}}}))}function T(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function E(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function D(e){let t=e.path?.at(-1),n=typeof t==`object`?typeof t.key==`string`:typeof t==`string`,r=e.path?.findLastIndex(e=>typeof e==`object`?typeof e.key==`number`:typeof e==`number`);if(!(!n&&r===-1)&&r!=null){let t=e.path?.slice(0,r+1);return{...e,path:t}}}function O(e,t){let n=T(e),r=e.path?.[e.path.length-1],i=typeof r==`object`?r.key:r;return{isArray:(typeof r==`object`&&`value`in r?Array.isArray(r.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(v(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function k(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&g(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=E(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&E(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>T(e)===T(n))&&t.push(n);return t},[]):[]:e}function A(e,t,n,r=!1){return k(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function j({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=D(e);if(t){let r=v(n.value,T(t));Object.defineProperty(e,`$currentArrayValue`,{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=k(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=O(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{_(a,t,[n],e)}),t.value=e}else t.value=[];return a}function M(e){let t=o(e)?e:d(e);return{processedState:t,isSingleField:n(()=>!g(t.value)),initialState:d(g(t.value)?{...C(t.value)}:C(t.value)),originalState:g(t.value)?{...C(t.value)}:C(t.value)}}function N({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=m([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&d()},{deep:!0})}function u(){c?.(),c=void 0}async function d(c=!1){let d=t()[`~standard`].validate(e.value);return d instanceof Promise&&(d=await d),n.value?r.value=A(d.issues??[],i,f(a.rewardEarly),c):r.value=j({result:d,previousIssues:i,processedState:e,rewardEarly:f(a.rewardEarly),isValidate:c}),d.issues||(c&&s||!c&&o)&&(u(),g(e.value)?e.value=b(e.value,d.value):e.value=d.value,l()),d}return{computeErrors:d,defineWatchState:l,stopWatching:u}}function P(e){let{options:i,shortcuts:o,overrides:c}=e??{};function u(e,u,h){if(!p(u)?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);let{syncState:g={onUpdate:!1,onValidate:!1},..._}=h??{},{onUpdate:v=!1,onValidate:y=!1}=g,b={...i,..._},{processedState:x,isSingleField:S,initialState:C,originalState:T}=M(e),E=d({}),D=d([]),O=new Set,k=!1,A,j,P;function F(){return N({processedState:x,getSchema:()=>p(u),isSingleField:S,customErrors:E,previousIssues:D,resolvedOptions:b,syncOnUpdate:v,syncOnValidate:y})}function I(){A?.stop(),A=r(),A.run(()=>{j=F(),j.defineWatchState(),j.computeErrors()})}function L(){j?.stopWatching(),j=void 0,A?.stop(),A=void 0}function R(){k||(k=!0,I(),P=m(()=>f(b.disabled),e=>{e?L():I()}),f(b.disabled)&&s().then(()=>{L()}))}function z(){k&&(k=!1,P?.(),P=void 0,L())}let B,V=async()=>{try{let e=await(j??F()).computeErrors(!0);return B?.regle.value?.$touch(),{valid:!e.issues?.length,data:x.value,errors:B?.regle.value?.$errors,issues:E.value}}catch(e){return Promise.reject(e)}};function H(){let e=a();!e||O.has(e)||(k||R(),O.add(e),l(()=>{O.delete(e),O.size||z()}))}let U=n(()=>f(b.disabled)??!1);return R(),B=t({scopeRules:n(()=>({})),state:x,options:b,schemaErrors:E,initialState:C,originalState:T,shortcuts:o,schemaMode:!0,onValidate:V,overrides:c}),H(),{r$:w(B.regle,U,()=>{H(),B?.bindToCurrentScope()})}}return u}const F=P();function I(e,t){return e}function L(){function e(e,t){return t}return e}const R=L();function z({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:P({options:e,shortcuts:t,overrides:n}),inferSchema:L()}}const B=t=>{let{customStore:n,customUseRegle:r=F,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:V,useScopedRegle:H}=e({customUseRegle:F}),U=V,W=H;export{B as createScopedUseRegleSchema,z as defineRegleSchemaConfig,R as inferSchema,U as useCollectSchemaScope,F as useRegleSchema,W as useScopedRegleSchema,I as withDeps};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.21.7",
3
+ "version": "1.22.0",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "homepage": "https://reglejs.dev/",
6
6
  "license": "MIT",
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@standard-schema/spec": "1.1.0",
39
39
  "type-fest": "5.5.0",
40
- "@regle/rules": "1.21.7",
41
- "@regle/core": "1.21.7"
40
+ "@regle/core": "1.22.0",
41
+ "@regle/rules": "1.22.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@total-typescript/ts-reset": "0.6.1",