import{d as Y,i as W,a as A,c as _,r as F,V as Q,L as V,o as l,e as i,f as e,F as h,s as f,t as v,m as X,J as y,b as x,n as O,l as w,q as C,ax as Z,ay as ee,y as te,z as oe,N as se,_ as ne}from"./index-8C--RVV5.js";import{e as ae}from"./toggleHighContrast-D1cjJdpv.js";import{B as T}from"./BuilderApp-BudRb5tG.js";import{B as le}from"./BuilderSettings-CHy-YURr.js";import"./marked.esm-273vDTCT.js";import"./instancePath-BsbOTTI8.js";const d=k=>(te("data-v-73907a14"),k=k(),oe(),k),ie={key:0,class:"BuilderSettingsHandlers"},de=d(()=>e("div",{class:"sectionTitle"},[e("i",{class:"material-symbols-outlined"},"bolt"),e("h3",null,"Events")],-1)),re={class:"list"},ce={class:"columns"},ue={class:"fieldWrapperMain"},pe={class:"name"},me={class:"content"},ve={class:"fieldActions"},_e=["onClick"],he=d(()=>e("i",{class:"material-symbols-outlined"},"help",-1)),fe=[he],ye={key:0,class:"desc"},ke=d(()=>e("div",{class:"stubMessage"}," You can use the following stub code as a starting point for your event handler. ",-1)),ge={class:"codeContainer"},be=d(()=>e("i",{class:"material-symbols-outlined"}," content_copy ",-1)),we={class:"customHandler"},Ce=d(()=>e("i",{class:"material-symbols-outlined"},"add",-1)),$e={class:"customHandlerModalForm"},He={class:"fieldWrapper"},Se={class:"fieldWrapperMain"},Be=d(()=>e("span",{class:"name"},"Event type",-1)),Me={id:"commonEventTypes"},Ee=["value"],Ne=d(()=>e("span",{class:"desc"},"Can be any event type.",-1)),We={class:"fieldWrapper"},Ae=d(()=>e("div",{class:"fieldWrapperMain"},[e("span",{class:"name"},"Handler function")],-1)),Fe=["value"],Ve=["value"],xe=["value"],Oe=d(()=>e("span",{class:"desc"},"The function that will handle the event.",-1)),Te=d(()=>e("i",{class:"material-symbols-outlined"},"add",-1)),De=Y({__name:"BuilderSettingsHandlers",setup(k){const u=W(A.core),g=W(A.builderManager),{setHandlerValue:$}=se(u,g),c=_(()=>u.getComponentById(g.getSelectedId())),H=_(()=>{const a=b.value.map(n=>n.name).map(n=>({value:n,label:n,icon:"function"})),o=S.value.map(n=>({label:`Go to page "${n}"`,value:`$goToPage_${n}`,icon:"link"})),t=B.value.map(n=>({label:`Run workflow "${n}"`,value:`$runWorkflow_${n}`,icon:"linked_services"}));return[{label:"(No handler)",value:"",icon:"block"},...a,...o,...t]});function D(a){var t;if(!j(a))return H.value;const o=(t=c.value.handlers)==null?void 0:t[a];return[...H.value,{value:o,label:`${o} (Not found)`}]}const K=_(()=>{const{type:a}=c.value,{events:o}=u.getComponentDefinition(a),t={...o};return Object.keys({...c.value.handlers}).forEach(n=>{t[n]||(t[n]={desc:"Custom event"})}),t}),b=u.userFunctions,S=_(()=>u.getComponents("root").filter(t=>t.type=="page").map(t=>t.content.key).filter(t=>!!t)),B=_(()=>u.getComponents("workflows_root").filter(t=>t.type=="workflows_workflow").map(t=>t.content.key).filter(t=>!!t)),j=a=>{var t;const o=(t=c.value.handlers)==null?void 0:t[a];return!(!o||o.startsWith("$")||b.value.some(n=>n.name==o))},U=(a,o)=>{$(c.value.id,o,a)},m=F(null),r=F(null);function z(){return`
# When dealing with a DOM event, Writer Framework generates a payload by serialising its
# primitive properties (non-Object, non-function properties).

# If the event is instead an instance of CustomEvent,
# it looks for a "payload" property inside the CustomEvent's "detail" property. 

def handle_keydown(state, payload):
	print(payload) # Shows all the properties captured

	key_activated = payload.get("key")
	if key_activated == "ArrowLeft":
		state["position"] += -10
	elif key_activated == "ArrowRight":
		state["position"] += 10

	`}function M(a){const{type:o}=c.value,{events:t}=u.getComponentDefinition(o),n=t==null?void 0:t[a];return n?n==null?void 0:n.stub:z()}async function I(a){const o=M(a),t=await ae.colorize(o.trim(),"python",{});m.value={modalTitle:`"${a}" event`,code:o,highlightedCodeHtml:t}}const L=["click","mousedown","mouseup","mouseenter","mouseleave","mousemove","keydown","keyup","keypress","input","change","submit","focus","blur","resize","scroll","load"];function P(){const{eventType:a,handlerFunctionName:o}=r.value;$(c.value.id,a,o),r.value=null}const R={desc:"Close",fn:()=>{m.value=null}};function G(){r.value={eventType:null,handlerFunctionName:null}}const q={desc:"Close",fn:()=>{r.value=null}},J=a=>{navigator.clipboard.writeText(a)};return(a,o)=>{var n;const t=Q("dompurify-html");return V(g).isSelectionActive()?(l(),i("div",ie,[de,e("div",re,[(l(!0),i(h,null,f(K.value,(s,p)=>{var E;return l(),i("div",{key:p,class:"fieldWrapper"},[e("div",ce,[e("div",ue,[e("span",pe,v(p),1),e("div",me,[X(le,{"model-value":((E=c.value.handlers)==null?void 0:E[p])??"",options:D(p),variant:"embedded","enable-search":"","onUpdate:modelValue":N=>U(N,p)},null,8,["model-value","options","onUpdate:modelValue"])])]),e("div",ve,[M(p)?(l(),i("button",{key:0,variant:"subtle",title:"Show event handler stub",onClick:N=>I(p)},fe,8,_e)):y("",!0)])]),s!=null&&s.desc?(l(),i("div",ye,v(s.desc),1)):y("",!0)])}),128))]),m.value?(l(),x(T,{key:0,"close-action":R,icon:"help","modal-title":(n=m.value)==null?void 0:n.modalTitle},{default:O(()=>[ke,e("div",ge,[w(e("code",null,null,512),[[t,m.value.highlightedCodeHtml]])]),e("button",{onClick:o[0]||(o[0]=s=>J(m.value.code))},[be,C(" Copy code to clipboard ")])]),_:1},8,["modal-title"])):y("",!0),e("div",we,[e("button",{title:"Add a custom event handler",onClick:G},[Ce,C("Add custom handler ")]),r.value?(l(),x(T,{key:0,"close-action":q,icon:"bolt","modal-title":"Add Custom Event Handler"},{default:O(()=>[e("div",$e,[e("div",He,[e("div",Se,[Be,w(e("input",{"onUpdate:modelValue":o[1]||(o[1]=s=>r.value.eventType=s),class:"content",type:"text",list:"commonEventTypes"},null,512),[[Z,r.value.eventType]]),e("datalist",Me,[(l(),i(h,null,f(L,s=>e("option",{key:s,value:s},v(s),9,Ee)),64))])]),Ne]),e("div",We,[Ae,w(e("select",{"onUpdate:modelValue":o[2]||(o[2]=s=>r.value.handlerFunctionName=s),class:"content"},[(l(!0),i(h,null,f(V(b),s=>(l(),i("option",{key:s.name,value:s.name},v(s.name),9,Fe))),128)),(l(!0),i(h,null,f(S.value,s=>(l(),i("option",{key:`$goToPage_${s}`,value:`$goToPage_${s}`},' Go to page "'+v(s)+'" ',9,Ve))),128)),(l(!0),i(h,null,f(B.value,s=>(l(),i("option",{key:`$runWorkflow_${s}`,value:`$runWorkflow_${s}`},' Run workflow "'+v(s)+'" ',9,xe))),128))],512),[[ee,r.value.handlerFunctionName]]),Oe])]),e("button",{onClick:o[3]||(o[3]=s=>P())},[Te,C("Add ")])]),_:1})):y("",!0)])])):y("",!0)}}}),Pe=ne(De,[["__scopeId","data-v-73907a14"]]);export{Pe as default};
