@remoteoss/json-schema-form 1.0.0-beta.2 → 1.0.0-beta.3
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 +56 -10
- package/dist/index.d.ts +176 -0
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -1
- package/dist/index.d.mts +0 -3
package/README.md
CHANGED
|
@@ -12,19 +12,65 @@ This is under active development, more info soon!
|
|
|
12
12
|
|
|
13
13
|
## Development
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
This means:
|
|
15
|
+
1. Clone the repository including submodules with the `--recursive` option
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/remoteoss/json-schema-form.git --recursive
|
|
19
|
+
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
If you already cloned the repository without the submodules,
|
|
22
|
+
you can initialize and update them with:
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
```bash
|
|
25
|
+
git submodule update --init
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
2. Navigate to the "next" folder
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cd json-schema-form/next
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
3. Install dependencies. You **must use [`pnpm`](https://pnpm.io/)**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm install
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. Work in the "next" folder only
|
|
41
|
+
|
|
42
|
+
Open your editor in this folder and run commands from.
|
|
43
|
+
Otherwise, your editor may fail to set up linting and type checking,
|
|
44
|
+
while your terminal may fail to resolve paths.
|
|
45
|
+
|
|
46
|
+
The limitation of this approach is that
|
|
47
|
+
your editor will fail to recognise our git repository here.
|
|
48
|
+
This also means you should turn off the editor's suggestion
|
|
49
|
+
to open git repository at root.
|
|
50
|
+
|
|
51
|
+
## Testing
|
|
52
|
+
|
|
53
|
+
To run the tests, navigate to the "next" folder and run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm test
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or run the tests in watch mode:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pnpm test:watch
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
We use Jest for testing and have 2 sets of tests:
|
|
66
|
+
|
|
67
|
+
1. The existing tests from the previous version
|
|
68
|
+
1. The new tests for this version
|
|
69
|
+
|
|
70
|
+
The old tests are located in the `../src/tests` folder.
|
|
71
|
+
The new tests are located in the `./test` folder.
|
|
72
|
+
|
|
73
|
+
The new tests are organized into separate files for each validation type (string, object, number, etc).
|
|
28
74
|
|
|
29
75
|
## Node.js Version
|
|
30
76
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { RulesLogic } from 'json-logic-js';
|
|
2
|
+
import { JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WIP type for UI field output that allows for all `x-jsf-presentation` properties to be splatted
|
|
6
|
+
* TODO/QUESTION: what are the required fields for a field? what are the things we want to deprecate, if any?
|
|
7
|
+
*/
|
|
8
|
+
interface Field {
|
|
9
|
+
name: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
fields?: Field[];
|
|
13
|
+
type: FieldType;
|
|
14
|
+
inputType: FieldType;
|
|
15
|
+
required: boolean;
|
|
16
|
+
jsonType: string;
|
|
17
|
+
isVisible: boolean;
|
|
18
|
+
accept?: string;
|
|
19
|
+
errorMessage?: Record<string, string>;
|
|
20
|
+
computedAttributes?: Record<string, unknown>;
|
|
21
|
+
minDate?: string;
|
|
22
|
+
maxDate?: string;
|
|
23
|
+
maxLength?: number;
|
|
24
|
+
maxFileSize?: number;
|
|
25
|
+
format?: string;
|
|
26
|
+
anyOf?: unknown[];
|
|
27
|
+
options?: unknown[];
|
|
28
|
+
const?: unknown;
|
|
29
|
+
checkboxValue?: unknown;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
type FieldType = 'text' | 'number' | 'select' | 'file' | 'radio' | 'group-array' | 'email' | 'date' | 'checkbox' | 'fieldset' | 'money' | 'country' | 'textarea';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Defines the type of a value in the form that will be validated against the schema.
|
|
36
|
+
*/
|
|
37
|
+
type SchemaValue = string | number | ObjectValue | null | undefined | Array<SchemaValue> | boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A nested object value.
|
|
40
|
+
*/
|
|
41
|
+
interface ObjectValue {
|
|
42
|
+
[key: string]: SchemaValue;
|
|
43
|
+
}
|
|
44
|
+
type JsfPresentation = {
|
|
45
|
+
inputType?: FieldType;
|
|
46
|
+
description?: string;
|
|
47
|
+
accept?: string;
|
|
48
|
+
maxFileSize?: number;
|
|
49
|
+
minDate?: string;
|
|
50
|
+
maxDate?: string;
|
|
51
|
+
} & {
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
};
|
|
54
|
+
interface JsonLogicSchema {
|
|
55
|
+
validations?: Record<string, {
|
|
56
|
+
errorMessage?: string;
|
|
57
|
+
rule: RulesLogic;
|
|
58
|
+
}>;
|
|
59
|
+
computedValues?: Record<string, {
|
|
60
|
+
rule: RulesLogic;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* JSON Schema Form extending JSON Schema with additional JSON Schema Form properties.
|
|
65
|
+
*/
|
|
66
|
+
type JsfSchema = JSONSchema & {
|
|
67
|
+
'properties'?: Record<string, JsfSchema>;
|
|
68
|
+
'items'?: JsfSchema;
|
|
69
|
+
'anyOf'?: JsfSchema[];
|
|
70
|
+
'allOf'?: JsfSchema[];
|
|
71
|
+
'oneOf'?: JsfSchema[];
|
|
72
|
+
'not'?: JsfSchema;
|
|
73
|
+
'if'?: JsfSchema;
|
|
74
|
+
'then'?: JsfSchema;
|
|
75
|
+
'else'?: JsfSchema;
|
|
76
|
+
'required'?: string[];
|
|
77
|
+
'x-jsf-order'?: string[];
|
|
78
|
+
'x-jsf-presentation'?: JsfPresentation;
|
|
79
|
+
'x-jsf-errorMessage'?: Record<string, string>;
|
|
80
|
+
'x-jsf-logic'?: JsonLogicSchema;
|
|
81
|
+
'x-jsf-logic-validations'?: string[];
|
|
82
|
+
'x-jsf-logic-computedAttrs'?: Record<keyof JsfSchema, string>;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* JSON Schema Form type without booleans.
|
|
86
|
+
* This type is used for convenience in places where a boolean is not allowed.
|
|
87
|
+
* @see `JsfSchema` for the full schema type which allows booleans and is used for sub schemas.
|
|
88
|
+
*/
|
|
89
|
+
type NonBooleanJsfSchema = Exclude<JsfSchema, boolean>;
|
|
90
|
+
/**
|
|
91
|
+
* JSON Schema Form type specifically for object schemas.
|
|
92
|
+
* This type ensures the schema has type 'object'.
|
|
93
|
+
*/
|
|
94
|
+
type JsfObjectSchema = NonBooleanJsfSchema & {
|
|
95
|
+
type: 'object';
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
interface ValidationOptions {
|
|
99
|
+
/**
|
|
100
|
+
* A null value will be treated as undefined.
|
|
101
|
+
* That means that when validating a null value, against a non-required field that is not of type 'null' or ['null']
|
|
102
|
+
* the validation will succeed instead of returning a type error.
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
treatNullAsUndefined?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interface FormResult {
|
|
109
|
+
fields: Field[];
|
|
110
|
+
isError: boolean;
|
|
111
|
+
error: string | null;
|
|
112
|
+
handleValidation: (value: SchemaValue) => ValidationResult;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Recursive type for form error messages
|
|
116
|
+
* - String for leaf error messages
|
|
117
|
+
* - Nested object for nested fields
|
|
118
|
+
*/
|
|
119
|
+
interface FormErrors {
|
|
120
|
+
[key: string]: string | FormErrors;
|
|
121
|
+
}
|
|
122
|
+
interface ValidationResult {
|
|
123
|
+
formErrors?: FormErrors;
|
|
124
|
+
}
|
|
125
|
+
interface CreateHeadlessFormOptions {
|
|
126
|
+
/**
|
|
127
|
+
* The initial values to use for the form
|
|
128
|
+
*/
|
|
129
|
+
initialValues?: SchemaValue;
|
|
130
|
+
/**
|
|
131
|
+
* The validation options to use for the form
|
|
132
|
+
*/
|
|
133
|
+
validationOptions?: ValidationOptions;
|
|
134
|
+
/**
|
|
135
|
+
* When enabled, ['x-jsf-presentation'].inputType is required for all properties.
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
strictInputType?: boolean;
|
|
139
|
+
}
|
|
140
|
+
declare function createHeadlessForm(schema: JsfObjectSchema, options?: CreateHeadlessFormOptions): FormResult;
|
|
141
|
+
|
|
142
|
+
type FieldOutput = Partial<JsfSchema> | Record<string, unknown>;
|
|
143
|
+
interface ModifyConfig {
|
|
144
|
+
fields?: Record<string, FieldOutput | ((attrs: JsfSchema) => FieldOutput)>;
|
|
145
|
+
allFields?: (name: string, attrs: JsfSchema) => FieldOutput;
|
|
146
|
+
create?: Record<string, FieldOutput>;
|
|
147
|
+
pick?: string[];
|
|
148
|
+
orderRoot?: string[] | ((originalOrder: string[]) => string[]);
|
|
149
|
+
muteLogging?: boolean;
|
|
150
|
+
}
|
|
151
|
+
type WarningType = 'FIELD_TO_CHANGE_NOT_FOUND' | 'ORDER_MISSING_FIELDS' | 'FIELD_TO_CREATE_EXISTS' | 'PICK_MISSED_FIELD';
|
|
152
|
+
interface Warning {
|
|
153
|
+
type: WarningType;
|
|
154
|
+
message: string;
|
|
155
|
+
meta?: Record<string, any>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Modifies the schema
|
|
159
|
+
* Use modify() when you need to customize the generated fields. This function creates a new version of JSON schema based on a provided configuration. Then you pass the new schema to createHeadlessForm()
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* const modifiedSchema = modify(schema, {
|
|
163
|
+
* fields: {
|
|
164
|
+
* name: { type: 'string', title: 'Name' },
|
|
165
|
+
* },
|
|
166
|
+
* })
|
|
167
|
+
* @param {JsfSchema} originalSchema - The original schema
|
|
168
|
+
* @param {ModifyConfig} config - The config
|
|
169
|
+
* @returns {ModifyResult} The new schema and the warnings that occurred during the modifications
|
|
170
|
+
*/
|
|
171
|
+
declare function modifySchema(originalSchema: JsfSchema, config: ModifyConfig): {
|
|
172
|
+
schema: JsfSchema;
|
|
173
|
+
warnings: (Warning | null)[];
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export { type CreateHeadlessFormOptions, type ValidationOptions, createHeadlessForm, modifySchema as modify };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
function e(){throw new Error("Not implemented")}export{e as createHeadlessForm};
|
|
1
|
+
var La=Object.create;var fr=Object.defineProperty;var Da=Object.getOwnPropertyDescriptor;var Ba=Object.getOwnPropertyNames;var $a=Object.getPrototypeOf,Ua=Object.prototype.hasOwnProperty;var u=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var Ha=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ba(r))!Ua.call(e,i)&&i!==t&&fr(e,i,{get:()=>r[i],enumerable:!(n=Da(r,i))||n.enumerable});return e};var w=(e,r,t)=>(t=e!=null?La($a(e)):{},Ha(r||!e||!e.__esModule?fr(t,"default",{value:e,enumerable:!0}):t,e));var G=u((Yh,cr)=>{"use strict";cr.exports={ROOT:0,GROUP:1,POSITION:2,SET:3,RANGE:4,REPETITION:5,REFERENCE:6,CHAR:7}});var Ae=u(q=>{"use strict";var d=G(),_e=()=>[{type:d.RANGE,from:48,to:57}],pr=()=>[{type:d.CHAR,value:95},{type:d.RANGE,from:97,to:122},{type:d.RANGE,from:65,to:90}].concat(_e()),dr=()=>[{type:d.CHAR,value:9},{type:d.CHAR,value:10},{type:d.CHAR,value:11},{type:d.CHAR,value:12},{type:d.CHAR,value:13},{type:d.CHAR,value:32},{type:d.CHAR,value:160},{type:d.CHAR,value:5760},{type:d.RANGE,from:8192,to:8202},{type:d.CHAR,value:8232},{type:d.CHAR,value:8233},{type:d.CHAR,value:8239},{type:d.CHAR,value:8287},{type:d.CHAR,value:12288},{type:d.CHAR,value:65279}],za=()=>[{type:d.CHAR,value:10},{type:d.CHAR,value:13},{type:d.CHAR,value:8232},{type:d.CHAR,value:8233}];q.words=()=>({type:d.SET,set:pr(),not:!1});q.notWords=()=>({type:d.SET,set:pr(),not:!0});q.ints=()=>({type:d.SET,set:_e(),not:!1});q.notInts=()=>({type:d.SET,set:_e(),not:!0});q.whitespace=()=>({type:d.SET,set:dr(),not:!1});q.notWhitespace=()=>({type:d.SET,set:dr(),not:!0});q.anyChar=()=>({type:d.SET,set:za(),not:!0})});var mr=u(W=>{"use strict";var hr=G(),P=Ae(),Ga="@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?",Wa={0:0,t:9,n:10,v:11,f:12,r:13};W.strToChars=function(e){var r=/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g;return e=e.replace(r,function(t,n,i,o,a,s,l,f){if(i)return t;var c=n?8:o?parseInt(o,16):a?parseInt(a,16):s?parseInt(s,8):l?Ga.indexOf(l):Wa[f],p=String.fromCharCode(c);return/[[\]{}^$.|?*+()]/.test(p)&&(p="\\"+p),p}),e};W.tokenizeClass=(e,r)=>{for(var t=[],n=/\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g,i,o;(i=n.exec(e))!=null;)if(i[1])t.push(P.words());else if(i[2])t.push(P.ints());else if(i[3])t.push(P.whitespace());else if(i[4])t.push(P.notWords());else if(i[5])t.push(P.notInts());else if(i[6])t.push(P.notWhitespace());else if(i[7])t.push({type:hr.RANGE,from:(i[8]||i[9]).charCodeAt(0),to:i[10].charCodeAt(0)});else if(o=i[12])t.push({type:hr.CHAR,value:o.charCodeAt(0)});else return[t,n.lastIndex];W.error(r,"Unterminated character class")};W.error=(e,r)=>{throw new SyntaxError("Invalid regular expression: /"+e+"/: "+r)}});var gr=u(k=>{"use strict";var ce=G();k.wordBoundary=()=>({type:ce.POSITION,value:"b"});k.nonWordBoundary=()=>({type:ce.POSITION,value:"B"});k.begin=()=>({type:ce.POSITION,value:"^"});k.end=()=>({type:ce.POSITION,value:"$"})});var yr=u((rm,Ve)=>{"use strict";var F=mr(),O=G(),_=Ae(),pe=gr();Ve.exports=e=>{var r=0,t,n,i={type:O.ROOT,stack:[]},o=i,a=i.stack,s=[],l=Ma=>{F.error(e,`Nothing to repeat at column ${Ma-1}`)},f=F.strToChars(e);for(t=f.length;r<t;)switch(n=f[r++],n){case"\\":switch(n=f[r++],n){case"b":a.push(pe.wordBoundary());break;case"B":a.push(pe.nonWordBoundary());break;case"w":a.push(_.words());break;case"W":a.push(_.notWords());break;case"d":a.push(_.ints());break;case"D":a.push(_.notInts());break;case"s":a.push(_.whitespace());break;case"S":a.push(_.notWhitespace());break;default:/\d/.test(n)?a.push({type:O.REFERENCE,value:parseInt(n,10)}):a.push({type:O.CHAR,value:n.charCodeAt(0)})}break;case"^":a.push(pe.begin());break;case"$":a.push(pe.end());break;case"[":var c;f[r]==="^"?(c=!0,r++):c=!1;var p=F.tokenizeClass(f.slice(r),e);r+=p[1],a.push({type:O.SET,set:p[0],not:c});break;case".":a.push(_.anyChar());break;case"(":var h={type:O.GROUP,stack:[],remember:!0};n=f[r],n==="?"&&(n=f[r+1],r+=2,n==="="?h.followedBy=!0:n==="!"?h.notFollowedBy=!0:n!==":"&&F.error(e,`Invalid group, character '${n}' after '?' at column ${r-1}`),h.remember=!1),a.push(h),s.push(o),o=h,a=h.stack;break;case")":s.length===0&&F.error(e,`Unmatched ) at column ${r-1}`),o=s.pop(),a=o.options?o.options[o.options.length-1]:o.stack;break;case"|":o.options||(o.options=[o.stack],delete o.stack);var b=[];o.options.push(b),a=b;break;case"{":var x=/^(\d+)(,(\d+)?)?\}/.exec(f.slice(r)),j,lr;x!==null?(a.length===0&&l(r),j=parseInt(x[1],10),lr=x[2]?x[3]?parseInt(x[3],10):1/0:j,r+=x[0].length,a.push({type:O.REPETITION,min:j,max:lr,value:a.pop()})):a.push({type:O.CHAR,value:123});break;case"?":a.length===0&&l(r),a.push({type:O.REPETITION,min:0,max:1,value:a.pop()});break;case"+":a.length===0&&l(r),a.push({type:O.REPETITION,min:1,max:1/0,value:a.pop()});break;case"*":a.length===0&&l(r),a.push({type:O.REPETITION,min:0,max:1/0,value:a.pop()});break;default:a.push({type:O.CHAR,value:n.charCodeAt(0)})}return s.length!==0&&F.error(e,"Unterminated group"),i};Ve.exports.types=O});var vr=u((tm,br)=>{"use strict";var N=class e{constructor(r,t){this.low=r,this.high=t,this.length=1+t-r}overlaps(r){return!(this.high<r.low||this.low>r.high)}touches(r){return!(this.high+1<r.low||this.low-1>r.high)}add(r){return new e(Math.min(this.low,r.low),Math.max(this.high,r.high))}subtract(r){return r.low<=this.low&&r.high>=this.high?[]:r.low>this.low&&r.high<this.high?[new e(this.low,r.low-1),new e(r.high+1,this.high)]:r.low<=this.low?[new e(r.high+1,this.high)]:[new e(this.low,r.low-1)]}toString(){return this.low==this.high?this.low.toString():this.low+"-"+this.high}},Re=class e{constructor(r,t){this.ranges=[],this.length=0,r!=null&&this.add(r,t)}_update_length(){this.length=this.ranges.reduce((r,t)=>r+t.length,0)}add(r,t){var n=i=>{for(var o=0;o<this.ranges.length&&!i.touches(this.ranges[o]);)o++;for(var a=this.ranges.slice(0,o);o<this.ranges.length&&i.touches(this.ranges[o]);)i=i.add(this.ranges[o]),o++;a.push(i),this.ranges=a.concat(this.ranges.slice(o)),this._update_length()};return r instanceof e?r.ranges.forEach(n):(t==null&&(t=r),n(new N(r,t))),this}subtract(r,t){var n=i=>{for(var o=0;o<this.ranges.length&&!i.overlaps(this.ranges[o]);)o++;for(var a=this.ranges.slice(0,o);o<this.ranges.length&&i.overlaps(this.ranges[o]);)a=a.concat(this.ranges[o].subtract(i)),o++;this.ranges=a.concat(this.ranges.slice(o)),this._update_length()};return r instanceof e?r.ranges.forEach(n):(t==null&&(t=r),n(new N(r,t))),this}intersect(r,t){var n=[],i=o=>{for(var a=0;a<this.ranges.length&&!o.overlaps(this.ranges[a]);)a++;for(;a<this.ranges.length&&o.overlaps(this.ranges[a]);){var s=Math.max(this.ranges[a].low,o.low),l=Math.min(this.ranges[a].high,o.high);n.push(new N(s,l)),a++}};return r instanceof e?r.ranges.forEach(i):(t==null&&(t=r),i(new N(r,t))),this.ranges=n,this._update_length(),this}index(r){for(var t=0;t<this.ranges.length&&this.ranges[t].length<=r;)r-=this.ranges[t].length,t++;return this.ranges[t].low+r}toString(){return"[ "+this.ranges.join(", ")+" ]"}clone(){return new e(this)}numbers(){return this.ranges.reduce((r,t)=>{for(var n=t.low;n<=t.high;)r.push(n),n++;return r},[])}subranges(){return this.ranges.map(r=>({low:r.low,high:r.high,length:1+r.high-r.low}))}};br.exports=Re});var Sr=u((nm,xr)=>{"use strict";var de=yr(),K=vr(),A=de.types;xr.exports=class X{constructor(r,t){if(this._setDefaults(r),r instanceof RegExp)this.ignoreCase=r.ignoreCase,this.multiline=r.multiline,r=r.source;else if(typeof r=="string")this.ignoreCase=t&&t.indexOf("i")!==-1,this.multiline=t&&t.indexOf("m")!==-1;else throw new Error("Expected a regexp or string");this.tokens=de(r)}_setDefaults(r){this.max=r.max!=null?r.max:X.prototype.max!=null?X.prototype.max:100,this.defaultRange=r.defaultRange?r.defaultRange:this.defaultRange.clone(),r.randInt&&(this.randInt=r.randInt)}gen(){return this._gen(this.tokens,[])}_gen(r,t){var n,i,o,a,s;switch(r.type){case A.ROOT:case A.GROUP:if(r.followedBy||r.notFollowedBy)return"";for(r.remember&&r.groupNumber===void 0&&(r.groupNumber=t.push(null)-1),n=r.options?this._randSelect(r.options):r.stack,i="",a=0,s=n.length;a<s;a++)i+=this._gen(n[a],t);return r.remember&&(t[r.groupNumber]=i),i;case A.POSITION:return"";case A.SET:var l=this._expand(r);return l.length?String.fromCharCode(this._randSelect(l)):"";case A.REPETITION:for(o=this.randInt(r.min,r.max===1/0?r.min+this.max:r.max),i="",a=0;a<o;a++)i+=this._gen(r.value,t);return i;case A.REFERENCE:return t[r.value-1]||"";case A.CHAR:var f=this.ignoreCase&&this._randBool()?this._toOtherCase(r.value):r.value;return String.fromCharCode(f)}}_toOtherCase(r){return r+(97<=r&&r<=122?-32:65<=r&&r<=90?32:0)}_randBool(){return!this.randInt(0,1)}_randSelect(r){return r instanceof K?r.index(this.randInt(0,r.length-1)):r[this.randInt(0,r.length-1)]}_expand(r){if(r.type===de.types.CHAR)return new K(r.value);if(r.type===de.types.RANGE)return new K(r.from,r.to);{let t=new K;for(let n=0;n<r.set.length;n++){let i=this._expand(r.set[n]);if(t.add(i),this.ignoreCase)for(let o=0;o<i.length;o++){let a=i.index(o),s=this._toOtherCase(a);a!==s&&t.add(s)}}return r.not?this.defaultRange.clone().subtract(t):this.defaultRange.clone().intersect(t)}}randInt(r,t){return r+Math.floor(Math.random()*(1+t-r))}get defaultRange(){return this._range=this._range||new K(32,126)}set defaultRange(r){this._range=r}static randexp(r,t){var n;return typeof r=="string"&&(r=new RegExp(r,t)),r._randexp===void 0?(n=new X(r,t),r._randexp=n):(n=r._randexp,n._setDefaults(r)),n.gen()}static sugar(){RegExp.prototype.gen=function(){return X.randexp(this)}}}});var Je=u((dg,Wr)=>{"use strict";var xs=typeof global=="object"&&global&&global.Object===Object&&global;Wr.exports=xs});var V=u((hg,kr)=>{"use strict";var Ss=Je(),Os=typeof self=="object"&&self&&self.Object===Object&&self,Es=Ss||Os||Function("return this")();kr.exports=Es});var Q=u((mg,Kr)=>{"use strict";var Ts=V(),qs=Ts.Symbol;Kr.exports=qs});var Qr=u((gg,Zr)=>{"use strict";var Xr=Q(),Yr=Object.prototype,Is=Yr.hasOwnProperty,ws=Yr.toString,ee=Xr?Xr.toStringTag:void 0;function _s(e){var r=Is.call(e,ee),t=e[ee];try{e[ee]=void 0;var n=!0}catch{}var i=ws.call(e);return n&&(r?e[ee]=t:delete e[ee]),i}Zr.exports=_s});var rt=u((yg,et)=>{"use strict";var As=Object.prototype,Vs=As.toString;function Rs(e){return Vs.call(e)}et.exports=Rs});var J=u((bg,it)=>{"use strict";var tt=Q(),Cs=Qr(),js=rt(),Ps="[object Null]",Fs="[object Undefined]",nt=tt?tt.toStringTag:void 0;function Ns(e){return e==null?e===void 0?Fs:Ps:nt&&nt in Object(e)?Cs(e):js(e)}it.exports=Ns});var T=u((vg,ot)=>{"use strict";function Js(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}ot.exports=Js});var me=u((xg,at)=>{"use strict";var Ms=J(),Ls=T(),Ds="[object AsyncFunction]",Bs="[object Function]",$s="[object GeneratorFunction]",Us="[object Proxy]";function Hs(e){if(!Ls(e))return!1;var r=Ms(e);return r==Bs||r==$s||r==Ds||r==Us}at.exports=Hs});var ut=u((Sg,st)=>{"use strict";var zs=V(),Gs=zs["__core-js_shared__"];st.exports=Gs});var ct=u((Og,ft)=>{"use strict";var Me=ut(),lt=function(){var e=/[^.]+$/.exec(Me&&Me.keys&&Me.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Ws(e){return!!lt&< in e}ft.exports=Ws});var dt=u((Eg,pt)=>{"use strict";var ks=Function.prototype,Ks=ks.toString;function Xs(e){if(e!=null){try{return Ks.call(e)}catch{}try{return e+""}catch{}}return""}pt.exports=Xs});var mt=u((Tg,ht)=>{"use strict";var Ys=me(),Zs=ct(),Qs=T(),eu=dt(),ru=/[\\^$.*+?()[\]{}|]/g,tu=/^\[object .+?Constructor\]$/,nu=Function.prototype,iu=Object.prototype,ou=nu.toString,au=iu.hasOwnProperty,su=RegExp("^"+ou.call(au).replace(ru,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function uu(e){if(!Qs(e)||Zs(e))return!1;var r=Ys(e)?su:tu;return r.test(eu(e))}ht.exports=uu});var yt=u((qg,gt)=>{"use strict";function lu(e,r){return e?.[r]}gt.exports=lu});var ge=u((Ig,bt)=>{"use strict";var fu=mt(),cu=yt();function pu(e,r){var t=cu(e,r);return fu(t)?t:void 0}bt.exports=pu});var re=u((wg,vt)=>{"use strict";var du=ge(),hu=du(Object,"create");vt.exports=hu});var Ot=u((_g,St)=>{"use strict";var xt=re();function mu(){this.__data__=xt?xt(null):{},this.size=0}St.exports=mu});var Tt=u((Ag,Et)=>{"use strict";function gu(e){var r=this.has(e)&&delete this.__data__[e];return this.size-=r?1:0,r}Et.exports=gu});var It=u((Vg,qt)=>{"use strict";var yu=re(),bu="__lodash_hash_undefined__",vu=Object.prototype,xu=vu.hasOwnProperty;function Su(e){var r=this.__data__;if(yu){var t=r[e];return t===bu?void 0:t}return xu.call(r,e)?r[e]:void 0}qt.exports=Su});var _t=u((Rg,wt)=>{"use strict";var Ou=re(),Eu=Object.prototype,Tu=Eu.hasOwnProperty;function qu(e){var r=this.__data__;return Ou?r[e]!==void 0:Tu.call(r,e)}wt.exports=qu});var Vt=u((Cg,At)=>{"use strict";var Iu=re(),wu="__lodash_hash_undefined__";function _u(e,r){var t=this.__data__;return this.size+=this.has(e)?0:1,t[e]=Iu&&r===void 0?wu:r,this}At.exports=_u});var Ct=u((jg,Rt)=>{"use strict";var Au=Ot(),Vu=Tt(),Ru=It(),Cu=_t(),ju=Vt();function M(e){var r=-1,t=e==null?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}M.prototype.clear=Au;M.prototype.delete=Vu;M.prototype.get=Ru;M.prototype.has=Cu;M.prototype.set=ju;Rt.exports=M});var Pt=u((Pg,jt)=>{"use strict";function Pu(){this.__data__=[],this.size=0}jt.exports=Pu});var te=u((Fg,Ft)=>{"use strict";function Fu(e,r){return e===r||e!==e&&r!==r}Ft.exports=Fu});var ne=u((Ng,Nt)=>{"use strict";var Nu=te();function Ju(e,r){for(var t=e.length;t--;)if(Nu(e[t][0],r))return t;return-1}Nt.exports=Ju});var Mt=u((Jg,Jt)=>{"use strict";var Mu=ne(),Lu=Array.prototype,Du=Lu.splice;function Bu(e){var r=this.__data__,t=Mu(r,e);if(t<0)return!1;var n=r.length-1;return t==n?r.pop():Du.call(r,t,1),--this.size,!0}Jt.exports=Bu});var Dt=u((Mg,Lt)=>{"use strict";var $u=ne();function Uu(e){var r=this.__data__,t=$u(r,e);return t<0?void 0:r[t][1]}Lt.exports=Uu});var $t=u((Lg,Bt)=>{"use strict";var Hu=ne();function zu(e){return Hu(this.__data__,e)>-1}Bt.exports=zu});var Ht=u((Dg,Ut)=>{"use strict";var Gu=ne();function Wu(e,r){var t=this.__data__,n=Gu(t,e);return n<0?(++this.size,t.push([e,r])):t[n][1]=r,this}Ut.exports=Wu});var ie=u((Bg,zt)=>{"use strict";var ku=Pt(),Ku=Mt(),Xu=Dt(),Yu=$t(),Zu=Ht();function L(e){var r=-1,t=e==null?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}L.prototype.clear=ku;L.prototype.delete=Ku;L.prototype.get=Xu;L.prototype.has=Yu;L.prototype.set=Zu;zt.exports=L});var Le=u(($g,Gt)=>{"use strict";var Qu=ge(),el=V(),rl=Qu(el,"Map");Gt.exports=rl});var Kt=u((Ug,kt)=>{"use strict";var Wt=Ct(),tl=ie(),nl=Le();function il(){this.size=0,this.__data__={hash:new Wt,map:new(nl||tl),string:new Wt}}kt.exports=il});var Yt=u((Hg,Xt)=>{"use strict";function ol(e){var r=typeof e;return r=="string"||r=="number"||r=="symbol"||r=="boolean"?e!=="__proto__":e===null}Xt.exports=ol});var oe=u((zg,Zt)=>{"use strict";var al=Yt();function sl(e,r){var t=e.__data__;return al(r)?t[typeof r=="string"?"string":"hash"]:t.map}Zt.exports=sl});var en=u((Gg,Qt)=>{"use strict";var ul=oe();function ll(e){var r=ul(this,e).delete(e);return this.size-=r?1:0,r}Qt.exports=ll});var tn=u((Wg,rn)=>{"use strict";var fl=oe();function cl(e){return fl(this,e).get(e)}rn.exports=cl});var on=u((kg,nn)=>{"use strict";var pl=oe();function dl(e){return pl(this,e).has(e)}nn.exports=dl});var sn=u((Kg,an)=>{"use strict";var hl=oe();function ml(e,r){var t=hl(this,e),n=t.size;return t.set(e,r),this.size+=t.size==n?0:1,this}an.exports=ml});var ye=u((Xg,un)=>{"use strict";var gl=Kt(),yl=en(),bl=tn(),vl=on(),xl=sn();function D(e){var r=-1,t=e==null?0:e.length;for(this.clear();++r<t;){var n=e[r];this.set(n[0],n[1])}}D.prototype.clear=gl;D.prototype.delete=yl;D.prototype.get=bl;D.prototype.has=vl;D.prototype.set=xl;un.exports=D});var fn=u((Yg,ln)=>{"use strict";var Sl="__lodash_hash_undefined__";function Ol(e){return this.__data__.set(e,Sl),this}ln.exports=Ol});var pn=u((Zg,cn)=>{"use strict";function El(e){return this.__data__.has(e)}cn.exports=El});var De=u((Qg,dn)=>{"use strict";var Tl=ye(),ql=fn(),Il=pn();function be(e){var r=-1,t=e==null?0:e.length;for(this.__data__=new Tl;++r<t;)this.add(e[r])}be.prototype.add=be.prototype.push=ql;be.prototype.has=Il;dn.exports=be});var mn=u((ey,hn)=>{"use strict";function wl(e,r,t,n){for(var i=e.length,o=t+(n?1:-1);n?o--:++o<i;)if(r(e[o],o,e))return o;return-1}hn.exports=wl});var yn=u((ry,gn)=>{"use strict";function _l(e){return e!==e}gn.exports=_l});var vn=u((ty,bn)=>{"use strict";function Al(e,r,t){for(var n=t-1,i=e.length;++n<i;)if(e[n]===r)return n;return-1}bn.exports=Al});var Sn=u((ny,xn)=>{"use strict";var Vl=mn(),Rl=yn(),Cl=vn();function jl(e,r,t){return r===r?Cl(e,r,t):Vl(e,Rl,t)}xn.exports=jl});var Be=u((iy,On)=>{"use strict";var Pl=Sn();function Fl(e,r){var t=e==null?0:e.length;return!!t&&Pl(e,r,0)>-1}On.exports=Fl});var $e=u((oy,En)=>{"use strict";function Nl(e,r,t){for(var n=-1,i=e==null?0:e.length;++n<i;)if(t(r,e[n]))return!0;return!1}En.exports=Nl});var ae=u((ay,Tn)=>{"use strict";function Jl(e,r){for(var t=-1,n=e==null?0:e.length,i=Array(n);++t<n;)i[t]=r(e[t],t,e);return i}Tn.exports=Jl});var ve=u((sy,qn)=>{"use strict";function Ml(e){return function(r){return e(r)}}qn.exports=Ml});var Ue=u((uy,In)=>{"use strict";function Ll(e,r){return e.has(r)}In.exports=Ll});var _n=u((ly,wn)=>{"use strict";var Dl=De(),Bl=Be(),$l=$e(),Ul=ae(),Hl=ve(),zl=Ue(),Gl=200;function Wl(e,r,t,n){var i=-1,o=Bl,a=!0,s=e.length,l=[],f=r.length;if(!s)return l;t&&(r=Ul(r,Hl(t))),n?(o=$l,a=!1):r.length>=Gl&&(o=zl,a=!1,r=new Dl(r));e:for(;++i<s;){var c=e[i],p=t==null?c:t(c);if(c=n||c!==0?c:0,a&&p===p){for(var h=f;h--;)if(r[h]===p)continue e;l.push(c)}else o(r,p,n)||l.push(c)}return l}wn.exports=Wl});var Vn=u((fy,An)=>{"use strict";function kl(e,r){for(var t=-1,n=r.length,i=e.length;++t<n;)e[i+t]=r[t];return e}An.exports=kl});var R=u((cy,Rn)=>{"use strict";function Kl(e){return e!=null&&typeof e=="object"}Rn.exports=Kl});var jn=u((py,Cn)=>{"use strict";var Xl=J(),Yl=R(),Zl="[object Arguments]";function Ql(e){return Yl(e)&&Xl(e)==Zl}Cn.exports=Ql});var xe=u((dy,Nn)=>{"use strict";var Pn=jn(),ef=R(),Fn=Object.prototype,rf=Fn.hasOwnProperty,tf=Fn.propertyIsEnumerable,nf=Pn(function(){return arguments}())?Pn:function(e){return ef(e)&&rf.call(e,"callee")&&!tf.call(e,"callee")};Nn.exports=nf});var C=u((hy,Jn)=>{"use strict";var of=Array.isArray;Jn.exports=of});var Bn=u((my,Dn)=>{"use strict";var Mn=Q(),af=xe(),sf=C(),Ln=Mn?Mn.isConcatSpreadable:void 0;function uf(e){return sf(e)||af(e)||!!(Ln&&e&&e[Ln])}Dn.exports=uf});var Hn=u((gy,Un)=>{"use strict";var lf=Vn(),ff=Bn();function $n(e,r,t,n,i){var o=-1,a=e.length;for(t||(t=ff),i||(i=[]);++o<a;){var s=e[o];r>0&&t(s)?r>1?$n(s,r-1,t,n,i):lf(i,s):n||(i[i.length]=s)}return i}Un.exports=$n});var He=u((yy,zn)=>{"use strict";function cf(e){return e}zn.exports=cf});var Wn=u((by,Gn)=>{"use strict";function pf(e,r,t){switch(t.length){case 0:return e.call(r);case 1:return e.call(r,t[0]);case 2:return e.call(r,t[0],t[1]);case 3:return e.call(r,t[0],t[1],t[2])}return e.apply(r,t)}Gn.exports=pf});var Xn=u((vy,Kn)=>{"use strict";var df=Wn(),kn=Math.max;function hf(e,r,t){return r=kn(r===void 0?e.length-1:r,0),function(){for(var n=arguments,i=-1,o=kn(n.length-r,0),a=Array(o);++i<o;)a[i]=n[r+i];i=-1;for(var s=Array(r+1);++i<r;)s[i]=n[i];return s[r]=t(a),df(e,this,s)}}Kn.exports=hf});var Zn=u((xy,Yn)=>{"use strict";function mf(e){return function(){return e}}Yn.exports=mf});var ze=u((Sy,Qn)=>{"use strict";var gf=ge(),yf=function(){try{var e=gf(Object,"defineProperty");return e({},"",{}),e}catch{}}();Qn.exports=yf});var ti=u((Oy,ri)=>{"use strict";var bf=Zn(),ei=ze(),vf=He(),xf=ei?function(e,r){return ei(e,"toString",{configurable:!0,enumerable:!1,value:bf(r),writable:!0})}:vf;ri.exports=xf});var ii=u((Ey,ni)=>{"use strict";var Sf=800,Of=16,Ef=Date.now;function Tf(e){var r=0,t=0;return function(){var n=Ef(),i=Of-(n-t);if(t=n,i>0){if(++r>=Sf)return arguments[0]}else r=0;return e.apply(void 0,arguments)}}ni.exports=Tf});var ai=u((Ty,oi)=>{"use strict";var qf=ti(),If=ii(),wf=If(qf);oi.exports=wf});var Se=u((qy,si)=>{"use strict";var _f=He(),Af=Xn(),Vf=ai();function Rf(e,r){return Vf(Af(e,r,_f),e+"")}si.exports=Rf});var Ge=u((Iy,ui)=>{"use strict";var Cf=9007199254740991;function jf(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Cf}ui.exports=jf});var Oe=u((wy,li)=>{"use strict";var Pf=me(),Ff=Ge();function Nf(e){return e!=null&&Ff(e.length)&&!Pf(e)}li.exports=Nf});var Ee=u((_y,fi)=>{"use strict";var Jf=Oe(),Mf=R();function Lf(e){return Mf(e)&&Jf(e)}fi.exports=Lf});var di=u((Ay,pi)=>{"use strict";var Df=_n(),Bf=Hn(),$f=Se(),ci=Ee(),Uf=$f(function(e,r){return ci(e)?Df(e,Bf(r,1,ci,!0)):[]});pi.exports=Uf});var Te=u((Vy,hi)=>{"use strict";var Hf=J(),zf=R(),Gf="[object Symbol]";function Wf(e){return typeof e=="symbol"||zf(e)&&Hf(e)==Gf}hi.exports=Wf});var gi=u((Ry,mi)=>{"use strict";var kf=C(),Kf=Te(),Xf=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Yf=/^\w*$/;function Zf(e,r){if(kf(e))return!1;var t=typeof e;return t=="number"||t=="symbol"||t=="boolean"||e==null||Kf(e)?!0:Yf.test(e)||!Xf.test(e)||r!=null&&e in Object(r)}mi.exports=Zf});var vi=u((Cy,bi)=>{"use strict";var yi=ye(),Qf="Expected a function";function We(e,r){if(typeof e!="function"||r!=null&&typeof r!="function")throw new TypeError(Qf);var t=function(){var n=arguments,i=r?r.apply(this,n):n[0],o=t.cache;if(o.has(i))return o.get(i);var a=e.apply(this,n);return t.cache=o.set(i,a)||o,a};return t.cache=new(We.Cache||yi),t}We.Cache=yi;bi.exports=We});var Si=u((jy,xi)=>{"use strict";var ec=vi(),rc=500;function tc(e){var r=ec(e,function(n){return t.size===rc&&t.clear(),n}),t=r.cache;return r}xi.exports=tc});var Ei=u((Py,Oi)=>{"use strict";var nc=Si(),ic=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,oc=/\\(\\)?/g,ac=nc(function(e){var r=[];return e.charCodeAt(0)===46&&r.push(""),e.replace(ic,function(t,n,i,o){r.push(i?o.replace(oc,"$1"):n||t)}),r});Oi.exports=ac});var Ai=u((Fy,_i)=>{"use strict";var Ti=Q(),sc=ae(),uc=C(),lc=Te(),fc=1/0,qi=Ti?Ti.prototype:void 0,Ii=qi?qi.toString:void 0;function wi(e){if(typeof e=="string")return e;if(uc(e))return sc(e,wi)+"";if(lc(e))return Ii?Ii.call(e):"";var r=e+"";return r=="0"&&1/e==-fc?"-0":r}_i.exports=wi});var Ri=u((Ny,Vi)=>{"use strict";var cc=Ai();function pc(e){return e==null?"":cc(e)}Vi.exports=pc});var ke=u((Jy,Ci)=>{"use strict";var dc=C(),hc=gi(),mc=Ei(),gc=Ri();function yc(e,r){return dc(e)?e:hc(e,r)?[e]:mc(gc(e))}Ci.exports=yc});var Ke=u((My,ji)=>{"use strict";var bc=Te(),vc=1/0;function xc(e){if(typeof e=="string"||bc(e))return e;var r=e+"";return r=="0"&&1/e==-vc?"-0":r}ji.exports=xc});var Fi=u((Ly,Pi)=>{"use strict";var Sc=ke(),Oc=Ke();function Ec(e,r){r=Sc(r,e);for(var t=0,n=r.length;e!=null&&t<n;)e=e[Oc(r[t++])];return t&&t==n?e:void 0}Pi.exports=Ec});var Ji=u((Dy,Ni)=>{"use strict";var Tc=Fi();function qc(e,r,t){var n=e==null?void 0:Tc(e,r);return n===void 0?t:n}Ni.exports=qc});var Di=u((By,Li)=>{"use strict";var Ic=De(),wc=Be(),_c=$e(),Ac=ae(),Vc=ve(),Mi=Ue(),Rc=Math.min;function Cc(e,r,t){for(var n=t?_c:wc,i=e[0].length,o=e.length,a=o,s=Array(o),l=1/0,f=[];a--;){var c=e[a];a&&r&&(c=Ac(c,Vc(r))),l=Rc(c.length,l),s[a]=!t&&(r||i>=120&&c.length>=120)?new Ic(a&&c):void 0}c=e[0];var p=-1,h=s[0];e:for(;++p<i&&f.length<l;){var b=c[p],x=r?r(b):b;if(b=t||b!==0?b:0,!(h?Mi(h,x):n(f,x,t))){for(a=o;--a;){var j=s[a];if(!(j?Mi(j,x):n(e[a],x,t)))continue e}h&&h.push(x),f.push(b)}}return f}Li.exports=Cc});var $i=u(($y,Bi)=>{"use strict";var jc=Ee();function Pc(e){return jc(e)?e:[]}Bi.exports=Pc});var Hi=u((Uy,Ui)=>{"use strict";var Fc=ae(),Nc=Di(),Jc=Se(),Mc=$i(),Lc=Jc(function(e){var r=Fc(e,Mc);return r.length&&r[0]===e[0]?Nc(r):[]});Ui.exports=Lc});var Gi=u((Hy,zi)=>{"use strict";var Dc=ie();function Bc(){this.__data__=new Dc,this.size=0}zi.exports=Bc});var ki=u((zy,Wi)=>{"use strict";function $c(e){var r=this.__data__,t=r.delete(e);return this.size=r.size,t}Wi.exports=$c});var Xi=u((Gy,Ki)=>{"use strict";function Uc(e){return this.__data__.get(e)}Ki.exports=Uc});var Zi=u((Wy,Yi)=>{"use strict";function Hc(e){return this.__data__.has(e)}Yi.exports=Hc});var eo=u((ky,Qi)=>{"use strict";var zc=ie(),Gc=Le(),Wc=ye(),kc=200;function Kc(e,r){var t=this.__data__;if(t instanceof zc){var n=t.__data__;if(!Gc||n.length<kc-1)return n.push([e,r]),this.size=++t.size,this;t=this.__data__=new Wc(n)}return t.set(e,r),this.size=t.size,this}Qi.exports=Kc});var to=u((Ky,ro)=>{"use strict";var Xc=ie(),Yc=Gi(),Zc=ki(),Qc=Xi(),ep=Zi(),rp=eo();function B(e){var r=this.__data__=new Xc(e);this.size=r.size}B.prototype.clear=Yc;B.prototype.delete=Zc;B.prototype.get=Qc;B.prototype.has=ep;B.prototype.set=rp;ro.exports=B});var qe=u((Xy,io)=>{"use strict";var no=ze();function tp(e,r,t){r=="__proto__"&&no?no(e,r,{configurable:!0,enumerable:!0,value:t,writable:!0}):e[r]=t}io.exports=tp});var Xe=u((Yy,oo)=>{"use strict";var np=qe(),ip=te();function op(e,r,t){(t!==void 0&&!ip(e[r],t)||t===void 0&&!(r in e))&&np(e,r,t)}oo.exports=op});var so=u((Zy,ao)=>{"use strict";function ap(e){return function(r,t,n){for(var i=-1,o=Object(r),a=n(r),s=a.length;s--;){var l=a[e?s:++i];if(t(o[l],l,o)===!1)break}return r}}ao.exports=ap});var lo=u((Qy,uo)=>{"use strict";var sp=so(),up=sp();uo.exports=up});var mo=u((se,$)=>{"use strict";var lp=V(),ho=typeof se=="object"&&se&&!se.nodeType&&se,fo=ho&&typeof $=="object"&&$&&!$.nodeType&&$,fp=fo&&fo.exports===ho,co=fp?lp.Buffer:void 0,po=co?co.allocUnsafe:void 0;function cp(e,r){if(r)return e.slice();var t=e.length,n=po?po(t):new e.constructor(t);return e.copy(n),n}$.exports=cp});var yo=u((eb,go)=>{"use strict";var pp=V(),dp=pp.Uint8Array;go.exports=dp});var xo=u((rb,vo)=>{"use strict";var bo=yo();function hp(e){var r=new e.constructor(e.byteLength);return new bo(r).set(new bo(e)),r}vo.exports=hp});var Oo=u((tb,So)=>{"use strict";var mp=xo();function gp(e,r){var t=r?mp(e.buffer):e.buffer;return new e.constructor(t,e.byteOffset,e.length)}So.exports=gp});var To=u((nb,Eo)=>{"use strict";function yp(e,r){var t=-1,n=e.length;for(r||(r=Array(n));++t<n;)r[t]=e[t];return r}Eo.exports=yp});var wo=u((ib,Io)=>{"use strict";var bp=T(),qo=Object.create,vp=function(){function e(){}return function(r){if(!bp(r))return{};if(qo)return qo(r);e.prototype=r;var t=new e;return e.prototype=void 0,t}}();Io.exports=vp});var Ao=u((ob,_o)=>{"use strict";function xp(e,r){return function(t){return e(r(t))}}_o.exports=xp});var Ye=u((ab,Vo)=>{"use strict";var Sp=Ao(),Op=Sp(Object.getPrototypeOf,Object);Vo.exports=Op});var Ze=u((sb,Ro)=>{"use strict";var Ep=Object.prototype;function Tp(e){var r=e&&e.constructor,t=typeof r=="function"&&r.prototype||Ep;return e===t}Ro.exports=Tp});var jo=u((ub,Co)=>{"use strict";var qp=wo(),Ip=Ye(),wp=Ze();function _p(e){return typeof e.constructor=="function"&&!wp(e)?qp(Ip(e)):{}}Co.exports=_p});var Fo=u((lb,Po)=>{"use strict";function Ap(){return!1}Po.exports=Ap});var Qe=u((ue,U)=>{"use strict";var Vp=V(),Rp=Fo(),Mo=typeof ue=="object"&&ue&&!ue.nodeType&&ue,No=Mo&&typeof U=="object"&&U&&!U.nodeType&&U,Cp=No&&No.exports===Mo,Jo=Cp?Vp.Buffer:void 0,jp=Jo?Jo.isBuffer:void 0,Pp=jp||Rp;U.exports=Pp});var Bo=u((fb,Do)=>{"use strict";var Fp=J(),Np=Ye(),Jp=R(),Mp="[object Object]",Lp=Function.prototype,Dp=Object.prototype,Lo=Lp.toString,Bp=Dp.hasOwnProperty,$p=Lo.call(Object);function Up(e){if(!Jp(e)||Fp(e)!=Mp)return!1;var r=Np(e);if(r===null)return!0;var t=Bp.call(r,"constructor")&&r.constructor;return typeof t=="function"&&t instanceof t&&Lo.call(t)==$p}Do.exports=Up});var Uo=u((cb,$o)=>{"use strict";var Hp=J(),zp=Ge(),Gp=R(),Wp="[object Arguments]",kp="[object Array]",Kp="[object Boolean]",Xp="[object Date]",Yp="[object Error]",Zp="[object Function]",Qp="[object Map]",ed="[object Number]",rd="[object Object]",td="[object RegExp]",nd="[object Set]",id="[object String]",od="[object WeakMap]",ad="[object ArrayBuffer]",sd="[object DataView]",ud="[object Float32Array]",ld="[object Float64Array]",fd="[object Int8Array]",cd="[object Int16Array]",pd="[object Int32Array]",dd="[object Uint8Array]",hd="[object Uint8ClampedArray]",md="[object Uint16Array]",gd="[object Uint32Array]",m={};m[ud]=m[ld]=m[fd]=m[cd]=m[pd]=m[dd]=m[hd]=m[md]=m[gd]=!0;m[Wp]=m[kp]=m[ad]=m[Kp]=m[sd]=m[Xp]=m[Yp]=m[Zp]=m[Qp]=m[ed]=m[rd]=m[td]=m[nd]=m[id]=m[od]=!1;function yd(e){return Gp(e)&&zp(e.length)&&!!m[Hp(e)]}$o.exports=yd});var zo=u((le,H)=>{"use strict";var bd=Je(),Ho=typeof le=="object"&&le&&!le.nodeType&&le,fe=Ho&&typeof H=="object"&&H&&!H.nodeType&&H,vd=fe&&fe.exports===Ho,er=vd&&bd.process,xd=function(){try{var e=fe&&fe.require&&fe.require("util").types;return e||er&&er.binding&&er.binding("util")}catch{}}();H.exports=xd});var rr=u((pb,ko)=>{"use strict";var Sd=Uo(),Od=ve(),Go=zo(),Wo=Go&&Go.isTypedArray,Ed=Wo?Od(Wo):Sd;ko.exports=Ed});var tr=u((db,Ko)=>{"use strict";function Td(e,r){if(!(r==="constructor"&&typeof e[r]=="function")&&r!="__proto__")return e[r]}Ko.exports=Td});var nr=u((hb,Xo)=>{"use strict";var qd=qe(),Id=te(),wd=Object.prototype,_d=wd.hasOwnProperty;function Ad(e,r,t){var n=e[r];(!(_d.call(e,r)&&Id(n,t))||t===void 0&&!(r in e))&&qd(e,r,t)}Xo.exports=Ad});var Zo=u((mb,Yo)=>{"use strict";var Vd=nr(),Rd=qe();function Cd(e,r,t,n){var i=!t;t||(t={});for(var o=-1,a=r.length;++o<a;){var s=r[o],l=n?n(t[s],e[s],s,t,e):void 0;l===void 0&&(l=e[s]),i?Rd(t,s,l):Vd(t,s,l)}return t}Yo.exports=Cd});var ea=u((gb,Qo)=>{"use strict";function jd(e,r){for(var t=-1,n=Array(e);++t<e;)n[t]=r(t);return n}Qo.exports=jd});var Ie=u((yb,ra)=>{"use strict";var Pd=9007199254740991,Fd=/^(?:0|[1-9]\d*)$/;function Nd(e,r){var t=typeof e;return r=r??Pd,!!r&&(t=="number"||t!="symbol"&&Fd.test(e))&&e>-1&&e%1==0&&e<r}ra.exports=Nd});var na=u((bb,ta)=>{"use strict";var Jd=ea(),Md=xe(),Ld=C(),Dd=Qe(),Bd=Ie(),$d=rr(),Ud=Object.prototype,Hd=Ud.hasOwnProperty;function zd(e,r){var t=Ld(e),n=!t&&Md(e),i=!t&&!n&&Dd(e),o=!t&&!n&&!i&&$d(e),a=t||n||i||o,s=a?Jd(e.length,String):[],l=s.length;for(var f in e)(r||Hd.call(e,f))&&!(a&&(f=="length"||i&&(f=="offset"||f=="parent")||o&&(f=="buffer"||f=="byteLength"||f=="byteOffset")||Bd(f,l)))&&s.push(f);return s}ta.exports=zd});var oa=u((vb,ia)=>{"use strict";function Gd(e){var r=[];if(e!=null)for(var t in Object(e))r.push(t);return r}ia.exports=Gd});var sa=u((xb,aa)=>{"use strict";var Wd=T(),kd=Ze(),Kd=oa(),Xd=Object.prototype,Yd=Xd.hasOwnProperty;function Zd(e){if(!Wd(e))return Kd(e);var r=kd(e),t=[];for(var n in e)n=="constructor"&&(r||!Yd.call(e,n))||t.push(n);return t}aa.exports=Zd});var ir=u((Sb,ua)=>{"use strict";var Qd=na(),eh=sa(),rh=Oe();function th(e){return rh(e)?Qd(e,!0):eh(e)}ua.exports=th});var fa=u((Ob,la)=>{"use strict";var nh=Zo(),ih=ir();function oh(e){return nh(e,ih(e))}la.exports=oh});var ga=u((Eb,ma)=>{"use strict";var ca=Xe(),ah=mo(),sh=Oo(),uh=To(),lh=jo(),pa=xe(),da=C(),fh=Ee(),ch=Qe(),ph=me(),dh=T(),hh=Bo(),mh=rr(),ha=tr(),gh=fa();function yh(e,r,t,n,i,o,a){var s=ha(e,t),l=ha(r,t),f=a.get(l);if(f){ca(e,t,f);return}var c=o?o(s,l,t+"",e,r,a):void 0,p=c===void 0;if(p){var h=da(l),b=!h&&ch(l),x=!h&&!b&&mh(l);c=l,h||b||x?da(s)?c=s:fh(s)?c=uh(s):b?(p=!1,c=ah(l,!0)):x?(p=!1,c=sh(l,!0)):c=[]:hh(l)||pa(l)?(c=s,pa(s)?c=gh(s):(!dh(s)||ph(s))&&(c=lh(l))):p=!1}p&&(a.set(l,c),i(c,l,n,o,a),a.delete(l)),ca(e,t,c)}ma.exports=yh});var or=u((Tb,ba)=>{"use strict";var bh=to(),vh=Xe(),xh=lo(),Sh=ga(),Oh=T(),Eh=ir(),Th=tr();function ya(e,r,t,n,i){e!==r&&xh(r,function(o,a){if(i||(i=new bh),Oh(o))Sh(e,r,a,t,ya,n,i);else{var s=n?n(Th(e,a),o,a+"",e,r,i):void 0;s===void 0&&(s=o),vh(e,a,s)}},Eh)}ba.exports=ya});var xa=u((qb,va)=>{"use strict";var qh=te(),Ih=Oe(),wh=Ie(),_h=T();function Ah(e,r,t){if(!_h(t))return!1;var n=typeof r;return(n=="number"?Ih(t)&&wh(r,t.length):n=="string"&&r in t)?qh(t[r],e):!1}va.exports=Ah});var ar=u((Ib,Sa)=>{"use strict";var Vh=Se(),Rh=xa();function Ch(e){return Vh(function(r,t){var n=-1,i=t.length,o=i>1?t[i-1]:void 0,a=i>2?t[2]:void 0;for(o=e.length>3&&typeof o=="function"?(i--,o):void 0,a&&Rh(t[0],t[1],a)&&(o=i<3?void 0:o,i=1),r=Object(r);++n<i;){var s=t[n];s&&e(r,s,n,o)}return r})}Sa.exports=Ch});var Ea=u((wb,Oa)=>{"use strict";var jh=or(),Ph=ar(),Fh=Ph(function(e,r,t){jh(e,r,t)});Oa.exports=Fh});var qa=u((_b,Ta)=>{"use strict";var Nh=or(),Jh=ar(),Mh=Jh(function(e,r,t,n){Nh(e,r,t,n)});Ta.exports=Mh});var _a=u((Ab,wa)=>{"use strict";var Lh=nr(),Dh=ke(),Bh=Ie(),Ia=T(),$h=Ke();function Uh(e,r,t,n){if(!Ia(e))return e;r=Dh(r,e);for(var i=-1,o=r.length,a=o-1,s=e;s!=null&&++i<o;){var l=$h(r[i]),f=t;if(l==="__proto__"||l==="constructor"||l==="prototype")return e;if(i!=a){var c=s[l];f=n?n(c,l,s):void 0,f===void 0&&(f=Ia(c)?c:Bh(r[i+1])?[]:{})}Lh(s,l,f),s=s[l]}return e}wa.exports=Uh});var Va=u((Vb,Aa)=>{"use strict";var Hh=_a();function zh(e,r,t){return e==null?e:Hh(e,r,t)}Aa.exports=zh});var Ir=w(Sr(),1);function Or(e){if(e===0)return 0;let r=e/1024;return Number.parseFloat(r.toFixed(2))}var Er="yyyy-MM-dd";function Tr(e,r){let t=new Date(e).getTime(),n=new Date(r).getTime();return t<n?"LESSER":t>n?"GREATER":"EQUAL"}function ka(e,r){let t=Tr(e,r);return t==="GREATER"||t==="EQUAL"}function Ka(e,r){let t=Tr(e,r);return t==="LESSER"||t==="EQUAL"}function qr(e,r,t,n=[]){let i=typeof e=="string",o=e==="",a=e===void 0||e===null&&t.treatNullAsUndefined,s=o||a,l=[];if(!i||s||r["x-jsf-presentation"]===void 0)return l;let{minDate:f,maxDate:c}=r["x-jsf-presentation"];return f&&!ka(e,f)&&l.push({path:n,validation:"minDate"}),c&&!Ka(e,c)&&l.push({path:n,validation:"maxDate"}),l}function wr(e,r,t,n){let i=e["x-jsf-presentation"];switch(t){case"type":return Xa(e.type);case"required":return e["x-jsf-presentation"]?.inputType==="checkbox"?"Please acknowledge this field":"Required field";case"valid":return"Always fails";case"const":return`The only accepted value is ${JSON.stringify(e.const)}.`;case"enum":return`The option "${Ce(r)}" is not valid.`;case"anyOf":return`The option "${Ce(r)}" is not valid.`;case"oneOf":return`The option "${Ce(r)}" is not valid.`;case"not":return"The value must not satisfy the provided schema";case"minLength":return`Please insert at least ${e.minLength} characters`;case"maxLength":return`Please insert up to ${e.maxLength} characters`;case"pattern":return`Must have a valid format. E.g. ${(0,Ir.randexp)(e.pattern||"")}`;case"format":if(e.format==="email")return"Please enter a valid email address";if(e.format==="date"){let o=new Date().toISOString().split("T")[0];return`Must be a valid date in ${Er.toLowerCase()} format. e.g. ${o}`}return`Must be a valid ${e.format} format`;case"multipleOf":return`Must be a multiple of ${e.multipleOf}`;case"maximum":return`Must be smaller or equal to ${e.maximum}`;case"exclusiveMaximum":return`Must be smaller than ${e.exclusiveMaximum}`;case"minimum":return`Must be greater or equal to ${e.minimum}`;case"exclusiveMinimum":return`Must be greater than ${e.exclusiveMinimum}`;case"minDate":return`The date must be ${i?.minDate} or after.`;case"maxDate":return`The date must be ${i?.maxDate} or before.`;case"fileStructure":return"Not a valid file.";case"maxFileSize":{let o=i?.maxFileSize,a=typeof o=="number"?Or(o):void 0;return`File size too large.${a?` The limit is ${a} MB.`:""}`}case"accept":{let o=i?.accept;return`Unsupported file format.${o?` The acceptable formats are ${o}.`:""}`}case"minItems":throw new Error("Array support is not implemented yet");case"maxItems":throw new Error("Array support is not implemented yet");case"uniqueItems":throw new Error("Array support is not implemented yet");case"contains":throw new Error("Array support is not implemented yet");case"minContains":throw new Error("Array support is not implemented yet");case"maxContains":throw new Error("Array support is not implemented yet");case"json-logic":return n||"The value is not valid"}}function Xa(e){if(Array.isArray(e))return`The value must be a ${e.map(t=>t==="integer"?"number":t).join(" or ")}`;switch(e){case"number":case"integer":return"The value must be a number";case"boolean":return"The value must be a boolean";case"null":return"The value must be null";case"string":return"The value must be a string";case"object":return"The value must be an object";case"array":return"The value must be an array";default:return e?`The value must be ${e}`:"Invalid value"}}function Ce(e){return typeof e=="string"?e:JSON.stringify(e)}function Ya(e){let{fields:r,order:t}=e,n={};return t.forEach((o,a)=>{n[o]=a}),r.sort((o,a)=>{let s=n[o.name]??1/0,l=n[a.name]??1/0;return s!==l?s-l:r.indexOf(o)-r.indexOf(a)})}function _r(e){let{schema:r,fields:t}=e;if(typeof r=="boolean")throw new Error("Schema must be an object");return r["x-jsf-order"]!==void 0?Ya({fields:t,order:r["x-jsf-order"]}):t}function Za(e){return Array.isArray(e.type)?"select":e.type!==void 0?e.type:"text"}function Qa(e,r){if(!e)return"text";switch(e){case"string":{let{oneOf:t,format:n}=r;return n==="email"?"email":n==="date"?"date":n==="data-url"?"file":t?"radio":"text"}case"number":case"integer":return"number";case"object":return"fieldset";case"array":{let{items:t}=r;return t?.properties?"group-array":"select"}case"boolean":return"checkbox";default:return"text"}}function es(e,r){let t=e["x-jsf-presentation"];if(t?.inputType)return t.inputType;if(r)throw new Error(`Strict error: Missing inputType to field "${e.title}".
|
|
2
|
+
You can fix the json schema or skip this error by calling createHeadlessForm(schema, { strictInputType: false })`);if(!e.type){if(e.items?.properties)return"group-array";if(e.properties)return"select"}return Qa(e.type||"string",e)}function je(e){return e.filter(r=>r!==null&&typeof r=="object"&&r.const!==null).map(r=>{let t=r.title,n=r.const,o=r["x-jsf-presentation"]?.meta,a={label:t||"",value:n};o&&(a.meta=o);let{title:s,const:l,"x-jsf-presentation":f,...c}=r;return{...a,...c}})}function rs(e){return e.oneOf?je(e.oneOf||[]):e.items?.anyOf?je(e.items.anyOf):e.anyOf?je(e.anyOf):null}var ts=["title","type","x-jsf-errorMessage","x-jsf-presentation","oneOf","anyOf","items"];function he(e,r,t=!1,n=!1){if(typeof e=="boolean")return null;if(e.type==="object"){let f={...e,type:"object"};return Y(f,r,t)}if(e.type==="array")throw new TypeError("Array type is not yet supported");let i=e["x-jsf-presentation"]||{},o=e["x-jsf-errorMessage"],a=es(e,n),s={...Object.entries(e).filter(([f])=>!ts.includes(f)).reduce((f,[c,p])=>({...f,[c]:p}),{}),type:a,name:r,inputType:a,jsonType:Za(e),required:t,isVisible:!0,...o&&{errorMessage:o}};e.const&&(s.const=e.const,a==="checkbox"&&(s.checkboxValue=e.const)),e.title&&(s.label=e.title),Object.keys(i).length>0&&Object.entries(i).forEach(([f,c])=>{f!=="inputType"&&(s[f]=c)});let l=rs(e);return l&&(s.options=l),s}function Y(e,r,t,n){let i=[];for(let s in e.properties){let l=e.required?.includes(s)||!1,f=he(e.properties[s],s,l,n);f&&i.push(f)}let o=_r({fields:i,schema:e}),a={...e["x-jsf-presentation"],type:e["x-jsf-presentation"]?.inputType||"fieldset",inputType:e["x-jsf-presentation"]?.inputType||"fieldset",jsonType:"object",name:r,required:t,fields:o,isVisible:!0};return e.title!==void 0&&(a.label=e.title),e.description!==void 0&&(a.description=e.description),e["x-jsf-presentation"]?.accept&&(a.accept=e["x-jsf-presentation"]?.accept),a}function S(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function E(e,r){if(typeof e!=typeof r)return!1;if(e===r)return!0;if(e===null||r===null)return!1;if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((t,n)=>E(t,r[n]));if(S(e)&&S(r)){let t=Object.keys(e).sort(),n=Object.keys(r).sort();return t.length!==n.length||!E(t,n)?!1:t.every(i=>E(e[i],r[i]))}return!1}function Ar(e,r,t,n,i){return Array.isArray(e)?[...ns(r,e,i),...ss(r,e,i),...as(e,r,t,n,i),...os(r,e,t,n,i),...is(r,e,t,n,i)]:[]}function ns(e,r,t){let n=[],i=r.length;return e.maxItems!==void 0&&i>e.maxItems&&n.push({path:t,validation:"maxItems"}),e.minItems!==void 0&&i<e.minItems&&n.push({path:t,validation:"minItems"}),n}function is(e,r,t,n,i){if(e.items===void 0)return[];let o=[],a=Array.isArray(e.prefixItems)?e.prefixItems.length:0;for(let[s,l]of r.slice(a).entries())o.push(...y(l,e.items,t,[...i,"items",s+a],n));return o}function os(e,r,t,n,i){if(!Array.isArray(e.prefixItems))return[];let o=[];for(let[a,s]of r.entries())a<e.prefixItems.length&&o.push(...y(s,e.prefixItems[a],t,[...i,"prefixItems",a],n));return o}function as(e,r,t,n,i){if(!("contains"in r))return[];let o=[],a=e.filter(s=>y(s,r.contains,t,[...i,"contains"],n).length===0).length;return r.minContains===void 0&&r.maxContains===void 0?a<1&&o.push({path:i,validation:"contains"}):(r.minContains!==void 0&&a<r.minContains&&o.push({path:i,validation:"minContains"}),r.maxContains!==void 0&&a>r.maxContains&&o.push({path:i,validation:"maxContains"})),o}function ss(e,r,t){if(e.uniqueItems!==!0)return[];let n=new Map;for(let i=0;i<r.length;i++){for(let o of n.values())if(E(r[i],o))return[{path:t,validation:"uniqueItems"}];n.set(i,r[i])}return[]}function Vr(e,r,t,n,i=[]){if(!r.allOf)return[];for(let o=0;o<r.allOf.length;o++){let a=r.allOf[o],s=y(e,a,t,[...i,"allOf",o],n);if(s.length>0)return s}return[]}function Rr(e,r,t,n,i=[]){if(!r.anyOf)return[];for(let o of r.anyOf)if(y(e,o,t,i,n).length===0)return[];return[{path:i,validation:"anyOf"}]}function Cr(e,r,t,n,i=[]){if(!r.oneOf)return[];let o=0;for(let a=0;a<r.oneOf.length&&!(y(e,r.oneOf[a],t,i,n).length===0&&(o++,o>1));a++);return o===0?[{path:i,validation:"oneOf"}]:o>1?[{path:i,validation:"oneOf"}]:[]}function jr(e,r,t,n,i=[]){return r.not===void 0?[]:typeof r.not=="boolean"?r.not?[{path:i,validation:"not"}]:[]:y(e,r.not,t,i,n).length===0?[{path:i,validation:"not"}]:[]}function Pr(e,r,t,n,i=[]){if(r.if===void 0)return[];let o=y(e,r.if,t,i,n).length===0;return o&&r.then!==void 0?y(e,r.then,t,[...i,"then"],n):!o&&r.else!==void 0?y(e,r.else,t,[...i,"else"],n):[]}function Fr(e,r,t=[]){return r.const===void 0?[]:E(r.const,e)?[]:[{path:t,validation:"const"}]}function Nr(e,r,t=[]){return r.enum===void 0?[]:r.enum.some(n=>E(n,e))?[]:[{path:t,validation:"enum"}]}function Jr(e,r,t=[]){let n=r["x-jsf-presentation"],i=n?.inputType==="file",o=typeof n?.maxFileSize=="number"||typeof n?.accept=="string";if(!(i||o))return[];if(!Array.isArray(e))return[];if(e.length===0)return[];if(!e.every(f=>S(f)&&typeof f.name=="string"&&typeof f.size=="number"))return[{path:t,validation:"fileStructure"}];let l=e;if(typeof n?.maxFileSize=="number"){let f=n.maxFileSize*1024;if(l.some(p=>p.size>f))return[{path:t,validation:"maxFileSize"}]}if(typeof n?.accept=="string"&&n.accept.trim()!==""){let f=n.accept.toLowerCase().split(",").map(c=>c.trim()).filter(c=>c).map(c=>c.startsWith(".")?c:`.${c}`);if(f.length>0&&!l.some(p=>{let h=p.name.toLowerCase(),b=h.includes(".")?`.${h.split(".").pop()}`:"";return b!==""&&f.includes(b)}))return[{path:t,validation:"accept"}]}return[]}import us from"json-logic-js";function ls(e={}){return Object.entries(e).reduce((r,[t,n])=>({...r,[t]:n??Number.NaN}),{})}function Mr(e,r,t=[]){let n=e["x-jsf-logic-validations"];return!n||n.length===0?[]:n.map(i=>{let o=r?.schema?.validations?.[i],a=r?.value;return o?us.apply(o.rule,ls(a))===!1?[{path:t,validation:"json-logic",customErrorMessage:o.errorMessage}]:[]:[]}).flat()}function Lr(e,r,t=[]){let n=[],i=Z(r);return typeof e!="number"?[]:i!==void 0&&!["number","integer"].includes(i)?[]:(r.multipleOf!==void 0&&e%r.multipleOf!==0&&n.push({path:t,validation:"multipleOf"}),r.maximum!==void 0&&e>r.maximum&&n.push({path:t,validation:"maximum"}),r.exclusiveMaximum!==void 0&&e>=r.exclusiveMaximum&&n.push({path:t,validation:"exclusiveMaximum"}),r.minimum!==void 0&&e<r.minimum&&n.push({path:t,validation:"minimum"}),r.exclusiveMinimum!==void 0&&e<=r.exclusiveMinimum&&n.push({path:t,validation:"exclusiveMinimum"}),n)}function Dr(e,r,t,n,i=[]){if(typeof r=="object"&&r.properties&&S(e)){let o=[];for(let[a,s]of Object.entries(r.properties))o.push(...y(e[a],s,t,[...i,a],n));return o}return[]}var Br;(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"})(Br||(Br={}));var g;(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"})(g||(g={}));var $r;(function(e){e.Array="array",e.Boolean="boolean",e.Integer="integer",e.Null="null",e.Number="number",e.Object="object",e.String="string"})($r||($r={}));var v={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},fs={[g.DateTime]:e=>v.DATE_TIME.test(e),[g.Date]:e=>v.DATE.test(e),[g.Time]:e=>v.TIME.test(e),[g.Duration]:e=>v.DURATION.test(e),[g.Email]:e=>e.length<=254&&v.EMAIL.test(e),[g.IDNEmail]:e=>e.length<=254&&v.IDN_EMAIL.test(e),[g.Hostname]:e=>e.length>255?!1:e.split(".").every(t=>v.HOSTNAME.test(t)),[g.IDNHostname]:e=>e.length>255?!1:e.split(".").every(t=>t.length<=63&&v.IDN_HOSTNAME.test(t)),[g.IPv4]:e=>{let r=e.split(".");return r.length!==4?!1:r.every(t=>{let n=Number.parseInt(t,10);return n>=0&&n<=255&&t===n.toString()})},[g.IPv6]:e=>{let r=e.split(":");if(r.length>8)return!1;let t=!1;return r.every(n=>n===""?t?!1:(t=!0,!0):v.IPV6_PART.test(n))},[g.URI]:e=>{try{let r=new URL(e);return r.protocol!==""&&v.PROTOCOL.test(r.protocol)}catch{return!1}},[g.URIReference]:e=>{try{return e.startsWith("//")?v.URI_REFERENCE.test(e.slice(2)):(new URL(e,"http://example.com"),!0)}catch{return!1}},[g.IRI]:e=>{try{let r=new URL(e);return r.protocol!==""&&v.PROTOCOL.test(r.protocol)}catch{return!1}},[g.IRIReference]:e=>{try{return e.startsWith("//")?v.URI_REFERENCE.test(e.slice(2)):(new URL(e,"http://example.com"),!0)}catch{return!1}},[g.RegEx]:e=>{try{return new RegExp(e,"u"),!0}catch{return!1}},[g.UUID]:e=>v.UUID.test(e),[g.JSONPointer]:e=>v.JSON_POINTER.test(e),[g.JSONPointerURIFragment]:e=>v.JSON_POINTER_URI_FRAGMENT.test(e),[g.RelativeJSONPointer]:e=>v.RELATIVE_JSON_POINTER.test(e),[g.URITemplate]:e=>v.URI_TEMPLATE.test(e)};function Ur(e,r,t=[]){let n=[];if(typeof e!="string")return n;let i=fs[r];return i&&!i(e)&&n.push({path:t,validation:"format"}),n}function Hr(e,r,t=[]){let n=[],i=Z(r);if(typeof e!="string")return[];if(i!==void 0&&i!=="string")return[];let o=[...new Intl.Segmenter().segment(e)].length;if(r.minLength!==void 0&&o<r.minLength&&n.push({path:t,validation:"minLength"}),r.maxLength!==void 0&&o>r.maxLength&&n.push({path:t,validation:"maxLength"}),r.pattern!==void 0&&(new RegExp(r.pattern).test(e)||n.push({path:t,validation:"pattern"})),r.format!==void 0){let a=Ur(e,r.format,t);n.push(...a)}return n}function Z(e){if(typeof e=="boolean")return"boolean";if(e.type!==void 0)return e.type}function cs(e,r,t=[]){let n=Z(r);if(n===void 0)return[];if(n==="null"&&e===null)return[];let i=e===null?"null":Array.isArray(e)?"array":typeof e;if(Array.isArray(n)){if(e===null&&n.includes("null"))return[];for(let o of n){if(o==="array"&&Array.isArray(e))return[];if(i==="number"&&o==="integer"&&Number.isInteger(e))return[];if(i===o||o==="null"&&e===null)return[]}}else{if(n==="array"&&Array.isArray(e))return[];if(i==="number"&&n==="integer"&&Number.isInteger(e))return[];if(i===n)return[]}return[{path:t,validation:"type"}]}function y(e,r,t={},n=[],i){let o=i;!i&&r["x-jsf-logic"]&&(o={schema:r["x-jsf-logic"],value:e});let a=e===void 0||e===null&&t.treatNullAsUndefined,s=[];if(a)return[];if(typeof r=="boolean")return r?[]:[{path:n,validation:"valid"}];let f=r["x-jsf-presentation"]?.inputType==="file",c=[];if(!f&&(c=cs(e,r,n),c.length>0))return c;if(r.required&&S(e)){let p=r.required.filter(h=>{let b=e[h];return b===void 0||b===null&&t.treatNullAsUndefined});for(let h of p)s.push({path:[...n,h],validation:"required"})}return[...s,...Fr(e,r,n),...Nr(e,r,n),...Dr(e,r,t,o,n),...Ar(e,r,t,o,n),...Hr(e,r,n),...Lr(e,r,n),...Jr(e,r,n),...jr(e,r,t,o,n),...Vr(e,r,t,o,n),...Rr(e,r,t,o,n),...Cr(e,r,t,o,n),...Pr(e,r,t,o,n),...qr(e,r,t,n),...Mr(r,o,n)]}function Ne(e,r,t,n={}){if(S(r)){Pe(e,r,t,n);for(let i in t.properties){let o=t.properties[i],a=e.find(s=>s.name===i);a?.fields&&Pe(a.fields,r[i],o,n)}}}function zr(e,r,t,n={}){let o=y(e,t.if,n).length===0,a=!1;return o&&t.if?.required&&(a=t.if.required.some(l=>{if(!r.properties||!r.properties[l])return!1;let f=r.properties[l],c=e[l];return y(c,f,n).some(h=>h.validation==="type")})),{rule:t,matches:o&&!a}}function Pe(e,r,t,n={}){if(!S(r))return;let i=[];t.if&&i.push(zr(r,t,t,n)),(t.allOf??[]).filter(o=>typeof o.if<"u").forEach(o=>{let a=zr(r,t,o,n);i.push(a)});for(let{rule:o,matches:a}of i)a&&o.then?Fe(e,r,o.then,n):!a&&o.else&&Fe(e,r,o.else,n)}function Fe(e,r,t,n={}){if(t.properties)for(let i in t.properties){let o=t.properties[i],a=e.find(s=>s.name===i);if(a){o===!1?a.isVisible=!1:a?.fields&&Fe(a.fields,r,o);let s=he(o,i,!0);for(let l in s)["type"].includes(l)||(a[l]=s[l])}}Pe(e,r,t,n)}function ps(e){let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(["allOf","anyOf","oneOf"].includes(n)){t+1<e.length&&typeof e[t+1]=="number"&&t++;continue}n==="then"||n==="else"||r.push(n)}return r}function ds(e){return e.length===0?null:e.reduce((r,t)=>{let{path:n}=t;if(n.length===0)return r[""]=t.message,r;let i=ps(n),o=r;if(i.slice(0,-1).forEach(a=>{(!(a in o)||typeof o[a]=="string")&&(o[a]={}),o=o[a]}),i.length>0){let a=i[i.length-1];o[a]=t.message}else r[""]=t.message;return r},{})}function hs(e,r,t){let n=e,i=r;for(let o of t)if(typeof n=="object"&&n!==null)if(n.properties&&n.properties[o])n=n.properties[o],S(i)&&(i=i[o]);else if(n.items&&typeof n.items!="boolean")n=n.items,Array.isArray(i)&&(i=i[Number(o)]);else{if(o==="allOf"&&n.allOf)continue;if(o==="anyOf"&&n.anyOf)continue;if(o==="oneOf"&&n.oneOf)continue;if((o==="then"||o==="else")&&n[o]){n=n[o];continue}else if(n.allOf||n.anyOf||n.oneOf){let a=Number(o);n.allOf&&a>=0&&a<n.allOf.length?n=n.allOf[a]:n.anyOf&&a>=0&&a<n.anyOf.length?n=n.anyOf[a]:n.oneOf&&a>=0&&a<n.oneOf.length&&(n=n.oneOf[a])}}return{schema:n,value:i}}function ms(e,r,t){return t.map(n=>{let{schema:i,value:o}=hs(r,e,n.path);return{...n,message:wr(i,o,n.validation,n.customErrorMessage)}})}function gs(e,r){return typeof r!="object"||!r||!e.length?e:e.map(t=>{if(!t.path.length)return t;let n=typeof r=="object"?r:null,i=null;for(let o of t.path){if(!n||typeof n!="object")break;if(n.properties&&n.properties[o]){let a=n.properties[o];if(typeof a!="boolean")n=a,i=n;else break}else if(n.items&&typeof n.items!="boolean")n=n.items,i=n;else break}return i&&i["x-jsf-errorMessage"]&&i["x-jsf-errorMessage"][t.validation]?{...t,message:i["x-jsf-errorMessage"][t.validation]}:t})}function ys(e,r,t={}){let n={},i=y(e,r,t),o=ms(e,r,i),a=gs(o,r),s=ds(a);return s&&(n.formErrors=s),n}function bs(e){let{schema:r,strictInputType:t}=e;return Y(r,"root",!0,t).fields||[]}function vs(e,r={}){let t=r.initialValues||{},n=r.strictInputType||!1,i=bs({schema:e,strictInputType:n});return Ne(i,t,e),{fields:i,isError:!1,error:null,handleValidation:s=>{let l=ys(s,e,r.validationOptions);return Gr(i,e),Ne(i,s,e,r.validationOptions),l}}}function Gr(e,r){e.length=0;let t=Y(r,"root",!0).fields||[];e.push(...t);for(let n of e)n.fields&&r.properties?.[n.name]?.type==="object"&&Gr(n.fields,r.properties[n.name])}var Ra=w(di(),1),I=w(Ji(),1),z=w(Hi(),1),Ca=w(Ea(),1),ur=w(qa(),1),we=w(Va(),1);function ja(e){return e.replace(".",".properties.")}function Pa(e,r){return Array.isArray(r)?r:void 0}function Gh(e,r){let{if:t,then:n,else:i}=e;return(0,z.default)(t?.required||[],r).length>0||((0,z.default)(n?.required||[],r)||(0,z.default)(Object.keys(n?.properties||{}),r)).length>0||((0,z.default)(i?.required||[],r)||(0,z.default)(Object.keys(i?.properties||{}),r)).length>0}function Fa(e,r){if(!r)return{warnings:null};let t=[];return Object.entries(r).forEach(([i,o])=>{let a=ja(i);if(!(0,I.default)(e.properties,a)){t.push({type:"FIELD_TO_CHANGE_NOT_FOUND",message:`Changing field "${i}" was ignored because it does not exist.`});return}let s=(0,I.default)(e.properties,a);if(!s)return{warnings:null};let l=typeof o=="function"?o(s):o,{properties:f,...c}=l;if((0,ur.default)((0,I.default)(e.properties,a),{...s,...c},Pa),l.properties){let p=Fa((0,I.default)(e.properties,a),l.properties);p.warnings&&t.push(...p.warnings)}}),{warnings:t.flat()}}function Na(e,r,t){if(!r||typeof e!="object"||e===null)return{warnings:null};let n=t?.parent;return typeof e=="object"&&e.properties&&Object.entries(e.properties).forEach(([i,o])=>{let a=n?`${n}.${i}`:i;(0,ur.default)((0,I.default)(e.properties,i),{...o,...r(a,o)},Pa),o.properties&&Na(o,r,{parent:i})}),{warnings:null}}function Wh(e,r){if(!r)return{warnings:null};let t=[],n=e["x-jsf-order"]||[],i=typeof r=="function"?r(n):r,o=(0,Ra.default)(n,i);return o.length>0&&t.push({type:"ORDER_MISSING_FIELDS",message:`Some fields got forgotten in the new order. They were automatically appended: ${o.join(", ")}`}),e["x-jsf-order"]=[...i,...o],{warnings:t}}function Ja(e,r){if(!r)return{warnings:null};let t=[];return Object.entries(r).forEach(([i,o])=>{let a=ja(i);if(!o)return{warnings:null};if(o.properties){let f=(0,I.default)(e.properties,a);if(!f)return{warnings:null};let c=Ja(f,o.properties);c.warnings&&t.push(...c.warnings)}if((0,I.default)(e.properties,a)){t.push({type:"FIELD_TO_CREATE_EXISTS",message:`Creating field "${i}" was ignored because it already exists.`});return}let l=(0,we.default)({},a,o);(0,Ca.default)(e.properties,l)}),{warnings:t.flat()}}function kh(e,r){if(!r)return{schema:e,warnings:null};let t={properties:{}};Object.entries(e).forEach(([o,a])=>{switch(o){case"properties":r.forEach(s=>{(0,we.default)(t.properties,s,a[s])});break;case"x-jsf-order":case"required":t[o]=a.filter(s=>r.includes(s));break;case"allOf":{let s=e[o]?.filter(l=>Gh(l,r));t[o]=s;break}case"x-jsf-logic":t[o]=a;break}});let n={};t.allOf?.length&&t.allOf.forEach(o=>{let{if:a,then:s,else:l}=o,f=e.allOf?.indexOf(o);n={...n,...sr(a,{fields:r,path:`allOf[${f}].if`}),...sr(s,{fields:r,path:`allOf[${f}].then`}),...sr(l,{fields:r,path:`allOf[${f}].else`})}});let i=[];return Object.keys(n).length>0&&(Object.entries(n).forEach(([o])=>{(0,we.default)(t.properties,o,e.properties?.[o])}),i.push({type:"PICK_MISSED_FIELD",message:`The picked fields are in conditionals that refeer other fields. They added automatically: ${Object.keys(n).map(o=>`"${o}"`).join(", ")}. Check "meta" for more details.`,meta:n})),{schema:t,warnings:i}}function sr(e,{fields:r,path:t}){if(!e)return null;let n={};return e.required?.forEach(i=>{r.includes(i)||(n[i]={path:t})}),Object.entries(e.properties||[]).forEach(([i])=>{r.includes(i)||(n[i]={path:t})}),n}function Kh(e,r){let t=JSON.parse(JSON.stringify(e)),n=Fa(t,r.fields),i=Na(t,r.allFields),o=Ja(t,r.create),a=kh(t,r.pick),s=a.schema,l=Wh(s,r.orderRoot);r.muteLogging||console.warn("json-schema-form modify(): We highly recommend you to handle/report the returned `warnings` as they highlight possible bugs in your modifications. To mute this log, pass `muteLogging: true` to the config.");let f=[n.warnings,i.warnings,o.warnings,a.warnings,l.warnings].flat().filter(Boolean);return{schema:s,warnings:f}}export{vs as createHeadlessForm,Kh as modify};
|
|
2
3
|
//# sourceMappingURL=index.mjs.map
|