@nyaruka/temba-components 0.131.2 → 0.131.3

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 (223) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/demo/components/floating-tabs/example.html +400 -0
  3. package/demo/components/flow/index.html +1 -1
  4. package/demo/data/flows/sample-flow.json +41 -2
  5. package/demo/data/flows/voicemail.json +613 -0
  6. package/demo/index.html +6 -0
  7. package/dist/locales/es.js +5 -5
  8. package/dist/locales/es.js.map +1 -1
  9. package/dist/locales/fr.js +5 -5
  10. package/dist/locales/fr.js.map +1 -1
  11. package/dist/locales/locale-codes.js +11 -2
  12. package/dist/locales/locale-codes.js.map +1 -1
  13. package/dist/locales/pt.js +5 -5
  14. package/dist/locales/pt.js.map +1 -1
  15. package/dist/temba-components.js +1109 -535
  16. package/dist/temba-components.js.map +1 -1
  17. package/out-tsc/src/display/FloatingTab.js +167 -0
  18. package/out-tsc/src/display/FloatingTab.js.map +1 -0
  19. package/out-tsc/src/display/ProgressBar.js +22 -2
  20. package/out-tsc/src/display/ProgressBar.js.map +1 -1
  21. package/out-tsc/src/events.js.map +1 -1
  22. package/out-tsc/src/flow/CanvasNode.js +165 -31
  23. package/out-tsc/src/flow/CanvasNode.js.map +1 -1
  24. package/out-tsc/src/flow/Editor.js +857 -3
  25. package/out-tsc/src/flow/Editor.js.map +1 -1
  26. package/out-tsc/src/flow/NodeEditor.js +239 -19
  27. package/out-tsc/src/flow/NodeEditor.js.map +1 -1
  28. package/out-tsc/src/flow/NodeTypeSelector.js +44 -3
  29. package/out-tsc/src/flow/NodeTypeSelector.js.map +1 -1
  30. package/out-tsc/src/flow/StickyNote.js +12 -3
  31. package/out-tsc/src/flow/StickyNote.js.map +1 -1
  32. package/out-tsc/src/flow/actions/add_contact_groups.js +2 -1
  33. package/out-tsc/src/flow/actions/add_contact_groups.js.map +1 -1
  34. package/out-tsc/src/flow/actions/add_contact_urn.js +2 -1
  35. package/out-tsc/src/flow/actions/add_contact_urn.js.map +1 -1
  36. package/out-tsc/src/flow/actions/add_input_labels.js +2 -1
  37. package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
  38. package/out-tsc/src/flow/actions/play_audio.js +2 -1
  39. package/out-tsc/src/flow/actions/play_audio.js.map +1 -1
  40. package/out-tsc/src/flow/actions/remove_contact_groups.js +2 -1
  41. package/out-tsc/src/flow/actions/remove_contact_groups.js.map +1 -1
  42. package/out-tsc/src/flow/actions/request_optin.js +1 -0
  43. package/out-tsc/src/flow/actions/request_optin.js.map +1 -1
  44. package/out-tsc/src/flow/actions/say_msg.js +2 -1
  45. package/out-tsc/src/flow/actions/say_msg.js.map +1 -1
  46. package/out-tsc/src/flow/actions/send_broadcast.js +2 -1
  47. package/out-tsc/src/flow/actions/send_broadcast.js.map +1 -1
  48. package/out-tsc/src/flow/actions/send_email.js +2 -1
  49. package/out-tsc/src/flow/actions/send_email.js.map +1 -1
  50. package/out-tsc/src/flow/actions/send_msg.js +93 -3
  51. package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
  52. package/out-tsc/src/flow/actions/set_contact_channel.js +2 -1
  53. package/out-tsc/src/flow/actions/set_contact_channel.js.map +1 -1
  54. package/out-tsc/src/flow/actions/set_contact_field.js +2 -1
  55. package/out-tsc/src/flow/actions/set_contact_field.js.map +1 -1
  56. package/out-tsc/src/flow/actions/set_contact_language.js +2 -1
  57. package/out-tsc/src/flow/actions/set_contact_language.js.map +1 -1
  58. package/out-tsc/src/flow/actions/set_contact_name.js +2 -1
  59. package/out-tsc/src/flow/actions/set_contact_name.js.map +1 -1
  60. package/out-tsc/src/flow/actions/set_contact_status.js +2 -1
  61. package/out-tsc/src/flow/actions/set_contact_status.js.map +1 -1
  62. package/out-tsc/src/flow/actions/set_run_result.js +2 -1
  63. package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
  64. package/out-tsc/src/flow/actions/start_session.js +2 -1
  65. package/out-tsc/src/flow/actions/start_session.js.map +1 -1
  66. package/out-tsc/src/flow/config.js +2 -10
  67. package/out-tsc/src/flow/config.js.map +1 -1
  68. package/out-tsc/src/flow/nodes/shared.js +54 -0
  69. package/out-tsc/src/flow/nodes/shared.js.map +1 -1
  70. package/out-tsc/src/flow/nodes/split_by_airtime.js +9 -3
  71. package/out-tsc/src/flow/nodes/split_by_airtime.js.map +1 -1
  72. package/out-tsc/src/flow/nodes/split_by_contact_field.js +8 -3
  73. package/out-tsc/src/flow/nodes/split_by_contact_field.js.map +1 -1
  74. package/out-tsc/src/flow/nodes/split_by_expression.js +8 -3
  75. package/out-tsc/src/flow/nodes/split_by_expression.js.map +1 -1
  76. package/out-tsc/src/flow/nodes/split_by_groups.js +8 -3
  77. package/out-tsc/src/flow/nodes/split_by_groups.js.map +1 -1
  78. package/out-tsc/src/flow/nodes/split_by_intent.js +3 -2
  79. package/out-tsc/src/flow/nodes/split_by_intent.js.map +1 -1
  80. package/out-tsc/src/flow/nodes/split_by_llm.js +9 -2
  81. package/out-tsc/src/flow/nodes/split_by_llm.js.map +1 -1
  82. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +9 -2
  83. package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -1
  84. package/out-tsc/src/flow/nodes/split_by_random.js +8 -2
  85. package/out-tsc/src/flow/nodes/split_by_random.js.map +1 -1
  86. package/out-tsc/src/flow/nodes/split_by_resthook.js +8 -3
  87. package/out-tsc/src/flow/nodes/split_by_resthook.js.map +1 -1
  88. package/out-tsc/src/flow/nodes/split_by_run_result.js +8 -3
  89. package/out-tsc/src/flow/nodes/split_by_run_result.js.map +1 -1
  90. package/out-tsc/src/flow/nodes/split_by_scheme.js +8 -3
  91. package/out-tsc/src/flow/nodes/split_by_scheme.js.map +1 -1
  92. package/out-tsc/src/flow/nodes/split_by_subflow.js +8 -2
  93. package/out-tsc/src/flow/nodes/split_by_subflow.js.map +1 -1
  94. package/out-tsc/src/flow/nodes/split_by_ticket.js +8 -2
  95. package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -1
  96. package/out-tsc/src/flow/nodes/split_by_webhook.js +8 -2
  97. package/out-tsc/src/flow/nodes/split_by_webhook.js.map +1 -1
  98. package/out-tsc/src/flow/nodes/wait_for_digits.js +3 -2
  99. package/out-tsc/src/flow/nodes/wait_for_digits.js.map +1 -1
  100. package/out-tsc/src/flow/nodes/wait_for_menu.js +3 -2
  101. package/out-tsc/src/flow/nodes/wait_for_menu.js.map +1 -1
  102. package/out-tsc/src/flow/nodes/wait_for_response.js +8 -3
  103. package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
  104. package/out-tsc/src/flow/types.js +15 -0
  105. package/out-tsc/src/flow/types.js.map +1 -1
  106. package/out-tsc/src/layout/FloatingWindow.js +346 -0
  107. package/out-tsc/src/layout/FloatingWindow.js.map +1 -0
  108. package/out-tsc/src/live/ContactChat.js +3 -19
  109. package/out-tsc/src/live/ContactChat.js.map +1 -1
  110. package/out-tsc/src/locales/es.js +5 -5
  111. package/out-tsc/src/locales/es.js.map +1 -1
  112. package/out-tsc/src/locales/fr.js +5 -5
  113. package/out-tsc/src/locales/fr.js.map +1 -1
  114. package/out-tsc/src/locales/locale-codes.js +11 -2
  115. package/out-tsc/src/locales/locale-codes.js.map +1 -1
  116. package/out-tsc/src/locales/pt.js +5 -5
  117. package/out-tsc/src/locales/pt.js.map +1 -1
  118. package/out-tsc/src/store/AppState.js +67 -0
  119. package/out-tsc/src/store/AppState.js.map +1 -1
  120. package/out-tsc/temba-modules.js +4 -0
  121. package/out-tsc/temba-modules.js.map +1 -1
  122. package/out-tsc/test/temba-floating-tab.test.js +91 -0
  123. package/out-tsc/test/temba-floating-tab.test.js.map +1 -0
  124. package/out-tsc/test/temba-floating-window.test.js +301 -0
  125. package/out-tsc/test/temba-floating-window.test.js.map +1 -0
  126. package/out-tsc/test/temba-flow-editor-node.test.js +117 -0
  127. package/out-tsc/test/temba-flow-editor-node.test.js.map +1 -1
  128. package/out-tsc/test/temba-localization.test.js +471 -0
  129. package/out-tsc/test/temba-localization.test.js.map +1 -0
  130. package/out-tsc/test/temba-node-type-selector.test.js +150 -0
  131. package/out-tsc/test/temba-node-type-selector.test.js.map +1 -1
  132. package/out-tsc/test/utils.test.js +18 -0
  133. package/out-tsc/test/utils.test.js.map +1 -1
  134. package/package.json +1 -1
  135. package/screenshots/truth/floating-tab/default.png +0 -0
  136. package/screenshots/truth/floating-tab/gray.png +0 -0
  137. package/screenshots/truth/floating-tab/green.png +0 -0
  138. package/screenshots/truth/floating-tab/hidden.png +0 -0
  139. package/screenshots/truth/floating-tab/hover.png +0 -0
  140. package/screenshots/truth/floating-tab/purple.png +0 -0
  141. package/screenshots/truth/floating-window/chromeless.png +0 -0
  142. package/screenshots/truth/floating-window/custom-size.png +0 -0
  143. package/screenshots/truth/floating-window/default.png +0 -0
  144. package/screenshots/truth/floating-window/with-header.png +0 -0
  145. package/screenshots/truth/node-type-selector/action-mode.png +0 -0
  146. package/screenshots/truth/node-type-selector/split-mode.png +0 -0
  147. package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
  148. package/src/display/FloatingTab.ts +174 -0
  149. package/src/display/ProgressBar.ts +22 -2
  150. package/src/events.ts +2 -4
  151. package/src/flow/CanvasNode.ts +190 -32
  152. package/src/flow/Editor.ts +1040 -3
  153. package/src/flow/NodeEditor.ts +317 -19
  154. package/src/flow/NodeTypeSelector.ts +47 -3
  155. package/src/flow/StickyNote.ts +12 -3
  156. package/src/flow/actions/add_contact_groups.ts +2 -1
  157. package/src/flow/actions/add_contact_urn.ts +3 -1
  158. package/src/flow/actions/add_input_labels.ts +2 -1
  159. package/src/flow/actions/play_audio.ts +2 -1
  160. package/src/flow/actions/remove_contact_groups.ts +3 -1
  161. package/src/flow/actions/request_optin.ts +1 -0
  162. package/src/flow/actions/say_msg.ts +2 -1
  163. package/src/flow/actions/send_broadcast.ts +2 -1
  164. package/src/flow/actions/send_email.ts +3 -1
  165. package/src/flow/actions/send_msg.ts +134 -3
  166. package/src/flow/actions/set_contact_channel.ts +2 -1
  167. package/src/flow/actions/set_contact_field.ts +2 -1
  168. package/src/flow/actions/set_contact_language.ts +3 -1
  169. package/src/flow/actions/set_contact_name.ts +2 -1
  170. package/src/flow/actions/set_contact_status.ts +2 -1
  171. package/src/flow/actions/set_run_result.ts +2 -1
  172. package/src/flow/actions/start_session.ts +3 -1
  173. package/src/flow/config.ts +2 -12
  174. package/src/flow/nodes/shared.ts +70 -1
  175. package/src/flow/nodes/split_by_airtime.ts +20 -3
  176. package/src/flow/nodes/split_by_contact_field.ts +13 -3
  177. package/src/flow/nodes/split_by_expression.ts +13 -3
  178. package/src/flow/nodes/split_by_groups.ts +13 -3
  179. package/src/flow/nodes/split_by_intent.ts +3 -2
  180. package/src/flow/nodes/split_by_llm.ts +19 -2
  181. package/src/flow/nodes/split_by_llm_categorize.ts +19 -2
  182. package/src/flow/nodes/split_by_random.ts +12 -2
  183. package/src/flow/nodes/split_by_resthook.ts +13 -3
  184. package/src/flow/nodes/split_by_run_result.ts +13 -3
  185. package/src/flow/nodes/split_by_scheme.ts +13 -3
  186. package/src/flow/nodes/split_by_subflow.ts +12 -2
  187. package/src/flow/nodes/split_by_ticket.ts +12 -2
  188. package/src/flow/nodes/split_by_webhook.ts +12 -2
  189. package/src/flow/nodes/wait_for_digits.ts +3 -2
  190. package/src/flow/nodes/wait_for_menu.ts +3 -2
  191. package/src/flow/nodes/wait_for_response.ts +13 -3
  192. package/src/flow/types.ts +47 -0
  193. package/src/layout/FloatingWindow.ts +386 -0
  194. package/src/live/ContactChat.ts +4 -19
  195. package/src/locales/es.ts +18 -13
  196. package/src/locales/fr.ts +18 -13
  197. package/src/locales/locale-codes.ts +11 -2
  198. package/src/locales/pt.ts +18 -13
  199. package/src/store/AppState.ts +104 -0
  200. package/static/api/llms.json +18 -0
  201. package/temba-modules.ts +4 -0
  202. package/test/temba-floating-tab.test.ts +110 -0
  203. package/test/temba-floating-window.test.ts +477 -0
  204. package/test/temba-flow-editor-node.test.ts +144 -0
  205. package/test/temba-localization.test.ts +611 -0
  206. package/test/temba-node-type-selector.test.ts +203 -0
  207. package/test/utils.test.ts +20 -0
  208. package/test-assets/contacts/history.json +5 -6
  209. package/test-assets/select/llms.json +2 -2
  210. package/web-dev-server.config.mjs +47 -1
  211. package/web-test-runner.config.mjs +0 -1
  212. package/out-tsc/src/flow/nodes/wait_for_audio.js +0 -7
  213. package/out-tsc/src/flow/nodes/wait_for_audio.js.map +0 -1
  214. package/out-tsc/src/flow/nodes/wait_for_image.js +0 -7
  215. package/out-tsc/src/flow/nodes/wait_for_image.js.map +0 -1
  216. package/out-tsc/src/flow/nodes/wait_for_location.js +0 -7
  217. package/out-tsc/src/flow/nodes/wait_for_location.js.map +0 -1
  218. package/out-tsc/src/flow/nodes/wait_for_video.js +0 -7
  219. package/out-tsc/src/flow/nodes/wait_for_video.js.map +0 -1
  220. package/src/flow/nodes/wait_for_audio.ts +0 -7
  221. package/src/flow/nodes/wait_for_image.ts +0 -7
  222. package/src/flow/nodes/wait_for_location.ts +0 -7
  223. package/src/flow/nodes/wait_for_video.ts +0 -7
