@ghentcdh/json-forms-core 0.6.6 → 0.6.7

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 o=require("zod"),F=require("lodash-es");var z=(e=>(e.xs="xs",e.sm="sm",e.lg="lg",e.xl="xl",e))(z||{});const C=e=>o.toJSONSchema(e,{unrepresentable:"any",target:"draft-07"}),P=e=>{if(!e.schema)throw new Error("no schema provided");const t=e.schema,r=e.dtoSchema,s=C(r),i=C(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:i}:void 0,filter:e.filterSchema?{uiSchema:e.filterSchema,schema:i}:void 0,uri:e.uri,searchUri:e.searchUri??`${e.uri}?filter=`}}},v=(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}},T=(e,t)=>{const{id:r,property:s}=v(e,t);return{...e,id:r,label:r,...s}};class p{constructor(t){this.type=t}}class d 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())}}class a extends d{constructor(t,r={}){super(t),this.options=r}static horizontal(){return new a("HorizontalLayout")}static stepper(t=!1){return new a("Categorization",{variant:"stepper",showNavButtons:!t})}static table(){return new a("table")}static vertical(){return new a("VerticalLayout")}build(){return{type:this.type,elements:this.buildElements(),options:this.options}}}class m extends p{constructor(t,r="TextCell"){super(r),this.scope=t}static properties(t){return new m(`#/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.table()}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 n={number:"number",string:"string",integer:"Integer",autocomplete:"autocomplete",textArea:"textArea",markdown:"markdown",fixedArray:"fixedArray",array:"array",custom:"custom"};class l extends p{constructor(t,r="Control"){super(r),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,r){const s=new l(`#/properties/${t}`);return s.options={format:n.custom,type:r},s}detail(t,r){return this._detail=t,this.options={...this.options??{},format:n.array,elementLabelProp:r},this}addAction(t){const r=this.options?.actions??[];return r.push(t),this.options={...this.options??{},actions:r},this}detailFixed(t,r){return this._detail=t,this.options={...this.options??{},format:n.fixedArray,elementLabelProp:r},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 r={xs:"w-12",sm:"w-24",md:"w-36",lg:"w-48",xl:"w-64"};return this.options={...this.options,styles:{...this.options?.styles,control:{wrapper:r[t]??r.sm}}},this}build(){return{type:this.type,scope:this.scope,options:{...this.options,detail:this._detail?this._detail?.build():void 0}}}}class f extends d{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 y extends d{constructor(t){super(t),this.label=t}static label(t){return new y(t)}build(){return{type:"Group",label:this.label,elements:this.buildElements()}}}const u=()=>o.z.coerce.number().int().positive().nonnegative(),q=()=>o.z.string().or(o.z.array(o.z.string())).transform(e=>F.isArray(e)?e:[e]),O=o.z.enum(["asc","desc"]),S=o.z.object({page:u().optional().default(1),pageSize:u().optional().default(20),sort:o.z.string().optional().default("id"),sortDir:O.optional().default("asc"),filter:q().optional().default([])}),k=S.transform(e=>{const{page:t,pageSize:r,sort:s}=e;return{...e,sort:s||"id",offset:(t-1)*r}}),R=S.extend({count:u(),totalPages:u()}),K=o.z.object({data:o.z.array(o.z.unknown()),request:R}),A=["contains","equals"],E=e=>{const[t,r,s]=e.split(":"),i=A.includes(s)?s:"contains";return{key:t,value:r,operator:i}},j=(e,t)=>{if(e.length===1)return{key:e[0],filterObj:t};const r=e.pop();return j(e,{[r]:t})},$=(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})},B=e=>{const t={};return e?.forEach(r=>{const{key:s,value:i,operator:c}=E(r);if(!s)return;const h=c||"contains",w={[c||"contains"]:i.toLowerCase()};h==="contains"&&(w.mode="insensitive");const x=j(s.split("."),w);t[x.key]=x.filterObj}),t},D=e=>{const t=[];return e.forEach(r=>{const{key:s,value:i,operator:c}=E(r);if(!s)return;const h=s;t.push({label:h,key:s,value:i,operator:c})}),t};exports.CategoryBuilder=f;exports.ControlBuilder=l;exports.ControlType=n;exports.GroupBuilder=y;exports.LayoutBuilder=a;exports.Operator=A;exports.PositiveRequestNumber=u;exports.RequestSchema=S;exports.RequestSchemaWithOffset=k;exports.ResponseRequestSchema=R;exports.ResponseSchema=K;exports.Size=z;exports.SortDirEnum=O;exports.StringOrArray=q;exports.TableBuilder=b;exports.TextCellBuilder=m;exports.buildFilter=B;exports.buildSort=$;exports.buildSortKey=g;exports.createSchema=P;exports.extractFilters=D;exports.findColumnDef=T;exports.findProperty=v;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("zod");var z=(e=>(e.xs="xs",e.sm="sm",e.lg="lg",e.xl="xl",e))(z||{});const C=e=>o.toJSONSchema(e,{unrepresentable:"any",target:"draft-07"}),F=e=>{if(!e.schema)throw new Error("no schema provided");const t=e.schema,r=e.dtoSchema,s=C(r),i=C(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:i}:void 0,filter:e.filterSchema?{uiSchema:e.filterSchema,schema:i}:void 0,uri:e.uri,searchUri:e.searchUri??`${e.uri}?filter=`}}},v=(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}},P=(e,t)=>{const{id:r,property:s}=v(e,t);return{...e,id:r,label:r,...s}};class p{constructor(t){this.type=t}}class d 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())}}class a extends d{constructor(t,r={}){super(t),this.options=r}static horizontal(){return new a("HorizontalLayout")}static stepper(t=!1){return new a("Categorization",{variant:"stepper",showNavButtons:!t})}static table(){return new a("table")}static vertical(){return new a("VerticalLayout")}build(){return{type:this.type,elements:this.buildElements(),options:this.options}}}class m extends p{constructor(t,r="TextCell"){super(r),this.scope=t}static properties(t){return new m(`#/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.table()}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 n={number:"number",string:"string",integer:"Integer",autocomplete:"autocomplete",textArea:"textArea",markdown:"markdown",fixedArray:"fixedArray",array:"array",custom:"custom"};class l extends p{constructor(t,r="Control"){super(r),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,r){const s=new l(`#/properties/${t}`);return s.options={format:n.custom,type:r},s}detail(t,r){return this._detail=t,this.options={...this.options??{},format:n.array,elementLabelProp:r},this}addAction(t){const r=this.options?.actions??[];return r.push(t),this.options={...this.options??{},actions:r},this}detailFixed(t,r){return this._detail=t,this.options={...this.options??{},format:n.fixedArray,elementLabelProp:r},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 r={xs:"w-12",sm:"w-24",md:"w-36",lg:"w-48",xl:"w-64"};return this.options={...this.options,styles:{...this.options?.styles,control:{wrapper:r[t]??r.sm}}},this}customLabel(t){return this.options={...this.options,label:t},this}build(){return{type:this.type,scope:this.scope,options:{...this.options,detail:this._detail?this._detail?.build():void 0}}}}class f extends d{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 y extends d{constructor(t){super(t),this.label=t}static label(t){return new y(t)}build(){return{type:"Group",label:this.label,elements:this.buildElements()}}}const u=()=>o.z.coerce.number().int().positive().nonnegative(),A=()=>o.z.string().or(o.z.array(o.z.string())).transform(e=>Array.isArray(e)?e:[e]),O=o.z.enum(["asc","desc"]),S=o.z.object({page:u().optional().default(1),pageSize:u().optional().default(20),sort:o.z.string().optional().default("id"),sortDir:O.optional().default("asc"),filter:A().optional().default([])}),T=S.transform(e=>{const{page:t,pageSize:r,sort:s}=e;return{...e,sort:s||"id",offset:(t-1)*r}}),R=S.extend({count:u(),totalPages:u()}),k=o.z.object({data:o.z.array(o.z.unknown()),request:R}),q=["contains","equals"],E=e=>{const[t,r,s]=e.split(":"),i=q.includes(s)?s:"contains";return{key:t,value:r,operator:i}},j=(e,t)=>{if(e.length===1)return{key:e[0],filterObj:t};const r=e.pop();return j(e,{[r]:t})},K=(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:i,operator:c}=E(r);if(!s)return;const h=c||"contains",w={[c||"contains"]:i.toLowerCase()};h==="contains"&&(w.mode="insensitive");const x=j(s.split("."),w);t[x.key]=x.filterObj}),t},B=e=>{const t=[];return e.forEach(r=>{const{key:s,value:i,operator:c}=E(r);if(!s)return;const h=s;t.push({label:h,key:s,value:i,operator:c})}),t};exports.CategoryBuilder=f;exports.ControlBuilder=l;exports.ControlType=n;exports.GroupBuilder=y;exports.LayoutBuilder=a;exports.Operator=q;exports.PositiveRequestNumber=u;exports.RequestSchema=S;exports.RequestSchemaWithOffset=T;exports.ResponseRequestSchema=R;exports.ResponseSchema=k;exports.Size=z;exports.SortDirEnum=O;exports.StringOrArray=A;exports.TableBuilder=b;exports.TextCellBuilder=m;exports.buildFilter=$;exports.buildSort=K;exports.buildSortKey=g;exports.createSchema=F;exports.extractFilters=B;exports.findColumnDef=P;exports.findProperty=v;
package/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { toJSONSchema as E, z as o } from "zod";
2
- import { isArray as O } from "lodash-es";
3
- var j = /* @__PURE__ */ ((e) => (e.xs = "xs", e.sm = "sm", e.lg = "lg", e.xl = "xl", e))(j || {});
4
- const b = (e) => E(e, {
2
+ var O = /* @__PURE__ */ ((e) => (e.xs = "xs", e.sm = "sm", e.lg = "lg", e.xl = "xl", e))(O || {});
3
+ const f = (e) => E(e, {
5
4
  unrepresentable: "any",
6
5
  target: "draft-07"
7
- }), $ = (e) => {
6
+ }), K = (e) => {
8
7
  if (!e.schema)
9
8
  throw new Error("no schema provided");
10
- const t = e.schema, s = e.dtoSchema, r = b(s), n = b(t.partial());
9
+ const t = e.schema, s = e.dtoSchema, r = f(s), n = f(t.partial());
11
10
  return {
12
11
  dtoSchema: s,
13
12
  responseSchema: e.responseSchema ?? s,
@@ -29,13 +28,13 @@ const b = (e) => E(e, {
29
28
  searchUri: e.searchUri ?? `${e.uri}?filter=`
30
29
  }
31
30
  };
32
- }, k = (e, t) => {
31
+ }, j = (e, t) => {
33
32
  if (!e.scope)
34
33
  return { id: null, property: null };
35
34
  const s = e.scope?.substring(13), r = t?.properties?.[s] ?? {};
36
35
  return { id: s, property: r };
37
- }, T = (e, t) => {
38
- const { id: s, property: r } = k(e, t);
36
+ }, P = (e, t) => {
37
+ const { id: s, property: r } = j(e, t);
39
38
  return { ...e, id: s, label: s, ...r };
40
39
  };
41
40
  class p {
@@ -235,6 +234,12 @@ class c extends p {
235
234
  }
236
235
  }, this;
237
236
  }
237
+ customLabel(t) {
238
+ return this.options = {
239
+ ...this.options,
240
+ label: t
241
+ }, this;
242
+ }
238
243
  build() {
239
244
  return {
240
245
  type: this.type,
@@ -280,41 +285,41 @@ class g extends d {
280
285
  };
281
286
  }
282
287
  }
283
- const u = () => o.coerce.number().int().positive().nonnegative(), q = () => o.string().or(o.array(o.string())).transform((e) => O(e) ? e : [e]), z = o.enum(["asc", "desc"]), x = o.object({
288
+ const u = () => o.coerce.number().int().positive().nonnegative(), k = () => o.string().or(o.array(o.string())).transform((e) => Array.isArray(e) ? e : [e]), q = o.enum(["asc", "desc"]), x = o.object({
284
289
  page: u().optional().default(1),
285
290
  pageSize: u().optional().default(20),
286
291
  // TODO add sorting and so
287
292
  sort: o.string().optional().default("id"),
288
- sortDir: z.optional().default("asc"),
293
+ sortDir: q.optional().default("asc"),
289
294
  // Filter is of the format key:value:operator (e.g. name:john:eq) operator is optional
290
- filter: q().optional().default([])
291
- }), N = x.transform((e) => {
295
+ filter: k().optional().default([])
296
+ }), $ = x.transform((e) => {
292
297
  const { page: t, pageSize: s, sort: r } = e;
293
298
  return {
294
299
  ...e,
295
300
  sort: r || "id",
296
301
  offset: (t - 1) * s
297
302
  };
298
- }), F = x.extend({
303
+ }), z = x.extend({
299
304
  count: u(),
300
305
  totalPages: u()
301
- }), V = o.object({
306
+ }), T = o.object({
302
307
  data: o.array(o.unknown()),
303
- request: F
304
- }), R = ["contains", "equals"], C = (e) => {
305
- const [t, s, r] = e.split(":"), n = R.includes(r) ? r : "contains";
308
+ request: z
309
+ }), F = ["contains", "equals"], C = (e) => {
310
+ const [t, s, r] = e.split(":"), n = F.includes(r) ? r : "contains";
306
311
  return { key: t, value: s, operator: n };
307
312
  }, v = (e, t) => {
308
313
  if (e.length === 1)
309
314
  return { key: e[0], filterObj: t };
310
315
  const s = e.pop();
311
316
  return v(e, { [s]: t });
312
- }, W = (e, t) => A(e.split("."), t), A = (e, t) => {
317
+ }, L = (e, t) => A(e.split("."), t), A = (e, t) => {
313
318
  if (e.length === 1)
314
319
  return { [e[0]]: t };
315
320
  const s = e.pop();
316
321
  return A(e, { [s]: t });
317
- }, D = (e) => {
322
+ }, N = (e) => {
318
323
  const t = {};
319
324
  return e?.forEach((s) => {
320
325
  const { key: r, value: n, operator: l } = C(s);
@@ -323,10 +328,10 @@ const u = () => o.coerce.number().int().positive().nonnegative(), q = () => o.st
323
328
  [l || "contains"]: n.toLowerCase()
324
329
  };
325
330
  h === "contains" && (m.mode = "insensitive");
326
- const f = v(r.split("."), m);
327
- t[f.key] = f.filterObj;
331
+ const b = v(r.split("."), m);
332
+ t[b.key] = b.filterObj;
328
333
  }), t;
329
- }, H = (e) => {
334
+ }, V = (e) => {
330
335
  const t = [];
331
336
  return e.forEach((s) => {
332
337
  const { key: r, value: n, operator: l } = C(s);
@@ -341,22 +346,22 @@ export {
341
346
  i as ControlType,
342
347
  g as GroupBuilder,
343
348
  a as LayoutBuilder,
344
- R as Operator,
349
+ F as Operator,
345
350
  u as PositiveRequestNumber,
346
351
  x as RequestSchema,
347
- N as RequestSchemaWithOffset,
348
- F as ResponseRequestSchema,
349
- V as ResponseSchema,
350
- j as Size,
351
- z as SortDirEnum,
352
- q as StringOrArray,
352
+ $ as RequestSchemaWithOffset,
353
+ z as ResponseRequestSchema,
354
+ T as ResponseSchema,
355
+ O as Size,
356
+ q as SortDirEnum,
357
+ k as StringOrArray,
353
358
  S as TableBuilder,
354
359
  y as TextCellBuilder,
355
- D as buildFilter,
356
- W as buildSort,
360
+ N as buildFilter,
361
+ L as buildSort,
357
362
  A as buildSortKey,
358
- $ as createSchema,
359
- H as extractFilters,
360
- T as findColumnDef,
361
- k as findProperty
363
+ K as createSchema,
364
+ V as extractFilters,
365
+ P as findColumnDef,
366
+ j as findProperty
362
367
  };
@@ -63,5 +63,6 @@ export declare class ControlBuilder<TYPE, KEY = keyof TYPE> extends Builder<Cont
63
63
  textArea(options?: Omit<TextAreaOptions, 'format'>): this;
64
64
  autocomplete(options: Omit<AutocompleteOptions, 'format'>): this;
65
65
  width(width: 'xs' | 'sm' | 'md' | 'lg' | 'xl'): this;
66
+ customLabel(label: string): this;
66
67
  build(): ControlTypes;
67
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghentcdh/json-forms-core",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -14,13 +14,11 @@
14
14
  "peerDependencies": {
15
15
  "@anatine/zod-openapi": "^2.2.0",
16
16
  "@jsonforms/core": "^3.4.0",
17
- "lodash-es": "^4.17.0",
18
17
  "zod": "^3.24.0"
19
18
  },
20
19
  "devDependencies": {
21
20
  "@anatine/zod-openapi": "2.2.8",
22
21
  "@jsonforms/core": "3.7.0",
23
- "lodash-es": "4.17.23",
24
22
  "zod": "4.3.6"
25
23
  },
26
24
  "repository": {