@vertigis/workflow 5.35.1 → 5.36.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.
Files changed (220) hide show
  1. package/Hooks.d.ts +3 -3
  2. package/IActivityHandler.d.ts +1 -6
  3. package/activities/arcgis/AddAttachment.d.ts +2 -2
  4. package/activities/arcgis/AddAttachment.js +1 -1
  5. package/activities/arcgis/AddFeatures.d.ts +3 -3
  6. package/activities/arcgis/AddFeatures.js +1 -1
  7. package/activities/arcgis/AddGraphics.d.ts +2 -2
  8. package/activities/arcgis/AddGraphics.js +1 -1
  9. package/activities/arcgis/ArcadeScript.d.ts +2 -2
  10. package/activities/arcgis/ArcadeScript.js +1 -1
  11. package/activities/arcgis/AreaEngineTask.d.ts +2 -2
  12. package/activities/arcgis/AreaEngineTask.js +1 -1
  13. package/activities/arcgis/BufferEngineTask.d.ts +2 -2
  14. package/activities/arcgis/BufferEngineTask.js +1 -1
  15. package/activities/arcgis/ClearGraphics.d.ts +1 -1
  16. package/activities/arcgis/ClearGraphics.js +1 -1
  17. package/activities/arcgis/ClipEngineTask.d.ts +2 -2
  18. package/activities/arcgis/ClipEngineTask.js +1 -1
  19. package/activities/arcgis/CompareGeometries.d.ts +2 -2
  20. package/activities/arcgis/CompareGeometries.js +1 -1
  21. package/activities/arcgis/CutEngineTask.d.ts +2 -2
  22. package/activities/arcgis/CutEngineTask.js +1 -1
  23. package/activities/arcgis/DeleteAttachments.d.ts +2 -2
  24. package/activities/arcgis/DeleteAttachments.js +1 -1
  25. package/activities/arcgis/DeleteFeatures.d.ts +3 -3
  26. package/activities/arcgis/DeleteFeatures.js +1 -1
  27. package/activities/arcgis/DensifyEngineTask.d.ts +2 -2
  28. package/activities/arcgis/DensifyEngineTask.js +1 -1
  29. package/activities/arcgis/DifferenceEngineTask.d.ts +2 -2
  30. package/activities/arcgis/DifferenceEngineTask.js +1 -1
  31. package/activities/arcgis/DistanceEngineTask.d.ts +2 -2
  32. package/activities/arcgis/DistanceEngineTask.js +1 -1
  33. package/activities/arcgis/ExtendedSpatialReferenceInfoEngineTask.d.ts +1 -1
  34. package/activities/arcgis/FlipEngineTask.d.ts +2 -2
  35. package/activities/arcgis/FlipEngineTask.js +1 -1
  36. package/activities/arcgis/GeneralizeEngineTask.d.ts +2 -2
  37. package/activities/arcgis/GeneralizeEngineTask.js +1 -1
  38. package/activities/arcgis/Geocode.d.ts +2 -2
  39. package/activities/arcgis/Geocode.js +1 -1
  40. package/activities/arcgis/GeoprocessingAsync.js +1 -1
  41. package/activities/arcgis/GetCodedValueDomain.d.ts +4 -4
  42. package/activities/arcgis/GetCodedValueDomain.js +1 -1
  43. package/activities/arcgis/GetFeatureLayerInfo.d.ts +2 -2
  44. package/activities/arcgis/GetFeatureLayerInfo.js +1 -1
  45. package/activities/arcgis/GetGraphics.d.ts +2 -2
  46. package/activities/arcgis/GetGraphics.js +1 -1
  47. package/activities/arcgis/GetLayer.d.ts +2 -2
  48. package/activities/arcgis/GetLayer.js +1 -1
  49. package/activities/arcgis/GetLayerDefinitionExpression.d.ts +2 -2
  50. package/activities/arcgis/GetLayerDefinitionExpression.js +1 -1
  51. package/activities/arcgis/GetLayerProperty.d.ts +2 -2
  52. package/activities/arcgis/GetLayerProperty.js +1 -1
  53. package/activities/arcgis/GetLayerVisibility.d.ts +2 -2
  54. package/activities/arcgis/GetLayerVisibility.js +1 -1
  55. package/activities/arcgis/GetMap.d.ts +2 -2
  56. package/activities/arcgis/GetMap.js +1 -1
  57. package/activities/arcgis/GetMapScreenshot.d.ts +1 -1
  58. package/activities/arcgis/GetTable.d.ts +2 -2
  59. package/activities/arcgis/GetTable.js +1 -1
  60. package/activities/arcgis/GetViewExtent.d.ts +2 -2
  61. package/activities/arcgis/GetViewExtent.js +1 -1
  62. package/activities/arcgis/GetViewpoint.d.ts +2 -2
  63. package/activities/arcgis/GetViewpoint.js +1 -1
  64. package/activities/arcgis/IntersectEngineTask.d.ts +2 -2
  65. package/activities/arcgis/IntersectEngineTask.js +1 -1
  66. package/activities/arcgis/LengthEngineTask.d.ts +2 -2
  67. package/activities/arcgis/LengthEngineTask.js +1 -1
  68. package/activities/arcgis/MapProvider.js +1 -1
  69. package/activities/arcgis/NearestVertexEngineTask.d.ts +2 -2
  70. package/activities/arcgis/NearestVertexEngineTask.js +1 -1
  71. package/activities/arcgis/NearestVerticesEngineTask.d.ts +2 -2
  72. package/activities/arcgis/NearestVerticesEngineTask.js +1 -1
  73. package/activities/arcgis/OffsetEngineTask.d.ts +2 -2
  74. package/activities/arcgis/OffsetEngineTask.js +1 -1
  75. package/activities/arcgis/QueryAttachmentInfos.d.ts +2 -2
  76. package/activities/arcgis/QueryAttachmentInfos.js +1 -1
  77. package/activities/arcgis/QueryTask.js +1 -1
  78. package/activities/arcgis/RelateEngineTask.d.ts +2 -2
  79. package/activities/arcgis/RelateEngineTask.js +1 -1
  80. package/activities/arcgis/RemoveGraphics.d.ts +2 -2
  81. package/activities/arcgis/RemoveGraphics.js +1 -1
  82. package/activities/arcgis/RemoveLayer.d.ts +2 -2
  83. package/activities/arcgis/RemoveLayer.js +1 -1
  84. package/activities/arcgis/RotateEngineTask.d.ts +2 -2
  85. package/activities/arcgis/RotateEngineTask.js +1 -1
  86. package/activities/arcgis/SetFeaturePopup.d.ts +1 -1
  87. package/activities/arcgis/SetImageryLayerOptions.d.ts +2 -2
  88. package/activities/arcgis/SetImageryLayerOptions.js +1 -1
  89. package/activities/arcgis/SetLayerDefinitionExpression.d.ts +2 -2
  90. package/activities/arcgis/SetLayerDefinitionExpression.js +1 -1
  91. package/activities/arcgis/SetLayerPopup.d.ts +2 -2
  92. package/activities/arcgis/SetLayerPopup.js +1 -1
  93. package/activities/arcgis/SetLayerProperty.d.ts +2 -2
  94. package/activities/arcgis/SetLayerProperty.js +1 -1
  95. package/activities/arcgis/SetLayerVisibility.d.ts +2 -2
  96. package/activities/arcgis/SetLayerVisibility.js +1 -1
  97. package/activities/arcgis/SetViewExtent.d.ts +2 -2
  98. package/activities/arcgis/SetViewExtent.js +1 -1
  99. package/activities/arcgis/SetViewpoint.d.ts +2 -2
  100. package/activities/arcgis/SetViewpoint.js +1 -1
  101. package/activities/arcgis/ShowFeaturePopup.d.ts +2 -2
  102. package/activities/arcgis/ShowFeaturePopup.js +1 -1
  103. package/activities/arcgis/ShowResults.d.ts +2 -2
  104. package/activities/arcgis/SimplifyEngineTask.d.ts +2 -2
  105. package/activities/arcgis/SimplifyEngineTask.js +1 -1
  106. package/activities/arcgis/UnionEngineTask.d.ts +2 -2
  107. package/activities/arcgis/UnionEngineTask.js +1 -1
  108. package/activities/arcgis/UpdateAttachment.d.ts +2 -2
  109. package/activities/arcgis/UpdateAttachment.js +1 -1
  110. package/activities/arcgis/UpdateFeatures.d.ts +3 -3
  111. package/activities/arcgis/UpdateFeatures.js +1 -1
  112. package/activities/arcgis/libs/arcGisRestApi.d.ts +1 -8
  113. package/activities/arcgis/tools.d.ts +0 -9
  114. package/activities/arcgis/tools.js +1 -1
  115. package/activities/core/WebRequest.js +1 -1
  116. package/activities/essentials/RunEssentialsWorkflow.d.ts +1 -1
  117. package/activities/essentials/RunEssentialsWorkflow.js +1 -1
  118. package/activities/forms/ActivateFormElement.d.ts +2 -2
  119. package/activities/forms/ActivateFormElement.js +1 -1
  120. package/activities/forms/AddFormElement.d.ts +3 -3
  121. package/activities/forms/ClearFormElementError.d.ts +2 -2
  122. package/activities/forms/ClearFormElementError.js +1 -1
  123. package/activities/forms/DisplayForm.d.ts +2 -2
  124. package/activities/forms/DisplayForm.js +1 -1
  125. package/activities/forms/FormRenderer.d.ts +35 -29
  126. package/activities/forms/FormRenderer.js +1 -1
  127. package/activities/forms/HideFormElement.d.ts +2 -2
  128. package/activities/forms/HideFormElement.js +1 -1
  129. package/activities/forms/SetCurrentFormElementItem.d.ts +2 -2
  130. package/activities/forms/SetCurrentFormElementItem.js +1 -1
  131. package/activities/forms/SetFormElementError.d.ts +2 -2
  132. package/activities/forms/SetFormElementError.js +1 -1
  133. package/activities/forms/SetFormElementEvent.d.ts +2 -2
  134. package/activities/forms/SetFormElementItemProperty.d.ts +2 -2
  135. package/activities/forms/SetFormElementItemProperty.js +1 -1
  136. package/activities/forms/SetFormElementItems.d.ts +2 -2
  137. package/activities/forms/SetFormElementItems.js +1 -1
  138. package/activities/forms/SetFormElementProperty.d.ts +2 -2
  139. package/activities/forms/SetFormElementProperty.js +1 -1
  140. package/activities/forms/ShowFormElement.d.ts +2 -2
  141. package/activities/forms/ShowFormElement.js +1 -1
  142. package/execution/ActivityLoader.js +1 -1
  143. package/execution/Engine.js +1 -1
  144. package/execution/ModuleLoader.js +1 -1
  145. package/execution/ProgramRunner.js +1 -1
  146. package/forms/FormComponent.d.ts +18 -1
  147. package/forms/FormComponent.js +1 -1
  148. package/forms/FormDefinition.d.ts +1 -6
  149. package/forms/FormHost.d.ts +0 -2
  150. package/forms/FormHost.js +1 -1
  151. package/forms/FormPresenterHost.d.ts +0 -2
  152. package/forms/NumberParser.d.ts +1 -0
  153. package/forms/NumberParser.js +1 -1
  154. package/forms/common.d.ts +2 -2
  155. package/forms/common.js +1 -1
  156. package/forms/components/AutoComplete.d.ts +3 -2
  157. package/forms/components/AutoComplete.js +1 -1
  158. package/forms/components/ButtonBar.d.ts +3 -8
  159. package/forms/components/ButtonBar.js +1 -1
  160. package/forms/components/CheckBox.d.ts +2 -2
  161. package/forms/components/CheckBox.js +1 -1
  162. package/forms/components/CheckGroup.d.ts +3 -2
  163. package/forms/components/CheckGroup.js +1 -1
  164. package/forms/components/Custom.d.ts +2 -2
  165. package/forms/components/Custom.js +1 -1
  166. package/forms/components/DatePicker.d.ts +3 -2
  167. package/forms/components/DatePicker.js +1 -1
  168. package/forms/components/DateRangePicker.d.ts +3 -2
  169. package/forms/components/DateRangePicker.js +1 -1
  170. package/forms/components/DateTimePicker.d.ts +3 -2
  171. package/forms/components/DateTimePicker.js +1 -1
  172. package/forms/components/DropDownList.js +1 -1
  173. package/forms/components/FilePicker.js +1 -1
  174. package/forms/components/Form.js +1 -1
  175. package/forms/components/FormLabelNumberField.d.ts +3 -1
  176. package/forms/components/FormLabelNumberField.js +1 -1
  177. package/forms/components/GeometryPicker.js +1 -1
  178. package/forms/components/HorizontalRule.d.ts +2 -2
  179. package/forms/components/Image.d.ts +2 -2
  180. package/forms/components/Image.js +1 -1
  181. package/forms/components/ItemPicker.js +1 -1
  182. package/forms/components/ListBox.d.ts +3 -2
  183. package/forms/components/ListBox.js +1 -1
  184. package/forms/components/Markdown.d.ts +3 -4
  185. package/forms/components/Markdown.js +1 -1
  186. package/forms/components/Number.d.ts +3 -2
  187. package/forms/components/Number.js +1 -1
  188. package/forms/components/NumberRangeSlider.d.ts +2 -2
  189. package/forms/components/NumberRangeSlider.js +1 -1
  190. package/forms/components/NumberSlider.d.ts +3 -2
  191. package/forms/components/NumberSlider.js +1 -1
  192. package/forms/components/RadioGroup.d.ts +3 -2
  193. package/forms/components/RadioGroup.js +1 -1
  194. package/forms/components/Scanner.js +1 -1
  195. package/forms/components/Section.js +1 -1
  196. package/forms/components/Signature.js +1 -1
  197. package/forms/components/SignatureDialog.js +1 -1
  198. package/forms/components/Text.d.ts +2 -2
  199. package/forms/components/TextArea.d.ts +2 -2
  200. package/forms/components/TextArea.js +1 -1
  201. package/forms/components/TextBox.d.ts +2 -16
  202. package/forms/components/TextBox.js +1 -1
  203. package/forms/components/TimePicker.d.ts +3 -2
  204. package/forms/components/TimePicker.js +1 -1
  205. package/forms/dateUtilities.d.ts +4 -18
  206. package/forms/dateUtilities.js +1 -1
  207. package/forms/index.d.ts +48 -12
  208. package/forms/listUtilities.d.ts +3 -0
  209. package/forms/listUtilities.js +1 -0
  210. package/forms/manifest.d.ts +3 -0
  211. package/forms/manifest.js +1 -0
  212. package/forms/numberUtilities.d.ts +40 -3
  213. package/forms/numberUtilities.js +1 -1
  214. package/forms/presenter.js +1 -1
  215. package/forms/renderers.js +1 -1
  216. package/forms/utils.d.ts +35 -21
  217. package/forms/utils.js +1 -1
  218. package/libs/version.d.ts +1 -1
  219. package/libs/version.js +1 -1
  220. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { IActivityHandler, IActivityContext, Deferrable, EmptyOutputs } from "../../IActivityHandler";
1
+ import { IActivityHandler, EmptyOutputs } from "../../IActivityHandler";
2
2
  import * as defs from "../../forms/FormDefinition";
3
3
  import { DisplayFormOutputs } from "./DisplayForm";