@@ -1,7 +1,7 @@
1
- import { SPLIT_GROUPS } from '../types';
1
+ import { SPLIT_GROUPS, FlowTypes } from '../types';
2
2
  import { generateUUID, createRulesRouter } from '../../utils';
3
3
  import { getWaitForResponseOperators, operatorsToSelectOptions, getOperatorConfig } from '../operators';
4
- import { resultNameField } from './shared';
4
+ import { resultNameField, categoriesToLocalizationFormData, localizationFormDataToCategories } from './shared';
5
5
  import { createRulesArrayConfig, extractUserRules, casesToFormRules } from './shared-rules';
6
6
  const TIMEOUT_OPTIONS = [
7
7
  { value: '60', name: '1 minute' },
@@ -45,6 +45,7 @@ export const wait_for_response = {
45
45
  type: 'wait_for_response',
46
46
  name: 'Wait for Response',
47
47
  group: SPLIT_GROUPS.wait,
48
+ flowTypes: [FlowTypes.MESSAGE],
48
49
  dialogSize: 'large',
49
50
  form: {
50
51
  rules: createRulesArrayConfig(operatorsToSelectOptions(getWaitForResponseOperators()), 'Define rules to categorize responses'),
@@ -291,6 +292,10 @@ export const wait_for_response = {
291
292
  router: finalRouter,
292
293
  exits: exits
293
294
  };
294
- }
295
+ },
296
+ // Localization support for categories
297
+ localizable: 'categories',
298
+ toLocalizationFormData: categoriesToLocalizationFormData,
299
+ fromLocalizationFormData: localizationFormDataToCategories
295
300
  };
