@nyaruka/temba-components 0.131.0 → 0.131.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +4 -1
- package/CHANGELOG.md +67 -1
- package/demo/data/flows/food-order.json +2 -2
- package/demo/data/flows/sample-flow.json +74 -125
- package/dist/static/svg/index.svg +1 -1
- package/dist/temba-components.js +1156 -619
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/Icons.js +4 -1
- package/out-tsc/src/Icons.js.map +1 -1
- package/out-tsc/src/events.js.map +1 -1
- package/out-tsc/src/flow/CanvasMenu.js +200 -0
- package/out-tsc/src/flow/CanvasMenu.js.map +1 -0
- package/out-tsc/src/flow/CanvasNode.js +327 -19
- package/out-tsc/src/flow/CanvasNode.js.map +1 -1
- package/out-tsc/src/flow/Editor.js +562 -66
- package/out-tsc/src/flow/Editor.js.map +1 -1
- package/out-tsc/src/flow/NodeEditor.js +240 -93
- package/out-tsc/src/flow/NodeEditor.js.map +1 -1
- package/out-tsc/src/flow/NodeTypeSelector.js +499 -0
- package/out-tsc/src/flow/NodeTypeSelector.js.map +1 -0
- package/out-tsc/src/flow/actions/add_contact_groups.js +3 -3
- package/out-tsc/src/flow/actions/add_contact_groups.js.map +1 -1
- package/out-tsc/src/flow/actions/add_contact_urn.js +62 -4
- package/out-tsc/src/flow/actions/add_contact_urn.js.map +1 -1
- package/out-tsc/src/flow/actions/add_input_labels.js +3 -3
- package/out-tsc/src/flow/actions/add_input_labels.js.map +1 -1
- package/out-tsc/src/flow/actions/play_audio.js +2 -2
- package/out-tsc/src/flow/actions/play_audio.js.map +1 -1
- package/out-tsc/src/flow/actions/remove_contact_groups.js +6 -5
- package/out-tsc/src/flow/actions/remove_contact_groups.js.map +1 -1
- package/out-tsc/src/flow/actions/request_optin.js +2 -2
- package/out-tsc/src/flow/actions/request_optin.js.map +1 -1
- package/out-tsc/src/flow/actions/say_msg.js +2 -2
- package/out-tsc/src/flow/actions/say_msg.js.map +1 -1
- package/out-tsc/src/flow/actions/send_broadcast.js +76 -23
- package/out-tsc/src/flow/actions/send_broadcast.js.map +1 -1
- package/out-tsc/src/flow/actions/send_email.js +4 -5
- package/out-tsc/src/flow/actions/send_email.js.map +1 -1
- package/out-tsc/src/flow/actions/send_msg.js +9 -19
- package/out-tsc/src/flow/actions/send_msg.js.map +1 -1
- package/out-tsc/src/flow/actions/set_contact_channel.js +5 -9
- package/out-tsc/src/flow/actions/set_contact_channel.js.map +1 -1
- package/out-tsc/src/flow/actions/set_contact_field.js +19 -20
- package/out-tsc/src/flow/actions/set_contact_field.js.map +1 -1
- package/out-tsc/src/flow/actions/set_contact_language.js +2 -2
- package/out-tsc/src/flow/actions/set_contact_language.js.map +1 -1
- package/out-tsc/src/flow/actions/set_contact_name.js +2 -12
- package/out-tsc/src/flow/actions/set_contact_name.js.map +1 -1
- package/out-tsc/src/flow/actions/set_contact_status.js +2 -2
- package/out-tsc/src/flow/actions/set_contact_status.js.map +1 -1
- package/out-tsc/src/flow/actions/set_run_result.js +3 -3
- package/out-tsc/src/flow/actions/set_run_result.js.map +1 -1
- package/out-tsc/src/flow/actions/start_session.js +180 -6
- package/out-tsc/src/flow/actions/start_session.js.map +1 -1
- package/out-tsc/src/flow/config.js +11 -15
- package/out-tsc/src/flow/config.js.map +1 -1
- package/out-tsc/src/flow/currencies.js +45 -0
- package/out-tsc/src/flow/currencies.js.map +1 -0
- package/out-tsc/src/flow/nodes/shared-rules.js +257 -0
- package/out-tsc/src/flow/nodes/shared-rules.js.map +1 -0
- package/out-tsc/src/flow/nodes/shared.js +17 -0
- package/out-tsc/src/flow/nodes/shared.js.map +1 -0
- package/out-tsc/src/flow/nodes/split_by_airtime.js +205 -5
- package/out-tsc/src/flow/nodes/split_by_airtime.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_contact_field.js +147 -3
- package/out-tsc/src/flow/nodes/split_by_contact_field.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_expression.js +68 -2
- package/out-tsc/src/flow/nodes/split_by_expression.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_groups.js +12 -9
- package/out-tsc/src/flow/nodes/split_by_groups.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_intent.js +7 -0
- package/out-tsc/src/flow/nodes/split_by_intent.js.map +1 -0
- package/out-tsc/src/flow/nodes/split_by_llm.js +3 -2
- package/out-tsc/src/flow/nodes/split_by_llm.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_llm_categorize.js +2 -2
- package/out-tsc/src/flow/nodes/split_by_llm_categorize.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_random.js +3 -3
- package/out-tsc/src/flow/nodes/split_by_random.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_resthook.js +108 -0
- package/out-tsc/src/flow/nodes/split_by_resthook.js.map +1 -0
- package/out-tsc/src/flow/nodes/split_by_run_result.js +206 -3
- package/out-tsc/src/flow/nodes/split_by_run_result.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_scheme.js +153 -2
- package/out-tsc/src/flow/nodes/split_by_scheme.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_subflow.js +6 -4
- package/out-tsc/src/flow/nodes/split_by_subflow.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_ticket.js +3 -2
- package/out-tsc/src/flow/nodes/split_by_ticket.js.map +1 -1
- package/out-tsc/src/flow/nodes/split_by_webhook.js +3 -2
- package/out-tsc/src/flow/nodes/split_by_webhook.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_audio.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_audio.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_digits.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_digits.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_image.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_image.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_location.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_location.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_menu.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_menu.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_response.js +32 -567
- package/out-tsc/src/flow/nodes/wait_for_response.js.map +1 -1
- package/out-tsc/src/flow/nodes/wait_for_video.js +2 -2
- package/out-tsc/src/flow/nodes/wait_for_video.js.map +1 -1
- package/out-tsc/src/flow/types.js +71 -12
- package/out-tsc/src/flow/types.js.map +1 -1
- package/out-tsc/src/flow/utils.js +101 -14
- package/out-tsc/src/flow/utils.js.map +1 -1
- package/out-tsc/src/form/ContactSearch.js +1 -1
- package/out-tsc/src/form/ContactSearch.js.map +1 -1
- package/out-tsc/src/form/FieldRenderer.js +2 -4
- package/out-tsc/src/form/FieldRenderer.js.map +1 -1
- package/out-tsc/src/interfaces.js +3 -0
- package/out-tsc/src/interfaces.js.map +1 -1
- package/out-tsc/src/list/SortableList.js +98 -33
- package/out-tsc/src/list/SortableList.js.map +1 -1
- package/out-tsc/src/live/ContactChat.js +15 -18
- package/out-tsc/src/live/ContactChat.js.map +1 -1
- package/out-tsc/src/store/AppState.js +53 -0
- package/out-tsc/src/store/AppState.js.map +1 -1
- package/out-tsc/src/utils.js +254 -13
- package/out-tsc/src/utils.js.map +1 -1
- package/out-tsc/temba-modules.js +4 -0
- package/out-tsc/temba-modules.js.map +1 -1
- package/out-tsc/test/ActionHelper.js +3 -3
- package/out-tsc/test/ActionHelper.js.map +1 -1
- package/out-tsc/test/NodeHelper.js +6 -3
- package/out-tsc/test/NodeHelper.js.map +1 -1
- package/out-tsc/test/actions/add_contact_urn.test.js +202 -0
- package/out-tsc/test/actions/add_contact_urn.test.js.map +1 -0
- package/out-tsc/test/actions/send_broadcast.test.js +148 -0
- package/out-tsc/test/actions/send_broadcast.test.js.map +1 -0
- package/out-tsc/test/actions/send_email.test.js +17 -23
- package/out-tsc/test/actions/send_email.test.js.map +1 -1
- package/out-tsc/test/actions/send_msg.test.js +33 -15
- package/out-tsc/test/actions/send_msg.test.js.map +1 -1
- package/out-tsc/test/actions/start_session.test.js +116 -0
- package/out-tsc/test/actions/start_session.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_airtime.test.js +604 -0
- package/out-tsc/test/nodes/split_by_airtime.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_contact_field.test.js +387 -0
- package/out-tsc/test/nodes/split_by_contact_field.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_expression.test.js +614 -0
- package/out-tsc/test/nodes/split_by_expression.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_random.test.js +3 -3
- package/out-tsc/test/nodes/split_by_random.test.js.map +1 -1
- package/out-tsc/test/nodes/split_by_resthook.test.js +337 -0
- package/out-tsc/test/nodes/split_by_resthook.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_run_result.test.js +920 -0
- package/out-tsc/test/nodes/split_by_run_result.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_scheme.test.js +399 -0
- package/out-tsc/test/nodes/split_by_scheme.test.js.map +1 -0
- package/out-tsc/test/nodes/split_by_subflow.test.js +333 -0
- package/out-tsc/test/nodes/split_by_subflow.test.js.map +1 -0
- package/out-tsc/test/nodes/wait_for_digits.test.js +2 -2
- package/out-tsc/test/nodes/wait_for_digits.test.js.map +1 -1
- package/out-tsc/test/nodes/wait_for_response.test.js +2 -1
- package/out-tsc/test/nodes/wait_for_response.test.js.map +1 -1
- package/out-tsc/test/temba-action-drag-between-nodes.test.js +252 -0
- package/out-tsc/test/temba-action-drag-between-nodes.test.js.map +1 -0
- package/out-tsc/test/temba-canvas-menu.test.js +122 -0
- package/out-tsc/test/temba-canvas-menu.test.js.map +1 -0
- package/out-tsc/test/temba-flow-editor-node.test.js +85 -2
- package/out-tsc/test/temba-flow-editor-node.test.js.map +1 -1
- package/out-tsc/test/temba-flow-editor.test.js +7 -8
- package/out-tsc/test/temba-flow-editor.test.js.map +1 -1
- package/out-tsc/test/temba-node-editor.test.js +3 -1
- package/out-tsc/test/temba-node-editor.test.js.map +1 -1
- package/out-tsc/test/temba-node-type-selector.test.js +115 -0
- package/out-tsc/test/temba-node-type-selector.test.js.map +1 -0
- package/out-tsc/test/temba-omnibox.test.js +2 -1
- package/out-tsc/test/temba-omnibox.test.js.map +1 -1
- package/out-tsc/test/temba-sortable-list.test.js +51 -0
- package/out-tsc/test/temba-sortable-list.test.js.map +1 -1
- package/out-tsc/test/temba-utils-index.test.js +1 -27
- package/out-tsc/test/temba-utils-index.test.js.map +1 -1
- package/out-tsc/test/utils.test.js +2 -0
- package/out-tsc/test/utils.test.js.map +1 -1
- package/package.json +2 -1
- package/screenshots/truth/actions/add_contact_groups/editor/descriptive-group-names.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/editor/long-group-names.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/editor/many-groups.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/editor/multiple-groups.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/editor/single-group.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/render/descriptive-group-names.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/render/long-group-names.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/render/many-groups.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/render/multiple-groups.png +0 -0
- package/screenshots/truth/actions/add_contact_groups/render/single-group.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/expression-facebook.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/expression-phone.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/facebook-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/instagram-handle.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/line-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/phone-number.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/telegram-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/viber-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/wechat-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/editor/whatsapp.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/expression-facebook.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/expression-phone.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/facebook-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/instagram-handle.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/line-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/phone-number.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/telegram-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/viber-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/wechat-id.png +0 -0
- package/screenshots/truth/actions/add_contact_urn/render/whatsapp.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/cleanup-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/long-descriptive-group-names.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/many-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/multiple-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/remove-from-all-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/editor/single-group.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/cleanup-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/long-descriptive-group-names.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/many-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/multiple-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/remove-from-all-groups.png +0 -0
- package/screenshots/truth/actions/remove_contact_groups/render/single-group.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/contacts-only.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/groups-and-contacts.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/groups-only.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/many-groups.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/multiline-text.png +0 -0
- package/screenshots/truth/actions/send_broadcast/editor/with-attachments.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/contacts-only.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/groups-and-contacts.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/groups-only.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/many-groups.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/multiline-text.png +0 -0
- package/screenshots/truth/actions/send_broadcast/render/with-attachments.png +0 -0
- package/screenshots/truth/actions/send_email/editor/complex-business-email.png +0 -0
- package/screenshots/truth/actions/send_email/editor/empty-body.png +0 -0
- package/screenshots/truth/actions/send_email/editor/empty-subject.png +0 -0
- package/screenshots/truth/actions/send_email/editor/long-subject.png +0 -0
- package/screenshots/truth/actions/send_email/editor/multiline-body.png +0 -0
- package/screenshots/truth/actions/send_email/editor/multiple-recipients.png +0 -0
- package/screenshots/truth/actions/send_email/editor/simple-email.png +0 -0
- package/screenshots/truth/actions/send_email/editor/with-expressions.png +0 -0
- package/screenshots/truth/actions/send_email/render/complex-business-email.png +0 -0
- package/screenshots/truth/actions/send_email/render/empty-body.png +0 -0
- package/screenshots/truth/actions/send_email/render/empty-subject.png +0 -0
- package/screenshots/truth/actions/send_email/render/long-subject.png +0 -0
- package/screenshots/truth/actions/send_email/render/multiline-body.png +0 -0
- package/screenshots/truth/actions/send_email/render/multiple-recipients.png +0 -0
- package/screenshots/truth/actions/send_email/render/simple-email.png +0 -0
- package/screenshots/truth/actions/send_email/render/with-expressions.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/long-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/multiline-text-with-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/simple-text.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/text-with-linebreaks.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/text-with-many-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/text-with-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/editor/text-without-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/render/long-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/render/multiline-text-with-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/render/simple-text.png +0 -0
- package/screenshots/truth/actions/send_msg/render/text-with-linebreaks.png +0 -0
- package/screenshots/truth/actions/send_msg/render/text-with-many-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/render/text-with-quick-replies.png +0 -0
- package/screenshots/truth/actions/send_msg/render/text-without-quick-replies.png +0 -0
- package/screenshots/truth/actions/start_session/editor/contact-query.png +0 -0
- package/screenshots/truth/actions/start_session/editor/contacts-only.png +0 -0
- package/screenshots/truth/actions/start_session/editor/create-contact.png +0 -0
- package/screenshots/truth/actions/start_session/editor/groups-and-contacts.png +0 -0
- package/screenshots/truth/actions/start_session/editor/groups-only.png +0 -0
- package/screenshots/truth/actions/start_session/editor/many-recipients.png +0 -0
- package/screenshots/truth/actions/start_session/render/contact-query.png +0 -0
- package/screenshots/truth/actions/start_session/render/contacts-only.png +0 -0
- package/screenshots/truth/actions/start_session/render/create-contact.png +0 -0
- package/screenshots/truth/actions/start_session/render/groups-and-contacts.png +0 -0
- package/screenshots/truth/actions/start_session/render/groups-only.png +0 -0
- package/screenshots/truth/actions/start_session/render/many-recipients.png +0 -0
- package/screenshots/truth/canvas-menu/open.png +0 -0
- package/screenshots/truth/editor/router.png +0 -0
- package/screenshots/truth/editor/wait.png +0 -0
- package/screenshots/truth/list/fields-dragging.png +0 -0
- package/screenshots/truth/list/sortable-dragging.png +0 -0
- package/screenshots/truth/node-type-selector/action-mode.png +0 -0
- package/screenshots/truth/node-type-selector/split-mode.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/editor/information-extraction.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/editor/sentiment-analysis.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/editor/summarization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/editor/translation-task.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/render/information-extraction.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/render/sentiment-analysis.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/render/summarization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm/render/translation-task.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/editor/basic-categorization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/editor/custom-input-and-result-name.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/editor/feedback-categorization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/editor/many-categories.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/editor/minimal-categories.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/render/basic-categorization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/render/custom-input-and-result-name.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/render/feedback-categorization.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/render/many-categories.png +0 -0
- package/screenshots/truth/nodes/split_by_llm_categorize/render/minimal-categories.png +0 -0
- package/screenshots/truth/nodes/split_by_random/editor/ab-test-multiple-variants.png +0 -0
- package/screenshots/truth/nodes/split_by_random/editor/sampling-split.png +0 -0
- package/screenshots/truth/nodes/split_by_random/editor/three-way-split.png +0 -0
- package/screenshots/truth/nodes/split_by_random/editor/two-bucket-split.png +0 -0
- package/screenshots/truth/nodes/split_by_random/render/ab-test-multiple-variants.png +0 -0
- package/screenshots/truth/nodes/split_by_random/render/sampling-split.png +0 -0
- package/screenshots/truth/nodes/split_by_random/render/three-way-split.png +0 -0
- package/screenshots/truth/nodes/split_by_random/render/two-bucket-split.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/editor/basic-digits-wait.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/editor/phone-number-collection.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/editor/single-digit-with-timeout.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/editor/verification-code.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/render/basic-digits-wait.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/render/phone-number-collection.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/render/single-digit-with-timeout.png +0 -0
- package/screenshots/truth/nodes/wait_for_digits/render/verification-code.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/editor/basic-wait.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/editor/custom-result-name.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/editor/no-timeout.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/editor/short-timeout.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/render/basic-wait.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/render/custom-result-name.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/render/no-timeout.png +0 -0
- package/screenshots/truth/nodes/wait_for_response/render/short-timeout.png +0 -0
- package/src/Icons.ts +4 -1
- package/src/events.ts +2 -6
- package/src/flow/CanvasMenu.ts +217 -0
- package/src/flow/CanvasNode.ts +408 -10
- package/src/flow/Editor.ts +683 -44
- package/src/flow/NodeEditor.ts +304 -125
- package/src/flow/NodeTypeSelector.ts +592 -0
- package/src/flow/actions/add_contact_groups.ts +4 -4
- package/src/flow/actions/add_contact_urn.ts +76 -4
- package/src/flow/actions/add_input_labels.ts +4 -4
- package/src/flow/actions/play_audio.ts +2 -2
- package/src/flow/actions/remove_contact_groups.ts +14 -6
- package/src/flow/actions/request_optin.ts +2 -2
- package/src/flow/actions/say_msg.ts +2 -2
- package/src/flow/actions/send_broadcast.ts +85 -23
- package/src/flow/actions/send_email.ts +10 -6
- package/src/flow/actions/send_msg.ts +22 -32
- package/src/flow/actions/set_contact_channel.ts +5 -11
- package/src/flow/actions/set_contact_field.ts +20 -25
- package/src/flow/actions/set_contact_language.ts +9 -4
- package/src/flow/actions/set_contact_name.ts +3 -15
- package/src/flow/actions/set_contact_status.ts +3 -3
- package/src/flow/actions/set_run_result.ts +4 -4
- package/src/flow/actions/start_session.ts +208 -6
- package/src/flow/config.ts +13 -15
- package/src/flow/currencies.ts +51 -0
- package/src/flow/nodes/shared-rules.ts +301 -0
- package/src/flow/nodes/shared.ts +18 -0
- package/src/flow/nodes/split_by_airtime.ts +238 -5
- package/src/flow/nodes/split_by_contact_field.ts +185 -3
- package/src/flow/nodes/split_by_expression.ts +94 -2
- package/src/flow/nodes/split_by_groups.ts +15 -10
- package/src/flow/nodes/split_by_intent.ts +7 -0
- package/src/flow/nodes/split_by_llm.ts +4 -3
- package/src/flow/nodes/split_by_llm_categorize.ts +4 -4
- package/src/flow/nodes/split_by_random.ts +5 -5
- package/src/flow/nodes/split_by_resthook.ts +130 -0
- package/src/flow/nodes/split_by_run_result.ts +249 -3
- package/src/flow/nodes/split_by_scheme.ts +192 -2
- package/src/flow/nodes/split_by_subflow.ts +6 -4
- package/src/flow/nodes/split_by_ticket.ts +4 -3
- package/src/flow/nodes/split_by_webhook.ts +6 -5
- package/src/flow/nodes/wait_for_audio.ts +2 -2
- package/src/flow/nodes/wait_for_digits.ts +2 -2
- package/src/flow/nodes/wait_for_image.ts +2 -2
- package/src/flow/nodes/wait_for_location.ts +2 -2
- package/src/flow/nodes/wait_for_menu.ts +2 -2
- package/src/flow/nodes/wait_for_response.ts +48 -679
- package/src/flow/nodes/wait_for_video.ts +2 -2
- package/src/flow/types.ts +109 -23
- package/src/flow/utils.ts +108 -14
- package/src/form/ContactSearch.ts +1 -1
- package/src/form/FieldRenderer.ts +2 -4
- package/src/interfaces.ts +3 -0
- package/src/list/SortableList.ts +109 -34
- package/src/live/ContactChat.ts +15 -18
- package/src/store/AppState.ts +69 -0
- package/src/store/flow-definition.d.ts +2 -5
- package/src/utils.ts +332 -12
- package/static/api/channels.json +46 -0
- package/static/api/resthooks.json +31 -0
- package/static/svg/index.svg +1 -1
- package/static/svg/work/traced/lightning-02.svg +1 -0
- package/static/svg/work/used/lightning-02.svg +3 -0
- package/temba-modules.ts +4 -0
- package/test/ActionHelper.ts +3 -3
- package/test/NodeHelper.ts +6 -3
- package/test/actions/add_contact_urn.test.ts +287 -0
- package/test/actions/send_broadcast.test.ts +190 -0
- package/test/actions/send_email.test.ts +17 -23
- package/test/actions/send_msg.test.ts +39 -15
- package/test/actions/start_session.test.ts +151 -0
- package/test/nodes/split_by_airtime.test.ts +673 -0
- package/test/nodes/split_by_contact_field.test.ts +451 -0
- package/test/nodes/split_by_expression.test.ts +751 -0
- package/test/nodes/split_by_random.test.ts +3 -3
- package/test/nodes/split_by_resthook.test.ts +398 -0
- package/test/nodes/split_by_run_result.test.ts +1109 -0
- package/test/nodes/split_by_scheme.test.ts +486 -0
- package/test/nodes/split_by_subflow.test.ts +381 -0
- package/test/nodes/wait_for_digits.test.ts +2 -2
- package/test/nodes/wait_for_response.test.ts +2 -1
- package/test/temba-action-drag-between-nodes.test.ts +301 -0
- package/test/temba-canvas-menu.test.ts +156 -0
- package/test/temba-flow-editor-node.test.ts +102 -2
- package/test/temba-flow-editor.test.ts +7 -8
- package/test/temba-node-editor.test.ts +3 -1
- package/test/temba-node-type-selector.test.ts +152 -0
- package/test/temba-omnibox.test.ts +2 -1
- package/test/temba-sortable-list.test.ts +69 -0
- package/test/temba-utils-index.test.ts +0 -35
- package/test/utils.test.ts +2 -0
- package/test-assets/contacts/history.json +14 -20
- package/web-dev-server.config.mjs +3 -1
- package/out-tsc/src/flow/actions/call_classifier.js +0 -11
- package/out-tsc/src/flow/actions/call_classifier.js.map +0 -1
- package/out-tsc/src/flow/actions/call_resthook.js +0 -11
- package/out-tsc/src/flow/actions/call_resthook.js.map +0 -1
- package/out-tsc/src/flow/actions/split_by_expression_example.js +0 -77
- package/out-tsc/src/flow/actions/split_by_expression_example.js.map +0 -1
- package/out-tsc/src/flow/actions/transfer_airtime.js +0 -11
- package/out-tsc/src/flow/actions/transfer_airtime.js.map +0 -1
- package/src/flow/actions/call_classifier.ts +0 -12
- package/src/flow/actions/call_resthook.ts +0 -12
- package/src/flow/actions/split_by_expression_example.ts +0 -88
- package/src/flow/actions/transfer_airtime.ts +0 -12
|
@@ -151,6 +151,17 @@ export const zustand = createStore()(subscribeWithSelector(immer((set, get) => (
|
|
|
151
151
|
state.dirtyDate = new Date();
|
|
152
152
|
});
|
|
153
153
|
},
|
|
154
|
+
updateNodeUIConfig: (uuid, config) => {
|
|
155
|
+
set((state) => {
|
|
156
|
+
if (state.flowDefinition._ui.nodes[uuid]) {
|
|
157
|
+
if (!state.flowDefinition._ui.nodes[uuid].config) {
|
|
158
|
+
state.flowDefinition._ui.nodes[uuid].config = {};
|
|
159
|
+
}
|
|
160
|
+
Object.assign(state.flowDefinition._ui.nodes[uuid].config, config);
|
|
161
|
+
}
|
|
162
|
+
state.dirtyDate = new Date();
|
|
163
|
+
});
|
|
164
|
+
},
|
|
154
165
|
updateConnection: (nodeUuid, exitUuid, destinationNodeUuid) => {
|
|
155
166
|
set((state) => {
|
|
156
167
|
// Find the exit with this UUID
|
|
@@ -188,6 +199,48 @@ export const zustand = createStore()(subscribeWithSelector(immer((set, get) => (
|
|
|
188
199
|
state.dirtyDate = new Date();
|
|
189
200
|
});
|
|
190
201
|
return uuid;
|
|
202
|
+
},
|
|
203
|
+
createNode: (nodeType, position) => {
|
|
204
|
+
const uuid = generateUUID();
|
|
205
|
+
const exitUuid = generateUUID();
|
|
206
|
+
set((state) => {
|
|
207
|
+
// Create a basic node with a single exit
|
|
208
|
+
const newNode = {
|
|
209
|
+
uuid,
|
|
210
|
+
actions: [],
|
|
211
|
+
exits: [
|
|
212
|
+
{
|
|
213
|
+
uuid: exitUuid,
|
|
214
|
+
destination_uuid: null
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
};
|
|
218
|
+
// Add the node to the flow definition
|
|
219
|
+
state.flowDefinition.nodes.push(newNode);
|
|
220
|
+
// Set up UI for the node
|
|
221
|
+
if (!state.flowDefinition._ui.nodes) {
|
|
222
|
+
state.flowDefinition._ui.nodes = {};
|
|
223
|
+
}
|
|
224
|
+
state.flowDefinition._ui.nodes[uuid] = {
|
|
225
|
+
position,
|
|
226
|
+
type: nodeType,
|
|
227
|
+
config: {}
|
|
228
|
+
};
|
|
229
|
+
state.dirtyDate = new Date();
|
|
230
|
+
});
|
|
231
|
+
return uuid;
|
|
232
|
+
},
|
|
233
|
+
addNode: (node, nodeUI) => {
|
|
234
|
+
set((state) => {
|
|
235
|
+
// Add the node to the flow definition
|
|
236
|
+
state.flowDefinition.nodes.push(node);
|
|
237
|
+
// Set up UI for the node
|
|
238
|
+
if (!state.flowDefinition._ui.nodes) {
|
|
239
|
+
state.flowDefinition._ui.nodes = {};
|
|
240
|
+
}
|
|
241
|
+
state.flowDefinition._ui.nodes[node.uuid] = nodeUI;
|
|
242
|
+
state.dirtyDate = new Date();
|
|
243
|
+
});
|
|
191
244
|
}
|
|
192
245
|
}))));
|
|
193
246
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppState.js","sourceRoot":"","sources":["../../../src/store/AppState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAUtD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACxC,MAAM,cAAc,GAAG,GAAG,CAAC;AA4F3B,MAAM,CAAC,MAAM,OA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,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAExC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAM,EAAE,EAAE;gBACpE,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;YACnB,CAAC,CAAC,CAAC;YAEH,IAAI,aAAa;gBAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC;QAEF,KAAK,CAAC,eAAe,CAAC,GAAG;;YACvB,MAAA,MAAA,IAAI,CAAC,mBAAmB,0CAAG,IAAI,CAAC,kDAAI,CAAC;YACrC,IAAI,gBAAgB;gBAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createStore, StoreApi } from 'zustand/vanilla';\nimport { fetchResults, generateUUID } from '../utils';\nimport {\n Action,\n Exit,\n FlowDefinition,\n FlowPosition,\n Node,\n Router,\n StickyNote\n} from './flow-definition';\nimport { immer } from 'zustand/middleware/immer';\nimport { subscribeWithSelector } from 'zustand/middleware';\nimport { property } from 'lit/decorators.js';\nimport { produce } from 'immer';\n\nexport const FLOW_SPEC_VERSION = '14.3';\nconst CANVAS_PADDING = 800;\n\nexport interface InfoResult {\n key: string;\n name: string;\n categories: string[];\n node_uuids: string[];\n}\n\nexport interface ObjectRef {\n uuid: string;\n name: string;\n}\n\nexport interface TypedObjectRef extends ObjectRef {\n type: string;\n}\n\nexport interface Language {\n code: string;\n name: string;\n}\n\nexport interface FlowInfo {\n results: InfoResult[];\n dependencies: TypedObjectRef[];\n counts: { nodes: number; languages: number };\n locals: string[];\n}\n\nexport interface FlowContents {\n definition: FlowDefinition;\n info: FlowInfo;\n}\n\nexport interface Workspace {\n anon: boolean;\n country: string;\n date_style: string;\n languages: string[];\n name: string;\n primary_language: string;\n timezone: string;\n uuid: string;\n}\n\nexport interface CanvasPositions {\n [uuid: string]: FlowPosition;\n}\n\nexport interface AppState {\n flowDefinition: FlowDefinition;\n flowInfo: FlowInfo;\n\n languageCode: string;\n languageNames: { [code: string]: Language };\n workspace: Workspace;\n isTranslating: boolean;\n\n dirtyDate: Date | null;\n\n canvasSize: { width: number; height: number };\n\n fetchRevision: (endpoint: string, id?: string) => void;\n fetchWorkspace: (endpoint: string) => Promise<void>;\n fetchAllLanguages: (endpoint: string) => Promise<void>;\n\n getFlowResults: () => InfoResult[];\n getResultByKey(id: any): InfoResult;\n\n setFlowContents: (flow: FlowContents) => void;\n setFlowInfo: (info: FlowInfo) => void;\n setLanguageCode: (languageCode: string) => void;\n setDirtyDate: (date: Date) => void;\n expandCanvas: (width: number, height: number) => void;\n\n updateNode(\n uuid: string,\n node: { actions: Action[]; uuid: string; exits: Exit[]; router?: Router }\n ): unknown;\n updateConnection(\n nodeUuid: string,\n exitUuid: string,\n destinationNodeUuid: string\n ): unknown;\n updateCanvasPositions: (positions: CanvasPositions) => void;\n removeNodes: (uuids: string[]) => void;\n removeStickyNotes: (uuids: string[]) => void;\n updateStickyNote(uuid: string, sticky: StickyNote): void;\n createStickyNote(position: FlowPosition): string;\n}\n\nexport const zustand = createStore<AppState>()(\n subscribeWithSelector(\n immer((set, get) => ({\n languageNames: {},\n canvasSize: { width: 0, height: 0 },\n languageCode: '',\n workspace: null,\n flowDefinition: null,\n flowInfo: null,\n isTranslating: false,\n dirtyDate: null,\n\n setDirtyDate: (date: Date) => {\n set((state: AppState) => {\n state.dirtyDate = date;\n });\n },\n\n fetchRevision: async (endpoint: string, id: string = null) => {\n if (!id) {\n id = 'latest';\n }\n const response = await fetch(\n `${endpoint}/${id}/?version=${FLOW_SPEC_VERSION}`\n );\n\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = (await response.json()) as FlowContents;\n set({ flowInfo: data.info, flowDefinition: data.definition });\n },\n\n fetchWorkspace: async (endpoint) => {\n const response = await fetch(endpoint);\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = await response.json();\n set({ workspace: data });\n },\n\n fetchAllLanguages: async (endpoint) => {\n const results = await fetchResults(endpoint);\n\n // convert array to map for easier lookup\n const allLanguages = results.reduce(function (\n languages: any,\n result: any\n ) {\n languages[result.value] = result.name;\n return languages;\n },\n {});\n\n set({ languageNames: allLanguages });\n },\n\n getFlowResults: () => {\n const state = get();\n return state.flowInfo.results;\n },\n\n getResultByKey: (id: any) => {\n const state = get();\n const results = state.flowInfo.results;\n return results.find((result) => result.key === id);\n },\n\n getLanguage: () => {\n const state = get();\n const languageCode = state.languageCode;\n const languageNames = state.languageNames;\n return { name: languageNames[languageCode], code: languageCode };\n },\n\n // todo: eventually we should be doing the fetching\n setFlowContents: (flow: FlowContents) => {\n set((state: AppState) => {\n const flowLang = flow.definition.language;\n state.flowDefinition = flow.definition;\n state.flowInfo = flow.info;\n // Reset to the flow's default language when loading a new flow\n state.languageCode = flowLang;\n state.isTranslating = false;\n });\n },\n\n setFlowInfo: (info: FlowInfo) => {\n set((state: AppState) => {\n state.flowInfo = info;\n });\n },\n\n setLanguageCode: (languageCode: string) => {\n set((state: AppState) => {\n state.languageCode = languageCode;\n state.isTranslating = state.flowDefinition.language !== languageCode;\n });\n },\n\n expandCanvas: (width: number, height: number) => {\n set((state: AppState) => {\n const minWidth = Math.max(\n state.canvasSize.width,\n width + CANVAS_PADDING\n );\n const minHeight = Math.max(\n state.canvasSize.height,\n height + CANVAS_PADDING\n );\n\n state.canvasSize.width = minWidth;\n state.canvasSize.height = minHeight;\n });\n },\n\n updateCanvasPositions: (positions: CanvasPositions) => {\n set((state: AppState) => {\n for (const uuid in positions) {\n // todo: add nodes that are created and then moved, for now ignore\n if (state.flowDefinition._ui.nodes[uuid]) {\n state.flowDefinition._ui.nodes[uuid].position = positions[uuid];\n }\n\n // otherwise, it might be a sticky\n else if (state.flowDefinition._ui.stickies[uuid]) {\n state.flowDefinition._ui.stickies[uuid].position =\n positions[uuid];\n }\n }\n state.dirtyDate = new Date();\n });\n },\n\n removeNodes: (uuids: string[]) => {\n set((state: AppState) => {\n for (const uuid of uuids) {\n delete state.flowDefinition._ui.nodes[uuid];\n }\n\n state.flowDefinition = produce(state.flowDefinition, (draft) => {\n draft.nodes = draft.nodes.filter(\n (node) => !uuids.includes(node.uuid)\n );\n\n draft.nodes.forEach((node) => {\n node.exits.forEach((exit) => {\n if (uuids.includes(exit.destination_uuid)) {\n exit.destination_uuid = null;\n }\n });\n });\n });\n\n state.dirtyDate = new Date();\n });\n },\n\n removeStickyNotes: (uuids: string[]) => {\n set((state: AppState) => {\n if (state.flowDefinition._ui?.stickies) {\n for (const uuid of uuids) {\n delete state.flowDefinition._ui.stickies[uuid];\n }\n }\n state.dirtyDate = new Date();\n });\n },\n\n updateNode: (uuid: string, newNode: Node) => {\n set((state: AppState) => {\n const node = state.flowDefinition?.nodes.find((n) => n.uuid === uuid);\n if (node) {\n node.actions = newNode.actions;\n node.uuid = newNode.uuid;\n node.exits = newNode.exits;\n node.router = newNode.router;\n }\n state.dirtyDate = new Date();\n });\n },\n\n updateConnection: (\n nodeUuid: string,\n exitUuid: string,\n destinationNodeUuid: string\n ) => {\n set((state: AppState) => {\n // Find the exit with this UUID\n const node = state.flowDefinition.nodes.find(\n (node) => node.uuid === nodeUuid\n );\n\n const exit = node?.exits.find((e) => e.uuid === exitUuid);\n if (exit) {\n // Update the destination\n exit.destination_uuid = destinationNodeUuid;\n state.dirtyDate = new Date();\n }\n });\n },\n\n updateStickyNote: (uuid: string, sticky: StickyNote) => {\n set((state: AppState) => {\n if (!state.flowDefinition._ui.stickies) {\n state.flowDefinition._ui.stickies = {};\n }\n state.flowDefinition._ui.stickies[uuid] = sticky;\n state.dirtyDate = new Date();\n });\n },\n\n createStickyNote: (position: FlowPosition): string => {\n const uuid = generateUUID();\n set((state: AppState) => {\n if (!state.flowDefinition._ui.stickies) {\n state.flowDefinition._ui.stickies = {};\n }\n\n const newSticky: StickyNote = {\n position,\n title: '',\n body: '',\n color: 'yellow'\n };\n\n state.flowDefinition._ui.stickies[uuid] = newSticky;\n state.dirtyDate = new Date();\n });\n return uuid;\n }\n }))\n )\n);\n\ntype SelectorAwareStoreApi<S extends object> = StoreApi<S> & {\n subscribe: <U>(\n selector: (state: S) => U,\n listener: (value: U, previous: U) => void\n ) => () => void;\n};\n\n/**\n * Custom Lit property decorator that binds a property to a Zustand store subscription.\n *\n * @param store - The Zustand store to subscribe to.\n * @param selector - A function selecting the slice of state to bind to the property.\n */\nexport function fromStore<S extends object, V = unknown>(\n store: SelectorAwareStoreApi<S>,\n selector: (state: S) => V\n): PropertyDecorator {\n return (proto: any, name: string | symbol) => {\n property()(proto, name as string);\n\n const connectedKey = 'connectedCallback';\n const disconnectedKey = 'disconnectedCallback';\n\n const userConnected = proto[connectedKey];\n const userDisconnected = proto[disconnectedKey];\n\n proto[connectedKey] = function () {\n this._zustandUnsubscribe ??= {};\n this[name] = selector(store.getState());\n\n this._zustandUnsubscribe[name] = store.subscribe(selector, (val: V) => {\n this[name] = val;\n });\n\n if (userConnected) userConnected.call(this);\n };\n\n proto[disconnectedKey] = function () {\n this._zustandUnsubscribe?.[name]?.();\n if (userDisconnected) userDisconnected.call(this);\n };\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AppState.js","sourceRoot":"","sources":["../../../src/store/AppState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAWtD,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACx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,MAAA,IAAI,CAAC,mBAAmB,0CAAG,IAAI,CAAC,kDAAI,CAAC;YACrC,IAAI,gBAAgB;gBAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createStore, StoreApi } from 'zustand/vanilla';\nimport { fetchResults, generateUUID } from '../utils';\nimport {\n Action,\n Exit,\n FlowDefinition,\n FlowPosition,\n Node,\n NodeUI,\n Router,\n StickyNote\n} from './flow-definition';\nimport { immer } from 'zustand/middleware/immer';\nimport { subscribeWithSelector } from 'zustand/middleware';\nimport { property } from 'lit/decorators.js';\nimport { produce } from 'immer';\n\nexport const FLOW_SPEC_VERSION = '14.3';\nconst CANVAS_PADDING = 800;\n\nexport interface InfoResult {\n key: string;\n name: string;\n categories: string[];\n node_uuids: string[];\n}\n\nexport interface ObjectRef {\n uuid: string;\n name: string;\n}\n\nexport interface TypedObjectRef extends ObjectRef {\n type: string;\n}\n\nexport interface Language {\n code: string;\n name: string;\n}\n\nexport interface FlowInfo {\n results: InfoResult[];\n dependencies: TypedObjectRef[];\n counts: { nodes: number; languages: number };\n locals: string[];\n}\n\nexport interface FlowContents {\n definition: FlowDefinition;\n info: FlowInfo;\n}\n\nexport interface Workspace {\n anon: boolean;\n country: string;\n date_style: string;\n languages: string[];\n name: string;\n primary_language: string;\n timezone: string;\n uuid: string;\n}\n\nexport interface CanvasPositions {\n [uuid: string]: FlowPosition;\n}\n\nexport interface AppState {\n flowDefinition: FlowDefinition;\n flowInfo: FlowInfo;\n\n languageCode: string;\n languageNames: { [code: string]: Language };\n workspace: Workspace;\n isTranslating: boolean;\n\n dirtyDate: Date | null;\n\n canvasSize: { width: number; height: number };\n\n fetchRevision: (endpoint: string, id?: string) => void;\n fetchWorkspace: (endpoint: string) => Promise<void>;\n fetchAllLanguages: (endpoint: string) => Promise<void>;\n\n getFlowResults: () => InfoResult[];\n getResultByKey(id: any): InfoResult;\n\n setFlowContents: (flow: FlowContents) => void;\n setFlowInfo: (info: FlowInfo) => void;\n setLanguageCode: (languageCode: string) => void;\n setDirtyDate: (date: Date) => void;\n expandCanvas: (width: number, height: number) => void;\n\n updateNode(\n uuid: string,\n node: { actions: Action[]; uuid: string; exits: Exit[]; router?: Router }\n ): unknown;\n updateNodeUIConfig(uuid: string, config: Record<string, any>): unknown;\n updateConnection(\n nodeUuid: string,\n exitUuid: string,\n destinationNodeUuid: string\n ): unknown;\n updateCanvasPositions: (positions: CanvasPositions) => void;\n removeNodes: (uuids: string[]) => void;\n removeStickyNotes: (uuids: string[]) => void;\n updateStickyNote(uuid: string, sticky: StickyNote): void;\n createStickyNote(position: FlowPosition): string;\n createNode(nodeType: string, position: FlowPosition): string;\n addNode(node: Node, nodeUI: NodeUI): void;\n}\n\nexport const zustand = createStore<AppState>()(\n subscribeWithSelector(\n immer((set, get) => ({\n languageNames: {},\n canvasSize: { width: 0, height: 0 },\n languageCode: '',\n workspace: null,\n flowDefinition: null,\n flowInfo: null,\n isTranslating: false,\n dirtyDate: null,\n\n setDirtyDate: (date: Date) => {\n set((state: AppState) => {\n state.dirtyDate = date;\n });\n },\n\n fetchRevision: async (endpoint: string, id: string = null) => {\n if (!id) {\n id = 'latest';\n }\n const response = await fetch(\n `${endpoint}/${id}/?version=${FLOW_SPEC_VERSION}`\n );\n\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = (await response.json()) as FlowContents;\n set({ flowInfo: data.info, flowDefinition: data.definition });\n },\n\n fetchWorkspace: async (endpoint) => {\n const response = await fetch(endpoint);\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = await response.json();\n set({ workspace: data });\n },\n\n fetchAllLanguages: async (endpoint) => {\n const results = await fetchResults(endpoint);\n\n // convert array to map for easier lookup\n const allLanguages = results.reduce(function (\n languages: any,\n result: any\n ) {\n languages[result.value] = result.name;\n return languages;\n },\n {});\n\n set({ languageNames: allLanguages });\n },\n\n getFlowResults: () => {\n const state = get();\n return state.flowInfo.results;\n },\n\n getResultByKey: (id: any) => {\n const state = get();\n const results = state.flowInfo.results;\n return results.find((result) => result.key === id);\n },\n\n getLanguage: () => {\n const state = get();\n const languageCode = state.languageCode;\n const languageNames = state.languageNames;\n return { name: languageNames[languageCode], code: languageCode };\n },\n\n // todo: eventually we should be doing the fetching\n setFlowContents: (flow: FlowContents) => {\n set((state: AppState) => {\n const flowLang = flow.definition.language;\n state.flowDefinition = flow.definition;\n state.flowInfo = flow.info;\n // Reset to the flow's default language when loading a new flow\n state.languageCode = flowLang;\n state.isTranslating = false;\n });\n },\n\n setFlowInfo: (info: FlowInfo) => {\n set((state: AppState) => {\n state.flowInfo = info;\n });\n },\n\n setLanguageCode: (languageCode: string) => {\n set((state: AppState) => {\n state.languageCode = languageCode;\n state.isTranslating = state.flowDefinition.language !== languageCode;\n });\n },\n\n expandCanvas: (width: number, height: number) => {\n set((state: AppState) => {\n const minWidth = Math.max(\n state.canvasSize.width,\n width + CANVAS_PADDING\n );\n const minHeight = Math.max(\n state.canvasSize.height,\n height + CANVAS_PADDING\n );\n\n state.canvasSize.width = minWidth;\n state.canvasSize.height = minHeight;\n });\n },\n\n updateCanvasPositions: (positions: CanvasPositions) => {\n set((state: AppState) => {\n for (const uuid in positions) {\n // todo: add nodes that are created and then moved, for now ignore\n if (state.flowDefinition._ui.nodes[uuid]) {\n state.flowDefinition._ui.nodes[uuid].position = positions[uuid];\n }\n\n // otherwise, it might be a sticky\n else if (state.flowDefinition._ui.stickies[uuid]) {\n state.flowDefinition._ui.stickies[uuid].position =\n positions[uuid];\n }\n }\n state.dirtyDate = new Date();\n });\n },\n\n removeNodes: (uuids: string[]) => {\n set((state: AppState) => {\n for (const uuid of uuids) {\n delete state.flowDefinition._ui.nodes[uuid];\n }\n\n state.flowDefinition = produce(state.flowDefinition, (draft) => {\n draft.nodes = draft.nodes.filter(\n (node) => !uuids.includes(node.uuid)\n );\n\n draft.nodes.forEach((node) => {\n node.exits.forEach((exit) => {\n if (uuids.includes(exit.destination_uuid)) {\n exit.destination_uuid = null;\n }\n });\n });\n });\n\n state.dirtyDate = new Date();\n });\n },\n\n removeStickyNotes: (uuids: string[]) => {\n set((state: AppState) => {\n if (state.flowDefinition._ui?.stickies) {\n for (const uuid of uuids) {\n delete state.flowDefinition._ui.stickies[uuid];\n }\n }\n state.dirtyDate = new Date();\n });\n },\n\n updateNode: (uuid: string, newNode: Node) => {\n set((state: AppState) => {\n const node = state.flowDefinition?.nodes.find((n) => n.uuid === uuid);\n if (node) {\n node.actions = newNode.actions;\n node.uuid = newNode.uuid;\n node.exits = newNode.exits;\n node.router = newNode.router;\n }\n state.dirtyDate = new Date();\n });\n },\n\n updateNodeUIConfig: (uuid: string, config: Record<string, any>) => {\n set((state: AppState) => {\n if (state.flowDefinition._ui.nodes[uuid]) {\n if (!state.flowDefinition._ui.nodes[uuid].config) {\n state.flowDefinition._ui.nodes[uuid].config = {};\n }\n Object.assign(state.flowDefinition._ui.nodes[uuid].config, config);\n }\n state.dirtyDate = new Date();\n });\n },\n\n updateConnection: (\n nodeUuid: string,\n exitUuid: string,\n destinationNodeUuid: string\n ) => {\n set((state: AppState) => {\n // Find the exit with this UUID\n const node = state.flowDefinition.nodes.find(\n (node) => node.uuid === nodeUuid\n );\n\n const exit = node?.exits.find((e) => e.uuid === exitUuid);\n if (exit) {\n // Update the destination\n exit.destination_uuid = destinationNodeUuid;\n state.dirtyDate = new Date();\n }\n });\n },\n\n updateStickyNote: (uuid: string, sticky: StickyNote) => {\n set((state: AppState) => {\n if (!state.flowDefinition._ui.stickies) {\n state.flowDefinition._ui.stickies = {};\n }\n state.flowDefinition._ui.stickies[uuid] = sticky;\n state.dirtyDate = new Date();\n });\n },\n\n createStickyNote: (position: FlowPosition): string => {\n const uuid = generateUUID();\n set((state: AppState) => {\n if (!state.flowDefinition._ui.stickies) {\n state.flowDefinition._ui.stickies = {};\n }\n\n const newSticky: StickyNote = {\n position,\n title: '',\n body: '',\n color: 'yellow'\n };\n\n state.flowDefinition._ui.stickies[uuid] = newSticky;\n state.dirtyDate = new Date();\n });\n return uuid;\n },\n\n createNode: (nodeType: string, position: FlowPosition): string => {\n const uuid = generateUUID();\n const exitUuid = generateUUID();\n\n set((state: AppState) => {\n // Create a basic node with a single exit\n const newNode: Node = {\n uuid,\n actions: [],\n exits: [\n {\n uuid: exitUuid,\n destination_uuid: null\n }\n ]\n };\n\n // Add the node to the flow definition\n state.flowDefinition.nodes.push(newNode);\n\n // Set up UI for the node\n if (!state.flowDefinition._ui.nodes) {\n state.flowDefinition._ui.nodes = {};\n }\n\n state.flowDefinition._ui.nodes[uuid] = {\n position,\n type: nodeType as any,\n config: {}\n };\n\n state.dirtyDate = new Date();\n });\n\n return uuid;\n },\n\n addNode: (node: Node, nodeUI: NodeUI) => {\n set((state: AppState) => {\n // Add the node to the flow definition\n state.flowDefinition.nodes.push(node);\n\n // Set up UI for the node\n if (!state.flowDefinition._ui.nodes) {\n state.flowDefinition._ui.nodes = {};\n }\n\n state.flowDefinition._ui.nodes[node.uuid] = nodeUI;\n\n state.dirtyDate = new Date();\n });\n }\n }))\n )\n);\n\ntype SelectorAwareStoreApi<S extends object> = StoreApi<S> & {\n subscribe: <U>(\n selector: (state: S) => U,\n listener: (value: U, previous: U) => void\n ) => () => void;\n};\n\n/**\n * Custom Lit property decorator that binds a property to a Zustand store subscription.\n *\n * @param store - The Zustand store to subscribe to.\n * @param selector - A function selecting the slice of state to bind to the property.\n */\nexport function fromStore<S extends object, V = unknown>(\n store: SelectorAwareStoreApi<S>,\n selector: (state: S) => V\n): PropertyDecorator {\n return (proto: any, name: string | symbol) => {\n property()(proto, name as string);\n\n const connectedKey = 'connectedCallback';\n const disconnectedKey = 'disconnectedCallback';\n\n const userConnected = proto[connectedKey];\n const userDisconnected = proto[disconnectedKey];\n\n proto[connectedKey] = function () {\n this._zustandUnsubscribe ??= {};\n this[name] = selector(store.getState());\n\n this._zustandUnsubscribe[name] = store.subscribe(selector, (val: V) => {\n this[name] = val;\n });\n\n if (userConnected) userConnected.call(this);\n };\n\n proto[disconnectedKey] = function () {\n this._zustandUnsubscribe?.[name]?.();\n if (userDisconnected) userDisconnected.call(this);\n };\n };\n}\n"]}
|
package/out-tsc/src/utils.js
CHANGED
|
@@ -378,19 +378,6 @@ export class Stubbable {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
export const stubbable = new Stubbable();
|
|
381
|
-
export const spreadAttributes = (obj) => {
|
|
382
|
-
return Object.entries(obj).map(([key, value]) => {
|
|
383
|
-
if (key.startsWith('@')) {
|
|
384
|
-
return html `@${key.slice(1)}=${value}`;
|
|
385
|
-
}
|
|
386
|
-
else if (key.startsWith('.')) {
|
|
387
|
-
return html `.${key.slice(1)}=${value}`;
|
|
388
|
-
}
|
|
389
|
-
else {
|
|
390
|
-
return html `${key}=${value}`;
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
};
|
|
394
381
|
export const timeSince = (date, options = {
|
|
395
382
|
suffix: ''
|
|
396
383
|
}) => {
|
|
@@ -843,6 +830,260 @@ export const createMultiCategoryRouter = (operand, userCategories, categoryToCas
|
|
|
843
830
|
exits: exits
|
|
844
831
|
};
|
|
845
832
|
};
|
|
833
|
+
// Helper function to check if a category is a system category
|
|
834
|
+
export const isSystemCategory = (categoryName) => {
|
|
835
|
+
return ['No Response', 'Other', 'All Responses', 'Timeout'].includes(categoryName);
|
|
836
|
+
};
|
|
837
|
+
// Helper function to check if a UUID belongs to a system category
|
|
838
|
+
export const isSystemCategoryUuid = (uuid, categories) => {
|
|
839
|
+
const category = categories.find((cat) => cat.uuid === uuid);
|
|
840
|
+
return category ? isSystemCategory(category.name) : false;
|
|
841
|
+
};
|
|
842
|
+
// Helper function to generate default category name based on operator and operands
|
|
843
|
+
export const generateDefaultCategoryName = (operator, getOperatorConfig, value1, value2) => {
|
|
844
|
+
const operatorConfig = getOperatorConfig(operator);
|
|
845
|
+
if (!operatorConfig)
|
|
846
|
+
return '';
|
|
847
|
+
// Fixed category names (no operands)
|
|
848
|
+
if (operatorConfig.operands === 0) {
|
|
849
|
+
return operatorConfig.categoryName || '';
|
|
850
|
+
}
|
|
851
|
+
// Dynamic category names based on operands
|
|
852
|
+
const cleanValue1 = (value1 || '').trim();
|
|
853
|
+
const cleanValue2 = (value2 || '').trim();
|
|
854
|
+
// Helper to capitalize first letter
|
|
855
|
+
const capitalize = (str) => {
|
|
856
|
+
if (!str)
|
|
857
|
+
return '';
|
|
858
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
859
|
+
};
|
|
860
|
+
// Handle different operator types
|
|
861
|
+
switch (operator) {
|
|
862
|
+
// Word/phrase operators - capitalize first letter of value
|
|
863
|
+
case 'has_any_word':
|
|
864
|
+
case 'has_all_words':
|
|
865
|
+
case 'has_phrase':
|
|
866
|
+
case 'has_only_phrase':
|
|
867
|
+
case 'has_beginning':
|
|
868
|
+
return cleanValue1 ? capitalize(cleanValue1) : '';
|
|
869
|
+
// Pattern operators - show as-is
|
|
870
|
+
case 'has_pattern':
|
|
871
|
+
return cleanValue1;
|
|
872
|
+
// Number comparison operators - include symbol
|
|
873
|
+
case 'has_number_eq':
|
|
874
|
+
return cleanValue1 ? `= ${cleanValue1}` : '';
|
|
875
|
+
case 'has_number_lt':
|
|
876
|
+
return cleanValue1 ? `< ${cleanValue1}` : '';
|
|
877
|
+
case 'has_number_lte':
|
|
878
|
+
return cleanValue1 ? `≤ ${cleanValue1}` : '';
|
|
879
|
+
case 'has_number_gt':
|
|
880
|
+
return cleanValue1 ? `> ${cleanValue1}` : '';
|
|
881
|
+
case 'has_number_gte':
|
|
882
|
+
return cleanValue1 ? `≥ ${cleanValue1}` : '';
|
|
883
|
+
// Number between - range format
|
|
884
|
+
case 'has_number_between':
|
|
885
|
+
if (cleanValue1 && cleanValue2) {
|
|
886
|
+
return `${cleanValue1} - ${cleanValue2}`;
|
|
887
|
+
}
|
|
888
|
+
return '';
|
|
889
|
+
// Date operators - format with relative expressions
|
|
890
|
+
case 'has_date_lt':
|
|
891
|
+
case 'has_date_lte':
|
|
892
|
+
if (cleanValue1) {
|
|
893
|
+
// Parse relative date expression (e.g., "today + 5" or "today - 3")
|
|
894
|
+
const match = cleanValue1.match(/^(today)\s*([+-])\s*(\d+)$/i);
|
|
895
|
+
if (match) {
|
|
896
|
+
const [, base, operator, days] = match;
|
|
897
|
+
const dayWord = days === '1' ? 'day' : 'days';
|
|
898
|
+
return `Before ${base} ${operator} ${days} ${dayWord}`;
|
|
899
|
+
}
|
|
900
|
+
// Fallback for other date formats
|
|
901
|
+
return `Before ${cleanValue1}`;
|
|
902
|
+
}
|
|
903
|
+
return '';
|
|
904
|
+
case 'has_date_gt':
|
|
905
|
+
case 'has_date_gte':
|
|
906
|
+
if (cleanValue1) {
|
|
907
|
+
// Parse relative date expression
|
|
908
|
+
const match = cleanValue1.match(/^(today)\s*([+-])\s*(\d+)$/i);
|
|
909
|
+
if (match) {
|
|
910
|
+
const [, base, operator, days] = match;
|
|
911
|
+
const dayWord = days === '1' ? 'day' : 'days';
|
|
912
|
+
return `After ${base} ${operator} ${days} ${dayWord}`;
|
|
913
|
+
}
|
|
914
|
+
// Fallback for other date formats
|
|
915
|
+
return `After ${cleanValue1}`;
|
|
916
|
+
}
|
|
917
|
+
return '';
|
|
918
|
+
case 'has_date_eq':
|
|
919
|
+
if (cleanValue1) {
|
|
920
|
+
// Parse relative date expression
|
|
921
|
+
const match = cleanValue1.match(/^(today)\s*([+-])\s*(\d+)$/i);
|
|
922
|
+
if (match) {
|
|
923
|
+
const [, base, operator, days] = match;
|
|
924
|
+
const dayWord = days === '1' ? 'day' : 'days';
|
|
925
|
+
return `${base} ${operator} ${days} ${dayWord}`;
|
|
926
|
+
}
|
|
927
|
+
return cleanValue1;
|
|
928
|
+
}
|
|
929
|
+
return '';
|
|
930
|
+
default:
|
|
931
|
+
// Fallback - capitalize first value
|
|
932
|
+
return cleanValue1 ? capitalize(cleanValue1) : '';
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
// Helper function to create a rules-based router (used by wait_for_response and split_by_expression)
|
|
936
|
+
export const createRulesRouter = (operand, userRules, getOperatorConfig, existingCategories = [], existingExits = [], existingCases = []) => {
|
|
937
|
+
const categories = [];
|
|
938
|
+
const exits = [];
|
|
939
|
+
const cases = [];
|
|
940
|
+
// Filter existing categories to get only user-defined rules (exclude system categories)
|
|
941
|
+
const existingUserCategories = existingCategories.filter((cat) => !isSystemCategory(cat.name));
|
|
942
|
+
// Track categories as we create them (case-insensitive lookup)
|
|
943
|
+
const createdCategories = new Map();
|
|
944
|
+
// Process rules in their original order to preserve rule order
|
|
945
|
+
userRules.forEach((rule, ruleIndex) => {
|
|
946
|
+
const categoryKey = rule.category.trim().toLowerCase();
|
|
947
|
+
const categoryName = rule.category.trim(); // Use original casing
|
|
948
|
+
let categoryInfo = createdCategories.get(categoryKey);
|
|
949
|
+
if (!categoryInfo) {
|
|
950
|
+
// First time seeing this category - create it
|
|
951
|
+
// Smart category matching: try by name first, then fall back to position
|
|
952
|
+
let existingCategory = existingUserCategories.find((cat) => cat.name.toLowerCase() === categoryKey);
|
|
953
|
+
// If no match by name, try by position (for category rename scenarios)
|
|
954
|
+
const categoryCreationOrder = Array.from(createdCategories.keys()).length;
|
|
955
|
+
if (!existingCategory &&
|
|
956
|
+
categoryCreationOrder < existingUserCategories.length) {
|
|
957
|
+
const candidateCategory = existingUserCategories[categoryCreationOrder];
|
|
958
|
+
// Double-check that this candidate is not a system category UUID
|
|
959
|
+
if (candidateCategory &&
|
|
960
|
+
!isSystemCategoryUuid(candidateCategory.uuid, existingCategories)) {
|
|
961
|
+
existingCategory = candidateCategory;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
const existingExit = existingCategory
|
|
965
|
+
? existingExits.find((exit) => exit.uuid === existingCategory.exit_uuid)
|
|
966
|
+
: null;
|
|
967
|
+
// Generate UUIDs, ensuring we don't reuse system category UUIDs
|
|
968
|
+
let exitUuid = (existingExit === null || existingExit === void 0 ? void 0 : existingExit.uuid) || generateUUID();
|
|
969
|
+
let categoryUuid = (existingCategory === null || existingCategory === void 0 ? void 0 : existingCategory.uuid) || generateUUID();
|
|
970
|
+
// Additional safety check: if somehow we got a system category UUID, generate new ones
|
|
971
|
+
if (isSystemCategoryUuid(categoryUuid, existingCategories)) {
|
|
972
|
+
categoryUuid = generateUUID();
|
|
973
|
+
exitUuid = generateUUID();
|
|
974
|
+
}
|
|
975
|
+
categoryInfo = {
|
|
976
|
+
uuid: categoryUuid,
|
|
977
|
+
name: categoryName,
|
|
978
|
+
exit_uuid: exitUuid
|
|
979
|
+
};
|
|
980
|
+
createdCategories.set(categoryKey, categoryInfo);
|
|
981
|
+
// Add category and exit
|
|
982
|
+
categories.push({
|
|
983
|
+
uuid: categoryUuid,
|
|
984
|
+
name: categoryName,
|
|
985
|
+
exit_uuid: exitUuid
|
|
986
|
+
});
|
|
987
|
+
exits.push({
|
|
988
|
+
uuid: exitUuid,
|
|
989
|
+
destination_uuid: (existingExit === null || existingExit === void 0 ? void 0 : existingExit.destination_uuid) || null
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
// Create case for this rule
|
|
993
|
+
let existingCase = existingCases[ruleIndex];
|
|
994
|
+
// If we can't find by position, try to find by matching rule content
|
|
995
|
+
if (!existingCase && existingCases.length > 0) {
|
|
996
|
+
existingCase = existingCases.find((case_) => {
|
|
997
|
+
// Find the category for this case
|
|
998
|
+
const caseCategory = existingCategories.find((cat) => cat.uuid === case_.category_uuid);
|
|
999
|
+
// Match by operator type and category name
|
|
1000
|
+
return (case_.type === rule.operator &&
|
|
1001
|
+
(caseCategory === null || caseCategory === void 0 ? void 0 : caseCategory.name.toLowerCase()) === categoryKey);
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
const caseUuid = (existingCase === null || existingCase === void 0 ? void 0 : existingCase.uuid) || generateUUID();
|
|
1005
|
+
// Parse rule value based on operator configuration
|
|
1006
|
+
const operatorConfig = getOperatorConfig(rule.operator);
|
|
1007
|
+
let arguments_ = [];
|
|
1008
|
+
if (operatorConfig) {
|
|
1009
|
+
if (operatorConfig.operands === 0) {
|
|
1010
|
+
// No operands needed
|
|
1011
|
+
arguments_ = [];
|
|
1012
|
+
}
|
|
1013
|
+
else if (operatorConfig.operands === 2) {
|
|
1014
|
+
// Split value for two operands (e.g., "1 10" for between)
|
|
1015
|
+
arguments_ = rule.value.split(' ').filter((arg) => arg.trim());
|
|
1016
|
+
}
|
|
1017
|
+
else {
|
|
1018
|
+
// Single operand - but split words for operators that expect multiple words
|
|
1019
|
+
if (rule.value && rule.value.trim()) {
|
|
1020
|
+
// Split on spaces and filter out empty strings
|
|
1021
|
+
arguments_ = rule.value
|
|
1022
|
+
.trim()
|
|
1023
|
+
.split(/\s+/)
|
|
1024
|
+
.filter((arg) => arg.length > 0);
|
|
1025
|
+
}
|
|
1026
|
+
else {
|
|
1027
|
+
arguments_ = [];
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
// Fallback for unknown operators - split on spaces if value exists
|
|
1033
|
+
if (rule.value && rule.value.trim()) {
|
|
1034
|
+
arguments_ = rule.value
|
|
1035
|
+
.trim()
|
|
1036
|
+
.split(/\s+/)
|
|
1037
|
+
.filter((arg) => arg.length > 0);
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
arguments_ = [];
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
cases.push({
|
|
1044
|
+
uuid: caseUuid,
|
|
1045
|
+
type: rule.operator,
|
|
1046
|
+
arguments: arguments_,
|
|
1047
|
+
category_uuid: categoryInfo.uuid
|
|
1048
|
+
});
|
|
1049
|
+
});
|
|
1050
|
+
// Add default category (always present)
|
|
1051
|
+
// Name is "Other" if there are user rules, "All Responses" if there are no user rules
|
|
1052
|
+
const defaultCategoryName = userRules.length > 0 ? 'Other' : 'All Responses';
|
|
1053
|
+
// Try to find existing default category by name (prefer exact match)
|
|
1054
|
+
let existingDefaultCategory = existingCategories.find((cat) => cat.name === defaultCategoryName);
|
|
1055
|
+
// If no exact match, try to find the other possible default category name
|
|
1056
|
+
if (!existingDefaultCategory) {
|
|
1057
|
+
const alternateName = userRules.length > 0 ? 'All Responses' : 'Other';
|
|
1058
|
+
existingDefaultCategory = existingCategories.find((cat) => cat.name === alternateName);
|
|
1059
|
+
}
|
|
1060
|
+
const existingDefaultExit = existingDefaultCategory
|
|
1061
|
+
? existingExits.find((exit) => exit.uuid === existingDefaultCategory.exit_uuid)
|
|
1062
|
+
: null;
|
|
1063
|
+
const defaultExitUuid = (existingDefaultExit === null || existingDefaultExit === void 0 ? void 0 : existingDefaultExit.uuid) || generateUUID();
|
|
1064
|
+
const defaultCategoryUuid = (existingDefaultCategory === null || existingDefaultCategory === void 0 ? void 0 : existingDefaultCategory.uuid) || generateUUID();
|
|
1065
|
+
categories.push({
|
|
1066
|
+
uuid: defaultCategoryUuid,
|
|
1067
|
+
name: defaultCategoryName,
|
|
1068
|
+
exit_uuid: defaultExitUuid
|
|
1069
|
+
});
|
|
1070
|
+
exits.push({
|
|
1071
|
+
uuid: defaultExitUuid,
|
|
1072
|
+
destination_uuid: (existingDefaultExit === null || existingDefaultExit === void 0 ? void 0 : existingDefaultExit.destination_uuid) || null
|
|
1073
|
+
});
|
|
1074
|
+
// Find the default category (either "Other" or "All Responses")
|
|
1075
|
+
const defaultCategory = categories.find((cat) => cat.name === 'Other' || cat.name === 'All Responses');
|
|
1076
|
+
return {
|
|
1077
|
+
router: {
|
|
1078
|
+
type: 'switch',
|
|
1079
|
+
categories: categories,
|
|
1080
|
+
default_category_uuid: defaultCategory === null || defaultCategory === void 0 ? void 0 : defaultCategory.uuid,
|
|
1081
|
+
operand: operand,
|
|
1082
|
+
cases: cases
|
|
1083
|
+
},
|
|
1084
|
+
exits: exits
|
|
1085
|
+
};
|
|
1086
|
+
};
|
|
846
1087
|
export const titleCase = (str) => {
|
|
847
1088
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
848
1089
|
};
|