4
4
  export interface SetFormElementPropertyInputs {
@@ -15,5 +15,5 @@ export interface SetFormElementPropertyInputs {
15
15
  export declare class SetFormElementProperty implements IActivityHandler {
16
16
  static readonly action = "gcx:wf:forms::SetFormElementProperty";
17
17
  static readonly suite = "gcx:wf:builtin";
18
- execute(inputs: SetFormElementPropertyInputs, context: IActivityContext): Deferrable<EmptyOutputs>;
18
+ execute(inputs: SetFormElementPropertyInputs): EmptyOutputs;
19
19
  }
@@ -1 +1 @@
1
- import{validation}from"../../Validation.js";import{getFormForElement}from"./FormElementMap.js";class SetFormElementProperty{execute(e,t){var{propertyName:r,propertyValue:o}=e;let{elementName:m,form:n}=e;"object"==typeof m&&(n=getFormForElement(m)),validation.exists("form",n);e=validation.boolean("markdown",e.markdown,!0);return m=n.actor.getElementName(m,n.event),n.actor.assignElementProperty(m,r,o,e),{}}}SetFormElementProperty.action="gcx:wf:forms::SetFormElementProperty",SetFormElementProperty.suite="gcx:wf:builtin";export{SetFormElementProperty};
1
+ import{validation}from"../../Validation.js";import{getFormForElement}from"./FormElementMap.js";class SetFormElementProperty{execute(e){var{propertyName:t,propertyValue:r}=e;let{elementName:o,form:m}=e;"object"==typeof o&&(m=getFormForElement(o)),validation.exists("form",m);e=validation.boolean("markdown",e.markdown,!0);return o=m.actor.getElementName(o,m.event),m.actor.assignElementProperty(o,t,r,e),{}}}SetFormElementProperty.action="gcx:wf:forms::SetFormElementProperty",SetFormElementProperty.suite="gcx:wf:builtin";export{SetFormElementProperty};
@@ -1,4 +1,4 @@
1
- import { IActivityHandler, IActivityContext, Deferrable, EmptyOutputs } from "../../IActivityHandler";
1
+ import { IActivityHandler, EmptyOutputs } from "../../IActivityHandler";
2
2
  import * as defs from "../../forms/FormDefinition";
3
3
  import { DisplayFormOutputs } from "./DisplayForm";
4
4
  export interface ShowFormElementInputs {
@@ -11,5 +11,5 @@ export interface ShowFormElementInputs {
11
11
  export declare class ShowFormElement implements IActivityHandler {
12
12
  static readonly action = "gcx:wf:forms::ShowFormElement";
13
13
  static readonly suite = "gcx:wf:builtin";
14
- execute(inputs: ShowFormElementInputs, context: IActivityContext): Deferrable<EmptyOutputs>;
14
+ execute(inputs: ShowFormElementInputs): EmptyOutputs;
15
15
  }
@@ -1 +1 @@
1
- import{validation}from"../../Validation.js";import{getFormForElement}from"./FormElementMap.js";class ShowFormElement{execute(e,t){var{elementName:o,visible:m}=e;let r=e["form"];"object"==typeof o&&(r=getFormForElement(o)),validation.exists("form",r);o=r.actor.getElement(o,r.event);return!1===m?r.actor.hideElement(o):r.actor.showElement(o),{}}}ShowFormElement.action="gcx:wf:forms::ShowFormElement",ShowFormElement.suite="gcx:wf:builtin";export{ShowFormElement};
1
+ import{validation}from"../../Validation.js";import{getFormForElement}from"./FormElementMap.js";class ShowFormElement{execute(e){var{elementName:t,visible:o}=e;let m=e["form"];"object"==typeof t&&(m=getFormForElement(t)),validation.exists("form",m);t=m.actor.getElement(t,m.event);return!1===o?m.actor.hideElement(t):m.actor.showElement(t),{}}}ShowFormElement.action="gcx:wf:forms::ShowFormElement",ShowFormElement.suite="gcx:wf:builtin";export{ShowFormElement};
@@ -1 +1 @@
1
- import{registerModuleName,importModule}from"./ModuleLoader.js";const activityCache={},modules={},formElementCache={};function getCachedFormElements(){return{...formElementCache}}const httpPrefix="http://",httpsPrefix="https://";function isHttp(t){return t.substring(0,httpPrefix.length)===httpPrefix||t.substring(0,httpsPrefix.length)===httpsPrefix}function importRef(t,e){if(isHttp(t)){var o=registerModuleName(t);return importModule(o+"/main",e,o)}return importModule(t+"main",e)}function exportIsFormElementRegistration(t){return!("object"!=typeof t||!t.component)}function exportIsActivity(t){if("function"!=typeof t)return!1;var e=t.prototype;return"object"==typeof e&&null!==e&&("function"==typeof e.execute&&("string"==typeof t.action&&"string"==typeof t.suite))}async function loadRef(t,e,o,r){var i=await importRef(e,{action:t,suite:o});if("object"==typeof i&&null!==i&&modules[e]!==i)for(const f in modules[e]=i){var n=i[f];exportIsActivity(n)?createRef(n.action,e,n.suite,r,n):exportIsFormElementRegistration(n)&&r(formElementCache[n.id]=n)}}function createRef(t,e,o,r,i){let n=activityCache[t];void 0===n&&(n=activityCache[t]=[]);for(const f of n)if(f.path===e&&f.suite===o)return void 0!==i&&(f.factory=i),f;const f={factory:i,path:e,suite:o};return n.push(f),void 0!==i?f.factory=i:f.promise=loadRef(t,e,o,r),f}async function resolveRef(t){for(const e of t)if(await e.promise,(e.promise=void 0)!==e.factory)return new e.factory}class ActivityLoader{constructor(){this.references=[]}create(f,c,t){if("string"==typeof f){let n;if(void 0!==t){const o=e(t.program.references);if(void 0!==o)return o}const o=e(this.references);return void 0!==o?o:void 0!==n?resolveRef(n):void 0;function e(t){for(const r of t){var e=r.path,o=r.suite;const i=createRef(f,e,o,c);if(void 0===n){if(void 0!==i.factory)return new i.factory;void 0!==i.promise&&(n=[i])}else n.push(i)}}}}}ActivityLoader.defaultReference={path:"@vertigis/workflow/runtime/activities/",suite:"gcx:wf:builtin"};export{getCachedFormElements,ActivityLoader};
1
+ import{registerModuleName,importModule}from"./ModuleLoader.js";const activityCache={},modules={},formElementCache={};function getCachedFormElements(){return{...formElementCache}}const httpPrefix="http://",httpsPrefix="https://";function isHttp(t){return t.substring(0,httpPrefix.length)===httpPrefix||t.substring(0,httpsPrefix.length)===httpsPrefix}function importRef(t,e){if(isHttp(t)){var o=registerModuleName(t);return importModule(o+"/main",e,o)}return importModule(t+"main",e)}function exportIsFormElementRegistration(t){return!("object"!=typeof t||!t.component)}function exportIsActivity(t){if("function"!=typeof t)return!1;var e=t.prototype;return"object"==typeof e&&null!==e&&("function"==typeof e.execute&&("string"==typeof t.action&&"string"==typeof t.suite))}async function loadRef(t,e,o,r){var i=await importRef(e,{action:t,suite:o});if("object"==typeof i&&null!==i&&modules[e]!==i)for(const f in modules[e]=i){var n=i[f];exportIsActivity(n)?createRef(n.action,e,n.suite,r,n):exportIsFormElementRegistration(n)&&r(formElementCache[n.id]=n)}}function createRef(t,e,o,r,i){let n=activityCache[t];void 0===n&&(n=activityCache[t]=[]);for(const f of n)if(f.path===e&&f.suite===o)return void 0!==i&&(f.factory=i),f;const f={factory:i,path:e,suite:o};return n.push(f),void 0!==i?f.factory=i:f.promise=loadRef(t,e,o,r),f}async function resolveRef(t){for(const e of t)if(await e.promise,(e.promise=void 0)!==e.factory)return new e.factory}class ActivityLoader{constructor(){this.references=[]}create(f,c,t){if("string"==typeof f){let n;if(void 0!==t){const o=e(t.program.references);if(void 0!==o)return o}const o=e(this.references);return void 0!==o?o:void 0!==n?resolveRef(n):void 0;function e(t){for(const r of t){var e=r.path,o=r.suite;const i=createRef(f,e,o,c);if(void 0===n){if(void 0!==i.factory)return new i.factory;void 0!==i.promise&&(n=[i])}else n.push(i)}}}}}ActivityLoader.defaultReference={path:"@vertigis/workflow/activities/",suite:"gcx:wf:builtin"};export{getCachedFormElements,ActivityLoader};
@@ -1 +1 @@
1
- import Bluebird from"bluebird";import{Activator}from"../Activator.js";import{getStringsForProgram}from"../LanguageStringUtils.js";import{Task}from"../Task.js";import{ProgramInspector,canonicalizeLocale}from"../definition/ProgramInspector.js";import{getCachedFormElements}from"../execution/ActivityLoader.js";import{check as checkLicense}from"../licensing/LicenseChecker.js";import{run}from"./ProgramRunner.js";class Engine{constructor(e){this._getFormElementRegistration=e=>this.formElements[e],this._registerFormElement=e=>{var t,r=e["id"];this.formElements[r]?(t={...this.formElements[r],...e},this.formElements[r]=t):this.formElements[r]=e},this.activator=new Activator,this.environment={},this.trivia={getFormElementRegistration:this._getFormElementRegistration,registerFormElement:this._registerFormElement},this.factories=[],this.implementations={},this.formElements={...getCachedFormElements()},this.appSkuCode=e}static buildOptions(e,t){(t={...t||{}}).locale=canonicalizeLocale(t.locale),t.locale||(t.locale=e.getDefaultLocale()),t.logLevel=t.logLevel||"log";var r=new Proxy({},{get(e,t,r){return t}});const i=getStringsForProgram(e,t);return t.environment={activities:r,encodeHtml:function(e){return"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"):""},getText:function(e){if("string"==typeof e&&"@"===e.charAt(0)){var t=e.slice(1);if(t in i)return i[t]}return e},strings:i,...t.environment||{}},t}createHandler(e,t){var r=this.implementations[e];if(void 0!==r){const n=Bluebird.resolve(r);return n.isFulfilled()?new(n.value()):n.then(function(e){return Bluebird.attempt(function(){return new e})})}for(const o of this.factories){var i=o.create(e,this._registerFormElement,t);if(void 0!==i)return i}}run(r,i){const n=this;return Task.attempt(function(){let e;r instanceof ProgramInspector?e=r:(e=new ProgramInspector,e.import(r)),checkLicense(e.program,n.appSkuCode),i=Engine.buildOptions(e,i);var t=e.resolveStart(i?i.start:void 0);return run(n,e,i,t)})}}export{Engine};
1
+ import Bluebird from"bluebird";import{Activator}from"../Activator.js";import{getStringsForProgram}from"../LanguageStringUtils.js";import{Task}from"../Task.js";import{ProgramInspector,canonicalizeLocale}from"../definition/ProgramInspector.js";import{getCachedFormElements}from"../execution/ActivityLoader.js";import{BuiltInFormElements}from"../forms/manifest.js";import{check as checkLicense}from"../licensing/LicenseChecker.js";import{run}from"./ProgramRunner.js";class Engine{constructor(e){this._getFormElementRegistration=e=>this.formElements[e],this._registerFormElement=e=>{var t,r=e["id"];this.formElements[r]?(t={...this.formElements[r],...e},this.formElements[r]=t):this.formElements[r]=e},this.activator=new Activator,this.environment={},this.trivia={getFormElementRegistration:this._getFormElementRegistration,registerFormElement:this._registerFormElement},this.factories=[],this.implementations={},this.formElements={...getCachedFormElements(),...BuiltInFormElements},this.appSkuCode=e}static buildOptions(e,t){(t={...t||{}}).locale=canonicalizeLocale(t.locale),t.locale||(t.locale=e.getDefaultLocale()),t.logLevel=t.logLevel||"log";var r=new Proxy({},{get(e,t,r){return t}});const i=getStringsForProgram(e,t);return t.environment={activities:r,encodeHtml:function(e){return"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"):""},getText:function(e){if("string"==typeof e&&"@"===e.charAt(0)){var t=e.slice(1);if(t in i)return i[t]}return e},strings:i,...t.environment||{}},t}createHandler(e,t){var r=this.implementations[e];if(void 0!==r){const n=Bluebird.resolve(r);return n.isFulfilled()?new(n.value()):n.then(function(e){return Bluebird.attempt(function(){return new e})})}for(const o of this.factories){var i=o.create(e,this._registerFormElement,t);if(void 0!==i)return i}}run(r,i){const n=this;return Task.attempt(function(){let e;r instanceof ProgramInspector?e=r:(e=new ProgramInspector,e.import(r)),checkLicense(e.program,n.appSkuCode),i=Engine.buildOptions(e,i);var t=e.resolveStart(i?i.start:void 0);return run(n,e,i,t)})}}export{Engine};
@@ -1 +1 @@
1
- import{Task}from"../Task.js";import*as Activities from"../activities/main.js";const global=new Function("return this")();function getRequireString(){return"require"}async function load(e,o,i){"function"!=typeof o&&(o=global[getRequireString()]);var t=new Task(function(t){o([e],function(e){t(e),"function"==typeof i&&i(e)})});return Task.race([t,new Task((e,t)=>setTimeout(t,9e4))])}"function"!=typeof global.Promise&&(global.Promise=Promise);let nextId=0;const moduleNames={};function registerModuleName(e){let t=moduleNames[e];if(void 0!==t)return t;t=`@vertigis/workflow/externals/ext-${nextId++}`;var o="/"===e[e.length-1]?e.substring(0,e.length-1):e;return global[getRequireString()]({map:{"*":{"@geocortex/workflow":"@vertigis/workflow"}},paths:{[t]:o}}),moduleNames[e]=t}async function importModule(e,t,o){let i;return i="@vertigis/workflow/runtime/activities/main"===e?Activities:await load(e),void 0!==i&&null!==i&&"function"==typeof i.main?i.main.call(global,load,t,o):i}export{global,load,registerModuleName,importModule};
1
+ import{Task}from"../Task.js";import*as Activities from"../activities/main.js";const global=new Function("return this")();function getRequireString(){return"require"}async function load(e,o,i){"function"!=typeof o&&(o=global[getRequireString()]);var t=new Task(function(t){o([e],function(e){t(e),"function"==typeof i&&i(e)})});return Task.race([t,new Task((e,t)=>setTimeout(t,9e4))])}"function"!=typeof global.Promise&&(global.Promise=Promise);let nextId=0;const moduleNames={};function registerModuleName(e){let t=moduleNames[e];if(void 0!==t)return t;t=`@vertigis/workflow/externals/ext-${nextId++}`;var o="/"===e[e.length-1]?e.substring(0,e.length-1):e;return global[getRequireString()]({map:{"*":{"@geocortex/workflow":"@vertigis/workflow"}},paths:{[t]:o}}),moduleNames[e]=t}async function importModule(e,t,o){let i;return i="@vertigis/workflow/activities/main"===e?Activities:await load(e),void 0!==i&&null!==i&&"function"==typeof i.main?i.main.call(global,load,t,o):i}export{global,load,registerModuleName,importModule};
@@ -1 +1 @@
1
- import Bluebird from"bluebird";import{ActivityActivationError,ActivityBindingError,ActivityCancellationError,ActivityError,AggregateActivityError,EngineRuntimeError,ExpressionAccessorError,ExpressionEvaluationError,ExpressionSyntaxError,GenericActivityError,ProgramStartError}from"../Errors.js";import{query}from"../Hooks.js";import{Task}from"../Task.js";function isExpression(t){var e=t.type;return null==e&&"string"==typeof t.code}function createLinkedCancellationToken(t,e){const r=Task.race([new Task(e),t]),i=new AbortController;return r.signal=i.signal,r.finally(()=>i.abort()),r}function isInvalidHandler(t){return null==t||"function"!=typeof t.execute}function isLiteral(t){switch(typeof t){case"boolean":case"number":case"string":return!0}return!1}let evaluators={};function clearExpressionCache(){evaluators={}}const reservedIdentifiers=["resources","values","Date","Math","Object","parseInt","parseFloat","decodeURIComponent","encodeURIComponent"];function isAccessor(e){return!("string"!=typeof e||e.length<1)&&(!(0<=e.indexOf("."))&&!reservedIdentifiers.some(t=>t===e))}function compileExpression(t,e){var r=t.code;let i=evaluators[r];if(void 0===i){const s=[],o={};s.push('"use strict"; ');var n=t.accessors;if(Array.isArray(n))for(const a of n)isAccessor(a)&&!o[a]&&(s.push(`var ${a} = this.${a};`),o[a]=!0);s.push("return "),s.push(r),s.push(";"),i=evaluators[r]=new Function("resources","values",s.join(""))}return function(){return i.call(this,e,t.values)}}function echo(t){return t}const echoHandler={execute:echo};function combine(t,e){return{...t||{},...e||{}}}function isError(t){return void 0!==t}function filterErrors(t){return t.filter(isError)}function reduceErrors(t){return t.isPending()?t.then(filterErrors):t.isFulfilled()?Bluebird.resolve(filterErrors(t.value())):t}let nextSymbol,nextSymbolPrefix;function newSymbol(){return void 0!==nextSymbol&&1073741824<=nextSymbol&&(nextSymbol=void 0),void 0===nextSymbol&&(nextSymbol=0,nextSymbolPrefix=(new Date).valueOf()+":"),nextSymbolPrefix+nextSymbol++}const immediate=Bluebird.resolve(void 0);let guard=!0;class Proxy{constructor(t){Object.defineProperty(this,"target",{get(){if(!1===guard)return guard=!0,t}})}}class AmbientStateProxy extends Proxy{get outputs(){return guard=!1,this.target.outputs}set outputs(t){guard=!1,this.target.outputs=t}get error(){return guard=!1,this.target.error}set error(t){guard=!1,this.target.error=t}get completion(){return guard=!1,this.target.completion}complete(t){return guard=!1,this.target.complete(t)}reject(t){return guard=!1,this.target.reject(t)}get environment(){return guard=!1,this.target.environment}get inputs(){return guard=!1,this.target.inputs}get activityContexts(){return guard=!1,this.target.activityContexts}get locale(){return guard=!1,this.target.locale}get logLevel(){return guard=!1,this.target.logLevel}set logLevel(t){guard=!1,this.target.logLevel=t}get resources(){return guard=!1,this.target.resources}get trivia(){return guard=!1,this.target.trivia}}class ActivityContextProxy extends Proxy{get luid(){return guard=!1,this.target.luid}get ambient(){return guard=!1,this.target.ambient.proxy}get action(){return guard=!1,this.target.action}get branch(){return guard=!1,this.target.branch}get cancellationToken(){return guard=!1,this.target.cancellationToken}get passes(){return guard=!1,this.target.passes}get caught(){return guard=!1,this.target.caught}call(t){return guard=!1,this.target.call(t)}fork(t){return guard=!1,this.target.fork(t)}jump(t){return guard=!1,this.target.jump(t)}hasBranch(t){return guard=!1,this.target.hasBranch(t)}get state(){return guard=!1,this.target.state}registerForErrors(){return guard=!1,this.target.registerForErrors()}persist(t){return guard=!1,this.target.persist(t)}goto(){return guard=!1,this.target.goto()}}class AmbientState{constructor(){this.frame=new MonikerFrame,this.stack=[],this.handlers={}}get activityContexts(){const t={};for(const e of[...this.stack,this.frame])for(const r in e.state)"$$"===r.substring(0,2)&&(t[r]=e.state[r]);return t}break(){this.halted=!0}continue(){this.halted=!1,void 0!==this.scheduler&&!this.scheduler.isFulfilled()||(this.scheduler=immediate.then(t=>{this.execute()}))}execute(t){if(this.inline)return!1;this.inline=!0;try{void 0!==t&&t();const e=this.completion;for(;e.isPending();){if(this.halted)return!1;const r=this.frame.current.execute();if(r.isPending())break;r.isRejected()&&this.fail(r.reason())}}catch(t){this.fail(t)}finally{this.inline=!1}return!0}complete(t){this.completion.isPending()&&(this.cancellationResolve(),this.resolveCompletion(t||this.outputs))}reject(t){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(t||this.error))}fail(t){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(new EngineRuntimeError(t)))}cancel(){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(new ActivityCancellationError))}push(){const t=this.stack;t.push(this.frame);const e=this.frame=new MonikerFrame;return e.index=t.length,e}pop(t){const e=this.frame;if(void 0!==e){e.current=void 0;const i=e.cancellationResolve;void 0!==i&&i()}var r=this.frame=this.stack.pop();return void 0===r&&(void 0!==t?this.reject(t):this.complete()),r}call(){var t=this.frame;const e=this.push();e.cancellationToken=t.cancellationToken,e.state=t.state}fork(){const e=this.push();e.cancellationToken=createLinkedCancellationToken(this.cancellationToken,t=>e.cancellationResolve=t),e.state={}}bubble(t){let e=this.pop(t);for(;void 0!==e&&!e.current.registeredForErrors;)e=this.pop(t);var r;void 0!==e&&(r=e.current,this.start(r.activity,r,t))}next(){var t=this.queue.pop();void 0!==t?this.attempt(t):void 0!==(t=this.pop())&&(t=t.current,this.start(t.activity,t))}prepare(e,t,r){const i=e.frame=this.frame;if((i.current=e).luid=this.id+":"+e.activity.id,e.action=e.activity.action,e.ambient=this,e.id=newSymbol(),e.caught=r,e.cancellationToken=createLinkedCancellationToken(i.cancellationToken,t=>e.cancellationResolve=t),e.proxy=new ActivityContextProxy(e),void 0!==t){const n=e.recent=t.recent||(t.recent={});t=n.context||t;(n.context=e).passes=t.passes+1,e.stateToPersist=e.state=t.stateToPersist}else e.passes=0}attempt(t){const e=new TransitionContext;e.activity=t,e.branch=t.branch,this.prepare(e)}start(t,e,r){const i=new(t.async?AsyncContext:StepContext);i.activity=t,i.monikers.push("$"),this.prepare(i,e,r)}enqueue(t,e){const r=this.inspector;this.queue=r.relate(t,e).list(),this.next()}goto(t){for(var e=this.stack,r=t.index;e[r]===t;)this.pop();return t===this.frame}}class MonikerFrame{}class PromiseWrapper{}class ActivityContext{constructor(){this.inputs={},this.extras=[],this.monikers=[]}registerForErrors(){this.registeredForErrors=!0}persist(t){this.stateToPersist=t}call(t){this.callBranch=!0,this.forkBranch=!1,this.jumpBranch=t}fork(t){this.callBranch=!1,this.forkBranch=!0,this.jumpBranch=t}jump(t){this.callBranch=!1,this.forkBranch=!1,this.jumpBranch=t}hasBranch(t){var e=this.activity;const r=this.ambient.inspector;return r.isStep(e)&&void 0!==r.relate(e,t).peek()}emitExpressionEvaluationError(t,e){var r=this.activity.id,i=this.activity.inputs[t];return new ExpressionEvaluationError(r,t,i.source||i.code,e)}emitExpressionSyntaxError(t,e){var r=this.activity.id,i=this.activity.inputs[t];return new ExpressionSyntaxError(r,t,i.source||i.code,e)}emitExpressionAccessorError(t,e,r){return new ExpressionAccessorError(this.activity.id,t,e,r)}emitActivityBindingError(t){var e=this.activity;return new ActivityBindingError(e.id,e.action,t)}emitActivityActivationError(t,e){return new ActivityActivationError(this.activity.id,t,e)}emitActivityError(t){if(t instanceof ActivityError)return t;var e=this.activity;const r=new GenericActivityError(void 0,t?.message);return r.activityId=e.id,r.error=t,r}executeHandlerInline(e){if(0<e.length||this.cancellationToken.isFulfilled())return e;const r=this.extras;for(let t=0;t<r.length;t++)r[t]=Bluebird.resolve(r[t]).value();const i=this.inputs;for(const o in i){let t=Bluebird.resolve(i[o]).value();t instanceof PromiseWrapper&&(t=t.result),i[o]=t}const t=this.proxy,n=this.handler.value(),s=Bluebird.attempt(function(){return n.execute(i,t,...r)});return s.isPending()?s.then(t=>(this.outputs=t,e),t=>[this.emitActivityError(t)]):s.isRejected()?[this.emitActivityError(s.reason())]:(this.outputs=s.value(),e)}resolveExtrasInline(){for(const e of query(this.handler.value())){const t=this.ambient.engine.activator,r=t.activate(e);if(this.extras.push(r),r.isPending())return r.then(t=>{},t=>this.emitActivityActivationError(e.type,t));if(r.isRejected())return this.emitActivityActivationError(e.type,r.reason())}}resolveInputsInline(t){if(0<t.length||this.cancellationToken.isFulfilled())return t;const e=[];e.push(this.resolveExtrasInline());const r=this.evaluators;if(void 0!==r){const i=this.scope;for(const s in i)i[s]=Bluebird.resolve(i[s]).value();const n=this.inputs;for(const o in r){const a=n[o]=Bluebird.attempt(function(){var t=r[o].call(i);if(t&&"function"==typeof t.then){const e=new PromiseWrapper;return e.result=t,e}return t});a.isPending()&&e.push(a.then(t=>{},t=>this.emitExpressionEvaluationError(o,t))),a.isRejected()&&e.push(this.emitExpressionEvaluationError(o,a.reason()))}}return reduceErrors(Bluebird.all(e))}resolveHandlerInline(){const e=this.activity.action;if("string"==typeof e){var r=this.ambient;const i=r.handlers;let t=this.handler=i[e];if(void 0===t){const n=r.engine,s=r.inspector;t=this.handler=i[e]=Bluebird.attempt(function(){return n.createHandler(e,s)})}return t.isPending()?t.then(t=>isInvalidHandler(t)?this.emitActivityBindingError():void 0,t=>this.emitActivityBindingError(t)):t.isRejected()?this.emitActivityBindingError(t.reason()):isInvalidHandler(t.value())?this.emitActivityBindingError():void 0}this.handler=Bluebird.resolve(echoHandler)}findContext(t){var e=this.ambient,r=e.stack;let i=e.frame;for(;void 0!==i;){var n=i.state[t];if(void 0!==n)return n;i=r[i.index-1]}}resolveOutputsInline(){const t=this.promise;if(t.isPending())return t.then(t=>void 0!==t&&0<t.length?Bluebird.reject(t):this.outputs,t=>{});if(t.isRejected())return immediate;var e=t.value();return void 0!==e&&0<e.length?Bluebird.reject(e):Bluebird.resolve(this.outputs)}resolveAccessorInline(e){const t=this.findContext(e);if(void 0!==t){const r=this.scope[e]=t.resolveOutputsInline();return r.isPending()?r.then(t=>{},t=>this.emitExpressionAccessorError(e,void 0,t)):r.isRejected()?this.emitExpressionAccessorError(e,void 0,r.reason()):void 0}const r=this.scope[e]=Bluebird.resolve(this.ambient.environment[e]);return r.isPending()?r.then(t=>{},t=>this.emitExpressionAccessorError(e,t)):r.isRejected()?this.emitExpressionAccessorError(e,r.reason()):void 0}resolveAssetsInline(){const r=[];r.push(this.resolveHandlerInline());var i=this.activity.inputs;if(null!=i){let t,e;const s=this.ambient;for(const o in i){const a=i[o];if(void 0!==a&&null!==a)if(isLiteral(a))this.inputs[o]=Bluebird.resolve(a);else if(isExpression(a)){void 0===t&&(this.scope=t={}),void 0===e&&(this.evaluators=e={});var n=a.accessors;if(Array.isArray(n))for(const l of n)"string"==typeof l&&void 0===t[l]&&r.push(this.resolveAccessorInline(l));const c=Bluebird.attempt(function(){return compileExpression(a,s.resources)});c.isFulfilled()?e[o]=c.value():r.push(this.emitExpressionSyntaxError(o,c.reason()))}else r.push(this.emitExpressionSyntaxError(o))}}return reduceErrors(Bluebird.all(r))}concludeInline(t){return this.cancellationResolve(),t}generateMonikers(){const t=this.monikers;var e=this.activity;t.push("$"+e.id),"string"==typeof e.name&&t.push("$"+e.name);const r=e.action;"string"!=typeof r||1<(e=r.split(":")).length&&(0<(e=e[e.length-2]).length&&t.push("$$"+e))}marshalError(){var t=this.promise.value();return 1<t.length?new AggregateActivityError(this.activity.id,t):0<t.length?t[0]:void 0}execute(){let t=this.promise;const e=this.ambient;if(void 0!==t)return e.debug(e),e.halted||this.transferInline(),t;{if(t=this.resolveAssetsInline(),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.resolveInputsInline(t)):Bluebird.resolve(this.resolveInputsInline(t.value())),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.executeHandlerInline(t)):Bluebird.resolve(this.executeHandlerInline(t.value())),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.concludeInline(t)):Bluebird.resolve(this.concludeInline(t.value())),t.isRejected())return t;t.isPending()&&(t=t.catch(t=>e.fail(t)),t.then(t=>e.execute())),this.generateMonikers();const r=e.frame.state;for(const i of this.monikers)r[i]=this;return this.promise=t,immediate}}goto(){}}class StepContext extends ActivityContext{transferInline(){const t=this.promise;if(t.isFulfilled()){const r=this.ambient;var e=this.marshalError();void 0!==e?r.bubble(e):this.repeat?r.start(this.activity,this):(this.callBranch&&r.call(),this.forkBranch&&r.fork(),r.enqueue(this.activity,this.jumpBranch))}}goto(){const t=this.frame,e=this.ambient;if(e.goto(t)){var r=this.recent;const i=void 0!==r?r.context:this;t.current=i,i.repeat=!0,e.halted=!1,e.execute()}}}class TransitionContext extends ActivityContext{test(){let t=void 0,e=void 0;var r=this.outputs;for(const i in r){if(void 0!==t&&void 0!==e)return!1;if(e=r[i],!isLiteral(e))return!1;if(void 0===t)t=e,e=void 0;else if(t!==e)return!1}return void 0===t||(void 0!==e||("boolean"==typeof t?t:"number"==typeof t?0<t:"string"==typeof t&&0<t.length))}transferInline(){const t=this.promise;if(t.isFulfilled()){const r=this.ambient;var e=this.marshalError();void 0!==e?r.bubble(e):this.test()?r.start(this.activity.target):r.next()}}}class AsyncContext extends ActivityContext{transferInline(){this.ambient.enqueue(this.activity)}execute(){return super.execute(),immediate}}function run(n,s,o,a){const c=t=>{var e=s.findStep(t);if(!e)throw new GenericActivityError(`The workflow does not contain a step with the id ${t}.`);return e},l=()=>{const e=v.frame.current.action;return s.allReferences().filter(t=>t.suite&&e.startsWith(t.suite)).peek()?.path},u=(t,e,r,i)=>{t=c(t);const n=c(e);if(!n.transitions.some(t=>"content"===t.branch||"try"===t.branch))throw new GenericActivityError(`The ${e} step is not a Container, Subworkflow, or Try Catch activity.`);r=`${i}$${r}`;d(t,n,r)},h=t=>{var e=v.frame.current.activity,r=c(t);if("gcx:wf:core::Subworkflow"!==r.action)throw new GenericActivityError(`The target step ${t} is not a Subworkflow activity.`);d(e,r,"default")},d=(t,e,r)=>{var i=s.relate(t,r).peek();void 0!==i&&s.remove(i);const n=s.addTransition(t,e);n.branch=r},v=new AmbientState;return v.completion=new Bluebird((t,e)=>{v.resolveCompletion=t,v.rejectCompletion=e}),v.cancellationToken=new Task(t=>v.cancellationResolve=t),v.execute(function(){if(s.isStep(a)){o=o||{},v.engine=n,v.inspector=s,v.id=newSymbol(),v.debug=o.debug||(()=>{}),v.environment=combine(n.environment,o.environment),v.inputs=o.inputs||{},v.locale=o.locale,v.logLevel=o.logLevel,v.resources={forms:s.cacheForms()},v.outputs={},v.trivia=combine(n.trivia,o.trivia),v.trivia.getActivityPackUrl=l,v.trivia.setFormElementEvent=u,v.trivia.setSubworkflowTransition=h,v.proxy=new AmbientStateProxy(v);const e=v.trivia.isDescendantOf;e?v.trivia.isDescendantOf=t=>t===v.proxy||e(t):v.trivia.isDescendantOf=t=>t===v.proxy;const r=v.frame;r.index=0,r.cancellationToken=v.cancellationToken,r.state=o.state||{};var t=o.cancellationToken;if(null!=t){const i=Task.race([t,v.cancellationToken]);i.isPending()?(t=()=>v.cancel(),i.then(t,t)):v.cancel()}v.start(a)}else v.reject(new ProgramStartError)}),v.completion}export{clearExpressionCache,run};
1
+ import Bluebird from"bluebird";import{ActivityActivationError,ActivityBindingError,ActivityCancellationError,ActivityError,AggregateActivityError,EngineRuntimeError,ExpressionAccessorError,ExpressionEvaluationError,ExpressionSyntaxError,GenericActivityError,ProgramStartError}from"../Errors.js";import{query}from"../Hooks.js";import{Task}from"../Task.js";function isExpression(t){var e=t.type;return null==e&&"string"==typeof t.code}function createLinkedCancellationToken(t,e){const r=Task.race([new Task(e),t]),i=new AbortController;return r.signal=i.signal,r.finally(()=>i.abort()),r}function isInvalidHandler(t){return null==t||"function"!=typeof t.execute}function isLiteral(t){switch(typeof t){case"boolean":case"number":case"string":return!0}return!1}let evaluators={};function clearExpressionCache(){evaluators={}}const reservedIdentifiers=["resources","values","Date","JSON","Math","Object","parseInt","parseFloat","decodeURIComponent","encodeURIComponent"];function isAccessor(e){return!("string"!=typeof e||e.length<1)&&(!(0<=e.indexOf("."))&&!reservedIdentifiers.some(t=>t===e))}function compileExpression(t,e){var r=t.code;let i=evaluators[r];if(void 0===i){const s=[],o={};s.push('"use strict"; ');var n=t.accessors;if(Array.isArray(n))for(const a of n)isAccessor(a)&&!o[a]&&(s.push(`var ${a} = this.${a};`),o[a]=!0);s.push("return "),s.push(r),s.push(";"),i=evaluators[r]=new Function("resources","values",s.join(""))}return function(){return i.call(this,e,t.values)}}function echo(t){return t}const echoHandler={execute:echo};function combine(t,e){return{...t||{},...e||{}}}function isError(t){return void 0!==t}function filterErrors(t){return t.filter(isError)}function reduceErrors(t){return t.isPending()?t.then(filterErrors):t.isFulfilled()?Bluebird.resolve(filterErrors(t.value())):t}let nextSymbol,nextSymbolPrefix;function newSymbol(){return void 0!==nextSymbol&&1073741824<=nextSymbol&&(nextSymbol=void 0),void 0===nextSymbol&&(nextSymbol=0,nextSymbolPrefix=(new Date).valueOf()+":"),nextSymbolPrefix+nextSymbol++}const immediate=Bluebird.resolve(void 0);let guard=!0;class Proxy{constructor(t){Object.defineProperty(this,"target",{get(){if(!1===guard)return guard=!0,t}})}}class AmbientStateProxy extends Proxy{get outputs(){return guard=!1,this.target.outputs}set outputs(t){guard=!1,this.target.outputs=t}get error(){return guard=!1,this.target.error}set error(t){guard=!1,this.target.error=t}get completion(){return guard=!1,this.target.completion}complete(t){return guard=!1,this.target.complete(t)}reject(t){return guard=!1,this.target.reject(t)}get environment(){return guard=!1,this.target.environment}get inputs(){return guard=!1,this.target.inputs}get activityContexts(){return guard=!1,this.target.activityContexts}get locale(){return guard=!1,this.target.locale}get logLevel(){return guard=!1,this.target.logLevel}set logLevel(t){guard=!1,this.target.logLevel=t}get resources(){return guard=!1,this.target.resources}get trivia(){return guard=!1,this.target.trivia}}class ActivityContextProxy extends Proxy{get luid(){return guard=!1,this.target.luid}get ambient(){return guard=!1,this.target.ambient.proxy}get action(){return guard=!1,this.target.action}get branch(){return guard=!1,this.target.branch}get cancellationToken(){return guard=!1,this.target.cancellationToken}get passes(){return guard=!1,this.target.passes}get caught(){return guard=!1,this.target.caught}call(t){return guard=!1,this.target.call(t)}fork(t){return guard=!1,this.target.fork(t)}jump(t){return guard=!1,this.target.jump(t)}hasBranch(t){return guard=!1,this.target.hasBranch(t)}get state(){return guard=!1,this.target.state}registerForErrors(){return guard=!1,this.target.registerForErrors()}persist(t){return guard=!1,this.target.persist(t)}goto(){return guard=!1,this.target.goto()}}class AmbientState{constructor(){this.frame=new MonikerFrame,this.stack=[],this.handlers={}}get activityContexts(){const t={};for(const e of[...this.stack,this.frame])for(const r in e.state)"$$"===r.substring(0,2)&&(t[r]=e.state[r]);return t}break(){this.halted=!0}continue(){this.halted=!1,void 0!==this.scheduler&&!this.scheduler.isFulfilled()||(this.scheduler=immediate.then(t=>{this.execute()}))}execute(t){if(this.inline)return!1;this.inline=!0;try{void 0!==t&&t();const e=this.completion;for(;e.isPending();){if(this.halted)return!1;const r=this.frame.current.execute();if(r.isPending())break;r.isRejected()&&this.fail(r.reason())}}catch(t){this.fail(t)}finally{this.inline=!1}return!0}complete(t){this.completion.isPending()&&(this.cancellationResolve(),this.resolveCompletion(t||this.outputs))}reject(t){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(t||this.error))}fail(t){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(new EngineRuntimeError(t)))}cancel(){this.completion.isPending()&&(this.cancellationResolve(),this.rejectCompletion(new ActivityCancellationError))}push(){const t=this.stack;t.push(this.frame);const e=this.frame=new MonikerFrame;return e.index=t.length,e}pop(t){const e=this.frame;if(void 0!==e){e.current=void 0;const i=e.cancellationResolve;void 0!==i&&i()}var r=this.frame=this.stack.pop();return void 0===r&&(void 0!==t?this.reject(t):this.complete()),r}call(){var t=this.frame;const e=this.push();e.cancellationToken=t.cancellationToken,e.state=t.state}fork(){const e=this.push();e.cancellationToken=createLinkedCancellationToken(this.cancellationToken,t=>e.cancellationResolve=t),e.state={}}bubble(t){let e=this.pop(t);for(;void 0!==e&&!e.current.registeredForErrors;)e=this.pop(t);var r;void 0!==e&&(r=e.current,this.start(r.activity,r,t))}next(){var t=this.queue.pop();void 0!==t?this.attempt(t):void 0!==(t=this.pop())&&(t=t.current,this.start(t.activity,t))}prepare(e,t,r){const i=e.frame=this.frame;if((i.current=e).luid=this.id+":"+e.activity.id,e.action=e.activity.action,e.ambient=this,e.id=newSymbol(),e.caught=r,e.cancellationToken=createLinkedCancellationToken(i.cancellationToken,t=>e.cancellationResolve=t),e.proxy=new ActivityContextProxy(e),void 0!==t){const n=e.recent=t.recent||(t.recent={});t=n.context||t;(n.context=e).passes=t.passes+1,e.stateToPersist=e.state=t.stateToPersist}else e.passes=0}attempt(t){const e=new TransitionContext;e.activity=t,e.branch=t.branch,this.prepare(e)}start(t,e,r){const i=new(t.async?AsyncContext:StepContext);i.activity=t,i.monikers.push("$"),this.prepare(i,e,r)}enqueue(t,e){const r=this.inspector;this.queue=r.relate(t,e).list(),this.next()}goto(t){for(var e=this.stack,r=t.index;e[r]===t;)this.pop();return t===this.frame}}class MonikerFrame{}class PromiseWrapper{}class ActivityContext{constructor(){this.inputs={},this.extras=[],this.monikers=[]}registerForErrors(){this.registeredForErrors=!0}persist(t){this.stateToPersist=t}call(t){this.callBranch=!0,this.forkBranch=!1,this.jumpBranch=t}fork(t){this.callBranch=!1,this.forkBranch=!0,this.jumpBranch=t}jump(t){this.callBranch=!1,this.forkBranch=!1,this.jumpBranch=t}hasBranch(t){var e=this.activity;const r=this.ambient.inspector;return r.isStep(e)&&void 0!==r.relate(e,t).peek()}emitExpressionEvaluationError(t,e){var r=this.activity.id,i=this.activity.inputs[t];return new ExpressionEvaluationError(r,t,i.source||i.code,e)}emitExpressionSyntaxError(t,e){var r=this.activity.id,i=this.activity.inputs[t];return new ExpressionSyntaxError(r,t,i.source||i.code,e)}emitExpressionAccessorError(t,e,r){return new ExpressionAccessorError(this.activity.id,t,e,r)}emitActivityBindingError(t){var e=this.activity;return new ActivityBindingError(e.id,e.action,t)}emitActivityActivationError(t,e){return new ActivityActivationError(this.activity.id,t,e)}emitActivityError(t){if(t instanceof ActivityError)return t;var e=this.activity;const r=new GenericActivityError(void 0,t?.message);return r.activityId=e.id,r.error=t,r}executeHandlerInline(e){if(0<e.length||this.cancellationToken.isFulfilled())return e;const r=this.extras;for(let t=0;t<r.length;t++)r[t]=Bluebird.resolve(r[t]).value();const i=this.inputs;for(const o in i){let t=Bluebird.resolve(i[o]).value();t instanceof PromiseWrapper&&(t=t.result),i[o]=t}const t=this.proxy,n=this.handler.value(),s=Bluebird.attempt(function(){return n.execute(i,t,...r)});return s.isPending()?s.then(t=>(this.outputs=t,e),t=>[this.emitActivityError(t)]):s.isRejected()?[this.emitActivityError(s.reason())]:(this.outputs=s.value(),e)}resolveExtrasInline(){for(const e of query(this.handler.value())){const t=this.ambient.engine.activator,r=t.activate(e);if(this.extras.push(r),r.isPending())return r.then(t=>{},t=>this.emitActivityActivationError(e.type,t));if(r.isRejected())return this.emitActivityActivationError(e.type,r.reason())}}resolveInputsInline(t){if(0<t.length||this.cancellationToken.isFulfilled())return t;const e=[];e.push(this.resolveExtrasInline());const r=this.evaluators;if(void 0!==r){const i=this.scope;for(const s in i)i[s]=Bluebird.resolve(i[s]).value();const n=this.inputs;for(const o in r){const a=n[o]=Bluebird.attempt(function(){var t=r[o].call(i);if(t&&"function"==typeof t.then){const e=new PromiseWrapper;return e.result=t,e}return t});a.isPending()&&e.push(a.then(t=>{},t=>this.emitExpressionEvaluationError(o,t))),a.isRejected()&&e.push(this.emitExpressionEvaluationError(o,a.reason()))}}return reduceErrors(Bluebird.all(e))}resolveHandlerInline(){const e=this.activity.action;if("string"==typeof e){var r=this.ambient;const i=r.handlers;let t=this.handler=i[e];if(void 0===t){const n=r.engine,s=r.inspector;t=this.handler=i[e]=Bluebird.attempt(function(){return n.createHandler(e,s)})}return t.isPending()?t.then(t=>isInvalidHandler(t)?this.emitActivityBindingError():void 0,t=>this.emitActivityBindingError(t)):t.isRejected()?this.emitActivityBindingError(t.reason()):isInvalidHandler(t.value())?this.emitActivityBindingError():void 0}this.handler=Bluebird.resolve(echoHandler)}findContext(t){var e=this.ambient,r=e.stack;let i=e.frame;for(;void 0!==i;){var n=i.state[t];if(void 0!==n)return n;i=r[i.index-1]}}resolveOutputsInline(){const t=this.promise;if(t.isPending())return t.then(t=>void 0!==t&&0<t.length?Bluebird.reject(t):this.outputs,t=>{});if(t.isRejected())return immediate;var e=t.value();return void 0!==e&&0<e.length?Bluebird.reject(e):Bluebird.resolve(this.outputs)}resolveAccessorInline(e){const t=this.findContext(e);if(void 0!==t){const r=this.scope[e]=t.resolveOutputsInline();return r.isPending()?r.then(t=>{},t=>this.emitExpressionAccessorError(e,void 0,t)):r.isRejected()?this.emitExpressionAccessorError(e,void 0,r.reason()):void 0}const r=this.scope[e]=Bluebird.resolve(this.ambient.environment[e]);return r.isPending()?r.then(t=>{},t=>this.emitExpressionAccessorError(e,t)):r.isRejected()?this.emitExpressionAccessorError(e,r.reason()):void 0}resolveAssetsInline(){const r=[];r.push(this.resolveHandlerInline());var i=this.activity.inputs;if(null!=i){let t,e;const s=this.ambient;for(const o in i){const a=i[o];if(void 0!==a&&null!==a)if(isLiteral(a))this.inputs[o]=Bluebird.resolve(a);else if(isExpression(a)){void 0===t&&(this.scope=t={}),void 0===e&&(this.evaluators=e={});var n=a.accessors;if(Array.isArray(n))for(const l of n)"string"==typeof l&&void 0===t[l]&&r.push(this.resolveAccessorInline(l));const c=Bluebird.attempt(function(){return compileExpression(a,s.resources)});c.isFulfilled()?e[o]=c.value():r.push(this.emitExpressionSyntaxError(o,c.reason()))}else r.push(this.emitExpressionSyntaxError(o))}}return reduceErrors(Bluebird.all(r))}concludeInline(t){return this.cancellationResolve(),t}generateMonikers(){const t=this.monikers;var e=this.activity;t.push("$"+e.id),"string"==typeof e.name&&t.push("$"+e.name);const r=e.action;"string"!=typeof r||1<(e=r.split(":")).length&&(0<(e=e[e.length-2]).length&&t.push("$$"+e))}marshalError(){var t=this.promise.value();return 1<t.length?new AggregateActivityError(this.activity.id,t):0<t.length?t[0]:void 0}execute(){let t=this.promise;const e=this.ambient;if(void 0!==t)return e.debug(e),e.halted||this.transferInline(),t;{if(t=this.resolveAssetsInline(),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.resolveInputsInline(t)):Bluebird.resolve(this.resolveInputsInline(t.value())),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.executeHandlerInline(t)):Bluebird.resolve(this.executeHandlerInline(t.value())),t.isRejected())return t;if(t=t.isPending()?t.then(t=>this.concludeInline(t)):Bluebird.resolve(this.concludeInline(t.value())),t.isRejected())return t;t.isPending()&&(t=t.catch(t=>e.fail(t)),t.then(t=>e.execute())),this.generateMonikers();const r=e.frame.state;for(const i of this.monikers)r[i]=this;return this.promise=t,immediate}}goto(){}}class StepContext extends ActivityContext{transferInline(){const t=this.promise;if(t.isFulfilled()){const r=this.ambient;var e=this.marshalError();void 0!==e?r.bubble(e):this.repeat?r.start(this.activity,this):(this.callBranch&&r.call(),this.forkBranch&&r.fork(),r.enqueue(this.activity,this.jumpBranch))}}goto(){const t=this.frame,e=this.ambient;if(e.goto(t)){var r=this.recent;const i=void 0!==r?r.context:this;t.current=i,i.repeat=!0,e.halted=!1,e.execute()}}}class TransitionContext extends ActivityContext{test(){let t=void 0,e=void 0;var r=this.outputs;for(const i in r){if(void 0!==t&&void 0!==e)return!1;if(e=r[i],!isLiteral(e))return!1;if(void 0===t)t=e,e=void 0;else if(t!==e)return!1}return void 0===t||(void 0!==e||("boolean"==typeof t?t:"number"==typeof t?0<t:"string"==typeof t&&0<t.length))}transferInline(){const t=this.promise;if(t.isFulfilled()){const r=this.ambient;var e=this.marshalError();void 0!==e?r.bubble(e):this.test()?r.start(this.activity.target):r.next()}}}class AsyncContext extends ActivityContext{transferInline(){this.ambient.enqueue(this.activity)}execute(){return super.execute(),immediate}}function run(n,s,o,a){const c=t=>{var e=s.findStep(t);if(!e)throw new GenericActivityError(`The workflow does not contain a step with the id ${t}.`);return e},l=()=>{const e=v.frame.current.action;return s.allReferences().filter(t=>t.suite&&e.startsWith(t.suite)).peek()?.path},u=(t,e,r,i)=>{t=c(t);const n=c(e);if(!n.transitions.some(t=>"content"===t.branch||"try"===t.branch))throw new GenericActivityError(`The ${e} step is not a Container, Subworkflow, or Try Catch activity.`);r=`${i}$${r}`;d(t,n,r)},h=t=>{var e=v.frame.current.activity,r=c(t);if("gcx:wf:core::Subworkflow"!==r.action)throw new GenericActivityError(`The target step ${t} is not a Subworkflow activity.`);d(e,r,"default")},d=(t,e,r)=>{var i=s.relate(t,r).peek();void 0!==i&&s.remove(i);const n=s.addTransition(t,e);n.branch=r},v=new AmbientState;return v.completion=new Bluebird((t,e)=>{v.resolveCompletion=t,v.rejectCompletion=e}),v.cancellationToken=new Task(t=>v.cancellationResolve=t),v.execute(function(){if(s.isStep(a)){o=o||{},v.engine=n,v.inspector=s,v.id=newSymbol(),v.debug=o.debug||(()=>{}),v.environment=combine(n.environment,o.environment),v.inputs=o.inputs||{},v.locale=o.locale,v.logLevel=o.logLevel,v.resources={forms:s.cacheForms()},v.outputs={},v.trivia=combine(n.trivia,o.trivia),v.trivia.getActivityPackUrl=l,v.trivia.setFormElementEvent=u,v.trivia.setSubworkflowTransition=h,v.proxy=new AmbientStateProxy(v);const e=v.trivia.isDescendantOf;e?v.trivia.isDescendantOf=t=>t===v.proxy||e(t):v.trivia.isDescendantOf=t=>t===v.proxy;const r=v.frame;r.index=0,r.cancellationToken=v.cancellationToken,r.state=o.state||{};var t=o.cancellationToken;if(null!=t){const i=Task.race([t,v.cancellationToken]);i.isPending()?(t=()=>v.cancel(),i.then(t,t)):v.cancel()}v.start(a)}else v.reject(new ProgramStartError)}),v.completion}export{clearExpressionCache,run};
@@ -3,6 +3,22 @@ import * as defs from "./FormDefinition";
3
3
  import { FormPresenterHost } from "./FormPresenterHost";