296
301
  //# sourceMappingURL=wait_for_response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wait_for_response.js","sourceRoot":"","sources":["../../../../src/flow/nodes/wait_for_response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwB,MAAM,UAAU,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,MAAM,eAAe,GAAG;IACtB,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE;IACjC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE;IACpC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE;IACpC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE;IACrC,EAAE,KAAK,EAAE,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E7C,sBAAsB;wBACtB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAErD,4BAA4B;wBAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAC/B,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,SAAS,CAC1D,CAAC;wBACF,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;4BACrB,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;wBAC7B,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAChE,4CAA4C;QAC9C,CAAC;QAED,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC;QAC9B,OAAO;YACL,GAAG,YAAY;YACf,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { SPLIT_GROUPS, FormData, NodeConfig } from '../types';\nimport { Node, Category, Exit, Case } from '../../store/flow-definition';\nimport { generateUUID, createRulesRouter } from '../../utils';\nimport {\n getWaitForResponseOperators,\n operatorsToSelectOptions,\n getOperatorConfig\n} from '../operators';\nimport { resultNameField } from './shared';\nimport {\n createRulesArrayConfig,\n extractUserRules,\n casesToFormRules\n} from './shared-rules';\n\nconst TIMEOUT_OPTIONS = [\n { value: '60', name: '1 minute' },\n { value: '120', name: '2 minutes' },\n { value: '180', name: '3 minutes' },\n { value: '240', name: '4 minutes' },\n { value: '300', name: '5 minutes' },\n { value: '600', name: '10 minutes' },\n { value: '900', name: '15 minutes' },\n { value: '1800', name: '30 minutes' },\n { value: '3600', name: '1 hour' },\n { value: '7200', name: '2 hours' },\n { value: '10800', name: '3 hours' },\n { value: '21600', name: '6 hours' },\n { value: '43200', name: '12 hours' },\n { value: '64800', name: '18 hours' },\n { value: '86400', name: '1 day' },\n { value: '172800', name: '2 days' },\n { value: '259200', name: '3 days' },\n { value: '604800', name: '1 week' }\n];\n\n// Helper function to create a wait_for_response router with user rules\n// This is a thin wrapper around createRulesRouter that adds the No Response category for timeouts\nconst createWaitForResponseRouter = (\n userRules: any[],\n existingCategories: Category[] = [],\n existingExits: Exit[] = [],\n existingCases: Case[] = []\n) => {\n const { router, exits } = createRulesRouter(\n '@input.text',\n userRules,\n getOperatorConfig,\n existingCategories,\n existingExits,\n existingCases\n );\n\n // Add \"No Response\" category last (if it exists in the original)\n const existingNoResponseCategory = existingCategories.find(\n (cat) => cat.name === 'No Response' || cat.name === 'Timeout'\n );\n\n if (existingNoResponseCategory) {\n const existingNoResponseExit = existingExits.find(\n (exit) => exit.uuid === existingNoResponseCategory.exit_uuid\n );\n\n if (existingNoResponseExit) {\n router.categories.push(existingNoResponseCategory);\n exits.push({\n uuid: existingNoResponseExit.uuid,\n destination_uuid: existingNoResponseExit.destination_uuid || null\n });\n }\n }\n\n return { router, exits };\n};\n\nexport const wait_for_response: NodeConfig = {\n type: 'wait_for_response',\n name: 'Wait for Response',\n group: SPLIT_GROUPS.wait,\n dialogSize: 'large',\n form: {\n rules: createRulesArrayConfig(\n operatorsToSelectOptions(getWaitForResponseOperators()),\n 'Define rules to categorize responses'\n ),\n timeout_enabled: {\n type: 'checkbox',\n label: (formData: Record<string, any>) => {\n return formData.timeout_enabled\n ? 'Continue when there is no response for'\n : 'Continue when there is no response..';\n },\n labelPadding: '4px 8px'\n },\n timeout_duration: {\n type: 'select',\n placeholder: '5 minutes',\n multi: false,\n maxWidth: '100px',\n flavor: 'xsmall',\n options: TIMEOUT_OPTIONS,\n\n conditions: {\n visible: (formData: Record<string, any>) => {\n return formData.timeout_enabled === true;\n }\n }\n },\n result_name: resultNameField\n },\n layout: ['rules', 'result_name'],\n gutter: [\n {\n type: 'row',\n items: ['timeout_enabled', 'timeout_duration'],\n gap: '0.5rem'\n }\n ],\n validate: (_formData: FormData) => {\n const errors: { [key: string]: string } = {};\n\n // No validation needed - allow multiple rules to use same category name\n // Rules with the same category name will be merged to use the same exit\n\n return {\n valid: Object.keys(errors).length === 0,\n errors\n };\n },\n toFormData: (node: Node) => {\n // Extract rules from router cases using shared function\n const rules = casesToFormRules(node);\n\n // Extract timeout configuration\n const timeoutSeconds = node.router?.wait?.timeout?.seconds;\n let timeoutOption = TIMEOUT_OPTIONS.find(\n (opt) => opt.value === String(timeoutSeconds)\n );\n\n if (!timeoutOption) {\n timeoutOption = { value: '300', name: '5 minutes' };\n }\n\n return {\n uuid: node.uuid,\n rules: rules,\n timeout_enabled: !!timeoutSeconds,\n timeout_duration: timeoutOption,\n result_name: node.router?.result_name || ''\n };\n },\n fromFormData: (formData: FormData, originalNode: Node): Node => {\n // Get user rules using shared extraction function\n const userRules = extractUserRules(formData);\n\n // If no user rules, clear cases but preserve other router config\n if (userRules.length === 0) {\n // Get existing router data for preservation\n let existingCategories = originalNode.router?.categories || [];\n const existingExits = [...(originalNode.exits || [])]; // Create a copy to avoid extensibility issues\n\n // Handle timeout: ensure \"No Response\" category exists if timeout is enabled,\n // or remove it if timeout is disabled\n if (formData.timeout_enabled) {\n let noResponseCategory = existingCategories.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n if (!noResponseCategory) {\n // Create new \"No Response\" category and exit\n const noResponseExitUuid = generateUUID();\n noResponseCategory = {\n uuid: generateUUID(),\n name: 'No Response',\n exit_uuid: noResponseExitUuid\n };\n\n // Add to existing categories for processing\n existingCategories = [...existingCategories, noResponseCategory];\n\n // Add corresponding exit if it doesn't exist\n if (!existingExits.find((exit) => exit.uuid === noResponseExitUuid)) {\n existingExits.push({\n uuid: noResponseExitUuid,\n destination_uuid: null\n });\n }\n }\n } else {\n // If timeout is disabled, remove \"No Response\" category from existing categories\n existingCategories = existingCategories.filter(\n (cat: any) => cat.name !== 'No Response'\n );\n }\n\n // Create router with \"All Responses\" as default category\n // This will now properly handle the \"No Response\" category if it exists\n const { router: noRulesRouter, exits: noRulesExits } =\n createWaitForResponseRouter(\n [], // No user rules\n existingCategories,\n existingExits,\n [] // No cases\n );\n\n const router: any = {\n ...noRulesRouter,\n cases: [] // Clear all cases when no rules\n };\n\n // Only set result_name if provided\n if (formData.result_name && formData.result_name.trim() !== '') {\n router.result_name = formData.result_name.trim();\n }\n\n // Build wait configuration based on form data\n const waitConfig: any = {\n type: 'msg'\n };\n\n // Add timeout if enabled\n if (formData.timeout_enabled) {\n // Extract timeout value (handle both string and object formats)\n let timeoutSeconds;\n\n if (formData.timeout_duration) {\n if (\n Array.isArray(formData.timeout_duration) &&\n formData.timeout_duration.length > 0\n ) {\n // Handle array of selected options (multi-select behavior)\n timeoutSeconds = parseInt(formData.timeout_duration[0].value, 10);\n } else if (typeof formData.timeout_duration === 'string') {\n timeoutSeconds = parseInt(formData.timeout_duration, 10);\n } else if (\n formData.timeout_duration &&\n typeof formData.timeout_duration === 'object' &&\n formData.timeout_duration.value\n ) {\n timeoutSeconds = parseInt(formData.timeout_duration.value, 10);\n } else {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n } else {\n // No duration selected, use default\n timeoutSeconds = 300; // Default to 5 minutes\n }\n\n // Validate that we got a valid number\n if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n\n // Find the \"No Response\" category (should exist now)\n const noResponseCategory = router.categories.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n if (noResponseCategory) {\n waitConfig.timeout = {\n seconds: timeoutSeconds,\n category_uuid: noResponseCategory.uuid\n };\n }\n }\n\n router.wait = waitConfig;\n\n return {\n ...originalNode,\n router,\n exits: noRulesExits\n };\n }\n\n // Get existing router data for preservation\n const existingCategories = originalNode.router?.categories || [];\n const existingExits = originalNode.exits || [];\n const existingCases = originalNode.router?.cases || [];\n\n // Create router and exits using existing data when possible\n const { router, exits } = createWaitForResponseRouter(\n userRules,\n existingCategories,\n existingExits,\n existingCases\n );\n\n // Build final router with wait configuration and result_name\n const finalRouter: any = {\n ...router\n };\n\n // Only set result_name if provided\n if (formData.result_name && formData.result_name.trim() !== '') {\n finalRouter.result_name = formData.result_name.trim();\n }\n\n // Build wait configuration based on form data\n const waitConfig: any = {\n type: 'msg'\n };\n\n try {\n // Handle timeout configuration\n if (formData.timeout_enabled) {\n // Extract timeout value (handle both string and object formats)\n let timeoutSeconds;\n\n if (formData.timeout_duration) {\n try {\n timeoutSeconds = parseInt(formData.timeout_duration[0].value, 10);\n } catch (e) {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n }\n\n // Find or create the \"No Response\" category\n const existingNoResponseCategory =\n originalNode.router?.categories?.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n const noResponseCategory = existingNoResponseCategory || {\n uuid: generateUUID(),\n name: 'No Response',\n exit_uuid: generateUUID()\n };\n\n waitConfig.timeout = {\n seconds: timeoutSeconds,\n category_uuid: noResponseCategory.uuid\n };\n\n // Ensure No Response category and exit exist\n if (\n !router.categories?.some((cat: any) => cat.name === 'No Response')\n ) {\n router.categories = router.categories || [];\n router.categories.push(noResponseCategory);\n\n // Add corresponding exit if it doesn't exist\n if (\n !exits.some(\n (exit: any) => exit.uuid === noResponseCategory.exit_uuid\n )\n ) {\n const noResponseExit = {\n uuid: noResponseCategory.exit_uuid,\n destination_uuid: existingNoResponseCategory?.exit_uuid\n ? originalNode.exits?.find(\n (exit) => exit.uuid === existingNoResponseCategory.exit_uuid\n )?.destination_uuid || null\n : null\n };\n exits.push(noResponseExit);\n }\n }\n } else {\n // Remove \"No Response\" category if timeout is disabled\n if (router.categories) {\n const noResponseCategoryIndex = router.categories.findIndex(\n (cat: any) => cat.name === 'No Response'\n );\n if (noResponseCategoryIndex !== -1) {\n const noResponseCategory =\n router.categories[noResponseCategoryIndex];\n\n // Remove the category\n router.categories.splice(noResponseCategoryIndex, 1);\n\n // Remove corresponding exit\n const exitIndex = exits.findIndex(\n (exit: any) => exit.uuid === noResponseCategory.exit_uuid\n );\n if (exitIndex !== -1) {\n exits.splice(exitIndex, 1);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error processing timeout configuration:', error);\n // Continue without timeout in case of error\n }\n\n finalRouter.wait = waitConfig;\n return {\n ...originalNode,\n router: finalRouter,\n exits: exits\n };\n }\n};\n"]}
