@react-typed-forms/schemas 14.2.0 → 14.3.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/lib/controlDefinition.d.ts +11 -0
- package/lib/index.cjs +3392 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +2869 -1
- package/lib/index.js.map +1 -1
- package/lib/renderers.d.ts +2 -2
- package/lib/util.d.ts +7 -2
- package/package.json +3 -2
- package/src/controlBuilder.ts +268 -0
- package/src/controlDefinition.ts +792 -0
- package/src/controlRender.tsx +1252 -0
- package/src/createFormRenderer.tsx +218 -0
- package/src/defaultSchemaInterface.ts +191 -0
- package/src/dynamicHooks.ts +98 -0
- package/src/entityExpression.ts +38 -0
- package/src/hooks.tsx +459 -0
- package/src/index.ts +14 -0
- package/src/renderers.tsx +205 -0
- package/src/schemaBuilder.ts +318 -0
- package/src/schemaField.ts +552 -0
- package/src/schemaValidator.ts +32 -0
- package/src/util.ts +1039 -0
- package/src/validators.ts +217 -0
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2870 @@
|
|
|
1
|
-
import{newControl as e,getElementIndex as n,ensureMetaValue as t,ControlChange as r,useControl as o,useComputed as l,useRefState as i,SubscriptionTracker as a,addAfterChangesCallback as u,trackedValue as d,collectChanges as c,useCalculatedControl as s,useValueChangeEffect as f,useValidator as p,useComponentTracking as y,useControlEffect as h,removeElement as v,RenderArrayElements as m,addElement as g}from"@react-typed-forms/core";import C,{useRef as b,useMemo as D,useCallback as N,useEffect as x}from"react";import T from"clsx";import E from"jsonata";import{v4 as O}from"uuid";var S,A,I,L,w,V,F,k,M,R,q,G,j,H;function B(e,n){return e.find(e=>e.field===n)}function U(e){return!$(e)}function $(e){return e.type===S.Compound}function J(e){return{field:"__missing",type:S.Any,displayName:e}}function P(e,n,t){const r={id:t?t.id+"/"+e.field:e.field,field:e,getSchema:n.getSchema,parent:t,getChildNode:function(t){if($(e)&&!e.schemaRef&&!e.treeChildren){const o=e.children.find(e=>e.field===t);return o?P(o,n,r):void 0}return o(!1,r).find(e=>e.field.field===t)},getChildNodes:o};return r;function o(o,l){if($(e)){if(e.treeChildren)return o?[]:t.getChildNodes(!1,null!=l?l:r);const i=e.schemaRef&&n.getSchema(e.schemaRef);return i?i.getChildNodes(!1,null!=l?l:r):e.children.map(e=>P(e,n,null!=l?l:r))}return[]}}function _(e){const n={getSchema:function(t){const r=e[t];if(r)return ee(r,n)}};return n}function W(e,n,t,r){const o={id:(t?t.id+"/"+e.field.field:e.field.field)+("number"==typeof r?"/"+r:""),schema:e,control:n,parent:t,elementIndex:r,getChild:function(e){const t=n;return t&&t.current.isNull&&(t.value={}),W(e,null==t?void 0:t.fields[e.field.field],o)},getChildElement:function(t){var r;return W(e,null==n||null==(r=n.elements)?void 0:r[t],o,t)}};return o}function Y(e,n){var t;return X(null!=(t=null==e?void 0:e.split("/"))?t:[],n)}function z(e,n){var t;return Z(null!=(t=null==e?void 0:e.split("/"))?t:[],n)}function K(e,n,t,r){let o=0;for(;o<e.length;){const l=e[o];let i=".."===l?n.parent:n.getChildNode(l);i||(i=P(J(l),n,n)),t=r(t,i),n=i,o++}return t}function Q(e,n,t){return K(e,n,t,(e,n)=>null==e?void 0:e[n.field.field])}function X(n,t){let r=0;for(;r<n.length;){const l=n[r];let i=".."===l?t.parent:o(l);null!=i||(i=W(P(J(l),t.schema,t.schema),e(void 0))),t=i,r++}return t;function o(e){const n=t.schema.getChildNode(e);if(n)return t.getChild(n)}}function Z(e,n){let t=0;for(;t<e.length;){const r=e[t];let o=".."===r?n.parent:n.getChildNode(r);o||(o=P(J(r),n,n)),n=o,t++}return n}function ee(e,n={getSchema(e){}}){return P({type:S.Compound,field:"",children:e},n,void 0)}function ne(e){const n=[];let t=e;for(;t;)n.push(t.field.field),t=t.parent;return n.reverse()}function te(e){return $(e.field)}function re(e,n){if(e.id===n.id)return"";const t=ne(e),r=ne(n);let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];)o++;const l=t.length-o,i=r.slice(o).join("/");return"../".repeat(l)+i}function oe(e,n){var t;return null==(t=e.tags)||null==(t=t.find(e=>e.startsWith(n)))?void 0:t.substring(n.length)}function le(e,n){return`${e}${n}`}function ie(e,n,t){switch(e.type){case L.Action:return n.action(e);case L.Data:return n.data(e);case L.Display:return n.display(e);case L.Group:return n.group(e);default:return t(e)}}function ae(e){return e.type===R.Grid}function ue(e){return e.type===R.SelectChild}function de(e){return e.type===R.Tabs}function ce(e){return e.type===R.Flex}function se(e){return e.type===k.DisplayOnly}function fe(e){return e.type===k.Textfield}function pe(e){return e.type===k.Autocomplete}function ye(e){return(null==e?void 0:e.type)===k.Autocomplete}function he(e){return(null==e?void 0:e.type)===k.Group}function ve(e){return e.type===k.Array}function me(e){return e.type===L.Data}function ge(e){return e.type===L.Group}function Ce(e){return e.type===L.Action}function be(e){return e.type===L.Display}function De(e){switch(null==e?void 0:e.type){case k.Radio:case k.CheckList:return!0;default:return!1}}!function(e){e.String="String",e.Bool="Bool",e.Int="Int",e.Date="Date",e.DateTime="DateTime",e.Time="Time",e.Double="Double",e.EntityRef="EntityRef",e.Compound="Compound",e.AutoId="AutoId",e.Image="Image",e.Any="Any"}(S||(S={})),function(e){e.NotEmpty="NotEmpty",e.MinLength="MinLength",e.MaxLength="MaxLength",e.NotAfterDate="NotAfterDate",e.NotBeforeDate="NotBeforeDate"}(A||(A={})),function(e){e.NoControl="_NoControl",e.HtmlEditor="_HtmlEditor",e.ControlGroup="_ControlGroup:",e.ControlRef="_ControlRef:",e.IdField="_IdField:"}(I||(I={})),function(e){e.Data="Data",e.Group="Group",e.Display="Display",e.Action="Action"}(L||(L={})),function(e){e.Visible="Visible",e.DefaultValue="DefaultValue",e.Readonly="Readonly",e.Disabled="Disabled",e.Display="Display",e.Style="Style",e.LayoutStyle="LayoutStyle",e.AllowedOptions="AllowedOptions",e.Label="Label",e.ActionData="ActionData"}(w||(w={})),function(e){e.ControlStart="ControlStart",e.ControlEnd="ControlEnd",e.LabelStart="LabelStart",e.LabelEnd="LabelEnd"}(V||(V={})),function(e){e.Tooltip="Tooltip",e.Accordion="Accordion",e.HelpText="HelpText",e.Icon="Icon",e.SetField="SetField",e.Optional="Optional"}(F||(F={})),function(e){e.Standard="Standard",e.Textfield="Textfield",e.Radio="Radio",e.HtmlEditor="HtmlEditor",e.IconList="IconList",e.CheckList="CheckList",e.UserSelection="UserSelection",e.Synchronised="Synchronised",e.IconSelector="IconSelector",e.DateTime="DateTime",e.Checkbox="Checkbox",e.Dropdown="Dropdown",e.DisplayOnly="DisplayOnly",e.Group="Group",e.NullToggle="NullToggle",e.Autocomplete="Autocomplete",e.Jsonata="Jsonata",e.Array="Array",e.ArrayElement="ArrayElement"}(k||(k={})),function(e){e.Camel="Camel",e.Snake="Snake",e.Pascal="Pascal"}(M||(M={})),function(e){e.Standard="Standard",e.Grid="Grid",e.Flex="Flex",e.Tabs="Tabs",e.GroupElement="GroupElement",e.SelectChild="SelectChild"}(R||(R={})),function(e){e.Text="Text",e.Html="Html",e.Icon="Icon",e.Custom="Custom"}(q||(q={}));class Ne{constructor(e,n,t,r,o){this.id=void 0,this.definition=void 0,this.tree=void 0,this.parent=void 0,this.overrideChildren=void 0,this.id=e,this.definition=n,this.tree=t,this.parent=r,this.overrideChildren=o,this.id=e,this.definition=n}getChildNodes(){var e,n;if(this.overrideChildren)return this.overrideChildren;let t=this.definition.children;if(this.definition.childRefId){const e=this.tree.controlMap[this.definition.childRefId];t=null==e?void 0:e.children}return null!=(e=null==(n=t)?void 0:n.map((e,n)=>new Ne(this.id+"/"+n,e,this.tree,this)))?e:[]}withOverrideChildren(e){return new Ne(this.id,this.definition,this.tree,this.parent,e.map(e=>xe(e,this.tree)))}}function xe(e,n,t,r){return new Ne(r?r.id+"/"+t:"",e,n,r)}function Te(e){return Se({$legacy:[e]}).getForm("$legacy").rootNode.getChildNodes()[0]}function Ee(e){var n,t;const r=null!=(n=null==(t=e.children)?void 0:t.flatMap(Ee))?n:[];return e.id?[[e.id,e],...r]:r}function Oe(e,n){const t={getForm:n,controlMap:Object.fromEntries(e.flatMap(Ee))};return t.rootNode=xe({children:e,type:L.Group},t),t}function Se(e){const n={getForm:function(e){return t[e]}},t=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Oe(t,n)]));return n}function Ae(e){const n=ge(e)?e.compoundField:me(e)?e.field:void 0;return null==n?void 0:n.split("/")}function Ie(e,n){const t=Ae(e);return t?X(t,n):void 0}function Le(e,n,t){let r=[];for(;e&&(null==t||!t(e));)r.push(n(e)),e=e.parent;return r.reverse()}function we(e){for(;e.parent;)e=e.parent;return e}function Ve(e){return Le(e,e=>null==e.elementIndex?e.schema.field.field:e.elementIndex,e=>!e.parent)}function Fe(e){return Le(e,e=>e.field,e=>!e.parent)}function ke(e){return e.getChildNodes().map(e=>e.field)}function Me(e,n,t){if(e)for(const r of e){const e=Re(r,n,t);if(void 0!==e)return e}}function Re(e,n,t){if(n.control&&!n.control.isNull)return ie(e,{data:e=>r(e),group:e=>r(e),action:()=>{},display:()=>{}},()=>{});function r(e){const r=e.children,o=Ie(e,n);if(!o)return Me(r,n,t);const l=me(e)?e:void 0,i=l?t(l,o):void 0;if(void 0!==i)return i;const a=o.schema,u=$(a.field);if(a.field.collection){const e=o.control;let n=0;for(const i of null!=(d=e.elements)?d:[]){var d;const e=o.getChildElement(n),i=l?t(l,e):void 0;if(void 0!==i)return i;if(u){const n=Me(r,e,t);if(void 0!==n)return n}n++}}else if(u)return Me(r,o,t)}}function qe(){return qe=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},qe.apply(null,arguments)}function Ge(e,n){if(null==e)return{};var t={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(n.includes(r))continue;t[r]=e[r]}return t}function je(e){return Object.entries(e).map(e=>e[1](e[0]))}function He(e,n){return $e(qe({type:S.String,displayName:e},n))}function Be(e,...n){return $e({type:S.String,displayName:e,options:n})}function Ue(e,n){return t=>qe({},n(t),e)}function $e(e){return n=>qe({},Xe(n,n),e)}function Je(e){return n=>qe({},Ze(n,n,!1),e)}function Pe(e,n){return $e(qe({type:S.Int,displayName:e},n))}function _e(e,n){return $e(qe({type:S.Double,displayName:e},n))}function We(e,n){return $e(qe({type:S.Date,displayName:e},n))}function Ye(e,n){return $e(qe({type:S.Time,displayName:e},n))}function ze(e,n){return $e(qe({type:S.DateTime,displayName:e},n))}function Ke(e,n){return $e(qe({type:S.Bool,displayName:e},n))}function Qe(e,n,t){return r=>qe({},Ze(r,e,!1),t,{children:n})}function Xe(e,n){return{field:e,displayName:n,type:S.String}}function Ze(e,n,t){return{field:e,displayName:n,type:S.Compound,collection:t,children:[]}}function en(e,n){const t=n.find(n=>n.field===e.field);return t?n.map(n=>n!==t?n:qe({},n,{onlyForTypes:r(n.onlyForTypes,e.onlyForTypes)})):[...n,e];function r(e,n){if(!e)return n;if(!n)return e;const t=n.filter(n=>!e.includes(n));return t.length?[...e,...t]:e}}function nn(e,n,t,r){const o=e.map(e=>e.isTypeField?tn(e,n,t):e);return r.map(e=>qe({},e,{onlyForTypes:[t]})).reduce((e,n)=>en(n,e),o)}function tn(e,n,t){var r;const o=null!=(r=e.options)?r:[];return o.some(e=>e.value===t)?e:qe({},e,{options:[...o,{name:n,value:t}]})}function rn(e){const n={};return Object.keys(e).forEach(function t(r){if(r in n)return n[r];const o=[];return n[r]=o,e[r].forEach(e=>{$(e)&&e.schemaRef?o.push(qe({},e,{children:t(e.schemaRef)})):o.push(e)}),o}),n}function on(e,n,t){if(!e)return an(n);if(t&&t.has(e))return e;null!=t||(t=new Set),t.add(e);const r=n.filter(n=>$(n)||!(n.field in e));if(!r.length)return e;const o=qe({},e);return r.forEach(r=>{o[r.field]=r.field in e?ln(e[r.field],r,n,!1,t):un(r)}),o}function ln(e,n,t,r,o){return n.collection&&!r?(null!=e?e:[]).map(e=>ln(e,n,t,!0,o)):$(n)?e||n.required?on(e,n.treeChildren?t:n.children,o):e:un(n)}function an(e){return Object.fromEntries(e.map(e=>[e.field,un(e)]))}function un(e,n){if(void 0!==e.defaultValue)return e.defaultValue;const t=!(!n&&!e.required);if($(e)){if(t){const n=an(e.children);return e.collection?[n]:n}return e.notNullable?e.collection?[]:{}:void 0}return e.collection&&e.notNullable?[]:void 0}function dn(e){return $(e)?an(e.children):e.defaultValue}function cn(e,n){return B(e,n)}function sn(e,n){return B(e,n)}function fn(e,n){var t;return Boolean(null==(t=e.tags)?void 0:t.includes(n))}function pn(e){var n;return null!=(n=e.displayName)?n:e.field}function yn(e){var n,t;return(null!=(n=null==(t=e.options)?void 0:t.length)?n:0)>0}function hn(e,n){if($(e)){const t=oe(e,I.ControlRef);return{type:L.Data,title:e.displayName,field:e.field,required:e.required,childRefId:t,children:n||t?void 0:e.children.filter(e=>!fn(e,I.NoControl)).map(e=>hn(e))}}if(U(e)){const n=fn(e,I.HtmlEditor);return{type:L.Data,title:e.displayName,field:e.field,required:e.required,renderOptions:{type:n?k.HtmlEditor:k.Standard}}}throw"Unknown schema field"}function vn(e,n){return me(n)&&e.field.field===n.field?[n]:ge(n)?n.compoundField===e.field.field?[n]:null!=(t=null==(r=n.children)?void 0:r.flatMap(n=>vn(e,n)))?t:[]:[];var t,r}function mn(e){return e.flatMap(e=>{var n;return ge(e)&&!e.compoundField?[e,...mn(null!=(n=e.children)?n:[])]:[]})}function gn(e,n){return Cn(ee(e),n)}function Cn(e,n){const t={},r={},o=n.map(n=>i(n,e));return l("",{schema:e,children:o}),o.forEach(function e(n){if(n.children.forEach(e),n.control.childRefId){const e=t[n.control.childRefId];if(e)return void e.children.forEach(e=>i(e.control,n.schema,n,!0));console.warn("Missing reference",n.control.childRefId)}}),e.getChildNodes().forEach(function e(n){if(!fn(n.field,I.NoControl)){if(!r[n.id]){const e=function(e){const n=[];let t=e.parent;for(;t&&(n.push(t.id),!t.field.collection);)t.parent||t.getChildNodes(!0).forEach(r),t=t.parent;return n;function r(e){te(e)&&!e.field.collection&&(n.push(e.id),e.getChildNodes(!0).forEach(r))}}(n),l=oe(n.field,I.ControlGroup);let a=l?t[l]:void 0;var o;if(!a&&l&&console.warn("No group '"+l+"' for "+n.id),a&&e.indexOf(a.schema.id)<0&&(console.warn(`Target group '${l}' is not an eligible parent for '${n.id}'`),a=void 0),!a&&e.length&&(a=null==(o=r[e[0]])?void 0:o[0]),a){const e=hn(n.field,!0);e.field=re(a.schema,n),a.children.push(i(e,a.schema,a))}else console.warn("Could not find a parent group for: "+n.id)}n.getChildNodes(!0).forEach(e)}}),o.map(function e(n){const t=n.children.length?n.children.map(e):null;return qe({},n.control,{children:t})});function l(e,n){r[e]||(r[e]=[]),r[e].push(n)}function i(e,n,r,o){var a,u;const d=Ae(e);let c=d?Z(d,n):void 0;ge(e)&&null==c&&(c=n);const s={schema:c,control:e,children:[],parent:r};return s.children=null!=(a=null==(u=e.children)?void 0:u.map(e=>{var t;return i(e,null!=(t=c)?t:n,s,o)}))?a:[],!o&&e.id&&(t[e.id]=s),c&&l(c.id,s),s}}function bn(e){const n=b(e);return n.current=e,n}function Dn(e){return me(e)&&!!e.readonly}function Nn(e){return me(e)&&!!e.disabled}function xn(e){return me(e)&&e.renderOptions&&se(e.renderOptions)?e.renderOptions:void 0}function Tn(e,n,t){if(!e)return e;const r=n.find(e=>e.isTypeField),o=r?e[r.field]:void 0,l=t?n:n.filter(e=>{var n,t;return $(e)||(null!=(n=null==(t=e.onlyForTypes)?void 0:t.length)?n:0)>0});if(!l.length)return e;const i=qe({},e);return l.forEach(r=>{var l;const a=e[r.field];if(!1===(null==(l=r.onlyForTypes)?void 0:l.includes(o))||!r.notNullable&&(t&&r.defaultValue===a||r.collection&&Array.isArray(a)&&!a.length))delete i[r.field];else if($(r)){const e=r.treeChildren?n:r.children;r.collection?Array.isArray(a)&&(i[r.field]=a.map(n=>Tn(n,e,t))):i[r.field]=Tn(a,e,t)}}),i}function En(e,n){var t,r;const o=null==(t=e.children)?void 0:t.flatMap(e=>En(e,n)),l=Mn(e),{entryWrapperClass:i,selectedClass:a,notSelectedClass:u}=me(e)&&De(e.renderOptions)?e.renderOptions:{},{listContainerClass:d,listEntryClass:c,chipContainerClass:s,chipCloseButtonClass:f}=me(e)&&ye(e.renderOptions)?e.renderOptions:{},p=T([e.styleClass,e.layoutClass,e.labelClass,...Object.values(l),...null!=(r=null==n?void 0:n(e))?r:[],i,a,u,d,c,s,f].map(An));return o&&!p?o:p?o?[p,...o]:[p]:[]}function On(e,n){let t="";return e.forEach((e,r)=>{var o;"number"==typeof e?t+=null!=(o=null==n?void 0:n(e))?o:"["+e+"]":(r>0&&(t+="."),t+=e)}),t}function Sn(e,n){if(Array.isArray(n)){let t=e;return n.forEach(e=>t=t.children[e]),t}return e.children[n]}function An(e){return e&&e.startsWith("@ ")?e.substring(2):e}function In(e,n){if(An(n)!==n)return n||void 0;const t=An(e);return t===e?T(e,n):t||void 0}function Ln(e,n,t,r,o){return[null==n||e>n?r:void 0,null==t||e<t?o:void 0]}function wn(e,n){if(!n)return;const t=n.split("/"),r=[];let o=0,l=e;for(;o<t.length&&l;){const e=B(l,t[o]);if(!e)return;r.push(e),l=$(e)&&!e.collection?e.children:void 0,o++}return r.length===t.length?r:void 0}function Vn(e,n,t=(e,n,t)=>null!=n?n:t){if(!e)return n;if(!n)return e;const r=qe({},e);for(const o in n)n.hasOwnProperty(o)&&(r[o]=t(o,e[o],n[o]));return r}function Fn(e){return null==e?"":"object"==typeof e?"error: "+JSON.stringify(e):e.toString()}function kn(e){return ge(e)?e.groupOptions:me(e)&&he(e.renderOptions)?e.renderOptions.groupOptions:void 0}function Mn(e){let n=kn(e);if(!n)return{};const{childLayoutClass:t,childStyleClass:r,childLabelClass:o}=n,l={};return t&&(l.layoutClass=t),r&&(l.styleClass=r),o&&(l.labelClass=o),l}function Rn(e){var n;return Boolean(null==(n=kn(e))?void 0:n.displayOnly)}function qn(...e){return(n,t,r)=>{for(let l=0;l<e.length;l++){var o;const i=null==(o=e[l])?void 0:o.call(e,n,t,r);if(i)return i}}}function Gn(e,t){const r=e.control,o=e.schema.field;if(r.dirty||t){if(r.isNull)return null;if(o.collection&&null==e.elementIndex){const t=oe(o,I.IdField);return r.as().elements.map((r,o)=>{var l;const i=Gn(e.getChildElement(o),void 0!==t);return null!=t?i:{old:null==(l=n(r))?void 0:l.initialIndex,edit:i}})}if($(o)){const n=e.schema.getChildNodes(),t=oe(o,I.IdField);return Object.fromEntries(n.flatMap(n=>{const r=Gn(e.getChild(n),t===n.field.field);return void 0!==r?[[n.field.field,r]]:[]}))}return r.value}}function jn(n){return t(n,"$nullToggler",()=>{const t=Bn(n),o=Un(n),l=null!=n.current.value;n.disabled=!l;const i=e(l);return l||(n.value=null),a(),o.subscribe(a,r.Value),i.subscribe(()=>{const e=i.current.value;n.value=e?t.current.value:null,n.disabled=!e},r.Value),i;function a(){i.disabled=!1===o.current.value}})}function Hn(n){return t(n,"$externalEditIndex",()=>e(void 0))}function Bn(n){return t(n,"$lastDefined",()=>{const t=e(n.current.value);return n.subscribe(()=>{const e=n.current.value;null!=e&&(t.value=e)},r.Value),t})}function Un(n){const o=Bn(n);return t(n,"$willEdit",()=>{const t=e(void 0);return t.subscribe(()=>{const e=t.current.value;void 0!==e&&(n.value=e?o.current.value:n.initialValue)},r.Value),t})}function $n(n){return t(n,"$allValues",()=>e([n.value]))}function Jn(e,n){const t=e.control,r=e.schema.field;if(!t.isEqual(t.initialValue,n)&&!r.collection)if($(r)){if(null==n)return;e.schema.getChildNodes().forEach(t=>{Jn(e.getChild(t),n[t.field.field])})}else $n(t).setValue(e=>e.every(e=>!t.isEqual(e,n))?[...e,n]:e)}function Pn(e,n){n.forEach((n,t)=>{0==t?e.control.setInitialValue(n):Jn(e,n)});const t=[];return function e(n){const r=n.control,o=n.schema.field;if(!o.collection)if($(o)){if(null==r.value)return;n.schema.getChildNodes().forEach(t=>{e(n.getChild(t))})}else t.push(Un(r)),$n(r).value.length>1&&(r.setInitialValue(void 0),Bn(r).value=null)}(e),()=>{let e=0,n=0;return t.forEach(t=>{const r=t.value;void 0!==r&&(e++,r&&n++)}),{editing:n,editable:e}}}function _n(e,n,t){return qe({type:L.Data,field:e,title:n},t)}function Wn(e){return n=>qe({type:e},n)}function Yn(e){return n=>qe({type:e},n)}function zn(e){return n=>({renderOptions:qe({type:e},n)})}!function(e){e.Jsonata="Jsonata",e.Date="Date",e.Length="Length"}(G||(G={})),function(e){e.NotBefore="NotBefore",e.NotAfter="NotAfter"}(j||(j={})),function(e){e.Jsonata="Jsonata",e.Data="Data",e.DataMatch="FieldValue",e.UserMatch="UserMatch",e.NotEmpty="NotEmpty",e.UUID="UUID"}(H||(H={}));const Kn=zn(k.Autocomplete),Qn=zn(k.CheckList),Xn=zn(k.Radio),Zn=Wn(G.Length),et=Wn(G.Jsonata),nt=Wn(G.Date),tt=Yn(F.Accordion),rt=zn(k.Textfield),ot=zn(k.DisplayOnly),lt=zn(k.Jsonata);function it(e,n){return qe({type:L.Display,displayData:{type:q.Text,text:e}},n)}function at(e,n){return qe({type:L.Display,displayData:{type:q.Html,html:e}},n)}function ut(e){return{type:w.DefaultValue,expr:e}}function dt(e){return{type:w.Readonly,expr:e}}function ct(e){return{type:w.Visible,expr:e}}function st(e){return{type:w.Disabled,expr:e}}function ft(e){return{type:H.Data,field:e}}function pt(e,n){return{type:H.DataMatch,field:e,value:n}}function yt(e){return{type:H.Jsonata,expression:e}}function ht(e,n,t){return qe({type:L.Group,children:e,title:n,groupOptions:{type:"Standard",hideTitle:!n}},t)}function vt(e,n,t,r){return qe({type:L.Data,field:e,children:t,title:n,renderOptions:{type:"Standard"}},r)}function mt(e,n,t){return qe({type:L.Action,title:e,actionId:n},t)}function gt(e,n,t,r){return qe({actionId:e,onClick:n,actionText:null!=t?t:e},r)}const Ct={type:L.Group,children:[],groupOptions:{type:R.Standard,hideTitle:!0}};function bt(e,n=Ct){return D(()=>{var t;return qe({},n,{children:gn(e,null!=(t=n.children)?t:[])})},[e,n])}function Dt(e,n){const t=qe({},e);return Object.entries(n).forEach(([e,n])=>{t[e]=(Array.isArray(n)?n:[n]).reduce((e,n)=>{var t;return nn(e,n.name,n.value,null!=(t=n.fields)?t:[])},t[e])}),t}function Nt(e,n){return rn(n.reduce(Dt,e))}function xt(e,n,t){return{deps:t,state:n,runHook:e}}function Tt(e,n){return e.map(e=>Ot(n(e))).join(",")}function Et(e){const n=Object.entries(e),t=Tt(n,e=>e[1].deps),r=b({}),o=r.current;return n.forEach(e=>o[e[0]]=e[1].state),N(e=>Object.fromEntries(n.map(([n,t])=>[n,t.runHook(e,r.current[n])])),[t])}function Ot(e){return void 0===e?"_":null===e?"~":e.toString()}function St(e,n,t){return Pt(qt(n,w.Visible,e),(e,{definition:n,overrideDataNode:t})=>l(()=>{const r=null!=t?t:e.dataNode;return!r||jt(r)&&!Ht(r,e.schemaInterface,n)}),{definition:n,overrideDataNode:t})}function At(e,n){return Pt(qt(n,w.Readonly,e),(e,{definition:n})=>s(()=>Dn(n)),{definition:n})}function It(e,n,t){return Pt(Gt(t,n,e),()=>o(void 0),void 0)}function Lt(e,n){return Pt(Gt(n,w.AllowedOptions,e),()=>o([]),void 0)}function wt(e,n){return Pt(qt(n,w.Disabled,e),e=>l(()=>{var t,r;const o=null==(t=e.dataNode)?void 0:t.control;return!1===(null==o||null==(r=o.meta.nullControl)?void 0:r.value)||Nn(n)}),void 0)}function Vt(e,n){return Gt(n,w.Display,e)}function Ft(e,n){return Pt(Gt(n,w.DefaultValue,e),(e,{definition:n})=>l(function(){var t;const[r,o]=me(n)?[n.required,n.defaultValue]:[!1,void 0],l=null==(t=e.dataNode)?void 0:t.schema.field;return null!=o?o:l?null!=e.dataNode.elementIndex?dn(l):un(l,r):void 0}),{definition:n})}function kt(e,n,t){switch(e.type){case H.Jsonata:const r=l(()=>({formData:n.formData}));return Ut(e.expression,we(n.parentNode).control,Ve(n.parentNode),r,t);case H.UUID:return Bt(t);case H.Data:return function(e,n,t=e=>e){const r=Y(e.field,n);return s(()=>{var e;return t(null==(e=r.control)?void 0:e.value)})}(e,n.parentNode,t);case H.DataMatch:return function(e,n,t=e=>e){const r=Y(e.field,n);return s(()=>{var n;const o=null==(n=r.control)?void 0:n.value;return t(Array.isArray(o)?o.includes(e.value):o===e.value)})}(e,n.parentNode,t);case H.NotEmpty:return function(e,n,t,r=e=>e){const o=Y(e.field,n);return s(()=>{var e;const n=null==(e=o.control)?void 0:e.value,l=o.schema.field;return r(l&&!t.isEmptyValue(l,n))})}(e,n.parentNode,n.schemaInterface,t);default:return o(void 0)}}const Mt=Rt(kt);function Rt(e){return(n,t)=>({deps:null==n?void 0:n.type,state:n&&n.type?n:void 0,runHook:(n,r)=>r?e(r,n,t):void 0})}function qt(e,n,t){return Gt(e,n,t,e=>Boolean(e))}function Gt(e,n,t,r=e=>e){var o;const l=null==(o=e.dynamic)?void 0:o.find(e=>e.type===n);return t(null==l?void 0:l.expr,r)}function jt(e){const n=e.schema.field.onlyForTypes;if(null==n||0===n.length)return!0;const t=e.parent,r=t.schema.getChildNodes().find(e=>e.field.isTypeField);if(null==r)return!0;const o=t.getChild(r).control;return o&&n.includes(o.value)}function Ht(e,n,t){var r;const o=xn(t);return o&&!o.emptyText&&n.isEmptyValue(e.schema.field,null==(r=e.control)?void 0:r.value)}function Bt(e=e=>e){return o(()=>e(O()))}function Ut(e,n,t,r,l=e=>e){const s=On(t,e=>`#$i[${e}]`),f=s?s+".("+e+")":e,p=D(()=>{try{return E(e?f:"null")}catch(e){return console.error(e),E("null")}},[f]),y=o(),h=b(),v=b(0),[m]=i(()=>new a(()=>{const e=h.current;e&&(h.current=void 0,u(()=>{h.current=e,e()}))}));return x(()=>{async function e(){const e=m.current;try{v.current++,y.value=l(await p.evaluate(d(n,e.collectUsage),c(e.collectUsage,()=>null==r?void 0:r.value)))}finally{--v.current||e.update()}}h.current=e,e()},[p]),x(()=>()=>{h.current=void 0,m.current.cleanup()},[]),y}function $t(e,n){return Pt(Gt(n,w.ActionData,e),()=>o(null),void 0)}function Jt(e,n){return Pt(Gt(n,w.Label,e),()=>o(null),void 0)}function Pt(e,n,t,r){return{deps:void 0===r?e.deps:[r,e.deps].map(Ot).join(),runHook:(t,r)=>{var o,l;return null!=(o=null==(l=e.runHook(t,r[0]))?void 0:l.as())?o:n(t,r[1])},state:[e.state,t]}}function _t(e,n=Wt){var t;const r=me(e)?e:void 0,o=bn({dd:r,useValidatorFor:n}),l=r?Tt(null!=(t=r.validators)?t:[],e=>e.type):"~";return N(e=>{var t,r,l;const{dd:i}=o.current;if(!i)return;const a=null!=(t=null==(r=e.dataContext.dataNode)?void 0:r.schema.field)?t:{field:"__missing",type:S.Any},{control:u,hiddenControl:d,dataContext:{schemaInterface:c}}=e;f(u,()=>u.setError("default","")),i.required&&p(u,e=>!d.value&&c.isEmptyValue(a,e)?c.validationMessageText(a,A.NotEmpty,!1,!0):null,"required"),null==(l=i.validators)||l.forEach((t,r)=>n(t,qe({},e,{index:r,field:a,definition:i})))},[!!r,null==r?void 0:r.required,l,n])}function Wt(e,n){switch(e.type){case G.Length:zt(e,n);break;case G.Jsonata:Yt(e,n);break;case G.Date:Kt(e,n)}}function Yt(e,n){const t=n.dataContext.parentNode,r=Ut(e.expression,we(t).control,Ve(t),void 0,e=>null==e?null:"string"==typeof e?e:JSON.stringify(e));p(n.control,()=>n.hiddenControl.value?null:r.value,"jsonata"+n.index)}function zt(e,n){const{control:t,dataContext:{schemaInterface:r},hiddenControl:o,field:l}=n;p(t,n=>{const i=r.controlLength(l,t);if(!o.value)if(null!=e.min&&i<e.min){if(null==l||!l.collection)return r.validationMessageText(l,A.MinLength,i,e.min);t.setValue(n=>Array.isArray(n)?n.concat(Array.from({length:e.min-n.length})):Array.from({length:e.min}))}else if(null!=e.max&&i>e.max)return r.validationMessageText(l,A.MaxLength,i,e.max)},"length"+n.index)}function Kt(e,n){const{control:t,field:r,index:o,dataContext:{schemaInterface:l}}=n;let i;if(e.fixedDate)i=l.parseToMillis(r,e.fixedDate);else{const n=new Date;i=Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()),e.daysFromCurrent&&(i+=864e5*e.daysFromCurrent)}p(t,n=>{if(n){const t=l.parseToMillis(r,n),o=e.comparison===j.NotAfter;if(o?t>i:t<i)return l.validationMessageText(r,o?A.NotAfterDate:A.NotBeforeDate,t,i)}return null},"date"+o)}class Qt{constructor(e=["No","Yes"],n=e=>Date.parse(e)){this.boolStrings=void 0,this.parseDateTime=void 0,this.boolStrings=e,this.parseDateTime=n}parseToMillis(e,n){return this.parseDateTime(n)}validationMessageText(e,n,t,r){switch(n){case A.NotEmpty:return"Please enter a value";case A.MinLength:return"Length must be at least "+r;case A.MaxLength:return"Length must be less than "+r;case A.NotBeforeDate:return`Date must not be before ${new Date(r).toDateString()}`;case A.NotAfterDate:return`Date must not be after ${new Date(r).toDateString()}`;default:return"Unknown error"}}getDataOptions(e){return this.getNodeOptions(e.schema)}getNodeOptions(e){return this.getOptions(e.field)}getOptions({options:e}){return e&&e.length>0?e:null}getFilterOptions(e,n){return this.getNodeOptions(n)}isEmptyValue(e,n){if(e.collection)return Array.isArray(n)?0===n.length:null==n;switch(e.type){case S.String:case S.DateTime:case S.Date:case S.Time:return!n;default:return null==n}}searchText(e,n){var t,r;return null!=(t=null==(r=this.textValue(e,n))?void 0:r.toLowerCase())?t:""}textValue(e,n,t){const r=this.getOptions(e),o=null==r?void 0:r.find(e=>e.value===n);if(o)return o.name;switch(e.type){case S.Date:return n?new Date(n).toLocaleDateString():void 0;case S.DateTime:return n?new Date(this.parseToMillis(e,n)).toLocaleString():void 0;case S.Time:return n?new Date("1970-01-01T"+n).toLocaleTimeString():void 0;case S.Bool:return this.boolStrings[n?1:0];default:return null!=n?n.toString():void 0}}controlLength(e,n){var t,r;return e.collection?null!=(t=null==(r=n.elements)?void 0:r.length)?t:0:this.valueLength(e,n.value)}valueLength(e,n){var t;return null!=(t=n&&(null==n?void 0:n.length))?t:0}compareValue(e,n,t){if(null==n)return null==t?0:1;if(null==t)return-1;switch(e.type){case S.Date:case S.DateTime:case S.Time:case S.String:return n.localeCompare(t);case S.Bool:return n?t?0:1:-1;case S.Int:case S.Double:return n-t;default:return 0}}compoundFieldSetup(e){return e.getChildNodes().map(e=>{const{field:n}=e.field;return[n,this.makeControlSetup(e)]})}compoundFieldEquality(e){return e.getChildNodes().map(e=>{const{field:n}=e.field;return[n,(t,r)=>this.makeEqualityFunc(e)(t[n],r[n])]})}makeEqualityFunc(e,n){if(e.field.collection&&!n){const n=this.makeEqualityFunc(e,!0);return(e,t)=>{if(e===t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}}if(e.field.type===S.Compound){const n=this.compoundFieldEquality(e);return(e,t)=>e===t||null!=e&&null!=t&&n.every(n=>n[1](e,t))}return(e,n)=>e===n}makeControlSetup(e,n){let t={equals:this.makeEqualityFunc(e,n)};return e.field.collection&&!n?(t.elems=this.makeControlSetup(e,!0),t):(e.field.type===S.Compound&&(t.fields=Object.fromEntries(this.compoundFieldSetup(e))),t)}}const Xt=new Qt,Zt=["parentDataNode"],er=["definition","control","formOptions","style","allowedOptions","schemaInterface","styleClass"],nr=0,tr=1e3;var rr;function or(e,n,t,r={}){const o=bn({definition:e,fields:n,renderer:t,options:r});return N(({control:e,parentPath:n})=>C.createElement(ir,qe({},o.current,{control:e,parentPath:n})),[o])}function lr(n,t,r={},i){var a,u,c;const[s,f]=n instanceof Ne?[n.definition,n]:[n,Te(n)],p=null!=(a=null==r.useDataHook?void 0:r.useDataHook(s))?a:ur,v=r.elementIndex,m=null!=(u=r.schemaInterface)?u:Xt,g=null!=(c=r.useEvalExpressionHook)?c:Mt;let b;b=null!=v?i.getChildElement(v):Ie(s,i);const D=_t(s,r.useValidationHook),T=Et({defaultValueControl:Ft(g,s),visibleControl:St(g,s),readonlyControl:At(g,s),disabledControl:wt(g,s),allowedOptions:Lt(g,s),labelText:Jt(g,s),actionData:$t(g,s),customStyle:It(g,w.Style,s),layoutStyle:It(g,w.LayoutStyle,s),displayControl:Vt(g,s)}),E=bn({options:r,definition:s,elementIndex:v,parentDataNode:i,dataNode:b,formNode:f}),O=N(()=>{const n=y();try{var r,a,u,c,f;const{definition:n,options:y,elementIndex:v,parentDataNode:N,dataNode:O,formNode:S}=E.current,A=null!=(r=y.formData)?r:{},I={schemaInterface:m,dataNode:O,parentNode:N,formData:A},{readonlyControl:L,disabledControl:w,visibleControl:V,displayControl:M,layoutStyle:R,labelText:q,customStyle:G,allowedOptions:j,defaultValueControl:H,actionData:B}=T(I),U=V.current.value,$=o(()=>null!=U?{visible:U,showing:U}:void 0);h(()=>V.value,e=>{null!=e&&$.setValue(n=>({visible:e,showing:n?n.showing:e}))});const J=i.control,P=null==(a=b)?void 0:a.control;h(()=>{var e,n;return[$.value,H.value,null==P?void 0:P.isNull,me(s)&&s.dontClearHidden,(null==(e=s.adornments)?void 0:e.some(e=>e.type===F.Optional))||me(s)&&(null==(n=s.renderOptions)?void 0:n.type)==k.NullToggle,J.isNull,y.hidden,L.value]},([e,n,t,r,o,l,i,a])=>{a||(P?e&&e.visible===e.showing&&(i||!e.visible?P.setValue(e=>y.clearHidden&&!r?void 0:null==e&&r&&!o?n:e):o||P.setValue(e=>null!=e?e:n)):l&&J.setValue(e=>null!=e?e:{}))},!0);const _=l(()=>{var e;return{hidden:y.hidden||!(null!=(e=$.fields)&&e.showing.value),readonly:y.readonly||L.value,disabled:y.disabled||w.value,displayOnly:y.displayOnly||Rn(n)}}),W=d(_);D({control:null!=P?P:e(null),hiddenControl:_.fields.hidden,dataContext:I});const Y=qe({},y,W,{elementIndex:void 0,formData:A});if(x(()=>{P&&"boolean"==typeof W.disabled&&P.disabled!=W.disabled&&(P.disabled=W.disabled)},[P,W.disabled]),J.isNull)return C.createElement(C.Fragment,null);const z=null!=(u=null==(c=s.adornments)?void 0:c.map(e=>t.renderAdornment({adornment:e,dataContext:I,useExpr:g,formOptions:W})))?u:[],K=dr({formNode:S,definition:n,renderer:t,renderChild:(e,r,o)=>{var l;const i=Mn(n),a=null!=o?o:{},{parentDataNode:u}=a,d=Ge(a,Zt),c=null!=(l=null!=u?u:I.dataNode)?l:I.parentNode;return C.createElement(ar,{key:e,definition:r,renderer:t,parentDataNode:c,options:qe({},Y,i,d)})},createDataProps:p,formOptions:W,dataContext:I,control:null!=M?M:P,elementIndex:v,schemaInterface:m,labelText:q,displayControl:M,style:G.value,allowedOptions:j,customDisplay:y.customDisplay,actionDataControl:B,actionOnClick:y.actionOnClick,styleClass:y.styleClass,labelClass:y.labelClass,useEvalExpression:g,useChildVisibility:(e,n,t)=>{var r;return St(g,e,t?void 0:Ie(e,null!=(r=null!=n?n:b)?r:i))}}),Q=qe({},K,{adornments:z,className:In(y.layoutClass,n.layoutClass),style:R.value}),X=t.renderLayout(null!=(f=null==y.adjustLayout?void 0:y.adjustLayout(I,Q))?f:Q);return t.renderVisibility(qe({visibility:$},X))}finally{n()}},[E,p,D,t,m,T]);return O.displayName="RenderControl",O}function ir({definition:e,fields:n,renderer:t,options:r,control:o}){const l=lr(e,t,r,W(_({"":n}).getSchema(""),o));return C.createElement(l,null)}function ar({definition:e,renderer:n,options:t,parentDataNode:r}){const o=lr(e,n,t,r);return C.createElement(o,null)}function ur(e){var n,t;let{definition:r,control:o,formOptions:l,style:i,allowedOptions:a,schemaInterface:u=Xt,styleClass:d}=e,c=Ge(e,er);const s=c.dataContext.dataNode,f=s.schema.field,p=In(d,r.styleClass),y=!!l.displayOnly,h=!!r.required&&!y,v=u.getDataOptions(s),m=null!=(n=null==a?void 0:a.value)?n:[],g=Array.isArray(m)?m:[m];return qe({dataNode:s,definition:r,control:o,field:f,id:"c"+o.uniqueId,options:g.length>0?g.map(e=>{var n;return"object"==typeof e?e:null!=(n=null==v?void 0:v.find(n=>n.value==e))?n:{name:e.toString(),value:e}}).filter(e=>null!=e):v,readonly:!!l.readonly,displayOnly:y,renderOptions:null!=(t=r.renderOptions)?t:{type:"Standard"},required:h,hidden:!!l.hidden,className:p,style:i},c)}function dr(e){const{definition:n,renderer:t,renderChild:r,control:o,dataContext:l,createDataProps:i,displayControl:a,style:u,labelText:d,useChildVisibility:c,designMode:s,customDisplay:f,useEvalExpression:p,labelClass:y,styleClass:h,formNode:v}=e;if(me(n))return S(n);var m,g,C,b;if(ge(n))return n.compoundField?S(_n(n.compoundField,n.title,{children:n.children,hideTitle:null==(b=n.groupOptions)?void 0:b.hideTitle})):{processLayout:t.renderGroup({formNode:v,definition:n,renderChild:r,useEvalExpression:p,dataContext:l,renderOptions:null!=(m=n.groupOptions)?m:{type:"Standard"},className:In(h,n.styleClass),useChildVisibility:c,style:u,designMode:s}),label:{label:null!=(g=null==d?void 0:d.value)?g:n.title,className:In(y,n.labelClass),type:rr.Group,hide:null==(C=n.groupOptions)?void 0:C.hideTitle}};if(Ce(n)){var D,N,x,T,E;const r=null!=(D=null==(N=e.actionDataControl)?void 0:N.value)?D:n.actionData;return{children:t.renderAction({actionText:null!=(x=null!=(T=null==d?void 0:d.value)?T:n.title)?x:n.actionId,actionId:n.actionId,actionData:r,onClick:null!=(E=null==e.actionOnClick?void 0:e.actionOnClick(n.actionId,r,l))?E:()=>{},className:In(h,n.styleClass),style:u})}}if(be(n)){var O;const e=null!=(O=n.displayData)?O:{},r={data:e,className:In(h,n.styleClass),style:u,display:a,dataContext:l};return e.type===q.Custom&&f?{children:f(e.customId,r)}:{children:t.renderDisplay(r)}}return{};function S(n){var r,l,a;if(!o)return{children:"No control for: "+n.field};const u=i(e),c=n.hideTitle?void 0:mr(null!=(r=null==d?void 0:d.value)?r:n.title,e.dataContext.dataNode.schema.field);return{processLayout:t.renderData(u),label:{type:(null!=(l=null==(a=n.children)?void 0:a.length)?l:0)>0?rr.Group:rr.Control,label:c,forId:u.id,required:n.required&&!e.formOptions.displayOnly,hide:n.hideTitle,className:In(y,n.labelClass)},errorControl:o}}}function cr(e,n){return t=>t[e]=C.createElement(C.Fragment,null,t[e],n)}function sr(e,n){return t=>t[e]=n(t[e])}function fr(e){switch(e){case V.ControlEnd:return"controlEnd";case V.ControlStart:return"controlStart";case V.LabelStart:return"labelStart";case V.LabelEnd:return"labelEnd"}}function pr(e){return n=>{const t=n.wrapLayout;n.wrapLayout=n=>e(t(n))}}function yr(e,n){return cr(fr(e),n)}function hr(e,n){return sr(fr(e),n)}function vr(e,n){var t;const{className:r,children:o,style:l,errorControl:i,label:a,adornments:u}=null!=(t=null==e.processLayout?void 0:e.processLayout(e))?t:e,d={children:o,errorControl:i,style:l,className:r,wrapLayout:e=>e};return(null!=u?u:[]).sort((e,n)=>e.priority-n.priority).forEach(e=>e.apply(d)),d.label=a&&!a.hide?n.renderLabel(a,d.labelStart,d.labelEnd):void 0,d}function mr(e,n){return e||pn(n)}function gr(e){var n;const t=null==(n=e.validators)?void 0:n.find(e=>e.type===G.Length);return{min:null==t?void 0:t.min,max:null==t?void 0:t.max}}function Cr(e,n,t){var r;const o=null!=(r=n.displayName)?r:n.field,{addText:l,noAdd:i,removeText:a,noRemove:u,removeActionId:d,addActionId:c,editActionId:s,editText:f,disabled:p,readonly:y,designMode:h,editExternal:m}=null!=t?t:{};return{arrayControl:e,addAction:y||i?void 0:C(()=>{if(!h){const t=dn(n);if(m){const t=Hn(e);t.value={data:[dn(n)],actions:[b(),C(()=>{g(e,t.fields.data.value[0]),t.value=void 0})]}}else g(e,t)}}),editAction:m?n=>({actionId:s||"edit",actionText:f||"Edit",onClick:()=>{if(!h){const t=Hn(e),r=e.as().elements[n];t.value={data:[r.current.value],actions:[b(),{actionId:"apply",actionText:"Apply",onClick:()=>{r.value=t.fields.data.value[0],t.value=void 0}}]}}}}):void 0,removeAction:y||u?void 0:n=>({actionId:d||"remove",actionText:a||"Remove",onClick:()=>{h||v(e,n)},disabled:p})};function C(e){return{actionId:c||"add",actionText:l||"Add "+o,onClick:e,disabled:p}}function b(){return{actionId:"cancel",actionText:"Cancel",onClick:()=>{Hn(e).value=void 0},disabled:p}}}function br({arrayControl:e,min:n,max:t,editAction:r,addAction:o,removeAction:l,required:i},a){var u,d;const[c,s]=Ln(null!=(u=null==(d=e.elements)?void 0:d.length)?u:0,null==n&&i?1:n,t,!0,!0);return{addAction:a||s?o:void 0,removeAction:a||c?l:void 0,removeDisabled:!c,addDisabled:!s,editAction:r}}function Dr(e){return(n,t,r)=>C.createElement(m,{array:e.formNode.getChildNodes()},(t,o)=>e.renderChild(o,t,{parentDataNode:e.dataContext.parentNode,formData:{option:n,optionSelected:r}}))}function Nr(e){return e.type===F.Icon}function xr(e){return e.type===F.Accordion}function Tr(e){return e.type===F.SetField}function Er(e){return e.type===F.Optional}function Or(e,n){return qe({type:"layout",render:e},n)}function Sr(e,n,t){return qe({type:"action",actionType:e,render:n},t)}function Ar(e,n){return qe({type:"array",render:e},n)}function Ir(e,n){return qe({type:"data",render:e},n)}function Lr(e,n){return qe({type:"group",render:e},n)}function wr(e,n){return qe({type:"display",render:e},n)}function Vr(e,n){return qe({type:"label",render:e},n)}function Fr(e,n){return qe({type:"visibility",render:e},n)}function kr(e,n){return qe({type:"adornment"},n,{render:e})}function Mr(e=[],n){var t;const r=e.filter(Gr),o=e.filter(jr),l=e.filter(qr),i=e.filter(Jr),a=e.filter(Hr),u=e.filter(Pr),d=e.filter($r),c=e.filter(Br),s={renderAction:function(e){var t;return(null!=(t=d.find(n=>Rr(n.actionType,e.actionId)))?t:n.action).render(e,s)},renderData:function(e){var t;const{renderOptions:{type:o},field:l}=e,i=yn(e),a=(null!=(t=r.find(n=>{var t,r,a;return(null!=(t=n.collection)&&t)===(null==e.elementIndex&&null!=(r=l.collection)&&r)&&(null!=(a=n.options)&&a)===i&&(n.schemaType&&o==k.Standard&&Rr(n.schemaType,l.type)||n.renderType&&Rr(n.renderType,o)||n.match&&n.match(e))}))?t:n.data).render(e,s);return"function"==typeof a?a:e=>qe({},e,{children:a})},renderGroup:function(e){var t;const r=e.renderOptions.type,l=(null!=(t=o.find(e=>Rr(e.renderType,r)))?t:n.group).render(e,s);return"function"==typeof l?l:e=>qe({},e,{children:l})},renderDisplay:function(e){var t;const r=e.data.type;return(null!=(t=i.find(e=>Rr(e.renderType,r)))?t:n.display).render(e,s)},renderLabel:f,renderArray:function(e){var t;return(null!=(t=u[0])?t:n.array).render(e,s)},renderAdornment:function(e){var t;return(null!=(t=l.find(n=>Rr(n.adornmentType,e.adornment.type)))?t:n.adornment).render(e,s)},renderLayout:function(e){var t;return(null!=(t=c.find(n=>!n.match||n.match(e)))?t:n.renderLayout).render(e,s)},renderVisibility:(null!=(t=e.find(Ur))?t:n.visibility).render,renderLabelText:function(e){return f({label:e,type:rr.Text},void 0,void 0)}};function f(e,t,r){var o;return(null!=(o=a.find(n=>Rr(n.labelType,e.type)))?o:n.label).render(e,t,r,s)}return s}function Rr(e,n){return null==e||(Array.isArray(e)?e.includes(n):n===e)}function qr(e){return"adornment"===e.type}function Gr(e){return"data"===e.type}function jr(e){return"group"===e.type}function Hr(e){return"label"===e.type}function Br(e){return"layout"===e.type}function Ur(e){return"visibility"===e.type}function $r(e){return"action"===e.type}function Jr(e){return"display"===e.type}function Pr(e){return"array"===e.type}!function(e){e[e.Control=0]="Control",e[e.Group=1]="Group",e[e.Text=2]="Text"}(rr||(rr={}));export{V as AdornmentPlacement,nr as AppendAdornmentPriority,F as ControlAdornmentType,L as ControlDefinitionType,ir as ControlRenderer,k as DataRenderType,j as DateComparison,Qt as DefaultSchemaInterface,q as DisplayDataType,w as DynamicPropertyType,H as ExpressionType,S as FieldType,Ne as FormNode,R as GroupRenderType,rr as LabelType,ar as NewControlRenderer,I as SchemaTags,M as SyncTextType,A as ValidationMessageType,G as ValidatorType,tr as WrapAdornmentPriority,tt as accordionOptions,mt as actionControl,qn as actionHandlers,tn as addFieldOption,gn as addMissingControls,Cn as addMissingControlsForSchema,Yn as adornmentOptions,cr as appendMarkup,yr as appendMarkupAt,br as applyArrayLengthRestrictions,ln as applyDefaultForField,on as applyDefaultValues,Dt as applyExtensionToSchema,Nt as applyExtensionsToSchema,Ln as applyLengthRestrictions,Jn as applyValues,Kn as autocompleteOptions,Ke as boolField,je as buildSchema,Qn as checkListOptions,Tn as cleanDataForSchema,Fn as coerceToString,Pn as collectDifferences,vt as compoundControl,Qe as compoundField,mr as controlTitle,gt as createAction,Sr as createActionRenderer,kr as createAdornmentRenderer,Cr as createArrayActions,Ar as createArrayRenderer,Ir as createDataRenderer,wr as createDisplayRenderer,Se as createFormLookup,Mr as createFormRenderer,Lr as createGroupRenderer,Vr as createLabelRenderer,Or as createLayoutRenderer,_ as createSchemaLookup,Fr as createVisibilityRenderer,_n as dataControl,We as dateField,ze as dateTimeField,nt as dateValidatorOptions,Ze as defaultCompoundField,hn as defaultControlForField,ur as defaultDataProps,kt as defaultEvalHooks,Xe as defaultScalarField,Xt as defaultSchemaInterface,Mt as defaultUseEvalExpressionHook,un as defaultValueForField,an as defaultValueForFields,ot as displayOnlyOptions,_e as doubleField,ut as dynamicDefaultValue,st as dynamicDisabled,dt as dynamicReadonly,ct as dynamicVisibility,dn as elementValueForField,Ct as emptyGroupDefinition,pn as fieldDisplayName,pt as fieldEqExpr,ft as fieldExpr,fn as fieldHasTag,Dr as fieldOptionAdornment,Ae as fieldPathForDefinition,Sn as findChildDefinition,sn as findCompoundField,vn as findControlsForCompound,B as findField,wn as findFieldPath,mn as findNonDataGroups,cn as findScalarField,En as getAllReferencedClasses,$n as getAllValues,Gn as getDiffObject,xn as getDisplayOnlyOptions,Hn as getExternalEditData,Mn as getGroupClassOverrides,kn as getGroupRendererOptions,Un as getIsEditing,Ve as getJsonPath,Bn as getLastDefinedValue,gr as getLengthRestrictions,jn as getNullToggler,An as getOverrideClass,we as getRootDataNode,ke as getSchemaFieldList,ne as getSchemaNodePath,Fe as getSchemaPath,oe as getTagParam,ht as groupedControl,yn as hasOptions,Ht as hideDisplayOnly,at as htmlDisplayControl,Pe as intField,xr as isAccordionAdornment,Ce as isActionControl,ve as isArrayRenderer,ye as isAutoCompleteClasses,pe as isAutocompleteRenderer,De as isCheckEntryClasses,$ as isCompoundField,te as isCompoundNode,Nn as isControlDisabled,Rn as isControlDisplayOnly,Dn as isControlReadonly,me as isDataControl,he as isDataGroupRenderer,be as isDisplayControl,se as isDisplayOnlyRenderer,ce as isFlexRenderer,ae as isGridRenderer,ge as isGroupControl,Nr as isIconAdornment,Er as isOptionalAdornment,U as isScalarField,ue as isSelectChildRenderer,Tr as isSetFieldAdornment,de as isTabsRenderer,fe as isTextfieldRenderer,On as jsonPathString,yt as jsonataExpr,lt as jsonataOptions,et as jsonataValidatorOptions,fr as layoutKeyForPlacement,Te as legacyFormNode,Zn as lengthValidatorOptions,Ie as lookupDataNode,Je as makeCompoundField,Rt as makeEvalExpressionHook,xt as makeHook,Tt as makeHookDepString,le as makeParamTag,$e as makeScalarField,W as makeSchemaDataNode,jt as matchesType,en as mergeField,nn as mergeFields,Vn as mergeObjects,xe as nodeForControl,Xn as radioButtonOptions,re as relativePath,dr as renderControlLayout,vr as renderLayoutParts,zn as renderOptionsFor,In as rendererClass,rn as resolveSchemas,ee as rootSchemaNode,X as schemaDataForFieldPath,Y as schemaDataForFieldRef,Z as schemaForFieldPath,z as schemaForFieldRef,He as stringField,Be as stringOptionsField,it as textDisplayControl,rt as textfieldOptions,Ye as timeField,Ot as toDepString,Q as traverseData,Le as traverseParents,K as traverseSchemaPath,bt as useControlDefinitionForSchema,or as useControlRenderer,lr as useControlRendererComponent,Kt as useDateValidator,Et as useDynamicHooks,$t as useEvalActionHook,Lt as useEvalAllowedOptionsHook,Ft as useEvalDefaultValueHook,wt as useEvalDisabledHook,Vt as useEvalDisplayHook,qt as useEvalDynamicBoolHook,Gt as useEvalDynamicHook,Jt as useEvalLabelText,At as useEvalReadonlyHook,It as useEvalStyleHook,St as useEvalVisibilityHook,Ut as useJsonataExpression,Yt as useJsonataValidator,zt as useLengthValidator,_t as useMakeValidationHook,bn as useUpdatedRef,Bt as useUuidExpression,Wn as validatorOptions,Re as visitControlData,Me as visitControlDataArray,ie as visitControlDefinition,Ue as withScalarOptions,pr as wrapLayout,sr as wrapMarkup,hr as wrapMarkupAt};
|
|
1
|
+
import { newControl, getElementIndex, ensureMetaValue, ControlChange, useControl, useComputed, useRefState, SubscriptionTracker, addAfterChangesCallback, trackedValue, collectChanges, useCalculatedControl, useValueChangeEffect, useValidator, useComponentTracking, useControlEffect, removeElement, RenderArrayElements, addElement } from '@react-typed-forms/core';
|
|
2
|
+
import React, { useRef, useMemo, useCallback, useEffect } from 'react';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import jsonata from 'jsonata';
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Enum representing the various field types.
|
|
9
|
+
*/
|
|
10
|
+
var FieldType;
|
|
11
|
+
(function (FieldType) {
|
|
12
|
+
FieldType["String"] = "String";
|
|
13
|
+
FieldType["Bool"] = "Bool";
|
|
14
|
+
FieldType["Int"] = "Int";
|
|
15
|
+
FieldType["Date"] = "Date";
|
|
16
|
+
FieldType["DateTime"] = "DateTime";
|
|
17
|
+
FieldType["Time"] = "Time";
|
|
18
|
+
FieldType["Double"] = "Double";
|
|
19
|
+
FieldType["EntityRef"] = "EntityRef";
|
|
20
|
+
FieldType["Compound"] = "Compound";
|
|
21
|
+
FieldType["AutoId"] = "AutoId";
|
|
22
|
+
FieldType["Image"] = "Image";
|
|
23
|
+
FieldType["Any"] = "Any";
|
|
24
|
+
})(FieldType || (FieldType = {}));
|
|
25
|
+
/**
|
|
26
|
+
* Enum representing the various validation message types.
|
|
27
|
+
*/
|
|
28
|
+
var ValidationMessageType;
|
|
29
|
+
(function (ValidationMessageType) {
|
|
30
|
+
ValidationMessageType["NotEmpty"] = "NotEmpty";
|
|
31
|
+
ValidationMessageType["MinLength"] = "MinLength";
|
|
32
|
+
ValidationMessageType["MaxLength"] = "MaxLength";
|
|
33
|
+
ValidationMessageType["NotAfterDate"] = "NotAfterDate";
|
|
34
|
+
ValidationMessageType["NotBeforeDate"] = "NotBeforeDate";
|
|
35
|
+
})(ValidationMessageType || (ValidationMessageType = {}));
|
|
36
|
+
function findField(fields, field) {
|
|
37
|
+
return fields.find(x => x.field === field);
|
|
38
|
+
}
|
|
39
|
+
function isScalarField(sf) {
|
|
40
|
+
return !isCompoundField(sf);
|
|
41
|
+
}
|
|
42
|
+
function isCompoundField(sf) {
|
|
43
|
+
return sf.type === FieldType.Compound;
|
|
44
|
+
}
|
|
45
|
+
function missingField(field) {
|
|
46
|
+
return {
|
|
47
|
+
field: "__missing",
|
|
48
|
+
type: FieldType.Any,
|
|
49
|
+
displayName: field
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function nodeForSchema(field, lookup, parent) {
|
|
53
|
+
const node = {
|
|
54
|
+
id: parent ? parent.id + "/" + field.field : field.field,
|
|
55
|
+
field,
|
|
56
|
+
getSchema: lookup.getSchema,
|
|
57
|
+
parent,
|
|
58
|
+
getChildNode,
|
|
59
|
+
getChildNodes
|
|
60
|
+
};
|
|
61
|
+
return node;
|
|
62
|
+
function getChildNode(fieldName) {
|
|
63
|
+
if (isCompoundField(field) && !field.schemaRef && !field.treeChildren) {
|
|
64
|
+
const childField = field.children.find(x => x.field === fieldName);
|
|
65
|
+
return childField ? nodeForSchema(childField, lookup, node) : undefined;
|
|
66
|
+
}
|
|
67
|
+
return getChildNodes(false, node).find(x => x.field.field === fieldName);
|
|
68
|
+
}
|
|
69
|
+
function getChildNodes(noRecurse, withParent) {
|
|
70
|
+
if (isCompoundField(field)) {
|
|
71
|
+
if (field.treeChildren) {
|
|
72
|
+
return noRecurse ? [] : parent.getChildNodes(false, withParent != null ? withParent : node);
|
|
73
|
+
}
|
|
74
|
+
const otherRef = field.schemaRef && lookup.getSchema(field.schemaRef);
|
|
75
|
+
if (otherRef) return otherRef.getChildNodes(false, withParent != null ? withParent : node);
|
|
76
|
+
return field.children.map(x => nodeForSchema(x, lookup, withParent != null ? withParent : node));
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function createSchemaLookup(schemaMap) {
|
|
82
|
+
const lookup = {
|
|
83
|
+
getSchema
|
|
84
|
+
};
|
|
85
|
+
return lookup;
|
|
86
|
+
function getSchema(schemaId) {
|
|
87
|
+
const fields = schemaMap[schemaId];
|
|
88
|
+
if (fields) {
|
|
89
|
+
return rootSchemaNode(fields, lookup);
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function makeSchemaDataNode(schema, control, parent, elementIndex) {
|
|
95
|
+
const indexId = typeof elementIndex === "number" ? "/" + elementIndex : "";
|
|
96
|
+
const dataNode = {
|
|
97
|
+
id: (parent ? parent.id + "/" + schema.field.field : schema.field.field) + indexId,
|
|
98
|
+
schema,
|
|
99
|
+
control,
|
|
100
|
+
parent,
|
|
101
|
+
elementIndex,
|
|
102
|
+
getChild,
|
|
103
|
+
getChildElement
|
|
104
|
+
};
|
|
105
|
+
return dataNode;
|
|
106
|
+
function getChild(childNode) {
|
|
107
|
+
const objControl = control;
|
|
108
|
+
if (objControl && objControl.current.isNull) {
|
|
109
|
+
objControl.value = {};
|
|
110
|
+
}
|
|
111
|
+
return makeSchemaDataNode(childNode, objControl == null ? void 0 : objControl.fields[childNode.field.field], dataNode);
|
|
112
|
+
}
|
|
113
|
+
function getChildElement(elementIndex) {
|
|
114
|
+
var _control$elements;
|
|
115
|
+
return makeSchemaDataNode(schema, control == null || (_control$elements = control.elements) == null ? void 0 : _control$elements[elementIndex], dataNode, elementIndex);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function schemaDataForFieldRef(fieldRef, schema) {
|
|
119
|
+
var _fieldRef$split;
|
|
120
|
+
return schemaDataForFieldPath((_fieldRef$split = fieldRef == null ? void 0 : fieldRef.split("/")) != null ? _fieldRef$split : [], schema);
|
|
121
|
+
}
|
|
122
|
+
function schemaForFieldRef(fieldRef, schema) {
|
|
123
|
+
var _fieldRef$split2;
|
|
124
|
+
return schemaForFieldPath((_fieldRef$split2 = fieldRef == null ? void 0 : fieldRef.split("/")) != null ? _fieldRef$split2 : [], schema);
|
|
125
|
+
}
|
|
126
|
+
function traverseSchemaPath(fieldPath, schema, acc, next) {
|
|
127
|
+
let i = 0;
|
|
128
|
+
while (i < fieldPath.length) {
|
|
129
|
+
const nextField = fieldPath[i];
|
|
130
|
+
let childNode = nextField === ".." ? schema.parent : schema.getChildNode(nextField);
|
|
131
|
+
if (!childNode) {
|
|
132
|
+
childNode = nodeForSchema(missingField(nextField), schema, schema);
|
|
133
|
+
}
|
|
134
|
+
acc = next(acc, childNode);
|
|
135
|
+
schema = childNode;
|
|
136
|
+
i++;
|
|
137
|
+
}
|
|
138
|
+
return acc;
|
|
139
|
+
}
|
|
140
|
+
function traverseData(fieldPath, root, data) {
|
|
141
|
+
return traverseSchemaPath(fieldPath, root, data, (acc, n) => acc == null ? void 0 : acc[n.field.field]);
|
|
142
|
+
}
|
|
143
|
+
function schemaDataForFieldPath(fieldPath, dataNode) {
|
|
144
|
+
let i = 0;
|
|
145
|
+
while (i < fieldPath.length) {
|
|
146
|
+
var _nextNode;
|
|
147
|
+
const nextField = fieldPath[i];
|
|
148
|
+
let nextNode = nextField === ".." ? dataNode.parent : lookupField(nextField);
|
|
149
|
+
(_nextNode = nextNode) != null ? _nextNode : nextNode = makeSchemaDataNode(nodeForSchema(missingField(nextField), dataNode.schema, dataNode.schema), newControl(undefined));
|
|
150
|
+
dataNode = nextNode;
|
|
151
|
+
i++;
|
|
152
|
+
}
|
|
153
|
+
return dataNode;
|
|
154
|
+
function lookupField(field) {
|
|
155
|
+
const childNode = dataNode.schema.getChildNode(field);
|
|
156
|
+
if (childNode) {
|
|
157
|
+
return dataNode.getChild(childNode);
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function schemaForFieldPath(fieldPath, schema) {
|
|
163
|
+
let i = 0;
|
|
164
|
+
while (i < fieldPath.length) {
|
|
165
|
+
const nextField = fieldPath[i];
|
|
166
|
+
let childNode = nextField === ".." ? schema.parent : schema.getChildNode(nextField);
|
|
167
|
+
if (!childNode) {
|
|
168
|
+
childNode = nodeForSchema(missingField(nextField), schema, schema);
|
|
169
|
+
}
|
|
170
|
+
schema = childNode;
|
|
171
|
+
i++;
|
|
172
|
+
}
|
|
173
|
+
return schema;
|
|
174
|
+
}
|
|
175
|
+
function rootSchemaNode(fields, lookup = {
|
|
176
|
+
getSchema(schemaId) {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}) {
|
|
180
|
+
return nodeForSchema({
|
|
181
|
+
type: FieldType.Compound,
|
|
182
|
+
field: "",
|
|
183
|
+
children: fields
|
|
184
|
+
}, lookup, undefined);
|
|
185
|
+
}
|
|
186
|
+
function getSchemaNodePath(node) {
|
|
187
|
+
const paths = [];
|
|
188
|
+
let curNode = node;
|
|
189
|
+
while (curNode) {
|
|
190
|
+
paths.push(curNode.field.field);
|
|
191
|
+
curNode = curNode.parent;
|
|
192
|
+
}
|
|
193
|
+
return paths.reverse();
|
|
194
|
+
}
|
|
195
|
+
function isCompoundNode(node) {
|
|
196
|
+
return isCompoundField(node.field);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Returns the relative path from a parent node to a child node.
|
|
200
|
+
* @param parent
|
|
201
|
+
* @param child
|
|
202
|
+
*/
|
|
203
|
+
function relativePath(parent, child) {
|
|
204
|
+
// return the path from child to parent
|
|
205
|
+
if (parent.id === child.id) return "";
|
|
206
|
+
const parentPath = getSchemaNodePath(parent);
|
|
207
|
+
const childPath = getSchemaNodePath(child);
|
|
208
|
+
let i = 0;
|
|
209
|
+
while (i < parentPath.length && i < childPath.length && parentPath[i] === childPath[i]) {
|
|
210
|
+
i++;
|
|
211
|
+
}
|
|
212
|
+
const upLevels = parentPath.length - i;
|
|
213
|
+
const downPath = childPath.slice(i).join("/");
|
|
214
|
+
return "../".repeat(upLevels) + downPath;
|
|
215
|
+
}
|
|
216
|
+
var SchemaTags;
|
|
217
|
+
(function (SchemaTags) {
|
|
218
|
+
SchemaTags["NoControl"] = "_NoControl";
|
|
219
|
+
SchemaTags["HtmlEditor"] = "_HtmlEditor";
|
|
220
|
+
SchemaTags["ControlGroup"] = "_ControlGroup:";
|
|
221
|
+
SchemaTags["ControlRef"] = "_ControlRef:";
|
|
222
|
+
SchemaTags["IdField"] = "_IdField:";
|
|
223
|
+
})(SchemaTags || (SchemaTags = {}));
|
|
224
|
+
function getTagParam(field, tag) {
|
|
225
|
+
var _field$tags;
|
|
226
|
+
return (_field$tags = field.tags) == null || (_field$tags = _field$tags.find(x => x.startsWith(tag))) == null ? void 0 : _field$tags.substring(tag.length);
|
|
227
|
+
}
|
|
228
|
+
function makeParamTag(tag, value) {
|
|
229
|
+
return `${tag}${value}`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
var ControlDefinitionType;
|
|
233
|
+
(function (ControlDefinitionType) {
|
|
234
|
+
ControlDefinitionType["Data"] = "Data";
|
|
235
|
+
ControlDefinitionType["Group"] = "Group";
|
|
236
|
+
ControlDefinitionType["Display"] = "Display";
|
|
237
|
+
ControlDefinitionType["Action"] = "Action";
|
|
238
|
+
})(ControlDefinitionType || (ControlDefinitionType = {}));
|
|
239
|
+
var DynamicPropertyType;
|
|
240
|
+
(function (DynamicPropertyType) {
|
|
241
|
+
DynamicPropertyType["Visible"] = "Visible";
|
|
242
|
+
DynamicPropertyType["DefaultValue"] = "DefaultValue";
|
|
243
|
+
DynamicPropertyType["Readonly"] = "Readonly";
|
|
244
|
+
DynamicPropertyType["Disabled"] = "Disabled";
|
|
245
|
+
DynamicPropertyType["Display"] = "Display";
|
|
246
|
+
DynamicPropertyType["Style"] = "Style";
|
|
247
|
+
DynamicPropertyType["LayoutStyle"] = "LayoutStyle";
|
|
248
|
+
DynamicPropertyType["AllowedOptions"] = "AllowedOptions";
|
|
249
|
+
DynamicPropertyType["Label"] = "Label";
|
|
250
|
+
DynamicPropertyType["ActionData"] = "ActionData";
|
|
251
|
+
})(DynamicPropertyType || (DynamicPropertyType = {}));
|
|
252
|
+
var AdornmentPlacement;
|
|
253
|
+
(function (AdornmentPlacement) {
|
|
254
|
+
AdornmentPlacement["ControlStart"] = "ControlStart";
|
|
255
|
+
AdornmentPlacement["ControlEnd"] = "ControlEnd";
|
|
256
|
+
AdornmentPlacement["LabelStart"] = "LabelStart";
|
|
257
|
+
AdornmentPlacement["LabelEnd"] = "LabelEnd";
|
|
258
|
+
})(AdornmentPlacement || (AdornmentPlacement = {}));
|
|
259
|
+
var ControlAdornmentType;
|
|
260
|
+
(function (ControlAdornmentType) {
|
|
261
|
+
ControlAdornmentType["Tooltip"] = "Tooltip";
|
|
262
|
+
ControlAdornmentType["Accordion"] = "Accordion";
|
|
263
|
+
ControlAdornmentType["HelpText"] = "HelpText";
|
|
264
|
+
ControlAdornmentType["Icon"] = "Icon";
|
|
265
|
+
ControlAdornmentType["SetField"] = "SetField";
|
|
266
|
+
ControlAdornmentType["Optional"] = "Optional";
|
|
267
|
+
})(ControlAdornmentType || (ControlAdornmentType = {}));
|
|
268
|
+
var DataRenderType;
|
|
269
|
+
(function (DataRenderType) {
|
|
270
|
+
DataRenderType["Standard"] = "Standard";
|
|
271
|
+
DataRenderType["Textfield"] = "Textfield";
|
|
272
|
+
DataRenderType["Radio"] = "Radio";
|
|
273
|
+
DataRenderType["HtmlEditor"] = "HtmlEditor";
|
|
274
|
+
DataRenderType["IconList"] = "IconList";
|
|
275
|
+
DataRenderType["CheckList"] = "CheckList";
|
|
276
|
+
DataRenderType["UserSelection"] = "UserSelection";
|
|
277
|
+
DataRenderType["Synchronised"] = "Synchronised";
|
|
278
|
+
DataRenderType["IconSelector"] = "IconSelector";
|
|
279
|
+
DataRenderType["DateTime"] = "DateTime";
|
|
280
|
+
DataRenderType["Checkbox"] = "Checkbox";
|
|
281
|
+
DataRenderType["Dropdown"] = "Dropdown";
|
|
282
|
+
DataRenderType["DisplayOnly"] = "DisplayOnly";
|
|
283
|
+
DataRenderType["Group"] = "Group";
|
|
284
|
+
DataRenderType["NullToggle"] = "NullToggle";
|
|
285
|
+
DataRenderType["Autocomplete"] = "Autocomplete";
|
|
286
|
+
DataRenderType["Jsonata"] = "Jsonata";
|
|
287
|
+
DataRenderType["Array"] = "Array";
|
|
288
|
+
DataRenderType["ArrayElement"] = "ArrayElement";
|
|
289
|
+
})(DataRenderType || (DataRenderType = {}));
|
|
290
|
+
var SyncTextType;
|
|
291
|
+
(function (SyncTextType) {
|
|
292
|
+
SyncTextType["Camel"] = "Camel";
|
|
293
|
+
SyncTextType["Snake"] = "Snake";
|
|
294
|
+
SyncTextType["Pascal"] = "Pascal";
|
|
295
|
+
})(SyncTextType || (SyncTextType = {}));
|
|
296
|
+
var GroupRenderType;
|
|
297
|
+
(function (GroupRenderType) {
|
|
298
|
+
GroupRenderType["Standard"] = "Standard";
|
|
299
|
+
GroupRenderType["Grid"] = "Grid";
|
|
300
|
+
GroupRenderType["Flex"] = "Flex";
|
|
301
|
+
GroupRenderType["Tabs"] = "Tabs";
|
|
302
|
+
GroupRenderType["GroupElement"] = "GroupElement";
|
|
303
|
+
GroupRenderType["SelectChild"] = "SelectChild";
|
|
304
|
+
})(GroupRenderType || (GroupRenderType = {}));
|
|
305
|
+
var DisplayDataType;
|
|
306
|
+
(function (DisplayDataType) {
|
|
307
|
+
DisplayDataType["Text"] = "Text";
|
|
308
|
+
DisplayDataType["Html"] = "Html";
|
|
309
|
+
DisplayDataType["Icon"] = "Icon";
|
|
310
|
+
DisplayDataType["Custom"] = "Custom";
|
|
311
|
+
})(DisplayDataType || (DisplayDataType = {}));
|
|
312
|
+
function visitControlDefinition(x, visitor, defaultValue) {
|
|
313
|
+
switch (x.type) {
|
|
314
|
+
case ControlDefinitionType.Action:
|
|
315
|
+
return visitor.action(x);
|
|
316
|
+
case ControlDefinitionType.Data:
|
|
317
|
+
return visitor.data(x);
|
|
318
|
+
case ControlDefinitionType.Display:
|
|
319
|
+
return visitor.display(x);
|
|
320
|
+
case ControlDefinitionType.Group:
|
|
321
|
+
return visitor.group(x);
|
|
322
|
+
default:
|
|
323
|
+
return defaultValue(x);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function isGridRenderer(options) {
|
|
327
|
+
return options.type === GroupRenderType.Grid;
|
|
328
|
+
}
|
|
329
|
+
function isSelectChildRenderer(options) {
|
|
330
|
+
return options.type === GroupRenderType.SelectChild;
|
|
331
|
+
}
|
|
332
|
+
function isTabsRenderer(options) {
|
|
333
|
+
return options.type === GroupRenderType.Tabs;
|
|
334
|
+
}
|
|
335
|
+
function isFlexRenderer(options) {
|
|
336
|
+
return options.type === GroupRenderType.Flex;
|
|
337
|
+
}
|
|
338
|
+
function isDisplayOnlyRenderer(options) {
|
|
339
|
+
return options.type === DataRenderType.DisplayOnly;
|
|
340
|
+
}
|
|
341
|
+
function isTextfieldRenderer(options) {
|
|
342
|
+
return options.type === DataRenderType.Textfield;
|
|
343
|
+
}
|
|
344
|
+
function isDateTimeRenderer(options) {
|
|
345
|
+
return options.type === DataRenderType.DateTime;
|
|
346
|
+
}
|
|
347
|
+
function isAutocompleteRenderer(options) {
|
|
348
|
+
return options.type === DataRenderType.Autocomplete;
|
|
349
|
+
}
|
|
350
|
+
function isAutoCompleteClasses(options) {
|
|
351
|
+
switch (options == null ? void 0 : options.type) {
|
|
352
|
+
case DataRenderType.Autocomplete:
|
|
353
|
+
return true;
|
|
354
|
+
default:
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function isDataGroupRenderer(options) {
|
|
359
|
+
return (options == null ? void 0 : options.type) === DataRenderType.Group;
|
|
360
|
+
}
|
|
361
|
+
function isArrayRenderer(options) {
|
|
362
|
+
return options.type === DataRenderType.Array;
|
|
363
|
+
}
|
|
364
|
+
function isDataControl(c) {
|
|
365
|
+
return c.type === ControlDefinitionType.Data;
|
|
366
|
+
}
|
|
367
|
+
function isGroupControl(c) {
|
|
368
|
+
return c.type === ControlDefinitionType.Group;
|
|
369
|
+
}
|
|
370
|
+
function isActionControl(c) {
|
|
371
|
+
return c.type === ControlDefinitionType.Action;
|
|
372
|
+
}
|
|
373
|
+
function isDisplayControl(c) {
|
|
374
|
+
return c.type === ControlDefinitionType.Display;
|
|
375
|
+
}
|
|
376
|
+
function isCheckEntryClasses(options) {
|
|
377
|
+
switch (options == null ? void 0 : options.type) {
|
|
378
|
+
case DataRenderType.Radio:
|
|
379
|
+
case DataRenderType.CheckList:
|
|
380
|
+
return true;
|
|
381
|
+
default:
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
class FormNode {
|
|
386
|
+
constructor(id, definition, tree, parent, overrideChildren) {
|
|
387
|
+
this.id = void 0;
|
|
388
|
+
this.definition = void 0;
|
|
389
|
+
this.tree = void 0;
|
|
390
|
+
this.parent = void 0;
|
|
391
|
+
this.overrideChildren = void 0;
|
|
392
|
+
this.id = id;
|
|
393
|
+
this.definition = definition;
|
|
394
|
+
this.tree = tree;
|
|
395
|
+
this.parent = parent;
|
|
396
|
+
this.overrideChildren = overrideChildren;
|
|
397
|
+
this.id = id;
|
|
398
|
+
this.definition = definition;
|
|
399
|
+
}
|
|
400
|
+
getChildNodes() {
|
|
401
|
+
var _children$map, _children;
|
|
402
|
+
if (this.overrideChildren) return this.overrideChildren;
|
|
403
|
+
let children = this.definition.children;
|
|
404
|
+
if (this.definition.childRefId) {
|
|
405
|
+
const ref = this.tree.controlMap[this.definition.childRefId];
|
|
406
|
+
children = ref == null ? void 0 : ref.children;
|
|
407
|
+
}
|
|
408
|
+
return (_children$map = (_children = children) == null ? void 0 : _children.map((x, i) => new FormNode(this.id + "/" + i, x, this.tree, this))) != null ? _children$map : [];
|
|
409
|
+
}
|
|
410
|
+
withOverrideChildren(children) {
|
|
411
|
+
return new FormNode(this.id, this.definition, this.tree, this.parent, children.map(x => nodeForControl(x, this.tree)));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function nodeForControl(definition, tree, indexOrId, parent) {
|
|
415
|
+
return new FormNode(parent ? parent.id + "/" + indexOrId : "", definition, tree, parent);
|
|
416
|
+
}
|
|
417
|
+
function legacyFormNode(definition) {
|
|
418
|
+
return createFormLookup({
|
|
419
|
+
$legacy: [definition]
|
|
420
|
+
}).getForm("$legacy").rootNode.getChildNodes()[0];
|
|
421
|
+
}
|
|
422
|
+
function getControlIds(definition) {
|
|
423
|
+
var _definition$children$, _definition$children;
|
|
424
|
+
const childEntries = (_definition$children$ = (_definition$children = definition.children) == null ? void 0 : _definition$children.flatMap(getControlIds)) != null ? _definition$children$ : [];
|
|
425
|
+
return !definition.id ? childEntries : [[definition.id, definition], ...childEntries];
|
|
426
|
+
}
|
|
427
|
+
function makeFormTree(controls, getForm) {
|
|
428
|
+
const tree = {
|
|
429
|
+
getForm,
|
|
430
|
+
controlMap: Object.fromEntries(controls.flatMap(getControlIds))
|
|
431
|
+
};
|
|
432
|
+
tree.rootNode = nodeForControl({
|
|
433
|
+
children: controls,
|
|
434
|
+
type: ControlDefinitionType.Group
|
|
435
|
+
}, tree);
|
|
436
|
+
return tree;
|
|
437
|
+
}
|
|
438
|
+
function createFormLookup(formMap) {
|
|
439
|
+
const lookup = {
|
|
440
|
+
getForm
|
|
441
|
+
};
|
|
442
|
+
const forms = Object.fromEntries(Object.entries(formMap).map(([k, v]) => [k, makeFormTree(v, lookup)]));
|
|
443
|
+
return lookup;
|
|
444
|
+
function getForm(formId) {
|
|
445
|
+
return forms[formId];
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function fieldPathForDefinition(c) {
|
|
449
|
+
const fieldName = isGroupControl(c) ? c.compoundField : isDataControl(c) ? c.field : undefined;
|
|
450
|
+
return fieldName == null ? void 0 : fieldName.split("/");
|
|
451
|
+
}
|
|
452
|
+
function lookupDataNode(c, parentNode) {
|
|
453
|
+
const fieldNamePath = fieldPathForDefinition(c);
|
|
454
|
+
return fieldNamePath ? schemaDataForFieldPath(fieldNamePath, parentNode) : undefined;
|
|
455
|
+
}
|
|
456
|
+
function traverseParents(current, get, until) {
|
|
457
|
+
let outArray = [];
|
|
458
|
+
while (current && !(until != null && until(current))) {
|
|
459
|
+
outArray.push(get(current));
|
|
460
|
+
current = current.parent;
|
|
461
|
+
}
|
|
462
|
+
return outArray.reverse();
|
|
463
|
+
}
|
|
464
|
+
function getRootDataNode(dataNode) {
|
|
465
|
+
while (dataNode.parent) {
|
|
466
|
+
dataNode = dataNode.parent;
|
|
467
|
+
}
|
|
468
|
+
return dataNode;
|
|
469
|
+
}
|
|
470
|
+
function getJsonPath(dataNode) {
|
|
471
|
+
return traverseParents(dataNode, d => d.elementIndex == null ? d.schema.field.field : d.elementIndex, x => !x.parent);
|
|
472
|
+
}
|
|
473
|
+
function getSchemaPath(schemaNode) {
|
|
474
|
+
return traverseParents(schemaNode, d => d.field, x => !x.parent);
|
|
475
|
+
}
|
|
476
|
+
function getSchemaFieldList(schema) {
|
|
477
|
+
return schema.getChildNodes().map(x => x.field);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* @deprecated use visitFormNodeData instead
|
|
481
|
+
*/
|
|
482
|
+
function visitControlDataArray(controls, context, cb) {
|
|
483
|
+
if (!controls) return undefined;
|
|
484
|
+
for (const c of controls) {
|
|
485
|
+
const r = visitControlData(c, context, cb);
|
|
486
|
+
if (r !== undefined) return r;
|
|
487
|
+
}
|
|
488
|
+
return undefined;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* @deprecated use visitFormDataInContext instead
|
|
492
|
+
*/
|
|
493
|
+
function visitControlData(definition, ctx, cb) {
|
|
494
|
+
return visitFormDataInContext(ctx, legacyFormNode(definition), (n, d) => cb(d, n));
|
|
495
|
+
}
|
|
496
|
+
function visitFormData(node, dataNode, cb, notSelf) {
|
|
497
|
+
const def = node.definition;
|
|
498
|
+
const result = !notSelf && isDataControl(def) ? cb(dataNode, def) : undefined;
|
|
499
|
+
if (result !== undefined) return result;
|
|
500
|
+
if (dataNode.elementIndex == null && dataNode.schema.field.collection) {
|
|
501
|
+
const _l = dataNode.control.elements.length;
|
|
502
|
+
for (let i = 0; i < _l; i++) {
|
|
503
|
+
const elemChild = dataNode.getChildElement(i);
|
|
504
|
+
const elemResult = visitFormData(node, elemChild, cb);
|
|
505
|
+
if (elemResult !== undefined) return elemResult;
|
|
506
|
+
}
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
509
|
+
if (dataNode.control.isNull) return undefined;
|
|
510
|
+
const children = node.getChildNodes();
|
|
511
|
+
const l = children.length;
|
|
512
|
+
for (let i = 0; i < l; i++) {
|
|
513
|
+
const elemResult = visitFormDataInContext(dataNode, children[i], cb);
|
|
514
|
+
if (elemResult !== undefined) return elemResult;
|
|
515
|
+
}
|
|
516
|
+
return undefined;
|
|
517
|
+
}
|
|
518
|
+
function visitFormDataInContext(parentContext, node, cb) {
|
|
519
|
+
const dataNode = lookupDataNode(node.definition, parentContext);
|
|
520
|
+
return visitFormData(node, dataNode != null ? dataNode : parentContext, cb, !dataNode);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function _extends() {
|
|
524
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
525
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
526
|
+
var t = arguments[e];
|
|
527
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
528
|
+
}
|
|
529
|
+
return n;
|
|
530
|
+
}, _extends.apply(null, arguments);
|
|
531
|
+
}
|
|
532
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
533
|
+
if (null == r) return {};
|
|
534
|
+
var t = {};
|
|
535
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
536
|
+
if (e.includes(n)) continue;
|
|
537
|
+
t[n] = r[n];
|
|
538
|
+
}
|
|
539
|
+
return t;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function buildSchema(def) {
|
|
543
|
+
return Object.entries(def).map(x => x[1](x[0]));
|
|
544
|
+
}
|
|
545
|
+
function stringField(displayName, options) {
|
|
546
|
+
return makeScalarField(_extends({
|
|
547
|
+
type: FieldType.String,
|
|
548
|
+
displayName
|
|
549
|
+
}, options));
|
|
550
|
+
}
|
|
551
|
+
function stringOptionsField(displayName, ...options) {
|
|
552
|
+
return makeScalarField({
|
|
553
|
+
type: FieldType.String,
|
|
554
|
+
displayName,
|
|
555
|
+
options
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
function withScalarOptions(options, v) {
|
|
559
|
+
return n => _extends({}, v(n), options);
|
|
560
|
+
}
|
|
561
|
+
function makeScalarField(options) {
|
|
562
|
+
return n => _extends({}, defaultScalarField(n, n), options);
|
|
563
|
+
}
|
|
564
|
+
function makeCompoundField(options) {
|
|
565
|
+
return n => _extends({}, defaultCompoundField(n, n, false), options);
|
|
566
|
+
}
|
|
567
|
+
function intField(displayName, options) {
|
|
568
|
+
return makeScalarField(_extends({
|
|
569
|
+
type: FieldType.Int,
|
|
570
|
+
displayName
|
|
571
|
+
}, options));
|
|
572
|
+
}
|
|
573
|
+
function doubleField(displayName, options) {
|
|
574
|
+
return makeScalarField(_extends({
|
|
575
|
+
type: FieldType.Double,
|
|
576
|
+
displayName
|
|
577
|
+
}, options));
|
|
578
|
+
}
|
|
579
|
+
function dateField(displayName, options) {
|
|
580
|
+
return makeScalarField(_extends({
|
|
581
|
+
type: FieldType.Date,
|
|
582
|
+
displayName
|
|
583
|
+
}, options));
|
|
584
|
+
}
|
|
585
|
+
function timeField(displayName, options) {
|
|
586
|
+
return makeScalarField(_extends({
|
|
587
|
+
type: FieldType.Time,
|
|
588
|
+
displayName
|
|
589
|
+
}, options));
|
|
590
|
+
}
|
|
591
|
+
function dateTimeField(displayName, options) {
|
|
592
|
+
return makeScalarField(_extends({
|
|
593
|
+
type: FieldType.DateTime,
|
|
594
|
+
displayName
|
|
595
|
+
}, options));
|
|
596
|
+
}
|
|
597
|
+
function boolField(displayName, options) {
|
|
598
|
+
return makeScalarField(_extends({
|
|
599
|
+
type: FieldType.Bool,
|
|
600
|
+
displayName
|
|
601
|
+
}, options));
|
|
602
|
+
}
|
|
603
|
+
function compoundField(displayName, fields, other) {
|
|
604
|
+
return field => _extends({}, defaultCompoundField(field, displayName, false), other, {
|
|
605
|
+
children: fields
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
function defaultScalarField(field, displayName) {
|
|
609
|
+
return {
|
|
610
|
+
field,
|
|
611
|
+
displayName,
|
|
612
|
+
type: FieldType.String
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function defaultCompoundField(field, displayName, collection) {
|
|
616
|
+
return {
|
|
617
|
+
field,
|
|
618
|
+
displayName,
|
|
619
|
+
type: FieldType.Compound,
|
|
620
|
+
collection,
|
|
621
|
+
children: []
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
function mergeField(field, mergeInto) {
|
|
625
|
+
const existing = mergeInto.find(x => x.field === field.field);
|
|
626
|
+
if (existing) {
|
|
627
|
+
return mergeInto.map(x => x !== existing ? x : _extends({}, x, {
|
|
628
|
+
onlyForTypes: mergeTypes(x.onlyForTypes, field.onlyForTypes)
|
|
629
|
+
}));
|
|
630
|
+
}
|
|
631
|
+
return [...mergeInto, field];
|
|
632
|
+
function mergeTypes(f, s) {
|
|
633
|
+
if (!f) return s;
|
|
634
|
+
if (!s) return f;
|
|
635
|
+
const extras = s.filter(x => !f.includes(x));
|
|
636
|
+
return extras.length ? [...f, ...extras] : f;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function mergeFields(fields, name, value, newFields) {
|
|
640
|
+
const withType = fields.map(x => x.isTypeField ? addFieldOption(x, name, value) : x);
|
|
641
|
+
return newFields.map(x => _extends({}, x, {
|
|
642
|
+
onlyForTypes: [value]
|
|
643
|
+
})).reduce((af, x) => mergeField(x, af), withType);
|
|
644
|
+
}
|
|
645
|
+
function addFieldOption(typeField, name, value) {
|
|
646
|
+
var _typeField$options;
|
|
647
|
+
const options = (_typeField$options = typeField.options) != null ? _typeField$options : [];
|
|
648
|
+
if (options.some(x => x.value === value)) return typeField;
|
|
649
|
+
return _extends({}, typeField, {
|
|
650
|
+
options: [...options, {
|
|
651
|
+
name,
|
|
652
|
+
value
|
|
653
|
+
}]
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function resolveSchemas(schemaMap) {
|
|
657
|
+
const out = {};
|
|
658
|
+
function resolveSchemaType(type) {
|
|
659
|
+
if (type in out) {
|
|
660
|
+
return out[type];
|
|
661
|
+
}
|
|
662
|
+
const resolvedFields = [];
|
|
663
|
+
out[type] = resolvedFields;
|
|
664
|
+
schemaMap[type].forEach(x => {
|
|
665
|
+
if (isCompoundField(x) && x.schemaRef) {
|
|
666
|
+
resolvedFields.push(_extends({}, x, {
|
|
667
|
+
children: resolveSchemaType(x.schemaRef)
|
|
668
|
+
}));
|
|
669
|
+
} else {
|
|
670
|
+
resolvedFields.push(x);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
return resolvedFields;
|
|
674
|
+
}
|
|
675
|
+
Object.keys(schemaMap).forEach(resolveSchemaType);
|
|
676
|
+
return out;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Applies default values to the given record based on the provided schema fields.
|
|
681
|
+
* @param v - The record to apply default values to.
|
|
682
|
+
* @param fields - The schema fields to use for applying default values.
|
|
683
|
+
* @param doneSet - A set to keep track of processed records.
|
|
684
|
+
* @returns The record with default values applied.
|
|
685
|
+
*/
|
|
686
|
+
function applyDefaultValues(v, fields, doneSet) {
|
|
687
|
+
var _doneSet;
|
|
688
|
+
if (!v) return defaultValueForFields(fields);
|
|
689
|
+
if (doneSet && doneSet.has(v)) return v;
|
|
690
|
+
(_doneSet = doneSet) != null ? _doneSet : doneSet = new Set();
|
|
691
|
+
doneSet.add(v);
|
|
692
|
+
const applyValue = fields.filter(x => isCompoundField(x) || !(x.field in v));
|
|
693
|
+
if (!applyValue.length) return v;
|
|
694
|
+
const out = _extends({}, v);
|
|
695
|
+
applyValue.forEach(x => {
|
|
696
|
+
out[x.field] = x.field in v ? applyDefaultForField(v[x.field], x, fields, false, doneSet) : defaultValueForField(x);
|
|
697
|
+
});
|
|
698
|
+
return out;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Applies default values to a specific field based on the provided schema field.
|
|
702
|
+
* @param v - The value to apply default values to.
|
|
703
|
+
* @param field - The schema field to use for applying default values.
|
|
704
|
+
* @param parent - The parent schema fields.
|
|
705
|
+
* @param notElement - Flag indicating if the field is not an element.
|
|
706
|
+
* @param doneSet - A set to keep track of processed records.
|
|
707
|
+
* @returns The value with default values applied.
|
|
708
|
+
*/
|
|
709
|
+
function applyDefaultForField(v, field, parent, notElement, doneSet) {
|
|
710
|
+
if (field.collection && !notElement) {
|
|
711
|
+
return (v != null ? v : []).map(x => applyDefaultForField(x, field, parent, true, doneSet));
|
|
712
|
+
}
|
|
713
|
+
if (isCompoundField(field)) {
|
|
714
|
+
if (!v && !field.required) return v;
|
|
715
|
+
return applyDefaultValues(v, field.treeChildren ? parent : field.children, doneSet);
|
|
716
|
+
}
|
|
717
|
+
return defaultValueForField(field);
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Returns the default values for the provided schema fields.
|
|
721
|
+
* @param fields - The schema fields to get default values for.
|
|
722
|
+
* @returns The default values for the schema fields.
|
|
723
|
+
*/
|
|
724
|
+
function defaultValueForFields(fields) {
|
|
725
|
+
return Object.fromEntries(fields.map(x => [x.field, defaultValueForField(x)]));
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Returns the default value for a specific schema field.
|
|
729
|
+
* @param sf - The schema field to get the default value for.
|
|
730
|
+
* @param required - Flag indicating if the field is required.
|
|
731
|
+
* @returns The default value for the schema field.
|
|
732
|
+
*/
|
|
733
|
+
function defaultValueForField(sf, required) {
|
|
734
|
+
if (sf.defaultValue !== undefined) return sf.defaultValue;
|
|
735
|
+
const isRequired = !!(required || sf.required);
|
|
736
|
+
if (isCompoundField(sf)) {
|
|
737
|
+
if (isRequired) {
|
|
738
|
+
const childValue = defaultValueForFields(sf.children);
|
|
739
|
+
return sf.collection ? [childValue] : childValue;
|
|
740
|
+
}
|
|
741
|
+
return sf.notNullable ? sf.collection ? [] : {} : undefined;
|
|
742
|
+
}
|
|
743
|
+
if (sf.collection && sf.notNullable) {
|
|
744
|
+
return [];
|
|
745
|
+
}
|
|
746
|
+
return undefined;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Returns the element value for a specific schema field.
|
|
750
|
+
* @param sf - The schema field to get the element value for.
|
|
751
|
+
* @returns The element value for the schema field.
|
|
752
|
+
*/
|
|
753
|
+
function elementValueForField(sf) {
|
|
754
|
+
if (isCompoundField(sf)) {
|
|
755
|
+
return defaultValueForFields(sf.children);
|
|
756
|
+
}
|
|
757
|
+
return sf.defaultValue;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Finds a scalar field in the provided schema fields.
|
|
761
|
+
* @param fields - The schema fields to search in.
|
|
762
|
+
* @param field - The field name to search for.
|
|
763
|
+
* @returns The found scalar field, or undefined if not found.
|
|
764
|
+
*/
|
|
765
|
+
function findScalarField(fields, field) {
|
|
766
|
+
return findField(fields, field);
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Finds a compound field in the provided schema fields.
|
|
770
|
+
* @param fields - The schema fields to search in.
|
|
771
|
+
* @param field - The field name to search for.
|
|
772
|
+
* @returns The found compound field, or undefined if not found.
|
|
773
|
+
*/
|
|
774
|
+
function findCompoundField(fields, field) {
|
|
775
|
+
return findField(fields, field);
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Checks if a field has a specific tag.
|
|
779
|
+
* @param field - The field to check.
|
|
780
|
+
* @param tag - The tag to check for.
|
|
781
|
+
* @returns True if the field has the tag, false otherwise.
|
|
782
|
+
*/
|
|
783
|
+
function fieldHasTag(field, tag) {
|
|
784
|
+
var _field$tags;
|
|
785
|
+
return Boolean((_field$tags = field.tags) == null ? void 0 : _field$tags.includes(tag));
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Returns the display name for a specific field.
|
|
789
|
+
* @param field - The field to get the display name for.
|
|
790
|
+
* @returns The display name for the field.
|
|
791
|
+
*/
|
|
792
|
+
function fieldDisplayName(field) {
|
|
793
|
+
var _field$displayName;
|
|
794
|
+
return (_field$displayName = field.displayName) != null ? _field$displayName : field.field;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Checks if an object has options.
|
|
798
|
+
* @param o - The object to check.
|
|
799
|
+
* @returns True if the object has options, false otherwise.
|
|
800
|
+
*/
|
|
801
|
+
function hasOptions(o) {
|
|
802
|
+
var _o$options$length, _o$options;
|
|
803
|
+
return ((_o$options$length = (_o$options = o.options) == null ? void 0 : _o$options.length) != null ? _o$options$length : 0) > 0;
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Returns the default control definition for a specific schema field.
|
|
807
|
+
* @param sf - The schema field to get the default control definition for.
|
|
808
|
+
* @param noChildren - Flag indicating if children should not be included.
|
|
809
|
+
* @returns The default control definition for the schema field.
|
|
810
|
+
*/
|
|
811
|
+
function defaultControlForField(sf, noChildren) {
|
|
812
|
+
if (isCompoundField(sf)) {
|
|
813
|
+
const ref = getTagParam(sf, SchemaTags.ControlRef);
|
|
814
|
+
return {
|
|
815
|
+
type: ControlDefinitionType.Data,
|
|
816
|
+
title: sf.displayName,
|
|
817
|
+
field: sf.field,
|
|
818
|
+
required: sf.required,
|
|
819
|
+
childRefId: ref,
|
|
820
|
+
children: !noChildren && !ref ? sf.children.filter(x => !fieldHasTag(x, SchemaTags.NoControl)).map(x => defaultControlForField(x)) : undefined
|
|
821
|
+
};
|
|
822
|
+
} else if (isScalarField(sf)) {
|
|
823
|
+
const htmlEditor = fieldHasTag(sf, SchemaTags.HtmlEditor);
|
|
824
|
+
return {
|
|
825
|
+
type: ControlDefinitionType.Data,
|
|
826
|
+
title: sf.displayName,
|
|
827
|
+
field: sf.field,
|
|
828
|
+
required: sf.required,
|
|
829
|
+
renderOptions: {
|
|
830
|
+
type: htmlEditor ? DataRenderType.HtmlEditor : DataRenderType.Standard
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
throw "Unknown schema field";
|
|
835
|
+
}
|
|
836
|
+
function findControlsForCompound(compound, definition) {
|
|
837
|
+
if (isDataControl(definition) && compound.field.field === definition.field) {
|
|
838
|
+
return [definition];
|
|
839
|
+
}
|
|
840
|
+
if (isGroupControl(definition)) {
|
|
841
|
+
var _definition$children$, _definition$children;
|
|
842
|
+
if (definition.compoundField === compound.field.field) return [definition];
|
|
843
|
+
return (_definition$children$ = (_definition$children = definition.children) == null ? void 0 : _definition$children.flatMap(d => findControlsForCompound(compound, d))) != null ? _definition$children$ : [];
|
|
844
|
+
}
|
|
845
|
+
return [];
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Finds non-data groups in the provided control definitions.
|
|
849
|
+
* @param controls - The control definitions to search in.
|
|
850
|
+
* @returns An array of found non-data groups.
|
|
851
|
+
*/
|
|
852
|
+
function findNonDataGroups(controls) {
|
|
853
|
+
return controls.flatMap(control => {
|
|
854
|
+
var _control$children2;
|
|
855
|
+
return isGroupControl(control) && !control.compoundField ? [control, ...findNonDataGroups((_control$children2 = control.children) != null ? _control$children2 : [])] : [];
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Adds missing controls to the provided control definitions based on the schema fields.
|
|
860
|
+
* @param fields - The schema fields to use for adding missing controls.
|
|
861
|
+
* @param controls - The control definitions to add missing controls to.
|
|
862
|
+
* @returns The control definitions with missing controls added.
|
|
863
|
+
*/
|
|
864
|
+
function addMissingControls(fields, controls) {
|
|
865
|
+
return addMissingControlsForSchema(rootSchemaNode(fields), controls);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Adds missing controls to the provided control definitions based on the schema fields.
|
|
869
|
+
* @param schema - The root schema node to use for adding missing controls.
|
|
870
|
+
* @param controls - The control definitions to add missing controls to.
|
|
871
|
+
* @returns The control definitions with missing controls added.
|
|
872
|
+
*/
|
|
873
|
+
function addMissingControlsForSchema(schema, controls) {
|
|
874
|
+
const controlMap = {};
|
|
875
|
+
const schemaControlMap = {};
|
|
876
|
+
const rootControls = controls.map(c => toControlAndSchema(c, schema));
|
|
877
|
+
const rootSchema = {
|
|
878
|
+
schema,
|
|
879
|
+
children: rootControls
|
|
880
|
+
};
|
|
881
|
+
addSchemaMapEntry("", rootSchema);
|
|
882
|
+
rootControls.forEach(addReferences);
|
|
883
|
+
const fields = schema.getChildNodes();
|
|
884
|
+
fields.forEach(addMissing);
|
|
885
|
+
return rootControls.map(toDefinition);
|
|
886
|
+
function toDefinition(c) {
|
|
887
|
+
const children = c.children.length ? c.children.map(toDefinition) : null;
|
|
888
|
+
return _extends({}, c.control, {
|
|
889
|
+
children
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
function addMissing(schemaNode) {
|
|
893
|
+
if (fieldHasTag(schemaNode.field, SchemaTags.NoControl)) return;
|
|
894
|
+
const existingControls = schemaControlMap[schemaNode.id];
|
|
895
|
+
if (!existingControls) {
|
|
896
|
+
const eligibleParents = getEligibleParents(schemaNode);
|
|
897
|
+
const desiredGroup = getTagParam(schemaNode.field, SchemaTags.ControlGroup);
|
|
898
|
+
let parentGroup = desiredGroup ? controlMap[desiredGroup] : undefined;
|
|
899
|
+
if (!parentGroup && desiredGroup) console.warn("No group '" + desiredGroup + "' for " + schemaNode.id);
|
|
900
|
+
if (parentGroup && eligibleParents.indexOf(parentGroup.schema.id) < 0) {
|
|
901
|
+
console.warn(`Target group '${desiredGroup}' is not an eligible parent for '${schemaNode.id}'`);
|
|
902
|
+
parentGroup = undefined;
|
|
903
|
+
}
|
|
904
|
+
if (!parentGroup && eligibleParents.length) {
|
|
905
|
+
var _schemaControlMap$eli;
|
|
906
|
+
parentGroup = (_schemaControlMap$eli = schemaControlMap[eligibleParents[0]]) == null ? void 0 : _schemaControlMap$eli[0];
|
|
907
|
+
}
|
|
908
|
+
if (parentGroup) {
|
|
909
|
+
const newControl = defaultControlForField(schemaNode.field, true);
|
|
910
|
+
newControl.field = relativePath(parentGroup.schema, schemaNode);
|
|
911
|
+
parentGroup.children.push(toControlAndSchema(newControl, parentGroup.schema, parentGroup));
|
|
912
|
+
} else console.warn("Could not find a parent group for: " + schemaNode.id);
|
|
913
|
+
}
|
|
914
|
+
schemaNode.getChildNodes(true).forEach(addMissing);
|
|
915
|
+
}
|
|
916
|
+
function getEligibleParents(schemaNode) {
|
|
917
|
+
const eligibleParents = [];
|
|
918
|
+
let parent = schemaNode.parent;
|
|
919
|
+
while (parent) {
|
|
920
|
+
eligibleParents.push(parent.id);
|
|
921
|
+
if (parent.field.collection) break;
|
|
922
|
+
if (!parent.parent) parent.getChildNodes(true).forEach(addCompound);
|
|
923
|
+
parent = parent.parent;
|
|
924
|
+
}
|
|
925
|
+
return eligibleParents;
|
|
926
|
+
function addCompound(node) {
|
|
927
|
+
if (isCompoundNode(node) && !node.field.collection) {
|
|
928
|
+
eligibleParents.push(node.id);
|
|
929
|
+
node.getChildNodes(true).forEach(addCompound);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function addReferences(c) {
|
|
934
|
+
c.children.forEach(addReferences);
|
|
935
|
+
if (c.control.childRefId) {
|
|
936
|
+
const ref = controlMap[c.control.childRefId];
|
|
937
|
+
if (ref) {
|
|
938
|
+
ref.children.forEach(x => toControlAndSchema(x.control, c.schema, c, true));
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
console.warn("Missing reference", c.control.childRefId);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function addSchemaMapEntry(schemaId, entry) {
|
|
945
|
+
if (!schemaControlMap[schemaId]) schemaControlMap[schemaId] = [];
|
|
946
|
+
schemaControlMap[schemaId].push(entry);
|
|
947
|
+
}
|
|
948
|
+
function toControlAndSchema(c, parentSchema, parentNode, dontRegister) {
|
|
949
|
+
var _c$children$map, _c$children;
|
|
950
|
+
const controlPath = fieldPathForDefinition(c);
|
|
951
|
+
let dataSchema = controlPath ? schemaForFieldPath(controlPath, parentSchema) : undefined;
|
|
952
|
+
if (isGroupControl(c) && dataSchema == null) dataSchema = parentSchema;
|
|
953
|
+
const entry = {
|
|
954
|
+
schema: dataSchema,
|
|
955
|
+
control: c,
|
|
956
|
+
children: [],
|
|
957
|
+
parent: parentNode
|
|
958
|
+
};
|
|
959
|
+
entry.children = (_c$children$map = (_c$children = c.children) == null ? void 0 : _c$children.map(x => {
|
|
960
|
+
var _dataSchema;
|
|
961
|
+
return toControlAndSchema(x, (_dataSchema = dataSchema) != null ? _dataSchema : parentSchema, entry, dontRegister);
|
|
962
|
+
})) != null ? _c$children$map : [];
|
|
963
|
+
if (!dontRegister && c.id) controlMap[c.id] = entry;
|
|
964
|
+
if (dataSchema) {
|
|
965
|
+
addSchemaMapEntry(dataSchema.id, entry);
|
|
966
|
+
}
|
|
967
|
+
return entry;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Custom hook to use an updated reference.
|
|
972
|
+
* @param a - The value to create a reference for.
|
|
973
|
+
* @returns A mutable reference object.
|
|
974
|
+
*/
|
|
975
|
+
function useUpdatedRef(a) {
|
|
976
|
+
const r = useRef(a);
|
|
977
|
+
r.current = a;
|
|
978
|
+
return r;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Checks if a control definition is readonly.
|
|
982
|
+
* @param c - The control definition to check.
|
|
983
|
+
* @returns True if the control definition is readonly, false otherwise.
|
|
984
|
+
*/
|
|
985
|
+
function isControlReadonly(c) {
|
|
986
|
+
return isDataControl(c) && !!c.readonly;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Checks if a control definition is disabled.
|
|
990
|
+
* @param c - The control definition to check.
|
|
991
|
+
* @returns True if the control definition is disabled, false otherwise.
|
|
992
|
+
*/
|
|
993
|
+
function isControlDisabled(c) {
|
|
994
|
+
return isDataControl(c) && !!c.disabled;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Returns the display-only render options for a control definition.
|
|
998
|
+
* @param d - The control definition to get the display-only render options for.
|
|
999
|
+
* @returns The display-only render options, or undefined if not applicable.
|
|
1000
|
+
*/
|
|
1001
|
+
function getDisplayOnlyOptions(d) {
|
|
1002
|
+
return isDataControl(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Cleans data for a schema based on the provided schema fields.
|
|
1006
|
+
* @param v - The data to clean.
|
|
1007
|
+
* @param fields - The schema fields to use for cleaning the data.
|
|
1008
|
+
* @param removeIfDefault - Flag indicating if default values should be removed.
|
|
1009
|
+
* @returns The cleaned data.
|
|
1010
|
+
*/
|
|
1011
|
+
function cleanDataForSchema(v, fields, removeIfDefault) {
|
|
1012
|
+
if (!v) return v;
|
|
1013
|
+
const typeField = fields.find(x => x.isTypeField);
|
|
1014
|
+
const typeValue = typeField ? v[typeField.field] : undefined;
|
|
1015
|
+
const cleanableFields = !removeIfDefault ? fields.filter(x => {
|
|
1016
|
+
var _x$onlyForTypes$lengt, _x$onlyForTypes;
|
|
1017
|
+
return isCompoundField(x) || ((_x$onlyForTypes$lengt = (_x$onlyForTypes = x.onlyForTypes) == null ? void 0 : _x$onlyForTypes.length) != null ? _x$onlyForTypes$lengt : 0) > 0;
|
|
1018
|
+
}) : fields;
|
|
1019
|
+
if (!cleanableFields.length) return v;
|
|
1020
|
+
const out = _extends({}, v);
|
|
1021
|
+
cleanableFields.forEach(x => {
|
|
1022
|
+
var _x$onlyForTypes2;
|
|
1023
|
+
const childValue = v[x.field];
|
|
1024
|
+
if (((_x$onlyForTypes2 = x.onlyForTypes) == null ? void 0 : _x$onlyForTypes2.includes(typeValue)) === false || !x.notNullable && canBeNull()) {
|
|
1025
|
+
delete out[x.field];
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
if (isCompoundField(x)) {
|
|
1029
|
+
const childFields = x.treeChildren ? fields : x.children;
|
|
1030
|
+
if (x.collection) {
|
|
1031
|
+
if (Array.isArray(childValue)) {
|
|
1032
|
+
out[x.field] = childValue.map(cv => cleanDataForSchema(cv, childFields, removeIfDefault));
|
|
1033
|
+
}
|
|
1034
|
+
} else {
|
|
1035
|
+
out[x.field] = cleanDataForSchema(childValue, childFields, removeIfDefault);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
function canBeNull() {
|
|
1039
|
+
return removeIfDefault && x.defaultValue === childValue || x.collection && Array.isArray(childValue) && !childValue.length
|
|
1040
|
+
//|| (x.type === FieldType.Bool && childValue === false)
|
|
1041
|
+
;
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
return out;
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Returns all referenced classes for a control definition.
|
|
1048
|
+
* @param c - The control definition to get the referenced classes for.
|
|
1049
|
+
* @param collectExtra - Optional function to collect extra classes.
|
|
1050
|
+
* @returns An array of referenced classes.
|
|
1051
|
+
*/
|
|
1052
|
+
function getAllReferencedClasses(c, collectExtra) {
|
|
1053
|
+
var _c$children2, _collectExtra;
|
|
1054
|
+
const childClasses = (_c$children2 = c.children) == null ? void 0 : _c$children2.flatMap(x => getAllReferencedClasses(x, collectExtra));
|
|
1055
|
+
const go = getGroupClassOverrides(c);
|
|
1056
|
+
const {
|
|
1057
|
+
entryWrapperClass,
|
|
1058
|
+
selectedClass,
|
|
1059
|
+
notSelectedClass
|
|
1060
|
+
} = isDataControl(c) && isCheckEntryClasses(c.renderOptions) ? c.renderOptions : {};
|
|
1061
|
+
const {
|
|
1062
|
+
listContainerClass,
|
|
1063
|
+
listEntryClass,
|
|
1064
|
+
chipContainerClass,
|
|
1065
|
+
chipCloseButtonClass
|
|
1066
|
+
} = isDataControl(c) && isAutoCompleteClasses(c.renderOptions) ? c.renderOptions : {};
|
|
1067
|
+
const tc = clsx([c.styleClass, c.layoutClass, c.labelClass, ...Object.values(go), ...((_collectExtra = collectExtra == null ? void 0 : collectExtra(c)) != null ? _collectExtra : []), entryWrapperClass, selectedClass, notSelectedClass, listContainerClass, listEntryClass, chipContainerClass, chipCloseButtonClass].map(getOverrideClass));
|
|
1068
|
+
if (childClasses && !tc) return childClasses;
|
|
1069
|
+
if (!tc) return [];
|
|
1070
|
+
if (childClasses) return [tc, ...childClasses];
|
|
1071
|
+
return [tc];
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Converts a JSON path array to a string.
|
|
1075
|
+
* @param jsonPath - The JSON path array to convert.
|
|
1076
|
+
* @param customIndex - Optional function to customize the index format.
|
|
1077
|
+
* @returns The JSON path string.
|
|
1078
|
+
*/
|
|
1079
|
+
function jsonPathString(jsonPath, customIndex) {
|
|
1080
|
+
let out = "";
|
|
1081
|
+
jsonPath.forEach((v, i) => {
|
|
1082
|
+
if (typeof v === "number") {
|
|
1083
|
+
var _customIndex;
|
|
1084
|
+
out += (_customIndex = customIndex == null ? void 0 : customIndex(v)) != null ? _customIndex : "[" + v + "]";
|
|
1085
|
+
} else {
|
|
1086
|
+
if (i > 0) out += ".";
|
|
1087
|
+
out += v;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
return out;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Finds a child control definition within a parent control definition.
|
|
1094
|
+
* @param parent - The parent control definition.
|
|
1095
|
+
* @param childPath - The path to the child control definition, either as a single index or an array of indices.
|
|
1096
|
+
* @returns The found child control definition.
|
|
1097
|
+
*/
|
|
1098
|
+
function findChildDefinition(parent, childPath) {
|
|
1099
|
+
if (Array.isArray(childPath)) {
|
|
1100
|
+
let base = parent;
|
|
1101
|
+
childPath.forEach(x => base = base.children[x]);
|
|
1102
|
+
return base;
|
|
1103
|
+
}
|
|
1104
|
+
return parent.children[childPath];
|
|
1105
|
+
}
|
|
1106
|
+
/**
|
|
1107
|
+
* Returns the override class name if the class name starts with "@ ".
|
|
1108
|
+
* Otherwise, returns the original class name.
|
|
1109
|
+
* @param className - The class name to check and potentially modify.
|
|
1110
|
+
* @returns The override class name or the original class name.
|
|
1111
|
+
*/
|
|
1112
|
+
function getOverrideClass(className) {
|
|
1113
|
+
if (className && className.startsWith("@ ")) {
|
|
1114
|
+
return className.substring(2);
|
|
1115
|
+
}
|
|
1116
|
+
return className;
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Returns the appropriate class name for a renderer.
|
|
1120
|
+
* If the global class name starts with "@ ", it overrides the control class name.
|
|
1121
|
+
* Otherwise, it combines the control class name and the global class name.
|
|
1122
|
+
*
|
|
1123
|
+
* @param controlClass - The class name for the control.
|
|
1124
|
+
* @param globalClass - The global class name.
|
|
1125
|
+
* @returns The appropriate class name for the renderer.
|
|
1126
|
+
*/
|
|
1127
|
+
function rendererClass(controlClass, globalClass) {
|
|
1128
|
+
const gc = getOverrideClass(globalClass);
|
|
1129
|
+
if (gc !== globalClass) return globalClass ? globalClass : undefined;
|
|
1130
|
+
const oc = getOverrideClass(controlClass);
|
|
1131
|
+
if (oc === controlClass) return clsx(controlClass, globalClass);
|
|
1132
|
+
return oc ? oc : undefined;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Applies length restrictions to a value.
|
|
1136
|
+
* @template Min - The type of the minimum value.
|
|
1137
|
+
* @template Max - The type of the maximum value.
|
|
1138
|
+
* @param {number} length - The length to check.
|
|
1139
|
+
* @param {number | null | undefined} min - The minimum length.
|
|
1140
|
+
* @param {number | null | undefined} max - The maximum length.
|
|
1141
|
+
* @param {Min} minValue - The value to return if the length is greater than the minimum.
|
|
1142
|
+
* @param {Max} maxValue - The value to return if the length is less than the maximum.
|
|
1143
|
+
* @returns {[Min | undefined, Max | undefined]} - An array containing the minimum and maximum values if the length restrictions are met.
|
|
1144
|
+
*/
|
|
1145
|
+
function applyLengthRestrictions(length, min, max, minValue, maxValue) {
|
|
1146
|
+
return [min == null || length > min ? minValue : undefined, max == null || length < max ? maxValue : undefined];
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Finds the path to a field in the schema fields.
|
|
1150
|
+
* @param {SchemaField[]} fields - The schema fields to search in.
|
|
1151
|
+
* @param {string | undefined} fieldPath - The path to the field.
|
|
1152
|
+
* @returns {SchemaField[] | undefined} - An array of schema fields representing the path, or undefined if not found.
|
|
1153
|
+
*/
|
|
1154
|
+
function findFieldPath(fields, fieldPath) {
|
|
1155
|
+
if (!fieldPath) return undefined;
|
|
1156
|
+
const fieldNames = fieldPath.split("/");
|
|
1157
|
+
const foundFields = [];
|
|
1158
|
+
let i = 0;
|
|
1159
|
+
let currentFields = fields;
|
|
1160
|
+
while (i < fieldNames.length && currentFields) {
|
|
1161
|
+
const cf = fieldNames[i];
|
|
1162
|
+
const nextField = findField(currentFields, cf);
|
|
1163
|
+
if (!nextField) return undefined;
|
|
1164
|
+
foundFields.push(nextField);
|
|
1165
|
+
currentFields = isCompoundField(nextField) && !nextField.collection ? nextField.children : undefined;
|
|
1166
|
+
i++;
|
|
1167
|
+
}
|
|
1168
|
+
return foundFields.length === fieldNames.length ? foundFields : undefined;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Merges two objects.
|
|
1172
|
+
* @template A - The type of the objects to merge.
|
|
1173
|
+
* @param {A} o1 - The first object.
|
|
1174
|
+
* @param {A} o2 - The second object.
|
|
1175
|
+
* @param {(k: keyof NonNullable<A>, v1: unknown, v2: unknown) => unknown} [doMerge] - Optional function to merge values.
|
|
1176
|
+
* @returns {A} - The merged object.
|
|
1177
|
+
*/
|
|
1178
|
+
function mergeObjects(o1, o2, doMerge = (_, v1, v2) => v1 != null ? v1 : v2) {
|
|
1179
|
+
if (!o1) return o2;
|
|
1180
|
+
if (!o2) return o1;
|
|
1181
|
+
const result = _extends({}, o1);
|
|
1182
|
+
for (const key in o2) {
|
|
1183
|
+
if (o2.hasOwnProperty(key)) {
|
|
1184
|
+
const value1 = o1[key];
|
|
1185
|
+
const value2 = o2[key];
|
|
1186
|
+
result[key] = doMerge(key, value1, value2);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
return result;
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Coerces a value to a string.
|
|
1193
|
+
* @param {unknown} v - The value to coerce.
|
|
1194
|
+
* @returns {string} - The coerced string.
|
|
1195
|
+
*/
|
|
1196
|
+
function coerceToString(v) {
|
|
1197
|
+
return v == null ? "" : typeof v === "object" ? "error: " + JSON.stringify(v) : v.toString();
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Returns the group renderer options for a control definition.
|
|
1201
|
+
* @param {ControlDefinition} def - The control definition to get the group renderer options for.
|
|
1202
|
+
* @returns {GroupRenderOptions | undefined} - The group renderer options, or undefined if not applicable.
|
|
1203
|
+
*/
|
|
1204
|
+
function getGroupRendererOptions(def) {
|
|
1205
|
+
return isGroupControl(def) ? def.groupOptions : isDataControl(def) && isDataGroupRenderer(def.renderOptions) ? def.renderOptions.groupOptions : undefined;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* Returns the group class overrides for a control definition.
|
|
1209
|
+
* @param {ControlDefinition} def - The control definition to get the group class overrides for.
|
|
1210
|
+
* @returns {ControlClasses} - The group class overrides.
|
|
1211
|
+
*/
|
|
1212
|
+
function getGroupClassOverrides(def) {
|
|
1213
|
+
let go = getGroupRendererOptions(def);
|
|
1214
|
+
if (!go) return {};
|
|
1215
|
+
const {
|
|
1216
|
+
childLayoutClass,
|
|
1217
|
+
childStyleClass,
|
|
1218
|
+
childLabelClass
|
|
1219
|
+
} = go;
|
|
1220
|
+
const out = {};
|
|
1221
|
+
if (childLayoutClass) out.layoutClass = childLayoutClass;
|
|
1222
|
+
if (childStyleClass) out.styleClass = childStyleClass;
|
|
1223
|
+
if (childLabelClass) out.labelClass = childLabelClass;
|
|
1224
|
+
return out;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Checks if a control definition is display-only.
|
|
1228
|
+
* @param {ControlDefinition} def - The control definition to check.
|
|
1229
|
+
* @returns {boolean} - True if the control definition is display-only, false otherwise.
|
|
1230
|
+
*/
|
|
1231
|
+
function isControlDisplayOnly(def) {
|
|
1232
|
+
var _getGroupRendererOpti;
|
|
1233
|
+
return Boolean((_getGroupRendererOpti = getGroupRendererOptions(def)) == null ? void 0 : _getGroupRendererOpti.displayOnly);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Combines multiple action handlers into a single handler.
|
|
1237
|
+
* @param {...(ControlActionHandler | undefined)[]} handlers - The action handlers to combine.
|
|
1238
|
+
* @returns {ControlActionHandler} - The combined action handler.
|
|
1239
|
+
*/
|
|
1240
|
+
function actionHandlers(...handlers) {
|
|
1241
|
+
return (actionId, actionData, ctx) => {
|
|
1242
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
1243
|
+
var _handlers$i;
|
|
1244
|
+
const res = (_handlers$i = handlers[i]) == null ? void 0 : _handlers$i.call(handlers, actionId, actionData, ctx);
|
|
1245
|
+
if (res) return res;
|
|
1246
|
+
}
|
|
1247
|
+
return undefined;
|
|
1248
|
+
};
|
|
1249
|
+
}
|
|
1250
|
+
function getDiffObject(dataNode, force) {
|
|
1251
|
+
const c = dataNode.control;
|
|
1252
|
+
const sf = dataNode.schema.field;
|
|
1253
|
+
if (!c.dirty && !force) return undefined;
|
|
1254
|
+
if (c.isNull) return null;
|
|
1255
|
+
if (sf.collection && dataNode.elementIndex == null) {
|
|
1256
|
+
const idField = getTagParam(sf, SchemaTags.IdField);
|
|
1257
|
+
return c.as().elements.map((x, i) => {
|
|
1258
|
+
var _getElementIndex;
|
|
1259
|
+
const change = getDiffObject(dataNode.getChildElement(i), idField !== undefined);
|
|
1260
|
+
return idField != null ? change : {
|
|
1261
|
+
old: (_getElementIndex = getElementIndex(x)) == null ? void 0 : _getElementIndex.initialIndex,
|
|
1262
|
+
edit: change
|
|
1263
|
+
};
|
|
1264
|
+
});
|
|
1265
|
+
} else if (isCompoundField(sf)) {
|
|
1266
|
+
const children = dataNode.schema.getChildNodes();
|
|
1267
|
+
const idField = getTagParam(sf, SchemaTags.IdField);
|
|
1268
|
+
return Object.fromEntries(children.flatMap(c => {
|
|
1269
|
+
const diff = getDiffObject(dataNode.getChild(c), idField === c.field.field);
|
|
1270
|
+
return diff !== undefined ? [[c.field.field, diff]] : [];
|
|
1271
|
+
}));
|
|
1272
|
+
}
|
|
1273
|
+
return c.value;
|
|
1274
|
+
}
|
|
1275
|
+
function getNullToggler(c) {
|
|
1276
|
+
return ensureMetaValue(c, "$nullToggler", () => {
|
|
1277
|
+
const lastDefined = getLastDefinedValue(c);
|
|
1278
|
+
const isEditing = getIsEditing(c);
|
|
1279
|
+
const currentNotNull = c.current.value != null;
|
|
1280
|
+
c.disabled = !currentNotNull;
|
|
1281
|
+
const notNull = newControl(currentNotNull);
|
|
1282
|
+
if (!currentNotNull) c.value = null;
|
|
1283
|
+
disableIfNotEditing();
|
|
1284
|
+
isEditing.subscribe(disableIfNotEditing, ControlChange.Value);
|
|
1285
|
+
notNull.subscribe(() => {
|
|
1286
|
+
const currentNotNull = notNull.current.value;
|
|
1287
|
+
c.value = currentNotNull ? lastDefined.current.value : null;
|
|
1288
|
+
c.disabled = !currentNotNull;
|
|
1289
|
+
}, ControlChange.Value);
|
|
1290
|
+
return notNull;
|
|
1291
|
+
function disableIfNotEditing() {
|
|
1292
|
+
notNull.disabled = isEditing.current.value === false;
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
function getExternalEditData(c) {
|
|
1297
|
+
return ensureMetaValue(c, "$externalEditIndex", () => newControl(undefined));
|
|
1298
|
+
}
|
|
1299
|
+
function getLastDefinedValue(control) {
|
|
1300
|
+
return ensureMetaValue(control, "$lastDefined", () => {
|
|
1301
|
+
const lastDefined = newControl(control.current.value);
|
|
1302
|
+
control.subscribe(() => {
|
|
1303
|
+
const nv = control.current.value;
|
|
1304
|
+
if (nv != null) lastDefined.value = nv;
|
|
1305
|
+
}, ControlChange.Value);
|
|
1306
|
+
return lastDefined;
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
function getIsEditing(control) {
|
|
1310
|
+
const lastDefined = getLastDefinedValue(control);
|
|
1311
|
+
return ensureMetaValue(control, "$willEdit", () => {
|
|
1312
|
+
const c = newControl(undefined);
|
|
1313
|
+
c.subscribe(() => {
|
|
1314
|
+
const currentEdit = c.current.value;
|
|
1315
|
+
if (currentEdit !== undefined) {
|
|
1316
|
+
control.value = currentEdit ? lastDefined.current.value : control.initialValue;
|
|
1317
|
+
}
|
|
1318
|
+
}, ControlChange.Value);
|
|
1319
|
+
return c;
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
function getAllValues(control) {
|
|
1323
|
+
return ensureMetaValue(control, "$allValues", () => newControl([control.value]));
|
|
1324
|
+
}
|
|
1325
|
+
function applyValues(dataNode, value) {
|
|
1326
|
+
const c = dataNode.control;
|
|
1327
|
+
const sf = dataNode.schema.field;
|
|
1328
|
+
if (c.isEqual(c.initialValue, value)) return;
|
|
1329
|
+
if (sf.collection) {
|
|
1330
|
+
return;
|
|
1331
|
+
} else if (isCompoundField(sf)) {
|
|
1332
|
+
if (value == null) return;
|
|
1333
|
+
dataNode.schema.getChildNodes().forEach(c => {
|
|
1334
|
+
applyValues(dataNode.getChild(c), value[c.field.field]);
|
|
1335
|
+
});
|
|
1336
|
+
} else {
|
|
1337
|
+
const allValues = getAllValues(c);
|
|
1338
|
+
allValues.setValue(changes => changes.every(x => !c.isEqual(x, value)) ? [...changes, value] : changes);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function collectDifferences(dataNode, values) {
|
|
1342
|
+
values.forEach((v, i) => {
|
|
1343
|
+
if (i == 0) dataNode.control.setInitialValue(v);else applyValues(dataNode, v);
|
|
1344
|
+
});
|
|
1345
|
+
const allEdits = [];
|
|
1346
|
+
resetMultiValues(dataNode);
|
|
1347
|
+
return () => {
|
|
1348
|
+
let editable = 0;
|
|
1349
|
+
let editing = 0;
|
|
1350
|
+
allEdits.forEach(x => {
|
|
1351
|
+
const b = x.value;
|
|
1352
|
+
if (b === undefined) return;
|
|
1353
|
+
editable++;
|
|
1354
|
+
if (b) editing++;
|
|
1355
|
+
});
|
|
1356
|
+
return {
|
|
1357
|
+
editing,
|
|
1358
|
+
editable
|
|
1359
|
+
};
|
|
1360
|
+
};
|
|
1361
|
+
function resetMultiValues(dataNode) {
|
|
1362
|
+
const c = dataNode.control;
|
|
1363
|
+
const sf = dataNode.schema.field;
|
|
1364
|
+
if (sf.collection) {
|
|
1365
|
+
return;
|
|
1366
|
+
} else if (isCompoundField(sf)) {
|
|
1367
|
+
if (c.value == null) return;
|
|
1368
|
+
dataNode.schema.getChildNodes().forEach(c => {
|
|
1369
|
+
resetMultiValues(dataNode.getChild(c));
|
|
1370
|
+
});
|
|
1371
|
+
} else {
|
|
1372
|
+
allEdits.push(getIsEditing(c));
|
|
1373
|
+
const allValues = getAllValues(c);
|
|
1374
|
+
if (allValues.value.length > 1) {
|
|
1375
|
+
c.setInitialValue(undefined);
|
|
1376
|
+
getLastDefinedValue(c).value = null;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
function validationVisitor(onInvalid) {
|
|
1382
|
+
return s => {
|
|
1383
|
+
if (isCompoundNode(s.schema)) return undefined;
|
|
1384
|
+
const v = s.control;
|
|
1385
|
+
v.touched = true;
|
|
1386
|
+
if (!v.validate()) {
|
|
1387
|
+
onInvalid(v);
|
|
1388
|
+
}
|
|
1389
|
+
return undefined;
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
var ValidatorType;
|
|
1394
|
+
(function (ValidatorType) {
|
|
1395
|
+
ValidatorType["Jsonata"] = "Jsonata";
|
|
1396
|
+
ValidatorType["Date"] = "Date";
|
|
1397
|
+
ValidatorType["Length"] = "Length";
|
|
1398
|
+
})(ValidatorType || (ValidatorType = {}));
|
|
1399
|
+
var DateComparison;
|
|
1400
|
+
(function (DateComparison) {
|
|
1401
|
+
DateComparison["NotBefore"] = "NotBefore";
|
|
1402
|
+
DateComparison["NotAfter"] = "NotAfter";
|
|
1403
|
+
})(DateComparison || (DateComparison = {}));
|
|
1404
|
+
|
|
1405
|
+
var ExpressionType;
|
|
1406
|
+
(function (ExpressionType) {
|
|
1407
|
+
ExpressionType["Jsonata"] = "Jsonata";
|
|
1408
|
+
ExpressionType["Data"] = "Data";
|
|
1409
|
+
ExpressionType["DataMatch"] = "FieldValue";
|
|
1410
|
+
ExpressionType["UserMatch"] = "UserMatch";
|
|
1411
|
+
ExpressionType["NotEmpty"] = "NotEmpty";
|
|
1412
|
+
ExpressionType["UUID"] = "UUID";
|
|
1413
|
+
})(ExpressionType || (ExpressionType = {}));
|
|
1414
|
+
|
|
1415
|
+
function dataControl(field, title, options) {
|
|
1416
|
+
return _extends({
|
|
1417
|
+
type: ControlDefinitionType.Data,
|
|
1418
|
+
field,
|
|
1419
|
+
title
|
|
1420
|
+
}, options);
|
|
1421
|
+
}
|
|
1422
|
+
function validatorOptions(type) {
|
|
1423
|
+
return o => _extends({
|
|
1424
|
+
type
|
|
1425
|
+
}, o);
|
|
1426
|
+
}
|
|
1427
|
+
function adornmentOptions(type) {
|
|
1428
|
+
return o => _extends({
|
|
1429
|
+
type
|
|
1430
|
+
}, o);
|
|
1431
|
+
}
|
|
1432
|
+
function renderOptionsFor(type) {
|
|
1433
|
+
return o => ({
|
|
1434
|
+
renderOptions: _extends({
|
|
1435
|
+
type
|
|
1436
|
+
}, o)
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
const autocompleteOptions = renderOptionsFor(DataRenderType.Autocomplete);
|
|
1440
|
+
const checkListOptions = renderOptionsFor(DataRenderType.CheckList);
|
|
1441
|
+
const radioButtonOptions = renderOptionsFor(DataRenderType.Radio);
|
|
1442
|
+
const lengthValidatorOptions = validatorOptions(ValidatorType.Length);
|
|
1443
|
+
const jsonataValidatorOptions = validatorOptions(ValidatorType.Jsonata);
|
|
1444
|
+
const dateValidatorOptions = validatorOptions(ValidatorType.Date);
|
|
1445
|
+
const accordionOptions = adornmentOptions(ControlAdornmentType.Accordion);
|
|
1446
|
+
const textfieldOptions = renderOptionsFor(DataRenderType.Textfield);
|
|
1447
|
+
const displayOnlyOptions = renderOptionsFor(DataRenderType.DisplayOnly);
|
|
1448
|
+
const jsonataOptions = renderOptionsFor(DataRenderType.Jsonata);
|
|
1449
|
+
function textDisplayControl(text, options) {
|
|
1450
|
+
return _extends({
|
|
1451
|
+
type: ControlDefinitionType.Display,
|
|
1452
|
+
displayData: {
|
|
1453
|
+
type: DisplayDataType.Text,
|
|
1454
|
+
text
|
|
1455
|
+
}
|
|
1456
|
+
}, options);
|
|
1457
|
+
}
|
|
1458
|
+
function htmlDisplayControl(html, options) {
|
|
1459
|
+
return _extends({
|
|
1460
|
+
type: ControlDefinitionType.Display,
|
|
1461
|
+
displayData: {
|
|
1462
|
+
type: DisplayDataType.Html,
|
|
1463
|
+
html
|
|
1464
|
+
}
|
|
1465
|
+
}, options);
|
|
1466
|
+
}
|
|
1467
|
+
function dynamicDefaultValue(expr) {
|
|
1468
|
+
return {
|
|
1469
|
+
type: DynamicPropertyType.DefaultValue,
|
|
1470
|
+
expr
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
function dynamicReadonly(expr) {
|
|
1474
|
+
return {
|
|
1475
|
+
type: DynamicPropertyType.Readonly,
|
|
1476
|
+
expr
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
function dynamicVisibility(expr) {
|
|
1480
|
+
return {
|
|
1481
|
+
type: DynamicPropertyType.Visible,
|
|
1482
|
+
expr
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
function dynamicDisabled(expr) {
|
|
1486
|
+
return {
|
|
1487
|
+
type: DynamicPropertyType.Disabled,
|
|
1488
|
+
expr
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
function fieldExpr(field) {
|
|
1492
|
+
return {
|
|
1493
|
+
type: ExpressionType.Data,
|
|
1494
|
+
field
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
function fieldEqExpr(field, value) {
|
|
1498
|
+
return {
|
|
1499
|
+
type: ExpressionType.DataMatch,
|
|
1500
|
+
field,
|
|
1501
|
+
value
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function jsonataExpr(expression) {
|
|
1505
|
+
return {
|
|
1506
|
+
type: ExpressionType.Jsonata,
|
|
1507
|
+
expression
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
function groupedControl(children, title, options) {
|
|
1511
|
+
return _extends({
|
|
1512
|
+
type: ControlDefinitionType.Group,
|
|
1513
|
+
children,
|
|
1514
|
+
title,
|
|
1515
|
+
groupOptions: {
|
|
1516
|
+
type: "Standard",
|
|
1517
|
+
hideTitle: !title
|
|
1518
|
+
}
|
|
1519
|
+
}, options);
|
|
1520
|
+
}
|
|
1521
|
+
function compoundControl(field, title, children, options) {
|
|
1522
|
+
return _extends({
|
|
1523
|
+
type: ControlDefinitionType.Data,
|
|
1524
|
+
field,
|
|
1525
|
+
children,
|
|
1526
|
+
title,
|
|
1527
|
+
renderOptions: {
|
|
1528
|
+
type: "Standard"
|
|
1529
|
+
}
|
|
1530
|
+
}, options);
|
|
1531
|
+
}
|
|
1532
|
+
function actionControl(actionText, actionId, options) {
|
|
1533
|
+
return _extends({
|
|
1534
|
+
type: ControlDefinitionType.Action,
|
|
1535
|
+
title: actionText,
|
|
1536
|
+
actionId
|
|
1537
|
+
}, options);
|
|
1538
|
+
}
|
|
1539
|
+
function createAction(actionId, onClick, actionText, options) {
|
|
1540
|
+
return _extends({
|
|
1541
|
+
actionId,
|
|
1542
|
+
onClick,
|
|
1543
|
+
actionText: actionText != null ? actionText : actionId
|
|
1544
|
+
}, options);
|
|
1545
|
+
}
|
|
1546
|
+
const emptyGroupDefinition = {
|
|
1547
|
+
type: ControlDefinitionType.Group,
|
|
1548
|
+
children: [],
|
|
1549
|
+
groupOptions: {
|
|
1550
|
+
type: GroupRenderType.Standard,
|
|
1551
|
+
hideTitle: true
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
function useControlDefinitionForSchema(sf, definition = emptyGroupDefinition) {
|
|
1555
|
+
return useMemo(() => {
|
|
1556
|
+
var _definition$children;
|
|
1557
|
+
return _extends({}, definition, {
|
|
1558
|
+
children: addMissingControls(sf, (_definition$children = definition.children) != null ? _definition$children : [])
|
|
1559
|
+
});
|
|
1560
|
+
}, [sf, definition]);
|
|
1561
|
+
}
|
|
1562
|
+
function applyExtensionToSchema(schemaMap, extension) {
|
|
1563
|
+
const outMap = _extends({}, schemaMap);
|
|
1564
|
+
Object.entries(extension).forEach(([field, cro]) => {
|
|
1565
|
+
outMap[field] = (Array.isArray(cro) ? cro : [cro]).reduce((a, cr) => {
|
|
1566
|
+
var _cr$fields;
|
|
1567
|
+
return mergeFields(a, cr.name, cr.value, (_cr$fields = cr.fields) != null ? _cr$fields : []);
|
|
1568
|
+
}, outMap[field]);
|
|
1569
|
+
});
|
|
1570
|
+
return outMap;
|
|
1571
|
+
}
|
|
1572
|
+
function applyExtensionsToSchema(schemaMap, extensions) {
|
|
1573
|
+
return resolveSchemas(extensions.reduce(applyExtensionToSchema, schemaMap));
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Creates a dynamic hook generator.
|
|
1578
|
+
* @template A - The type of the hook result.
|
|
1579
|
+
* @template P - The type of the hook context.
|
|
1580
|
+
* @template S - The type of the hook state.
|
|
1581
|
+
* @param runHook - The function to run the hook.
|
|
1582
|
+
* @param state - The initial state of the hook.
|
|
1583
|
+
* @param deps - The dependencies of the hook.
|
|
1584
|
+
* @returns The dynamic hook generator.
|
|
1585
|
+
*/
|
|
1586
|
+
function makeHook(runHook, state, deps) {
|
|
1587
|
+
return {
|
|
1588
|
+
deps,
|
|
1589
|
+
state,
|
|
1590
|
+
runHook
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Converts an array of dependencies to a dependency string.
|
|
1595
|
+
* @template A - The type of the dependencies.
|
|
1596
|
+
* @param deps - The array of dependencies.
|
|
1597
|
+
* @param asHookDep - The function to convert a dependency to a hook dependency.
|
|
1598
|
+
* @returns The dependency string.
|
|
1599
|
+
*/
|
|
1600
|
+
function makeHookDepString(deps, asHookDep) {
|
|
1601
|
+
return deps.map(x => toDepString(asHookDep(x))).join(",");
|
|
1602
|
+
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Custom hook to use dynamic hooks.
|
|
1605
|
+
* @template P - The type of the hook context.
|
|
1606
|
+
* @template Hooks - The type of the hooks.
|
|
1607
|
+
* @param hooks - The hooks to use.
|
|
1608
|
+
* @returns A function that takes the hook context and returns the hook values.
|
|
1609
|
+
*/
|
|
1610
|
+
function useDynamicHooks(hooks) {
|
|
1611
|
+
const hookEntries = Object.entries(hooks);
|
|
1612
|
+
const deps = makeHookDepString(hookEntries, x => x[1].deps);
|
|
1613
|
+
const ref = useRef({});
|
|
1614
|
+
const s = ref.current;
|
|
1615
|
+
hookEntries.forEach(x => s[x[0]] = x[1].state);
|
|
1616
|
+
return useCallback(p => {
|
|
1617
|
+
return Object.fromEntries(hookEntries.map(([f, hg]) => [f, hg.runHook(p, ref.current[f])]));
|
|
1618
|
+
}, [deps]);
|
|
1619
|
+
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Converts a value to a dependency string.
|
|
1622
|
+
* @param x - The value to convert.
|
|
1623
|
+
* @returns The dependency string.
|
|
1624
|
+
*/
|
|
1625
|
+
function toDepString(x) {
|
|
1626
|
+
if (x === undefined) return "_";
|
|
1627
|
+
if (x === null) return "~";
|
|
1628
|
+
return x.toString();
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
function useEvalVisibilityHook(useEvalExpressionHook, definition, overrideDataNode) {
|
|
1632
|
+
const dynamicVisibility = useEvalDynamicBoolHook(definition, DynamicPropertyType.Visible, useEvalExpressionHook);
|
|
1633
|
+
return makeDynamicPropertyHook(dynamicVisibility, (ctx, {
|
|
1634
|
+
definition,
|
|
1635
|
+
overrideDataNode
|
|
1636
|
+
}) => useComputed(() => {
|
|
1637
|
+
const dataNode = overrideDataNode != null ? overrideDataNode : ctx.dataNode;
|
|
1638
|
+
return !dataNode || matchesType(dataNode) && !hideDisplayOnly(dataNode, ctx.schemaInterface, definition);
|
|
1639
|
+
}), {
|
|
1640
|
+
definition,
|
|
1641
|
+
overrideDataNode
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
function useEvalReadonlyHook(useEvalExpressionHook, definition) {
|
|
1645
|
+
const dynamicReadonly = useEvalDynamicBoolHook(definition, DynamicPropertyType.Readonly, useEvalExpressionHook);
|
|
1646
|
+
return makeDynamicPropertyHook(dynamicReadonly, (ctx, {
|
|
1647
|
+
definition
|
|
1648
|
+
}) => useCalculatedControl(() => isControlReadonly(definition)), {
|
|
1649
|
+
definition
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
function useEvalStyleHook(useEvalExpressionHook, property, definition) {
|
|
1653
|
+
const dynamicStyle = useEvalDynamicHook(definition, property, useEvalExpressionHook);
|
|
1654
|
+
return makeDynamicPropertyHook(dynamicStyle, () => useControl(undefined), undefined);
|
|
1655
|
+
}
|
|
1656
|
+
function useEvalAllowedOptionsHook(useEvalExpressionHook, definition) {
|
|
1657
|
+
const dynamicAllowed = useEvalDynamicHook(definition, DynamicPropertyType.AllowedOptions, useEvalExpressionHook);
|
|
1658
|
+
return makeDynamicPropertyHook(dynamicAllowed, () => useControl([]), undefined);
|
|
1659
|
+
}
|
|
1660
|
+
function useEvalDisabledHook(useEvalExpressionHook, definition) {
|
|
1661
|
+
const dynamicDisabled = useEvalDynamicBoolHook(definition, DynamicPropertyType.Disabled, useEvalExpressionHook);
|
|
1662
|
+
return makeDynamicPropertyHook(dynamicDisabled, ctx => useComputed(() => {
|
|
1663
|
+
var _ctx$dataNode, _dataControl$meta$nul;
|
|
1664
|
+
const dataControl = (_ctx$dataNode = ctx.dataNode) == null ? void 0 : _ctx$dataNode.control;
|
|
1665
|
+
const setToNull = (dataControl == null || (_dataControl$meta$nul = dataControl.meta["nullControl"]) == null ? void 0 : _dataControl$meta$nul.value) === false;
|
|
1666
|
+
return setToNull || isControlDisabled(definition);
|
|
1667
|
+
}), undefined);
|
|
1668
|
+
}
|
|
1669
|
+
function useEvalDisplayHook(useEvalExpressionHook, definition) {
|
|
1670
|
+
return useEvalDynamicHook(definition, DynamicPropertyType.Display, useEvalExpressionHook);
|
|
1671
|
+
}
|
|
1672
|
+
function useEvalDefaultValueHook(useEvalExpressionHook, definition) {
|
|
1673
|
+
const dynamicValue = useEvalDynamicHook(definition, DynamicPropertyType.DefaultValue, useEvalExpressionHook);
|
|
1674
|
+
return makeDynamicPropertyHook(dynamicValue, (ctx, {
|
|
1675
|
+
definition
|
|
1676
|
+
}) => {
|
|
1677
|
+
return useComputed(calcDefault);
|
|
1678
|
+
function calcDefault() {
|
|
1679
|
+
var _ctx$dataNode2;
|
|
1680
|
+
const [required, dcv] = isDataControl(definition) ? [definition.required, definition.defaultValue] : [false, undefined];
|
|
1681
|
+
const field = (_ctx$dataNode2 = ctx.dataNode) == null ? void 0 : _ctx$dataNode2.schema.field;
|
|
1682
|
+
return dcv != null ? dcv : field ? ctx.dataNode.elementIndex != null ? elementValueForField(field) : defaultValueForField(field, required) : undefined;
|
|
1683
|
+
}
|
|
1684
|
+
}, {
|
|
1685
|
+
definition
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
function useDataExpression(fvExpr, node, coerce = x => x) {
|
|
1689
|
+
const otherField = schemaDataForFieldRef(fvExpr.field, node);
|
|
1690
|
+
return useCalculatedControl(() => {
|
|
1691
|
+
var _otherField$control;
|
|
1692
|
+
return coerce((_otherField$control = otherField.control) == null ? void 0 : _otherField$control.value);
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
function useDataMatchExpression(fvExpr, node, coerce = x => x) {
|
|
1696
|
+
const otherField = schemaDataForFieldRef(fvExpr.field, node);
|
|
1697
|
+
return useCalculatedControl(() => {
|
|
1698
|
+
var _otherField$control2;
|
|
1699
|
+
const fv = (_otherField$control2 = otherField.control) == null ? void 0 : _otherField$control2.value;
|
|
1700
|
+
return coerce(Array.isArray(fv) ? fv.includes(fvExpr.value) : fv === fvExpr.value);
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
function useNotEmptyExpression(fvExpr, node, schemaInterface, coerce = x => x) {
|
|
1704
|
+
const otherField = schemaDataForFieldRef(fvExpr.field, node);
|
|
1705
|
+
return useCalculatedControl(() => {
|
|
1706
|
+
var _otherField$control3;
|
|
1707
|
+
const fv = (_otherField$control3 = otherField.control) == null ? void 0 : _otherField$control3.value;
|
|
1708
|
+
const field = otherField.schema.field;
|
|
1709
|
+
return coerce(field && !schemaInterface.isEmptyValue(field, fv));
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
function defaultEvalHooks(expr, context, coerce) {
|
|
1713
|
+
switch (expr.type) {
|
|
1714
|
+
case ExpressionType.Jsonata:
|
|
1715
|
+
const bindings = useComputed(() => ({
|
|
1716
|
+
formData: context.formData
|
|
1717
|
+
}));
|
|
1718
|
+
return useJsonataExpression(expr.expression, getRootDataNode(context.parentNode).control, getJsonPath(context.parentNode), bindings, coerce);
|
|
1719
|
+
case ExpressionType.UUID:
|
|
1720
|
+
return useUuidExpression(coerce);
|
|
1721
|
+
case ExpressionType.Data:
|
|
1722
|
+
return useDataExpression(expr, context.parentNode, coerce);
|
|
1723
|
+
case ExpressionType.DataMatch:
|
|
1724
|
+
return useDataMatchExpression(expr, context.parentNode, coerce);
|
|
1725
|
+
case ExpressionType.NotEmpty:
|
|
1726
|
+
return useNotEmptyExpression(expr, context.parentNode, context.schemaInterface, coerce);
|
|
1727
|
+
default:
|
|
1728
|
+
return useControl(undefined);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
const defaultUseEvalExpressionHook = makeEvalExpressionHook(defaultEvalHooks);
|
|
1732
|
+
function makeEvalExpressionHook(f) {
|
|
1733
|
+
return (expr, coerce) => ({
|
|
1734
|
+
deps: expr == null ? void 0 : expr.type,
|
|
1735
|
+
state: expr && expr.type ? expr : undefined,
|
|
1736
|
+
runHook: (ctx, state) => {
|
|
1737
|
+
return state ? f(state, ctx, coerce) : undefined;
|
|
1738
|
+
}
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
function useEvalDynamicBoolHook(definition, type, useEvalExpressionHook) {
|
|
1742
|
+
return useEvalDynamicHook(definition, type, useEvalExpressionHook, x => Boolean(x));
|
|
1743
|
+
}
|
|
1744
|
+
function useEvalDynamicHook(definition, type, useEvalExpressionHook, coerce = x => x) {
|
|
1745
|
+
var _definition$dynamic;
|
|
1746
|
+
const expression = (_definition$dynamic = definition.dynamic) == null ? void 0 : _definition$dynamic.find(x => x.type === type);
|
|
1747
|
+
return useEvalExpressionHook(expression == null ? void 0 : expression.expr, coerce);
|
|
1748
|
+
}
|
|
1749
|
+
function matchesType(context) {
|
|
1750
|
+
const types = context.schema.field.onlyForTypes;
|
|
1751
|
+
if (types == null || types.length === 0) return true;
|
|
1752
|
+
const parent = context.parent;
|
|
1753
|
+
const typeNode = parent.schema.getChildNodes().find(x => x.field.isTypeField);
|
|
1754
|
+
if (typeNode == null) return true;
|
|
1755
|
+
const typeField = parent.getChild(typeNode).control;
|
|
1756
|
+
return typeField && types.includes(typeField.value);
|
|
1757
|
+
}
|
|
1758
|
+
function hideDisplayOnly(context, schemaInterface, definition) {
|
|
1759
|
+
var _context$control;
|
|
1760
|
+
const displayOptions = getDisplayOnlyOptions(definition);
|
|
1761
|
+
return displayOptions && !displayOptions.emptyText && schemaInterface.isEmptyValue(context.schema.field, (_context$control = context.control) == null ? void 0 : _context$control.value);
|
|
1762
|
+
}
|
|
1763
|
+
function useUuidExpression(coerce = x => x) {
|
|
1764
|
+
return useControl(() => coerce(v4()));
|
|
1765
|
+
}
|
|
1766
|
+
function useJsonataExpression(jExpr, data, path, bindings, coerce = x => x) {
|
|
1767
|
+
const pathString = jsonPathString(path, x => `#$i[${x}]`);
|
|
1768
|
+
const fullExpr = pathString ? pathString + ".(" + jExpr + ")" : jExpr;
|
|
1769
|
+
const compiledExpr = useMemo(() => {
|
|
1770
|
+
try {
|
|
1771
|
+
return jsonata(jExpr ? fullExpr : "null");
|
|
1772
|
+
} catch (e) {
|
|
1773
|
+
console.error(e);
|
|
1774
|
+
return jsonata("null");
|
|
1775
|
+
}
|
|
1776
|
+
}, [fullExpr]);
|
|
1777
|
+
const control = useControl();
|
|
1778
|
+
const listenerRef = useRef();
|
|
1779
|
+
const updateRef = useRef(0);
|
|
1780
|
+
const [ref] = useRefState(() => new SubscriptionTracker(() => {
|
|
1781
|
+
const l = listenerRef.current;
|
|
1782
|
+
if (l) {
|
|
1783
|
+
listenerRef.current = undefined;
|
|
1784
|
+
addAfterChangesCallback(() => {
|
|
1785
|
+
listenerRef.current = l;
|
|
1786
|
+
l();
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
}));
|
|
1790
|
+
useEffect(() => {
|
|
1791
|
+
listenerRef.current = apply;
|
|
1792
|
+
apply();
|
|
1793
|
+
async function apply() {
|
|
1794
|
+
const tracker = ref.current;
|
|
1795
|
+
try {
|
|
1796
|
+
updateRef.current++;
|
|
1797
|
+
control.value = coerce(await compiledExpr.evaluate(trackedValue(data, tracker.collectUsage), collectChanges(tracker.collectUsage, () => bindings == null ? void 0 : bindings.value)));
|
|
1798
|
+
} finally {
|
|
1799
|
+
if (! --updateRef.current) tracker.update();
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}, [compiledExpr]);
|
|
1803
|
+
useEffect(() => {
|
|
1804
|
+
return () => {
|
|
1805
|
+
listenerRef.current = undefined;
|
|
1806
|
+
ref.current.cleanup();
|
|
1807
|
+
};
|
|
1808
|
+
}, []);
|
|
1809
|
+
return control;
|
|
1810
|
+
}
|
|
1811
|
+
function useEvalActionHook(useExpr, definition) {
|
|
1812
|
+
const dynamicValue = useEvalDynamicHook(definition, DynamicPropertyType.ActionData, useExpr);
|
|
1813
|
+
return makeDynamicPropertyHook(dynamicValue, () => useControl(null), undefined);
|
|
1814
|
+
}
|
|
1815
|
+
function useEvalLabelText(useExpr, definition) {
|
|
1816
|
+
const dynamicValue = useEvalDynamicHook(definition, DynamicPropertyType.Label, useExpr);
|
|
1817
|
+
return makeDynamicPropertyHook(dynamicValue, () => useControl(null), undefined);
|
|
1818
|
+
}
|
|
1819
|
+
function makeDynamicPropertyHook(dynamicValue, makeDefault, state, deps) {
|
|
1820
|
+
return {
|
|
1821
|
+
deps: deps === undefined ? dynamicValue.deps : [deps, dynamicValue.deps].map(toDepString).join(),
|
|
1822
|
+
runHook: (ctx, s) => {
|
|
1823
|
+
var _dynamicValue$runHook, _dynamicValue$runHook2;
|
|
1824
|
+
return (_dynamicValue$runHook = (_dynamicValue$runHook2 = dynamicValue.runHook(ctx, s[0])) == null ? void 0 : _dynamicValue$runHook2.as()) != null ? _dynamicValue$runHook : makeDefault(ctx, s[1]);
|
|
1825
|
+
},
|
|
1826
|
+
state: [dynamicValue.state, state]
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
function useMakeValidationHook(definition, useValidatorFor = useDefaultValidator) {
|
|
1831
|
+
var _dd$validators;
|
|
1832
|
+
const dd = isDataControl(definition) ? definition : undefined;
|
|
1833
|
+
const refData = useUpdatedRef({
|
|
1834
|
+
dd,
|
|
1835
|
+
useValidatorFor
|
|
1836
|
+
});
|
|
1837
|
+
const depString = dd ? makeHookDepString((_dd$validators = dd.validators) != null ? _dd$validators : [], x => x.type) : "~";
|
|
1838
|
+
return useCallback(ctx => {
|
|
1839
|
+
var _ctx$dataContext$data, _ctx$dataContext$data2, _dd$validators2;
|
|
1840
|
+
const {
|
|
1841
|
+
dd
|
|
1842
|
+
} = refData.current;
|
|
1843
|
+
if (!dd) return;
|
|
1844
|
+
const field = (_ctx$dataContext$data = (_ctx$dataContext$data2 = ctx.dataContext.dataNode) == null ? void 0 : _ctx$dataContext$data2.schema.field) != null ? _ctx$dataContext$data : {
|
|
1845
|
+
field: "__missing",
|
|
1846
|
+
type: FieldType.Any
|
|
1847
|
+
};
|
|
1848
|
+
const {
|
|
1849
|
+
control,
|
|
1850
|
+
hiddenControl,
|
|
1851
|
+
dataContext: {
|
|
1852
|
+
schemaInterface
|
|
1853
|
+
}
|
|
1854
|
+
} = ctx;
|
|
1855
|
+
useValueChangeEffect(control, () => control.setError("default", ""));
|
|
1856
|
+
if (dd.required) useValidator(control, v => {
|
|
1857
|
+
return !hiddenControl.value && schemaInterface.isEmptyValue(field, v) ? schemaInterface.validationMessageText(field, ValidationMessageType.NotEmpty, false, true) : null;
|
|
1858
|
+
}, "required");
|
|
1859
|
+
(_dd$validators2 = dd.validators) == null || _dd$validators2.forEach((v, i) => useValidatorFor(v, _extends({}, ctx, {
|
|
1860
|
+
index: i,
|
|
1861
|
+
field,
|
|
1862
|
+
definition: dd
|
|
1863
|
+
})));
|
|
1864
|
+
}, [!!dd, dd == null ? void 0 : dd.required, depString, useValidatorFor]);
|
|
1865
|
+
}
|
|
1866
|
+
function useDefaultValidator(validator, ctx) {
|
|
1867
|
+
switch (validator.type) {
|
|
1868
|
+
case ValidatorType.Length:
|
|
1869
|
+
useLengthValidator(validator, ctx);
|
|
1870
|
+
break;
|
|
1871
|
+
case ValidatorType.Jsonata:
|
|
1872
|
+
useJsonataValidator(validator, ctx);
|
|
1873
|
+
break;
|
|
1874
|
+
case ValidatorType.Date:
|
|
1875
|
+
useDateValidator(validator, ctx);
|
|
1876
|
+
break;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
function useJsonataValidator(validator, ctx) {
|
|
1880
|
+
const sdn = ctx.dataContext.parentNode;
|
|
1881
|
+
const errorMsg = useJsonataExpression(validator.expression, getRootDataNode(sdn).control, getJsonPath(sdn), undefined, v => v == null ? null : typeof v === "string" ? v : JSON.stringify(v));
|
|
1882
|
+
useValidator(ctx.control, () => !ctx.hiddenControl.value ? errorMsg.value : null, "jsonata" + ctx.index);
|
|
1883
|
+
}
|
|
1884
|
+
function useLengthValidator(lv, ctx) {
|
|
1885
|
+
const {
|
|
1886
|
+
control,
|
|
1887
|
+
dataContext: {
|
|
1888
|
+
schemaInterface
|
|
1889
|
+
},
|
|
1890
|
+
hiddenControl,
|
|
1891
|
+
field
|
|
1892
|
+
} = ctx;
|
|
1893
|
+
useValidator(control, v => {
|
|
1894
|
+
const len = schemaInterface.controlLength(field, control);
|
|
1895
|
+
const hidden = hiddenControl.value;
|
|
1896
|
+
if (hidden) {
|
|
1897
|
+
return undefined;
|
|
1898
|
+
}
|
|
1899
|
+
if (lv.min != null && len < lv.min) {
|
|
1900
|
+
if (field != null && field.collection) {
|
|
1901
|
+
control.setValue(v => Array.isArray(v) ? v.concat(Array.from({
|
|
1902
|
+
length: lv.min - v.length
|
|
1903
|
+
})) : Array.from({
|
|
1904
|
+
length: lv.min
|
|
1905
|
+
}));
|
|
1906
|
+
} else {
|
|
1907
|
+
return schemaInterface.validationMessageText(field, ValidationMessageType.MinLength, len, lv.min);
|
|
1908
|
+
}
|
|
1909
|
+
} else if (lv.max != null && len > lv.max) {
|
|
1910
|
+
return schemaInterface.validationMessageText(field, ValidationMessageType.MaxLength, len, lv.max);
|
|
1911
|
+
}
|
|
1912
|
+
return undefined;
|
|
1913
|
+
}, "length" + ctx.index);
|
|
1914
|
+
}
|
|
1915
|
+
function useDateValidator(dv, ctx) {
|
|
1916
|
+
const {
|
|
1917
|
+
control,
|
|
1918
|
+
field,
|
|
1919
|
+
index,
|
|
1920
|
+
dataContext: {
|
|
1921
|
+
schemaInterface
|
|
1922
|
+
}
|
|
1923
|
+
} = ctx;
|
|
1924
|
+
let comparisonDate;
|
|
1925
|
+
if (dv.fixedDate) {
|
|
1926
|
+
comparisonDate = schemaInterface.parseToMillis(field, dv.fixedDate);
|
|
1927
|
+
} else {
|
|
1928
|
+
const nowDate = new Date();
|
|
1929
|
+
comparisonDate = Date.UTC(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate());
|
|
1930
|
+
if (dv.daysFromCurrent) {
|
|
1931
|
+
comparisonDate += dv.daysFromCurrent * 86400000;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
useValidator(control, v => {
|
|
1935
|
+
if (v) {
|
|
1936
|
+
const selDate = schemaInterface.parseToMillis(field, v);
|
|
1937
|
+
const notAfter = dv.comparison === DateComparison.NotAfter;
|
|
1938
|
+
if (notAfter ? selDate > comparisonDate : selDate < comparisonDate) {
|
|
1939
|
+
return schemaInterface.validationMessageText(field, notAfter ? ValidationMessageType.NotAfterDate : ValidationMessageType.NotBeforeDate, selDate, comparisonDate);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return null;
|
|
1943
|
+
}, "date" + index);
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
class DefaultSchemaInterface {
|
|
1947
|
+
constructor(boolStrings = ["No", "Yes"], parseDateTime = s => Date.parse(s)) {
|
|
1948
|
+
this.boolStrings = void 0;
|
|
1949
|
+
this.parseDateTime = void 0;
|
|
1950
|
+
this.boolStrings = boolStrings;
|
|
1951
|
+
this.parseDateTime = parseDateTime;
|
|
1952
|
+
}
|
|
1953
|
+
parseToMillis(field, v) {
|
|
1954
|
+
return this.parseDateTime(v);
|
|
1955
|
+
}
|
|
1956
|
+
validationMessageText(field, messageType, actual, expected) {
|
|
1957
|
+
switch (messageType) {
|
|
1958
|
+
case ValidationMessageType.NotEmpty:
|
|
1959
|
+
return "Please enter a value";
|
|
1960
|
+
case ValidationMessageType.MinLength:
|
|
1961
|
+
return "Length must be at least " + expected;
|
|
1962
|
+
case ValidationMessageType.MaxLength:
|
|
1963
|
+
return "Length must be less than " + expected;
|
|
1964
|
+
case ValidationMessageType.NotBeforeDate:
|
|
1965
|
+
return `Date must not be before ${new Date(expected).toDateString()}`;
|
|
1966
|
+
case ValidationMessageType.NotAfterDate:
|
|
1967
|
+
return `Date must not be after ${new Date(expected).toDateString()}`;
|
|
1968
|
+
default:
|
|
1969
|
+
return "Unknown error";
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
getDataOptions(node) {
|
|
1973
|
+
return this.getNodeOptions(node.schema);
|
|
1974
|
+
}
|
|
1975
|
+
getNodeOptions(node) {
|
|
1976
|
+
return this.getOptions(node.field);
|
|
1977
|
+
}
|
|
1978
|
+
getOptions({
|
|
1979
|
+
options
|
|
1980
|
+
}) {
|
|
1981
|
+
return options && options.length > 0 ? options : null;
|
|
1982
|
+
}
|
|
1983
|
+
getFilterOptions(array, field) {
|
|
1984
|
+
return this.getNodeOptions(field);
|
|
1985
|
+
}
|
|
1986
|
+
isEmptyValue(f, value) {
|
|
1987
|
+
if (f.collection) return Array.isArray(value) ? value.length === 0 : value == null;
|
|
1988
|
+
switch (f.type) {
|
|
1989
|
+
case FieldType.String:
|
|
1990
|
+
case FieldType.DateTime:
|
|
1991
|
+
case FieldType.Date:
|
|
1992
|
+
case FieldType.Time:
|
|
1993
|
+
return !value;
|
|
1994
|
+
default:
|
|
1995
|
+
return value == null;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
searchText(field, value) {
|
|
1999
|
+
var _this$textValue$toLow, _this$textValue;
|
|
2000
|
+
return (_this$textValue$toLow = (_this$textValue = this.textValue(field, value)) == null ? void 0 : _this$textValue.toLowerCase()) != null ? _this$textValue$toLow : "";
|
|
2001
|
+
}
|
|
2002
|
+
textValue(field, value, element) {
|
|
2003
|
+
const options = this.getOptions(field);
|
|
2004
|
+
const option = options == null ? void 0 : options.find(x => x.value === value);
|
|
2005
|
+
if (option) return option.name;
|
|
2006
|
+
switch (field.type) {
|
|
2007
|
+
case FieldType.Date:
|
|
2008
|
+
return value ? new Date(value).toLocaleDateString() : undefined;
|
|
2009
|
+
case FieldType.DateTime:
|
|
2010
|
+
return value ? new Date(this.parseToMillis(field, value)).toLocaleString() : undefined;
|
|
2011
|
+
case FieldType.Time:
|
|
2012
|
+
return value ? new Date("1970-01-01T" + value).toLocaleTimeString() : undefined;
|
|
2013
|
+
case FieldType.Bool:
|
|
2014
|
+
return this.boolStrings[value ? 1 : 0];
|
|
2015
|
+
default:
|
|
2016
|
+
return value != null ? value.toString() : undefined;
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
controlLength(f, control) {
|
|
2020
|
+
var _control$elements$len, _control$elements;
|
|
2021
|
+
return f.collection ? (_control$elements$len = (_control$elements = control.elements) == null ? void 0 : _control$elements.length) != null ? _control$elements$len : 0 : this.valueLength(f, control.value);
|
|
2022
|
+
}
|
|
2023
|
+
valueLength(field, value) {
|
|
2024
|
+
var _ref;
|
|
2025
|
+
return (_ref = value && (value == null ? void 0 : value.length)) != null ? _ref : 0;
|
|
2026
|
+
}
|
|
2027
|
+
compareValue(field, v1, v2) {
|
|
2028
|
+
if (v1 == null) return v2 == null ? 0 : 1;
|
|
2029
|
+
if (v2 == null) return -1;
|
|
2030
|
+
switch (field.type) {
|
|
2031
|
+
case FieldType.Date:
|
|
2032
|
+
case FieldType.DateTime:
|
|
2033
|
+
case FieldType.Time:
|
|
2034
|
+
case FieldType.String:
|
|
2035
|
+
return v1.localeCompare(v2);
|
|
2036
|
+
case FieldType.Bool:
|
|
2037
|
+
return v1 ? v2 ? 0 : 1 : -1;
|
|
2038
|
+
case FieldType.Int:
|
|
2039
|
+
case FieldType.Double:
|
|
2040
|
+
return v1 - v2;
|
|
2041
|
+
default:
|
|
2042
|
+
return 0;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
compoundFieldSetup(f) {
|
|
2046
|
+
return f.getChildNodes().map(x => {
|
|
2047
|
+
const {
|
|
2048
|
+
field
|
|
2049
|
+
} = x.field;
|
|
2050
|
+
return [field, this.makeControlSetup(x)];
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
compoundFieldEquality(f) {
|
|
2054
|
+
return f.getChildNodes().map(x => {
|
|
2055
|
+
const {
|
|
2056
|
+
field
|
|
2057
|
+
} = x.field;
|
|
2058
|
+
return [field, (a, b) => this.makeEqualityFunc(x)(a[field], b[field])];
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
makeEqualityFunc(field, element) {
|
|
2062
|
+
if (field.field.collection && !element) {
|
|
2063
|
+
const elemEqual = this.makeEqualityFunc(field, true);
|
|
2064
|
+
return (a, b) => {
|
|
2065
|
+
if (a === b) return true;
|
|
2066
|
+
if (a == null || b == null) return false;
|
|
2067
|
+
if (a.length !== b.length) return false;
|
|
2068
|
+
for (let i = 0; i < a.length; i++) {
|
|
2069
|
+
if (!elemEqual(a[i], b[i])) return false;
|
|
2070
|
+
}
|
|
2071
|
+
return true;
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
switch (field.field.type) {
|
|
2075
|
+
case FieldType.Compound:
|
|
2076
|
+
const allChecks = this.compoundFieldEquality(field);
|
|
2077
|
+
return (a, b) => a === b || a != null && b != null && allChecks.every(x => x[1](a, b));
|
|
2078
|
+
default:
|
|
2079
|
+
return (a, b) => a === b;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
makeControlSetup(field, element) {
|
|
2083
|
+
let setup = {
|
|
2084
|
+
equals: this.makeEqualityFunc(field, element)
|
|
2085
|
+
};
|
|
2086
|
+
if (field.field.collection && !element) {
|
|
2087
|
+
setup.elems = this.makeControlSetup(field, true);
|
|
2088
|
+
return setup;
|
|
2089
|
+
}
|
|
2090
|
+
switch (field.field.type) {
|
|
2091
|
+
case FieldType.Compound:
|
|
2092
|
+
setup.fields = Object.fromEntries(this.compoundFieldSetup(field));
|
|
2093
|
+
}
|
|
2094
|
+
return setup;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
const defaultSchemaInterface = new DefaultSchemaInterface();
|
|
2098
|
+
|
|
2099
|
+
const _excluded = ["parentDataNode"],
|
|
2100
|
+
_excluded2 = ["definition", "control", "formOptions", "style", "allowedOptions", "schemaInterface", "styleClass"];
|
|
2101
|
+
const AppendAdornmentPriority = 0;
|
|
2102
|
+
const WrapAdornmentPriority = 1000;
|
|
2103
|
+
/**
|
|
2104
|
+
* Enum representing the types of labels that can be rendered.
|
|
2105
|
+
*/
|
|
2106
|
+
var LabelType;
|
|
2107
|
+
(function (LabelType) {
|
|
2108
|
+
/**
|
|
2109
|
+
* Label for a control.
|
|
2110
|
+
*/
|
|
2111
|
+
LabelType[LabelType["Control"] = 0] = "Control";
|
|
2112
|
+
/**
|
|
2113
|
+
* Label for a group.
|
|
2114
|
+
*/
|
|
2115
|
+
LabelType[LabelType["Group"] = 1] = "Group";
|
|
2116
|
+
/**
|
|
2117
|
+
* Label for text.
|
|
2118
|
+
*/
|
|
2119
|
+
LabelType[LabelType["Text"] = 2] = "Text";
|
|
2120
|
+
})(LabelType || (LabelType = {}));
|
|
2121
|
+
function useControlRenderer(definition, fields, renderer, options = {}) {
|
|
2122
|
+
const r = useUpdatedRef({
|
|
2123
|
+
definition,
|
|
2124
|
+
fields,
|
|
2125
|
+
renderer,
|
|
2126
|
+
options
|
|
2127
|
+
});
|
|
2128
|
+
return useCallback(({
|
|
2129
|
+
control,
|
|
2130
|
+
parentPath
|
|
2131
|
+
}) => {
|
|
2132
|
+
return React.createElement(ControlRenderer, _extends({}, r.current, {
|
|
2133
|
+
control: control,
|
|
2134
|
+
parentPath: parentPath
|
|
2135
|
+
}));
|
|
2136
|
+
}, [r]);
|
|
2137
|
+
}
|
|
2138
|
+
function useControlRendererComponent(controlOrFormNode, renderer, options = {}, parentDataNode) {
|
|
2139
|
+
var _options$useDataHook, _options$schemaInterf, _options$useEvalExpre;
|
|
2140
|
+
const [definition, formNode] = controlOrFormNode instanceof FormNode ? [controlOrFormNode.definition, controlOrFormNode] : [controlOrFormNode, legacyFormNode(controlOrFormNode)];
|
|
2141
|
+
const dataProps = (_options$useDataHook = options.useDataHook == null ? void 0 : options.useDataHook(definition)) != null ? _options$useDataHook : defaultDataProps;
|
|
2142
|
+
const elementIndex = options.elementIndex;
|
|
2143
|
+
const schemaInterface = (_options$schemaInterf = options.schemaInterface) != null ? _options$schemaInterf : defaultSchemaInterface;
|
|
2144
|
+
const useExpr = (_options$useEvalExpre = options.useEvalExpressionHook) != null ? _options$useEvalExpre : defaultUseEvalExpressionHook;
|
|
2145
|
+
let dataNode;
|
|
2146
|
+
if (elementIndex != null) {
|
|
2147
|
+
dataNode = parentDataNode.getChildElement(elementIndex);
|
|
2148
|
+
} else {
|
|
2149
|
+
dataNode = lookupDataNode(definition, parentDataNode);
|
|
2150
|
+
}
|
|
2151
|
+
const useValidation = useMakeValidationHook(definition, options.useValidationHook);
|
|
2152
|
+
const dynamicHooks = useDynamicHooks({
|
|
2153
|
+
defaultValueControl: useEvalDefaultValueHook(useExpr, definition),
|
|
2154
|
+
visibleControl: useEvalVisibilityHook(useExpr, definition),
|
|
2155
|
+
readonlyControl: useEvalReadonlyHook(useExpr, definition),
|
|
2156
|
+
disabledControl: useEvalDisabledHook(useExpr, definition),
|
|
2157
|
+
allowedOptions: useEvalAllowedOptionsHook(useExpr, definition),
|
|
2158
|
+
labelText: useEvalLabelText(useExpr, definition),
|
|
2159
|
+
actionData: useEvalActionHook(useExpr, definition),
|
|
2160
|
+
customStyle: useEvalStyleHook(useExpr, DynamicPropertyType.Style, definition),
|
|
2161
|
+
layoutStyle: useEvalStyleHook(useExpr, DynamicPropertyType.LayoutStyle, definition),
|
|
2162
|
+
displayControl: useEvalDisplayHook(useExpr, definition)
|
|
2163
|
+
});
|
|
2164
|
+
const r = useUpdatedRef({
|
|
2165
|
+
options,
|
|
2166
|
+
definition,
|
|
2167
|
+
elementIndex,
|
|
2168
|
+
parentDataNode,
|
|
2169
|
+
dataNode,
|
|
2170
|
+
formNode
|
|
2171
|
+
});
|
|
2172
|
+
const Component = useCallback(() => {
|
|
2173
|
+
const stopTracking = useComponentTracking();
|
|
2174
|
+
try {
|
|
2175
|
+
var _options$formData, _dataNode, _definition$adornment2, _definition$adornment3, _options$adjustLayout;
|
|
2176
|
+
const {
|
|
2177
|
+
definition: c,
|
|
2178
|
+
options,
|
|
2179
|
+
elementIndex,
|
|
2180
|
+
parentDataNode: pdn,
|
|
2181
|
+
dataNode: dn,
|
|
2182
|
+
formNode
|
|
2183
|
+
} = r.current;
|
|
2184
|
+
const formData = (_options$formData = options.formData) != null ? _options$formData : {};
|
|
2185
|
+
const dataContext = {
|
|
2186
|
+
schemaInterface,
|
|
2187
|
+
dataNode: dn,
|
|
2188
|
+
parentNode: pdn,
|
|
2189
|
+
formData
|
|
2190
|
+
};
|
|
2191
|
+
const {
|
|
2192
|
+
readonlyControl,
|
|
2193
|
+
disabledControl,
|
|
2194
|
+
visibleControl,
|
|
2195
|
+
displayControl,
|
|
2196
|
+
layoutStyle,
|
|
2197
|
+
labelText,
|
|
2198
|
+
customStyle,
|
|
2199
|
+
allowedOptions,
|
|
2200
|
+
defaultValueControl,
|
|
2201
|
+
actionData
|
|
2202
|
+
} = dynamicHooks(dataContext);
|
|
2203
|
+
const visible = visibleControl.current.value;
|
|
2204
|
+
const visibility = useControl(() => visible != null ? {
|
|
2205
|
+
visible,
|
|
2206
|
+
showing: visible
|
|
2207
|
+
} : undefined);
|
|
2208
|
+
useControlEffect(() => visibleControl.value, visible => {
|
|
2209
|
+
if (visible != null) visibility.setValue(ex => ({
|
|
2210
|
+
visible,
|
|
2211
|
+
showing: ex ? ex.showing : visible
|
|
2212
|
+
}));
|
|
2213
|
+
});
|
|
2214
|
+
const parentControl = parentDataNode.control;
|
|
2215
|
+
const control = (_dataNode = dataNode) == null ? void 0 : _dataNode.control;
|
|
2216
|
+
useControlEffect(() => {
|
|
2217
|
+
var _definition$adornment, _definition$renderOpt;
|
|
2218
|
+
return [visibility.value, defaultValueControl.value, control == null ? void 0 : control.isNull, isDataControl(definition) && definition.dontClearHidden, ((_definition$adornment = definition.adornments) == null ? void 0 : _definition$adornment.some(x => x.type === ControlAdornmentType.Optional)) || isDataControl(definition) && ((_definition$renderOpt = definition.renderOptions) == null ? void 0 : _definition$renderOpt.type) == DataRenderType.NullToggle, parentControl.isNull, options.hidden, readonlyControl.value];
|
|
2219
|
+
}, ([vc, dv, _, dontClear, dontDefault, parentNull, hidden, ro]) => {
|
|
2220
|
+
if (!ro) {
|
|
2221
|
+
if (control) {
|
|
2222
|
+
if (vc && vc.visible === vc.showing) {
|
|
2223
|
+
if (hidden || !vc.visible) {
|
|
2224
|
+
control.setValue(x => options.clearHidden && !dontClear ? undefined : x == null && dontClear && !dontDefault ? dv : x);
|
|
2225
|
+
} else if (!dontDefault) control.setValue(x => x != null ? x : dv);
|
|
2226
|
+
}
|
|
2227
|
+
} else if (parentNull) {
|
|
2228
|
+
parentControl.setValue(x => x != null ? x : {});
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
}, true);
|
|
2232
|
+
const myOptionsControl = useComputed(() => {
|
|
2233
|
+
var _visibility$fields;
|
|
2234
|
+
return {
|
|
2235
|
+
hidden: options.hidden || !((_visibility$fields = visibility.fields) != null && _visibility$fields.showing.value),
|
|
2236
|
+
readonly: options.readonly || readonlyControl.value,
|
|
2237
|
+
disabled: options.disabled || disabledControl.value,
|
|
2238
|
+
displayOnly: options.displayOnly || isControlDisplayOnly(c)
|
|
2239
|
+
};
|
|
2240
|
+
});
|
|
2241
|
+
const myOptions = trackedValue(myOptionsControl);
|
|
2242
|
+
useValidation({
|
|
2243
|
+
control: control != null ? control : newControl(null),
|
|
2244
|
+
hiddenControl: myOptionsControl.fields.hidden,
|
|
2245
|
+
dataContext
|
|
2246
|
+
});
|
|
2247
|
+
const childOptions = _extends({}, options, myOptions, {
|
|
2248
|
+
elementIndex: undefined,
|
|
2249
|
+
formData
|
|
2250
|
+
});
|
|
2251
|
+
useEffect(() => {
|
|
2252
|
+
if (control && typeof myOptions.disabled === "boolean" && control.disabled != myOptions.disabled) control.disabled = myOptions.disabled;
|
|
2253
|
+
}, [control, myOptions.disabled]);
|
|
2254
|
+
if (parentControl.isNull) return React.createElement(React.Fragment, null);
|
|
2255
|
+
const adornments = (_definition$adornment2 = (_definition$adornment3 = definition.adornments) == null ? void 0 : _definition$adornment3.map(x => renderer.renderAdornment({
|
|
2256
|
+
adornment: x,
|
|
2257
|
+
dataContext,
|
|
2258
|
+
useExpr,
|
|
2259
|
+
formOptions: myOptions
|
|
2260
|
+
}))) != null ? _definition$adornment2 : [];
|
|
2261
|
+
const labelAndChildren = renderControlLayout({
|
|
2262
|
+
formNode,
|
|
2263
|
+
definition: c,
|
|
2264
|
+
renderer,
|
|
2265
|
+
renderChild: (k, child, options) => {
|
|
2266
|
+
var _ref2;
|
|
2267
|
+
const overrideClasses = getGroupClassOverrides(c);
|
|
2268
|
+
const _ref = options != null ? options : {},
|
|
2269
|
+
{
|
|
2270
|
+
parentDataNode
|
|
2271
|
+
} = _ref,
|
|
2272
|
+
renderOptions = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
2273
|
+
const dContext = (_ref2 = parentDataNode != null ? parentDataNode : dataContext.dataNode) != null ? _ref2 : dataContext.parentNode;
|
|
2274
|
+
return React.createElement(NewControlRenderer, {
|
|
2275
|
+
key: k,
|
|
2276
|
+
definition: child,
|
|
2277
|
+
renderer: renderer,
|
|
2278
|
+
parentDataNode: dContext,
|
|
2279
|
+
options: _extends({}, childOptions, overrideClasses, renderOptions)
|
|
2280
|
+
});
|
|
2281
|
+
},
|
|
2282
|
+
createDataProps: dataProps,
|
|
2283
|
+
formOptions: myOptions,
|
|
2284
|
+
dataContext,
|
|
2285
|
+
control: displayControl != null ? displayControl : control,
|
|
2286
|
+
elementIndex,
|
|
2287
|
+
schemaInterface,
|
|
2288
|
+
labelText,
|
|
2289
|
+
displayControl,
|
|
2290
|
+
style: customStyle.value,
|
|
2291
|
+
allowedOptions,
|
|
2292
|
+
customDisplay: options.customDisplay,
|
|
2293
|
+
actionDataControl: actionData,
|
|
2294
|
+
actionOnClick: options.actionOnClick,
|
|
2295
|
+
styleClass: options.styleClass,
|
|
2296
|
+
labelClass: options.labelClass,
|
|
2297
|
+
useEvalExpression: useExpr,
|
|
2298
|
+
useChildVisibility: (childDef, parentNode, dontOverride) => {
|
|
2299
|
+
var _ref3;
|
|
2300
|
+
return useEvalVisibilityHook(useExpr, childDef, !dontOverride ? lookupDataNode(childDef, (_ref3 = parentNode != null ? parentNode : dataNode) != null ? _ref3 : parentDataNode) : undefined);
|
|
2301
|
+
}
|
|
2302
|
+
});
|
|
2303
|
+
const layoutProps = _extends({}, labelAndChildren, {
|
|
2304
|
+
adornments,
|
|
2305
|
+
className: rendererClass(options.layoutClass, c.layoutClass),
|
|
2306
|
+
style: layoutStyle.value
|
|
2307
|
+
});
|
|
2308
|
+
const renderedControl = renderer.renderLayout((_options$adjustLayout = options.adjustLayout == null ? void 0 : options.adjustLayout(dataContext, layoutProps)) != null ? _options$adjustLayout : layoutProps);
|
|
2309
|
+
return renderer.renderVisibility(_extends({
|
|
2310
|
+
visibility
|
|
2311
|
+
}, renderedControl));
|
|
2312
|
+
} finally {
|
|
2313
|
+
stopTracking();
|
|
2314
|
+
}
|
|
2315
|
+
}, [r, dataProps, useValidation, renderer, schemaInterface, dynamicHooks]);
|
|
2316
|
+
Component.displayName = "RenderControl";
|
|
2317
|
+
return Component;
|
|
2318
|
+
}
|
|
2319
|
+
function ControlRenderer({
|
|
2320
|
+
definition,
|
|
2321
|
+
fields,
|
|
2322
|
+
renderer,
|
|
2323
|
+
options,
|
|
2324
|
+
control,
|
|
2325
|
+
parentPath
|
|
2326
|
+
}) {
|
|
2327
|
+
const schemaDataNode = makeSchemaDataNode(createSchemaLookup({
|
|
2328
|
+
"": fields
|
|
2329
|
+
}).getSchema(""), control);
|
|
2330
|
+
const Render = useControlRendererComponent(definition, renderer, options, schemaDataNode);
|
|
2331
|
+
return React.createElement(Render, null);
|
|
2332
|
+
}
|
|
2333
|
+
function NewControlRenderer({
|
|
2334
|
+
definition,
|
|
2335
|
+
renderer,
|
|
2336
|
+
options,
|
|
2337
|
+
parentDataNode
|
|
2338
|
+
}) {
|
|
2339
|
+
const Render = useControlRendererComponent(definition, renderer, options, parentDataNode);
|
|
2340
|
+
return React.createElement(Render, null);
|
|
2341
|
+
}
|
|
2342
|
+
function defaultDataProps(_ref4) {
|
|
2343
|
+
var _allowedOptions$value, _definition$renderOpt2;
|
|
2344
|
+
let {
|
|
2345
|
+
definition,
|
|
2346
|
+
control,
|
|
2347
|
+
formOptions,
|
|
2348
|
+
style,
|
|
2349
|
+
allowedOptions,
|
|
2350
|
+
schemaInterface = defaultSchemaInterface,
|
|
2351
|
+
styleClass
|
|
2352
|
+
} = _ref4,
|
|
2353
|
+
props = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
2354
|
+
const dataNode = props.dataContext.dataNode;
|
|
2355
|
+
const field = dataNode.schema.field;
|
|
2356
|
+
const className = rendererClass(styleClass, definition.styleClass);
|
|
2357
|
+
const displayOnly = !!formOptions.displayOnly;
|
|
2358
|
+
const required = !!definition.required && !displayOnly;
|
|
2359
|
+
const fieldOptions = schemaInterface.getDataOptions(dataNode);
|
|
2360
|
+
const _allowed = (_allowedOptions$value = allowedOptions == null ? void 0 : allowedOptions.value) != null ? _allowedOptions$value : [];
|
|
2361
|
+
const allowed = Array.isArray(_allowed) ? _allowed : [_allowed];
|
|
2362
|
+
return _extends({
|
|
2363
|
+
dataNode,
|
|
2364
|
+
definition,
|
|
2365
|
+
control,
|
|
2366
|
+
field,
|
|
2367
|
+
id: "c" + control.uniqueId,
|
|
2368
|
+
options: allowed.length > 0 ? allowed.map(x => {
|
|
2369
|
+
var _fieldOptions$find;
|
|
2370
|
+
return typeof x === "object" ? x : (_fieldOptions$find = fieldOptions == null ? void 0 : fieldOptions.find(y => y.value == x)) != null ? _fieldOptions$find : {
|
|
2371
|
+
name: x.toString(),
|
|
2372
|
+
value: x
|
|
2373
|
+
};
|
|
2374
|
+
}).filter(x => x != null) : fieldOptions,
|
|
2375
|
+
readonly: !!formOptions.readonly,
|
|
2376
|
+
displayOnly,
|
|
2377
|
+
renderOptions: (_definition$renderOpt2 = definition.renderOptions) != null ? _definition$renderOpt2 : {
|
|
2378
|
+
type: "Standard"
|
|
2379
|
+
},
|
|
2380
|
+
required,
|
|
2381
|
+
hidden: !!formOptions.hidden,
|
|
2382
|
+
className,
|
|
2383
|
+
style
|
|
2384
|
+
}, props);
|
|
2385
|
+
}
|
|
2386
|
+
function renderControlLayout(props) {
|
|
2387
|
+
const {
|
|
2388
|
+
definition: c,
|
|
2389
|
+
renderer,
|
|
2390
|
+
renderChild,
|
|
2391
|
+
control,
|
|
2392
|
+
dataContext,
|
|
2393
|
+
createDataProps: dataProps,
|
|
2394
|
+
displayControl,
|
|
2395
|
+
style,
|
|
2396
|
+
labelText,
|
|
2397
|
+
useChildVisibility,
|
|
2398
|
+
designMode,
|
|
2399
|
+
customDisplay,
|
|
2400
|
+
useEvalExpression,
|
|
2401
|
+
labelClass,
|
|
2402
|
+
styleClass,
|
|
2403
|
+
formNode
|
|
2404
|
+
} = props;
|
|
2405
|
+
if (isDataControl(c)) {
|
|
2406
|
+
return renderData(c);
|
|
2407
|
+
}
|
|
2408
|
+
if (isGroupControl(c)) {
|
|
2409
|
+
var _c$groupOptions2, _labelText$value, _c$groupOptions3;
|
|
2410
|
+
if (c.compoundField) {
|
|
2411
|
+
var _c$groupOptions;
|
|
2412
|
+
return renderData(dataControl(c.compoundField, c.title, {
|
|
2413
|
+
children: c.children,
|
|
2414
|
+
hideTitle: (_c$groupOptions = c.groupOptions) == null ? void 0 : _c$groupOptions.hideTitle
|
|
2415
|
+
}));
|
|
2416
|
+
}
|
|
2417
|
+
return {
|
|
2418
|
+
processLayout: renderer.renderGroup({
|
|
2419
|
+
formNode,
|
|
2420
|
+
definition: c,
|
|
2421
|
+
renderChild,
|
|
2422
|
+
useEvalExpression,
|
|
2423
|
+
dataContext,
|
|
2424
|
+
renderOptions: (_c$groupOptions2 = c.groupOptions) != null ? _c$groupOptions2 : {
|
|
2425
|
+
type: "Standard"
|
|
2426
|
+
},
|
|
2427
|
+
className: rendererClass(styleClass, c.styleClass),
|
|
2428
|
+
useChildVisibility,
|
|
2429
|
+
style,
|
|
2430
|
+
designMode
|
|
2431
|
+
}),
|
|
2432
|
+
label: {
|
|
2433
|
+
label: (_labelText$value = labelText == null ? void 0 : labelText.value) != null ? _labelText$value : c.title,
|
|
2434
|
+
className: rendererClass(labelClass, c.labelClass),
|
|
2435
|
+
type: LabelType.Group,
|
|
2436
|
+
hide: (_c$groupOptions3 = c.groupOptions) == null ? void 0 : _c$groupOptions3.hideTitle
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
if (isActionControl(c)) {
|
|
2441
|
+
var _props$actionDataCont, _props$actionDataCont2, _ref5, _labelText$value2, _props$actionOnClick;
|
|
2442
|
+
const actionData = (_props$actionDataCont = (_props$actionDataCont2 = props.actionDataControl) == null ? void 0 : _props$actionDataCont2.value) != null ? _props$actionDataCont : c.actionData;
|
|
2443
|
+
return {
|
|
2444
|
+
children: renderer.renderAction({
|
|
2445
|
+
actionText: (_ref5 = (_labelText$value2 = labelText == null ? void 0 : labelText.value) != null ? _labelText$value2 : c.title) != null ? _ref5 : c.actionId,
|
|
2446
|
+
actionId: c.actionId,
|
|
2447
|
+
actionData,
|
|
2448
|
+
onClick: (_props$actionOnClick = props.actionOnClick == null ? void 0 : props.actionOnClick(c.actionId, actionData, dataContext)) != null ? _props$actionOnClick : () => {},
|
|
2449
|
+
className: rendererClass(styleClass, c.styleClass),
|
|
2450
|
+
style
|
|
2451
|
+
})
|
|
2452
|
+
};
|
|
2453
|
+
}
|
|
2454
|
+
if (isDisplayControl(c)) {
|
|
2455
|
+
var _c$displayData;
|
|
2456
|
+
const data = (_c$displayData = c.displayData) != null ? _c$displayData : {};
|
|
2457
|
+
const displayProps = {
|
|
2458
|
+
data,
|
|
2459
|
+
className: rendererClass(styleClass, c.styleClass),
|
|
2460
|
+
style,
|
|
2461
|
+
display: displayControl,
|
|
2462
|
+
dataContext
|
|
2463
|
+
};
|
|
2464
|
+
if (data.type === DisplayDataType.Custom && customDisplay) {
|
|
2465
|
+
return {
|
|
2466
|
+
children: customDisplay(data.customId, displayProps)
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
return {
|
|
2470
|
+
children: renderer.renderDisplay(displayProps)
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
return {};
|
|
2474
|
+
function renderData(c) {
|
|
2475
|
+
var _labelText$value3, _c$children$length, _c$children;
|
|
2476
|
+
if (!control) return {
|
|
2477
|
+
children: "No control for: " + c.field
|
|
2478
|
+
};
|
|
2479
|
+
const rendererProps = dataProps(props);
|
|
2480
|
+
const label = !c.hideTitle ? controlTitle((_labelText$value3 = labelText == null ? void 0 : labelText.value) != null ? _labelText$value3 : c.title, props.dataContext.dataNode.schema.field) : undefined;
|
|
2481
|
+
return {
|
|
2482
|
+
processLayout: renderer.renderData(rendererProps),
|
|
2483
|
+
label: {
|
|
2484
|
+
type: ((_c$children$length = (_c$children = c.children) == null ? void 0 : _c$children.length) != null ? _c$children$length : 0) > 0 ? LabelType.Group : LabelType.Control,
|
|
2485
|
+
label,
|
|
2486
|
+
forId: rendererProps.id,
|
|
2487
|
+
required: c.required && !props.formOptions.displayOnly,
|
|
2488
|
+
hide: c.hideTitle,
|
|
2489
|
+
className: rendererClass(labelClass, c.labelClass)
|
|
2490
|
+
},
|
|
2491
|
+
errorControl: control
|
|
2492
|
+
};
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
function appendMarkup(k, markup) {
|
|
2496
|
+
return layout => layout[k] = React.createElement(React.Fragment, null, layout[k], markup);
|
|
2497
|
+
}
|
|
2498
|
+
function wrapMarkup(k, wrap) {
|
|
2499
|
+
return layout => layout[k] = wrap(layout[k]);
|
|
2500
|
+
}
|
|
2501
|
+
function layoutKeyForPlacement(pos) {
|
|
2502
|
+
switch (pos) {
|
|
2503
|
+
case AdornmentPlacement.ControlEnd:
|
|
2504
|
+
return "controlEnd";
|
|
2505
|
+
case AdornmentPlacement.ControlStart:
|
|
2506
|
+
return "controlStart";
|
|
2507
|
+
case AdornmentPlacement.LabelStart:
|
|
2508
|
+
return "labelStart";
|
|
2509
|
+
case AdornmentPlacement.LabelEnd:
|
|
2510
|
+
return "labelEnd";
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
function wrapLayout(wrap) {
|
|
2514
|
+
return rl => {
|
|
2515
|
+
const orig = rl.wrapLayout;
|
|
2516
|
+
rl.wrapLayout = x => wrap(orig(x));
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
function appendMarkupAt(pos, markup) {
|
|
2520
|
+
return appendMarkup(layoutKeyForPlacement(pos), markup);
|
|
2521
|
+
}
|
|
2522
|
+
function wrapMarkupAt(pos, wrap) {
|
|
2523
|
+
return wrapMarkup(layoutKeyForPlacement(pos), wrap);
|
|
2524
|
+
}
|
|
2525
|
+
function renderLayoutParts(props, renderer) {
|
|
2526
|
+
var _props$processLayout;
|
|
2527
|
+
const {
|
|
2528
|
+
className,
|
|
2529
|
+
children,
|
|
2530
|
+
style,
|
|
2531
|
+
errorControl,
|
|
2532
|
+
label,
|
|
2533
|
+
adornments
|
|
2534
|
+
} = (_props$processLayout = props.processLayout == null ? void 0 : props.processLayout(props)) != null ? _props$processLayout : props;
|
|
2535
|
+
const layout = {
|
|
2536
|
+
children,
|
|
2537
|
+
errorControl,
|
|
2538
|
+
style,
|
|
2539
|
+
className: className,
|
|
2540
|
+
wrapLayout: x => x
|
|
2541
|
+
};
|
|
2542
|
+
(adornments != null ? adornments : []).sort((a, b) => a.priority - b.priority).forEach(x => x.apply(layout));
|
|
2543
|
+
layout.label = label && !label.hide ? renderer.renderLabel(label, layout.labelStart, layout.labelEnd) : undefined;
|
|
2544
|
+
return layout;
|
|
2545
|
+
}
|
|
2546
|
+
function controlTitle(title, field) {
|
|
2547
|
+
return title ? title : fieldDisplayName(field);
|
|
2548
|
+
}
|
|
2549
|
+
function getLengthRestrictions(definition) {
|
|
2550
|
+
var _definition$validator;
|
|
2551
|
+
const lengthVal = (_definition$validator = definition.validators) == null ? void 0 : _definition$validator.find(x => x.type === ValidatorType.Length);
|
|
2552
|
+
return {
|
|
2553
|
+
min: lengthVal == null ? void 0 : lengthVal.min,
|
|
2554
|
+
max: lengthVal == null ? void 0 : lengthVal.max
|
|
2555
|
+
};
|
|
2556
|
+
}
|
|
2557
|
+
function createArrayActions(control, field, options) {
|
|
2558
|
+
var _field$displayName;
|
|
2559
|
+
const noun = (_field$displayName = field.displayName) != null ? _field$displayName : field.field;
|
|
2560
|
+
const {
|
|
2561
|
+
addText,
|
|
2562
|
+
noAdd,
|
|
2563
|
+
removeText,
|
|
2564
|
+
noRemove,
|
|
2565
|
+
removeActionId,
|
|
2566
|
+
addActionId,
|
|
2567
|
+
editActionId,
|
|
2568
|
+
editText,
|
|
2569
|
+
disabled,
|
|
2570
|
+
readonly,
|
|
2571
|
+
designMode,
|
|
2572
|
+
editExternal
|
|
2573
|
+
} = options != null ? options : {};
|
|
2574
|
+
return {
|
|
2575
|
+
arrayControl: control,
|
|
2576
|
+
addAction: !readonly && !noAdd ? makeAdd(() => {
|
|
2577
|
+
if (!designMode) {
|
|
2578
|
+
const newValue = elementValueForField(field);
|
|
2579
|
+
if (editExternal) {
|
|
2580
|
+
const editData = getExternalEditData(control);
|
|
2581
|
+
editData.value = {
|
|
2582
|
+
data: [elementValueForField(field)],
|
|
2583
|
+
actions: [makeCancel(), {
|
|
2584
|
+
action: makeAdd(() => {
|
|
2585
|
+
const newValue = editData.fields.data.value[0];
|
|
2586
|
+
addElement(control, newValue);
|
|
2587
|
+
editData.value = undefined;
|
|
2588
|
+
})
|
|
2589
|
+
}]
|
|
2590
|
+
};
|
|
2591
|
+
} else {
|
|
2592
|
+
addElement(control, newValue);
|
|
2593
|
+
}
|
|
2594
|
+
}
|
|
2595
|
+
}) : undefined,
|
|
2596
|
+
editAction: editExternal ? i => ({
|
|
2597
|
+
actionId: editActionId ? editActionId : "edit",
|
|
2598
|
+
actionText: editText ? editText : "Edit",
|
|
2599
|
+
onClick: () => {
|
|
2600
|
+
if (!designMode) {
|
|
2601
|
+
const editData = getExternalEditData(control);
|
|
2602
|
+
const elementToEdit = control.as().elements[i];
|
|
2603
|
+
editData.value = {
|
|
2604
|
+
data: [elementToEdit.current.value],
|
|
2605
|
+
actions: [makeCancel(), {
|
|
2606
|
+
action: createAction("apply", () => {
|
|
2607
|
+
elementToEdit.value = editData.fields.data.value[0];
|
|
2608
|
+
editData.value = undefined;
|
|
2609
|
+
}, "Apply")
|
|
2610
|
+
}]
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
}) : undefined,
|
|
2615
|
+
removeAction: !readonly && !noRemove ? i => ({
|
|
2616
|
+
actionId: removeActionId ? removeActionId : "remove",
|
|
2617
|
+
actionText: removeText ? removeText : "Remove",
|
|
2618
|
+
onClick: () => {
|
|
2619
|
+
if (!designMode) {
|
|
2620
|
+
removeElement(control, i);
|
|
2621
|
+
}
|
|
2622
|
+
},
|
|
2623
|
+
disabled
|
|
2624
|
+
}) : undefined
|
|
2625
|
+
};
|
|
2626
|
+
function makeAdd(onClick) {
|
|
2627
|
+
return createAction(addActionId ? addActionId : "add", onClick, addText ? addText : "Add " + noun, {
|
|
2628
|
+
disabled
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
function makeCancel() {
|
|
2632
|
+
return {
|
|
2633
|
+
dontValidate: true,
|
|
2634
|
+
action: {
|
|
2635
|
+
actionId: "cancel",
|
|
2636
|
+
actionText: "Cancel",
|
|
2637
|
+
onClick: () => {
|
|
2638
|
+
getExternalEditData(control).value = undefined;
|
|
2639
|
+
},
|
|
2640
|
+
disabled
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
function applyArrayLengthRestrictions({
|
|
2646
|
+
arrayControl,
|
|
2647
|
+
min,
|
|
2648
|
+
max,
|
|
2649
|
+
editAction,
|
|
2650
|
+
addAction: aa,
|
|
2651
|
+
removeAction: ra,
|
|
2652
|
+
required
|
|
2653
|
+
}, disable) {
|
|
2654
|
+
var _arrayControl$element, _arrayControl$element2;
|
|
2655
|
+
const [removeAllowed, addAllowed] = applyLengthRestrictions((_arrayControl$element = (_arrayControl$element2 = arrayControl.elements) == null ? void 0 : _arrayControl$element2.length) != null ? _arrayControl$element : 0, min == null && required ? 1 : min, max, true, true);
|
|
2656
|
+
return {
|
|
2657
|
+
addAction: disable || addAllowed ? aa : undefined,
|
|
2658
|
+
removeAction: disable || removeAllowed ? ra : undefined,
|
|
2659
|
+
removeDisabled: !removeAllowed,
|
|
2660
|
+
addDisabled: !addAllowed,
|
|
2661
|
+
editAction
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
function fieldOptionAdornment(p) {
|
|
2665
|
+
return (o, i, selected) => React.createElement(RenderArrayElements, {
|
|
2666
|
+
array: p.formNode.getChildNodes()
|
|
2667
|
+
}, (cd, i) => p.renderChild(i, cd, {
|
|
2668
|
+
parentDataNode: p.dataContext.parentNode,
|
|
2669
|
+
formData: {
|
|
2670
|
+
option: o,
|
|
2671
|
+
optionSelected: selected
|
|
2672
|
+
}
|
|
2673
|
+
}));
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
function isIconAdornment(a) {
|
|
2677
|
+
return a.type === ControlAdornmentType.Icon;
|
|
2678
|
+
}
|
|
2679
|
+
function isAccordionAdornment(a) {
|
|
2680
|
+
return a.type === ControlAdornmentType.Accordion;
|
|
2681
|
+
}
|
|
2682
|
+
function isSetFieldAdornment(a) {
|
|
2683
|
+
return a.type === ControlAdornmentType.SetField;
|
|
2684
|
+
}
|
|
2685
|
+
function isOptionalAdornment(a) {
|
|
2686
|
+
return a.type === ControlAdornmentType.Optional;
|
|
2687
|
+
}
|
|
2688
|
+
function createLayoutRenderer(render, options) {
|
|
2689
|
+
return _extends({
|
|
2690
|
+
type: "layout",
|
|
2691
|
+
render
|
|
2692
|
+
}, options);
|
|
2693
|
+
}
|
|
2694
|
+
function createActionRenderer(actionId, render, options) {
|
|
2695
|
+
return _extends({
|
|
2696
|
+
type: "action",
|
|
2697
|
+
actionType: actionId,
|
|
2698
|
+
render
|
|
2699
|
+
}, options);
|
|
2700
|
+
}
|
|
2701
|
+
function createArrayRenderer(render, options) {
|
|
2702
|
+
return _extends({
|
|
2703
|
+
type: "array",
|
|
2704
|
+
render
|
|
2705
|
+
}, options);
|
|
2706
|
+
}
|
|
2707
|
+
function createDataRenderer(render, options) {
|
|
2708
|
+
return _extends({
|
|
2709
|
+
type: "data",
|
|
2710
|
+
render
|
|
2711
|
+
}, options);
|
|
2712
|
+
}
|
|
2713
|
+
function createGroupRenderer(render, options) {
|
|
2714
|
+
return _extends({
|
|
2715
|
+
type: "group",
|
|
2716
|
+
render
|
|
2717
|
+
}, options);
|
|
2718
|
+
}
|
|
2719
|
+
function createDisplayRenderer(render, options) {
|
|
2720
|
+
return _extends({
|
|
2721
|
+
type: "display",
|
|
2722
|
+
render
|
|
2723
|
+
}, options);
|
|
2724
|
+
}
|
|
2725
|
+
function createLabelRenderer(render, options) {
|
|
2726
|
+
return _extends({
|
|
2727
|
+
type: "label",
|
|
2728
|
+
render
|
|
2729
|
+
}, options);
|
|
2730
|
+
}
|
|
2731
|
+
function createVisibilityRenderer(render, options) {
|
|
2732
|
+
return _extends({
|
|
2733
|
+
type: "visibility",
|
|
2734
|
+
render
|
|
2735
|
+
}, options);
|
|
2736
|
+
}
|
|
2737
|
+
function createAdornmentRenderer(render, options) {
|
|
2738
|
+
return _extends({
|
|
2739
|
+
type: "adornment"
|
|
2740
|
+
}, options, {
|
|
2741
|
+
render
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
function createFormRenderer(customRenderers = [], defaultRenderers) {
|
|
2746
|
+
var _customRenderers$find;
|
|
2747
|
+
const dataRegistrations = customRenderers.filter(isDataRegistration);
|
|
2748
|
+
const groupRegistrations = customRenderers.filter(isGroupRegistration);
|
|
2749
|
+
const adornmentRegistrations = customRenderers.filter(isAdornmentRegistration);
|
|
2750
|
+
const displayRegistrations = customRenderers.filter(isDisplayRegistration);
|
|
2751
|
+
const labelRenderers = customRenderers.filter(isLabelRegistration);
|
|
2752
|
+
const arrayRenderers = customRenderers.filter(isArrayRegistration);
|
|
2753
|
+
const actionRenderers = customRenderers.filter(isActionRegistration);
|
|
2754
|
+
const layoutRenderers = customRenderers.filter(isLayoutRegistration);
|
|
2755
|
+
const visibilityRenderer = (_customRenderers$find = customRenderers.find(isVisibilityRegistration)) != null ? _customRenderers$find : defaultRenderers.visibility;
|
|
2756
|
+
const formRenderers = {
|
|
2757
|
+
renderAction,
|
|
2758
|
+
renderData,
|
|
2759
|
+
renderGroup,
|
|
2760
|
+
renderDisplay,
|
|
2761
|
+
renderLabel,
|
|
2762
|
+
renderArray,
|
|
2763
|
+
renderAdornment,
|
|
2764
|
+
renderLayout,
|
|
2765
|
+
renderVisibility: visibilityRenderer.render,
|
|
2766
|
+
renderLabelText
|
|
2767
|
+
};
|
|
2768
|
+
function renderLabelText(label) {
|
|
2769
|
+
return renderLabel({
|
|
2770
|
+
label,
|
|
2771
|
+
type: LabelType.Text
|
|
2772
|
+
}, undefined, undefined);
|
|
2773
|
+
}
|
|
2774
|
+
function renderLayout(props) {
|
|
2775
|
+
var _layoutRenderers$find;
|
|
2776
|
+
const renderer = (_layoutRenderers$find = layoutRenderers.find(x => !x.match || x.match(props))) != null ? _layoutRenderers$find : defaultRenderers.renderLayout;
|
|
2777
|
+
return renderer.render(props, formRenderers);
|
|
2778
|
+
}
|
|
2779
|
+
function renderAdornment(props) {
|
|
2780
|
+
var _adornmentRegistratio;
|
|
2781
|
+
const renderer = (_adornmentRegistratio = adornmentRegistrations.find(x => isOneOf(x.adornmentType, props.adornment.type))) != null ? _adornmentRegistratio : defaultRenderers.adornment;
|
|
2782
|
+
return renderer.render(props, formRenderers);
|
|
2783
|
+
}
|
|
2784
|
+
function renderArray(props) {
|
|
2785
|
+
var _arrayRenderers$;
|
|
2786
|
+
return ((_arrayRenderers$ = arrayRenderers[0]) != null ? _arrayRenderers$ : defaultRenderers.array).render(props, formRenderers);
|
|
2787
|
+
}
|
|
2788
|
+
function renderLabel(props, labelStart, labelEnd) {
|
|
2789
|
+
var _labelRenderers$find;
|
|
2790
|
+
const renderer = (_labelRenderers$find = labelRenderers.find(x => isOneOf(x.labelType, props.type))) != null ? _labelRenderers$find : defaultRenderers.label;
|
|
2791
|
+
return renderer.render(props, labelStart, labelEnd, formRenderers);
|
|
2792
|
+
}
|
|
2793
|
+
function renderData(props) {
|
|
2794
|
+
var _dataRegistrations$fi;
|
|
2795
|
+
const {
|
|
2796
|
+
renderOptions,
|
|
2797
|
+
field
|
|
2798
|
+
} = props;
|
|
2799
|
+
const options = hasOptions(props);
|
|
2800
|
+
const renderType = renderOptions.type;
|
|
2801
|
+
const renderer = (_dataRegistrations$fi = dataRegistrations.find(matchesRenderer)) != null ? _dataRegistrations$fi : defaultRenderers.data;
|
|
2802
|
+
const result = renderer.render(props, formRenderers);
|
|
2803
|
+
if (typeof result === "function") return result;
|
|
2804
|
+
return l => _extends({}, l, {
|
|
2805
|
+
children: result
|
|
2806
|
+
});
|
|
2807
|
+
function matchesRenderer(x) {
|
|
2808
|
+
var _x$collection, _field$collection, _x$options;
|
|
2809
|
+
const matchCollection = ((_x$collection = x.collection) != null ? _x$collection : false) === (props.elementIndex == null && ((_field$collection = field.collection) != null ? _field$collection : false));
|
|
2810
|
+
const matchSchemaType = x.schemaType && renderType == DataRenderType.Standard && isOneOf(x.schemaType, field.type);
|
|
2811
|
+
const matchRenderType = !x.renderType || isOneOf(x.renderType, renderType);
|
|
2812
|
+
return matchCollection && ((_x$options = x.options) != null ? _x$options : false) === options && (matchSchemaType || matchRenderType) && (!x.match || x.match(props, renderOptions));
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
function renderGroup(props) {
|
|
2816
|
+
var _groupRegistrations$f;
|
|
2817
|
+
const renderType = props.renderOptions.type;
|
|
2818
|
+
const renderer = (_groupRegistrations$f = groupRegistrations.find(x => isOneOf(x.renderType, renderType))) != null ? _groupRegistrations$f : defaultRenderers.group;
|
|
2819
|
+
const result = renderer.render(props, formRenderers);
|
|
2820
|
+
if (typeof result === "function") return result;
|
|
2821
|
+
return l => _extends({}, l, {
|
|
2822
|
+
children: result
|
|
2823
|
+
});
|
|
2824
|
+
}
|
|
2825
|
+
function renderAction(props) {
|
|
2826
|
+
var _actionRenderers$find;
|
|
2827
|
+
const renderer = (_actionRenderers$find = actionRenderers.find(x => isOneOf(x.actionType, props.actionId))) != null ? _actionRenderers$find : defaultRenderers.action;
|
|
2828
|
+
return renderer.render(props, formRenderers);
|
|
2829
|
+
}
|
|
2830
|
+
function renderDisplay(props) {
|
|
2831
|
+
var _displayRegistrations;
|
|
2832
|
+
const renderType = props.data.type;
|
|
2833
|
+
const renderer = (_displayRegistrations = displayRegistrations.find(x => isOneOf(x.renderType, renderType))) != null ? _displayRegistrations : defaultRenderers.display;
|
|
2834
|
+
return renderer.render(props, formRenderers);
|
|
2835
|
+
}
|
|
2836
|
+
return formRenderers;
|
|
2837
|
+
}
|
|
2838
|
+
function isOneOf(x, v) {
|
|
2839
|
+
return x == null ? true : Array.isArray(x) ? x.includes(v) : v === x;
|
|
2840
|
+
}
|
|
2841
|
+
function isAdornmentRegistration(x) {
|
|
2842
|
+
return x.type === "adornment";
|
|
2843
|
+
}
|
|
2844
|
+
function isDataRegistration(x) {
|
|
2845
|
+
return x.type === "data";
|
|
2846
|
+
}
|
|
2847
|
+
function isGroupRegistration(x) {
|
|
2848
|
+
return x.type === "group";
|
|
2849
|
+
}
|
|
2850
|
+
function isLabelRegistration(x) {
|
|
2851
|
+
return x.type === "label";
|
|
2852
|
+
}
|
|
2853
|
+
function isLayoutRegistration(x) {
|
|
2854
|
+
return x.type === "layout";
|
|
2855
|
+
}
|
|
2856
|
+
function isVisibilityRegistration(x) {
|
|
2857
|
+
return x.type === "visibility";
|
|
2858
|
+
}
|
|
2859
|
+
function isActionRegistration(x) {
|
|
2860
|
+
return x.type === "action";
|
|
2861
|
+
}
|
|
2862
|
+
function isDisplayRegistration(x) {
|
|
2863
|
+
return x.type === "display";
|
|
2864
|
+
}
|
|
2865
|
+
function isArrayRegistration(x) {
|
|
2866
|
+
return x.type === "array";
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
export { AdornmentPlacement, AppendAdornmentPriority, ControlAdornmentType, ControlDefinitionType, ControlRenderer, DataRenderType, DateComparison, DefaultSchemaInterface, DisplayDataType, DynamicPropertyType, ExpressionType, FieldType, FormNode, GroupRenderType, LabelType, NewControlRenderer, SchemaTags, SyncTextType, ValidationMessageType, ValidatorType, WrapAdornmentPriority, accordionOptions, actionControl, actionHandlers, addFieldOption, addMissingControls, addMissingControlsForSchema, adornmentOptions, appendMarkup, appendMarkupAt, applyArrayLengthRestrictions, applyDefaultForField, applyDefaultValues, applyExtensionToSchema, applyExtensionsToSchema, applyLengthRestrictions, applyValues, autocompleteOptions, boolField, buildSchema, checkListOptions, cleanDataForSchema, coerceToString, collectDifferences, compoundControl, compoundField, controlTitle, createAction, createActionRenderer, createAdornmentRenderer, createArrayActions, createArrayRenderer, createDataRenderer, createDisplayRenderer, createFormLookup, createFormRenderer, createGroupRenderer, createLabelRenderer, createLayoutRenderer, createSchemaLookup, createVisibilityRenderer, dataControl, dateField, dateTimeField, dateValidatorOptions, defaultCompoundField, defaultControlForField, defaultDataProps, defaultEvalHooks, defaultScalarField, defaultSchemaInterface, defaultUseEvalExpressionHook, defaultValueForField, defaultValueForFields, displayOnlyOptions, doubleField, dynamicDefaultValue, dynamicDisabled, dynamicReadonly, dynamicVisibility, elementValueForField, emptyGroupDefinition, fieldDisplayName, fieldEqExpr, fieldExpr, fieldHasTag, fieldOptionAdornment, fieldPathForDefinition, findChildDefinition, findCompoundField, findControlsForCompound, findField, findFieldPath, findNonDataGroups, findScalarField, getAllReferencedClasses, getAllValues, getDiffObject, getDisplayOnlyOptions, getExternalEditData, getGroupClassOverrides, getGroupRendererOptions, getIsEditing, getJsonPath, getLastDefinedValue, getLengthRestrictions, getNullToggler, getOverrideClass, getRootDataNode, getSchemaFieldList, getSchemaNodePath, getSchemaPath, getTagParam, groupedControl, hasOptions, hideDisplayOnly, htmlDisplayControl, intField, isAccordionAdornment, isActionControl, isArrayRenderer, isAutoCompleteClasses, isAutocompleteRenderer, isCheckEntryClasses, isCompoundField, isCompoundNode, isControlDisabled, isControlDisplayOnly, isControlReadonly, isDataControl, isDataGroupRenderer, isDateTimeRenderer, isDisplayControl, isDisplayOnlyRenderer, isFlexRenderer, isGridRenderer, isGroupControl, isIconAdornment, isOptionalAdornment, isScalarField, isSelectChildRenderer, isSetFieldAdornment, isTabsRenderer, isTextfieldRenderer, jsonPathString, jsonataExpr, jsonataOptions, jsonataValidatorOptions, layoutKeyForPlacement, legacyFormNode, lengthValidatorOptions, lookupDataNode, makeCompoundField, makeEvalExpressionHook, makeHook, makeHookDepString, makeParamTag, makeScalarField, makeSchemaDataNode, matchesType, mergeField, mergeFields, mergeObjects, nodeForControl, radioButtonOptions, relativePath, renderControlLayout, renderLayoutParts, renderOptionsFor, rendererClass, resolveSchemas, rootSchemaNode, schemaDataForFieldPath, schemaDataForFieldRef, schemaForFieldPath, schemaForFieldRef, stringField, stringOptionsField, textDisplayControl, textfieldOptions, timeField, toDepString, traverseData, traverseParents, traverseSchemaPath, useControlDefinitionForSchema, useControlRenderer, useControlRendererComponent, useDateValidator, useDynamicHooks, useEvalActionHook, useEvalAllowedOptionsHook, useEvalDefaultValueHook, useEvalDisabledHook, useEvalDisplayHook, useEvalDynamicBoolHook, useEvalDynamicHook, useEvalLabelText, useEvalReadonlyHook, useEvalStyleHook, useEvalVisibilityHook, useJsonataExpression, useJsonataValidator, useLengthValidator, useMakeValidationHook, useUpdatedRef, useUuidExpression, validationVisitor, validatorOptions, visitControlData, visitControlDataArray, visitControlDefinition, visitFormData, visitFormDataInContext, withScalarOptions, wrapLayout, wrapMarkup, wrapMarkupAt };
|
|
2
2870
|
//# sourceMappingURL=index.js.map
|