4
4
  import type { FormElementProps, FormElementRegistration } from "./index";
5
5
  export { FormPresenterHost };
6
+ export interface EventValueTypes {
7
+ changed: defs.Value | undefined;
8
+ cancel: string;
9
+ clicked: defs.Value | undefined;
10
+ custom: any;
11
+ dragged: defs.NumberRef | number[];
12
+ suggest: defs.Value | undefined;
13
+ }
14
+ export interface EventArgumentTypes {
15
+ changed: boolean | string;
16
+ cancel: never;
17
+ clicked: undefined;
18
+ custom: any;
19
+ dragged: never;
20
+ suggest: string;
21
+ }
6
22
  export interface FormComponentProps {
7
23
  host: FormPresenterHost;
8
24
  type?: "form" | "body" | "row" | "header" | "main" | "footer" | "element" | "section" | "accordionGroup";
@@ -19,8 +35,9 @@ export declare class FormComponent extends Component<FormComponentProps, {}> {
19
35
  private get element();
20
36
  prepare(): defs.Element;
21
37
  render(): any;
22
- raiseEvent: (eventName: "cancel" | "changed" | "clicked" | "custom", eventValue: any) => void;
38
+ raiseEvent: <K extends keyof EventValueTypes>(eventName: K, eventValue: EventValueTypes[K], argument?: EventArgumentTypes[K], item?: string, cancellationToken?: PromiseLike<void> | undefined) => void;
23
39
  setProperty: FormElementProps<any>["setProperty"];
40
+ setItemProperty: FormElementProps<any>["setItemProperty"];
24
41
  setValue: FormElementProps["setValue"];
25
42
  }
26
43
  export declare class FormElementComponent extends FormComponent {
@@ -1 +1 @@
1
- import{Component}from"react";import{makeId}from"./utils.js";class FormComponent extends Component{constructor(){super(...arguments),this.raiseEvent=(e,t)=>this.props.host?.post(e,{name:this.props.name,value:t}),this.setProperty=(e,t)=>{const s=this.props.host;var n=this.props.name;s.assignElementProperty(n,e,t)},this.setValue=e=>this.setProperty("value",e)}get elementRegistration(){const e=this.props["host"];if(isFormRenderer(e))return e.getElementRegistration(this.element)}get element(){const{host:e,name:t}=this.props;if(t)return e.find(t)}prepare(){var e;void 0===this.id&&(this.id=makeId()),this.enabled=!0;const t=this.props.host;return!1===t.enabled&&(this.enabled=!1),void 0!==this.element&&(void 0!==(e=t.find(this.element.section))&&!1===e.enabled&&(this.enabled=!1),!1===this.element.enabled&&(this.enabled=!1)),this.element}render(){return this.props.host.renderVisual(this)}}class FormElementComponent extends FormComponent{componentDidMount(){const e=this.props;e.host.refs[e.name]=this}componentDidUpdate(){const e=this.props;e.host.refs[e.name]=this}componentWillUnmount(){const e=this.props;e.host.refs[e.name]=void 0}}function isFormRenderer(e){return!!e&&"function"==typeof e.getElementRegistration}export{FormComponent,FormElementComponent};
1
+ import{Component}from"react";import{makeId}from"./utils.js";class FormComponent extends Component{constructor(){super(...arguments),this.raiseEvent=(e,t,s,n,o)=>this.props.host?.post(e,{name:this.props.name,value:t,argument:s,item:n,cancellationToken:o}),this.setProperty=(e,t,s=!0)=>{const n=this.props.host;var o=this.props.name;n.assignElementProperty(o,e,t,void 0,s)},this.setItemProperty=(e,t,s,n)=>{const o=this.props.host;var r=this.props.name;o.assignElementItemProperty(r,e,t,s,n)},this.setValue=(e,t=!0)=>this.setProperty("value",e,t)}get elementRegistration(){const e=this.props["host"];if(isFormRenderer(e))return e.getElementRegistration(this.element)}get element(){const{host:e,name:t}=this.props;if(t)return e.find(t)}prepare(){var e;void 0===this.id&&(this.id=makeId()),this.enabled=!0;const t=this.props.host;return!1===t.enabled&&(this.enabled=!1),void 0!==this.element&&(void 0!==(e=t.find(this.element.section))&&!1===e.enabled&&(this.enabled=!1),!1===this.element.enabled&&(this.enabled=!1)),this.element}render(){return this.props.host.renderVisual(this)}}class FormElementComponent extends FormComponent{componentDidMount(){const e=this.props;e.host.refs[e.name]=this}componentDidUpdate(){const e=this.props;e.host.refs[e.name]=this}componentWillUnmount(){const e=this.props;e.host.refs[e.name]=void 0}}function isFormRenderer(e){return!!e&&"function"==typeof e.getElementRegistration}export{FormComponent,FormElementComponent};
@@ -131,11 +131,6 @@ export declare type TitleLocation = "above" | "beside";
131
131
  export declare type Value = boolean | number | number[] | string | DataRef | DateRangeRef | DateTimeRef | FilesRef | GeometryRef | ItemsRef | NumberRef | ScanRef | SignatureRef;
132
132
  /** Types of matching that can be performed when finding an Item within a Form Element. */
133
133
  export declare type ItemMatchType = "index" | "item" | "key" | "label" | "value";
134
- /**
135
- * References what kind of elements exist.
136
- * @product This is intended for internal use only within VertiGIS Studio products.
137
- */
138
- export declare type ElementType = "DropDownEdit" | "DropDownList" | "GeometryPicker" | "Header";
139
134
  /** References the format types. */
140
135
  export declare type FormatRef = DateTimeFormat | NumberFormat | GeometryFormat | SectionFormat;
141
136
  /** References the date/time type. */
@@ -346,7 +341,7 @@ export interface Element {
346
341
  /** Indicates the tooltip for the element. */
347
342
  tooltip?: Text;
348
343
  /** Indicates the type of the element. */
349
- type?: ElementType | string;
344
+ type?: string;
350
345
  /** Indicates if the element triggers validation when submitting. */
351
346
  validates?: boolean;
352
347
  /** Indicates the current value. */
@@ -208,8 +208,6 @@ export declare abstract class FormHost implements FormPresenterHost {
208
208
  coerceNumber(value: string): number;
209
209
  /** Formats a number. */
210
210
  formatNumber(value: number, options?: FormatOptions): string;
211
- /** Renders a custom element. */
212
- renderCustom(component: {}, element: defs.Element): JSX.Element;
213
211
  /** Renders a component's state. */
214
212
  renderState(name: string, type: "geometry", state?: defs.GeometryState[]): boolean;
215
213
  /** Renders a component's state. */
package/forms/FormHost.js CHANGED
@@ -1 +1 @@
1
- import Bluebird from"bluebird";import{Task}from"../Task.js";import{DEFAULT_LOCALE}from"../constants.js";import{FormComponent}from"./FormComponent.js";import*as defs from"./FormDefinition.js";import MutuallyExclusiveSectionGroup from"./MutuallyExclusiveSectionGroup.js";import NumberParser from"./NumberParser.js";import{FormElementTypes}from"./constants.js";import{format}from"./numberFormatter.js";import*as presenter from"./presenter.js";import{renderElement}from"./renderers.js";import{sort,text}from"./utils.js";const guid="C0166F74-982A-464E-9FB6-9605CB7649C1:",eventName=guid+"FormEvent";function createEvent(e,t){return new CustomEvent(e,{bubbles:!1,cancelable:!1,detail:t})}function overlay(i,s){switch(typeof i){case"boolean":case"number":case"string":return i;case"object":break;default:return s}if(null===i)return s;if(i instanceof Array){let e=s;void 0!==e&&null!==e||(e=[]);let t=0;for(const r of i){var n=overlay(r,e[t]);void 0!==n&&(t<i.length?e[t]=n:e.push(n),++t)}return e}let e=s;void 0===e&&(e={});for(const t in i)e[t]=overlay(i[t],e[t]);return e}function createSubscription(e){function t(){return void 0!==e&&(t.active=!1,e(),!0)}return t.active=!0,t}class FormHost{constructor(){this.form={defaults:{},elements:{}},this.errors={},this.refs={},this.enabled=!1,this.visible=!1,this.dismiss=!1,this.custom=!1,this.container=document.createElement("div"),this.eventIndex=0,this.eventQueue=[],this.mutuallyExclusiveSections={},this.nextFocus=!1,this.nextRefresh=!1,this.style=void 0}deriveLocale(){return DEFAULT_LOCALE}mount(){var e=this.container,t=e.parentNode;null==t&&document.body.appendChild(e),this.update()}unmount(){var e=this.container;const t=e.parentNode;void 0!==t&&null!==t&&t.removeChild(e)}observeFocus(e){this.enabled&&e instanceof HTMLElement&&(this.lastFocus&&this.lastFocus.target===e||this.setLastFocus(e))}focus(e){!0===(e=null==e?!1:e)&&(this.lastFocus=void 0),!1===e&&!1===(e=this.nextFocus)&&(e=!0),this.nextFocus=e,this.invalidate(!0!==e?e:void 0)}show(){const e=this.container;if(void 0===e)return!1;this.custom||void 0!==this.focusObserver||e.addEventListener("focus",this.focusObserver=e=>this.observeFocus(e.target),!0),this.enabled||(this.nextRefresh=!0,this.focus()),this.enforceAccordionConstraints();var t=this.errors;for(const i in t){const s=this.form.elements[i];void 0!==s&&null!==s&&(s.error=t[i],this.invalidate(i))}return this.idle(),!1!==this.nextRefresh&&(this.enabled=!0,this.visible=!0,this.mount()),this.enabled}isInvalid(e){return!!e.error&&!1!==e.visible}getInvalidElements(){return Object.keys(this.form.elements).map(e=>this.form.elements[e]).filter(this.isInvalid)}hasInvalidChild(e){for(const i in this.form.elements){var t=this.form.elements[i];if(this.isInvalid(t)&&this.getParentSection(t)===e)return!0}return!1}spin(){return void 0!==this.container&&(this.idle(),this.visible&&!this.enabled||(this.nextRefresh=!0,this.enabled=!1,this.visible=!0,this.mount()),this.visible)}hide(){return void 0!==this.container&&(this.idle(),this.visible&&(this.enabled=!1,this.visible=!1,this.unmount()),!0)}dispose(){if(this.dismiss)return!1;{this.dismiss=!0;const t=this.container;t.dispatchEvent(createEvent(eventName));var e=this.focusObserver;return void 0!==e&&t.removeEventListener("focus",e,!0),this.idle(),this.unmount(),this.refs={},presenter.releaseForm(this.container),this.container=void 0,this.lastFocus=void 0,!(this.eventTask=void 0)}}renderFocus(e,t){var i=this.nextFocus;if(this.enabled&&e instanceof HTMLElement)if(!1!==i)if(void 0!==t){if(t===i||!0===i&&void 0===this.lastFocus)return this.nextFocus=!1,this.setLastFocus(e,t),e.focus(),!0}else{const s=this.lastFocus?.target;if(!0===i&&s instanceof HTMLElement&&e.contains(s))return this.nextFocus=!1,s.focus(),!0}else if(!1===i&&t&&t!==this.lastFocus?.name&&this.isElementPositionBeforeLastFocused(t))return this.setLastFocus(e,t),e.focus(),!0;return!1}renderHtml(e,t){return"string"==typeof e?text.textToHtml(e):text.isMarkdown(e)?text.markdownToSafeHtml(e.markdown,{inline:t===defs.HTMLContentCategory.Phrasing}):""}renderText(e){return"string"==typeof e?e:text.isMarkdown(e)?text.markdownToText(e.markdown):""}translateText(e){return"string"==typeof e||text.isMarkdown(e)?e:text.isStatus(e)?e.status:void 0}renderVisual(e){return presenter.render(e)||presenter.renderNone(e)}qualifyDefault(e){var t=sort(this.form.elements);for(const r in t){var i=t[r];if(null!=i&&!1!==i.visible&&i.enabled){if(i.default)return e.value=i.value,r;var s=sort(i.items);if(null!=s)for(const o in s){var n=s[o];if(null!=n&&n.visible&&n.enabled&&n.default)return e.item=o,e.value=n.value,r}}}}qualify(e,t){var i;return null==t&&(t={}),"clicked"===e&&void 0===t.name&&(t.name=this.qualifyDefault(t)),t.type=e,void 0===t.routingKey&&(i=t.name,t.routingKey=void 0!==i?e+"$"+i:e),t}post(e,t){t=this.publish(e,t);const i=this.container;void 0!==i&&i.dispatchEvent(createEvent(eventName,t))}subscribe(i){const e=this.container;if(void 0===e)return createSubscription();const s=function(){i=void 0,e.removeEventListener(eventName,t)},t=function(e){const t=e.detail;void 0!==t?Bluebird.resolve().then(function(){"function"==typeof i&&i(t)}):s()};return e.addEventListener(eventName,t),createSubscription(s)}refresh(e){this.custom||("string"==typeof e?(e=this.refs[e],presenter.refresh(e)):(this.refs={},presenter.refreshForm(this,this.container)))}invalidate(e){const t=this.nextRefresh;"string"==typeof e&&!0!==t&&(!1===t?this.nextRefresh={[e]:!0}:t[e]=!0),void 0!==e&&!0!==e||(this.nextRefresh=!0),!1===e&&!1===t&&(this.nextRefresh={})}update(){var e=this.nextRefresh;if(!0===e&&(this.nextRefresh=!1,this.refresh()),"object"==typeof e){this.nextRefresh=!1;for(const t in e)!0===e[t]&&this.refresh(t)}}idle(){const e=this.timerHandle;void 0!==e&&(this.timerHandle=void 0,e())}busy(){if(void 0===this.timerHandle&&void 0!==this.container){let e=setTimeout(()=>this.spin());this.timerHandle=function(){void 0!==e&&(clearTimeout(e),e=void 0)}}}publish(e,t){return this.enabled?(t=this.enqueue(e,t),0<this.eventQueue.length&&this.spin(),t):this.qualify(e,t)}enqueue(e,t){return t=this.qualify(e,t),void 0!==this.eventTask?(this.resolveEvent(t),this.eventTask=void 0):this.eventQueue.push(t),t}dequeue(){const e=this.eventQueue;if(0<e.length){var t=this.eventIndex,i=e[t++];return t>=e.length?e.length=this.eventIndex=0:this.eventIndex=t,i}}observe(){const t=this;return Bluebird.attempt(function(){if(void 0!==t.eventTask)return t.eventTask;var e=t.dequeue();return void 0!==e?e:t.show()?(t.eventTask=new Task(e=>{t.resolveEvent=e}),t.eventTask):void 0})}load(e,t){if(void 0===this.container)return!1;if(this.eventQueue.length=this.eventIndex=0,this.eventTask=void 0,this.errors={},this.lastFocus=void 0,this.nextFocus=!0,this.nextRefresh=!0,this.enqueue("load"),this.enqueue("prepare"),null!=e){e=overlay(e,e={defaults:{},elements:{}});this.form=overlay(t,e);for(const i in this.form.elements){let e=this.form.elements[i];if(e=overlay(e,{showFilter:!1,checked:!1,enabled:!0,hoisted:!1,visible:!0,overlay:!1,default:!1,validates:!1,readOnly:!1,require:!1,autoActivate:!1}),e.items)for(const s in e.items)e.items[s]=overlay(e.items[s],{enabled:!0,checked:!1,visible:!0,default:!1,validates:!1});this.form.elements[i]=e}}return!0}route(e){switch(e.type){case"changed":return this.cascade(e.name);case"prepare":return this.hydrate(e);case"suggest":return this.suggest(e);case"clicked":return this.click(e);case"validate":return this.verify(e);case"verify":return this.submit(e);case"checked":return this.changed(e)}return!1}changed(e){return this.enqueue("changed",{name:e.name,item:e.item,value:e.value}),!0}isElementValid(e,t=!0,i={status:void 0}){return null!=e&&(i.status=void 0,text.isStatus(e.error)&&"invalid"===e.error.status?!(i.status="invalid"):!0!==e.require||(this.isElementEffectivelyVisible(e)?!!this.isElementValueDefined(e)||!(i.status="missing"):t))}isElementEffectivelyVisible(e){return null!=e&&(!1!==this.getParentSection(e)?.visible&&!1!==e.visible)}isElementValueDefined(e){if(null==e)return!1;if("CheckBox"===e.type)return!0;var t=e.current;if(null!=t)return!0;t=e.value;if(null!=t&&""!==t)return!0;if("Signature"!==e.type){t=e.label;if(null!=t&&""!==t)return!0}var i=e.items;if(null!=i)for(const n in i){var s=i[n];if(null!=s&&!0===s.checked)return!0}return!1}trap(e){switch(e.type){case"populate":case"load":case"suggest":break;default:return!1}var t=e.name;const i=this.find(t);if(void 0===i||null===i)return!1;e=i.dependsOn;if("string"!=typeof e)return!1;e=this.find(e);return i.enabled=this.isElementEffectivelyVisible(e)&&this.isElementValueDefined(e),this.invalidate(t),!i.enabled}cascade(e){var t=this.find(e);if(null==t||!1===t.dependsOn)return!1;const i={[e]:!0};var s=sort(this.form.elements);for(const r in s){const o=s[r];var n=o.dependsOn;if("string"==typeof n){const l=this.find(n);void 0!==l&&"string"!=typeof l.dependsOn&&(l.dependsOn=!0),!0===i[n]&&(i[r]=!0,o.checked=!1,o.current=void 0,o.label=void 0,o.items=void 0,o.value=void 0,this.invalidate(r),o.dependsOn===e&&this.enqueue("populate",{name:r}))}else o.dependsOn=!1}return!0}click(e){var t=this.form.elements[e.name];return null!=t&&"ButtonBar"==t.type&&this.validate(e)}hasInitialSelectionToDependOn(e){e=this.form.elements[e];return e.type===FormElementTypes.DROPDOWNLIST&&(void 0!==e.current&&null!==e.current)}hydrate(e){for(const i in sort(this.form.elements)){var t=this.form.elements[i].dependsOn;"string"==typeof t&&!this.hasInitialSelectionToDependOn(t)||this.enqueue("populate",{name:i}),this.enqueue("load",{name:i})}return!0}shouldTriggerValidation(e){var t=this.find(e.name);if(null!=t&&"string"==typeof e.value){e=e.item;if("string"!=typeof e)return!0===t.validates;t=t.items;if(null!=t){e=t[e];if(null!=e)return!0===e.validates}}}validate(e){var t=this.shouldTriggerValidation(e);if(!0!==t)return!1===t&&(this.enqueue("end",{name:e.name,item:e.item,value:e.value,routingKey:"end"}),!0);{const n=this.errors={};var i=sort(this.form.elements);for(const r in i){var s=i[r];null!=s&&(n[r]=void 0,this.enqueue("validate",{name:r}))}return this.enqueue("verify",{name:e.name,item:e.item,value:e.value,routingKey:"verify"}),!0}}verify(e){var t=e.name,i=this.form.elements[t],e={status:void 0};return!this.isElementValid(i,!0,e)&&(e.status&&(this.errors[t]={status:e.status}),!1===this.nextFocus&&this.focus(t),!0)}suggest(e){const t=this.form.elements[e.name];return void 0!==t&&null!==t&&(t.items={message:{label:{status:"trivial"},enabled:!1}},this.invalidate(e.name),!0)}submit(e){if(!this.hasErrors()){for(const r in this.form.elements)this.form.elements[r].error=void 0;return this.enqueue("submit",{name:e.name,item:e.item,value:e.value}),!0}var t=this.errors;for(const o in t){const l=this.form.elements[o];void 0!==l&&null!==l&&(l.error=t[o],this.invalidate(o))}const i=[];let s=!1;for(const a of this.getInvalidElements()){const u=this.getParentSection(a);if(this.isAccordionSection(u)){var n=this.findName(u);const h=this.getMutuallyExclusiveSectionGroup(n);if(h){const c=i.find(e=>e.group===h);c?c.element.rowNumber>u.rowNumber&&(c.element=u):(i.push({group:h,element:u}),s=!0)}}else this.isSectionCollapsed(u)&&(u.collapsed=!1,s=!0)}for(const d of i)d.group.expandedSection=d.element;return s&&this.invalidate(),!(this.errors={})}hasErrors(){var e=this.errors;for(const i in e){var t=e[i];if(null!=t)return!0}return!1}find(e){if(null!=e)return"string"==typeof(e="object"==typeof e?e.name:e)?this.form.elements[e]:void 0}findName(e){for(const t in this.form.elements)if(this.form.elements[t]===e)return t}coerceNumber(e){var t=this.deriveLocale();return new NumberParser(t).parse(e)}formatNumber(e,t){return t=t||{locale:this.deriveLocale()},format(t,e)}renderCustom(e,t){if(e instanceof FormComponent)return renderElement(FormElementTypes.CUSTOM,e,t)}renderState(e,t,i){return!1}getParentSection(e){e=e.section;if(e){e="string"==typeof e?e:e.name;return this.form.elements[e]}}isSectionCollapsed(e){return!(!e||"Section"!==e.type||!this.isCollapsibleSection(e)&&!this.isAccordionSection(e))&&!0===e.collapsed}isElementPositionBeforeLastFocused(e){var t=this.lastFocus;if(e&&void 0!==t?.rowNumber&&void 0!==t.rowIndex){e=this.form.elements?.[e];if(e)return void 0!==e.rowNumber&&void 0!==e.rowIndex?e.rowNumber<t.rowNumber||e.rowNumber===t.rowNumber&&e.rowIndex<t.rowIndex:e.index<t.rowNumber||e.index===t.rowNumber&&0<t.rowIndex}return!1}setLastFocus(e,t){this.lastFocus={target:e},t&&(this.lastFocus.name=t,(t=this.form.elements?.[t])&&(void 0!==t.rowNumber&&void 0!==t.rowIndex?(this.lastFocus.rowNumber=t.rowNumber,this.lastFocus.rowIndex=t.rowIndex):(this.lastFocus.rowNumber=t.index,this.lastFocus.rowIndex=0)))}isSection(e){return"Section"===e?.type}isAccordionSection(e){return this.isSection(e)&&"accordion-section"===e.format}isCollapsibleSection(e){return this.isSection(e)&&"collapsible-section"===e.format}getAllSectionElements(){const e={};for(const i in this.form.elements){var t=this.form.elements[i];this.isSection(t)&&(e[i]=t)}return e}getMutuallyExclusiveSectionGroup(t){let i=this.mutuallyExclusiveSections[t];if(!i){var e=this.find(t);if(!this.isAccordionSection(e))return;i=new MutuallyExclusiveSectionGroup({elementName:t,element:e});e=this.getAllSectionElements();const r=Object.keys(sort(e,e=>e.rowNumber));t=r.indexOf(t);for(let e=t-1;0<=e;e--){const o=r[e];var s=this.find(o);if(!this.isAccordionSection(s))break;i.unshift({elementName:o,element:s})}for(let e=t+1;e<r.length;e++){const o=r[e];var n=this.find(o);if(!this.isAccordionSection(n))break;i.push({elementName:o,element:n})}i.forEach(e=>{this.mutuallyExclusiveSections[e.elementName]=i})}return i}updateAccordionSections(t){const e=this.getMutuallyExclusiveSectionGroup(t);e.forEach(e=>{e.element.collapsed=e.elementName!==t}),presenter.refreshForm(this,this.container)}enforceAccordionConstraints(){const e=[];for(const i of Object.keys(this.form.elements).map(e=>({elementName:e,element:this.form.elements[e]})).filter(e=>this.isAccordionSection(e.element)&&!1!==e.element.visible&&!0!==e.element.collapsed).sort((e,t)=>e.element.rowNumber-t.element.rowNumber)){var t=this.getMutuallyExclusiveSectionGroup(i.elementName);-1===e.indexOf(t)?e.push(t):i.element.collapsed=!0}}async displayDialog(e,t){await Promise.resolve()}}export{defs,FormHost};
1
+ import Bluebird from"bluebird";import{Task}from"../Task.js";import{DEFAULT_LOCALE}from"../constants.js";import*as defs from"./FormDefinition.js";import MutuallyExclusiveSectionGroup from"./MutuallyExclusiveSectionGroup.js";import NumberParser from"./NumberParser.js";import{FormElementTypes}from"./constants.js";import{format}from"./numberFormatter.js";import*as presenter from"./presenter.js";import{sortAndFilter,text}from"./utils.js";const guid="C0166F74-982A-464E-9FB6-9605CB7649C1:",eventName=guid+"FormEvent";function createEvent(e,t){return new CustomEvent(e,{bubbles:!1,cancelable:!1,detail:t})}function overlay(i,s){switch(typeof i){case"boolean":case"number":case"string":return i;case"object":break;default:return s}if(null===i)return s;if(i instanceof Array){let e=s;void 0!==e&&null!==e||(e=[]);let t=0;for(const r of i){var n=overlay(r,e[t]);void 0!==n&&(t<i.length?e[t]=n:e.push(n),++t)}return e}let e=s;void 0===e&&(e={});for(const t in i)e[t]=overlay(i[t],e[t]);return e}function createSubscription(e){function t(){return void 0!==e&&(t.active=!1,e(),!0)}return t.active=!0,t}class FormHost{constructor(){this.form={defaults:{},elements:{}},this.errors={},this.refs={},this.enabled=!1,this.visible=!1,this.dismiss=!1,this.custom=!1,this.container=document.createElement("div"),this.eventIndex=0,this.eventQueue=[],this.mutuallyExclusiveSections={},this.nextFocus=!1,this.nextRefresh=!1,this.style=void 0}deriveLocale(){return DEFAULT_LOCALE}mount(){var e=this.container,t=e.parentNode;null==t&&document.body.appendChild(e),this.update()}unmount(){var e=this.container;const t=e.parentNode;void 0!==t&&null!==t&&t.removeChild(e)}observeFocus(e){this.enabled&&e instanceof HTMLElement&&(this.lastFocus&&this.lastFocus.target===e||this.setLastFocus(e))}focus(e){!0===(e=null==e?!1:e)&&(this.lastFocus=void 0),!1===e&&!1===(e=this.nextFocus)&&(e=!0),this.nextFocus=e,this.invalidate(!0!==e?e:void 0)}show(){const e=this.container;if(void 0===e)return!1;this.custom||void 0!==this.focusObserver||e.addEventListener("focus",this.focusObserver=e=>this.observeFocus(e.target),!0),this.enabled||(this.nextRefresh=!0,this.focus()),this.enforceAccordionConstraints();var t=this.errors;for(const i in t){const s=this.form.elements[i];void 0!==s&&null!==s&&(s.error=t[i],this.invalidate(i))}return this.idle(),!1!==this.nextRefresh&&(this.enabled=!0,this.visible=!0,this.mount()),this.enabled}isInvalid(e){return!!e.error&&!1!==e.visible}getInvalidElements(){return Object.keys(this.form.elements).map(e=>this.form.elements[e]).filter(this.isInvalid)}hasInvalidChild(e){for(const i in this.form.elements){var t=this.form.elements[i];if(this.isInvalid(t)&&this.getParentSection(t)===e)return!0}return!1}spin(){return void 0!==this.container&&(this.idle(),this.visible&&!this.enabled||(this.nextRefresh=!0,this.enabled=!1,this.visible=!0,this.mount()),this.visible)}hide(){return void 0!==this.container&&(this.idle(),this.visible&&(this.enabled=!1,this.visible=!1,this.unmount()),!0)}dispose(){if(this.dismiss)return!1;{this.dismiss=!0;const t=this.container;t.dispatchEvent(createEvent(eventName));var e=this.focusObserver;return void 0!==e&&t.removeEventListener("focus",e,!0),this.idle(),this.unmount(),this.refs={},presenter.releaseForm(this.container),this.container=void 0,this.lastFocus=void 0,!(this.eventTask=void 0)}}renderFocus(e,t){var i=this.nextFocus;if(this.enabled&&e instanceof HTMLElement)if(!1!==i)if(void 0!==t){if(t===i||!0===i&&void 0===this.lastFocus)return this.nextFocus=!1,this.setLastFocus(e,t),e.focus(),!0}else{const s=this.lastFocus?.target;if(!0===i&&s instanceof HTMLElement&&e.contains(s))return this.nextFocus=!1,s.focus(),!0}else if(!1===i&&t&&t!==this.lastFocus?.name&&this.isElementPositionBeforeLastFocused(t))return this.setLastFocus(e,t),e.focus(),!0;return!1}renderHtml(e,t){return"string"==typeof e?text.textToHtml(e):text.isMarkdown(e)?text.markdownToSafeHtml(e.markdown,{inline:t===defs.HTMLContentCategory.Phrasing}):""}renderText(e){return"string"==typeof e?e:text.isMarkdown(e)?text.markdownToText(e.markdown):""}translateText(e){return"string"==typeof e||text.isMarkdown(e)?e:text.isStatus(e)?e.status:void 0}renderVisual(e){return presenter.render(e)||presenter.renderNone(e)}qualifyDefault(e){var t=sortAndFilter(this.form.elements);for(const r in t){var i=t[r];if(null!=i&&!1!==i.visible&&i.enabled){if(i.default)return e.value=i.value,r;var s=sortAndFilter(i.items);if(null!=s)for(const o in s){var n=s[o];if(null!=n&&n.visible&&n.enabled&&n.default)return e.item=o,e.value=n.value,r}}}}qualify(e,t){var i;return null==t&&(t={}),"clicked"===e&&void 0===t.name&&(t.name=this.qualifyDefault(t)),t.type=e,void 0===t.routingKey&&(i=t.name,t.routingKey=void 0!==i?e+"$"+i:e),t}post(e,t){t=this.publish(e,t);const i=this.container;void 0!==i&&i.dispatchEvent(createEvent(eventName,t))}subscribe(i){const e=this.container;if(void 0===e)return createSubscription();const s=function(){i=void 0,e.removeEventListener(eventName,t)},t=function(e){const t=e.detail;void 0!==t?Bluebird.resolve().then(function(){"function"==typeof i&&i(t)}):s()};return e.addEventListener(eventName,t),createSubscription(s)}refresh(e){this.custom||("string"==typeof e?(e=this.refs[e],presenter.refresh(e)):(this.refs={},presenter.refreshForm(this,this.container)))}invalidate(e){const t=this.nextRefresh;"string"==typeof e&&!0!==t&&(!1===t?this.nextRefresh={[e]:!0}:t[e]=!0),void 0!==e&&!0!==e||(this.nextRefresh=!0),!1===e&&!1===t&&(this.nextRefresh={})}update(){var e=this.nextRefresh;if(!0===e&&(this.nextRefresh=!1,this.refresh()),"object"==typeof e){this.nextRefresh=!1;for(const t in e)!0===e[t]&&this.refresh(t)}}idle(){const e=this.timerHandle;void 0!==e&&(this.timerHandle=void 0,e())}busy(){if(void 0===this.timerHandle&&void 0!==this.container){let e=setTimeout(()=>this.spin());this.timerHandle=function(){void 0!==e&&(clearTimeout(e),e=void 0)}}}publish(e,t){return this.enabled?(t=this.enqueue(e,t),0<this.eventQueue.length&&this.spin(),t):this.qualify(e,t)}enqueue(e,t){return t=this.qualify(e,t),void 0!==this.eventTask?(this.resolveEvent(t),this.eventTask=void 0):this.eventQueue.push(t),t}dequeue(){const e=this.eventQueue;if(0<e.length){var t=this.eventIndex,i=e[t++];return t>=e.length?e.length=this.eventIndex=0:this.eventIndex=t,i}}observe(){const t=this;return Bluebird.attempt(function(){if(void 0!==t.eventTask)return t.eventTask;var e=t.dequeue();return void 0!==e?e:t.show()?(t.eventTask=new Task(e=>{t.resolveEvent=e}),t.eventTask):void 0})}load(e,t){if(void 0===this.container)return!1;if(this.eventQueue.length=this.eventIndex=0,this.eventTask=void 0,this.errors={},this.lastFocus=void 0,this.nextFocus=!0,this.nextRefresh=!0,this.enqueue("load"),this.enqueue("prepare"),null!=e){e=overlay(e,e={defaults:{},elements:{}});this.form=overlay(t,e);for(const i in this.form.elements){let e=this.form.elements[i];if(e=overlay(e,{showFilter:!1,checked:!1,enabled:!0,hoisted:!1,visible:!0,overlay:!1,default:!1,validates:!1,readOnly:!1,require:!1,autoActivate:!1}),e.items)for(const s in e.items)e.items[s]=overlay(e.items[s],{enabled:!0,checked:!1,visible:!0,default:!1,validates:!1});this.form.elements[i]=e}}return!0}route(e){switch(e.type){case"changed":return this.cascade(e.name);case"prepare":return this.hydrate(e);case"suggest":return this.suggest(e);case"clicked":return this.click(e);case"validate":return this.verify(e);case"verify":return this.submit(e);case"checked":return this.changed(e)}return!1}changed(e){return this.enqueue("changed",{name:e.name,item:e.item,value:e.value}),!0}isElementValid(e,t=!0,i={status:void 0}){return null!=e&&(i.status=void 0,text.isStatus(e.error)&&"invalid"===e.error.status?!(i.status="invalid"):!0!==e.require||(this.isElementEffectivelyVisible(e)?!!this.isElementValueDefined(e)||!(i.status="missing"):t))}isElementEffectivelyVisible(e){return null!=e&&(!1!==this.getParentSection(e)?.visible&&!1!==e.visible)}isElementValueDefined(e){if(null==e)return!1;if(e.type===FormElementTypes.CHECKBOX)return!0;var t=e.current;if(null!=t)return!0;t=e.value;if(null!=t&&""!==t)return!0;if(e.type!==FormElementTypes.SIGNATURE){t=e.label;if(null!=t&&""!==t)return!0}var i=e.items;if(null!=i)for(const n in i){var s=i[n];if(null!=s&&!0===s.checked)return!0}return!1}trap(e){switch(e.type){case"populate":case"load":case"suggest":break;default:return!1}var t=e.name;const i=this.find(t);if(void 0===i||null===i)return!1;e=i.dependsOn;if("string"!=typeof e)return!1;e=this.find(e);return i.enabled=this.isElementEffectivelyVisible(e)&&this.isElementValueDefined(e),this.invalidate(t),!i.enabled}cascade(e){var t=this.find(e);if(null==t||!1===t.dependsOn)return!1;const i={[e]:!0};var s=sortAndFilter(this.form.elements);for(const r in s){const o=s[r];var n=o.dependsOn;if("string"==typeof n){const l=this.find(n);void 0!==l&&"string"!=typeof l.dependsOn&&(l.dependsOn=!0),!0===i[n]&&(i[r]=!0,o.checked=!1,o.current=void 0,o.label=void 0,o.items=void 0,o.value=void 0,this.invalidate(r),o.dependsOn===e&&this.enqueue("populate",{name:r}))}else o.dependsOn=!1}return!0}click(e){var t=this.form.elements[e.name];return null!=t&&t.type==FormElementTypes.BUTTONBAR&&this.validate(e)}hasInitialSelectionToDependOn(e){e=this.form.elements[e];return e.type===FormElementTypes.DROPDOWNLIST&&(void 0!==e.current&&null!==e.current)}hydrate(e){for(const i in sortAndFilter(this.form.elements)){var t=this.form.elements[i].dependsOn;"string"==typeof t&&!this.hasInitialSelectionToDependOn(t)||this.enqueue("populate",{name:i}),this.enqueue("load",{name:i})}return!0}shouldTriggerValidation(e){var t=this.find(e.name);if(null!=t&&"string"==typeof e.value){e=e.item;if("string"!=typeof e)return!0===t.validates;t=t.items;if(null!=t){e=t[e];if(null!=e)return!0===e.validates}}}validate(e){var t=this.shouldTriggerValidation(e);if(!0!==t)return!1===t&&(this.enqueue("end",{name:e.name,item:e.item,value:e.value,routingKey:"end"}),!0);{const n=this.errors={};var i=sortAndFilter(this.form.elements);for(const r in i){var s=i[r];null!=s&&(n[r]=void 0,this.enqueue("validate",{name:r}))}return this.enqueue("verify",{name:e.name,item:e.item,value:e.value,routingKey:"verify"}),!0}}verify(e){var t=e.name,i=this.form.elements[t],e={status:void 0};return!this.isElementValid(i,!0,e)&&(e.status&&(this.errors[t]={status:e.status}),!1===this.nextFocus&&this.focus(t),!0)}suggest(e){const t=this.form.elements[e.name];return void 0!==t&&null!==t&&(t.items={message:{label:{status:"trivial"},enabled:!1}},this.invalidate(e.name),!0)}submit(e){if(!this.hasErrors()){for(const r in this.form.elements)this.form.elements[r].error=void 0;return this.enqueue("submit",{name:e.name,item:e.item,value:e.value}),!0}var t=this.errors;for(const o in t){const l=this.form.elements[o];void 0!==l&&null!==l&&(l.error=t[o],this.invalidate(o))}const i=[];let s=!1;for(const a of this.getInvalidElements()){const u=this.getParentSection(a);if(this.isAccordionSection(u)){var n=this.findName(u);const h=this.getMutuallyExclusiveSectionGroup(n);if(h){const c=i.find(e=>e.group===h);c?c.element.rowNumber>u.rowNumber&&(c.element=u):(i.push({group:h,element:u}),s=!0)}}else this.isSectionCollapsed(u)&&(u.collapsed=!1,s=!0)}for(const d of i)d.group.expandedSection=d.element;return s&&this.invalidate(),!(this.errors={})}hasErrors(){var e=this.errors;for(const i in e){var t=e[i];if(null!=t)return!0}return!1}find(e){if(null!=e)return"string"==typeof(e="object"==typeof e?e.name:e)?this.form.elements[e]:void 0}findName(e){for(const t in this.form.elements)if(this.form.elements[t]===e)return t}coerceNumber(e){var t=this.deriveLocale();return new NumberParser(t).parse(e)}formatNumber(e,t){return t=t||{locale:this.deriveLocale()},format(t,e)}renderState(e,t,i){return!1}getParentSection(e){e=e.section;if(e){e="string"==typeof e?e:e.name;return this.form.elements[e]}}isSectionCollapsed(e){return!(!e||e.type!==FormElementTypes.SECTION||!this.isCollapsibleSection(e)&&!this.isAccordionSection(e))&&!0===e.collapsed}isElementPositionBeforeLastFocused(e){var t=this.lastFocus;if(!t)return!0;if("footer"===e)return!1;if("footer"===t.name)return!0;if(e&&void 0!==t?.rowNumber&&void 0!==t.rowIndex){e=this.form.elements?.[e];if(e)return void 0!==e.rowNumber&&void 0!==e.rowIndex?e.rowNumber<t.rowNumber||e.rowNumber===t.rowNumber&&e.rowIndex<t.rowIndex:e.index<t.rowNumber||e.index===t.rowNumber&&0<t.rowIndex}return!1}setLastFocus(e,t){this.lastFocus={target:e},t&&(this.lastFocus.name=t,(t=this.form.elements?.[t])&&(void 0!==t.rowNumber&&void 0!==t.rowIndex?(this.lastFocus.rowNumber=t.rowNumber,this.lastFocus.rowIndex=t.rowIndex):(this.lastFocus.rowNumber=t.index,this.lastFocus.rowIndex=0)))}isSection(e){return e?.type===FormElementTypes.SECTION}isAccordionSection(e){return this.isSection(e)&&"accordion-section"===e.format}isCollapsibleSection(e){return this.isSection(e)&&"collapsible-section"===e.format}getAllSectionElements(){const e={};for(const i in this.form.elements){var t=this.form.elements[i];this.isSection(t)&&(e[i]=t)}return e}getMutuallyExclusiveSectionGroup(t){let i=this.mutuallyExclusiveSections[t];if(!i){var e=this.find(t);if(!this.isAccordionSection(e))return;i=new MutuallyExclusiveSectionGroup({elementName:t,element:e});e=this.getAllSectionElements();const r=Object.keys(sortAndFilter(e,e=>e.rowNumber));t=r.indexOf(t);for(let e=t-1;0<=e;e--){const o=r[e];var s=this.find(o);if(!this.isAccordionSection(s))break;i.unshift({elementName:o,element:s})}for(let e=t+1;e<r.length;e++){const o=r[e];var n=this.find(o);if(!this.isAccordionSection(n))break;i.push({elementName:o,element:n})}i.forEach(e=>{this.mutuallyExclusiveSections[e.elementName]=i})}return i}updateAccordionSections(t){const e=this.getMutuallyExclusiveSectionGroup(t);e.forEach(e=>{e.element.collapsed=e.elementName!==t}),this.refresh()}enforceAccordionConstraints(){const e=[];for(const i of Object.keys(this.form.elements).map(e=>({elementName:e,element:this.form.elements[e]})).filter(e=>this.isAccordionSection(e.element)&&!1!==e.element.visible&&!0!==e.element.collapsed).sort((e,t)=>e.element.rowNumber-t.element.rowNumber)){var t=this.getMutuallyExclusiveSectionGroup(i.elementName);-1===e.indexOf(t)?e.push(t):i.element.collapsed=!0}}async displayDialog(e,t){await Promise.resolve()}}export{defs,FormHost};
@@ -21,8 +21,6 @@ export interface FormPresenterHost {
21
21
  refs: {
22
22
  [name: string]: FormComponent | undefined;
23
23
  };
24
- /** Renders a custom element. */
25
- renderCustom(component: {}, element: defs.Element): any;
26
24
  /** Renders the focus. */
27
25
  renderFocus(target: Node, name?: string): boolean;
28
26
  /** Renders form text to HTML. */
@@ -9,6 +9,7 @@
9
9
  export default class NumberParser {
10
10
  private _group;
11
11
  private _decimal;
12
+ private _minus;
12
13
  private _numeral;
13
14
  private _index;
14
15
  /**
@@ -1 +1 @@
1
- export default class NumberParser{constructor(e){const r=new Intl.NumberFormat(e).formatToParts(12345.6),t=Array.from(new Intl.NumberFormat(e,{useGrouping:!1}).format(9876543210)).reverse(),a=new Map(t.map((e,r)=>[e,r.toString()]));this._group=new RegExp(`[${r.find(e=>"group"===e.type).value}]`,"g"),this._decimal=new RegExp(`[${r.find(e=>"decimal"===e.type).value}]`),this._numeral=new RegExp(`[${t.join("")}]`,"g"),this._index=e=>a.get(e)}parse(e){e=e.trim().replace(this._group,"").replace(this._decimal,".").replace(this._numeral,this._index);return e?+e:NaN}}
1
+ export default class NumberParser{constructor(e){const r=new Intl.NumberFormat(e).formatToParts(-12345.6),t=Array.from(new Intl.NumberFormat(e,{useGrouping:!1}).format(9876543210)).reverse(),i=new Map(t.map((e,r)=>[e,r.toString()]));this._group=new RegExp(`[${r.find(e=>"group"===e.type).value}]`,"g"),this._decimal=new RegExp(`[${r.find(e=>"decimal"===e.type).value}]`),this._minus=new RegExp(`[${r.find(e=>"minusSign"===e.type).value}]`),this._numeral=new RegExp(`[${t.join("")}]`,"g"),this._index=e=>i.get(e)}parse(e){e=e.trim().replace(this._group,"").replace(this._decimal,".").replace(this._minus,"-").replace(this._numeral,this._index);return e?+e:NaN}}
package/forms/common.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { FormComponent, FormPresenterHost } from "./FormComponent";
2
+ import { FormPresenterHost } from "./FormComponent";
3
3
  import { defs } from "./FormHost";
4
4
  export declare function getTitleId(elementId: string): string;
5
5
  export declare function getDescriptionId(elementId: string): string;
@@ -56,7 +56,7 @@ export declare function renderFocus(target: (HTMLElement & {
56
56
  * @param component The form component
57
57
  * @returns A memoized function that focuses a target HTML element.
58
58
  */
59
- export declare function useFocusCallback(component: FormComponent): (target: (ReactNode & {
59
+ export declare function useFocusCallback(enabled: boolean, name: string | undefined, renderFocus: (target: Node, name?: string) => boolean): (target: (ReactNode & {
60
60
  disabled?: boolean;
61
61
  thumbRefs?: any[];
62
62
  }) | null) => void;
package/forms/common.js CHANGED
@@ -1 +1 @@
1
- import Box from"@vertigis/react-ui/Box";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabel from"@vertigis/react-ui/FormLabel";import{useCallback}from"react";import*as React from"react";import{formClasses}from"./components/Form.js";import Markdown from"./components/Markdown.js";import{hasContent,isMarkdown,markdownToText}from"./textUtilities.js";const ERROR_SUFFIX="-error",DESCRIPTION_SUFFIX="-description",TITLE_SUFFIX="-title";function getTitleId(e){return`${e}${TITLE_SUFFIX}`}function getDescriptionId(e){return`${e}${DESCRIPTION_SUFFIX}`}function getErrorId(e){return`${e}${ERROR_SUFFIX}`}function renderTitle(e,r,t,n){return hasContent(r.title)?React.createElement(FormLabel,{className:formClasses.formElementTitle,htmlFor:n,id:`${t}-label`,required:!!r.require},React.createElement(Markdown,{host:e,inline:!0,text:r.title})):null}function renderDescription(e,r,t,n){return hasContent(r.description)?React.createElement(FormHelperText,{className:n,component:"div",disabled:!r.enabled,error:!1,id:`${t}-description`},React.createElement(Markdown,{host:e,text:r.description})):null}function renderAccessibleDescription(e,r,t){let n=e.translateText(r.accessibleDescription);return n||(r=e.translateText(r.description),n=isMarkdown(r)?markdownToText(r.markdown):r),n?React.createElement(Box,{sx:{display:"none"},id:`${t}-accessible-description`},n):null}function renderError(e,r){return hasContent(r.error)?React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},React.createElement(Markdown,{host:e,text:r.error})):null}function renderFocus(e,r,t){null===e||e.disabled||t.renderFocus(e,r)}function useFocusCallback(e){const{host:r,name:t}=e.props;return useCallback(e=>{null===(e=Array.isArray(e?.thumbRefs)&&0<e.thumbRefs.length?e.thumbRefs[0].current:e)||e.disabled||r.renderFocus(e,t)},[e.enabled,t,r])}export{getTitleId,getDescriptionId,getErrorId,renderTitle,renderDescription,renderAccessibleDescription,renderError,renderFocus,useFocusCallback};
1
+ import Box from"@vertigis/react-ui/Box";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabel from"@vertigis/react-ui/FormLabel";import{useCallback}from"react";import*as React from"react";import{formClasses}from"./components/Form.js";import Markdown from"./components/Markdown.js";import{hasContent,isMarkdown,markdownToText}from"./textUtilities.js";const ERROR_SUFFIX="-error",DESCRIPTION_SUFFIX="-description",TITLE_SUFFIX="-title";function getTitleId(e){return`${e}${TITLE_SUFFIX}`}function getDescriptionId(e){return`${e}${DESCRIPTION_SUFFIX}`}function getErrorId(e){return`${e}${ERROR_SUFFIX}`}function renderTitle(e,r,t,n){return hasContent(r.title)?React.createElement(FormLabel,{className:formClasses.formElementTitle,htmlFor:n,id:`${t}-label`,required:!!r.require},React.createElement(Markdown,{inline:!0,text:r.title,translateText:e.translateText.bind(e)})):null}function renderDescription(e,r,t,n){return hasContent(r.description)?React.createElement(FormHelperText,{className:n,component:"div",disabled:!r.enabled,error:!1,id:`${t}-description`},React.createElement(Markdown,{text:r.description,translateText:e.translateText.bind(e)})):null}function renderAccessibleDescription(e,r,t){let n=e.translateText(r.accessibleDescription);return n||(r=e.translateText(r.description),n=isMarkdown(r)?markdownToText(r.markdown):r),n?React.createElement(Box,{sx:{display:"none"},id:`${t}-accessible-description`},n):null}function renderError(e,r){return hasContent(r.error)?React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},React.createElement(Markdown,{text:r.error,translateText:e.translateText.bind(e)})):null}function renderFocus(e,r,t){null===e||e.disabled||t.renderFocus(e,r)}function useFocusCallback(e,r,t){return useCallback(e=>{null===(e=Array.isArray(e?.thumbRefs)&&0<e.thumbRefs.length?e.thumbRefs[0].current:e)||e.disabled||t(e,r)},[e,r,t])}export{getTitleId,getDescriptionId,getErrorId,renderTitle,renderDescription,renderAccessibleDescription,renderError,renderFocus,useFocusCallback};
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
+ import { defs } from "../FormHost";
3
4
  /**
4
5
  * The component for the "Auto Complete" Form Element.
5
6
  */
6
- declare const AutoComplete: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
7
+ declare const AutoComplete: ({ className, component, current, delay: elementDelay, element, enabled, error, items: elementItems, label, minLength: elementMinLength, name, prompt, tooltip, renderFocus, renderText, raiseEvent, setProperty, setValue, value, }: FormElementProps<defs.Value | undefined>) => JSX.Element;
7
8
  export default AutoComplete;
@@ -1 +1 @@
1
- import BaseAutoComplete,{autocompleteClasses,HighlightOption}from"@vertigis/react-ui/Autocomplete";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import Popper from"@vertigis/react-ui/Popper";import Skeleton from"@vertigis/react-ui/Skeleton";import{styled}from"@vertigis/react-ui/styles";import clsx from"clsx";import{useEffect,useMemo,useRef,useState}from"react";import*as React from"react";import{ExclusiveTimer}from"../ExclusiveTimer.js";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{autoCompletePropertyConstraints}from"../elements/AutoComplete.js";import{getKeyString}from"../keyboard.js";import{getItemId,makeSafeClassName,makeUniqueId,sortAndFilterItems}from"../utils.js";const StyledAutoComplete=styled(BaseAutoComplete)(()=>({[`.${autocompleteClasses.endAdornment}`]:{right:1}})),popperClasses={skeletonOption:"skeleton-option"},StyledPopper=styled(Popper)(()=>({[`.${autocompleteClasses.listbox}`]:{[`.${autocompleteClasses.option}`]:{display:"block",[`&.${popperClasses.skeletonOption}`]:{'&[data-option-index="0"]':{span:{width:"70%"}},'&[data-option-index="1"]':{span:{width:"85%"}},'&[data-option-index="2"]':{span:{width:"55%"}}}}}})),StyledSkeleton=styled(Skeleton)(()=>({fontSize:"1.25rem",lineHeight:"inherit"})),pendingOption={enabled:!1,label:""},pendingOptions=[pendingOption,pendingOption,pendingOption],AutoComplete=({className:e,component:m,element:c})=>{const{host:d,name:r}=m.props,[t,o]=useState(),[n,a]=useState(""),[l,f]=useState([]),[i,g]=useState(null),s=useRef(!1),p=useRef(!1),u=`${makeUniqueId(r)}-input`;var v=useRef(d.renderText({status:"trivial"}));const y=d.renderText(c.prompt),C=d.renderText(c.tooltip),h=useFocusCallback(m),b=useRef({}),x=useRef({}),S=useMemo(()=>{let e=c.delay;return"number"==typeof e&&!isNaN(e)||(e=autoCompletePropertyConstraints.delay.default),Math.max(e,autoCompletePropertyConstraints.delay.minimum)},[c.delay]),k=useMemo(()=>{let e=c.minLength;return"number"==typeof e&&!isNaN(e)||(e=autoCompletePropertyConstraints.minLength.default),Math.max(e,autoCompletePropertyConstraints.minLength.minimum)},[c.minLength]),O=m.timer||(m.timer=new ExclusiveTimer),E=()=>{d.post("suggest",{name:r,value:c.value,argument:n,cancellationToken:O.cancellationToken}),f(pendingOptions)},T=()=>{c.items={},f([])};return useEffect(()=>{"clear"===t?T():"input"===t&&(s.current=!0,n.length>=k?(c.current=void 0,m.forceUpdate(),O.reset(),O.start(S,E)):0<Object.keys(c.items||{}).length&&T())},[t,n]),useEffect(()=>{var e,t=i?.value;c.value!==t&&(e=getItemId(i,b.current),e=(c.current=e)?x.current[e]:void 0,c.label=e,c.value=t,m.forceUpdate(),d.post("changed",{name:r,value:t,argument:e}))},[i]),useEffect(()=>{var{current:e,items:t,label:r,value:o}=sortAndFilterItems(c);c.current=e,c.label=r,c.value=o,m.forceUpdate();const n={};var a="string"==typeof e?e:void 0;let l=null;const i=[];for(const u in t){var s=t[u];i.push(s);var p=d.renderText(s.label).trim();n[u]=p,a&&u===a&&(l=s)}x.current=n,b.current=t,f(i),g(l)},[c.items]),useEffect(()=>{var e="string"==typeof c.current?c.current:void 0,t=e?b.current[e]:void 0,e=e?x.current[e]:void 0;t?(c.label=e,c.value=t.value,m.forceUpdate(),a(e||"")):(c.value=void 0,m.forceUpdate(),s.current||a("")),g(t||null)},[c.current]),useEffect(()=>{s.current||p.current||a(""),s.current=!1,p.current=!1},[c.label]),React.createElement(FormElement,{className:e,component:m,element:c,inputId:u},React.createElement(StyledAutoComplete,{autoSelect:!0,clearOnEscape:!0,clearOnBlur:!1,disabled:!m.enabled,filterOptions:e=>e,getOptionDisabled:e=>!1===e.enabled,getOptionLabel:e=>{e=getItemId(e,b.current);return e?x.current[e]:""},inputValue:n,noOptionsText:v.current,onBlur:()=>{1===l.length&&n.toLowerCase()===x.current[0]?.toLowerCase()?(a(x.current[0]),g(l[0])):(c.label=n,m.forceUpdate())},onChange:(e,t,r,o)=>{p.current=!0,g(t)},onInputChange:(e,t,r)=>{a(t),o(r)},onKeyDown:e=>{"enter"===getKeyString(e)&&e.stopPropagation()},options:l,PopperComponent:StyledPopper,renderOption:(e,t,{inputValue:r})=>{if(t===pendingOption){var o=clsx(e.className,popperClasses.skeletonOption);return React.createElement("li",{...e,className:o,key:e.id},React.createElement(StyledSkeleton,null))}o=getItemId(t,b.current),o={...e,className:clsx(e.className,t.styleName?makeSafeClassName(t.styleName):void 0),title:t.tooltip?d.renderText(t.tooltip):void 0,inputText:r,optionText:o?x.current[o]:""};return React.createElement(HighlightOption,{...o})},renderInput:e=>(e.inputProps={...e.inputProps,id:u,placeholder:y,title:C},React.createElement(FormLabelTextField,{error:!!c.error,...e,fullWidth:!0,inputRef:h})),value:i}))};export default AutoComplete;
1
+ import BaseAutoComplete,{autocompleteClasses,HighlightOption}from"@vertigis/react-ui/Autocomplete";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import Popper from"@vertigis/react-ui/Popper";import Skeleton from"@vertigis/react-ui/Skeleton";import{styled}from"@vertigis/react-ui/styles";import clsx from"clsx";import{useEffect,useMemo,useRef,useState}from"react";import*as React from"react";import{ExclusiveTimer}from"../ExclusiveTimer.js";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{autoCompletePropertyConstraints}from"../elements/AutoComplete.js";import{getKeyString}from"../keyboard.js";import{getItemId,makeSafeClassName,makeUniqueId,inspectItems}from"../utils.js";const StyledAutoComplete=styled(BaseAutoComplete)(()=>({[`.${autocompleteClasses.endAdornment}`]:{right:1}})),popperClasses={skeletonOption:"skeleton-option"},StyledPopper=styled(Popper)(()=>({[`.${autocompleteClasses.listbox}`]:{[`.${autocompleteClasses.option}`]:{display:"block",[`&.${popperClasses.skeletonOption}`]:{'&[data-option-index="0"]':{span:{width:"70%"}},'&[data-option-index="1"]':{span:{width:"85%"}},'&[data-option-index="2"]':{span:{width:"55%"}}}}}})),StyledSkeleton=styled(Skeleton)(()=>({fontSize:"1.25rem",lineHeight:"inherit"})),pendingOption={enabled:!1,label:""},pendingOptions=[pendingOption,pendingOption,pendingOption],AutoComplete=({className:e,component:t,current:u,delay:r,element:o,enabled:n,error:l,items:m,label:a,minLength:i,name:s,prompt:p,tooltip:c,renderFocus:d,renderText:f,raiseEvent:g,setProperty:v,setValue:C,value:y})=>{const[b,h]=useState(),[S,x]=useState(""),[k,E]=useState([]),[O,I]=useState(null),P=useRef(!1),N=useRef(!1),R=`${makeUniqueId(s)}-input`;var F=useRef(f({status:"trivial"}));const T=f(p),A=f(c),L=useFocusCallback(n,s,d),j=useRef({}),w=useRef({}),M=useMemo(()=>{let e=r;return"number"==typeof e&&!isNaN(e)||(e=autoCompletePropertyConstraints.delay.default),Math.max(e,autoCompletePropertyConstraints.delay.minimum)},[r]),$=useMemo(()=>{let e=i;return"number"==typeof e&&!isNaN(e)||(e=autoCompletePropertyConstraints.minLength.default),Math.max(e,autoCompletePropertyConstraints.minLength.minimum)},[i]),B=t.timer||(t.timer=new ExclusiveTimer),H=()=>{g("suggest",y,S,void 0,B.cancellationToken),E(pendingOptions)},K=()=>{v("items",{})};return useEffect(()=>{"clear"===b?K():"input"===b&&(P.current=!0,S.length>=$?(v("current",void 0),B.reset(),B.start(M,H)):0<Object.keys(m||{}).length&&K())},[b,S]),useEffect(()=>{var e,t,r=O?.value;y!==r&&(t=(e=getItemId(O,j.current))?w.current[e]:void 0,v("current",e),v("label",t),C(r,{argument:t}))},[O]),useEffect(()=>{var{current:e,items:t,label:r,value:o}=inspectItems(u,m,y);v("current",e),v("label",r),v("value",o,!1);const n={};let l=null;const a=[];for(const p in t){var i=t[p];a.push(i);var s=f(i.label).trim();n[p]=s,e&&p===e&&(l=i)}w.current=n,j.current=t,E(a),I(l)},[m]),useEffect(()=>{var e="string"==typeof u?u:void 0,t=e?j.current[e]:void 0,e=e?w.current[e]:void 0;t?(v("label",e),v("value",t.value),x(e||"")):(v("value",void 0),P.current||x("")),I(t||null)},[u]),useEffect(()=>{P.current||N.current||x(""),P.current=!1,N.current=!1},[a]),React.createElement(FormElement,{className:e,component:t,element:o,inputId:R},React.createElement(StyledAutoComplete,{autoSelect:!0,clearOnEscape:!0,clearOnBlur:!1,disabled:!n,filterOptions:e=>e,getOptionDisabled:e=>!1===e.enabled,getOptionLabel:e=>{e=getItemId(e,j.current);return e?w.current[e]:""},inputValue:S,noOptionsText:F.current,onBlur:()=>{1===k.length&&S.toLowerCase()===w.current[0]?.toLowerCase()?(x(w.current[0]),I(k[0])):v("label",S)},onChange:(e,t,r,o)=>{N.current=!0,I(t)},onInputChange:(e,t,r)=>{x(t),h(r)},onKeyDown:e=>{"enter"===getKeyString(e)&&e.stopPropagation()},options:k,PopperComponent:StyledPopper,renderOption:(e,t,{inputValue:r})=>{if(t===pendingOption){var o=clsx(e.className,popperClasses.skeletonOption);return React.createElement("li",{...e,className:o,key:e.id},React.createElement(StyledSkeleton,null))}o=getItemId(t,j.current),o={...e,className:clsx(e.className,t.styleName?makeSafeClassName(t.styleName):void 0),title:t.tooltip?f(t.tooltip):void 0,inputText:r,optionText:o?w.current[o]:""};return React.createElement(HighlightOption,{...o})},renderInput:e=>(e.inputProps={...e.inputProps,id:R,placeholder:T,title:A},React.createElement(FormLabelTextField,{error:!!l,...e,fullWidth:!0,inputRef:L})),value:O}))};export default AutoComplete;
@@ -1,13 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
3
- export interface ButtonBarProps extends BaseFormElementProps {
4
- /**
5
- * Defines the space between immediate children.
6
- */
7
- spacing?: number;
8
- }
2
+ import { FormElementProps } from "../..";
3
+ import { defs } from "../FormHost";
9
4
  /**
10
5
  * The component for the "Button Bar" Form Element.
11
6
  */
12
- declare const ButtonBar: ({ className, component, element, spacing }: ButtonBarProps) => JSX.Element;
7
+ declare const ButtonBar: ({ className, component, element, enabled, items: elementItems, name, orientation, raiseEvent, renderFocus: hostRenderFocus, renderText, translateText, }: FormElementProps<defs.Value | undefined>) => JSX.Element;
13
8
  export default ButtonBar;
@@ -1 +1 @@
1
- import Button from"@vertigis/react-ui/Button";import Stack,{stackClasses}from"@vertigis/react-ui/Stack";import{styled}from"@vertigis/react-ui/styles";import*as React from"react";import FormElement from"../FormElement.js";import{Orientation}from"../constants.js";import{makeSafeClassName,sort}from"../utils.js";import Markdown from"./Markdown.js";const Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${stackClasses.root}`]:{alignItems:"flex-start",flexWrap:"wrap",marginTop:e(1),marginBottom:e(1)}})),ButtonBar=({className:e,component:c,element:t,spacing:a})=>{const{host:p,name:u}=c.props,d=sort(t.items);let f;void 0===a&&(a=1);return React.createElement(Root,{className:e,component:c,element:t},React.createElement(Stack,{direction:t.orientation===Orientation.VERTICAL?"column":"row",spacing:a},Object.keys(d).map(e=>{var t,a,o,r=d[e],n=r.styleName?makeSafeClassName(r.styleName):void 0,i=!1!==r.visible,s=c.enabled&&!1!==r.enabled&&i,m=p.renderText(r.tooltip),l=d[e]["value"];return s&&void 0===f&&(f=e),i?React.createElement(Button,{onClick:(a=e,o=l,function(e){p.post("clicked",{name:u,item:a,value:o})}),className:n,color:r.default?"primary":"inherit",disabled:!s,key:e,ref:(t=e,function(e){null!==e&&t===f&&p.renderFocus(e,u)}),title:m,variant:r.default?"contained":"outlined"},React.createElement(Markdown,{host:p,inline:!0,text:r.label||""})):null})))};export default ButtonBar;
1
+ import Button from"@vertigis/react-ui/Button";import Stack,{stackClasses}from"@vertigis/react-ui/Stack";import{styled}from"@vertigis/react-ui/styles";import*as React from"react";import FormElement from"../FormElement.js";import{Orientation}from"../constants.js";import{makeSafeClassName,sortAndFilter}from"../utils.js";import Markdown from"./Markdown.js";const Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${stackClasses.root}`]:{alignItems:"flex-start",flexWrap:"wrap",marginTop:e(1),marginBottom:e(1)}})),ButtonBar=({className:e,component:t,element:a,enabled:c,items:r,name:d,orientation:o,raiseEvent:u,renderFocus:p,renderText:f,translateText:k})=>{const v=sortAndFilter(r);let E;return React.createElement(Root,{className:e,component:t,element:a},React.createElement(Stack,{direction:o===Orientation.VERTICAL?"column":"row",spacing:1},Object.keys(v).map(e=>{var t,a,r,o=v[e],n=o.styleName?makeSafeClassName(o.styleName):void 0,i=!1!==o.visible,l=c&&!1!==o.enabled&&i,s=f(o.tooltip),m=v[e]["value"];return l&&void 0===E&&(E=e),i?React.createElement(Button,{onClick:(a=e,r=m,function(e){u("clicked",r,void 0,a)}),className:n,color:o.default?"primary":"inherit",disabled:!l,key:e,ref:(t=e,function(e){null!==e&&t===E&&p(e,d)}),title:s,variant:o.default?"contained":"outlined"},React.createElement(Markdown,{inline:!0,text:o.label||"",translateText:k})):null})))};export default ButtonBar;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
3
  /**
4
4
  * The component for the "Check Box" Form Element.
5
5
  */
6
- declare const CheckBox: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
6
+ declare const CheckBox: ({ checked, className, component, element, enabled, label, name, raiseEvent, renderFocus: hostRenderFocus, renderText, setProperty, tooltip: elementTooltip, translateText, value, }: FormElementProps) => JSX.Element;
7
7
  export default CheckBox;
@@ -1 +1 @@
1
- import Checkbox from"@vertigis/react-ui/Checkbox";import FormControlLabel from"@vertigis/react-ui/FormControlLabel";import*as React from"react";import{useEffect,useState}from"react";import FormElement from"../FormElement.js";import Markdown from"./Markdown.js";const CheckBox=({className:e,component:t,element:o})=>{const[r,a]=useState(!1),[c,l]=useState(null),{host:n,name:m}=t.props;var s=n.renderText(o.tooltip);useEffect(()=>{a(!!o.checked)},[o.checked]),useEffect(()=>{l(React.createElement(Markdown,{host:n,text:o.label}))},[o.label]);return React.createElement(FormElement,{className:e,component:t,element:o},React.createElement(FormControlLabel,{control:React.createElement(Checkbox,{checked:r,onChange:e=>{e=e.target.checked;o.checked=e,n.post("changed",{name:m,value:e?o.value:void 0,argument:e}),a(e)},inputRef:e=>{null===e||e.disabled||n.renderFocus(e,m)}}),disabled:!t.enabled,label:c,title:s}))};export default CheckBox;
1
+ import Checkbox from"@vertigis/react-ui/Checkbox";import FormControlLabel from"@vertigis/react-ui/FormControlLabel";import*as React from"react";import FormElement from"../FormElement.js";import Markdown from"./Markdown.js";const CheckBox=({checked:e,className:t,component:r,element:o,enabled:a,label:n,name:c,raiseEvent:l,renderFocus:m,renderText:i,setProperty:d,tooltip:s,translateText:k,value:b})=>{s=i(s);return React.createElement(FormElement,{className:t,component:r,element:o},React.createElement(FormControlLabel,{control:React.createElement(Checkbox,{checked:e,onChange:e=>{e=e.target.checked;d("checked",e),l("changed",e?b:void 0,e)},inputRef:e=>{null===e||e.disabled||m(e,c)}}),disabled:!a,label:React.createElement(Markdown,{text:n,translateText:k}),title:s}))};export default CheckBox;
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
+ import { defs } from "../FormHost";
3
4
  /**
4
5
  * The component for the "Check Group" Form Element.
5
6
  */
6
- declare const CheckGroup: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
7
+ declare const CheckGroup: ({ className, component, current, element, enabled, items: elementItems, name, orientation, raiseEvent, renderFocus: hostRenderFocus, renderText, setProperty, setValue, translateText, value, }: FormElementProps<defs.ItemsRef | undefined>) => JSX.Element;
7
8
  export default CheckGroup;
@@ -1 +1 @@
1
- import Checkbox from"@vertigis/react-ui/Checkbox";import FormControlLabel from"@vertigis/react-ui/FormControlLabel";import FormGroup,{formGroupClasses}from"@vertigis/react-ui/FormGroup";import{styled}from"@vertigis/react-ui/styles";import*as React from"react";import{useEffect,useState}from"react";import FormElement from"../FormElement.js";import{Orientation}from"../constants.js";import{makeSafeClassName,sortItems}from"../utils.js";import Markdown from"./Markdown.js";const Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${formGroupClasses.root}`]:{paddingBottom:e(2)}})),CheckGroup=({className:e,component:t,element:a})=>{const[n,m]=useState([]),{host:o,name:s}=t.props,c=sortItems(a);useEffect(()=>{l()});var r=e=>{null===e||e.disabled||o.renderFocus(e,s)};function l(){const e=[],t=[];for(const o in c){var r=c[o];r.checked&&(e.push(r),t.push(o))}0===e.length?a.value=void 0:a.value={refValueType:"items",items:e},a.current=void 0,i(t,n)||m(t)}const i=(t,r)=>{if(!t&&!r)return!0;if(!t||!r)return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==r[e])return!1;return!0};const u=[];for(const v in c){var f=c[v],p=-1!==n.indexOf(v),d=t.enabled&&!1!==f.enabled,h=o.renderText(f.tooltip),k=f.styleName?makeSafeClassName(f.styleName):void 0;u.push(React.createElement(FormControlLabel,{className:k,control:React.createElement(Checkbox,{checked:p,onChange:((t,r)=>function(e){e=c[t].checked=e.currentTarget.checked;l(),o.post("changed",{name:s,item:t,value:e?r:void 0,argument:e})})(v,f.value),inputRef:r}),disabled:!d,key:v,label:React.createElement(Markdown,{host:o,text:f.label}),title:h}))}return React.createElement(Root,{className:e,component:t,element:a},React.createElement(FormGroup,{row:a.orientation===Orientation.HORIZONTAL},u))};export default CheckGroup;
1
+ import Checkbox from"@vertigis/react-ui/Checkbox";import FormControlLabel from"@vertigis/react-ui/FormControlLabel";import FormGroup,{formGroupClasses}from"@vertigis/react-ui/FormGroup";import{styled}from"@vertigis/react-ui/styles";import*as React from"react";import{useEffect,useState}from"react";import FormElement from"../FormElement.js";import{Orientation}from"../constants.js";import{arrayEqual}from"../listUtilities.js";import{makeSafeClassName,inspectItems}from"../utils.js";import Markdown from"./Markdown.js";const Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${formGroupClasses.root}`]:{paddingBottom:e(2)}})),CheckGroup=({className:e,component:t,current:o,element:r,enabled:a,items:s,name:n,orientation:m,raiseEvent:c,renderFocus:i,renderText:l,setProperty:u,setValue:p,translateText:d,value:f})=>{const[h,v]=useState([]),[k,C]=useState();useEffect(()=>{var e=inspectItems(o,s,f)["items"];C(e);const t=[];for(const r in e)e[r].checked&&t.push(r);v(t)},[s]);var E=e=>{null===e||e.disabled||i(e,n)};var b=(r,o)=>function(e){const t=k?k[r]:void 0;t&&(e=t.checked=e.currentTarget.checked,function(){const e=[],t=[];for(const a in k){var r=k[a];r.checked&&(e.push(r),t.push(a))}var o=0===e.length?void 0:{refValueType:"items",items:e};p(o,!1),u("current",void 0),arrayEqual(t,h)||v(t)}(),c("changed",e?o:void 0,e,r))};const g=[];for(const G in k){var y=k[G],F=-1!==h.indexOf(G),R=a&&!1!==y.enabled,x=l(y.tooltip),N=y.styleName?makeSafeClassName(y.styleName):void 0;g.push(React.createElement(FormControlLabel,{className:N,control:React.createElement(Checkbox,{checked:F,onChange:b(G,y.value),inputRef:E}),disabled:!R,key:G,label:React.createElement(Markdown,{text:y.label,translateText:d}),title:x}))}return React.createElement(Root,{className:e,component:t,element:r},React.createElement(FormGroup,{row:m===Orientation.HORIZONTAL},g))};export default CheckGroup;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
3
  /**
4
4
  * The component for the "Custom" Form Element.
5
5
  */