1
+ {"version":3,"file":"wait_for_response.js","sourceRoot":"","sources":["../../../../src/flow/nodes/wait_for_response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwB,SAAS,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,gCAAgC,EAChC,gCAAgC,EACjC,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,MAAM,eAAe,GAAG;IACtB,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE;IACjC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE;IACnC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE;IACpC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE;IACpC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE;IACrC,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IACjC,E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;wBAE7C,sBAAsB;wBACtB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;wBAErD,4BAA4B;wBAC5B,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAC/B,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,SAAS,CAC1D,CAAC;wBACF,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;4BACrB,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;wBAC7B,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAChE,4CAA4C;QAC9C,CAAC;QAED,WAAW,CAAC,IAAI,GAAG,UAAU,CAAC;QAC9B,OAAO;YACL,GAAG,YAAY;YACf,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,KAAK;SACb,CAAC;IACJ,CAAC;IAED,sCAAsC;IACtC,WAAW,EAAE,YAAY;IACzB,sBAAsB,EAAE,gCAAgC;IACxD,wBAAwB,EAAE,gCAAgC;CAC3D,CAAC","sourcesContent":["import { SPLIT_GROUPS, FormData, NodeConfig, FlowTypes } from '../types';\nimport { Node, Category, Exit, Case } from '../../store/flow-definition';\nimport { generateUUID, createRulesRouter } from '../../utils';\nimport {\n getWaitForResponseOperators,\n operatorsToSelectOptions,\n getOperatorConfig\n} from '../operators';\nimport {\n resultNameField,\n categoriesToLocalizationFormData,\n localizationFormDataToCategories\n} from './shared';\nimport {\n createRulesArrayConfig,\n extractUserRules,\n casesToFormRules\n} from './shared-rules';\n\nconst TIMEOUT_OPTIONS = [\n { value: '60', name: '1 minute' },\n { value: '120', name: '2 minutes' },\n { value: '180', name: '3 minutes' },\n { value: '240', name: '4 minutes' },\n { value: '300', name: '5 minutes' },\n { value: '600', name: '10 minutes' },\n { value: '900', name: '15 minutes' },\n { value: '1800', name: '30 minutes' },\n { value: '3600', name: '1 hour' },\n { value: '7200', name: '2 hours' },\n { value: '10800', name: '3 hours' },\n { value: '21600', name: '6 hours' },\n { value: '43200', name: '12 hours' },\n { value: '64800', name: '18 hours' },\n { value: '86400', name: '1 day' },\n { value: '172800', name: '2 days' },\n { value: '259200', name: '3 days' },\n { value: '604800', name: '1 week' }\n];\n\n// Helper function to create a wait_for_response router with user rules\n// This is a thin wrapper around createRulesRouter that adds the No Response category for timeouts\nconst createWaitForResponseRouter = (\n userRules: any[],\n existingCategories: Category[] = [],\n existingExits: Exit[] = [],\n existingCases: Case[] = []\n) => {\n const { router, exits } = createRulesRouter(\n '@input.text',\n userRules,\n getOperatorConfig,\n existingCategories,\n existingExits,\n existingCases\n );\n\n // Add \"No Response\" category last (if it exists in the original)\n const existingNoResponseCategory = existingCategories.find(\n (cat) => cat.name === 'No Response' || cat.name === 'Timeout'\n );\n\n if (existingNoResponseCategory) {\n const existingNoResponseExit = existingExits.find(\n (exit) => exit.uuid === existingNoResponseCategory.exit_uuid\n );\n\n if (existingNoResponseExit) {\n router.categories.push(existingNoResponseCategory);\n exits.push({\n uuid: existingNoResponseExit.uuid,\n destination_uuid: existingNoResponseExit.destination_uuid || null\n });\n }\n }\n\n return { router, exits };\n};\n\nexport const wait_for_response: NodeConfig = {\n type: 'wait_for_response',\n name: 'Wait for Response',\n group: SPLIT_GROUPS.wait,\n flowTypes: [FlowTypes.MESSAGE],\n dialogSize: 'large',\n form: {\n rules: createRulesArrayConfig(\n operatorsToSelectOptions(getWaitForResponseOperators()),\n 'Define rules to categorize responses'\n ),\n timeout_enabled: {\n type: 'checkbox',\n label: (formData: Record<string, any>) => {\n return formData.timeout_enabled\n ? 'Continue when there is no response for'\n : 'Continue when there is no response..';\n },\n labelPadding: '4px 8px'\n },\n timeout_duration: {\n type: 'select',\n placeholder: '5 minutes',\n multi: false,\n maxWidth: '100px',\n flavor: 'xsmall',\n options: TIMEOUT_OPTIONS,\n\n conditions: {\n visible: (formData: Record<string, any>) => {\n return formData.timeout_enabled === true;\n }\n }\n },\n result_name: resultNameField\n },\n layout: ['rules', 'result_name'],\n gutter: [\n {\n type: 'row',\n items: ['timeout_enabled', 'timeout_duration'],\n gap: '0.5rem'\n }\n ],\n validate: (_formData: FormData) => {\n const errors: { [key: string]: string } = {};\n\n // No validation needed - allow multiple rules to use same category name\n // Rules with the same category name will be merged to use the same exit\n\n return {\n valid: Object.keys(errors).length === 0,\n errors\n };\n },\n toFormData: (node: Node) => {\n // Extract rules from router cases using shared function\n const rules = casesToFormRules(node);\n\n // Extract timeout configuration\n const timeoutSeconds = node.router?.wait?.timeout?.seconds;\n let timeoutOption = TIMEOUT_OPTIONS.find(\n (opt) => opt.value === String(timeoutSeconds)\n );\n\n if (!timeoutOption) {\n timeoutOption = { value: '300', name: '5 minutes' };\n }\n\n return {\n uuid: node.uuid,\n rules: rules,\n timeout_enabled: !!timeoutSeconds,\n timeout_duration: timeoutOption,\n result_name: node.router?.result_name || ''\n };\n },\n fromFormData: (formData: FormData, originalNode: Node): Node => {\n // Get user rules using shared extraction function\n const userRules = extractUserRules(formData);\n\n // If no user rules, clear cases but preserve other router config\n if (userRules.length === 0) {\n // Get existing router data for preservation\n let existingCategories = originalNode.router?.categories || [];\n const existingExits = [...(originalNode.exits || [])]; // Create a copy to avoid extensibility issues\n\n // Handle timeout: ensure \"No Response\" category exists if timeout is enabled,\n // or remove it if timeout is disabled\n if (formData.timeout_enabled) {\n let noResponseCategory = existingCategories.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n if (!noResponseCategory) {\n // Create new \"No Response\" category and exit\n const noResponseExitUuid = generateUUID();\n noResponseCategory = {\n uuid: generateUUID(),\n name: 'No Response',\n exit_uuid: noResponseExitUuid\n };\n\n // Add to existing categories for processing\n existingCategories = [...existingCategories, noResponseCategory];\n\n // Add corresponding exit if it doesn't exist\n if (!existingExits.find((exit) => exit.uuid === noResponseExitUuid)) {\n existingExits.push({\n uuid: noResponseExitUuid,\n destination_uuid: null\n });\n }\n }\n } else {\n // If timeout is disabled, remove \"No Response\" category from existing categories\n existingCategories = existingCategories.filter(\n (cat: any) => cat.name !== 'No Response'\n );\n }\n\n // Create router with \"All Responses\" as default category\n // This will now properly handle the \"No Response\" category if it exists\n const { router: noRulesRouter, exits: noRulesExits } =\n createWaitForResponseRouter(\n [], // No user rules\n existingCategories,\n existingExits,\n [] // No cases\n );\n\n const router: any = {\n ...noRulesRouter,\n cases: [] // Clear all cases when no rules\n };\n\n // Only set result_name if provided\n if (formData.result_name && formData.result_name.trim() !== '') {\n router.result_name = formData.result_name.trim();\n }\n\n // Build wait configuration based on form data\n const waitConfig: any = {\n type: 'msg'\n };\n\n // Add timeout if enabled\n if (formData.timeout_enabled) {\n // Extract timeout value (handle both string and object formats)\n let timeoutSeconds;\n\n if (formData.timeout_duration) {\n if (\n Array.isArray(formData.timeout_duration) &&\n formData.timeout_duration.length > 0\n ) {\n // Handle array of selected options (multi-select behavior)\n timeoutSeconds = parseInt(formData.timeout_duration[0].value, 10);\n } else if (typeof formData.timeout_duration === 'string') {\n timeoutSeconds = parseInt(formData.timeout_duration, 10);\n } else if (\n formData.timeout_duration &&\n typeof formData.timeout_duration === 'object' &&\n formData.timeout_duration.value\n ) {\n timeoutSeconds = parseInt(formData.timeout_duration.value, 10);\n } else {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n } else {\n // No duration selected, use default\n timeoutSeconds = 300; // Default to 5 minutes\n }\n\n // Validate that we got a valid number\n if (isNaN(timeoutSeconds) || timeoutSeconds <= 0) {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n\n // Find the \"No Response\" category (should exist now)\n const noResponseCategory = router.categories.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n if (noResponseCategory) {\n waitConfig.timeout = {\n seconds: timeoutSeconds,\n category_uuid: noResponseCategory.uuid\n };\n }\n }\n\n router.wait = waitConfig;\n\n return {\n ...originalNode,\n router,\n exits: noRulesExits\n };\n }\n\n // Get existing router data for preservation\n const existingCategories = originalNode.router?.categories || [];\n const existingExits = originalNode.exits || [];\n const existingCases = originalNode.router?.cases || [];\n\n // Create router and exits using existing data when possible\n const { router, exits } = createWaitForResponseRouter(\n userRules,\n existingCategories,\n existingExits,\n existingCases\n );\n\n // Build final router with wait configuration and result_name\n const finalRouter: any = {\n ...router\n };\n\n // Only set result_name if provided\n if (formData.result_name && formData.result_name.trim() !== '') {\n finalRouter.result_name = formData.result_name.trim();\n }\n\n // Build wait configuration based on form data\n const waitConfig: any = {\n type: 'msg'\n };\n\n try {\n // Handle timeout configuration\n if (formData.timeout_enabled) {\n // Extract timeout value (handle both string and object formats)\n let timeoutSeconds;\n\n if (formData.timeout_duration) {\n try {\n timeoutSeconds = parseInt(formData.timeout_duration[0].value, 10);\n } catch (e) {\n timeoutSeconds = 300; // Default to 5 minutes\n }\n }\n\n // Find or create the \"No Response\" category\n const existingNoResponseCategory =\n originalNode.router?.categories?.find(\n (cat: any) => cat.name === 'No Response'\n );\n\n const noResponseCategory = existingNoResponseCategory || {\n uuid: generateUUID(),\n name: 'No Response',\n exit_uuid: generateUUID()\n };\n\n waitConfig.timeout = {\n seconds: timeoutSeconds,\n category_uuid: noResponseCategory.uuid\n };\n\n // Ensure No Response category and exit exist\n if (\n !router.categories?.some((cat: any) => cat.name === 'No Response')\n ) {\n router.categories = router.categories || [];\n router.categories.push(noResponseCategory);\n\n // Add corresponding exit if it doesn't exist\n if (\n !exits.some(\n (exit: any) => exit.uuid === noResponseCategory.exit_uuid\n )\n ) {\n const noResponseExit = {\n uuid: noResponseCategory.exit_uuid,\n destination_uuid: existingNoResponseCategory?.exit_uuid\n ? originalNode.exits?.find(\n (exit) => exit.uuid === existingNoResponseCategory.exit_uuid\n )?.destination_uuid || null\n : null\n };\n exits.push(noResponseExit);\n }\n }\n } else {\n // Remove \"No Response\" category if timeout is disabled\n if (router.categories) {\n const noResponseCategoryIndex = router.categories.findIndex(\n (cat: any) => cat.name === 'No Response'\n );\n if (noResponseCategoryIndex !== -1) {\n const noResponseCategory =\n router.categories[noResponseCategoryIndex];\n\n // Remove the category\n router.categories.splice(noResponseCategoryIndex, 1);\n\n // Remove corresponding exit\n const exitIndex = exits.findIndex(\n (exit: any) => exit.uuid === noResponseCategory.exit_uuid\n );\n if (exitIndex !== -1) {\n exits.splice(exitIndex, 1);\n }\n }\n }\n }\n } catch (error) {\n console.error('Error processing timeout configuration:', error);\n // Continue without timeout in case of error\n }\n\n finalRouter.wait = waitConfig;\n return {\n ...originalNode,\n router: finalRouter,\n exits: exits\n };\n },\n\n // Localization support for categories\n localizable: 'categories',\n toLocalizationFormData: categoriesToLocalizationFormData,\n fromLocalizationFormData: localizationFormDataToCategories\n};\n"]}
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Flow types - defines the type of flow being edited
3
+ */
4
+ export const FlowTypes = {
5
+ MESSAGE: 'message',
6
+ VOICE: 'voice',
7
+ BACKGROUND: 'background'
8
+ };
9
+ /**
10
+ * Features - defines the features available in the account
11
+ */
12
+ export const Features = {
13
+ AI: 'ai',
14
+ AIRTIME: 'airtime'
15
+ };
1
16
  /**
2
17
  * Action group constants - single source of truth for action categorization
3
18
  * Use as const for compile-time type checking
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/flow/types.ts"],"names":[],"mappings":"AAqQA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;CACV,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACN,CAAC;AAeX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACvE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,mDAAmD;KACjE;IACD,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;QACxB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,yCAAyC;KACvD;IACD,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,iCAAiC;KAC/C;IACD,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;QACxB,KAAK,EAAE,WAAW;QAClB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,iCAAiC;KAC/C;IACD,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;QACzB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,qDAAqD;KACnE;IACD,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QACvB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,qCAAqC;KACnD;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsC;IACrE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QACnB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,2CAA2C;KACzD;IACD,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,oCAAoC;KAClD;CACF,CAAC","sourcesContent":["import { TemplateResult } from 'lit-html';\nimport { Action, Node, NodeUI } from '../store/flow-definition';\n\nexport interface ValidationResult {\n valid: boolean;\n errors: { [key: string]: string };\n}\n\n// Component attribute interfaces - these define what's allowed for each component type\nexport interface TextInputAttributes {\n type?: 'text' | 'email' | 'number' | 'url' | 'tel';\n placeholder?: string;\n clearable?: boolean;\n maxlength?: number;\n gsm?: boolean;\n autogrow?: boolean;\n textarea?: boolean;\n submitOnEnter?: boolean;\n}\n\nexport interface CompletionAttributes {\n placeholder?: string;\n clearable?: boolean;\n maxlength?: number;\n gsm?: boolean;\n autogrow?: boolean;\n textarea?: boolean;\n expressions?: string;\n counter?: string;\n minHeight?: number;\n}\n\nexport interface SelectAttributes {\n placeholder?: string;\n multi?: boolean;\n searchable?: boolean;\n tags?: boolean;\n emails?: boolean;\n clearable?: boolean;\n endpoint?: string;\n valueKey?: string;\n nameKey?: string;\n queryParam?: string;\n maxItems?: number;\n maxItemsText?: string;\n expressions?: string;\n options?: Array<{ name: string; value: any }>;\n sorted?: boolean;\n allowCreate?: boolean;\n jsonValue?: boolean;\n spaceSelect?: boolean;\n infoText?: string;\n}\n\nexport interface CheckboxAttributes {\n label?: string;\n size?: number;\n disabled?: boolean;\n animateChange?: string;\n}\n\nexport interface SliderAttributes {\n min?: number;\n max?: number;\n range?: boolean;\n}\n\nexport interface FormData extends Record<string, any> {}\n\nexport interface FormConfig {\n form?: Record<string, FieldConfig>;\n layout?: LayoutItem[];\n gutter?: LayoutItem[];\n sanitize?: (formData: FormData) => void;\n validate?: (formData: FormData) => ValidationResult;\n}\n\nexport interface NodeConfig extends FormConfig {\n type: string;\n name?: string;\n group?: ActionGroup | SplitGroup; // Nodes can use either when showAsAction is true\n dialogSize?: 'small' | 'medium' | 'large' | 'xlarge';\n action?: ActionConfig;\n showAsAction?: boolean; // if true, show in action dialog instead of splits (default: false - nodes show in splits)\n router?: {\n type: 'switch' | 'random';\n defaultCategory?: string;\n operand?: string;\n configurable?: boolean; // can the rules be configured in the UI\n rules?: {\n type:\n | 'has_number_between'\n | 'has_string'\n | 'has_value'\n | 'has_not_value'\n | 'has_text';\n arguments: string[];\n categoryName: string;\n }[];\n };\n\n toFormData?: (node: Node, nodeUI?: any) => FormData;\n fromFormData?: (formData: FormData, originalNode: Node) => Node;\n toUIConfig?: (formData: FormData) => Record<string, any>;\n render?: (node: Node, nodeUI?: any) => TemplateResult;\n renderTitle?: (node: Node, nodeUI?: NodeUI) => TemplateResult;\n}\n\n// New field configuration system for generic form generation\nexport interface BaseFieldConfig {\n label?: string | ((formData: Record<string, any>) => string);\n required?: boolean;\n evaluated?: boolean;\n dependsOn?: string[];\n computeValue?: (\n values: Record<string, any>,\n currentValue: any,\n originalValues?: Record<string, any>\n ) => any;\n\n // Validation properties\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n helpText?: string;\n\n // Layout properties\n maxWidth?: string;\n width?: string;\n\n // Conditional rendering\n conditions?: {\n visible?: (formData: Record<string, any>) => boolean;\n disabled?: (formData: Record<string, any>) => boolean;\n };\n\n // Optional field with reveal link\n // When set, the field is hidden by default and a link with this text is shown\n // Clicking the link reveals the field permanently (can't be hidden again)\n optionalLink?: string;\n}\n\nexport interface TextFieldConfig extends BaseFieldConfig {\n type: 'text';\n placeholder?: string;\n flavor?: 'xsmall' | 'small' | 'large';\n}\n\nexport interface TextareaFieldConfig extends BaseFieldConfig {\n type: 'textarea';\n placeholder?: string;\n rows?: number;\n minHeight?: number;\n}\n\nexport interface SelectFieldConfig extends BaseFieldConfig {\n type: 'select';\n options?: string[] | { value: string; name: string }[];\n multi?: boolean;\n clearable?: boolean;\n searchable?: boolean;\n tags?: boolean;\n placeholder?: string;\n maxItems?: number;\n valueKey?: string;\n nameKey?: string;\n endpoint?: string;\n emails?: boolean;\n getName?: (item: any) => string;\n flavor?: 'xsmall' | 'small' | 'large';\n createArbitraryOption?: (input: string, options: any[]) => any;\n allowCreate?: boolean;\n getDynamicOptions?: () => Array<{ value: string; name: string }>;\n}\n\nexport interface KeyValueFieldConfig extends BaseFieldConfig {\n type: 'key-value';\n sortable?: boolean;\n keyPlaceholder?: string;\n valuePlaceholder?: string;\n minRows?: number;\n}\n\nexport interface ArrayFieldConfig extends BaseFieldConfig {\n type: 'array';\n itemConfig: Record<string, FieldConfig>;\n sortable?: boolean;\n minItems?: number;\n maxItems?: number;\n itemLabel?: string;\n maintainEmptyItem?: boolean;\n onItemChange?: (\n itemIndex: number,\n field: string,\n value: any,\n allItems: any[]\n ) => any[];\n isEmptyItem?: (item: any) => boolean;\n}\n\nexport interface CheckboxFieldConfig extends BaseFieldConfig {\n type: 'checkbox';\n size?: number;\n animateChange?: string;\n labelPadding?: string;\n}\n\nexport interface MessageEditorFieldConfig extends BaseFieldConfig {\n type: 'message-editor';\n placeholder?: string;\n minHeight?: number;\n maxAttachments?: number;\n accept?: string;\n endpoint?: string;\n counter?: string;\n gsm?: boolean;\n autogrow?: boolean;\n disableCompletion?: boolean;\n}\n\nexport type FieldConfig =\n | TextFieldConfig\n | TextareaFieldConfig\n | SelectFieldConfig\n | KeyValueFieldConfig\n | ArrayFieldConfig\n | CheckboxFieldConfig\n | MessageEditorFieldConfig;\n\n// Layout configurations for better form organization\n// Recursive layout system - any layout item can contain other layout items\n\nexport interface FieldItemConfig {\n type: 'field';\n field: string; // field name to render\n}\n\nexport interface RowLayoutConfig {\n type: 'row';\n items: LayoutItem[]; // can contain fields, groups, or other rows\n gap?: string; // CSS gap value, defaults to '1rem'\n label?: string; // optional label for the entire row\n helpText?: string; // optional help text for the entire row\n}\n\nexport interface GroupLayoutConfig {\n type: 'group';\n label: string;\n items: LayoutItem[]; // can contain fields, rows, or other groups\n collapsible?: boolean;\n collapsed?: boolean | ((formData: FormData) => boolean); // initial state if collapsible - can be a function\n helpText?: string;\n getGroupValueCount?: (formData: FormData) => number; // optional function to get count for bubble display\n}\n\nexport type LayoutItem =\n | FieldItemConfig\n | RowLayoutConfig\n | GroupLayoutConfig\n | string; // string is shorthand for field\n\n/**\n * Action group constants - single source of truth for action categorization\n * Use as const for compile-time type checking\n */\nexport const ACTION_GROUPS = {\n send: 'send',\n contacts: 'contacts',\n save: 'save',\n services: 'services',\n broadcast: 'broadcast',\n trigger: 'trigger'\n} as const;\n\n/**\n * Split group constants - single source of truth for split categorization\n * Use as const for compile-time type checking\n */\nexport const SPLIT_GROUPS = {\n wait: 'wait',\n split: 'split'\n} as const;\n\n// Extract types from const objects for compile-time checking\nexport type ActionGroup = (typeof ACTION_GROUPS)[keyof typeof ACTION_GROUPS];\nexport type SplitGroup = (typeof SPLIT_GROUPS)[keyof typeof SPLIT_GROUPS];\n\n/**\n * Metadata for group display\n */\nexport interface GroupMetadata {\n color: string;\n title: string;\n description: string;\n}\n\n/**\n * Action group metadata - defines display properties for each action group\n * Order in this object determines display order in action selector (top to bottom)\n */\nexport const ACTION_GROUP_METADATA: Record<ActionGroup, GroupMetadata> = {\n [ACTION_GROUPS.send]: {\n color: '#3498db',\n title: 'Send',\n description: 'Actions that send messages or content to contacts'\n },\n [ACTION_GROUPS.contacts]: {\n color: '#01c1af',\n title: 'Contact',\n description: 'Actions that update contact information'\n },\n [ACTION_GROUPS.save]: {\n color: '#1a777c',\n title: 'Save',\n description: 'Actions that save or store data'\n },\n [ACTION_GROUPS.services]: {\n color: '#f79035ff',\n title: 'Services',\n description: 'Call external services and APIs'\n },\n [ACTION_GROUPS.broadcast]: {\n color: '#8e5ea7',\n title: 'Other People',\n description: 'Actions that apply to others instead of the contact'\n },\n [ACTION_GROUPS.trigger]: {\n color: '#df419f',\n title: 'Trigger',\n description: 'Actions that trigger other behavior'\n }\n};\n\n/**\n * Split group metadata - defines display properties for each split group\n * Order in this object determines display order in split selector (top to bottom)\n */\nexport const SPLIT_GROUP_METADATA: Record<SplitGroup, GroupMetadata> = {\n [SPLIT_GROUPS.wait]: {\n color: '#4d7dad',\n title: 'Wait',\n description: 'Wait for user and split on their response'\n },\n [SPLIT_GROUPS.split]: {\n color: '#aaaaaa',\n title: 'Split',\n description: 'Split the flow based on conditions'\n }\n};\n\nexport interface ActionConfig extends FormConfig {\n name: string;\n group: ActionGroup;\n dialogSize?: 'small' | 'medium' | 'large' | 'xlarge';\n evaluated?: string[];\n hideFromActions?: boolean; // if true, don't show in action dialog (default: false - actions show in actions)\n render?: (node: any, action: any) => TemplateResult;\n\n form?: Record<string, FieldConfig>;\n layout?: LayoutItem[]; // optional layout configuration - array of layout items\n gutter?: LayoutItem[]; // fields to render in the dialog gutter (left side of buttons)\n\n toFormData?: (action: Action) => FormData;\n fromFormData?: (formData: FormData) => Action;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/flow/types.ts"],"names":[],"mappings":"AAQA;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,YAAY;CAChB,CAAC;AAIX;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,EAAE,EAAE,IAAI;IACR,OAAO,EAAE,SAAS;CACV,CAAC;AA8QX;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;CACV,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACN,CAAC;AAeX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAuC;IACvE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,mDAAmD;KACjE;IACD,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;QACxB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,yCAAyC;KACvD;IACD,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,iCAAiC;KAC/C;IACD,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE;QACxB,KAAK,EAAE,WAAW;QAClB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,iCAAiC;KAC/C;IACD,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;QACzB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,qDAAqD;KACnE;IACD,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;QACvB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,qCAAqC;KACnD;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsC;IACrE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;QACnB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,MAAM;QACb,WAAW,EAAE,2CAA2C;KACzD;IACD,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QACpB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,oCAAoC;KAClD;CACF,CAAC","sourcesContent":["import { TemplateResult } from 'lit-html';\nimport { Action, Node, NodeUI } from '../store/flow-definition';\n\nexport interface ValidationResult {\n valid: boolean;\n errors: { [key: string]: string };\n}\n\n/**\n * Flow types - defines the type of flow being edited\n */\nexport const FlowTypes = {\n MESSAGE: 'message',\n VOICE: 'voice',\n BACKGROUND: 'background'\n} as const;\n\nexport type FlowType = (typeof FlowTypes)[keyof typeof FlowTypes];\n\n/**\n * Features - defines the features available in the account\n */\nexport const Features = {\n AI: 'ai',\n AIRTIME: 'airtime'\n} as const;\n\nexport type Feature = (typeof Features)[keyof typeof Features];\n\n// Component attribute interfaces - these define what's allowed for each component type\nexport interface TextInputAttributes {\n type?: 'text' | 'email' | 'number' | 'url' | 'tel';\n placeholder?: string;\n clearable?: boolean;\n maxlength?: number;\n gsm?: boolean;\n autogrow?: boolean;\n textarea?: boolean;\n submitOnEnter?: boolean;\n}\n\nexport interface CompletionAttributes {\n placeholder?: string;\n clearable?: boolean;\n maxlength?: number;\n gsm?: boolean;\n autogrow?: boolean;\n textarea?: boolean;\n expressions?: string;\n counter?: string;\n minHeight?: number;\n}\n\nexport interface SelectAttributes {\n placeholder?: string;\n multi?: boolean;\n searchable?: boolean;\n tags?: boolean;\n emails?: boolean;\n clearable?: boolean;\n endpoint?: string;\n valueKey?: string;\n nameKey?: string;\n queryParam?: string;\n maxItems?: number;\n maxItemsText?: string;\n expressions?: string;\n options?: Array<{ name: string; value: any }>;\n sorted?: boolean;\n allowCreate?: boolean;\n jsonValue?: boolean;\n spaceSelect?: boolean;\n infoText?: string;\n}\n\nexport interface CheckboxAttributes {\n label?: string;\n size?: number;\n disabled?: boolean;\n animateChange?: string;\n}\n\nexport interface SliderAttributes {\n min?: number;\n max?: number;\n range?: boolean;\n}\n\nexport interface FormData extends Record<string, any> {}\n\nexport interface FormConfig {\n form?: Record<string, FieldConfig>;\n layout?: LayoutItem[];\n gutter?: LayoutItem[];\n sanitize?: (formData: FormData) => void;\n validate?: (formData: FormData) => ValidationResult;\n}\n\nexport interface NodeConfig extends FormConfig {\n type: string;\n name?: string;\n group?: ActionGroup | SplitGroup; // Nodes can use either when showAsAction is true\n dialogSize?: 'small' | 'medium' | 'large' | 'xlarge';\n action?: ActionConfig;\n showAsAction?: boolean; // if true, show in action dialog instead of splits (default: false - nodes show in splits)\n flowTypes?: FlowType[]; // which flow types this node is available for (defaults to all if not specified)\n features?: Feature[]; // which features are required for this node (all must be present)\n router?: {\n type: 'switch' | 'random';\n defaultCategory?: string;\n operand?: string;\n configurable?: boolean; // can the rules be configured in the UI\n rules?: {\n type:\n | 'has_number_between'\n | 'has_string'\n | 'has_value'\n | 'has_not_value'\n | 'has_text';\n arguments: string[];\n categoryName: string;\n }[];\n };\n\n toFormData?: (node: Node, nodeUI?: any) => FormData;\n fromFormData?: (formData: FormData, originalNode: Node) => Node;\n toUIConfig?: (formData: FormData) => Record<string, any>;\n render?: (node: Node, nodeUI?: any) => TemplateResult;\n renderTitle?: (node: Node, nodeUI?: NodeUI) => TemplateResult;\n\n // Localization support for router categories\n localizable?: 'categories'; // Only categories are localizable for routers\n toLocalizationFormData?: (\n node: Node,\n localization: Record<string, any>\n ) => FormData;\n fromLocalizationFormData?: (\n formData: FormData,\n node: Node\n ) => Record<string, any>;\n}\n\n// New field configuration system for generic form generation\nexport interface BaseFieldConfig {\n label?: string | ((formData: Record<string, any>) => string);\n required?: boolean;\n evaluated?: boolean;\n dependsOn?: string[];\n computeValue?: (\n values: Record<string, any>,\n currentValue: any,\n originalValues?: Record<string, any>\n ) => any;\n\n // Validation properties\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n helpText?: string;\n\n // Layout properties\n maxWidth?: string;\n width?: string;\n\n // Conditional rendering\n conditions?: {\n visible?: (formData: Record<string, any>) => boolean;\n disabled?: (formData: Record<string, any>) => boolean;\n };\n\n // Optional field with reveal link\n // When set, the field is hidden by default and a link with this text is shown\n // Clicking the link reveals the field permanently (can't be hidden again)\n optionalLink?: string;\n}\n\nexport interface TextFieldConfig extends BaseFieldConfig {\n type: 'text';\n placeholder?: string;\n flavor?: 'xsmall' | 'small' | 'large';\n}\n\nexport interface TextareaFieldConfig extends BaseFieldConfig {\n type: 'textarea';\n placeholder?: string;\n rows?: number;\n minHeight?: number;\n}\n\nexport interface SelectFieldConfig extends BaseFieldConfig {\n type: 'select';\n options?: string[] | { value: string; name: string }[];\n multi?: boolean;\n clearable?: boolean;\n searchable?: boolean;\n tags?: boolean;\n placeholder?: string;\n maxItems?: number;\n valueKey?: string;\n nameKey?: string;\n endpoint?: string;\n emails?: boolean;\n getName?: (item: any) => string;\n flavor?: 'xsmall' | 'small' | 'large';\n createArbitraryOption?: (input: string, options: any[]) => any;\n allowCreate?: boolean;\n getDynamicOptions?: () => Array<{ value: string; name: string }>;\n}\n\nexport interface KeyValueFieldConfig extends BaseFieldConfig {\n type: 'key-value';\n sortable?: boolean;\n keyPlaceholder?: string;\n valuePlaceholder?: string;\n minRows?: number;\n}\n\nexport interface ArrayFieldConfig extends BaseFieldConfig {\n type: 'array';\n itemConfig: Record<string, FieldConfig>;\n sortable?: boolean;\n minItems?: number;\n maxItems?: number;\n itemLabel?: string;\n maintainEmptyItem?: boolean;\n onItemChange?: (\n itemIndex: number,\n field: string,\n value: any,\n allItems: any[]\n ) => any[];\n isEmptyItem?: (item: any) => boolean;\n}\n\nexport interface CheckboxFieldConfig extends BaseFieldConfig {\n type: 'checkbox';\n size?: number;\n animateChange?: string;\n labelPadding?: string;\n}\n\nexport interface MessageEditorFieldConfig extends BaseFieldConfig {\n type: 'message-editor';\n placeholder?: string;\n minHeight?: number;\n maxAttachments?: number;\n accept?: string;\n endpoint?: string;\n counter?: string;\n gsm?: boolean;\n autogrow?: boolean;\n disableCompletion?: boolean;\n}\n\nexport type FieldConfig =\n | TextFieldConfig\n | TextareaFieldConfig\n | SelectFieldConfig\n | KeyValueFieldConfig\n | ArrayFieldConfig\n | CheckboxFieldConfig\n | MessageEditorFieldConfig;\n\n// Layout configurations for better form organization\n// Recursive layout system - any layout item can contain other layout items\n\nexport interface FieldItemConfig {\n type: 'field';\n field: string; // field name to render\n}\n\nexport interface RowLayoutConfig {\n type: 'row';\n items: LayoutItem[]; // can contain fields, groups, or other rows\n gap?: string; // CSS gap value, defaults to '1rem'\n label?: string; // optional label for the entire row\n helpText?: string; // optional help text for the entire row\n}\n\nexport interface GroupLayoutConfig {\n type: 'group';\n label: string;\n items: LayoutItem[]; // can contain fields, rows, or other groups\n collapsible?: boolean;\n collapsed?: boolean | ((formData: FormData) => boolean); // initial state if collapsible - can be a function\n helpText?: string;\n getGroupValueCount?: (formData: FormData) => number; // optional function to get count for bubble display\n}\n\nexport type LayoutItem =\n | FieldItemConfig\n | RowLayoutConfig\n | GroupLayoutConfig\n | string; // string is shorthand for field\n\n/**\n * Action group constants - single source of truth for action categorization\n * Use as const for compile-time type checking\n */\nexport const ACTION_GROUPS = {\n send: 'send',\n contacts: 'contacts',\n save: 'save',\n services: 'services',\n broadcast: 'broadcast',\n trigger: 'trigger'\n} as const;\n\n/**\n * Split group constants - single source of truth for split categorization\n * Use as const for compile-time type checking\n */\nexport const SPLIT_GROUPS = {\n wait: 'wait',\n split: 'split'\n} as const;\n\n// Extract types from const objects for compile-time checking\nexport type ActionGroup = (typeof ACTION_GROUPS)[keyof typeof ACTION_GROUPS];\nexport type SplitGroup = (typeof SPLIT_GROUPS)[keyof typeof SPLIT_GROUPS];\n\n/**\n * Metadata for group display\n */\nexport interface GroupMetadata {\n color: string;\n title: string;\n description: string;\n}\n\n/**\n * Action group metadata - defines display properties for each action group\n * Order in this object determines display order in action selector (top to bottom)\n */\nexport const ACTION_GROUP_METADATA: Record<ActionGroup, GroupMetadata> = {\n [ACTION_GROUPS.send]: {\n color: '#3498db',\n title: 'Send',\n description: 'Actions that send messages or content to contacts'\n },\n [ACTION_GROUPS.contacts]: {\n color: '#01c1af',\n title: 'Contact',\n description: 'Actions that update contact information'\n },\n [ACTION_GROUPS.save]: {\n color: '#1a777c',\n title: 'Save',\n description: 'Actions that save or store data'\n },\n [ACTION_GROUPS.services]: {\n color: '#f79035ff',\n title: 'Services',\n description: 'Call external services and APIs'\n },\n [ACTION_GROUPS.broadcast]: {\n color: '#8e5ea7',\n title: 'Other People',\n description: 'Actions that apply to others instead of the contact'\n },\n [ACTION_GROUPS.trigger]: {\n color: '#df419f',\n title: 'Trigger',\n description: 'Actions that trigger other behavior'\n }\n};\n\n/**\n * Split group metadata - defines display properties for each split group\n * Order in this object determines display order in split selector (top to bottom)\n */\nexport const SPLIT_GROUP_METADATA: Record<SplitGroup, GroupMetadata> = {\n [SPLIT_GROUPS.wait]: {\n color: '#4d7dad',\n title: 'Wait',\n description: 'Wait for user and split on their response'\n },\n [SPLIT_GROUPS.split]: {\n color: '#aaaaaa',\n title: 'Split',\n description: 'Split the flow based on conditions'\n }\n};\n\nexport interface ActionConfig extends FormConfig {\n name: string;\n group: ActionGroup;\n dialogSize?: 'small' | 'medium' | 'large' | 'xlarge';\n evaluated?: string[];\n hideFromActions?: boolean; // if true, don't show in action dialog (default: false - actions show in actions)\n flowTypes?: FlowType[]; // which flow types this action is available for (defaults to all if not specified)\n features?: Feature[]; // which features are required for this action (all must be present)\n render?: (node: any, action: any) => TemplateResult;\n\n form?: Record<string, FieldConfig>;\n layout?: LayoutItem[]; // optional layout configuration - array of layout items\n gutter?: LayoutItem[]; // fields to render in the dialog gutter (left side of buttons)\n\n toFormData?: (action: Action) => FormData;\n fromFormData?: (formData: FormData) => Action;\n\n // Localization support\n localizable?: string[]; // array of field names that can be localized\n toLocalizationFormData?: (\n action: Action,\n localization: Record<string, any>\n ) => FormData;\n fromLocalizationFormData?: (\n formData: FormData,\n action: Action\n ) => Record<string, any>;\n}\n"]}
@@ -0,0 +1,346 @@
1
+ import { __decorate } from "tslib";
2
+ import { css, html } from 'lit';
3
+ import { property } from 'lit/decorators.js';
4
+ import { RapidElement } from '../RapidElement';
5
+ import { CustomEventType } from '../interfaces';
6
+ import { getClasses } from '../utils';
7
+ import { FloatingTab } from '../display/FloatingTab';
8
+ export class FloatingWindow extends RapidElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.header = '';
12
+ this.width = 500;
13
+ this.minHeight = 200;
14
+ this.maxHeight = 800;
15
+ this.top = 100;
16
+ this.left = -1; // -1 means calculate from right side
17
+ this.hidden = true;
18
+ this.dragging = false;
19
+ this.chromeless = false;
20
+ this.color = '#6B7280';
21
+ this.dragStartX = 0;
22
+ this.dragStartY = 0;
23
+ this.dragOffsetX = 0;
24
+ this.dragOffsetY = 0;
25
+ this.positionFromRight = false;
26
+ this.defaultTop = 100;
27
+ this.defaultLeft = -1;
28
+ this.handleSlotMouseDown = (event) => {
29
+ // check if the target or any parent has the drag-handle class
30
+ const target = event.target;
31
+ const dragHandle = target.closest('.drag-handle');
32
+ if (!dragHandle) {
33
+ return;
34
+ }
35
+ this.dragging = true;
36
+ this.dragStartX = event.clientX;
37
+ this.dragStartY = event.clientY;
38
+ this.dragOffsetX = this.left;
39
+ this.dragOffsetY = this.top;
40
+ document.addEventListener('mousemove', this.handleMouseMove);
41
+ document.addEventListener('mouseup', this.handleMouseUp);
42
+ event.preventDefault();
43
+ };
44
+ this.handleMouseMove = (event) => {
45
+ var _a;
46
+ if (!this.dragging)
47
+ return;
48
+ const deltaX = event.clientX - this.dragStartX;
49
+ const deltaY = event.clientY - this.dragStartY;
50
+ this.left = this.dragOffsetX + deltaX;
51
+ this.top = this.dragOffsetY + deltaY;
52
+ // keep window within viewport bounds with 20px padding
53
+ const padding = 20;
54
+ this.left = Math.max(padding, Math.min(this.left, window.innerWidth - this.width - padding));
55
+ // get the actual rendered height of the window element
56
+ const windowElement = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.window');
57
+ const currentHeight = (windowElement === null || windowElement === void 0 ? void 0 : windowElement.offsetHeight) || this.maxHeight || window.innerHeight;
58
+ const maxTop = Math.max(padding, window.innerHeight - currentHeight - padding);
59
+ this.top = Math.max(padding, Math.min(this.top, maxTop));
60
+ };
61
+ this.handleMouseUp = () => {
62
+ this.dragging = false;
63
+ document.removeEventListener('mousemove', this.handleMouseMove);
64
+ document.removeEventListener('mouseup', this.handleMouseUp);
65
+ // once user drags the window, stop auto-positioning from right
66
+ this.positionFromRight = false;
67
+ };
68
+ this.handleResize = () => {
69
+ var _a;
70
+ // only constrain position if window is visible
71
+ if (this.hidden)
72
+ return;
73
+ const padding = 20;
74
+ const windowElement = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.window');
75
+ const currentHeight = (windowElement === null || windowElement === void 0 ? void 0 : windowElement.offsetHeight) || this.maxHeight || window.innerHeight;
76
+ // if positioned from right, always recalculate from right edge
77
+ if (this.positionFromRight) {
78
+ this.left = window.innerWidth - this.width - padding;
79
+ }
80
+ else {
81
+ // only adjust left if out of bounds
82
+ const minLeft = padding;
83
+ const maxLeft = window.innerWidth - this.width - padding;
84
+ if (this.left < minLeft) {
85
+ this.left = minLeft;
86
+ }
87
+ else if (this.left > maxLeft) {
88
+ this.left = maxLeft;
89
+ }
90
+ }
91
+ // only adjust top if out of bounds
92
+ const minTop = padding;
93
+ const maxTop = Math.max(padding, window.innerHeight - currentHeight - padding);
94
+ if (this.top < minTop) {
95
+ this.top = minTop;
96
+ }
97
+ else if (this.top > maxTop) {
98
+ this.top = maxTop;
99
+ }
100
+ };
101
+ }
102
+ static get styles() {
103
+ return css `
104
+ .window.hidden {
105
+ transform: translateX(100%);
106
+ opacity: 0;
107
+ pointer-events: none;
108
+ }
109
+
110
+ .window {
111
+ transition: transform var(--transition-duration, 300ms) ease-in-out,
112
+ opacity var(--transition-duration, 300ms) ease-in-out;
113
+ position: fixed;
114
+ z-index: 9999;
115
+ top: 100px;
116
+ background: white;
117
+ border-radius: 8px;
118
+ box-shadow: -4px 4px 20px rgba(0, 0, 0, 0.3);
119
+ display: flex;
120
+ flex-direction: column;
121
+ overflow: hidden;
122
+ }
123
+
124
+ .window.chromeless {
125
+ background: transparent;
126
+ border-radius: 0;
127
+ box-shadow: none;
128
+ }
129
+
130
+ .window.dragging {
131
+ user-select: none;
132
+ cursor: move;
133
+ }
134
+
135
+ .header {
136
+ display: flex;
137
+ align-items: center;
138
+ justify-content: space-between;
139
+ padding: 6px 6px;
140
+ background: var(--header-color, var(--color-primary-light, #f3f4f6));
141
+ border-bottom: 1px solid rgba(0, 0, 0, 0.1);
142
+ cursor: move;
143
+ user-select: none;
144
+ }
145
+
146
+ .title {
147
+ font-weight: 600;
148
+ font-size: 16px;
149
+ color: white;
150
+ padding-left: 8px;
151
+ }
152
+
153
+ .close-button {
154
+ background: none;
155
+ border: none;
156
+ cursor: pointer;
157
+ padding: 4px;
158
+ display: flex;
159
+ align-items: center;
160
+ justify-content: center;
161
+ border-radius: 4px;
162
+ transition: background-color calc(var(--transition-duration, 150ms) / 2)
163
+ ease-in-out;
164
+ }
165
+
166
+ .close-button:hover {
167
+ background-color: rgba(255, 255, 255, 0.2);
168
+ }
169
+
170
+ .close-button temba-icon {
171
+ --icon-color: white;
172
+ }
173
+
174
+ .body {
175
+ flex: 1;
176
+ overflow-y: auto;
177
+ padding: 16px;
178
+ }
179
+
180
+ .window.chromeless .body {
181
+ padding: 0;
182
+ }
183
+
184
+ ::slotted(.drag-handle) {
185
+ cursor: move;
186
+ user-select: none;
187
+ border: 1px solid red;
188
+ }
189
+ `;
190
+ }
191
+ firstUpdated(changes) {
192
+ super.firstUpdated(changes);
193
+ // store the default position from properties
194
+ this.defaultTop = this.top;
195
+ this.defaultLeft = this.left;
196
+ // determine if we should position from right side
197
+ if (this.left === -1) {
198
+ this.positionFromRight = true;
199
+ }
200
+ // set up drag handle listeners for chromeless windows
201
+ if (this.chromeless) {
202
+ this.setupDragHandles();
203
+ }
204
+ // listen for window resize to keep window in bounds
205
+ window.addEventListener('resize', this.handleResize);
206
+ }
207
+ disconnectedCallback() {
208
+ super.disconnectedCallback();
209
+ window.removeEventListener('resize', this.handleResize);
210
+ }
211
+ setupDragHandles() {
212
+ // listen for mousedown on slotted content
213
+ this.addEventListener('mousedown', this.handleSlotMouseDown);
214
+ }
215
+ updated(changes) {
216
+ super.updated(changes);
217
+ if (changes.has('hidden')) {
218
+ this.classList.toggle('hidden', this.hidden);
219
+ // when hiding, reset positioning behavior to original
220
+ if (this.hidden && !changes.get('hidden')) {
221
+ if (this.defaultLeft === -1) {
222
+ this.positionFromRight = true;
223
+ }
224
+ }
225
+ // reset to default position when showing
226
+ if (!this.hidden && changes.get('hidden')) {
227
+ // reset top to default
228
+ this.top = this.defaultTop;
229
+ // if positioned from right, recalculate based on current viewport
230
+ if (this.positionFromRight) {
231
+ this.left = window.innerWidth - this.width - 20;
232
+ }
233
+ else {
234
+ // reset left to default
235
+ this.left = this.defaultLeft;
236
+ }
237
+ }
238
+ }
239
+ // setup drag handles if chromeless changed to true
240
+ if (changes.has('chromeless') && this.chromeless) {
241
+ this.setupDragHandles();
242
+ }
243
+ }
244
+ handleClose() {
245
+ this.hidden = true;
246
+ // show all tabs when window is closed
247
+ FloatingTab.showAllTabs();
248
+ this.fireCustomEvent(CustomEventType.DialogHidden);
249
+ }
250
+ handleHeaderMouseDown(event) {
251
+ // don't start drag if clicking on close button
252
+ if (event.target.closest('.close-button')) {
253
+ return;
254
+ }
255
+ this.dragging = true;
256
+ this.dragStartX = event.clientX;
257
+ this.dragStartY = event.clientY;
258
+ this.dragOffsetX = this.left;
259
+ this.dragOffsetY = this.top;
260
+ document.addEventListener('mousemove', this.handleMouseMove);
261
+ document.addEventListener('mouseup', this.handleMouseUp);
262
+ event.preventDefault();
263
+ }
264
+ show() {
265
+ this.hidden = false;
266
+ }
267
+ hide() {
268
+ this.hidden = true;
269
+ }
270
+ close() {
271
+ this.hidden = true;
272
+ // show all tabs when window is closed
273
+ FloatingTab.showAllTabs();
274
+ this.fireCustomEvent(CustomEventType.DialogHidden);
275
+ }
276
+ render() {
277
+ const minHeightStyle = this.minHeight
278
+ ? `min-height: ${this.minHeight}px;`
279
+ : '';
280
+ const maxHeightStyle = this.maxHeight
281
+ ? `max-height: ${this.maxHeight}px;`
282
+ : '';
283
+ const windowStyle = `
284
+ width: ${this.width}px;
285
+ ${minHeightStyle}
286
+ ${maxHeightStyle}
287
+ top: ${this.top}px;
288
+ left: ${this.left}px;
289
+ --header-color: ${this.color};
290
+ `;
291
+ const windowClasses = getClasses({
292
+ window: true,
293
+ dragging: this.dragging,
294
+ hidden: this.hidden,
295
+ chromeless: this.chromeless
296
+ });
297
+ return html `
298
+ <div class="${windowClasses}" style="${windowStyle}">
299
+ ${!this.chromeless
300
+ ? html `
301
+ <div class="header" @mousedown=${this.handleHeaderMouseDown}>
302
+ <div class="title">${this.header}</div>
303
+ <button class="close-button" @click=${this.handleClose}>
304
+ <temba-icon name="close" size="1.5"></temba-icon>
305
+ </button>
306
+ </div>
307
+ `
308
+ : ''}
309
+ <div class="body">
310
+ <slot></slot>
311
+ </div>
312
+ </div>
313
+ `;
314
+ }
315
+ }
316
+ __decorate([
317
+ property({ type: String })
318
+ ], FloatingWindow.prototype, "header", void 0);
319
+ __decorate([
320
+ property({ type: Number })
321
+ ], FloatingWindow.prototype, "width", void 0);
322
+ __decorate([
323
+ property({ type: Number })
324
+ ], FloatingWindow.prototype, "minHeight", void 0);
325
+ __decorate([
326
+ property({ type: Number })
327
+ ], FloatingWindow.prototype, "maxHeight", void 0);
328
+ __decorate([
329
+ property({ type: Number })
330
+ ], FloatingWindow.prototype, "top", void 0);
331
+ __decorate([
332
+ property({ type: Number })
333
+ ], FloatingWindow.prototype, "left", void 0);
334
+ __decorate([
335
+ property({ type: Boolean })
336
+ ], FloatingWindow.prototype, "hidden", void 0);
337
+ __decorate([
338
+ property({ type: Boolean })
339
+ ], FloatingWindow.prototype, "dragging", void 0);
340
+ __decorate([
341
+ property({ type: Boolean })
342
+ ], FloatingWindow.prototype, "chromeless", void 0);
343
+ __decorate([
344
+ property({ type: String })
345
+ ], FloatingWindow.prototype, "color", void 0);
346
+ //# sourceMappingURL=FloatingWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FloatingWindow.js","sourceRoot":"","sources":["../../../src/layout/FloatingWindow.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAoC,MAAM,KAAK,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,OAAO,cAAe,SAAQ,YAAY;IAAhD;;QA4FE,WAAM,GAAG,EAAE,CAAC;QAGZ,UAAK,GAAG,GAAG,CAAC;QAGZ,cAAS,GAAG,GAAG,CAAC;QAGhB,cAAS,GAAG,GAAG,C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import { RapidElement } from '../RapidElement';\nimport { CustomEventType } from '../interfaces';\nimport { getClasses } from '../utils';\nimport { FloatingTab } from '../display/FloatingTab';\n\nexport class FloatingWindow extends RapidElement {\n static get styles() {\n return css`\n .window.hidden {\n transform: translateX(100%);\n opacity: 0;\n pointer-events: none;\n }\n\n .window {\n transition: transform var(--transition-duration, 300ms) ease-in-out,\n opacity var(--transition-duration, 300ms) ease-in-out;\n position: fixed;\n z-index: 9999;\n top: 100px;\n background: white;\n border-radius: 8px;\n box-shadow: -4px 4px 20px rgba(0, 0, 0, 0.3);\n display: flex;\n flex-direction: column;\n overflow: hidden;\n }\n\n .window.chromeless {\n background: transparent;\n border-radius: 0;\n box-shadow: none;\n }\n\n .window.dragging {\n user-select: none;\n cursor: move;\n }\n\n .header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 6px 6px;\n background: var(--header-color, var(--color-primary-light, #f3f4f6));\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n cursor: move;\n user-select: none;\n }\n\n .title {\n font-weight: 600;\n font-size: 16px;\n color: white;\n padding-left: 8px;\n }\n\n .close-button {\n background: none;\n border: none;\n cursor: pointer;\n padding: 4px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n transition: background-color calc(var(--transition-duration, 150ms) / 2)\n ease-in-out;\n }\n\n .close-button:hover {\n background-color: rgba(255, 255, 255, 0.2);\n }\n\n .close-button temba-icon {\n --icon-color: white;\n }\n\n .body {\n flex: 1;\n overflow-y: auto;\n padding: 16px;\n }\n\n .window.chromeless .body {\n padding: 0;\n }\n\n ::slotted(.drag-handle) {\n cursor: move;\n user-select: none;\n border: 1px solid red;\n }\n `;\n }\n\n @property({ type: String })\n header = '';\n\n @property({ type: Number })\n width = 500;\n\n @property({ type: Number })\n minHeight = 200;\n\n @property({ type: Number })\n maxHeight = 800;\n\n @property({ type: Number })\n top = 100;\n\n @property({ type: Number })\n left = -1; // -1 means calculate from right side\n\n @property({ type: Boolean })\n hidden = true;\n\n @property({ type: Boolean })\n dragging = false;\n\n @property({ type: Boolean })\n chromeless = false;\n\n @property({ type: String })\n color = '#6B7280';\n\n private dragStartX = 0;\n private dragStartY = 0;\n private dragOffsetX = 0;\n private dragOffsetY = 0;\n private positionFromRight = false;\n private defaultTop = 100;\n private defaultLeft = -1;\n\n public firstUpdated(\n changes: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.firstUpdated(changes);\n\n // store the default position from properties\n this.defaultTop = this.top;\n this.defaultLeft = this.left;\n\n // determine if we should position from right side\n if (this.left === -1) {\n this.positionFromRight = true;\n }\n\n // set up drag handle listeners for chromeless windows\n if (this.chromeless) {\n this.setupDragHandles();\n }\n\n // listen for window resize to keep window in bounds\n window.addEventListener('resize', this.handleResize);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n window.removeEventListener('resize', this.handleResize);\n }\n\n private setupDragHandles() {\n // listen for mousedown on slotted content\n this.addEventListener('mousedown', this.handleSlotMouseDown);\n }\n\n private handleSlotMouseDown = (event: MouseEvent) => {\n // check if the target or any parent has the drag-handle class\n const target = event.target as HTMLElement;\n const dragHandle = target.closest('.drag-handle');\n\n if (!dragHandle) {\n return;\n }\n\n this.dragging = true;\n this.dragStartX = event.clientX;\n this.dragStartY = event.clientY;\n this.dragOffsetX = this.left;\n this.dragOffsetY = this.top;\n\n document.addEventListener('mousemove', this.handleMouseMove);\n document.addEventListener('mouseup', this.handleMouseUp);\n\n event.preventDefault();\n };\n\n public updated(\n changes: PropertyValueMap<any> | Map<PropertyKey, unknown>\n ): void {\n super.updated(changes);\n if (changes.has('hidden')) {\n this.classList.toggle('hidden', this.hidden);\n\n // when hiding, reset positioning behavior to original\n if (this.hidden && !changes.get('hidden')) {\n if (this.defaultLeft === -1) {\n this.positionFromRight = true;\n }\n }\n\n // reset to default position when showing\n if (!this.hidden && changes.get('hidden')) {\n // reset top to default\n this.top = this.defaultTop;\n\n // if positioned from right, recalculate based on current viewport\n if (this.positionFromRight) {\n this.left = window.innerWidth - this.width - 20;\n } else {\n // reset left to default\n this.left = this.defaultLeft;\n }\n }\n }\n\n // setup drag handles if chromeless changed to true\n if (changes.has('chromeless') && this.chromeless) {\n this.setupDragHandles();\n }\n }\n\n private handleClose() {\n this.hidden = true;\n // show all tabs when window is closed\n FloatingTab.showAllTabs();\n this.fireCustomEvent(CustomEventType.DialogHidden);\n }\n\n private handleHeaderMouseDown(event: MouseEvent) {\n // don't start drag if clicking on close button\n if ((event.target as HTMLElement).closest('.close-button')) {\n return;\n }\n\n this.dragging = true;\n this.dragStartX = event.clientX;\n this.dragStartY = event.clientY;\n this.dragOffsetX = this.left;\n this.dragOffsetY = this.top;\n\n document.addEventListener('mousemove', this.handleMouseMove);\n document.addEventListener('mouseup', this.handleMouseUp);\n\n event.preventDefault();\n }\n\n private handleMouseMove = (event: MouseEvent) => {\n if (!this.dragging) return;\n\n const deltaX = event.clientX - this.dragStartX;\n const deltaY = event.clientY - this.dragStartY;\n\n this.left = this.dragOffsetX + deltaX;\n this.top = this.dragOffsetY + deltaY;\n\n // keep window within viewport bounds with 20px padding\n const padding = 20;\n this.left = Math.max(\n padding,\n Math.min(this.left, window.innerWidth - this.width - padding)\n );\n\n // get the actual rendered height of the window element\n const windowElement = this.shadowRoot?.querySelector(\n '.window'\n ) as HTMLElement;\n const currentHeight =\n windowElement?.offsetHeight || this.maxHeight || window.innerHeight;\n const maxTop = Math.max(\n padding,\n window.innerHeight - currentHeight - padding\n );\n this.top = Math.max(padding, Math.min(this.top, maxTop));\n };\n\n private handleMouseUp = () => {\n this.dragging = false;\n document.removeEventListener('mousemove', this.handleMouseMove);\n document.removeEventListener('mouseup', this.handleMouseUp);\n\n // once user drags the window, stop auto-positioning from right\n this.positionFromRight = false;\n };\n\n private handleResize = () => {\n // only constrain position if window is visible\n if (this.hidden) return;\n\n const padding = 20;\n const windowElement = this.shadowRoot?.querySelector(\n '.window'\n ) as HTMLElement;\n const currentHeight =\n windowElement?.offsetHeight || this.maxHeight || window.innerHeight;\n\n // if positioned from right, always recalculate from right edge\n if (this.positionFromRight) {\n this.left = window.innerWidth - this.width - padding;\n } else {\n // only adjust left if out of bounds\n const minLeft = padding;\n const maxLeft = window.innerWidth - this.width - padding;\n\n if (this.left < minLeft) {\n this.left = minLeft;\n } else if (this.left > maxLeft) {\n this.left = maxLeft;\n }\n }\n\n // only adjust top if out of bounds\n const minTop = padding;\n const maxTop = Math.max(\n padding,\n window.innerHeight - currentHeight - padding\n );\n\n if (this.top < minTop) {\n this.top = minTop;\n } else if (this.top > maxTop) {\n this.top = maxTop;\n }\n };\n\n public show() {\n this.hidden = false;\n }\n\n public hide() {\n this.hidden = true;\n }\n\n public close() {\n this.hidden = true;\n // show all tabs when window is closed\n FloatingTab.showAllTabs();\n this.fireCustomEvent(CustomEventType.DialogHidden);\n }\n\n public render(): TemplateResult {\n const minHeightStyle = this.minHeight\n ? `min-height: ${this.minHeight}px;`\n : '';\n const maxHeightStyle = this.maxHeight\n ? `max-height: ${this.maxHeight}px;`\n : '';\n\n const windowStyle = `\n width: ${this.width}px;\n ${minHeightStyle}\n ${maxHeightStyle}\n top: ${this.top}px;\n left: ${this.left}px;\n --header-color: ${this.color};\n `;\n\n const windowClasses = getClasses({\n window: true,\n dragging: this.dragging,\n hidden: this.hidden,\n chromeless: this.chromeless\n });\n\n return html`\n <div class=\"${windowClasses}\" style=\"${windowStyle}\">\n ${!this.chromeless\n ? html`\n <div class=\"header\" @mousedown=${this.handleHeaderMouseDown}>\n <div class=\"title\">${this.header}</div>\n <button class=\"close-button\" @click=${this.handleClose}>\n <temba-icon name=\"close\" size=\"1.5\"></temba-icon>\n </button>\n </div>\n `\n : ''}\n <div class=\"body\">\n <slot></slot>\n </div>\n </div>\n `;\n }\n}\n"]}