@remoteoss/json-schema-form 1.0.0-dev.20250305202108 → 1.0.0-dev.20250305204935

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,2 +1,2 @@
1
1
  function P(e){let{fields:t,order:n}=e,r={};return n.forEach((o,a)=>{r[o]=a}),t.sort((o,a)=>{let u=r[o.name]??1/0,f=r[a.name]??1/0;return u!==f?u-f:t.indexOf(o)-t.indexOf(a)})}function b(e){let{schema:t,fields:n}=e;if(typeof t=="boolean")throw new Error("Schema must be an object");return t["x-jsf-order"]!==void 0?P({fields:n,order:t["x-jsf-order"]}):n}function _(e){return Array.isArray(e.type)?"select":e.type!==void 0?e.type:"text"}function E(e){return e.filter(t=>t!==null&&typeof t=="object").map(t=>{let n=t.title,r=t.const,o=t["x-jsf-presentation"]?.meta,a={label:n||"",value:r};o&&(a.meta=o);let{title:u,const:f,"x-jsf-presentation":c,...S}=t;return{...a,...S}})}function U(e){return e.oneOf?E(e.oneOf||[]):e.items?.anyOf?E(e.items.anyOf):e.anyOf?E(e.anyOf):null}var L=["title","type","x-jsf-errorMessage","x-jsf-presentation","oneOf","anyOf","items"];function x(e,t,n=!1){if(typeof e=="boolean")return null;if(e.type==="object"){let f={...e,type:"object"};return y(f,t,n)}if(e.type==="array")throw new TypeError("Array type is not yet supported");let r=e["x-jsf-presentation"]||{},i=e["x-jsf-errorMessage"],o=r.inputType||"text",a={...Object.entries(e).filter(([f])=>!L.includes(f)).reduce((f,[c,S])=>({...f,[c]:S}),{}),type:o,name:t,inputType:o,jsonType:_(e),required:n,isVisible:!0,...i&&{errorMessage:i}};e.title&&(a.label=e.title),Object.keys(r).length>0&&Object.entries(r).forEach(([f,c])=>{f!=="inputType"&&(a[f]=c)});let u=U(e);return u&&(a.options=u),a}function y(e,t,n){let r=[];for(let a in e.properties){let u=e.required?.includes(a)||!1,f=x(e.properties[a],a,u);f&&r.push(f)}let i=b({fields:r,schema:e}),o={...e["x-jsf-presentation"],type:e["x-jsf-presentation"]?.inputType||"fieldset",inputType:e["x-jsf-presentation"]?.inputType||"fieldset",jsonType:"object",name:e.title||t,required:n,fields:i,isVisible:!0};return e.title!==void 0&&(o.label=e.title),e["x-jsf-presentation"]?.accept&&(o.accept=e["x-jsf-presentation"]?.accept),o}function V(e,t,n=[]){if(!t.allOf||!Array.isArray(t.allOf))return[];for(let r of t.allOf){let i=m(e,r,!1,n);if(i.length>0)return i}return[]}function h(e,t,n=[]){if(!t.anyOf||!Array.isArray(t.anyOf))return[];for(let r of t.anyOf)if(m(e,r,!1,n).length===0)return[];return[{path:n,validation:"anyOf",message:"should match at least one schema"}]}function T(e,t,n=[]){if(!t.oneOf||!Array.isArray(t.oneOf))return[];let r=0;for(let i=0;i<t.oneOf.length&&!(m(e,t.oneOf[i],!1,n).length===0&&(r++,r>1));i++);return r===0?[{path:n,validation:"oneOf",message:"should match exactly one schema"}]:r>1?[{path:n,validation:"oneOf",message:"should match exactly one schema but matches multiple"}]:[]}function I(e,t,n=[]){return t.not===void 0?[]:typeof t.not=="boolean"?t.not?[{path:n,validation:"not",message:"should NOT be valid against schema"}]:[]:m(e,t.not,!1,n).length===0?[{path:n,validation:"not",message:"should NOT be valid against schema"}]:[]}function O(e,t,n,r){if(t.if===void 0)return[];let i=m(e,t.if,n,r).length===0;return i&&t.then!==void 0?m(e,t.then,n,[...r,"then"]):!i&&t.else!==void 0?m(e,t.else,n,[...r,"else"]):[]}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function d(e,t){if(typeof e!=typeof t)return!1;if(e===t)return!0;if(e===null||t===null)return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((n,r)=>d(n,t[r]));if(g(e)&&g(t)){let n=Object.keys(e).sort(),r=Object.keys(t).sort();return n.length!==r.length||!d(n,r)?!1:n.every(i=>d(e[i],t[i]))}return!1}function R(e,t,n=[]){return t.const===void 0?[]:d(t.const,e)?[]:[{path:n,validation:"const",message:`must be equal to ${JSON.stringify(t.const)}`}]}function N(e,t,n=[]){return t.enum===void 0?[]:t.enum.some(r=>d(r,e))?[]:[{path:n,validation:"enum",message:`must be one of ${JSON.stringify(t.enum)}`}]}function v(e,t,n=[]){let r=[],i=p(t);return typeof e!="number"?[]:i!==void 0&&!["number","integer"].includes(i)?[]:(t.multipleOf!==void 0&&e%t.multipleOf!==0&&r.push({path:n,validation:"multipleOf",message:`must be a multiple of ${t.multipleOf}`}),t.maximum!==void 0&&e>t.maximum&&r.push({path:n,validation:"maximum",message:`must be less than or equal to ${t.maximum}`}),t.exclusiveMaximum!==void 0&&e>=t.exclusiveMaximum&&r.push({path:n,validation:"exclusiveMaximum",message:`must be less than ${t.exclusiveMaximum}`}),t.minimum!==void 0&&e<t.minimum&&r.push({path:n,validation:"minimum",message:`must be greater than or equal to ${t.minimum}`}),t.exclusiveMinimum!==void 0&&e<=t.exclusiveMinimum&&r.push({path:n,validation:"exclusiveMinimum",message:`must be greater than ${t.exclusiveMinimum}`}),r)}function J(e,t,n=[]){if(typeof t=="object"&&t.properties&&g(e)){let r=[];for(let[i,o]of Object.entries(t.properties)){let a=e[i],u=t.required?.includes(i),f=m(a,o,u,[...n,i]);r.push(...f)}return r}return[]}var j;(function(e){e["7bit"]="7bit",e["8bit"]="8bit",e.Base64="base64",e.Binary="binary",e.IETFToken="ietf-token",e.QuotedPrintable="quoted-printable",e.XToken="x-token"})(j||(j={}));var s;(function(e){e.Date="date",e.DateTime="date-time",e.Duration="duration",e.Email="email",e.Hostname="hostname",e.IDNEmail="idn-email",e.IDNHostname="idn-hostname",e.IPv4="ipv4",e.IPv6="ipv6",e.IRI="iri",e.IRIReference="iri-reference",e.JSONPointer="json-pointer",e.JSONPointerURIFragment="json-pointer-uri-fragment",e.RegEx="regex",e.RelativeJSONPointer="relative-json-pointer",e.Time="time",e.URI="uri",e.URIReference="uri-reference",e.URITemplate="uri-template",e.UUID="uuid"})(s||(s={}));var A;(function(e){e.Array="array",e.Boolean="boolean",e.Integer="integer",e.Null="null",e.Number="number",e.Object="object",e.String="string"})(A||(A={}));var l={DATE_TIME:/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/,DATE:/^\d{4}-\d{2}-\d{2}$/,TIME:/^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/,DURATION:/^P(?!$)(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$/,EMAIL:/^[\w.!#$%&'*+/=?^`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,IDN_EMAIL:/^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/,HOSTNAME:/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,IDN_HOSTNAME:/^[^\s._-].*[^\s._-]$/,IPV6_PART:/^[0-9a-f]{1,4}$/i,PROTOCOL:/^[a-z]+:/,URI_REFERENCE:/^\S*$/,UUID:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,JSON_POINTER:/^(?:\/(?:[^~/]|~0|~1)*)*$/,JSON_POINTER_URI_FRAGMENT:/^#(?:\/(?:[\w\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,RELATIVE_JSON_POINTER:/^(?:0|[1-9]\d*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,URI_TEMPLATE:/^(?:[!#$&'()*+,/:;=?@\w\-.~]|%[0-9a-f]{2}|\{[+#./;?&=,!@|]?(?:\w|%[0-9a-f]{2})+(?::[1-9]\d{0,3}|\*)?(?:,(?:\w|%[0-9a-f]{2})+(?::[1-9]\d{0,3}|\*)?)*\})*$/i},D={[s.DateTime]:e=>l.DATE_TIME.test(e),[s.Date]:e=>l.DATE.test(e),[s.Time]:e=>l.TIME.test(e),[s.Duration]:e=>l.DURATION.test(e),[s.Email]:e=>e.length<=254&&l.EMAIL.test(e),[s.IDNEmail]:e=>e.length<=254&&l.IDN_EMAIL.test(e),[s.Hostname]:e=>e.length>255?!1:e.split(".").every(n=>l.HOSTNAME.test(n)),[s.IDNHostname]:e=>e.length>255?!1:e.split(".").every(n=>n.length<=63&&l.IDN_HOSTNAME.test(n)),[s.IPv4]:e=>{let t=e.split(".");return t.length!==4?!1:t.every(n=>{let r=Number.parseInt(n,10);return r>=0&&r<=255&&n===r.toString()})},[s.IPv6]:e=>{let t=e.split(":");if(t.length>8)return!1;let n=!1;return t.every(r=>r===""?n?!1:(n=!0,!0):l.IPV6_PART.test(r))},[s.URI]:e=>{try{let t=new URL(e);return t.protocol!==""&&l.PROTOCOL.test(t.protocol)}catch{return!1}},[s.URIReference]:e=>{try{return e.startsWith("//")?l.URI_REFERENCE.test(e.slice(2)):(new URL(e,"http://example.com"),!0)}catch{return!1}},[s.IRI]:e=>{try{let t=new URL(e);return t.protocol!==""&&l.PROTOCOL.test(t.protocol)}catch{return!1}},[s.IRIReference]:e=>{try{return e.startsWith("//")?l.URI_REFERENCE.test(e.slice(2)):(new URL(e,"http://example.com"),!0)}catch{return!1}},[s.RegEx]:e=>{try{return new RegExp(e,"u"),!0}catch{return!1}},[s.UUID]:e=>l.UUID.test(e),[s.JSONPointer]:e=>l.JSON_POINTER.test(e),[s.JSONPointerURIFragment]:e=>l.JSON_POINTER_URI_FRAGMENT.test(e),[s.RelativeJSONPointer]:e=>l.RELATIVE_JSON_POINTER.test(e),[s.URITemplate]:e=>l.URI_TEMPLATE.test(e)};function $(e,t,n=[]){let r=[];if(typeof e!="string")return r;let i=D[t];return i&&!i(e)&&r.push({path:n,validation:"format",message:`must be a valid ${t} format`}),r}function M(e,t,n=[]){let r=[],i=p(t);if(typeof e!="string")return[];if(i!==void 0&&i!=="string")return[];let o=[...new Intl.Segmenter().segment(e)].length;if(t.minLength!==void 0&&o<t.minLength&&r.push({path:n,validation:"minLength",message:`must be at least ${t.minLength} characters`}),t.maxLength!==void 0&&o>t.maxLength&&r.push({path:n,validation:"maxLength",message:`must be at most ${t.maxLength} characters`}),t.pattern!==void 0&&(new RegExp(t.pattern).test(e)||r.push({path:n,validation:"pattern",message:`must match the pattern '${t.pattern}'`})),t.format!==void 0){let a=$(e,t.format,n);r.push(...a)}return r}function p(e){if(typeof e=="boolean")return"boolean";if(e.type!==void 0)return e.type}function w(e,t,n=[]){let r=p(t);if(r===void 0)return[];if(e===null)return Array.isArray(r)?r.includes("null")?[]:[{path:n,validation:"type",message:`should be ${r.join(" or ")}`}]:r==="null"?[]:[{path:n,validation:"required",message:"is required"}];let i=typeof e;if(Array.isArray(r))for(let o of r){if(i==="number"&&o==="integer"&&Number.isInteger(e))return[];if(i===o||o==="null"&&e===null)return[]}return i==="number"&&r==="integer"&&Number.isInteger(e)?[]:i===r?[]:[{path:n,validation:"type",message:`should be ${Array.isArray(r)?r.join(" | "):r}`}]}function m(e,t,n=!1,r=[]){if(e===void 0&&n)return[{path:r,validation:"required",message:"is required"}];if(e===void 0)return[];if(typeof t=="boolean")return t?[]:[{path:r,validation:"valid",message:"always fails"}];let i=w(e,t,r);if(i.length>0)return i;if(t.required&&Array.isArray(t.required)&&typeof e=="object"&&e!==null){let o=t.required.filter(a=>!(a in e));if(o.length>0)return o.map(a=>({path:[...r,a],validation:"required",message:"is required"}))}return[...R(e,t,r),...N(e,t,r),...J(e,t,r),...M(e,t,r),...v(e,t,r),...O(e,t,n,r),...I(e,t,r),...V(e,t,r),...h(e,t,r),...T(e,t,r),...O(e,t,n,r)]}function F(e){return e.length===0?null:e.reduce((t,n)=>{let{path:r,message:i}=n;if(r.length===0)return t[""]=i,t;let o=t;r.slice(0,-1).forEach(u=>{(!(u in o)||typeof o[u]=="string")&&(o[u]={}),o=o[u]});let a=r[r.length-1];return o[a]=i,t},{})}function B(e,t){return typeof t!="object"||!t||!e.length?e:e.map(n=>{if(!n.path.length)return n;let r=typeof t=="object"?t:null,i=null;for(let o of n.path){if(!r||typeof r!="object")break;if(r.properties&&r.properties[o]){let a=r.properties[o];if(typeof a!="boolean")r=a,i=r;else break}else if(r.items&&typeof r.items!="boolean")r=r.items,i=r;else break}return i&&i["x-jsf-errorMessage"]&&i["x-jsf-errorMessage"][n.validation]?{...n,message:i["x-jsf-errorMessage"][n.validation]}:n})}function k(e,t){let n={},r=m(e,t),i=B(r,t),o=F(i);return o&&(n.formErrors=o),n}function q(e){let{schema:t}=e;return y(t,"root",!0).fields||[]}function C(e,t={}){let n=m(t.initialValues,e),i=F(n)!==null,o=a=>k(a,e);return{fields:q({schema:e}),isError:i,error:null,handleValidation:o}}export{C as createHeadlessForm};
2
- //# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
3
  "type": "module",
4
- "version": "1.0.0-dev.20250305202108",
4
+ "version": "1.0.0-dev.20250305204935",
5
5
  "packageManager": "pnpm@9.15.2",
6
6
  "description": "WIP V2 – Headless UI form powered by JSON Schemas",
7
7
  "author": "Remote.com <engineering@remote.com> (https://remote.com/)",
File without changes