6
- declare const Custom: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
6
+ declare const Custom: ({ className, component, customType, element }: FormElementProps) => JSX.Element;
7
7
  export default Custom;
@@ -1 +1 @@
1
- import*as React from"react";import{createElement}from"react";import FormElement from"../FormElement.js";import{getElementProps}from"../utils.js";const Custom=({className:e,component:t,element:m})=>{var o=t.props.name;let r;return r=t.elementRegistration?createElement(t.elementRegistration.component,getElementProps(t,m)):(console.warn(`Unable to render custom form element '${o}' of type '${m.customType}'.`),`--- ${m.customType} ---`),React.createElement(FormElement,{className:e,component:t,element:m},r)};export default Custom;
1
+ import*as React from"react";import{createElement}from"react";import FormElement from"../FormElement.js";import{getElementProps}from"../utils.js";const Custom=({className:e,component:t,customType:m,element:o})=>{var r=t.props.name;let n;return m&&t.elementRegistration&&(n=createElement(t.elementRegistration.component,getElementProps(t,o))),n||(console.warn(`Unable to render custom form element '${r}' of type '${m}'.`),n=`--- ${m} ---`),React.createElement(FormElement,{className:e,component:t,element:o},n)};export default Custom;
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
+ import { defs } from "../FormHost";
3
4
  /**
4
5
  * The component for the "Date Picker" Form Element.
5
6
  */
