wicked-crew 0.18.11 → 0.18.13
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/api/chat-jobs.d.ts.map +1 -1
- package/dist/api/chat-jobs.js +4 -1
- package/dist/api/chat-jobs.js.map +1 -1
- package/dist/api/chat-proposals.d.ts +8 -0
- package/dist/api/chat-proposals.d.ts.map +1 -1
- package/dist/api/chat-proposals.js +38 -1
- package/dist/api/chat-proposals.js.map +1 -1
- package/dist/api/requirements.d.ts +3 -0
- package/dist/api/requirements.d.ts.map +1 -1
- package/dist/api/requirements.js +3 -0
- package/dist/api/requirements.js.map +1 -1
- package/dist/api/routes.d.ts +2 -0
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +7 -2
- package/dist/api/routes.js.map +1 -1
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +57 -52
- package/dist/api/server.js.map +1 -1
- package/dist/api/stall-watchdog.d.ts +15 -0
- package/dist/api/stall-watchdog.d.ts.map +1 -1
- package/dist/api/stall-watchdog.js +21 -1
- package/dist/api/stall-watchdog.js.map +1 -1
- package/dist/apps/check.d.ts +12 -0
- package/dist/apps/check.d.ts.map +1 -1
- package/dist/apps/check.js +34 -8
- package/dist/apps/check.js.map +1 -1
- package/dist/apps/exec/executor.d.ts +2 -1
- package/dist/apps/exec/executor.d.ts.map +1 -1
- package/dist/apps/exec/executor.js +3 -2
- package/dist/apps/exec/executor.js.map +1 -1
- package/dist/apps/exec/limits.d.ts +7 -1
- package/dist/apps/exec/limits.d.ts.map +1 -1
- package/dist/apps/exec/limits.js +35 -2
- package/dist/apps/exec/limits.js.map +1 -1
- package/dist/apps/exec/source-stage.d.ts.map +1 -1
- package/dist/apps/exec/source-stage.js +3 -1
- package/dist/apps/exec/source-stage.js.map +1 -1
- package/dist/apps/self-check.d.ts +25 -0
- package/dist/apps/self-check.d.ts.map +1 -0
- package/dist/apps/self-check.js +102 -0
- package/dist/apps/self-check.js.map +1 -0
- package/dist/apps/store.d.ts +7 -1
- package/dist/apps/store.d.ts.map +1 -1
- package/dist/apps/store.js +10 -0
- package/dist/apps/store.js.map +1 -1
- package/dist/apps/turns.d.ts +10 -4
- package/dist/apps/turns.d.ts.map +1 -1
- package/dist/apps/turns.js +44 -4
- package/dist/apps/turns.js.map +1 -1
- package/dist/apps-server/server/lib/bundle/server.mjs +45 -14
- package/dist/core/estate-mcp-client.d.ts +3 -1
- package/dist/core/estate-mcp-client.d.ts.map +1 -1
- package/dist/core/estate-mcp-client.js +22 -14
- package/dist/core/estate-mcp-client.js.map +1 -1
- package/dist/knowledge/estate-write.d.ts +5 -0
- package/dist/knowledge/estate-write.d.ts.map +1 -0
- package/dist/knowledge/estate-write.js +23 -0
- package/dist/knowledge/estate-write.js.map +1 -0
- package/dist/knowledge/gate/gate.d.ts +1 -1
- package/dist/knowledge/gate/gate.d.ts.map +1 -1
- package/dist/knowledge/gate/gate.js +11 -7
- package/dist/knowledge/gate/gate.js.map +1 -1
- package/dist/knowledge/package.d.ts +11 -0
- package/dist/knowledge/package.d.ts.map +1 -1
- package/dist/knowledge/package.js +63 -28
- package/dist/knowledge/package.js.map +1 -1
- package/dist/knowledge/projector.d.ts +4 -2
- package/dist/knowledge/projector.d.ts.map +1 -1
- package/dist/knowledge/projector.js +5 -4
- package/dist/knowledge/projector.js.map +1 -1
- package/dist/knowledge/trackers/projector.d.ts +2 -0
- package/dist/knowledge/trackers/projector.d.ts.map +1 -1
- package/dist/knowledge/trackers/projector.js +4 -3
- package/dist/knowledge/trackers/projector.js.map +1 -1
- package/dist/mcp/broker.d.ts +5 -0
- package/dist/mcp/broker.d.ts.map +1 -1
- package/dist/mcp/broker.js +55 -1
- package/dist/mcp/broker.js.map +1 -1
- package/dist/mcp/classify.d.ts +2 -0
- package/dist/mcp/classify.d.ts.map +1 -1
- package/dist/mcp/classify.js +2 -0
- package/dist/mcp/classify.js.map +1 -1
- package/dist/mcp/estate-relay.d.ts.map +1 -1
- package/dist/mcp/estate-relay.js +7 -3
- package/dist/mcp/estate-relay.js.map +1 -1
- package/dist/mcp/registry.d.ts.map +1 -1
- package/dist/mcp/registry.js +6 -1
- package/dist/mcp/registry.js.map +1 -1
- package/dist/sources/ask.d.ts +5 -1
- package/dist/sources/ask.d.ts.map +1 -1
- package/dist/sources/ask.js +9 -15
- package/dist/sources/ask.js.map +1 -1
- package/dist/sources/drivers/sqlite.d.ts.map +1 -1
- package/dist/sources/drivers/sqlite.js +8 -3
- package/dist/sources/drivers/sqlite.js.map +1 -1
- package/dist/sources/policy/rules.d.ts +3 -0
- package/dist/sources/policy/rules.d.ts.map +1 -0
- package/dist/sources/policy/rules.js +21 -0
- package/dist/sources/policy/rules.js.map +1 -0
- package/dist/sources/policy/sqlite.d.ts +2 -0
- package/dist/sources/policy/sqlite.d.ts.map +1 -1
- package/dist/sources/policy/sqlite.js +6 -0
- package/dist/sources/policy/sqlite.js.map +1 -1
- package/dist/studio/apps-standalone/fixture.js +3 -3
- package/dist/studio/apps-standalone/runtime.css +38 -5
- package/dist/studio/apps-standalone/runtime.js +1 -1
- package/dist/studio/assets/{KnowledgeGraph-B2NelLEg.js → KnowledgeGraph-BgXDoH6k.js} +1 -1
- package/dist/studio/assets/index-CrcZTJjG.css +32 -0
- package/dist/studio/assets/{index-BeEB56KG.js → index-rMZ47jUD.js} +306 -305
- package/dist/studio/editors/wicked-apps/editor.json +1 -1
- package/dist/studio/editors/wicked-apps/index.html +40 -7
- package/dist/studio/editors/wicked-deck/editor.json +1 -1
- package/dist/studio/editors/wicked-deck/index.html +1 -1
- package/dist/studio/editors/wicked-doc/editor.json +1 -1
- package/dist/studio/editors/wicked-doc/index.html +1 -1
- package/dist/studio/editors/wicked-insights/editor.json +1 -1
- package/dist/studio/editors/wicked-insights/index.html +1 -1
- package/dist/studio/editors/wicked-page/editor.json +1 -1
- package/dist/studio/editors/wicked-page/index.html +1 -1
- package/dist/studio/editors/wicked-video/editor.json +1 -1
- package/dist/studio/editors/wicked-video/index.html +1 -1
- package/dist/studio/index.html +2 -2
- package/dist/studio/testid-inventory.json +113 -5
- package/endpoint-manifest.json +1 -1
- package/package.json +4 -4
- package/dist/studio/assets/index-CnfeJvlM.css +0 -32
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="wicked-editor" content="wicked-apps">
|
|
6
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
6
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
7
7
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
8
|
<title>App</title>
|
|
9
9
|
<!-- THE one stylesheet (DES-APPS-001 §7.1). The runtime adds its geometry and colours to THIS sheet through the CSSOM
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
html, body { height: 100%; margin: 0; }
|
|
25
25
|
body { font: 13px/1.4 var(--font-sans); color: var(--ink-high); background: var(--surface-base); overflow: hidden; }
|
|
26
26
|
.wk-app { display: flex; height: 100%; min-width: 0; }
|
|
27
|
-
.wk-main { flex: 1 1 auto; min-width: 0; overflow: auto; padding: 14px 18px 24px; }
|
|
27
|
+
.wk-main { flex: 1 1 auto; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 14px 18px 24px; }
|
|
28
28
|
.wk-app[data-mode="edit"] .wk-main {
|
|
29
29
|
background-image: radial-gradient(circle, color-mix(in srgb, var(--ink-muted) 28%, transparent) 1px, transparent 1px);
|
|
30
30
|
background-size: 16px 16px;
|
|
31
31
|
}
|
|
32
|
-
.wk-pages { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--border); }
|
|
33
|
-
.wk-page { font: inherit; font-size: 14px; padding: 6px 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-muted); cursor: pointer; }
|
|
32
|
+
.wk-pages { display: flex; min-width: 0; max-width: 100%; overflow-x: auto; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--border); }
|
|
33
|
+
.wk-page { flex: 0 0 auto; white-space: nowrap; font: inherit; font-size: 14px; padding: 6px 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-muted); cursor: pointer; }
|
|
34
34
|
.wk-page.is-on { color: var(--ink-high); border-bottom-color: var(--ink-high); font-weight: 600; }
|
|
35
35
|
.wk-page:focus-visible, .wk-btn:focus-visible, .wk-tile:focus-visible, .wk-link:focus-visible, .wk-cell:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 1px; }
|
|
36
36
|
.wk-grid { position: relative; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: var(--row); gap: var(--gap); }
|
|
@@ -53,9 +53,14 @@
|
|
|
53
53
|
.wk-kpi-caption { margin-top: 4px; font-size: 12px; color: var(--ink-muted); }
|
|
54
54
|
.wk-delta--up { color: var(--status-fail); }
|
|
55
55
|
.wk-delta--down { color: var(--status-ok); }
|
|
56
|
+
.wk-table-scroll { min-width: 0; max-width: 100%; overflow-x: auto; }
|
|
56
57
|
.wk-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
57
58
|
.wk-table th { text-align: left; font-weight: 500; color: var(--ink-muted); padding: 4px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
|
|
58
|
-
.wk-table td { padding: 6px 8px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); color: var(--ink-high); overflow-wrap:
|
|
59
|
+
.wk-table td { padding: 6px 8px; border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); color: var(--ink-high); overflow-wrap: normal; word-break: normal; vertical-align: top; }
|
|
60
|
+
.wk-table td.wk-token { white-space: nowrap; }
|
|
61
|
+
.wk-table td.wk-token--long { max-width: 48ch; overflow: hidden; text-overflow: ellipsis; }
|
|
62
|
+
.wk-table-scroll:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 2px; }
|
|
63
|
+
.wk-table td.wk-prose { min-width: 16ch; max-width: 60ch; white-space: normal; }
|
|
59
64
|
.wk-table td.wk-num { font-family: var(--font-mono); text-align: right; white-space: nowrap; }
|
|
60
65
|
.wk-td-actions { white-space: nowrap; text-align: right; }
|
|
61
66
|
.wk-td-actions .wk-btn + .wk-btn { margin-left: 4px; }
|
|
@@ -73,6 +78,32 @@
|
|
|
73
78
|
.wk-text--heading { font-size: 18px; font-weight: 650; }
|
|
74
79
|
.wk-text--caption { font-size: 12px; color: var(--ink-muted); }
|
|
75
80
|
.wk-filter { display: flex; align-items: center; gap: 6px; height: 100%; }
|
|
81
|
+
.wk-filter-select { display: flex; align-items: center; gap: 6px; min-width: 0; height: 100%; container: wkfilter / inline-size; }
|
|
82
|
+
/* A select with an option search shares its one row: the label gives way first (an ellipsis, its full words in its
|
|
83
|
+
title), the select and the search each keep 6ch, so nothing overlaps; in a narrow filter (the default three
|
|
84
|
+
columns) the count leaves the row (it stays in the select's last option and for screen readers). A select without
|
|
85
|
+
a search keeps its layout and its label. */
|
|
86
|
+
.wk-filter-select--search .wk-filter-label { flex: 0 1 auto; min-width: 3ch; overflow: hidden; text-overflow: ellipsis; }
|
|
87
|
+
.wk-filter-select--search .wk-filter .wk-input { flex: 1 1 0; width: 0; min-width: 6ch; }
|
|
88
|
+
/* (specificity over the shorthand below) The select's group takes 3/5 of the row; neither group draws over the other. */
|
|
89
|
+
.wk-filter-select.wk-filter-select--search > .wk-filter { flex-grow: 3; overflow: clip; overflow-clip-margin: 4px; }
|
|
90
|
+
.wk-filter-select.wk-filter-select--search > .wk-filter-options { flex-grow: 2; overflow: clip; overflow-clip-margin: 4px; }
|
|
91
|
+
.wk-filter-select--search .wk-filter-options .wk-input { flex: 1 1 0; min-width: 6ch; }
|
|
92
|
+
@container wkfilter (max-width: 300px) {
|
|
93
|
+
.wk-filter-select--search .wk-filter-options .wk-muted { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
94
|
+
}
|
|
95
|
+
/* A narrow searchable filter (200px or less: the default three columns): the label leaves the row (it still names the
|
|
96
|
+
select), and the select and the search split the row 1:1 with no ch floors, so neither can overflow the cell
|
|
97
|
+
whatever the font's ch (WebKit's is wider: the floors pushed a control out of a three-column filter there). */
|
|
98
|
+
@container wkfilter (max-width: 200px) {
|
|
99
|
+
.wk-filter-select--search .wk-filter-label { position: absolute; width: 1px; height: 1px; min-width: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
100
|
+
.wk-filter-select.wk-filter-select--search > .wk-filter, .wk-filter-select.wk-filter-select--search > .wk-filter-options { flex-grow: 1; }
|
|
101
|
+
.wk-filter-select--search .wk-filter .wk-input, .wk-filter-select--search .wk-filter-options .wk-input { min-width: 0; }
|
|
102
|
+
}
|
|
103
|
+
.wk-filter-select .wk-filter { height: auto; flex: 1 1 0; min-width: 0; }
|
|
104
|
+
.wk-filter-options { display: flex; flex: 1 1 0; min-width: 0; align-items: center; gap: 6px; }
|
|
105
|
+
.wk-filter-options .wk-muted { flex: 0 0 auto; white-space: nowrap; }
|
|
106
|
+
.wk-filter-options .wk-input { width: 0; flex: 1 1 100px; }
|
|
76
107
|
.wk-filter-label { font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
|
|
77
108
|
.wk-input { font: inherit; min-width: 0; flex: 1 1 auto; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-raised); color: var(--ink-high); }
|
|
78
109
|
.wk-input--date { flex: 0 1 140px; }
|
|
@@ -118,7 +149,7 @@
|
|
|
118
149
|
.wk-prop-label { font-size: 12px; color: var(--ink-muted); }
|
|
119
150
|
.wk-prop-box { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
|
|
120
151
|
.wk-check { align-self: flex-start; }
|
|
121
|
-
.wk-cell, .wk-handle { touch-action: none; }
|
|
152
|
+
.wk-app[data-mode="edit"] .wk-cell, .wk-handle { touch-action: none; }
|
|
122
153
|
/* Edit in place: a component's own words show they can be edited (an outline and a pencil on hover). */
|
|
123
154
|
.wk-app[data-mode="edit"] .wk-editable { cursor: text; border-radius: 3px; }
|
|
124
155
|
.wk-app[data-mode="edit"] .wk-editable:hover { outline: 1px dashed var(--ui-accent); outline-offset: 2px; }
|
|
@@ -140,12 +171,14 @@
|
|
|
140
171
|
.wk-grid { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
|
|
141
172
|
.wk-grid > .wk-cell { grid-column: 1 !important; grid-row: auto !important; min-height: var(--row); }
|
|
142
173
|
.wk-cell--chart, .wk-cell--table { min-height: 220px; }
|
|
174
|
+
.wk-filter-select { flex-wrap: wrap; height: auto; }
|
|
175
|
+
.wk-filter-select .wk-filter, .wk-filter-options { flex-basis: 100%; }
|
|
143
176
|
.wk-palette, .wk-props { display: none; }
|
|
144
177
|
}
|
|
145
178
|
</style>
|
|
146
179
|
</head>
|
|
147
180
|
<body>
|
|
148
|
-
<script>var Kt=Object.defineProperty;var Zt=(ae,de,$e)=>de in ae?Kt(ae,de,{enumerable:!0,configurable:!0,writable:!0,value:$e}):ae[de]=$e;var Pe=(ae,de,$e)=>Zt(ae,typeof de!="symbol"?de+"":de,$e);(function(){"use strict";const ae="wicked.editor";function $e(u,c,h){return{editor:u,version:c,protocol:[1,2],surfaces:h}}function mt(u,c){const h=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:ae,v:1,type:"plugin.ready",payload:$e(u,h,c)},"*")}const wt=/^[A-Z]{3}$/u;function ue(u,c,h){if(u==null)return"";if(typeof u=="boolean")return u?"yes":"no";const w=typeof c?.decimals=="number"&&Number.isInteger(c.decimals)?Math.min(10,Math.max(0,c.decimals)):void 0,m=typeof u=="number"?u:typeof u=="string"&&u.trim()!==""&&Number.isFinite(Number(u))?Number(u):null;try{switch(c?.kind){case"currency":if(m===null||!wt.test(c.currency))break;return new Intl.NumberFormat(h,{style:"currency",currency:c.currency,...w!==void 0?{minimumFractionDigits:w,maximumFractionDigits:w}:{}}).format(m);case"percent":if(m===null)break;return new Intl.NumberFormat(h,{style:"percent",maximumFractionDigits:w??1}).format(m);case"number":if(m===null)break;return new Intl.NumberFormat(h,w!==void 0?{minimumFractionDigits:w,maximumFractionDigits:w}:{}).format(m);case"date":case"datetime":{const O=new Date(typeof u=="number"?u:String(u));if(Number.isNaN(O.getTime()))break;return new Intl.DateTimeFormat(h,c.kind==="date"?{dateStyle:"medium",timeZone:"UTC"}:{dateStyle:"medium",timeStyle:"short"}).format(O)}case"duration":{if(m===null)break;const O=Math.abs(Math.round(m)),b=Math.floor(O/86400),x=Math.floor(O%86400/3600),Z=Math.floor(O%3600/60);return b>0?`${b}d ${x}h`:x>0?`${x}h ${Z}m`:`${Z}m`}default:break}}catch{}return typeof u=="number"?Number.isInteger(u)?String(u):new Intl.NumberFormat(h,{maximumFractionDigits:6}).format(u):String(u)}function T(u,c=200){return typeof u=="string"?u.replace(/[\u0000-\u001f\u007f]+/gu," ").slice(0,c):""}const yt="http://www.w3.org/2000/svg";function G(u,c,h){const w=document.createElementNS(yt,u);for(const[m,O]of Object.entries(c))w.setAttribute(m,String(O));return h!==void 0&&w.setAttribute("class",h),w}function Ce(u,c,h,w,m="start"){const O=G("text",{x:u,y:c,"text-anchor":m},w);return O.textContent=h,O}function be(u){return typeof u=="number"?Number.isFinite(u)?u:0:typeof u=="string"&&u.trim()!==""&&Number.isFinite(Number(u))?Number(u):0}const _=u=>Math.round(u*10)/10;function _e(u,c){const h=document.createElement("ul");h.className="wk-legend",c.forEach((w,m)=>{const O=document.createElement("li"),b=document.createElement("span");b.className=`wk-swatch wk-series-${m%12}`,O.append(b,document.createTextNode(w)),h.append(O)}),u.append(h)}function bt(u,c,h,w){const m=y=>h.columns.findIndex(g=>g.name===y),O=m(c.x),b=c.series.slice(0,c.chart==="pie"?1:12).map(y=>({label:T(y.label??y.column,60),i:m(y.column)})).filter(y=>y.i>=0),x=h.rows.slice(0,500);if(O<0||b.length===0||x.length===0){const y=document.createElement("p");y.className="wk-empty",y.textContent=x.length===0?"No rows":"This chart’s columns are not in its query’s rows",u.append(y);return}const Z=x.map(y=>ue(y[O],void 0,w));if(c.chart==="bar"){const y=c.stacked===!0&&b.length>1,g=x.map(I=>b.map(P=>be(I[P.i])));let v=0,E=0;for(const I of g)if(y)E=Math.max(E,I.filter(P=>P>0).reduce((P,H)=>P+H,0)),v=Math.min(v,I.filter(P=>P<0).reduce((P,H)=>P+H,0));else for(const P of I)E=Math.max(E,P),v=Math.min(v,P);E===v&&(E=v+1);const q=130,A=b.length>1?250:220,L=I=>q+(I-v)/(E-v)*A,C=L(0),S=y||b.length===1?26:Math.max(26,b.length*10+10),N=G("svg",{viewBox:`0 0 400 ${x.length*S+4}`,role:"img","aria-label":T(c.title??"bar chart",120)},"wk-chart wk-chart--bar");v<0&&N.append(G("line",{x1:_(C),x2:_(C),y1:0,y2:x.length*S+4},"wk-grid-line")),x.forEach((I,P)=>{const H=P*S+2;if(N.append(Ce(0,_(H+S/2+4),Z[P].slice(0,22),"wk-axis")),y){let Ee=0,ne=0;b.forEach((me,pe)=>{const oe=g[P][pe],U=oe>=0?Ee:ne+oe,He=oe>=0?Ee+oe:ne;oe>=0?Ee+=oe:ne+=oe,N.append(G("rect",{x:_(L(U)),y:H+4,width:_(Math.max(1,L(He)-L(U))),height:S-10},`wk-series-${pe%12}`))});return}const re=(S-8)/b.length;b.forEach((Ee,ne)=>{const me=g[P][ne],pe=Math.min(L(me),C),oe=Math.max(1,Math.abs(L(me)-C));N.append(G("rect",{x:_(pe),y:_(H+4+ne*re),width:_(oe),height:_(Math.max(2,re-2)),rx:2},`wk-series-${ne%12}`)),b.length===1&&N.append(Ce(_(me<0?pe-6:pe+oe+6),_(H+S/2+4),ue(I[Ee.i],void 0,w),"wk-value",me<0?"end":"start"))})}),u.append(N),b.length>1&&_e(u,b.map(I=>I.label));return}if(c.chart==="pie"){const y=b[0],g=x.reduce((q,A)=>q+Math.max(0,be(A[y.i])),0)||1,v=G("svg",{viewBox:"0 0 240 240",role:"img","aria-label":T(c.title??"pie chart",120)},"wk-chart wk-chart--pie");let E=-Math.PI/2;x.forEach((q,A)=>{const L=Math.max(0,be(q[y.i]))/g,C=E+L*Math.PI*2,S=C-E>Math.PI?1:0,N=P=>`${_(120+100*Math.cos(P))} ${_(120+100*Math.sin(P))}`,I=L>=.9999?"M 120 20 A 100 100 0 1 1 119.9 20 Z":`M 120 120 L ${N(E)} A 100 100 0 ${S} 1 ${N(C)} Z`;v.append(G("path",{d:I},`wk-series-${A%12}`)),E=C}),u.append(v),_e(u,Z.slice(0,12));return}const ge=600,ce=220,W=36,ve=24,Q=c.chart==="area"&&c.stacked===!0&&b.length>1,X=[],D=new Map;x.forEach((y,g)=>{if(X.push(g),!Q||g+1>=x.length)return;const v=new Map;b.forEach((E,q)=>{const A=be(x[g][E.i]),L=be(x[g+1][E.i]);if(A>0&&L<0||A<0&&L>0){const C=A/(A-L);v.set(C,[...v.get(C)??[],q])}});for(const E of[...v.keys()].sort((q,A)=>q-A))D.set(X.length,new Set(v.get(E))),X.push(g+E)});const ke=(y,g)=>{if(D.get(g)?.has(y)===!0)return 0;const v=X[g],E=Math.floor(v),q=v-E,A=be(x[E][b[y].i]);return q===0||E+1>=x.length?A:A+(be(x[E+1][b[y].i])-A)*q},B=b.map(()=>[]),R=b.map(()=>[]);let Y=0,fe=1;const xe=y=>{y<Y&&(Y=y),y>fe&&(fe=y)};X.forEach((y,g)=>{let v=0,E=0;b.forEach((q,A)=>{const L=ke(A,g);if(!Q){B[A][g]=[0,L],R[A][g]=[0,0],xe(L);return}const C=Math.max(0,L),S=Math.min(0,L);B[A][g]=[v,v+C],R[A][g]=[E+S,E],v+=C,E+=S,xe(v),xe(E)})});const ee=fe,le=Y,qe=y=>W+(x.length===1?0:y/(x.length-1)*(ge-W-8)),he=y=>ce-ve-(y-le)/(ee-le||1)*(ce-ve-10),te=G("svg",{viewBox:`0 0 ${ge} ${ce}`,role:"img","aria-label":T(c.title??`${c.chart} chart`,120)},`wk-chart wk-chart--${c.chart}`);for(let y=0;y<=3;y+=1){const g=le+(ee-le)*y/3;te.append(G("line",{x1:W,x2:ge-8,y1:_(he(g)),y2:_(he(g))},"wk-grid-line")),te.append(Ce(W-6,_(he(g)+4),ue(Math.round(g*10)/10,void 0,w),"wk-axis","end"))}const Te=x.length<=4?x.map((y,g)=>g):[0,Math.floor((x.length-1)/3),Math.floor((x.length-1)*2/3),x.length-1];for(const y of Te)te.append(Ce(_(qe(y)),ce-6,Z[y].slice(0,14),"wk-axis",y===0?"start":y===x.length-1?"end":"middle"));b.forEach((y,g)=>{const v=(S,N)=>`${_(qe(X[S]))},${_(he(N))}`;if(c.chart==="area"){const S=N=>{const I=X.map((H,re)=>v(re,N[re][1])),P=X.map((H,re)=>v(re,N[re][0])).reverse();return`M ${I.join(" L ")} L ${P.join(" L ")} Z`};te.append(G("path",{d:S(B[g])},`wk-area wk-series-${g}`)),Q&&R[g].some(([N,I])=>N!==I)&&te.append(G("path",{d:S(R[g])},`wk-area wk-area--neg wk-series-${g}`))}if(!Q){te.append(G("polyline",{points:X.map((S,N)=>v(N,ke(g,N))).join(" "),fill:"none"},`wk-stroke wk-series-${g}`));return}const E=[];let q=null,A=0,L=[];const C=(S,N)=>S<0?v(N,R[g][N][0]):v(N,B[g][N][1]);X.forEach((S,N)=>{const I=ke(g,N);if(D.get(N)?.has(g)===!0||I===0){q!==null&&q.push(C(A,N)),L.push(N);return}const P=I>0?1:-1;if(q===null)q=L.map(H=>C(P,H)),E.push(q),A=P;else if(P!==A){const H=L[L.length-1];q=H!==void 0?[C(P,H)]:[],E.push(q),A=P}q.push(C(P,N)),L=[]}),q===null&&L.length>1&&E.push(L.map(S=>C(1,S)));for(const S of E)S.length>1&&te.append(G("polyline",{points:S.join(" "),fill:"none"},`wk-stroke wk-series-${g}`))}),u.append(te),b.length>1&&_e(u,b.map(y=>y.label))}const gt=/^#[0-9a-fA-F]{6}$/u,je=/^(?::root|\.wk-c\d{1,4}(?: \.wk-[a-z]+)?)$/u,vt=/^(?:--[a-z0-9-]{1,40}|[a-z-]{1,40})$/u,kt="(max-width: 639px)";function Be(u){return typeof u=="string"&>.test(u)?u.toLowerCase():null}function Le(u,c,h,w){return Number.isInteger(u)?Math.min(h,Math.max(c,u)):w}function xt(u){return typeof u=="string"&&u.length<=200&&!/url\(|[;{}]|\/\*|\\/iu.test(u)?u:null}class Et{constructor(c){Pe(this,"sheet");Pe(this,"base");Pe(this,"rules",new Map);Pe(this,"phone",null);Pe(this,"phoneRules",new Map);if(c.sheet===null)throw new Error("the runtime stylesheet did not load");this.sheet=c.sheet,this.base=this.sheet.cssRules.length}reset(){for(;this.sheet.cssRules.length>this.base;)this.sheet.deleteRule(this.sheet.cssRules.length-1);this.rules.clear(),this.phoneRules.clear(),this.phone=null}rule(c){if(!je.test(c))throw new Error("a selector outside the runtime’s vocabulary");const h=this.rules.get(c);if(h!==void 0)return h;const w=this.sheet.insertRule(`${c} {}`,this.sheet.cssRules.length),m=this.sheet.cssRules[w];return this.rules.set(c,m),m}phoneRule(c){if(!je.test(c))throw new Error("a selector outside the runtime’s vocabulary");const h=this.phoneRules.get(c);if(h!==void 0)return h;if(this.phone===null){const O=this.sheet.insertRule(`@media ${kt} {}`,this.sheet.cssRules.length);this.phone=this.sheet.cssRules[O]}const w=this.phone.insertRule(`${c} {}`,this.phone.cssRules.length),m=this.phone.cssRules[w];return this.phoneRules.set(c,m),m}set(c,h,w){vt.test(h)&&c.style.setProperty(h,w)}theme(c,h){const w=this.rule(":root");for(const[b,x]of Object.entries(c)){const Z=xt(x);/^--[a-z0-9-]{1,40}$/u.test(b)&&Z!==null&&this.set(w,b,Z)}const m=Be(h.accent);m!==null&&this.set(w,"--app-accent",m),h.density==="compact"&&(this.set(w,"--row","36px"),this.set(w,"--gap","8px"));const O=Array.isArray(h.palette)?h.palette:[];for(let b=0;b<12;b+=1){const x=Be(O[b]);x!==null&&this.set(w,`--s${b}`,x)}}place(c,h){const w=this.rule(`.wk-c${c}`),m=Le(h.x,0,11,0),O=Le(h.w,1,12-m,1),b=Le(h.y,0,999,0),x=Le(h.h,1,50,1);this.set(w,"grid-column",`${m+1} / span ${O}`),this.set(w,"grid-row",`${b+1} / span ${x}`)}phoneOrder(c,h,w){const m=this.phoneRule(`.wk-c${c}`);this.set(m,"order",String(Le(h,0,9999,0))),w?this.set(m,"display","none"):m.style.removeProperty("display")}seriesColour(c,h,w){const m=Be(w);m!==null&&this.set(this.rule(`.wk-c${c}`),`--c${Le(h,0,11,0)}`,m)}}const Mt={comfortable:44,compact:36},Ge={comfortable:12,compact:8},At=450,Je=500,$t=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/u,Oe=()=>Object.create(null);function Lt(u,c){if(u===void 0||c===null||c===void 0)return c;if((u.type==="number"||u.type==="integer")&&typeof c=="string"&&c.trim()!==""){const h=Number(c);return Number.isFinite(h)&&(u.type==="number"||Number.isInteger(h))?h:c}return u.type==="boolean"&&typeof c=="string"&&(c==="true"||c==="false")?c==="true":u.type==="string"&&(typeof c=="number"||typeof c=="boolean")?String(c):c}const j=u=>typeof u=="object"&&u!==null&&!Array.isArray(u),St=/^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/u,Qe={table:{w:12,h:5},chart:{w:6,h:5},kpi:{w:3,h:2},text:{w:6,h:1},filter:{w:3,h:1},form:{w:4,h:6},button:{w:2,h:1},image:{w:3,h:3},link:{w:2,h:1}},Nt=[{type:"table",label:"Table"},{type:"chart",label:"Chart"},{type:"kpi",label:"KPI"},{type:"filter",label:"Filter"},{type:"form",label:"Form"},{type:"button",label:"Button"},{type:"text",label:"Text"},{type:"link",label:"Link"}];function d(u,c,h){const w=document.createElement(u);return c!==void 0&&(w.className=c),h!==void 0&&(w.textContent=h),w}function et(u){return u.toISOString().slice(0,10)}function Pt(u){Ot(u)}function Ot(u,c){const h=document.getElementById("wk-apps-sheet")??null;if(!(h instanceof HTMLStyleElement)&&!(h instanceof HTMLLinkElement))return;const w=new Et(h),m=d("div","wk-app");m.setAttribute("data-testid","apps-runtime"),document.body.append(m);let O=null,b=new Set,x=!0,Z=!1,ge=!1,ce=!1,W="preview",ve="full",Q="en",X=0,D=null,ke=!1,B=null,R=null;const Y=Oe(),fe=Oe(),xe=Oe(),ee=new Map,le=new Map,qe=new Map,he=new Map,te=new Map;let Te=0,y=0;const g=new Map;let v=null;const E=new Map;let q=!1,A=null,L=null;const C=e=>{O?.postMessage({p:ae,v:1,...e})},S=(e,t)=>{y+=1;const n=`a${y}`;return C({type:e,id:n,payload:t}),new Promise(s=>g.set(n,s))},N=(e,t)=>C({type:e,payload:t}),I=e=>{const t=e.data;if(!j(t)||t.p!==ae||t.v!==1)return;const n=j(t.payload)?t.payload:{};if(typeof t.re=="string"){const s=g.get(t.re);if(s===void 0)return;g.delete(t.re);const o=j(t.error)?t.error:{};s(t.ok===!0?{ok:!0,payload:n}:{ok:!1,code:String(o.code??"unavailable"),message:T(o.message,300),payload:n});return}if(!q)switch(t.type){case"host.ping":typeof t.id=="string"&&C({re:t.id,ok:!0,payload:{}});return;case"host.theme":j(n.theme)&&(P=n.theme),V();return;case"artifact.changed":ne();return;case"app.mode":(n.mode==="edit"||n.mode==="preview")&&(W=n.mode,W==="preview"&&(R=null),V());return;case"data.invalidate":Me();return;case"host.surface":(n.surface==="card"||n.surface==="full")&&(ve=n.surface,V());return;case"selection.cleared":R=null,V();return;case"host.teardown":q=!0;for(const s of E.values())clearInterval(s);E.clear(),document.removeEventListener("keydown",ht),O?.close(),O=null,m.replaceChildren(d("p","wk-empty","Closed"));return;default:return}};let P={};const H=e=>{j(e)&&(P=e),w.theme(P,{accent:D?.theme?.accent,palette:D?.theme?.palette,density:D?.theme?.density})},re=()=>D?.theme?.density==="compact"?"compact":"comfortable",Ee=(e,t)=>{O=e,O.onmessage=I,b=new Set(Array.isArray(t.grants)?t.grants.filter(o=>typeof o=="string"):[]);const n=j(t.app)?t.app:{};if(x=n.framed!==!1,Z=n.tile===!0,ge=Z&&n.rows===!0,ce=n.propsHost===!0,W=n.mode==="edit"?"edit":"preview",ve=t.surface==="card"||t.size==="inline"?"card":"full",j(n.url))for(const[o,l]of Object.entries(n.url).slice(0,30))$t.test(o)&&typeof l=="string"&&l.length<=1e3&&(xe[o]=l);const s=j(t.prefs)?t.prefs:{};Q=typeof s.locale=="string"&&/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u.test(s.locale)?s.locale:"en",H(t.theme),ne()};window.addEventListener("message",e=>{const t=e.data;O!==null||e.source!==parent||!j(t)||t.p!==ae||t.type!=="host.hello"||e.ports[0]===void 0||Ee(e.ports[0],j(t.payload)?t.payload:{})});const ne=async()=>{const e=await S("artifact.read",{});if(!e.ok){v=e.message,V();return}const t=j(e.payload.content)?e.payload.content:{};if(t.type!=="app"||!j(t.spec)){v="This is not an app",V();return}const n=X;X=typeof e.payload.version=="number"?e.payload.version:0,D=t.spec,ke=t.readonly===!0,(B===null||!D.pages.some(o=>o.id===B))&&(B=D.pages[0]?.id??null),R!==null&&!U().some(o=>o.id===R)&&(R=null),v=null,Ke();const s=me();V(),(n!==X||s||ee.size===0)&&Me()},me=()=>{const e=new Map;for(const n of D?.pages??[])for(const s of n.components){const o=Ze(s);o!==null&&e.set(s.id,pe(o))}let t=!1;for(const n of[...ee.keys()])le.get(n)!==e.get(n)&&(ee.delete(n),le.delete(n),t=!0);return t},pe=e=>`${e.query}\0${JSON.stringify(e.params)}`,oe=()=>D?.pages.find(e=>e.id===B)??null,U=()=>oe()?.components??[],He=(e,t)=>{const n=Y[e];if(n!==void 0)return typeof n=="string"?t===void 0?n:void 0:t==="from"?n.from:t==="to"?n.to:void 0},Ie=(e,t,n)=>{const s={},o=n?.properties??{};for(const[l,a]of Object.entries(e??{})){const[p,i,r]=a.split(".");let f;if(p==="filter"&&i!==void 0)f=He(i,r);else if(p==="row"&&i!==void 0&&t.row!==void 0&&Object.hasOwn(t.row,i))f=t.row[i];else if(p==="form"&&i!==void 0&&t.form!==void 0){const k=fe[t.form];f=k!==void 0&&Object.hasOwn(k,i)?k[i]:void 0}else p==="url"&&i!==void 0&&(f=xe[i]);f!==void 0&&f!==""&&(s[l]=Lt(Object.hasOwn(o,l)?o[l]:void 0,f))}return s},Ke=()=>{for(const e of D?.pages??[])for(const t of e.components)if(!(t.type!=="filter"||Y[t.id]!==void 0))if(t.filter==="date-range"){const n=j(t.default)&&Number.isInteger(t.default.lastDays)?Math.min(3650,Math.max(1,t.default.lastDays)):30,s=new Date;Y[t.id]={from:et(new Date(s.getTime()-n*864e5)),to:et(s)}}else Y[t.id]=typeof t.default=="string"?t.default:""},tt=e=>D?.queries.find(t=>t.id===e)?.params,Ze=e=>e.type==="table"||e.type==="chart"||e.type==="kpi"?{query:e.data.query,params:Ie(e.data.params,{},tt(e.data.query))}:e.type==="filter"&&e.filter==="select"&&e.options?.kind==="query"?{query:e.options.query.query,params:Ie(e.options.query.params,{},tt(e.options.query.query))}:null,Me=(e,t=!1)=>{if(q||!b.has("data.read")||D===null||Z&&!ge)return;Ke(),Te+=1;const n=Te,s=new Map;for(const o of U()){const l=Ze(o);if(l===null||e!==void 0&&l.query!==e||t&&ee.has(o.id))continue;const a=pe(l);let p=s.get(a);p===void 0&&(p=S("data.query",{query:l.query,params:l.params}).then(i=>{if(!i.ok)return{state:"error",message:i.message};const r=Array.isArray(i.payload.columns)?i.payload.columns:[],f=Array.isArray(i.payload.rows)?i.payload.rows.filter(Array.isArray):[];return{state:"rows",rows:{columns:r,rows:f,sample:i.payload.sample===!0,hasMore:i.payload.hasMore===!0,truncated:i.payload.truncated===!0}}}),s.set(a,p)),ee.has(o.id)||(ee.set(o.id,{state:"loading"}),le.set(o.id,a)),qe.set(o.id,n),p.then(i=>{!q&&qe.get(o.id)===n&&(ee.set(o.id,i),le.set(o.id,a),Fe(o.id))})}e===void 0&&qt()},qt=()=>{const e=new Map;for(const t of U()){const n=Ze(t),s=n===null?void 0:D?.queries.find(o=>o.id===n.query);s?.refresh?.mode==="every"&&e.set(s.id,Math.max(15,s.refresh.seconds))}for(const[t,n]of[...E]){const[s,o]=t.split("\0");e.get(s)!==Number(o)&&(clearInterval(n),E.delete(t))}for(const[t,n]of e){const s=`${t}\0${n}`;E.has(s)||E.set(s,setInterval(()=>{document.visibilityState==="visible"&&Me(t)},n*1e3))}},Dt=async(e,t,n)=>{if(x||W!=="preview"||!b.has("data.write"))return;const s=U().find(i=>i.id===e)?.type!=="button",o=i=>{s?(he.set(e,i),Fe(e)):ot(`${T(t.label,60)}: ${i}`)};o("Waiting for you in studio…");const l=await S("data.action",{action:t.action,params:Ie(t.params,n,D?.actions.find(i=>i.id===t.action)?.params)}),a=l.ok?String(l.payload.state):"refused",p=l.ok?T(l.payload.reason,200):l.message;o(a==="succeeded"?`Done${p!==""?`: ${p}`:""}`:a==="cancelled"?"Not run":a==="unknown"?`Not known whether it ran: ${p}`:`Not run: ${p}`)},We=(e,t,n,s="wk-btn wk-btn--sm")=>{if(x)return d("span","wk-muted","Open to make changes");const o=d("button",s,T(t.label,60));return o.type="button",o.setAttribute("data-action",t.action),Z||W!=="preview"||!b.has("data.write")?(o.setAttribute("aria-disabled","true"),o.title=Z?"":W==="edit"?"Actions run in Preview":"This app may not ask to run actions here"):o.addEventListener("click",l=>{l.stopPropagation(),Dt(e,t,n)}),o},Xe=new Map;let J=null,Ye=null;const Ue=new Map,nt=(e,t)=>{Ct(e,t),Rt(e,t)},Rt=(e,t)=>{if(!z())return;const n=(s,o)=>{s!==null&&(s.setAttribute("data-inline",o),s.classList.add("wk-editable"),s.setAttribute("title","Double-click to edit"))};e.type==="text"&&n(t.querySelector(".wk-text"),"text"),e.type==="button"&&n(t.querySelector("button[data-action]"),"label"),e.type==="link"&&n(t.querySelector(".wk-link"),"label"),e.type==="filter"&&n(t.querySelector(".wk-filter-label"),"label")},Ct=(e,t)=>{t.replaceChildren();const n=ee.get(e.id);if(e.type==="table"||e.type==="chart"||e.type==="kpi"){if(Z&&!ge){t.append(d("div",`wk-skeleton wk-skeleton--${e.type}`));return}if(!b.has("data.read")){t.append(d("p","wk-muted","Live rows are not shown here"));return}if(n===void 0||n.state==="loading"){t.append(d("p","wk-muted","Loading…"));return}if(n.state==="error"){t.append(d("p","wk-error",`${"data"in e?e.data.query:""}: ${n.message}`));return}}const o=n?.state==="rows"?n.rows:null;switch(e.type){case"kpi":{const l=i=>i===void 0?-1:o.columns.findIndex(r=>r.name===i),a=o.rows[0];t.append(d("div","wk-kpi-value",a===void 0?"—":ue(a[l(e.value)],e.format,Q)));const p=d("div","wk-kpi-caption");if(a!==void 0&&e.delta!==void 0&&l(e.delta)>=0){const i=a[l(e.delta)],r=typeof i=="number"&&i<0||typeof i=="string"&&i.trim().startsWith("-");p.append(d("span",r?"wk-delta wk-delta--down":"wk-delta wk-delta--up",`${r?"▼":"▲"} ${ue(i,void 0,Q).replace(/^\s*-/u,"")}`)),p.append(document.createTextNode(" "))}e.caption!==void 0&&p.append(document.createTextNode(T(e.caption,120))),t.append(p);return}case"chart":bt(t,e,o,Q),(o.truncated||o.rows.length>Je)&&t.append(d("p","wk-muted",o.truncated?"Only part of the source’s rows: the answer was cut at the app’s limit":`The first ${Je} of ${o.rows.length} rows`));return;case"table":{Tt(e,t,o);return}case"text":t.append(d(e.style==="heading"?"h2":"p",`wk-text wk-text--${e.style??"body"}`,e.text.slice(0,4e3)));return;case"filter":{It(e,t);return}case"form":{Ft(e,t);return}case"button":t.append(We(e.id,e.action,{},"wk-btn"));return;case"image":{if(!St.test(e.src)){t.append(d("p","wk-muted","This image is not one the app can show"));return}const l=d("img","wk-image");l.alt=T(e.alt,300),l.src=e.src,t.append(l);return}case"link":{const l=d("button","wk-link",T(e.label,120));if(l.type="button",e.to.kind==="page"){const a=e.to;l.addEventListener("click",()=>{if(W==="preview"){v=null;for(const[p,i]of Object.entries(Ie(a.params,{})))xe[p]=String(i);D?.pages.some(p=>p.id===a.page)&&(B=a.page,R=null,V(),Me())}})}else{const a=e.to.href;l.title=a.slice(0,300),l.addEventListener("click",async()=>{if(W!=="preview")return;const p=await S("link.open",{href:a});p.ok||ot(`${T(e.label,60)} not opened: ${p.message}`)})}t.append(l);return}}},Tt=(e,t,n)=>{const s=M=>n.columns.findIndex($=>$.name===M),o=(e.columns??n.columns.map(M=>({column:M.name}))).filter(M=>s(M.column)>=0),l=Math.min(500,Math.max(5,e.pageSize??10)),a=Math.max(1,Math.ceil(n.rows.length/l)),p=Math.min(te.get(e.id)??0,a-1),i=d("table","wk-table"),r=d("tr");for(const M of o)r.append(d("th",void 0,T(M.label??M.column,80)));(e.rowActions??[]).length>0&&r.append(d("th","wk-th-actions","")),i.append(d("thead")),i.tHead.append(r);const f=d("tbody");for(const M of n.rows.slice(p*l,p*l+l)){const $=d("tr"),K=Oe();n.columns.forEach((ie,Ne)=>{K[ie.name]=M[Ne]??null});for(const ie of o){const Ne=M[s(ie.column)];$.append(d("td",typeof Ne=="number"?"wk-num":void 0,ue(Ne,ie.format,Q)))}if((e.rowActions??[]).length>0){const ie=d("td","wk-td-actions");for(const Ne of(e.rowActions??[]).slice(0,4))ie.append(We(e.id,Ne,{row:K}));$.append(ie)}f.append($)}i.append(f),t.append(i),n.rows.length===0&&t.append(d("p","wk-muted","No rows"));const k=d("div","wk-table-foot");if(a>1){const M=d("button","wk-btn wk-btn--sm","Previous"),$=d("button","wk-btn wk-btn--sm","Next");M.type="button",$.type="button",M.disabled=p===0,$.disabled=p>=a-1,M.addEventListener("click",()=>{te.set(e.id,p-1),Fe(e.id)}),$.addEventListener("click",()=>{te.set(e.id,p+1),Fe(e.id)}),k.append(M,d("span","wk-muted",`${p+1} of ${a}`),$)}n.truncated?k.append(d("span","wk-muted",`Only the first ${n.rows.length} rows: the answer was cut at the app’s limit`)):n.hasMore&&k.append(d("span","wk-muted","First page of the source’s rows"));const F=he.get(e.id);F!==void 0&&k.append(d("span","wk-status",F)),k.childNodes.length>0&&t.append(k)},It=(e,t)=>{const n=d("label","wk-filter");n.append(d("span","wk-filter-label",T(e.label??(e.filter==="search"?"Search":e.filter==="date-range"?"Dates":"Filter"),60)));const s=()=>{Me()};if(e.filter==="search"){const o=d("input","wk-input");o.type="search",o.value=typeof Y[e.id]=="string"?Y[e.id]:"";let l=null;o.addEventListener("input",()=>{Y[e.id]=o.value.slice(0,200),l!==null&&clearTimeout(l),l=setTimeout(s,300)}),n.append(o)}else if(e.filter==="select"){const o=d("select","wk-input"),l=[{value:"",label:"All"}];if(e.options?.kind==="values")for(const a of e.options.values.slice(0,200))l.push({value:T(a.value,200),label:T(a.label??a.value,200)});if(e.options?.kind==="query"){const a=ee.get(e.id);if(a?.state==="rows"){const p=a.rows.columns.findIndex(r=>r.name===e.options.value),i=a.rows.columns.findIndex(r=>r.name===(e.options.label??""));for(const r of a.rows.rows.slice(0,200))p>=0&&l.push({value:ue(r[p],void 0,Q),label:ue(r[i>=0?i:p],void 0,Q)})}}for(const a of l){const p=d("option",void 0,a.label);p.value=a.value,o.append(p)}o.value=typeof Y[e.id]=="string"?Y[e.id]:"",o.addEventListener("change",()=>{Y[e.id]=o.value,s()}),n.append(o)}else{const o=Y[e.id]??{from:"",to:""},l=d("input","wk-input wk-input--date"),a=d("input","wk-input wk-input--date");l.type="date",a.type="date",l.value=o.from,a.value=o.to;const p=()=>{Y[e.id]={from:l.value,to:a.value},s()};l.addEventListener("change",p),a.addEventListener("change",p),n.append(l,d("span","wk-muted","–"),a)}t.append(n)},Ft=(e,t)=>{var p;const n=fe[p=e.id]??(fe[p]=Oe()),s=D?.actions.find(i=>i.id===e.submit.action)?.params?.properties??{};for(const i of e.fields){if(Object.hasOwn(n,i.name))continue;const r=e.submit.params===void 0?void 0:Object.entries(e.submit.params).find(([,k])=>k===`form.${i.name}`)?.[0],f=r!==void 0&&Object.hasOwn(s,r)?s[r].default:void 0;i.input==="checkbox"?n[i.name]=f===!0:f!==void 0&&(n[i.name]=String(f))}const o=d("div","wk-form");for(const i of e.fields.slice(0,30)){const r=d("label","wk-field");r.append(d("span","wk-filter-label",T(i.label??i.name,80)));let f;if(i.input==="textarea")f=d("textarea","wk-input");else if(i.input==="select"){f=d("select","wk-input");for(const k of i.options??[]){const F=d("option",void 0,T(k.label??k.value,200));F.value=T(k.value,200),f.append(F)}}else f=d("input","wk-input"),f.type=i.input==="number"?"number":i.input==="date"?"date":i.input==="checkbox"?"checkbox":"text";f instanceof HTMLInputElement&&f.type==="checkbox"?(f.checked=n[i.name]===!0,f.addEventListener("change",()=>{n[i.name]=f.checked})):(f.value=typeof n[i.name]=="string"?n[i.name]:"",f.addEventListener("input",()=>{n[i.name]=f.value.slice(0,1e3)})),f.disabled=W!=="preview",r.append(f),o.append(r)}const l=d("div","wk-form-foot");l.append(We(e.id,e.submit,{form:e.id},"wk-btn"));const a=he.get(e.id);l.append(d("span","wk-muted",a??(x?"":"Studio asks before it writes"))),o.append(l),t.append(o)};let we=null;const ot=e=>{v=e,we!==null?(we.textContent=e,we.hidden=!1):V()},Fe=e=>{if(A!==null&&A.id===e)return;const t=U().find(s=>s.id===e),n=Ue.get(e);t!==void 0&&n!==void 0&&nt(t,n)},z=()=>W==="edit"&&ve==="full"&&!ke&&b.has("artifact.write");let ye=null;const st=()=>{const e=ye.getBoundingClientRect(),t=re();return{col:(e.width+Ge[t])/12,row:Mt[t]+Ge[t],left:e.left,top:e.top}},zt=(e,t)=>{const n=st();return{x:Math.min(11,Math.max(0,Math.floor((e-n.left)/n.col))),y:Math.min(999,Math.max(0,Math.floor((t-n.top)/n.row)))}},se=async(e,t={})=>{const n=await S("spec.edit",{base:X,ops:e});if(!n.ok)return v=n.code==="head_moved"?"The app changed meanwhile: showing the newest version":`Not changed: ${n.message}`,n.code==="head_moved"?await ne():V(),null;j(n.payload.spec)&&(D=n.payload.spec),v=null,Ke(),me();const s=Array.isArray(n.payload.added)?n.payload.added.filter(o=>typeof o=="string"):[];return s[0]!==void 0&&Se(s[0]),V({keepProps:t.typed===!0&&s.length===0}),Me(void 0,!0),s},Se=e=>{const t=R;R=e,e!==null&&b.has("selection.chip")?N("selection.set",{anchors:[{kind:"element",id:e}]}):e===null&&t!==null&&b.has("selection.chip")&&N("selection.set",{anchors:[]})},it=(e,t,n,s)=>{if(!z()||e.button!==0)return;e.preventDefault(),e.stopPropagation(),(s.closest(".wk-cell")??s).focus({preventScroll:!0});const o=Xe.get(t.id),l=st(),a={x:e.clientX,y:e.clientY};let p={...t.box},i=!1;const r=n==="move"?e.target?.closest?.("[data-inline]"):null;s.setPointerCapture(e.pointerId),s.classList.add("is-dragging");const f=F=>{const M=Math.round((F.clientX-a.x)/l.col),$=Math.round((F.clientY-a.y)/l.row);M===0&&$===0&&!i||(i=!0,p=n==="move"?{...t.box,x:Math.min(12-t.box.w,Math.max(0,t.box.x+M)),y:Math.max(0,t.box.y+$)}:{...t.box,w:Math.min(12-t.box.x,Math.max(1,t.box.w+M)),h:Math.min(50,Math.max(1,t.box.h+$))},w.place(o,p))},k=()=>{s.removeEventListener("pointermove",f),s.removeEventListener("pointerup",k),s.removeEventListener("pointercancel",k),s.classList.remove("is-dragging");const F=n==="move"?p.x!==t.box.x||p.y!==t.box.y:p.w!==t.box.w||p.h!==t.box.h;if(!i||!F){w.place(o,t.box),i||(Se(t.id),dt(),ut(t.id,r));return}se([n==="move"?{op:"component-move",id:t.id,x:p.x,y:p.y}:{op:"component-resize",id:t.id,w:p.w,h:p.h}])};s.addEventListener("pointermove",f),s.addEventListener("pointerup",k),s.addEventListener("pointercancel",k)},at=()=>U().reduce((e,t)=>Math.max(e,t.box.y+t.box.h),0),_t=(e,t,n)=>{if(!z()||e.button!==0||ye===null||B===null)return;e.preventDefault(),n.focus({preventScroll:!0});const s=Qe[t],o=d("div","wk-drop wk-c9999");o.setAttribute("data-testid","apps-drop-target");let l=null;n.setPointerCapture(e.pointerId);const a=i=>{const r=ye.getBoundingClientRect();if(i.clientX<r.left||i.clientX>r.right||i.clientY<r.top){o.remove(),l=null;return}l=zt(i.clientX,i.clientY),l.x=Math.min(l.x,12-s.w),w.place(9999,{x:l.x,y:l.y,w:s.w,h:s.h}),o.parentNode===null&&ye.append(o)},p=i=>{if(n.removeEventListener("pointermove",a),n.removeEventListener("pointerup",p),n.removeEventListener("pointercancel",p),o.remove(),Math.abs(i.clientX-e.clientX)+Math.abs(i.clientY-e.clientY)>6&&l===null)return;const f=l??{x:0,y:at()};se([{op:"component-add",page:B,type:t,box:{x:f.x,y:f.y,w:Math.min(s.w,12-f.x),h:s.h}}])};n.addEventListener("pointermove",a),n.addEventListener("pointerup",p),n.addEventListener("pointercancel",p)},Ve=(e,t,n=!1,s)=>{let o=e.value,l=null;const a=()=>{if(e.value===o)return;o=e.value;const i=t();if(i===void 0)return;const r=Promise.resolve(i);l=r,r.finally(()=>{l===r&&(l=null)})};let p=!1;e.addEventListener("compositionstart",()=>{p=!0}),e.addEventListener("compositionend",()=>{p=!1,a()}),e.addEventListener("input",i=>{!p&&i.isComposing!==!0&&a()}),s!==void 0&&e.addEventListener("blur",()=>{const i=()=>{if(document.activeElement===e)return;const r=s();e.value!==r&&(e.value=r,o=r)};l!==null?l.then(i,i):i()}),e.addEventListener("change",()=>{p||a()}),e.addEventListener("keydown",i=>{const r=i;p||r.isComposing||r.keyCode===229||r.key==="Enter"&&(!n||r.metaKey||r.ctrlKey)&&(r.preventDefault(),a())})},De=(e,t)=>{const n=d("label","wk-prop");return n.append(d("span","wk-prop-label",e),t),n},Ae=(e,t,n,s,o,l=!1)=>{const a=d(l?"textarea":"input","wk-input");return a.value=s??"",a.maxLength=o,a.setAttribute("data-prop",n),Ve(a,()=>se([{op:"component-set",id:e.id,prop:n,value:a.value}],{typed:!0}),l,()=>{const p=U().find(r=>r.id===e.id),i=n==="label"&&p?.type==="button"?p.action?.label:p?.[n];return typeof i=="string"?i:""}),De(t,a)},Re=(e,t,n,s,o,l="set")=>{const a=d("select","wk-input");for(const p of o){const i=d("option",void 0,p);i.value=p,a.append(i)}return a.value=s,a.setAttribute("data-prop",n),a.addEventListener("change",()=>{se([l==="bind"?{op:"bind",id:e.id,query:a.value}:{op:"component-set",id:e.id,prop:n,value:a.value}])}),De(t,a)},rt=(e,t,n,s)=>{const o=d("input","wk-check");return o.type="checkbox",o.checked=s,o.setAttribute("data-prop",n),o.addEventListener("change",()=>{se([{op:"component-set",id:e.id,prop:n,value:o.checked}])}),De(t,o)},ze=(e,t,n,s,o)=>{const l=d("input","wk-input wk-input--num");l.type="number",l.min=String(s),l.max=String(o),l.value=String(n==="x"?e.box.x+1:n==="y"?e.box.y+1:e.box[n]),l.setAttribute("data-prop",`box-${n}`);const a=()=>U().find(i=>i.id===e.id)?.box??e.box,p=i=>String(n==="x"?i.x+1:n==="y"?i.y+1:i[n]);return Ve(l,()=>{if(l.value.trim()==="")return;const i=Math.round(Number(l.value));if(!Number.isFinite(i))return;const r=a();if(n==="x"||n==="y"){const F=n==="x"?Math.min(12-r.w,Math.max(0,i-1)):r.x,M=n==="y"?Math.max(0,i-1):r.y;return se([{op:"component-move",id:e.id,x:F,y:M}],{typed:!0})}const f=n==="w"?Math.min(12-r.x,Math.max(1,i)):r.w,k=n==="h"?Math.min(50,Math.max(1,i)):r.h;return se([{op:"component-resize",id:e.id,w:f,h:k}],{typed:!0})},!1,()=>p(a())),De(t,l)},lt=e=>{const t=d("aside","wk-props");t.setAttribute("aria-label","Properties"),t.setAttribute("data-testid","apps-properties"),t.append(d("h3","wk-props-title","Properties")),t.append(d("p","wk-muted",`${e.type==="chart"?`${e.chart} chart`:e.type} · ${e.id}`)),t.append(Ae(e,"Title","title",e.title,120));const n=(D?.queries??[]).map(a=>a.id),s=a=>D?.queries.find(p=>p.id===a)?.output.map(p=>p.name)??[];if((e.type==="table"||e.type==="chart"||e.type==="kpi")&&t.append(Re(e,"Data","query",e.data.query,n,"bind")),e.type==="table"){const a=d("input","wk-input wk-input--num");a.type="number",a.min="5",a.max="500",a.value=String(e.pageSize??10),a.setAttribute("data-prop","pageSize"),Ve(a,()=>{if(a.value.trim()==="")return;const p=Math.round(Number(a.value));return Number.isFinite(p)?se([{op:"component-set",id:e.id,prop:"pageSize",value:Math.min(500,Math.max(5,p))}],{typed:!0}):void 0},!1,()=>String(U().find(p=>p.id===e.id)?.pageSize??10)),t.append(De("Rows per page",a))}e.type==="chart"&&(t.append(Re(e,"Chart","chart",e.chart,["bar","line","area","pie"])),t.append(Re(e,"Category","x",e.x,s(e.data.query))),(e.chart==="bar"||e.chart==="area")&&t.append(rt(e,"Stacked","stacked",e.stacked===!0))),e.type==="kpi"&&(t.append(Re(e,"Figure","value",e.value,s(e.data.query))),t.append(Ae(e,"Caption","caption",e.caption,120))),e.type==="text"&&(t.append(Ae(e,"Text","text",e.text,4e3,!0)),t.append(Re(e,"Style","style",e.style??"body",["heading","body","caption"]))),e.type==="filter"&&t.append(Ae(e,"Label","label",e.label,120)),e.type==="button"&&t.append(Ae(e,"Label","label",e.action.label,60)),e.type==="link"&&t.append(Ae(e,"Label","label",e.label,120)),e.type==="image"&&t.append(Ae(e,"Description","alt",e.alt,300));const o=d("div","wk-prop-box");o.append(ze(e,"Column","x",1,12),ze(e,"Row","y",1,1e3),ze(e,"Width","w",1,12),ze(e,"Height","h",1,50)),t.append(o),t.append(rt(e,"Hide on phones","hideOnPhone",e.hideOnPhone===!0));const l=d("button","wk-btn wk-btn--danger","Delete this component");return l.type="button",l.setAttribute("data-testid","apps-remove"),l.addEventListener("click",()=>{const a=e.id;R=null,se([{op:"component-remove",id:a}])}),t.append(l),t},pt=()=>{const e=d("aside","wk-props wk-props--empty");return e.setAttribute("aria-label","Properties"),e.setAttribute("data-testid","apps-properties-empty"),e.append(d("h3","wk-props-title","Properties")),e.append(d("p","wk-muted","Select a component to change it here. Double-click its words to edit them in place.")),e},Bt=()=>{const e=d("aside","wk-palette");e.setAttribute("aria-label","Components"),e.append(d("h3","wk-props-title","Components")),e.append(d("p","wk-muted","Drag onto the canvas, or click to add"));const t=d("div","wk-tiles");for(const n of Nt){const s=d("button","wk-tile",n.label);s.type="button",s.setAttribute("data-palette",n.type),s.addEventListener("pointerdown",o=>_t(o,n.type,s)),s.addEventListener("click",o=>{if(o.detail!==0||!z()||B===null)return;const l=Qe[n.type];se([{op:"component-add",page:B,type:n.type,box:{x:0,y:at(),w:l.w,h:l.h}}])}),t.append(s)}return e.append(t),e},V=(e={})=>{const t=A;let n=!1;if(t!==null){const s=z()?U().find(o=>o.id===t.id):void 0;if(n=s!==void 0&&ct(s,t.prop)===t.before,n&&t.composing()){t.defer();return}n?t.hold():t.drop()}Ht(e),n&&t!==null&&A===t&&t.place()},Ht=e=>{const t=document.activeElement instanceof HTMLElement&&m.contains(document.activeElement)?document.activeElement.getAttribute("data-prop"):null;if(Ue.clear(),Xe.clear(),w.reset(),H(void 0),m.setAttribute("data-mode",z()?"edit":"preview"),m.setAttribute("data-tile",Z?"true":"false"),m.setAttribute("data-surface",ve),D===null){m.replaceChildren(d("p","wk-empty",v??"Loading the app…")),J=null;return}const n=[];z()&&n.push(Bt());const s=d("main","wk-main"),o=d("nav","wk-pages");o.setAttribute("aria-label","Pages");for(const r of D.pages){const f=d("button",r.id===B?"wk-page is-on":"wk-page",T(r.title,80));f.type="button",f.setAttribute("aria-current",r.id===B?"page":"false"),f.addEventListener("click",()=>{B!==r.id&&(B=r.id,Se(null),V(),Me())}),o.append(f)}s.append(o),we=d("p","wk-notice",v??""),we.setAttribute("data-testid","apps-notice"),we.setAttribute("aria-live","polite"),we.hidden=v===null,s.append(we),ke&&W==="edit"&&s.append(d("p","wk-notice","A chat turn is changing this app: it is read-only until the turn ends")),ye=d("div","wk-grid");const l=U(),a=[...l].sort((r,f)=>r.box.y-f.box.y||r.box.x-f.box.x);l.forEach((r,f)=>{Xe.set(r.id,f),w.place(f,r.box),w.phoneOrder(f,a.indexOf(r),r.hideOnPhone===!0),r.type==="chart"&&r.series.slice(0,12).forEach((M,$)=>w.seriesColour(f,$,M.color));const k=d("section",`wk-cell wk-cell--${r.type} wk-c${f}${r.id===R&&z()?" is-selected":""}`);if(k.setAttribute("data-component",r.id),r.title!==void 0&&r.type!=="text"){const M=d("h3","wk-cell-title",T(r.title,120));z()&&(M.setAttribute("data-inline","title"),M.classList.add("wk-editable"),M.setAttribute("title","Double-click to edit")),k.append(M)}const F=d("div","wk-cell-body");if(Ue.set(r.id,F),nt(r,F),k.append(F),z()){k.classList.add("is-editable"),k.tabIndex=0,k.setAttribute("aria-label",`${r.type==="chart"?`${r.chart} chart`:r.type} ${T(r.title??r.id,80)}: Enter to select`),k.append(d("span","wk-tag",`${r.type==="chart"?`${r.chart} chart`:r.type}${"data"in r&&r.data!==void 0?` · ${r.data.query}`:""}`));const M=d("span","wk-handle");M.setAttribute("aria-hidden","true"),M.addEventListener("pointerdown",$=>it($,r,"resize",M)),k.append(M),k.addEventListener("pointerdown",$=>{$.target.closest("input, select, textarea, button, .wk-handle")===null&&it($,r,"move",k)}),k.addEventListener("pointerup",$=>{const K=$.target.closest?.("button[data-inline]");K!==null&&$.button===0&&ut(r.id,K)})}ye.append(k)}),l.length===0&&ye.append(d("p","wk-empty",z()?"Drag a component here from the palette":"This page is empty")),s.append(ye),n.push(s);const p=z()&&R!==null?l.find(r=>r.id===R):void 0;if(e.keepProps===!0&&p!==void 0&&J!==null&&Ye===p.id&&J.parentNode===m){for(const r of[...m.childNodes])r!==J&&r.remove();for(const r of n)m.insertBefore(r,J);return}J=ce?null:p!==void 0?lt(p):z()?pt():null,Ye=p?.id??null,m.replaceChildren(...n,...J!==null?[J]:[]),t!==null&&[...m.querySelectorAll("[data-prop]")].find(r=>r.getAttribute("data-prop")===t)?.focus({preventScroll:!0})},dt=()=>{for(const n of m.querySelectorAll("[data-component]"))n.classList.toggle("is-selected",z()&&n.getAttribute("data-component")===R);const e=z()&&R!==null?U().find(n=>n.id===R):void 0,t=ce?null:e!==void 0?lt(e):z()?pt():null;J!==null&&t!==null&&J.parentNode===m?J.replaceWith(t):(J?.remove(),t!==null&&m.append(t)),J=t,Ye=e?.id??null},ut=(e,t)=>{const n=t?.getAttribute("data-inline")??null,s=Date.now();n!==null&&t!==null&&L!==null&&L.id===e&&L.prop===n&&s-L.at<At?(L=null,t.isConnected&&ft(e,t)):L=n!==null?{id:e,prop:n,at:s}:null},ct=(e,t)=>{if(t==="title")return e.title??"";if(t==="text"&&e.type==="text")return e.text;if(t==="label"){if(e.type==="button")return e.action.label;if(e.type==="link")return e.label;if(e.type==="filter")return e.label??""}return""},ft=(e,t)=>{const n=U().find($=>$.id===e),s=t.getAttribute("data-inline");if(n===void 0||s===null||!z()||A!==null)return;const o=ct(n,s),l=s==="text",a=l?d("textarea","wk-inline-input wk-inline-input--multi"):d("input","wk-inline-input");a.value=o,a.maxLength=l?4e3:n.type==="button"?60:120,a.setAttribute("data-testid","apps-inline"),a.setAttribute("aria-label",`Edit the ${s==="text"?"text":s}`),t.replaceWith(a),a.closest("[data-component]")?.classList.add("is-inline"),a.focus(),a.select();let p=!1,i=!1,r=!1,f=!1,k=[null,null,"none"];const F={id:e,prop:s,before:o,drop:()=>{p=!0,r=!1,A===F&&(A=null)},hold:()=>{r=!0,k=[a.selectionStart,a.selectionEnd,a.selectionDirection??"none"]},composing:()=>i,defer:()=>{f=!0},place:()=>{const $=[...m.querySelectorAll("[data-component]")].find(ie=>ie.getAttribute("data-component")===e),K=$===void 0?void 0:[...$.querySelectorAll("[data-inline]")].find(ie=>ie.getAttribute("data-inline")===s);if(K===void 0){F.drop();return}K.replaceWith(a),$.classList.add("is-inline"),a.focus(),k[0]!==null&&k[1]!==null&&a.setSelectionRange(k[0],k[1],k[2]),r=!1}};A=F;const M=$=>{p||(F.drop(),$&&a.value!==o?se([{op:"component-set",id:e,prop:s,value:a.value}]):V())};a.addEventListener("compositionstart",()=>{i=!0}),a.addEventListener("compositionend",()=>{i=!1,f&&(f=!1,p||V())}),a.addEventListener("keydown",$=>{const K=$;if(!(i||K.isComposing||K.keyCode===229)){if(K.key==="Escape"){K.preventDefault(),K.stopPropagation(),M(!1);return}K.key==="Enter"&&!(l&&K.shiftKey)&&(K.preventDefault(),K.stopPropagation(),M(!0))}}),a.addEventListener("blur",()=>{r||(a.isConnected?M(!0):F.drop())})};m.addEventListener("dblclick",e=>{if(!z()||A!==null)return;const n=((typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):null)??e.target)?.closest("[data-inline]"),s=n?.closest("[data-component]");n==null||s===null||s===void 0||(e.preventDefault(),ft(s.getAttribute("data-component"),n))});function ht(e){if(O===null||D===null)return;const t=e.target?.closest?.(".wk-cell.is-editable");if(t!==null&&(e.key==="Enter"||e.key===" ")&&e.target===t){e.preventDefault();const o=t.getAttribute("data-component");o!==null&&(Se(o),dt(),m.querySelector(".wk-props input, .wk-props select")?.focus());return}const n=e.target?.closest("input, textarea, select")!=null;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="z"&&!n&&z()){e.preventDefault(),S("app.history",{move:e.shiftKey?"redo":"undo",base:X}).then(o=>{o.ok||(v=o.message,o.code==="head_moved"?ne():V())});return}if((e.key==="Delete"||e.key==="Backspace")&&!n&&z()&&R!==null){e.preventDefault();const o=R;Se(null),se([{op:"component-remove",id:o}]);return}e.key==="Escape"&&R!==null&&!n&&(Se(null),V())}document.addEventListener("keydown",ht),m.append(d("p","wk-empty","Loading the app…")),mt(u.editor,u.surfaces)}Pt({editor:"wicked-apps",surfaces:{card:{interactive:!0,aspect:"16:9",actions:[]},full:{}}})})();
|
|
181
|
+
<script>var nn=Object.defineProperty;var on=(de,we,qe)=>we in de?nn(de,we,{enumerable:!0,configurable:!0,writable:!0,value:qe}):de[we]=qe;var Te=(de,we,qe)=>on(de,typeof we!="symbol"?we+"":we,qe);(function(){"use strict";const de="wicked.editor";function qe(c,u,m){return{editor:c,version:u,protocol:[1,2],surfaces:m}}function $t(c,u){const m=document.querySelector('meta[name="wicked-editor-version"]')?.getAttribute("content")??"0.0.0";parent.postMessage({p:de,v:1,type:"plugin.ready",payload:qe(c,m,u)},"*")}const Lt=/^[A-Z]{3}$/u;function ye(c,u,m){if(c==null)return"";if(typeof c=="boolean")return c?"yes":"no";const y=typeof u?.decimals=="number"&&Number.isInteger(u.decimals)?Math.min(10,Math.max(0,u.decimals)):void 0,h=typeof c=="number"?c:typeof c=="string"&&c.trim()!==""&&Number.isFinite(Number(c))?Number(c):null;try{switch(u?.kind){case"currency":if(h===null||!Lt.test(u.currency))break;return new Intl.NumberFormat(m,{style:"currency",currency:u.currency,...y!==void 0?{minimumFractionDigits:y,maximumFractionDigits:y}:{}}).format(h);case"percent":if(h===null)break;return new Intl.NumberFormat(m,{style:"percent",maximumFractionDigits:y??1}).format(h);case"number":if(h===null)break;return new Intl.NumberFormat(m,y!==void 0?{minimumFractionDigits:y,maximumFractionDigits:y}:{}).format(h);case"date":case"datetime":{const N=new Date(typeof c=="number"?c:String(c));if(Number.isNaN(N.getTime()))break;return new Intl.DateTimeFormat(m,u.kind==="date"?{dateStyle:"medium",timeZone:"UTC"}:{dateStyle:"medium",timeStyle:"short"}).format(N)}case"duration":{if(h===null)break;const N=Math.abs(Math.round(h)),k=Math.floor(N/86400),M=Math.floor(N%86400/3600),Y=Math.floor(N%3600/60);return k>0?`${k}d ${M}h`:M>0?`${M}h ${Y}m`:`${Y}m`}default:break}}catch{}return typeof c=="number"?Number.isInteger(c)?String(c):new Intl.NumberFormat(m,{maximumFractionDigits:6}).format(c):String(c)}function F(c,u=200){return typeof c=="string"?c.replace(/[\u0000-\u001f\u007f]+/gu," ").slice(0,u):""}const St="http://www.w3.org/2000/svg";function ne(c,u,m){const y=document.createElementNS(St,c);for(const[h,N]of Object.entries(u))y.setAttribute(h,String(N));return m!==void 0&&y.setAttribute("class",m),y}function He(c,u,m,y,h="start"){const N=ne("text",{x:c,y:u,"text-anchor":h},y);return N.textContent=m,N}function xe(c){return typeof c=="number"?Number.isFinite(c)?c:0:typeof c=="string"&&c.trim()!==""&&Number.isFinite(Number(c))?Number(c):0}const W=c=>Math.round(c*10)/10;function Ve(c,u){const m=document.createElement("ul");m.className="wk-legend",u.forEach((y,h)=>{const N=document.createElement("li"),k=document.createElement("span");k.className=`wk-swatch wk-series-${h%12}`,N.append(k,document.createTextNode(y)),m.append(N)}),c.append(m)}function Nt(c,u,m,y){const h=g=>m.columns.findIndex(x=>x.name===g),N=h(u.x),k=u.series.slice(0,u.chart==="pie"?1:12).map(g=>({label:F(g.label??g.column,60),i:h(g.column)})).filter(g=>g.i>=0),M=m.rows.slice(0,500);if(N<0||k.length===0||M.length===0){const g=document.createElement("p");g.className="wk-empty",g.textContent=M.length===0?"No rows":"This chart’s columns are not in its query’s rows",c.append(g);return}const Y=M.map(g=>ye(g[N],void 0,y));if(u.chart==="bar"){const g=u.stacked===!0&&k.length>1,x=M.map(_=>k.map(P=>xe(_[P.i])));let L=0,E=0;for(const _ of x)if(g)E=Math.max(E,_.filter(P=>P>0).reduce((P,K)=>P+K,0)),L=Math.min(L,_.filter(P=>P<0).reduce((P,K)=>P+K,0));else for(const P of _)E=Math.max(E,P),L=Math.min(L,P);E===L&&(E=L+1);const O=130,S=k.length>1?250:220,$=_=>O+(_-L)/(E-L)*S,T=$(0),D=g||k.length===1?26:Math.max(26,k.length*10+10),A=ne("svg",{viewBox:`0 0 400 ${M.length*D+4}`,role:"img","aria-label":F(u.title??"bar chart",120)},"wk-chart wk-chart--bar");L<0&&A.append(ne("line",{x1:W(T),x2:W(T),y1:0,y2:M.length*D+4},"wk-grid-line")),M.forEach((_,P)=>{const K=P*D+2;if(A.append(He(0,W(K+D/2+4),Y[P].slice(0,22),"wk-axis")),g){let Se=0,he=0;k.forEach((ce,me)=>{const oe=x[P][me],We=oe>=0?Se:he+oe,Q=oe>=0?Se+oe:he;oe>=0?Se+=oe:he+=oe,A.append(ne("rect",{x:W($(We)),y:K+4,width:W(Math.max(1,$(Q)-$(We))),height:D-10},`wk-series-${me%12}`))});return}const pe=(D-8)/k.length;k.forEach((Se,he)=>{const ce=x[P][he],me=Math.min($(ce),T),oe=Math.max(1,Math.abs($(ce)-T));A.append(ne("rect",{x:W(me),y:W(K+4+he*pe),width:W(oe),height:W(Math.max(2,pe-2)),rx:2},`wk-series-${he%12}`)),k.length===1&&A.append(He(W(ce<0?me-6:me+oe+6),W(K+D/2+4),ye(_[Se.i],void 0,y),"wk-value",ce<0?"end":"start"))})}),c.append(A),k.length>1&&Ve(c,k.map(_=>_.label));return}if(u.chart==="pie"){const g=k[0],x=M.reduce((O,S)=>O+Math.max(0,xe(S[g.i])),0)||1,L=ne("svg",{viewBox:"0 0 240 240",role:"img","aria-label":F(u.title??"pie chart",120)},"wk-chart wk-chart--pie");let E=-Math.PI/2;M.forEach((O,S)=>{const $=Math.max(0,xe(O[g.i]))/x,T=E+$*Math.PI*2,D=T-E>Math.PI?1:0,A=P=>`${W(120+100*Math.cos(P))} ${W(120+100*Math.sin(P))}`,_=$>=.9999?"M 120 20 A 100 100 0 1 1 119.9 20 Z":`M 120 120 L ${A(E)} A 100 100 0 ${D} 1 ${A(T)} Z`;L.append(ne("path",{d:_},`wk-series-${S%12}`)),E=T}),c.append(L),Ve(c,Y.slice(0,12));return}const Ee=600,ge=220,V=36,Me=24,ie=u.chart==="area"&&u.stacked===!0&&k.length>1,j=[],I=new Map;M.forEach((g,x)=>{if(j.push(x),!ie||x+1>=M.length)return;const L=new Map;k.forEach((E,O)=>{const S=xe(M[x][E.i]),$=xe(M[x+1][E.i]);if(S>0&&$<0||S<0&&$>0){const T=S/(S-$);L.set(T,[...L.get(T)??[],O])}});for(const E of[...L.keys()].sort((O,S)=>O-S))I.set(j.length,new Set(L.get(E))),j.push(x+E)});const Ae=(g,x)=>{if(I.get(x)?.has(g)===!0)return 0;const L=j[x],E=Math.floor(L),O=L-E,S=xe(M[E][k[g].i]);return O===0||E+1>=M.length?S:S+(xe(M[E+1][k[g].i])-S)*O},X=k.map(()=>[]),z=k.map(()=>[]);let G=0,fe=1;const be=g=>{g<G&&(G=g),g>fe&&(fe=g)};j.forEach((g,x)=>{let L=0,E=0;k.forEach((O,S)=>{const $=Ae(S,x);if(!ie){X[S][x]=[0,$],z[S][x]=[0,0],be($);return}const T=Math.max(0,$),D=Math.min(0,$);X[S][x]=[L,L+T],z[S][x]=[E+D,E],L+=T,E+=D,be(L),be(E)})});const De=fe,te=G,$e=g=>V+(M.length===1?0:g/(M.length-1)*(Ee-V-8)),Le=g=>ge-Me-(g-te)/(De-te||1)*(ge-Me-10),ae=ne("svg",{viewBox:`0 0 ${Ee} ${ge}`,role:"img","aria-label":F(u.title??`${u.chart} chart`,120)},`wk-chart wk-chart--${u.chart}`);for(let g=0;g<=3;g+=1){const x=te+(De-te)*g/3;ae.append(ne("line",{x1:V,x2:Ee-8,y1:W(Le(x)),y2:W(Le(x))},"wk-grid-line")),ae.append(He(V-6,W(Le(x)+4),ye(Math.round(x*10)/10,void 0,y),"wk-axis","end"))}const Fe=M.length<=4?M.map((g,x)=>x):[0,Math.floor((M.length-1)/3),Math.floor((M.length-1)*2/3),M.length-1];for(const g of Fe)ae.append(He(W($e(g)),ge-6,Y[g].slice(0,14),"wk-axis",g===0?"start":g===M.length-1?"end":"middle"));k.forEach((g,x)=>{const L=(D,A)=>`${W($e(j[D]))},${W(Le(A))}`;if(u.chart==="area"){const D=A=>{const _=j.map((K,pe)=>L(pe,A[pe][1])),P=j.map((K,pe)=>L(pe,A[pe][0])).reverse();return`M ${_.join(" L ")} L ${P.join(" L ")} Z`};ae.append(ne("path",{d:D(X[x])},`wk-area wk-series-${x}`)),ie&&z[x].some(([A,_])=>A!==_)&&ae.append(ne("path",{d:D(z[x])},`wk-area wk-area--neg wk-series-${x}`))}if(!ie){ae.append(ne("polyline",{points:j.map((D,A)=>L(A,Ae(x,A))).join(" "),fill:"none"},`wk-stroke wk-series-${x}`));return}const E=[];let O=null,S=0,$=[];const T=(D,A)=>D<0?L(A,z[x][A][0]):L(A,X[x][A][1]);j.forEach((D,A)=>{const _=Ae(x,A);if(I.get(A)?.has(x)===!0||_===0){O!==null&&O.push(T(S,A)),$.push(A);return}const P=_>0?1:-1;if(O===null)O=$.map(K=>T(P,K)),E.push(O),S=P;else if(P!==S){const K=$[$.length-1];O=K!==void 0?[T(P,K)]:[],E.push(O),S=P}O.push(T(P,A)),$=[]}),O===null&&$.length>1&&E.push($.map(D=>T(1,D)));for(const D of E)D.length>1&&ae.append(ne("polyline",{points:D.join(" "),fill:"none"},`wk-stroke wk-series-${x}`))}),c.append(ae),k.length>1&&Ve(c,k.map(g=>g.label))}const Pt=/^#[0-9a-fA-F]{6}$/u,it=/^(?::root|\.wk-c\d{1,4}(?: \.wk-[a-z]+)?)$/u,qt=/^(?:--[a-z0-9-]{1,40}|[a-z-]{1,40})$/u,Ot="(max-width: 639px)";function je(c){return typeof c=="string"&&Pt.test(c)?c.toLowerCase():null}function Oe(c,u,m,y){return Number.isInteger(c)?Math.min(m,Math.max(u,c)):y}function Dt(c){return typeof c=="string"&&c.length<=200&&!/url\(|[;{}]|\/\*|\\/iu.test(c)?c:null}class Ct{constructor(u){Te(this,"sheet");Te(this,"base");Te(this,"rules",new Map);Te(this,"phone",null);Te(this,"phoneRules",new Map);if(u.sheet===null)throw new Error("the runtime stylesheet did not load");this.sheet=u.sheet,this.base=this.sheet.cssRules.length}reset(){for(;this.sheet.cssRules.length>this.base;)this.sheet.deleteRule(this.sheet.cssRules.length-1);this.rules.clear(),this.phoneRules.clear(),this.phone=null}rule(u){if(!it.test(u))throw new Error("a selector outside the runtime’s vocabulary");const m=this.rules.get(u);if(m!==void 0)return m;const y=this.sheet.insertRule(`${u} {}`,this.sheet.cssRules.length),h=this.sheet.cssRules[y];return this.rules.set(u,h),h}phoneRule(u){if(!it.test(u))throw new Error("a selector outside the runtime’s vocabulary");const m=this.phoneRules.get(u);if(m!==void 0)return m;if(this.phone===null){const N=this.sheet.insertRule(`@media ${Ot} {}`,this.sheet.cssRules.length);this.phone=this.sheet.cssRules[N]}const y=this.phone.insertRule(`${u} {}`,this.phone.cssRules.length),h=this.phone.cssRules[y];return this.phoneRules.set(u,h),h}set(u,m,y){qt.test(m)&&u.style.setProperty(m,y)}theme(u,m){const y=this.rule(":root");for(const[k,M]of Object.entries(u)){const Y=Dt(M);/^--[a-z0-9-]{1,40}$/u.test(k)&&Y!==null&&this.set(y,k,Y)}const h=je(m.accent);h!==null&&this.set(y,"--app-accent",h),m.density==="compact"&&(this.set(y,"--row","36px"),this.set(y,"--gap","8px"));const N=Array.isArray(m.palette)?m.palette:[];for(let k=0;k<12;k+=1){const M=je(N[k]);M!==null&&this.set(y,`--s${k}`,M)}}place(u,m){const y=this.rule(`.wk-c${u}`),h=Oe(m.x,0,11,0),N=Oe(m.w,1,12-h,1),k=Oe(m.y,0,999,0),M=Oe(m.h,1,50,1);this.set(y,"grid-column",`${h+1} / span ${N}`),this.set(y,"grid-row",`${k+1} / span ${M}`)}phoneOrder(u,m,y){const h=this.phoneRule(`.wk-c${u}`);this.set(h,"order",String(Oe(m,0,9999,0))),y?this.set(h,"display","none"):h.style.removeProperty("display")}seriesColour(u,m,y){const h=je(y);h!==null&&this.set(this.rule(`.wk-c${u}`),`--c${Oe(m,0,11,0)}`,h)}}const Rt={comfortable:44,compact:36},at={comfortable:12,compact:8},Tt=450,rt=500,It=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/u,Ie=()=>Object.create(null);function Ft(c,u){if(c===void 0||u===null||u===void 0)return u;if((c.type==="number"||c.type==="integer")&&typeof u=="string"&&u.trim()!==""){const m=Number(u);return Number.isFinite(m)&&(c.type==="number"||Number.isInteger(m))?m:u}return c.type==="boolean"&&typeof u=="string"&&(u==="true"||u==="false")?u==="true":c.type==="string"&&(typeof u=="number"||typeof u=="boolean")?String(u):u}const ee=c=>typeof c=="object"&&c!==null&&!Array.isArray(c),zt=/^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/u,lt={table:{w:12,h:5},chart:{w:6,h:5},kpi:{w:3,h:2},text:{w:6,h:1},filter:{w:3,h:1},form:{w:4,h:6},button:{w:2,h:1},image:{w:3,h:3},link:{w:2,h:1}},_t=[{type:"table",label:"Table"},{type:"chart",label:"Chart"},{type:"kpi",label:"KPI"},{type:"filter",label:"Filter"},{type:"form",label:"Form"},{type:"button",label:"Button"},{type:"text",label:"Text"},{type:"link",label:"Link"}];function p(c,u,m){const y=document.createElement(c);return u!==void 0&&(y.className=u),m!==void 0&&(y.textContent=m),y}function pt(c){return c.toISOString().slice(0,10)}function Bt(c){Ht(c)}function Ht(c,u){const m=document.getElementById("wk-apps-sheet")??null;if(!(m instanceof HTMLStyleElement)&&!(m instanceof HTMLLinkElement))return;const y=new Ct(m),h=p("div","wk-app");h.setAttribute("data-testid","apps-runtime"),document.body.append(h);let N=null,k=new Set,M=!0,Y=!1,Ee=!1,ge=!1,V="preview",Me="full",ie="en",j=0,I=null,Ae=!1,X=null,z=null;const G=Ie(),fe=new Map,be=Ie(),De=Ie(),te=new Map,$e=new Map,Le=new Map,ae=new Map,Fe=new Map;let g=0,x=0;const L=new Map;let E=null;const O=new Map;let S=!1,$=null,T=null;const D=e=>{N?.postMessage({p:de,v:1,...e})},A=(e,t)=>{x+=1;const n=`a${x}`;return D({type:e,id:n,payload:t}),new Promise(i=>L.set(n,i))},_=(e,t)=>D({type:e,payload:t}),P=e=>{const t=e.data;if(!ee(t)||t.p!==de||t.v!==1)return;const n=ee(t.payload)?t.payload:{};if(typeof t.re=="string"){const i=L.get(t.re);if(i===void 0)return;L.delete(t.re);const s=ee(t.error)?t.error:{};i(t.ok===!0?{ok:!0,payload:n}:{ok:!1,code:String(s.code??"unavailable"),message:F(s.message,300),payload:n});return}if(!S)switch(t.type){case"host.ping":typeof t.id=="string"&&D({re:t.id,ok:!0,payload:{}});return;case"host.theme":ee(n.theme)&&(K=n.theme),U();return;case"artifact.changed":ce();return;case"app.mode":(n.mode==="edit"||n.mode==="preview")&&(V=n.mode,V==="preview"&&(z=null),U());return;case"data.invalidate":Ne();return;case"host.surface":(n.surface==="card"||n.surface==="full")&&(Me=n.surface,U());return;case"selection.cleared":z=null,U();return;case"host.teardown":S=!0;for(const i of O.values())clearInterval(i);O.clear(),document.removeEventListener("keydown",Mt),N?.close(),N=null,h.replaceChildren(p("p","wk-empty","Closed"));return;default:return}};let K={};const pe=e=>{ee(e)&&(K=e),y.theme(K,{accent:I?.theme?.accent,palette:I?.theme?.palette,density:I?.theme?.density})},Se=()=>I?.theme?.density==="compact"?"compact":"comfortable",he=(e,t)=>{N=e,N.onmessage=P,k=new Set(Array.isArray(t.grants)?t.grants.filter(s=>typeof s=="string"):[]);const n=ee(t.app)?t.app:{};if(M=n.framed!==!1,Y=n.tile===!0,Ee=Y&&n.rows===!0,ge=n.propsHost===!0,V=n.mode==="edit"?"edit":"preview",Me=t.surface==="card"||t.size==="inline"?"card":"full",ee(n.url))for(const[s,l]of Object.entries(n.url).slice(0,30))It.test(s)&&typeof l=="string"&&l.length<=1e3&&(De[s]=l);const i=ee(t.prefs)?t.prefs:{};ie=typeof i.locale=="string"&&/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/u.test(i.locale)?i.locale:"en",pe(t.theme),ce()};window.addEventListener("message",e=>{const t=e.data;N!==null||e.source!==parent||!ee(t)||t.p!==de||t.type!=="host.hello"||e.ports[0]===void 0||he(e.ports[0],ee(t.payload)?t.payload:{})});const ce=async()=>{const e=await A("artifact.read",{});if(!e.ok){E=e.message,U();return}const t=ee(e.payload.content)?e.payload.content:{};if(t.type!=="app"||!ee(t.spec)){E="This is not an app",U();return}const n=j;j=typeof e.payload.version=="number"?e.payload.version:0,I=t.spec,Ae=t.readonly===!0,(X===null||!I.pages.some(s=>s.id===X))&&(X=I.pages[0]?.id??null),z!==null&&!Q().some(s=>s.id===z)&&(z=null),E=null,Ge();const i=me();U(),(n!==j||i||te.size===0)&&Ne()},me=()=>{const e=new Map;for(const n of I?.pages??[])for(const i of n.components){const s=Je(i);s!==null&&e.set(i.id,oe(s))}let t=!1;for(const n of[...te.keys()])$e.get(n)!==e.get(n)&&(te.delete(n),$e.delete(n),t=!0);return t},oe=e=>`${e.query}\0${JSON.stringify(e.params)}`,We=()=>I?.pages.find(e=>e.id===X)??null,Q=()=>We()?.components??[],Wt=(e,t)=>{const n=G[e];if(n!==void 0)return typeof n=="string"?t===void 0?n:void 0:t==="from"?n.from:t==="to"?n.to:void 0},Ke=(e,t,n)=>{const i={},s=n?.properties??{};for(const[l,a]of Object.entries(e??{})){const[r,o,f]=a.split(".");let v;if(r==="filter"&&o!==void 0)v=Wt(o,f);else if(r==="row"&&o!==void 0&&t.row!==void 0&&Object.hasOwn(t.row,o))v=t.row[o];else if(r==="form"&&o!==void 0&&t.form!==void 0){const b=be[t.form];v=b!==void 0&&Object.hasOwn(b,o)?b[o]:void 0}else r==="url"&&o!==void 0&&(v=De[o]);v!==void 0&&v!==""&&(i[l]=Ft(Object.hasOwn(s,l)?s[l]:void 0,v))}return i},Ge=()=>{for(const e of I?.pages??[])for(const t of e.components)if(!(t.type!=="filter"||G[t.id]!==void 0))if(t.filter==="date-range"){const n=ee(t.default)&&Number.isInteger(t.default.lastDays)?Math.min(3650,Math.max(1,t.default.lastDays)):30,i=new Date;G[t.id]={from:pt(new Date(i.getTime()-n*864e5)),to:pt(i)}}else G[t.id]=typeof t.default=="string"?t.default:""},dt=e=>I?.queries.find(t=>t.id===e)?.params,Je=e=>e.type==="table"||e.type==="chart"||e.type==="kpi"?{query:e.data.query,params:Ke(e.data.params,{},dt(e.data.query))}:e.type==="filter"&&e.filter==="select"&&e.options?.kind==="query"?{query:e.options.query.query,params:Ke(e.options.query.params,{},dt(e.options.query.query))}:null,Ne=(e,t=!1)=>{if(S||!k.has("data.read")||I===null||Y&&!Ee)return;Ge(),g+=1;const n=g,i=new Map;for(const s of Q()){const l=Je(s);if(l===null||e!==void 0&&l.query!==e||t&&te.has(s.id))continue;const a=oe(l);let r=i.get(a);r===void 0&&(r=A("data.query",{query:l.query,params:l.params}).then(o=>{if(!o.ok)return{state:"error",message:o.message};const f=Array.isArray(o.payload.columns)?o.payload.columns:[],v=Array.isArray(o.payload.rows)?o.payload.rows.filter(Array.isArray):[];return{state:"rows",rows:{columns:f,rows:v,sample:o.payload.sample===!0,hasMore:o.payload.hasMore===!0,truncated:o.payload.truncated===!0}}}),i.set(a,r)),te.has(s.id)||(te.set(s.id,{state:"loading"}),$e.set(s.id,a)),Le.set(s.id,n),r.then(o=>{!S&&Le.get(s.id)===n&&(te.set(s.id,o),$e.set(s.id,a),ze(s.id))})}e===void 0&&Kt()},Kt=()=>{const e=new Map;for(const t of Q()){const n=Je(t),i=n===null?void 0:I?.queries.find(s=>s.id===n.query);i?.refresh?.mode==="every"&&e.set(i.id,Math.max(15,i.refresh.seconds))}for(const[t,n]of[...O]){const[i,s]=t.split("\0");e.get(i)!==Number(s)&&(clearInterval(n),O.delete(t))}for(const[t,n]of e){const i=`${t}\0${n}`;O.has(i)||O.set(i,setInterval(()=>{document.visibilityState==="visible"&&Ne(t)},n*1e3))}},Zt=async(e,t,n)=>{if(M||V!=="preview"||!k.has("data.write"))return;const i=Q().find(o=>o.id===e)?.type!=="button",s=o=>{i?(ae.set(e,o),ze(e)):ft(`${F(t.label,60)}: ${o}`)};s("Waiting for you in studio…");const l=await A("data.action",{action:t.action,params:Ke(t.params,n,I?.actions.find(o=>o.id===t.action)?.params)}),a=l.ok?String(l.payload.state):"refused",r=l.ok?F(l.payload.reason,200):l.message;s(a==="succeeded"?`Done${r!==""?`: ${r}`:""}`:a==="cancelled"?"Not run":a==="unknown"?`Not known whether it ran: ${r}`:`Not run: ${r}`)},Qe=(e,t,n,i="wk-btn wk-btn--sm")=>{if(M)return p("span","wk-muted","Open to make changes");const s=p("button",i,F(t.label,60));return s.type="button",s.setAttribute("data-action",t.action),Y||V!=="preview"||!k.has("data.write")?(s.setAttribute("aria-disabled","true"),s.title=Y?"":V==="edit"?"Actions run in Preview":"This app may not ask to run actions here"):s.addEventListener("click",l=>{l.stopPropagation(),Zt(e,t,n)}),s},et=new Map;let se=null,tt=null;const nt=new Map,Ze=new WeakSet,ot=new WeakSet;let Xe=null;const Xt=()=>{const e=document.activeElement;if(!(e instanceof HTMLInputElement)||e.type!=="search"||e.closest(".wk-filter-options")===null)return null;const t=e.closest("[data-component]")?.getAttribute("data-component");return t==null?null:{id:t,el:e,range:[e.selectionStart,e.selectionEnd,e.selectionDirection]}},ct=e=>{if(e===null)return;const t=[...h.querySelectorAll("[data-component]")].find(n=>n.getAttribute("data-component")===e.id)?.querySelector('.wk-filter-options input[type="search"]');t==null||t===e.el||(t.focus({preventScroll:!0}),t.setSelectionRange(e.range[0],e.range[1],e.range[2]??void 0))},ut=(e,t)=>{const n=t.querySelector('.wk-filter-options input[type="search"]'),i=n!==null&&document.activeElement===n;if(i&&Ze.has(n)){ot.add(n);return}const s=i?[n.selectionStart,n.selectionEnd,n.selectionDirection]:null;if(i&&fe.set(e.id,n.value),Ut(e,t),Yt(e,t),s!==null){const l=t.querySelector('.wk-filter-options input[type="search"]');l?.focus({preventScroll:!0}),l?.setSelectionRange(s[0],s[1],s[2]??void 0)}},Yt=(e,t)=>{if(!H())return;const n=(i,s)=>{i!==null&&(i.setAttribute("data-inline",s),i.classList.add("wk-editable"),i.setAttribute("title","Double-click to edit"))};e.type==="text"&&n(t.querySelector(".wk-text"),"text"),e.type==="button"&&n(t.querySelector("button[data-action]"),"label"),e.type==="link"&&n(t.querySelector(".wk-link"),"label"),e.type==="filter"&&n(t.querySelector(".wk-filter-label"),"label")},Ut=(e,t)=>{t.replaceChildren();const n=te.get(e.id);if(e.type==="table"||e.type==="chart"||e.type==="kpi"){if(Y&&!Ee){t.append(p("div",`wk-skeleton wk-skeleton--${e.type}`));return}if(!k.has("data.read")){t.append(p("p","wk-muted","Live rows are not shown here"));return}if(n===void 0||n.state==="loading"){t.append(p("p","wk-muted","Loading…"));return}if(n.state==="error"){t.append(p("p","wk-error",`${"data"in e?e.data.query:""}: ${n.message}`));return}}const s=n?.state==="rows"?n.rows:null;switch(e.type){case"kpi":{const l=o=>o===void 0?-1:s.columns.findIndex(f=>f.name===o),a=s.rows[0];t.append(p("div","wk-kpi-value",a===void 0?"—":ye(a[l(e.value)],e.format,ie)));const r=p("div","wk-kpi-caption");if(a!==void 0&&e.delta!==void 0&&l(e.delta)>=0){const o=a[l(e.delta)],f=typeof o=="number"&&o<0||typeof o=="string"&&o.trim().startsWith("-");r.append(p("span",f?"wk-delta wk-delta--down":"wk-delta wk-delta--up",`${f?"▼":"▲"} ${ye(o,void 0,ie).replace(/^\s*-/u,"")}`)),r.append(document.createTextNode(" "))}e.caption!==void 0&&r.append(document.createTextNode(F(e.caption,120))),t.append(r);return}case"chart":Nt(t,e,s,ie),(s.truncated||s.rows.length>rt)&&t.append(p("p","wk-muted",s.truncated?"Only part of the source’s rows: the answer was cut at the app’s limit":`The first ${rt} of ${s.rows.length} rows`));return;case"table":{Vt(e,t,s);return}case"text":t.append(p(e.style==="heading"?"h2":"p",`wk-text wk-text--${e.style??"body"}`,e.text.slice(0,4e3)));return;case"filter":{jt(e,t);return}case"form":{Gt(e,t);return}case"button":t.append(Qe(e.id,e.action,{},"wk-btn"));return;case"image":{if(!zt.test(e.src)){t.append(p("p","wk-muted","This image is not one the app can show"));return}const l=p("img","wk-image");l.alt=F(e.alt,300),l.src=e.src,t.append(l);return}case"link":{const l=p("button","wk-link",F(e.label,120));if(l.type="button",e.to.kind==="page"){const a=e.to;l.addEventListener("click",()=>{if(V==="preview"){E=null;for(const[r,o]of Object.entries(Ke(a.params,{})))De[r]=String(o);I?.pages.some(r=>r.id===a.page)&&(X=a.page,z=null,U(),Ne())}})}else{const a=e.to.href;l.title=a.slice(0,300),l.addEventListener("click",async()=>{if(V!=="preview")return;const r=await A("link.open",{href:a});r.ok||ft(`${F(e.label,60)} not opened: ${r.message}`)})}t.append(l);return}}},Vt=(e,t,n)=>{const i=d=>n.columns.findIndex(w=>w.name===d),s=(e.columns??n.columns.map(d=>({column:d.name}))).filter(d=>i(d.column)>=0),l=Math.min(500,Math.max(5,e.pageSize??10)),a=Math.max(1,Math.ceil(n.rows.length/l)),r=Math.min(Fe.get(e.id)??0,a-1),o=p("table","wk-table"),f=p("tr");for(const d of s)f.append(p("th",void 0,F(d.label??d.column,80)));(e.rowActions??[]).length>0&&f.append(p("th","wk-th-actions","")),o.append(p("thead")),o.tHead.append(f);const v=p("tbody");for(const d of n.rows.slice(r*l,r*l+l)){const w=p("tr"),C=Ie();n.columns.forEach((B,R)=>{C[B.name]=d[R]??null});for(const B of s){const R=d[i(B.column)],Z=ye(R,B.format,ie),ue=/^\S+$/u.test(Z),Ue=typeof R=="number"?"wk-num":ue?Z.length>64?"wk-token wk-token--long":"wk-token":"wk-prose",Re=p("td",Ue,Z);ue&&Z.length>64&&(Re.title=Z),w.append(Re)}if((e.rowActions??[]).length>0){const B=p("td","wk-td-actions");for(const R of(e.rowActions??[]).slice(0,4))B.append(Qe(e.id,R,{row:C}));w.append(B)}v.append(w)}o.append(v);const b=p("div","wk-table-scroll");b.tabIndex=0,b.setAttribute("role","region"),b.setAttribute("aria-label",`${F(e.title??"Table",80)}, scrolls sideways`),b.append(o),t.append(b),n.rows.length===0&&t.append(p("p","wk-muted","No rows"));const q=p("div","wk-table-foot");if(a>1){const d=p("button","wk-btn wk-btn--sm","Previous"),w=p("button","wk-btn wk-btn--sm","Next");d.type="button",w.type="button",d.disabled=r===0,w.disabled=r>=a-1,d.addEventListener("click",()=>{Fe.set(e.id,r-1),ze(e.id)}),w.addEventListener("click",()=>{Fe.set(e.id,r+1),ze(e.id)}),q.append(d,p("span","wk-muted",`${r+1} of ${a}`),w)}n.truncated?q.append(p("span","wk-muted",`Only the first ${n.rows.length} rows: the answer was cut at the app’s limit`)):n.hasMore&&q.append(p("span","wk-muted","First page of the source’s rows"));const J=ae.get(e.id);J!==void 0&&q.append(p("span","wk-status",J)),q.childNodes.length>0&&t.append(q)},jt=(e,t)=>{const n=p("label","wk-filter"),i=F(e.label??(e.filter==="search"?"Search":e.filter==="date-range"?"Dates":"Filter"),60),s=p("span","wk-filter-label",i);s.title=i,n.append(s);const l=()=>{Ne()};if(e.filter==="search"){const a=p("input","wk-input");a.type="search",a.value=typeof G[e.id]=="string"?G[e.id]:"";let r=null;a.addEventListener("input",()=>{G[e.id]=a.value.slice(0,200),r!==null&&clearTimeout(r),r=setTimeout(l,300)}),n.append(a)}else if(e.filter==="select"){const a=p("select","wk-input"),r=[];let o=!1;if(e.options?.kind==="values")for(const w of e.options.values)r.push({value:F(w.value,200),label:F(w.label??w.value,200)});if(e.options?.kind==="query"){const w=te.get(e.id);if(w?.state==="rows"){o=w.rows.hasMore||w.rows.truncated;const C=w.rows.columns.findIndex(R=>R.name===e.options.value),B=w.rows.columns.findIndex(R=>R.name===(e.options.label??""));for(const R of w.rows.rows)C>=0&&r.push({value:ye(R[C],void 0,ie),label:ye(R[B>=0?B:C],void 0,ie)})}}const f=p("div","wk-filter-select"),v=p("div","wk-filter-options"),b=p("input","wk-input");b.type="search",b.placeholder="Search",b.setAttribute("aria-label",`Search ${F(e.label??"Filter",60)} options`),b.value=fe.get(e.id)??"";const q=p("span","wk-muted");q.setAttribute("aria-live","polite");const J=r.length>200||o,d=()=>{const w=J?b.value.toLowerCase():"",C=r.filter(le=>le.label.toLowerCase().includes(w)),B=C.slice(0,200),R=typeof G[e.id]=="string"?G[e.id]:"",Z=R===""?void 0:r.find(le=>le.value===R);Z!==void 0&&!B.includes(Z)&&(B.length===200&&B.pop(),B.push(Z)),a.replaceChildren();for(const le of[{value:"",label:"All"},...B]){const At=p("option",void 0,le.label);At.value=le.value,a.append(At)}const ue=B.filter(le=>C.includes(le)).length,Ue=w===""?`${ue} of ${r.length}${o?"+":""}`:`${ue}${ue<C.length?` of ${C.length}`:""} matches`,Re=`Showing ${Ue}${w!==""&&o?" in fetched rows":""}`;if(q.textContent=Ue,q.title=Re,q.setAttribute("aria-label",Re),ue<C.length||o){const le=p("option",void 0,`${Re}: search to narrow`);le.disabled=!0,le.value="",a.append(le)}a.value=R};b.addEventListener("input",()=>{fe.set(e.id,b.value),d()}),b.addEventListener("compositionstart",()=>{Ze.add(b)}),b.addEventListener("compositionend",()=>{if(Ze.delete(b),fe.set(e.id,b.value),Xe!==null){const w=Xe;Xe=null,ot.delete(b),U(w)}else ot.delete(b)&&ze(e.id)}),d(),a.addEventListener("change",()=>{G[e.id]=a.value,d(),l()}),n.append(a),f.append(n),J&&(f.classList.add("wk-filter-select--search"),v.append(b,q),f.append(v)),t.append(f);return}else{const a=G[e.id]??{from:"",to:""},r=p("input","wk-input wk-input--date"),o=p("input","wk-input wk-input--date");r.type="date",o.type="date",r.value=a.from,o.value=a.to;const f=()=>{G[e.id]={from:r.value,to:o.value},l()};r.addEventListener("change",f),o.addEventListener("change",f),n.append(r,p("span","wk-muted","–"),o)}t.append(n)},Gt=(e,t)=>{var r;const n=be[r=e.id]??(be[r]=Ie()),i=I?.actions.find(o=>o.id===e.submit.action)?.params?.properties??{};for(const o of e.fields){if(Object.hasOwn(n,o.name))continue;const f=e.submit.params===void 0?void 0:Object.entries(e.submit.params).find(([,b])=>b===`form.${o.name}`)?.[0],v=f!==void 0&&Object.hasOwn(i,f)?i[f].default:void 0;o.input==="checkbox"?n[o.name]=v===!0:v!==void 0&&(n[o.name]=String(v))}const s=p("div","wk-form");for(const o of e.fields.slice(0,30)){const f=p("label","wk-field");f.append(p("span","wk-filter-label",F(o.label??o.name,80)));let v;if(o.input==="textarea")v=p("textarea","wk-input");else if(o.input==="select"){v=p("select","wk-input");for(const b of o.options??[]){const q=p("option",void 0,F(b.label??b.value,200));q.value=F(b.value,200),v.append(q)}}else v=p("input","wk-input"),v.type=o.input==="number"?"number":o.input==="date"?"date":o.input==="checkbox"?"checkbox":"text";v instanceof HTMLInputElement&&v.type==="checkbox"?(v.checked=n[o.name]===!0,v.addEventListener("change",()=>{n[o.name]=v.checked})):(v.value=typeof n[o.name]=="string"?n[o.name]:"",v.addEventListener("input",()=>{n[o.name]=v.value.slice(0,1e3)})),v.disabled=V!=="preview",f.append(v),s.append(f)}const l=p("div","wk-form-foot");l.append(Qe(e.id,e.submit,{form:e.id},"wk-btn"));const a=ae.get(e.id);l.append(p("span","wk-muted",a??(M?"":"Studio asks before it writes"))),s.append(l),t.append(s)};let ve=null;const ft=e=>{E=e,ve!==null?(ve.textContent=e,ve.hidden=!1):U()},ze=e=>{if($!==null&&$.id===e)return;const t=Q().find(i=>i.id===e),n=nt.get(e);t!==void 0&&n!==void 0&&ut(t,n)},H=()=>V==="edit"&&Me==="full"&&!Ae&&k.has("artifact.write");let ke=null;const ht=()=>{const e=ke.getBoundingClientRect(),t=Se();return{col:(e.width+at[t])/12,row:Rt[t]+at[t],left:e.left,top:e.top}},Jt=(e,t)=>{const n=ht();return{x:Math.min(11,Math.max(0,Math.floor((e-n.left)/n.col))),y:Math.min(999,Math.max(0,Math.floor((t-n.top)/n.row)))}},re=async(e,t={})=>{const n=await A("spec.edit",{base:j,ops:e});if(!n.ok)return E=n.code==="head_moved"?"The app changed meanwhile: showing the newest version":`Not changed: ${n.message}`,n.code==="head_moved"?await ce():U(),null;ee(n.payload.spec)&&(I=n.payload.spec),E=null,Ge(),me();const i=Array.isArray(n.payload.added)?n.payload.added.filter(s=>typeof s=="string"):[];return i[0]!==void 0&&Ce(i[0]),U({keepProps:t.typed===!0&&i.length===0}),Ne(void 0,!0),i},Ce=e=>{const t=z;z=e,e!==null&&k.has("selection.chip")?_("selection.set",{anchors:[{kind:"element",id:e}]}):e===null&&t!==null&&k.has("selection.chip")&&_("selection.set",{anchors:[]})},mt=(e,t,n,i)=>{if(!H()||e.button!==0)return;e.preventDefault(),e.stopPropagation(),(i.closest(".wk-cell")??i).focus({preventScroll:!0});const s=et.get(t.id),l=ht(),a={x:e.clientX,y:e.clientY};let r={...t.box},o=!1;const f=n==="move"?e.target?.closest?.("[data-inline]"):null;i.setPointerCapture(e.pointerId),i.classList.add("is-dragging");const v=q=>{const J=Math.round((q.clientX-a.x)/l.col),d=Math.round((q.clientY-a.y)/l.row);J===0&&d===0&&!o||(o=!0,r=n==="move"?{...t.box,x:Math.min(12-t.box.w,Math.max(0,t.box.x+J)),y:Math.max(0,t.box.y+d)}:{...t.box,w:Math.min(12-t.box.x,Math.max(1,t.box.w+J)),h:Math.min(50,Math.max(1,t.box.h+d))},y.place(s,r))},b=()=>{i.removeEventListener("pointermove",v),i.removeEventListener("pointerup",b),i.removeEventListener("pointercancel",b),i.classList.remove("is-dragging");const q=n==="move"?r.x!==t.box.x||r.y!==t.box.y:r.w!==t.box.w||r.h!==t.box.h;if(!o||!q){y.place(s,t.box),o||(Ce(t.id),vt(),kt(t.id,f));return}re([n==="move"?{op:"component-move",id:t.id,x:r.x,y:r.y}:{op:"component-resize",id:t.id,w:r.w,h:r.h}])};i.addEventListener("pointermove",v),i.addEventListener("pointerup",b),i.addEventListener("pointercancel",b)},wt=()=>Q().reduce((e,t)=>Math.max(e,t.box.y+t.box.h),0),Qt=(e,t,n)=>{if(!H()||e.button!==0||ke===null||X===null)return;e.preventDefault(),n.focus({preventScroll:!0});const i=lt[t],s=p("div","wk-drop wk-c9999");s.setAttribute("data-testid","apps-drop-target");let l=null;n.setPointerCapture(e.pointerId);const a=o=>{const f=ke.getBoundingClientRect();if(o.clientX<f.left||o.clientX>f.right||o.clientY<f.top){s.remove(),l=null;return}l=Jt(o.clientX,o.clientY),l.x=Math.min(l.x,12-i.w),y.place(9999,{x:l.x,y:l.y,w:i.w,h:i.h}),s.parentNode===null&&ke.append(s)},r=o=>{if(n.removeEventListener("pointermove",a),n.removeEventListener("pointerup",r),n.removeEventListener("pointercancel",r),s.remove(),Math.abs(o.clientX-e.clientX)+Math.abs(o.clientY-e.clientY)>6&&l===null)return;const v=l??{x:0,y:wt()};re([{op:"component-add",page:X,type:t,box:{x:v.x,y:v.y,w:Math.min(i.w,12-v.x),h:i.h}}])};n.addEventListener("pointermove",a),n.addEventListener("pointerup",r),n.addEventListener("pointercancel",r)},st=(e,t,n=!1,i)=>{let s=e.value,l=null;const a=()=>{if(e.value===s)return;s=e.value;const o=t();if(o===void 0)return;const f=Promise.resolve(o);l=f,f.finally(()=>{l===f&&(l=null)})};let r=!1;e.addEventListener("compositionstart",()=>{r=!0}),e.addEventListener("compositionend",()=>{r=!1,a()}),e.addEventListener("input",o=>{!r&&o.isComposing!==!0&&a()}),i!==void 0&&e.addEventListener("blur",()=>{const o=()=>{if(document.activeElement===e)return;const f=i();e.value!==f&&(e.value=f,s=f)};l!==null?l.then(o,o):o()}),e.addEventListener("change",()=>{r||a()}),e.addEventListener("keydown",o=>{const f=o;r||f.isComposing||f.keyCode===229||f.key==="Enter"&&(!n||f.metaKey||f.ctrlKey)&&(f.preventDefault(),a())})},_e=(e,t)=>{const n=p("label","wk-prop");return n.append(p("span","wk-prop-label",e),t),n},Pe=(e,t,n,i,s,l=!1)=>{const a=p(l?"textarea":"input","wk-input");return a.value=i??"",a.maxLength=s,a.setAttribute("data-prop",n),st(a,()=>re([{op:"component-set",id:e.id,prop:n,value:a.value}],{typed:!0}),l,()=>{const r=Q().find(f=>f.id===e.id),o=n==="label"&&r?.type==="button"?r.action?.label:r?.[n];return typeof o=="string"?o:""}),_e(t,a)},Be=(e,t,n,i,s,l="set")=>{const a=p("select","wk-input");for(const r of s){const o=p("option",void 0,r);o.value=r,a.append(o)}return a.value=i,a.setAttribute("data-prop",n),a.addEventListener("change",()=>{re([l==="bind"?{op:"bind",id:e.id,query:a.value}:{op:"component-set",id:e.id,prop:n,value:a.value}])}),_e(t,a)},yt=(e,t,n,i)=>{const s=p("input","wk-check");return s.type="checkbox",s.checked=i,s.setAttribute("data-prop",n),s.addEventListener("change",()=>{re([{op:"component-set",id:e.id,prop:n,value:s.checked}])}),_e(t,s)},Ye=(e,t,n,i,s)=>{const l=p("input","wk-input wk-input--num");l.type="number",l.min=String(i),l.max=String(s),l.value=String(n==="x"?e.box.x+1:n==="y"?e.box.y+1:e.box[n]),l.setAttribute("data-prop",`box-${n}`);const a=()=>Q().find(o=>o.id===e.id)?.box??e.box,r=o=>String(n==="x"?o.x+1:n==="y"?o.y+1:o[n]);return st(l,()=>{if(l.value.trim()==="")return;const o=Math.round(Number(l.value));if(!Number.isFinite(o))return;const f=a();if(n==="x"||n==="y"){const q=n==="x"?Math.min(12-f.w,Math.max(0,o-1)):f.x,J=n==="y"?Math.max(0,o-1):f.y;return re([{op:"component-move",id:e.id,x:q,y:J}],{typed:!0})}const v=n==="w"?Math.min(12-f.x,Math.max(1,o)):f.w,b=n==="h"?Math.min(50,Math.max(1,o)):f.h;return re([{op:"component-resize",id:e.id,w:v,h:b}],{typed:!0})},!1,()=>r(a())),_e(t,l)},gt=e=>{const t=p("aside","wk-props");t.setAttribute("aria-label","Properties"),t.setAttribute("data-testid","apps-properties"),t.append(p("h3","wk-props-title","Properties")),t.append(p("p","wk-muted",`${e.type==="chart"?`${e.chart} chart`:e.type} · ${e.id}`)),t.append(Pe(e,"Title","title",e.title,120));const n=(I?.queries??[]).map(a=>a.id),i=a=>I?.queries.find(r=>r.id===a)?.output.map(r=>r.name)??[];if((e.type==="table"||e.type==="chart"||e.type==="kpi")&&t.append(Be(e,"Data","query",e.data.query,n,"bind")),e.type==="table"){const a=p("input","wk-input wk-input--num");a.type="number",a.min="5",a.max="500",a.value=String(e.pageSize??10),a.setAttribute("data-prop","pageSize"),st(a,()=>{if(a.value.trim()==="")return;const r=Math.round(Number(a.value));return Number.isFinite(r)?re([{op:"component-set",id:e.id,prop:"pageSize",value:Math.min(500,Math.max(5,r))}],{typed:!0}):void 0},!1,()=>String(Q().find(r=>r.id===e.id)?.pageSize??10)),t.append(_e("Rows per page",a))}e.type==="chart"&&(t.append(Be(e,"Chart","chart",e.chart,["bar","line","area","pie"])),t.append(Be(e,"Category","x",e.x,i(e.data.query))),(e.chart==="bar"||e.chart==="area")&&t.append(yt(e,"Stacked","stacked",e.stacked===!0))),e.type==="kpi"&&(t.append(Be(e,"Figure","value",e.value,i(e.data.query))),t.append(Pe(e,"Caption","caption",e.caption,120))),e.type==="text"&&(t.append(Pe(e,"Text","text",e.text,4e3,!0)),t.append(Be(e,"Style","style",e.style??"body",["heading","body","caption"]))),e.type==="filter"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="button"&&t.append(Pe(e,"Label","label",e.action.label,60)),e.type==="link"&&t.append(Pe(e,"Label","label",e.label,120)),e.type==="image"&&t.append(Pe(e,"Description","alt",e.alt,300));const s=p("div","wk-prop-box");s.append(Ye(e,"Column","x",1,12),Ye(e,"Row","y",1,1e3),Ye(e,"Width","w",1,12),Ye(e,"Height","h",1,50)),t.append(s),t.append(yt(e,"Hide on phones","hideOnPhone",e.hideOnPhone===!0));const l=p("button","wk-btn wk-btn--danger","Delete this component");return l.type="button",l.setAttribute("data-testid","apps-remove"),l.addEventListener("click",()=>{const a=e.id;z=null,re([{op:"component-remove",id:a}])}),t.append(l),t},bt=()=>{const e=p("aside","wk-props wk-props--empty");return e.setAttribute("aria-label","Properties"),e.setAttribute("data-testid","apps-properties-empty"),e.append(p("h3","wk-props-title","Properties")),e.append(p("p","wk-muted","Select a component to change it here. Double-click its words to edit them in place.")),e},en=()=>{const e=p("aside","wk-palette");e.setAttribute("aria-label","Components"),e.append(p("h3","wk-props-title","Components")),e.append(p("p","wk-muted","Drag onto the canvas, or click to add"));const t=p("div","wk-tiles");for(const n of _t){const i=p("button","wk-tile",n.label);i.type="button",i.setAttribute("data-palette",n.type),i.addEventListener("pointerdown",s=>Qt(s,n.type,i)),i.addEventListener("click",s=>{if(s.detail!==0||!H()||X===null)return;const l=lt[n.type];re([{op:"component-add",page:X,type:n.type,box:{x:0,y:wt(),w:l.w,h:l.h}}])}),t.append(i)}return e.append(t),e},U=(e={})=>{const t=$;let n=!1;if(t!==null){const i=H()?Q().find(s=>s.id===t.id):void 0;if(n=i!==void 0&&xt(i,t.prop)===t.before,n&&t.composing()){t.defer();return}n?t.hold():t.drop()}tn(e),n&&t!==null&&$===t&&t.place()},tn=e=>{const t=h.querySelector(".wk-pages"),n=t?.scrollLeft??0,i=e.focusPage===!0||(t?.contains(document.activeElement)??!1),s=Xt();if(s!==null&&Ze.has(s.el)){Xe=e;return}s!==null&&fe.set(s.id,s.el.value);const l=document.activeElement instanceof HTMLElement&&h.contains(document.activeElement)?document.activeElement.getAttribute("data-prop"):null;if(nt.clear(),et.clear(),y.reset(),pe(void 0),h.setAttribute("data-mode",H()?"edit":"preview"),h.setAttribute("data-tile",Y?"true":"false"),h.setAttribute("data-surface",Me),I===null){h.replaceChildren(p("p","wk-empty",E??"Loading the app…")),se=null;return}const a=[];H()&&a.push(en());const r=p("main","wk-main"),o=p("nav","wk-pages");o.setAttribute("aria-label","Pages");for(const d of I.pages){const w=p("button",d.id===X?"wk-page is-on":"wk-page",F(d.title,80));w.type="button",w.setAttribute("aria-current",d.id===X?"page":"false"),w.addEventListener("click",()=>{X!==d.id&&(X=d.id,Ce(null),U({focusPage:!0}),Ne())}),o.append(w)}r.append(o),ve=p("p","wk-notice",E??""),ve.setAttribute("data-testid","apps-notice"),ve.setAttribute("aria-live","polite"),ve.hidden=E===null,r.append(ve),Ae&&V==="edit"&&r.append(p("p","wk-notice","A chat turn is changing this app: it is read-only until the turn ends")),ke=p("div","wk-grid");const f=Q(),v=[...f].sort((d,w)=>d.box.y-w.box.y||d.box.x-w.box.x);f.forEach((d,w)=>{et.set(d.id,w),y.place(w,d.box),y.phoneOrder(w,v.indexOf(d),d.hideOnPhone===!0),d.type==="chart"&&d.series.slice(0,12).forEach((R,Z)=>y.seriesColour(w,Z,R.color));const C=p("section",`wk-cell wk-cell--${d.type} wk-c${w}${d.id===z&&H()?" is-selected":""}`);if(C.setAttribute("data-component",d.id),d.title!==void 0&&d.type!=="text"){const R=p("h3","wk-cell-title",F(d.title,120));H()&&(R.setAttribute("data-inline","title"),R.classList.add("wk-editable"),R.setAttribute("title","Double-click to edit")),C.append(R)}const B=p("div","wk-cell-body");if(nt.set(d.id,B),ut(d,B),C.append(B),H()){C.classList.add("is-editable"),C.tabIndex=0,C.setAttribute("aria-label",`${d.type==="chart"?`${d.chart} chart`:d.type} ${F(d.title??d.id,80)}: Enter to select`),C.append(p("span","wk-tag",`${d.type==="chart"?`${d.chart} chart`:d.type}${"data"in d&&d.data!==void 0?` · ${d.data.query}`:""}`));const R=p("span","wk-handle");R.setAttribute("aria-hidden","true"),R.addEventListener("pointerdown",Z=>mt(Z,d,"resize",R)),C.append(R),C.addEventListener("pointerdown",Z=>{Z.target.closest("input, select, textarea, button, .wk-handle")===null&&mt(Z,d,"move",C)}),C.addEventListener("pointerup",Z=>{const ue=Z.target.closest?.("button[data-inline]");ue!==null&&Z.button===0&&kt(d.id,ue)})}ke.append(C)}),f.length===0&&ke.append(p("p","wk-empty",H()?"Drag a component here from the palette":"This page is empty")),r.append(ke),a.push(r);const b=H()&&z!==null?f.find(d=>d.id===z):void 0,q=()=>{o.scrollLeft=n;const d=o.querySelector(".is-on");i&&d?.focus({preventScroll:!0}),d?.scrollIntoView?.({block:"nearest",inline:"nearest"})};if(e.keepProps===!0&&b!==void 0&&se!==null&&tt===b.id&&se.parentNode===h){for(const d of[...h.childNodes])d!==se&&d.remove();for(const d of a)h.insertBefore(d,se);q(),ct(s);return}se=ge?null:b!==void 0?gt(b):H()?bt():null,tt=b?.id??null,h.replaceChildren(...a,...se!==null?[se]:[]),q(),ct(s),l!==null&&[...h.querySelectorAll("[data-prop]")].find(d=>d.getAttribute("data-prop")===l)?.focus({preventScroll:!0})},vt=()=>{for(const n of h.querySelectorAll("[data-component]"))n.classList.toggle("is-selected",H()&&n.getAttribute("data-component")===z);const e=H()&&z!==null?Q().find(n=>n.id===z):void 0,t=ge?null:e!==void 0?gt(e):H()?bt():null;se!==null&&t!==null&&se.parentNode===h?se.replaceWith(t):(se?.remove(),t!==null&&h.append(t)),se=t,tt=e?.id??null},kt=(e,t)=>{const n=t?.getAttribute("data-inline")??null,i=Date.now();n!==null&&t!==null&&T!==null&&T.id===e&&T.prop===n&&i-T.at<Tt?(T=null,t.isConnected&&Et(e,t)):T=n!==null?{id:e,prop:n,at:i}:null},xt=(e,t)=>{if(t==="title")return e.title??"";if(t==="text"&&e.type==="text")return e.text;if(t==="label"){if(e.type==="button")return e.action.label;if(e.type==="link")return e.label;if(e.type==="filter")return e.label??""}return""},Et=(e,t)=>{const n=Q().find(d=>d.id===e),i=t.getAttribute("data-inline");if(n===void 0||i===null||!H()||$!==null)return;const s=xt(n,i),l=i==="text",a=l?p("textarea","wk-inline-input wk-inline-input--multi"):p("input","wk-inline-input");a.value=s,a.maxLength=l?4e3:n.type==="button"?60:120,a.setAttribute("data-testid","apps-inline"),a.setAttribute("aria-label",`Edit the ${i==="text"?"text":i}`),t.replaceWith(a),a.closest("[data-component]")?.classList.add("is-inline"),a.focus(),a.select();let r=!1,o=!1,f=!1,v=!1,b=[null,null,"none"];const q={id:e,prop:i,before:s,drop:()=>{r=!0,f=!1,$===q&&($=null)},hold:()=>{f=!0,b=[a.selectionStart,a.selectionEnd,a.selectionDirection??"none"]},composing:()=>o,defer:()=>{v=!0},place:()=>{const d=[...h.querySelectorAll("[data-component]")].find(C=>C.getAttribute("data-component")===e),w=d===void 0?void 0:[...d.querySelectorAll("[data-inline]")].find(C=>C.getAttribute("data-inline")===i);if(w===void 0){q.drop();return}w.replaceWith(a),d.classList.add("is-inline"),a.focus(),b[0]!==null&&b[1]!==null&&a.setSelectionRange(b[0],b[1],b[2]),f=!1}};$=q;const J=d=>{r||(q.drop(),d&&a.value!==s?re([{op:"component-set",id:e,prop:i,value:a.value}]):U())};a.addEventListener("compositionstart",()=>{o=!0}),a.addEventListener("compositionend",()=>{o=!1,v&&(v=!1,r||U())}),a.addEventListener("keydown",d=>{const w=d;if(!(o||w.isComposing||w.keyCode===229)){if(w.key==="Escape"){w.preventDefault(),w.stopPropagation(),J(!1);return}w.key==="Enter"&&!(l&&w.shiftKey)&&(w.preventDefault(),w.stopPropagation(),J(!0))}}),a.addEventListener("blur",()=>{f||(a.isConnected?J(!0):q.drop())})};h.addEventListener("dblclick",e=>{if(!H()||$!==null)return;const n=((typeof document.elementFromPoint=="function"?document.elementFromPoint(e.clientX,e.clientY):null)??e.target)?.closest("[data-inline]"),i=n?.closest("[data-component]");n==null||i===null||i===void 0||(e.preventDefault(),Et(i.getAttribute("data-component"),n))});function Mt(e){if(N===null||I===null)return;const t=e.target?.closest?.(".wk-cell.is-editable");if(t!==null&&(e.key==="Enter"||e.key===" ")&&e.target===t){e.preventDefault();const s=t.getAttribute("data-component");s!==null&&(Ce(s),vt(),h.querySelector(".wk-props input, .wk-props select")?.focus());return}const n=e.target?.closest("input, textarea, select")!=null;if((e.metaKey||e.ctrlKey)&&!e.altKey&&e.key.toLowerCase()==="z"&&!n&&H()){e.preventDefault(),A("app.history",{move:e.shiftKey?"redo":"undo",base:j}).then(s=>{s.ok||(E=s.message,s.code==="head_moved"?ce():U())});return}if((e.key==="Delete"||e.key==="Backspace")&&!n&&H()&&z!==null){e.preventDefault();const s=z;Ce(null),re([{op:"component-remove",id:s}]);return}e.key==="Escape"&&z!==null&&!n&&(Ce(null),U())}document.addEventListener("keydown",Mt),h.append(p("p","wk-empty","Loading the app…")),$t(c.editor,c.surfaces)}Bt({editor:"wicked-apps",surfaces:{card:{interactive:!0,aspect:"16:9",actions:[]},full:{}}})})();
|
|
149
182
|
</script>
|
|
150
183
|
</body>
|
|
151
184
|
</html>
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="wicked-editor" content="wicked-deck">
|
|
6
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
6
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
7
7
|
<title>Slides</title>
|
|
8
8
|
<style>
|
|
9
9
|
/* The editor's own chrome takes the host's tokens (`host.hello.theme` / `host.theme`), with plain
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="wicked-editor" content="wicked-doc">
|
|
6
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
6
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
7
7
|
<title>Document</title>
|
|
8
8
|
<style>
|
|
9
9
|
/* The plugin's own chrome takes the host's tokens (`host.hello.theme` / `host.theme`), with plain
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="wicked-editor" content="wicked-insights">
|
|
6
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
6
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
7
7
|
<title>Run insights</title>
|
|
8
8
|
<style>
|
|
9
9
|
/* The host's tokens arrive in host.hello / host.theme; these are plain fallbacks. */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="wicked-editor" content="wicked-page">
|
|
6
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
6
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
7
7
|
<title>Document</title>
|
|
8
8
|
<style>
|
|
9
9
|
/* The plugin's own chrome takes the host's tokens (`host.hello.theme` / `host.theme`), with plain
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en"><head><meta charset="utf-8">
|
|
3
3
|
<meta name="wicked-editor" content="wicked-video">
|
|
4
|
-
<meta name="wicked-editor-version" content="0.16.
|
|
4
|
+
<meta name="wicked-editor-version" content="0.16.8">
|
|
5
5
|
<title>Video</title>
|
|
6
6
|
<style>
|
|
7
7
|
:root{--surface-base:#fff;--surface-card:#f6f7f9;--surface-raised:#fff;--ink-high:#0d1117;--ink-body:#2b333d;--ink-muted:#5b6673;--border:#d5dae1;--accent:#224a5e;--font-sans:system-ui,sans-serif}
|
package/dist/studio/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>wicked-studio</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="/assets/favicon-BJA6hF2f.svg" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-rMZ47jUD.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CrcZTJjG.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<div id="root"></div>
|