@regle/schemas 1.19.12 → 1.19.13
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/regle-schemas.d.ts
CHANGED
package/dist/regle-schemas.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.19.
|
|
2
|
+
* @regle/schemas v1.19.13
|
|
3
3
|
* (c) 2026 Victor Garcia
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { createScopedUseRegle, useRootStorage } from "@regle/core";
|
|
8
|
-
import { computed, effectScope, getCurrentScope, isRef, nextTick, onScopeDispose, reactive, ref, toValue, unref, watch } from "vue";
|
|
8
|
+
import { computed, effectScope, getCurrentScope, isRef, nextTick, onMounted, onScopeDispose, reactive, ref, toValue, unref, watch } from "vue";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Server side friendly way of checking for a File
|
|
@@ -155,13 +155,21 @@ function cloneDeep(obj, dep = 0) {
|
|
|
155
155
|
/**
|
|
156
156
|
* Converts ref to reactive.
|
|
157
157
|
*
|
|
158
|
-
* @see https://vueuse.org/toReactive
|
|
159
158
|
* @param objectRef A ref of object
|
|
159
|
+
* @param isDisabled A ref to check if the object is disabled
|
|
160
160
|
*/
|
|
161
|
-
function toReactive(objectRef) {
|
|
161
|
+
function toReactive(objectRef, isDisabled) {
|
|
162
162
|
if (!isRef(objectRef)) return reactive(objectRef);
|
|
163
|
+
const firstRun = ref(false);
|
|
164
|
+
onMounted(async () => {
|
|
165
|
+
await nextTick();
|
|
166
|
+
if (typeof window !== "undefined") window.requestAnimationFrame(() => {
|
|
167
|
+
firstRun.value = true;
|
|
168
|
+
});
|
|
169
|
+
});
|
|
163
170
|
return reactive(new Proxy({}, {
|
|
164
171
|
get(_, p, receiver) {
|
|
172
|
+
if (isDisabled.value && p !== `$value` && firstRun.value) return Reflect.get(_, p, receiver);
|
|
165
173
|
if (objectRef.value === void 0) return void 0;
|
|
166
174
|
return unref(Reflect.get(objectRef.value, p, receiver));
|
|
167
175
|
},
|
|
@@ -408,6 +416,7 @@ function createUseRegleSchemaComposable(params) {
|
|
|
408
416
|
unwatchDisabled();
|
|
409
417
|
stopSchemaRuntime();
|
|
410
418
|
});
|
|
419
|
+
const isDisabled = computed(() => toValue(resolvedOptions.disabled) ?? false);
|
|
411
420
|
regle = useRootStorage({
|
|
412
421
|
scopeRules: computed(() => ({})),
|
|
413
422
|
state: processedState,
|
|
@@ -420,7 +429,7 @@ function createUseRegleSchemaComposable(params) {
|
|
|
420
429
|
onValidate,
|
|
421
430
|
overrides
|
|
422
431
|
});
|
|
423
|
-
return { r$: toReactive(regle) };
|
|
432
|
+
return { r$: toReactive(regle, isDisabled) };
|
|
424
433
|
}
|
|
425
434
|
return useRegleSchema;
|
|
426
435
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @regle/schemas v1.19.
|
|
2
|
+
* @regle/schemas v1.19.13
|
|
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,getCurrentScope as i,isRef as a,nextTick as o,
|
|
7
|
+
import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,effectScope as r,getCurrentScope as i,isRef as a,nextTick as o,onMounted as s,onScopeDispose as c,reactive as l,ref as u,toValue as d,unref as f,watch as p}from"vue";function m(e){return e?.constructor?.name==`File`}function h(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function g(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;v(a);for(var o;o=i.shift();)if(v(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],b(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 _(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 v(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function y(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 b(e,t=!0,n=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):m(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:h(e)?e==null?!0:n?Object.keys(e).length===0:!1:!String(e).length}function x(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 S(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=>S(e,t++)))),r==`Map`&&(n=new Map([...e].map(e=>[S(e[0]),S(e[1])]))),r==`Date`&&(n=new Date(e.getTime())),r==`RegExp`&&(n=RegExp(e.source,x(e))),r==`Array`||r==`Object`){n=Array.isArray(e)?[]:{};for(let r in e)n[r]=S(e[r],t++)}return n}function C(e,t){if(!a(e))return l(e);let n=u(!1);return s(async()=>{await o(),typeof window<`u`&&window.requestAnimationFrame(()=>{n.value=!0})}),l(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 f(Reflect.get(e.value,i,a))},set(t,n,r){return a(e.value[n])&&!a(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 w(e){return e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``}function T(e){let t=e.path?.at(-1);return typeof t==`object`?t.key:t}function E(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 D(e,t){let n=w(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(_(t.value,n)),$path:n,lastItemKey:i,lastItem:r}}function O(e,t,n,r=!1){return!r&&n?t.value.length?t.value.reduce((t,n)=>{if(`$currentArrayValue`in n&&h(n.$currentArrayValue)&&`$id`in n.$currentArrayValue){let r=n.$currentArrayValue.$id,i=T(n),a=e.find(e=>e?.$currentArrayValue?.$id===r&&T(e)===i);a&&t.push({...n,path:a?.path??[]})}else e.some(e=>w(e)===w(n))&&t.push(n);return t},[]):[]:e}function k(e,t,n,r=!1){return O(e,t,n,r)?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]}function A({result:e,previousIssues:t,processedState:n,rewardEarly:r,isValidate:i=!1}){let a={},o=e.issues?.map(e=>{let t=E(e);if(t){let r=_(n.value,w(t));Object.defineProperty(e,`$currentArrayValue`,{value:r,enumerable:!0,configurable:!0,writable:!0})}return e}),s=O(o??[],t,r,i);if(o?.length){let e=s.map(e=>{let{isArray:t,$path:r,lastItemKey:i}=D(e,n);return{...e,$path:r,isArray:t,$property:i,$rule:`schema`,$message:e.message}});e.forEach(({isArray:e,$path:t,...n})=>{g(a,t,[n],e)}),t.value=e}else t.value=[];return a}function j(e){let t=a(e)?e:u(e);return{processedState:t,isSingleField:n(()=>!h(t.value)),initialState:u(h(t.value)?{...S(t.value)}:S(t.value)),originalState:h(t.value)?{...S(t.value)}:S(t.value)}}function M({processedState:e,getSchema:t,isSingleField:n,customErrors:r,previousIssues:i,resolvedOptions:a,syncOnUpdate:o,syncOnValidate:s}){let c;function l(){u(),c=p([e,t],()=>{a.silent||t()[`~standard`].vendor!==`regle`&&f()},{deep:!0})}function u(){c?.(),c=void 0}async function f(c=!1){let f=t()[`~standard`].validate(e.value);return f instanceof Promise&&(f=await f),n.value?r.value=k(f.issues??[],i,d(a.rewardEarly),c):r.value=A({result:f,previousIssues:i,processedState:e,rewardEarly:d(a.rewardEarly),isValidate:c}),f.issues||(c&&s||!c&&o)&&(u(),h(e.value)?e.value=y(e.value,f.value):e.value=f.value,l()),f}return{computeErrors:f,defineWatchState:l,stopWatching:u}}function N(e){let{options:a,shortcuts:s,overrides:l}=e??{};function m(e,m,h){if(!f(m)?.[`~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={...a,..._},{processedState:x,isSingleField:S,initialState:w,originalState:T}=j(e),E=u({}),D=u([]),O,k;function A(){return M({processedState:x,getSchema:()=>f(m),isSingleField:S,customErrors:E,previousIssues:D,resolvedOptions:b,syncOnUpdate:v,syncOnValidate:y})}function N(){O?.stop(),O=r(),O.run(()=>{k=A(),k.defineWatchState(),k.computeErrors()})}function P(){k?.stopWatching(),k=void 0,O?.stop(),O=void 0}N();let F=p(()=>d(b.disabled),e=>{e?P():N()});d(b.disabled)&&o().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)}};i()&&c(()=>{F(),P()});let R=n(()=>d(b.disabled)??!1);return I=t({scopeRules:n(()=>({})),state:x,options:b,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:L,overrides:l}),{r$:C(I,R)}}return m}const P=N();function F(e,t){return e}function I(){function e(e,t){return t}return e}const L=I();function R({modifiers:e,shortcuts:t,overrides:n}){return{useRegleSchema:N({options:e,shortcuts:t,overrides:n}),inferSchema:I()}}const z=t=>{let{customStore:n,customUseRegle:r=P,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})},{useCollectScope:B,useScopedRegle:V}=e({customUseRegle:P}),H=B,U=V;export{z as createScopedUseRegleSchema,R as defineRegleSchemaConfig,L as inferSchema,H as useCollectSchemaScope,P as useRegleSchema,U as useScopedRegleSchema,F as withDeps};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/schemas",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.13",
|
|
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.4.4",
|
|
40
|
-
"@regle/core": "1.19.
|
|
41
|
-
"@regle/rules": "1.19.
|
|
40
|
+
"@regle/core": "1.19.13",
|
|
41
|
+
"@regle/rules": "1.19.13"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@total-typescript/ts-reset": "0.6.1",
|