@golemui/gui-shared 1.0.0-rc.2 → 1.0.0-rc.4
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/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/index.js +1 -1
- package/index.umd.cjs +1 -1
- package/internals.js +244 -230
- package/internals.umd.cjs +1 -1
- package/lib/dx/core/dxBase.types.d.ts +24 -4
- package/lib/dx/core/eventWiring.service.d.ts +13 -0
- package/lib/dx/shortcuts/custom-action/customAction.domain.d.ts +1 -1
- package/package.json +4 -3
- package/{register-BCL1xvhN.js → register-BxVKv9Qh.js} +274 -248
- package/register-dBzdQbWZ.cjs +1 -0
- package/register-CjTULX-4.cjs +0 -1
package/internals.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./register-CjTULX-4.cjs");require("@golemui/core");require("@golemui/gui-validators");function E(a,...e){return e.map(t=>({...t,targetState:a}))}function v(a,...e){return{kind:"aggregated",matcher:t=>t.tags?.includes(a)??!1,children:e}}const B={INPUTS:new Set(["INPUTS","TEXTAREA","PASSWORD","SELECT","DROPDOWN","RADIOGROUP","CHECKBOX","CALENDAR","DATE_INPUT","DATE_PICKER","RANGE_CALENDAR","RANGE_DATE_INPUT","RANGE_DATE_PICKER","CURRENCY","MARKDOWN","LIST","CUSTOM_INPUT","REPEATER","TAGS"]),ACTIONS:new Set(["ACTIONS","CUSTOM_ACTION"]),DISPLAYS:new Set(["DISPLAYS","ALERTS","MARKDOWN_TEXTS","CUSTOM_DISPLAY"]),LAYOUTS:new Set(["LAYOUTS","TABS","ACCORDION","CUSTOM_LAYOUT"])};function P(a,e){const t=B[a];return t?t.has(e):a===e}class L{resolve(e,t){const i=[];for(const r of t)r.kind==="aggregated"?this.collectFromAggregated(r,e,i):this.collectFromLeaf(r,e,i);const n=this.rollUpSensibleDefaults(i);return{leafSelectors:i,sensibleDefaults:n}}collectFromAggregated(e,t,i){if(e.matcher(t))for(const n of e.children)this.collectFromLeaf(n,t,i)}collectFromLeaf(e,t,i){P(e.selectorType,t.itemType??"")&&e.matcher(t)&&i.push(e)}rollUpSensibleDefaults(e){const t=new Map,i=(r,o)=>{const l=t.get(r)??[];l.push(o),t.set(r,l)};for(const r of e){const o=B[r.selectorType];if(o)for(const l of o)i(l,r);else i(r.selectorType,r)}const n={};for(const[r,o]of t)s.hasItemTypeHandler(r)&&(n[r]=s.getItemTypeHandler(r).rollUpSensibleDefaults(o));return n}}const F=new L;class j{deepMerge(e,t){if(t==null)return e;if(e==null||typeof e!="object"||typeof t!="object"||Array.isArray(e)||Array.isArray(t))return t;const i={...e};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(typeof t[n]=="object"&&!Array.isArray(t[n])&&t[n]!==null&&typeof e[n]=="object"&&!Array.isArray(e[n])&&e[n]!==null?i[n]=this.deepMerge(e[n],t[n]):i[n]=t[n]);return i}}const N=new j;class W{constructor(e){this.objectUtils=e}merge(e,t,i){let n={},r=null;typeof e=="function"&&(r=e);const o=this.collectDecorators(i);for(const c of o){if(r!=null){r=this.composeRuntimeFunctions(r,c);continue}if(typeof c=="function"){const g=c({...n,...typeof e=="function"?{}:e});if(typeof g=="function"){r=this.createPromotedFunction(n,e,g,t,i);continue}n=this.objectUtils.deepMerge(n,g)}else n=this.objectUtils.deepMerge(n,c)}if(r!=null)return{kind:"dynamic",fn:this.wrapWithSensibleDefaults(r,n,t,i)};const l=this.objectUtils.deepMerge(e,n);return{kind:"static",def:this.applySensibleDefaults({...l},t,i)}}collectDecorators(e){const t=[];for(const i of e.leafSelectors){const n=i.config;n.override!=null&&t.push(n.override)}return t}applySensibleDefaults(e,t,i){if(!s.hasItemTypeHandler(t))return e;const n=i.sensibleDefaults[t]??{};return s.getItemTypeHandler(t).applySensibleDefaults(e,n)}createPromotedFunction(e,t,i,n,r){return o=>{const l=i(o);let u=this.objectUtils.deepMerge(e,l);return u=this.objectUtils.deepMerge(u,t),this.applySensibleDefaults(u,n,r)}}wrapWithSensibleDefaults(e,t,i,n){return r=>{let o=e(r);return Object.keys(t).length>0&&(o=this.objectUtils.deepMerge(t,o)),this.applySensibleDefaults(o,i,n)}}composeRuntimeFunctions(e,t){return typeof t=="function"?i=>{const n=e(i),r=t(n);return typeof r=="function"?r(i):this.objectUtils.deepMerge(r,n)}:i=>{const n=e(i);return this.objectUtils.deepMerge(n,t)}}}const z=new W(N);class G{mapToWidget(e,t){if(e.kind==="dynamic"){const i=e.fn;return(n=>{const r=i(n);return this.mapStaticDef(r,t)})}return this.mapStaticDef(e.def,t)}mapStaticDef(e,t){const i=s.getItemTypeHandler(t).mapToWidget(e);return this.applyBaseWidgetFields(i,e)}applyBaseWidgetFields(e,t){return t.size!=null&&(e.size=t.size),t.defaultValue!=null&&e.kind==="input"&&(e.defaultValue=t.defaultValue),t.on!=null&&(e.on=t.on),t.include!=null&&(e.include=t.include),t.exclude!=null&&(e.exclude=t.exclude),e}}const K=new G;class H{normalizeSelectors(e){const t=Array.isArray(e)?e:[e],i=[],n=[];for(const r of t)r.kind==="leaf"?n.push(r):i.push(r);return n.length>0&&i.unshift({kind:"aggregated",matcher:()=>!0,children:n}),i}extractFormConfig(){return{suppressAutomaticStack:!1}}}const V=new H,$={input:new Set(["disabled","readonly","label","validator","size"]),action:new Set(["disabled","label","size"]),layout:new Set(["size"]),display:new Set([])},D={onChange:"change",onLoad:"load",onFilter:"filter",onClick:"click"};class Y{extractFromMergeResult(e,t){const i={};for(const l of t){const u=l.targetState,c=l.config,g=c.override&&typeof c.override!="function"?c.override:c;i[u]={...i[u]||{},...g}}if(e.kind==="dynamic"){const l=e.fn;return{cleanedResult:{kind:"dynamic",fn:c=>{const g=l(c),{states:d,..._}=g;return _}},stateData:{stateOverrides:i}}}const{states:n,...r}=e.def,o={};for(const[l,u]of Object.entries(i))o[l]={...u};if(n)for(const[l,u]of Object.entries(n))o[l]={...o[l]||{},...u};return{cleanedResult:{kind:"static",def:r},stateData:{stateOverrides:o}}}applyToWidget(e,t,i,n){const{stateOverrides:r}=t;if(Object.keys(r).length===0)return e;const o={...e},l=e.kind,u=$[l]||new Set;e.props&&(o.props={...e.props}),e.on&&(o.on={...e.on});for(const[c,g]of Object.entries(r))for(const[d,_]of Object.entries(g))d==="visible"?this.applyVisibility(o,c,_):D[d]?this.applyStateEvent(o,c,d,_,i,n):u.has(d)?o[`${d}.${c}`]=_:(o.props||(o.props={}),o.props[`${d}.${c}`]=_);return o}hasStateData(e){return Object.keys(e.stateOverrides).length>0}applyVisibility(e,t,i){if(i){const n=e.include?.in||[];e.include={...e.include||{},in:[...n,t]}}else{const n=e.exclude?.from||[];e.exclude={...e.exclude||{},from:[...n,t]}}}applyStateEvent(e,t,i,n,r,o){const l=D[i];if(e.on||(e.on={}),typeof n=="function"){const u=o.next();r.set(u,n),e.on[`${l}.${t}`]=u}else typeof n=="string"&&(e.on[`${l}.${t}`]=n)}}const X=new Y;function q(){let a=0;return{next:()=>`event_${a++}`}}class J{constructor(e,t,i,n,r){this.resolver=e,this.merger=t,this.mapper=i,this.eventWiring=n,this.stateExpansion=r}walkAndMap(e,t,i){const n=new Map,r=q(),o={value:0},l=new Set;return{widgets:this.walkItems(e,t,n,i,r,o,l),eventRegistry:n}}walkItems(e,t,i,n,r,o,l){return e.flatMap(u=>{if(u.type!=="ITEMS")throw new Error("Unexpected gui shortcut type");return u.items.map(c=>this.processItem(c,u.itemType,u.tags,t,i,n,r,o,l))})}processItem(e,t,i,n,r,o,l,u,c){const g=t,d=s.getItemTypeHandler(t),_=d.parseEntry(e),m=this.buildBaseDef(_),k=this.buildDecoratorForMatching(m,g,i),h=this.resolver.resolve(k,n),x=h.leafSelectors.filter(p=>p.targetState!=null),O={leafSelectors:h.leafSelectors.filter(p=>p.targetState==null),sensibleDefaults:h.sensibleDefaults};let f=this.merger.merge(m,g,O);d.afterMerge&&(f=d.afterMerge(f,{eventRegistry:r,formConfig:o,eventIdGenerator:l})),f=this.eventWiring.wireInputLayoutEvents(f,r,l);const{cleanedResult:b,stateData:S}=this.stateExpansion.extractFromMergeResult(f,x);let y;if(d.buildCustomWidget){const p=this.buildCustomWidgetContext(_.children,n,r,o,l,u,c);y=this.buildCustomWidget(d,b,p)}else y=this.mapper.mapToWidget(b,g);if(typeof y!="function"){const p=y;p.uid||(p.path&&!c.has(p.path)?(p.uid=p.path,c.add(p.path)):p.uid=`dx_${u.value++}`)}if(this.stateExpansion.hasStateData(S))if(typeof y=="function"){const p=y;y=(w=>{const M=p(w);return this.stateExpansion.applyToWidget(M,S,r,l)})}else y=this.stateExpansion.applyToWidget(y,S,r,l);return y}buildCustomWidgetContext(e,t,i,n,r,o,l){return{children:e,mapStaticDef:(u,c)=>this.mapper.mapStaticDef(u,c),walkChildren:u=>this.walkItems(u,t,i,n,r,o,l)}}buildCustomWidget(e,t,i){return e.buildCustomWidget(t,i)}buildBaseDef(e){const t=e.baseDef;return typeof t=="function"?i=>{const r=t(i??{});return e.path!=null?{...r,path:e.path}:r}:e.path!=null?{...t,path:e.path}:t}buildDecoratorForMatching(e,t,i){if(typeof e=="function")return{itemType:t,tags:[...i]};const n=[...i,..."tags"in e&&e.tags?e.tags:[]],r="uid"in e?e.uid:void 0,o="type"in e?e.type:void 0;return{itemType:t,tags:n,uid:r,type:o}}}class Q{constructor(e,t){this.selectorNormalizer=e,this.walker=t}processDxFacade(e,t=[],i){const{defs:n,gslSelectors:r,formConfig:o}=this.prepareForm(e,t,i),{widgets:l,eventRegistry:u}=this.walker.walkAndMap(n,r,o),c=l[0];return this.buildResult({form:c},u,o)}prepareForm(e,t,i){const r=(Array.isArray(e)?[...e]:[e]).map(u=>typeof u=="function"?s._guiDisplay(u):u),o=this.selectorNormalizer.normalizeSelectors(t),l={...this.selectorNormalizer.extractFormConfig(),...i};if(!l.suppressAutomaticStack){const u={def:{uid:"#root",direction:"column",widgetName:"flex"},children:r};return{defs:[{type:"ITEMS",itemType:s.GuiItemTypes.LAYOUTS,items:[u],tags:[]}],gslSelectors:o,formConfig:l}}return{defs:r,gslSelectors:o,formConfig:l}}convertStateNames(e){const t={};for(const[i,n]of Object.entries(e))t[i.replace(/\$/g,":")]=n;return t}buildResult(e,t,i){i.states&&Object.keys(i.states).length>0&&(e={...e,states:this.convertStateNames(i.states)});const n={form:e};return t.size>0&&(n.events=r=>{const o=t.get(r.name);if(o){const l=c=>{if(c&&typeof c=="object"&&"path"in c&&!("type"in c)){const{path:g,...d}=c;for(const[_,m]of Object.entries(d))r.callback({type:"OVERRIDE_WIDGET_PROP",payload:{path:g,prop:_,value:m}})}else r.callback(c)},u={...r,callback:l,update:l};o(u)}}),i.dependencies&&(n.dependencies=i.dependencies),i.widgetLoaders&&(n.widgetLoaders=i.widgetLoaders),i.validateOn&&(n.validateOn=i.validateOn),i.itemRenderers&&(n.itemRenderers=i.itemRenderers),n}}const Z=new J(F,z,K,s.eventWiringService,X),C=new Q(V,Z);function R(a){return typeof a=="function"?!0:Array.isArray(a)?a.length===0||a.every(T):T(a)}function T(a){if(typeof a=="function")return!0;if(a===null||typeof a!="object")return!1;const e=a;return e.type==="ITEMS"&&typeof e.itemType=="string"}const I=Object.freeze({}),ee=Object.freeze({}),A=new WeakMap;function U(a,e){return a==null?e:typeof a=="object"?a:{}}function te(a,e,t){if(!R(a))return{formDef:a};const i=U(a,I),n=U(e,I),r=U(t,ee);let o=A.get(i);o||(o=new WeakMap,A.set(i,o));let l=o.get(n);l||(l=new WeakMap,o.set(n,l));const u=l.get(r);if(u)return u;const c=C.processDxFacade(a,e,t),g={formDef:c.form,formEvent:c.events,dependencies:c.dependencies,widgetLoaders:c.widgetLoaders,validateOn:c.validateOn,itemRenderers:c.itemRenderers};return l.set(r,g),g}class se{create(e){return{states:e.states,form:{uid:"gui-root-uid",type:"flex",kind:"layout",children:e.form}}}}function ne(){return new se}const ie=a=>a!==null&&typeof a=="object"&&Object.prototype.hasOwnProperty.call(a,"label")&&Object.prototype.hasOwnProperty.call(a,"value");function re(a,e){if(a!=null&&typeof a=="object"&&"__rid"in a)return a.__rid;const t=e();return Object.defineProperty(a,"__rid",{value:t,enumerable:!1,configurable:!1}),t}exports._gslAccordionByUid=s._gslAccordionByUid;exports._gslAccordions=s._gslAccordions;exports._gslActionByUid=s._gslActionByUid;exports._gslActions=s._gslActions;exports._gslAlertByUid=s._gslAlertByUid;exports._gslAlerts=s._gslAlerts;exports._gslBooleanInputs=s._gslBooleanInputs;exports._gslCalendarByUid=s._gslCalendarByUid;exports._gslCalendars=s._gslCalendars;exports._gslCheckboxByUid=s._gslCheckboxByUid;exports._gslCheckboxes=s._gslCheckboxes;exports._gslCurrencies=s._gslCurrencies;exports._gslCurrencyByUid=s._gslCurrencyByUid;exports._gslCustomActionByUid=s._gslCustomActionByUid;exports._gslCustomActions=s._gslCustomActions;exports._gslCustomDisplayByUid=s._gslCustomDisplayByUid;exports._gslCustomDisplays=s._gslCustomDisplays;exports._gslCustomInputByUid=s._gslCustomInputByUid;exports._gslCustomInputs=s._gslCustomInputs;exports._gslCustomLayoutByUid=s._gslCustomLayoutByUid;exports._gslCustomLayouts=s._gslCustomLayouts;exports._gslDateInputByUid=s._gslDateInputByUid;exports._gslDateInputs=s._gslDateInputs;exports._gslDatePickerByUid=s._gslDatePickerByUid;exports._gslDatePickers=s._gslDatePickers;exports._gslDisplayByUid=s._gslDisplayByUid;exports._gslDisplays=s._gslDisplays;exports._gslDropdownByUid=s._gslDropdownByUid;exports._gslDropdowns=s._gslDropdowns;exports._gslInputByUid=s._gslInputByUid;exports._gslInputs=s._gslInputs;exports._gslLayoutByUid=s._gslLayoutByUid;exports._gslLayouts=s._gslLayouts;exports._gslListByUid=s._gslListByUid;exports._gslLists=s._gslLists;exports._gslMarkdownByUid=s._gslMarkdownByUid;exports._gslMarkdownTextByUid=s._gslMarkdownTextByUid;exports._gslMarkdownTexts=s._gslMarkdownTexts;exports._gslMarkdowns=s._gslMarkdowns;exports._gslNumberInputs=s._gslNumberInputs;exports._gslPasswordByUid=s._gslPasswordByUid;exports._gslPasswords=s._gslPasswords;exports._gslRadiogroupByUid=s._gslRadiogroupByUid;exports._gslRadiogroups=s._gslRadiogroups;exports._gslRangeCalendarByUid=s._gslRangeCalendarByUid;exports._gslRangeCalendars=s._gslRangeCalendars;exports._gslRangeDateInputByUid=s._gslRangeDateInputByUid;exports._gslRangeDateInputs=s._gslRangeDateInputs;exports._gslRangeDatePickerByUid=s._gslRangeDatePickerByUid;exports._gslRangeDatePickers=s._gslRangeDatePickers;exports._gslRepeaterByUid=s._gslRepeaterByUid;exports._gslRepeaters=s._gslRepeaters;exports._gslSelectByUid=s._gslSelectByUid;exports._gslSelects=s._gslSelects;exports._gslTabs=s._gslTabs;exports._gslTabsByUid=s._gslTabsByUid;exports._gslTags=s._gslTags;exports._gslTagsByUid=s._gslTagsByUid;exports._gslTextInputs=s._gslTextInputs;exports._gslTextareaByUid=s._gslTextareaByUid;exports._gslTextareas=s._gslTextareas;exports._guiAccordion=s._guiAccordion;exports._guiAlert=s._guiAlert;exports._guiBooleanInput=s._guiBooleanInput;exports._guiButton=s._guiButton;exports._guiCalendar=s._guiCalendar;exports._guiCheckbox=s._guiCheckbox;exports._guiCurrency=s._guiCurrency;exports._guiCustomAction=s._guiCustomAction;exports._guiCustomDisplay=s._guiCustomDisplay;exports._guiCustomInput=s._guiCustomInput;exports._guiCustomLayout=s._guiCustomLayout;exports._guiDateInput=s._guiDateInput;exports._guiDatePicker=s._guiDatePicker;exports._guiDisplay=s._guiDisplay;exports._guiDropdown=s._guiDropdown;exports._guiFlex=s._guiFlex;exports._guiGrid=s._guiGrid;exports._guiHorizontalFlex=s._guiHorizontalFlex;exports._guiHorizontalGrid=s._guiHorizontalGrid;exports._guiList=s._guiList;exports._guiMarkdown=s._guiMarkdown;exports._guiMarkdownText=s._guiMarkdownText;exports._guiNumberInput=s._guiNumberInput;exports._guiPassword=s._guiPassword;exports._guiRadiogroup=s._guiRadiogroup;exports._guiRangeCalendar=s._guiRangeCalendar;exports._guiRangeDateInput=s._guiRangeDateInput;exports._guiRangeDatePicker=s._guiRangeDatePicker;exports._guiRepeater=s._guiRepeater;exports._guiSelect=s._guiSelect;exports._guiTabs=s._guiTabs;exports._guiTags=s._guiTags;exports._guiTextInput=s._guiTextInput;exports._guiTextarea=s._guiTextarea;exports._guiVerticalFlex=s._guiVerticalFlex;exports._guiVerticalGrid=s._guiVerticalGrid;exports.createGslSelector=s.createGslSelector;exports.defineShortcutType=s.defineShortcutType;exports.extractWidgetProps=s.extractWidgetProps;exports.processAutoLabel=s.processAutoLabel;exports.processAutoPlaceholder=s.processAutoPlaceholder;exports._gslStates=E;exports._gslTag=v;exports.formDefs=C;exports.getItemKey=re;exports.golemForm=ne;exports.isDxDefinitions=R;exports.isOption=ie;exports.resolveFormInput=te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./register-dBzdQbWZ.cjs");require("@golemui/core");require("@golemui/gui-validators");function v(l,...e){return e.map(t=>({...t,targetState:l}))}function M(l,...e){return{kind:"aggregated",matcher:t=>t.tags?.includes(l)??!1,children:e}}const B={INPUTS:new Set(["INPUTS","TEXTAREA","PASSWORD","SELECT","DROPDOWN","RADIOGROUP","CHECKBOX","CALENDAR","DATE_INPUT","DATE_PICKER","RANGE_CALENDAR","RANGE_DATE_INPUT","RANGE_DATE_PICKER","CURRENCY","MARKDOWN","LIST","CUSTOM_INPUT","REPEATER","TAGS"]),ACTIONS:new Set(["ACTIONS","CUSTOM_ACTION"]),DISPLAYS:new Set(["DISPLAYS","ALERTS","MARKDOWN_TEXTS","CUSTOM_DISPLAY"]),LAYOUTS:new Set(["LAYOUTS","TABS","ACCORDION","CUSTOM_LAYOUT"])};function P(l,e){const t=B[l];return t?t.has(e):l===e}class L{resolve(e,t){const r=[];for(const i of t)i.kind==="aggregated"?this.collectFromAggregated(i,e,r):this.collectFromLeaf(i,e,r);const n=this.rollUpSensibleDefaults(r);return{leafSelectors:r,sensibleDefaults:n}}collectFromAggregated(e,t,r){if(e.matcher(t))for(const n of e.children)this.collectFromLeaf(n,t,r)}collectFromLeaf(e,t,r){P(e.selectorType,t.itemType??"")&&e.matcher(t)&&r.push(e)}rollUpSensibleDefaults(e){const t=new Map,r=(i,o)=>{const a=t.get(i)??[];a.push(o),t.set(i,a)};for(const i of e){const o=B[i.selectorType];if(o)for(const a of o)r(a,i);else r(i.selectorType,i)}const n={};for(const[i,o]of t)s.hasItemTypeHandler(i)&&(n[i]=s.getItemTypeHandler(i).rollUpSensibleDefaults(o));return n}}const F=new L;class j{deepMerge(e,t){if(t==null)return e;if(e==null||typeof e!="object"||typeof t!="object"||Array.isArray(e)||Array.isArray(t))return t;const r={...e};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(typeof t[n]=="object"&&!Array.isArray(t[n])&&t[n]!==null&&typeof e[n]=="object"&&!Array.isArray(e[n])&&e[n]!==null?r[n]=this.deepMerge(e[n],t[n]):r[n]=t[n]);return r}}const N=new j;class W{constructor(e){this.objectUtils=e}merge(e,t,r){let n={},i=null;typeof e=="function"&&(i=e);const o=this.collectDecorators(r);for(const c of o){if(i!=null){i=this.composeRuntimeFunctions(i,c);continue}if(typeof c=="function"){const g=c({...n,...typeof e=="function"?{}:e});if(typeof g=="function"){i=this.createPromotedFunction(n,e,g,t,r);continue}n=this.objectUtils.deepMerge(n,g)}else n=this.objectUtils.deepMerge(n,c)}if(i!=null)return{kind:"dynamic",fn:this.wrapWithSensibleDefaults(i,n,t,r)};const a=this.objectUtils.deepMerge(e,n);return{kind:"static",def:this.applySensibleDefaults({...a},t,r)}}collectDecorators(e){const t=[];for(const r of e.leafSelectors){const n=r.config;n.override!=null&&t.push(n.override)}return t}applySensibleDefaults(e,t,r){if(!s.hasItemTypeHandler(t))return e;const n=r.sensibleDefaults[t]??{};return s.getItemTypeHandler(t).applySensibleDefaults(e,n)}createPromotedFunction(e,t,r,n,i){return o=>{const a=r(o);let u=this.objectUtils.deepMerge(e,a);return u=this.objectUtils.deepMerge(u,t),this.applySensibleDefaults(u,n,i)}}wrapWithSensibleDefaults(e,t,r,n){return i=>{let o=e(i);return Object.keys(t).length>0&&(o=this.objectUtils.deepMerge(t,o)),this.applySensibleDefaults(o,r,n)}}composeRuntimeFunctions(e,t){return typeof t=="function"?r=>{const n=e(r),i=t(n);return typeof i=="function"?i(r):this.objectUtils.deepMerge(i,n)}:r=>{const n=e(r);return this.objectUtils.deepMerge(n,t)}}}const z=new W(N);class G{mapToWidget(e,t){if(e.kind==="dynamic"){const r=e.fn;return(n=>{const i=r(n);return this.mapStaticDef(i,t)})}return this.mapStaticDef(e.def,t)}mapStaticDef(e,t){const r=s.getItemTypeHandler(t).mapToWidget(e);return this.applyBaseWidgetFields(r,e)}applyBaseWidgetFields(e,t){return t.size!=null&&(e.size=t.size),t.defaultValue!=null&&e.kind==="input"&&(e.defaultValue=t.defaultValue),t.on!=null&&(e.on=t.on),t.include!=null&&(e.include=t.include),t.exclude!=null&&(e.exclude=t.exclude),e}}const $=new G;class H{normalizeSelectors(e){const t=Array.isArray(e)?e:[e],r=[],n=[];for(const i of t)i.kind==="leaf"?n.push(i):r.push(i);return n.length>0&&r.unshift({kind:"aggregated",matcher:()=>!0,children:n}),r}extractFormConfig(){return{suppressAutomaticStack:!1}}}const K=new H,V={input:new Set(["disabled","readonly","label","validator","size"]),action:new Set(["disabled","label","size"]),layout:new Set(["size"]),display:new Set([])},T={onChange:"change",onLoad:"load",onFilter:"filter",onClick:"click"};class Y{extractFromMergeResult(e,t){const r={};for(const a of t){const u=a.targetState,c=a.config,g=c.override&&typeof c.override!="function"?c.override:c;r[u]={...r[u]||{},...g}}if(e.kind==="dynamic"){const a=e.fn;return{cleanedResult:{kind:"dynamic",fn:c=>{const g=a(c),{states:d,..._}=g;return _}},stateData:{stateOverrides:r}}}const{states:n,...i}=e.def,o={};for(const[a,u]of Object.entries(r))o[a]={...u};if(n)for(const[a,u]of Object.entries(n))o[a]={...o[a]||{},...u};return{cleanedResult:{kind:"static",def:i},stateData:{stateOverrides:o}}}applyToWidget(e,t,r,n){const{stateOverrides:i}=t;if(Object.keys(i).length===0)return e;const o={...e},a=e.kind,u=V[a]||new Set;e.props&&(o.props={...e.props}),e.on&&(o.on={...e.on});for(const[c,g]of Object.entries(i))for(const[d,_]of Object.entries(g))d==="visible"?this.applyVisibility(o,c,_):T[d]?this.applyStateEvent(o,c,d,_,r,n):u.has(d)?o[`${d}.${c}`]=_:(o.props||(o.props={}),o.props[`${d}.${c}`]=_);return o}hasStateData(e){return Object.keys(e.stateOverrides).length>0}applyVisibility(e,t,r){if(r){const n=e.include?.in||[];e.include={...e.include||{},in:[...n,t]}}else{const n=e.exclude?.from||[];e.exclude={...e.exclude||{},from:[...n,t]}}}applyStateEvent(e,t,r,n,i,o){const a=T[r];if(e.on||(e.on={}),typeof n=="function"){const u=s.probeForHostEventName(n);if(u!=null)e.on[`${a}.${t}`]=u;else{const c=o.next();i.set(c,n),e.on[`${a}.${t}`]=c}}else typeof n=="string"&&(e.on[`${a}.${t}`]=n)}}const X=new Y;function q(){let l=0;return{next:()=>`event_${l++}`}}class J{constructor(e,t,r,n,i){this.resolver=e,this.merger=t,this.mapper=r,this.eventWiring=n,this.stateExpansion=i}walkAndMap(e,t,r){const n=new Map,i=q(),o={value:0},a=new Set;return{widgets:this.walkItems(e,t,n,r,i,o,a),eventRegistry:n}}walkItems(e,t,r,n,i,o,a){return e.flatMap(u=>{if(u.type!=="ITEMS")throw new Error("Unexpected gui shortcut type");return u.items.map(c=>this.processItem(c,u.itemType,u.tags,t,r,n,i,o,a))})}processItem(e,t,r,n,i,o,a,u,c){const g=t,d=s.getItemTypeHandler(t),_=d.parseEntry(e),m=this.buildBaseDef(_),x=this.buildDecoratorForMatching(m,g,r),h=this.resolver.resolve(x,n),w=h.leafSelectors.filter(p=>p.targetState!=null),k={leafSelectors:h.leafSelectors.filter(p=>p.targetState==null),sensibleDefaults:h.sensibleDefaults};let y=this.merger.merge(m,g,k);d.afterMerge&&(y=d.afterMerge(y,{eventRegistry:i,formConfig:o,eventIdGenerator:a})),y=this.eventWiring.wireInputLayoutEvents(y,i,a);const{cleanedResult:U,stateData:S}=this.stateExpansion.extractFromMergeResult(y,w);let f;if(d.buildCustomWidget){const p=this.buildCustomWidgetContext(_.children,n,i,o,a,u,c);f=this.buildCustomWidget(d,U,p)}else f=this.mapper.mapToWidget(U,g);if(typeof f!="function"){const p=f;p.uid||(p.path&&!c.has(p.path)?(p.uid=p.path,c.add(p.path)):p.uid=`dx_${u.value++}`)}if(this.stateExpansion.hasStateData(S))if(typeof f=="function"){const p=f;f=(O=>{const E=p(O);return this.stateExpansion.applyToWidget(E,S,i,a)})}else f=this.stateExpansion.applyToWidget(f,S,i,a);return f}buildCustomWidgetContext(e,t,r,n,i,o,a){return{children:e,mapStaticDef:(u,c)=>this.mapper.mapStaticDef(u,c),walkChildren:u=>this.walkItems(u,t,r,n,i,o,a)}}buildCustomWidget(e,t,r){return e.buildCustomWidget(t,r)}buildBaseDef(e){const t=e.baseDef;return typeof t=="function"?r=>{const i=t(r??{});return e.path!=null?{...i,path:e.path}:i}:e.path!=null?{...t,path:e.path}:t}buildDecoratorForMatching(e,t,r){if(typeof e=="function")return{itemType:t,tags:[...r]};const n=[...r,..."tags"in e&&e.tags?e.tags:[]],i="uid"in e?e.uid:void 0,o="type"in e?e.type:void 0;return{itemType:t,tags:n,uid:i,type:o}}}class Q{constructor(e,t){this.selectorNormalizer=e,this.walker=t}processDxFacade(e,t=[],r){const{defs:n,gslSelectors:i,formConfig:o}=this.prepareForm(e,t,r),{widgets:a,eventRegistry:u}=this.walker.walkAndMap(n,i,o),c=a[0];return this.buildResult({form:c},u,o)}prepareForm(e,t,r){const i=(Array.isArray(e)?[...e]:[e]).map(u=>typeof u=="function"?s._guiDisplay(u):u),o=this.selectorNormalizer.normalizeSelectors(t),a={...this.selectorNormalizer.extractFormConfig(),...r};if(!a.suppressAutomaticStack){const u={def:{uid:"#root",direction:"column",widgetName:"flex"},children:i};return{defs:[{type:"ITEMS",itemType:s.GuiItemTypes.LAYOUTS,items:[u],tags:[]}],gslSelectors:o,formConfig:a}}return{defs:i,gslSelectors:o,formConfig:a}}convertStateNames(e){const t={};for(const[r,n]of Object.entries(e))t[r.replace(/\$/g,":")]=n;return t}buildResult(e,t,r){r.states&&Object.keys(r.states).length>0&&(e={...e,states:this.convertStateNames(r.states)});const n={form:e};return t.size>0&&(n.events=i=>{const o=t.get(i.name);if(o){const a=c=>{if(c&&typeof c=="object"&&"path"in c&&!("type"in c)){const{path:g,...d}=c;for(const[_,m]of Object.entries(d))i.callback({type:"OVERRIDE_WIDGET_PROP",payload:{path:g,prop:_,value:m}})}else i.callback(c)},u={...i,callback:a,update:a};o(u)}}),r.dependencies&&(n.dependencies=r.dependencies),r.widgetLoaders&&(n.widgetLoaders=r.widgetLoaders),r.validateOn&&(n.validateOn=r.validateOn),r.itemRenderers&&(n.itemRenderers=r.itemRenderers),n}}const Z=new J(F,z,$,s.eventWiringService,X),R=new Q(K,Z);function D(l){return typeof l=="function"?!0:Array.isArray(l)?l.length===0||l.every(I):I(l)}function I(l){if(typeof l=="function")return!0;if(l===null||typeof l!="object")return!1;const e=l;return e.type==="ITEMS"&&typeof e.itemType=="string"}function ee(l){if(!l||typeof l!="object"||Array.isArray(l))return;const e=l.form;if(D(e))throw new Error("[GolemUI] The gui.* form definition was wrapped in an extra `{ form: ... }` object, so its fields were never resolved. Pass the gui.* array DIRECTLY as formDef (`config={{ formDef: form }}`) and put any named `states` in `formConfig`: `config={{ formDef: form, formConfig: { states } }}`. Do NOT wrap them as a `{ form: [...] }` object.")}const A=Object.freeze({}),te=Object.freeze({}),C=new WeakMap;function b(l,e){return l==null?e:typeof l=="object"?l:{}}function se(l,e,t){if(!D(l))return ee(l),{formDef:l};const r=b(l,A),n=b(e,A),i=b(t,te);let o=C.get(r);o||(o=new WeakMap,C.set(r,o));let a=o.get(n);a||(a=new WeakMap,o.set(n,a));const u=a.get(i);if(u)return u;const c=R.processDxFacade(l,e,t),g={formDef:c.form,formEvent:c.events,dependencies:c.dependencies,widgetLoaders:c.widgetLoaders,validateOn:c.validateOn,itemRenderers:c.itemRenderers};return a.set(i,g),g}class ne{create(e){return{states:e.states,form:{uid:"gui-root-uid",type:"flex",kind:"layout",children:e.form}}}}function re(){return new ne}const ie=l=>l!==null&&typeof l=="object"&&Object.prototype.hasOwnProperty.call(l,"label")&&Object.prototype.hasOwnProperty.call(l,"value");function oe(l,e){if(l!=null&&typeof l=="object"&&"__rid"in l)return l.__rid;const t=e();return Object.defineProperty(l,"__rid",{value:t,enumerable:!1,configurable:!1}),t}exports._gslAccordionByUid=s._gslAccordionByUid;exports._gslAccordions=s._gslAccordions;exports._gslActionByUid=s._gslActionByUid;exports._gslActions=s._gslActions;exports._gslAlertByUid=s._gslAlertByUid;exports._gslAlerts=s._gslAlerts;exports._gslBooleanInputs=s._gslBooleanInputs;exports._gslCalendarByUid=s._gslCalendarByUid;exports._gslCalendars=s._gslCalendars;exports._gslCheckboxByUid=s._gslCheckboxByUid;exports._gslCheckboxes=s._gslCheckboxes;exports._gslCurrencies=s._gslCurrencies;exports._gslCurrencyByUid=s._gslCurrencyByUid;exports._gslCustomActionByUid=s._gslCustomActionByUid;exports._gslCustomActions=s._gslCustomActions;exports._gslCustomDisplayByUid=s._gslCustomDisplayByUid;exports._gslCustomDisplays=s._gslCustomDisplays;exports._gslCustomInputByUid=s._gslCustomInputByUid;exports._gslCustomInputs=s._gslCustomInputs;exports._gslCustomLayoutByUid=s._gslCustomLayoutByUid;exports._gslCustomLayouts=s._gslCustomLayouts;exports._gslDateInputByUid=s._gslDateInputByUid;exports._gslDateInputs=s._gslDateInputs;exports._gslDatePickerByUid=s._gslDatePickerByUid;exports._gslDatePickers=s._gslDatePickers;exports._gslDisplayByUid=s._gslDisplayByUid;exports._gslDisplays=s._gslDisplays;exports._gslDropdownByUid=s._gslDropdownByUid;exports._gslDropdowns=s._gslDropdowns;exports._gslInputByUid=s._gslInputByUid;exports._gslInputs=s._gslInputs;exports._gslLayoutByUid=s._gslLayoutByUid;exports._gslLayouts=s._gslLayouts;exports._gslListByUid=s._gslListByUid;exports._gslLists=s._gslLists;exports._gslMarkdownByUid=s._gslMarkdownByUid;exports._gslMarkdownTextByUid=s._gslMarkdownTextByUid;exports._gslMarkdownTexts=s._gslMarkdownTexts;exports._gslMarkdowns=s._gslMarkdowns;exports._gslNumberInputs=s._gslNumberInputs;exports._gslPasswordByUid=s._gslPasswordByUid;exports._gslPasswords=s._gslPasswords;exports._gslRadiogroupByUid=s._gslRadiogroupByUid;exports._gslRadiogroups=s._gslRadiogroups;exports._gslRangeCalendarByUid=s._gslRangeCalendarByUid;exports._gslRangeCalendars=s._gslRangeCalendars;exports._gslRangeDateInputByUid=s._gslRangeDateInputByUid;exports._gslRangeDateInputs=s._gslRangeDateInputs;exports._gslRangeDatePickerByUid=s._gslRangeDatePickerByUid;exports._gslRangeDatePickers=s._gslRangeDatePickers;exports._gslRepeaterByUid=s._gslRepeaterByUid;exports._gslRepeaters=s._gslRepeaters;exports._gslSelectByUid=s._gslSelectByUid;exports._gslSelects=s._gslSelects;exports._gslTabs=s._gslTabs;exports._gslTabsByUid=s._gslTabsByUid;exports._gslTags=s._gslTags;exports._gslTagsByUid=s._gslTagsByUid;exports._gslTextInputs=s._gslTextInputs;exports._gslTextareaByUid=s._gslTextareaByUid;exports._gslTextareas=s._gslTextareas;exports._guiAccordion=s._guiAccordion;exports._guiAlert=s._guiAlert;exports._guiBooleanInput=s._guiBooleanInput;exports._guiButton=s._guiButton;exports._guiCalendar=s._guiCalendar;exports._guiCheckbox=s._guiCheckbox;exports._guiCurrency=s._guiCurrency;exports._guiCustomAction=s._guiCustomAction;exports._guiCustomDisplay=s._guiCustomDisplay;exports._guiCustomInput=s._guiCustomInput;exports._guiCustomLayout=s._guiCustomLayout;exports._guiDateInput=s._guiDateInput;exports._guiDatePicker=s._guiDatePicker;exports._guiDisplay=s._guiDisplay;exports._guiDropdown=s._guiDropdown;exports._guiFlex=s._guiFlex;exports._guiGrid=s._guiGrid;exports._guiHorizontalFlex=s._guiHorizontalFlex;exports._guiHorizontalGrid=s._guiHorizontalGrid;exports._guiList=s._guiList;exports._guiMarkdown=s._guiMarkdown;exports._guiMarkdownText=s._guiMarkdownText;exports._guiNumberInput=s._guiNumberInput;exports._guiPassword=s._guiPassword;exports._guiRadiogroup=s._guiRadiogroup;exports._guiRangeCalendar=s._guiRangeCalendar;exports._guiRangeDateInput=s._guiRangeDateInput;exports._guiRangeDatePicker=s._guiRangeDatePicker;exports._guiRepeater=s._guiRepeater;exports._guiSelect=s._guiSelect;exports._guiTabs=s._guiTabs;exports._guiTags=s._guiTags;exports._guiTextInput=s._guiTextInput;exports._guiTextarea=s._guiTextarea;exports._guiVerticalFlex=s._guiVerticalFlex;exports._guiVerticalGrid=s._guiVerticalGrid;exports.createGslSelector=s.createGslSelector;exports.defineShortcutType=s.defineShortcutType;exports.extractWidgetProps=s.extractWidgetProps;exports.processAutoLabel=s.processAutoLabel;exports.processAutoPlaceholder=s.processAutoPlaceholder;exports._gslStates=v;exports._gslTag=M;exports.formDefs=R;exports.getItemKey=oe;exports.golemForm=re;exports.isDxDefinitions=D;exports.isOption=ie;exports.resolveFormInput=se;
|
|
@@ -14,10 +14,24 @@ export type DxFormEvent = FormEvent & {
|
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Event handler type for DX event properties.
|
|
17
|
-
*
|
|
18
|
-
* -
|
|
17
|
+
*
|
|
18
|
+
* Function-only, mirroring action `onClick`. Bare strings are NOT accepted — a stray
|
|
19
|
+
* `onChange: 'something'` is a footgun (it looks like a value, not a handler), so the
|
|
20
|
+
* type rejects it.
|
|
21
|
+
*
|
|
22
|
+
* - Return a string to wire a host-managed event name (e.g. `onChange: () => 'fieldChange'`
|
|
23
|
+
* dispatches `fieldChange` to the host event bus). Only zero-arg handlers are probed for
|
|
24
|
+
* this, so the `event` parameter is never touched at build time.
|
|
25
|
+
* - Otherwise the handler runs on dispatch; use `event.update(...)` to push widget changes.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Host-managed dispatch by name:
|
|
29
|
+
* onChange: () => 'fieldChange'
|
|
30
|
+
* @example
|
|
31
|
+
* // Imperative handler:
|
|
32
|
+
* onChange: (event) => event.update({ path: 'country', options: [] })
|
|
19
33
|
*/
|
|
20
|
-
export type DxEventHandler =
|
|
34
|
+
export type DxEventHandler = (event: DxFormEvent) => void | string;
|
|
21
35
|
/**
|
|
22
36
|
* INTERNAL decorator fields — used by the pipeline, NOT by form authors.
|
|
23
37
|
* Contains fields that the pipeline needs but users should never set.
|
|
@@ -58,7 +72,13 @@ export interface DxCommonFields {
|
|
|
58
72
|
uid?: string;
|
|
59
73
|
tags?: string[];
|
|
60
74
|
size?: number;
|
|
61
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Per-state property overrides. Keys are state names (use `:` for hierarchy).
|
|
77
|
+
*
|
|
78
|
+
* NOTE: the override values are an untyped escape hatch (`Record<string, any>`), so they
|
|
79
|
+
* are NOT type-checked — e.g. `states: { editing: { onChange: 'foo' } }` compiles even
|
|
80
|
+
* though a top-level `onChange: 'foo'` does not (events are function-only).
|
|
81
|
+
*/
|
|
62
82
|
states?: Record<string, Record<string, any>>;
|
|
63
83
|
/** Conditionally include the widget — by active state list or reactive expression. */
|
|
64
84
|
include?: DxIncludeCondition;
|
|
@@ -2,6 +2,19 @@ import { FormEvent } from '@golemui/core';
|
|
|
2
2
|
import { MergeResult } from './dx.domain';
|
|
3
3
|
import { EventIdGenerator } from './itemTypeRegistry';
|
|
4
4
|
export type EventRegistry = Map<string, (event: FormEvent) => void>;
|
|
5
|
+
/**
|
|
6
|
+
* Probe a DX event handler for a host-managed event name.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the action `onClick` pattern: a handler that simply returns a string
|
|
9
|
+
* (`() => 'fieldChange'`) declares a host-managed dispatch by name. Only **zero-arg**
|
|
10
|
+
* handlers are probed — a handler that declares the `event` parameter
|
|
11
|
+
* (`(event) => event.update(...)`) is an imperative handler and is never invoked here,
|
|
12
|
+
* so its method-bearing `DxFormEvent` is never touched with `undefined`.
|
|
13
|
+
*
|
|
14
|
+
* @returns the returned event name, or `null` when the handler is not a declarative
|
|
15
|
+
* zero-arg string-returning handler (i.e. it should be registered and run on dispatch).
|
|
16
|
+
*/
|
|
17
|
+
export declare function probeForHostEventName(handler: (...args: any[]) => any): string | null;
|
|
5
18
|
/**
|
|
6
19
|
* Generalisation of ActionOnClickService.
|
|
7
20
|
*
|
|
@@ -3,7 +3,7 @@ import { DefOrCallback, GslConfigBase, GuiShortcutOf } from '../../core/dxUtilit
|
|
|
3
3
|
export interface CustomActionDecorator extends DxActionBase, DxCommonFields {
|
|
4
4
|
customType: string;
|
|
5
5
|
props?: Record<string, unknown>;
|
|
6
|
-
onClick?: (
|
|
6
|
+
onClick?: (data: any) => void | string;
|
|
7
7
|
data?: any | null;
|
|
8
8
|
on?: {
|
|
9
9
|
click: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@golemui/gui-shared",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "./index.umd.cjs",
|
|
6
7
|
"module": "./index.js",
|
|
@@ -30,8 +31,8 @@
|
|
|
30
31
|
"*.md"
|
|
31
32
|
],
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@golemui/core": "1.0.0-rc.
|
|
34
|
-
"@golemui/gui-validators": "1.0.0-rc.
|
|
34
|
+
"@golemui/core": "1.0.0-rc.4",
|
|
35
|
+
"@golemui/gui-validators": "1.0.0-rc.4"
|
|
35
36
|
},
|
|
36
37
|
"repository": {
|
|
37
38
|
"type": "git",
|