@kizenapps/cli 1.1.0 → 1.1.1-d2d94ec
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/dist/viewer/assets/{CodeStepsPage-nECzIPiV.js → CodeStepsPage-B8GxbLxI.js} +1 -1
- package/dist/viewer/assets/ConfigurationPage-Dxbnrr9j.js +1 -0
- package/dist/viewer/assets/SandboxPage-B0MxFcYd.js +1 -0
- package/dist/viewer/assets/WhenBadge-BcgTLbpu.js +1 -0
- package/dist/viewer/assets/api-BcUybEsl.js +10 -0
- package/dist/viewer/assets/configStorage-CJZAV_2p.js +1 -0
- package/dist/viewer/assets/{index-BVpA7WNR.js → index-CiXkrLfH.js} +3 -3
- package/dist/viewer/assets/useCriticalExceptionDialog-DQOlM11I.js +5 -0
- package/dist/viewer/index.html +3 -3
- package/package.json +1 -1
- package/dist/viewer/assets/ConfigurationPage-D0tcJxje.js +0 -1
- package/dist/viewer/assets/SandboxPage-Bnp6YAtk.js +0 -1
- package/dist/viewer/assets/WhenBadge-pfupnVMz.js +0 -1
- package/dist/viewer/assets/api-CT-MKz2h.js +0 -1
- package/dist/viewer/assets/configStorage-TfZCyGrB.js +0 -10
- package/dist/viewer/assets/useCriticalExceptionDialog-FcLgRoVH.js +0 -5
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-DF2fYuay.js";import{A as t,j as n,k as r,y as i}from"./fa-core-BoBqCOD3.js";import{n as a}from"./react-csXWLXSE.js";import{A as o,I as s,M as c,O as l,a as u,c as d,d as f,f as p,i as m,l as h,n as g,o as _,p as v,r as y,s as b,u as x,v as S}from"./useQuery-5OkVbV1s.js";import{a as C,i as w,n as T,o as E,r as D}from"./BootstrapContext-D5ZnMrOp.js";import{C as O,S as k,_ as A,b as j,c as M,d as N,f as P,g as F,h as I,i as L,l as R,m as ee,p as z,u as te,v as B,x as ne,y as re}from"./api-BcUybEsl.js";function ie(e,t){let n=new Set(t);return e.filter(e=>!n.has(e))}function ae(e,t,n){let r=e.slice(0);return r[t]=n,r}var V=class extends s{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=[];constructor(e,t,n){super(),this.#e=e,this.#r=n,this.#n=[],this.#i=[],this.#t=[],this.setQueries(t)}onSubscribe(){this.listeners.size===1&&this.#i.forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,this.#i.forEach(e=>{e.destroy()})}setQueries(e,t){this.#n=e,this.#r=t,S.batch(()=>{let e=this.#i,t=this.#f(this.#n);t.forEach(e=>e.observer.setOptions(e.defaultedQueryOptions));let n=t.map(e=>e.observer),r=n.map(e=>e.getCurrentResult()),i=e.length!==n.length,a=n.some((t,n)=>t!==e[n]),o=i||a,s=o?!0:r.some((e,t)=>{let n=this.#t[t];return!n||!c(e,n)});!o&&!s||(o&&(this.#l=t,this.#i=n),this.#t=r,this.hasListeners()&&(o&&(ie(e,n).forEach(e=>{e.destroy()}),ie(n,e).forEach(e=>{e.subscribe(t=>{this.#p(e,t)})})),this.#m()))})}getCurrentResult(){return this.#t}getQueries(){return this.#i.map(e=>e.getCurrentQuery())}getObservers(){return this.#i}getOptimisticResult(e,t){let n=this.#f(e),r=n.map(e=>e.observer.getOptimisticResult(e.defaultedQueryOptions)),i=n.map(e=>e.defaultedQueryOptions.queryHash);return[r,e=>this.#d(e??r,t,i),()=>this.#u(r,n)]}#u(e,t){return t.map((n,r)=>{let i=e[r];return n.defaultedQueryOptions.notifyOnChangeProps?i:n.observer.trackResult(i,e=>{t.forEach(t=>{t.observer.trackProp(e)})})})}#d(e,t,n){if(t){let r=this.#c,i=n!==void 0&&r!==void 0&&(r.length!==n.length||n.some((e,t)=>e!==r[t]));return(!this.#a||this.#t!==this.#s||i||t!==this.#o)&&(this.#o=t,this.#s=this.#t,n!==void 0&&(this.#c=n),this.#a=o(this.#a,t(e))),this.#a}return e}#f(e){let t=new Map;this.#i.forEach(e=>{let n=e.options.queryHash;if(!n)return;let r=t.get(n);r?r.push(e):t.set(n,[e])});let n=[];return e.forEach(e=>{let r=this.#e.defaultQueryOptions(e),i=t.get(r.queryHash)?.shift()??new v(this.#e,r);n.push({defaultedQueryOptions:r,observer:i})}),n}#p(e,t){let n=this.#i.indexOf(e);n!==-1&&(this.#t=ae(this.#t,n,t),this.#m())}#m(){if(this.hasListeners()){let e=this.#a,t=this.#u(this.#t,this.#l);e!==this.#d(t,this.#r?.combine)&&S.batch(()=>{this.listeners.forEach(e=>{e(this.#t)})})}}},H=e(n(),1);function U({queries:e,...t},n){let r=p(n),i=h(),a=d(),o=H.useMemo(()=>e.map(e=>{let t=r.defaultQueryOptions(e);return t._optimisticResults=i?`isRestoring`:`optimistic`,t}),[e,r,i]);o.forEach(e=>{g(e),u(e,a,r.getQueryCache().get(e.queryHash))}),b(a);let[s]=H.useState(()=>new V(r,o,t)),[c,f,x]=s.getOptimisticResult(o,t.combine),C=!i&&t.subscribed!==!1;H.useSyncExternalStore(H.useCallback(e=>C?s.subscribe(S.batchCalls(e)):l,[s,C]),()=>s.getCurrentResult(),()=>s.getCurrentResult()),H.useEffect(()=>{s.setQueries(o,t)},[o,t,s]);let w=c.some((e,t)=>m(o[t],e))?c.flatMap((e,t)=>{let n=o[t];return n&&m(n,e)?y(n,new v(r,n),a):[]}):[];if(w.length>0)throw Promise.all(w);let T=c.find((e,t)=>{let n=o[t];return n&&_({result:e,errorResetBoundary:a,throwOnError:n.throwOnError,query:r.getQueryCache().get(n.queryHash),suspense:n.suspense})});if(T?.error)throw T.error;return f(x())}var oe=`integration:${re.RUN_FRAME_SCRIPT}`,se={lessThanXSeconds:{one:`less than a second`,other:`less than {{count}} seconds`},xSeconds:{one:`1 second`,other:`{{count}} seconds`},halfAMinute:`half a minute`,lessThanXMinutes:{one:`less than a minute`,other:`less than {{count}} minutes`},xMinutes:{one:`1 minute`,other:`{{count}} minutes`},aboutXHours:{one:`about 1 hour`,other:`about {{count}} hours`},xHours:{one:`1 hour`,other:`{{count}} hours`},xDays:{one:`1 day`,other:`{{count}} days`},aboutXWeeks:{one:`about 1 week`,other:`about {{count}} weeks`},xWeeks:{one:`1 week`,other:`{{count}} weeks`},aboutXMonths:{one:`about 1 month`,other:`about {{count}} months`},xMonths:{one:`1 month`,other:`{{count}} months`},aboutXYears:{one:`about 1 year`,other:`about {{count}} years`},xYears:{one:`1 year`,other:`{{count}} years`},overXYears:{one:`over 1 year`,other:`over {{count}} years`},almostXYears:{one:`almost 1 year`,other:`almost {{count}} years`}},ce=(e,t,n)=>{let r,i=se[e];return r=typeof i==`string`?i:t===1?i.one:i.other.replace(`{{count}}`,t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?`in `+r:r+` ago`:r};function le(e){return(t={})=>{let n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}var ue={date:le({formats:{full:`EEEE, MMMM do, y`,long:`MMMM do, y`,medium:`MMM d, y`,short:`MM/dd/yyyy`},defaultWidth:`full`}),time:le({formats:{full:`h:mm:ss a zzzz`,long:`h:mm:ss a z`,medium:`h:mm:ss a`,short:`h:mm a`},defaultWidth:`full`}),dateTime:le({formats:{full:`{{date}} 'at' {{time}}`,long:`{{date}} 'at' {{time}}`,medium:`{{date}}, {{time}}`,short:`{{date}}, {{time}}`},defaultWidth:`full`})},de={lastWeek:`'last' eeee 'at' p`,yesterday:`'yesterday at' p`,today:`'today at' p`,tomorrow:`'tomorrow at' p`,nextWeek:`eeee 'at' p`,other:`P`},fe=(e,t,n,r)=>de[e];function pe(e){return(t,n)=>{let r=n?.context?String(n.context):`standalone`,i;if(r===`formatting`&&e.formattingValues){let t=e.defaultFormattingWidth||e.defaultWidth,r=n?.width?String(n.width):t;i=e.formattingValues[r]||e.formattingValues[t]}else{let t=e.defaultWidth,r=n?.width?String(n.width):e.defaultWidth;i=e.values[r]||e.values[t]}let a=e.argumentCallback?e.argumentCallback(t):t;return i[a]}}var me={ordinalNumber:(e,t)=>{let n=Number(e),r=n%100;if(r>20||r<10)switch(r%10){case 1:return n+`st`;case 2:return n+`nd`;case 3:return n+`rd`}return n+`th`},era:pe({values:{narrow:[`B`,`A`],abbreviated:[`BC`,`AD`],wide:[`Before Christ`,`Anno Domini`]},defaultWidth:`wide`}),quarter:pe({values:{narrow:[`1`,`2`,`3`,`4`],abbreviated:[`Q1`,`Q2`,`Q3`,`Q4`],wide:[`1st quarter`,`2nd quarter`,`3rd quarter`,`4th quarter`]},defaultWidth:`wide`,argumentCallback:e=>e-1}),month:pe({values:{narrow:[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`],abbreviated:[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],wide:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`]},defaultWidth:`wide`}),day:pe({values:{narrow:[`S`,`M`,`T`,`W`,`T`,`F`,`S`],short:[`Su`,`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`],abbreviated:[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],wide:[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`]},defaultWidth:`wide`}),dayPeriod:pe({values:{narrow:{am:`a`,pm:`p`,midnight:`mi`,noon:`n`,morning:`morning`,afternoon:`afternoon`,evening:`evening`,night:`night`},abbreviated:{am:`AM`,pm:`PM`,midnight:`midnight`,noon:`noon`,morning:`morning`,afternoon:`afternoon`,evening:`evening`,night:`night`},wide:{am:`a.m.`,pm:`p.m.`,midnight:`midnight`,noon:`noon`,morning:`morning`,afternoon:`afternoon`,evening:`evening`,night:`night`}},defaultWidth:`wide`,formattingValues:{narrow:{am:`a`,pm:`p`,midnight:`mi`,noon:`n`,morning:`in the morning`,afternoon:`in the afternoon`,evening:`in the evening`,night:`at night`},abbreviated:{am:`AM`,pm:`PM`,midnight:`midnight`,noon:`noon`,morning:`in the morning`,afternoon:`in the afternoon`,evening:`in the evening`,night:`at night`},wide:{am:`a.m.`,pm:`p.m.`,midnight:`midnight`,noon:`noon`,morning:`in the morning`,afternoon:`in the afternoon`,evening:`in the evening`,night:`at night`}},defaultFormattingWidth:`wide`})};function W(e){return(t,n={})=>{let r=n.width,i=r&&e.matchPatterns[r]||e.matchPatterns[e.defaultMatchWidth],a=t.match(i);if(!a)return null;let o=a[0],s=r&&e.parsePatterns[r]||e.parsePatterns[e.defaultParseWidth],c=Array.isArray(s)?ge(s,e=>e.test(o)):he(s,e=>e.test(o)),l;l=e.valueCallback?e.valueCallback(c):c,l=n.valueCallback?n.valueCallback(l):l;let u=t.slice(o.length);return{value:l,rest:u}}}function he(e,t){for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function ge(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function _e(e){return(t,n={})=>{let r=t.match(e.matchPattern);if(!r)return null;let i=r[0],a=t.match(e.parsePattern);if(!a)return null;let o=e.valueCallback?e.valueCallback(a[0]):a[0];o=n.valueCallback?n.valueCallback(o):o;let s=t.slice(i.length);return{value:o,rest:s}}}var ve={code:`en-US`,formatDistance:ce,formatLong:ue,formatRelative:fe,localize:me,match:{ordinalNumber:_e({matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:e=>parseInt(e,10)}),era:W({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:`wide`,parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:`any`}),quarter:W({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:`wide`,parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:`any`,valueCallback:e=>e+1}),month:W({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:`wide`,parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:`any`}),day:W({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:`wide`,parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:`any`}),dayPeriod:W({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:`any`,parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:`any`})},options:{weekStartsOn:0,firstWeekContainsDate:1}},ye={};function be(){return ye}var xe=365.2425,Se=6048e5,Ce=864e5,we=3600*24;we*7,we*xe/12*3;var Te=Symbol.for(`constructDateFrom`);function G(e,t){return typeof e==`function`?e(t):e&&typeof e==`object`&&Te in e?e[Te](t):e instanceof Date?new e.constructor(t):new Date(t)}function K(e,t){return G(t||e,e)}function Ee(e){let t=K(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),e-+n}function De(e,...t){let n=G.bind(null,e||t.find(e=>typeof e==`object`));return t.map(n)}function Oe(e,t){let n=K(e,t?.in);return n.setHours(0,0,0,0),n}function ke(e,t,n){let[r,i]=De(n?.in,e,t),a=Oe(r),o=Oe(i),s=+a-Ee(a),c=+o-Ee(o);return Math.round((s-c)/Ce)}function Ae(e,t){let n=K(e,t?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}function je(e,t){let n=K(e,t?.in);return ke(n,Ae(n))+1}function Me(e,t){let n=be(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,i=K(e,t?.in),a=i.getDay(),o=(a<r?7:0)+a-r;return i.setDate(i.getDate()-o),i.setHours(0,0,0,0),i}function Ne(e,t){return Me(e,{...t,weekStartsOn:1})}function Pe(e,t){let n=K(e,t?.in),r=n.getFullYear(),i=G(n,0);i.setFullYear(r+1,0,4),i.setHours(0,0,0,0);let a=Ne(i),o=G(n,0);o.setFullYear(r,0,4),o.setHours(0,0,0,0);let s=Ne(o);return n.getTime()>=a.getTime()?r+1:n.getTime()>=s.getTime()?r:r-1}function Fe(e,t){let n=Pe(e,t),r=G(t?.in||e,0);return r.setFullYear(n,0,4),r.setHours(0,0,0,0),Ne(r)}function Ie(e,t){let n=K(e,t?.in),r=Ne(n)-+Fe(n);return Math.round(r/Se)+1}function Le(e,t){let n=K(e,t?.in),r=n.getFullYear(),i=be(),a=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??i.firstWeekContainsDate??i.locale?.options?.firstWeekContainsDate??1,o=G(t?.in||e,0);o.setFullYear(r+1,0,a),o.setHours(0,0,0,0);let s=Me(o,t),c=G(t?.in||e,0);c.setFullYear(r,0,a),c.setHours(0,0,0,0);let l=Me(c,t);return+n>=+s?r+1:+n>=+l?r:r-1}function Re(e,t){let n=be(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,i=Le(e,t),a=G(t?.in||e,0);return a.setFullYear(i,0,r),a.setHours(0,0,0,0),Me(a,t)}function ze(e,t){let n=K(e,t?.in),r=Me(n,t)-+Re(n,t);return Math.round(r/Se)+1}function q(e,t){return(e<0?`-`:``)+Math.abs(e).toString().padStart(t,`0`)}var J={y(e,t){let n=e.getFullYear(),r=n>0?n:1-n;return q(t===`yy`?r%100:r,t.length)},M(e,t){let n=e.getMonth();return t===`M`?String(n+1):q(n+1,2)},d(e,t){return q(e.getDate(),t.length)},a(e,t){let n=e.getHours()/12>=1?`pm`:`am`;switch(t){case`a`:case`aa`:return n.toUpperCase();case`aaa`:return n;case`aaaaa`:return n[0];default:return n===`am`?`a.m.`:`p.m.`}},h(e,t){return q(e.getHours()%12||12,t.length)},H(e,t){return q(e.getHours(),t.length)},m(e,t){return q(e.getMinutes(),t.length)},s(e,t){return q(e.getSeconds(),t.length)},S(e,t){let n=t.length,r=e.getMilliseconds();return q(Math.trunc(r*10**(n-3)),t.length)}},Be={am:`am`,pm:`pm`,midnight:`midnight`,noon:`noon`,morning:`morning`,afternoon:`afternoon`,evening:`evening`,night:`night`},Ve={G:function(e,t,n){let r=+(e.getFullYear()>0);switch(t){case`G`:case`GG`:case`GGG`:return n.era(r,{width:`abbreviated`});case`GGGGG`:return n.era(r,{width:`narrow`});default:return n.era(r,{width:`wide`})}},y:function(e,t,n){if(t===`yo`){let t=e.getFullYear(),r=t>0?t:1-t;return n.ordinalNumber(r,{unit:`year`})}return J.y(e,t)},Y:function(e,t,n,r){let i=Le(e,r),a=i>0?i:1-i;return t===`YY`?q(a%100,2):t===`Yo`?n.ordinalNumber(a,{unit:`year`}):q(a,t.length)},R:function(e,t){return q(Pe(e),t.length)},u:function(e,t){return q(e.getFullYear(),t.length)},Q:function(e,t,n){let r=Math.ceil((e.getMonth()+1)/3);switch(t){case`Q`:return String(r);case`QQ`:return q(r,2);case`Qo`:return n.ordinalNumber(r,{unit:`quarter`});case`QQQ`:return n.quarter(r,{width:`abbreviated`,context:`formatting`});case`QQQQQ`:return n.quarter(r,{width:`narrow`,context:`formatting`});default:return n.quarter(r,{width:`wide`,context:`formatting`})}},q:function(e,t,n){let r=Math.ceil((e.getMonth()+1)/3);switch(t){case`q`:return String(r);case`qq`:return q(r,2);case`qo`:return n.ordinalNumber(r,{unit:`quarter`});case`qqq`:return n.quarter(r,{width:`abbreviated`,context:`standalone`});case`qqqqq`:return n.quarter(r,{width:`narrow`,context:`standalone`});default:return n.quarter(r,{width:`wide`,context:`standalone`})}},M:function(e,t,n){let r=e.getMonth();switch(t){case`M`:case`MM`:return J.M(e,t);case`Mo`:return n.ordinalNumber(r+1,{unit:`month`});case`MMM`:return n.month(r,{width:`abbreviated`,context:`formatting`});case`MMMMM`:return n.month(r,{width:`narrow`,context:`formatting`});default:return n.month(r,{width:`wide`,context:`formatting`})}},L:function(e,t,n){let r=e.getMonth();switch(t){case`L`:return String(r+1);case`LL`:return q(r+1,2);case`Lo`:return n.ordinalNumber(r+1,{unit:`month`});case`LLL`:return n.month(r,{width:`abbreviated`,context:`standalone`});case`LLLLL`:return n.month(r,{width:`narrow`,context:`standalone`});default:return n.month(r,{width:`wide`,context:`standalone`})}},w:function(e,t,n,r){let i=ze(e,r);return t===`wo`?n.ordinalNumber(i,{unit:`week`}):q(i,t.length)},I:function(e,t,n){let r=Ie(e);return t===`Io`?n.ordinalNumber(r,{unit:`week`}):q(r,t.length)},d:function(e,t,n){return t===`do`?n.ordinalNumber(e.getDate(),{unit:`date`}):J.d(e,t)},D:function(e,t,n){let r=je(e);return t===`Do`?n.ordinalNumber(r,{unit:`dayOfYear`}):q(r,t.length)},E:function(e,t,n){let r=e.getDay();switch(t){case`E`:case`EE`:case`EEE`:return n.day(r,{width:`abbreviated`,context:`formatting`});case`EEEEE`:return n.day(r,{width:`narrow`,context:`formatting`});case`EEEEEE`:return n.day(r,{width:`short`,context:`formatting`});default:return n.day(r,{width:`wide`,context:`formatting`})}},e:function(e,t,n,r){let i=e.getDay(),a=(i-r.weekStartsOn+8)%7||7;switch(t){case`e`:return String(a);case`ee`:return q(a,2);case`eo`:return n.ordinalNumber(a,{unit:`day`});case`eee`:return n.day(i,{width:`abbreviated`,context:`formatting`});case`eeeee`:return n.day(i,{width:`narrow`,context:`formatting`});case`eeeeee`:return n.day(i,{width:`short`,context:`formatting`});default:return n.day(i,{width:`wide`,context:`formatting`})}},c:function(e,t,n,r){let i=e.getDay(),a=(i-r.weekStartsOn+8)%7||7;switch(t){case`c`:return String(a);case`cc`:return q(a,t.length);case`co`:return n.ordinalNumber(a,{unit:`day`});case`ccc`:return n.day(i,{width:`abbreviated`,context:`standalone`});case`ccccc`:return n.day(i,{width:`narrow`,context:`standalone`});case`cccccc`:return n.day(i,{width:`short`,context:`standalone`});default:return n.day(i,{width:`wide`,context:`standalone`})}},i:function(e,t,n){let r=e.getDay(),i=r===0?7:r;switch(t){case`i`:return String(i);case`ii`:return q(i,t.length);case`io`:return n.ordinalNumber(i,{unit:`day`});case`iii`:return n.day(r,{width:`abbreviated`,context:`formatting`});case`iiiii`:return n.day(r,{width:`narrow`,context:`formatting`});case`iiiiii`:return n.day(r,{width:`short`,context:`formatting`});default:return n.day(r,{width:`wide`,context:`formatting`})}},a:function(e,t,n){let r=e.getHours()/12>=1?`pm`:`am`;switch(t){case`a`:case`aa`:return n.dayPeriod(r,{width:`abbreviated`,context:`formatting`});case`aaa`:return n.dayPeriod(r,{width:`abbreviated`,context:`formatting`}).toLowerCase();case`aaaaa`:return n.dayPeriod(r,{width:`narrow`,context:`formatting`});default:return n.dayPeriod(r,{width:`wide`,context:`formatting`})}},b:function(e,t,n){let r=e.getHours(),i;switch(i=r===12?Be.noon:r===0?Be.midnight:r/12>=1?`pm`:`am`,t){case`b`:case`bb`:return n.dayPeriod(i,{width:`abbreviated`,context:`formatting`});case`bbb`:return n.dayPeriod(i,{width:`abbreviated`,context:`formatting`}).toLowerCase();case`bbbbb`:return n.dayPeriod(i,{width:`narrow`,context:`formatting`});default:return n.dayPeriod(i,{width:`wide`,context:`formatting`})}},B:function(e,t,n){let r=e.getHours(),i;switch(i=r>=17?Be.evening:r>=12?Be.afternoon:r>=4?Be.morning:Be.night,t){case`B`:case`BB`:case`BBB`:return n.dayPeriod(i,{width:`abbreviated`,context:`formatting`});case`BBBBB`:return n.dayPeriod(i,{width:`narrow`,context:`formatting`});default:return n.dayPeriod(i,{width:`wide`,context:`formatting`})}},h:function(e,t,n){if(t===`ho`){let t=e.getHours()%12;return t===0&&(t=12),n.ordinalNumber(t,{unit:`hour`})}return J.h(e,t)},H:function(e,t,n){return t===`Ho`?n.ordinalNumber(e.getHours(),{unit:`hour`}):J.H(e,t)},K:function(e,t,n){let r=e.getHours()%12;return t===`Ko`?n.ordinalNumber(r,{unit:`hour`}):q(r,t.length)},k:function(e,t,n){let r=e.getHours();return r===0&&(r=24),t===`ko`?n.ordinalNumber(r,{unit:`hour`}):q(r,t.length)},m:function(e,t,n){return t===`mo`?n.ordinalNumber(e.getMinutes(),{unit:`minute`}):J.m(e,t)},s:function(e,t,n){return t===`so`?n.ordinalNumber(e.getSeconds(),{unit:`second`}):J.s(e,t)},S:function(e,t){return J.S(e,t)},X:function(e,t,n){let r=e.getTimezoneOffset();if(r===0)return`Z`;switch(t){case`X`:return Ue(r);case`XXXX`:case`XX`:return We(r);default:return We(r,`:`)}},x:function(e,t,n){let r=e.getTimezoneOffset();switch(t){case`x`:return Ue(r);case`xxxx`:case`xx`:return We(r);default:return We(r,`:`)}},O:function(e,t,n){let r=e.getTimezoneOffset();switch(t){case`O`:case`OO`:case`OOO`:return`GMT`+He(r,`:`);default:return`GMT`+We(r,`:`)}},z:function(e,t,n){let r=e.getTimezoneOffset();switch(t){case`z`:case`zz`:case`zzz`:return`GMT`+He(r,`:`);default:return`GMT`+We(r,`:`)}},t:function(e,t,n){return q(Math.trunc(e/1e3),t.length)},T:function(e,t,n){return q(+e,t.length)}};function He(e,t=``){let n=e>0?`-`:`+`,r=Math.abs(e),i=Math.trunc(r/60),a=r%60;return a===0?n+String(i):n+String(i)+t+q(a,2)}function Ue(e,t){return e%60==0?(e>0?`-`:`+`)+q(Math.abs(e)/60,2):We(e,t)}function We(e,t=``){let n=e>0?`-`:`+`,r=Math.abs(e),i=q(Math.trunc(r/60),2),a=q(r%60,2);return n+i+t+a}var Ge=(e,t)=>{switch(e){case`P`:return t.date({width:`short`});case`PP`:return t.date({width:`medium`});case`PPP`:return t.date({width:`long`});default:return t.date({width:`full`})}},Ke=(e,t)=>{switch(e){case`p`:return t.time({width:`short`});case`pp`:return t.time({width:`medium`});case`ppp`:return t.time({width:`long`});default:return t.time({width:`full`})}},qe={p:Ke,P:(e,t)=>{let n=e.match(/(P+)(p+)?/)||[],r=n[1],i=n[2];if(!i)return Ge(e,t);let a;switch(r){case`P`:a=t.dateTime({width:`short`});break;case`PP`:a=t.dateTime({width:`medium`});break;case`PPP`:a=t.dateTime({width:`long`});break;default:a=t.dateTime({width:`full`});break}return a.replace(`{{date}}`,Ge(r,t)).replace(`{{time}}`,Ke(i,t))}},Je=/^D+$/,Ye=/^Y+$/,Xe=[`D`,`DD`,`YY`,`YYYY`];function Ze(e){return Je.test(e)}function Qe(e){return Ye.test(e)}function $e(e,t,n){let r=et(e,t,n);if(console.warn(r),Xe.includes(e))throw RangeError(r)}function et(e,t,n){let r=e[0]===`Y`?`years`:`days of the month`;return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${r} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}function tt(e){return e instanceof Date||typeof e==`object`&&Object.prototype.toString.call(e)===`[object Date]`}function nt(e){return!(!tt(e)&&typeof e!=`number`||isNaN(+K(e)))}var rt=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,it=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,at=/^'([^]*?)'?$/,ot=/''/g,st=/[a-zA-Z]/;function ct(e,t,n){let r=be(),i=n?.locale??r.locale??ve,a=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,o=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,s=K(e,n?.in);if(!nt(s))throw RangeError(`Invalid time value`);let c=t.match(it).map(e=>{let t=e[0];if(t===`p`||t===`P`){let n=qe[t];return n(e,i.formatLong)}return e}).join(``).match(rt).map(e=>{if(e===`''`)return{isToken:!1,value:`'`};let t=e[0];if(t===`'`)return{isToken:!1,value:lt(e)};if(Ve[t])return{isToken:!0,value:e};if(t.match(st))throw RangeError("Format string contains an unescaped latin alphabet character `"+t+"`");return{isToken:!1,value:e}});i.localize.preprocessor&&(c=i.localize.preprocessor(s,c));let l={firstWeekContainsDate:a,weekStartsOn:o,locale:i};return c.map(r=>{if(!r.isToken)return r.value;let a=r.value;(!n?.useAdditionalWeekYearTokens&&Qe(a)||!n?.useAdditionalDayOfYearTokens&&Ze(a))&&$e(a,t,String(e));let o=Ve[a[0]];return o(s,a,i.localize,l)}).join(``)}function lt(e){let t=e.match(at);return t?t[1].replace(ot,`'`):e}function ut(e,t){let n=K(e,t?.in);return n.setHours(23,59,59,999),n}function dt(){return Object.assign({},be())}function ft(e,t,n){let r=dt(),i=ht(e,n.timeZone,n.locale??r.locale);return`formatToParts`in i?pt(i,t):mt(i,t)}function pt(e,t){let n=e.formatToParts(t);for(let e=n.length-1;e>=0;--e)if(n[e].type===`timeZoneName`)return n[e].value}function mt(e,t){let n=e.format(t).replace(/\u200E/g,``),r=/ [\w-+ ]+$/.exec(n);return r?r[0].substr(1):``}function ht(e,t,n){return new Intl.DateTimeFormat(n?[n.code,`en-US`]:void 0,{timeZone:t,timeZoneName:e})}function gt(e,t){let n=Ct(t);return`formatToParts`in n?vt(n,e):yt(n,e)}var _t={year:0,month:1,day:2,hour:3,minute:4,second:5};function vt(e,t){try{let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let t=_t[n[e].type];t!==void 0&&(r[t]=parseInt(n[e].value,10))}return r}catch(e){if(e instanceof RangeError)return[NaN];throw e}}function yt(e,t){let n=e.format(t),r=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);return[parseInt(r[3],10),parseInt(r[1],10),parseInt(r[2],10),parseInt(r[4],10),parseInt(r[5],10),parseInt(r[6],10)]}var bt={},xt=new Intl.DateTimeFormat(`en-US`,{hourCycle:`h23`,timeZone:`America/New_York`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}).format(new Date(`2014-06-25T04:00:00.123Z`)),St=xt===`06/25/2014, 00:00:00`||xt===`06/25/2014 00:00:00`;function Ct(e){return bt[e]||(bt[e]=St?new Intl.DateTimeFormat(`en-US`,{hourCycle:`h23`,timeZone:e,year:`numeric`,month:`numeric`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`numeric`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`})),bt[e]}function wt(e,t,n,r,i,a,o){let s=new Date(0);return s.setUTCFullYear(e,t,n),s.setUTCHours(r,i,a,o),s}var Tt=36e5,Et=6e4,Dt={timezone:/([Z+-].*)$/,timezoneZ:/^(Z)$/,timezoneHH:/^([+-]\d{2})$/,timezoneHHMM:/^([+-])(\d{2}):?(\d{2})$/};function Ot(e,t,n){if(!e)return 0;let r=Dt.timezoneZ.exec(e);if(r)return 0;let i,a;if(r=Dt.timezoneHH.exec(e),r)return i=parseInt(r[1],10),Mt(i)?-(i*Tt):NaN;if(r=Dt.timezoneHHMM.exec(e),r){i=parseInt(r[2],10);let e=parseInt(r[3],10);return Mt(i,e)?(a=Math.abs(i)*Tt+e*Et,r[1]===`+`?-a:a):NaN}if(Pt(e)){t=new Date(t||Date.now());let r=At(n?t:kt(t),e);return-(n?r:jt(t,r,e))}return NaN}function kt(e){return wt(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function At(e,t){let n=gt(e,t),r=wt(n[0],n[1]-1,n[2],n[3]%24,n[4],n[5],0).getTime(),i=e.getTime(),a=i%1e3;return i-=a>=0?a:1e3+a,r-i}function jt(e,t,n){let r=e.getTime()-t,i=At(new Date(r),n);if(t===i)return t;r-=i-t;let a=At(new Date(r),n);return i===a?i:Math.max(i,a)}function Mt(e,t){return-23<=e&&e<=23&&(t==null||0<=t&&t<=59)}var Nt={};function Pt(e){if(Nt[e])return!0;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),Nt[e]=!0,!0}catch{return!1}}var Ft=60*1e3,It={X:function(e,t,n){let r=Lt(n.timeZone,e);if(r===0)return`Z`;switch(t){case`X`:return Bt(r);case`XXXX`:case`XX`:return zt(r);default:return zt(r,`:`)}},x:function(e,t,n){let r=Lt(n.timeZone,e);switch(t){case`x`:return Bt(r);case`xxxx`:case`xx`:return zt(r);default:return zt(r,`:`)}},O:function(e,t,n){let r=Lt(n.timeZone,e);switch(t){case`O`:case`OO`:case`OOO`:return`GMT`+Vt(r,`:`);default:return`GMT`+zt(r,`:`)}},z:function(e,t,n){switch(t){case`z`:case`zz`:case`zzz`:return ft(`short`,e,n);default:return ft(`long`,e,n)}}};function Lt(e,t){let n=e?Ot(e,t,!0)/Ft:t?.getTimezoneOffset()??0;if(Number.isNaN(n))throw RangeError(`Invalid time zone specified: `+e);return n}function Rt(e,t){let n=e<0?`-`:``,r=Math.abs(e).toString();for(;r.length<t;)r=`0`+r;return n+r}function zt(e,t=``){let n=e>0?`-`:`+`,r=Math.abs(e),i=Rt(Math.floor(r/60),2),a=Rt(Math.floor(r%60),2);return n+i+t+a}function Bt(e,t){return e%60==0?(e>0?`-`:`+`)+Rt(Math.abs(e)/60,2):zt(e,t)}function Vt(e,t=``){let n=e>0?`-`:`+`,r=Math.abs(e),i=Math.floor(r/60),a=r%60;return a===0?n+String(i):n+String(i)+t+Rt(a,2)}function Ht(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),e-+t}var Ut=/(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/,Wt=36e5,Gt=6e4,Kt=2,Y={dateTimePattern:/^([0-9W+-]+)(T| )(.*)/,datePattern:/^([0-9W+-]+)(.*)/,plainTime:/:/,YY:/^(\d{2})$/,YYY:[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],YYYY:/^(\d{4})/,YYYYY:[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})/],MM:/^-(\d{2})$/,DDD:/^-?(\d{3})$/,MMDD:/^-?(\d{2})-?(\d{2})$/,Www:/^-?W(\d{2})$/,WwwD:/^-?W(\d{2})-?(\d{1})$/,HH:/^(\d{2}([.,]\d*)?)$/,HHMM:/^(\d{2}):?(\d{2}([.,]\d*)?)$/,HHMMSS:/^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,timeZone:Ut};function qt(e,t={}){if(arguments.length<1)throw TypeError(`1 argument required, but only `+arguments.length+` present`);if(e===null)return new Date(NaN);let n=t.additionalDigits==null?Kt:Number(t.additionalDigits);if(n!==2&&n!==1&&n!==0)throw RangeError(`additionalDigits must be 0, 1 or 2`);if(e instanceof Date||typeof e==`object`&&Object.prototype.toString.call(e)===`[object Date]`)return new Date(e.getTime());if(typeof e==`number`||Object.prototype.toString.call(e)===`[object Number]`)return new Date(e);if(Object.prototype.toString.call(e)!==`[object String]`)return new Date(NaN);let r=Jt(e),{year:i,restDateString:a}=Yt(r.date,n),o=Xt(a,i);if(o===null||isNaN(o.getTime()))return new Date(NaN);if(o){let e=o.getTime(),n=0,i;if(r.time&&(n=Zt(r.time),n===null||isNaN(n)))return new Date(NaN);if(r.timeZone||t.timeZone){if(i=Ot(r.timeZone||t.timeZone,new Date(e+n)),isNaN(i))return new Date(NaN)}else i=Ht(new Date(e+n)),i=Ht(new Date(e+n+i));return new Date(e+n+i)}else return new Date(NaN)}function Jt(e){let t={},n=Y.dateTimePattern.exec(e),r;if(n?(t.date=n[1],r=n[3]):(n=Y.datePattern.exec(e),n?(t.date=n[1],r=n[2]):(t.date=null,r=e)),r){let e=Y.timeZone.exec(r);e?(t.time=r.replace(e[1],``),t.timeZone=e[1].trim()):t.time=r}return t}function Yt(e,t){if(e){let n=Y.YYY[t],r=Y.YYYYY[t],i=Y.YYYY.exec(e)||r.exec(e);if(i){let t=i[1];return{year:parseInt(t,10),restDateString:e.slice(t.length)}}if(i=Y.YY.exec(e)||n.exec(e),i){let t=i[1];return{year:parseInt(t,10)*100,restDateString:e.slice(t.length)}}}return{year:null}}function Xt(e,t){if(t===null)return null;let n,r,i;if(!e||!e.length)return n=new Date(0),n.setUTCFullYear(t),n;let a=Y.MM.exec(e);if(a)return n=new Date(0),r=parseInt(a[1],10)-1,nn(t,r)?(n.setUTCFullYear(t,r),n):new Date(NaN);if(a=Y.DDD.exec(e),a){n=new Date(0);let e=parseInt(a[1],10);return rn(t,e)?(n.setUTCFullYear(t,0,e),n):new Date(NaN)}if(a=Y.MMDD.exec(e),a){n=new Date(0),r=parseInt(a[1],10)-1;let e=parseInt(a[2],10);return nn(t,r,e)?(n.setUTCFullYear(t,r,e),n):new Date(NaN)}if(a=Y.Www.exec(e),a)return i=parseInt(a[1],10)-1,an(i)?Qt(t,i):new Date(NaN);if(a=Y.WwwD.exec(e),a){i=parseInt(a[1],10)-1;let e=parseInt(a[2],10)-1;return an(i,e)?Qt(t,i,e):new Date(NaN)}return null}function Zt(e){let t,n,r=Y.HH.exec(e);if(r)return t=parseFloat(r[1].replace(`,`,`.`)),on(t)?t%24*Wt:NaN;if(r=Y.HHMM.exec(e),r)return t=parseInt(r[1],10),n=parseFloat(r[2].replace(`,`,`.`)),on(t,n)?t%24*Wt+n*Gt:NaN;if(r=Y.HHMMSS.exec(e),r){t=parseInt(r[1],10),n=parseInt(r[2],10);let e=parseFloat(r[3].replace(`,`,`.`));return on(t,n,e)?t%24*Wt+n*Gt+e*1e3:NaN}return null}function Qt(e,t,n){t||=0,n||=0;let r=new Date(0);r.setUTCFullYear(e,0,4);let i=r.getUTCDay()||7,a=t*7+n+1-i;return r.setUTCDate(r.getUTCDate()+a),r}var $t=[31,28,31,30,31,30,31,31,30,31,30,31],en=[31,29,31,30,31,30,31,31,30,31,30,31];function tn(e){return e%400==0||e%4==0&&e%100!=0}function nn(e,t,n){if(t<0||t>11)return!1;if(n!=null){if(n<1)return!1;let r=tn(e);if(r&&n>en[t]||!r&&n>$t[t])return!1}return!0}function rn(e,t){if(t<1)return!1;let n=tn(e);return!(n&&t>366||!n&&t>365)}function an(e,t){return!(e<0||e>52||t!=null&&(t<0||t>6))}function on(e,t,n){return!(e<0||e>=25||t!=null&&(t<0||t>=60)||n!=null&&(n<0||n>=60))}var sn=/([xXOz]+)|''|'(''|[^'])+('|$)/g;function cn(e,t,n={}){t=String(t);let r=t.match(sn);if(r){let i=qt(n.originalDate||e,n);t=r.reduce(function(e,t){if(t[0]===`'`)return e;let r=e.indexOf(t),a=e[r-1]===`'`,o=e.replace(t,`'`+It[t[0]](i,t,n)+`'`);return a?o.substring(0,r-1)+o.substring(r+1):o},t)}return ct(e,t,n)}function ln(e,t,n){e=qt(e,n);let r=Ot(t,e,!0),i=new Date(e.getTime()-r),a=new Date(0);return a.setFullYear(i.getUTCFullYear(),i.getUTCMonth(),i.getUTCDate()),a.setHours(i.getUTCHours(),i.getUTCMinutes(),i.getUTCSeconds(),i.getUTCMilliseconds()),a}function un(e,t,n,r){return r={...r,timeZone:t,originalDate:e},cn(ln(e,t,{timeZone:r.timeZone}),n,r)}var X=t(),dn=a(),fn=(0,H.createContext)(null),pn=({children:e})=>{let t=(0,H.useRef)({}),n=(0,H.useCallback)(()=>{Object.keys(t.current).forEach(e=>{t.current[e]?.forEach(e=>{e()}),t.current[e]=[]})},[]);return(0,H.useEffect)(()=>()=>{n()},[n]),(0,X.jsx)(fn.Provider,{value:{terminators:t,cleanupWorkers:n},children:e})},mn=()=>{let e=(0,H.useContext)(fn);if(!e)throw Error(`useTerminators must be used within a TerminatorsWrapper`);return e},hn=(0,H.createContext)(null),gn=({children:e})=>{let[t,n]=(0,H.useState)({}),r=(0,H.useCallback)((e,t)=>{n(n=>({...n,[e]:{...n[e],...t}}))},[]);return(0,X.jsx)(hn.Provider,{value:{sessionData:t,setSessionData:r},children:e})},_n=()=>{let e=(0,H.useContext)(hn);if(!e)throw Error(`useSessionData must be used within a SessionDataWrapper`);return e},vn=(0,H.createContext)(null),yn=({children:e,bootstrapPlugins:t=[],userConfigs:n=[],user:r,teamMember:i,business:a,clientObject:o,appPath:s})=>{let[c,l]=(0,H.useState)(!1),[u,d]=(0,H.useState)({}),f=(0,H.useMemo)(()=>Object.values(u).some(e=>e.waitingOnRouteScript),[u]),p=(0,H.useMemo)(()=>t.reduce((e,t)=>({...e,[t.api_name]:t.id}),{}),[t]),m=(0,H.useMemo)(()=>n.reduce((e,t)=>({...e,[t.api_name]:t.config}),{}),[n]),h=(0,H.useCallback)(()=>{l(!0)},[]);return(0,X.jsx)(vn.Provider,{value:{installedPluginAPINamesToIds:p,userConfigsByApiName:m,user:r,teamMember:i,business:a,clientObject:o,appPath:s,onInitialBootstrap:h,setRouteScriptRunState:d},children:e({waitingOnRouteScript:f,hasFinishedBootstrapping:c})})},bn=()=>{let e=(0,H.useContext)(vn);if(!e)throw Error(`useAppState must be used within an AppStateWrapper`);return e},xn=(0,H.createContext)(null),Sn=({children:e})=>{let[t,n]=(0,H.useState)({}),r=(0,H.useCallback)(e=>t=>{n(n=>({...n,[e]:t(n[e]??{indicator:`none`,hidden:!1,pending:!1})}))},[]),i=(0,H.useCallback)(e=>!e||!t[e]?{indicator:`none`,hidden:!1,pending:!1}:{...t[e]},[t]),a=(0,H.useMemo)(()=>{let e=Object.keys(t);return e.length>0&&e.some(e=>t[e]?.indicator===`block`)},[t]);return(0,X.jsx)(xn.Provider,{value:{getRunnerStateUpdater:r,getRunnerState:i},children:e(a)})},Cn=()=>{let e=(0,H.useContext)(xn);if(!e)throw Error(`useRunnerState must be used within a RunnerStateWrapper`);return e},wn=(0,H.createContext)(null),Tn=({children:e,showing:t,showPrompt:n,show:r,onConfirm:i,onHide:a})=>{let[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)([]),[u,d]=(0,H.useState)([]),f=(0,H.useRef)(void 0),p=(0,H.useRef)(void 0),m=(0,H.useCallback)((e,t)=>{s(n=>[...n,{config:e,cb:t}])},[]),h=(0,H.useCallback)((e,t)=>{l(n=>[...n,{objectId:e,cb:t}])},[]),g=(0,H.useCallback)((e,t,n)=>{d(r=>[...r,{objectId:e,relatedEntityId:t,cb:n}])},[]),_=(0,H.useCallback)(e=>{c[0]?.cb(e),l(e=>e.slice(1))},[c]),v=(0,H.useCallback)(e=>{u[0]?.cb(e),d(e=>e.slice(1))},[u]);(0,H.useEffect)(()=>{o.length>0&&!t&&(f.current=o[0]?.config,p.current=o[0]?.cb,n())},[o,t,n]);let y=(0,H.useCallback)(()=>{f.current=void 0,p.current=void 0,s(e=>e.slice(1))},[]),b=(0,H.useMemo)(()=>({props:{show:r,onConfirm:e=>{i(),p.current&&p.current({canceled:!1,values:e}),y()},onHide:(e,...t)=>{a(...t),p.current&&p.current({canceled:!0,values:{},eventSource:e}),y()}},config:f.current??{}}),[i,a,r,y]);return(0,X.jsx)(wn.Provider,{value:{modalState:b,showModal:m,showCreateRecordModal:h,showCreateRelatedRecordModal:g,onCreateRecordComplete:_,onCreateRelatedRecordComplete:v},children:e({showPluginModal:b.props.show,pluginApiName:b.config.pluginApiName??``,handleShowModal:m,handleShowCreateRecordModal:h,handleShowCreateRelatedRecordModal:g,derivedModalState:b,handleCreateRecordComplete:_,handleCreateRelatedRecordComplete:v,showCreateRecordModal:c.length>0,createRecordModalObjectId:c[0]?.objectId??``,showCreateRelatedRecordModal:u.length>0,createRelatedRecordModalObjectId:u[0]?.objectId??``,createRelatedRecordModalRelatedEntityId:u[0]?.relatedEntityId??``})})},En=()=>{let e=(0,H.useContext)(wn);if(!e)throw Error(`useModals must be used within a ModalsWrapper`);return e},Dn=(0,H.createContext)(null),On=({children:e,monitoringExceptionHelper:t})=>{let n=(0,H.useCallback)((e,n)=>{t(e,{extra:n})},[t]);return(0,X.jsx)(Dn.Provider,{value:{sendException:n},children:e})},kn=()=>{let e=(0,H.useContext)(Dn);if(!e)throw Error(`useMonitoring must be used within an MonitoringWrapper`);return e},An=(0,H.createContext)(null),jn=({children:e,onNavigate:t})=>{let n=(0,H.useCallback)(e=>{t(e,{replace:!1})},[t]),r=(0,H.useCallback)(e=>{t(e,{replace:!0})},[t]);return(0,X.jsx)(An.Provider,{value:{push:n,replace:r},children:e})},Mn=()=>{let e=(0,H.useContext)(An);if(!e)throw Error(`useHistory must be used within an HistoryWrapper`);return e},Nn=(0,H.createContext)(null),Pn=({children:e,performRequest:t,createFileId:n,performFileUpload:r,getPendingCacheCount:i,invalidateCache:a})=>(0,X.jsx)(Nn.Provider,{value:{performRequest:t,createFileId:n,performFileUpload:r,getPendingCacheCount:i,invalidateCache:a},children:e}),Fn=()=>{let e=(0,H.useContext)(Nn);if(!e)throw Error(`useNetwork must be used within a NetworkWrapper`);return e},In=e=>e,Ln=(0,H.createContext)({t:In}),Rn=e=>{let{children:t,t:n=In}=e;return(0,X.jsx)(Ln.Provider,{value:{t:n},children:t})},Z=()=>(0,H.useContext)(Ln),zn=(e,t)=>{if(!Array.isArray(e))throw Error(`Return value must be an array`);t.required.forEach(t=>{e.forEach((e,n)=>{if(!(t.key in e))throw Error(`Missing required field: ${t.key} in result row ${String(n)}`);let r=typeof e[t.key];if(r!==t.type)throw Error(`Invalid type for field: ${t.key} in result row ${String(n)}. Expected ${t.type}, got ${r}`)})}),t.optional.forEach(t=>{e.forEach((e,n)=>{if(t.key in e){let r=typeof e[t.key];if(r!==t.type)throw Error(`Invalid type for field: ${t.key} in result row ${String(n)}. Expected ${t.type}, got ${r}`)}})})},Bn=({onError:e,showToast:t,clearToasts:n})=>{let{t:r}=Z(),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(void 0),{terminators:c}=mn(),{sessionData:l,setSessionData:u}=_n(),{installedPluginAPINamesToIds:d,userConfigsByApiName:f,user:p,teamMember:m,business:h,clientObject:g,appPath:_}=bn(),{getRunnerState:v,getRunnerStateUpdater:y}=Cn(),{showModal:b,showCreateRecordModal:x}=En(),{sendException:S}=kn(),C=Mn(),{performRequest:w,createFileId:T,performFileUpload:E,getPendingCacheCount:D,invalidateCache:O}=Fn(),k=(0,H.useCallback)(t=>n=>{e?.(n);let r=n?.message??`Unknown plugin error`;S(Error(r),{error:n,workerName:`calendarSource`,pluginApiName:t?.plugin_api_name??``})},[e,S]);return[(0,H.useCallback)(async(i,o,v,S)=>{let A=``,j=B(o);s(j);try{let e=d[o.plugin_api_name];A=JSON.stringify({...v,pluginId:e,__kizen_user_config:f[o.plugin_api_name]})}catch{k(o)({message:r(`Arguments passed to the script are invalid`)})}let M=!1,N=await I({user:p,teamMember:m,business:h,onError:k(o),setLoadingState:a,scriptBody:i,clientObject:g,onStateChange:e=>{y(j)(t=>({...t,...e}))},workerName:`calendarSource`,args:A,pushHistory:C.push,onShowToast:t,onClearToasts:n,terminators:c,plugin:o,sessionData:l,setSessionData:u,onShowModal:b,onShowCreateRecordModal:x,onShowCreateRelatedRecordModal:()=>{},onNetworkError:e=>{e?.status===503&&(M=!0)},appPath:_,onNetworkRequest:w,createFileId:T,performFileUpload:E,getPendingCacheCount:D,invalidateCache:O});try{S&&zn(N,S)}catch(t){e?.(t)}return{result:N,authError:M}},[p,m,d,h,g,C,t,n,c,l,u,b,x,k,y,f,e,w,T,_,E,D,O,r]),{...v(o),pending:i}]},Vn=(0,H.createContext)(null),Hn=({children:e,showToast:t,clearToasts:n})=>(0,X.jsx)(Vn.Provider,{value:{showToast:t,clearToasts:n},children:e}),Un=()=>{let e=(0,H.useContext)(Vn);if(!e)throw Error(`useToast must be used within a ToastWrapper`);return e},Wn=async(e,t,n,r)=>{let{result:i,authError:a}=await n(e,t,r,{required:[{key:`id`,type:`string`},{key:`name`,type:`string`}],optional:[{key:`description`,type:`string`}]});return Array.isArray(i)?{result:i,authError:a}:(console.warn(`Expected calendar source script to return an array, but got:`,i),{result:[],authError:a})},Gn=async(e,t,n,r)=>{let{result:i,authError:a}=await n(e,t,r,{required:[{key:`id`,type:`string`},{key:`calendar_id`,type:`string`},{key:`title`,type:`string`},{key:`start_time`,type:`number`},{key:`end_time`,type:`number`}],optional:[{key:`description`,type:`string`},{key:`url`,type:`string`},{key:`activity_id`,type:`string`},{key:`all_day`,type:`boolean`},{key:`busy`,type:`boolean`}]});return Array.isArray(i)?{result:i,authError:a}:(console.warn(`Expected calendar event script to return an array, but got:`,i),{result:[],authError:a})},Kn=(e,t,n={})=>{let{showToast:r,clearToasts:i}=Un(),{t:a}=Z(),[o]=Bn({onError:e=>{r({message:`${a(`Error fetching calendar options.`)} ${e?.message??``}`,variant:`failure`})},showToast:r,clearToasts:i}),s=U({queries:t.map(t=>({queryKey:ne.CALENDAR_SOURCE_CALENDAR_LIST(t.plugin_api_name,t.api_name),queryFn:async()=>{let e=n[t.plugin_api_name]?.business_config??{},{result:r,authError:i}=await Wn(t.calendars_script,t,o,e);return{source:t,calendars:r,authError:i}},enabled:e&&!!t.calendars_script}))}),c=s.some(e=>e.isLoading);return{calendars:(0,H.useMemo)(()=>c||!e?{}:s.reduce((e,t)=>{if(!t.data?.source.plugin_api_name||typeof t.data.source.plugin_api_name!=`string`)return e;let n=t.data.source.plugin_api_name;return e[n]??=[],e[n].push(...t.data.calendars.map(e=>({calendar:e,source:t.data.source}))),e},{}),[s,c,e]),errorServices:(0,H.useMemo)(()=>s.filter(e=>e.data?.authError).map(e=>e.data?.source.plugin_api_name),[s]),isLoading:c}},qn=`yyyy-MM-dd'T'HH:mm:ssXXX`,Jn=e=>{if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw Error(`Invalid date string: ${e}. Expected format: YYYY-MM-DD`);let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)},Yn=(e,t)=>un(e,t,qn),Xn=(e,t,n={})=>{let r=Intl.DateTimeFormat().resolvedOptions().timeZone,i=Yn(Oe(Jn(t.rangeStart)),r),a=Yn(ut(Jn(t.rangeEnd)),r),{showToast:o,clearToasts:s}=Un(),{t:c}=Z(),[l]=Bn({onError:e=>{o({message:`${c(`Error fetching calendar events.`)} ${e?.message??``}`,variant:`failure`})},showToast:o,clearToasts:s}),u=U({queries:e.map(({calendar:e,source:r})=>({queryKey:ne.CALENDAR_SOURCE_EVENTS(r.plugin_api_name,r.api_name,e.id,t),queryFn:async()=>{let t=n[r.plugin_api_name]?.business_config??{},{result:o,authError:s}=await Gn(r.events_script,r,l,{...t,calendar:{calendar_id:e.id,range_start:i,range_end:a}});return{calendarId:e.id,events:o,authError:s}}}))}),d=u.some(e=>e.isLoading),f=(0,H.useMemo)(()=>e.reduce((e,{calendar:t,source:n})=>(e[t.id]={source:n,calendar:t},e),{}),[e]);return{events:(0,H.useMemo)(()=>d?{}:u.reduce((e,t)=>(t.data?.calendarId&&(e[t.data.calendarId]=t.data.events),e),{}),[u,d]),sources:f,isLoading:d}},Zn=({onError:e,scriptUIRef:t,plugin:n,onChangeMinimized:r})=>{let{terminators:i}=mn(),{sessionData:a,setSessionData:o}=_n(),{installedPluginAPINamesToIds:s,userConfigsByApiName:c,user:l,teamMember:u,business:d,clientObject:f,appPath:p}=bn(),{showModal:m,showCreateRecordModal:h,showCreateRelatedRecordModal:g}=En(),{sendException:_}=kn(),{showToast:v,clearToasts:y}=Un(),b=Mn(),{performRequest:x,createFileId:S,performFileUpload:C,getPendingCacheCount:w,invalidateCache:T}=Fn(),{t:E}=Z(),[D,O]=(0,H.useState)(!1),[k,A]=(0,H.useState)({indicator:`none`,hidden:!0,triggerHidden:!1,hideHeader:!1}),j=(0,H.useRef)(!1),[M,N]=(0,H.useState)(!1);D&&!j.current&&(j.current=!0),!D&&j.current&&!M&&N(!0);let P=(0,H.useCallback)(t=>{e?.(t);let r=t?.message??`Unknown plugin error`;_(Error(r),{error:t,workerName:`floatingFrame`,pluginApiName:n.plugin_api_name})},[e,n,_]);return[(0,H.useCallback)((e,_)=>{let D=``;try{let e=s[n.plugin_api_name];D=JSON.stringify({..._,pluginId:e,__kizen_user_config:c[n.plugin_api_name]})}catch{P({message:E(`Arguments passed to the script are invalid`)})}return I({user:l,teamMember:u,business:d,onError:P,setLoadingState:(...e)=>{(0,dn.flushSync)(()=>{O(...e)})},scriptBody:e,clientObject:f,scriptUIRef:t,onStateChange:e=>{let{minimized:t,...n}=e;typeof t==`boolean`&&r?.(t),A(e=>({...e,...n}))},workerName:`floatingFramePlugin`,args:D,pushHistory:b.push,plugin:n,onShowToast:v,onClearToasts:y,terminators:i,sessionData:a,setSessionData:o,onShowModal:m,onShowCreateRecordModal:h,onShowCreateRelatedRecordModal:g,appPath:p,onNetworkRequest:x,createFileId:S,performFileUpload:C,getPendingCacheCount:w,invalidateCache:T})},[l,u,d,s,f,t,b,n,r,v,y,i,a,o,P,A,c,m,h,g,x,p,S,C,w,T,E]),{...k,pending:M?!1:D}]},Qn=({onError:e,scriptUIRef:t,plugin:n})=>{let{terminators:r}=mn(),{sessionData:i,setSessionData:a}=_n(),{installedPluginAPINamesToIds:o,userConfigsByApiName:s,user:c,teamMember:l,business:u,clientObject:d,appPath:f}=bn(),{getRunnerState:p,getRunnerStateUpdater:m}=Cn(),{showModal:h,showCreateRecordModal:g}=En(),{sendException:_}=kn(),{showToast:v,clearToasts:y}=Un(),b=Mn(),{performRequest:x,createFileId:S,performFileUpload:C,getPendingCacheCount:w,invalidateCache:T}=Fn(),{t:E}=Z(),[D,O]=(0,H.useState)(!1),[k,A]=(0,H.useState)(void 0),j=(0,H.useCallback)((t,r)=>{e?.(t);let i=t?.message??`Unknown plugin error`;_(Error(i),{error:t,workerName:`genericPlugin`,pluginApiName:n?.plugin_api_name??r?.plugin_api_name??``})},[e,n,_]);return[(0,H.useCallback)((e,p,_)=>{let D=``,k=B(_);A(k);try{let e=o[n?.plugin_api_name??_?.plugin_api_name??``];D=JSON.stringify({...p,pluginId:e,__kizen_user_config:s[n?.plugin_api_name??_?.plugin_api_name??``]})}catch{j({message:E(`Arguments passed to the script are invalid`)})}return I({user:c,teamMember:l,business:u,onError:j,setLoadingState:O,scriptBody:e,clientObject:d,scriptUIRef:t,onStateChange:e=>{m(k)(t=>({...t,...e}))},workerName:`genericPlugin`,args:D,pushHistory:b.push,onShowToast:v,onClearToasts:y,terminators:r,plugin:n,executionPlugin:_,sessionData:i,setSessionData:a,onShowModal:h,onShowCreateRecordModal:g,onShowCreateRelatedRecordModal:()=>{},appPath:f,onNetworkRequest:x,createFileId:S,performFileUpload:C,getPendingCacheCount:w,invalidateCache:T})},[c,l,o,u,d,t,b,v,y,r,n,i,a,j,m,s,h,g,x,f,S,C,w,T,E]),{...p(k),pending:D}]},$n=({entityId:e,objectId:t,onError:n,scriptUIRef:r,onReleaseBlockingScript:i})=>{let{terminators:a}=mn(),{sessionData:o,setSessionData:s}=_n(),{installedPluginAPINamesToIds:c,userConfigsByApiName:l,user:u,teamMember:d,business:f,clientObject:p,appPath:m}=bn(),{getRunnerState:h,getRunnerStateUpdater:g}=Cn(),{showModal:_,showCreateRecordModal:v,showCreateRelatedRecordModal:y}=En(),{sendException:b}=kn(),{showToast:x,clearToasts:S}=Un(),C=Mn(),{performRequest:w,createFileId:T,performFileUpload:E,getPendingCacheCount:D,invalidateCache:O}=Fn(),{t:k}=Z(),[A,j]=(0,H.useState)(!1),[M,N]=(0,H.useState)(void 0),P=(0,H.useCallback)((r,i)=>{n?.(r);let a=r?.message??`Unknown plugin error`;b(Error(a),{error:r,workerName:`recordDetail`,pluginApiName:i?.plugin_api_name??``,objectId:t,entityId:e})},[n,t,e,b]);return[(0,H.useCallback)((n,h,b,A)=>{let M=``;try{let e=c[b?.plugin_api_name??``];M=JSON.stringify({...h,pluginId:e,__kizen_user_config:l[b?.plugin_api_name??``]})}catch{P({message:k(`Arguments passed to the script are invalid`)},b)}let F=B(b);return N(F),I({user:u,teamMember:d,business:f,onReleaseBlockingScript:i,onError:e=>{P(e,b)},setLoadingState:j,scriptBody:n,clientObject:p,scriptUIRef:r,onStateChange:e=>{g(F)(t=>({...t,...e}))},workerName:`recordDetail`,args:M,context:A??{entityId:e,objectId:t},pushHistory:C.push,onShowToast:x,onClearToasts:S,terminators:a,executionPlugin:b,sessionData:o,setSessionData:s,onShowModal:_,onShowCreateRecordModal:v,onShowCreateRelatedRecordModal:y,appPath:m,onNetworkRequest:w,createFileId:T,performFileUpload:E,getPendingCacheCount:D,invalidateCache:O})},[u,d,c,f,e,t,p,r,C,x,S,a,o,s,_,v,y,i,P,g,l,w,m,T,E,D,O,k]),{...h(M),pending:A}]},er=(e,t)=>{let{showToast:n}=Un(),{t:r}=Z(),i=(0,H.useRef)(null),a=(0,H.useRef)(null),o=e?.css,s=(0,H.useMemo)(()=>{let t=e?.html;return t?A.sanitize(t):null},[e]),c=(0,H.useMemo)(()=>e?.event_scripts??{},[e]),[l,{pending:u}]=Qn({onError:e=>{n({message:`${r(`Script could not be executed:`)} ${e?.message??`Unknown Error`}`,variant:`failure`})},scriptUIRef:i,plugin:e}),d=(0,H.useCallback)(e=>{if(e.preventDefault(),e.stopPropagation(),!u){let n=e.target.getAttribute(`data-script`);n&&c[n]&&l(c[n],t)}},[u,l,c,t]);return(0,H.useEffect)(()=>{let e=a.current;return e&&e.addEventListener(`click`,d),()=>{e&&e.removeEventListener(`click`,d)}},[d,e]),{scopedCss:`
|
|
2
|
+
@scope {
|
|
3
|
+
${o??``}
|
|
4
|
+
}
|
|
5
|
+
`,sanitizedHtml:s,outputUIRef:i,interactableScriptRef:a}},tr=(e,t,n,r,i={})=>{let a=(0,H.useMemo)(()=>t?.event_scripts??{},[t]),o=(0,H.useCallback)(t=>{if(t.preventDefault(),t.stopPropagation(),!r){let n=t.target.getAttribute(`data-script`);n&&a[n]&&e(a[n],{...i})}},[r,e,a,i]);(0,H.useEffect)(()=>{let e=n?.current;return e&&e.addEventListener(`click`,o),()=>{e&&e.removeEventListener(`click`,o)}},[o,t,n])},nr=(e,t,n)=>{let r=e?.iframe_url,i=e?.script,a=e?.callback,o=e?.args,{showToast:s}=Un(),{t:c}=Z(),l=(0,H.useRef)(null),[u,{pending:d}]=Qn({onError:e=>{s({message:`${c(`Plugin error:`)} ${e?.message??``}`,variant:`failure`})},scriptUIRef:l,plugin:e}),f=(0,H.useMemo)(()=>{let e=new URLSearchParams(t);return{...Object.fromEntries(e),...o}},[t,o]),{outputUIRef:p,scopedCss:m,sanitizedHtml:h,interactableScriptRef:g}=er(e,f);tr(u,e,l,d);let _=(0,H.useRef)(!1);(0,H.useEffect)(()=>{!r&&!_.current&&i&&!n&&(_.current=!0,u(i,f))},[r,u,i,f,n]);let v=(0,H.useCallback)(e=>{let t=e.data;if(t?.type===`kizen:plugin_callback`){let e=t.query;a&&u(a,e)}},[u,a]);return(0,H.useEffect)(()=>(window.addEventListener(`message`,v),()=>{window.removeEventListener(`message`,v)}),[v]),{scriptUIRef:l,outputUIRef:p,scopedCss:m,sanitizedHtml:h,interactableScriptRef:g,iframeURL:r,pending:d}},rr=(0,H.createContext)(null),ir=({children:e})=>{let[t,n]=(0,H.useState)([]),[r,i]=(0,H.useState)(!1),a=(0,H.useCallback)((e,t)=>{n(n=>{let r=[e,...n.filter(t=>t!==e)];return t?.(r),r})},[]),o=(0,H.useMemo)(()=>[...t].reverse().reduce((e,t,n)=>({...e,[t]:n}),{}),[t]);return(0,H.useEffect)(()=>{let e=new MutationObserver(()=>{document.querySelector(`div[role="dialog"]`)?i(!0):i(!1)});return e.observe(document.body,{childList:!0}),()=>{e.disconnect()}},[]),(0,X.jsx)(rr.Provider,{value:{touchFloatingFrame:a,floatingFrameOffset:o},children:e(r)})},ar=()=>{let e=(0,H.useContext)(rr);if(!e)throw Error(`useFloatingFrame must be used within a FloatingFrameWrapper`);return e},or=[`^/$`,`^/login*`,`/settings/mine$`,`/settings/others$`,`/create-new-business$`,`^/choose-business*`,`^/inactive-business$`,`^/reset$`,`/welcome$`,`/embed/*`,`/create-new-business$`,`/businessbuilder`],sr=[`https://js.stripe.com`],cr=(e,t,n,r)=>e<n?t<r?`top-left`:`top-right`:t<r?`bottom-left`:`bottom-right`,lr=e=>{let{currentWindow:t,pathname:n,id:r,frameHeaderSize:i,defaultPositionGap:a=0,viewportHeight:o=window.innerHeight,hiddenByModal:s,updateEmployeeConfig:c}=e,l=(0,H.useRef)(null),u=(0,H.useRef)(!1),{showToast:d}=Un(),{t:f}=Z(),{installedPluginAPINamesToIds:p,clientObject:m}=bn(),{touchFloatingFrame:h,floatingFrameOffset:g}=ar(),_=g[r]??-1,v=t.minimized_style===`none`,y=t.minimized_style===`circle`||v,b=t.default_position===`bottom-right-fixed`,x=t.default_position===`bottom-left-fixed`,S=b||x,C=t.minimized_config?.icon??`action-drag-handle`,w=t.minimized_config?.color??`blue`,T=(0,H.useMemo)(()=>{let e=n.split(`/`),t=e[1],r=e[2];if(t===`client`)return{objectId:m?.id,entityId:r};if(t===`custom-objects`)return{objectId:r,entityId:e[3]}},[m,n]),E=(0,H.useMemo)(()=>{let e=t.match,r=t.ignore;return!!(e?.length&&!e.some(e=>new RegExp(e).test(n))||or.concat(r??[]).filter(Boolean).some(e=>{try{return new RegExp(e).test(n)}catch{return!1}}))},[t,n]),D=t.plugin_api_name?p[t.plugin_api_name]:``,[O,k]=(0,H.useState)(()=>t.employee_config?.[r]?.minimized??!1),A=t.script,j=t.type,M=t.args,N=t.message_handler,P=t.width??0,[F,I]=(0,H.useState)(()=>{let e=window.innerHeight;return Math.min(t.height??0,e-i)}),[L,R]=(0,H.useState)(null),ee=t.default_position,z=(0,H.useCallback)(e=>{let n=t.employee_config?.[r]?.position;if(!n?.quadrant){let t=window.innerWidth-P,r=window.innerHeight-F-i;if(O&&!e&&(r=window.innerHeight-i),n)try{let e=n;return e.left>t&&(e.left=t),e.top>r&&(e.top=r),e.left<0&&(e.left=a),e.top<0&&(e.top=a),e}catch{}let o=t;return ee===`bottom-left`&&(o=a),{left:o,top:r-a}}else if(n.quadrant===`top-left`){let e=n.deltas?.left??0,t=n.deltas?.top??0;return{...n,left:e,top:t}}else if(n.quadrant===`top-right`){let e=window.innerWidth-P-(n.deltas?.right??0),t=n.deltas?.top??0;return{...n,left:e,top:t}}else if(n.quadrant===`bottom-left`){let e=n.deltas?.left??0,t=window.innerHeight-(O?0:F)-(n.deltas?.bottom??0)-i;return{...n,left:e,top:t}}else{let e=window.innerWidth-P-(n.deltas?.right??0),t=window.innerHeight-(O?0:F)-(n.deltas?.bottom??0)-i;return{...n,left:e,top:t}}},[t,r,ee,O,P,F,i,a]),te=(0,H.useCallback)(e=>{let t=z(e),n=[`bottom-right`,`bottom-left`].includes(t.quadrant??``)&&O?0:F;return t.left<0?t.left=0:t.left>window.innerWidth-P&&(t.left=window.innerWidth-P),t.top<0?t.top=0:t.top>window.innerHeight-n&&(t.top=window.innerHeight-n),t},[z,P,F,O]);(0,H.useEffect)(()=>{let e=t.height??0;if(e>o){I(o-i);let e=z(!0);e.top=0,R(e)}else I(e)},[t.height,z,o,i]);let[B,ne]=(0,H.useState)(O),[re,ie]=(0,H.useState)(O&&y),ae=F*5e-4*1e3,V=e=>{k(e),e&&y?setTimeout(()=>{ie(e)},ae):y&&ie(e),s?setTimeout(()=>{ne(e)},ae):ne(e),(L?.quadrant===`bottom-left`||L?.quadrant===`bottom-right`)&&R(e?e=>e?{...e,top:e.top+F}:null:e=>{if(!e)return null;let t=window.innerHeight,n=e.top>=0&&e.top+F<=t;return{...e,top:n?e.top:e.top-F}}),c?.(r,O,L)({minimized:e})},[U,{pending:se,hidden:ce,indicator:le,triggerHidden:ue,hideHeader:de}]=Zn({onError:e=>{d({message:`${f(`Plugin error:`)} ${e?.message??``}`,variant:`failure`})},scriptUIRef:l,plugin:t,onChangeMinimized:e=>{V(e)}}),fe=(0,H.useMemo)(()=>de&&S,[de,S]),pe=(0,H.useMemo)(()=>{if(!L)return`top`;let{left:e,top:t}=L;return window.innerWidth-(e+P)<40?`left`:t<40?`bottom`:`top`},[L,P]),me=(0,H.useCallback)(()=>{let e=x?`left`:`right`,n=`${t.plugin_api_name}-${t.api_name}-trigger-${e}`;return document.getElementById(n)},[x,t]),W=(0,H.useCallback)(()=>{if(!S)return;let e=me();if(!e)return;let t=e.getBoundingClientRect(),n=O?0:F,r=fe?0:i,o=t.top-(n+r)-a,s=x?t.left:t.right-P,c=n+r,l=Math.max(0,window.innerWidth-P),u=Math.max(0,window.innerHeight-c);s=Math.min(Math.max(0,s),l),o=Math.min(Math.max(0,o),u),R({left:s,top:o,quadrant:x?`bottom-left`:`bottom-right`,deltas:{top:o,left:s,right:window.innerWidth-(s+P),bottom:window.innerHeight-(o+c)}})},[S,x,F,O,P,fe,me,i,a]);(0,H.useEffect)(()=>{S&&W()},[S,F,O,W]),(0,H.useEffect)(()=>{if(!S)return;W();let e=new ResizeObserver(()=>{W()});return e.observe(document.body),()=>{e.disconnect()}},[S,W]),(0,H.useEffect)(()=>{!u.current&&A&&j===`script`&&!E&&(u.current=!0,U(A,{...M}))},[U,A,j,M,E]),(0,H.useEffect)(()=>{let e=e=>{let n=e;if(n?.detail?.recipient?.frame===t.api_name){let e=n.detail;if(e.recipient?.plugin!==t.plugin_api_name)return;e.recipient.script&&t.event_scripts?.[e.recipient.script]&&U(t.event_scripts[e.recipient.script]??``,{...e.args,...M,...T})}};return window.addEventListener(oe,e),()=>{window.removeEventListener(oe,e)}},[t,U,M,T]);let[he,ge]=(0,H.useState)(!1),_e=(e,t)=>{ge(!1),h(r);let n=window.innerWidth,i=window.innerHeight;if(t.node){let e=t.node.getBoundingClientRect(),a=e.left,o=e.top,s=o+e.height,l=a+e.width,u=o,d=i-s,f=a,p=n-l,m={left:a,right:l,top:o,quadrant:cr(u,f,d,p),deltas:{top:u,bottom:d,left:f,right:p}};R(m),c?.(r,O,L)({position:m})}};(0,H.useEffect)(()=>{let e=()=>{S?W():R(te(!1))};return window.addEventListener(`resize`,e),()=>{window.removeEventListener(`resize`,e)}},[S,W,te]),tr(U,t,l,se,M),(0,H.useEffect)(()=>{let e=e=>{e.source!==window&&N&&!sr.includes(e.origin)&&U(N,{...M,eventData:e.data})};return window.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e)}},[U,M,N]);let{outputUIRef:ve,scopedCss:ye,sanitizedHtml:be,interactableScriptRef:xe}=er(t,{}),Se=B?ce||E||s:ce||E,Ce=`floating-window-parent--${r}`,we=`floating-drag-handle--${r}`,Te=`floating-window-content--${r}`,G=t.employee_config?.[r]?.position?.quadrant?.split(`-`)[1]===`right`?`right`:`left`;x?G=`left`:b&&(G=`right`);let K=t.minimized_config?.customIcon,Ee=null;return K?.startsWith(`data:image/`)&&(Ee=({className:e=``})=>(0,X.jsx)(`img`,{src:K,alt:t.title||`Open Frame`,className:`object-cover select-none pointer-events-none ${e}`})),L||R(te(!1)),{circleProps:{id:r,side:G,circleIcon:C,CustomIcon:Ee,circleColor:w,onClick:()=>{V(!O)},hidden:!!(Se||E||v||ue)},parentProps:{className:Ce,dragging:he,hidden:Se||re||E||v},draggableProps:{onStop:_e,onStart:()=>{ge(!0)},bounds:`.${Ce}`,handle:`.${we}`,defaultPosition:{x:L?.left??0,y:L?.top??0},position:{x:L?.left??0,y:L?.top??0},disabled:S},floatProps:{pending:se,width:P,dragging:he,height:F,isCircle:y&&O},contentProps:{className:Te,dragging:he,solid:!0},minimized:O,pending:se,indicator:le,hideHeader:fe,isFixed:S,isCircle:y,outputUIRef:ve,scopedCss:ye,sanitizedHtml:be,interactableScriptRef:xe,tooltipPosition:pe,currentPluginId:D,setMinimized:V,dragHandleClassName:we,height:F,script:A,dragging:he,frameOffset:_,scriptUIRef:l}},ur=()=>{(0,H.useEffect)(()=>{let e=null,t=t=>{if(!t.detail?.location)return;let n=te(t.detail.location);n!==e&&(e=n,document.querySelectorAll(`iframe[id^=${j}-]`).forEach(e=>{let n=null;try{n=new URL(e.src,window.location.href).origin}catch(e){N(`script-runner-logging`)&&console.warn(`Failed to parse iframe src for location change message target origin:`,e),n=null}n&&e.contentWindow?.postMessage({action:k,location:t.detail?.location},n)}))};return window.addEventListener(O,t),()=>{window.removeEventListener(O,t)}},[])},dr=[],fr=[],pr=new E,mr=({children:e})=>(0,H.useContext)(x)?(0,X.jsx)(X.Fragment,{children:e}):(0,X.jsx)(f,{client:pr,children:e}),hr=e=>{let{children:t,bootstrapPlugins:n,userConfigs:r,user:i,teamMember:a,business:o,clientObject:s,onNavigate:c,modal:l,monitoringExceptionHelper:u,showToast:d,clearToasts:f,performRequest:p,appPath:m,hideFramesOnModal:h=!0,createFileId:g,performFileUpload:_,t:v,invalidateCache:y,getPendingCacheCount:b}=e;return ur(),(0,X.jsx)(mr,{children:(0,X.jsx)(yn,{bootstrapPlugins:n??dr,userConfigs:r??fr,user:i,teamMember:a,business:o,clientObject:s,appPath:m,children:({hasFinishedBootstrapping:e,waitingOnRouteScript:n})=>(0,X.jsx)(Rn,{t:v,children:(0,X.jsx)(Sn,{children:r=>(0,X.jsx)(jn,{onNavigate:c,children:(0,X.jsx)(Tn,{...l,children:i=>(0,X.jsx)(On,{monitoringExceptionHelper:u,children:(0,X.jsx)(gn,{children:(0,X.jsx)(pn,{children:(0,X.jsx)(Hn,{showToast:d,clearToasts:f,children:(0,X.jsx)(ir,{children:a=>(0,X.jsx)(Pn,{performRequest:p,createFileId:g,performFileUpload:_,invalidateCache:y,getPendingCacheCount:b,children:t({...i,showLoadingIndicator:r,hasFinishedBootstrapping:e,waitingOnRouteScript:n,hiddenByModal:h?a:!1})})})})})})})})})})})})})},gr=(0,H.createContext)(null),_r=gr.Provider,vr=(e,t)=>{if(e===`custom_object`)return t?.id},yr=(e,t)=>{if(e.type===`custom_object`)return e.allow_multiple?(t?.value??[]).length>0:!!t?.value?.id;if(e.type===`field`)return e.allow_multiple?(t?.value??[]).length>0:!!t?.value?.value;if(e.type===`text`)return!!(t?.value??``).trim();if(e.type===`number`){let e=Number(t?.value);return!!t?.value&&!isNaN(e)}else if(e.type===`select`)return e.allow_multiple?(t?.value??[]).length>0:!!t?.value?.value;else if(e.type===`boolean`)return!!t?.value;return!1},br=e=>{let t=(e.fields??[]).filter(e=>e.type===`custom_object`),n=(e.fields??[]).filter(e=>e.type===`container`).flatMap(e=>br(e)),r=e.actions?.filter(e=>e.hint_object_name)??[];return[...t,...n,...r.map(e=>({...R(e),match_hint:e.hint_object_name??``}))]},xr=e=>{let t=(e.fields??[]).filter(e=>e.type===`field`),n=(e.fields??[]).filter(e=>e.type===`container`).flatMap(e=>xr(e));return[...t,...n]},Sr=({children:e,config:t,value:n,onStateChange:r,disabledKeys:i,templateAssociationsByActionApiName:a,getObjectByAPIName:o,getCustomObjectDetails:s})=>{let[c,l]=(0,H.useState)(n??{}),u=(0,H.useMemo)(()=>M(t),[t]),d=(0,H.useMemo)(()=>u.reduce((e,t)=>({...e,[t.key]:{type:t.type,value:t.default}}),{}),[u]),f=(0,H.useMemo)(()=>{let e={...Object.entries(a??{}).reduce((e,[t,n])=>{let r=`action__${t}`,i=n.map(e=>({id:e.custom_object.id??``,objectName:e.custom_object.object_name??`Unknown Object`}));return i.length>0&&n.length>0&&n[0]&&(e[r]={type:`custom_object`,value:i,config:R(n[0].browser_js_action_template)}),e},{}),...c};return i?.forEach(t=>{e[t]&&(e[t]=void 0)}),e},[c,a,i]),p=(0,H.useRef)(!!n),m=(0,H.useRef)({}),[h,g]=(0,H.useState)(!n),[_,v]=(0,H.useState)({}),[y,b]=(0,H.useState)({}),[x,S]=(0,H.useState)(!1),C=(0,H.useRef)(null),[w,T]=(0,H.useState)({}),[E,D]=(0,H.useState)(!1),[O,k]=(0,H.useState)(!0),A=(0,H.useRef)({}),j=(0,H.useCallback)((e,t)=>{A.current[e]=t},[]),N=(0,H.useCallback)(e=>{typeof e==`function`?l(t=>{let n=e(t);return m.current=n,r?.(n),n}):(m.current=e,l(e),r?.(e)),T({})},[r]),F=(0,H.useCallback)((e,t)=>{if(e.startsWith(`{{`)&&e.endsWith(`}}`)){let n=e.slice(2,-2).trim();return vr(t[n]?.type,t[n]?.value)}return e},[]),I=(0,H.useCallback)(e=>F(e,f),[f,F]),{clientObject:L}=bn(),ee=(0,H.useCallback)(async e=>e===`client_client`&&L?[{id:L.id,object_name:L.objectName}]:await o(e),[L,o]),z=(0,H.useCallback)(async()=>{let e=br(t);for(let t of e){if(!t.match_hint)continue;let e=await ee(t.match_hint);if(e?.[0]){let n={id:e[0].id,objectName:e[0].object_name};N(e=>({...e,[t.key]:{type:`custom_object`,value:t.allow_multiple?[n]:n}}))}}},[t,N,ee]),te=(0,H.useCallback)(()=>xr(t),[t]),B=(0,H.useCallback)(async(e,t)=>{let n=te(),r={};for(let i of n){if(!i.object_id)continue;let n=t??F(i.object_id,m.current);if(e&&!i.object_id.includes(e))continue;if(!r[n]&&n)try{r[n]=await s(n)}catch{}let a=r[n];if(a){let e=a.fields.find(e=>e.name===i.match_hint);e&&N(t=>({...t,[i.key]:{type:`field`,value:{value:e.id,label:e.displayName},associatedObject:{id:n,name:a.objectName}}}))}}},[F,te,N,s]),ne=(0,H.useCallback)(async e=>{let n=br(t).find(t=>t.key===e);if(n?.match_hint){let t=``,r=(await ee(n.match_hint))?.[0];r&&(t=r.id,N(t=>({...t,[e]:{type:`custom_object`,value:{id:r.id,objectName:r.object_name}}})),t&&B(void 0,t))}},[t,N,B,ee]),re=(0,H.useCallback)(async()=>{await z(),await B(),g(!1)},[z,B]),ie=(0,H.useCallback)(()=>xr(t),[t]),ae=(0,H.useCallback)(e=>B(e),[B]),V=(0,H.useCallback)(()=>{C.current&&=(clearTimeout(C.current),null),C.current=setTimeout(()=>{S(!0)},500)},[]),U=(0,H.useCallback)(async(e,t)=>{V(),v(e=>({...e,[t]:!0})),D(!0);let n=await P(e,{...d,...f});return b(e=>(e[t]===!1&&typeof n==`boolean`&&n&&(f[t]||ne(t)),{...e,[t]:n})),v(e=>({...e,[t]:!1})),n},[f,V,ne,d]);p.current||(p.current=!0,re());let oe=(0,H.useCallback)(e=>y[e]===!1,[y]),se=(0,H.useCallback)(e=>_[e]===!0,[_]),ce=(0,H.useCallback)(e=>{if(w[e])return{message:w[e],showMessage:!0,error:!0}},[w]),le=(0,H.useMemo)(()=>{let e=(t.fields??[]).filter(e=>e.type===`container`).map(e=>e.when),n=u.map(e=>e.when);return[...e,...n].filter(Boolean)},[t,u]),ue=(0,H.useMemo)(()=>u.reduce((e,t)=>(e[t.key]=t,e),{}),[u]),de=(0,H.useCallback)((e,t,n)=>{t.add(e);let r=ue[e];r?.dependencies?.length&&r.dependencies.forEach(e=>{n.has(e)||(n.add(e),de(e,t,n))})},[ue]),fe=(0,H.useMemo)(()=>u.map(e=>{let t=new Set,n=e.dependencies??[],r=new Set;return n.forEach(e=>{de(e,t,r)}),{...e,dependencies:Array.from(t)}}),[u,de]),pe=(0,H.useCallback)(e=>{fe.filter(t=>t.dependencies.length===0?!1:t.dependencies.includes(e)&&t.key!==e).forEach(e=>{A.current[e.key]?.()})},[fe]),me=(0,H.useCallback)(async()=>{let e=(await Promise.all(u.map(async e=>e.when?await P(e.when,{...d,...f})?e:null:e))).filter(Boolean),t=0;for(let n of e)n&&n.required&&!yr(n,f[n.key])?(T(e=>({...e,[n.key]:`This field is required`})),t++):n?.validation_pattern?new RegExp(n.validation_pattern).test(f[n.key]?.value??n.default??``)||(T(e=>({...e,[n.key]:`Value must match the pattern ${n.validation_pattern??``}`})),t++):n&&T(e=>({...e,[n.key]:void 0}));return{isValid:t===0,includedKeys:e.map(e=>e?.key).filter(e=>!!e)}},[f,u,d]);(0,H.useEffect)(()=>{V()},[V]);let W=Object.values(_).filter(Boolean).length;return!E&&le.length===0&&D(!0),E&&O&&W===0&&k(!1),(0,X.jsx)(_r,{value:{state:f,setState:N,interpolateValue:I,getNestedFields:ie,reInferFieldsForObject:ae,inferencePending:h,evaluateExpression:U,shouldHideField:oe,shouldDisableField:se,expressionsIdle:x,getFieldErrorState:ce,validateForm:me,waitingExpressionCount:W,initialExpressionsPending:O,flattenedFields:u,flattenedFieldsByKey:ue,afterFieldChange:pe,registerFieldResetter:j,disabledKeys:i??[]},children:e})},Cr=()=>{let e=(0,H.useContext)(gr);if(!e)throw Error(`useSetupAssistant must be used within a SetupAssistantController`);return e};function Q(e,t=!1){let n=Cr(),{evaluateExpression:r,shouldHideField:i,getFieldErrorState:a,disabledKeys:o}=n;(0,H.useEffect)(()=>{e.when&&r(e.when,e.key)},[e.when,e.key,r]);let s=i(e.key),c=o.includes(e.key)||t,l=a(e.key);return{...n,shouldHide:s,isDisabled:c,errorState:l}}var wr=({field:e,disabled:t=!1})=>{let{state:n,setState:r,afterFieldChange:i,registerFieldResetter:a,isDisabled:o,shouldHide:s,errorState:c}=Q(e,t),l=n[e.key]?.value??e.default??!1,u=l===!0||l===`true`,d=(0,H.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`boolean`,value:t}})),i(e.key)},[e.key,r,i]);return(0,H.useEffect)(()=>{a(e.key,()=>{d(void 0)})},[e.key,a,d]),s?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:u,onChange:e=>{d(e.target.checked)},disabled:o,className:`h-3.5 w-3.5 cursor-pointer accent-blue-600`}),(0,X.jsxs)(`span`,{className:`text-[13px] ${o?`text-neutral-400`:`text-neutral-700`}`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-red-500 ml-0.5`,children:`*`})]}),e.tooltip&&(0,X.jsx)(`span`,{className:`text-[11px] text-neutral-400`,title:e.tooltip,children:`?`})]}),c?.showMessage&&c.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:c.message})]})},Tr=({field:e,pluginApiName:t,disabled:n=!1})=>{let{shouldHide:r}=Q(e,n),i=e.columns??1;return r?null:(0,X.jsxs)(`div`,{children:[e.label&&(0,X.jsx)(`h3`,{className:`text-[14px] font-semibold text-neutral-800 mb-3 mt-4`,children:e.label}),(0,X.jsx)(`div`,{className:`gap-4`,style:{display:`grid`,gridTemplateColumns:`repeat(${String(i)}, 1fr)`},children:e.fields?.map(e=>(0,X.jsx)(Or,{field:e,pluginApiName:t,disabled:n},e.key))})]})},$=({field:e})=>e.label?(0,X.jsxs)(`label`,{className:`text-[12px] font-medium text-neutral-600`,children:[e.label,e.required&&(0,X.jsx)(`span`,{className:`text-red-500 ml-0.5`,children:`*`}),e.tooltip&&(0,X.jsx)(`span`,{className:`ml-1 text-neutral-400 cursor-help`,title:e.tooltip,children:`?`})]}):null,Er=({label:e,value:t,onChange:n,onSelect:a,options:o,loading:s,placeholder:c,disabled:l,keepOpenOnSelect:u})=>{let[d,f]=(0,H.useState)(!1),p=(0,H.useRef)(null);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e&&(0,X.jsx)(`label`,{className:`text-[11px] font-semibold uppercase tracking-widest text-neutral-500`,children:e}),(0,X.jsxs)(`div`,{ref:p,className:`relative`,children:[(0,X.jsx)(r,{icon:i,className:`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-[10px] text-neutral-400`}),(0,X.jsx)(`input`,{type:`text`,className:`w-full rounded border border-black/10 bg-white py-1.5 pl-7 pr-2.5 font-mono text-[12px] text-neutral-800 focus:border-neutral-400 focus:outline-none disabled:opacity-50`,value:t,placeholder:c,disabled:l,onChange:e=>{n(e.target.value)},onFocus:()=>{f(!0)},onBlur:()=>{f(!1)}})]}),(0,X.jsxs)(D,{anchorRef:p,open:d,children:[s&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`Loading…`}),!s&&o.length===0&&t.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`Start typing to search…`}),!s&&o.length===0&&t.length>0&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`No results`}),!s&&o.map(e=>(0,X.jsx)(`div`,{className:`cursor-pointer px-3 py-2 text-[12px] text-neutral-800 hover:bg-neutral-100`,onClick:()=>{a(e.id,e.label),u||f(!1)},children:e.label},e.id))]})]})},Dr={container:Tr,custom_object:({field:e,disabled:t=!1})=>{let{state:n,setState:r,getNestedFields:i,reInferFieldsForObject:a,shouldDisableField:o,registerFieldResetter:s,afterFieldChange:c,isDisabled:l,shouldHide:u,errorState:d}=Q(e,t),f=o(e.key)||l,[p,m]=(0,H.useState)(``),[h,g]=(0,H.useState)([]),[_,v]=(0,H.useState)(!1),y=(0,H.useRef)(null),b=L(),x=T(),S=(0,H.useCallback)(async e=>{v(!0);try{let t=new URLSearchParams({page_size:`20`});e&&t.set(`search`,e);let n=await(await b(`/custom-objects?${t.toString()}`)).json(),r=(Array.isArray(n)?n:n.results??[]).map(e=>({id:e.id,label:e.object_name})),i=x?.business.client_object;i?.access&&(!e||i.object_name.toLowerCase().includes(e.toLowerCase()))&&r.unshift({id:i.id,label:i.object_name}),g(r)}catch{}finally{v(!1)}},[b,x]),C=e.allow_multiple?n[e.key]?.value??[]:[],w=(0,H.useCallback)((t,i)=>{let a=n[e.key]?.value??[];a.some(e=>e.id===t)||(r(n=>({...n,[e.key]:{type:`custom_object`,value:[...a,{id:t,objectName:i}]}})),c(e.key),m(``))},[n,e.key,r,c]),E=(0,H.useCallback)(t=>{let i=n[e.key]?.value??[];r(n=>({...n,[e.key]:{type:`custom_object`,value:i.filter(e=>e.id!==t)}})),c(e.key)},[n,e.key,r,c]),D=e.allow_multiple?void 0:n[e.key]?.value,O=(0,H.useRef)(!1);(0,H.useEffect)(()=>{!e.allow_multiple&&D?.objectName&&!O.current&&(m(D.objectName),O.current=!0)},[e.allow_multiple,D]);let k=(0,H.useCallback)(t=>{m(t),D&&(r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),c(e.key)),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{S(t)},300)},[D,e.key,r,c,S]),A=(0,H.useCallback)((t,n)=>{m(n),r(r=>({...r,[e.key]:{type:`custom_object`,value:{id:t,objectName:n}}}));let o=i().filter(t=>t.object_id?.includes(e.key));for(let e of o)r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key)));a(e.key),c(e.key)},[e.key,r,i,a,c]),j=(0,H.useCallback)(t=>{e.allow_multiple?(m(t),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{S(t)},300)):k(t)},[e.allow_multiple,k,S]),M=(0,H.useCallback)((t,n)=>{e.allow_multiple?w(t,n):A(t,n)},[e.allow_multiple,w,A]);if((0,H.useEffect)(()=>{s(e.key,()=>{r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),m(``),O.current=!1})},[e.key,s,r]),u)return null;if(e.allow_multiple){let t=h.filter(e=>!C.some(t=>t.id===e.id));return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),C.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1 mb-1`,children:C.map(e=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-neutral-100 px-2 py-0.5 text-[11px] text-neutral-700`,children:[e.objectName,(0,X.jsx)(`button`,{type:`button`,onClick:()=>{E(e.id)},disabled:f,className:`text-neutral-400 hover:text-neutral-600`,"aria-label":`Remove ${e.objectName}`,children:`×`})]},e.id))}),(0,X.jsx)(Er,{value:p,onChange:j,onSelect:M,options:t,loading:_,placeholder:e.placeholder??`Search for objects...`,disabled:f,keepOpenOnSelect:!0}),d?.showMessage&&d.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:d.message})]})}return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Er,{value:p,onChange:j,onSelect:M,options:h,loading:_,placeholder:e.placeholder??`Search for an object...`,disabled:f}),D&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>{r(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),m(``),O.current=!1,c(e.key)},disabled:f,className:`absolute right-2 top-1/2 -translate-y-1/2 text-[11px] text-neutral-400 hover:text-neutral-600`,"aria-label":`Clear selection`,children:`×`})]}),d?.showMessage&&d.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:d.message})]})},field:({field:e,disabled:t=!1})=>{let{interpolateValue:n,state:r,setState:i,registerFieldResetter:a,afterFieldChange:o,isDisabled:s,shouldHide:c,errorState:l}=Q(e,t),u=n(e.object_id??``),[d,f]=(0,H.useState)([]),[p,m]=(0,H.useState)(``),[h,g]=(0,H.useState)(!1),[_,v]=(0,H.useState)(null),y=L();(0,H.useEffect)(()=>{!u||u===_||c||(async()=>{g(!0);try{m((await(await y(`/custom-objects/${u}`)).json()).object_name??``);let e=await(await y(`/custom-objects/${u}/fields`)).json();f((Array.isArray(e)?e:e.results??[]).map(e=>({label:e.display_name,value:e.id}))),v(u)}catch{}finally{g(!1)}})()},[u,_,y,e.key,c]);let b=r[e.key]?.value,x=(0,H.useCallback)(t=>{i(n=>({...n,[e.key]:{type:`field`,value:t,associatedObject:{id:u,name:p}}})),o(e.key)},[e.key,i,u,p,o]);if((0,H.useEffect)(()=>{a(e.key,()=>{i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key)))})},[e.key,a,i]),c)return null;let S=!u||s;if(e.allow_multiple){let t=Array.isArray(b)?b:[];return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsx)(`div`,{className:`rounded border p-2 text-[13px] ${l?.error?`border-red-300`:`border-black/10`} ${S?`bg-neutral-50`:`bg-white`}`,children:h&&d.length===0?(0,X.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Loading fields...`}):u?d.length===0?(0,X.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`No fields available`}):(0,X.jsx)(`div`,{className:`flex flex-col gap-1 max-h-48 overflow-y-auto transition-opacity ${h?`opacity-60`:``}`,children:d.map(e=>{let n=t.some(t=>t.value===e.value);return(0,X.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n,disabled:S,onChange:()=>{x(n?t.filter(t=>t.value!==e.value):[...t,e])},className:`h-3 w-3 accent-blue-600`}),(0,X.jsx)(`span`,{className:`text-[12px]`,children:e.label})]},e.value)})}):(0,X.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Select an object first`})}),l?.showMessage&&l.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:l.message})]})}let C=b&&!Array.isArray(b)?b.value:``;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),h&&d.length===0?(0,X.jsx)(`div`,{className:`w-full rounded border border-black/10 px-2 py-1.5 text-[12px] text-neutral-400 bg-neutral-50`,children:`Loading fields...`}):(0,X.jsxs)(`select`,{value:C,onChange:e=>{let t=d.find(t=>t.value===e.target.value);t&&x(t)},disabled:S,className:`w-full rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 transition-opacity ${l?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${S?`bg-neutral-50 text-neutral-400`:`bg-white`} ${h?`opacity-60`:``}`,children:[(0,X.jsx)(`option`,{value:``,children:u?`Choose a field`:`Select an object first`}),d.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),l?.showMessage&&l.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:l.message})]})},text:({field:e,disabled:t=!1})=>{let{state:n,setState:r,afterFieldChange:i,registerFieldResetter:a,isDisabled:o,shouldHide:s,errorState:c}=Q(e,t),[l,u]=(0,H.useState)(n[e.key]?.value??e.default??``),d=(0,H.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`text`,value:t}})),i(e.key)},[e.key,r,i]);return(0,H.useEffect)(()=>{a(e.key,()=>{u(``),d(``)})},[e.key,a,d]),(0,H.useEffect)(()=>{let e=setTimeout(()=>{d(l)},300);return()=>{clearTimeout(e)}},[l,d]),s?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsx)(`input`,{type:`text`,value:l,onChange:e=>{u(e.target.value)},placeholder:e.placeholder??e.default??`Enter text`,disabled:o,className:`rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${c?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${o?`bg-neutral-50 text-neutral-400`:`bg-white`}`}),c?.showMessage&&c.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:c.message})]})},description:({field:e})=>{let{shouldHide:t}=Q(e);return t?null:(0,X.jsx)(`div`,{className:`text-[13px] text-neutral-500 leading-relaxed`,children:e.content})},number:({field:e,disabled:t=!1})=>{let{state:n,setState:r,afterFieldChange:i,registerFieldResetter:a,isDisabled:o,shouldHide:s,errorState:c}=Q(e,t),l=n[e.key]?.value??e.default??``,[u,d]=(0,H.useState)(String(l)),f=(0,H.useCallback)(t=>{r(n=>({...n,[e.key]:{type:`number`,value:t}})),i(e.key)},[e.key,r,i]);return(0,H.useEffect)(()=>{a(e.key,()=>{d(``),f(``)})},[e.key,a,f]),(0,H.useEffect)(()=>{let e=setTimeout(()=>{f(u)},300);return()=>{clearTimeout(e)}},[u,f]),s?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsx)(`input`,{type:`number`,value:u,onChange:e=>{d(e.target.value)},placeholder:e.placeholder??e.default??`Enter a number`,disabled:o,className:`rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${c?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${o?`bg-neutral-50 text-neutral-400`:`bg-white`}`}),c?.showMessage&&c.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:c.message})]})},select:({field:e,pluginApiName:t,disabled:n=!1})=>{let{state:r,setState:i,inferencePending:a,initialExpressionsPending:o,expressionsIdle:s,afterFieldChange:c,registerFieldResetter:l,isDisabled:u,shouldHide:d,errorState:f}=Q(e,n),p=!a&&!o&&s,[m,h]=(0,H.useState)([]),[g,_]=(0,H.useState)(!1),v=(0,H.useRef)(null),[y,b]=(0,H.useState)(``),[x,S]=(0,H.useState)(``),[C,w]=(0,H.useState)(!1),T=(0,H.useRef)(null),E=!!(e.getFetchUrl||e.optionMapper),O=r[e.key]?.value,k=L(),A=(0,H.useCallback)(t=>{i(n=>({...n,[e.key]:{type:`select`,value:t}})),c(e.key)},[c,e.key,i]);(0,H.useEffect)(()=>{l(e.key,()=>{i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),b(``),S(``)})},[e.key,l,i]),(0,H.useEffect)(()=>{if(!e.typeahead)return;let t=setTimeout(()=>{S(y)},300);return()=>{clearTimeout(t)}},[y,e.typeahead]);let j=(0,H.useMemo)(()=>e.typeahead?{...r,search:x}:r,[r,x,e.typeahead]),M=(0,H.useMemo)(()=>JSON.stringify(j),[j]),N=(0,H.useCallback)(async n=>{_(!0);try{let r={__kizen_state:{value:{...n,pluginApiName:t}}},i;if(e.getFetchUrl){let t=await F(e.getFetchUrl,r);if(t){let n=e.fetchMethod??`GET`,a={"Content-Type":`application/json`},o=null;if(e.getHeaders&&(a=await z(e.getHeaders,r)),n===`POST`&&e.getBody){let t=await z(e.getBody,r);o=JSON.stringify(t)}if(t.startsWith(`/`))i={data:await(await k(t,{method:n,headers:a,...o!=null&&{body:o}})).json()};else{let e=await fetch(t,{method:n,headers:a,...o!=null&&{body:o}});e.ok&&(i=await e.json())}}}if(e.optionMapper){let r=await ee(e.optionMapper,{__kizen_state:{value:{...n,result:i,pluginApiName:t}}});h(structuredClone(r))}else Array.isArray(i)&&h(i)}catch{}finally{_(!1)}},[e,t,k]);if((0,H.useEffect)(()=>{!E||!p||d||e.typeahead||v.current!==M&&(v.current=M,N(j))},[E,p,M,j,e.typeahead,d,N]),(0,H.useEffect)(()=>{!E||!p||d||!e.typeahead||C&&v.current!==M&&(v.current=M,N(j))},[E,p,M,j,e.typeahead,C,d,N]),(0,H.useEffect)(()=>{!E||!e.autoSelect||e.typeahead||u||d||O||m.length===1&&m[0]&&(e.allow_multiple?A([m[0]]):A(m[0]))},[E,e.autoSelect,e.typeahead,e.allow_multiple,u,d,O,m,A]),d)return null;let P=E?m:e.options??[];if(e.allow_multiple){let t=Array.isArray(O)?O:[];return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsx)(`div`,{className:`rounded border p-2 text-[13px] ${f?.error?`border-red-300`:`border-black/10`} ${u?`bg-neutral-50`:`bg-white`}`,children:g&&P.length===0?(0,X.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`Loading options...`}):P.length===0?(0,X.jsx)(`span`,{className:`text-neutral-400 text-[12px]`,children:`No options available`}):(0,X.jsx)(`div`,{className:`flex flex-col gap-1 max-h-48 overflow-y-auto transition-opacity ${g?`opacity-60`:``}`,children:P.map(e=>{let n=t.some(t=>t.value===e.value);return(0,X.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:n,disabled:u,onChange:()=>{A(n?t.filter(t=>t.value!==e.value):[...t,e])},className:`h-3 w-3 accent-blue-600`}),(0,X.jsx)(`span`,{className:`text-[12px]`,children:e.label})]},e.value)})})}),f?.showMessage&&f.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:f.message})]})}if(e.typeahead){let t=O&&!Array.isArray(O)?O.label:``;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),(0,X.jsxs)(`div`,{ref:T,className:`relative`,children:[(0,X.jsx)(`input`,{type:`text`,value:t&&!C?t:y,placeholder:e.placeholder??`Search...`,disabled:u,onChange:t=>{b(t.target.value),O&&(i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),c(e.key))},onFocus:()=>{w(!0),t&&b(t)},onBlur:()=>{w(!1)},className:`w-full rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 ${f?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${u?`bg-neutral-50 text-neutral-400`:`bg-white`}`}),t&&!C&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>{i(t=>Object.fromEntries(Object.entries(t).filter(([t])=>t!==e.key))),b(``),S(``),c(e.key)},disabled:u,className:`absolute right-2 top-1/2 -translate-y-1/2 text-[11px] text-neutral-400 hover:text-neutral-600`,"aria-label":`Clear selection`,children:`×`})]}),(0,X.jsxs)(D,{anchorRef:T,open:C,children:[g&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`Loading...`}),!g&&P.length===0&&y.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`Start typing to search...`}),!g&&P.length===0&&y.length>0&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-[12px] text-neutral-400`,children:`No results`}),!g&&P.map(e=>(0,X.jsx)(`div`,{className:`cursor-pointer px-3 py-2 text-[12px] text-neutral-800 hover:bg-neutral-100`,onClick:()=>{A(e),b(e.label),w(!1)},children:e.label},e.value))]}),f?.showMessage&&f.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:f.message})]})}let I=O&&!Array.isArray(O)?P.findIndex(e=>JSON.stringify(e.value)===JSON.stringify(O.value)):-1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)($,{field:e}),g&&P.length===0?(0,X.jsx)(`div`,{className:`w-full rounded border border-black/10 px-2 py-1.5 text-[12px] text-neutral-400 bg-neutral-50`,children:`Loading options...`}):(0,X.jsxs)(`select`,{value:I>=0?String(I):``,onChange:e=>{let t=P[Number(e.target.value)];t&&A(t)},disabled:u,className:`w-full rounded border px-2 py-1.5 text-[13px] font-mono focus:outline-none focus:ring-1 transition-opacity ${f?.error?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`} ${u?`bg-neutral-50 text-neutral-400`:`bg-white`} ${g?`opacity-60`:``}`,children:[(0,X.jsx)(`option`,{value:``,children:e.placeholder??`Choose an option`}),P.map((e,t)=>(0,X.jsx)(`option`,{value:String(t),children:e.label},e.label))]}),f?.showMessage&&f.message&&(0,X.jsx)(`span`,{className:`text-[11px] text-red-500`,children:f.message})]})},boolean:wr},Or=({field:e,pluginApiName:t,disabled:n=!1})=>{let r=Dr[e.type];return(0,X.jsx)(r,{field:e,pluginApiName:t,disabled:n})},kr=()=>{let e=L(),t=T();return{getObjectByAPIName:(0,H.useCallback)(async n=>{try{let t=await(await e(`/api/custom-objects?filters=${encodeURIComponent(JSON.stringify({api_name:n}))}`)).json(),r=Array.isArray(t)?t:t.results;if(r&&r.length>0)return r}catch{}let r=t?.business.client_object;if(r?.access&&r.name===n)return[{id:r.id,object_name:r.object_name}]},[e,t]),getCustomObjectDetails:(0,H.useCallback)(async t=>{try{let[n,r]=await Promise.all([e(`/api/custom-objects/${t}`),e(`/api/custom-objects/${t}/fields`)]),i=await n.json(),a=await r.json(),o=Array.isArray(a)?a:a.results??[];return{id:t,objectName:i.object_name??``,fields:o.map(e=>({id:e.id,name:e.name,displayName:e.display_name}))}}catch{return{id:t,objectName:``,fields:[]}}},[e])}},Ar=({state:e,onDismiss:t})=>{let n=e.error?.message??`Unknown error`,r=e.context?.workerName,i=e.context?.pluginApiName;return(0,X.jsx)(w,{open:e.visible,size:`xl`,ariaModal:!0,fontMono:!1,onBackdropClick:t,header:(0,X.jsx)(C,{title:`Critical Exception`,statusDot:`red`}),footer:(0,X.jsx)(`button`,{onClick:t,className:`rounded bg-neutral-900 px-3 py-1.5 text-[12px] text-white transition-colors hover:bg-neutral-700`,children:`Dismiss`}),children:(0,X.jsxs)(`div`,{className:`px-5 py-4`,children:[(0,X.jsx)(`p`,{className:`m-0 mb-3 text-[12px] leading-relaxed text-neutral-700`,children:`This error will be logged in Kizen's monitoring stack. Did you mean to throw it, or would you prefer to handle the error in your application code with a toast or other messaging?`}),(r??i)&&(0,X.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-2 text-[11px] text-neutral-600`,children:[r&&(0,X.jsxs)(`span`,{className:`rounded bg-neutral-100 px-2 py-0.5 font-mono`,children:[`worker: `,r]}),i&&(0,X.jsxs)(`span`,{className:`rounded bg-neutral-100 px-2 py-0.5 font-mono`,children:[`plugin: `,i]})]}),(0,X.jsx)(`div`,{className:`mb-2 text-[11px] font-semibold uppercase tracking-wide text-neutral-500`,children:`Error`}),(0,X.jsx)(`div`,{className:`whitespace-pre-wrap break-words rounded border border-black/10 bg-neutral-950 px-3 py-2 font-mono text-[11px] leading-relaxed text-amber-300`,children:n})]})})};function jr(){let[e,t]=(0,H.useState)({visible:!1});return{onMonitoringException:(0,H.useCallback)((e,n)=>{let r={};n.extra.workerName!==void 0&&(r.workerName=n.extra.workerName),n.extra.pluginApiName!==void 0&&(r.pluginApiName=n.extra.pluginApiName),t({visible:!0,error:e,context:r})},[]),dialog:(0,X.jsx)(Ar,{state:e,onDismiss:(0,H.useCallback)(()=>{t(e=>({...e,visible:!1}))},[])})}}export{hr as a,Xn as c,Qn as d,$n as f,Er as i,Kn as l,kr as n,Sr as o,Cr as p,Or as r,nr as s,jr as t,lr as u};
|
package/dist/viewer/index.html
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Kizen App Development Toolkit</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-CiXkrLfH.js"></script>
|
|
8
8
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-DF2fYuay.js">
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/fa-core-BoBqCOD3.js">
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/storageKeys-C6c8YF5Y.js">
|
|
11
|
+
<link rel="modulepreload" crossorigin href="/assets/api-BcUybEsl.js">
|
|
10
12
|
<link rel="modulepreload" crossorigin href="/assets/useQuery-5OkVbV1s.js">
|
|
11
13
|
<link rel="modulepreload" crossorigin href="/assets/react-csXWLXSE.js">
|
|
12
14
|
<link rel="modulepreload" crossorigin href="/assets/BootstrapContext-D5ZnMrOp.js">
|
|
13
15
|
<link rel="modulepreload" crossorigin href="/assets/bundleQuery-CjbA01rb.js">
|
|
14
16
|
<link rel="modulepreload" crossorigin href="/assets/useNavigate-BblEmQ3O.js">
|
|
15
|
-
<link rel="modulepreload" crossorigin href="/assets/storageKeys-C6c8YF5Y.js">
|
|
16
17
|
<link rel="modulepreload" crossorigin href="/assets/SidebarContext-Cn8QRb77.js">
|
|
17
|
-
<link rel="modulepreload" crossorigin href="/assets/api-CT-MKz2h.js">
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/assets/Card-BpDJPrPZ.js">
|
|
19
19
|
<link rel="stylesheet" crossorigin href="/assets/index-DtzraybB.css">
|
|
20
20
|
</head>
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-DF2fYuay.js";import{A as t,T as n,j as r,k as i}from"./fa-core-BoBqCOD3.js";import{n as a,t as o}from"./bundleQuery-CjbA01rb.js";import{t as s}from"./useQuery-5OkVbV1s.js";import{a as c,i as l,n as u}from"./BootstrapContext-D5ZnMrOp.js";import{i as d,n as f,o as p,r as m,s as h,t as g}from"./useCriticalExceptionDialog-FcLgRoVH.js";import{d as _}from"./storageKeys-C6c8YF5Y.js";import{n as v,r as y}from"./api-CT-MKz2h.js";import{t as b}from"./Card-BpDJPrPZ.js";import{t as x}from"./CodeViewer-C9aVhzG7.js";import{C as S,c as C,d as w,i as T,l as E,n as D,o as O,r as k,s as A,t as j}from"./configStorage-TfZCyGrB.js";var M=e(r(),1),N=t(),P=e=>e?JSON.stringify(e,null,2):`{}`,F=({apiName:e,configTemplate:t})=>{let n=k(e),r=P(t),[i,a]=(0,M.useState)(n?.__kizen_clean_config?JSON.stringify(n.__kizen_clean_config,null,2):r),[o,s]=(0,M.useState)(null),[c,l]=(0,M.useState)(!1);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,N.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,N.jsxs)(`p`,{className:`text-[13px] text-neutral-500 m-0`,children:[`No setup assistant defined. Enter configuration as JSON.`,t?` Pre-populated from config_template.`:``]})}),(0,N.jsx)(`textarea`,{value:i,onChange:e=>{a(e.target.value),s(null),l(!1)},spellCheck:!1,className:`w-full min-h-[300px] rounded border p-3 text-[13px] font-mono leading-relaxed focus:outline-none focus:ring-1 ${o?`border-red-300 focus:ring-red-400`:`border-black/10 focus:ring-blue-400`}`}),o&&(0,N.jsxs)(`span`,{className:`text-[12px] text-red-500`,children:[`Parse error: `,o]}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`button`,{onClick:()=>{try{A(e,JSON.parse(i)),s(null),l(!0),setTimeout(()=>{l(!1)},2e3)}catch(e){s(e instanceof Error?e.message:`Invalid JSON`),l(!1)}},className:`rounded bg-blue-600 px-4 py-1.5 text-[13px] font-medium text-white hover:bg-blue-700 active:bg-blue-800`,children:`Save Configuration`}),(0,N.jsx)(`button`,{onClick:()=>{j(e),a(r),s(null),l(!1)},className:`rounded border border-black/10 px-4 py-1.5 text-[13px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`Reset`}),c&&(0,N.jsx)(`span`,{className:`text-[12px] text-green-600 font-medium`,children:`Saved`})]})]})},I=({open:e,onClose:t,apiName:n,loadFn:r,label:i})=>{let a=(0,M.useMemo)(()=>e?r(n)?.__kizen_clean_config??null:null,[e,n,r]),o=(0,M.useMemo)(()=>a?JSON.stringify(a,null,2):``,[a]),[s,u]=(0,M.useState)(!1);return(0,M.useEffect)(()=>{e||u(!1)},[e]),(0,N.jsx)(l,{open:e,size:`xl`,ariaModal:!0,onBackdropClick:t,header:(0,N.jsx)(c,{title:`Stored JSON — ${i}`,onClose:t}),footer:a?(0,N.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{u(!0),setTimeout(()=>{u(!1)},1200)})},className:`rounded border border-black/10 px-3 py-1 text-[12px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:s?`Copied`:`Copy`}):void 0,children:(0,N.jsxs)(`div`,{className:`px-5 py-4`,children:[(0,N.jsxs)(`p`,{className:`m-0 mb-3 text-[12px] text-neutral-500`,children:[`This is the saved JSON the plugin runtime will see as`,` `,(0,N.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 font-mono text-[11px]`,children:i}),`. Save the form to refresh.`]}),a?(0,N.jsx)(x,{code:o,language:`json`}):(0,N.jsx)(`div`,{className:`rounded border border-dashed border-black/10 px-4 py-6 text-center text-[12px] text-neutral-400`,children:`No saved configuration yet. Save the form to populate this view.`})]})})},L=({config:e,apiName:t,loadFn:n,saveFn:r,clearFn:i})=>{let a=n(t)?.__kizen_setup_assistant_values,o=(0,M.useRef)({}),[s,c]=(0,M.useState)(!1),{getObjectByAPIName:l,getCustomObjectDetails:u}=f(),p=(0,M.useCallback)(e=>{o.current=e},[]);return(0,N.jsx)(h,{config:e,value:a,onStateChange:p,disabledKeys:[],getObjectByAPIName:l,getCustomObjectDetails:u,children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[e.fields?.map(e=>(0,N.jsx)(d,{field:e,pluginApiName:t},e.key)),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,N.jsx)(`button`,{onClick:()=>{let n=o.current;r(t,n,e),c(!0),setTimeout(()=>{c(!1)},2e3)},className:`rounded bg-blue-600 px-4 py-1.5 text-[13px] font-medium text-white hover:bg-blue-700 active:bg-blue-800`,children:`Save Configuration`}),(0,N.jsx)(`button`,{onClick:()=>{i(t),window.location.reload()},className:`rounded border border-black/10 px-4 py-1.5 text-[13px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`Reset`}),s&&(0,N.jsx)(`span`,{className:`text-[12px] text-green-600 font-medium`,children:`Saved`})]})]})})},R=({config:e,apiName:t,loadFn:r,saveFn:a,clearFn:o})=>{let s=u(),c=y(),l=(0,M.useMemo)(()=>m(c),[c]),{environment:d}=_(),f=v[d],[h,b]=(0,M.useState)(!1),[x,C]=(0,M.useState)(!1),{onMonitoringException:T,dialog:D}=g();return s?(0,N.jsx)(p,{appPath:f,user:{id:s.team.user,crm_client_id:``},business:s.business,clientObject:s.business.client_object?{id:s.business.client_object.id,objectName:s.business.client_object.object_name}:void 0,teamMember:s.team,onNavigate:()=>{},performFileUpload:()=>Promise.resolve({url:``}),monitoringExceptionHelper:T,performRequest:async(e,t,n,r)=>{try{return w({data:await l.request(e,t,n,r),status:200})}catch(e){throw e instanceof S?e:E(500,`Unknown error occurred during request`)}},modal:{showing:h,show:x,showPrompt:()=>{b(!0),C(!0)},onConfirm:()=>{b(!1),C(!1)},onHide:()=>{b(!1),C(!1)}},showToast:()=>{},clearToasts:()=>{},children:()=>(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(L,{config:e,apiName:t,loadFn:r,saveFn:a,clearFn:o}),D]})}):(0,N.jsx)(i,{icon:n,className:`animate-spin text-neutral-400`})},z=()=>{let{apiName:e}=a({strict:!1}),{data:t,isLoading:n,isError:r}=s(o),[i,c]=(0,M.useState)(null);if(n)return(0,N.jsx)(b,{children:(0,N.jsx)(`p`,{className:`m-0 text-[13px] text-neutral-400`,children:`Fetching bundle.json…`})});if(r)return(0,N.jsx)(b,{children:(0,N.jsx)(`p`,{className:`m-0 text-[13px] text-red-700`,children:`Could not load bundle.json.`})});let l=t?.find(t=>t.api_name===e);if(!l)return(0,N.jsx)(b,{children:(0,N.jsxs)(`p`,{className:`m-0 text-[13px] text-neutral-500`,children:[`No app found with api_name`,` `,(0,N.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 py-0.5`,children:e}),`.`]})});let u=l.base_config,d=u?.setup_assistant,f=u?.user_setup_assistant,p=(d?.fields?.length??0)>0,m=(f?.fields?.length??0)>0;return!p&&!m?(0,N.jsx)(b,{children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`Configuration`}),(0,N.jsx)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:`Enter plugin configuration as JSON.`})]}),(0,N.jsx)(F,{apiName:e??``,configTemplate:l.config_template})]})}):(0,N.jsxs)(`div`,{className:`flex flex-col gap-4 lg:flex-row lg:items-start`,children:[p&&d&&(0,N.jsx)(b,{className:`lg:flex-1 lg:min-w-0`,children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`Business Configuration`}),(0,N.jsxs)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:[`Configure the business-level setup assistant fields. These values are shared across the whole business and exposed to plugin scripts at`,` `,(0,N.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 font-mono text-[11px]`,children:`this.config`}),`.`]})]}),(0,N.jsx)(`button`,{onClick:()=>{c(`business`)},className:`shrink-0 rounded border border-black/10 px-3 py-1.5 text-[12px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`View JSON`})]}),(0,N.jsx)(R,{config:d,apiName:e??``,loadFn:k,saveFn:O,clearFn:j})]})}),m&&f&&(0,N.jsx)(b,{className:`lg:flex-1 lg:min-w-0`,children:(0,N.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h2`,{className:`text-[15px] font-bold text-neutral-900 m-0`,children:`User Configuration`}),(0,N.jsxs)(`p`,{className:`text-[12px] text-neutral-400 m-0 mt-1`,children:[`Configure the per-user setup assistant fields. These values are scoped to the logged-in user and exposed to plugin scripts at`,` `,(0,N.jsx)(`code`,{className:`rounded bg-neutral-100 px-1 font-mono text-[11px]`,children:`this.userConfig`}),`.`]})]}),(0,N.jsx)(`button`,{onClick:()=>{c(`user`)},className:`shrink-0 rounded border border-black/10 px-3 py-1.5 text-[12px] font-medium text-neutral-600 hover:bg-neutral-50 active:bg-neutral-100`,children:`View JSON`})]}),(0,N.jsx)(R,{config:f,apiName:e??``,loadFn:T,saveFn:C,clearFn:D})]})}),(0,N.jsx)(I,{open:i===`business`,onClose:()=>{c(null)},apiName:e??``,loadFn:k,label:`this.config`}),(0,N.jsx)(I,{open:i===`user`,onClose:()=>{c(null)},apiName:e??``,loadFn:T,label:`this.userConfig`})]})};export{z as ConfigurationPage};
|