@nyaruka/temba-components 0.159.4 → 0.159.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/static/svg/index.svg +1 -1
- package/dist/temba-components.js +82 -36
- package/dist/temba-components.js.map +1 -1
- package/package.json +1 -1
- package/src/Icons.ts +3 -1
- package/src/flow/Editor.ts +201 -1
- package/src/flow/EditorToolbar.ts +24 -0
- package/src/interfaces.ts +6 -2
- package/src/list/ContentList.ts +99 -28
- package/src/list/FlowList.ts +7 -15
- package/src/live/ContactFields.ts +35 -5
- package/static/svg/index.svg +1 -1
- package/static/svg/work/traced/shuffle-01.svg +1 -0
- package/static/svg/work/traced/switch-horizontal-01.svg +1 -0
- package/static/svg/work/used/shuffle-01.svg +3 -0
- package/static/svg/work/used/switch-horizontal-01.svg +3 -0
package/dist/temba-components.js
CHANGED
|
@@ -353,7 +353,7 @@ const Ke=1,Ge=2,Xe=t=>(...e)=>({_$litDirective$:t,values:e});let Qe=class{constr
|
|
|
353
353
|
</div>
|
|
354
354
|
`:null}
|
|
355
355
|
</div>
|
|
356
|
-
`}render(){return this.renderField()}}zo.formAssociated=!0,i([ft({type:String})],zo.prototype,"name",void 0),i([ft({type:String,attribute:"help_text"})],zo.prototype,"helpText",void 0),i([ft({type:Boolean,attribute:"widget_only"})],zo.prototype,"widgetOnly",void 0),i([ft({type:Array})],zo.prototype,"errors",void 0),i([ft({type:String})],zo.prototype,"value",null),i([ft({attribute:!1})],zo.prototype,"inputRoot",void 0),i([ft({type:Boolean})],zo.prototype,"disabled",void 0),i([ft({type:Boolean})],zo.prototype,"hideErrors",void 0),i([ft({type:Boolean,attribute:"hide_label"})],zo.prototype,"hideLabel",void 0),i([ft({type:String})],zo.prototype,"label",void 0);var Io;!function(t){t.ai="stars-02",t.alert_warning="alert-square",t.account="user-01",t.action="lightning-02",t.active="play",t.add="plus",t.add_note="file-02",t.airtime="bank-note-01",t.analytics="bar-chart-01",t.archive="archive",t.arrow_up="chevron-up",t.arrow_down="chevron-down",t.arrow_left="chevron-left",t.arrow_right="chevron-right",t.attachment="paperclip",t.attachment_audio="volume-min",t.attachment_document="file-06",t.attachment_image="image-01",t.attachment_location="marker-pin-01",t.attachment_video="video-recorder",t.branding="brush-02",t.branding_hostname="server-05",t.branding_notifications="mail-01",t.branding_styling="palette",t.branding_raw="pencil-01",t.broadcast="announcement-01",t.call="phone-call-01",t.call_missed="phone-call-02",t.campaign="clock-refresh",t.campaign_active="play",t.campaign_archived="archive",t.campaigns="clock-refresh",t.channel="zap",t.children="git-branch-01",t.check="check",t.checkbox="square",t.checkbox_checked="check-square",t.checkbox_partial="stop-square",t.close="x",t.compose="send-01",t.contact="user-01",t.contact_archived="archive",t.contact_blocked="message-x-square",t.contact_export="download-cloud-01",t.contact_import="upload-cloud-01",t.contact_stopped="slash-octagon",t.contact_updated="user-edit",t.contacts="user-01",t.copy="copy-04",t.dashboard="pie-chart-01",t.definitions_export="download-cloud-01",t.delete="trash-03",t.delete_small="x",t.down="chevron-down",t.down_double="chevron-down-double",t.download="download-01",t.drag="dots-grid",t.edit="edit-02",t.email="mail-01",t.error="alert-circle",t.event="zap",t.export="download-cloud-01",t.expressions="at-sign",t.fields="user-edit",t.filter="filter-funnel-01",t.flow="flow",t.flow_background="layers-two-01",t.flow_interrupted="x-close",t.flow_ivr="phone",t.flow_message="message-square-02",t.flow_surveyor="tablet-01",t.flow_user="hard-drive",t.flows="flow",t.follow="route",t.global="at-sign",t.grid="dots-grid",t.group="users-01",t.group_exclude="users-x",t.group_include="users-check",t.group_smart="atom-01",t.help="help-circle",t.hide="eye-off",t.home="settings-02",t.image="image-01",t.import="upload-cloud-01",t.inbox="inbox-01",t.incidents="alert-square",t.incoming_call="phone-incoming-01",t.info="user-square",t.integrations="layers-three-01",t.invitations="user-plus-01",t.issue="alert-square",t.label="tag-01",t.language="translate-01",t.link="link-external-01",t.location="marker-pin-01",t.log="file-02",t.logout="log-out-04",t.menu="menu-01",t.menu_collapse="chevron-left-double",t.message="message-square-02",t.message_export="download-cloud-01",t.messages="message-square-02",t.missing="maximize-02",t.missed_call="phone-x",t.new="plus",t.next_schedule="alarm-clock",t.note="edit-03",t.notes="edit-03",t.notification="bell-01",t.number="hash-01",t.optin_requested="message-notification-circle",t.optin="message-check-circle",t.optout="message-x-circle",t.org_active="credit-card-02",t.org_anonymous="glasses-01",t.org_bulk="credit-card-plus",t.org_flagged="flag-01",t.org_new="stars-02",t.org_suspended="slash-circle-01",t.org_verified="check-verified-02",t.overview="pie-chart-01",t.prometheus="prometheus",t.progress_spinner="refresh-cw-04",t.refresh="refresh-cw-05",t.featured="star-01",t.quick_replies="dotpoints-01",t.recording="microphone-01",t.resend="refresh-cw-05",t.reset="flip-backward",t.resthooks="share-07",t.restore="play",t.restore_messages="inbox-01",t.results_export="download-cloud-01",t.retry="refresh-cw-05",t.revisions="clock-rewind",t.rocketchat="rocketchat",t.runs="rows-03",t.schedule="calendar",t.search="search-refraction",t.select_open="chevron-down",t.select_clear="x",t.send="send-03",t.service="magic-wand-01",t.service_end="log-out-04",t.settings="settings-02",t.shortcut="zap-fast",t.show="eye",t.simulator="phone-02",t.split="flow",t.sort="chevron-selector-vertical",t.sort_down="sort-arrow-down",t.sort_up="sort-arrow-up",t.staff="hard-drive",t.submit="check",t.success="check",t.template_approved="check-circle",t.template_pending="hourglass-01",t.template_rejected="alert-circle",t.tickets="agent",t.tickets_all="archive",t.tickets_closed="check",t.tickets_mine="coffee",t.tickets_mine_done="coffee-empty",t.tickets_open="inbox-01",t.tickets_export="download-cloud-01",t.tickets_unassigned="inbox-01",t.topic="message-text-circle-02",t.two_factor_enabled="shield-02",t.two_factor_disabled="shield-01",t.trigger="signal-01",t.trigger_active="play",t.trigger_archived="archive",t.trigger_new="plus",t.trigger_keyword="message-check-square",t.trigger_catch_all="message-question-square",t.trigger_inbound_call="phone-incoming-01",t.trigger_missed_call="phone-hang-up",t.trigger_schedule="calendar",t.trigger_new_conversation="message-chat-square",t.trigger_referral="user-right-01",t.trigger_closed_ticket="agent",t.trigger_opt_in="message-check-circle",t.trigger_opt_out="message-x-circle",t.triggers="signal-01",t.updated="edit-02",t.up="chevron-up",t.up_double="chevron-up-double",t.upload="upload-cloud-01",t.upload_image="camera-01",t.usages="link-04",t.user="users-01",t.user_beta="shield-zap",t.user_token="key-01",t.users="users-01",t.video="video-recorder",t.webhook="link-external-01",t.workspace="folder",t.zoom_fit="maximize-02",t.zoom_in="expand-06",t.channel_a="channel-android",t.channel_ac="zap",t.channel_at="zap",t.channel_bs="zap",t.channel_bw="zap",t.channel_cs="zap",t.channel_ct="channel-clickatell",t.channel_d3="channel-whatsapp",t.channel_d3c="channel-whatsapp",t.channel_da="zap",t.channel_ds="channel-discord",t.channel_ex="zap",t.channel_fb="channel-facebook",t.channel_fba="channel-facebook",t.channel_fc="channel-freshchat",t.channel_fcm="channel-firebase",t.channel_hm="zap",t.channel_ib="zap",t.channel_ig="channel-instagram",t.channel_jc="channel-jiochat",t.channel_kn="channel-kannel",t.channel_kwa="channel-whatsapp",t.channel_ln="channel-line",t.channel_mt="channel-mtarget",t.channel_mtn="zap",t.channel_nx="channel-vonage",t.channel_pl="channel-plivo",t.channel_rc="channel-rocketchat",t.channel_sl="channel-slack",t.channel_sq="zap",t.channel_st="zap",t.channel_sw="channel-signalwire",t.channel_t="channel-twilio",t.channel_tg="channel-telegram",t.channel_tms="channel-twilio",t.channel_tq="channel-thinq",t.channel_tw="zap",t.channel_twa="channel-whatsapp",t.channel_twc="zap",t.channel_twt="channel-twitter",t.channel_vk="channel-vk",t.channel_vp="channel-viber",t.channel_wa="channel-whatsapp",t.channel_wac="channel-whatsapp",t.channel_wc="channel-wechat",t.channel_yo="zap",t.channel_zvw="channel-whatsapp",t.ai_openai="openai",t.ai_anthropic="anthropic",t.ai_google="gemini",t.ai_microsoft="azure",t.ai_deepseek="deepseek",t.classifier_wit="classifier-wit",t.dtone="dtone",t.zapier="zapier",t.default="list",t.datepicker="calendar",t.slider="sliders-02",t.select="browser",t.input="edit-05"}(Io||(Io={}));class Lo extends zo{constructor(){super(...arguments),this.name="",this.disabled=!1,this.busy=!1,this.size=1.2,this.animateChange="pulse",this.initialized=!1}static get styles(){return d`
|
|
356
|
+
`}render(){return this.renderField()}}zo.formAssociated=!0,i([ft({type:String})],zo.prototype,"name",void 0),i([ft({type:String,attribute:"help_text"})],zo.prototype,"helpText",void 0),i([ft({type:Boolean,attribute:"widget_only"})],zo.prototype,"widgetOnly",void 0),i([ft({type:Array})],zo.prototype,"errors",void 0),i([ft({type:String})],zo.prototype,"value",null),i([ft({attribute:!1})],zo.prototype,"inputRoot",void 0),i([ft({type:Boolean})],zo.prototype,"disabled",void 0),i([ft({type:Boolean})],zo.prototype,"hideErrors",void 0),i([ft({type:Boolean,attribute:"hide_label"})],zo.prototype,"hideLabel",void 0),i([ft({type:String})],zo.prototype,"label",void 0);var Io;!function(t){t.ai="stars-02",t.alert_warning="alert-square",t.account="user-01",t.action="lightning-02",t.active="play",t.add="plus",t.add_note="file-02",t.airtime="bank-note-01",t.analytics="bar-chart-01",t.archive="archive",t.arrow_up="chevron-up",t.arrow_down="chevron-down",t.arrow_left="chevron-left",t.arrow_right="chevron-right",t.attachment="paperclip",t.attachment_audio="volume-min",t.attachment_document="file-06",t.attachment_image="image-01",t.attachment_location="marker-pin-01",t.attachment_video="video-recorder",t.branding="brush-02",t.branding_hostname="server-05",t.branding_notifications="mail-01",t.branding_styling="palette",t.branding_raw="pencil-01",t.broadcast="announcement-01",t.call="phone-call-01",t.call_missed="phone-call-02",t.campaign="clock-refresh",t.campaign_active="play",t.campaign_archived="archive",t.campaigns="clock-refresh",t.channel="zap",t.children="git-branch-01",t.check="check",t.checkbox="square",t.checkbox_checked="check-square",t.checkbox_partial="stop-square",t.close="x",t.compose="send-01",t.contact="user-01",t.contact_archived="archive",t.contact_blocked="message-x-square",t.contact_export="download-cloud-01",t.contact_import="upload-cloud-01",t.contact_stopped="slash-octagon",t.contact_updated="user-edit",t.contacts="user-01",t.copy="copy-04",t.dashboard="pie-chart-01",t.definitions_export="download-cloud-01",t.delete="trash-03",t.delete_small="x",t.down="chevron-down",t.down_double="chevron-down-double",t.download="download-01",t.drag="dots-grid",t.edit="edit-02",t.email="mail-01",t.error="alert-circle",t.event="zap",t.export="download-cloud-01",t.expressions="at-sign",t.fields="user-edit",t.filter="filter-funnel-01",t.flow="flow",t.flow_background="layers-two-01",t.flow_interrupted="x-close",t.flow_ivr="phone",t.flow_message="message-square-02",t.flow_surveyor="tablet-01",t.flow_user="hard-drive",t.flows="flow",t.follow="route",t.global="at-sign",t.grid="dots-grid",t.group="users-01",t.group_exclude="users-x",t.group_include="users-check",t.group_smart="atom-01",t.help="help-circle",t.hide="eye-off",t.home="settings-02",t.image="image-01",t.import="upload-cloud-01",t.inbox="inbox-01",t.incidents="alert-square",t.incoming_call="phone-incoming-01",t.info="user-square",t.integrations="layers-three-01",t.invitations="user-plus-01",t.issue="alert-square",t.label="tag-01",t.language="translate-01",t.language_default="switch-horizontal-01",t.link="link-external-01",t.location="marker-pin-01",t.shuffle="shuffle-01",t.log="file-02",t.logout="log-out-04",t.menu="menu-01",t.menu_collapse="chevron-left-double",t.message="message-square-02",t.message_export="download-cloud-01",t.messages="message-square-02",t.missing="maximize-02",t.missed_call="phone-x",t.new="plus",t.next_schedule="alarm-clock",t.note="edit-03",t.notes="edit-03",t.notification="bell-01",t.number="hash-01",t.optin_requested="message-notification-circle",t.optin="message-check-circle",t.optout="message-x-circle",t.org_active="credit-card-02",t.org_anonymous="glasses-01",t.org_bulk="credit-card-plus",t.org_flagged="flag-01",t.org_new="stars-02",t.org_suspended="slash-circle-01",t.org_verified="check-verified-02",t.overview="pie-chart-01",t.prometheus="prometheus",t.progress_spinner="refresh-cw-04",t.refresh="refresh-cw-05",t.featured="star-01",t.quick_replies="dotpoints-01",t.recording="microphone-01",t.resend="refresh-cw-05",t.reset="flip-backward",t.resthooks="share-07",t.restore="play",t.restore_messages="inbox-01",t.results_export="download-cloud-01",t.retry="refresh-cw-05",t.revisions="clock-rewind",t.rocketchat="rocketchat",t.runs="rows-03",t.schedule="calendar",t.search="search-refraction",t.select_open="chevron-down",t.select_clear="x",t.send="send-03",t.service="magic-wand-01",t.service_end="log-out-04",t.settings="settings-02",t.shortcut="zap-fast",t.show="eye",t.simulator="phone-02",t.split="flow",t.sort="chevron-selector-vertical",t.sort_down="sort-arrow-down",t.sort_up="sort-arrow-up",t.staff="hard-drive",t.submit="check",t.success="check",t.template_approved="check-circle",t.template_pending="hourglass-01",t.template_rejected="alert-circle",t.tickets="agent",t.tickets_all="archive",t.tickets_closed="check",t.tickets_mine="coffee",t.tickets_mine_done="coffee-empty",t.tickets_open="inbox-01",t.tickets_export="download-cloud-01",t.tickets_unassigned="inbox-01",t.topic="message-text-circle-02",t.two_factor_enabled="shield-02",t.two_factor_disabled="shield-01",t.trigger="signal-01",t.trigger_active="play",t.trigger_archived="archive",t.trigger_new="plus",t.trigger_keyword="message-check-square",t.trigger_catch_all="message-question-square",t.trigger_inbound_call="phone-incoming-01",t.trigger_missed_call="phone-hang-up",t.trigger_schedule="calendar",t.trigger_new_conversation="message-chat-square",t.trigger_referral="user-right-01",t.trigger_closed_ticket="agent",t.trigger_opt_in="message-check-circle",t.trigger_opt_out="message-x-circle",t.triggers="signal-01",t.updated="edit-02",t.up="chevron-up",t.up_double="chevron-up-double",t.upload="upload-cloud-01",t.upload_image="camera-01",t.usages="link-04",t.user="users-01",t.user_beta="shield-zap",t.user_token="key-01",t.users="users-01",t.video="video-recorder",t.webhook="link-external-01",t.workspace="folder",t.zoom_fit="maximize-02",t.zoom_in="expand-06",t.channel_a="channel-android",t.channel_ac="zap",t.channel_at="zap",t.channel_bs="zap",t.channel_bw="zap",t.channel_cs="zap",t.channel_ct="channel-clickatell",t.channel_d3="channel-whatsapp",t.channel_d3c="channel-whatsapp",t.channel_da="zap",t.channel_ds="channel-discord",t.channel_ex="zap",t.channel_fb="channel-facebook",t.channel_fba="channel-facebook",t.channel_fc="channel-freshchat",t.channel_fcm="channel-firebase",t.channel_hm="zap",t.channel_ib="zap",t.channel_ig="channel-instagram",t.channel_jc="channel-jiochat",t.channel_kn="channel-kannel",t.channel_kwa="channel-whatsapp",t.channel_ln="channel-line",t.channel_mt="channel-mtarget",t.channel_mtn="zap",t.channel_nx="channel-vonage",t.channel_pl="channel-plivo",t.channel_rc="channel-rocketchat",t.channel_sl="channel-slack",t.channel_sq="zap",t.channel_st="zap",t.channel_sw="channel-signalwire",t.channel_t="channel-twilio",t.channel_tg="channel-telegram",t.channel_tms="channel-twilio",t.channel_tq="channel-thinq",t.channel_tw="zap",t.channel_twa="channel-whatsapp",t.channel_twc="zap",t.channel_twt="channel-twitter",t.channel_vk="channel-vk",t.channel_vp="channel-viber",t.channel_wa="channel-whatsapp",t.channel_wac="channel-whatsapp",t.channel_wc="channel-wechat",t.channel_yo="zap",t.channel_zvw="channel-whatsapp",t.ai_openai="openai",t.ai_anthropic="anthropic",t.ai_google="gemini",t.ai_microsoft="azure",t.ai_deepseek="deepseek",t.classifier_wit="classifier-wit",t.dtone="dtone",t.zapier="zapier",t.default="list",t.datepicker="calendar",t.slider="sliders-02",t.select="browser",t.input="edit-05"}(Io||(Io={}));class Lo extends zo{constructor(){super(...arguments),this.name="",this.disabled=!1,this.busy=!1,this.size=1.2,this.animateChange="pulse",this.initialized=!1}static get styles(){return d`
|
|
357
357
|
${super.styles}
|
|
358
358
|
|
|
359
359
|
:host {
|
|
@@ -698,7 +698,7 @@ const Oo=t=>t??K,Po="important",Ro=" !"+Po,No=Xe(class extends Qe{constructor(t)
|
|
|
698
698
|
>
|
|
699
699
|
<slot></slot>
|
|
700
700
|
</div>
|
|
701
|
-
`}}i([ft({type:Boolean})],Ho.prototype,"textarea",void 0),i([ft({type:String})],Ho.prototype,"placeholder",void 0),i([ft({type:Boolean})],Ho.prototype,"password",void 0),i([ft({type:Number})],Ho.prototype,"maxlength",void 0),i([ft({type:Boolean})],Ho.prototype,"clearable",void 0),i([ft({type:Boolean})],Ho.prototype,"gsm",void 0),i([ft({type:String})],Ho.prototype,"counter",void 0),i([ft({type:Boolean})],Ho.prototype,"loading",void 0),i([ft({type:Boolean})],Ho.prototype,"submitOnEnter",void 0),i([ft()],Ho.prototype,"onBlur",void 0),i([ft({type:Boolean})],Ho.prototype,"autogrow",void 0),i([ft({type:String})],Ho.prototype,"type",void 0),i([ft({type:String})],Ho.prototype,"flavor",void 0),function(t){t.DayFirst="day_first",t.MonthFirst="month_first",t.YearFirst="year_first"}(Fo||(Fo={})),function(t){t.CampaignEvent="campaign_event",t.ScheduledBroadcast="scheduled_broadcast",t.ScheduledTrigger="scheduled_trigger",t.SentBroadcast="sent_broadcast"}(qo||(qo={})),function(t){t.Open="open",t.Closed="closed"}(Uo||(Uo={})),function(t){t.Loaded="temba-loaded",t.Loading="temba-loading",t.Canceled="temba-canceled",t.CursorChanged="temba-cursor-changed",t.Refreshed="temba-refreshed",t.Selection="temba-selection",t.ButtonClicked="temba-button-clicked",t.DialogHidden="temba-dialog-hidden",t.ScrollThreshold="temba-scroll-threshold",t.ScrollThresholdBottom="temba-scroll-threshold-bottom",t.ContentChanged="temba-content-changed",t.ContextChanged="temba-context-changed",t.FetchComplete="temba-fetch-complete",t.MessageSent="temba-message-sent",t.Submitted="temba-submitted",t.Redirected="temba-redirected",t.NoPath="temba-no-path",t.StoreUpdated="temba-store-updated",t.Ready="temba-ready",t.OrderChanged="temba-order-changed",t.DragStart="temba-drag-start",t.DragStop="temba-drag-stop",t.DragExternal="temba-drag-external",t.DragInternal="temba-drag-internal",t.Resized="temba-resized",t.DetailsChanged="temba-details-changed",t.Error="temba-error",t.Interrupt="temba-interrupt",t.Opened="temba-opened",t.TicketUpdated="temba-ticket-updated",t.Moved="temba-moved",t.DateRangeChanged="temba-date-range-changed",t.NodeDeleted="temba-node-deleted",t.StickyNoteDeleted="temba-sticky-note-deleted",t.ActionEditRequested="temba-action-edit-requested",t.AddActionRequested="temba-add-action-requested",t.ActionSaved="temba-action-saved",t.ActionEditCanceled="temba-action-edit-canceled",t.NodeEditRequested="temba-node-edit-requested",t.NodeSaved="temba-node-saved",t.NodeEditCancelled="temba-node-edit-cancelled",t.FollowSimulation="temba-follow-simulation",t.ContactClicked="temba-contact-clicked",t.FlowClicked="temba-flow-clicked",t.GroupClicked="temba-group-clicked",t.ShowIssue="temba-show-issue",t.SizeChanged="temba-size-changed",t.IssueSelected="temba-issue-selected",t.IssuesClosed="temba-issues-closed",t.IssuesTabClicked="temba-issues-tab-clicked",t.RevisionViewed="temba-revision-viewed",t.RevisionCancelled="temba-revision-cancelled",t.RevisionReverted="temba-revision-reverted",t.RevisionsClosed="temba-revisions-closed",t.RowClick="temba-row-click",t.SelectionChange="temba-selection-change",t.BulkAction="temba-bulk-action",t.HistoryChange="temba-history-change"}(jo||(jo={}));
|
|
701
|
+
`}}i([ft({type:Boolean})],Ho.prototype,"textarea",void 0),i([ft({type:String})],Ho.prototype,"placeholder",void 0),i([ft({type:Boolean})],Ho.prototype,"password",void 0),i([ft({type:Number})],Ho.prototype,"maxlength",void 0),i([ft({type:Boolean})],Ho.prototype,"clearable",void 0),i([ft({type:Boolean})],Ho.prototype,"gsm",void 0),i([ft({type:String})],Ho.prototype,"counter",void 0),i([ft({type:Boolean})],Ho.prototype,"loading",void 0),i([ft({type:Boolean})],Ho.prototype,"submitOnEnter",void 0),i([ft()],Ho.prototype,"onBlur",void 0),i([ft({type:Boolean})],Ho.prototype,"autogrow",void 0),i([ft({type:String})],Ho.prototype,"type",void 0),i([ft({type:String})],Ho.prototype,"flavor",void 0),function(t){t.DayFirst="day_first",t.MonthFirst="month_first",t.YearFirst="year_first"}(Fo||(Fo={})),function(t){t.CampaignEvent="campaign_event",t.ScheduledBroadcast="scheduled_broadcast",t.ScheduledTrigger="scheduled_trigger",t.SentBroadcast="sent_broadcast"}(qo||(qo={})),function(t){t.Open="open",t.Closed="closed"}(Uo||(Uo={})),function(t){t.Loaded="temba-loaded",t.Loading="temba-loading",t.Canceled="temba-canceled",t.CursorChanged="temba-cursor-changed",t.Refreshed="temba-refreshed",t.Selection="temba-selection",t.ButtonClicked="temba-button-clicked",t.DialogHidden="temba-dialog-hidden",t.ScrollThreshold="temba-scroll-threshold",t.ScrollThresholdBottom="temba-scroll-threshold-bottom",t.ContentChanged="temba-content-changed",t.ContextChanged="temba-context-changed",t.FetchComplete="temba-fetch-complete",t.MessageSent="temba-message-sent",t.Submitted="temba-submitted",t.Redirected="temba-redirected",t.NoPath="temba-no-path",t.StoreUpdated="temba-store-updated",t.Ready="temba-ready",t.OrderChanged="temba-order-changed",t.DragStart="temba-drag-start",t.DragStop="temba-drag-stop",t.DragExternal="temba-drag-external",t.DragInternal="temba-drag-internal",t.Resized="temba-resized",t.DetailsChanged="temba-details-changed",t.Error="temba-error",t.Interrupt="temba-interrupt",t.Opened="temba-opened",t.TicketUpdated="temba-ticket-updated",t.Moved="temba-moved",t.DateRangeChanged="temba-date-range-changed",t.NodeDeleted="temba-node-deleted",t.StickyNoteDeleted="temba-sticky-note-deleted",t.ActionEditRequested="temba-action-edit-requested",t.AddActionRequested="temba-add-action-requested",t.ActionSaved="temba-action-saved",t.ActionEditCanceled="temba-action-edit-canceled",t.NodeEditRequested="temba-node-edit-requested",t.NodeSaved="temba-node-saved",t.NodeEditCancelled="temba-node-edit-cancelled",t.FollowSimulation="temba-follow-simulation",t.ContactClicked="temba-contact-clicked",t.FlowClicked="temba-flow-clicked",t.GroupClicked="temba-group-clicked",t.ShowIssue="temba-show-issue",t.SizeChanged="temba-size-changed",t.IssueSelected="temba-issue-selected",t.IssuesClosed="temba-issues-closed",t.IssuesTabClicked="temba-issues-tab-clicked",t.RevisionViewed="temba-revision-viewed",t.RevisionCancelled="temba-revision-cancelled",t.RevisionReverted="temba-revision-reverted",t.RevisionsClosed="temba-revisions-closed",t.RowClick="temba-row-click",t.SelectionChange="temba-selection-change",t.BulkAction="temba-bulk-action",t.LabelCreate="temba-label-create",t.HistoryChange="temba-history-change"}(jo||(jo={}));
|
|
702
702
|
/**
|
|
703
703
|
* tiny-lru
|
|
704
704
|
*
|
|
@@ -4696,7 +4696,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
4696
4696
|
class="${fe({sheet:""===this.src,[this.animateChange]:!!this.animateChange,[this.animateChange+"-"+this.animationStep]:this.animationStep>0,[this.animateClick]:!!this.animateClick,[this.animateClick+"-"+this.animationStep]:this.animationStep>0})}"
|
|
4697
4697
|
>
|
|
4698
4698
|
<use
|
|
4699
|
-
href="${this.src?this.src:`${this.prefix||window.static_url||"/static/"}svg/index.svg?v=
|
|
4699
|
+
href="${this.src?this.src:`${this.prefix||window.static_url||"/static/"}svg/index.svg?v=45268f1573f1e352c7d62232863725bb#${t}`}"
|
|
4700
4700
|
/>
|
|
4701
4701
|
</svg>
|
|
4702
4702
|
</div>
|
|
@@ -6151,7 +6151,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
6151
6151
|
height="${this.size}em"
|
|
6152
6152
|
src="${this.prefix||window.static_url||"/static/"}img/schemes/${t}.svg"
|
|
6153
6153
|
/>
|
|
6154
|
-
`}}i([ft({type:String})],eu.prototype,"urn",void 0),i([ft({type:String})],eu.prototype,"scheme",void 0),i([ft({type:Number})],eu.prototype,"size",void 0);class iu extends nh{constructor(){super(...arguments),this.disabled=!1}static get styles(){return d`
|
|
6154
|
+
`}}i([ft({type:String})],eu.prototype,"urn",void 0),i([ft({type:String})],eu.prototype,"scheme",void 0),i([ft({type:Number})],eu.prototype,"size",void 0);class iu extends nh{constructor(){super(...arguments),this.disabled=!1,this.fieldsReady=!1}static get styles(){return d`
|
|
6155
6155
|
.field {
|
|
6156
6156
|
display: flex;
|
|
6157
6157
|
margin: 1em 0.3em;
|
|
@@ -6208,7 +6208,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
6208
6208
|
.disabled .toggle {
|
|
6209
6209
|
display: none;
|
|
6210
6210
|
}
|
|
6211
|
-
`}connectedCallback(){super.connectedCallback(),this.handleFieldChanged=this.handleFieldChanged.bind(this)}isAgent(){return"T"===this.role}willUpdate(t){super.willUpdate(t),t.has("data")&&this.data&&Object.keys(this.data.fields).length<=10&&(this.showAll=!0)}updated(t){super.updated(t),t.has("data")&&this.data&&this.fireCustomEvent(jo.DetailsChanged,{count:Object.values(this.data.fields).filter(t=>!!t).length})}handleFieldChanged(t){const e=t.currentTarget,i=e.value;_e("/api/v2/contacts.json?uuid="+this.data.uuid,{fields:{[e.key]:i}}).then(t=>{e.handleResponse(t),this.setContact(t.json)}).catch(t=>{e.handleResponse(t)})}handleToggle(t){const e=t.currentTarget;this.showAll=e.checked}render(){if(this.data){const t=Object.entries(this.data.fields).sort((t,e)=>{const[i]=t,[o]=e,n=this.store.getContactField(i),s=this.store.getContactField(o);if("ward"===n.type)return 1;if("ward"===s.type)return-1;if("district"===n.type&&"ward"!==s.type&&"district"!==s.type)return 1;if("district"===s.type&&"ward"!==n.type&&"district"!==n.type)return-1;if("state"===n.type&&"ward"!==s.type&&"district"!==s.type&&"state"!==s.type)return 1;if("state"===s.type&&"ward"!==n.type&&"district"!==n.type&&"state"!==n.type)return-1;if(n.featured&&!s.featured)return-1;if(s.featured&&!n.featured)return 1;const r=s.priority-n.priority;return 0!==r?r:i.localeCompare(o)});if(0==t.length)return Z`<slot name="empty"></slot>`;const e=t.map(t=>{const[e,i]=t,o=this.store.getContactField(e);return Z`<temba-contact-field
|
|
6211
|
+
`}connectedCallback(){super.connectedCallback(),this.handleFieldChanged=this.handleFieldChanged.bind(this),this.fieldsReady=!!this.store&&(this.store.ready||(this.store.getKeyedAssets().fields||[]).length>0)}storeUpdated(t){super.storeUpdated(t),this.store&&t.detail.url===this.store.fieldsEndpoint&&(this.fieldsReady=!0)}isAgent(){return"T"===this.role}willUpdate(t){super.willUpdate(t),t.has("data")&&this.data&&Object.keys(this.data.fields).length<=10&&(this.showAll=!0)}updated(t){super.updated(t),t.has("data")&&this.data&&this.fireCustomEvent(jo.DetailsChanged,{count:Object.values(this.data.fields).filter(t=>!!t).length})}handleFieldChanged(t){const e=t.currentTarget,i=e.value;_e("/api/v2/contacts.json?uuid="+this.data.uuid,{fields:{[e.key]:i}}).then(t=>{e.handleResponse(t),this.setContact(t.json)}).catch(t=>{e.handleResponse(t)})}handleToggle(t){const e=t.currentTarget;this.showAll=e.checked}render(){if(this.data&&this.fieldsReady){const t=Object.entries(this.data.fields).filter(([t])=>!!this.store.getContactField(t)).sort((t,e)=>{const[i]=t,[o]=e,n=this.store.getContactField(i),s=this.store.getContactField(o);if("ward"===n.type)return 1;if("ward"===s.type)return-1;if("district"===n.type&&"ward"!==s.type&&"district"!==s.type)return 1;if("district"===s.type&&"ward"!==n.type&&"district"!==n.type)return-1;if("state"===n.type&&"ward"!==s.type&&"district"!==s.type&&"state"!==s.type)return 1;if("state"===s.type&&"ward"!==n.type&&"district"!==n.type&&"state"!==n.type)return-1;if(n.featured&&!s.featured)return-1;if(s.featured&&!n.featured)return 1;const r=s.priority-n.priority;return 0!==r?r:i.localeCompare(o)});if(0==t.length)return Z`<slot name="empty"></slot>`;const e=t.map(t=>{const[e,i]=t,o=this.store.getContactField(e);return Z`<temba-contact-field
|
|
6212
6212
|
class=${fe({set:!!i,unset:!i,featured:o.featured})}
|
|
6213
6213
|
key=${o.key}
|
|
6214
6214
|
name=${o.label}
|
|
@@ -6231,7 +6231,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
6231
6231
|
</div>
|
|
6232
6232
|
</div>`:null}
|
|
6233
6233
|
</div>
|
|
6234
|
-
`}return super.render()}}var ou;i([ft({type:Boolean})],iu.prototype,"system",void 0),i([ft({type:Boolean})],iu.prototype,"dirty",void 0),i([ft({type:Boolean})],iu.prototype,"showAll",void 0),i([ft({type:String})],iu.prototype,"timezone",void 0),i([ft({type:String})],iu.prototype,"role",void 0),i([ft({type:Boolean})],iu.prototype,"disabled",void 0),function(t){t.Success="success",t.Failure="failure",t.Saving="saving",t.Ready="ready"}(ou||(ou={}));class nu extends Ye{constructor(){super(...arguments),this.icon=navigator.clipboard?Io.copy:"",this.iconClass="",this.status=ou.Ready,this.disabled=!1,this.dirty=!1}static get styles(){return d`
|
|
6234
|
+
`}return super.render()}}var ou;i([ft({type:Boolean})],iu.prototype,"system",void 0),i([ft({type:Boolean})],iu.prototype,"dirty",void 0),i([ft({type:Boolean})],iu.prototype,"showAll",void 0),i([ft({type:String})],iu.prototype,"timezone",void 0),i([ft({type:String})],iu.prototype,"role",void 0),i([ft({type:Boolean})],iu.prototype,"disabled",void 0),i([ft({type:Boolean,attribute:!1})],iu.prototype,"fieldsReady",void 0),function(t){t.Success="success",t.Failure="failure",t.Saving="saving",t.Ready="ready"}(ou||(ou={}));class nu extends Ye{constructor(){super(...arguments),this.icon=navigator.clipboard?Io.copy:"",this.iconClass="",this.status=ou.Ready,this.disabled=!1,this.dirty=!1}static get styles(){return d`
|
|
6235
6235
|
:host {
|
|
6236
6236
|
--transition-speed: 0ms;
|
|
6237
6237
|
margin-bottom: 1em;
|
|
@@ -8719,6 +8719,33 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
8719
8719
|
color: var(--text-3);
|
|
8720
8720
|
font-size: 12.5px;
|
|
8721
8721
|
}
|
|
8722
|
+
/* "New Label…" creation row — separated from the toggle rows
|
|
8723
|
+
above it (mirrors the legacy dropdown's add-label row). */
|
|
8724
|
+
.lbl-create {
|
|
8725
|
+
border-top: 1px solid var(--border-1);
|
|
8726
|
+
margin-top: 4px;
|
|
8727
|
+
padding: 10px 12px 6px;
|
|
8728
|
+
cursor: pointer;
|
|
8729
|
+
color: var(--text-2);
|
|
8730
|
+
border-radius: var(--r-sm);
|
|
8731
|
+
}
|
|
8732
|
+
.lbl-create:hover {
|
|
8733
|
+
background: var(--accent-50);
|
|
8734
|
+
color: var(--text-1);
|
|
8735
|
+
}
|
|
8736
|
+
/* Blocked while a label-toggle POST is in flight, matching the
|
|
8737
|
+
treatment of the label rows above. */
|
|
8738
|
+
.lbl-create.blocked,
|
|
8739
|
+
.lbl-create.blocked:hover {
|
|
8740
|
+
cursor: not-allowed;
|
|
8741
|
+
background: transparent;
|
|
8742
|
+
color: var(--text-3);
|
|
8743
|
+
}
|
|
8744
|
+
.lbl-create:first-child {
|
|
8745
|
+
border-top: none;
|
|
8746
|
+
margin-top: 0;
|
|
8747
|
+
padding-top: 6px;
|
|
8748
|
+
}
|
|
8722
8749
|
.lbl-menu {
|
|
8723
8750
|
display: flex;
|
|
8724
8751
|
align-items: center;
|
|
@@ -9329,14 +9356,12 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9329
9356
|
color: var(--accent-700);
|
|
9330
9357
|
}
|
|
9331
9358
|
|
|
9332
|
-
/* Leading entity-type icon — a small icon
|
|
9333
|
-
|
|
9359
|
+
/* Leading entity-type icon — a small icon flagging a row (contact
|
|
9360
|
+
silhouette, voice/background flow, etc.). It rides inside the
|
|
9334
9361
|
first column's cell rather than in its own column, so the column
|
|
9335
|
-
header aligns with the
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
{@link getRowIcon}; when it returns null for every row no space
|
|
9339
|
-
is reserved (see {@link reservesIcon}). */
|
|
9362
|
+
header aligns with the row's leading content. Subclasses
|
|
9363
|
+
override {@link getRowIcon}; a row whose icon is null renders
|
|
9364
|
+
its value flush at the column edge with no reserved gutter. */
|
|
9340
9365
|
.lead-wrap {
|
|
9341
9366
|
display: flex;
|
|
9342
9367
|
align-items: center;
|
|
@@ -9345,12 +9370,12 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9345
9370
|
.lead-wrap .cell-inner {
|
|
9346
9371
|
min-width: 0;
|
|
9347
9372
|
}
|
|
9348
|
-
/*
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9373
|
+
/* The icon's 1em footprint plus a snug 5px gap to the value.
|
|
9374
|
+
The fixed box keeps the column's intrinsic width stable while
|
|
9375
|
+
<temba-icon> upgrades — without it the column briefly measures
|
|
9376
|
+
narrow and downstream pinned columns jump, which races with
|
|
9377
|
+
whatever moment we snapshot. Rows without an icon don't render
|
|
9378
|
+
this box at all — their value sits flush at the column edge. */
|
|
9354
9379
|
.lead-icon {
|
|
9355
9380
|
flex: 0 0 auto;
|
|
9356
9381
|
display: flex;
|
|
@@ -9503,7 +9528,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9503
9528
|
background: var(--danger-bg);
|
|
9504
9529
|
color: var(--danger);
|
|
9505
9530
|
}
|
|
9506
|
-
`}contentMenuEndpointWithSearch(){if(!this.contentMenuEndpoint||!this.search)return this.contentMenuEndpoint;try{const t=new URL(this.contentMenuEndpoint,window.location.origin);return t.searchParams.set("search",this.search),t.pathname+t.search}catch(t){return this.contentMenuEndpoint}}get hasCheckboxes(){return this.selectable&&this.bulkActions.length>0}constructor(){super(),this.contentMenuEndpoint="",this.columns=[],this.bulkActions=[],this.valueKey="uuid",this.pageSize=50,this.searchable=!0,this.selectable=!0,this.fixedLayout=!1,this.minTableWidth="",this.fillWindow=!1,this.urlState=!1,this.urlParamPrefix="",this.historyStateKey="",this.searchPlaceholder="Search",this.listTitle="",this.subtitle="",this.emptyMessage="Nothing to show",this.refreshKey="",this.actionEndpoint="",this.items=[],this.total=0,this.hasCount=!1,this.page=1,this.cursorMode=!1,this.nextCursor="",this.prevCursor="",this.currentUrl="",this.restoreUrl="",this.sort="",this.search="",this.loading=!1,this.searching=!1,this.searchError="",this.selectedIds=new Set,this.searchOpen=!1,this.searchDraft="",this.labelsByActionKey={},this.pendingLabel=null,this.bulkCollapsed=!1,this.bulkCollapseFrame=0,this.pending=null,this.pinIndexByColumn=new Map,this.rightPinIndexByColumn=new Map,this.checkPinIndex=-1,this.lastPinIndex=-1,this.firstRightPinIndex=-1,this.spacerAfterIndex=-1,this.reservesIcon=!1}connectedCallback(){super.connectedCallback(),this.urlState?(this.readUrlState(),this.popstateHandler=()=>{this.readUrlState(),this.fetchPage()},window.addEventListener("popstate",this.popstateHandler)):this.historyStateKey&&(this.readHistoryState(),this.popstateHandler=()=>{this.readHistoryState();const t=this.restoreUrl;this.restoreUrl="",this.fetchPage(t||void 0)},window.addEventListener("popstate",this.popstateHandler)),this.resizeHandler=()=>{this.syncScrollAffordance(),this.updateBulkCollapse()},window.addEventListener("resize",this.resizeHandler),document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.measurePinOffsets(),this.syncScrollAffordance()})}disconnectedCallback(){if(this.popstateHandler&&window.removeEventListener("popstate",this.popstateHandler),this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler),this.bulkCollapseFrame&&(cancelAnimationFrame(this.bulkCollapseFrame),this.bulkCollapseFrame=0),this.pending){const t=this.pending;this.pending=null,t.abort()}super.disconnectedCallback()}updated(t){if(super.updated(t),(t.has("endpoint")||t.has("refreshKey"))&&this.endpoint){const t=this.restoreUrl;this.restoreUrl="",this.fetchPage(t||void 0)}this.measurePinOffsets(),this.syncScrollAffordance(),this.updateBulkCollapse()}updateBulkCollapse(){this.measureBulkCollapse(),this.bulkCollapseFrame&&cancelAnimationFrame(this.bulkCollapseFrame),this.bulkCollapseFrame=requestAnimationFrame(()=>{this.bulkCollapseFrame=0,this.measureBulkCollapse()})}measureBulkCollapse(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".bulk-bar");if(!e)return;e.classList.add("measuring"),e.classList.remove("collapsed");const i=e.scrollWidth>e.clientWidth+1;e.classList.toggle("collapsed",this.bulkCollapsed),e.offsetWidth,e.classList.remove("measuring"),i!==this.bulkCollapsed&&(this.bulkCollapsed=i)}readUrlState(){const t=new URLSearchParams(window.location.search),e=t=>this.urlParamPrefix?`${this.urlParamPrefix}_${t}`:t,i=this.search;this.search=t.get(e("search"))||"",this.sort=t.get(e("sort"))||"";const o=parseInt(t.get(e("page"))||"1",10);this.page=isNaN(o)||o<1?1:o,this.search?(this.searchOpen=!0,this.searchDraft=this.search):i&&(this.searchOpen=!1,this.searchDraft="")}writeUrlState(t=!1){if(this.bubbleHistoryState(t),!this.urlState)return;const e=new URLSearchParams(window.location.search),i=t=>this.urlParamPrefix?`${this.urlParamPrefix}_${t}`:t,o=(t,i)=>{i?e.set(t,i):e.delete(t)};o(i("search"),this.search),o(i("sort"),this.sort),o(i("page"),this.page>1?String(this.page):"");const n=e.toString(),s=window.location.pathname+(n?"?"+n:"");t?window.history.replaceState({},"",s):window.history.pushState({},"",s)}readHistoryState(){const t=this.historyStateKey;if(!t)return;const e=(window.history.state||{})[t]||{},i=this.search;this.search="string"==typeof e.search?e.search:"",this.sort="string"==typeof e.sort?e.sort:"";const o=parseInt(e.page,10);this.page=isNaN(o)||o<1?1:o,this.restoreUrl="string"==typeof e.url?e.url:"",this.search?(this.searchOpen=!0,this.searchDraft=this.search):i&&(this.searchOpen=!1,this.searchDraft="")}bubbleHistoryState(t){if(!this.historyStateKey)return;const e={page:this.page,sort:this.sort,search:this.search};this.cursorMode&&this.currentUrl&&(e.url=this.currentUrl),this.fireCustomEvent(jo.HistoryChange,{key:this.historyStateKey,state:e,replace:t})}buildRequestUrl(){const t=new URL(this.endpoint,window.location.origin);return this.search&&t.searchParams.set("search",this.search),this.sort&&t.searchParams.set("sort",this.sort),this.page>1&&t.searchParams.set("page",String(this.page)),50!==this.pageSize&&t.searchParams.set("page_size",String(this.pageSize)),t.pathname+t.search}detectCursorMode(t){const e=t=>{if(!t)return!1;try{return new URL(t,window.location.origin).searchParams.has("cursor")}catch(t){return!1}};return!(!e(t.next)&&!e(t.previous))||null==t.count}toRequestUrl(t){try{const e=new URL(t,window.location.origin);return e.origin!==window.location.origin?"":e.pathname+e.search}catch(t){return""}}async fetchPage(t){var e;if(!this.endpoint)return;this.pending&&this.pending.abort();const i=new AbortController;this.pending=i,this.loading=!0,this.searchError="";const o=this.searching,n=t||this.buildRequestUrl();this.currentUrl=n;try{const t=(await ge(n,i)).json||{};this.searchError="string"==typeof t.error?t.error:"",this.items=t.results||[],this.nextCursor=t.next?this.toRequestUrl(t.next):"",this.prevCursor=t.previous?this.toRequestUrl(t.previous):"",this.cursorMode=this.detectCursorMode(t),this.hasCount=null!=t.count,this.total=null!==(e=t.count)&&void 0!==e?e:this.items.length,this.cursorMode&&!this.prevCursor&&1!==this.page&&(this.page=1,this.writeUrlState(!0));const s=new Set(this.items.map(t=>this.rowId(t))),r=new Set;this.selectedIds.forEach(t=>{s.has(t)&&r.add(t)}),this.selectedIds=r,o&&"string"==typeof t.query&&(this.search=t.query,this.searchDraft=t.query,this.writeUrlState(!0))}catch(t){"AbortError"!==(null==t?void 0:t.name)&&console.error("ContentList fetch failed",t)}finally{this.pending===i&&(this.pending=null,this.loading=!1,this.searching=!1,o&&this.searchOpen&&this.updateComplete.then(()=>this.focusSearchEnd()),this.fireCustomEvent(jo.FetchComplete))}}focusSearchEnd(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".searchbar input");if(!e)return;e.focus();const i=e.value.length;e.setSelectionRange(i,i)}refresh(){this.fetchPage(this.currentUrl||void 0)}rowId(t){const e=null==t?void 0:t[this.valueKey];return null!=e?String(e):JSON.stringify(t)}renderCell(t,e){const i=null==t?void 0:t[e.key];return null==i?"":String(i)}getRowHref(t){return null}handleSearchInput(t){this.searchDraft=t.target.value||""}handleSearchKey(t){"Enter"===t.key?(t.preventDefault(),this.commitSearch()):"Escape"===t.key&&(t.preventDefault(),this.toggleSearch())}commitSearch(){this.search!==this.searchDraft&&(this.search=this.searchDraft,this.page=1,this.searching=!0,this.fetchPage(),this.writeUrlState())}handleSortClick(t){t.sortable&&(this.sort===t.key?this.sort="-"+t.key:this.sort==="-"+t.key?this.sort="":this.sort=t.key,this.page=1,this.fetchPage(),this.writeUrlState())}handleRowClick(t,e){if(e.composedPath().some(t=>{var e,i;return null===(i=null===(e=null==t?void 0:t.classList)||void 0===e?void 0:e.contains)||void 0===i?void 0:i.call(e,"check-cell")}))return;this.fireCustomEvent(jo.RowClick,{item:t});const i=this.getRowHref(t);if(i&&this.isSafeHref(i)){if(e.metaKey||e.ctrlKey)return void window.open(i,"_blank");this.fireCustomEvent(jo.Redirected,{url:i})}}isSafeHref(t){if("string"!=typeof t||0===t.length)return!1;if(t.startsWith("//"))return!1;if(t.startsWith("/"))return!0;try{return new URL(t,window.location.origin).origin===window.location.origin}catch(t){return!1}}handleRowToggle(t){const e=this.rowId(t),i=new Set(this.selectedIds);i.has(e)?i.delete(e):i.add(e),this.selectedIds=i,this.fireCustomEvent(jo.SelectionChange,{ids:Array.from(i)})}handleSelectAll(){const t=this.items.map(t=>this.rowId(t)),e=t.length>0&&t.every(t=>this.selectedIds.has(t));this.selectedIds=e?new Set:new Set(t),this.fireCustomEvent(jo.SelectionChange,{ids:Array.from(this.selectedIds)})}async handleBulkAction(t){if(t.confirm&&!window.confirm(t.confirm))return;const e=Array.from(this.selectedIds);if(this.actionEndpoint&&!t.clientOnly){const i=new URLSearchParams;i.append("action",t.key),e.forEach(t=>i.append("objects",t));try{await we(this.actionEndpoint,i),await this.fetchPage(this.currentUrl||void 0),this.recheckSelection(e),this.fireCustomEvent(jo.BulkAction,{action:t.key,ids:e})}catch(t){console.error("bulk action POST failed",t)}}else this.fireCustomEvent(jo.BulkAction,{action:t.key,ids:e})}handlePage(t){if(this.cursorMode){const e=t>0?this.nextCursor:this.prevCursor;return void(e&&(this.page=Math.max(1,this.page+t),this.fetchPage(e),this.writeUrlState()))}const e=Math.max(1,Math.ceil(this.total/this.pageSize)),i=Math.min(e,Math.max(1,this.page+t));i!==this.page&&(this.page=i,this.fetchPage(),this.writeUrlState())}renderTitlebar(){const t=this.subtitle||this.querySelector('[slot="subtitle"]');return Z`
|
|
9531
|
+
`}contentMenuEndpointWithSearch(){if(!this.contentMenuEndpoint||!this.search)return this.contentMenuEndpoint;try{const t=new URL(this.contentMenuEndpoint,window.location.origin);return t.searchParams.set("search",this.search),t.pathname+t.search}catch(t){return this.contentMenuEndpoint}}get hasCheckboxes(){return this.selectable&&this.bulkActions.length>0}constructor(){super(),this.contentMenuEndpoint="",this.columns=[],this.bulkActions=[],this.valueKey="uuid",this.pageSize=50,this.searchable=!0,this.selectable=!0,this.fixedLayout=!1,this.minTableWidth="",this.fillWindow=!1,this.urlState=!1,this.urlParamPrefix="",this.historyStateKey="",this.searchPlaceholder="Search",this.listTitle="",this.subtitle="",this.emptyMessage="Nothing to show",this.refreshKey="",this.actionEndpoint="",this.items=[],this.total=0,this.hasCount=!1,this.page=1,this.cursorMode=!1,this.nextCursor="",this.prevCursor="",this.currentUrl="",this.restoreUrl="",this.sort="",this.search="",this.loading=!1,this.searching=!1,this.searchError="",this.selectedIds=new Set,this.searchOpen=!1,this.searchDraft="",this.labelsByActionKey={},this.pendingLabel=null,this.bulkCollapsed=!1,this.bulkCollapseFrame=0,this.pending=null,this.pinIndexByColumn=new Map,this.rightPinIndexByColumn=new Map,this.checkPinIndex=-1,this.lastPinIndex=-1,this.firstRightPinIndex=-1,this.spacerAfterIndex=-1,this.reservesIcon=!1}connectedCallback(){super.connectedCallback(),this.urlState?(this.readUrlState(),this.popstateHandler=()=>{this.readUrlState(),this.fetchPage()},window.addEventListener("popstate",this.popstateHandler)):this.historyStateKey&&(this.readHistoryState(),this.popstateHandler=()=>{this.readHistoryState();const t=this.restoreUrl;this.restoreUrl="",this.fetchPage(t||void 0)},window.addEventListener("popstate",this.popstateHandler)),this.resizeHandler=()=>{this.syncScrollAffordance(),this.updateBulkCollapse()},window.addEventListener("resize",this.resizeHandler),document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.measurePinOffsets(),this.syncScrollAffordance()})}disconnectedCallback(){if(this.popstateHandler&&window.removeEventListener("popstate",this.popstateHandler),this.resizeHandler&&window.removeEventListener("resize",this.resizeHandler),this.bulkCollapseFrame&&(cancelAnimationFrame(this.bulkCollapseFrame),this.bulkCollapseFrame=0),this.pending){const t=this.pending;this.pending=null,t.abort()}super.disconnectedCallback()}updated(t){if(super.updated(t),(t.has("endpoint")||t.has("refreshKey"))&&this.endpoint){const t=this.restoreUrl;this.restoreUrl="",this.fetchPage(t||void 0)}this.measurePinOffsets(),this.syncScrollAffordance(),this.updateBulkCollapse()}updateBulkCollapse(){this.measureBulkCollapse(),this.bulkCollapseFrame&&cancelAnimationFrame(this.bulkCollapseFrame),this.bulkCollapseFrame=requestAnimationFrame(()=>{this.bulkCollapseFrame=0,this.measureBulkCollapse()})}measureBulkCollapse(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".bulk-bar");if(!e)return;e.classList.add("measuring"),e.classList.remove("collapsed");const i=e.scrollWidth>e.clientWidth+1;e.classList.toggle("collapsed",this.bulkCollapsed),e.offsetWidth,e.classList.remove("measuring"),i!==this.bulkCollapsed&&(this.bulkCollapsed=i)}readUrlState(){const t=new URLSearchParams(window.location.search),e=t=>this.urlParamPrefix?`${this.urlParamPrefix}_${t}`:t,i=this.search;this.search=t.get(e("search"))||"",this.sort=t.get(e("sort"))||"";const o=parseInt(t.get(e("page"))||"1",10);this.page=isNaN(o)||o<1?1:o,this.search?(this.searchOpen=!0,this.searchDraft=this.search):i&&(this.searchOpen=!1,this.searchDraft="")}writeUrlState(t=!1){if(this.bubbleHistoryState(t),!this.urlState)return;const e=new URLSearchParams(window.location.search),i=t=>this.urlParamPrefix?`${this.urlParamPrefix}_${t}`:t,o=(t,i)=>{i?e.set(t,i):e.delete(t)};o(i("search"),this.search),o(i("sort"),this.sort),o(i("page"),this.page>1?String(this.page):"");const n=e.toString(),s=window.location.pathname+(n?"?"+n:"");t?window.history.replaceState({},"",s):window.history.pushState({},"",s)}readHistoryState(){const t=this.historyStateKey;if(!t)return;const e=(window.history.state||{})[t]||{},i=this.search;this.search="string"==typeof e.search?e.search:"",this.sort="string"==typeof e.sort?e.sort:"";const o=parseInt(e.page,10);this.page=isNaN(o)||o<1?1:o,this.restoreUrl="string"==typeof e.url?e.url:"",this.search?(this.searchOpen=!0,this.searchDraft=this.search):i&&(this.searchOpen=!1,this.searchDraft="")}bubbleHistoryState(t){if(!this.historyStateKey)return;const e={page:this.page,sort:this.sort,search:this.search};this.cursorMode&&this.currentUrl&&(e.url=this.currentUrl),this.fireCustomEvent(jo.HistoryChange,{key:this.historyStateKey,state:e,replace:t})}buildRequestUrl(){const t=new URL(this.endpoint,window.location.origin);return this.search&&t.searchParams.set("search",this.search),this.sort&&t.searchParams.set("sort",this.sort),this.page>1&&t.searchParams.set("page",String(this.page)),50!==this.pageSize&&t.searchParams.set("page_size",String(this.pageSize)),t.pathname+t.search}detectCursorMode(t){const e=t=>{if(!t)return!1;try{return new URL(t,window.location.origin).searchParams.has("cursor")}catch(t){return!1}};return!(!e(t.next)&&!e(t.previous))||null==t.count}toRequestUrl(t){try{const e=new URL(t,window.location.origin);return e.origin!==window.location.origin?"":e.pathname+e.search}catch(t){return""}}async fetchPage(t){var e;if(!this.endpoint)return;this.pending&&this.pending.abort();const i=new AbortController;this.pending=i,this.loading=!0,this.searchError="";const o=this.searching,n=t||this.buildRequestUrl();this.currentUrl=n;try{const t=(await ge(n,i)).json||{};this.searchError="string"==typeof t.error?t.error:"",this.items=t.results||[],this.nextCursor=t.next?this.toRequestUrl(t.next):"",this.prevCursor=t.previous?this.toRequestUrl(t.previous):"",this.cursorMode=this.detectCursorMode(t),this.hasCount=null!=t.count,this.total=null!==(e=t.count)&&void 0!==e?e:this.items.length,this.cursorMode&&!this.prevCursor&&1!==this.page&&(this.page=1,this.writeUrlState(!0));const s=new Set(this.items.map(t=>this.rowId(t))),r=new Set;this.selectedIds.forEach(t=>{s.has(t)&&r.add(t)}),this.selectedIds=r,o&&"string"==typeof t.query&&(this.search=t.query,this.searchDraft=t.query,this.writeUrlState(!0))}catch(t){"AbortError"!==(null==t?void 0:t.name)&&console.error("ContentList fetch failed",t)}finally{this.pending===i&&(this.pending=null,this.loading=!1,this.searching=!1,o&&this.searchOpen&&this.updateComplete.then(()=>this.focusSearchEnd()),this.fireCustomEvent(jo.FetchComplete))}}focusSearchEnd(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".searchbar input");if(!e)return;e.focus();const i=e.value.length;e.setSelectionRange(i,i)}refresh(){this.labelsByActionKey={},this.fetchPage(this.currentUrl||void 0)}rowId(t){const e=null==t?void 0:t[this.valueKey];return null!=e?String(e):JSON.stringify(t)}renderCell(t,e){const i=null==t?void 0:t[e.key];return null==i?"":String(i)}getRowHref(t){return null}handleSearchInput(t){this.searchDraft=t.target.value||""}handleSearchKey(t){"Enter"===t.key?(t.preventDefault(),this.commitSearch()):"Escape"===t.key&&(t.preventDefault(),this.toggleSearch())}commitSearch(){this.search!==this.searchDraft&&(this.search=this.searchDraft,this.page=1,this.searching=!0,this.fetchPage(),this.writeUrlState())}handleSortClick(t){t.sortable&&(this.sort===t.key?this.sort="-"+t.key:this.sort==="-"+t.key?this.sort="":this.sort=t.key,this.page=1,this.fetchPage(),this.writeUrlState())}handleRowClick(t,e){if(e.composedPath().some(t=>{var e,i;return null===(i=null===(e=null==t?void 0:t.classList)||void 0===e?void 0:e.contains)||void 0===i?void 0:i.call(e,"check-cell")}))return;this.fireCustomEvent(jo.RowClick,{item:t});const i=this.getRowHref(t);if(i&&this.isSafeHref(i)){if(e.metaKey||e.ctrlKey)return void window.open(i,"_blank");this.fireCustomEvent(jo.Redirected,{url:i})}}isSafeHref(t){if("string"!=typeof t||0===t.length)return!1;if(t.startsWith("//"))return!1;if(t.startsWith("/"))return!0;try{return new URL(t,window.location.origin).origin===window.location.origin}catch(t){return!1}}handleRowToggle(t){const e=this.rowId(t),i=new Set(this.selectedIds);i.has(e)?i.delete(e):i.add(e),this.selectedIds=i,this.fireCustomEvent(jo.SelectionChange,{ids:Array.from(i)})}handleSelectAll(){const t=this.items.map(t=>this.rowId(t)),e=t.length>0&&t.every(t=>this.selectedIds.has(t));this.selectedIds=e?new Set:new Set(t),this.fireCustomEvent(jo.SelectionChange,{ids:Array.from(this.selectedIds)})}async handleBulkAction(t){if(t.confirm&&!window.confirm(t.confirm))return;const e=Array.from(this.selectedIds);if(this.actionEndpoint&&!t.clientOnly){const i=new URLSearchParams;i.append("action",t.key),e.forEach(t=>i.append("objects",t));try{await we(this.actionEndpoint,i),await this.fetchPage(this.currentUrl||void 0),this.recheckSelection(e),this.fireCustomEvent(jo.BulkAction,{action:t.key,ids:e})}catch(t){console.error("bulk action POST failed",t)}}else this.fireCustomEvent(jo.BulkAction,{action:t.key,ids:e})}handlePage(t){if(this.cursorMode){const e=t>0?this.nextCursor:this.prevCursor;return void(e&&(this.page=Math.max(1,this.page+t),this.fetchPage(e),this.writeUrlState()))}const e=Math.max(1,Math.ceil(this.total/this.pageSize)),i=Math.min(e,Math.max(1,this.page+t));i!==this.page&&(this.page=i,this.fetchPage(),this.writeUrlState())}renderTitlebar(){const t=this.subtitle||this.querySelector('[slot="subtitle"]');return Z`
|
|
9507
9532
|
<temba-page-header
|
|
9508
9533
|
content-menu-endpoint=${this.contentMenuEndpointWithSearch()}
|
|
9509
9534
|
>
|
|
@@ -9569,7 +9594,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9569
9594
|
${t.icon?Z`<temba-icon name=${t.icon} size="0.9"></temba-icon>`:null}
|
|
9570
9595
|
<span class="bulk-label">${t.label}</span>
|
|
9571
9596
|
</span>
|
|
9572
|
-
`}renderLabelDropdown(t){const e=this.labelsByActionKey[t.key]
|
|
9597
|
+
`}renderLabelDropdown(t){const e=this.labelsByActionKey[t.key];return Z`
|
|
9573
9598
|
<temba-dropdown
|
|
9574
9599
|
class="label-dropdown"
|
|
9575
9600
|
@temba-opened=${()=>this.handleLabelDropdownOpened(t)}
|
|
@@ -9583,10 +9608,16 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9583
9608
|
<span class="bulk-label">${t.label}</span>
|
|
9584
9609
|
</span>
|
|
9585
9610
|
<div slot="dropdown" class="label-menu">
|
|
9586
|
-
${0
|
|
9611
|
+
${e?0!==e.length||t.allowCreate?e.map(e=>this.renderLabelOption(e,t)):Z`<div class="label-menu-empty">No labels</div>`:Z`<div class="label-menu-empty">Loading…</div>`}
|
|
9612
|
+
${e&&t.allowCreate?Z`<div
|
|
9613
|
+
class="lbl-create ${null!==this.pendingLabel?"blocked":""}"
|
|
9614
|
+
@click=${()=>this.handleLabelCreate(t)}
|
|
9615
|
+
>
|
|
9616
|
+
New Label…
|
|
9617
|
+
</div>`:null}
|
|
9587
9618
|
</div>
|
|
9588
9619
|
</temba-dropdown>
|
|
9589
|
-
`}renderLabelOption(t,e){const i=this.computeLabelState(t.uuid,e.labelsKey),o=this.pendingLabel===t.uuid,n=null!==this.pendingLabel&&!o;return Z`
|
|
9620
|
+
`}handleLabelCreate(t){null===this.pendingLabel&&this.fireCustomEvent(jo.LabelCreate,{action:t.key,ids:Array.from(this.selectedIds)})}renderLabelOption(t,e){const i=this.computeLabelState(t.uuid,e.labelsKey),o=this.pendingLabel===t.uuid,n=null!==this.pendingLabel&&!o;return Z`
|
|
9590
9621
|
<div
|
|
9591
9622
|
class="lbl-menu ${o?"pending":""} ${n?"blocked":""}"
|
|
9592
9623
|
@click=${e=>{e.stopPropagation(),null===this.pendingLabel&&this.toggleLabel(t,i)}}
|
|
@@ -9600,7 +9631,7 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9600
9631
|
></temba-checkbox>
|
|
9601
9632
|
<span class="lbl-name">${t.name}</span>
|
|
9602
9633
|
</div>
|
|
9603
|
-
`}async handleLabelDropdownOpened(t){var e;if(!this.labelsByActionKey[t.key]&&t.labelsEndpoint)try{const i=((null===(e=(await ge(t.labelsEndpoint)).json)||void 0===e?void 0:e.results)||[]).slice().sort((t,e)=>String(t.name||"").localeCompare(String(e.name||"")));this.labelsByActionKey={...this.labelsByActionKey,[t.key]:i}}catch(
|
|
9634
|
+
`}async handleLabelDropdownOpened(t){var e;if(!this.labelsByActionKey[t.key]&&t.labelsEndpoint)try{const i=((null===(e=(await ge(t.labelsEndpoint)).json)||void 0===e?void 0:e.results)||[]).slice().sort((t,e)=>String(t.name||"").localeCompare(String(e.name||"")));this.labelsByActionKey={...this.labelsByActionKey,[t.key]:i}}catch(e){this.labelsByActionKey={...this.labelsByActionKey,[t.key]:[]},console.error("failed to fetch labels",e)}}computeLabelState(t,e="labels"){const i=this.items.filter(t=>this.selectedIds.has(this.rowId(t)));if(0===i.length)return"none";const o=i.filter(i=>(i[e]||[]).some(e=>e.uuid===t));return 0===o.length?"none":o.length===i.length?"all":"some"}async toggleLabel(t,e){if(null!==this.pendingLabel)return;const i="all"!==e,o=Array.from(this.selectedIds);this.pendingLabel=t.uuid;try{if(this.actionEndpoint){const e=new URLSearchParams;e.append("action","label"),e.append("label",t.uuid),i||e.append("add","false"),o.forEach(t=>e.append("objects",t));try{await we(this.actionEndpoint,e),await this.fetchPage(this.currentUrl||void 0),this.recheckSelection(o),this.fireCustomEvent(jo.BulkAction,{action:"label",ids:o,label:t.uuid,add:i})}catch(t){console.error("label toggle POST failed",t)}}else this.fireCustomEvent(jo.BulkAction,{action:"label",ids:o,label:t.uuid,add:i})}finally{this.pendingLabel=null}}recheckSelection(t){const e=new Set(this.items.map(t=>this.rowId(t)));this.selectedIds=new Set(t.filter(t=>e.has(t)))}toggleSearch(){this.searchOpen=!this.searchOpen,this.searchOpen?(this.searchDraft=this.search,this.updateComplete.then(()=>{var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".searchbar input");null==e||e.focus()})):this.search?this.clearSearch():this.searchDraft=""}clearSearch(){this.searchDraft="",this.search&&(this.search="",this.page=1,this.searching=!1,this.fetchPage(),this.writeUrlState())}renderStatusPill(t,e){return Z`<span class="status-pill status-${t}">${e}</span>`}getRowIcon(t){return null}isLeftPinned(t){return!0===t.pinned||"left"===t.pinned}isRightPinned(t){return"right"===t.pinned}computePinLayout(){this.reservesIcon=this.items.some(t=>null!==this.getRowIcon(t)),this.pinIndexByColumn=new Map,this.rightPinIndexByColumn=new Map,this.checkPinIndex=-1,this.lastPinIndex=-1,this.firstRightPinIndex=-1,this.spacerAfterIndex=-1;let t=0;for(let e=this.columns.length-1;e>=0&&this.isRightPinned(this.columns[e]);e--)this.rightPinIndexByColumn.set(this.columns[e],t++);this.firstRightPinIndex=t-1;const e=this.columns.filter(t=>this.isLeftPinned(t)).length;if(0===e)return;let i=0;this.hasCheckboxes&&(this.checkPinIndex=i++),this.columns.forEach(t=>{this.isLeftPinned(t)&&this.pinIndexByColumn.set(t,i++)}),this.lastPinIndex=i-1,this.spacerAfterIndex=this.columns.some(t=>t.grow)?-1:e-1}pinClass(t){return t<0?"":t===this.lastPinIndex?"pinned pin-last":"pinned"}pinStyle(t){return t<0?"":`left: var(--cl-pin-${t}, 0px);`}columnPinClass(t){const e=this.pinIndexByColumn.get(t);if(null!=e)return this.pinClass(e);const i=this.rightPinIndexByColumn.get(t);return null!=i?i===this.firstRightPinIndex?"pinned pin-right pin-first":"pinned pin-right":""}columnPinStyle(t){const e=this.pinIndexByColumn.get(t);if(null!=e)return`left: var(--cl-pin-${e}, 0px);`;const i=this.rightPinIndexByColumn.get(t);return null!=i?`right: var(--cl-rpin-${i}, 0px);`:""}cellWidthStyle(t){if(this.fixedLayout)return"";if(t.width)return`width: ${t.width};`;const e=[];return t.minWidth&&e.push(`min-width: ${t.minWidth};`),t.grow||e.push(`max-width: ${t.maxWidth||"320px"};`),e.join(" ")}measurePinOffsets(){var t;const e=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("tr.header");if(!e)return;const i=Array.from(e.children);let o=0,n=0;for(const t of i){if(!t.classList.contains("pinned"))break;if(t.classList.contains("pin-right"))break;this.style.setProperty(`--cl-pin-${n}`,`${o}px`),o+=t.offsetWidth,n++}let s=0,r=0;for(let t=i.length-1;t>=0&&i[t].classList.contains("pin-right");t--)this.style.setProperty(`--cl-rpin-${r}`,`${s}px`),s+=i[t].offsetWidth,r++;this.style.setProperty("--cl-rpin-total",`${s}px`)}syncScrollAffordance(){var t,e;const i=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector(".table-frame"),o=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(".table-scroll");if(!i||!o)return;const n=o.scrollWidth-o.clientWidth;i.classList.toggle("overflowing",n>1),i.classList.toggle("scrolled",o.scrollLeft>1),i.classList.toggle("can-scroll-right",o.scrollLeft<n-1),i.classList.toggle("scrolled-down",o.scrollTop>1),this.style.setProperty("--cl-scrollbar-w",o.offsetWidth-o.clientWidth+"px");const s=o.querySelector("table"),r=s?Math.min(o.clientHeight,s.offsetHeight):o.clientHeight;this.style.setProperty("--cl-rows-height",`${r}px`);const a=o.querySelector("tr.header");a&&this.style.setProperty("--cl-header-height",`${a.offsetHeight}px`);const l=i.getBoundingClientRect(),d=o.querySelector("tr.row td.lead-cell .lead-icon")||o.querySelector("tr.row td.cell .cell-inner")||o.querySelector("tr.header th.head-cell .head-inner");d&&this.style.setProperty("--cl-firstcol-left",d.getBoundingClientRect().left-l.left+"px")}renderHeader(){const t=this.items.map(t=>this.rowId(t)),e=t.length>0&&t.every(t=>this.selectedIds.has(t)),i=!e&&this.selectedIds.size>0;return Z`
|
|
9604
9635
|
<thead>
|
|
9605
9636
|
<tr class="header">
|
|
9606
9637
|
${this.hasCheckboxes?Z`
|
|
@@ -9671,9 +9702,9 @@ const{I:sh}=lt,rh=t=>t,ah=()=>document.createComment(""),lh=(t,e,i)=>{const o=t.
|
|
|
9671
9702
|
class="cell ${n?"lead-cell":""} ${e.align||""} ${e.grow?"grow":""} ${this.columnPinClass(e)}"
|
|
9672
9703
|
style=${this.columnPinStyle(e)}
|
|
9673
9704
|
>
|
|
9674
|
-
${
|
|
9705
|
+
${s?Z`<div class="lead-wrap">
|
|
9675
9706
|
<span class="lead-icon"
|
|
9676
|
-
|
|
9707
|
+
><temba-icon name=${s} size="1"></temba-icon></span
|
|
9677
9708
|
>${o}
|
|
9678
9709
|
</div>`:o}
|
|
9679
9710
|
</td>
|
|
@@ -11093,7 +11124,7 @@ background: #ccc;
|
|
|
11093
11124
|
${this.renderUploader()}
|
|
11094
11125
|
</div>
|
|
11095
11126
|
</div>
|
|
11096
|
-
</div>`}}i([ft({type:String,attribute:!1})],Vu.prototype,"endpoint",void 0),i([ft({type:Boolean})],Vu.prototype,"pendingDrop",void 0),i([ft({type:Boolean})],Vu.prototype,"ignoreDrops",void 0),i([ft({type:String})],Vu.prototype,"icon",void 0),i([ft({type:String})],Vu.prototype,"accept",void 0),i([ft({type:Number})],Vu.prototype,"max",void 0),i([ft({type:Array})],Vu.prototype,"attachments",void 0),i([ft({type:Boolean,attribute:!1})],Vu.prototype,"uploading",void 0);let Zu="dev";try{Zu="0.159.
|
|
11127
|
+
</div>`}}i([ft({type:String,attribute:!1})],Vu.prototype,"endpoint",void 0),i([ft({type:Boolean})],Vu.prototype,"pendingDrop",void 0),i([ft({type:Boolean})],Vu.prototype,"ignoreDrops",void 0),i([ft({type:String})],Vu.prototype,"icon",void 0),i([ft({type:String})],Vu.prototype,"accept",void 0),i([ft({type:Number})],Vu.prototype,"max",void 0),i([ft({type:Array})],Vu.prototype,"attachments",void 0),i([ft({type:Boolean,attribute:!1})],Vu.prototype,"uploading",void 0);let Zu="dev";try{Zu="0.159.6"}catch(t){}const Yu=Zu,Ku=[{type:"has_any_word",name:"has any of the words",operands:1},{type:"has_all_words",name:"has all of the words",operands:1},{type:"has_phrase",name:"has the phrase",operands:1},{type:"has_only_phrase",name:"has only the phrase",operands:1},{type:"has_beginning",name:"starts with",operands:1},{type:"has_text",name:"has some text",operands:0,categoryName:"Has Text"},{type:"has_number",name:"has a number",operands:0,categoryName:"Has Number"},{type:"has_number_between",name:"has a number between",operands:2},{type:"has_number_lt",name:"has a number below",operands:1},{type:"has_number_lte",name:"has a number at or below",operands:1},{type:"has_number_eq",name:"has a number equal to",operands:1},{type:"has_number_gte",name:"has a number at or above",operands:1},{type:"has_number_gt",name:"has a number above",operands:1},{type:"has_date",name:"has a date",operands:0,categoryName:"Has Date"},{type:"has_date_lt",name:"has a date before",operands:1},{type:"has_date_eq",name:"has a date equal to",operands:1},{type:"has_date_gt",name:"has a date after",operands:1},{type:"has_time",name:"has a time",operands:0,categoryName:"Has Time"},{type:"has_phone",name:"has a phone number",operands:0,categoryName:"Has Phone"},{type:"has_email",name:"has an email",operands:0,categoryName:"Has Email"},{type:"has_state",name:"has state",operands:0,categoryName:"Has State",filter:"locations"},{type:"has_district",name:"has district",operands:1,categoryName:"Has District",filter:"locations"},{type:"has_ward",name:"has ward",operands:2,categoryName:"Has Ward",filter:"locations"},{type:"has_group",name:"is in the group",operands:1,visibility:"hidden"},{type:"has_category",name:"has the category",operands:0,visibility:"hidden"},{type:"has_error",name:"has an error",operands:0,categoryName:"Has Error",visibility:"hidden"},{type:"has_value",name:"is not empty",operands:0,categoryName:"Not Empty",visibility:"hidden"},{type:"has_pattern",name:"matches regex",operands:1}],Gu=t=>Ku.filter(e=>"hidden"!==e.visibility&&(!e.filter||!!t&&t.includes(e.filter))),Xu=new Set(["has_beginning","has_number","has_number_between","has_number_lt","has_number_lte","has_number_eq","has_number_gte","has_number_gt","has_pattern"]),Qu=t=>Ku.find(e=>e.type===t),Ju=t=>t.map(t=>({value:t.type,name:t.name})),tp={type:"text",required:!1,maxLength:64,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"},ep={type:"checkbox",label:"Require rules to be localized",helpText:"Each language must specify its own rules for this node"},ip={type:"checkbox",label:"Require categories to be localized",helpText:t=>{var e;const i=null===(e=t.result_name)||void 0===e?void 0:e.trim();if(i){return`Only enable if you plan to use @results.${i.toLowerCase().replace(/\s+/g,"_")}.category_localized`}return"Only enable if you plan to use category_localized in your expressions for this result"},conditions:{visible:t=>!!t.result_name}},op={label:"Save Result",localizable:!1,items:["result_name"],collapsed:t=>!(t._isNew&&t.result_name),getValueCount:t=>!!t.result_name},np={type:"accordion",multi:!0,sections:[op,{label:"Localization",localizable:!1,items:["localizeRules","localizeCategories"],collapsed:!0,getValueCount:t=>!(!t.localizeRules&&!t.localizeCategories)}]},sp={type:"accordion",multi:!0,sections:[op]},rp={type:"accordion",multi:!0,sections:[op,{label:"Localization",localizable:!1,items:["localizeCategories"],collapsed:!0,getValueCount:t=>!!t.localizeCategories}]};function ap(t,e){var i,o;const n=(null===(i=t.router)||void 0===i?void 0:i.categories)||[],s={};n.forEach(t=>{const i=t.uuid,o=e[i];s[i]={originalName:t.name,localizedName:o&&o.name?Array.isArray(o.name)?o.name[0]||"":o.name:""}});const r=(null===(o=t.router)||void 0===o?void 0:o.cases)||[],a={};return r.forEach(t=>{var i,o;if(!(null===(i=t.arguments)||void 0===i?void 0:i.length)||!t.arguments.some(t=>t))return;const n=e[t.uuid],s=(null===(o=Qu(t.type))||void 0===o?void 0:o.name)||t.type;a[t.uuid]={operatorName:s,originalArguments:[...t.arguments],localizedArguments:(null==n?void 0:n.arguments)?[...n.arguments]:t.arguments.map(()=>"")}}),{categories:s,rules:a}}function lp(t,e){const i={};return t.categories&&Object.keys(t.categories).forEach(e=>{var o,n;const s=t.categories[e],r=(null===(o=s.localizedName)||void 0===o?void 0:o.trim())||"",a=(null===(n=s.originalName)||void 0===n?void 0:n.trim())||"";r&&r!==a&&(i[e]={name:[r]})}),t.rules&&Object.keys(t.rules).forEach(e=>{const o=t.rules[e],n=o.localizedArguments||[],s=o.originalArguments||[],r=n.some((t,e)=>(null==t?void 0:t.trim())&&t.trim()!==(s[e]||""));r&&(i[e]={arguments:n.map(t=>(null==t?void 0:t.trim())||"")})}),i}function dp(t,e,i,o=[]){const n=[],s=[],r=[];return t.forEach(t=>{const a=ae(e,t.name),l=a?i.find(t=>t.uuid===a.exit_uuid):null,d=(null==l?void 0:l.uuid)||Xt(),c=(null==a?void 0:a.uuid)||Xt();if(n.push({uuid:c,name:t.name,exit_uuid:d}),s.push({uuid:d,destination_uuid:(null==l?void 0:l.destination_uuid)||null}),t.case){const e=t.case.arguments[0],i=o.find(t=>{var i;return(null===(i=t.arguments)||void 0===i?void 0:i[0])===e});r.push({uuid:(null==i?void 0:i.uuid)||Xt(),type:t.case.type,arguments:t.case.arguments,category_uuid:c})}}),{categories:n,exits:s,cases:r}}function cp(t,e,i,o,n){const s=n.some(t=>re(t,"Other"))?null:ae(i,"Other"),r=s?o.find(t=>t.uuid===s.exit_uuid):null,a=(null==r?void 0:r.uuid)||Xt(),l=(null==s?void 0:s.uuid)||Xt();return t.push({uuid:l,name:"Other",exit_uuid:a}),e.push({uuid:a,destination_uuid:(null==r?void 0:r.destination_uuid)||null}),l}function hp(t){return e=>{const i={};return t(e,i),{valid:0===Object.keys(i).length,errors:i}}}function up(t){return t.toLocalizationFormData?t.toLocalizationFormData:"categories"===t.localizable?ap:Array.isArray(t.localizable)?(e=t.localizable,(t,i)=>{const o={uuid:t.uuid};return e.forEach(t=>{const e=i[t];o[t]=Array.isArray(e)&&e[0]||""}),o}):void 0;var e}function pp(t){return t.fromLocalizationFormData?t.fromLocalizationFormData:"categories"===t.localizable?lp:Array.isArray(t.localizable)?(e=t.localizable,(t,i)=>{const o={};return e.forEach(e=>{const n=t[e];n&&""!==n.trim()&&n!==i[e]&&(o[e]=[n])}),o}):void 0;var e}const mp="undefined"!=typeof navigator&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function gp(t){return 0!==t.button||!(!mp||!t.ctrlKey)}function fp(t){if(t.dependency){const e=t.dependency.name||t.dependency.key;return`Cannot find a ${t.dependency.type} for ${e}`}return t.description}function vp(t){const e=20*Math.round(t/20);return Math.max(e,0)}const bp="font-family:SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;font-size:0.95em",yp={[sc.ExpressionPrefix]:`color:${Sc.expression};font-weight:600;${bp}`,[sc.Identifier]:`color:${Sc.expression};${bp}`,[sc.FunctionName]:`color:${Sc.fn};font-weight:900;${bp}`,[sc.StringLiteral]:`color:${Sc.string};${bp}`,[sc.NumberLiteral]:`color:${Sc.number};${bp}`,[sc.Keyword]:`color:${Sc.keyword};${bp}`,[sc.Operator]:`color:${Sc.operator};${bp}`,[sc.ContextRef]:`color:${Sc.expression};${bp}`,[sc.Separator]:`color:${Sc.operator};${bp}`,[sc.Arrow]:`color:${Sc.operator};${bp}`,[sc.Bracket]:`color:${Sc.operator};${bp}`,[sc.Paren]:`color:${Sc.paren};${bp}`,[sc.Whitespace]:bp},xp=[[/claude|anthropic/i,"anthropic"],[/gpt|openai|o1|o3|o4/i,"openai"],[/gemini|google/i,"gemini"],[/azure|microsoft/i,"azure"],[/deepseek/i,"deepseek"]],wp=(t,e=!1)=>{const i=hc(t||"",e?Xd:Gd),o=[];for(const t of i){const e=!!yp[t.type],i=o[o.length-1];i&&i.isExpr===e?i.tokens.push(t):o.push({isExpr:e,tokens:[t]})}const n=t=>{const e=yp[t.type];if(!e){const e=t.text.split("\n");return Z`${e.map((t,e)=>Z`${e>0?Z`<br />`:null}${t}`)}`}const i=t.text.split("\n");return Z`${i.map((t,i)=>Z`${i>0?Z`<br />`:null}${t?Z`<span style="${e}">${t}</span>`:null}`)}`};return Z`${o.map(t=>{const e=Z`${t.tokens.map(n)}`;return t.isExpr?Z`<span style="hyphens:none">${e}</span>`:e})}`},_p=(t,e,i=3)=>Z`<div
|
|
11097
11128
|
style="display: -webkit-box; -webkit-line-clamp: ${i}; -webkit-box-orient: vertical; overflow: hidden; word-wrap: break-word; overflow-wrap: break-word; hyphens: auto;"
|
|
11098
11129
|
title="${e}"
|
|
11099
11130
|
>
|
|
@@ -11237,7 +11268,7 @@ background: #ccc;
|
|
|
11237
11268
|
</div>
|
|
11238
11269
|
`},form:{llm:{type:"select",label:"LLM",required:!0,options:[],endpoint:"/api/internal/llms.json",searchable:!0,valueKey:"uuid",nameKey:"name",placeholder:"Select an LLM...",shouldExclude:t=>!fm(t,"engine")},input:{type:"text",label:"Input",helpText:"The input the AI will process",required:!0,evaluated:!0,placeholder:"@input"},instructions:{type:"textarea",label:"Instructions",helpText:"Tell the AI what to do with the input. The result can be referenced as **`@locals._llm_output`**",required:!0,evaluated:!0,placeholder:"Enter instructions for the AI model...",minHeight:130}},layout:["llm","input","instructions"],toFormData:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type);return{uuid:t.uuid,llm:(null==i?void 0:i.llm)?[i.llm]:[],input:(null==i?void 0:i.input)||"@input",instructions:(null==i?void 0:i.instructions)||""}},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),a={type:"call_llm",uuid:(null==r?void 0:r.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},input:t.input||"@input",instructions:t.instructions||"",output_local:"_llm_output"},l=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],d=e.exits||[],c=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:h,exits:u}=qe("@locals._llm_output",{type:"has_text",arguments:[]},l,d,c);return{uuid:e.uuid,actions:[a],router:h,exits:u}},localizable:"categories",nonTranslatableCategories:"all"},Km={type:"split_by_llm_categorize",name:"Split by AI",group:Up.services,flowTypes:[Bp,Np,Fp],form:{llm:{type:"select",label:"LLM",helpText:"Select the LLM to use for categorization",required:!0,endpoint:"/api/internal/llms.json",valueKey:"uuid",nameKey:"name",placeholder:"Select an LLM...",shouldExclude:t=>!fm(t,"engine")},input:{type:"text",label:"Input",helpText:"The input to categorize (usually @input)",required:!0,evaluated:!0,placeholder:"@input"},categories:{type:"array",helpText:"Define the categories for classification",required:!0,sortable:!0,itemLabel:"Category",minItems:1,maxItems:10,isEmptyItem:t=>!t.name||""===t.name.trim(),itemConfig:{name:{type:"text",placeholder:"Category name",required:!0}}},result_name:tp,localizeCategories:ip},layout:["llm","input","categories",rp],validate:hp((t,e)=>{if(!t.categories||!Array.isArray(t.categories))return;const i=t.categories.filter(t=>(null==t?void 0:t.name)&&""!==t.name.trim()),o=[],n=new Map;if(i.forEach(t=>{const e=t.name.trim().toLowerCase();n.has(e)||n.set(e,[]),n.get(e).push(t.name.trim())}),n.forEach(t=>{t.length>1&&o.push(...t)}),o.length>0){const t=[...new Set(o)];e.categories=`Duplicate category names found: ${t.join(", ")}`}}),render:t=>{var e;const i=null===(e=t.actions)||void 0===e?void 0:e.find(t=>"call_llm"===t.type);return Z`
|
|
11239
11270
|
<div class="body">Categorize with ${i.llm.name}</div>
|
|
11240
|
-
`},toFormData:(t,e)=>{var i,o,n,s,r;const a=null===(i=t.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l=(null===(n=null===(o=t.router)||void 0===o?void 0:o.categories)||void 0===n?void 0:n.filter(t=>"Other"!==t.name&&"Failure"!==t.name).map(t=>({name:t.name})))||[];return{uuid:t.uuid,llm:(null==a?void 0:a.llm)?[a.llm]:[],input:(null==a?void 0:a.input)||"@input",categories:l,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeCategories:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),a=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l={type:"call_llm",uuid:(null==a?void 0:a.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},instructions:'@(prompt("categorize", slice(node.categories, 0, -2)))',input:t.input||"@input",output_local:"_llm_output"},d=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],c=e.exits||[],h=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:u,exits:p}=((t,e,i,o=[],n=[],s=[])=>{const r=[],a=[],l=[];e.forEach(t=>{const e=Fe({name:t,existingCategories:o,existingExits:n,existingCases:s,caseConfig:i(t)});r.push(e.category),a.push(e.exit),e.case&&l.push(e.case)});const d=Fe({name:"Other",existingCategories:o,existingExits:n});r.push(d.category),a.push(d.exit);const c=Fe({name:"Failure",existingCategories:o,existingExits:n,existingCases:s,caseConfig:{type:"has_only_text",arguments:["<ERROR>"]}});return r.push(c.category),a.push(c.exit),c.case&&l.push(c.case),{router:{type:"switch",categories:r,default_category_uuid:d.category.uuid,operand:t,cases:l},exits:a}})("@locals._llm_output",r,t=>({type:"has_only_text",arguments:[t]}),d,c,h),m={...u};return t.result_name&&""!==t.result_name.trim()&&(m.result_name=t.result_name.trim()),{uuid:e.uuid,actions:[l],router:m,exits:p}},localizable:"categories",nonTranslatableCategories:["Failure"]},Gm={type:"wait_for_audio",name:"Make Recording",group:jp.wait,flowTypes:[Bp],form:{result_name:{type:"text",label:"Result Name",required:!1,maxLength:64,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"}},layout:["result_name"],toFormData:t=>{var e;return{uuid:t.uuid,result_name:(null===(e=t.router)||void 0===e?void 0:e.result_name)||""}},fromFormData:(t,e)=>{var i;const o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],n=e.exits||[];let s,r=o.find(t=>"All Responses"===t.name);if(r)s=n.find(t=>t.uuid===r.exit_uuid)||{uuid:r.exit_uuid,destination_uuid:null};else{const t=Xt();r={uuid:Xt(),name:"All Responses",exit_uuid:t},s={uuid:t,destination_uuid:null}}const a={type:"switch",operand:"@input",default_category_uuid:r.uuid,cases:[],categories:[r],wait:{type:"msg",hint:{type:"audio"}}};return t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim()),{...e,router:a,exits:[s]}},localizable:"categories",nonTranslatableCategories:"all"},Xm=["Answered","No Answer","Busy","Failed"],Qm=[{type:"has_only_text",arguments:["answered"],categoryName:"Answered"},{type:"has_only_text",arguments:["no_answer"],categoryName:"No Answer"},{type:"has_only_text",arguments:["busy"],categoryName:"Busy"}],Jm={type:"wait_for_dial",name:"Redirect Call",group:jp.wait,flowTypes:[Bp],router:{type:"switch",defaultCategory:"Failed",rules:Qm.map(t=>({type:t.type,arguments:t.arguments,categoryName:t.categoryName}))},form:{phone:{type:"text",label:"Phone Number",required:!0,evaluated:!0,placeholder:"Phone number or expression"},dial_limit_seconds:{type:"text",label:"Dial Limit (seconds)",required:!1,placeholder:"60"},call_limit_seconds:{type:"text",label:"Call Limit (seconds)",required:!1,placeholder:"7200"},result_name:tp},layout:["phone",{type:"row",items:["dial_limit_seconds","call_limit_seconds"]},"result_name"],toFormData:t=>{var e,i;const o=null===(e=t.router)||void 0===e?void 0:e.wait;return{uuid:t.uuid,phone:(null==o?void 0:o.phone)||"",dial_limit_seconds:(null==o?void 0:o.dial_limit_seconds)?String(o.dial_limit_seconds):"",call_limit_seconds:(null==o?void 0:o.call_limit_seconds)?String(o.call_limit_seconds):"",result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const t of Xm){const e=n.find(e=>e.name===t);if(e){a.push(e);const t=s.find(t=>t.uuid===e.exit_uuid);l.push(t||{uuid:e.exit_uuid,destination_uuid:null})}else{const e=Xt();a.push({uuid:Xt(),name:t,exit_uuid:e}),l.push({uuid:e,destination_uuid:null})}}for(const t of Qm){const e=a.find(e=>e.name===t.categoryName);if(!e)continue;const i=r.find(e=>{var i;return e.type===t.type&&(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.arguments[0]});d.push({uuid:(null==i?void 0:i.uuid)||Xt(),type:t.type,arguments:t.arguments,category_uuid:e.uuid})}const c=a.find(t=>"Failed"===t.name),h=(t.phone||"").trim(),u=parseInt(t.dial_limit_seconds,10),p=parseInt(t.call_limit_seconds,10),m={type:"dial",phone:h};!isNaN(u)&&u>0&&(m.dial_limit_seconds=u),!isNaN(p)&&p>0&&(m.call_limit_seconds=p);const g={type:"switch",operand:'@(default(resume.dial.status, ""))',default_category_uuid:null==c?void 0:c.uuid,cases:d,categories:a,wait:m};return t.result_name&&""!==t.result_name.trim()&&(g.result_name=t.result_name.trim()),{...e,router:g,exits:l}},localizable:"categories",nonTranslatableCategories:"all"},tg={type:"wait_for_digits",name:"Wait for Digits",group:jp.wait,flowTypes:[Bp],dialogSize:"large",form:{rules:Dm(Ju(Ku.filter(t=>Xu.has(t.type))),""),result_name:tp,localizeRules:ep,localizeCategories:ip},layout:[{type:"text",text:"Rules match against all digits pressed by the caller followed by the # sign."},"rules",np],validate:t=>({valid:!0,errors:{}}),toFormData:(t,e)=>{var i,o,n;const s=Tm(t);return{uuid:t.uuid,rules:s,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||"",localizeRules:(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.localizeRules)||!1,localizeCategories:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=Em(t),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=He("@input.text",n,Qu,s,r,a),c={...l,wait:{type:"msg",hint:{type:"digits"}}};return t.result_name&&""!==t.result_name.trim()&&(c.result_name=t.result_name.trim()),{...e,router:c,exits:d}},localizable:"categories"},eg=["1","2","3","4","5","6","7","8","9","0"];function ig(t){return`digit_${t}`}const og={type:"wait_for_menu",name:"Wait for Menu",group:jp.wait,flowTypes:[Bp],form:{...Object.fromEntries(eg.map(t=>[ig(t),{type:"text",required:!1,placeholder:"",flavor:"xsmall"}])),result_name:tp,localizeRules:ep,localizeCategories:ip},layout:[{type:"row",items:["digit_1","digit_2","digit_3"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_1:"1",digit_2:"2",digit_3:"3"}},{type:"row",items:["digit_4","digit_5","digit_6"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_4:"4",digit_5:"5",digit_6:"6"}},{type:"row",items:["digit_7","digit_8","digit_9"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_7:"7",digit_8:"8",digit_9:"9"}},{type:"row",items:[{type:"spacer"},"digit_0",{type:"spacer"}],gap:"2rem",inlineLabels:{digit_0:"0"}},np],toFormData:(t,e)=>{var i,o,n,s,r,a;const l={uuid:t.uuid,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""};for(const t of eg)l[ig(t)]="";if((null===(o=t.router)||void 0===o?void 0:o.cases)&&(null===(n=t.router)||void 0===n?void 0:n.categories))for(const e of t.router.cases)if("has_number_eq"===e.type&&(null===(s=e.arguments)||void 0===s?void 0:s[0])){const i=e.arguments[0],o=t.router.categories.find(t=>t.uuid===e.category_uuid);o&&eg.includes(i)&&(l[ig(i)]=o.name)}return l.localizeRules=(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,l.localizeCategories=(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1,l},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const e of eg){const i=(t[ig(e)]||"").trim();if(!i)continue;let o=a.find(t=>t.name===i);if(!o){const t=n.find(t=>t.name===i);if(t){o=t;const e=s.find(e=>e.uuid===t.exit_uuid);a.push(o),l.push(e||{uuid:t.exit_uuid,destination_uuid:null})}else{const t=Xt();o={uuid:Xt(),name:i,exit_uuid:t},a.push(o),l.push({uuid:t,destination_uuid:null})}}const c=r.find(t=>{var i;return"has_number_eq"===t.type&&(null===(i=t.arguments)||void 0===i?void 0:i[0])===e});d.push({uuid:(null==c?void 0:c.uuid)||Xt(),type:"has_number_eq",arguments:[e],category_uuid:o.uuid})}const c=n.find(t=>"Other"===t.name);let h;if(c){h=c;const t=s.find(t=>t.uuid===c.exit_uuid);l.push(t||{uuid:c.exit_uuid,destination_uuid:null})}else{const t=Xt();h={uuid:Xt(),name:"Other",exit_uuid:t},l.push({uuid:t,destination_uuid:null})}a.push(h);const u={type:"switch",operand:"@input.text",default_category_uuid:h.uuid,cases:d,categories:a,wait:{type:"msg",hint:{type:"digits",count:1}}};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:l}},localizable:"categories"},ng=[{value:"60",name:"1 minute"},{value:"120",name:"2 minutes"},{value:"180",name:"3 minutes"},{value:"240",name:"4 minutes"},{value:"300",name:"5 minutes"},{value:"600",name:"10 minutes"},{value:"900",name:"15 minutes"},{value:"1800",name:"30 minutes"},{value:"3600",name:"1 hour"},{value:"7200",name:"2 hours"},{value:"10800",name:"3 hours"},{value:"21600",name:"6 hours"},{value:"43200",name:"12 hours"},{value:"64800",name:"18 hours"},{value:"86400",name:"1 day"},{value:"172800",name:"2 days"},{value:"259200",name:"3 days"},{value:"604800",name:"1 week"}],sg=(t,e=[],i=[],o=[])=>{const{router:n,exits:s}=He("@input.text",t,Qu,e,i,o),r=e.find(t=>"No Response"===t.name||"Timeout"===t.name);if(r){const t=i.find(t=>t.uuid===r.exit_uuid);t&&(n.categories.push(r),s.push({uuid:t.uuid,destination_uuid:t.destination_uuid||null}))}return{router:n,exits:s}},rg={type:"wait_for_response",name:"Wait for Response",group:jp.wait,flowTypes:[Np],hideFromSplits:!0,dialogSize:"large",form:{rules:Dm(Ju(Gu()),"If the message from the contact..."),timeout_enabled:{type:"checkbox",label:t=>t.timeout_enabled?"Continue when there is no response for":"Continue when there is no response..",labelPadding:"4px 8px"},timeout_duration:{type:"select",placeholder:"5 minutes",multi:!1,maxWidth:"130px",flavor:"xsmall",options:ng,conditions:{visible:t=>!0===t.timeout_enabled}},result_name:tp,localizeRules:ep,localizeCategories:ip},layout:["rules",np],gutter:[{type:"row",items:["timeout_enabled","timeout_duration"],gap:"0.5rem"}],validate:hp(()=>{}),toFormData:(t,e)=>{var i,o,n,s,r,a;const l=Tm(t),d=null===(n=null===(o=null===(i=t.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.seconds;let c=ng.find(t=>t.value===String(d));return c||(c={value:"300",name:"5 minutes"}),{uuid:t.uuid,rules:l,timeout_enabled:!!d,timeout_duration:c,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeRules:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,localizeCategories:(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=Em(t);if(0===c.length){let o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[];const n=[...e.exits||[]];if(t.timeout_enabled){let t=o.find(t=>"No Response"===t.name);if(!t){const e=Xt();t={uuid:Xt(),name:"No Response",exit_uuid:e},o=[...o,t],n.find(t=>t.uuid===e)||n.push({uuid:e,destination_uuid:null})}}else o=o.filter(t=>"No Response"!==t.name);const{router:s,exits:r}=sg([],o,n,[]),a={...s,cases:[]};t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim());const l={type:"msg"};if(t.timeout_enabled){let e;e=t.timeout_duration?Array.isArray(t.timeout_duration)&&t.timeout_duration.length>0?parseInt(t.timeout_duration[0].value,10):"string"==typeof t.timeout_duration?parseInt(t.timeout_duration,10):t.timeout_duration&&"object"==typeof t.timeout_duration&&t.timeout_duration.value?parseInt(t.timeout_duration.value,10):300:300,(isNaN(e)||e<=0)&&(e=300);const i=a.categories.find(t=>"No Response"===t.name);i&&(l.timeout={seconds:e,category_uuid:i.uuid})}return a.wait=l,{...e,router:a,exits:r}}const h=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],u=e.exits||[],p=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:m,exits:g}=sg(c,h,u,p),f={...m};t.result_name&&""!==t.result_name.trim()&&(f.result_name=t.result_name.trim());const v={type:"msg"};try{if(t.timeout_enabled){let i;if(t.timeout_duration)try{i=parseInt(t.timeout_duration[0].value,10)}catch(t){i=300}const o=null===(r=null===(s=e.router)||void 0===s?void 0:s.categories)||void 0===r?void 0:r.find(t=>"No Response"===t.name),n=o||{uuid:Xt(),name:"No Response",exit_uuid:Xt()};if(v.timeout={seconds:i,category_uuid:n.uuid},!(null===(a=m.categories)||void 0===a?void 0:a.some(t=>"No Response"===t.name))&&(m.categories=m.categories||[],m.categories.push(n),!g.some(t=>t.uuid===n.exit_uuid))){const t={uuid:n.exit_uuid,destination_uuid:(null==o?void 0:o.exit_uuid)&&(null===(d=null===(l=e.exits)||void 0===l?void 0:l.find(t=>t.uuid===o.exit_uuid))||void 0===d?void 0:d.destination_uuid)||null};g.push(t)}}else if(m.categories){const t=m.categories.findIndex(t=>"No Response"===t.name);if(-1!==t){const e=m.categories[t];m.categories.splice(t,1);const i=g.findIndex(t=>t.uuid===e.exit_uuid);-1!==i&&g.splice(i,1)}}}catch(t){console.error("Error processing timeout configuration:",t)}return f.wait=v,{...e,router:f,exits:g}},localizable:"categories",nonTranslatableCategories:["Timeout"]},ag=lg({say_msg:pm,play_audio:mm,set_contact_field:Yp,send_broadcast:Qp,set_run_result:Jp,send_msg:em,send_email:im,start_session:om,set_contact_name:nm,add_contact_groups:sm,remove_contact_groups:rm,set_contact_channel:Kp,set_contact_language:Gp,set_contact_status:Xp,add_contact_urn:Zp,add_input_labels:Vp,request_optin:am,enter_flow:vm});function lg(t){const e={...t};return Object.values(t).forEach(t=>{t.aliases&&t.aliases.forEach(i=>{e[i]=t})}),e}const dg=lg({execute_actions:{type:"execute_actions"},split_by_contact_field:zm,split_by_expression:Im,split_by_groups:Lm,split_by_llm:Ym,split_by_llm_categorize:Km,split_by_random:Om,split_by_run_result:Nm,split_by_scheme:Fm,split_by_subflow:qm,split_by_ticket:Um,split_by_webhook:Vm,split_by_resthook:Zm,wait_for_menu:og,wait_for_digits:tg,wait_for_audio:Gm,wait_for_dial:Jm,wait_for_response:rg,split_by_airtime:xm,terminal:{type:"terminal"}}),cg="__primary_language__";class hg extends Ye{constructor(){super(...arguments),this.messageView=!1,this.zoom=1,this.zoomInitialized=!1,this.zoomFitted=!1,this.revisionsActive=!1,this.isSaving=!1,this.searchDisabled=!1,this.languageOptions=[],this.currentLanguageName="",this.isBaseLanguage=!0,this.languagePercent=0,this.showLocalizationTools=!1,this.hasPendingTranslations=!1,this.autoTranslateDisabled=!1,this.autoTranslating=!1,this.showLanguageOptions=!1}static get styles(){return d`
|
|
11271
|
+
`},toFormData:(t,e)=>{var i,o,n,s,r;const a=null===(i=t.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l=(null===(n=null===(o=t.router)||void 0===o?void 0:o.categories)||void 0===n?void 0:n.filter(t=>"Other"!==t.name&&"Failure"!==t.name).map(t=>({name:t.name})))||[];return{uuid:t.uuid,llm:(null==a?void 0:a.llm)?[a.llm]:[],input:(null==a?void 0:a.input)||"@input",categories:l,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeCategories:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n;const s=Array.isArray(t.llm)&&t.llm.length>0?t.llm[0]:null,r=(t.categories||[]).filter(t=>{var e;return null===(e=null==t?void 0:t.name)||void 0===e?void 0:e.trim()}).map(t=>t.name.trim()),a=null===(i=e.actions)||void 0===i?void 0:i.find(t=>"call_llm"===t.type),l={type:"call_llm",uuid:(null==a?void 0:a.uuid)||Xt(),llm:s?{uuid:s.uuid||s.value,name:s.name}:{uuid:"",name:""},instructions:'@(prompt("categorize", slice(node.categories, 0, -2)))',input:t.input||"@input",output_local:"_llm_output"},d=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],c=e.exits||[],h=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:u,exits:p}=((t,e,i,o=[],n=[],s=[])=>{const r=[],a=[],l=[];e.forEach(t=>{const e=Fe({name:t,existingCategories:o,existingExits:n,existingCases:s,caseConfig:i(t)});r.push(e.category),a.push(e.exit),e.case&&l.push(e.case)});const d=Fe({name:"Other",existingCategories:o,existingExits:n});r.push(d.category),a.push(d.exit);const c=Fe({name:"Failure",existingCategories:o,existingExits:n,existingCases:s,caseConfig:{type:"has_only_text",arguments:["<ERROR>"]}});return r.push(c.category),a.push(c.exit),c.case&&l.push(c.case),{router:{type:"switch",categories:r,default_category_uuid:d.category.uuid,operand:t,cases:l},exits:a}})("@locals._llm_output",r,t=>({type:"has_only_text",arguments:[t]}),d,c,h),m={...u};return t.result_name&&""!==t.result_name.trim()&&(m.result_name=t.result_name.trim()),{uuid:e.uuid,actions:[l],router:m,exits:p}},localizable:"categories",nonTranslatableCategories:["Failure"]},Gm={type:"wait_for_audio",name:"Make Recording",group:jp.wait,flowTypes:[Bp],form:{result_name:{type:"text",label:"Result Name",required:!1,maxLength:64,placeholder:"(optional)",helpText:"The name to use to reference this result in the flow"}},layout:["result_name"],toFormData:t=>{var e;return{uuid:t.uuid,result_name:(null===(e=t.router)||void 0===e?void 0:e.result_name)||""}},fromFormData:(t,e)=>{var i;const o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],n=e.exits||[];let s,r=o.find(t=>"All Responses"===t.name);if(r)s=n.find(t=>t.uuid===r.exit_uuid)||{uuid:r.exit_uuid,destination_uuid:null};else{const t=Xt();r={uuid:Xt(),name:"All Responses",exit_uuid:t},s={uuid:t,destination_uuid:null}}const a={type:"switch",operand:"@input",default_category_uuid:r.uuid,cases:[],categories:[r],wait:{type:"msg",hint:{type:"audio"}}};return t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim()),{...e,router:a,exits:[s]}},localizable:"categories",nonTranslatableCategories:"all"},Xm=["Answered","No Answer","Busy","Failed"],Qm=[{type:"has_only_text",arguments:["answered"],categoryName:"Answered"},{type:"has_only_text",arguments:["no_answer"],categoryName:"No Answer"},{type:"has_only_text",arguments:["busy"],categoryName:"Busy"}],Jm={type:"wait_for_dial",name:"Redirect Call",group:jp.wait,flowTypes:[Bp],router:{type:"switch",defaultCategory:"Failed",rules:Qm.map(t=>({type:t.type,arguments:t.arguments,categoryName:t.categoryName}))},form:{phone:{type:"text",label:"Phone Number",required:!0,evaluated:!0,placeholder:"Phone number or expression"},dial_limit_seconds:{type:"text",label:"Dial Limit (seconds)",required:!1,placeholder:"60"},call_limit_seconds:{type:"text",label:"Call Limit (seconds)",required:!1,placeholder:"7200"},result_name:tp},layout:["phone",{type:"row",items:["dial_limit_seconds","call_limit_seconds"]},"result_name"],toFormData:t=>{var e,i;const o=null===(e=t.router)||void 0===e?void 0:e.wait;return{uuid:t.uuid,phone:(null==o?void 0:o.phone)||"",dial_limit_seconds:(null==o?void 0:o.dial_limit_seconds)?String(o.dial_limit_seconds):"",call_limit_seconds:(null==o?void 0:o.call_limit_seconds)?String(o.call_limit_seconds):"",result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""}},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const t of Xm){const e=n.find(e=>e.name===t);if(e){a.push(e);const t=s.find(t=>t.uuid===e.exit_uuid);l.push(t||{uuid:e.exit_uuid,destination_uuid:null})}else{const e=Xt();a.push({uuid:Xt(),name:t,exit_uuid:e}),l.push({uuid:e,destination_uuid:null})}}for(const t of Qm){const e=a.find(e=>e.name===t.categoryName);if(!e)continue;const i=r.find(e=>{var i;return e.type===t.type&&(null===(i=e.arguments)||void 0===i?void 0:i[0])===t.arguments[0]});d.push({uuid:(null==i?void 0:i.uuid)||Xt(),type:t.type,arguments:t.arguments,category_uuid:e.uuid})}const c=a.find(t=>"Failed"===t.name),h=(t.phone||"").trim(),u=parseInt(t.dial_limit_seconds,10),p=parseInt(t.call_limit_seconds,10),m={type:"dial",phone:h};!isNaN(u)&&u>0&&(m.dial_limit_seconds=u),!isNaN(p)&&p>0&&(m.call_limit_seconds=p);const g={type:"switch",operand:'@(default(resume.dial.status, ""))',default_category_uuid:null==c?void 0:c.uuid,cases:d,categories:a,wait:m};return t.result_name&&""!==t.result_name.trim()&&(g.result_name=t.result_name.trim()),{...e,router:g,exits:l}},localizable:"categories",nonTranslatableCategories:"all"},tg={type:"wait_for_digits",name:"Wait for Digits",group:jp.wait,flowTypes:[Bp],dialogSize:"large",form:{rules:Dm(Ju(Ku.filter(t=>Xu.has(t.type))),""),result_name:tp,localizeRules:ep,localizeCategories:ip},layout:[{type:"text",text:"Rules match against all digits pressed by the caller followed by the # sign."},"rules",np],validate:t=>({valid:!0,errors:{}}),toFormData:(t,e)=>{var i,o,n;const s=Tm(t);return{uuid:t.uuid,rules:s,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||"",localizeRules:(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.localizeRules)||!1,localizeCategories:(null===(n=null==e?void 0:e.config)||void 0===n?void 0:n.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=Em(t),s=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],r=e.exits||[],a=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],{router:l,exits:d}=He("@input.text",n,Qu,s,r,a),c={...l,wait:{type:"msg",hint:{type:"digits"}}};return t.result_name&&""!==t.result_name.trim()&&(c.result_name=t.result_name.trim()),{...e,router:c,exits:d}},localizable:"categories"},eg=["1","2","3","4","5","6","7","8","9","0"];function ig(t){return`digit_${t}`}const og={type:"wait_for_menu",name:"Wait for Menu",group:jp.wait,flowTypes:[Bp],form:{...Object.fromEntries(eg.map(t=>[ig(t),{type:"text",required:!1,placeholder:"",flavor:"xsmall"}])),result_name:tp,localizeRules:ep,localizeCategories:ip},layout:[{type:"row",items:["digit_1","digit_2","digit_3"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_1:"1",digit_2:"2",digit_3:"3"}},{type:"row",items:["digit_4","digit_5","digit_6"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_4:"4",digit_5:"5",digit_6:"6"}},{type:"row",items:["digit_7","digit_8","digit_9"],gap:"2rem",marginBottom:"0.5rem",inlineLabels:{digit_7:"7",digit_8:"8",digit_9:"9"}},{type:"row",items:[{type:"spacer"},"digit_0",{type:"spacer"}],gap:"2rem",inlineLabels:{digit_0:"0"}},np],toFormData:(t,e)=>{var i,o,n,s,r,a;const l={uuid:t.uuid,result_name:(null===(i=t.router)||void 0===i?void 0:i.result_name)||""};for(const t of eg)l[ig(t)]="";if((null===(o=t.router)||void 0===o?void 0:o.cases)&&(null===(n=t.router)||void 0===n?void 0:n.categories))for(const e of t.router.cases)if("has_number_eq"===e.type&&(null===(s=e.arguments)||void 0===s?void 0:s[0])){const i=e.arguments[0],o=t.router.categories.find(t=>t.uuid===e.category_uuid);o&&eg.includes(i)&&(l[ig(i)]=o.name)}return l.localizeRules=(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,l.localizeCategories=(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1,l},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o;const n=(null===(i=e.router)||void 0===i?void 0:i.categories)||[],s=e.exits||[],r=(null===(o=e.router)||void 0===o?void 0:o.cases)||[],a=[],l=[],d=[];for(const e of eg){const i=(t[ig(e)]||"").trim();if(!i)continue;let o=a.find(t=>t.name===i);if(!o){const t=n.find(t=>t.name===i);if(t){o=t;const e=s.find(e=>e.uuid===t.exit_uuid);a.push(o),l.push(e||{uuid:t.exit_uuid,destination_uuid:null})}else{const t=Xt();o={uuid:Xt(),name:i,exit_uuid:t},a.push(o),l.push({uuid:t,destination_uuid:null})}}const c=r.find(t=>{var i;return"has_number_eq"===t.type&&(null===(i=t.arguments)||void 0===i?void 0:i[0])===e});d.push({uuid:(null==c?void 0:c.uuid)||Xt(),type:"has_number_eq",arguments:[e],category_uuid:o.uuid})}const c=n.find(t=>"Other"===t.name);let h;if(c){h=c;const t=s.find(t=>t.uuid===c.exit_uuid);l.push(t||{uuid:c.exit_uuid,destination_uuid:null})}else{const t=Xt();h={uuid:Xt(),name:"Other",exit_uuid:t},l.push({uuid:t,destination_uuid:null})}a.push(h);const u={type:"switch",operand:"@input.text",default_category_uuid:h.uuid,cases:d,categories:a,wait:{type:"msg",hint:{type:"digits",count:1}}};return t.result_name&&""!==t.result_name.trim()&&(u.result_name=t.result_name.trim()),{...e,router:u,exits:l}},localizable:"categories"},ng=[{value:"60",name:"1 minute"},{value:"120",name:"2 minutes"},{value:"180",name:"3 minutes"},{value:"240",name:"4 minutes"},{value:"300",name:"5 minutes"},{value:"600",name:"10 minutes"},{value:"900",name:"15 minutes"},{value:"1800",name:"30 minutes"},{value:"3600",name:"1 hour"},{value:"7200",name:"2 hours"},{value:"10800",name:"3 hours"},{value:"21600",name:"6 hours"},{value:"43200",name:"12 hours"},{value:"64800",name:"18 hours"},{value:"86400",name:"1 day"},{value:"172800",name:"2 days"},{value:"259200",name:"3 days"},{value:"604800",name:"1 week"}],sg=(t,e=[],i=[],o=[])=>{const{router:n,exits:s}=He("@input.text",t,Qu,e,i,o),r=e.find(t=>"No Response"===t.name||"Timeout"===t.name);if(r){const t=i.find(t=>t.uuid===r.exit_uuid);t&&(n.categories.push(r),s.push({uuid:t.uuid,destination_uuid:t.destination_uuid||null}))}return{router:n,exits:s}},rg={type:"wait_for_response",name:"Wait for Response",group:jp.wait,flowTypes:[Np],hideFromSplits:!0,dialogSize:"large",form:{rules:Dm(Ju(Gu()),"If the message from the contact..."),timeout_enabled:{type:"checkbox",label:t=>t.timeout_enabled?"Continue when there is no response for":"Continue when there is no response..",labelPadding:"4px 8px"},timeout_duration:{type:"select",placeholder:"5 minutes",multi:!1,maxWidth:"130px",flavor:"xsmall",options:ng,conditions:{visible:t=>!0===t.timeout_enabled}},result_name:tp,localizeRules:ep,localizeCategories:ip},layout:["rules",np],gutter:[{type:"row",items:["timeout_enabled","timeout_duration"],gap:"0.5rem"}],validate:hp(()=>{}),toFormData:(t,e)=>{var i,o,n,s,r,a;const l=Tm(t),d=null===(n=null===(o=null===(i=t.router)||void 0===i?void 0:i.wait)||void 0===o?void 0:o.timeout)||void 0===n?void 0:n.seconds;let c=ng.find(t=>t.value===String(d));return c||(c={value:"300",name:"5 minutes"}),{uuid:t.uuid,rules:l,timeout_enabled:!!d,timeout_duration:c,result_name:(null===(s=t.router)||void 0===s?void 0:s.result_name)||"",localizeRules:(null===(r=null==e?void 0:e.config)||void 0===r?void 0:r.localizeRules)||!1,localizeCategories:(null===(a=null==e?void 0:e.config)||void 0===a?void 0:a.localizeCategories)||!1}},toUIConfig:t=>{const e={};return e.localizeRules=!!t.localizeRules,e.localizeCategories=!!t.result_name&&!!t.localizeCategories,e},fromFormData:(t,e)=>{var i,o,n,s,r,a,l,d;const c=Em(t);if(0===c.length){let o=(null===(i=e.router)||void 0===i?void 0:i.categories)||[];const n=[...e.exits||[]];if(t.timeout_enabled){let t=o.find(t=>"No Response"===t.name);if(!t){const e=Xt();t={uuid:Xt(),name:"No Response",exit_uuid:e},o=[...o,t],n.find(t=>t.uuid===e)||n.push({uuid:e,destination_uuid:null})}}else o=o.filter(t=>"No Response"!==t.name);const{router:s,exits:r}=sg([],o,n,[]),a={...s,cases:[]};t.result_name&&""!==t.result_name.trim()&&(a.result_name=t.result_name.trim());const l={type:"msg"};if(t.timeout_enabled){let e;e=t.timeout_duration?Array.isArray(t.timeout_duration)&&t.timeout_duration.length>0?parseInt(t.timeout_duration[0].value,10):"string"==typeof t.timeout_duration?parseInt(t.timeout_duration,10):t.timeout_duration&&"object"==typeof t.timeout_duration&&t.timeout_duration.value?parseInt(t.timeout_duration.value,10):300:300,(isNaN(e)||e<=0)&&(e=300);const i=a.categories.find(t=>"No Response"===t.name);i&&(l.timeout={seconds:e,category_uuid:i.uuid})}return a.wait=l,{...e,router:a,exits:r}}const h=(null===(o=e.router)||void 0===o?void 0:o.categories)||[],u=e.exits||[],p=(null===(n=e.router)||void 0===n?void 0:n.cases)||[],{router:m,exits:g}=sg(c,h,u,p),f={...m};t.result_name&&""!==t.result_name.trim()&&(f.result_name=t.result_name.trim());const v={type:"msg"};try{if(t.timeout_enabled){let i;if(t.timeout_duration)try{i=parseInt(t.timeout_duration[0].value,10)}catch(t){i=300}const o=null===(r=null===(s=e.router)||void 0===s?void 0:s.categories)||void 0===r?void 0:r.find(t=>"No Response"===t.name),n=o||{uuid:Xt(),name:"No Response",exit_uuid:Xt()};if(v.timeout={seconds:i,category_uuid:n.uuid},!(null===(a=m.categories)||void 0===a?void 0:a.some(t=>"No Response"===t.name))&&(m.categories=m.categories||[],m.categories.push(n),!g.some(t=>t.uuid===n.exit_uuid))){const t={uuid:n.exit_uuid,destination_uuid:(null==o?void 0:o.exit_uuid)&&(null===(d=null===(l=e.exits)||void 0===l?void 0:l.find(t=>t.uuid===o.exit_uuid))||void 0===d?void 0:d.destination_uuid)||null};g.push(t)}}else if(m.categories){const t=m.categories.findIndex(t=>"No Response"===t.name);if(-1!==t){const e=m.categories[t];m.categories.splice(t,1);const i=g.findIndex(t=>t.uuid===e.exit_uuid);-1!==i&&g.splice(i,1)}}}catch(t){console.error("Error processing timeout configuration:",t)}return f.wait=v,{...e,router:f,exits:g}},localizable:"categories",nonTranslatableCategories:["Timeout"]},ag=lg({say_msg:pm,play_audio:mm,set_contact_field:Yp,send_broadcast:Qp,set_run_result:Jp,send_msg:em,send_email:im,start_session:om,set_contact_name:nm,add_contact_groups:sm,remove_contact_groups:rm,set_contact_channel:Kp,set_contact_language:Gp,set_contact_status:Xp,add_contact_urn:Zp,add_input_labels:Vp,request_optin:am,enter_flow:vm});function lg(t){const e={...t};return Object.values(t).forEach(t=>{t.aliases&&t.aliases.forEach(i=>{e[i]=t})}),e}const dg=lg({execute_actions:{type:"execute_actions"},split_by_contact_field:zm,split_by_expression:Im,split_by_groups:Lm,split_by_llm:Ym,split_by_llm_categorize:Km,split_by_random:Om,split_by_run_result:Nm,split_by_scheme:Fm,split_by_subflow:qm,split_by_ticket:Um,split_by_webhook:Vm,split_by_resthook:Zm,wait_for_menu:og,wait_for_digits:tg,wait_for_audio:Gm,wait_for_dial:Jm,wait_for_response:rg,split_by_airtime:xm,terminal:{type:"terminal"}}),cg="__primary_language__";class hg extends Ye{constructor(){super(...arguments),this.messageView=!1,this.zoom=1,this.zoomInitialized=!1,this.zoomFitted=!1,this.revisionsActive=!1,this.isSaving=!1,this.searchDisabled=!1,this.languageOptions=[],this.currentLanguageName="",this.isBaseLanguage=!0,this.languagePercent=0,this.showLocalizationTools=!1,this.canMakeDefault=!1,this.hasPendingTranslations=!1,this.autoTranslateDisabled=!1,this.autoTranslating=!1,this.showLanguageOptions=!1}static get styles(){return d`
|
|
11241
11272
|
:host {
|
|
11242
11273
|
display: block;
|
|
11243
11274
|
}
|
|
@@ -11415,6 +11446,11 @@ background: #ccc;
|
|
|
11415
11446
|
color: #1a7f37;
|
|
11416
11447
|
}
|
|
11417
11448
|
|
|
11449
|
+
.toolbar-btn.make-default {
|
|
11450
|
+
width: var(--toolbar-translation-control-height);
|
|
11451
|
+
height: var(--toolbar-translation-control-height);
|
|
11452
|
+
}
|
|
11453
|
+
|
|
11418
11454
|
.toolbar-zoom-level {
|
|
11419
11455
|
font-size: 12px;
|
|
11420
11456
|
min-width: 40px;
|
|
@@ -11521,6 +11557,7 @@ background: #ccc;
|
|
|
11521
11557
|
min-width="230"
|
|
11522
11558
|
></temba-options>
|
|
11523
11559
|
</div>
|
|
11560
|
+
${this.canMakeDefault?this.renderMakeDefaultButton():""}
|
|
11524
11561
|
${this.showLocalizationTools?this.renderTranslationTools():""}
|
|
11525
11562
|
</div>
|
|
11526
11563
|
`:""}
|
|
@@ -11600,7 +11637,15 @@ background: #ccc;
|
|
|
11600
11637
|
`)}
|
|
11601
11638
|
</div>
|
|
11602
11639
|
</div>
|
|
11603
|
-
`}
|
|
11640
|
+
`}renderMakeDefaultButton(){return this.renderTip(`Make ${this.currentLanguageName} the default`,Z`
|
|
11641
|
+
<button
|
|
11642
|
+
class="toolbar-btn language-tool make-default"
|
|
11643
|
+
@click=${()=>this.fireToolbarAction("make-default-language")}
|
|
11644
|
+
aria-label="Make default language"
|
|
11645
|
+
>
|
|
11646
|
+
<temba-icon name=${Io.language_default} size="1"></temba-icon>
|
|
11647
|
+
</button>
|
|
11648
|
+
`)}renderTranslationTools(){if(!this.hasPendingTranslations&&!this.autoTranslating)return Z``;const t=this.autoTranslating?"Stop auto translate":"Auto translate";return Z`
|
|
11604
11649
|
<div class="toolbar-translation">
|
|
11605
11650
|
${this.renderTip(t,Z`
|
|
11606
11651
|
<button
|
|
@@ -11617,7 +11662,7 @@ background: #ccc;
|
|
|
11617
11662
|
</button>
|
|
11618
11663
|
`)}
|
|
11619
11664
|
</div>
|
|
11620
|
-
`}}function ug(t,e){if(!t||!(null==e?void 0:e.length))return[];const i=dg[t],o=null==i?void 0:i.nonTranslatableCategories;if(!o)return[...e];if("all"===o)return e.filter(t=>te.has(t.name));const n=new Set(o);return e.filter(t=>!n.has(t.name)||te.has(t.name))}function pg(t){if(null==t)return null;if(Array.isArray(t)){const e=t.map(t=>pg(t)).filter(t=>!!t);return e.length>0?e.join(", "):null}if("object"==typeof t)return"name"in t&&t.name?String(t.name):"arguments"in t&&Array.isArray(t.arguments)?t.arguments.join(" "):null;if("number"==typeof t)return t.toString();if("string"==typeof t){const e=t.trim();return e.length>0?e:null}return null}function mg(t,e,i,o,n){const s=[];return i.forEach(i=>{if("quick_replies"===i)return;const r=i.split(".");let a=o,l=[];for(;r.length>0&&a;){a.uuid&&(l=n[a.uuid]);const t=r.shift();if(!t)break;l&&(l=l[t]),a=a[t]}if(!a)return;const d=pg(a);if(!d)return;const c=l?pg(l):null,h=t=>Array.isArray(t)?t.map(t=>null==t?"":String(t)):null==t?[]:[String(t)],u=h(a),p=null!=l?h(l):null;s.push({uuid:e,type:t,attribute:i,from:d,to:c,fromValues:u,toValues:p})}),s}function gg(t,e){var i;if(!t||!e||e===t.language)return[];const o=(null===(i=t.localization)||void 0===i?void 0:i[e])||{},n=[];return t.nodes.forEach(e=>{var i,s,r,a,l,d,c,h,u;null===(i=e.actions)||void 0===i||i.forEach(t=>{const i=ag[t.type];if(!(null==i?void 0:i.localizable)||0===i.localizable.length)return;const s="send_msg"===t.type?i.localizable.filter(t=>"text"===t):i.localizable,r=mg("property",t.uuid,s,t,o);r.length>0&&n.push({nodeUuid:e.uuid,actionUuid:t.uuid,translations:r})});const p=null===(r=null===(s=t._ui)||void 0===s?void 0:s.nodes)||void 0===r?void 0:r[e.uuid],m=null==p?void 0:p.type;if(!m)return;if((null===(a=null==p?void 0:p.config)||void 0===a?void 0:a.localizeRules)&&(null===(d=null===(l=e.router)||void 0===l?void 0:l.cases)||void 0===d?void 0:d.length)){const t=e.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).flatMap(t=>mg("property",t.uuid,["arguments"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}const g=dg[m];if((null===(c=null==p?void 0:p.config)||void 0===c?void 0:c.localizeCategories)&&"categories"===(null==g?void 0:g.localizable)&&(null===(u=null===(h=e.router)||void 0===h?void 0:h.categories)||void 0===u?void 0:u.length)){const t=ug(m,e.router.categories).flatMap(t=>mg("category",t.uuid,["name"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}}),n}i([ft({type:Boolean,attribute:"message-view"})],hg.prototype,"messageView",void 0),i([ft({type:Number})],hg.prototype,"zoom",void 0),i([ft({type:Boolean,attribute:"zoom-initialized"})],hg.prototype,"zoomInitialized",void 0),i([ft({type:Boolean,attribute:"zoom-fitted"})],hg.prototype,"zoomFitted",void 0),i([ft({type:Boolean,attribute:"revisions-active"})],hg.prototype,"revisionsActive",void 0),i([ft({type:Boolean,attribute:"is-saving"})],hg.prototype,"isSaving",void 0),i([ft({type:Boolean,attribute:"search-disabled"})],hg.prototype,"searchDisabled",void 0),i([ft({type:Array})],hg.prototype,"languageOptions",void 0),i([ft({type:String,attribute:"current-language-name"})],hg.prototype,"currentLanguageName",void 0),i([ft({type:Boolean,attribute:"is-base-language"})],hg.prototype,"isBaseLanguage",void 0),i([ft({type:Number,attribute:"language-percent"})],hg.prototype,"languagePercent",void 0),i([ft({type:Boolean,attribute:"show-localization-tools"})],hg.prototype,"showLocalizationTools",void 0),i([ft({type:Boolean,attribute:"has-pending-translations"})],hg.prototype,"hasPendingTranslations",void 0),i([ft({type:Boolean,attribute:"auto-translate-disabled"})],hg.prototype,"autoTranslateDisabled",void 0),i([ft({type:Boolean,attribute:"auto-translating"})],hg.prototype,"autoTranslating",void 0),i([vt()],hg.prototype,"showLanguageOptions",void 0);const fg=60,vg=20;function bg(t,e,i,o){if(0===t.length)return{};const n=new Set(t.map(t=>t.uuid)),s=new Map,r=new Map;for(const e of t){const t=new Set,i=[];for(const o of e.exits)if(o.destination_uuid&&n.has(o.destination_uuid)&&!t.has(o.destination_uuid)){t.add(o.destination_uuid),i.push(o.destination_uuid);const n=r.get(o.destination_uuid)||[];n.push(e.uuid),r.set(o.destination_uuid,n)}s.set(e.uuid,i)}const a=function(t,e){const i=new Set,o=new Set,n=new Set;function s(t){o.add(t),n.add(t);for(const r of e.get(t)||[])o.has(r)?i.add(`${t}->${r}`):n.has(r)||s(r);o.delete(t)}return s(t),i}(i,s),l=function(t,e,i,o,n){const s=new Map;s.set(t,0);const r=new Map;for(const t of e)r.set(t.uuid,0);for(const[t,e]of i)for(const i of e)n.has(`${t}->${i}`)||r.set(i,(r.get(i)||0)+1);const a=[];for(const[t,e]of r)0===e&&(a.push(t),s.has(t)||s.set(t,0));for(;a.length>0;){const t=a.shift(),e=s.get(t);for(const o of i.get(t)||[]){if(n.has(`${t}->${o}`))continue;const i=e+1;(!s.has(o)||i>s.get(o))&&s.set(o,i);const l=r.get(o)-1;r.set(o,l),0===l&&a.push(o)}}const l=e.filter(t=>!s.has(t.uuid));if(l.length>0){let t=Math.max(...Array.from(s.values()),-1)+2;for(const e of l)s.set(e.uuid,t),t++}return s}(i,t,s,0,a),d=new Map;for(const[t,e]of l){const i=d.get(e)||[];i.push(t),d.set(e,i)}const c=Array.from(d.keys()).sort((t,e)=>t-e);!function(t,e,i,o){const n=new Map;for(const s of t){const r=e.get(s);if(s===t[0]){r.forEach((t,e)=>n.set(t,e));continue}const a=r.map(t=>{const e=(i.get(t)||[]).filter(t=>{const e=o.get(t);return void 0!==e&&e<s});if(0===e.length)return{uuid:t,value:1/0};const r=e.reduce((t,e)=>{var i;return t+(null!==(i=n.get(e))&&void 0!==i?i:0)},0);return{uuid:t,value:r/e.length}});a.sort((t,e)=>t.value-e.value);const l=a.map(t=>t.uuid);e.set(s,l),l.forEach((t,e)=>n.set(t,e))}}(c,d,r,l);const h=new Map;for(const e of t)h.set(e.uuid,o(e.uuid));return function(t,e,i,o,n,s){var r,a,l,d;const c={};let h=0;for(const u of t){const p=yg(e.get(u),i);for(const e of p){const p=vp(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:vp(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+fg}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=fg*(e.length-1);const s=[];for(const t of e){const e=(o.get(t)||[]).filter(t=>{const e=n.get(t);return void 0!==e&&e<u});for(const t of e){const e=c[t];if(e){const o=(null===(l=i.get(t))||void 0===l?void 0:l.width)||200;s.push(e.left+o/2)}}}let r;if(s.length>0){const e=(Math.min(...s)+Math.max(...s))/2;r=Math.max(0,e-t/2)}else r=0;let h=r;for(const t of e){const e=(null===(d=i.get(t))||void 0===d?void 0:d.width)||200;c[t]={left:vp(h),top:p},h=vp(h)+e+fg}}const m=Math.max(...e.map(t=>{var e;return(null===(e=i.get(t))||void 0===e?void 0:e.height)||100}));h=p+m+80}}const u=c[s];if(u){const t=u.left,e=u.top;for(const i of Object.keys(c))c[i]={left:vp(Math.max(0,c[i].left-t)),top:vp(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function yg(t,e){var i;const o=[];let n=[],s=0;for(const r of t){const t=(null===(i=e.get(r))||void 0===i?void 0:i.width)||200,a=n.length>0?fg+t:t;n.length>0&&s+a>1200?(o.push(n),n=[r],s=t):(n.push(r),s+=a)}return n.length>0&&o.push(n),o}function xg(t,e,i,o,n){for(const s of n)if(t<s.left+s.width+vg&&t+i+vg>s.left&&e<s.top+s.height+vg&&e+o+vg>s.top)return!0;return!1}function wg(t){if("touches"in t){const e=t.touches[0]||t.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}}return{clientX:t.clientX,clientY:t.clientY}}function _g(t,e,i,o,n=20,s=10,r=5,a="top",l=0){const d=r;if("top"===a){const r=e+n,a=o-s;let c=`M ${t} ${e}`;if(t===i)c+=` L ${i} ${a}`;else{const o=i>t?1:-1,n=Math.max(e+d,Math.min(r,a-d)),s=Math.max(e+d,Math.min(n+l,a-d-3)),h=Math.min(d,s-e);h>=1?(c+=` L ${t} ${s-h}`,c+=` Q ${t} ${s}, ${t+o*h} ${s}`):c+=` L ${t} ${s}`;const u=3,p=Math.min(d,Math.max(0,a-s-u));p>=1?(c+=` L ${i-o*p} ${s}`,c+=` Q ${i} ${s}, ${i} ${s+p}`):c+=` L ${i} ${s}`,c+=` L ${i} ${a}`}return c+=` L ${i} ${o}`,c}if("left"===a||"right"===a){const r=e+(o<e?0:n),l="left"===a?-1:1,c=i+l*s,h=c>t?1:-1,u=3,p=h===l?r+2*d:Math.max(r+2*d,o);let m=`M ${t} ${e} L ${t} ${r}`;p-r>d&&(m+=` L ${t} ${p-d}`,m+=` Q ${t} ${p}, ${t+h*d} ${p}`);const g=Math.abs(p-o);if(g<1)m+=` L ${c} ${o}`,m+=` L ${i} ${o}`;else{const t=o<p?-1:1,e=Math.min(d,Math.max(0,Math.floor((g-u)/2)),Math.max(0,s-u));e>=1?(m+=` L ${c-h*e} ${p}`,m+=` Q ${c} ${p}, ${c} ${p+t*e}`,m+=` L ${c} ${o-t*e}`,m+=` Q ${c} ${o}, ${c-l*e} ${o}`):(m+=` L ${c} ${p}`,m+=` L ${c} ${o}`),m+=` L ${i} ${o}`}return m}return`M ${t} ${e} L ${i} ${o}`}class kg{constructor(t,e){this.connections=new Map,this.sources=new Map,this.pendingConnections=[],this.connectionWait=null,this.connectionListeners=new Map,this.dragState=null,this.retryCount=0,this.maxRetries=3,this.activityData=null,this.overlays=new Map,this.hoveredActivityKey=null,this.recentContactsPopup=null,this.recentContactsCache={},this.pendingFetches={},this.hideContactsTimeout=null,this.showContactsTimeout=null,this.connectionDragging=!1,this.zoom=1,this.canvas=t,this.editor=e}setContainer(t){this.canvas=t}notifyListeners(t,e){(this.connectionListeners.get(t)||[]).forEach(t=>t(e))}on(t,e){this.connectionListeners.has(t)||this.connectionListeners.set(t,[]),this.connectionListeners.get(t).push(e)}off(t,e){if(!this.connectionListeners.has(t))return;const i=this.connectionListeners.get(t),o=i.indexOf(e);-1!==o&&i.splice(o,1)}makeSource(t){const e=document.getElementById(t);if(!e)return;this.sources.has(t)&&this.sources.get(t)();let i=null;const o=o=>{if("button"in o&&gp(o))return;if(this.connections.has(t))return;const n="touches"in o;n&&o.preventDefault();const{clientX:s,clientY:r}=wg(o),a=e.closest("temba-flow-node"),l=(null==a?void 0:a.getAttribute("uuid"))||"",d=e=>{const{clientX:i,clientY:o}=wg(e),n=i-s,a=o-r;Math.sqrt(n*n+a*a)>5&&(h(),this.startDrag(t,l,null,e))},c=()=>{h()},h=()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",c),document.removeEventListener("touchcancel",c),i=null};document.addEventListener("mousemove",d),document.addEventListener("mouseup",c),document.addEventListener("touchmove",d,{passive:!1}),document.addEventListener("touchend",c),document.addEventListener("touchcancel",c),i={startX:s,startY:r,onMove:d,onUp:c,isTouch:n}};e.addEventListener("mousedown",o),e.addEventListener("touchstart",o,{passive:!1}),this.sources.set(t,()=>{e.removeEventListener("mousedown",o),e.removeEventListener("touchstart",o),i&&(document.removeEventListener("mousemove",i.onMove),document.removeEventListener("mouseup",i.onUp),document.removeEventListener("touchmove",i.onMove),document.removeEventListener("touchend",i.onUp),document.removeEventListener("touchcancel",i.onUp),i=null)})}makeTarget(t){}connectIds(t,e,i){this.pendingConnections.push({scope:t,fromId:e,toId:i}),this.processPendingConnections()}processPendingConnections(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.connectionWait=requestAnimationFrame(()=>{const t=[],e=new Set;if(this.pendingConnections.forEach(i=>{const{scope:o,fromId:n,toId:s}=i;this.removeConnectionSVG(n),this.createConnectionSVG(n,o,s)?e.add(s):t.push(i)}),this.pendingConnections=[],e.size>0){const t=new Set;this.connections.forEach(i=>{e.has(i.toId)&&t.add(i.scope)}),this.connections.forEach((i,o)=>{(e.has(i.toId)||t.has(i.scope))&&this.updateConnectionSVG(o)})}t.length>0&&this.retryCount<this.maxRetries?(this.retryCount++,this.pendingConnections=t,this.processPendingConnections()):this.retryCount=0})}toCanvas(t){return t/this.zoom}determineTargetFace(t,e,i,o){return o-e>30?"top":t<i?"left":"right"}getConnectionEndpoints(t,e,i){const o=document.getElementById(t),n=document.getElementById(e);if(!o||!n)return null;const s=this.canvas.getBoundingClientRect(),r=o.getBoundingClientRect(),a=n.getBoundingClientRect();if(0===r.width||0===a.width)return null;const l=this.toCanvas(r.left+r.width/2-s.left),d=this.toCanvas(r.bottom-s.top),c=this.toCanvas(a.left+a.width/2-s.left),h=this.toCanvas(a.top-s.top),u=this.determineTargetFace(l,d,c,h),p=new Map;this.connections.forEach(t=>{if(t.toId===e){const e=document.getElementById(t.fromId);if(e){const i=e.getBoundingClientRect(),o=this.toCanvas(i.left+i.width/2-s.left),n=this.toCanvas(i.bottom-s.top),r=this.determineTargetFace(o,n,c,h);p.has(r)||p.set(r,[]);const a="top"===r?o:n;p.get(r).push({fromId:t.fromId,sortPos:a})}}}),p.has(u)||p.set(u,[]);const m=p.get(u);if(!m.find(e=>e.fromId===t)){const e="top"===u?l:d;m.push({fromId:t,sortPos:e})}m.sort((t,e)=>t.sortPos-e.sortPos);const g=m.findIndex(e=>e.fromId===t),f=m.length,v=this.toCanvas(a.left-s.left),b=h,y=this.toCanvas(a.width),x=this.toCanvas(a.height);let w,_;if("top"===u){w=1===f?v+y/2:v+.2*y+.6*y*(g+.5)/f,_=b}else if("left"===u){w=v;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}else{w=v+y;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}let k=0;if("top"===u&&i){const o=8,n=50,r=[];if(this.connections.forEach(t=>{if(t.scope===i&&t.toId!==e){const e=document.getElementById(t.fromId),i=document.getElementById(t.toId);if(e&&i){const o=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=this.toCanvas(o.left+o.width/2-s.left),l=this.toCanvas(o.bottom-s.top),d=this.toCanvas(n.left+n.width/2-s.left),c=this.toCanvas(n.top-s.top);if("top"===this.determineTargetFace(a,l,d,c)){const e=this.toCanvas(n.left-s.left),i=this.toCanvas(n.width);r.push({fromId:t.fromId,targetX:e+i/2})}}}}),r.length>0){r.push({fromId:t,targetX:w}),r.sort((t,e)=>t.targetX-e.targetX);const e=r.findIndex(e=>e.fromId===t),i=r.length;k=(e-(i-1)/2)*((i-1)*o>n?n/(i-1):o)}}return{sourceX:l,sourceY:d,targetX:w,targetY:_,targetFace:u,jogYOffset:k}}createSVGElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("plumb-connector"),t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.overflow="visible";const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke","var(--color-connectors)"),e.setAttribute("stroke-width","3"),e.style.pointerEvents="stroke";const i=document.createElementNS("http://www.w3.org/2000/svg","polygon");i.setAttribute("fill","var(--color-connectors)"),i.classList.add("plumb-arrow"),i.style.pointerEvents="fill",i.style.cursor="pointer";const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("r","18"),o.setAttribute("fill","transparent"),o.style.pointerEvents="fill",o.style.cursor="pointer",t.appendChild(e),t.appendChild(o),t.appendChild(i);const n=()=>t.classList.add("hover"),s=()=>t.classList.remove("hover");return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",s),i.addEventListener("mouseenter",n),i.addEventListener("mouseleave",s),o.addEventListener("mouseenter",n),o.addEventListener("mouseleave",s),{svgEl:t,pathEl:e,arrowEl:i,hitAreaEl:o}}updateSVGPath(t,e,i,o,n,s,r="top",a=0,l){const d=6.5,c=13;let h=n,u=s;"top"===r?u=s-c:"left"===r?h=n-c:"right"===r&&(h=n+c);const p=_g(i,o,h,u,30,8,5,r,a);if(t.setAttribute("d",p),"top"===r?e.setAttribute("points",`${n},${s} ${n-d},${s-c} ${n+d},${s-c}`):"left"===r?e.setAttribute("points",`${n},${s} ${n-c},${s-d} ${n-c},${s+d}`):e.setAttribute("points",`${n},${s} ${n+c},${s-d} ${n+c},${s+d}`),l){const t=6.5;let e=n,i=s;"top"===r?i=s-t:e="left"===r?n-t:n+t,l.setAttribute("cx",String(e)),l.setAttribute("cy",String(i))}}createConnectionSVG(t,e,i){const o=this.getConnectionEndpoints(t,i,e);if(!o)return!1;const{svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a}=this.createSVGElement();this.updateSVGPath(s,r,o.sourceX,o.sourceY,o.targetX,o.targetY,o.targetFace,o.jogYOffset,a),this.canvas.appendChild(n),this.connections.set(t,{scope:e,fromId:t,toId:i,svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a});const l=o=>{if("button"in o&&gp(o))return;o.stopPropagation(),"touches"in o&&o.preventDefault();const{clientX:n,clientY:s}=wg(o),r=o=>{const{clientX:l,clientY:d}=wg(o),c=l-n,h=d-s;Math.sqrt(c*c+h*h)>5&&(document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a),this.startDrag(t,e,i,o))},a=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a)};document.addEventListener("mousemove",r),document.addEventListener("mouseup",a),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",a),document.addEventListener("touchcancel",a)};r.addEventListener("mousedown",l),r.addEventListener("touchstart",l,{passive:!1}),a.addEventListener("mousedown",l),a.addEventListener("touchstart",l,{passive:!1}),s.addEventListener("mousedown",l),s.addEventListener("touchstart",l,{passive:!1});const d=document.getElementById(t);if(d&&d.classList.add("connected"),this.activityData){const e=`${t}:${i}`,o=this.activityData.segments[e];if(o&&o>0){const i=this.createOverlayElement(o,e);this.canvas.appendChild(i),this.overlays.set(t,i),this.updateOverlayPosition(t)}}return!0}updateConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.getConnectionEndpoints(e.fromId,e.toId,e.scope);i&&(this.updateSVGPath(e.pathEl,e.arrowEl,i.sourceX,i.sourceY,i.targetX,i.targetY,i.targetFace,i.jogYOffset,e.hitAreaEl),this.updateOverlayPosition(t))}removeConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.overlays.get(t);i&&(i.remove(),this.overlays.delete(t)),e.svgEl.remove(),this.connections.delete(t)}repaintEverything(){this.connections.forEach((t,e)=>{this.updateConnectionSVG(e)})}revalidate(t){const e=[],i=new Set;this.connections.forEach((o,n)=>{(t.includes(o.fromId)||t.includes(o.toId)||t.includes(o.scope))&&(e.push(n),i.add(o.toId))});const o=new Set(e);this.connections.forEach((t,e)=>{i.has(t.toId)&&o.add(e)}),o.forEach(t=>{this.updateConnectionSVG(t)})}forgetNode(t){var e;const i=[];this.connections.forEach((e,o)=>{e.scope!==t&&e.toId!==t||i.push(o)}),i.forEach(t=>this.removeConnectionSVG(t));const o=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");o&&o.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}removeNodeConnections(t,e){var i;(e||Array.from((null===(i=document.getElementById(t))||void 0===i?void 0:i.querySelectorAll(".exit"))||[]).map(t=>t.id)).forEach(t=>this.removeConnectionSVG(t))}removeExitConnection(t){return!!this.connections.has(t)&&(this.removeConnectionSVG(t),!0)}removeAllEndpoints(t){var e;const i=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");i&&i.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}setConnectionRemovingState(t,e){const i=this.connections.get(t);return!!i&&(e?i.svgEl.classList.add("removing"):i.svgEl.classList.remove("removing"),!0)}setActivityData(t){this.activityData=t,this.clearRecentContactsCache(),this.updateActivityOverlays()}updateActivityOverlays(){if(!this.activityData)return this.overlays.forEach(t=>t.remove()),void this.overlays.clear();const t=new Set;this.connections.forEach((e,i)=>{const o=`${e.fromId}:${e.toId}`,n=this.activityData.segments[o];if(n&&n>0){t.add(i);let e=this.overlays.get(i);e?(e.textContent=n.toLocaleString(),e.setAttribute("data-activity-key",o)):(e=this.createOverlayElement(n,o),this.canvas.appendChild(e),this.overlays.set(i,e)),this.updateOverlayPosition(i)}}),this.overlays.forEach((e,i)=>{t.has(i)||(e.remove(),this.overlays.delete(i))})}createOverlayElement(t,e){const i=document.createElement("div");return i.className="activity-overlay",i.textContent=t.toLocaleString(),i.setAttribute("data-activity-key",e),i.addEventListener("mouseenter",()=>{const t=this.getFlowUuid();t&&(this.fetchRecentContacts(e,t),this.showContactsTimeout=window.setTimeout(()=>{this.showRecentContacts(e,t)},500))}),i.addEventListener("mouseleave",()=>{this.showContactsTimeout&&(clearTimeout(this.showContactsTimeout),this.showContactsTimeout=null),this.hoveredActivityKey=null,this.hideRecentContacts()}),i}updateOverlayPosition(t){const e=this.overlays.get(t),i=this.connections.get(t);if(!e||!i)return;const o=this.getConnectionEndpoints(i.fromId,i.toId,i.scope);o&&(e.style.position="absolute",e.style.left=`${o.sourceX}px`,e.style.top=`${o.sourceY+15}px`,e.style.transform="translate(-50%, -50%)")}getFlowUuid(){var t,e;return(null===(e=null===(t=this.editor)||void 0===t?void 0:t.definition)||void 0===e?void 0:e.uuid)||null}async fetchRecentContacts(t,e){if(this.recentContactsCache[t]||this.pendingFetches[t])return;const i=new AbortController;this.pendingFetches[t]=i;try{const[o,n]=t.split(":"),s=`/flow/recent_contacts/${e}/${o}/${n}/`,r=await fetch(s,{signal:i.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const a=await r.json();this.recentContactsCache[t]=Array.isArray(a)?a:a.results||[]}catch(t){"AbortError"!==t.name&&console.error("Failed to fetch recent contacts:",t)}finally{delete this.pendingFetches[t]}}async showRecentContacts(t,e){const i=this.findOverlayForActivityKey(t);i&&(this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null),this.hoveredActivityKey=t,this.recentContactsPopup||(this.recentContactsPopup=document.createElement("div"),this.recentContactsPopup.className="recent-contacts-popup",this.recentContactsPopup.style.position="absolute",this.recentContactsPopup.style.zIndex="1015",this.recentContactsPopup.style.display="none",document.body.appendChild(this.recentContactsPopup),this.recentContactsPopup.onmouseenter=()=>{this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null)},this.recentContactsPopup.onmouseleave=()=>{this.hoveredActivityKey=null,this.hideRecentContacts()},this.recentContactsPopup.onclick=t=>{const e=t.target;if(e.classList.contains("contact-name")){this.hideRecentContacts(!1);const i=e.getAttribute("data-uuid");i&&this.editor.fireCustomEvent("temba-contact-clicked",{uuid:i,metaKey:t.metaKey,ctrlKey:t.ctrlKey})}}),this.recentContactsCache[t]?(this.renderRecentContactsPopup(this.recentContactsCache[t]),this.positionPopup(i)):(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">Loading...</div>',this.positionPopup(i),await this.fetchRecentContacts(t,e),this.hoveredActivityKey===t&&(this.renderRecentContactsPopup(this.recentContactsCache[t]||[]),this.positionPopup(i))))}findOverlayForActivityKey(t){for(const[,e]of this.overlays)if(e.getAttribute("data-activity-key")===t)return e;return null}positionPopup(t){if(!this.recentContactsPopup)return;const e=t.getBoundingClientRect();this.recentContactsPopup.style.left=`${e.left+window.scrollX}px`,this.recentContactsPopup.style.top=`${e.bottom+window.scrollY+5}px`,this.recentContactsPopup.style.display="",this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.offsetWidth,this.recentContactsPopup.classList.add("show")}renderRecentContactsPopup(t){if(!this.recentContactsPopup)return;if(0===t.length)return void(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">No Recent Contacts</div>');let e='<div class="popup-title">Recent Contacts</div>';t.forEach(t=>{if(e+='<div class="contact-row">',e+=`<div class="contact-name" data-uuid="${t.contact.uuid}">${t.contact.name}</div>`,t.operand&&(e+=`<div class="contact-operand">${t.operand}</div>`),t.time){const i=new Date(t.time),o=Date.now()-i.getTime(),n=Math.floor(o/6e4),s=Math.floor(o/36e5),r=Math.floor(o/864e5);let a="";a=n<1?"just now":n<60?`${n}m ago`:s<24?`${s}h ago`:`${r}d ago`,e+=`<div class="contact-time">${a}</div>`}e+="</div>"}),this.recentContactsPopup.innerHTML=e}hideRecentContacts(t=!0){t?this.hideContactsTimeout=window.setTimeout(()=>{!this.hoveredActivityKey&&this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)},200):this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)}clearRecentContactsCache(){this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={}}startDrag(t,e,i,o){const n=this.connections.get(t);if(n){n.svgEl.style.display="none";const e=this.overlays.get(t);e&&(e.style.display="none")}const{svgEl:s,pathEl:r,arrowEl:a,hitAreaEl:l}=this.createSVGElement();s.classList.add("dragging"),r.style.pointerEvents="none",a.style.pointerEvents="none",l.style.pointerEvents="none",this.canvas.appendChild(s);const d=document.getElementById(t);if(!d)return void s.remove();const c=this.canvas.getBoundingClientRect(),h=d.getBoundingClientRect(),u=this.toCanvas(h.left+h.width/2-c.left),p=this.toCanvas(h.bottom-c.top),m=6.5,g=(t,e)=>{const i=e<p;let o,n="top";i&&(n=t<u?"left":"right"),o=i?e+1+13:e-1;const s=_g(u,p,t,o,30,i?0:8,5,n);if(r.setAttribute("d",s),i){const i=e+1;a.setAttribute("points",`${t},${i} ${t-m},${o} ${t+m},${o}`)}else{const e=o+13;a.setAttribute("points",`${t},${e} ${t-m},${o} ${t+m},${o}`)}},{clientX:f,clientY:v}=wg(o),b=this.toCanvas(f-c.left),y=this.toCanvas(v-c.top);g(b,y),this.connectionDragging=!0;const x=t=>{"touches"in t&&t.preventDefault();const e=this.canvas.getBoundingClientRect(),{clientX:i,clientY:o}=wg(t),n=this.toCanvas(i-e.left),s=this.toCanvas(o-e.top);g(n,s)},w=o=>{document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w),document.removeEventListener("touchmove",x),document.removeEventListener("touchend",w),document.removeEventListener("touchcancel",w),s.remove(),this.removeConnectionSVG(t),this.connectionDragging=!1,this.dragState=null,this.notifyListeners("connection:abort",{source:d,sourceId:t,target:{id:i},data:{nodeId:e}})};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("touchend",w),document.addEventListener("touchcancel",w),this.dragState={sourceId:t,scope:e,originalTargetId:i,svgEl:s,pathEl:r,arrowEl:a,onMove:x,onUp:w},this.notifyListeners("connection:drag",{sourceId:t,sourceX:u,sourceY:p,data:{nodeId:e},target:{id:i}})}reset(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.pendingConnections=[],this.connections.forEach(t=>t.svgEl.remove()),this.connections.clear(),this.overlays.forEach(t=>t.remove()),this.overlays.clear(),this.hideRecentContacts(!1),this.recentContactsPopup&&(this.recentContactsPopup.remove(),this.recentContactsPopup=null),this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={},this.sources.forEach(t=>t()),this.sources.clear(),this.dragState&&(document.removeEventListener("mousemove",this.dragState.onMove),document.removeEventListener("mouseup",this.dragState.onUp),this.dragState.svgEl.remove(),this.dragState=null,this.connectionDragging=!1)}}class Cg extends Ye{createRenderRoot(){return this}static get styles(){return d`
|
|
11665
|
+
`}}function ug(t,e){if(!t||!(null==e?void 0:e.length))return[];const i=dg[t],o=null==i?void 0:i.nonTranslatableCategories;if(!o)return[...e];if("all"===o)return e.filter(t=>te.has(t.name));const n=new Set(o);return e.filter(t=>!n.has(t.name)||te.has(t.name))}function pg(t){if(null==t)return null;if(Array.isArray(t)){const e=t.map(t=>pg(t)).filter(t=>!!t);return e.length>0?e.join(", "):null}if("object"==typeof t)return"name"in t&&t.name?String(t.name):"arguments"in t&&Array.isArray(t.arguments)?t.arguments.join(" "):null;if("number"==typeof t)return t.toString();if("string"==typeof t){const e=t.trim();return e.length>0?e:null}return null}function mg(t,e,i,o,n){const s=[];return i.forEach(i=>{if("quick_replies"===i)return;const r=i.split(".");let a=o,l=[];for(;r.length>0&&a;){a.uuid&&(l=n[a.uuid]);const t=r.shift();if(!t)break;l&&(l=l[t]),a=a[t]}if(!a)return;const d=pg(a);if(!d)return;const c=l?pg(l):null,h=t=>Array.isArray(t)?t.map(t=>null==t?"":String(t)):null==t?[]:[String(t)],u=h(a),p=null!=l?h(l):null;s.push({uuid:e,type:t,attribute:i,from:d,to:c,fromValues:u,toValues:p})}),s}function gg(t,e){var i;if(!t||!e||e===t.language)return[];const o=(null===(i=t.localization)||void 0===i?void 0:i[e])||{},n=[];return t.nodes.forEach(e=>{var i,s,r,a,l,d,c,h,u;null===(i=e.actions)||void 0===i||i.forEach(t=>{const i=ag[t.type];if(!(null==i?void 0:i.localizable)||0===i.localizable.length)return;const s="send_msg"===t.type?i.localizable.filter(t=>"text"===t):i.localizable,r=mg("property",t.uuid,s,t,o);r.length>0&&n.push({nodeUuid:e.uuid,actionUuid:t.uuid,translations:r})});const p=null===(r=null===(s=t._ui)||void 0===s?void 0:s.nodes)||void 0===r?void 0:r[e.uuid],m=null==p?void 0:p.type;if(!m)return;if((null===(a=null==p?void 0:p.config)||void 0===a?void 0:a.localizeRules)&&(null===(d=null===(l=e.router)||void 0===l?void 0:l.cases)||void 0===d?void 0:d.length)){const t=e.router.cases.filter(t=>{var e;return(null===(e=t.arguments)||void 0===e?void 0:e.length)>0&&t.arguments.some(t=>t)}).flatMap(t=>mg("property",t.uuid,["arguments"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}const g=dg[m];if((null===(c=null==p?void 0:p.config)||void 0===c?void 0:c.localizeCategories)&&"categories"===(null==g?void 0:g.localizable)&&(null===(u=null===(h=e.router)||void 0===h?void 0:h.categories)||void 0===u?void 0:u.length)){const t=ug(m,e.router.categories).flatMap(t=>mg("category",t.uuid,["name"],t,o));t.length>0&&n.push({nodeUuid:e.uuid,translations:t})}}),n}i([ft({type:Boolean,attribute:"message-view"})],hg.prototype,"messageView",void 0),i([ft({type:Number})],hg.prototype,"zoom",void 0),i([ft({type:Boolean,attribute:"zoom-initialized"})],hg.prototype,"zoomInitialized",void 0),i([ft({type:Boolean,attribute:"zoom-fitted"})],hg.prototype,"zoomFitted",void 0),i([ft({type:Boolean,attribute:"revisions-active"})],hg.prototype,"revisionsActive",void 0),i([ft({type:Boolean,attribute:"is-saving"})],hg.prototype,"isSaving",void 0),i([ft({type:Boolean,attribute:"search-disabled"})],hg.prototype,"searchDisabled",void 0),i([ft({type:Array})],hg.prototype,"languageOptions",void 0),i([ft({type:String,attribute:"current-language-name"})],hg.prototype,"currentLanguageName",void 0),i([ft({type:Boolean,attribute:"is-base-language"})],hg.prototype,"isBaseLanguage",void 0),i([ft({type:Number,attribute:"language-percent"})],hg.prototype,"languagePercent",void 0),i([ft({type:Boolean,attribute:"show-localization-tools"})],hg.prototype,"showLocalizationTools",void 0),i([ft({type:Boolean,attribute:"can-make-default"})],hg.prototype,"canMakeDefault",void 0),i([ft({type:Boolean,attribute:"has-pending-translations"})],hg.prototype,"hasPendingTranslations",void 0),i([ft({type:Boolean,attribute:"auto-translate-disabled"})],hg.prototype,"autoTranslateDisabled",void 0),i([ft({type:Boolean,attribute:"auto-translating"})],hg.prototype,"autoTranslating",void 0),i([vt()],hg.prototype,"showLanguageOptions",void 0);const fg=60,vg=20;function bg(t,e,i,o){if(0===t.length)return{};const n=new Set(t.map(t=>t.uuid)),s=new Map,r=new Map;for(const e of t){const t=new Set,i=[];for(const o of e.exits)if(o.destination_uuid&&n.has(o.destination_uuid)&&!t.has(o.destination_uuid)){t.add(o.destination_uuid),i.push(o.destination_uuid);const n=r.get(o.destination_uuid)||[];n.push(e.uuid),r.set(o.destination_uuid,n)}s.set(e.uuid,i)}const a=function(t,e){const i=new Set,o=new Set,n=new Set;function s(t){o.add(t),n.add(t);for(const r of e.get(t)||[])o.has(r)?i.add(`${t}->${r}`):n.has(r)||s(r);o.delete(t)}return s(t),i}(i,s),l=function(t,e,i,o,n){const s=new Map;s.set(t,0);const r=new Map;for(const t of e)r.set(t.uuid,0);for(const[t,e]of i)for(const i of e)n.has(`${t}->${i}`)||r.set(i,(r.get(i)||0)+1);const a=[];for(const[t,e]of r)0===e&&(a.push(t),s.has(t)||s.set(t,0));for(;a.length>0;){const t=a.shift(),e=s.get(t);for(const o of i.get(t)||[]){if(n.has(`${t}->${o}`))continue;const i=e+1;(!s.has(o)||i>s.get(o))&&s.set(o,i);const l=r.get(o)-1;r.set(o,l),0===l&&a.push(o)}}const l=e.filter(t=>!s.has(t.uuid));if(l.length>0){let t=Math.max(...Array.from(s.values()),-1)+2;for(const e of l)s.set(e.uuid,t),t++}return s}(i,t,s,0,a),d=new Map;for(const[t,e]of l){const i=d.get(e)||[];i.push(t),d.set(e,i)}const c=Array.from(d.keys()).sort((t,e)=>t-e);!function(t,e,i,o){const n=new Map;for(const s of t){const r=e.get(s);if(s===t[0]){r.forEach((t,e)=>n.set(t,e));continue}const a=r.map(t=>{const e=(i.get(t)||[]).filter(t=>{const e=o.get(t);return void 0!==e&&e<s});if(0===e.length)return{uuid:t,value:1/0};const r=e.reduce((t,e)=>{var i;return t+(null!==(i=n.get(e))&&void 0!==i?i:0)},0);return{uuid:t,value:r/e.length}});a.sort((t,e)=>t.value-e.value);const l=a.map(t=>t.uuid);e.set(s,l),l.forEach((t,e)=>n.set(t,e))}}(c,d,r,l);const h=new Map;for(const e of t)h.set(e.uuid,o(e.uuid));return function(t,e,i,o,n,s){var r,a,l,d;const c={};let h=0;for(const u of t){const p=yg(e.get(u),i);for(const e of p){const p=vp(h);if(u===t[0]){let t=0;for(const o of e){const e=o===s?p:p+40;c[o]={left:vp(t),top:e},t+=((null===(r=i.get(o))||void 0===r?void 0:r.width)||200)+fg}}else{let t=0;for(const o of e)t+=(null===(a=i.get(o))||void 0===a?void 0:a.width)||200;t+=fg*(e.length-1);const s=[];for(const t of e){const e=(o.get(t)||[]).filter(t=>{const e=n.get(t);return void 0!==e&&e<u});for(const t of e){const e=c[t];if(e){const o=(null===(l=i.get(t))||void 0===l?void 0:l.width)||200;s.push(e.left+o/2)}}}let r;if(s.length>0){const e=(Math.min(...s)+Math.max(...s))/2;r=Math.max(0,e-t/2)}else r=0;let h=r;for(const t of e){const e=(null===(d=i.get(t))||void 0===d?void 0:d.width)||200;c[t]={left:vp(h),top:p},h=vp(h)+e+fg}}const m=Math.max(...e.map(t=>{var e;return(null===(e=i.get(t))||void 0===e?void 0:e.height)||100}));h=p+m+80}}const u=c[s];if(u){const t=u.left,e=u.top;for(const i of Object.keys(c))c[i]={left:vp(Math.max(0,c[i].left-t)),top:vp(Math.max(0,c[i].top-e))}}return c}(c,d,h,r,l,i)}function yg(t,e){var i;const o=[];let n=[],s=0;for(const r of t){const t=(null===(i=e.get(r))||void 0===i?void 0:i.width)||200,a=n.length>0?fg+t:t;n.length>0&&s+a>1200?(o.push(n),n=[r],s=t):(n.push(r),s+=a)}return n.length>0&&o.push(n),o}function xg(t,e,i,o,n){for(const s of n)if(t<s.left+s.width+vg&&t+i+vg>s.left&&e<s.top+s.height+vg&&e+o+vg>s.top)return!0;return!1}function wg(t){if("touches"in t){const e=t.touches[0]||t.changedTouches[0];return{clientX:e.clientX,clientY:e.clientY}}return{clientX:t.clientX,clientY:t.clientY}}function _g(t,e,i,o,n=20,s=10,r=5,a="top",l=0){const d=r;if("top"===a){const r=e+n,a=o-s;let c=`M ${t} ${e}`;if(t===i)c+=` L ${i} ${a}`;else{const o=i>t?1:-1,n=Math.max(e+d,Math.min(r,a-d)),s=Math.max(e+d,Math.min(n+l,a-d-3)),h=Math.min(d,s-e);h>=1?(c+=` L ${t} ${s-h}`,c+=` Q ${t} ${s}, ${t+o*h} ${s}`):c+=` L ${t} ${s}`;const u=3,p=Math.min(d,Math.max(0,a-s-u));p>=1?(c+=` L ${i-o*p} ${s}`,c+=` Q ${i} ${s}, ${i} ${s+p}`):c+=` L ${i} ${s}`,c+=` L ${i} ${a}`}return c+=` L ${i} ${o}`,c}if("left"===a||"right"===a){const r=e+(o<e?0:n),l="left"===a?-1:1,c=i+l*s,h=c>t?1:-1,u=3,p=h===l?r+2*d:Math.max(r+2*d,o);let m=`M ${t} ${e} L ${t} ${r}`;p-r>d&&(m+=` L ${t} ${p-d}`,m+=` Q ${t} ${p}, ${t+h*d} ${p}`);const g=Math.abs(p-o);if(g<1)m+=` L ${c} ${o}`,m+=` L ${i} ${o}`;else{const t=o<p?-1:1,e=Math.min(d,Math.max(0,Math.floor((g-u)/2)),Math.max(0,s-u));e>=1?(m+=` L ${c-h*e} ${p}`,m+=` Q ${c} ${p}, ${c} ${p+t*e}`,m+=` L ${c} ${o-t*e}`,m+=` Q ${c} ${o}, ${c-l*e} ${o}`):(m+=` L ${c} ${p}`,m+=` L ${c} ${o}`),m+=` L ${i} ${o}`}return m}return`M ${t} ${e} L ${i} ${o}`}class kg{constructor(t,e){this.connections=new Map,this.sources=new Map,this.pendingConnections=[],this.connectionWait=null,this.connectionListeners=new Map,this.dragState=null,this.retryCount=0,this.maxRetries=3,this.activityData=null,this.overlays=new Map,this.hoveredActivityKey=null,this.recentContactsPopup=null,this.recentContactsCache={},this.pendingFetches={},this.hideContactsTimeout=null,this.showContactsTimeout=null,this.connectionDragging=!1,this.zoom=1,this.canvas=t,this.editor=e}setContainer(t){this.canvas=t}notifyListeners(t,e){(this.connectionListeners.get(t)||[]).forEach(t=>t(e))}on(t,e){this.connectionListeners.has(t)||this.connectionListeners.set(t,[]),this.connectionListeners.get(t).push(e)}off(t,e){if(!this.connectionListeners.has(t))return;const i=this.connectionListeners.get(t),o=i.indexOf(e);-1!==o&&i.splice(o,1)}makeSource(t){const e=document.getElementById(t);if(!e)return;this.sources.has(t)&&this.sources.get(t)();let i=null;const o=o=>{if("button"in o&&gp(o))return;if(this.connections.has(t))return;const n="touches"in o;n&&o.preventDefault();const{clientX:s,clientY:r}=wg(o),a=e.closest("temba-flow-node"),l=(null==a?void 0:a.getAttribute("uuid"))||"",d=e=>{const{clientX:i,clientY:o}=wg(e),n=i-s,a=o-r;Math.sqrt(n*n+a*a)>5&&(h(),this.startDrag(t,l,null,e))},c=()=>{h()},h=()=>{document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",c),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",c),document.removeEventListener("touchcancel",c),i=null};document.addEventListener("mousemove",d),document.addEventListener("mouseup",c),document.addEventListener("touchmove",d,{passive:!1}),document.addEventListener("touchend",c),document.addEventListener("touchcancel",c),i={startX:s,startY:r,onMove:d,onUp:c,isTouch:n}};e.addEventListener("mousedown",o),e.addEventListener("touchstart",o,{passive:!1}),this.sources.set(t,()=>{e.removeEventListener("mousedown",o),e.removeEventListener("touchstart",o),i&&(document.removeEventListener("mousemove",i.onMove),document.removeEventListener("mouseup",i.onUp),document.removeEventListener("touchmove",i.onMove),document.removeEventListener("touchend",i.onUp),document.removeEventListener("touchcancel",i.onUp),i=null)})}makeTarget(t){}connectIds(t,e,i){this.pendingConnections.push({scope:t,fromId:e,toId:i}),this.processPendingConnections()}processPendingConnections(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.connectionWait=requestAnimationFrame(()=>{const t=[],e=new Set;if(this.pendingConnections.forEach(i=>{const{scope:o,fromId:n,toId:s}=i;this.removeConnectionSVG(n),this.createConnectionSVG(n,o,s)?e.add(s):t.push(i)}),this.pendingConnections=[],e.size>0){const t=new Set;this.connections.forEach(i=>{e.has(i.toId)&&t.add(i.scope)}),this.connections.forEach((i,o)=>{(e.has(i.toId)||t.has(i.scope))&&this.updateConnectionSVG(o)})}t.length>0&&this.retryCount<this.maxRetries?(this.retryCount++,this.pendingConnections=t,this.processPendingConnections()):this.retryCount=0})}toCanvas(t){return t/this.zoom}determineTargetFace(t,e,i,o){return o-e>30?"top":t<i?"left":"right"}getConnectionEndpoints(t,e,i){const o=document.getElementById(t),n=document.getElementById(e);if(!o||!n)return null;const s=this.canvas.getBoundingClientRect(),r=o.getBoundingClientRect(),a=n.getBoundingClientRect();if(0===r.width||0===a.width)return null;const l=this.toCanvas(r.left+r.width/2-s.left),d=this.toCanvas(r.bottom-s.top),c=this.toCanvas(a.left+a.width/2-s.left),h=this.toCanvas(a.top-s.top),u=this.determineTargetFace(l,d,c,h),p=new Map;this.connections.forEach(t=>{if(t.toId===e){const e=document.getElementById(t.fromId);if(e){const i=e.getBoundingClientRect(),o=this.toCanvas(i.left+i.width/2-s.left),n=this.toCanvas(i.bottom-s.top),r=this.determineTargetFace(o,n,c,h);p.has(r)||p.set(r,[]);const a="top"===r?o:n;p.get(r).push({fromId:t.fromId,sortPos:a})}}}),p.has(u)||p.set(u,[]);const m=p.get(u);if(!m.find(e=>e.fromId===t)){const e="top"===u?l:d;m.push({fromId:t,sortPos:e})}m.sort((t,e)=>t.sortPos-e.sortPos);const g=m.findIndex(e=>e.fromId===t),f=m.length,v=this.toCanvas(a.left-s.left),b=h,y=this.toCanvas(a.width),x=this.toCanvas(a.height);let w,_;if("top"===u){w=1===f?v+y/2:v+.2*y+.6*y*(g+.5)/f,_=b}else if("left"===u){w=v;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}else{w=v+y;_=1===f?b+x/2:b+.2*x+.6*x*(g+.5)/f}let k=0;if("top"===u&&i){const o=8,n=50,r=[];if(this.connections.forEach(t=>{if(t.scope===i&&t.toId!==e){const e=document.getElementById(t.fromId),i=document.getElementById(t.toId);if(e&&i){const o=e.getBoundingClientRect(),n=i.getBoundingClientRect(),a=this.toCanvas(o.left+o.width/2-s.left),l=this.toCanvas(o.bottom-s.top),d=this.toCanvas(n.left+n.width/2-s.left),c=this.toCanvas(n.top-s.top);if("top"===this.determineTargetFace(a,l,d,c)){const e=this.toCanvas(n.left-s.left),i=this.toCanvas(n.width);r.push({fromId:t.fromId,targetX:e+i/2})}}}}),r.length>0){r.push({fromId:t,targetX:w}),r.sort((t,e)=>t.targetX-e.targetX);const e=r.findIndex(e=>e.fromId===t),i=r.length;k=(e-(i-1)/2)*((i-1)*o>n?n/(i-1):o)}}return{sourceX:l,sourceY:d,targetX:w,targetY:_,targetFace:u,jogYOffset:k}}createSVGElement(){const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.classList.add("plumb-connector"),t.style.position="absolute",t.style.left="0",t.style.top="0",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none",t.style.overflow="visible";const e=document.createElementNS("http://www.w3.org/2000/svg","path");e.setAttribute("fill","none"),e.setAttribute("stroke","var(--color-connectors)"),e.setAttribute("stroke-width","3"),e.style.pointerEvents="stroke";const i=document.createElementNS("http://www.w3.org/2000/svg","polygon");i.setAttribute("fill","var(--color-connectors)"),i.classList.add("plumb-arrow"),i.style.pointerEvents="fill",i.style.cursor="pointer";const o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttribute("r","18"),o.setAttribute("fill","transparent"),o.style.pointerEvents="fill",o.style.cursor="pointer",t.appendChild(e),t.appendChild(o),t.appendChild(i);const n=()=>t.classList.add("hover"),s=()=>t.classList.remove("hover");return e.addEventListener("mouseenter",n),e.addEventListener("mouseleave",s),i.addEventListener("mouseenter",n),i.addEventListener("mouseleave",s),o.addEventListener("mouseenter",n),o.addEventListener("mouseleave",s),{svgEl:t,pathEl:e,arrowEl:i,hitAreaEl:o}}updateSVGPath(t,e,i,o,n,s,r="top",a=0,l){const d=6.5,c=13;let h=n,u=s;"top"===r?u=s-c:"left"===r?h=n-c:"right"===r&&(h=n+c);const p=_g(i,o,h,u,30,8,5,r,a);if(t.setAttribute("d",p),"top"===r?e.setAttribute("points",`${n},${s} ${n-d},${s-c} ${n+d},${s-c}`):"left"===r?e.setAttribute("points",`${n},${s} ${n-c},${s-d} ${n-c},${s+d}`):e.setAttribute("points",`${n},${s} ${n+c},${s-d} ${n+c},${s+d}`),l){const t=6.5;let e=n,i=s;"top"===r?i=s-t:e="left"===r?n-t:n+t,l.setAttribute("cx",String(e)),l.setAttribute("cy",String(i))}}createConnectionSVG(t,e,i){const o=this.getConnectionEndpoints(t,i,e);if(!o)return!1;const{svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a}=this.createSVGElement();this.updateSVGPath(s,r,o.sourceX,o.sourceY,o.targetX,o.targetY,o.targetFace,o.jogYOffset,a),this.canvas.appendChild(n),this.connections.set(t,{scope:e,fromId:t,toId:i,svgEl:n,pathEl:s,arrowEl:r,hitAreaEl:a});const l=o=>{if("button"in o&&gp(o))return;o.stopPropagation(),"touches"in o&&o.preventDefault();const{clientX:n,clientY:s}=wg(o),r=o=>{const{clientX:l,clientY:d}=wg(o),c=l-n,h=d-s;Math.sqrt(c*c+h*h)>5&&(document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a),this.startDrag(t,e,i,o))},a=()=>{document.removeEventListener("mousemove",r),document.removeEventListener("mouseup",a),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",a),document.removeEventListener("touchcancel",a)};document.addEventListener("mousemove",r),document.addEventListener("mouseup",a),document.addEventListener("touchmove",r,{passive:!1}),document.addEventListener("touchend",a),document.addEventListener("touchcancel",a)};r.addEventListener("mousedown",l),r.addEventListener("touchstart",l,{passive:!1}),a.addEventListener("mousedown",l),a.addEventListener("touchstart",l,{passive:!1}),s.addEventListener("mousedown",l),s.addEventListener("touchstart",l,{passive:!1});const d=document.getElementById(t);if(d&&d.classList.add("connected"),this.activityData){const e=`${t}:${i}`,o=this.activityData.segments[e];if(o&&o>0){const i=this.createOverlayElement(o,e);this.canvas.appendChild(i),this.overlays.set(t,i),this.updateOverlayPosition(t)}}return!0}updateConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.getConnectionEndpoints(e.fromId,e.toId,e.scope);i&&(this.updateSVGPath(e.pathEl,e.arrowEl,i.sourceX,i.sourceY,i.targetX,i.targetY,i.targetFace,i.jogYOffset,e.hitAreaEl),this.updateOverlayPosition(t))}removeConnectionSVG(t){const e=this.connections.get(t);if(!e)return;const i=this.overlays.get(t);i&&(i.remove(),this.overlays.delete(t)),e.svgEl.remove(),this.connections.delete(t)}repaintEverything(){this.connections.forEach((t,e)=>{this.updateConnectionSVG(e)})}revalidate(t){const e=[],i=new Set;this.connections.forEach((o,n)=>{(t.includes(o.fromId)||t.includes(o.toId)||t.includes(o.scope))&&(e.push(n),i.add(o.toId))});const o=new Set(e);this.connections.forEach((t,e)=>{i.has(t.toId)&&o.add(e)}),o.forEach(t=>{this.updateConnectionSVG(t)})}forgetNode(t){var e;const i=[];this.connections.forEach((e,o)=>{e.scope!==t&&e.toId!==t||i.push(o)}),i.forEach(t=>this.removeConnectionSVG(t));const o=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");o&&o.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}removeNodeConnections(t,e){var i;(e||Array.from((null===(i=document.getElementById(t))||void 0===i?void 0:i.querySelectorAll(".exit"))||[]).map(t=>t.id)).forEach(t=>this.removeConnectionSVG(t))}removeExitConnection(t){return!!this.connections.has(t)&&(this.removeConnectionSVG(t),!0)}removeAllEndpoints(t){var e;const i=null===(e=document.getElementById(t))||void 0===e?void 0:e.querySelectorAll(".exit");i&&i.forEach(t=>{const e=t.id;this.sources.has(e)&&(this.sources.get(e)(),this.sources.delete(e))})}setConnectionRemovingState(t,e){const i=this.connections.get(t);return!!i&&(e?i.svgEl.classList.add("removing"):i.svgEl.classList.remove("removing"),!0)}setActivityData(t){this.activityData=t,this.clearRecentContactsCache(),this.updateActivityOverlays()}updateActivityOverlays(){if(!this.activityData)return this.overlays.forEach(t=>t.remove()),void this.overlays.clear();const t=new Set;this.connections.forEach((e,i)=>{const o=`${e.fromId}:${e.toId}`,n=this.activityData.segments[o];if(n&&n>0){t.add(i);let e=this.overlays.get(i);e?(e.textContent=n.toLocaleString(),e.setAttribute("data-activity-key",o)):(e=this.createOverlayElement(n,o),this.canvas.appendChild(e),this.overlays.set(i,e)),this.updateOverlayPosition(i)}}),this.overlays.forEach((e,i)=>{t.has(i)||(e.remove(),this.overlays.delete(i))})}createOverlayElement(t,e){const i=document.createElement("div");return i.className="activity-overlay",i.textContent=t.toLocaleString(),i.setAttribute("data-activity-key",e),i.addEventListener("mouseenter",()=>{const t=this.getFlowUuid();t&&(this.fetchRecentContacts(e,t),this.showContactsTimeout=window.setTimeout(()=>{this.showRecentContacts(e,t)},500))}),i.addEventListener("mouseleave",()=>{this.showContactsTimeout&&(clearTimeout(this.showContactsTimeout),this.showContactsTimeout=null),this.hoveredActivityKey=null,this.hideRecentContacts()}),i}updateOverlayPosition(t){const e=this.overlays.get(t),i=this.connections.get(t);if(!e||!i)return;const o=this.getConnectionEndpoints(i.fromId,i.toId,i.scope);o&&(e.style.position="absolute",e.style.left=`${o.sourceX}px`,e.style.top=`${o.sourceY+15}px`,e.style.transform="translate(-50%, -50%)")}getFlowUuid(){var t,e;return(null===(e=null===(t=this.editor)||void 0===t?void 0:t.definition)||void 0===e?void 0:e.uuid)||null}async fetchRecentContacts(t,e){if(this.recentContactsCache[t]||this.pendingFetches[t])return;const i=new AbortController;this.pendingFetches[t]=i;try{const[o,n]=t.split(":"),s=`/flow/recent_contacts/${e}/${o}/${n}/`,r=await fetch(s,{signal:i.signal});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const a=await r.json();this.recentContactsCache[t]=Array.isArray(a)?a:a.results||[]}catch(t){"AbortError"!==t.name&&console.error("Failed to fetch recent contacts:",t)}finally{delete this.pendingFetches[t]}}async showRecentContacts(t,e){const i=this.findOverlayForActivityKey(t);i&&(this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null),this.hoveredActivityKey=t,this.recentContactsPopup||(this.recentContactsPopup=document.createElement("div"),this.recentContactsPopup.className="recent-contacts-popup",this.recentContactsPopup.style.position="absolute",this.recentContactsPopup.style.zIndex="1015",this.recentContactsPopup.style.display="none",document.body.appendChild(this.recentContactsPopup),this.recentContactsPopup.onmouseenter=()=>{this.hideContactsTimeout&&(clearTimeout(this.hideContactsTimeout),this.hideContactsTimeout=null)},this.recentContactsPopup.onmouseleave=()=>{this.hoveredActivityKey=null,this.hideRecentContacts()},this.recentContactsPopup.onclick=t=>{const e=t.target;if(e.classList.contains("contact-name")){this.hideRecentContacts(!1);const i=e.getAttribute("data-uuid");i&&this.editor.fireCustomEvent("temba-contact-clicked",{uuid:i,metaKey:t.metaKey,ctrlKey:t.ctrlKey})}}),this.recentContactsCache[t]?(this.renderRecentContactsPopup(this.recentContactsCache[t]),this.positionPopup(i)):(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">Loading...</div>',this.positionPopup(i),await this.fetchRecentContacts(t,e),this.hoveredActivityKey===t&&(this.renderRecentContactsPopup(this.recentContactsCache[t]||[]),this.positionPopup(i))))}findOverlayForActivityKey(t){for(const[,e]of this.overlays)if(e.getAttribute("data-activity-key")===t)return e;return null}positionPopup(t){if(!this.recentContactsPopup)return;const e=t.getBoundingClientRect();this.recentContactsPopup.style.left=`${e.left+window.scrollX}px`,this.recentContactsPopup.style.top=`${e.bottom+window.scrollY+5}px`,this.recentContactsPopup.style.display="",this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.offsetWidth,this.recentContactsPopup.classList.add("show")}renderRecentContactsPopup(t){if(!this.recentContactsPopup)return;if(0===t.length)return void(this.recentContactsPopup.innerHTML='<div class="no-contacts-message">No Recent Contacts</div>');let e='<div class="popup-title">Recent Contacts</div>';t.forEach(t=>{if(e+='<div class="contact-row">',e+=`<div class="contact-name" data-uuid="${t.contact.uuid}">${t.contact.name}</div>`,t.operand&&(e+=`<div class="contact-operand">${t.operand}</div>`),t.time){const i=new Date(t.time),o=Date.now()-i.getTime(),n=Math.floor(o/6e4),s=Math.floor(o/36e5),r=Math.floor(o/864e5);let a="";a=n<1?"just now":n<60?`${n}m ago`:s<24?`${s}h ago`:`${r}d ago`,e+=`<div class="contact-time">${a}</div>`}e+="</div>"}),this.recentContactsPopup.innerHTML=e}hideRecentContacts(t=!0){t?this.hideContactsTimeout=window.setTimeout(()=>{!this.hoveredActivityKey&&this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)},200):this.recentContactsPopup&&(this.recentContactsPopup.classList.remove("show"),this.recentContactsPopup.style.display="none",this.hoveredActivityKey=null)}clearRecentContactsCache(){this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={}}startDrag(t,e,i,o){const n=this.connections.get(t);if(n){n.svgEl.style.display="none";const e=this.overlays.get(t);e&&(e.style.display="none")}const{svgEl:s,pathEl:r,arrowEl:a,hitAreaEl:l}=this.createSVGElement();s.classList.add("dragging"),r.style.pointerEvents="none",a.style.pointerEvents="none",l.style.pointerEvents="none",this.canvas.appendChild(s);const d=document.getElementById(t);if(!d)return void s.remove();const c=this.canvas.getBoundingClientRect(),h=d.getBoundingClientRect(),u=this.toCanvas(h.left+h.width/2-c.left),p=this.toCanvas(h.bottom-c.top),m=6.5,g=(t,e)=>{const i=e<p;let o,n="top";i&&(n=t<u?"left":"right"),o=i?e+1+13:e-1;const s=_g(u,p,t,o,30,i?0:8,5,n);if(r.setAttribute("d",s),i){const i=e+1;a.setAttribute("points",`${t},${i} ${t-m},${o} ${t+m},${o}`)}else{const e=o+13;a.setAttribute("points",`${t},${e} ${t-m},${o} ${t+m},${o}`)}},{clientX:f,clientY:v}=wg(o),b=this.toCanvas(f-c.left),y=this.toCanvas(v-c.top);g(b,y),this.connectionDragging=!0;const x=t=>{"touches"in t&&t.preventDefault();const e=this.canvas.getBoundingClientRect(),{clientX:i,clientY:o}=wg(t),n=this.toCanvas(i-e.left),s=this.toCanvas(o-e.top);g(n,s)},w=o=>{document.removeEventListener("mousemove",x),document.removeEventListener("mouseup",w),document.removeEventListener("touchmove",x),document.removeEventListener("touchend",w),document.removeEventListener("touchcancel",w),s.remove(),this.removeConnectionSVG(t),this.connectionDragging=!1,this.dragState=null,this.notifyListeners("connection:abort",{source:d,sourceId:t,target:{id:i},data:{nodeId:e}})};document.addEventListener("mousemove",x),document.addEventListener("mouseup",w),document.addEventListener("touchmove",x,{passive:!1}),document.addEventListener("touchend",w),document.addEventListener("touchcancel",w),this.dragState={sourceId:t,scope:e,originalTargetId:i,svgEl:s,pathEl:r,arrowEl:a,onMove:x,onUp:w},this.notifyListeners("connection:drag",{sourceId:t,sourceX:u,sourceY:p,data:{nodeId:e},target:{id:i}})}reset(){this.connectionWait&&(cancelAnimationFrame(this.connectionWait),this.connectionWait=null),this.pendingConnections=[],this.connections.forEach(t=>t.svgEl.remove()),this.connections.clear(),this.overlays.forEach(t=>t.remove()),this.overlays.clear(),this.hideRecentContacts(!1),this.recentContactsPopup&&(this.recentContactsPopup.remove(),this.recentContactsPopup=null),this.recentContactsCache={},Object.values(this.pendingFetches).forEach(t=>t.abort()),this.pendingFetches={},this.sources.forEach(t=>t()),this.sources.clear(),this.dragState&&(document.removeEventListener("mousemove",this.dragState.onMove),document.removeEventListener("mouseup",this.dragState.onUp),this.dragState.svgEl.remove(),this.dragState=null,this.connectionDragging=!1)}}class Cg extends Ye{createRenderRoot(){return this}static get styles(){return d`
|
|
11621
11666
|
|
|
11622
11667
|
.node {
|
|
11623
11668
|
background-color: #fff;
|
|
@@ -13099,7 +13144,7 @@ background: #ccc;
|
|
|
13099
13144
|
animation-timing-function: linear;
|
|
13100
13145
|
animation-fill-mode: forwards;
|
|
13101
13146
|
}
|
|
13102
|
-
`}constructor(){super(),this.saveTimer=null,this.flowType=Np,this.features=[],this.activityTimer=null,this.activityInterval=100,this.isDragging=!1,this.currentDragItem=null,this.selectedItems=new Set,this.isSelecting=!1,this.selectionBox=null,this.targetId=null,this.sourceId=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null,this.isValidTarget=!0,this.connectionSourceX=null,this.connectionSourceY=null,this.issuesWindowHidden=!0,this.revisionsWindowHidden=!0,this.viewingRevision=!1,this.isSaving=!1,this.saveError=null,this.zoom=1,this.autoTranslating=!1,this._suppressDirtySave=!1,this.savePromise=null,this.pendingTimer=new Tg("Unsaved Changes",5e3,this,()=>{this.pendingPositions=null,this.copiedItemUuids=[],this.saveChanges()}),this.pendingPositions=null,this.copiedItemUuids=[],this.deleteDialog=null,this.dirtyAdapter={dirtyMessage:"Your flow is still saving. If you leave now, your latest changes may be lost.",markClean:()=>{}},this.boundBeforeUnload=t=>{t.preventDefault()},this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.showMessageTable=!1,this.isCreatingNewNode=!1,this.pendingNodePosition=null,this.canvasDropPreview=null,this.addActionToNodeUuid=null,this.actionDragTargetNodeUuid=null,this.previousActionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.connectionPlaceholder=null,this.pendingCanvasConnection=null,this.boundCanvasContextMenu=this.handleCanvasContextMenu.bind(this),this.boundWheel=t=>this.zoomManager.handleWheel(t),this.boundWindowResize=()=>this.zoomManager.updateZoomControlPositioning(),this.flushSave=async()=>{const t=this.definition?{...this.definition}:null;this.pendingTimer.unsaved&&(this.pendingPositions=null,this.copiedItemUuids=[],this.pendingTimer.dismiss()),null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.savePromise&&await this.savePromise,t&&this.dirtyDate&&await this.saveChanges(t)},this.editForceBase=!1,this.dragManager=new Sg(this),this.zoomManager=new Ag(this)}firstUpdated(t){var e,i,o;super.firstUpdated(t),this.plumber=new kg(this.querySelector("#canvas"),this),this.plumber.zoom=this.zoom,this.setupGlobalEventListeners(),null===(e=qd())||void 0===e||e.getState().setFlushSave(this.flushSave),Nd.getState().setFeatures(this.features),navigator.maxTouchPoints>0&&(null===(i=this.querySelector("#canvas"))||void 0===i||i.classList.add("touch-device"),null===(o=this.querySelector("#editor"))||void 0===o||o.classList.add("touch-device")),this.zoomManager.updateZoomControlPositioning(),this.zoomManager.setLoupeElements(this.querySelector("#loupe"),this.querySelector("#loupe-content")),this.zoomManager.initLoupe(),t.has("flow")&&this.flow&&setTimeout(()=>{this.isConnected&&this.flow&&qd().getState().fetchRevision(`/flow/revisions/${this.flow}`)},0),this.plumber.on("connection:drag",t=>{this.dragFromNodeId=t.data.nodeId,this.sourceId=t.sourceId,this.connectionSourceX=t.sourceX,this.connectionSourceY=t.sourceY,this.originalConnectionTargetId=t.target.id}),this.plumber.on("connection:abort",t=>{this.makeConnection(t)}),this.plumber.on("connection:detach",t=>{this.makeConnection(t)})}makeConnection(t){if(this.sourceId&&this.targetId&&this.isValidTarget)t.target.id===this.targetId?this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.targetId):qd().getState().updateConnection(this.dragFromNodeId,this.sourceId,this.targetId);else if(this.connectionPlaceholder&&this.connectionPlaceholder.visible&&this.sourceId){const t={left:vp(this.connectionPlaceholder.position.left),top:vp(this.connectionPlaceholder.position.top)},e=!!this.connectionPlaceholder.dragUp;this.connectionPlaceholder.position=t,this.pendingCanvasConnection={fromNodeId:this.dragFromNodeId,exitId:this.sourceId,position:t};const i=this.querySelector("#canvas");if(i){const o=i.getBoundingClientRect(),n=o.left+t.left*this.zoom-40,s=e?o.top+t.top*this.zoom+74:o.top+t.top*this.zoom+80,r=this.querySelector("temba-canvas-menu");r&&r.show(n,s,{x:t.left,y:t.top},!1,!1,qp[this.flowType])}return void this.requestUpdate()}document.querySelectorAll("temba-flow-node").forEach(t=>{t.classList.remove("connection-target-valid","connection-target-invalid")}),this.pendingCanvasConnection||(this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.targetId=null,this.isValidTarget=!0}willUpdate(t){var e;super.willUpdate(t),t.has("definition")&&((null===(e=this.definition)||void 0===e?void 0:e.type)&&(this.flowType=this.getFlowTypeFromDefinition(this.definition.type)),this.zoomManager.restoreInitialZoomFromSettings()),t.has("dirtyDate")&&this.dirtyDate&&(this.pendingTimer.pending?(this.pendingTimer.pending=!1,this._suppressDirtySave=!0):this.pendingTimer.unsaved?(this.pendingTimer.start(!1),this._suppressDirtySave=!0):this.isSaving=!0)}setSimulatorTabHidden(t){var e;const i=document.querySelector("temba-simulator"),o=null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector("#phone-tab");o&&(o.hidden=t)}updated(t){var e;if(super.updated(t),t.has("features")&&Nd.getState().setFeatures(this.features),t.has("revisionsWindowHidden")&&this.setSimulatorTabHidden(!this.revisionsWindowHidden),t.has("canvasSize")&&this.zoomManager.updateZoomControlPositioning(),t.has("showMessageTable")&&!this.showMessageTable&&this.plumber&&requestAnimationFrame(()=>{const t=this.querySelector("#canvas");t&&(this.plumber.setContainer(t),this.plumber.repaintEverything(),t.addEventListener("contextmenu",this.boundCanvasContextMenu))}),t.has("showMessageTable")&&this.zoomManager.updateZoomControlPositioning(),t.has("definition")&&(setTimeout(()=>this.updateCanvasSize(),0),(null===(e=this.definition)||void 0===e?void 0:e.uuid)&&this.startActivityFetching()),t.has("simulatorActive")&&(this.simulatorActive?(this.closeFloatingWindows(),this.stopActivityFetching()):(this.activityInterval=100,this.startActivityFetching())),t.has("activityData")&&this.plumber&&this.plumber.setActivityData(this.activityData),t.has("dirtyDate")&&this.dirtyDate&&(this._suppressDirtySave?this._suppressDirtySave=!1:this.debouncedSave()),t.has("isSaving")){const t=document.querySelector("temba-store");this.isSaving?(window.addEventListener("beforeunload",this.boundBeforeUnload),(null==t?void 0:t.markDirty)&&t.markDirty(this.dirtyAdapter)):(window.removeEventListener("beforeunload",this.boundBeforeUnload),(null==t?void 0:t.markClean)&&t.markClean(this.dirtyAdapter))}t.has("saveError")&&this.saveError&&(this.showSaveErrorDialog(this.saveError),setTimeout(()=>{this.saveError=null},0))}getFlowTypeFromDefinition(t){return"voice"===t?Bp:"messaging_background"===t||"messaging_offline"===t?Fp:Np}debouncedSave(){null!==this.saveTimer&&clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>{if(this.pendingTimer.unsaved)return void(this.saveTimer=null);(new Date).getTime()-this.dirtyDate.getTime()>=2e3?(this.saveChanges(),this.saveTimer=null):this.debouncedSave()},2e3)}definitionForSave(t){return{...t,_ui:{...t._ui,editor:Yu}}}saveChanges(t){const e=this.definitionForSave(t||this.definition);this.isSaving=!0;const i=qd().postJSON(`/flow/revisions/${this.flow}/`,e).then(t=>{var e,i;if(t.status<200||t.status>=300)this.saveError=this.extractErrorMessage(t);else{if(t.json){const i=qd().getState();t.json.info&&i.setFlowInfo(t.json.info),void 0!==(null===(e=t.json.revision)||void 0===e?void 0:e.revision)&&i.setRevision(t.json.revision.revision)}qd().getState().setDirtyDate(null),null===(i=this.getRevisionsWindow())||void 0===i||i.refresh()}}).catch(t=>{console.error("Failed to save flow:",t),t instanceof Response?this.saveError=`Server error (${t.status}). Your changes have not been saved.`:this.saveError="Unable to reach the server. Please check your connection and try again."}).finally(()=>{this.isSaving=!1,this.savePromise=null});return this.savePromise=i,i}extractErrorMessage(t){if(t.json){if("string"==typeof t.json.detail)return t.json.detail;if("string"==typeof t.json.error)return t.json.error;if("string"==typeof t.json.description)return t.json.description}return`Save failed with status ${t.status}.`}showSaveErrorDialog(t){const e=document.createElement("temba-dialog");e.header="Save Failed",e.primaryButtonName="",e.cancelButtonName="Dismiss";const i=document.createElement("div");i.style.cssText="padding: 20px; font-size: 14px; line-height: 1.5;",i.textContent=t,e.appendChild(i),document.body.appendChild(e),e.open=!0,e.addEventListener("temba-dialog-hidden",()=>{document.body.removeChild(e)})}startActivityFetching(){this.simulatorActive||this.fetchActivityData()}stopActivityFetching(){null!==this.activityTimer&&(clearTimeout(this.activityTimer),this.activityTimer=null)}fetchActivityData(){var t;if(!(null===(t=this.definition)||void 0===t?void 0:t.uuid))return;if(this.simulatorActive)return;const e=`/flow/activity/${this.definition.uuid}/`,i=qd();if(!i)return;i.getState().fetchActivity(e).then(()=>{this.isConnected&&(this.activityInterval=Math.min(3e5,this.activityInterval+100),null!==this.activityTimer&&clearTimeout(this.activityTimer),this.activityTimer=window.setTimeout(()=>{this.fetchActivityData()},this.activityInterval))})}handleLanguageChange(t){Nd.getState().setLanguageCode(t)}getAvailableLanguages(){var t,e,i;return(null===(t=this.workspace)||void 0===t?void 0:t.languages)&&this.workspace.languages.length>0?this.workspace.languages.map(t=>({code:t,name:Bl(t)})).filter(t=>t.code&&t.name):(null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.languages)&&this.definition._ui.languages.length>0?this.definition._ui.languages.map(t=>{const e="string"==typeof t?t:t.iso||t.code;return{code:e,name:Bl(e)}}):[]}getLocalizationLanguages(){if(!this.definition)return[];const t=this.definition.language;return this.getAvailableLanguages().filter(e=>e.code!==t)}getLocalizationProgress(t){return gg(this.definition,t).reduce((t,e)=>(e.translations.forEach(e=>{t.total+=1,e.to&&e.to.trim().length>0&&(t.localized+=1)}),t),{total:0,localized:0})}hasAnyNodeWithLocalizeCategories(){var t,e;return!!(null===(e=null===(t=this.definition)||void 0===t?void 0:t._ui)||void 0===e?void 0:e.nodes)&&Object.values(this.definition._ui.nodes).some(t=>{var e;return null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.localizeCategories})}handleAutoTranslateClick(){if(this.viewingRevision)return;const t=this.querySelector("temba-auto-translate");null==t||t.start()}handleAutoTranslateChanged(t){var e;this.autoTranslating=!!(null===(e=t.detail)||void 0===e?void 0:e.running)}disconnectedCallback(){var t;super.disconnectedCallback(),this.zoomManager.teardownLoupe(),null===(t=qd())||void 0===t||t.getState().setFlushSave(null),this.dragManager.teardownListeners(),window.removeEventListener("beforeunload",this.boundBeforeUnload);const e=document.querySelector("temba-store");(null==e?void 0:e.markClean)&&e.markClean(this.dirtyAdapter),null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),null!==this.activityTimer&&(clearTimeout(this.activityTimer),this.activityTimer=null),this.pendingTimer.clearTimer(),window.removeEventListener("resize",this.boundWindowResize);const i=this.querySelector("#canvas");i&&i.removeEventListener("contextmenu",this.boundCanvasContextMenu);const o=this.querySelector("#editor");o&&o.removeEventListener("wheel",this.boundWheel),this.savePromise?this.savePromise.then(()=>Nd.getState().clearFlowData()):Nd.getState().clearFlowData()}setupGlobalEventListeners(){this.dragManager.setupListeners(),window.addEventListener("resize",this.boundWindowResize);const t=this.querySelector("#canvas");t&&t.addEventListener("contextmenu",this.boundCanvasContextMenu);const e=this.querySelector("#editor");e&&e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.addEventListener(jo.ActionEditRequested,this.handleActionEditRequested.bind(this)),this.addEventListener(jo.AddActionRequested,this.handleAddActionRequested.bind(this)),this.addEventListener(jo.NodeEditRequested,this.handleNodeEditRequested.bind(this)),this.addEventListener(jo.NodeDeleted,this.handleNodeDeleted.bind(this)),this.addEventListener(jo.StickyNoteDeleted,t=>{var e;const i=null===(e=t.detail)||void 0===e?void 0:e.uuid;i&&qd().getState().removeStickyNotes([i])}),this.addEventListener(jo.Selection,t=>{const e=t.target;"TEMBA-CANVAS-MENU"===e.tagName?this.handleCanvasMenuSelection(t):"TEMBA-NODE-TYPE-SELECTOR"===e.tagName&&this.handleNodeTypeSelection(t)}),this.addEventListener(jo.Canceled,t=>{const e=t.target;"TEMBA-CANVAS-MENU"===e.tagName?this.handleCanvasMenuClosed():"TEMBA-NODE-TYPE-SELECTOR"===e.tagName&&this.handleNodeTypeSelectorClosed()}),this.addEventListener(jo.DragExternal,this.handleActionDragExternal.bind(this)),this.addEventListener(jo.DragInternal,this.handleActionDragInternal.bind(this)),this.addEventListener(jo.DragStop,t=>{t.detail.isExternal&&this.handleActionDropExternal(t)}),this.addEventListener(jo.SizeChanged,t=>{const{uuid:e}=t.detail;e&&requestAnimationFrame(()=>{this.checkCollisionsAndReflow([e])})})}openFlowSearch(){if(this.viewingRevision)return;if(this.zoomManager.isDialogOrMenuOpen())return;const t=this.querySelector("temba-flow-search");t&&(t.definition=this.definition,t.languageCode=this.languageCode||"",t.scope=this.showMessageTable?"table":"flow",t.includeCategories=this.isTranslating&&this.hasAnyNodeWithLocalizeCategories(),t.show())}closeFlowSearch(){const t=this.querySelector("temba-flow-search");(null==t?void 0:t.open)&&t.hide()}handleKeyDown(t){var e,i;if("Shift"===t.key&&this.isActionExternalDrag&&!this.actionDragIsCopy&&(this.actionDragIsCopy=!0,this.showActionOriginal(!0),(null===(e=this.actionDragLastDetail)||void 0===e?void 0:e.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate()),(t.metaKey||t.ctrlKey)&&"f"===t.key)return t.preventDefault(),void this.openFlowSearch();const o=this.querySelector("temba-flow-search");if(!(null==o?void 0:o.open)){if("Delete"===t.key||"Backspace"===t.key){if(null===(i=this.deleteDialog)||void 0===i?void 0:i.open)return this.deleteSelectedItems(),void(this.deleteDialog.open=!1);this.selectedItems.size>0&&this.showDeleteConfirmation()}"Escape"===t.key&&(this.selectedItems.clear(),this.requestUpdate())}}handleKeyUp(t){var e;"Shift"===t.key&&this.isActionExternalDrag&&this.actionDragIsCopy&&(this.actionDragIsCopy=!1,this.showActionOriginal(!1),(null===(e=this.actionDragLastDetail)||void 0===e?void 0:e.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate())}handleWindowBlur(){var t;this.isActionExternalDrag&&this.actionDragIsCopy&&(this.actionDragIsCopy=!1,this.showActionOriginal(!1),(null===(t=this.actionDragLastDetail)||void 0===t?void 0:t.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate())}getFlowSettings(){try{return JSON.parse(Te("flow-settings")||"{}")}catch(t){return{}}}saveFlowSetting(t,e){if(!this.flow)return;const i=this.getFlowSettings();delete i[this.flow],i[this.flow]={...i[this.flow]||{},[t]:e};const o=Object.keys(i);if(o.length>Dg.MAX_FLOW_SETTINGS)for(const t of o.slice(0,o.length-Dg.MAX_FLOW_SETTINGS))delete i[t];Ee("flow-settings",JSON.stringify(i))}getFlowSetting(t){var e;if(this.flow)return null===(e=this.getFlowSettings()[this.flow])||void 0===e?void 0:e[t]}showDeleteConfirmation(){var t;const e=this.selectedItems.size,i=1===e?"item":"items";if(null===(t=this.deleteDialog)||void 0===t?void 0:t.open)return;const o=document.createElement("temba-dialog");o.header="Delete Items",o.primaryButtonName="Delete",o.cancelButtonName="Cancel",o.destructive=!0,o.innerHTML=`<div style="padding: 20px;">Are you sure you want to delete ${e} ${i}?</div>`,o.addEventListener("temba-button-clicked",t=>{"Delete"===t.detail.button.name&&(this.deleteSelectedItems(),o.open=!1)}),document.body.appendChild(o),o.open=!0,this.deleteDialog=o,o.addEventListener("temba-dialog-hidden",()=>{document.body.removeChild(o),this.deleteDialog=null})}performReflow(){var t,e;if(!this.definition||0===this.definition.nodes.length)return;this.capturePositionsOnce();const i=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{},o={};for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];(null==i?void 0:i.position)&&(o[t.uuid]={...i.position})}const n=this.definition.nodes[0].uuid,s=new Map,r=bg(this.definition.nodes,this.definition._ui.nodes,n,t=>{const e=this.querySelector(`[id="${t}"]`);if(e){const i={width:e.offsetWidth,height:e.offsetHeight};return s.set(t,i),i}const i={width:200,height:100};return s.set(t,i),i});if(Object.keys(i).length>0){const t=new Map;for(const e of Object.keys(i)){const o=this.querySelector(`temba-sticky-note[uuid="${e}"]`);if(o)t.set(e,{width:o.offsetWidth,height:o.offsetHeight});else{const o=i[e];t.set(e,{width:o.width||200,height:o.height||100})}}const e=function(t,e,i,o,n,s){const r={},a=Object.keys(i);if(0===a.length)return r;const l=new Map,d=new Map;for(const[i,o]of Object.entries(t)){if(!o.position)continue;const t=o.position.left,n=o.position.top;let s=a[0],r=1/0;for(const i of a){const o=e[i];if(!o)continue;const a=t-o.left,l=n-o.top,d=a*a+l*l;d<r&&(r=d,s=i)}l.set(i,s);const c=e[s],h=!!c&&t<c.left,u=d.get(s)||[];u.push({uuid:i,wasLeft:h}),d.set(s,u)}const c=[];for(const t of a){const e=i[t],n=o.get(t)||{width:200,height:100};c.push({left:e.left,top:e.top,width:n.width,height:n.height})}for(const[t,e]of d){const a=i[t];if(!a)continue;const l=o.get(t)||{width:200};for(const{uuid:i,wasLeft:o}of e){const e=n.get(i)||{width:182,height:100};let d;d=t===s&&o||!o?a.left+l.width+vg:a.left-e.width-vg;let h=a.top;d=vp(Math.max(0,d)),h=vp(Math.max(0,h));let u=50;for(;u-- >0&&xg(d,h,e.width,e.height,c);)h=vp(h+vg);r[i]={left:d,top:h},c.push({left:d,top:h,width:e.width,height:e.height})}}return r}(i,o,r,s,t,n);Object.assign(r,e)}null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.pendingTimer.pending=!0,qd().getState().updateCanvasPositions(r),this.updateCanvasSize(),requestAnimationFrame(()=>{this.plumber.repaintEverything()});const a=this.querySelector("#editor");a&&a.scrollTo({left:0,top:0,behavior:"smooth"}),this.pendingTimer.start()}handlePendingDiscard(){this.pendingTimer.dismiss();if(this.copiedItemUuids.length>0||this.pendingPositions){if(null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.copiedItemUuids.length>0){const t=this.copiedItemUuids.filter(t=>this.definition.nodes.some(e=>e.uuid===t)),e=this.copiedItemUuids.filter(t=>{var e,i;return null===(i=null===(e=this.definition._ui)||void 0===e?void 0:e.stickies)||void 0===i?void 0:i[t]});this.pendingTimer.pending=!0,t.length>0&&qd().getState().removeNodes(t),e.length>0&&(this.pendingTimer.pending=!0,qd().getState().removeStickyNotes(e)),this.copiedItemUuids=[]}this.pendingPositions&&(this.pendingTimer.pending=!0,qd().getState().updateCanvasPositions(this.pendingPositions),this.pendingPositions=null),setTimeout(()=>{qd().getState().setDirtyDate(null),this.isSaving=!1},0),requestAnimationFrame(()=>{this.plumber.repaintEverything()})}}renderPendingCard(){if(!this.pendingTimer.unsaved)return"";const t=`pc-${this.pendingTimer.resetCount}`;return Z`<div class="reflow-card">
|
|
13147
|
+
`}constructor(){super(),this.saveTimer=null,this.flowType=Np,this.features=[],this.activityTimer=null,this.activityInterval=100,this.isDragging=!1,this.currentDragItem=null,this.selectedItems=new Set,this.isSelecting=!1,this.selectionBox=null,this.targetId=null,this.sourceId=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null,this.isValidTarget=!0,this.connectionSourceX=null,this.connectionSourceY=null,this.issuesWindowHidden=!0,this.revisionsWindowHidden=!0,this.viewingRevision=!1,this.isSaving=!1,this.saveError=null,this.zoom=1,this.autoTranslating=!1,this._suppressDirtySave=!1,this.savePromise=null,this.pendingTimer=new Tg("Unsaved Changes",5e3,this,()=>{this.pendingPositions=null,this.copiedItemUuids=[],this.saveChanges()}),this.pendingPositions=null,this.copiedItemUuids=[],this.deleteDialog=null,this.dirtyAdapter={dirtyMessage:"Your flow is still saving. If you leave now, your latest changes may be lost.",markClean:()=>{}},this.boundBeforeUnload=t=>{t.preventDefault()},this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.showMessageTable=!1,this.isCreatingNewNode=!1,this.pendingNodePosition=null,this.canvasDropPreview=null,this.addActionToNodeUuid=null,this.actionDragTargetNodeUuid=null,this.previousActionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.connectionPlaceholder=null,this.pendingCanvasConnection=null,this.boundCanvasContextMenu=this.handleCanvasContextMenu.bind(this),this.boundWheel=t=>this.zoomManager.handleWheel(t),this.boundWindowResize=()=>this.zoomManager.updateZoomControlPositioning(),this.flushSave=async()=>{const t=this.definition?{...this.definition}:null;this.pendingTimer.unsaved&&(this.pendingPositions=null,this.copiedItemUuids=[],this.pendingTimer.dismiss()),null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.savePromise&&await this.savePromise,t&&this.dirtyDate&&await this.saveChanges(t)},this.editForceBase=!1,this.dragManager=new Sg(this),this.zoomManager=new Ag(this)}firstUpdated(t){var e,i,o;super.firstUpdated(t),this.plumber=new kg(this.querySelector("#canvas"),this),this.plumber.zoom=this.zoom,this.setupGlobalEventListeners(),null===(e=qd())||void 0===e||e.getState().setFlushSave(this.flushSave),Nd.getState().setFeatures(this.features),navigator.maxTouchPoints>0&&(null===(i=this.querySelector("#canvas"))||void 0===i||i.classList.add("touch-device"),null===(o=this.querySelector("#editor"))||void 0===o||o.classList.add("touch-device")),this.zoomManager.updateZoomControlPositioning(),this.zoomManager.setLoupeElements(this.querySelector("#loupe"),this.querySelector("#loupe-content")),this.zoomManager.initLoupe(),t.has("flow")&&this.flow&&setTimeout(()=>{this.isConnected&&this.flow&&qd().getState().fetchRevision(`/flow/revisions/${this.flow}`)},0),this.plumber.on("connection:drag",t=>{this.dragFromNodeId=t.data.nodeId,this.sourceId=t.sourceId,this.connectionSourceX=t.sourceX,this.connectionSourceY=t.sourceY,this.originalConnectionTargetId=t.target.id}),this.plumber.on("connection:abort",t=>{this.makeConnection(t)}),this.plumber.on("connection:detach",t=>{this.makeConnection(t)})}makeConnection(t){if(this.sourceId&&this.targetId&&this.isValidTarget)t.target.id===this.targetId?this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.targetId):qd().getState().updateConnection(this.dragFromNodeId,this.sourceId,this.targetId);else if(this.connectionPlaceholder&&this.connectionPlaceholder.visible&&this.sourceId){const t={left:vp(this.connectionPlaceholder.position.left),top:vp(this.connectionPlaceholder.position.top)},e=!!this.connectionPlaceholder.dragUp;this.connectionPlaceholder.position=t,this.pendingCanvasConnection={fromNodeId:this.dragFromNodeId,exitId:this.sourceId,position:t};const i=this.querySelector("#canvas");if(i){const o=i.getBoundingClientRect(),n=o.left+t.left*this.zoom-40,s=e?o.top+t.top*this.zoom+74:o.top+t.top*this.zoom+80,r=this.querySelector("temba-canvas-menu");r&&r.show(n,s,{x:t.left,y:t.top},!1,!1,qp[this.flowType])}return void this.requestUpdate()}document.querySelectorAll("temba-flow-node").forEach(t=>{t.classList.remove("connection-target-valid","connection-target-invalid")}),this.pendingCanvasConnection||(this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.targetId=null,this.isValidTarget=!0}willUpdate(t){var e;super.willUpdate(t),t.has("definition")&&((null===(e=this.definition)||void 0===e?void 0:e.type)&&(this.flowType=this.getFlowTypeFromDefinition(this.definition.type)),this.zoomManager.restoreInitialZoomFromSettings()),t.has("dirtyDate")&&this.dirtyDate&&(this.pendingTimer.pending?(this.pendingTimer.pending=!1,this._suppressDirtySave=!0):this.pendingTimer.unsaved?(this.pendingTimer.start(!1),this._suppressDirtySave=!0):this.isSaving=!0)}setSimulatorTabHidden(t){var e;const i=document.querySelector("temba-simulator"),o=null===(e=null==i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector("#phone-tab");o&&(o.hidden=t)}updated(t){var e;if(super.updated(t),t.has("features")&&Nd.getState().setFeatures(this.features),t.has("revisionsWindowHidden")&&this.setSimulatorTabHidden(!this.revisionsWindowHidden),t.has("canvasSize")&&this.zoomManager.updateZoomControlPositioning(),t.has("showMessageTable")&&!this.showMessageTable&&this.plumber&&requestAnimationFrame(()=>{const t=this.querySelector("#canvas");t&&(this.plumber.setContainer(t),this.plumber.repaintEverything(),t.addEventListener("contextmenu",this.boundCanvasContextMenu))}),t.has("showMessageTable")&&this.zoomManager.updateZoomControlPositioning(),t.has("definition")&&(setTimeout(()=>this.updateCanvasSize(),0),(null===(e=this.definition)||void 0===e?void 0:e.uuid)&&this.startActivityFetching()),t.has("simulatorActive")&&(this.simulatorActive?(this.closeFloatingWindows(),this.stopActivityFetching()):(this.activityInterval=100,this.startActivityFetching())),t.has("activityData")&&this.plumber&&this.plumber.setActivityData(this.activityData),t.has("dirtyDate")&&this.dirtyDate&&(this._suppressDirtySave?this._suppressDirtySave=!1:this.debouncedSave()),t.has("isSaving")){const t=document.querySelector("temba-store");this.isSaving?(window.addEventListener("beforeunload",this.boundBeforeUnload),(null==t?void 0:t.markDirty)&&t.markDirty(this.dirtyAdapter)):(window.removeEventListener("beforeunload",this.boundBeforeUnload),(null==t?void 0:t.markClean)&&t.markClean(this.dirtyAdapter))}t.has("saveError")&&this.saveError&&(this.showSaveErrorDialog(this.saveError),setTimeout(()=>{this.saveError=null},0))}getFlowTypeFromDefinition(t){return"voice"===t?Bp:"messaging_background"===t||"messaging_offline"===t?Fp:Np}debouncedSave(){null!==this.saveTimer&&clearTimeout(this.saveTimer),this.saveTimer=window.setTimeout(()=>{if(this.pendingTimer.unsaved)return void(this.saveTimer=null);(new Date).getTime()-this.dirtyDate.getTime()>=2e3?(this.saveChanges(),this.saveTimer=null):this.debouncedSave()},2e3)}definitionForSave(t){return{...t,_ui:{...t._ui,editor:Yu}}}saveChanges(t){const e=this.definitionForSave(t||this.definition);this.isSaving=!0;const i=qd().postJSON(`/flow/revisions/${this.flow}/`,e).then(t=>{var e,i;if(t.status<200||t.status>=300)this.saveError=this.extractErrorMessage(t);else{if(t.json){const i=qd().getState();t.json.info&&i.setFlowInfo(t.json.info),void 0!==(null===(e=t.json.revision)||void 0===e?void 0:e.revision)&&i.setRevision(t.json.revision.revision)}qd().getState().setDirtyDate(null),null===(i=this.getRevisionsWindow())||void 0===i||i.refresh()}}).catch(t=>{console.error("Failed to save flow:",t),t instanceof Response?this.saveError=`Server error (${t.status}). Your changes have not been saved.`:this.saveError="Unable to reach the server. Please check your connection and try again."}).finally(()=>{this.isSaving=!1,this.savePromise=null});return this.savePromise=i,i}extractErrorMessage(t){if(t.json){if("string"==typeof t.json.detail)return t.json.detail;if("string"==typeof t.json.error)return t.json.error;if("string"==typeof t.json.description)return t.json.description}return`Save failed with status ${t.status}.`}showSaveErrorDialog(t){const e=document.createElement("temba-dialog");e.header="Save Failed",e.primaryButtonName="",e.cancelButtonName="Dismiss";const i=document.createElement("div");i.style.cssText="padding: 20px; font-size: 14px; line-height: 1.5;",i.textContent=t,e.appendChild(i),document.body.appendChild(e),e.open=!0,e.addEventListener("temba-dialog-hidden",()=>{document.body.removeChild(e)})}startActivityFetching(){this.simulatorActive||this.fetchActivityData()}stopActivityFetching(){null!==this.activityTimer&&(clearTimeout(this.activityTimer),this.activityTimer=null)}fetchActivityData(){var t;if(!(null===(t=this.definition)||void 0===t?void 0:t.uuid))return;if(this.simulatorActive)return;const e=`/flow/activity/${this.definition.uuid}/`,i=qd();if(!i)return;i.getState().fetchActivity(e).then(()=>{this.isConnected&&(this.activityInterval=Math.min(3e5,this.activityInterval+100),null!==this.activityTimer&&clearTimeout(this.activityTimer),this.activityTimer=window.setTimeout(()=>{this.fetchActivityData()},this.activityInterval))})}handleLanguageChange(t){Nd.getState().setLanguageCode(t)}buildMakeDefaultBody(t,e){const i=document.createElement("div");i.style.cssText="padding: 20px; line-height: 1.5;";const o=document.createElement("b");o.textContent=t;const n=document.createElement("b");return n.textContent=e,i.append("Make ",o," the default language for this flow? ",n," will be kept as a translation."),i}showMakeDefaultLanguageConfirmation(){var t;if(this.viewingRevision)return;const e=this.languageCode,i=null===(t=this.definition)||void 0===t?void 0:t.language;if(!e||!i||e===i)return;if(document.body.querySelector("temba-dialog[data-make-default]"))return;const o=Bl(e),n=Bl(i),s=document.createElement("temba-dialog");s.setAttribute("data-make-default",""),s.header="Change Default Language",s.primaryButtonName="Update",s.cancelButtonName="Cancel",s.submittingName="Updating",s.appendChild(this.buildMakeDefaultBody(o,n));const r=()=>{s.removeAttribute("data-make-default"),s.open=!1,window.setTimeout(()=>s.remove(),500)};let a=null;let l=!1;s.addEventListener("temba-button-clicked",async t=>{if("Update"!==t.detail.button.name){if(l)return;return void r()}if(l)return;l=!0,s.submitting=!0,s.disabled=!0,s.cancelButtonName="";const{error:i,flushFailed:o}=await this.changeDefaultLanguage(e);if(l=!1,s.submitting=!1,s.disabled=!1,s.cancelButtonName="Cancel",o)r();else{if(i)return a||(a=document.createElement("div"),a.style.cssText="padding: 0 20px 16px; color: var(--color-error, #e34f4f);",s.appendChild(a)),void(a.textContent=i);a&&(a.remove(),a=null),r()}}),document.body.appendChild(s),s.open=!0}async changeDefaultLanguage(t){var e;if(await this.flushSave(),this.dirtyDate)return{error:null,flushFailed:!0};try{const i=await qd().postJSON(`/flow/change_language/${this.flow}/`,{language:t});return i.status<200||i.status>=300?{error:this.extractErrorMessage(i),flushFailed:!1}:(await qd().getState().fetchRevision(`/flow/revisions/${this.flow}`),null===(e=this.getRevisionsWindow())||void 0===e||e.refresh(),{error:null,flushFailed:!1})}catch(t){return console.error("Failed to change default language:",t),{error:"Unable to change the default language. Please try again.",flushFailed:!1}}}getAvailableLanguages(){var t,e,i;return(null===(t=this.workspace)||void 0===t?void 0:t.languages)&&this.workspace.languages.length>0?this.workspace.languages.map(t=>({code:t,name:Bl(t)})).filter(t=>t.code&&t.name):(null===(i=null===(e=this.definition)||void 0===e?void 0:e._ui)||void 0===i?void 0:i.languages)&&this.definition._ui.languages.length>0?this.definition._ui.languages.map(t=>{const e="string"==typeof t?t:t.iso||t.code;return{code:e,name:Bl(e)}}):[]}getLocalizationLanguages(){if(!this.definition)return[];const t=this.definition.language;return this.getAvailableLanguages().filter(e=>e.code!==t)}getLocalizationProgress(t){return gg(this.definition,t).reduce((t,e)=>(e.translations.forEach(e=>{t.total+=1,e.to&&e.to.trim().length>0&&(t.localized+=1)}),t),{total:0,localized:0})}hasAnyNodeWithLocalizeCategories(){var t,e;return!!(null===(e=null===(t=this.definition)||void 0===t?void 0:t._ui)||void 0===e?void 0:e.nodes)&&Object.values(this.definition._ui.nodes).some(t=>{var e;return null===(e=null==t?void 0:t.config)||void 0===e?void 0:e.localizeCategories})}handleAutoTranslateClick(){if(this.viewingRevision)return;const t=this.querySelector("temba-auto-translate");null==t||t.start()}handleAutoTranslateChanged(t){var e;this.autoTranslating=!!(null===(e=t.detail)||void 0===e?void 0:e.running)}disconnectedCallback(){var t;super.disconnectedCallback(),this.zoomManager.teardownLoupe(),null===(t=qd())||void 0===t||t.getState().setFlushSave(null),this.dragManager.teardownListeners(),window.removeEventListener("beforeunload",this.boundBeforeUnload);const e=document.querySelector("temba-store");(null==e?void 0:e.markClean)&&e.markClean(this.dirtyAdapter),null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),null!==this.activityTimer&&(clearTimeout(this.activityTimer),this.activityTimer=null),this.pendingTimer.clearTimer(),window.removeEventListener("resize",this.boundWindowResize);const i=this.querySelector("#canvas");i&&i.removeEventListener("contextmenu",this.boundCanvasContextMenu);const o=this.querySelector("#editor");o&&o.removeEventListener("wheel",this.boundWheel),this.savePromise?this.savePromise.then(()=>Nd.getState().clearFlowData()):Nd.getState().clearFlowData()}setupGlobalEventListeners(){this.dragManager.setupListeners(),window.addEventListener("resize",this.boundWindowResize);const t=this.querySelector("#canvas");t&&t.addEventListener("contextmenu",this.boundCanvasContextMenu);const e=this.querySelector("#editor");e&&e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.addEventListener(jo.ActionEditRequested,this.handleActionEditRequested.bind(this)),this.addEventListener(jo.AddActionRequested,this.handleAddActionRequested.bind(this)),this.addEventListener(jo.NodeEditRequested,this.handleNodeEditRequested.bind(this)),this.addEventListener(jo.NodeDeleted,this.handleNodeDeleted.bind(this)),this.addEventListener(jo.StickyNoteDeleted,t=>{var e;const i=null===(e=t.detail)||void 0===e?void 0:e.uuid;i&&qd().getState().removeStickyNotes([i])}),this.addEventListener(jo.Selection,t=>{const e=t.target;"TEMBA-CANVAS-MENU"===e.tagName?this.handleCanvasMenuSelection(t):"TEMBA-NODE-TYPE-SELECTOR"===e.tagName&&this.handleNodeTypeSelection(t)}),this.addEventListener(jo.Canceled,t=>{const e=t.target;"TEMBA-CANVAS-MENU"===e.tagName?this.handleCanvasMenuClosed():"TEMBA-NODE-TYPE-SELECTOR"===e.tagName&&this.handleNodeTypeSelectorClosed()}),this.addEventListener(jo.DragExternal,this.handleActionDragExternal.bind(this)),this.addEventListener(jo.DragInternal,this.handleActionDragInternal.bind(this)),this.addEventListener(jo.DragStop,t=>{t.detail.isExternal&&this.handleActionDropExternal(t)}),this.addEventListener(jo.SizeChanged,t=>{const{uuid:e}=t.detail;e&&requestAnimationFrame(()=>{this.checkCollisionsAndReflow([e])})})}openFlowSearch(){if(this.viewingRevision)return;if(this.zoomManager.isDialogOrMenuOpen())return;const t=this.querySelector("temba-flow-search");t&&(t.definition=this.definition,t.languageCode=this.languageCode||"",t.scope=this.showMessageTable?"table":"flow",t.includeCategories=this.isTranslating&&this.hasAnyNodeWithLocalizeCategories(),t.show())}closeFlowSearch(){const t=this.querySelector("temba-flow-search");(null==t?void 0:t.open)&&t.hide()}handleKeyDown(t){var e,i;if("Shift"===t.key&&this.isActionExternalDrag&&!this.actionDragIsCopy&&(this.actionDragIsCopy=!0,this.showActionOriginal(!0),(null===(e=this.actionDragLastDetail)||void 0===e?void 0:e.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate()),(t.metaKey||t.ctrlKey)&&"f"===t.key)return t.preventDefault(),void this.openFlowSearch();const o=this.querySelector("temba-flow-search");if(!(null==o?void 0:o.open)){if("Delete"===t.key||"Backspace"===t.key){if(null===(i=this.deleteDialog)||void 0===i?void 0:i.open)return this.deleteSelectedItems(),void(this.deleteDialog.open=!1);this.selectedItems.size>0&&this.showDeleteConfirmation()}"Escape"===t.key&&(this.selectedItems.clear(),this.requestUpdate())}}handleKeyUp(t){var e;"Shift"===t.key&&this.isActionExternalDrag&&this.actionDragIsCopy&&(this.actionDragIsCopy=!1,this.showActionOriginal(!1),(null===(e=this.actionDragLastDetail)||void 0===e?void 0:e.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate())}handleWindowBlur(){var t;this.isActionExternalDrag&&this.actionDragIsCopy&&(this.actionDragIsCopy=!1,this.showActionOriginal(!1),(null===(t=this.actionDragLastDetail)||void 0===t?void 0:t.isLastAction)&&this.reprocessActionDrag(),this.requestUpdate())}getFlowSettings(){try{return JSON.parse(Te("flow-settings")||"{}")}catch(t){return{}}}saveFlowSetting(t,e){if(!this.flow)return;const i=this.getFlowSettings();delete i[this.flow],i[this.flow]={...i[this.flow]||{},[t]:e};const o=Object.keys(i);if(o.length>Dg.MAX_FLOW_SETTINGS)for(const t of o.slice(0,o.length-Dg.MAX_FLOW_SETTINGS))delete i[t];Ee("flow-settings",JSON.stringify(i))}getFlowSetting(t){var e;if(this.flow)return null===(e=this.getFlowSettings()[this.flow])||void 0===e?void 0:e[t]}showDeleteConfirmation(){var t;const e=this.selectedItems.size,i=1===e?"item":"items";if(null===(t=this.deleteDialog)||void 0===t?void 0:t.open)return;const o=document.createElement("temba-dialog");o.header="Delete Items",o.primaryButtonName="Delete",o.cancelButtonName="Cancel",o.destructive=!0,o.innerHTML=`<div style="padding: 20px;">Are you sure you want to delete ${e} ${i}?</div>`,o.addEventListener("temba-button-clicked",t=>{"Delete"===t.detail.button.name&&(this.deleteSelectedItems(),o.open=!1)}),document.body.appendChild(o),o.open=!0,this.deleteDialog=o,o.addEventListener("temba-dialog-hidden",()=>{document.body.removeChild(o),this.deleteDialog=null})}performReflow(){var t,e;if(!this.definition||0===this.definition.nodes.length)return;this.capturePositionsOnce();const i=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{},o={};for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];(null==i?void 0:i.position)&&(o[t.uuid]={...i.position})}const n=this.definition.nodes[0].uuid,s=new Map,r=bg(this.definition.nodes,this.definition._ui.nodes,n,t=>{const e=this.querySelector(`[id="${t}"]`);if(e){const i={width:e.offsetWidth,height:e.offsetHeight};return s.set(t,i),i}const i={width:200,height:100};return s.set(t,i),i});if(Object.keys(i).length>0){const t=new Map;for(const e of Object.keys(i)){const o=this.querySelector(`temba-sticky-note[uuid="${e}"]`);if(o)t.set(e,{width:o.offsetWidth,height:o.offsetHeight});else{const o=i[e];t.set(e,{width:o.width||200,height:o.height||100})}}const e=function(t,e,i,o,n,s){const r={},a=Object.keys(i);if(0===a.length)return r;const l=new Map,d=new Map;for(const[i,o]of Object.entries(t)){if(!o.position)continue;const t=o.position.left,n=o.position.top;let s=a[0],r=1/0;for(const i of a){const o=e[i];if(!o)continue;const a=t-o.left,l=n-o.top,d=a*a+l*l;d<r&&(r=d,s=i)}l.set(i,s);const c=e[s],h=!!c&&t<c.left,u=d.get(s)||[];u.push({uuid:i,wasLeft:h}),d.set(s,u)}const c=[];for(const t of a){const e=i[t],n=o.get(t)||{width:200,height:100};c.push({left:e.left,top:e.top,width:n.width,height:n.height})}for(const[t,e]of d){const a=i[t];if(!a)continue;const l=o.get(t)||{width:200};for(const{uuid:i,wasLeft:o}of e){const e=n.get(i)||{width:182,height:100};let d;d=t===s&&o||!o?a.left+l.width+vg:a.left-e.width-vg;let h=a.top;d=vp(Math.max(0,d)),h=vp(Math.max(0,h));let u=50;for(;u-- >0&&xg(d,h,e.width,e.height,c);)h=vp(h+vg);r[i]={left:d,top:h},c.push({left:d,top:h,width:e.width,height:e.height})}}return r}(i,o,r,s,t,n);Object.assign(r,e)}null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.pendingTimer.pending=!0,qd().getState().updateCanvasPositions(r),this.updateCanvasSize(),requestAnimationFrame(()=>{this.plumber.repaintEverything()});const a=this.querySelector("#editor");a&&a.scrollTo({left:0,top:0,behavior:"smooth"}),this.pendingTimer.start()}handlePendingDiscard(){this.pendingTimer.dismiss();if(this.copiedItemUuids.length>0||this.pendingPositions){if(null!==this.saveTimer&&(clearTimeout(this.saveTimer),this.saveTimer=null),this.copiedItemUuids.length>0){const t=this.copiedItemUuids.filter(t=>this.definition.nodes.some(e=>e.uuid===t)),e=this.copiedItemUuids.filter(t=>{var e,i;return null===(i=null===(e=this.definition._ui)||void 0===e?void 0:e.stickies)||void 0===i?void 0:i[t]});this.pendingTimer.pending=!0,t.length>0&&qd().getState().removeNodes(t),e.length>0&&(this.pendingTimer.pending=!0,qd().getState().removeStickyNotes(e)),this.copiedItemUuids=[]}this.pendingPositions&&(this.pendingTimer.pending=!0,qd().getState().updateCanvasPositions(this.pendingPositions),this.pendingPositions=null),setTimeout(()=>{qd().getState().setDirtyDate(null),this.isSaving=!1},0),requestAnimationFrame(()=>{this.plumber.repaintEverything()})}}renderPendingCard(){if(!this.pendingTimer.unsaved)return"";const t=`pc-${this.pendingTimer.resetCount}`;return Z`<div class="reflow-card">
|
|
13103
13148
|
<div class="reflow-top">
|
|
13104
13149
|
<span class="reflow-label">${this.pendingTimer.label}</span>
|
|
13105
13150
|
<button class="reflow-discard" @click=${this.handlePendingDiscard}>
|
|
@@ -13179,7 +13224,7 @@ background: #ccc;
|
|
|
13179
13224
|
</div>
|
|
13180
13225
|
</div>
|
|
13181
13226
|
</div>
|
|
13182
|
-
</div>`}checkCollisionsAndReflow(t=[]){var e,i;if(!this.definition)return;const o=[];for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];if(!(null==i?void 0:i.position))continue;const n=zp(t.uuid,i.position);n&&o.push(n)}const n=(null===(i=this.definition._ui)||void 0===i?void 0:i.stickies)||{};for(const[t,e]of Object.entries(n)){if(!e.position)continue;const i=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(!i)continue;const n=zp(t,e.position,i);n&&o.push(n)}const s=((t,e)=>{const i=new Map,o=new Set(t),n=new Map;for(const t of e)n.set(t.uuid,{...t});for(const t of[...o]){const e=n.get(t);if(e)for(const[i,s]of n)if(i!==t&&!o.has(i)&&Ip(e,s)&&e.top>s.top&&s.top<30){o.delete(t),o.add(i);break}}const s=[],r=new Set;for(const t of o){const e=n.get(t);if(e)for(const[t,i]of n)o.has(t)||r.has(t)||Ip(e,i)&&(s.push(t),r.add(t))}const a=new Set;let l=0;for(;s.length>0&&l<200;){l++;const t=s.shift();if(a.has(t))continue;const e=n.get(t),d=[];for(const[i,s]of n)i!==t&&(o.has(i)||a.has(i))&&Ip(e,s)&&d.push(s);if(0===d.length)continue;const c=d.filter(t=>o.has(t.uuid)),h=[...Lp];let u=null;if(c.length>0){for(const t of c){if(e.top>t.top){const t=h.indexOf("up");-1!==t&&h.splice(t,1)}if(e.left>t.left){const t=h.indexOf("left");-1!==t&&h.splice(t,1)}}let t=0,i=0;for(const o of c)t+=Math.min(e.right,o.right)-Math.max(e.left,o.left),i+=Math.min(e.bottom,o.bottom)-Math.max(e.top,o.top);t>i?u="vertical":i>t&&(u="horizontal")}let p=null,m=1/0;for(const i of h){const s=Pp(e,d,i);if(!s)continue;const r=Op(e,s.left,s.top);let l=!1,h=0;for(const[e,i]of n)if(e!==t&&Ip(r,i)){if(o.has(e)||a.has(e)){l=!0;break}h++}if(l)continue;const g=Math.abs(s.left-e.left)+Math.abs(s.top-e.top);let f;if(c.length>0){const t="up"===i||"down"===i;f=2e3*h+(null===u||"vertical"===u&&t||"horizontal"===u&&!t?0:5e3)+g}else f=1e4*h+g;f<m&&(m=f,p=s)}if(p){i.set(t,{left:p.left,top:p.top});const l=Op(e,p.left,p.top);n.set(t,l),a.add(t);for(const[e,i]of n)e!==t&&(o.has(e)||a.has(e)||r.has(e)||Ip(l,i)&&(s.push(e),r.add(e)))}}return i})(t,o);if(s.size>0){const t={};for(const[e,i]of s.entries())t[e]=i;qd().getState().updateCanvasPositions(t)}}findTargetNodeAt(t,e){var i;const o=document.elementFromPoint(t,e);return null!==(i=null==o?void 0:o.closest("temba-flow-node"))&&void 0!==i?i:null}updateCanvasSize(){var t;if(!this.definition)return;const e=qd();if(!e)return;let i=0,o=0;this.definition.nodes.forEach(t=>{const e=this.definition._ui.nodes[t.uuid];if(e&&e.position){const n=this.querySelector(`[id="${t.uuid}"]`);n&&(i=Math.max(i,e.position.left+n.offsetWidth),o=Math.max(o,e.position.top+n.offsetHeight))}});const n=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{};Object.entries(n).forEach(([t,e])=>{if(e.position){const n=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(n){const t=n.clientWidth,s=n.clientHeight;i=Math.max(i,e.position.left+t),o=Math.max(o,e.position.top+s)}else i=Math.max(i,e.position.left+(e.width||200)),o=Math.max(o,e.position.top+(e.height||100))}}),e.getState().expandCanvas(i,o)}handleCanvasContextMenu(t){if(this.isReadOnly())return void t.preventDefault();"canvas"===t.target.id&&(t.preventDefault(),t.stopPropagation(),this.dragManager.blurActiveContentEditable(),this.showContextMenuAt(t.clientX,t.clientY))}showContextMenuAt(t,e){if(this.isReadOnly())return;const i=this.querySelector("#canvas");if(!i)return;const o=i.getBoundingClientRect(),n=(t-o.left)/this.zoom-10,s=(e-o.top)/this.zoom-10,r=vp(n),a=vp(s),l=this.querySelector("temba-canvas-menu");if(l){const i=this.definition&&this.definition.nodes.length>0;l.show(t,e,{x:r,y:a},!0,i,qp[this.flowType])}}handleEmptyFlowClick(t){const e=this.querySelector("#editor");if(!e)return;e.scrollTo({left:0,top:0,behavior:"smooth"});const i=this.querySelector("temba-canvas-menu");if(i){const e=t.currentTarget.getBoundingClientRect(),o=265,n=e.left+e.width/2-o/2,s=e.bottom+8;i.show(n,s,{x:0,y:0},!1,!1,qp[this.flowType])}}handleCanvasMenuSelection(t){const e=t.detail,i=qd();if("reflow"!==e.action)if("sticky"===e.action){const t=i.getState().createStickyNote({left:e.position.x,top:e.position.y});requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])}),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null}else if("other"===e.action){const t=this.querySelector("temba-node-type-selector");t&&t.show("all",e.position)}else this.handleNodeTypeSelection(new CustomEvent(jo.Selection,{detail:{nodeType:e.action,position:e.position}}));else this.performReflow()}cleanUpConnection(){this.isCreatingNewNode&&(this.isCreatingNewNode=!1,this.pendingNodePosition=null),this.originalConnectionTargetId&&(this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.originalConnectionTargetId),this.originalConnectionTargetId=null),this.pendingCanvasConnection&&(this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null)}handleCanvasMenuClosed(){this.cleanUpConnection()}handleNodeTypeSelectorClosed(){this.addActionToNodeUuid=null,this.cleanUpConnection()}handleNodeTypeSelection(t){const e=t.detail;if(this.pendingCanvasConnection,this.addActionToNodeUuid){const t=this.definition.nodes.find(t=>t.uuid===this.addActionToNodeUuid),i=this.definition._ui.nodes[this.addActionToNodeUuid];if(t&&i){const o=Xt();return this.editingAction={uuid:o,type:e.nodeType},this.editingNode=t,this.editingNodeUI=i,this.isCreatingNewNode=!1,void(this.addActionToNodeUuid=null)}this.addActionToNodeUuid=null}const i=Xt(),o=e.nodeType in ag,n=o?"execute_actions":e.nodeType,s=dg[n],r=(null==s?void 0:s.form)&&Object.keys(s.form).some(t=>{var e;return["rules","categories","cases"].includes(t)||"array"===(null===(e=s.form[t])||void 0===e?void 0:e.type)}),a={uuid:i,actions:[],exits:r?[]:[{uuid:Xt(),destination_uuid:null}]};r&&(a.router={type:"switch",categories:[],cases:[],operand:"@input.text",default_category_uuid:void 0});const l={position:this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},type:n,config:{}};if(this.isCreatingNewNode=!0,this.pendingNodePosition=this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},this.editingNode=a,this.editingNodeUI=l,o){const t=Xt();this.editingAction={uuid:t,type:e.nodeType}}}handleActionEditRequested(t){this.editingAction=t.detail.action,this.editForceBase=!!t.detail.forceBase,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null;const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);i&&(this.editingNode=i,this.editingNodeUI=this.definition._ui.nodes[e])}handleAddActionRequested(t){const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);if(!i)return;const o=this.definition._ui.nodes[e];if(!o)return;const n=this.querySelector("temba-node-type-selector");n&&(n.show("action-no-branching",{x:o.position.left,y:o.position.top}),this.addActionToNodeUuid=e)}handleNodeEditRequested(t){this.editForceBase=!!t.detail.forceBase,this.editingAction=null,this.editingNode=t.detail.node,this.editingNodeUI=t.detail.nodeUI,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null}handleNodeDeleted(t){const e=t.detail.uuid;e&&this.deleteNodes([e])}handleActionSaved(t){var e,i;if(this.editingNode&&this.editingAction){let o;o=this.editingNode.actions.findIndex(t=>t.uuid===this.editingAction.uuid)>=0?this.editingNode.actions.map(e=>e.uuid===this.editingAction.uuid?t:e):[...this.editingNode.actions,t];const n={...this.editingNode,actions:o};if(this.isCreatingNewNode){const t=qd(),i={position:this.pendingNodePosition||{left:0,top:0},type:null===(e=this.editingNodeUI)||void 0===e?void 0:e.type,config:{}};t.getState().addNode(n,i),this.pendingCanvasConnection&&(t.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,n.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([n.uuid])})}else{const t=this.editingNode.uuid;null===(i=qd())||void 0===i||i.getState().updateNode(t,n),requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])})}}this.closeNodeEditor()}closeNodeEditor(){this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.editForceBase=!1}handleActionEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}handleNodeSaved(t,e){var i,o,n;if(this.editingNode)if(this.isCreatingNewNode){const o=qd(),n={position:this.pendingNodePosition||{left:0,top:0},type:null===(i=this.editingNodeUI)||void 0===i?void 0:i.type,config:e||{}};o.getState().addNode(t,n),this.pendingCanvasConnection&&(o.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,t.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t.uuid])})}else{if(this.plumber){const e=this.editingNode.exits||[],i=t.exits||[];e.filter(t=>!i.find(e=>e.uuid===t.uuid)).forEach(t=>{this.plumber.removeExitConnection(t.uuid)})}this.plumber.revalidate([t.uuid]),null===(o=qd())||void 0===o||o.getState().updateNode(this.editingNode.uuid,t),e&&(null===(n=qd())||void 0===n||n.getState().updateNodeUIConfig(t.uuid,e));const i=t.uuid;requestAnimationFrame(()=>{this.checkCollisionsAndReflow([i])})}this.closeNodeEditor()}handleNodeEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}getNodeAtPosition(t,e){const i=this.querySelectorAll("temba-flow-node");for(const o of Array.from(i)){const i=o.getBoundingClientRect();if(t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom)return o.getAttribute("data-node-uuid")}return null}calculateCanvasDropPosition(t,e,i=!0){const o=this.querySelector("#canvas");if(!o)return{left:0,top:0};const n=o.getBoundingClientRect(),s=(t-n.left)/this.zoom-20,r=(e-n.top)/this.zoom-20;return i?{left:vp(s),top:vp(r)}:{left:s,top:r}}handleActionDragExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d=60,isLastAction:c=!1}=t.detail,h=!this.isActionExternalDrag;if(this.isActionExternalDrag=!0,this.actionDragLastDetail={action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d,isLastAction:c},h){null!==(i=null===(e=this.querySelector("#canvas"))||void 0===e?void 0:e.classList.contains("shift-held"))&&void 0!==i&&i?(this.actionDragIsCopy=!0,this.showActionOriginal(!0)):null===(o=this.querySelector("#drag-hint"))||void 0===o||o.classList.add("visible")}const u=this.getNodeAtPosition(a,l);if(u&&u!==s){const t=this.definition._ui.nodes[u],e=this.definition.nodes.find(t=>t.uuid===u);if("execute_actions"===(null==t?void 0:t.type)&&e){if(this.previousActionDragTargetNodeUuid&&this.previousActionDragTargetNodeUuid!==u){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1}))}this.actionDragTargetNodeUuid=u,this.previousActionDragTargetNodeUuid=u,this.canvasDropPreview=null;const t=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);t&&t.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1}));const e=this.querySelector(`temba-flow-node[data-node-uuid="${u}"]`);return e&&e.dispatchEvent(new CustomEvent("action-drag-over",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d},bubbles:!1})),void this.requestUpdate()}}if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.actionDragTargetNodeUuid=null;const p=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);if(!c||this.actionDragIsCopy){p&&p.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const t=this.calculateCanvasDropPosition(a,l,!1);this.canvasDropPreview={action:n,nodeUuid:s,actionIndex:r,position:t,actionHeight:d}}else p&&p.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null;this.requestUpdate()}handleActionDragInternal(t){var e;if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible"),this.actionDragLastDetail=null}showActionOriginal(t){if(!this.actionDragLastDetail)return;const e=this.querySelector(`temba-flow-node[data-node-uuid="${this.actionDragLastDetail.nodeUuid}"]`);e&&e.dispatchEvent(new CustomEvent(t?"action-show-original":"action-hide-original",{detail:{},bubbles:!1}))}reprocessActionDrag(){if(!this.actionDragLastDetail)return;const{action:t,nodeUuid:e,actionIndex:i,mouseX:o,mouseY:n,actionHeight:s}=this.actionDragLastDetail,r=this.querySelector(`temba-flow-node[data-node-uuid="${e}"]`);if(!this.actionDragTargetNodeUuid)if(this.actionDragIsCopy){r&&r.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const a=this.calculateCanvasDropPosition(o,n,!1);this.canvasDropPreview={action:t,nodeUuid:e,actionIndex:i,position:a,actionHeight:s}}else r&&r.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null}handleActionDropExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isLastAction:d=!1}=t.detail,c=this.actionDragIsCopy;this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.previousActionDragTargetNodeUuid=null,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible");const h=this.actionDragTargetNodeUuid;if(h&&h!==s){const t=this.querySelector(`temba-flow-node[data-node-uuid="${h}"]`);return t&&t.dispatchEvent(new CustomEvent("action-drop",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isCopy:c},bubbles:!1})),this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null)}if(d&&!c)return this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null);const u=this.calculateCanvasDropPosition(a,l,!0);if(!c){const t=this.definition.nodes.find(t=>t.uuid===s);if(!t)return;const e=t.actions.filter((t,e)=>e!==r);if(0===e.length)this.deleteNodes([s]);else{const o={...t,actions:e};null===(i=qd())||void 0===i||i.getState().updateNode(s,o)}}const p=c?{...n,uuid:Xt()}:n,m={uuid:Xt(),actions:[p],exits:[{uuid:Xt(),destination_uuid:null}]},g={position:u,type:"execute_actions",config:{}};null===(o=qd())||void 0===o||o.getState().addNode(m,g),c&&this.copyActionLocalizations(n.uuid,p.uuid),this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([m.uuid])})}copyActionLocalizations(t,e){var i,o,n;const s=null===(i=this.definition)||void 0===i?void 0:i.localization;if(!s)return;const r=null===(o=qd())||void 0===o?void 0:o.getState();if(r)for(const i of Object.keys(s)){const o=null===(n=s[i])||void 0===n?void 0:n[t];o&&r.updateLocalization(i,e,JSON.parse(JSON.stringify(o)))}}closeOpenWindows(){var t;if(this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0),this.simulatorActive){const t=document.querySelector("temba-simulator");null==t||t.handleClose()}}closeFloatingWindows(){var t;this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0)}getRevisionsWindow(){return this.querySelector("temba-revisions-window")}handleIssuesTabClick(){this.issuesWindowHidden?(this.closeOpenWindows(),this.issuesWindowHidden=!1):this.issuesWindowHidden=!0}handleIssueSelected(t){var e;const{issue:i}=t.detail;this.issuesWindowHidden=!0,this.focusNode(i.node_uuid);const o=this.definition.nodes.find(t=>t.uuid===i.node_uuid);if(o)if(i.action_uuid){const t=null===(e=o.actions)||void 0===e?void 0:e.find(t=>t.uuid===i.action_uuid);t&&(this.editingAction=t,this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid])}else this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid]}handleRevisionViewed(){var t;this.viewingRevision=!0,this.closeFlowSearch(),null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionCancelled(){var t;this.viewingRevision=!1,null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionsClosed(){this.viewingRevision=!1,this.revisionsWindowHidden=!0}async handleRevisionReverted(t){var e;const{definition:i,languageCode:o}=t.detail;this.viewingRevision=!1,this.revisionsWindowHidden=!0,null===(e=this.plumber)||void 0===e||e.reset(),await this.saveChanges(i),qd().getState().fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{o&&this.handleLanguageChange(o)})}renderToolbarElement(){var t,e,i,o;const n=this.getLocalizationLanguages(),s=this.getAvailableLanguages(),r=null===(t=this.definition)||void 0===t?void 0:t.language,a=(null===(e=s.find(t=>t.code===r))||void 0===e?void 0:e.name)||(r?Bl(r):"")||"Primary language",l=!this.languageCode||this.languageCode===r||!n.some(t=>t.code===this.languageCode),d=l?null:n.find(t=>t.code===this.languageCode),c=d||{name:a},h=this.getLocalizationProgress(l?"":this.languageCode),u=Math.round(h.localized/Math.max(h.total,1)*100),p=!this.definition||0===this.definition.nodes.length?[]:[{name:a,value:cg},...n.map(t=>{const e=this.getLocalizationProgress(t.code),i=Math.round(e.localized/Math.max(e.total,1)*100);return{name:t.name,value:t.code,percent:i}})],m=Boolean(d)&&h.total>0;return Z`
|
|
13227
|
+
</div>`}checkCollisionsAndReflow(t=[]){var e,i;if(!this.definition)return;const o=[];for(const t of this.definition.nodes){const i=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid];if(!(null==i?void 0:i.position))continue;const n=zp(t.uuid,i.position);n&&o.push(n)}const n=(null===(i=this.definition._ui)||void 0===i?void 0:i.stickies)||{};for(const[t,e]of Object.entries(n)){if(!e.position)continue;const i=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(!i)continue;const n=zp(t,e.position,i);n&&o.push(n)}const s=((t,e)=>{const i=new Map,o=new Set(t),n=new Map;for(const t of e)n.set(t.uuid,{...t});for(const t of[...o]){const e=n.get(t);if(e)for(const[i,s]of n)if(i!==t&&!o.has(i)&&Ip(e,s)&&e.top>s.top&&s.top<30){o.delete(t),o.add(i);break}}const s=[],r=new Set;for(const t of o){const e=n.get(t);if(e)for(const[t,i]of n)o.has(t)||r.has(t)||Ip(e,i)&&(s.push(t),r.add(t))}const a=new Set;let l=0;for(;s.length>0&&l<200;){l++;const t=s.shift();if(a.has(t))continue;const e=n.get(t),d=[];for(const[i,s]of n)i!==t&&(o.has(i)||a.has(i))&&Ip(e,s)&&d.push(s);if(0===d.length)continue;const c=d.filter(t=>o.has(t.uuid)),h=[...Lp];let u=null;if(c.length>0){for(const t of c){if(e.top>t.top){const t=h.indexOf("up");-1!==t&&h.splice(t,1)}if(e.left>t.left){const t=h.indexOf("left");-1!==t&&h.splice(t,1)}}let t=0,i=0;for(const o of c)t+=Math.min(e.right,o.right)-Math.max(e.left,o.left),i+=Math.min(e.bottom,o.bottom)-Math.max(e.top,o.top);t>i?u="vertical":i>t&&(u="horizontal")}let p=null,m=1/0;for(const i of h){const s=Pp(e,d,i);if(!s)continue;const r=Op(e,s.left,s.top);let l=!1,h=0;for(const[e,i]of n)if(e!==t&&Ip(r,i)){if(o.has(e)||a.has(e)){l=!0;break}h++}if(l)continue;const g=Math.abs(s.left-e.left)+Math.abs(s.top-e.top);let f;if(c.length>0){const t="up"===i||"down"===i;f=2e3*h+(null===u||"vertical"===u&&t||"horizontal"===u&&!t?0:5e3)+g}else f=1e4*h+g;f<m&&(m=f,p=s)}if(p){i.set(t,{left:p.left,top:p.top});const l=Op(e,p.left,p.top);n.set(t,l),a.add(t);for(const[e,i]of n)e!==t&&(o.has(e)||a.has(e)||r.has(e)||Ip(l,i)&&(s.push(e),r.add(e)))}}return i})(t,o);if(s.size>0){const t={};for(const[e,i]of s.entries())t[e]=i;qd().getState().updateCanvasPositions(t)}}findTargetNodeAt(t,e){var i;const o=document.elementFromPoint(t,e);return null!==(i=null==o?void 0:o.closest("temba-flow-node"))&&void 0!==i?i:null}updateCanvasSize(){var t;if(!this.definition)return;const e=qd();if(!e)return;let i=0,o=0;this.definition.nodes.forEach(t=>{const e=this.definition._ui.nodes[t.uuid];if(e&&e.position){const n=this.querySelector(`[id="${t.uuid}"]`);n&&(i=Math.max(i,e.position.left+n.offsetWidth),o=Math.max(o,e.position.top+n.offsetHeight))}});const n=(null===(t=this.definition._ui)||void 0===t?void 0:t.stickies)||{};Object.entries(n).forEach(([t,e])=>{if(e.position){const n=this.querySelector(`temba-sticky-note[uuid="${t}"]`);if(n){const t=n.clientWidth,s=n.clientHeight;i=Math.max(i,e.position.left+t),o=Math.max(o,e.position.top+s)}else i=Math.max(i,e.position.left+(e.width||200)),o=Math.max(o,e.position.top+(e.height||100))}}),e.getState().expandCanvas(i,o)}handleCanvasContextMenu(t){if(this.isReadOnly())return void t.preventDefault();"canvas"===t.target.id&&(t.preventDefault(),t.stopPropagation(),this.dragManager.blurActiveContentEditable(),this.showContextMenuAt(t.clientX,t.clientY))}showContextMenuAt(t,e){if(this.isReadOnly())return;const i=this.querySelector("#canvas");if(!i)return;const o=i.getBoundingClientRect(),n=(t-o.left)/this.zoom-10,s=(e-o.top)/this.zoom-10,r=vp(n),a=vp(s),l=this.querySelector("temba-canvas-menu");if(l){const i=this.definition&&this.definition.nodes.length>0;l.show(t,e,{x:r,y:a},!0,i,qp[this.flowType])}}handleEmptyFlowClick(t){const e=this.querySelector("#editor");if(!e)return;e.scrollTo({left:0,top:0,behavior:"smooth"});const i=this.querySelector("temba-canvas-menu");if(i){const e=t.currentTarget.getBoundingClientRect(),o=265,n=e.left+e.width/2-o/2,s=e.bottom+8;i.show(n,s,{x:0,y:0},!1,!1,qp[this.flowType])}}handleCanvasMenuSelection(t){const e=t.detail,i=qd();if("reflow"!==e.action)if("sticky"===e.action){const t=i.getState().createStickyNote({left:e.position.x,top:e.position.y});requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])}),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null}else if("other"===e.action){const t=this.querySelector("temba-node-type-selector");t&&t.show("all",e.position)}else this.handleNodeTypeSelection(new CustomEvent(jo.Selection,{detail:{nodeType:e.action,position:e.position}}));else this.performReflow()}cleanUpConnection(){this.isCreatingNewNode&&(this.isCreatingNewNode=!1,this.pendingNodePosition=null),this.originalConnectionTargetId&&(this.plumber.connectIds(this.dragFromNodeId,this.sourceId,this.originalConnectionTargetId),this.originalConnectionTargetId=null),this.pendingCanvasConnection&&(this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null,this.originalConnectionTargetId=null)}handleCanvasMenuClosed(){this.cleanUpConnection()}handleNodeTypeSelectorClosed(){this.addActionToNodeUuid=null,this.cleanUpConnection()}handleNodeTypeSelection(t){const e=t.detail;if(this.pendingCanvasConnection,this.addActionToNodeUuid){const t=this.definition.nodes.find(t=>t.uuid===this.addActionToNodeUuid),i=this.definition._ui.nodes[this.addActionToNodeUuid];if(t&&i){const o=Xt();return this.editingAction={uuid:o,type:e.nodeType},this.editingNode=t,this.editingNodeUI=i,this.isCreatingNewNode=!1,void(this.addActionToNodeUuid=null)}this.addActionToNodeUuid=null}const i=Xt(),o=e.nodeType in ag,n=o?"execute_actions":e.nodeType,s=dg[n],r=(null==s?void 0:s.form)&&Object.keys(s.form).some(t=>{var e;return["rules","categories","cases"].includes(t)||"array"===(null===(e=s.form[t])||void 0===e?void 0:e.type)}),a={uuid:i,actions:[],exits:r?[]:[{uuid:Xt(),destination_uuid:null}]};r&&(a.router={type:"switch",categories:[],cases:[],operand:"@input.text",default_category_uuid:void 0});const l={position:this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},type:n,config:{}};if(this.isCreatingNewNode=!0,this.pendingNodePosition=this.pendingCanvasConnection?this.pendingCanvasConnection.position:{left:e.position.x,top:e.position.y},this.editingNode=a,this.editingNodeUI=l,o){const t=Xt();this.editingAction={uuid:t,type:e.nodeType}}}handleActionEditRequested(t){this.editingAction=t.detail.action,this.editForceBase=!!t.detail.forceBase,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null;const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);i&&(this.editingNode=i,this.editingNodeUI=this.definition._ui.nodes[e])}handleAddActionRequested(t){const e=t.detail.nodeUuid,i=this.definition.nodes.find(t=>t.uuid===e);if(!i)return;const o=this.definition._ui.nodes[e];if(!o)return;const n=this.querySelector("temba-node-type-selector");n&&(n.show("action-no-branching",{x:o.position.left,y:o.position.top}),this.addActionToNodeUuid=e)}handleNodeEditRequested(t){this.editForceBase=!!t.detail.forceBase,this.editingAction=null,this.editingNode=t.detail.node,this.editingNodeUI=t.detail.nodeUI,this.dialogOrigin=null!=t.detail.originX?{x:t.detail.originX,y:t.detail.originY}:null}handleNodeDeleted(t){const e=t.detail.uuid;e&&this.deleteNodes([e])}handleActionSaved(t){var e,i;if(this.editingNode&&this.editingAction){let o;o=this.editingNode.actions.findIndex(t=>t.uuid===this.editingAction.uuid)>=0?this.editingNode.actions.map(e=>e.uuid===this.editingAction.uuid?t:e):[...this.editingNode.actions,t];const n={...this.editingNode,actions:o};if(this.isCreatingNewNode){const t=qd(),i={position:this.pendingNodePosition||{left:0,top:0},type:null===(e=this.editingNodeUI)||void 0===e?void 0:e.type,config:{}};t.getState().addNode(n,i),this.pendingCanvasConnection&&(t.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,n.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([n.uuid])})}else{const t=this.editingNode.uuid;null===(i=qd())||void 0===i||i.getState().updateNode(t,n),requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t])})}}this.closeNodeEditor()}closeNodeEditor(){this.editingNode=null,this.editingNodeUI=null,this.editingAction=null,this.dialogOrigin=null,this.editForceBase=!1}handleActionEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}handleNodeSaved(t,e){var i,o,n;if(this.editingNode)if(this.isCreatingNewNode){const o=qd(),n={position:this.pendingNodePosition||{left:0,top:0},type:null===(i=this.editingNodeUI)||void 0===i?void 0:i.type,config:e||{}};o.getState().addNode(t,n),this.pendingCanvasConnection&&(o.getState().updateConnection(this.pendingCanvasConnection.fromNodeId,this.pendingCanvasConnection.exitId,t.uuid),this.pendingCanvasConnection=null,this.connectionPlaceholder=null,this.sourceId=null,this.connectionSourceX=null,this.connectionSourceY=null,this.dragFromNodeId=null),this.isCreatingNewNode=!1,this.pendingNodePosition=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([t.uuid])})}else{if(this.plumber){const e=this.editingNode.exits||[],i=t.exits||[];e.filter(t=>!i.find(e=>e.uuid===t.uuid)).forEach(t=>{this.plumber.removeExitConnection(t.uuid)})}this.plumber.revalidate([t.uuid]),null===(o=qd())||void 0===o||o.getState().updateNode(this.editingNode.uuid,t),e&&(null===(n=qd())||void 0===n||n.getState().updateNodeUIConfig(t.uuid,e));const i=t.uuid;requestAnimationFrame(()=>{this.checkCollisionsAndReflow([i])})}this.closeNodeEditor()}handleNodeEditCanceled(){this.cleanUpConnection(),this.closeNodeEditor()}getNodeAtPosition(t,e){const i=this.querySelectorAll("temba-flow-node");for(const o of Array.from(i)){const i=o.getBoundingClientRect();if(t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom)return o.getAttribute("data-node-uuid")}return null}calculateCanvasDropPosition(t,e,i=!0){const o=this.querySelector("#canvas");if(!o)return{left:0,top:0};const n=o.getBoundingClientRect(),s=(t-n.left)/this.zoom-20,r=(e-n.top)/this.zoom-20;return i?{left:vp(s),top:vp(r)}:{left:s,top:r}}handleActionDragExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d=60,isLastAction:c=!1}=t.detail,h=!this.isActionExternalDrag;if(this.isActionExternalDrag=!0,this.actionDragLastDetail={action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d,isLastAction:c},h){null!==(i=null===(e=this.querySelector("#canvas"))||void 0===e?void 0:e.classList.contains("shift-held"))&&void 0!==i&&i?(this.actionDragIsCopy=!0,this.showActionOriginal(!0)):null===(o=this.querySelector("#drag-hint"))||void 0===o||o.classList.add("visible")}const u=this.getNodeAtPosition(a,l);if(u&&u!==s){const t=this.definition._ui.nodes[u],e=this.definition.nodes.find(t=>t.uuid===u);if("execute_actions"===(null==t?void 0:t.type)&&e){if(this.previousActionDragTargetNodeUuid&&this.previousActionDragTargetNodeUuid!==u){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1}))}this.actionDragTargetNodeUuid=u,this.previousActionDragTargetNodeUuid=u,this.canvasDropPreview=null;const t=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);t&&t.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1}));const e=this.querySelector(`temba-flow-node[data-node-uuid="${u}"]`);return e&&e.dispatchEvent(new CustomEvent("action-drag-over",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,actionHeight:d},bubbles:!1})),void this.requestUpdate()}}if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.actionDragTargetNodeUuid=null;const p=this.querySelector(`temba-flow-node[data-node-uuid="${s}"]`);if(!c||this.actionDragIsCopy){p&&p.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const t=this.calculateCanvasDropPosition(a,l,!1);this.canvasDropPreview={action:n,nodeUuid:s,actionIndex:r,position:t,actionHeight:d}}else p&&p.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null;this.requestUpdate()}handleActionDragInternal(t){var e;if(this.previousActionDragTargetNodeUuid){const t=this.querySelector(`temba-flow-node[data-node-uuid="${this.previousActionDragTargetNodeUuid}"]`);t&&t.dispatchEvent(new CustomEvent("action-drag-leave",{detail:{},bubbles:!1})),this.previousActionDragTargetNodeUuid=null}this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible"),this.actionDragLastDetail=null}showActionOriginal(t){if(!this.actionDragLastDetail)return;const e=this.querySelector(`temba-flow-node[data-node-uuid="${this.actionDragLastDetail.nodeUuid}"]`);e&&e.dispatchEvent(new CustomEvent(t?"action-show-original":"action-hide-original",{detail:{},bubbles:!1}))}reprocessActionDrag(){if(!this.actionDragLastDetail)return;const{action:t,nodeUuid:e,actionIndex:i,mouseX:o,mouseY:n,actionHeight:s}=this.actionDragLastDetail,r=this.querySelector(`temba-flow-node[data-node-uuid="${e}"]`);if(!this.actionDragTargetNodeUuid)if(this.actionDragIsCopy){r&&r.dispatchEvent(new CustomEvent("action-hide-ghost",{detail:{},bubbles:!1}));const a=this.calculateCanvasDropPosition(o,n,!1);this.canvasDropPreview={action:t,nodeUuid:e,actionIndex:i,position:a,actionHeight:s}}else r&&r.dispatchEvent(new CustomEvent("action-show-ghost",{detail:{},bubbles:!1})),this.canvasDropPreview=null}handleActionDropExternal(t){var e,i,o;const{action:n,nodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isLastAction:d=!1}=t.detail,c=this.actionDragIsCopy;this.isActionExternalDrag=!1,this.actionDragIsCopy=!1,this.actionDragLastDetail=null,this.previousActionDragTargetNodeUuid=null,null===(e=this.querySelector("#drag-hint"))||void 0===e||e.classList.remove("visible");const h=this.actionDragTargetNodeUuid;if(h&&h!==s){const t=this.querySelector(`temba-flow-node[data-node-uuid="${h}"]`);return t&&t.dispatchEvent(new CustomEvent("action-drop",{detail:{action:n,sourceNodeUuid:s,actionIndex:r,mouseX:a,mouseY:l,isCopy:c},bubbles:!1})),this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null)}if(d&&!c)return this.canvasDropPreview=null,void(this.actionDragTargetNodeUuid=null);const u=this.calculateCanvasDropPosition(a,l,!0);if(!c){const t=this.definition.nodes.find(t=>t.uuid===s);if(!t)return;const e=t.actions.filter((t,e)=>e!==r);if(0===e.length)this.deleteNodes([s]);else{const o={...t,actions:e};null===(i=qd())||void 0===i||i.getState().updateNode(s,o)}}const p=c?{...n,uuid:Xt()}:n,m={uuid:Xt(),actions:[p],exits:[{uuid:Xt(),destination_uuid:null}]},g={position:u,type:"execute_actions",config:{}};null===(o=qd())||void 0===o||o.getState().addNode(m,g),c&&this.copyActionLocalizations(n.uuid,p.uuid),this.canvasDropPreview=null,this.actionDragTargetNodeUuid=null,requestAnimationFrame(()=>{this.checkCollisionsAndReflow([m.uuid])})}copyActionLocalizations(t,e){var i,o,n;const s=null===(i=this.definition)||void 0===i?void 0:i.localization;if(!s)return;const r=null===(o=qd())||void 0===o?void 0:o.getState();if(r)for(const i of Object.keys(s)){const o=null===(n=s[i])||void 0===n?void 0:n[t];o&&r.updateLocalization(i,e,JSON.parse(JSON.stringify(o)))}}closeOpenWindows(){var t;if(this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0),this.simulatorActive){const t=document.querySelector("temba-simulator");null==t||t.handleClose()}}closeFloatingWindows(){var t;this.issuesWindowHidden||(this.issuesWindowHidden=!0),this.revisionsWindowHidden||(null===(t=this.getRevisionsWindow())||void 0===t||t.close(),this.revisionsWindowHidden=!0)}getRevisionsWindow(){return this.querySelector("temba-revisions-window")}handleIssuesTabClick(){this.issuesWindowHidden?(this.closeOpenWindows(),this.issuesWindowHidden=!1):this.issuesWindowHidden=!0}handleIssueSelected(t){var e;const{issue:i}=t.detail;this.issuesWindowHidden=!0,this.focusNode(i.node_uuid);const o=this.definition.nodes.find(t=>t.uuid===i.node_uuid);if(o)if(i.action_uuid){const t=null===(e=o.actions)||void 0===e?void 0:e.find(t=>t.uuid===i.action_uuid);t&&(this.editingAction=t,this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid])}else this.editingNode=o,this.editingNodeUI=this.definition._ui.nodes[i.node_uuid]}handleRevisionViewed(){var t;this.viewingRevision=!0,this.closeFlowSearch(),null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionCancelled(){var t;this.viewingRevision=!1,null===(t=this.plumber)||void 0===t||t.reset()}handleRevisionsClosed(){this.viewingRevision=!1,this.revisionsWindowHidden=!0}async handleRevisionReverted(t){var e;const{definition:i,languageCode:o}=t.detail;this.viewingRevision=!1,this.revisionsWindowHidden=!0,null===(e=this.plumber)||void 0===e||e.reset(),await this.saveChanges(i),qd().getState().fetchRevision(`/flow/revisions/${this.flow}`).finally(()=>{o&&this.handleLanguageChange(o)})}renderToolbarElement(){var t,e,i,o;const n=this.getLocalizationLanguages(),s=this.getAvailableLanguages(),r=null===(t=this.definition)||void 0===t?void 0:t.language,a=(null===(e=s.find(t=>t.code===r))||void 0===e?void 0:e.name)||(r?Bl(r):"")||"Primary language",l=!this.languageCode||this.languageCode===r||!n.some(t=>t.code===this.languageCode),d=l?null:n.find(t=>t.code===this.languageCode),c=d||{name:a},h=this.getLocalizationProgress(l?"":this.languageCode),u=Math.round(h.localized/Math.max(h.total,1)*100),p=!this.definition||0===this.definition.nodes.length?[]:[{name:a,value:cg},...n.map(t=>{const e=this.getLocalizationProgress(t.code),i=Math.round(e.localized/Math.max(e.total,1)*100);return{name:t.name,value:t.code,percent:i}})],m=Boolean(d)&&h.total>0,g=Boolean(d)&&h.total>0&&h.localized===h.total&&!this.viewingRevision;return Z`
|
|
13183
13228
|
<temba-editor-toolbar
|
|
13184
13229
|
?message-view=${this.showMessageTable}
|
|
13185
13230
|
.zoom=${this.zoom}
|
|
@@ -13193,12 +13238,13 @@ background: #ccc;
|
|
|
13193
13238
|
?is-base-language=${l}
|
|
13194
13239
|
.languagePercent=${u}
|
|
13195
13240
|
?show-localization-tools=${Boolean(d)}
|
|
13241
|
+
?can-make-default=${g}
|
|
13196
13242
|
?has-pending-translations=${m||this.autoTranslating}
|
|
13197
13243
|
?auto-translate-disabled=${this.viewingRevision}
|
|
13198
13244
|
?auto-translating=${this.autoTranslating}
|
|
13199
13245
|
@temba-button-clicked=${this.handleToolbarAction}
|
|
13200
13246
|
></temba-editor-toolbar>
|
|
13201
|
-
`}handleToolbarAction(t){var e,i;const o=t.detail;switch(o.action){case"view-change":this.showMessageTable="table"===o.view;break;case"zoom-in":this.zoomManager.zoomIn();break;case"zoom-out":this.zoomManager.zoomOut();break;case"zoom-to-fit":this.zoomManager.zoomToFit();break;case"zoom-to-full":this.zoomManager.zoomToFull();break;case"revisions":this.revisionsWindowHidden?(this.closeOpenWindows(),this.revisionsWindowHidden=!1):(null===(e=this.getRevisionsWindow())||void 0===e||e.close(),this.revisionsWindowHidden=!0);break;case"search":this.openFlowSearch();break;case"auto-translate":this.handleAutoTranslateClick();break;case"language-change":o.isPrimary?this.handleLanguageChange((null===(i=this.definition)||void 0===i?void 0:i.language)||""):o.languageCode&&this.handleLanguageChange(o.languageCode)}}focusNode(t){const e=this.querySelector(`temba-flow-node[uuid="${t}"]`);if(!e)return;const i=this.querySelector("#editor");if(!i)return;const o=i.getBoundingClientRect(),n=o.width/2,s=o.height/2,r=e.offsetLeft+e.offsetWidth/2,a=e.offsetTop+e.offsetHeight/2,l=r*this.zoom-n,d=a*this.zoom-s;i.scrollTo({left:Math.max(0,l),top:Math.max(0,d),behavior:"smooth"})}handleSearchResultSelected(t){var e,i,o;const n=t.detail;if(n.stickyField)return void this.focusCanvasElement(`temba-sticky-note[uuid="${n.nodeUuid}"]`,n.stickyField);const s=this.definition.nodes.find(t=>t.uuid===n.nodeUuid);if(!s)return;const r=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[n.nodeUuid];if(this.showMessageTable){const t=this.querySelector("temba-message-table");null===(i=null==t?void 0:t.focusSearchResult)||void 0===i||i.call(t,n.nodeUuid,(null===(o=n.action)||void 0===o?void 0:o.uuid)||null)}else this.focusNode(n.nodeUuid);setTimeout(()=>{n.action?(this.editingAction=n.action,this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null):(this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null)},200)}focusCanvasElement(t,e){const i=this.querySelector(t);if(!i)return;const o=this.querySelector("#editor");if(!o)return;const n=o.getBoundingClientRect(),s=i.offsetLeft+i.offsetWidth/2,r=i.offsetTop+i.offsetHeight/2,a=s*this.zoom-n.width/2,l=r*this.zoom-n.height/2;o.scrollTo({left:Math.max(0,a),top:Math.max(0,l),behavior:"smooth"}),e&&setTimeout(()=>{var t;const o=null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelector(`.sticky-${e}`);o&&o.focus()},300)}isReadOnly(){return this.viewingRevision||this.isTranslating}render(){var t,e,i;const o=Z`<style>
|
|
13247
|
+
`}handleToolbarAction(t){var e,i;const o=t.detail;switch(o.action){case"view-change":this.showMessageTable="table"===o.view;break;case"zoom-in":this.zoomManager.zoomIn();break;case"zoom-out":this.zoomManager.zoomOut();break;case"zoom-to-fit":this.zoomManager.zoomToFit();break;case"zoom-to-full":this.zoomManager.zoomToFull();break;case"revisions":this.revisionsWindowHidden?(this.closeOpenWindows(),this.revisionsWindowHidden=!1):(null===(e=this.getRevisionsWindow())||void 0===e||e.close(),this.revisionsWindowHidden=!0);break;case"search":this.openFlowSearch();break;case"auto-translate":this.handleAutoTranslateClick();break;case"make-default-language":this.showMakeDefaultLanguageConfirmation();break;case"language-change":o.isPrimary?this.handleLanguageChange((null===(i=this.definition)||void 0===i?void 0:i.language)||""):o.languageCode&&this.handleLanguageChange(o.languageCode)}}focusNode(t){const e=this.querySelector(`temba-flow-node[uuid="${t}"]`);if(!e)return;const i=this.querySelector("#editor");if(!i)return;const o=i.getBoundingClientRect(),n=o.width/2,s=o.height/2,r=e.offsetLeft+e.offsetWidth/2,a=e.offsetTop+e.offsetHeight/2,l=r*this.zoom-n,d=a*this.zoom-s;i.scrollTo({left:Math.max(0,l),top:Math.max(0,d),behavior:"smooth"})}handleSearchResultSelected(t){var e,i,o;const n=t.detail;if(n.stickyField)return void this.focusCanvasElement(`temba-sticky-note[uuid="${n.nodeUuid}"]`,n.stickyField);const s=this.definition.nodes.find(t=>t.uuid===n.nodeUuid);if(!s)return;const r=null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[n.nodeUuid];if(this.showMessageTable){const t=this.querySelector("temba-message-table");null===(i=null==t?void 0:t.focusSearchResult)||void 0===i||i.call(t,n.nodeUuid,(null===(o=n.action)||void 0===o?void 0:o.uuid)||null)}else this.focusNode(n.nodeUuid);setTimeout(()=>{n.action?(this.editingAction=n.action,this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null):(this.editingNode=s,this.editingNodeUI=r,this.dialogOrigin=null)},200)}focusCanvasElement(t,e){const i=this.querySelector(t);if(!i)return;const o=this.querySelector("#editor");if(!o)return;const n=o.getBoundingClientRect(),s=i.offsetLeft+i.offsetWidth/2,r=i.offsetTop+i.offsetHeight/2,a=s*this.zoom-n.width/2,l=r*this.zoom-n.height/2;o.scrollTo({left:Math.max(0,a),top:Math.max(0,l),behavior:"smooth"}),e&&setTimeout(()=>{var t;const o=null===(t=i.shadowRoot)||void 0===t?void 0:t.querySelector(`.sticky-${e}`);o&&o.focus()},300)}isReadOnly(){return this.viewingRevision||this.isTranslating}render(){var t,e,i;const o=Z`<style>
|
|
13202
13248
|
${l(Dg.styles.cssText)}
|
|
13203
13249
|
${l(Cg.styles.cssText)}
|
|
13204
13250
|
</style>`,n=(null===(e=null===(t=this.definition)||void 0===t?void 0:t._ui)||void 0===e?void 0:e.stickies)||{},s=this.definition&&this.definition.nodes.length>0&&this.definition.nodes.some(t=>{var e;return!(null===(e=this.definition._ui)||void 0===e?void 0:e.nodes[t.uuid])});return Z`${o}
|
|
@@ -18654,7 +18700,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
|
|
|
18654
18700
|
fill: var(--accent-100);
|
|
18655
18701
|
opacity: 0.7;
|
|
18656
18702
|
}
|
|
18657
|
-
`}constructor(){super(),this.valueKey="uuid",this.emptyMessage="No flows",this.searchPlaceholder="Search flows",this.columns=[{key:"name",label:"Name",sortable:!0,width:"280px",pinned:!0},{key:"
|
|
18703
|
+
`}constructor(){super(),this.valueKey="uuid",this.emptyMessage="No flows",this.searchPlaceholder="Search flows",this.columns=[{key:"name",label:"Name",sortable:!0,width:"280px",pinned:!0},{key:"runs",label:"Runs",sortable:!0,width:"90px",align:"right"},{key:"ongoing",label:"Ongoing",sortable:!0,width:"90px",align:"right"},{key:"completion",label:"Completion",width:"130px",align:"right"},{key:"activity",label:"Activity",width:"120px",align:"right"}],this.bulkActions=[{key:"label",label:"Label",icon:Io.label,labelsEndpoint:"/api/v2/flow-labels.json"},{key:"export",label:"Export results",icon:Io.export},{key:"archive",label:"Archive",icon:Io.archive}]}getRowIcon(t){switch(null==t?void 0:t.type){case"voice":case"ivr":return Io.flow_ivr;case"background":return Io.flow_background;case"survey":return Io.flow_surveyor;default:return null}}getRowHref(t){return(null==t?void 0:t.uuid)?`/flow/editor/${t.uuid}/`:null}renderCell(t,e){var i,o;switch(e.key){case"name":{const e=t.labels||[];return Z`<span class="flow-name"
|
|
18658
18704
|
>${t.name||""}
|
|
18659
18705
|
${t.has_issues?Z`<temba-icon
|
|
18660
18706
|
class="issue-icon"
|
|
@@ -18668,7 +18714,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
|
|
|
18668
18714
|
</span>`:null}
|
|
18669
18715
|
</span>`}case"runs":return Z`<span class="num"
|
|
18670
18716
|
>${(null!==(i=t.runs)&&void 0!==i?i:0).toLocaleString()}</span
|
|
18671
|
-
>`;case"ongoing":return Z`<span class="num">${null!==(o=t.ongoing)&&void 0!==o?o:0}</span>`;case"completion":return this.renderCompletion(t);case"activity":return this.renderSparkline(t.activity||[]);
|
|
18717
|
+
>`;case"ongoing":return Z`<span class="num">${null!==(o=t.ongoing)&&void 0!==o?o:0}</span>`;case"completion":return this.renderCompletion(t);case"activity":return this.renderSparkline(t.activity||[]);default:return super.renderCell(t,e)}}renderCompletion(t){const e="number"==typeof t.completion?t.completion:0,i=Math.round(100*e);return Z`
|
|
18672
18718
|
<div class="completion-bar">
|
|
18673
18719
|
<div class="bar">
|
|
18674
18720
|
<div class="fill" style="width: ${i}%"></div>
|
|
@@ -18686,7 +18732,7 @@ function(t){return(e,i,o)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Reflect.
|
|
|
18686
18732
|
<path class="area" d=${`${r} L90,22 L0,22 Z`}></path>
|
|
18687
18733
|
<polyline class="line" points=${s}></polyline>
|
|
18688
18734
|
</svg>
|
|
18689
|
-
`}
|
|
18735
|
+
`}}),VC("temba-list",Ph),VC("temba-sortable-list",Hd),VC("temba-run-list",hu),VC("temba-flow-details",uu),VC("temba-label",Jh),VC("temba-menu",Yh),VC("temba-contact-search",qh),VC("temba-icon",Uh),VC("temba-dropdown",Gh),VC("temba-tabs",Xh),VC("temba-tab",Qh),VC("temba-contact-badges",ru),VC("temba-contact-timeline",lu),VC("temba-slider",du),VC("temba-content-menu",xu),VC("temba-compose",ku),VC("temba-color-picker",Su),VC("temba-resizer",$u),VC("temba-thumbnail",Du),VC("temba-webchat",Bu),VC("temba-image-picker",qu),VC("temba-mask",Uu),VC("temba-user",Ol),VC("temba-template-editor",ju),VC("temba-toast",Hu),VC("temba-chat",xh),VC("temba-media-picker",Vu),VC("temba-flow-editor",Dg),VC("temba-editor-toolbar",hg),VC("temba-message-table",WC),VC("temba-node-editor",uC),VC("temba-flow-node",Cg),VC("temba-sticky-note",Mg),VC("temba-canvas-menu",zg),VC("temba-node-type-selector",Ig),VC("temba-contact-notepad",Lg),VC("temba-progress",Og),VC("temba-start-progress",Pg),VC("temba-shortcuts",Rg),VC("temba-popup-select",Ng),VC("temba-user-select",Bg),VC("temba-workspace-select",Fg),VC("temba-chart",Jk),VC("temba-key-value-editor",mC),VC("temba-array-editor",gC),VC("temba-message-editor",fC),VC("temba-rich-edit",vC),VC("temba-accordion",xC),VC("temba-accordion-section",wC),VC("temba-expression-highlight",bC),VC("temba-floating-tab",$g),VC("temba-floating-window",yC),VC("temba-simulator",AC),VC("temba-flow-search",OC),VC("temba-issues-window",PC),VC("temba-revisions-window",UC),VC("temba-auto-translate",HC);class ZC extends ht{static get styles(){return d`
|
|
18690
18736
|
:host {
|
|
18691
18737
|
line-height: normal;
|
|
18692
18738
|
}
|