@ghentcdh/json-forms-core 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod");var z=(e=>(e.xs="xs",e.sm="sm",e.lg="lg",e.xl="xl",e))(z||{});const j=e=>{const t=e.anyOf;if(!Array.isArray(t)||t.length!==2)return;const s=t.find(o=>o.type!=="null"),r=t.some(o=>o.type==="null");s&&r&&(delete e.anyOf,Object.assign(e,s))},C=e=>{const t=i.toJSONSchema(e,{unrepresentable:"any",target:"draft-07"});t.additionalProperties=!0;const s=t.properties;if(s)for(const r of Object.keys(s))j(s[r]);return t},P=e=>{if(!e.schema)throw new Error("no schema provided");const t=e.schema,s=e.dtoSchema,r=C(s),o=C(t.partial());return{dtoSchema:s,responseSchema:e.responseSchema??s,schema:{form:{uiSchema:e.uiSchema,schema:r,modalSize:e.modalSize??"sm"},table:e.tableSchema?{uiSchema:e.tableSchema,schema:o}:void 0,filter:e.filterSchema?{uiSchema:e.filterSchema,schema:o}:void 0,uri:e.uri,searchUri:e.searchUri??`${e.uri}?filter=`}}},L=(e,t)=>{if(!e.scope)return{id:null,property:null};const s=e.scope?.substring(13),r=t?.properties?.[s]??{};return{id:s,property:r}},k=(e,t)=>{const{id:s,property:r}=L(e,t);return{...e,id:s,label:s,...r}};class p{constructor(t){this.type=t}}class m extends p{constructor(){super(...arguments),this.elements=[]}addControl(t){return this.elements.push(t),this}addControls(...t){return this.elements.push(...t),this}buildElements(){return this.elements.map(t=>t.build())}}const h={HorizontalLayout:"HorizontalLayout",VerticalLayout:"VerticalLayout",CollapseLayout:"CollapseLayout"};class a extends m{constructor(t,s={}){super(t),this.options=s}static horizontal(){return new a(h.HorizontalLayout)}static collapse(){return new a(h.CollapseLayout)}static vertical(){return new a(h.VerticalLayout)}titleKey(t){return this.addOptions({titleKey:t})}title(t){return this.addOptions({title:t})}addOptions(t){return this.options={...this.options,...t},this}build(){return{type:this.type,elements:this.buildElements(),options:this.options}}}class f extends p{constructor(t,s="TextCell"){super(s),this.scope=t}static properties(t){return new f(`#/properties/${t}`)}key(t){return this.options={format:"keyValue",key:t},this}setSortId(t){return this.options={...this.options??{format:"TextCell"},sortId:t},this}build(){return{type:this.type,scope:this.scope,options:this.options}}}class y{constructor(){this.builder=a.horizontal()}static init(){return new y}addControl(t){return this.builder.addControls(t),this}addControls(...t){return this.builder.addControls(...t),this}build(){return this.builder.build()}}const n={number:"number",string:"string",integer:"Integer",autocomplete:"autocomplete",textArea:"textArea",markdown:"markdown",array:"array",custom:"custom"};class l extends p{constructor(t,s="Control"){super(s),this.scope=t,this.options={format:"Control",styles:{control:{wrapper:"w-full"}}}}static asObject(t){return new l(`#/properties/${t}`,"Object")}static properties(t){return new l(`#/properties/${t}`)}static asCustom(t,s){const r=new l(`#/properties/${t}`);return r.options={format:n.custom,type:s},r}detail(t,s){return this._detail=t,this.options={...this.options??{},format:n.array,elementLabelProp:s},this}addAction(t){const s=this.options?.actions??[];return s.push(t),this.options={...this.options??{},actions:s},this}detailFixed(t,s={}){return this._detail=t,this.options={...this.options??{},hideActions:!0,format:n.array,layout:s.layout??"column",elementLabelProp:s.label},this}labelKey(t){return this.options={...this.options??{},labelKey:t},this}readonly(){return this.options={format:n.string,readonly:!0},this}markdown(){return this.options={format:n.markdown},this}textArea(t){return this.options={format:n.textArea,...t??{}},this}autocomplete(t){return this.options={format:n.autocomplete,dataField:"data",...t},this}width(t){const s={xs:"w-12",sm:"w-24",md:"w-36",lg:"w-48",xl:"w-64",full:"w-full"};return this.addOptions({styles:{...this.options?.styles,control:{wrapper:` ${s[t]??s.sm}`}}})}customLabel(t){return this.addOptions({label:t})}placeHolder(t){return this.addOptions({placeholder:t})}hideLabel(){return this.addOptions({hideLabel:!0})}addOptions(t){return this.options={...this.options,...t},this}build(){return{type:this.type,scope:this.scope,options:{...this.options,detail:this._detail?this._detail?.build():void 0}}}}class b extends m{constructor(t){super(t),this.label=t,this.rule={effect:"SHOW",condition:{}}}static label(t){return new b(t)}build(){return{type:"Category",label:this.label,rule:this.rule,elements:this.buildElements()}}}class S extends m{constructor(t){super(t),this.label=t}static label(t){return new S(t)}build(){return{type:"Group",label:this.label,elements:this.buildElements()}}}const u=()=>i.z.coerce.number().int().positive().nonnegative(),v=()=>i.z.string().or(i.z.array(i.z.string())).transform(e=>Array.isArray(e)?e:[e]),A=i.z.enum(["asc","desc"]),g=i.z.object({page:u().optional().default(1),pageSize:u().optional().default(20),sort:i.z.string().optional().default("id"),sortDir:A.optional().default("asc"),filter:v().optional().default([])}),F=g.transform(e=>{const{page:t,pageSize:s,sort:r}=e;return{...e,sort:r||"id",offset:(t-1)*s}}),R=g.extend({count:u(),totalPages:u()}),K=i.z.object({data:i.z.array(i.z.unknown()),request:R}),q=["contains","equals"],E=e=>{const[t,s,r]=e.split(":"),o=q.includes(r)?r:"contains";return{key:t,value:s,operator:o}},T=(e,t)=>{if(e.length===1)return{key:e[0],filterObj:t};const s=e.pop();return T(e,{[s]:t})},N=(e,t)=>w(e.split("."),t),w=(e,t)=>{if(e.length===1)return{[e[0]]:t};const s=e.pop();return w(e,{[s]:t})},$=e=>{const t={};return e?.forEach(s=>{const{key:r,value:o,operator:c}=E(s);if(!r)return;const d=c||"contains",O={[c||"contains"]:o.toLowerCase()};d==="contains"&&(O.mode="insensitive");const x=T(r.split("."),O);t[x.key]=x.filterObj}),t},H=e=>{const t=[];return e.forEach(s=>{const{key:r,value:o,operator:c}=E(s);if(!r)return;const d=r;t.push({label:d,key:r,value:o,operator:c})}),t};exports.CategoryBuilder=b;exports.ControlBuilder=l;exports.ControlType=n;exports.GroupBuilder=S;exports.LayoutBuilder=a;exports.LayoutTypes=h;exports.Operator=q;exports.PositiveRequestNumber=u;exports.RequestSchema=g;exports.RequestSchemaWithOffset=F;exports.ResponseRequestSchema=R;exports.ResponseSchema=K;exports.Size=z;exports.SortDirEnum=A;exports.StringOrArray=v;exports.TableBuilder=y;exports.TextCellBuilder=f;exports.buildFilter=$;exports.buildSort=N;exports.buildSortKey=w;exports.createSchema=P;exports.extractFilters=H;exports.findColumnDef=k;exports.findProperty=L;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("zod");var z=(e=>(e.xs="xs",e.sm="sm",e.lg="lg",e.xl="xl",e))(z||{});const j=e=>{const t=e.anyOf;if(!Array.isArray(t)||t.length!==2)return;const r=t.find(o=>o.type!=="null"),s=t.some(o=>o.type==="null");r&&s&&(delete e.anyOf,Object.assign(e,r))},w=e=>{const t=n.toJSONSchema(e,{unrepresentable:"any",target:"draft-07"});t.additionalProperties=!0;const r=t.properties;if(r)for(const s of Object.keys(r))j(r[s]);return t},P=e=>{if(!e.schema)throw new Error("no schema provided");const t=e.schema,r=e.dtoSchema,s=w(r),o=w(t.partial());return{dtoSchema:r,responseSchema:e.responseSchema??r,schema:{form:{uiSchema:e.uiSchema,schema:s,modalSize:e.modalSize??"sm"},table:e.tableSchema?{uiSchema:e.tableSchema,schema:o}:void 0,filter:e.filterSchema?{uiSchema:e.filterSchema,schema:o}:void 0,uri:e.uri,searchUri:e.searchUri??`${e.uri}?filter=`}}},L=(e,t)=>{if(!e.scope)return{id:null,property:null};const r=e.scope?.substring(13),s=t?.properties?.[r]??{};return{id:r,property:s}},k=(e,t)=>{const{id:r,property:s}=L(e,t);return{...e,id:r,label:r,...s}};class p{constructor(t){this.type=t}}class m extends p{constructor(){super(...arguments),this.elements=[]}addControl(t){return this.elements.push(t),this}addControls(...t){return this.elements.push(...t),this}buildElements(){return this.elements.map(t=>t.build())}}const l={HorizontalLayout:"HorizontalLayout",VerticalLayout:"VerticalLayout",CollapseLayout:"CollapseLayout",GridLayout:"GridLayout"};class a extends m{constructor(t,r={}){super(t),this.options=r}static horizontal(){return new a(l.HorizontalLayout)}static collapse(){return new a(l.CollapseLayout)}static vertical(){return new a(l.VerticalLayout)}static grid(){return new a(l.GridLayout)}titleKey(t){return this.addOptions({titleKey:t})}title(t){return this.addOptions({title:t})}addOptions(t){return this.options={...this.options,...t},this}build(){return{type:this.type,elements:this.buildElements(),options:this.options}}}class y extends p{constructor(t,r="TextCell"){super(r),this.scope=t}static properties(t){return new y(`#/properties/${t}`)}key(t){return this.options={format:"keyValue",key:t},this}setSortId(t){return this.options={...this.options??{format:"TextCell"},sortId:t},this}build(){return{type:this.type,scope:this.scope,options:this.options}}}class b{constructor(){this.builder=a.horizontal()}static init(){return new b}addControl(t){return this.builder.addControls(t),this}addControls(...t){return this.builder.addControls(...t),this}build(){return this.builder.build()}}const i={number:"number",string:"string",integer:"Integer",autocomplete:"autocomplete",textArea:"textArea",markdown:"markdown",array:"array",custom:"custom",select:"select",mutliSelect:"mutliSelect",boolean:"boolean"};class u extends p{constructor(t,r="Control"){super(r),this.scope=t,this.options={format:"Control",styles:{}}}static asObject(t){return new u(`#/properties/${t}`,"Object")}static properties(t){return new u(`#/properties/${t}`)}static asCustom(t,r){const s=new u(`#/properties/${t}`);return s.addOptions({format:i.custom,type:r}),s}detail(t,r){return this._detail=t,this.addOptions({format:i.array,elementLabelProp:r}),this}addAction(t){const r=this.options?.actions??[];return r.push(t),this.addOptions({actions:r})}detailFixed(t,r={}){return this._detail=t,this.addOptions({hideActions:!0,format:i.array,layout:r.layout??"column",elementLabelProp:r.label})}labelKey(t){return this.addOptions({labelKey:t})}readonly(){return this.addOptions({format:i.string,readonly:!0})}markdown(t){return this.addOptions({format:i.markdown,...t??{}})}textArea(t){return this.addOptions({format:i.textArea,...t??{}})}autocomplete(t){return this.addOptions({format:i.autocomplete,dataField:"data",...t??{}})}control(t,r){return this.addOptions({format:t,...r})}select(t){return this.addOptions({format:i.select,...t})}mutliSelect(t){return this.addOptions({format:i.mutliSelect,...t})}width(t){return this.addOptions({styles:{...this.options?.styles,width:t,control:{wrapper:`input-${t}`}}})}customLabel(t){return this.addOptions({label:t})}placeHolder(t){return this.addOptions({placeholder:t})}hideLabel(){return this.addOptions({hideLabel:!0})}addOptions(t){return this.options={...this.options,...t},this}build(){return{type:this.type,scope:this.scope,options:{...this.options,detail:this._detail?this._detail?.build():void 0}}}}class f extends m{constructor(t){super(t),this.label=t,this.rule={effect:"SHOW",condition:{}}}static label(t){return new f(t)}build(){return{type:"Category",label:this.label,rule:this.rule,elements:this.buildElements()}}}class S extends m{constructor(t){super(t),this.label=t}static label(t){return new S(t)}build(){return{type:"Group",label:this.label,elements:this.buildElements()}}}const c=()=>n.z.coerce.number().int().positive().nonnegative(),v=()=>n.z.string().or(n.z.array(n.z.string())).transform(e=>Array.isArray(e)?e:[e]),A=n.z.enum(["asc","desc"]),O=n.z.object({page:c().optional().default(1),pageSize:c().optional().default(20),sort:n.z.string().optional().default("id"),sortDir:A.optional().default("asc"),filter:v().optional().default([])}),F=O.transform(e=>{const{page:t,pageSize:r,sort:s}=e;return{...e,sort:s||"id",offset:(t-1)*r}}),R=O.extend({count:c(),totalPages:c()}),K=n.z.object({data:n.z.array(n.z.unknown()),request:R}),q=["contains","equals"],E=e=>{const[t,r,s]=e.split(":"),o=q.includes(s)?s:"contains";return{key:t,value:r,operator:o}},T=(e,t)=>{if(e.length===1)return{key:e[0],filterObj:t};const r=e.pop();return T(e,{[r]:t})},N=(e,t)=>g(e.split("."),t),g=(e,t)=>{if(e.length===1)return{[e[0]]:t};const r=e.pop();return g(e,{[r]:t})},$=e=>{const t={};return e?.forEach(r=>{const{key:s,value:o,operator:d}=E(r);if(!s)return;const h=d||"contains",x={[d||"contains"]:o.toLowerCase()};h==="contains"&&(x.mode="insensitive");const C=T(s.split("."),x);t[C.key]=C.filterObj}),t},G=e=>{const t=[];return e.forEach(r=>{const{key:s,value:o,operator:d}=E(r);if(!s)return;const h=s;t.push({label:h,key:s,value:o,operator:d})}),t};exports.CategoryBuilder=f;exports.ControlBuilder=u;exports.ControlType=i;exports.GroupBuilder=S;exports.LayoutBuilder=a;exports.LayoutTypes=l;exports.Operator=q;exports.PositiveRequestNumber=c;exports.RequestSchema=O;exports.RequestSchemaWithOffset=F;exports.ResponseRequestSchema=R;exports.ResponseSchema=K;exports.Size=z;exports.SortDirEnum=A;exports.StringOrArray=v;exports.TableBuilder=b;exports.TextCellBuilder=y;exports.buildFilter=$;exports.buildSort=N;exports.buildSortKey=g;exports.createSchema=P;exports.extractFilters=G;exports.findColumnDef=k;exports.findProperty=L;
package/index.js CHANGED
@@ -3,34 +3,34 @@ var E = /* @__PURE__ */ ((e) => (e.xs = "xs", e.sm = "sm", e.lg = "lg", e.xl = "
3
3
  const j = (e) => {
4
4
  const t = e.anyOf;
5
5
  if (!Array.isArray(t) || t.length !== 2) return;
6
- const s = t.find(
6
+ const r = t.find(
7
7
  (o) => o.type !== "null"
8
- ), r = t.some(
8
+ ), s = t.some(
9
9
  (o) => o.type === "null"
10
10
  );
11
- s && r && (delete e.anyOf, Object.assign(e, s));
11
+ r && s && (delete e.anyOf, Object.assign(e, r));
12
12
  }, y = (e) => {
13
13
  const t = v(e, {
14
14
  unrepresentable: "any",
15
15
  target: "draft-07"
16
16
  });
17
17
  t.additionalProperties = !0;
18
- const s = t.properties;
19
- if (s)
20
- for (const r of Object.keys(s))
21
- j(s[r]);
18
+ const r = t.properties;
19
+ if (r)
20
+ for (const s of Object.keys(r))
21
+ j(r[s]);
22
22
  return t;
23
23
  }, R = (e) => {
24
24
  if (!e.schema)
25
25
  throw new Error("no schema provided");
26
- const t = e.schema, s = e.dtoSchema, r = y(s), o = y(t.partial());
26
+ const t = e.schema, r = e.dtoSchema, s = y(r), o = y(t.partial());
27
27
  return {
28
- dtoSchema: s,
29
- responseSchema: e.responseSchema ?? s,
28
+ dtoSchema: r,
29
+ responseSchema: e.responseSchema ?? r,
30
30
  schema: {
31
31
  form: {
32
32
  uiSchema: e.uiSchema,
33
- schema: r,
33
+ schema: s,
34
34
  modalSize: e.modalSize ?? "sm"
35
35
  },
36
36
  table: e.tableSchema ? {
@@ -48,18 +48,18 @@ const j = (e) => {
48
48
  }, k = (e, t) => {
49
49
  if (!e.scope)
50
50
  return { id: null, property: null };
51
- const s = e.scope?.substring(13), r = t?.properties?.[s] ?? {};
52
- return { id: s, property: r };
51
+ const r = e.scope?.substring(13), s = t?.properties?.[r] ?? {};
52
+ return { id: r, property: s };
53
53
  }, $ = (e, t) => {
54
- const { id: s, property: r } = k(e, t);
55
- return { ...e, id: s, label: s, ...r };
54
+ const { id: r, property: s } = k(e, t);
55
+ return { ...e, id: r, label: r, ...s };
56
56
  };
57
- class d {
57
+ class p {
58
58
  constructor(t) {
59
59
  this.type = t;
60
60
  }
61
61
  }
62
- class m extends d {
62
+ class m extends p {
63
63
  constructor() {
64
64
  super(...arguments), this.elements = [];
65
65
  }
@@ -73,23 +73,27 @@ class m extends d {
73
73
  return this.elements.map((t) => t.build());
74
74
  }
75
75
  }
76
- const p = {
76
+ const u = {
77
77
  HorizontalLayout: "HorizontalLayout",
78
78
  VerticalLayout: "VerticalLayout",
79
- CollapseLayout: "CollapseLayout"
79
+ CollapseLayout: "CollapseLayout",
80
+ GridLayout: "GridLayout"
80
81
  };
81
82
  class a extends m {
82
- constructor(t, s = {}) {
83
- super(t), this.options = s;
83
+ constructor(t, r = {}) {
84
+ super(t), this.options = r;
84
85
  }
85
86
  static horizontal() {
86
- return new a(p.HorizontalLayout);
87
+ return new a(u.HorizontalLayout);
87
88
  }
88
89
  static collapse() {
89
- return new a(p.CollapseLayout);
90
+ return new a(u.CollapseLayout);
90
91
  }
91
92
  static vertical() {
92
- return new a(p.VerticalLayout);
93
+ return new a(u.VerticalLayout);
94
+ }
95
+ static grid() {
96
+ return new a(u.GridLayout);
93
97
  }
94
98
  titleKey(t) {
95
99
  return this.addOptions({ titleKey: t });
@@ -111,12 +115,12 @@ class a extends m {
111
115
  };
112
116
  }
113
117
  }
114
- class S extends d {
115
- constructor(t, s = "TextCell") {
116
- super(s), this.scope = t;
118
+ class O extends p {
119
+ constructor(t, r = "TextCell") {
120
+ super(r), this.scope = t;
117
121
  }
118
122
  static properties(t) {
119
- return new S(`#/properties/${t}`);
123
+ return new O(`#/properties/${t}`);
120
124
  }
121
125
  key(t) {
122
126
  return this.options = {
@@ -138,12 +142,12 @@ class S extends d {
138
142
  };
139
143
  }
140
144
  }
141
- class g {
145
+ class S {
142
146
  constructor() {
143
147
  this.builder = a.horizontal();
144
148
  }
145
149
  static init() {
146
- return new g();
150
+ return new S();
147
151
  }
148
152
  addControl(t) {
149
153
  return this.builder.addControls(t), this;
@@ -163,102 +167,107 @@ const i = {
163
167
  textArea: "textArea",
164
168
  markdown: "markdown",
165
169
  array: "array",
166
- custom: "custom"
170
+ custom: "custom",
171
+ select: "select",
172
+ mutliSelect: "mutliSelect",
173
+ boolean: "boolean"
167
174
  };
168
- class u extends d {
169
- constructor(t, s = "Control") {
170
- super(s), this.scope = t, this.options = {
175
+ class c extends p {
176
+ constructor(t, r = "Control") {
177
+ super(r), this.scope = t, this.options = {
171
178
  format: "Control",
172
- styles: {
173
- control: {
174
- wrapper: "w-full"
175
- }
176
- }
179
+ styles: {}
177
180
  };
178
181
  }
179
182
  static asObject(t) {
180
- return new u(
183
+ return new c(
181
184
  `#/properties/${t}`,
182
185
  "Object"
183
186
  );
184
187
  }
185
188
  static properties(t) {
186
- return new u(`#/properties/${t}`);
189
+ return new c(`#/properties/${t}`);
187
190
  }
188
- static asCustom(t, s) {
189
- const r = new u(
191
+ static asCustom(t, r) {
192
+ const s = new c(
190
193
  `#/properties/${t}`
191
194
  );
192
- return r.options = {
195
+ return s.addOptions({
193
196
  format: i.custom,
194
- type: s
195
- }, r;
197
+ type: r
198
+ }), s;
196
199
  }
197
- detail(t, s) {
198
- return this._detail = t, this.options = {
199
- ...this.options ?? {},
200
+ detail(t, r) {
201
+ return this._detail = t, this.addOptions({
200
202
  format: i.array,
201
- elementLabelProp: s
202
- }, this;
203
+ elementLabelProp: r
204
+ }), this;
203
205
  }
204
206
  addAction(t) {
205
- const s = this.options?.actions ?? [];
206
- return s.push(t), this.options = {
207
- ...this.options ?? {},
208
- actions: s
209
- }, this;
207
+ const r = this.options?.actions ?? [];
208
+ return r.push(t), this.addOptions({ actions: r });
210
209
  }
211
- detailFixed(t, s = {}) {
212
- return this._detail = t, this.options = {
213
- ...this.options ?? {},
210
+ detailFixed(t, r = {}) {
211
+ return this._detail = t, this.addOptions({
214
212
  hideActions: !0,
215
213
  format: i.array,
216
- layout: s.layout ?? "column",
217
- elementLabelProp: s.label
218
- }, this;
214
+ layout: r.layout ?? "column",
215
+ elementLabelProp: r.label
216
+ });
219
217
  }
220
218
  labelKey(t) {
221
- return this.options = {
222
- ...this.options ?? {},
223
- labelKey: t
224
- }, this;
219
+ return this.addOptions({ labelKey: t });
225
220
  }
226
221
  readonly() {
227
- return this.options = {
222
+ return this.addOptions({
228
223
  format: i.string,
229
224
  readonly: !0
230
- }, this;
225
+ });
231
226
  }
232
- markdown() {
233
- return this.options = { format: i.markdown }, this;
227
+ markdown(t) {
228
+ return this.addOptions({
229
+ format: i.markdown,
230
+ ...t ?? {}
231
+ });
234
232
  }
235
233
  textArea(t) {
236
- return this.options = {
234
+ return this.addOptions({
237
235
  format: i.textArea,
238
236
  ...t ?? {}
239
- }, this;
237
+ });
240
238
  }
241
239
  autocomplete(t) {
242
- return this.options = {
240
+ return this.addOptions({
243
241
  format: i.autocomplete,
244
242
  dataField: "data",
243
+ ...t ?? {}
244
+ });
245
+ }
246
+ control(t, r) {
247
+ return this.addOptions({
248
+ format: t,
249
+ ...r
250
+ });
251
+ }
252
+ select(t) {
253
+ return this.addOptions({
254
+ format: i.select,
245
255
  ...t
246
- }, this;
256
+ });
257
+ }
258
+ mutliSelect(t) {
259
+ return this.addOptions({
260
+ format: i.mutliSelect,
261
+ ...t
262
+ });
247
263
  }
248
264
  width(t) {
249
- const s = {
250
- xs: "w-12",
251
- sm: "w-24",
252
- md: "w-36",
253
- lg: "w-48",
254
- xl: "w-64",
255
- full: "w-full"
256
- };
257
265
  return this.addOptions({
258
266
  styles: {
259
267
  ...this.options?.styles,
268
+ width: t,
260
269
  control: {
261
- wrapper: ` ${s[t] ?? s.sm}`
270
+ wrapper: `input-${t}`
262
271
  }
263
272
  }
264
273
  });
@@ -289,7 +298,7 @@ class u extends d {
289
298
  };
290
299
  }
291
300
  }
292
- class w extends m {
301
+ class g extends m {
293
302
  constructor(t) {
294
303
  super(t), this.label = t, this.rule = {
295
304
  effect: "SHOW",
@@ -297,7 +306,7 @@ class w extends m {
297
306
  };
298
307
  }
299
308
  static label(t) {
300
- return new w(t);
309
+ return new g(t);
301
310
  }
302
311
  build() {
303
312
  return {
@@ -308,12 +317,12 @@ class w extends m {
308
317
  };
309
318
  }
310
319
  }
311
- class x extends m {
320
+ class w extends m {
312
321
  constructor(t) {
313
322
  super(t), this.label = t;
314
323
  }
315
324
  static label(t) {
316
- return new x(t);
325
+ return new w(t);
317
326
  }
318
327
  build() {
319
328
  return {
@@ -323,84 +332,84 @@ class x extends m {
323
332
  };
324
333
  }
325
334
  }
326
- const c = () => n.coerce.number().int().positive().nonnegative(), z = () => n.string().or(n.array(n.string())).transform((e) => Array.isArray(e) ? e : [e]), q = n.enum(["asc", "desc"]), O = n.object({
327
- page: c().optional().default(1),
328
- pageSize: c().optional().default(20),
335
+ const d = () => n.coerce.number().int().positive().nonnegative(), z = () => n.string().or(n.array(n.string())).transform((e) => Array.isArray(e) ? e : [e]), q = n.enum(["asc", "desc"]), x = n.object({
336
+ page: d().optional().default(1),
337
+ pageSize: d().optional().default(20),
329
338
  // TODO add sorting and so
330
339
  sort: n.string().optional().default("id"),
331
340
  sortDir: q.optional().default("asc"),
332
341
  // Filter is of the format key:value:operator (e.g. name:john:eq) operator is optional
333
342
  filter: z().optional().default([])
334
- }), H = O.transform((e) => {
335
- const { page: t, pageSize: s, sort: r } = e;
343
+ }), H = x.transform((e) => {
344
+ const { page: t, pageSize: r, sort: s } = e;
336
345
  return {
337
346
  ...e,
338
- sort: r || "id",
339
- offset: (t - 1) * s
347
+ sort: s || "id",
348
+ offset: (t - 1) * r
340
349
  };
341
- }), F = O.extend({
342
- count: c(),
343
- totalPages: c()
350
+ }), F = x.extend({
351
+ count: d(),
352
+ totalPages: d()
344
353
  }), N = n.object({
345
354
  data: n.array(n.unknown()),
346
355
  request: F
347
356
  }), K = ["contains", "equals"], C = (e) => {
348
- const [t, s, r] = e.split(":"), o = K.includes(r) ? r : "contains";
349
- return { key: t, value: s, operator: o };
357
+ const [t, r, s] = e.split(":"), o = K.includes(s) ? s : "contains";
358
+ return { key: t, value: r, operator: o };
350
359
  }, L = (e, t) => {
351
360
  if (e.length === 1)
352
361
  return { key: e[0], filterObj: t };
353
- const s = e.pop();
354
- return L(e, { [s]: t });
362
+ const r = e.pop();
363
+ return L(e, { [r]: t });
355
364
  }, T = (e, t) => A(e.split("."), t), A = (e, t) => {
356
365
  if (e.length === 1)
357
366
  return { [e[0]]: t };
358
- const s = e.pop();
359
- return A(e, { [s]: t });
367
+ const r = e.pop();
368
+ return A(e, { [r]: t });
360
369
  }, V = (e) => {
361
370
  const t = {};
362
- return e?.forEach((s) => {
363
- const { key: r, value: o, operator: l } = C(s);
364
- if (!r) return;
371
+ return e?.forEach((r) => {
372
+ const { key: s, value: o, operator: l } = C(r);
373
+ if (!s) return;
365
374
  const h = l || "contains", f = {
366
375
  [l || "contains"]: o.toLowerCase()
367
376
  };
368
377
  h === "contains" && (f.mode = "insensitive");
369
- const b = L(r.split("."), f);
378
+ const b = L(s.split("."), f);
370
379
  t[b.key] = b.filterObj;
371
380
  }), t;
372
- }, W = (e) => {
381
+ }, G = (e) => {
373
382
  const t = [];
374
- return e.forEach((s) => {
375
- const { key: r, value: o, operator: l } = C(s);
376
- if (!r) return;
377
- const h = r;
378
- t.push({ label: h, key: r, value: o, operator: l });
383
+ return e.forEach((r) => {
384
+ const { key: s, value: o, operator: l } = C(r);
385
+ if (!s) return;
386
+ const h = s;
387
+ t.push({ label: h, key: s, value: o, operator: l });
379
388
  }), t;
380
389
  };
381
390
  export {
382
- w as CategoryBuilder,
383
- u as ControlBuilder,
391
+ g as CategoryBuilder,
392
+ c as ControlBuilder,
384
393
  i as ControlType,
385
- x as GroupBuilder,
394
+ w as GroupBuilder,
386
395
  a as LayoutBuilder,
387
- p as LayoutTypes,
396
+ u as LayoutTypes,
388
397
  K as Operator,
389
- c as PositiveRequestNumber,
390
- O as RequestSchema,
398
+ d as PositiveRequestNumber,
399
+ x as RequestSchema,
391
400
  H as RequestSchemaWithOffset,
392
401
  F as ResponseRequestSchema,
393
402
  N as ResponseSchema,
394
403
  E as Size,
395
404
  q as SortDirEnum,
396
405
  z as StringOrArray,
397
- g as TableBuilder,
398
- S as TextCellBuilder,
406
+ S as TableBuilder,
407
+ O as TextCellBuilder,
399
408
  V as buildFilter,
400
409
  T as buildSort,
401
410
  A as buildSortKey,
402
411
  R as createSchema,
403
- W as extractFilters,
412
+ G as extractFilters,
404
413
  $ as findColumnDef,
405
414
  k as findProperty
406
415
  };
@@ -1,5 +1,4 @@
1
- import { JsonSchema } from '@jsonforms/core';
2
- import { Layout } from '@jsonforms/core/src/models/uischema';
1
+ import { JsonSchema, Layout } from '@jsonforms/core';
3
2
  import { ZodObject } from 'zod';
4
3
  export declare enum Size {
5
4
  xs = "xs",
@@ -9,23 +9,37 @@ export declare const ControlType: {
9
9
  readonly markdown: "markdown";
10
10
  readonly array: "array";
11
11
  readonly custom: "custom";
12
+ readonly select: "select";
13
+ readonly mutliSelect: "mutliSelect";
14
+ readonly boolean: "boolean";
12
15
  };
13
16
  export interface TextAreaOptions extends ControlOption {
14
17
  format: 'textArea';
15
18
  }
19
+ export interface MarkdownOptions extends ControlOption {
20
+ format: 'markdown';
21
+ minHeight: string;
22
+ }
16
23
  export interface DetailOptions extends ControlOption {
17
24
  format: 'array';
18
25
  layout: 'row' | 'column';
19
26
  }
20
- export interface AutocompleteOptions extends ControlOption {
27
+ export interface SelectOptions extends ControlOption {
28
+ format: 'select' | 'multiselect';
29
+ options: Array<any>;
30
+ labelKey?: string;
31
+ valueKey?: string;
32
+ }
33
+ export interface AutocompleteOptions extends Omit<SelectOptions, 'format'> {
34
+ format: 'autocomplete';
35
+ freeText?: boolean;
36
+ enableCreate?: boolean;
37
+ }
38
+ export interface AutocompleteRemoteOptions extends Omit<AutocompleteOptions, 'format' | 'options'> {
21
39
  format: 'autocomplete';
22
40
  uri: string;
23
41
  dataField?: string;
24
42
  skipAuth?: boolean;
25
- field: {
26
- id: string;
27
- label: string;
28
- };
29
43
  }
30
44
  export type ArrayActionType = 'edit';
31
45
  export type ArrayAction = {
@@ -39,7 +53,7 @@ export interface ControlOption {
39
53
  styles?: Partial<any>;
40
54
  elements?: any;
41
55
  elementLabelProp?: string;
42
- labelKey?: string;
56
+ customLabel?: string;
43
57
  actions?: ArrayAction[];
44
58
  placeholder?: string;
45
59
  hideLabel?: boolean;
@@ -66,9 +80,12 @@ export declare class ControlBuilder<TYPE, KEY = keyof TYPE> extends Builder<Cont
66
80
  }): this;
67
81
  labelKey(labelKey: string): this;
68
82
  readonly(): ControlBuilder<TYPE>;
69
- markdown(): ControlBuilder<TYPE>;
83
+ markdown(options?: Omit<MarkdownOptions, 'format'>): ControlBuilder<TYPE>;
70
84
  textArea(options?: Omit<TextAreaOptions, 'format'>): this;
71
- autocomplete(options: Omit<AutocompleteOptions, 'format'>): this;
85
+ autocomplete(options: Omit<AutocompleteOptions, 'format'> | Omit<AutocompleteRemoteOptions, 'format'>): this;
86
+ control(format: string, options?: Partial<ControlOption>): this;
87
+ select(options: Omit<SelectOptions, 'format'>): this;
88
+ mutliSelect(options: Omit<SelectOptions, 'format'>): this;
72
89
  width(width: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full'): this;
73
90
  customLabel(label: string): this;
74
91
  placeHolder(placeholder: string): this;
@@ -8,6 +8,7 @@ export declare const LayoutTypes: {
8
8
  readonly HorizontalLayout: "HorizontalLayout";
9
9
  readonly VerticalLayout: "VerticalLayout";
10
10
  readonly CollapseLayout: "CollapseLayout";
11
+ readonly GridLayout: "GridLayout";
11
12
  };
12
13
  type _LayoutTypes = (typeof LayoutTypes)[keyof typeof LayoutTypes];
13
14
  export type LayoutType = {
@@ -20,6 +21,7 @@ export declare class LayoutBuilder<TYPE> extends BuilderWithElements<LayoutType,
20
21
  static horizontal<TYPE>(): LayoutBuilder<TYPE>;
21
22
  static collapse<TYPE>(): LayoutBuilder<TYPE>;
22
23
  static vertical<TYPE>(): LayoutBuilder<TYPE>;
24
+ static grid<TYPE>(): LayoutBuilder<TYPE>;
23
25
  titleKey(titleKey: string): this;
24
26
  title(title: string): this;
25
27
  private addOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghentcdh/json-forms-core",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",