6
- declare const DatePicker: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
7
+ declare const DatePicker: ({ className, component, deriveLocale, element, enabled, error, name, prompt, renderFocus, renderText, tooltip: elementTooltip, value: elementValue, setProperty, setValue: setElementValue, }: FormElementProps<defs.DateTimeRef | undefined>) => JSX.Element;
7
8
  export default DatePicker;
@@ -1 +1 @@
1
- import BaseDatePicker from"@vertigis/react-ui/DatePicker";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import*as React from"react";import{useEffect,useRef,useState}from"react";import{Calendar}from"../Calendar.js";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{hasErrorChanged,isInvalidDate,makeProperFormat,makeProperValue,updateElementValue}from"../dateUtilities.js";import{isDateTimeRef,makeUniqueId}from"../utils.js";const DatePicker=({className:e,component:t,element:r})=>{const[a,o]=useState(!1),[l,n]=useState(!1),[s,i]=useState(null),m=useRef(),u=useRef(!0),{host:c,name:p}=t.props;var d=useFocusCallback(t);const f=c.renderText(r.tooltip),v=makeProperFormat(r.value,r.format),F=Calendar.useNative(),k="date";useEffect(()=>{var e=makeProperValue(r.value,F);updateElementValue(r,e,k,v,F),i(e||null)},[r.value]),useEffect(()=>{if(u.current)u.current=!1;else if(!l&&!a)if(isInvalidDate(s))E({status:"invalid"});else{E();let e=s||void 0;if(e&&isDateTimeRef(r.value)){const t=new Date(r.value.value);e=new Date(e),e.setHours(t.getHours()),e.setMinutes(t.getMinutes()),e.setSeconds(t.getSeconds()),e.setMilliseconds(t.getMilliseconds())}updateElementValue(r,e,k,v,F)&&c.post("changed",{name:p,value:r.value})}},[l,a]);const E=e=>{hasErrorChanged(r,e)&&(r.error=e,t.forceUpdate())},P=`${makeUniqueId(p)}-input`,g=c.renderText(r.prompt);return React.createElement(FormElement,{className:e,component:t,element:r,inputId:P},r.error&&React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},m.current),React.createElement(BaseDatePicker,{disabled:!t.enabled,key:"date-picker",inputRef:d,onChange:e=>{i(e)},onOpen:()=>{n(!0)},onClose:()=>{n(!1)},renderInput:e=>(m.current=e.inputProps?.placeholder,e.error=!!r.error,e.inputProps={...e.inputProps,id:P,onBlur:()=>{o(!1)},onFocus:()=>{o(!0)},placeholder:g||e.inputProps?.placeholder,title:f},React.createElement(FormLabelTextField,{...e})),value:s}))};export default DatePicker;
1
+ import BaseDatePicker from"@vertigis/react-ui/DatePicker";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import*as React from"react";import{useEffect,useRef,useState}from"react";import{Calendar}from"../Calendar.js";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{areValuesEqual,getNewElementValue,hasErrorChanged,isInvalidDate,makeProperValue}from"../dateUtilities.js";import{isDateTimeRef,makeUniqueId}from"../utils.js";const DatePicker=({className:e,component:t,deriveLocale:r,element:a,enabled:o,error:l,name:s,prompt:n,renderFocus:i,renderText:m,tooltip:u,value:c,setProperty:p,setValue:d})=>{const[f,E]=useState(!1),[F,v]=useState(!1),[g,k]=useState(null),D=useRef(),P=useRef(!0);i=useFocusCallback(o,s,i);const R=m(u),T={locale:r(),timezone:(new Intl.DateTimeFormat).resolvedOptions().timeZone},C=Calendar.useNative(),V="date";useEffect(()=>{var e=makeProperValue(c,C),t=getNewElementValue(e,V,T,C);areValuesEqual(c,t)||d(t,!1),k(e||null)},[c]),useEffect(()=>{if(P.current)P.current=!1;else if(!F&&!f)if(isInvalidDate(g))h({status:"invalid"});else{h();let e=g||void 0;if(e&&isDateTimeRef(c)){const r=new Date(c.value);e=new Date(e),e.setHours(r.getHours()),e.setMinutes(r.getMinutes()),e.setSeconds(r.getSeconds()),e.setMilliseconds(r.getMilliseconds())}var t=getNewElementValue(e,V,T,C);areValuesEqual(c,t)||d(t)}},[F,f]);const h=e=>{hasErrorChanged(l,e)&&p("error",e)},x=`${makeUniqueId(s)}-input`,b=m(n);return React.createElement(FormElement,{className:e,component:t,element:a,inputId:x},l&&React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},D.current),React.createElement(BaseDatePicker,{disabled:!o,key:"date-picker",inputRef:i,onChange:e=>{k(e)},onOpen:()=>{v(!0)},onClose:()=>{v(!1)},renderInput:e=>(D.current=e.inputProps?.placeholder,e.error=!!l,e.inputProps={...e.inputProps,id:x,onBlur:()=>{E(!1)},onFocus:()=>{E(!0)},placeholder:b||e.inputProps?.placeholder,title:R},React.createElement(FormLabelTextField,{...e})),value:g}))};export default DatePicker;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- import { BaseFormElementProps } from "../FormElement";
2
+ import { FormElementProps } from "../..";
3
+ import { DateRangeRef } from "../FormDefinition";
3
4
  export declare const dateRangePickerClasses: {
4
5
  root: string;
5
6
  toLabel: string;
@@ -7,5 +8,5 @@ export declare const dateRangePickerClasses: {
7
8
  /**
8
9
  * The component for the "Date Range Picker" Form Element.
9
10
  */
10
- declare const DateRangePicker: ({ className, component, element }: BaseFormElementProps) => JSX.Element;
11
+ declare const DateRangePicker: ({ className, component, element, enabled, error, name, renderFocus, renderText, tooltip: elementTooltip, value: elementValue, setProperty, setValue: setElementValue, }: FormElementProps<DateRangeRef | undefined>) => JSX.Element;
11
12
  export default DateRangePicker;
@@ -1 +1 @@
1
- import Box from"@vertigis/react-ui/Box";import BaseDateRangePicker from"@vertigis/react-ui/DateRangePicker";import{formControlClasses}from"@vertigis/react-ui/FormControl";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import{styled}from"@vertigis/react-ui/styles";import clsx from"clsx";import{useEffect,useRef,useState}from"react";import*as React from"react";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{areValuesEqual,convertToDateRangeRef,hasErrorChanged,isInvalidDate}from"../dateUtilities.js";import{makeUniqueId}from"../utils.js";const PREFIX="DateRangePicker",dateRangePickerClasses={root:`${PREFIX}-root`,toLabel:`${PREFIX}-toLabel`},Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${formControlClasses.root}`]:{flexGrow:1},[`.${dateRangePickerClasses.toLabel}`]:{marginLeft:e(2),marginRight:e(2),paddingTop:e(2),alignSelf:"center"}})),DateRangePicker=({className:e,component:t,element:r})=>{const[a,o]=useState(-1),[n,l]=useState([!1,!1]),s=useRef(),[i,c]=useState(!1),[m,u]=useState([null,null]),p=useRef(!0);useEffect(()=>{var e=convertToDateRangeRef(r.value),e=[e?.startDate||null,e?.endDate||null];u(e),E(e)},[r.value]),useEffect(()=>{var e,t;p.current?p.current=!1:(e=0===a?n[0]:isInvalidDate(m[0]),t=1===a?n[1]:isInvalidDate(m[1]),l([e,t]),e||t?d({status:"invalid"}):d(),i||-1!==a||r.error||E(m)&&R.post("changed",{name:g,value:r.value}))},[i,a]);const d=e=>{hasErrorChanged(r,e)&&(r.error=e,t.forceUpdate())};var f=!t.enabled;const{host:R,name:g}=t.props,v=R.renderText(r.tooltip),F=useFocusCallback(t),E=e=>{if(e[0]&&e[1]){e={refValueType:"daterange",startDate:e[0],endDate:e[1]};if(!areValuesEqual(r,e))return r.value=e,!0}else if(void 0!==r.value)return!(r.value=void 0);return!1},P=`${makeUniqueId(g)}-input`;return React.createElement(Root,{className:clsx(e,dateRangePickerClasses.root),component:t,element:r,inputId:P},r.error&&React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},s.current),React.createElement(BaseDateRangePicker,{disabled:f,onChange:e=>{u(e)},onOpen:()=>{c(!0)},onClose:()=>{c(!1)},renderInput:(e,t)=>(s.current=e.inputProps?.placeholder,e.error=!!r.error&&n[0],e.inputProps={...e.inputProps,id:P,title:v,onBlur:()=>{o(-1)},onFocus:()=>{o(0)}},e.inputRef=F,t.error=!!r.error&&n[1],t.inputProps={...t.inputProps,title:v,onBlur:()=>{o(-1)},onFocus:()=>{o(1)}},React.createElement(React.Fragment,null,React.createElement(FormLabelTextField,{...e}),React.createElement(Box,{className:dateRangePickerClasses.toLabel}," ",R.renderText("@common-to")," "),React.createElement(FormLabelTextField,{...t}))),value:m}))};export default DateRangePicker;export{dateRangePickerClasses};
1
+ import Box from"@vertigis/react-ui/Box";import BaseDateRangePicker from"@vertigis/react-ui/DateRangePicker";import{formControlClasses}from"@vertigis/react-ui/FormControl";import FormHelperText from"@vertigis/react-ui/FormHelperText";import FormLabelTextField from"@vertigis/react-ui/FormLabelTextField";import{styled}from"@vertigis/react-ui/styles";import clsx from"clsx";import{useEffect,useRef,useState}from"react";import*as React from"react";import FormElement from"../FormElement.js";import{useFocusCallback}from"../common.js";import{areValuesEqual,convertToDateRangeRef,hasErrorChanged,isInvalidDate}from"../dateUtilities.js";import{makeUniqueId}from"../utils.js";const PREFIX="DateRangePicker",dateRangePickerClasses={root:`${PREFIX}-root`,toLabel:`${PREFIX}-toLabel`},Root=styled(FormElement)(({theme:{spacing:e}})=>({[`.${formControlClasses.root}`]:{flexGrow:1},[`.${dateRangePickerClasses.toLabel}`]:{marginLeft:e(2),marginRight:e(2),paddingTop:e(2),alignSelf:"center"}})),DateRangePicker=({className:e,component:t,element:r,enabled:a,error:o,name:n,renderFocus:l,renderText:s,tooltip:i,value:c,setProperty:m,setValue:u})=>{const[p,d]=useState(-1),[R,f]=useState([!1,!1]),g=useRef(),[F,E]=useState(!1),[P,v]=useState([null,null]),x=useRef(!0);useEffect(()=>{var e=convertToDateRangeRef(c),t=[e?.startDate||null,e?.endDate||null],e=b(t);areValuesEqual(c,e)||u(e,!1),v(t)},[c]),useEffect(()=>{var e,t;x.current?x.current=!1:(e=0===p?R[0]:isInvalidDate(P[0]),t=1===p?R[1]:isInvalidDate(P[1]),f([e,t]),t=e||t?{status:"invalid"}:void 0,C(t),F||-1!==p||t||(t=b(P),areValuesEqual(c,t)||u(t)))},[F,p]);const C=e=>{hasErrorChanged(o,e)&&m("error",e)},k=s(i),D=useFocusCallback(a,n,l),b=e=>{if(e[0]&&e[1])return{refValueType:"daterange",startDate:e[0],endDate:e[1]}},T=`${makeUniqueId(n)}-input`;return React.createElement(Root,{className:clsx(e,dateRangePickerClasses.root),component:t,element:r,inputId:T},o&&React.createElement(FormHelperText,{component:"div",error:!0,role:"alert"},g.current),React.createElement(BaseDateRangePicker,{disabled:!a,onChange:e=>{v(e)},onOpen:()=>{E(!0)},onClose:()=>{E(!1)},renderInput:(e,t)=>(g.current=e.inputProps?.placeholder,e.error=!!o&&R[0],e.inputProps={...e.inputProps,id:T,title:k,onBlur:()=>{d(-1)},onFocus:()=>{d(0)}},e.inputRef=D,t.error=!!o&&R[1],t.inputProps={...t.inputProps,title:k,onBlur:()=>{d(-1)},onFocus:()=>{d(1)}},React.createElement(React.Fragment,null,React.createElement(FormLabelTextField,{...e}),React.createElement(Box,{className:dateRangePickerClasses.toLabel}," ",s("@common-to")," "),React.createElement(FormLabelTextField,{...t}))),value:P}))};export default DateRangePicker;export{dateRangePickerClasses};