@protobase/ui 0.111.1 → 0.112.0
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/account/messages.d.ts +2 -2
- package/dist/app/change-confirm/messages.d.ts +2 -2
- package/dist/app/charts/messages.d.ts +2 -2
- package/dist/app/comments/messages.d.ts +2 -2
- package/dist/app/confirm-sign-in-messages.d.ts +2 -2
- package/dist/app/create/messages.d.ts +2 -2
- package/dist/app/delete/messages.d.ts +2 -2
- package/dist/app/displays/messages.d.ts +2 -2
- package/dist/app/embedded-list/messages.d.ts +2 -2
- package/dist/app/export/messages.d.ts +2 -2
- package/dist/app/field-types/workflow/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
- package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
- package/dist/app/focus/messages.d.ts +2 -2
- package/dist/app/gallery/messages.d.ts +2 -2
- package/dist/app/hand-order/messages.d.ts +2 -2
- package/dist/app/history/messages.d.ts +2 -2
- package/dist/app/import/messages.d.ts +2 -2
- package/dist/app/list-messages.d.ts +2 -2
- package/dist/app/messages.d.ts +2 -2
- package/dist/app/new-version/messages.d.ts +2 -2
- package/dist/app/pages/messages.d.ts +2 -2
- package/dist/app/record-chart/messages.d.ts +2 -2
- package/dist/app/record-messages.d.ts +2 -2
- package/dist/app/record-mode/shown-layout.d.ts +1 -1
- package/dist/app/record-row/messages.d.ts +2 -2
- package/dist/app/related-cards/messages.d.ts +2 -2
- package/dist/app/runtime/messages.d.ts +2 -2
- package/dist/app/saved/messages.d.ts +2 -2
- package/dist/app/saved/use-favorite.d.ts +1 -1
- package/dist/app/search/messages.d.ts +2 -2
- package/dist/app/searches/messages.d.ts +2 -2
- package/dist/app/searches/use-save-search.d.ts +1 -1
- package/dist/app-shell/messages.d.ts +2 -2
- package/dist/assistant-dock/messages.d.ts +2 -2
- package/dist/auth/messages.d.ts +2 -2
- package/dist/calls/messages.d.ts +2 -2
- package/dist/data-grid/messages.d.ts +2 -2
- package/dist/filter-panel/messages.d.ts +2 -2
- package/dist/invitations/messages.d.ts +2 -2
- package/dist/locale/en.js +8 -1
- package/dist/locale/en.json.d.ts +7 -0
- package/dist/locale/messages.d.ts +14 -0
- package/dist/locale/nl.js +8 -1
- package/dist/mailbox/messages.d.ts +2 -2
- package/dist/mocks/customers.d.ts +1 -1
- package/dist/mocks/invoices.d.ts +1 -1
- package/dist/mocks/orders.d.ts +1 -1
- package/dist/notifications/bell/messages.d.ts +2 -2
- package/dist/organizations/messages.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/record-view/messages.d.ts +2 -2
- package/dist/shell/assets/{api-provider-BopdAXpc.js → api-provider-CcDtTh0D.js} +2 -2
- package/dist/shell/assets/{app-CFp4G8NK.js → app-CYep6fHL.js} +8 -8
- package/dist/shell/assets/{badge-B4ikYIDJ.js → badge-ChHXC28D.js} +2 -2
- package/dist/shell/assets/{checkbox-B23HcgB6.js → checkbox-COOOlJPG.js} +2 -2
- package/dist/shell/assets/{display-value-DoqvOXh1.js → display-value-fDiKbfJO.js} +2 -2
- package/dist/shell/assets/export-worker-BGjZsI8V.js +15 -0
- package/dist/shell/assets/{field-badge-Dhke0lFK.js → field-badge-3QmjR1r3.js} +2 -2
- package/dist/shell/assets/{graph-view-DI1ULzNt.js → graph-view-BfYs6ayj.js} +2 -2
- package/dist/shell/assets/{html-viewer-C_AC-COH.js → html-viewer-C0QI0zaR.js} +2 -2
- package/dist/shell/assets/{in-place-form-BE0jeXxK.js → in-place-form-y_QOwKOi.js} +2 -2
- package/dist/shell/assets/{index-or0lVadT.js → index-CW7p8b2W.js} +2 -2
- package/dist/shell/assets/{intl-cache-ULd6cKG6.js → intl-cache-bXVNV0Yq.js} +2 -2
- package/dist/shell/assets/{maplibre-DrBxXIsy.js → maplibre-BGA6uo19.js} +2 -2
- package/dist/shell/assets/{markdown-content-COBuNH9x.js → markdown-content-DFkH88LY.js} +2 -2
- package/dist/shell/assets/messages-ClKBpZlk.js +2 -0
- package/dist/shell/assets/parse-worker-D7uEODYK.js +35 -0
- package/dist/shell/assets/{record-map-DfwRSYzd.js → record-map-4A4R4ckl.js} +2 -2
- package/dist/shell/assets/{records-map-qZnBB7DR.js → records-map-BsE-mBBB.js} +2 -2
- package/dist/shell/assets/{run-trace-view-Fk1tXCaT.js → run-trace-view-CSoeovIo.js} +2 -2
- package/dist/shell/assets/{search-picker-DJ78Pz1K.js → search-picker-DAcPiMQA.js} +2 -2
- package/dist/shell/assets/{shared-protobase-ui-DSiFrCL5.js → shared-protobase-ui-BudhYj2I.js} +2 -2
- package/dist/shell/assets/{step-catalog-C1OlIQJx.js → step-catalog-BuUwSkK9.js} +2 -2
- package/dist/shell/assets/{step-panel-DztOKEAB.js → step-panel-CoOoYMdA.js} +2 -2
- package/dist/shell/assets/{use-app-address-EhuvnsNl.js → use-app-address-D50fN1nP.js} +2 -2
- package/dist/shell/assets/{use-meta-7JZ_HBay.js → use-meta-BqEqOLNe.js} +2 -2
- package/dist/shell/assets/{use-sibling-page-Cd-rFEbN.js → use-sibling-page-Ccwp2gM-.js} +2 -2
- package/dist/shell/assets/{value-badge-D3nfF_kP.js → value-badge-BKLV4otJ.js} +2 -2
- package/dist/shell/assets/{workflow-canvas-DsvH-l5e.js → workflow-canvas-CNpgSr9v.js} +2 -2
- package/dist/shell/assets/{workflow-graph-editor-sZa5WHEO.js → workflow-graph-editor-z38xU0ar.js} +2 -2
- package/dist/shell/assets/{workflow-workbench-Bq7-Q1-w.js → workflow-workbench-CAk5M4iT.js} +2 -2
- package/dist/shell/index.html +12 -12
- package/dist/shell/protobase.shell.json +2 -2
- package/dist/shell/protobase.sw.js +2 -2
- package/dist/shell-source-maps/assets/{api-provider-BopdAXpc.js.map → api-provider-CcDtTh0D.js.map} +1 -1
- package/dist/shell-source-maps/assets/{app-CFp4G8NK.js.map → app-CYep6fHL.js.map} +1 -1
- package/dist/shell-source-maps/assets/{badge-B4ikYIDJ.js.map → badge-ChHXC28D.js.map} +1 -1
- package/dist/shell-source-maps/assets/{checkbox-B23HcgB6.js.map → checkbox-COOOlJPG.js.map} +1 -1
- package/dist/shell-source-maps/assets/{display-value-DoqvOXh1.js.map → display-value-fDiKbfJO.js.map} +1 -1
- package/dist/shell-source-maps/assets/export-worker-BGjZsI8V.js.map +1 -0
- package/dist/shell-source-maps/assets/{field-badge-Dhke0lFK.js.map → field-badge-3QmjR1r3.js.map} +1 -1
- package/dist/shell-source-maps/assets/{graph-view-DI1ULzNt.js.map → graph-view-BfYs6ayj.js.map} +1 -1
- package/dist/shell-source-maps/assets/{html-viewer-C_AC-COH.js.map → html-viewer-C0QI0zaR.js.map} +1 -1
- package/dist/shell-source-maps/assets/{in-place-form-BE0jeXxK.js.map → in-place-form-y_QOwKOi.js.map} +1 -1
- package/dist/shell-source-maps/assets/{index-or0lVadT.js.map → index-CW7p8b2W.js.map} +1 -1
- package/dist/shell-source-maps/assets/{intl-cache-ULd6cKG6.js.map → intl-cache-bXVNV0Yq.js.map} +1 -1
- package/dist/shell-source-maps/assets/{maplibre-DrBxXIsy.js.map → maplibre-BGA6uo19.js.map} +1 -1
- package/dist/shell-source-maps/assets/{markdown-content-COBuNH9x.js.map → markdown-content-DFkH88LY.js.map} +1 -1
- package/dist/shell-source-maps/assets/messages-ClKBpZlk.js.map +1 -0
- package/dist/shell-source-maps/assets/parse-worker-D7uEODYK.js.map +1 -0
- package/dist/shell-source-maps/assets/{record-map-DfwRSYzd.js.map → record-map-4A4R4ckl.js.map} +1 -1
- package/dist/shell-source-maps/assets/{records-map-qZnBB7DR.js.map → records-map-BsE-mBBB.js.map} +1 -1
- package/dist/shell-source-maps/assets/{run-trace-view-Fk1tXCaT.js.map → run-trace-view-CSoeovIo.js.map} +1 -1
- package/dist/shell-source-maps/assets/{search-picker-DJ78Pz1K.js.map → search-picker-DAcPiMQA.js.map} +1 -1
- package/dist/shell-source-maps/assets/{shared-protobase-ui-DSiFrCL5.js.map → shared-protobase-ui-BudhYj2I.js.map} +1 -1
- package/dist/shell-source-maps/assets/{step-catalog-C1OlIQJx.js.map → step-catalog-BuUwSkK9.js.map} +1 -1
- package/dist/shell-source-maps/assets/{step-panel-DztOKEAB.js.map → step-panel-CoOoYMdA.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-app-address-EhuvnsNl.js.map → use-app-address-D50fN1nP.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-meta-7JZ_HBay.js.map → use-meta-BqEqOLNe.js.map} +1 -1
- package/dist/shell-source-maps/assets/{use-sibling-page-Cd-rFEbN.js.map → use-sibling-page-Ccwp2gM-.js.map} +1 -1
- package/dist/shell-source-maps/assets/{value-badge-D3nfF_kP.js.map → value-badge-BKLV4otJ.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-canvas-DsvH-l5e.js.map → workflow-canvas-CNpgSr9v.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-graph-editor-sZa5WHEO.js.map → workflow-graph-editor-z38xU0ar.js.map} +1 -1
- package/dist/shell-source-maps/assets/{workflow-workbench-Bq7-Q1-w.js.map → workflow-workbench-CAk5M4iT.js.map} +1 -1
- package/dist/status/messages.d.ts +2 -2
- package/dist/users/messages.d.ts +2 -2
- package/package.json +5 -5
- package/dist/shell/assets/export-worker-DcpuaeRz.js +0 -15
- package/dist/shell/assets/messages-Y1hA4dds.js +0 -2
- package/dist/shell/assets/parse-worker-B5yLKylw.js +0 -35
- package/dist/shell-source-maps/assets/export-worker-DcpuaeRz.js.map +0 -1
- package/dist/shell-source-maps/assets/messages-Y1hA4dds.js.map +0 -1
- package/dist/shell-source-maps/assets/parse-worker-B5yLKylw.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{t as r}from"./guarded-D7vqlAj1.js";import{At as i,Dt as a,Et as o,Ot as s,X as c,ft as l,rt as u}from"./vendor-WWp_xlp2.js";import{A as d,M as f,N as p,P as m,S as h,_ as g,b as _,j as v,k as y,n as b,o as x,r as ee,u as te}from"./api-provider-BopdAXpc.js";import{$ as ne,F as S,I as re,K as ie,P as C,U as ae,V as oe,W as se,Z as ce,i as le,nt as ue,rt as w,t as de}from"./display-value-DoqvOXh1.js";import{i as fe,n as pe,s as me,t as he}from"./messages-Y1hA4dds.js";import{a as ge,n as _e,r as ve,t as ye}from"./use-meta-7JZ_HBay.js";import{t as be}from"./cn-B1sdg8aY.js";var T=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),xe=(e,t)=>{let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[a]+1,i[a-1]+1,n[a-1]+o)}n=i}return n[t.length]},Se=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:xe(n,e.toLowerCase())})).sort((e,t)=>e.score-t.score)[0];return r&&r.score<=Math.max(2,Math.floor(e.length/3))?r.candidate:void 0},Ce=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),E=(e,t,n)=>{if(t.path.length>1){e.errors.push(T(`unsupported-traversal`,`Traversal into "${t.path.join(`.`)}" is not supported yet`,`Filter on fields of this resource only`,t.span));return}let r=t.path[0],i=Ce(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Se(r,i);e.errors.push(T(`unknown-field`,`Unknown field "${r}"`,a?`Did you mean "${a}"?`:`Available fields: ${i.join(`, `)}`,t.span));return}if(!i[n]){let r=n===`filterable`?`filterable`:`sortable`;e.errors.push(T(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},D=(e,t,n,r)=>{e.errors.push(T(`unsupported`,t,n,r))},O=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:D(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),we=(e,t)=>{switch(t.kind){case`member`:return{kind:`string`,value:t.path.join(`.`),span:t.span};case`call`:return t.name===`now`&&t.args.length===0?{kind:`now`,span:t.span}:D(e,`${t.name}() cannot be used as a value`,`Only now() is a value function`,t.span);case`binary`:{let n=t.left;return n.kind===`call`&&n.name===`now`&&n.args.length===0&&t.right.kind===`duration`?{kind:`now`,offset:{sign:t.op,duration:t.right},span:t.span}:D(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},Te=(e,t)=>(`kind`in t&&[`member`,`call`,`binary`].includes(t.kind)?void 0:t)||(t.kind===`member`?{kind:`string`,value:t.path.join(`.`),span:t.span}:D(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),Ee=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`string`:case`timestamp`:return e.kind,e.value;case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;default:return``}},De=e=>[`sequence`,`and`,`or`,`not`,`compare`,`has`,`present`,`global`,`call`].includes(e.kind),Oe=e=>{let[t,n,r,...i]=e;if(!(i.length>0)&&!(t&&t.kind!==`string`)&&!(n&&(n.kind!==`number`||!Number.isSafeInteger(n.value)||n.value<1))&&!(r&&r.kind!==`string`))return{...t?.kind===`string`&&{orderBy:t.value},...n?.kind===`number`&&{limit:n.value},...r?.kind===`string`&&{pageToken:r.value}}},ke=(e,t,n,r)=>{let[,i,...a]=t.args,o=`related(field, resource.field, (filter), "order_by", limit, "page_token"), each after the field optional`;if(!n||i?.kind!==`member`||i.path.length!==2)return r(o);let s=a[0]&&De(a[0])?a[0]:void 0,c=Oe(s?a.slice(1):a);if(!c)return r(o);let l={kind:`related`,field:n,resource:i.path[0],key:i.path[1],...c,span:t.span};if(!s)return l;let u=k(e,s);return u&&{...l,filter:u}},Ae=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?O(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(T(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>Te(e,t));return!a||n.length===0?s(`in(field, value1, value2, ...)`):n.every(e=>e)?{kind:`in`,field:a,values:n,span:t.span}:void 0}case`search`:return o(n)!==void 0&&!r?{kind:`search`,text:o(n),span:t.span}:s(`search("text")`);case`similar`:return a&&o(r)!==void 0&&i.length===0?{kind:`similar`,field:a,text:o(r),span:t.span}:s(`similar(field, "text")`);case`regex`:return a&&o(r)!==void 0&&i.length===0?{kind:`regex`,field:a,pattern:o(r),span:t.span}:s(`regex(field, "pattern")`);case`isNull`:return a&&!r?{kind:`isNull`,field:a,span:t.span}:s(`isNull(field)`);case`related`:return ke(e,t,a,s);default:e.errors.push(T(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(f).join(`, `)}`,t.span));return}},je=e=>e.every(e=>e)?e:void 0,k=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=je(t.args.map(t=>k(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=k(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=O(e,t.left),r=we(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=O(e,t.left),r=Te(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=O(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:Ee(t.value),span:t.span};case`call`:return Ae(e,t)}},Me=(e,t={})=>{let n=i(e,{...p,...t}),r={errors:[]},a=n.ast&&k(r,n.ast),o=[...n.errors,...r.errors].sort((e,t)=>e.span.start-t.span.start);return o.length===0?{ok:!0,ast:a,errors:[]}:{ok:!1,ast:a,errors:o}},Ne=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,Pe=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])];return r>=1&&r<=12&&i>=1&&i<=Ne(n,r)},Fe=e=>{let t=/^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[2]),Number(t[3]),Number(t[4])],[a,o]=[Number(t[5]??0),Number(t[6]??0)];return Pe(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},A=(e,t)=>({message:e,hint:t}),Ie=-(2n**63n),Le=2n**63n-1n,Re=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ze=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,j=(e,t=`Write ${e} values like the examples in the docs`)=>A(`Expected ${e}`,t),Be=e=>{let t=ze(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return j(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},Ve=e=>{let t=ze(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<Ie||BigInt(t)>Le)return j(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},He=e=>{let t=ze(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return j(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},Ue=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:A(`now() only works with date and timestamp fields`,`Field "${e.name}" is ${e.type}`);switch(e.type){case`text`:return t.kind===`string`?void 0:j(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return Be(t);case`bigint`:return Ve(t);case`decimal`:return He(t);case`boolean`:return t.kind===`boolean`?void 0:j(`true or false`);case`date`:return t.kind===`string`&&Pe(t.value)?void 0:j(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&Fe(t.value)?void 0:j(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&Re.test(t.value)?void 0:j(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:A(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:j(`an ISO 4217 currency code`,`Use three capital letters, for example "EUR"`);case`country`:return t.kind===`string`&&/^[A-Z]{2}$/.test(t.value)?void 0:j(`an ISO 3166-1 country code`,`Use two capital letters, for example "NL"`);case`relation`:return t.kind===`string`||t.kind===`number`&&Number.isSafeInteger(t.value)?void 0:j(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return A(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},We=[`=`,`!=`],Ge=[`=`,`!=`,`<`,`<=`,`>`,`>=`],Ke=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return Ge;case`json`:case`file`:return[];default:return We}},qe=e=>e===`json`||e===`file`,Je=e=>T(`unsupported-traversal`,`related() only works in a list's filter, ANDed with the rest`,`Put it at the top of the filter or of a subfilter, joined with AND`,e),Ye=(e,t,n)=>{let r=Ue(t,n);return r&&e.errors.push(T(`invalid-value`,r.message,r.hint,n.span)),!r},M=(e,t,n,r)=>{e.errors.push(T(`operator-not-allowed`,t,n,r))},Xe=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Ze=(e,t)=>{let n=E(e,t.field,`filterable`);if(!n)return;let r=Ke(n.type);if(!r.includes(t.op)){M(e,`Operator "${t.op}" is not supported for ${n.type} fields`,r.length?`Supported: ${r.join(` `)}`:`Use field:value on json fields, or isNull(field)`,t.span);return}if(Xe(t.op,t.value)&&n.type!==`text`){e.errors.push(T(`wildcard-not-allowed`,`Wildcards are only supported on text fields, not ${n.type}`,`Remove the "*" or filter a text field`,t.value.span));return}if(Xe(t.op,t.value)||Ye(e,n,t.value))return{...t,field:n}},Qe=(e,t)=>{let n=E(e,t.field,`filterable`);if(n){if(n.type!==`json`){M(e,`":" is only supported on json fields, not ${n.type}`,`Use = on ${n.type} fields, or field:* to test for a value`,t.span);return}return{...t,field:n}}},$e=(e,t)=>{let n=E(e,t.field,`filterable`);if(n){if(qe(n.type)){M(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>Ye(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},et=(e,t,n)=>{let r=E(e,n,`filterable`);if(r&&r.type!==`text`){M(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},tt=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>tt(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=tt(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Ze(e,t);case`has`:return Qe(e,t);case`in`:return $e(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(T(`no-search-fields`,`This resource has no search fields`,`Declare them with .search((r) => [r.title]) in data.ts`,t.span));return;case`present`:case`isNull`:{let n=E(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=et(e,t.kind,t.field);return n&&{...t,field:n}}case`related`:e.errors.push(Je(t.span));return}},nt=(e,t)=>{let n={model:e,errors:[]},r=tt(n,t);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,filter:r}},rt=(e,t)=>{let n=nt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=s(v(t),m(e));return r.ok?nt(e,t):{ok:!1,errors:r.errors}},it=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),at=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),ot=e=>{let t=a(at(e)),n=t.items.map(e=>({path:{kind:`field`,path:e.path,span:e.span},direction:e.direction,span:e.span}));return t.ok?{ok:!0,items:n,errors:[]}:{ok:!1,items:n,errors:t.errors}},st=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>T(`unsupported-traversal`,`Traversal into "${e.path.path.join(`.`)}" is not supported yet`,`Sort on fields of this resource only`,e.path.span));if(n.length>0)return{ok:!1,errors:n};let r=o(it(t),m(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},ct=e=>{let t=/^(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([smhdw])$/.exec(e);if(!t)throw Error(`Invalid duration "${e}", expected for example 30d or 1.5h`);return{kind:`duration`,amount:Number(t[1]),unit:t[2],span:{start:0,end:0}}},N={start:0,end:0},P=e=>({kind:`field`,path:e.split(`.`),span:N}),lt=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:N};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:N};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:N}},ut=e=>typeof e==`object`?e:lt(e),dt=(e,t)=>{if(t.length===0)throw Error(`where.${e} needs at least one filter`);return t.length===1?t[0]:{kind:e,args:t,span:N}},ft=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:P(t),value:ut(n),span:N}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:ct(t)},span:N});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>dt(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:P(e),value:lt(t),span:N}),present:e=>({kind:`present`,field:P(e),span:N}),in:(e,t)=>({kind:`in`,field:P(e),values:t.map(lt),span:N}),isNull:e=>({kind:`isNull`,field:P(e),span:N}),search:e=>({kind:`search`,text:e,span:N}),similar:(e,t)=>({kind:`similar`,field:P(e),text:t,span:N}),regex:(e,t)=>({kind:`regex`,field:P(e),pattern:t,span:N}),related:(e,t,n,r,i)=>({kind:`related`,field:P(e),resource:t,key:n,...r&&{filter:r},...i,span:N}),and:(...e)=>dt(`and`,e),or:(...e)=>dt(`or`,e),not:e=>({kind:`not`,arg:e,span:N}),now:()=>({kind:`now`,span:N}),ago:t(`-`),fromNow:t(`+`)}},pt=ft(),mt=Symbol(`protobase.ref`),ht=e=>Object.defineProperty({name:e},mt,{value:!0}),gt=e=>typeof e==`object`&&!!e&&e[mt]===!0,_t=(e,t)=>new Proxy({},{get:(n,r)=>{if(typeof r!=`symbol`){if(t&&!t.includes(r))throw Error(`Unknown field "${r}"`);return e(r)}}}),vt=e=>({$field:e}),yt=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,bt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xt=e=>gt(e)?vt(e.name):Array.isArray(e)?e.map(xt):bt(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,xt(t)])):e,St=e=>yt(e)?e.$field:Array.isArray(e)?e.map(St):bt(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,St(t)])):e,Ct=e=>yt(e)?[e.$field]:Array.isArray(e)?e.flatMap(Ct):bt(e)?Object.values(e).flatMap(Ct):[],F=({label:e,icon:t})=>({...e!==void 0&&{label:e},...t!==void 0&&{icon:t}}),I=`table`,wt=(e,t)=>{if(!e.custom)throw Error(`${t} takes a component declared with component(...), not the built-in block ${e.blockName}`);return e.blockName},Tt={cards:(e,t={})=>({kind:`cards`,name:t.name??`cards`,...F(t),...e.image&&{image:e.image.name},...e.title&&{title:e.title.name},...e.subtitle&&{subtitle:e.subtitle.name},...e.amount&&{amount:e.amount.map(e=>e.name)},...e.badge&&{badge:e.badge.name},...e.code&&{code:e.code.name},...e.meta&&{meta:e.meta.map(e=>e.name)},...e.footer&&{footer:e.footer.map(e=>e.name)},...e.flags&&{flags:e.flags.map(e=>e.name)},...e.dots&&{dots:e.dots.map(e=>e.name)},...t.card&&{card:wt(t.card,`d.cards card`)},...t.photos&&{photos:{...t.photos}},...t.favorite&&{favorite:{...t.favorite}}}),map:(e,t={})=>({kind:`map`,name:t.name??`map`,...F(t),latitude:e.latitude.name,longitude:e.longitude.name,...t.cards!==void 0&&{cards:t.cards},...e.approximate&&{approximate:e.approximate.name},...e.exact&&{exact:e.exact.name},...e.radius&&{radius:e.radius.name},...t.defaultRadius!==void 0&&{defaultRadius:t.defaultRadius},...e.area&&{area:e.area.name}}),board:(e,t={})=>({kind:`board`,name:t.name??`board`,...F(t),by:e.by.name,...e.title&&{title:e.title.name},...e.subtitle&&{subtitle:e.subtitle.name},...e.badge&&{badge:e.badge.name},...e.meta&&{meta:e.meta.map(e=>e.name)}}),calendar:(e,t={})=>({kind:`calendar`,name:t.name??`calendar`,...F(t),start:e.start.name,...e.end&&{end:e.end.name},...e.title&&{title:e.title.name}}),timeline:(e,t={})=>({kind:`timeline`,name:t.name??`timeline`,...F(t),start:e.start.name,...e.end&&{end:e.end.name},...e.group&&{group:e.group.name},...e.title&&{title:e.title.name}}),custom:(e,t)=>({kind:`custom`,name:t.name,label:t.label,...F({icon:t.icon}),component:wt(e,`d.custom`),fields:t.fields.map(e=>e.name),...t.props&&{props:xt(t.props)}})},Et=/^[a-z][a-zA-Z0-9-]*$/,Dt=e=>{let t=(e.displays??[]).map(e=>e.name);return[...t.filter(e=>!Et.test(e)).map(e=>`display name "${e}" must start with a lowercase letter and hold only letters, digits and dashes`),...t.filter(e=>e===I).map(()=>`"${I}" is the list's own display; give the display another name`),...t.filter((e,n)=>t.indexOf(e)!==n).map(e=>`display "${e}" is defined twice`),...(e.displays??[]).flatMap(t=>t.kind===`map`&&t.cards!==void 0&&!e.displays.some(e=>e.kind===`cards`&&e.name===t.cards)?[`display "${t.name}" names cards "${t.cards}", which is not a cards display of the list`]:[]),...(e.displays??[]).flatMap(t=>t.kind===`cards`?(t.dots??[]).filter(t=>!e.relatedColumns?.some(e=>e.name===t)).map(e=>`display "${t.name}" shows dots of "${e}", which is not a related column of the list`):[]),...(e.displays??[]).flatMap(e=>e.kind===`map`?Ot(e).map(t=>`display "${e.name}": ${t}`):[]),...e.default===void 0||e.default===`table`||t.includes(e.default)?[]:[`default "${e.default}" is not one of the displays (${[I,...t].join(`, `)})`]]},Ot=e=>{let{approximate:t,exact:n,radius:r,defaultRadius:i,area:a}=e;return t!==void 0&&n!==void 0?[`name approximate or exact, not both`]:[...(r!==void 0||i!==void 0||a!==void 0)&&t===void 0&&n===void 0?[`an area around approximate positions needs the approximate or exact field`]:[],...i===void 0||Number.isFinite(i)&&i>0?[]:[`defaultRadius ${i} is not a number of metres above 0`]]},kt=(e,t)=>{let n=Object.hasOwn(t.fields,e.by)?t.fields[e.by]:void 0;return n?n.type===`enum`?n.filterable?[]:[`"${e.by}" on ${t.name} is not filterable, and each column of the board filters by its value`]:[`"${e.by}" on ${t.name} is ${n.type}, not an enum, whose values are the board's columns`]:[]},At=(e,t)=>{let n=e=>Object.hasOwn(t.fields,e)?t.fields[e]:void 0,r=n(e.start),i=e.end===void 0?void 0:n(e.end);if(!r)return[];if(r.type!==`date`&&r.type!==`timestamp`)return[`start "${e.start}" on ${t.name} is ${r.type}, not a date or timestamp`];let a=n=>`${n===e.start?`start`:`end`} "${n}" on ${t.name} is not filterable, and the ${e.kind} filters by it for the days it shows`;return[...r.filterable?[]:[a(e.start)],...i&&i.type!==r.type?[`end "${e.end}" on ${t.name} is ${i.type}, not ${r.type} like start "${e.start}"`]:[],...i&&i.type===r.type&&!i.filterable?[a(e.end)]:[]]},jt=e=>e.kind===`map`?[e.latitude,e.longitude,e.approximate,e.exact,e.radius,e.area].filter(e=>e!==void 0):e.kind===`custom`?[...e.fields,...Ct(e.props)]:e.kind===`board`?[e.by,e.title,e.subtitle,e.badge,...e.meta??[]].filter(e=>e!==void 0):e.kind===`calendar`?[e.start,e.end,e.title].filter(e=>e!==void 0):e.kind===`timeline`?[e.start,e.end,e.group,e.title].filter(e=>e!==void 0):[e.image,e.title,e.subtitle,...e.amount??[],e.badge,e.code,...e.meta??[],...e.footer??[],...e.flags??[]].filter(e=>e!==void 0),Mt=(e,t)=>{if(t===void 0)return e;let n=e?.lists?.find(e=>e.name===t);if(!e||!n)return;let{list:r,chart:i,help:a,nav:o,lists:s,names:c,...l}=e,{name:u,...d}=n;return{...l,...d}},Nt=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Pt=e=>e.replace(/(["']?)\{\{\s*[^{}]*?\s*\}\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Ft=(e,t)=>{let n=ie(t);if(n.length>0)return n.map(e=>`filter: "{{${e}}}" sits inside a longer quoted value; quote it alone, such as title = "{{${e}}}"`);let r=Me(Pt(t));if(!r.ok)return r.errors.map(e=>`filter: ${e.message}`);if(!r.ast)return[];let i=rt(e,r.ast);return i.ok?[]:i.errors.filter(e=>Nt.includes(e.code)).map(e=>`filter: ${e.message}`)},It=(e,t)=>{if(se({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=ot(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=st(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Lt=(e,{models:t,pages:n,source:r,placeholderError:i,createPages:a,filterFromRecord:o})=>{let s=se(e).flatMap(e=>{if(i){let t=i(e);return t===void 0?[]:[t]}return r?Object.hasOwn(r.fields,e)?[]:[`"{{${e}}}" is not a field of ${r.name}`]:[`"{{${e}}}" takes a value from the record, but the link sits on none`]}),c=o===!0&&ce(e)!==void 0;if(e.kind!==`page`&&ue(e)!==void 0){if(!(e.kind===`list`?e.filter!==void 0&&!c||e.orderBy!==void 0:e.kind===`create`&&e.values!==void 0))return s;let t=o?`no order or values, and a filter only as one field, such as filter: '{{filter}}'`:`no filter, order or values`;return[...s,`a link whose resource comes from the record ("${e.resource}") names ${t}`]}switch(e.kind){case`page`:return n&&!n.has(e.page)?[...s,`unknown page "${e.page}"`]:s;case`list`:case`record`:case`create`:{let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;return n?e.kind===`create`&&a?.has(e.resource)?s:e.kind===`create`?[...s,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...s,...e.filter&&!c?Ft(n,e.filter):[],...e.orderBy?It(n,e.orderBy):[]]:s:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Rt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),zt=`a row button is { label, to } or { label, href }, such as { label: 'Open', to: { kind: 'record', resource: 'tasks', key: '{{id}}' } } or { label: 'Report', href: '{{report_url}}' }, or a list of them`,Bt=e=>Array.isArray(e)?e:[e],Vt=e=>{let t=e.href;return t===void 0?{to:e.to}:{href:t}},Ht=e=>{let t=Vt(e);return[...new Set([...w(e.label),...`href`in t?w(t.href):se(t.to)])]},Ut=e=>[...new Set(Bt(e).flatMap(Ht))],Wt=(e,t,n)=>e.flatMap(e=>Object.hasOwn(t.fields,e)?[]:[`${n}: "{{${e}}}" is not a field of ${t.name}`]),Gt=(e,t,n)=>{if(!Rt(e))return[zt];if(typeof e.label!=`string`||e.label.trim()===``)return[`a row button needs a label`];if(e.to!==void 0&&e.href!==void 0)return["a row button opens an address in `to` or an outside page in `href`, not both"];let r=Wt(w(e.label),t,`label`);if(e.href!==void 0){let n=typeof e.href==`string`?ne(e.href):void 0;return n===void 0?[...r,`href: a row button's href is the one field that holds the page's https URL, such as '{{report_url}}'`]:[...r,...Wt([n],t,`href`)]}return!Rt(e.to)||typeof e.to.kind!=`string`?["a row button needs an address in `to`, such as { kind: 'record', resource: 'tasks', key: '{{id}}' }, or an outside page in `href`"]:[...r,...Lt(e.to,{...n,source:t,filterFromRecord:!0}).map(e=>`to: ${e}`)]},Kt=(e,t,n)=>Array.isArray(e)?e.length===0?[`a row button list needs at least one choice`]:e.flatMap((e,r)=>Gt(e,t,n).map(e=>`choice ${r+1}: ${e}`)):Gt(e,t,n),qt=(e,t,n)=>{if(!Array.isArray(e))return Kt(e,t,n).length===0?e:void 0;let r=Bt(e).filter(e=>Gt(e,t,n).length===0);return r.length===0?void 0:r},Jt=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],Yt=e=>e?.type===`text`&&!e.sensitive,Xt=(e,t)=>t?.title??Jt.find(t=>Yt(e.fields[t]))??Object.values(e.fields).find(Yt)?.name??e.primaryKey[0],L=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??Xt(e),Zt=(e,t,n,r)=>{let i=L(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?ae(String(a),t?.fields[i]?.valueLabels):String(a)},Qt=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),R=e(t(),1),z=e(n(),1),$t=(0,R.createContext)([]),en=({name:e,children:t})=>{let n=(0,R.useContext)($t),r=(0,R.useMemo)(()=>[...n,e],[n,e]);return(0,z.jsx)($t.Provider,{value:r,children:t})},tn=()=>(0,R.useContext)($t),nn=(e,t,n)=>{let r=new URL(e,`http://local`),i=new URL(t,`http://local`);return r.pathname!==i.pathname||[...n].some(e=>e.params.some(e=>r.searchParams.get(e)!==i.searchParams.get(e)))},rn=(e,{replace:t=!1,keepScroll:n=!1}={})=>({kind:`link`,full:e,replace:t,keepScroll:n}),an=(e,t)=>t(e.full,e.replace,e.keepScroll),on=`protobase:page-places`,sn=50,cn=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,ln=e=>r(()=>{let t=e.getItem(on);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(cn):[]},[]),un=e=>{let t=new Map(ln(e));return{placeOf:e=>t.get(e)??0,save:(e,n)=>{t.delete(e),t.set(e,Math.max(0,Math.round(n)));for(let e of[...t.keys()].slice(0,Math.max(0,t.size-sn)))t.delete(e)},persist:()=>r(()=>e.setItem(on,JSON.stringify([...t])),void 0)}},dn=3e3,fn=e=>{let t=0,n=()=>(window.scrollTo({top:e,behavior:`instant`}),t=window.scrollY,t>=e-1);if(n())return()=>{};let r=new ResizeObserver(()=>n()&&a()),i=()=>Math.abs(window.scrollY-t)>1&&a(),a=()=>{r.disconnect(),clearTimeout(o),window.removeEventListener(`scroll`,i)},o=setTimeout(a,dn);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},pn=(0,R.createContext)(null),B=()=>{let e=(0,R.useContext)(pn);if(!e)throw Error(`useRouter must be used inside Router`);return e},mn=()=>`${window.location.pathname}${window.location.search}`,hn=e=>new URL(e,`http://local`).pathname,V=()=>window.history.state??{},gn=()=>V().protobaseIndex??0,_n=()=>Math.random().toString(36).slice(2),vn=()=>{let e=V();if(e.protobaseEntry)return e.protobaseEntry;let t=_n();return window.history.replaceState({...e,protobaseEntry:t},``),t},yn={getItem:()=>null,setItem:()=>{}},bn=({basePath:e=``,initialUrl:t,children:n})=>{let i=t!==void 0,[a,o]=(0,R.useState)(()=>({url:t??mn(),entry:i?_n():vn()})),[s]=(0,R.useState)(()=>un(i?yn:r(()=>window.sessionStorage,void 0)??yn)),c=(0,R.useRef)(new Map),l=()=>[...c.current.values()].some(e=>e.kind===`input-lost`),u=(0,R.useRef)(a);u.current=a;let d=(0,R.useRef)(i?0:gn()),f=(0,R.useRef)(!1),p=(0,R.useRef)(!1),m=(0,R.useRef)(void 0),h=(0,R.useRef)(!1),[g,v]=(0,R.useState)(),y=(0,R.useCallback)(()=>s.save(u.current.entry,window.scrollY),[s]);(0,R.useLayoutEffect)(()=>fn(s.placeOf(a.entry)),[s,a.entry]),(0,R.useEffect)(()=>{if(i)return;window.history.scrollRestoration=`manual`,window.history.replaceState({...V(),protobaseIndex:d.current,protobaseEntry:u.current.entry},``);let e=()=>{y(),s.persist()},t=()=>document.visibilityState===`hidden`&&e();window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t);let n=()=>{let e=gn();if(f.current){f.current=!1,d.current=e,m.current!==void 0&&window.history.go(m.current),m.current=void 0;return}let t=e-d.current;if(!p.current&&c.current.size>0&&nn(u.current.url,mn(),c.current.values())){f.current=!0,window.history.go(-t),v({kind:`history`,delta:t,inputLost:l()});return}p.current=!1,d.current=e,y(),o({url:mn(),entry:vn()})};return window.addEventListener(`popstate`,n),()=>{window.removeEventListener(`popstate`,n),window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[i,y,s]);let b=(0,R.useCallback)((e,t,n=!1)=>{let r=t?u.current.entry:_n();if(!i){d.current+=+!t;let n=t?V().protobasePrevious:u.current.url;window.history[t?`replaceState`:`pushState`]({protobaseIndex:d.current,protobaseEntry:r,protobasePrevious:n},``,e)}y(),n&&s.save(r,window.scrollY),o({url:e,entry:r})},[i,y,s]),x=(0,R.useCallback)((t,n)=>{let r=rn(`${e}${t}`,n);if(c.current.size>0&&nn(u.current.url,r.full,c.current.values()))return v({...r,inputLost:l()});an(r,b)},[e,b]),ee=(0,R.useCallback)(t=>{let n=i?void 0:V().protobasePrevious;if(n!==void 0&&hn(n)===hn(`${e}${t}`))return window.history.back();x(t)},[i,e,x]),te=(0,R.useCallback)((e=`draft-kept`,t=[])=>{let n=Symbol(`guard`);return c.current.set(n,{kind:e,params:t}),()=>void c.current.delete(n)},[]),ne=(0,R.useCallback)(()=>{if(c.current.size>0)return v({kind:`reload`,inputLost:l()});window.location.reload()},[]),re=(0,R.useCallback)(()=>h.current,[]),ie=(0,R.useCallback)(()=>c.current.size>0,[]),C=()=>{if(g){if(v(void 0),g.kind===`link`)return an(g,b);if(g.kind===`reload`)return h.current=!0,window.location.reload();p.current=!0,f.current?m.current=g.delta:window.history.go(g.delta)}},ae=(0,R.useMemo)(()=>{let t=new URL(a.url,`http://local`);return{path:t.pathname.slice(e.length)||`/`,params:t.searchParams,basePath:e,entry:a.entry,navigate:x,back:ee,registerGuard:te,reload:ne,reloadConfirmed:re,holdsChanges:ie}},[a,e,x,ee,te,ne,re,ie]);return(0,z.jsxs)(pn.Provider,{value:ae,children:[n,g?.kind===`reload`&&(0,z.jsx)(ve,{title:S(`reloadTitle`),description:S(g.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>v(void 0),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(_,{onClick:()=>v(void 0),children:S(`keepEditing`)}),(0,z.jsx)(_,{variant:`primary`,onClick:C,children:S(`reload`)})]})}),g&&g.kind!==`reload`&&(0,z.jsx)(ve,{title:S(`leaveTitle`),description:S(g.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>v(void 0),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(_,{onClick:()=>v(void 0),children:S(`stay`)}),(0,z.jsx)(_,{variant:`primary`,onClick:C,children:S(`leave`)})]})})]})},xn=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=B();return(0,z.jsx)(re,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},Sn=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=B(),i=tn();(0,R.useEffect)(()=>e?n(t,i):void 0,[e,t,i,n]),(0,R.useEffect)(()=>{if(!e)return;let t=e=>{r()||e.preventDefault()};return window.addEventListener(`beforeunload`,t),()=>window.removeEventListener(`beforeunload`,t)},[e,r])},H={list:`list`,filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,calendar:`calendar`,timeline:`timeline`,savedSearch:`saved_search`,create:`new`,edit:`edit`,open:`open`,tab:`tab`,standard:`standard`,call:`call`,version:`version`,run:`run`,panel:`panel`,file:`file`},Cn=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],wn=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Tn=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,En=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Tn(n,90)&&Tn(r,180)&&Tn(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Dn=e=>`${e.scale},${e.day}`,On=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=t.slice(1).map(Number),a=new Date(Date.UTC(n,r-1,i));return a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i},kn=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&On(i)?{scale:r,day:i}:void 0},An=e=>{let t=new URLSearchParams;for(let n of Cn){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(H[n],r)}e.map&&t.set(H.map,wn(e.map)),e.calendar&&t.set(H.calendar,Dn(e.calendar)),e.timeline&&t.set(H.timeline,Dn(e.timeline));let n=t.toString();return n?`?${n}`:``},jn=e=>{let t=new URLSearchParams;e.edit&&t.set(H.edit,`true`);for(let n of e.open??[])t.append(H.open,n);e.tab&&t.set(H.tab,e.tab),e.standard&&t.set(H.standard,`true`),e.call&&t.set(H.call,e.call),e.version!==void 0&&t.set(H.version,String(e.version)),e.run&&t.set(H.run,e.run),e.panel&&t.set(H.panel,e.panel),e.file&&t.set(H.file,e.file);let n=t.toString();return n?`?${n}`:``},U=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}${Nn(e.params)}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${H.create}${Nn(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(y(e.key))}${jn(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${An(e)}`}},Mn=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Nn=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Pn=e=>e!==null&&/^[1-9]\d{0,8}$/.test(e)?Number(e):void 0,Fn=e=>e===`bar`||e===`panel`?e:void 0,In=(e,t)=>{let n=new URL(e,`http://app`),r=Mn(n.pathname);if(!r||r.length===0||r.length>2)return;let[i,a]=r;if(i===`-`)return;if(t.has(i)){let e=Object.fromEntries([...n.searchParams].filter(([,e])=>e!==``));return{kind:`page`,page:i,...a!==void 0&&{tab:a},...Object.keys(e).length>0&&{params:e}}}if(a===H.create){let e=Object.fromEntries([...n.searchParams].filter(([,e])=>e!==``));return{kind:`create`,resource:i,...Object.keys(e).length>0&&{values:e}}}if(a!==void 0){let e=[...new Set(n.searchParams.getAll(H.open).filter(e=>e!==``))],t=n.searchParams.get(H.tab)||void 0,r=n.searchParams.get(H.standard)===`true`,o=n.searchParams.get(H.call)===`join`,s=Pn(n.searchParams.get(H.version)),c=n.searchParams.get(H.run)||void 0,l=n.searchParams.get(H.panel)||void 0,u=n.searchParams.get(H.file)||void 0;return{kind:`record`,resource:i,key:a,...n.searchParams.get(H.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t},...r&&{standard:r},...o&&{call:`join`},...s!==void 0&&{version:s},...c&&{run:c},...l&&{panel:l},...u&&{file:u}}}let o=n.searchParams,s=o.get(H.list)||void 0,c=o.get(H.display)||void 0,l=o.get(H.filter)??void 0,u=o.get(H.orderBy)||void 0,d=Fn(o.get(H.filterLayout)),f=En(o.get(H.map)),p=kn(o.get(H.calendar),[`month`,`week`]),m=kn(o.get(H.timeline),[`week`,`month`,`quarter`]),h=o.get(H.savedSearch)||void 0;return{kind:`list`,resource:i,...s&&{list:s},...c&&{display:c},...l!==void 0&&{filter:l},...u&&{orderBy:u},...d&&{filterLayout:d},...f&&{map:f},...p&&{calendar:p},...m&&{timeline:m},...h&&{savedSearch:h}}},Ln=e=>typeof e==`string`?e:e.toModel().name,Rn=(e,t)=>{let n=n=>t(Ln(n))??e;return{list:(e,t)=>n(e).list(e,t),search:(e,t)=>n(e).search(e,t),get:(e,t)=>n(e).get(e,t),create:(e,t)=>n(e).create(e,t),update:(e,t,r,i)=>n(e).update(e,t,r,i),remove:(e,t,r)=>n(e).remove(e,t,r),undelete:(e,t)=>n(e).undelete(e,t),generate:(e,t,r)=>n(e).generate(e,t,r),reveal:(e,t,r)=>n(e).reveal(e,t,r),history:(e,t,r)=>n(e).history(e,t,r),comments:(e,t,r)=>n(e).comments(e,t,r),comment:(e,t,r)=>n(e).comment(e,t,r),mentionable:(e,t,r)=>n(e).mentionable(e,t,r),batchWrite:t=>{let r=[...new Set(t.map(e=>n(e.resource)))];return r.length>1?Promise.reject(Error(`A batch writes to one API, but these writes are for ${[...new Set(t.map(e=>Ln(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),aggregate:(e,t)=>n(e).aggregate(e,t),series:(e,t)=>n(e).series(e,t),histogram:(e,t,r)=>n(e).histogram(e,t,r),map:(e,t)=>n(e).map(e,t),seek:(e,t)=>n(e).seek(e,t),meta:(t,n)=>e.meta(t,n),fileReadUrl:(e,t)=>n(e).fileReadUrl(e,t),invoke:(t,n)=>e.invoke(t,n),upload:(e,t,r,i)=>n(e).upload(e,t,r,i),form:t=>e.form(t),formChallenge:t=>e.formChallenge(t),submitForm:(t,n,r)=>e.submitForm(t,n,r),live:t=>e.live(t),channel:(t,n)=>e.channel(t,n),bridges:e.bridges,devices:e.devices,notifications:e.notifications,status:e.status,rings:e.rings,callGuests:e.callGuests,calls:(e,t)=>n(e).calls(e,t),watchCalls:(e,t,r)=>n(e).watchCalls(e,t,r),workflowTypes:()=>n(`workflows`).workflowTypes(),workflowRunTrace:(e,t)=>n(`workflow_runs`).workflowRunTrace(e,t),runnerRegistration:e=>n(`workflow_runners`).runnerRegistration(e)}},W=Symbol(`recorded`),zn=[],Bn=0,Vn=0,Hn=e=>{if(Vn===0)throw Error(`A record block's children are a function of its record only inside a typed layout: layout(), recordLayout() or defineTemplate()`);Bn+=1;let t=Bn;zn.push(t);try{return{scope:t,built:e(t)}}finally{zn.pop()}},Un=new WeakMap,Wn=(e,t)=>{Un.set(e,t)},Gn=(e,t)=>{let n=Un.get(e);n!==void 0&&Un.set(t,n)},Kn=/^\d+[smhdw]$/,qn=class e{offset;constructor(e){this.offset=e}plus(t){return new e({sign:`+`,duration:Jn(t)})}minus(t){return new e({sign:`-`,duration:Jn(t)})}toString(){return this.offset?`now() ${this.offset.sign} ${this.offset.duration}`:`now()`}},Jn=e=>{if(!Kn.test(e))throw Error(`"${e}" is not a duration: write a number and s, m, h, d or w, such as '7d'`);return e},G=class{text;op;constructor(e,t){this.text=e,this.op=t}and(e){return Yn(`and`,this,e)}or(e){return Yn(`or`,this,e)}toString(){return this.text}},Yn=(e,t,n)=>{let r=t=>t.op===`term`||t.op===e?t.text:`(${t.text})`;return new G(`${r(t)} ${e.toUpperCase()} ${r(n)}`,e)},Xn=e=>(typeof e==`object`||typeof e==`function`)&&e!==null&&W in e,K=e=>`{{~${e[W].scope}~${e[W].path.join(`.`)}}}`,Zn=({path:e,scope:t})=>`~~${t}~${e.join(`.`)}~~`,q=e=>{if(Xn(e))return K(e);if(e instanceof qn)return e.toString();if(e instanceof Date)return JSON.stringify(e.toISOString());if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`&&Number.isFinite(e)||typeof e==`boolean`||e===null)return String(e);throw Error(`${String(e)} cannot be a filter value: compare with text, a number, true or false, null, now() or a recorded field`)},J=e=>new G(e,`term`),Qn=e=>({eq:t=>J(t===null?`isNull(${e})`:`${e} = ${q(t)}`),ne:t=>J(t===null?`NOT isNull(${e})`:`${e} != ${q(t)}`),lt:t=>J(`${e} < ${q(t)}`),le:t=>J(`${e} <= ${q(t)}`),gt:t=>J(`${e} > ${q(t)}`),ge:t=>J(`${e} >= ${q(t)}`),in:t=>J(`in(${e}, ${t.map(q).join(`, `)})`),contains:t=>J(`${e}:${q(t)}`),isNull:()=>J(`isNull(${e})`)}),$n=new Set(Object.keys(Qn(``))),er=(e=[],t=zn.at(-1)??0)=>new Proxy({},{get:(n,r)=>{if(r===W)return{path:e,scope:t};if(r===Symbol.toPrimitive||r===`toString`||r===`toJSON`)return()=>K({[W]:{path:e,scope:t}});if(typeof r!=`symbol`)return $n.has(r)?Qn(Zn({path:e,scope:t}))[r]:er([...e,r],t)},has:(e,t)=>t===W}),tr=(e=[])=>new Proxy({},{get:(t,n)=>{if(typeof n!=`symbol`)return $n.has(n)&&e.length>0?Qn(e.join(`.`))[n]:tr([...e,n])}}),nr=`Layouts are static data, sent to the browser as JSON: use <Action name="..."> for behaviour, or register a custom component for React code.`,rr=e=>typeof e==`function`?`a function`:typeof e==`number`?String(e):typeof e!=`object`||!e?`a ${typeof e}`:`a ${e.constructor?.name??`object without prototype`}`,ir=e=>{let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},ar=(e,t)=>{if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(Xn(e))return K(e);if(e instanceof G||e instanceof qn)return e.toString();if(typeof e==`number`&&Number.isFinite(e))return e;if(Array.isArray(e))return e.map((e,n)=>ar(e,`${t.slice(0,-1)}[${n}]>`));if(typeof e==`object`&&ir(e)){let n=Object.fromEntries(Object.entries(e).flatMap(([e,n])=>n===void 0?[]:[[e,ar(n,`${t.slice(0,-1)}.${e}>`)]]));return Gn(e,n),n}throw Error(`${t} is ${rr(e)}. ${nr}`)},Y=(e,t)=>{if(e==null||typeof e==`boolean`)return[];if(typeof e==`string`)return[e];if(Xn(e))return[K(e)];if(typeof e==`number`&&Number.isFinite(e))return[String(e)];if(Array.isArray(e))return e.flatMap(e=>Y(e,t));if(C(e))return e.type===`Fragment`&&!e.custom?e.children:[e];throw Error(`${t} has a child that is ${rr(e)}. ${nr}`)},or=e=>typeof e==`function`&&typeof e.blockName==`string`,sr=[`RecordCard`,`CardRow`,`ReferenceField`,`RecordsIterator`],cr=[`filter`,`edgeFilter`,`animated`,`dashed`,`dotted`],lr=(e,t)=>{let n={...t};for(let t of cr){let r=n[t];if(typeof r==`function`){let i=r(tr());if(!(i instanceof G))throw Error(`<${e} ${t}> is an arrow that gives no condition: write (f) => f.status.eq('open'), or the ${t} as AIP-160 text`);n[t]=i.text}else if(typeof r==`object`&&r&&!(r instanceof G))throw Error(`<${e} ${t}> is an object: write the ${t} as an arrow, (f) => f.status.eq('open'), or as AIP-160 text`)}if(n.sort!==void 0){if(!Array.isArray(n.sort)||!n.sort.every(e=>typeof e==`string`))throw Error(`<${e} sort> takes a list of fields, each with asc or desc if it likes: sort={['next_run_at asc']}`);n.sort=n.sort.join(`, `)}return n},ur=(e,t,n)=>{if(typeof t!=`function`)return{children:Y(t,n)};if(!sr.includes(e))throw Error(`<${e}> takes elements as children; only ${sr.join(`, `)} take a function of their record`);let{scope:r,built:i}=Hn(e=>Y(t(er([],e)),n));return{children:i,scope:r}},dr={Graph:`node`},fr=new Set([`Graph`]),pr=(e,t,n)=>{let r=`<${e} ${t}>`,i=e=>{let[t]=e;return e.length===1&&typeof t==`object`?t:{type:`Box`,props:{},children:e}};if(typeof n!=`function`)return{value:n===void 0||C(n)?n:i(Y(n,r))};let{scope:a,built:o}=Hn(e=>Y(n(er([],e)),r));return{value:i(o),scope:a}},mr=(e,t)=>{if(typeof e==`string`)throw Error(`<${e}> is an HTML element, not a layout block: use the blocks from @protobase/layout or a custom component`);if(!or(e))throw Error(`<${typeof e==`function`&&e.name?e.name:`unknown`}> is not a layout block. Components in a layout are declared with component('Name') and implemented in the app; ${nr}`);let n=e.blockName,{children:r,...i}=t,a=!e.custom&&fr.has(n),{fallback:o,...s}=i,c=a?s:i,l=e.custom?c:lr(n,c),u=e.custom?void 0:dr[n],d=u===void 0?void 0:pr(n,u,l[u]);u!==void 0&&(l[u]=d.value);let f=e.custom?{children:Y(r,`<${n}>`)}:ur(n,r,`<${n}>`),p={type:n,props:Object.fromEntries(Object.entries(l).flatMap(([e,t])=>t===void 0?[]:[[e,ar(t,`<${n} ${e}>`)]])),children:f.children},m=f.scope??d?.scope;return m!==void 0&&Wn(p,m),e.custom&&(p.custom=!0),e.fallback&&(p.fallback=e.fallback),a&&o!==void 0&&(p.fallback=Y(o,`<${n} fallback>`)),e.reads&&(p.reads=e.reads),p},hr=(e,t,n,r)=>{let i=Object.assign(e=>mr(i,e),{blockName:e,custom:t,...n&&{fallback:n},...r&&{reads:r}});return i},gr=(e,t,n)=>{let r=[],i=e[t],a=n.split(`.`);for(let[o,s]of a.entries()){if(!i)return{ok:!1,message:`unknown resource "${t}"`};let c=Object.hasOwn(i.fields,s)?i.fields[s]:void 0;if(!c)return{ok:!1,message:`unknown field "${a.slice(0,o+1).join(`.`)}" on ${i.name}`};if(r.push({model:i,field:c}),o===a.length-1)break;if(c.type!==`relation`||!c.relation)return{ok:!1,message:`"${a.slice(0,o+1).join(`.`)}" is not a relation, so "${n}" cannot go through it`};t=c.relation.resource,i=e[t]}return{ok:!0,steps:r}},_r=new Set([1,2,3,4,5,6]),vr=8,yr=(e,t)=>{for(let n of e){_r.has(n.type)&&n.value!==void 0&&t.values.add(n.value),n.type===vr&&n.value!==void 0&&t.tags.add(n.value);for(let e of Object.values(n.options??{}))yr(e.value,t);n.children&&yr(n.children,t)}},br=(e,t)=>{let n={values:new Set,tags:new Set};return yr(new l(e,t).getAst(),n),{values:[...n.values],tags:[...n.tags]}},xr=new Map,Sr=(e,t,n={},r={})=>{let i=e?.messages[t];if(i===void 0||!e)return t;let a=`${e.locale}\u0000${i}`,o=xr.get(a);return o||(o=new l(i,e.locale),xr.set(a,o)),o.format({...n,...r})},Cr=(e,t,n={})=>{let r=Sr(e,t,n,Object.fromEntries((e?.messages[t]?br(e.messages[t],e.locale).tags:[]).map(e=>[e,e=>e.join(``)])));return Array.isArray(r)?r.join(``):r};hr(`Trans`,!1);var wr=e=>C(e)&&e.type===`Trans`&&!e.custom,Tr=(e,t)=>({...e,fields:Object.fromEntries(Object.entries(e.fields).map(([e,n])=>{if(!n.relation||Object.hasOwn(t,n.relation.resource))return[e,n];let{relation:r,...i}=n;return[e,i]}))}),Er=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>Er(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>Er(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind!==`related`)return[e];if(!Object.hasOwn(t,e.resource)||e.through&&!Object.hasOwn(t,e.through.resource))return[];let{columns:n,button:r,...i}=e,a=n?.filter(n=>gr(t,e.resource,n).ok),o=a&&a.length>0?{...i,columns:a}:i,s=r===void 0?void 0:qt(r,t[e.resource],{models:t,pages:new Set});return[s===void 0?o:{...o,button:s}]},Dr=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Lt(e.run.to,{models:n,pages:new Set,source:t}).length===0,Or=(e,t)=>({...e,layout:e.layout.flatMap(e=>Er(e,t)),actions:e.actions.filter(n=>Dr(n,t[e.resource],t))}),kr=(e,t)=>{let n=e.resources.filter(e=>t.resources.includes(e.name)),r=Object.fromEntries(n.map(e=>[e.name,e])),i=n.map(e=>Tr(e,r)),a=Object.fromEntries(i.map(e=>[e.name,e]));return{resources:i,views:e.views.filter(e=>Object.hasOwn(a,e.resource)).map(e=>Or(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},Ar={create:!0,update:!0,delete:!0,conditional:[]},jr=1e4,Mr=e=>e.map(e=>({data:e.data?.meta,error:e.error})),Nr=(e,t)=>{let n=u(),r=c({queries:e.map(e=>{let r=te.sourceMeta(e.url,e.resources);return{queryKey:r,staleTime:0,refetchOnWindowFocus:`always`,queryFn:async()=>{let i=n.getQueryData(r),a=await t(e).meta(i?.etag,{signal:AbortSignal.timeout(jr)});if(a.status===`unchanged`){if(!i)throw Error(`${e.label} answered 304 to a request without If-None-Match`);return i}return{etag:a.etag,meta:kr(a.meta,e)}}}}),combine:Mr});return(0,R.useMemo)(()=>e.map((e,t)=>{let{data:n,error:i}=r[t];return n?{source:e,state:`ready`,meta:n}:i?{source:e,state:`error`,error:i}:{source:e,state:`loading`}}),[e,r])},Pr=(e,t)=>{if(t.length===0)return e;let n=t.flatMap(e=>e.state===`ready`?[e.meta]:[]),r=t.map(e=>e.state===`error`?{source:e.source,state:`error`,error:e.error}:{source:e.source,state:e.state});return{...e,resources:{...e.resources,...Object.fromEntries(n.flatMap(e=>e.resources.map(e=>[e.name,e])))},views:{...e.views,...Object.fromEntries(n.flatMap(e=>e.views.map(e=>[e.resource,e])))},permissions:{...e.permissions,...Object.assign({},...n.map(e=>e.permissions))},sources:r}},Fr=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),Ir=({locale:e,children:t})=>{me(e);let n=fe();return(0,R.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,z.jsx)(R.Fragment,{children:t},n)},Lr=(0,R.createContext)(void 0),Rr=()=>(0,R.useContext)(Lr),zr=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Br=(e,t)=>Cr(t,String(e.props.i18nKey),zr(e.props.values)?e.props.values:{}),Vr=(e,t)=>e.custom||!Object.values(e.props).some(wr)?e:{...e,props:Object.fromEntries(Object.entries(e.props).map(([e,n])=>[e,wr(n)?Br(n,t):n]))},Hr=(e,t)=>{let n=Vr(e,t);if(e.custom||e.type!==`Tabs`)return n;let r=n.children.map(e=>typeof e==`string`?e:Vr(e,t));return r.some((e,t)=>e!==n.children[t])?{...n,children:r}:n},Ur=`app/built-in-views`,Wr=pe(Ur),X=(e,t)=>Object.hasOwn(he.en[Ur],e)?Wr(e):t,Gr=(e,t)=>({...t,...t.label!==void 0&&{label:X(`${e}.label`,t.label)},...t.help!==void 0&&{help:X(`${e}.help`,t.help)},...t.valueLabels&&{valueLabels:Object.fromEntries(Object.entries(t.valueLabels).map(([t,n])=>[t,X(`${e}.values.${t}`,n)]))}}),Kr=(e,t)=>{let n=t;return{...t,...n.title!==void 0&&{title:X(`${e}.title`,n.title)},...n.help!==void 0&&{help:X(`${e}.help`,n.help)},...n.empty!==void 0&&{empty:X(`${e}.empty`,n.empty)}}},qr=e=>e.name===`record_history`&&e.table.name===`history`?`changes.history`:`${e.table.schema??`public`}.${e.table.name}`,Jr=(e,t)=>({...t,label:X(`${e}.label`,t.label),...t.confirm!==void 0&&{confirm:X(`${e}.confirm`,t.confirm)}}),Yr=(e,t)=>{if(!t)return e;let n=qr(t);return{...e,...e.names&&{names:{singular:X(`${n}.names.singular`,e.names.singular),plural:X(`${n}.names.plural`,e.names.plural)}},...e.help!==void 0&&{help:X(`${n}.help`,e.help)},fields:Object.fromEntries(Object.entries(e.fields).map(([e,t])=>[e,Gr(`${n}.fields.${e}`,t)])),layout:e.layout.map((e,t)=>Kr(`${n}.layout.${t}`,e)),actions:e.actions.map(e=>Jr(`${n}.actions.${e.name}`,e))}},Xr=e=>({...e,views:Object.fromEntries(Object.entries(e.views).map(([t,n])=>[t,Yr(n,e.resources[n.resource])]))}),Zr=e=>{let t=0,n=!1,r=!1,i=()=>queueMicrotask(()=>{!n||r||t>0||(r=!0,e())});return{hold:()=>{t+=1;let e=!1;return()=>{e||(e=!0,--t,i())}},start:()=>{n=!0,i()}}},Qr=(0,R.createContext)(void 0),$r=({value:e,children:t})=>(0,z.jsx)(Qr.Provider,{value:e,children:t}),ei=()=>{let e=(0,R.useContext)(Qr);return(0,R.useEffect)(()=>e?.hold(),[e]),null},Z=pe(`app/meta-gate`),ti=()=>{let e=(0,R.useContext)(_e);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},ni=({title:e,children:t})=>(0,z.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,z.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,z.jsx)(`h1`,{className:`text-base font-semibold`,children:e}),(0,z.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t})]})}),ri=({meta:e,children:t})=>{let n=ee(),r=x(),i=(0,R.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=Nr(i,r),o=(0,R.useMemo)(()=>Pr(e,a),[e,a]),s=(0,R.useMemo)(()=>{let e=new Map(i.flatMap(e=>e.resources.map(t=>[t,e]))),t=t=>{let n=e.get(t);return n&&r(n)};return{client:Rn(n,t),resourceClient:t}},[i,n,r]);return(0,z.jsx)(b,{client:s.client,resourceClient:s.resourceClient,children:(0,z.jsx)(Ir,{locale:e.locale,children:(0,z.jsx)(Lr.Provider,{value:e.texts,children:(0,z.jsx)(ii,{meta:o,children:t})})})})},ii=({meta:e,children:t})=>{let n=(0,R.useMemo)(()=>Xr(e),[e]);return(0,z.jsx)(_e.Provider,{value:n,children:t})},ai=({children:e})=>{let t=ye();return t.isPending?(0,z.jsxs)(`div`,{className:be(`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,oe),children:[(0,z.jsx)(ei,{}),(0,z.jsx)(h,{}),` `,Z(`loading`)]}):t.error?(0,z.jsx)(ni,{title:Z(`cannotReach`),children:g(t.error)?t.error.message:Z(`noAnswer`)}):(0,z.jsx)(ri,{meta:t.data,children:e})},oi=e=>ti().permissions[e]??Ar,si=e=>(0,R.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),ci=()=>si(`(min-width: 768px)`),li=()=>si(`not all and (min-width: 640px)`),ui=`$photos`,di=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},fi=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[ui]:n[String(e[r])]??[]}))},pi=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),Q=pe(`app/displays`),mi=(e,t,n)=>{let r=e.fields[n.by];if(!r)return[];let i=t?.fields[n.by],a=(r.enumValues??[]).map(e=>({value:e,label:ae(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:Q(`noValue`,{label:i?.label??ge(n.by)})}]:a},hi=e=>e.position&&e.position.within===void 0?e.position.field:void 0,gi=(e,t,n)=>{let r=d(n===null?pt.isNull(t):pt.eq(t,n));return e===``?r:`(${e}) AND ${r}`},_i=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??L(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),vi=e=>{if(!g(e))return e instanceof Error?e.message:Q(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},$=e=>e?.list?.displays??[],yi=(e,t)=>t??e?.list?.default,bi=(e,t,n)=>{let r=yi(e,n);return r===void 0?t?$(e).find(e=>e.kind===`cards`)?.name??`table`:I:r},xi=`rows`,Si=(e,t)=>{if($(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=L(e,t),r=Qt(e,t).filter(t=>t!==n&&e.fields[t]!==void 0),i=r.find(t=>e.fields[t].type===`enum`),a=r.filter(t=>t!==i&&e.fields[t].type!==`boolean`).slice(0,2);return{kind:`cards`,name:xi,label:Q(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},Ci=(e,t)=>t.name===`rows`&&!$(e).some(e=>e.name===`rows`),wi=(e,t,n)=>{let r=bi(t,n);return n&&yi(t)===void 0&&r===`table`&&Si(e,t)?xi:r},Ti=(e,t,n)=>(n===`rows`?Si(e,t):void 0)??Ei(t,n),Ei=(e,t)=>{if(t===`table`)return;let n=t=>$(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},Di={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},Oi=e=>[{name:I,label:Q(`table`),icon:`table`},...$(e).map(e=>({name:e.name,label:e.label??ge(e.name),icon:e.icon??Di[e.kind]}))],ki=(e,t,n)=>{let r=Oi(t);return n&&Si(e,t)?[...r,{name:xi,label:Q(`list`),icon:`list`}]:r},Ai=(e,t,n)=>({image:n.image,title:n.title??L(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,code:n.code,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),ji=(e,t)=>pi(e.record,t),Mi=(e,t)=>ji(e,t)[0],Ni=(e,t)=>t===void 0?void 0:ji(e,[t])[0],Pi=(e,t)=>e?.type===`text`&&typeof t==`string`?t:void 0,Fi=(e,t,n={})=>{let{suffix:r,...i}=n;return e.type!==`decimal`&&e.type!==`integer`&&e.type!==`bigint`||r===void 0||n.format===`percent`?{amount:de(e,t,n)}:{amount:de(e,t,i),suffix:r}},Ii=(e,t)=>{let n=$(e).filter(e=>e.kind===`cards`);return(t.cards===void 0?n[0]:n.find(e=>e.name===t.cards))??{kind:`cards`,name:t.name}},Li=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...Li(e,t,Ii(t,n))];if(n.kind===`board`){let r=_i(e,t,n);return[n.by,r.title,r.subtitle,r.badge,...r.meta??[]].filter(e=>e!==void 0)}if(n.kind===`calendar`)return[n.start,n.end,n.title??L(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??L(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,code:c,meta:l,footer:u,flags:d}=Ai(e,t,n);return[r,i,a,...o,s,c,...l,...u,...d].filter(e=>e!==void 0)},Ri=e=>(e?.actions??[]).flatMap(e=>(e.inputs??[]).flatMap(e=>e.from===void 0?[]:[e.from])),zi=(e,t)=>t.flatMap(t=>w(e?.fields[t]?.linkText??``)),Bi=(e,t,n)=>{let r=Si(e,t),i=r?[...$(t),r]:$(t),a=[...n,...i.flatMap(n=>Li(e,t,n))];return[...new Set([...a,...zi(t,a),...Ri(t)])]},Vi=(e,t,n)=>{let r=Ci(t,n)?[L(e,t),...Qt(e,t)]:Li(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},Hi=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,Ui=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[ui]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&Hi(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:y(le(e,n)),record:n,labels:r,...i&&{photos:i}}},Wi=(e,t)=>{let n=t?.list?.sort?.[0];if(n)return`${n[0]} ${n[1]}`;let r=e.primaryKey[0];return e.fields[r]?.sortable?`${r} asc`:``},Gi=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},Ki=e=>`${e.columnId} ${e.direction}`,qi=(e,t,n,r)=>{let i=e[n],a=Mt(t[n],r),o=a?.listOf,s=o===void 0?void 0:i?.fields[o]?.relation?.resource;return s!==void 0&&e[s]?{model:e[s],view:t[s],listOf:!0}:{model:i,view:a,listOf:!1}},Ji=(e,t,n=!1)=>({display:e?wi(e,t,n):bi(t,n),orderBy:e?Wi(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),Yi=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:y(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab},...e.standard&&{standard:!0},...e.call&&{call:e.call},...e.version!==void 0&&{version:e.version},...e.run&&{run:e.run},...e.panel&&{panel:e.panel},...e.file&&{file:e.file}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,Xi=(e,t,n)=>{let r={...e,...t},i=e=>r[e]!==void 0&&r[e]!==n[e];return{kind:`list`,resource:e.resource,...e.list&&{list:e.list},...i(`filter`)&&{filter:r.filter},...i(`display`)&&{display:r.display},...i(`orderBy`)&&{orderBy:r.orderBy},...i(`filterLayout`)&&{filterLayout:r.filterLayout},...r.map&&{map:r.map},...r.calendar&&{calendar:r.calendar},...r.timeline&&{timeline:r.timeline},...r.savedSearch&&{savedSearch:r.savedSearch}}},Zi=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=B(),{pages:a,resources:o,views:s}=ti(),c=li(),l=(0,R.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,R.useMemo)(()=>In(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,R.useCallback)((e,t)=>{let n=qi(o,s,e,t);return Ji(n.model,n.view,c)},[o,s,c]),p=(0,R.useMemo)(()=>Yi(d,f),[d,f]),m=(0,R.useCallback)((e,t)=>r(U(e),t),[r]),h=(0,R.useCallback)(e=>{if(d?.kind!==`list`)throw Error(`listTo and set change the list the app shows; use go to move to another address`);return Xi(d,e,f(d.resource,d.list))},[d,f]),g=(0,R.useCallback)(e=>m(h(e),{replace:!0}),[h,m]),_=(0,R.useCallback)(e=>U(e,n),[n]),v=(0,R.useCallback)(e=>e.startsWith(`${n}/`)?e.slice(n.length):e,[n]);return{address:p,set:g,listTo:h,go:m,href:_,open:(0,R.useCallback)(e=>r(v(e)),[v,r]),back:(0,R.useCallback)(e=>i(v(e)),[v,i])}},Qi=({to:e,...t})=>(0,z.jsx)(xn,{to:U(e),...t});export{hr as $,vi as A,Me as At,ti as B,Li as C,_t as Ct,mi as D,st as Dt,_i as E,pt as Et,ci as F,Zr as G,Z as H,li as I,Ir as J,Rr as K,si as L,pi as M,di as N,hi as O,ot as Ot,fi as P,gr as Q,ai as R,Ei as S,St,Vi as T,ft as Tt,ei as U,oi as V,$r as W,Ar as X,Fr as Y,Sr as Z,ji as _,At as _t,qi as a,en as at,Ii as b,Tt as bt,Ki as c,Zt as ct,bi as d,Bt as dt,U as et,Oi as f,Ut as ft,Ni as g,wt as gt,Mi as h,kt as ht,Ji as i,B as it,Q as j,gi as k,rt as kt,Fi as l,L as lt,$ as m,Mt as mt,Zi as n,bn as nt,Wi as o,Qt as ot,Ui as p,Vt as pt,Hr as q,Xi as r,Sn as rt,Gi as s,Xt as st,Qi as t,xn as tt,Ai as u,Ht as ut,ki as v,Dt as vt,Ti as w,ht as wt,Pi as x,I as xt,Bi as y,jt as yt,ni as z};
|
|
2
|
-
//# debugId=
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{t as r}from"./guarded-D7vqlAj1.js";import{At as i,Dt as a,Et as o,Ot as s,X as c,ft as l,rt as u}from"./vendor-WWp_xlp2.js";import{A as d,M as f,N as p,P as m,S as h,_ as g,b as _,j as v,k as y,n as b,o as x,r as ee,u as te}from"./api-provider-CcDtTh0D.js";import{$ as ne,F as S,I as re,K as ie,P as C,U as ae,V as oe,W as se,Z as ce,i as le,nt as ue,rt as w,t as de}from"./display-value-fDiKbfJO.js";import{i as fe,n as pe,s as me,t as he}from"./messages-ClKBpZlk.js";import{a as ge,n as _e,r as ve,t as ye}from"./use-meta-BqEqOLNe.js";import{t as be}from"./cn-B1sdg8aY.js";var T=(e,t,n,r)=>({code:e,message:t,hint:n,span:r}),xe=(e,t)=>{let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=[r];for(let a=1;a<=t.length;a++){let o=e[r-1]===t[a-1]?0:1;i[a]=Math.min(n[a]+1,i[a-1]+1,n[a-1]+o)}n=i}return n[t.length]},Se=(e,t)=>{let n=e.toLowerCase(),r=t.map(e=>({candidate:e,score:xe(n,e.toLowerCase())})).sort((e,t)=>e.score-t.score)[0];return r&&r.score<=Math.max(2,Math.floor(e.length/3))?r.candidate:void 0},Ce=(e,t)=>Object.hasOwn(e.fields,t)?e.fields[t]:Object.values(e.fields).find(e=>e.aliases.includes(t)),E=(e,t,n)=>{if(t.path.length>1){e.errors.push(T(`unsupported-traversal`,`Traversal into "${t.path.join(`.`)}" is not supported yet`,`Filter on fields of this resource only`,t.span));return}let r=t.path[0],i=Ce(e.model,r);if(!i){let i=Object.values(e.model.fields).filter(e=>e[n]).map(e=>e.name),a=Se(r,i);e.errors.push(T(`unknown-field`,`Unknown field "${r}"`,a?`Did you mean "${a}"?`:`Available fields: ${i.join(`, `)}`,t.span));return}if(!i[n]){let r=n===`filterable`?`filterable`:`sortable`;e.errors.push(T(n===`filterable`?`not-filterable`:`not-sortable`,`Field "${i.name}" is not ${r}`,`Mark it with .${r}() in data.ts`,t.span));return}return i},D=(e,t,n,r)=>{e.errors.push(T(`unsupported`,t,n,r))},O=(e,t)=>t.kind===`member`?{kind:`field`,path:t.path,span:t.span}:D(e,`Only fields can be compared`,`Put a field name on the left, for example total > 100`,t.span),we=(e,t)=>{switch(t.kind){case`member`:return{kind:`string`,value:t.path.join(`.`),span:t.span};case`call`:return t.name===`now`&&t.args.length===0?{kind:`now`,span:t.span}:D(e,`${t.name}() cannot be used as a value`,`Only now() is a value function`,t.span);case`binary`:{let n=t.left;return n.kind===`call`&&n.name===`now`&&n.args.length===0&&t.right.kind===`duration`?{kind:`now`,offset:{sign:t.op,duration:t.right},span:t.span}:D(e,`Arithmetic is only supported as now() +/- duration`,`Write now() - 30d`,t.span)}default:return t}},Te=(e,t)=>(`kind`in t&&[`member`,`call`,`binary`].includes(t.kind)?void 0:t)||(t.kind===`member`?{kind:`string`,value:t.path.join(`.`),span:t.span}:D(e,`Expected a literal value`,`Use strings, numbers, true/false, durations or timestamps`,t.span)),Ee=e=>{switch(e.kind){case`member`:return e.path.join(`.`);case`string`:case`timestamp`:return e.kind,e.value;case`number`:return e.raw;case`boolean`:return String(e.value);case`duration`:return`${e.amount}${e.unit}`;default:return``}},De=e=>[`sequence`,`and`,`or`,`not`,`compare`,`has`,`present`,`global`,`call`].includes(e.kind),Oe=e=>{let[t,n,r,...i]=e;if(!(i.length>0)&&!(t&&t.kind!==`string`)&&!(n&&(n.kind!==`number`||!Number.isSafeInteger(n.value)||n.value<1))&&!(r&&r.kind!==`string`))return{...t?.kind===`string`&&{orderBy:t.value},...n?.kind===`number`&&{limit:n.value},...r?.kind===`string`&&{pageToken:r.value}}},ke=(e,t,n,r)=>{let[,i,...a]=t.args,o=`related(field, resource.field, (filter), "order_by", limit, "page_token"), each after the field optional`;if(!n||i?.kind!==`member`||i.path.length!==2)return r(o);let s=a[0]&&De(a[0])?a[0]:void 0,c=Oe(s?a.slice(1):a);if(!c)return r(o);let l={kind:`related`,field:n,resource:i.path[0],key:i.path[1],...c,span:t.span};if(!s)return l;let u=k(e,s);return u&&{...l,filter:u}},Ae=(e,t)=>{let[n,r,...i]=t.args,a=n?.kind===`member`?O(e,n):void 0,o=e=>e?.kind===`string`?e.value:void 0,s=n=>{e.errors.push(T(`invalid-arguments`,`Invalid arguments to ${t.name}()`,`Usage: ${n}`,t.span))};switch(t.name){case`in`:{let n=t.args.slice(1).map(t=>Te(e,t));return!a||n.length===0?s(`in(field, value1, value2, ...)`):n.every(e=>e)?{kind:`in`,field:a,values:n,span:t.span}:void 0}case`search`:return o(n)!==void 0&&!r?{kind:`search`,text:o(n),span:t.span}:s(`search("text")`);case`similar`:return a&&o(r)!==void 0&&i.length===0?{kind:`similar`,field:a,text:o(r),span:t.span}:s(`similar(field, "text")`);case`regex`:return a&&o(r)!==void 0&&i.length===0?{kind:`regex`,field:a,pattern:o(r),span:t.span}:s(`regex(field, "pattern")`);case`isNull`:return a&&!r?{kind:`isNull`,field:a,span:t.span}:s(`isNull(field)`);case`related`:return ke(e,t,a,s);default:e.errors.push(T(`unknown-function`,`Unknown function "${t.name}"`,`Available functions: ${Object.keys(f).join(`, `)}`,t.span));return}},je=e=>e.every(e=>e)?e:void 0,k=(e,t)=>{switch(t.kind){case`sequence`:case`and`:case`or`:{let n=je(t.args.map(t=>k(e,t)));return n&&{kind:t.kind===`or`?`or`:`and`,args:n,span:t.span}}case`not`:{let n=k(e,t.arg);return n&&{kind:`not`,arg:n,span:t.span}}case`compare`:{let n=O(e,t.left),r=we(e,t.right);return n&&r&&{kind:`compare`,op:t.op,field:n,value:r,span:t.span}}case`has`:{let n=O(e,t.left),r=Te(e,t.right);return n&&r&&{kind:`has`,field:n,value:r,span:t.span}}case`present`:{let n=O(e,t.left);return n&&{kind:`present`,field:n,span:t.span}}case`global`:return{kind:`search`,text:Ee(t.value),span:t.span};case`call`:return Ae(e,t)}},Me=(e,t={})=>{let n=i(e,{...p,...t}),r={errors:[]},a=n.ast&&k(r,n.ast),o=[...n.errors,...r.errors].sort((e,t)=>e.span.start-t.span.start);return o.length===0?{ok:!0,ast:a,errors:[]}:{ok:!1,ast:a,errors:o}},Ne=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,Pe=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])];return r>=1&&r<=12&&i>=1&&i<=Ne(n,r)},Fe=e=>{let t=/^(\d{4}-\d{2}-\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/.exec(e);if(!t)return!1;let[n,r,i]=[Number(t[2]),Number(t[3]),Number(t[4])],[a,o]=[Number(t[5]??0),Number(t[6]??0)];return Pe(t[1])&&n<=23&&r<=59&&i<=59&&a<=23&&o<=59},A=(e,t)=>({message:e,hint:t}),Ie=-(2n**63n),Le=2n**63n-1n,Re=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,ze=e=>e.kind===`number`?e.raw:e.kind===`string`?e.value:void 0,j=(e,t=`Write ${e} values like the examples in the docs`)=>A(`Expected ${e}`,t),Be=e=>{let t=ze(e),n=t===void 0?NaN:Number(t);if(t===void 0||t.trim()===``||!Number.isSafeInteger(n))return j(`a whole number`,`Use an integer such as 42, or a bigint field for larger values`)},Ve=e=>{let t=ze(e);if(t===void 0||!/^-?\d+$/.test(t)||BigInt(t)<Ie||BigInt(t)>Le)return j(`a 64-bit integer`,`Use plain digits such as 9007199254740993 (no exponent or fraction)`)},He=e=>{let t=ze(e);if(t===void 0||!/^-?\d+(\.\d+)?$/.test(t))return j(`a decimal number`,`Use plain digits such as 100.50, or quote it: "100.50" (no exponent)`)},Ue=(e,t)=>{if(t.kind===`now`)return e.type===`date`||e.type===`timestamp`?void 0:A(`now() only works with date and timestamp fields`,`Field "${e.name}" is ${e.type}`);switch(e.type){case`text`:return t.kind===`string`?void 0:j(`a quoted string`,`Wrap the text in double quotes`);case`integer`:return Be(t);case`bigint`:return Ve(t);case`decimal`:return He(t);case`boolean`:return t.kind===`boolean`?void 0:j(`true or false`);case`date`:return t.kind===`string`&&Pe(t.value)?void 0:j(`a date`,`Quote a calendar date: "2012-04-21"`);case`timestamp`:return t.kind===`timestamp`||t.kind===`string`&&Fe(t.value)?void 0:j(`an RFC-3339 timestamp`,`Use 2012-04-21T11:30:00Z, or now() - 7d`);case`uuid`:return t.kind===`string`&&Re.test(t.value)?void 0:j(`a uuid`,`Quote a uuid like "0b5a4f0e-6f2a-4a3c-9d4e-1f2a3b4c5d6e"`);case`enum`:return t.kind===`string`&&e.enumValues?.includes(t.value)?void 0:A(`Invalid enum value`,`Allowed values: ${(e.enumValues??[]).join(`, `)}`);case`currency`:return t.kind===`string`&&/^[A-Z]{3}$/.test(t.value)?void 0:j(`an ISO 4217 currency code`,`Use three capital letters, for example "EUR"`);case`country`:return t.kind===`string`&&/^[A-Z]{2}$/.test(t.value)?void 0:j(`an ISO 3166-1 country code`,`Use two capital letters, for example "NL"`);case`relation`:return t.kind===`string`||t.kind===`number`&&Number.isSafeInteger(t.value)?void 0:j(`a record key`,`Use the related record key: 42 or "abc"`);case`json`:case`file`:return A(`${e.type} fields cannot be compared`,`Use field:value on json fields, or isNull(field)`)}},We=[`=`,`!=`],Ge=[`=`,`!=`,`<`,`<=`,`>`,`>=`],Ke=e=>{switch(e){case`text`:case`integer`:case`bigint`:case`decimal`:case`date`:case`timestamp`:return Ge;case`json`:case`file`:return[];default:return We}},qe=e=>e===`json`||e===`file`,Je=e=>T(`unsupported-traversal`,`related() only works in a list's filter, ANDed with the rest`,`Put it at the top of the filter or of a subfilter, joined with AND`,e),Ye=(e,t,n)=>{let r=Ue(t,n);return r&&e.errors.push(T(`invalid-value`,r.message,r.hint,n.span)),!r},M=(e,t,n,r)=>{e.errors.push(T(`operator-not-allowed`,t,n,r))},Xe=(e,t)=>(e===`=`||e===`!=`)&&t.kind===`string`&&t.value.includes(`*`),Ze=(e,t)=>{let n=E(e,t.field,`filterable`);if(!n)return;let r=Ke(n.type);if(!r.includes(t.op)){M(e,`Operator "${t.op}" is not supported for ${n.type} fields`,r.length?`Supported: ${r.join(` `)}`:`Use field:value on json fields, or isNull(field)`,t.span);return}if(Xe(t.op,t.value)&&n.type!==`text`){e.errors.push(T(`wildcard-not-allowed`,`Wildcards are only supported on text fields, not ${n.type}`,`Remove the "*" or filter a text field`,t.value.span));return}if(Xe(t.op,t.value)||Ye(e,n,t.value))return{...t,field:n}},Qe=(e,t)=>{let n=E(e,t.field,`filterable`);if(n){if(n.type!==`json`){M(e,`":" is only supported on json fields, not ${n.type}`,`Use = on ${n.type} fields, or field:* to test for a value`,t.span);return}return{...t,field:n}}},$e=(e,t)=>{let n=E(e,t.field,`filterable`);if(n){if(qe(n.type)){M(e,`in() is not supported for ${n.type} fields`,`Use field:value on json fields`,t.span);return}return t.values.map(t=>Ye(e,n,t)).every(Boolean)?{...t,field:n}:void 0}},et=(e,t,n)=>{let r=E(e,n,`filterable`);if(r&&r.type!==`text`){M(e,`${t}() only works on text fields, not ${r.type}`,`Field "${r.name}" is ${r.type}`,n.span);return}return r},tt=(e,t)=>{switch(t.kind){case`and`:case`or`:{let n=t.args.map(t=>tt(e,t));return n.every(e=>e)?{...t,args:n}:void 0}case`not`:{let n=tt(e,t.arg);return n&&{...t,arg:n}}case`compare`:return Ze(e,t);case`has`:return Qe(e,t);case`in`:return $e(e,t);case`search`:if(e.model.search?.length)return t;e.errors.push(T(`no-search-fields`,`This resource has no search fields`,`Declare them with .search((r) => [r.title]) in data.ts`,t.span));return;case`present`:case`isNull`:{let n=E(e,t.field,`filterable`);return n&&{...t,field:n}}case`similar`:case`regex`:{let n=et(e,t.kind,t.field);return n&&{...t,field:n}}case`related`:e.errors.push(Je(t.span));return}},nt=(e,t)=>{let n={model:e,errors:[]},r=tt(n,t);return!r||n.errors.length>0?{ok:!1,errors:[...n.errors].sort((e,t)=>e.span.start-t.span.start)}:{ok:!0,filter:r}},rt=(e,t)=>{let n=nt(e,t);if(!n.ok&&n.errors.some(e=>e.code===`unsupported-traversal`))return n;let r=s(v(t),m(e));return r.ok?nt(e,t):{ok:!1,errors:r.errors}},it=e=>e.map(e=>({path:e.path.path,direction:e.direction,span:e.span})),at=e=>e.replace(/([^\s,])(\s+)(asc|desc)(?=\s|,|$)/gi,(e,t,n,r)=>`${t}${n}${r.toLowerCase()}`),ot=e=>{let t=a(at(e)),n=t.items.map(e=>({path:{kind:`field`,path:e.path,span:e.span},direction:e.direction,span:e.span}));return t.ok?{ok:!0,items:n,errors:[]}:{ok:!1,items:n,errors:t.errors}},st=(e,t)=>{let n=t.filter(e=>e.path.path.length>1).map(e=>T(`unsupported-traversal`,`Traversal into "${e.path.path.join(`.`)}" is not supported yet`,`Sort on fields of this resource only`,e.path.span));if(n.length>0)return{ok:!1,errors:n};let r=o(it(t),m(e));return r.ok?{ok:!0,sort:r.items.map(e=>[e.path[0],e.direction])}:{ok:!1,errors:r.errors}},ct=e=>{let t=/^(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)([smhdw])$/.exec(e);if(!t)throw Error(`Invalid duration "${e}", expected for example 30d or 1.5h`);return{kind:`duration`,amount:Number(t[1]),unit:t[2],span:{start:0,end:0}}},N={start:0,end:0},P=e=>({kind:`field`,path:e.split(`.`),span:N}),lt=e=>{if(typeof e==`string`)return{kind:`string`,value:e,span:N};if(typeof e==`boolean`)return{kind:`boolean`,value:e,span:N};if(!Number.isFinite(e))throw Error(`Filter numbers must be finite`);return{kind:`number`,value:e,raw:String(e),span:N}},ut=e=>typeof e==`object`?e:lt(e),dt=(e,t)=>{if(t.length===0)throw Error(`where.${e} needs at least one filter`);return t.length===1?t[0]:{kind:e,args:t,span:N}},ft=()=>{let e=e=>(t,n)=>({kind:`compare`,op:e,field:P(t),value:ut(n),span:N}),t=e=>t=>({kind:`now`,offset:{sign:e,duration:ct(t)},span:N});return{eq:e(`=`),ne:e(`!=`),lt:e(`<`),lte:e(`<=`),gt:e(`>`),gte:e(`>=`),between:(t,n,r)=>dt(`and`,[e(`>=`)(t,n),e(`<=`)(t,r)]),has:(e,t)=>({kind:`has`,field:P(e),value:lt(t),span:N}),present:e=>({kind:`present`,field:P(e),span:N}),in:(e,t)=>({kind:`in`,field:P(e),values:t.map(lt),span:N}),isNull:e=>({kind:`isNull`,field:P(e),span:N}),search:e=>({kind:`search`,text:e,span:N}),similar:(e,t)=>({kind:`similar`,field:P(e),text:t,span:N}),regex:(e,t)=>({kind:`regex`,field:P(e),pattern:t,span:N}),related:(e,t,n,r,i)=>({kind:`related`,field:P(e),resource:t,key:n,...r&&{filter:r},...i,span:N}),and:(...e)=>dt(`and`,e),or:(...e)=>dt(`or`,e),not:e=>({kind:`not`,arg:e,span:N}),now:()=>({kind:`now`,span:N}),ago:t(`-`),fromNow:t(`+`)}},pt=ft(),mt=Symbol(`protobase.ref`),ht=e=>Object.defineProperty({name:e},mt,{value:!0}),gt=e=>typeof e==`object`&&!!e&&e[mt]===!0,_t=(e,t)=>new Proxy({},{get:(n,r)=>{if(typeof r!=`symbol`){if(t&&!t.includes(r))throw Error(`Unknown field "${r}"`);return e(r)}}}),vt=e=>({$field:e}),yt=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length===1&&typeof e.$field==`string`,bt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xt=e=>gt(e)?vt(e.name):Array.isArray(e)?e.map(xt):bt(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,xt(t)])):e,St=e=>yt(e)?e.$field:Array.isArray(e)?e.map(St):bt(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,St(t)])):e,Ct=e=>yt(e)?[e.$field]:Array.isArray(e)?e.flatMap(Ct):bt(e)?Object.values(e).flatMap(Ct):[],F=({label:e,icon:t})=>({...e!==void 0&&{label:e},...t!==void 0&&{icon:t}}),I=`table`,wt=(e,t)=>{if(!e.custom)throw Error(`${t} takes a component declared with component(...), not the built-in block ${e.blockName}`);return e.blockName},Tt={cards:(e,t={})=>({kind:`cards`,name:t.name??`cards`,...F(t),...e.image&&{image:e.image.name},...e.title&&{title:e.title.name},...e.subtitle&&{subtitle:e.subtitle.name},...e.amount&&{amount:e.amount.map(e=>e.name)},...e.badge&&{badge:e.badge.name},...e.code&&{code:e.code.name},...e.meta&&{meta:e.meta.map(e=>e.name)},...e.footer&&{footer:e.footer.map(e=>e.name)},...e.flags&&{flags:e.flags.map(e=>e.name)},...e.dots&&{dots:e.dots.map(e=>e.name)},...t.card&&{card:wt(t.card,`d.cards card`)},...t.photos&&{photos:{...t.photos}},...t.favorite&&{favorite:{...t.favorite}}}),map:(e,t={})=>({kind:`map`,name:t.name??`map`,...F(t),latitude:e.latitude.name,longitude:e.longitude.name,...t.cards!==void 0&&{cards:t.cards},...e.approximate&&{approximate:e.approximate.name},...e.exact&&{exact:e.exact.name},...e.radius&&{radius:e.radius.name},...t.defaultRadius!==void 0&&{defaultRadius:t.defaultRadius},...e.area&&{area:e.area.name}}),board:(e,t={})=>({kind:`board`,name:t.name??`board`,...F(t),by:e.by.name,...e.title&&{title:e.title.name},...e.subtitle&&{subtitle:e.subtitle.name},...e.badge&&{badge:e.badge.name},...e.meta&&{meta:e.meta.map(e=>e.name)}}),calendar:(e,t={})=>({kind:`calendar`,name:t.name??`calendar`,...F(t),start:e.start.name,...e.end&&{end:e.end.name},...e.title&&{title:e.title.name}}),timeline:(e,t={})=>({kind:`timeline`,name:t.name??`timeline`,...F(t),start:e.start.name,...e.end&&{end:e.end.name},...e.group&&{group:e.group.name},...e.title&&{title:e.title.name}}),custom:(e,t)=>({kind:`custom`,name:t.name,label:t.label,...F({icon:t.icon}),component:wt(e,`d.custom`),fields:t.fields.map(e=>e.name),...t.props&&{props:xt(t.props)}})},Et=/^[a-z][a-zA-Z0-9-]*$/,Dt=e=>{let t=(e.displays??[]).map(e=>e.name);return[...t.filter(e=>!Et.test(e)).map(e=>`display name "${e}" must start with a lowercase letter and hold only letters, digits and dashes`),...t.filter(e=>e===I).map(()=>`"${I}" is the list's own display; give the display another name`),...t.filter((e,n)=>t.indexOf(e)!==n).map(e=>`display "${e}" is defined twice`),...(e.displays??[]).flatMap(t=>t.kind===`map`&&t.cards!==void 0&&!e.displays.some(e=>e.kind===`cards`&&e.name===t.cards)?[`display "${t.name}" names cards "${t.cards}", which is not a cards display of the list`]:[]),...(e.displays??[]).flatMap(t=>t.kind===`cards`?(t.dots??[]).filter(t=>!e.relatedColumns?.some(e=>e.name===t)).map(e=>`display "${t.name}" shows dots of "${e}", which is not a related column of the list`):[]),...(e.displays??[]).flatMap(e=>e.kind===`map`?Ot(e).map(t=>`display "${e.name}": ${t}`):[]),...e.default===void 0||e.default===`table`||t.includes(e.default)?[]:[`default "${e.default}" is not one of the displays (${[I,...t].join(`, `)})`]]},Ot=e=>{let{approximate:t,exact:n,radius:r,defaultRadius:i,area:a}=e;return t!==void 0&&n!==void 0?[`name approximate or exact, not both`]:[...(r!==void 0||i!==void 0||a!==void 0)&&t===void 0&&n===void 0?[`an area around approximate positions needs the approximate or exact field`]:[],...i===void 0||Number.isFinite(i)&&i>0?[]:[`defaultRadius ${i} is not a number of metres above 0`]]},kt=(e,t)=>{let n=Object.hasOwn(t.fields,e.by)?t.fields[e.by]:void 0;return n?n.type===`enum`?n.filterable?[]:[`"${e.by}" on ${t.name} is not filterable, and each column of the board filters by its value`]:[`"${e.by}" on ${t.name} is ${n.type}, not an enum, whose values are the board's columns`]:[]},At=(e,t)=>{let n=e=>Object.hasOwn(t.fields,e)?t.fields[e]:void 0,r=n(e.start),i=e.end===void 0?void 0:n(e.end);if(!r)return[];if(r.type!==`date`&&r.type!==`timestamp`)return[`start "${e.start}" on ${t.name} is ${r.type}, not a date or timestamp`];let a=n=>`${n===e.start?`start`:`end`} "${n}" on ${t.name} is not filterable, and the ${e.kind} filters by it for the days it shows`;return[...r.filterable?[]:[a(e.start)],...i&&i.type!==r.type?[`end "${e.end}" on ${t.name} is ${i.type}, not ${r.type} like start "${e.start}"`]:[],...i&&i.type===r.type&&!i.filterable?[a(e.end)]:[]]},jt=e=>e.kind===`map`?[e.latitude,e.longitude,e.approximate,e.exact,e.radius,e.area].filter(e=>e!==void 0):e.kind===`custom`?[...e.fields,...Ct(e.props)]:e.kind===`board`?[e.by,e.title,e.subtitle,e.badge,...e.meta??[]].filter(e=>e!==void 0):e.kind===`calendar`?[e.start,e.end,e.title].filter(e=>e!==void 0):e.kind===`timeline`?[e.start,e.end,e.group,e.title].filter(e=>e!==void 0):[e.image,e.title,e.subtitle,...e.amount??[],e.badge,e.code,...e.meta??[],...e.footer??[],...e.flags??[]].filter(e=>e!==void 0),Mt=(e,t)=>{if(t===void 0)return e;let n=e?.lists?.find(e=>e.name===t);if(!e||!n)return;let{list:r,chart:i,help:a,nav:o,lists:s,names:c,...l}=e,{name:u,...d}=n;return{...l,...d}},Nt=[`unknown-field`,`not-filterable`,`not-sortable`,`unsupported-traversal`,`invalid-traversal`],Pt=e=>e.replace(/(["']?)\{\{\s*[^{}]*?\s*\}\}\1/g,(e,t)=>t?`${t}x${t}`:`0`),Ft=(e,t)=>{let n=ie(t);if(n.length>0)return n.map(e=>`filter: "{{${e}}}" sits inside a longer quoted value; quote it alone, such as title = "{{${e}}}"`);let r=Me(Pt(t));if(!r.ok)return r.errors.map(e=>`filter: ${e.message}`);if(!r.ast)return[];let i=rt(e,r.ast);return i.ok?[]:i.errors.filter(e=>Nt.includes(e.code)).map(e=>`filter: ${e.message}`)},It=(e,t)=>{if(se({kind:`list`,resource:e.name,orderBy:t}).length>0)return[];let n=ot(t);if(!n.ok)return n.errors.map(e=>`orderBy: ${e.message}`);let r=st(e,n.items);return r.ok?[]:r.errors.map(e=>`orderBy: ${e.message}`)},Lt=(e,{models:t,pages:n,source:r,placeholderError:i,createPages:a,filterFromRecord:o})=>{let s=se(e).flatMap(e=>{if(i){let t=i(e);return t===void 0?[]:[t]}return r?Object.hasOwn(r.fields,e)?[]:[`"{{${e}}}" is not a field of ${r.name}`]:[`"{{${e}}}" takes a value from the record, but the link sits on none`]}),c=o===!0&&ce(e)!==void 0;if(e.kind!==`page`&&ue(e)!==void 0){if(!(e.kind===`list`?e.filter!==void 0&&!c||e.orderBy!==void 0:e.kind===`create`&&e.values!==void 0))return s;let t=o?`no order or values, and a filter only as one field, such as filter: '{{filter}}'`:`no filter, order or values`;return[...s,`a link whose resource comes from the record ("${e.resource}") names ${t}`]}switch(e.kind){case`page`:return n&&!n.has(e.page)?[...s,`unknown page "${e.page}"`]:s;case`list`:case`record`:case`create`:{let n=Object.hasOwn(t,e.resource)?t[e.resource]:void 0;return n?e.kind===`create`&&a?.has(e.resource)?s:e.kind===`create`?[...s,...Object.keys(e.values??{}).filter(e=>!Object.hasOwn(n.fields,e)).map(t=>`values: unknown field "${t}" on ${e.resource}`)]:e.kind===`list`?[...s,...e.filter&&!c?Ft(n,e.filter):[],...e.orderBy?It(n,e.orderBy):[]]:s:[`unknown resource "${e.resource}"`]}default:return[`an address's kind is list, record, create or page, not "${String(e.kind)}"`]}},Rt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),zt=`a row button is { label, to } or { label, href }, such as { label: 'Open', to: { kind: 'record', resource: 'tasks', key: '{{id}}' } } or { label: 'Report', href: '{{report_url}}' }, or a list of them`,Bt=e=>Array.isArray(e)?e:[e],Vt=e=>{let t=e.href;return t===void 0?{to:e.to}:{href:t}},Ht=e=>{let t=Vt(e);return[...new Set([...w(e.label),...`href`in t?w(t.href):se(t.to)])]},Ut=e=>[...new Set(Bt(e).flatMap(Ht))],Wt=(e,t,n)=>e.flatMap(e=>Object.hasOwn(t.fields,e)?[]:[`${n}: "{{${e}}}" is not a field of ${t.name}`]),Gt=(e,t,n)=>{if(!Rt(e))return[zt];if(typeof e.label!=`string`||e.label.trim()===``)return[`a row button needs a label`];if(e.to!==void 0&&e.href!==void 0)return["a row button opens an address in `to` or an outside page in `href`, not both"];let r=Wt(w(e.label),t,`label`);if(e.href!==void 0){let n=typeof e.href==`string`?ne(e.href):void 0;return n===void 0?[...r,`href: a row button's href is the one field that holds the page's https URL, such as '{{report_url}}'`]:[...r,...Wt([n],t,`href`)]}return!Rt(e.to)||typeof e.to.kind!=`string`?["a row button needs an address in `to`, such as { kind: 'record', resource: 'tasks', key: '{{id}}' }, or an outside page in `href`"]:[...r,...Lt(e.to,{...n,source:t,filterFromRecord:!0}).map(e=>`to: ${e}`)]},Kt=(e,t,n)=>Array.isArray(e)?e.length===0?[`a row button list needs at least one choice`]:e.flatMap((e,r)=>Gt(e,t,n).map(e=>`choice ${r+1}: ${e}`)):Gt(e,t,n),qt=(e,t,n)=>{if(!Array.isArray(e))return Kt(e,t,n).length===0?e:void 0;let r=Bt(e).filter(e=>Gt(e,t,n).length===0);return r.length===0?void 0:r},Jt=[`name`,`title`,`number`,`sku`,`email`,`code`,`description`],Yt=e=>e?.type===`text`&&!e.sensitive,Xt=(e,t)=>t?.title??Jt.find(t=>Yt(e.fields[t]))??Object.values(e.fields).find(Yt)?.name??e.primaryKey[0],L=(e,t)=>t?.title??t?.list?.columns.find(t=>e.fields[t]?.type===`text`)??Xt(e),Zt=(e,t,n,r)=>{let i=L(e,t),a=n[i];return a==null?r:e.fields[i]?.type===`enum`?ae(String(a),t?.fields[i]?.valueLabels):String(a)},Qt=(e,t)=>t?.list?.columns??Object.values(e.fields).filter(e=>!e.writeOnly).slice(0,6).map(e=>e.name),R=e(t(),1),z=e(n(),1),$t=(0,R.createContext)([]),en=({name:e,children:t})=>{let n=(0,R.useContext)($t),r=(0,R.useMemo)(()=>[...n,e],[n,e]);return(0,z.jsx)($t.Provider,{value:r,children:t})},tn=()=>(0,R.useContext)($t),nn=(e,t,n)=>{let r=new URL(e,`http://local`),i=new URL(t,`http://local`);return r.pathname!==i.pathname||[...n].some(e=>e.params.some(e=>r.searchParams.get(e)!==i.searchParams.get(e)))},rn=(e,{replace:t=!1,keepScroll:n=!1}={})=>({kind:`link`,full:e,replace:t,keepScroll:n}),an=(e,t)=>t(e.full,e.replace,e.keepScroll),on=`protobase:page-places`,sn=50,cn=e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`&&typeof e[1]==`number`&&Number.isFinite(e[1])&&e[1]>=0,ln=e=>r(()=>{let t=e.getItem(on);if(t===null)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(cn):[]},[]),un=e=>{let t=new Map(ln(e));return{placeOf:e=>t.get(e)??0,save:(e,n)=>{t.delete(e),t.set(e,Math.max(0,Math.round(n)));for(let e of[...t.keys()].slice(0,Math.max(0,t.size-sn)))t.delete(e)},persist:()=>r(()=>e.setItem(on,JSON.stringify([...t])),void 0)}},dn=3e3,fn=e=>{let t=0,n=()=>(window.scrollTo({top:e,behavior:`instant`}),t=window.scrollY,t>=e-1);if(n())return()=>{};let r=new ResizeObserver(()=>n()&&a()),i=()=>Math.abs(window.scrollY-t)>1&&a(),a=()=>{r.disconnect(),clearTimeout(o),window.removeEventListener(`scroll`,i)},o=setTimeout(a,dn);return r.observe(document.body),window.addEventListener(`scroll`,i,{passive:!0}),a},pn=(0,R.createContext)(null),B=()=>{let e=(0,R.useContext)(pn);if(!e)throw Error(`useRouter must be used inside Router`);return e},mn=()=>`${window.location.pathname}${window.location.search}`,hn=e=>new URL(e,`http://local`).pathname,V=()=>window.history.state??{},gn=()=>V().protobaseIndex??0,_n=()=>Math.random().toString(36).slice(2),vn=()=>{let e=V();if(e.protobaseEntry)return e.protobaseEntry;let t=_n();return window.history.replaceState({...e,protobaseEntry:t},``),t},yn={getItem:()=>null,setItem:()=>{}},bn=({basePath:e=``,initialUrl:t,children:n})=>{let i=t!==void 0,[a,o]=(0,R.useState)(()=>({url:t??mn(),entry:i?_n():vn()})),[s]=(0,R.useState)(()=>un(i?yn:r(()=>window.sessionStorage,void 0)??yn)),c=(0,R.useRef)(new Map),l=()=>[...c.current.values()].some(e=>e.kind===`input-lost`),u=(0,R.useRef)(a);u.current=a;let d=(0,R.useRef)(i?0:gn()),f=(0,R.useRef)(!1),p=(0,R.useRef)(!1),m=(0,R.useRef)(void 0),h=(0,R.useRef)(!1),[g,v]=(0,R.useState)(),y=(0,R.useCallback)(()=>s.save(u.current.entry,window.scrollY),[s]);(0,R.useLayoutEffect)(()=>fn(s.placeOf(a.entry)),[s,a.entry]),(0,R.useEffect)(()=>{if(i)return;window.history.scrollRestoration=`manual`,window.history.replaceState({...V(),protobaseIndex:d.current,protobaseEntry:u.current.entry},``);let e=()=>{y(),s.persist()},t=()=>document.visibilityState===`hidden`&&e();window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t);let n=()=>{let e=gn();if(f.current){f.current=!1,d.current=e,m.current!==void 0&&window.history.go(m.current),m.current=void 0;return}let t=e-d.current;if(!p.current&&c.current.size>0&&nn(u.current.url,mn(),c.current.values())){f.current=!0,window.history.go(-t),v({kind:`history`,delta:t,inputLost:l()});return}p.current=!1,d.current=e,y(),o({url:mn(),entry:vn()})};return window.addEventListener(`popstate`,n),()=>{window.removeEventListener(`popstate`,n),window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t)}},[i,y,s]);let b=(0,R.useCallback)((e,t,n=!1)=>{let r=t?u.current.entry:_n();if(!i){d.current+=+!t;let n=t?V().protobasePrevious:u.current.url;window.history[t?`replaceState`:`pushState`]({protobaseIndex:d.current,protobaseEntry:r,protobasePrevious:n},``,e)}y(),n&&s.save(r,window.scrollY),o({url:e,entry:r})},[i,y,s]),x=(0,R.useCallback)((t,n)=>{let r=rn(`${e}${t}`,n);if(c.current.size>0&&nn(u.current.url,r.full,c.current.values()))return v({...r,inputLost:l()});an(r,b)},[e,b]),ee=(0,R.useCallback)(t=>{let n=i?void 0:V().protobasePrevious;if(n!==void 0&&hn(n)===hn(`${e}${t}`))return window.history.back();x(t)},[i,e,x]),te=(0,R.useCallback)((e=`draft-kept`,t=[])=>{let n=Symbol(`guard`);return c.current.set(n,{kind:e,params:t}),()=>void c.current.delete(n)},[]),ne=(0,R.useCallback)(()=>{if(c.current.size>0)return v({kind:`reload`,inputLost:l()});window.location.reload()},[]),re=(0,R.useCallback)(()=>h.current,[]),ie=(0,R.useCallback)(()=>c.current.size>0,[]),C=()=>{if(g){if(v(void 0),g.kind===`link`)return an(g,b);if(g.kind===`reload`)return h.current=!0,window.location.reload();p.current=!0,f.current?m.current=g.delta:window.history.go(g.delta)}},ae=(0,R.useMemo)(()=>{let t=new URL(a.url,`http://local`);return{path:t.pathname.slice(e.length)||`/`,params:t.searchParams,basePath:e,entry:a.entry,navigate:x,back:ee,registerGuard:te,reload:ne,reloadConfirmed:re,holdsChanges:ie}},[a,e,x,ee,te,ne,re,ie]);return(0,z.jsxs)(pn.Provider,{value:ae,children:[n,g?.kind===`reload`&&(0,z.jsx)(ve,{title:S(`reloadTitle`),description:S(g.inputLost?`reloadInputLost`:`reloadDraftKept`),onClose:()=>v(void 0),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(_,{onClick:()=>v(void 0),children:S(`keepEditing`)}),(0,z.jsx)(_,{variant:`primary`,onClick:C,children:S(`reload`)})]})}),g&&g.kind!==`reload`&&(0,z.jsx)(ve,{title:S(`leaveTitle`),description:S(g.inputLost?`leaveInputLost`:`leaveDescription`),onClose:()=>v(void 0),actions:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(_,{onClick:()=>v(void 0),children:S(`stay`)}),(0,z.jsx)(_,{variant:`primary`,onClick:C,children:S(`leave`)})]})})]})},xn=({to:e,replace:t,...n})=>{let{navigate:r,basePath:i}=B();return(0,z.jsx)(re,{to:{href:`${i}${e}`,onFollow:()=>r(e,{replace:t})},...n})},Sn=(e,t=`draft-kept`)=>{let{registerGuard:n,reloadConfirmed:r}=B(),i=tn();(0,R.useEffect)(()=>e?n(t,i):void 0,[e,t,i,n]),(0,R.useEffect)(()=>{if(!e)return;let t=e=>{r()||e.preventDefault()};return window.addEventListener(`beforeunload`,t),()=>window.removeEventListener(`beforeunload`,t)},[e,r])},H={list:`list`,filter:`filter`,orderBy:`order_by`,display:`display`,filterLayout:`layout`,map:`map`,calendar:`calendar`,timeline:`timeline`,savedSearch:`saved_search`,create:`new`,edit:`edit`,open:`open`,tab:`tab`,standard:`standard`,call:`call`,version:`version`,run:`run`,panel:`panel`,file:`file`},Cn=[`list`,`display`,`filter`,`orderBy`,`filterLayout`,`savedSearch`],wn=e=>`${e.latitude.toFixed(5)},${e.longitude.toFixed(5)},${e.zoom.toFixed(2)}`,Tn=(e,t,n=-t)=>Number.isFinite(e)&&e>=n&&e<=t,En=e=>{let t=e?.split(`,`);if(t?.length!==3||t.some(e=>e.trim()===``))return;let[n,r,i]=t.map(Number);return Tn(n,90)&&Tn(r,180)&&Tn(i,22,0)?{latitude:n,longitude:r,zoom:i}:void 0},Dn=e=>`${e.scale},${e.day}`,On=e=>{let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!t)return!1;let[n,r,i]=t.slice(1).map(Number),a=new Date(Date.UTC(n,r-1,i));return a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i},kn=(e,t)=>{let n=e?.split(`,`);if(n?.length!==2)return;let[r,i]=n;return t.includes(r)&&On(i)?{scale:r,day:i}:void 0},An=e=>{let t=new URLSearchParams;for(let n of Cn){let r=e[n];r===void 0||r===``&&n!==`filter`||t.set(H[n],r)}e.map&&t.set(H.map,wn(e.map)),e.calendar&&t.set(H.calendar,Dn(e.calendar)),e.timeline&&t.set(H.timeline,Dn(e.timeline));let n=t.toString();return n?`?${n}`:``},jn=e=>{let t=new URLSearchParams;e.edit&&t.set(H.edit,`true`);for(let n of e.open??[])t.append(H.open,n);e.tab&&t.set(H.tab,e.tab),e.standard&&t.set(H.standard,`true`),e.call&&t.set(H.call,e.call),e.version!==void 0&&t.set(H.version,String(e.version)),e.run&&t.set(H.run,e.run),e.panel&&t.set(H.panel,e.panel),e.file&&t.set(H.file,e.file);let n=t.toString();return n?`?${n}`:``},U=(e,t=``)=>{switch(e.kind){case`page`:return`${t}/${encodeURIComponent(e.page)}${e.tab?`/${encodeURIComponent(e.tab)}`:``}${Nn(e.params)}`;case`create`:return`${t}/${encodeURIComponent(e.resource)}/${H.create}${Nn(e.values)}`;case`record`:return`${t}/${encodeURIComponent(e.resource)}/${encodeURIComponent(y(e.key))}${jn(e)}`;case`list`:return`${t}/${encodeURIComponent(e.resource)}${An(e)}`}},Mn=e=>{try{return e.split(`/`).filter(Boolean).map(decodeURIComponent)}catch(e){if(e instanceof URIError)return;throw e}},Nn=(e={})=>{let t=new URLSearchParams(Object.entries(e).filter(([,e])=>e!==``)).toString();return t?`?${t}`:``},Pn=e=>e!==null&&/^[1-9]\d{0,8}$/.test(e)?Number(e):void 0,Fn=e=>e===`bar`||e===`panel`?e:void 0,In=(e,t)=>{let n=new URL(e,`http://app`),r=Mn(n.pathname);if(!r||r.length===0||r.length>2)return;let[i,a]=r;if(i===`-`)return;if(t.has(i)){let e=Object.fromEntries([...n.searchParams].filter(([,e])=>e!==``));return{kind:`page`,page:i,...a!==void 0&&{tab:a},...Object.keys(e).length>0&&{params:e}}}if(a===H.create){let e=Object.fromEntries([...n.searchParams].filter(([,e])=>e!==``));return{kind:`create`,resource:i,...Object.keys(e).length>0&&{values:e}}}if(a!==void 0){let e=[...new Set(n.searchParams.getAll(H.open).filter(e=>e!==``))],t=n.searchParams.get(H.tab)||void 0,r=n.searchParams.get(H.standard)===`true`,o=n.searchParams.get(H.call)===`join`,s=Pn(n.searchParams.get(H.version)),c=n.searchParams.get(H.run)||void 0,l=n.searchParams.get(H.panel)||void 0,u=n.searchParams.get(H.file)||void 0;return{kind:`record`,resource:i,key:a,...n.searchParams.get(H.edit)===`true`&&{edit:!0},...e.length>0&&{open:e},...t&&{tab:t},...r&&{standard:r},...o&&{call:`join`},...s!==void 0&&{version:s},...c&&{run:c},...l&&{panel:l},...u&&{file:u}}}let o=n.searchParams,s=o.get(H.list)||void 0,c=o.get(H.display)||void 0,l=o.get(H.filter)??void 0,u=o.get(H.orderBy)||void 0,d=Fn(o.get(H.filterLayout)),f=En(o.get(H.map)),p=kn(o.get(H.calendar),[`month`,`week`]),m=kn(o.get(H.timeline),[`week`,`month`,`quarter`]),h=o.get(H.savedSearch)||void 0;return{kind:`list`,resource:i,...s&&{list:s},...c&&{display:c},...l!==void 0&&{filter:l},...u&&{orderBy:u},...d&&{filterLayout:d},...f&&{map:f},...p&&{calendar:p},...m&&{timeline:m},...h&&{savedSearch:h}}},Ln=e=>typeof e==`string`?e:e.toModel().name,Rn=(e,t)=>{let n=n=>t(Ln(n))??e;return{list:(e,t)=>n(e).list(e,t),search:(e,t)=>n(e).search(e,t),get:(e,t)=>n(e).get(e,t),create:(e,t)=>n(e).create(e,t),update:(e,t,r,i)=>n(e).update(e,t,r,i),remove:(e,t,r)=>n(e).remove(e,t,r),undelete:(e,t)=>n(e).undelete(e,t),generate:(e,t,r)=>n(e).generate(e,t,r),reveal:(e,t,r)=>n(e).reveal(e,t,r),history:(e,t,r)=>n(e).history(e,t,r),comments:(e,t,r)=>n(e).comments(e,t,r),comment:(e,t,r)=>n(e).comment(e,t,r),mentionable:(e,t,r)=>n(e).mentionable(e,t,r),batchWrite:t=>{let r=[...new Set(t.map(e=>n(e.resource)))];return r.length>1?Promise.reject(Error(`A batch writes to one API, but these writes are for ${[...new Set(t.map(e=>Ln(e.resource)))].join(`, `)}, which different APIs serve`)):(r[0]??e).batchWrite(t)},facets:(e,t,r)=>n(e).facets(e,t,r),aggregate:(e,t)=>n(e).aggregate(e,t),series:(e,t)=>n(e).series(e,t),histogram:(e,t,r)=>n(e).histogram(e,t,r),map:(e,t)=>n(e).map(e,t),seek:(e,t)=>n(e).seek(e,t),meta:(t,n)=>e.meta(t,n),fileReadUrl:(e,t)=>n(e).fileReadUrl(e,t),invoke:(t,n)=>e.invoke(t,n),upload:(e,t,r,i)=>n(e).upload(e,t,r,i),form:t=>e.form(t),formChallenge:t=>e.formChallenge(t),submitForm:(t,n,r)=>e.submitForm(t,n,r),live:t=>e.live(t),channel:(t,n)=>e.channel(t,n),bridges:e.bridges,devices:e.devices,notifications:e.notifications,status:e.status,rings:e.rings,callGuests:e.callGuests,calls:(e,t)=>n(e).calls(e,t),watchCalls:(e,t,r)=>n(e).watchCalls(e,t,r),workflowTypes:()=>n(`workflows`).workflowTypes(),workflowRunTrace:(e,t)=>n(`workflow_runs`).workflowRunTrace(e,t),runnerRegistration:e=>n(`workflow_runners`).runnerRegistration(e)}},W=Symbol(`recorded`),zn=[],Bn=0,Vn=0,Hn=e=>{if(Vn===0)throw Error(`A record block's children are a function of its record only inside a typed layout: layout(), recordLayout() or defineTemplate()`);Bn+=1;let t=Bn;zn.push(t);try{return{scope:t,built:e(t)}}finally{zn.pop()}},Un=new WeakMap,Wn=(e,t)=>{Un.set(e,t)},Gn=(e,t)=>{let n=Un.get(e);n!==void 0&&Un.set(t,n)},Kn=/^\d+[smhdw]$/,qn=class e{offset;constructor(e){this.offset=e}plus(t){return new e({sign:`+`,duration:Jn(t)})}minus(t){return new e({sign:`-`,duration:Jn(t)})}toString(){return this.offset?`now() ${this.offset.sign} ${this.offset.duration}`:`now()`}},Jn=e=>{if(!Kn.test(e))throw Error(`"${e}" is not a duration: write a number and s, m, h, d or w, such as '7d'`);return e},G=class{text;op;constructor(e,t){this.text=e,this.op=t}and(e){return Yn(`and`,this,e)}or(e){return Yn(`or`,this,e)}toString(){return this.text}},Yn=(e,t,n)=>{let r=t=>t.op===`term`||t.op===e?t.text:`(${t.text})`;return new G(`${r(t)} ${e.toUpperCase()} ${r(n)}`,e)},Xn=e=>(typeof e==`object`||typeof e==`function`)&&e!==null&&W in e,K=e=>`{{~${e[W].scope}~${e[W].path.join(`.`)}}}`,Zn=({path:e,scope:t})=>`~~${t}~${e.join(`.`)}~~`,q=e=>{if(Xn(e))return K(e);if(e instanceof qn)return e.toString();if(e instanceof Date)return JSON.stringify(e.toISOString());if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`&&Number.isFinite(e)||typeof e==`boolean`||e===null)return String(e);throw Error(`${String(e)} cannot be a filter value: compare with text, a number, true or false, null, now() or a recorded field`)},J=e=>new G(e,`term`),Qn=e=>({eq:t=>J(t===null?`isNull(${e})`:`${e} = ${q(t)}`),ne:t=>J(t===null?`NOT isNull(${e})`:`${e} != ${q(t)}`),lt:t=>J(`${e} < ${q(t)}`),le:t=>J(`${e} <= ${q(t)}`),gt:t=>J(`${e} > ${q(t)}`),ge:t=>J(`${e} >= ${q(t)}`),in:t=>J(`in(${e}, ${t.map(q).join(`, `)})`),contains:t=>J(`${e}:${q(t)}`),isNull:()=>J(`isNull(${e})`)}),$n=new Set(Object.keys(Qn(``))),er=(e=[],t=zn.at(-1)??0)=>new Proxy({},{get:(n,r)=>{if(r===W)return{path:e,scope:t};if(r===Symbol.toPrimitive||r===`toString`||r===`toJSON`)return()=>K({[W]:{path:e,scope:t}});if(typeof r!=`symbol`)return $n.has(r)?Qn(Zn({path:e,scope:t}))[r]:er([...e,r],t)},has:(e,t)=>t===W}),tr=(e=[])=>new Proxy({},{get:(t,n)=>{if(typeof n!=`symbol`)return $n.has(n)&&e.length>0?Qn(e.join(`.`))[n]:tr([...e,n])}}),nr=`Layouts are static data, sent to the browser as JSON: use <Action name="..."> for behaviour, or register a custom component for React code.`,rr=e=>typeof e==`function`?`a function`:typeof e==`number`?String(e):typeof e!=`object`||!e?`a ${typeof e}`:`a ${e.constructor?.name??`object without prototype`}`,ir=e=>{let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},ar=(e,t)=>{if(e===null||typeof e==`string`||typeof e==`boolean`)return e;if(Xn(e))return K(e);if(e instanceof G||e instanceof qn)return e.toString();if(typeof e==`number`&&Number.isFinite(e))return e;if(Array.isArray(e))return e.map((e,n)=>ar(e,`${t.slice(0,-1)}[${n}]>`));if(typeof e==`object`&&ir(e)){let n=Object.fromEntries(Object.entries(e).flatMap(([e,n])=>n===void 0?[]:[[e,ar(n,`${t.slice(0,-1)}.${e}>`)]]));return Gn(e,n),n}throw Error(`${t} is ${rr(e)}. ${nr}`)},Y=(e,t)=>{if(e==null||typeof e==`boolean`)return[];if(typeof e==`string`)return[e];if(Xn(e))return[K(e)];if(typeof e==`number`&&Number.isFinite(e))return[String(e)];if(Array.isArray(e))return e.flatMap(e=>Y(e,t));if(C(e))return e.type===`Fragment`&&!e.custom?e.children:[e];throw Error(`${t} has a child that is ${rr(e)}. ${nr}`)},or=e=>typeof e==`function`&&typeof e.blockName==`string`,sr=[`RecordCard`,`CardRow`,`ReferenceField`,`RecordsIterator`],cr=[`filter`,`edgeFilter`,`animated`,`dashed`,`dotted`],lr=(e,t)=>{let n={...t};for(let t of cr){let r=n[t];if(typeof r==`function`){let i=r(tr());if(!(i instanceof G))throw Error(`<${e} ${t}> is an arrow that gives no condition: write (f) => f.status.eq('open'), or the ${t} as AIP-160 text`);n[t]=i.text}else if(typeof r==`object`&&r&&!(r instanceof G))throw Error(`<${e} ${t}> is an object: write the ${t} as an arrow, (f) => f.status.eq('open'), or as AIP-160 text`)}if(n.sort!==void 0){if(!Array.isArray(n.sort)||!n.sort.every(e=>typeof e==`string`))throw Error(`<${e} sort> takes a list of fields, each with asc or desc if it likes: sort={['next_run_at asc']}`);n.sort=n.sort.join(`, `)}return n},ur=(e,t,n)=>{if(typeof t!=`function`)return{children:Y(t,n)};if(!sr.includes(e))throw Error(`<${e}> takes elements as children; only ${sr.join(`, `)} take a function of their record`);let{scope:r,built:i}=Hn(e=>Y(t(er([],e)),n));return{children:i,scope:r}},dr={Graph:`node`},fr=new Set([`Graph`]),pr=(e,t,n)=>{let r=`<${e} ${t}>`,i=e=>{let[t]=e;return e.length===1&&typeof t==`object`?t:{type:`Box`,props:{},children:e}};if(typeof n!=`function`)return{value:n===void 0||C(n)?n:i(Y(n,r))};let{scope:a,built:o}=Hn(e=>Y(n(er([],e)),r));return{value:i(o),scope:a}},mr=(e,t)=>{if(typeof e==`string`)throw Error(`<${e}> is an HTML element, not a layout block: use the blocks from @protobase/layout or a custom component`);if(!or(e))throw Error(`<${typeof e==`function`&&e.name?e.name:`unknown`}> is not a layout block. Components in a layout are declared with component('Name') and implemented in the app; ${nr}`);let n=e.blockName,{children:r,...i}=t,a=!e.custom&&fr.has(n),{fallback:o,...s}=i,c=a?s:i,l=e.custom?c:lr(n,c),u=e.custom?void 0:dr[n],d=u===void 0?void 0:pr(n,u,l[u]);u!==void 0&&(l[u]=d.value);let f=e.custom?{children:Y(r,`<${n}>`)}:ur(n,r,`<${n}>`),p={type:n,props:Object.fromEntries(Object.entries(l).flatMap(([e,t])=>t===void 0?[]:[[e,ar(t,`<${n} ${e}>`)]])),children:f.children},m=f.scope??d?.scope;return m!==void 0&&Wn(p,m),e.custom&&(p.custom=!0),e.fallback&&(p.fallback=e.fallback),a&&o!==void 0&&(p.fallback=Y(o,`<${n} fallback>`)),e.reads&&(p.reads=e.reads),p},hr=(e,t,n,r)=>{let i=Object.assign(e=>mr(i,e),{blockName:e,custom:t,...n&&{fallback:n},...r&&{reads:r}});return i},gr=(e,t,n)=>{let r=[],i=e[t],a=n.split(`.`);for(let[o,s]of a.entries()){if(!i)return{ok:!1,message:`unknown resource "${t}"`};let c=Object.hasOwn(i.fields,s)?i.fields[s]:void 0;if(!c)return{ok:!1,message:`unknown field "${a.slice(0,o+1).join(`.`)}" on ${i.name}`};if(r.push({model:i,field:c}),o===a.length-1)break;if(c.type!==`relation`||!c.relation)return{ok:!1,message:`"${a.slice(0,o+1).join(`.`)}" is not a relation, so "${n}" cannot go through it`};t=c.relation.resource,i=e[t]}return{ok:!0,steps:r}},_r=new Set([1,2,3,4,5,6]),vr=8,yr=(e,t)=>{for(let n of e){_r.has(n.type)&&n.value!==void 0&&t.values.add(n.value),n.type===vr&&n.value!==void 0&&t.tags.add(n.value);for(let e of Object.values(n.options??{}))yr(e.value,t);n.children&&yr(n.children,t)}},br=(e,t)=>{let n={values:new Set,tags:new Set};return yr(new l(e,t).getAst(),n),{values:[...n.values],tags:[...n.tags]}},xr=new Map,Sr=(e,t,n={},r={})=>{let i=e?.messages[t];if(i===void 0||!e)return t;let a=`${e.locale}\u0000${i}`,o=xr.get(a);return o||(o=new l(i,e.locale),xr.set(a,o)),o.format({...n,...r})},Cr=(e,t,n={})=>{let r=Sr(e,t,n,Object.fromEntries((e?.messages[t]?br(e.messages[t],e.locale).tags:[]).map(e=>[e,e=>e.join(``)])));return Array.isArray(r)?r.join(``):r};hr(`Trans`,!1);var wr=e=>C(e)&&e.type===`Trans`&&!e.custom,Tr=(e,t)=>({...e,fields:Object.fromEntries(Object.entries(e.fields).map(([e,n])=>{if(!n.relation||Object.hasOwn(t,n.relation.resource))return[e,n];let{relation:r,...i}=n;return[e,i]}))}),Er=(e,t)=>{if(e.kind===`group`){let n=e.items.flatMap(e=>Er(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind===`tab`){let n=e.items.flatMap(e=>Er(e,t));return n.length>0?[{...e,items:n}]:[]}if(e.kind!==`related`)return[e];if(!Object.hasOwn(t,e.resource)||e.through&&!Object.hasOwn(t,e.through.resource))return[];let{columns:n,button:r,...i}=e,a=n?.filter(n=>gr(t,e.resource,n).ok),o=a&&a.length>0?{...i,columns:a}:i,s=r===void 0?void 0:qt(r,t[e.resource],{models:t,pages:new Set});return[s===void 0?o:{...o,button:s}]},Dr=(e,t,n)=>e.run?.kind!==`link`||!(`to`in e.run)||Lt(e.run.to,{models:n,pages:new Set,source:t}).length===0,Or=(e,t)=>({...e,layout:e.layout.flatMap(e=>Er(e,t)),actions:e.actions.filter(n=>Dr(n,t[e.resource],t))}),kr=(e,t)=>{let n=e.resources.filter(e=>t.resources.includes(e.name)),r=Object.fromEntries(n.map(e=>[e.name,e])),i=n.map(e=>Tr(e,r)),a=Object.fromEntries(i.map(e=>[e.name,e]));return{resources:i,views:e.views.filter(e=>Object.hasOwn(a,e.resource)).map(e=>Or(e,a)),permissions:Object.fromEntries(n.flatMap(t=>e.permissions?.[t.name]?[[t.name,e.permissions[t.name]]]:[]))}},Ar={create:!0,update:!0,delete:!0,conditional:[]},jr=1e4,Mr=e=>e.map(e=>({data:e.data?.meta,error:e.error})),Nr=(e,t)=>{let n=u(),r=c({queries:e.map(e=>{let r=te.sourceMeta(e.url,e.resources);return{queryKey:r,staleTime:0,refetchOnWindowFocus:`always`,queryFn:async()=>{let i=n.getQueryData(r),a=await t(e).meta(i?.etag,{signal:AbortSignal.timeout(jr)});if(a.status===`unchanged`){if(!i)throw Error(`${e.label} answered 304 to a request without If-None-Match`);return i}return{etag:a.etag,meta:kr(a.meta,e)}}}}),combine:Mr});return(0,R.useMemo)(()=>e.map((e,t)=>{let{data:n,error:i}=r[t];return n?{source:e,state:`ready`,meta:n}:i?{source:e,state:`error`,error:i}:{source:e,state:`loading`}}),[e,r])},Pr=(e,t)=>{if(t.length===0)return e;let n=t.flatMap(e=>e.state===`ready`?[e.meta]:[]),r=t.map(e=>e.state===`error`?{source:e.source,state:`error`,error:e.error}:{source:e.source,state:e.state});return{...e,resources:{...e.resources,...Object.fromEntries(n.flatMap(e=>e.resources.map(e=>[e.name,e])))},views:{...e.views,...Object.fromEntries(n.flatMap(e=>e.views.map(e=>[e.resource,e])))},permissions:{...e.permissions,...Object.assign({},...n.map(e=>e.permissions))},sources:r}},Fr=(e,t)=>e.sources?.find(e=>e.source.resources.includes(t)),Ir=({locale:e,children:t})=>{me(e);let n=fe();return(0,R.useEffect)(()=>{document.documentElement.lang=n},[n]),(0,z.jsx)(R.Fragment,{children:t},n)},Lr=(0,R.createContext)(void 0),Rr=()=>(0,R.useContext)(Lr),zr=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Br=(e,t)=>Cr(t,String(e.props.i18nKey),zr(e.props.values)?e.props.values:{}),Vr=(e,t)=>e.custom||!Object.values(e.props).some(wr)?e:{...e,props:Object.fromEntries(Object.entries(e.props).map(([e,n])=>[e,wr(n)?Br(n,t):n]))},Hr=(e,t)=>{let n=Vr(e,t);if(e.custom||e.type!==`Tabs`)return n;let r=n.children.map(e=>typeof e==`string`?e:Vr(e,t));return r.some((e,t)=>e!==n.children[t])?{...n,children:r}:n},Ur=`app/built-in-views`,Wr=pe(Ur),X=(e,t)=>Object.hasOwn(he.en[Ur],e)?Wr(e):t,Gr=(e,t)=>({...t,...t.label!==void 0&&{label:X(`${e}.label`,t.label)},...t.help!==void 0&&{help:X(`${e}.help`,t.help)},...t.valueLabels&&{valueLabels:Object.fromEntries(Object.entries(t.valueLabels).map(([t,n])=>[t,X(`${e}.values.${t}`,n)]))}}),Kr=(e,t)=>{let n=t;return{...t,...n.title!==void 0&&{title:X(`${e}.title`,n.title)},...n.help!==void 0&&{help:X(`${e}.help`,n.help)},...n.empty!==void 0&&{empty:X(`${e}.empty`,n.empty)}}},qr=e=>e.name===`record_history`&&e.table.name===`history`?`changes.history`:`${e.table.schema??`public`}.${e.table.name}`,Jr=(e,t)=>({...t,label:X(`${e}.label`,t.label),...t.confirm!==void 0&&{confirm:X(`${e}.confirm`,t.confirm)}}),Yr=(e,t)=>{if(!t)return e;let n=qr(t);return{...e,...e.names&&{names:{singular:X(`${n}.names.singular`,e.names.singular),plural:X(`${n}.names.plural`,e.names.plural)}},...e.help!==void 0&&{help:X(`${n}.help`,e.help)},fields:Object.fromEntries(Object.entries(e.fields).map(([e,t])=>[e,Gr(`${n}.fields.${e}`,t)])),layout:e.layout.map((e,t)=>Kr(`${n}.layout.${t}`,e)),actions:e.actions.map(e=>Jr(`${n}.actions.${e.name}`,e))}},Xr=e=>({...e,views:Object.fromEntries(Object.entries(e.views).map(([t,n])=>[t,Yr(n,e.resources[n.resource])]))}),Zr=e=>{let t=0,n=!1,r=!1,i=()=>queueMicrotask(()=>{!n||r||t>0||(r=!0,e())});return{hold:()=>{t+=1;let e=!1;return()=>{e||(e=!0,--t,i())}},start:()=>{n=!0,i()}}},Qr=(0,R.createContext)(void 0),$r=({value:e,children:t})=>(0,z.jsx)(Qr.Provider,{value:e,children:t}),ei=()=>{let e=(0,R.useContext)(Qr);return(0,R.useEffect)(()=>e?.hold(),[e]),null},Z=pe(`app/meta-gate`),ti=()=>{let e=(0,R.useContext)(_e);if(!e)throw Error(`useAdminMeta must be used inside MetaGate`);return e},ni=({title:e,children:t})=>(0,z.jsx)(`div`,{className:`flex h-full min-h-48 flex-1 items-center justify-center p-8`,children:(0,z.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,z.jsx)(`h1`,{className:`text-base font-semibold`,children:e}),(0,z.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:t})]})}),ri=({meta:e,children:t})=>{let n=ee(),r=x(),i=(0,R.useMemo)(()=>(e.sources??[]).map(e=>e.source),[e.sources]),a=Nr(i,r),o=(0,R.useMemo)(()=>Pr(e,a),[e,a]),s=(0,R.useMemo)(()=>{let e=new Map(i.flatMap(e=>e.resources.map(t=>[t,e]))),t=t=>{let n=e.get(t);return n&&r(n)};return{client:Rn(n,t),resourceClient:t}},[i,n,r]);return(0,z.jsx)(b,{client:s.client,resourceClient:s.resourceClient,children:(0,z.jsx)(Ir,{locale:e.locale,children:(0,z.jsx)(Lr.Provider,{value:e.texts,children:(0,z.jsx)(ii,{meta:o,children:t})})})})},ii=({meta:e,children:t})=>{let n=(0,R.useMemo)(()=>Xr(e),[e]);return(0,z.jsx)(_e.Provider,{value:n,children:t})},ai=({children:e})=>{let t=ye();return t.isPending?(0,z.jsxs)(`div`,{className:be(`flex h-full min-h-48 items-center justify-center gap-2 text-muted-foreground`,oe),children:[(0,z.jsx)(ei,{}),(0,z.jsx)(h,{}),` `,Z(`loading`)]}):t.error?(0,z.jsx)(ni,{title:Z(`cannotReach`),children:g(t.error)?t.error.message:Z(`noAnswer`)}):(0,z.jsx)(ri,{meta:t.data,children:e})},oi=e=>ti().permissions[e]??Ar,si=e=>(0,R.useSyncExternalStore)(t=>{let n=window.matchMedia(e);return n.addEventListener(`change`,t),()=>n.removeEventListener(`change`,t)},()=>window.matchMedia(e).matches,()=>!1),ci=()=>si(`(min-width: 768px)`),li=()=>si(`not all and (min-width: 640px)`),ui=`$photos`,di=e=>{for(let t of e?.list?.displays??[])if(t.kind===`cards`&&t.photos)return t.photos},fi=(e,t,n)=>{if(n===void 0||e.primaryKey.length!==1)return t;let r=e.primaryKey[0];return t.map(e=>({...e,[ui]:n[String(e[r])]??[]}))},pi=(e,t)=>t.filter(t=>e[t]!==null&&e[t]!==void 0&&e[t]!==``),Q=pe(`app/displays`),mi=(e,t,n)=>{let r=e.fields[n.by];if(!r)return[];let i=t?.fields[n.by],a=(r.enumValues??[]).map(e=>({value:e,label:ae(e,i?.valueLabels)}));return r.nullable?[...a,{value:null,label:Q(`noValue`,{label:i?.label??ge(n.by)})}]:a},hi=e=>e.position&&e.position.within===void 0?e.position.field:void 0,gi=(e,t,n)=>{let r=d(n===null?pt.isNull(t):pt.eq(t,n));return e===``?r:`(${e}) AND ${r}`},_i=(e,t,n)=>({kind:`cards`,name:n.name,title:n.title??L(e,t),...n.subtitle!==void 0&&{subtitle:n.subtitle},...n.badge!==void 0&&{badge:n.badge},...n.meta&&{meta:n.meta}}),vi=e=>{if(!g(e))return e instanceof Error?e.message:Q(`somethingWrong`);let t=e.errors.map(e=>e.message);return t.length>0?t.join(`; `):e.message},$=e=>e?.list?.displays??[],yi=(e,t)=>t??e?.list?.default,bi=(e,t,n)=>{let r=yi(e,n);return r===void 0?t?$(e).find(e=>e.kind===`cards`)?.name??`table`:I:r},xi=`rows`,Si=(e,t)=>{if($(t).some(e=>e.kind===`cards`||e.name===`rows`))return;let n=L(e,t),r=Qt(e,t).filter(t=>t!==n&&e.fields[t]!==void 0),i=r.find(t=>e.fields[t].type===`enum`),a=r.filter(t=>t!==i&&e.fields[t].type!==`boolean`).slice(0,2);return{kind:`cards`,name:xi,label:Q(`list`),icon:`list`,title:n,...i!==void 0&&{badge:i},footer:a}},Ci=(e,t)=>t.name===`rows`&&!$(e).some(e=>e.name===`rows`),wi=(e,t,n)=>{let r=bi(t,n);return n&&yi(t)===void 0&&r===`table`&&Si(e,t)?xi:r},Ti=(e,t,n)=>(n===`rows`?Si(e,t):void 0)??Ei(t,n),Ei=(e,t)=>{if(t===`table`)return;let n=t=>$(e).find(e=>e.name===t);return n(t)??n(e?.list?.default)},Di={cards:`cards`,map:`map`,board:`kanban`,calendar:`calendar`,timeline:`timeline`},Oi=e=>[{name:I,label:Q(`table`),icon:`table`},...$(e).map(e=>({name:e.name,label:e.label??ge(e.name),icon:e.icon??Di[e.kind]}))],ki=(e,t,n)=>{let r=Oi(t);return n&&Si(e,t)?[...r,{name:xi,label:Q(`list`),icon:`list`}]:r},Ai=(e,t,n)=>({image:n.image,title:n.title??L(e,t),subtitle:n.subtitle,amount:n.amount??[],badge:n.badge,code:n.code,meta:n.meta??[],footer:n.footer??[],flags:n.flags??[]}),ji=(e,t)=>pi(e.record,t),Mi=(e,t)=>ji(e,t)[0],Ni=(e,t)=>t===void 0?void 0:ji(e,[t])[0],Pi=(e,t)=>e?.type===`text`&&typeof t==`string`?t:void 0,Fi=(e,t,n={})=>{let{suffix:r,...i}=n;return e.type!==`decimal`&&e.type!==`integer`&&e.type!==`bigint`||r===void 0||n.format===`percent`?{amount:de(e,t,n)}:{amount:de(e,t,i),suffix:r}},Ii=(e,t)=>{let n=$(e).filter(e=>e.kind===`cards`);return(t.cards===void 0?n[0]:n.find(e=>e.name===t.cards))??{kind:`cards`,name:t.name}},Li=(e,t,n)=>{if(n.kind===`custom`)return n.fields;if(n.kind===`map`)return[n.latitude,n.longitude,...Li(e,t,Ii(t,n))];if(n.kind===`board`){let r=_i(e,t,n);return[n.by,r.title,r.subtitle,r.badge,...r.meta??[]].filter(e=>e!==void 0)}if(n.kind===`calendar`)return[n.start,n.end,n.title??L(e,t)].filter(e=>e!==void 0);if(n.kind===`timeline`)return[n.start,n.end,n.group,n.title??L(e,t)].filter(e=>e!==void 0);let{image:r,title:i,subtitle:a,amount:o,badge:s,code:c,meta:l,footer:u,flags:d}=Ai(e,t,n);return[r,i,a,...o,s,c,...l,...u,...d].filter(e=>e!==void 0)},Ri=e=>(e?.actions??[]).flatMap(e=>(e.inputs??[]).flatMap(e=>e.from===void 0?[]:[e.from])),zi=(e,t)=>t.flatMap(t=>w(e?.fields[t]?.linkText??``)),Bi=(e,t,n)=>{let r=Si(e,t),i=r?[...$(t),r]:$(t),a=[...n,...i.flatMap(n=>Li(e,t,n))];return[...new Set([...a,...zi(t,a),...Ri(t)])]},Vi=(e,t,n)=>{let r=Ci(t,n)?[L(e,t),...Qt(e,t)]:Li(e,t,n);return[...new Set(r)].filter(t=>e.fields[t]?.sortable)},Hi=e=>typeof e==`object`&&!!e&&`id`in e&&`name`in e,Ui=(e,t)=>{let n={},r={},i=Array.isArray(t.$photos)?t[ui]:void 0;for(let[i,a]of Object.entries(t))(i!==`id`&&i!==`$photos`||Object.hasOwn(e.fields,i))&&(e.fields[i]?.type===`relation`&&Hi(a)?(n[i]=a.id,r[i]=a.name):n[i]=a);return{key:y(le(e,n)),record:n,labels:r,...i&&{photos:i}}},Wi=(e,t)=>{let n=t?.list?.sort?.[0];if(n)return`${n[0]} ${n[1]}`;let r=e.primaryKey[0];return e.fields[r]?.sortable?`${r} asc`:``},Gi=e=>{let[t=``,n]=e.trim().split(/\s+/);return{columnId:t,direction:n===`desc`?`desc`:`asc`}},Ki=e=>`${e.columnId} ${e.direction}`,qi=(e,t,n,r)=>{let i=e[n],a=Mt(t[n],r),o=a?.listOf,s=o===void 0?void 0:i?.fields[o]?.relation?.resource;return s!==void 0&&e[s]?{model:e[s],view:t[s],listOf:!0}:{model:i,view:a,listOf:!1}},Ji=(e,t,n=!1)=>({display:e?wi(e,t,n):bi(t,n),orderBy:e?Wi(e,t):``,filterLayout:`bar`,filter:t?.list?.filter??``}),Yi=(e,t)=>e?.kind===`record`?{kind:`record`,resource:e.resource,key:y(e.key),...e.edit&&{edit:!0},...e.open&&{open:e.open},...e.tab&&{tab:e.tab},...e.standard&&{standard:!0},...e.call&&{call:e.call},...e.version!==void 0&&{version:e.version},...e.run&&{run:e.run},...e.panel&&{panel:e.panel},...e.file&&{file:e.file}}:e?.kind===`list`?{...t(e.resource,e.list),...e}:e,Xi=(e,t,n)=>{let r={...e,...t},i=e=>r[e]!==void 0&&r[e]!==n[e];return{kind:`list`,resource:e.resource,...e.list&&{list:e.list},...i(`filter`)&&{filter:r.filter},...i(`display`)&&{display:r.display},...i(`orderBy`)&&{orderBy:r.orderBy},...i(`filterLayout`)&&{filterLayout:r.filterLayout},...r.map&&{map:r.map},...r.calendar&&{calendar:r.calendar},...r.timeline&&{timeline:r.timeline},...r.savedSearch&&{savedSearch:r.savedSearch}}},Zi=()=>{let{path:e,params:t,basePath:n,navigate:r,back:i}=B(),{pages:a,resources:o,views:s}=ti(),c=li(),l=(0,R.useMemo)(()=>new Set(Object.keys(a)),[a]),u=t.toString(),d=(0,R.useMemo)(()=>In(u?`${e}?${u}`:e,l),[e,u,l]),f=(0,R.useCallback)((e,t)=>{let n=qi(o,s,e,t);return Ji(n.model,n.view,c)},[o,s,c]),p=(0,R.useMemo)(()=>Yi(d,f),[d,f]),m=(0,R.useCallback)((e,t)=>r(U(e),t),[r]),h=(0,R.useCallback)(e=>{if(d?.kind!==`list`)throw Error(`listTo and set change the list the app shows; use go to move to another address`);return Xi(d,e,f(d.resource,d.list))},[d,f]),g=(0,R.useCallback)(e=>m(h(e),{replace:!0}),[h,m]),_=(0,R.useCallback)(e=>U(e,n),[n]),v=(0,R.useCallback)(e=>e.startsWith(`${n}/`)?e.slice(n.length):e,[n]);return{address:p,set:g,listTo:h,go:m,href:_,open:(0,R.useCallback)(e=>r(v(e)),[v,r]),back:(0,R.useCallback)(e=>i(v(e)),[v,i])}},Qi=({to:e,...t})=>(0,z.jsx)(xn,{to:U(e),...t});export{hr as $,vi as A,Me as At,ti as B,Li as C,_t as Ct,mi as D,st as Dt,_i as E,pt as Et,ci as F,Zr as G,Z as H,li as I,Ir as J,Rr as K,si as L,pi as M,di as N,hi as O,ot as Ot,fi as P,gr as Q,ai as R,Ei as S,St,Vi as T,ft as Tt,ei as U,oi as V,$r as W,Ar as X,Fr as Y,Sr as Z,ji as _,At as _t,qi as a,en as at,Ii as b,Tt as bt,Ki as c,Zt as ct,bi as d,Bt as dt,U as et,Oi as f,Ut as ft,Ni as g,wt as gt,Mi as h,kt as ht,Ji as i,B as it,Q as j,gi as k,rt as kt,Fi as l,L as lt,$ as m,Mt as mt,Zi as n,bn as nt,Wi as o,Qt as ot,Ui as p,Vt as pt,Hr as q,Xi as r,Sn as rt,Gi as s,Xt as st,Qi as t,xn as tt,Ai as u,Ht as ut,ki as v,Dt as vt,Ti as w,ht as wt,Pi as x,I as xt,Bi as y,jt as yt,ni as z};
|
|
2
|
+
//# debugId=f9d1f375-9cfb-4aa5-a465-7f9e0fd2e010
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,r as n,t as r}from"./react-CuiNlnus.js";import{Y as i,rt as a}from"./vendor-WWp_xlp2.js";import{c as o,r as s,s as c,u as l}from"./api-provider-
|
|
2
|
-
//# debugId=
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,r as n,t as r}from"./react-CuiNlnus.js";import{Y as i,rt as a}from"./vendor-WWp_xlp2.js";import{c as o,r as s,s as c,u as l}from"./api-provider-CcDtTh0D.js";import{t as u}from"./cn-B1sdg8aY.js";var d=e=>e.charAt(0).toUpperCase()+e.slice(1),f=e=>d(e.replace(/(Id|Code|_id|_code)$/,``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/_+/g,` `).trim().toLowerCase()||e),p=e(t(),1),m=e(n(),1),h=`data-pb-scroll-locked`,g=()=>{let{body:e,documentElement:t}=document,n=e.style.overflow,r=t.hasAttribute(h);return window.innerWidth>t.clientWidth&&t.setAttribute(h,``),e.style.overflow=`hidden`,()=>{e.style.overflow=n,r||t.removeAttribute(h)}},_=`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`,v=[],y=(e,t,n)=>{let r=(0,p.useRef)(n);r.current=n,(0,p.useEffect)(()=>{if(!t||!e.current)return;let n=e.current,i=document.activeElement instanceof HTMLElement?document.activeElement:null,a=g(),o={};v.push(o);let s=()=>[...n.querySelectorAll(_)];(s()[0]??n).focus();let c=e=>{if(v.at(-1)!==o)return;if(e.key===`Escape`)return r.current();if(e.key!==`Tab`)return;let t=s();if(t.length===0)return e.preventDefault();let i=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===i?(e.preventDefault(),a.focus()):!e.shiftKey&&document.activeElement===a?(e.preventDefault(),i.focus()):n.contains(document.activeElement)||(e.preventDefault(),i.focus())};return document.addEventListener(`keydown`,c),()=>{document.removeEventListener(`keydown`,c),v.splice(v.indexOf(o),1),a(),i?.focus()}},[t,e])},b=e(r(),1),x=({title:e,description:t,onClose:n,actions:r,children:i,wide:a=!1,name:o})=>{let s=(0,p.useRef)(null);return y(s,!0,n),(0,m.createPortal)((0,b.jsx)(`div`,{"data-dialog":o??``,className:`fixed inset-0 z-[90] flex items-center justify-center bg-backdrop/30 p-4 pb-[calc(1rem+var(--pb-safe-bottom))] pl-[calc(1rem+var(--pb-safe-left))] pr-[calc(1rem+var(--pb-safe-right))] pt-[calc(1rem+var(--pb-safe-top))]`,onMouseDown:e=>e.target===e.currentTarget&&n(),children:(0,b.jsxs)(`div`,{ref:s,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,className:u(`outline-none max-h-[min(90vh,100%)] w-full overflow-y-auto rounded-lg border bg-background p-4 shadow-pop sm:p-5`,a?`max-w-3xl`:`max-w-md`),children:[(0,b.jsx)(`h2`,{className:`text-base font-semibold`,children:e}),t&&(0,b.jsx)(`p`,{className:`mt-1.5 text-muted-foreground`,children:t}),i&&(0,b.jsx)(`div`,{className:`mt-4`,children:i}),(0,b.jsx)(`div`,{className:`mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end [&>*]:min-h-11 sm:[&>*]:min-h-0`,children:r})]})}),document.body)},S=(0,p.createContext)(null),C=(e,t)=>e?e.versionChange?e:t.protobaseVersion===e.protobaseVersion?t:{...e,versionChange:{...t.protobaseVersion&&{to:t.protobaseVersion}}}:t,w=()=>{let e=s(),t=a(),n=(0,p.useContext)(S),r=(0,p.useContext)(c),u=i({queryKey:l.meta,staleTime:0,refetchOnWindowFocus:`always`,enabled:e=>!e.state.data?.versionChange,queryFn:async()=>{let n=t.getQueryData(l.meta),i=await e.meta(n?.etag);if(i.status===`unchanged`){if(!n)throw Error(`The server answered 304 to a request without If-None-Match`);return n}let a=t.getQueryState(l.meta);return C(a&&o(a,r)?void 0:n,{etag:i.etag,appName:i.meta.appName,...i.meta.protobaseVersion&&{protobaseVersion:i.meta.protobaseVersion},...i.meta.appIcon&&{appIcon:i.meta.appIcon},resources:Object.fromEntries(i.meta.resources.map(e=>[e.name,e])),views:Object.fromEntries(i.meta.views.map(e=>[e.resource,e])),pages:Object.fromEntries((i.meta.pages??[]).map(e=>[e.name,e])),...i.meta.account&&{account:i.meta.account},permissions:i.meta.permissions??{},...i.meta.userMenu&&{userMenu:i.meta.userMenu},...i.meta.signIn&&{signIn:Object.fromEntries(i.meta.signIn.map(e=>[e.resource,e]))},...i.meta.bottomBar&&{bottomBar:i.meta.bottomBar},...i.meta.assistant&&{assistant:i.meta.assistant},...i.meta.runtime&&{runtime:i.meta.runtime},...i.meta.errorReporting&&{errorReporting:i.meta.errorReporting},...i.meta.maps&&{maps:i.meta.maps},...i.meta.notifications?.bell&&{bell:!0},...i.meta.status&&{status:!0},...i.meta.calls&&{calls:!0},...i.meta.locale&&{locale:i.meta.locale},...i.meta.texts&&{texts:i.meta.texts},...i.meta.files&&{files:i.meta.files},...i.meta.plugins&&{plugins:i.meta.plugins},...i.meta.sources&&{sources:i.meta.sources.map(e=>({source:e,state:`loading`}))}})}});return(0,p.useMemo)(()=>n&&u.data?{...u,data:n}:u,[n,u])};export{f as a,y as i,S as n,x as r,w as t};
|
|
2
|
+
//# debugId=6a12a38b-35ea-4db0-b9b0-5f5ff2cef250
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{X as r,Y as i}from"./vendor-WWp_xlp2.js";import{i as a}from"./api-provider-
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{X as r,Y as i}from"./vendor-WWp_xlp2.js";import{i as a}from"./api-provider-CcDtTh0D.js";import{Dt as o,Tt as s}from"./app-CYep6fHL.js";import{t as c}from"./cn-B1sdg8aY.js";var l=e(t(),1),u=(e,t,n)=>e?.nonce===t?e.value:n,d=(e,t)=>{let[n,r]=(0,l.useState)(),i=(0,l.useCallback)(n=>r(r=>({nonce:e,value:n(u(r,e,t))})),[e,t]);return[u(n,e,t),i]},f=`data-protobase-link`,p=`(() => {
|
|
2
2
|
const post = (message) => parent.postMessage({ protobase: 'html-frame', ...message }, '*')
|
|
3
3
|
const place = (hash) => {
|
|
4
4
|
const name = decodeURIComponent(hash.slice(1))
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
new ResizeObserver(height).observe(document.documentElement)
|
|
24
24
|
})()`,m=`allow-scripts`,h=(e,t)=>[`default-src 'none'`,e===`bridge`?`script-src 'nonce-${t}'`:`script-src 'unsafe-inline'`,`img-src data:`,`media-src data:`,`style-src 'unsafe-inline' data:`,`font-src data:`,`base-uri 'none'`,`form-action 'none'`].join(`; `),g=()=>Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,`0`)).join(``),_=`meta[http-equiv], base, noscript`,v=(e,t,n)=>{let r=new DOMParser().parseFromString(e,`text/html`);for(let e of r.querySelectorAll(_))e.remove();let i=r.createElement(`meta`);i.httpEquiv=`Content-Security-Policy`,i.content=h(t,n);let a=r.createElement(`meta`);a.name=`referrer`,a.content=`no-referrer`;let o=r.createElement(`script`);return t===`bridge`&&o.setAttribute(`nonce`,n),o.textContent=p,r.head.prepend(i,a,o),`<!doctype html>${r.documentElement.outerHTML}`},y=1,b=(e,t,n)=>e?.kind===`fixed`?e:e&&n!==e.viewport&&Math.abs(t-e.height-(n-e.viewport))<=y?{kind:`fixed`}:{kind:`measured`,height:t,viewport:n},x=e=>e?.kind===`measured`&&e.height>0?{style:{height:e.height}}:{className:`min-h-[60vh]`},S=1e5,C=(e,t,n)=>{if(!t||e.source!==t)return;let r=e.data;if(typeof r==`object`&&r&&`protobase`in r&&r.protobase===`html-frame`){if(`link`in r&&Number.isInteger(r.link)&&r.link>=0&&r.link<n)return{kind:`link`,index:r.link,newTab:`newTab`in r&&r.newTab===!0};if(`height`in r&&typeof r.height==`number`&&Number.isFinite(r.height)&&r.height>=0)return{kind:`height`,height:Math.min(Math.ceil(r.height),S)};if(`scroll`in r&&typeof r.scroll==`number`&&Number.isFinite(r.scroll))return{kind:`scroll`,top:Math.min(Math.max(Math.round(r.scroll),0),S)}}},w=e(n(),1),T=[],E=(e,t)=>{let n=Number.parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop)||0;window.scrollTo({top:e.getBoundingClientRect().top+window.scrollY+t-n})},D=({html:e,title:t,links:n=T,onLink:r,scripts:i=`bridge`,className:a})=>{let o=(0,l.useRef)(null),s=(0,l.useMemo)(()=>{let t=g();return{nonce:t,srcDoc:v(e,i,t)}},[e,i]),[u,f]=d(s.nonce,void 0),[p,h]=d(s.nonce,0),_=`${s.nonce}:${p}`,y=(0,l.useRef)({key:_,count:0});(0,l.useEffect)(()=>{let e=e=>{let t=C(e,o.current?.contentWindow,n.length),i=o.current?.clientHeight;t?.kind===`height`&&i!==void 0&&f(e=>b(e,t.height,i)),t?.kind===`link`&&r?.(n[t.index],{newTab:t.newTab}),t?.kind===`scroll`&&o.current&&E(o.current,t.top)};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[n,r,f]);let S=()=>{y.current.key!==_&&(y.current={key:_,count:0}),y.current.count+=1,y.current.count>1&&h(e=>e+1)},D=x(u);return(0,w.jsx)(`iframe`,{ref:o,title:t,sandbox:m,referrerPolicy:`no-referrer`,allow:i===`bridge`?`fullscreen`:void 0,srcDoc:p>1?``:s.srcDoc,onLoad:S,className:c(`block w-full border-0 bg-white`,D.className,a),style:D.style},_)},O=e=>e.split(/[?#]/,1)[0].split(`/`).includes(`..`),k=(e,t)=>{let n=t.trim(),r=A(n);if(!(O(n)||O(r)))return o(e,n)??o(e,r)},A=e=>{try{return decodeURI(e)}catch(t){if(t instanceof URIError)return e;throw t}},j=(e,t)=>e.split(`,`).map(e=>{let n=/^(\s*)(\S+)([\s\S]*)$/.exec(e),r=n&&t(n[2]);return n&&r?`${n[1]}${r}${n[3]}`:e}).join(`,`),M=(e,t)=>e.replace(/url\(\s*(['"]?)([^'")]*)\1\s*\)/gi,(e,n,r)=>{let i=t(r.trim());return i?`url("${i}")`:e}),N=e=>{if(!URL.canParse(e))return;let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`?t.href:void 0},P=[`img[src]`,`source[src]`,`video[src]`,`audio[src]`,`track[src]`,`input[src]`].join(`, `),F=(e,t)=>{let n=(e,t,n)=>n!==void 0&&e.setAttribute(t,n);for(let r of e.querySelectorAll(P))n(r,`src`,t(r.getAttribute(`src`)));for(let r of e.querySelectorAll(`video[poster]`))n(r,`poster`,t(r.getAttribute(`poster`)));for(let r of e.querySelectorAll(`img[srcset], source[srcset]`))n(r,`srcset`,j(r.getAttribute(`srcset`),t));for(let r of e.querySelectorAll(`link[href]`))n(r,`href`,t(r.getAttribute(`href`)));for(let r of e.querySelectorAll(`image[href]`))n(r,`href`,t(r.getAttribute(`href`)));for(let r of e.querySelectorAll(`[style]`))n(r,`style`,M(r.getAttribute(`style`),t));for(let n of e.querySelectorAll(`style`))n.textContent=M(n.textContent,t)},I=e=>new DOMParser().parseFromString(e,`text/html`),L=(e,t)=>{let n=new Set;return F(I(e),e=>{let r=k(t,e);r&&n.add(r)}),[...n]},R=(e,t,n,r)=>{let i=I(e);for(let e of i.querySelectorAll(`[${f}]`))e.removeAttribute(f);F(i,e=>{let r=k(t,e);return r&&n.get(r.uri)});let a=[];for(let e of i.querySelectorAll(`a[href], area[href]`)){let n=e.getAttribute(`href`);if(n.startsWith(`#`))continue;e.removeAttribute(`target`);let i=k(t,n),o=i?void 0:N(n);if(!i&&!o){e.removeAttribute(`href`);continue}let s=i?{kind:`file`,file:i}:{kind:`external`,url:o},c=r?.(s);c!==void 0&&e.setAttribute(`href`,c),e.setAttribute(f,String(a.length)),a.push(s)}return{html:`<!doctype html>${i.documentElement.outerHTML}`,links:a}},z=e=>JSON.stringify(e.map(e=>[e.uri,`key`in e?e.key:null,`field`in e?e.field:null])),B=class extends Error{status;name=`FileReadError`;constructor(e){super(`The file could not be read: its link answered ${e}`),this.status=e}},V=e=>{let t=s(),n=a(t);return i({queryKey:[`file-text`,t,e.uri],staleTime:1/0,queryFn:async()=>{let r=await fetch(n.fileReadUrl(t,e));if(!r.ok)throw new B(r.status);return r.text()}})},H=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error),r.readAsDataURL(e)}),U=e=>{let t=s(),n=a(t),i=r({queries:e.map(e=>({queryKey:[`file-data-url`,t,e.uri],staleTime:1/0,retry:!1,queryFn:async()=>{let r=await fetch(n.fileReadUrl(t,e));if(!r.ok)throw new B(r.status);return H(new Blob([await r.arrayBuffer()],{type:e.type}))}}))}),o=new Map;return i.forEach((t,n)=>t.data!==void 0&&o.set(e[n].uri,t.data)),{contents:o,ready:i.every(e=>!e.isPending)}},W=(e,t,n)=>{let r=z(t),{contents:i,ready:a}=U((0,l.useMemo)(()=>e===void 0?[]:L(e,t),[e,r])),o=[...i.keys()].join(`
|
|
25
25
|
`);return(0,l.useMemo)(()=>e===void 0||!a?void 0:R(e,t,i,n),[e,r,a,o,n])};export{D as a,R as i,B as n,V as r,W as t};
|
|
26
|
-
//# debugId=
|
|
26
|
+
//# debugId=9cc29da0-33e5-466e-a365-30958c1bcafc
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{Y as r,rt as i,tt as a}from"./vendor-WWp_xlp2.js";import{d as o,k as s,r as c,u as l}from"./api-provider-
|
|
2
|
-
//# debugId=
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{Y as r,rt as i,tt as a}from"./vendor-WWp_xlp2.js";import{d as o,k as s,r as c,u as l}from"./api-provider-CcDtTh0D.js";import{i as u}from"./display-value-fDiKbfJO.js";import{n as d}from"./messages-ClKBpZlk.js";import{t as f}from"./badge-ChHXC28D.js";var p=[`neutral`,`blue`,`green`,`amber`,`red`,`violet`],m=e=>p.includes(e),h=e(t(),1),g=(e,t)=>{let n=String(t);return e&&Object.hasOwn(e,n)?e[n]:void 0},_=(e,t)=>{let n=g(e,t);return n===void 0||m(n)?void 0:n},v=(e,t)=>{let n=g(e,t);return n!==void 0&&m(n)?n:`neutral`},y=(e,t)=>({model:e,record:t,key:s(u(e,t)),etag:typeof t.etag==`string`?t.etag:void 0,permissions:t.permissions}),b=(e,t,n=``)=>({queryKey:l.count(t.name,n),queryFn:async()=>{let r=await e.list(t.name,{filter:n||void 0,pageSize:1,count:`exact`,fields:t.primaryKey});return r.totalSize??r.totalSizeEstimate}}),x=(e,t=``,n=!0)=>r({...b(c(),e,t),enabled:n}),S=(e,t,{filter:n=``,sort:r=``,key:i})=>({queryKey:i===void 0?l.firstRecord(t.name,n,r):l.record(t.name,i),queryFn:async()=>{if(i!==void 0){let n=await e.get(t.name,i);return{...y(t,n.record),etag:n.etag,permissions:n.permissions}}let a=await e.list(t.name,{filter:n||void 0,orderBy:r||void 0,pageSize:1});return a.items[0]?y(t,a.items[0]):null}}),C=(e,{enabled:t=!0,...n})=>r({...S(c(),e,n),enabled:t}),w=(e,t,{filter:n=``,sort:r=``,pageSize:i,pageToken:a=``})=>({queryKey:l.list(t.name,n,r,i,a),queryFn:()=>e.list(t.name,{filter:n||void 0,orderBy:r||void 0,pageSize:i,pageToken:a||void 0})}),T=(e,{enabled:t=!0,...n})=>r({...w(c(),e,n),enabled:t,placeholderData:a}),E=(e,t)=>({isPending:t.isPending,error:t.error,data:t.rows[0]?{...y(e,t.rows[0]),planned:!0}:t.isPending?void 0:null}),D=()=>{let e=i();return(0,h.useCallback)(t=>e.invalidateQueries({predicate:e=>o(e.queryKey,new Set([t]))}),[e])},O=d(`app/pages`),k=e(n(),1),A=({value:e,hints:t,children:n})=>(0,k.jsx)(f,{tone:v(t?.valueColors,e),color:_(t?.valueColors,e),shape:t?.badgeShape,children:n});export{w as a,x as c,D as d,_ as f,m as h,S as i,C as l,p as m,O as n,E as o,v as p,b as r,y as s,A as t,T as u};
|
|
2
|
+
//# debugId=4a2d5e28-b49d-46bf-a959-02a8fc14bcb4
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{t as r}from"./guarded-D7vqlAj1.js";import{b as i}from"./api-provider-
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{t as r}from"./guarded-D7vqlAj1.js";import{b as i}from"./api-provider-CcDtTh0D.js";import{in as a}from"./app-CYep6fHL.js";import{r as o}from"./messages-ClKBpZlk.js";import{t as s}from"./cn-B1sdg8aY.js";import{C as c,D as l,M as u,N as d,O as f,S as p,a as m,b as h,c as g,d as _,f as v,g as y,h as ee,i as te,j as b,l as ne,m as x,n as S,o as re,p as C,r as ie,s as w,t as T,u as ae}from"./checkbox-COOOlJPG.js";import{t as E}from"./badge-ChHXC28D.js";import{c as D,d as O,f as k,i as A,l as j,o as M,s as oe}from"./workflows-Bku4o2su.js";import{O as se,S as N,T as P,a as ce,b as F,c as le,f as ue,i as de,l as fe,o as pe,s as me,v as he,w as ge}from"./workflows-start-kl7rSSay.js";import{a as _e,c as ve,f as I,i as ye,l as be,n as xe,o as Se,p as Ce,r as L,s as we,t as Te,u as Ee}from"./lib-xyflow-react-DGg_5r7u.js";import{t as De}from"./use-elk-u1Ql5AOs.js";var Oe={name:`pin`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]};Oe.node;var ke=o(Oe),R=e(t(),1),Ae={"app:http":()=>S(`stepHttp`),"app:records.create":()=>S(`stepRecordsCreate`),"app:records.update":()=>S(`stepRecordsUpdate`),"app:records.get":()=>S(`stepRecordsGet`),"app:records.list":()=>S(`stepRecordsList`),"app:mail.send":()=>S(`stepMailSend`),"app:mail.template":()=>S(`stepMailTemplate`),"app:piece":()=>S(`stepPiece`)},je=(e,t)=>Ae[e]?.()??t??e,Me=(e,t)=>{let n=je(e,t),r=de(e);return r?S(`stepTypeVersion`,{type:n,version:r.version}):n},Ne={Pass:()=>S(`typePass`),Choice:()=>S(`typeChoice`),Wait:()=>S(`typeWait`),Map:()=>S(`typeMap`),Block:()=>S(`typeBlock`),Succeed:()=>S(`typeSucceed`),Fail:()=>S(`typeFail`)},Pe=e=>Ne[e]?.()??e,Fe=(e,t)=>{if(e.Type!==`Task`)return Pe(e.Type);let{type:n,waits:r}=N(String(e.Resource)),i=je(n,t?.step_types.find(e=>e.id===n)?.label);return r?S(`stepTypeWaits`,{type:i}):i},Ie={url:()=>S(`inputUrl`),method:()=>S(`inputMethod`),headers:()=>S(`inputHeaders`),query:()=>S(`inputQuery`),body:()=>S(`inputBody`),response:()=>S(`inputResponse`),resource:()=>S(`inputResource`),data:()=>S(`inputData`),key:()=>S(`inputKey`),filter:()=>S(`inputFilter`),order_by:()=>S(`inputOrderBy`),limit:()=>S(`inputLimit`),to:()=>S(`inputTo`),subject:()=>S(`inputSubject`),text:()=>S(`inputText`),html:()=>S(`inputHtml`),attachments:()=>S(`inputAttachments`),piece:()=>S(`inputPiece`),action:()=>S(`inputAction`),connection:()=>S(`inputConnection`),props:()=>S(`inputProps`),when:()=>S(`inputWhen`),body_schema:()=>S(`inputBodySchema`)},Le=(e,t)=>Ie[e]?.()??t??e,Re={manual:()=>S(`triggerManual`),"app:record":()=>S(`triggerRecord`)},ze=(e,t)=>Re[e]?.()??t??e,Be=e=>Object.keys(e??{})[0],Ve=(e,t)=>{let n=Be(e);return n===void 0?S(`triggerUnknown`):ze(n,t?.triggers.find(e=>e.id===n)?.label)},He={succeeded:()=>S(`traceSucceeded`),caught:()=>S(`traceCaught`),retrying:()=>S(`traceRetrying`),failed:()=>S(`traceFailed`),current:()=>S(`traceCurrent`)},Ue=e=>He[e](),We=(e,t)=>t?.step_types.find(t=>t.id===N(e.Resource).type)?.cache,Ge=(e,t)=>e.Type===`Task`&&e.Cache===!0&&We(e,t)?.choice===`discouraged`,Ke=(e,t)=>{let n=We(e,t);if(n?.choice!==`hidden`)return n?.choice===`switch`?{on:e.Cache??n.default===!0,forces:!1,offValue:!1,disclaimer:void 0}:{on:e.Cache===!0,forces:!0,offValue:void 0,disclaimer:n?.choice===`discouraged`?n.disclaimer:void 0}},z=e=>encodeURIComponent(e),qe=e=>e.map(e=>`/${z(e)}`).join(``),Je=e=>e===``?[]:e.split(`/`).slice(1).map(decodeURIComponent),Ye=(e,t)=>`break:${z(e)}|${qe(t)}`,Xe=(e,t)=>`make:${z(e)}|${z(t)}`,Ze=(e,t)=>`when:${z(e)}|${t.join(`/`)}`,Qe=(e,t)=>`select:${z(e)}|${z(t)}`,B=e=>`in:${z(e)}`,V=e=>`out:${qe(e)}`,$e=`break-in`,et=`make-out`,tt=`condition-out`,nt=`select-out`,rt=`value`,it=e=>e?.startsWith(`in:`)?decodeURIComponent(e.slice(3)):void 0,at=e=>e?.startsWith(`out:`)?Je(e.slice(4)):void 0,H=e(n(),1),ot=(e,t)=>{let n=e.pure.find(e=>e.id===t.target),r=it(t.targetHandle);return n?.kind===`condition`&&r!==void 0?{step:n.target,at:[...n.at,Number(r)]}:void 0},st=e=>e.kind===`condition`?{step:e.target,at:e.at}:void 0,ct=(e,t)=>{for(let n=0;n<Math.min(e.length,t.length);n++)if(e[n]!==t[n])return e[n]-t[n];return e.length-t.length},lt=(e,t,n)=>{let r=new Map,i=[];for(let e of t){let t=n(e);if(!t){i.push(e);continue}let a=`step:${t.step}`;r.has(a)||(r.set(a,[]),i.push(a)),r.get(a).push({removal:e,at:t.at})}return i.flatMap(e=>typeof e==`string`&&r.has(e)?r.get(e).toSorted((e,t)=>ct(t.at,e.at)).map(({removal:e})=>e):[e])},ut=e=>e.Type===`Choice`&&Array.isArray(e.Choices)?e.Choices:[],dt=e=>`Catch`in e&&Array.isArray(e.Catch)?e.Catch:[],ft=(e,t,n,r)=>{let i=p(t,n),a=(n,r,a,o)=>Object.hasOwn(e.States,a)?[{id:`${i}\n${r}`,kind:n,source:i,target:p(t,a),field:r,...o!==void 0&&{label:o}}]:[];return[...`Next`in r&&typeof r.Next==`string`?a(`next`,`Next`,r.Next):[],...ut(r).flatMap((e,t)=>a(`rule`,`Choices[${t}].Next`,e.Next,e.Condition)),...r.Type===`Choice`&&typeof r.Default==`string`?a(`default`,`Default`,r.Default):[],...dt(r).flatMap((e,t)=>e.Next===void 0?[]:a(`catch`,`Catch[${t}].Next`,e.Next,Array.isArray(e.ErrorEquals)?e.ErrorEquals.join(`, `):void 0))]},pt=(e,t)=>{let n=t.length>0?t.join(`/`):void 0,r=Object.entries(e.States).map(([r,i])=>{let a={kind:`state`,id:p(t,r),name:r,state:i,scope:t,...n!==void 0&&{parent:n},first:e.StartAt===r},o=P(i),s=o?.States?pt(o,[...t,r]):{nodes:[],edges:[]};return{nodes:[a,...s.nodes],edges:[...ft(e,t,r,i),...s.edges]}});return{nodes:r.flatMap(e=>e.nodes),edges:r.flatMap(e=>e.edges)}},mt=(e,t,n)=>[...k(e)].flatMap(([r,i])=>{let a=p(t,r),o=[...O(i)].map(e=>{let n=i.data.has(e)?`reads`:`status`;return{id:`${p(t,e)}\n${n}\n${a}`,kind:n,source:p(t,e),target:a,field:n}}),s=P(e.States[r]),c=s?.States?mt(s,[...t,r],!1):[];return[...n&&o.length===0?[{id:`\nStart\n${a}`,kind:`start`,source:``,target:a,field:`StartAt`}]:[],...o,...c]}),ht=e=>{let t=e.stateMachine,n=pt(t,[]);if(ce(e)===`data`)return{nodes:[{kind:`trigger`,id:``,trigger:e.trigger},...n.nodes.map(e=>e.kind===`state`?{...e,first:!1}:e)],edges:mt(t,[],!0)};let r=t.StartAt!==void 0&&Object.hasOwn(t.States,t.StartAt)?[{id:`
|
|
2
2
|
StartAt`,kind:`start`,source:``,target:t.StartAt,field:`StartAt`}]:[];return{nodes:[{kind:`trigger`,id:``,trigger:e.trigger},...n.nodes],edges:[...r,...n.edges]}},U={width:224,height:64},gt=(e,t)=>`${e}\u0000${t}`,_t={"elk.algorithm":`layered`,"elk.direction":`RIGHT`,"elk.hierarchyHandling":`INCLUDE_CHILDREN`,"elk.layered.spacing.nodeNodeBetweenLayers":`72`,"elk.spacing.nodeNode":`32`,"elk.edgeLabels.inline":`false`},vt={"elk.layered.layering.strategy":`LONGEST_PATH`},yt={"elk.padding":`[top=48,left=24,bottom=24,right=24]`},bt=e=>e.kind===`state`&&h(e.state),xt=(e,t={})=>{let n=e=>{let n=t.sizes?.get(e)??U,r=t.ports?.get(e);return r?.length?{id:e,...n,layoutOptions:{"elk.portConstraints":`FIXED_POS`},ports:r.map(t=>({id:gt(e,t.handle),x:t.side===`in`?0:n.width,y:t.y,width:0,height:0,layoutOptions:{"elk.port.side":t.side===`in`?`WEST`:`EAST`}}))}:{id:e,...n}},r=(e,n)=>n!==void 0&&t.ports?.get(e)?.some(e=>e.handle===n)?gt(e,n):e,i=e=>(t.pure??[]).filter(t=>t.parent===e).map(e=>n(e.id)),a=t=>{if(!bt(t))return n(t.id);let r=e.nodes.filter(e=>e.kind===`state`&&e.parent===t.id);return{id:t.id,layoutOptions:yt,children:[...r.map(a),...i(t.id)],edges:s(t.id)}},o=n=>{let r=t.pure?.find(e=>e.id===n);if(r)return r.parent;let i=e.nodes.find(e=>e.id===n);return i?.kind===`state`?i.parent:void 0},s=n=>[...e.edges.filter(e=>o(e.target)===n).map(e=>({id:e.id,sources:[e.source],targets:[e.target]})),...(t.wires??[]).filter(e=>o(e.target)===n&&o(e.source)===n).map(e=>({id:e.id,sources:[r(e.source,e.sourceHandle)],targets:[r(e.target,e.targetHandle)]}))],c=e.nodes.filter(e=>e.kind===`trigger`||e.parent===void 0);return{id:`root`,layoutOptions:t.dataOrder?{..._t,...vt}:_t,children:[...c.map(a),...i(void 0)],edges:s(void 0)}},St=e=>{let t=new Map,n=e=>{for(let r of e.children??[])t.set(r.id,{x:r.x??0,y:r.y??0,width:r.width??U.width,height:r.height??U.height}),n(r)};return n(e),t},Ct=async(e,t)=>St(await e.layout(t)),wt=24,Tt=8,Et=(e,t)=>{let n=t?[...e]:e.filter(e=>e.required||e.state!==`empty`);return{shown:n,folded:e.length-n.length}},Dt=(e,t,n,r=52)=>r+Math.max(e,typeof t==`number`?t:t.length)*26+(n?wt:0)+Tt,Ot={string:()=>S(`typeString`),integer:()=>S(`typeInteger`),number:()=>S(`typeNumber`),boolean:()=>S(`typeBoolean`),object:()=>S(`typeObject`),array:()=>S(`typeArray`),null:()=>S(`typeNull`),any:()=>S(`typeAny`)},W=e=>e.title===void 0?e.kinds===`any`?Ot.any():e.kinds.map(e=>Ot[e]()).reduce((e,t)=>S(`typeOr`,{first:e,second:t})):e.title,G=e=>e.kinds===`any`?`any`:e.kinds[0],kt={status:()=>S(`outputStatus`),headers:()=>S(`outputHeaders`),body:()=>S(`outputBody`),record:()=>S(`outputRecord`),resource:()=>S(`outputResource`),key:()=>S(`outputKey`),records:()=>S(`outputRecords`),message_id:()=>S(`outputMessageId`)},At=(e,t=!1,n=!1)=>{if(e.length===0)return S(t?`pinRunInput`:`pinResult`);if(e.length===1&&e[0]===`#status`)return S(`stepStatusType`);let r=e.at(-1);return n||!Object.hasOwn(kt,r)?r:kt[r]()},jt=e=>e===`#condition`?S(`onlyWhen`):Le(e),Mt={"=":()=>S(`conditionEquals`),"!=":()=>S(`conditionNotEquals`),">":()=>S(`conditionGreater`),"<":()=>S(`conditionLess`),matches:()=>S(`conditionMatches`),and:()=>S(`conditionAnd`),or:()=>S(`conditionOr`),not:()=>S(`conditionNot`),expression:()=>S(`conditionExpression`)},Nt=e=>Mt[e](),Pt=({part:e})=>Nt(e.kind===`compare`||e.kind===`logic`?e.op:e.kind),Ft={SUCCEEDED:()=>S(`statusSucceeded`),FAILED:()=>S(`statusFailed`),TIMED_OUT:()=>S(`statusTimedOut`),ABORTED:()=>S(`statusAborted`),SKIPPED:()=>S(`statusSkipped`)},It=e=>Object.hasOwn(Ft,e)?Ft[e]():e,Lt=34,Rt=280,zt=8,Bt=(e,t)=>e.kind===`condition`?{shown:e.inputs,folded:0}:e.kind===`make`?Et(e.inputs,t||e.inputs.length<=zt):{shown:[],folded:0},Vt=(e,t,n)=>{let r=new Set(t.filter(t=>t.source===e.id).map(e=>e.sourceHandle)),i=e.outputs.filter(e=>r.has(V(e.path))),a=i.length>0&&i.length<e.outputs.length;return n||!a?{shown:e.outputs,folded:0,foldable:a}:{shown:i,folded:e.outputs.length-i.length,foldable:a}},Ht=e=>106+e*26+8,Ut=(e,t,n)=>{let r=new Map;for(let i of e.nodes){if(i.kind===`state`&&h(i.state))continue;let{shown:e,folded:a}=Et(t.inputs.get(i.id)??[],n.has(i.id));r.set(i.id,{width:296,height:Dt(e.length,t.outputs.get(i.id)??[],a>0||n.has(i.id))})}for(let e of t.pure){if(e.kind===`condition`&&e.part.kind===`expression`){r.set(e.id,{width:216,height:Ht(e.inputs.length)});continue}if(e.kind===`select`){r.set(e.id,{width:Rt,height:Dt(e.part.cases.length+3,1,!1,Lt)});continue}if(e.kind===`break`){let i=Vt(e,t.edges,n.has(e.id));r.set(e.id,{width:216,height:Dt(0,i.shown.length,i.foldable,Lt)});continue}let{shown:i,folded:a}=Bt(e,n.has(e.id));r.set(e.id,{width:216,height:Dt(i.length,1,e.kind===`make`&&(a>0||n.has(e.id)),Lt)})}return r},Wt=(e,t)=>e+t*26+13,Gt=13,Kt=38,qt=(e,t,n)=>{let r=new Map;for(let i of e.nodes){if(i.kind===`state`&&h(i.state))continue;let{shown:e}=Et(t.inputs.get(i.id)??[],n.has(i.id));r.set(i.id,[...e.map((e,t)=>({handle:B(e.key),side:`in`,y:Wt(52,t)})),...(t.outputs.get(i.id)??[]).map((e,t)=>({handle:V(e.path),side:`out`,y:Wt(52,t)}))])}for(let e of t.pure){let i=(e,t=Kt)=>e.map((e,n)=>({handle:B(e.key),side:`in`,y:Wt(t,n)}));if(e.kind===`break`){let{shown:i}=Vt(e,t.edges,n.has(e.id));r.set(e.id,[{handle:$e,side:`in`,y:Gt},...i.map((e,t)=>({handle:V(e.path),side:`out`,y:Wt(Kt,t)}))])}else if(e.kind===`make`)r.set(e.id,[{handle:et,side:`out`,y:Gt},...i(Bt(e,n.has(e.id)).shown)]);else if(e.kind===`select`)r.set(e.id,[{handle:nt,side:`out`,y:Gt},...i(e.inputs)]);else{let t=e.part.kind===`expression`?Kt+64+4:Kt;r.set(e.id,[{handle:tt,side:`out`,y:Gt},...i(e.inputs,t)])}}return r},Jt=(e,t)=>{let n=e.nodes.find(e=>e.id===(t.kind===`break`?t.source:t.target));return n?.kind===`state`?n.parent:void 0},Yt=`trigger`,K=e=>e===``?Yt:`state:${e}`,q=e=>e!==Yt&&!e.startsWith(`state:`),J=e=>e===Yt?``:e.startsWith(`state:`)?e.slice(6):e,Xt=(e,t,n)=>{let{shown:r,folded:i}=Et(e.inputs.get(t)??[],n);return{inputs:r,outputs:e.outputs.get(t)??[],folded:i,open:n}},Zt=(e,t,n,r,i,a,o,s,c=!1)=>e.nodes.map(e=>{let l=t?.get(e.id)??{x:0,y:0,...U},u=e.kind===`state`?e.parent:void 0,d=e.kind===`trigger`?Ve(e.trigger,a):Fe(e.state,a),f=e.kind===`state`&&Ge(e.state,a),p=e.kind===`state`?S(`stateNode`,{name:e.name,type:d}):S(`triggerNode`,{trigger:d}),m=o?.get(e.id)??[],h=[...f?[S(`cacheForcedAgainst`)]:[],...m.map(e=>e.message)];return{id:K(e.id),type:e.kind,ariaLabel:[p,...h].join(`, `),position:{x:l.x,y:l.y},width:l.width,height:l.height,measured:{width:l.width,height:l.height},data:{node:e,kind:d,problems:n.get(e.id)??[],...i?.has(e.id)&&{trace:i.get(e.id)},...f&&{cacheWarning:f},...m.length>0&&{warnings:m},...s&&{pins:Xt(s.data,e.id,s.open.has(e.id))},...c&&{dataOrder:c}},draggable:!1,deletable:e.kind===`state`,selected:e.id===r,...u!==void 0&&{parentId:K(u),extent:`parent`}}}),Qt=40,$t=e=>e.length>Qt?`${e.slice(0,39)}…`:e,en=e=>{if(e.kind==="default")return S(`otherwise`);if(e.kind===`catch`)return S(`onError`,{errors:e.label??``});if(e.kind===`rule`)return e.label?$t(e.label):S(`conditionToWrite`)},tn=e=>({id:e.id,source:K(e.source),sourceHandle:`out`,target:K(e.target),targetHandle:`in`,deletable:!1,data:{kind:e.kind,field:e.field,source:e.source},...e.kind===`status`&&{className:`pb-workflow-status`}}),nn=(e,t=!1)=>e.edges.map(e=>{if(t)return tn(e);let n=en(e);return{id:e.id,source:K(e.source),sourceHandle:e.kind,target:K(e.target),targetHandle:`in`,deletable:e.kind!==`start`,data:{kind:e.kind,field:e.field,source:e.source},...n!==void 0&&{label:n},...e.kind===`catch`&&{className:`pb-workflow-catch`}}}),rn=(e,t,n,r)=>t.pure.map(i=>{let a=n?.get(i.id)??{x:0,y:0,...U},o=Jt(e,i),{shown:s,folded:c}=Bt(i,r.has(i.id)),l=i.kind===`break`?Vt(i,t.edges,r.has(i.id)):void 0,u=e.nodes.find(e=>e.id===(i.kind===`break`?i.source:i.target));return{id:i.id,type:`pure`,position:{x:a.x,y:a.y},width:a.width,height:a.height,measured:{width:a.width,height:a.height},data:{node:u,kind:i.kind,problems:[],pureData:{pure:i,shownInputs:s,shownOutputs:l?.shown??[],folded:l?.folded??c,open:r.has(i.id),foldable:l?l.foldable:c>0||r.has(i.id)}},draggable:!1,deletable:!0,...o!==void 0&&{parentId:K(o),extent:`parent`}}}),an=(e,t)=>{let n=e=>{let n=t.pure.find(t=>t.id===e);return n?n.kind===`break`?n.source:n.target:e},r=new Set(t.edges.map(e=>`${n(e.source)}\n${n(e.target)}`));return nn({...e,edges:e.edges.filter(e=>e.source!==``&&!r.has(`${e.source}\n${e.target}`))},!0)},on=e=>{let t=new Set(e.pure.map(e=>e.id)),n=e=>t.has(e)?e:K(e);return e.edges.map(e=>({id:e.id,source:n(e.source),sourceHandle:e.sourceHandle,target:n(e.target),targetHandle:e.targetHandle,deletable:!e.expression,data:{kind:`data`,wire:e},className:`pb-wire pb-wire-${G(e.type)}${e.expression?` pb-wire-expression`:``}`}))},sn=(0,R.createContext)(void 0),cn={succeeded:`green`,caught:`amber`,retrying:`amber`,failed:`red`,current:`blue`},ln=(0,R.createContext)(void 0),Y=()=>(0,R.useContext)(ln),un=e=>{if(e.options)return`choice`;if(e.type.kinds===`any`)return;let[t,...n]=e.type.kinds.filter(e=>e!==`null`);if(t===`string`&&n.every(e=>e===`integer`||e===`number`))return`string`;if(!(n.length>0))return t===`integer`||t===`number`?`number`:t===`boolean`?`boolean`:void 0},dn=e=>e.trim()===``?void 0:Number.isNaN(Number(e))?e:Number(e),fn=({name:e,className:t,value:n,onChange:r})=>{let[i,a]=(0,R.useState)();return(0,H.jsx)(f,{"aria-label":e,wrapperClassName:`${t} h-6 w-[55%] px-1.5`,className:`text-xs`,inputMode:`decimal`,value:i??(n===void 0?``:String(n)),onChange:e=>{a(e.target.value),r(dn(e.target.value))},onBlur:()=>a(void 0)})},pn=({pin:e,label:t,onChange:n})=>{if(e.state===`wired`||e.state===`made`||e.key===`#condition`&&e.state!==`expression`)return null;if(e.state===`expression`)return(0,H.jsx)(`span`,{className:`ml-auto shrink-0 rounded bg-muted px-1 font-mono text-xs text-muted-foreground`,title:S(`pinExpression`,{expression:String(e.value)}),children:`ƒ`});let r=un(e);if(e.state===`literal`&&typeof e.value==`object`)return(0,H.jsx)(`span`,{className:`ml-auto shrink-0 text-xs text-muted-foreground`,title:S(`pinObjectValue`),children:`{…}`});if(!r)return e.state===`literal`?(0,H.jsx)(`span`,{className:`ml-auto min-w-0 truncate text-xs text-muted-foreground`,children:String(e.value)}):null;let i=S(`inputValue`,{label:t});if(!n)return(0,H.jsx)(`span`,{className:`ml-auto min-w-0 truncate text-xs text-muted-foreground`,children:e.value===void 0?``:String(e.value)});let a=`nodrag nopan nowheel ml-auto min-w-0`;return r===`boolean`?(0,H.jsx)(T,{className:a,checked:e.value===!0,label:i,onChange:e=>n(e)}):r===`choice`?(0,H.jsxs)(l,{"aria-label":i,className:`${a} h-6 max-w-[55%] px-1 py-0 text-xs`,value:typeof e.value==`string`?e.value:``,onChange:e=>n(e.target.value===``?void 0:e.target.value),children:[(0,H.jsx)(`option`,{value:``}),e.options.map(t=>(0,H.jsx)(`option`,{value:t,children:e.statuses?It(t):t},t))]}):r===`number`?(0,H.jsx)(fn,{name:i,className:a,value:e.value,onChange:n}):(0,H.jsx)(f,{"aria-label":i,wrapperClassName:`${a} h-6 w-[55%] px-1.5`,className:`text-xs`,value:e.value===void 0?``:String(e.value),onChange:e=>n(e.target.value===``?void 0:e.target.value)})},mn=e=>`pb-pin pb-pin-${G(e.type)}`,hn=({pin:e,step:t,keys:n,connectable:r,name:i,onValue:a,bare:o=!1})=>{let s=Y(),c=i??jt(e.key);return(0,H.jsxs)(`div`,{className:`relative flex h-[26px] items-center gap-1.5 pr-2 pl-3`,children:[(0,H.jsx)(L,{id:B(e.key),type:`target`,position:I.Left,isConnectable:r,className:mn(e)}),(0,H.jsxs)(`span`,{className:`min-w-0 shrink truncate text-xs text-body`,title:S(`pinTypeTitle`,{label:c,type:W(e.type)}),children:[c,e.required&&(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`text-danger-text`,children:`*`})]}),!o&&(0,H.jsx)(pn,{pin:e,label:c,...s&&r&&{onChange:a??(e=>s.setArgument(t,n,e))}})]})},gn=({pin:e,connectable:t,trigger:n=!1,field:r=!1})=>{let i=At(e.path,n,r);return(0,H.jsxs)(`div`,{className:`relative flex h-[26px] items-center justify-end pr-3 pl-2`,children:[(0,H.jsx)(`span`,{className:`min-w-0 truncate text-xs text-body`,title:S(`pinTypeTitle`,{label:i,type:W(e.type)}),children:i}),(0,H.jsx)(L,{id:V(e.path),type:`source`,position:I.Right,isConnectable:t,className:mn(e)})]})},_n=({inputs:e,outputs:t,connectable:n})=>{let r=(e,t)=>({top:`${(e+1)*100/(t+1)}%`});return(0,H.jsxs)(H.Fragment,{children:[e.map((t,i)=>(0,H.jsx)(L,{id:B(t.key),type:`target`,position:I.Left,isConnectable:n,className:mn(t),style:r(i,e.length),title:S(`pinTypeTitle`,{label:jt(t.key),type:W(t.type)})},t.key)),t.map((e,i)=>(0,H.jsx)(L,{id:V(e.path),type:`source`,position:I.Right,isConnectable:n,className:mn(e),style:r(i,t.length),title:S(`pinTypeTitle`,{label:At(e.path),type:W(e.type)})},e.path.join(`/`)))]})},vn=({node:e,folded:t,open:n,fields:r=!1})=>{let i=Y();return t===0&&!n?null:(0,H.jsx)(`button`,{type:`button`,className:`nodrag h-6 w-full px-3 text-left text-xs text-muted-foreground hover:text-foreground`,onClick:()=>i?.toggleOpen(e),disabled:!i,children:r?n?S(`foldLessFields`):S(`foldMoreFields`,{count:t}):n?S(`foldLess`):S(`foldMore`,{count:t})})},yn=({node:e,inputs:t,outputs:n,folded:r,open:i,editable:a,trigger:o=!1})=>(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`grid grid-cols-[3fr_2fr]`,children:[(0,H.jsx)(`div`,{className:`min-w-0`,children:t.map(t=>(0,H.jsx)(hn,{pin:t,step:e,keys:[t.key],connectable:a},t.key))}),(0,H.jsx)(`div`,{className:`min-w-0`,children:n.map(e=>(0,H.jsx)(gn,{pin:e,connectable:a,trigger:o},JSON.stringify(e.path)))})]}),(0,H.jsx)(vn,{node:e,folded:r,open:i})]}),bn=(0,R.createContext)(void 0),xn=`nodrag absolute -top-4 -right-4 z-10`,Sn=({node:e,name:t})=>{let n=(0,R.useContext)(bn);return n?(0,H.jsx)(i,{size:`icon`,className:xn,"aria-label":S(`unpin`,{name:t}),title:S(`unpinHelp`),onClick:t=>{t.stopPropagation(),n(e)},children:(0,H.jsx)(ke,{className:`size-3.5`,"aria-hidden":!0})}):(0,H.jsxs)(`span`,{className:s(xn,`inline-flex size-7 items-center justify-center rounded-md border border-border-strong bg-background text-muted-foreground shadow-sm`),title:S(`movedByHand`),children:[(0,H.jsx)(ke,{className:`size-3.5`,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`sr-only`,children:S(`movedByHand`)})]})},X=[18,38],Cn=e=>{if(e.Type===`Choice`)return[{kind:`rule`,top:X[0],label:S(`when`)},{kind:`default`,top:X[1],label:S(`otherwise`)}];let t=[`Task`,`Pass`,`Wait`,`Map`,`Block`].includes(e.Type)?[{kind:`next`,top:X[0]}]:[],n=e.Type===`Task`||e.Type===`Map`||e.Type===`Block`?[{kind:`catch`,top:X[t.length],label:S(`onErrorHandle`)}]:[];return[...t,...n]},wn=(e,t,n)=>{let r=(0,R.useContext)(sn);if(!r||!t)return{};let i=t=>{t.stopPropagation(),r(e)},a=n?S(`addStepAtNamedHandle`,{handle:n}):S(`addStepAtHandle`);return{role:`button`,tabIndex:0,"aria-label":a,title:a,onClick:i,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i(e))}}},Tn=({source:e,path:t,editable:n})=>(0,H.jsx)(L,{id:e.kind,type:`source`,position:I.Right,isConnectable:n,style:{top:e.top},className:s(`pb-workflow-exec`,`pb-workflow-handle-${e.kind}`),...wn({kind:e.kind,source:t},n,e.label),children:e.label&&(0,H.jsx)(`span`,{className:`pb-workflow-handle-label`,children:e.label})}),En=({state:e,path:t,editable:n})=>Cn(e).map(e=>(0,H.jsx)(Tn,{source:e,path:t,editable:n},e.kind)),Dn=({count:e})=>e>0&&(0,H.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-1 text-xs font-medium text-danger-text`,title:S(`problemCount`,{count:e}),children:[(0,H.jsx)(d,{className:`size-3.5`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`sr-only`,children:S(`problemCount`,{count:e})}),(0,H.jsx)(`span`,{"aria-hidden":`true`,children:e})]}),On=({label:e})=>(0,H.jsxs)(`span`,{className:`inline-flex shrink-0 items-center text-warning-text`,title:e,children:[(0,H.jsx)(d,{className:`size-3.5`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`sr-only`,children:e})]}),kn=({trace:e})=>(0,H.jsxs)(`span`,{className:`flex shrink-0 flex-col items-end gap-0.5`,children:[e.changed?(0,H.jsx)(`span`,{title:S(`changedSinceRun`),className:`rounded-full border border-dashed px-1.5 text-xs text-muted-foreground`,children:S(`changedShort`)}):(0,H.jsx)(E,{tone:cn[e.status],children:Ue(e.status)}),e.steps>1&&(0,H.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:S(`traceSteps`,{count:e.steps})})]}),An=(e,t,n)=>s(`rounded-lg border bg-background text-body shadow-sm`,t>0||n?.status===`failed`?`border-danger`:`border-border-strong`,e&&`ring-2 ring-primary/40`),jn=({name:e,kind:t,problems:n,first:r,trace:i,warnings:a=[]})=>(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 truncate text-xs text-muted-foreground`,children:[t,r&&(0,H.jsxs)(`span`,{className:`text-primary-text`,children:[` · `,S(`startsHere`)]})]}),a.length>0&&(0,H.jsx)(On,{label:a.join(`
|
|
3
3
|
`)}),(0,H.jsx)(Dn,{count:n}),i&&(0,H.jsx)(kn,{trace:i})]}),(0,H.jsx)(`div`,{className:`truncate font-medium text-foreground`,children:e})]}),Mn=()=>(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(L,{id:`in`,type:`target`,position:I.Left,isConnectable:!1,className:`pb-workflow-side`,style:{top:X[0]}}),(0,H.jsx)(L,{id:`out`,type:`source`,position:I.Right,isConnectable:!1,className:`pb-workflow-side`,style:{top:X[0]}})]}),Nn=({condition:e})=>e!==void 0&&(0,H.jsx)(`span`,{className:`absolute top-1 right-6 max-w-[45%] truncate rounded bg-muted px-1 text-[0.625rem] text-muted-foreground`,title:e,children:S(`onlyWhenBadge`)}),Pn=({id:e,data:t,selected:n,isConnectable:r})=>{let{node:i,kind:a,problems:o,trace:c,cacheWarning:l,warnings:u=[],pins:d,dataOrder:f,moved:p}=t;return i.kind===`state`?(0,H.jsxs)(`div`,{className:s(An(n,o.length,c),`h-full`,h(i.state)&&`bg-muted/40`),children:[p&&(0,H.jsx)(Sn,{node:e,name:i.name}),(0,H.jsxs)(`div`,{className:`relative h-[52px] py-2 pr-6 pl-4`,children:[f?(0,H.jsx)(Mn,{}):(0,H.jsx)(L,{id:`in`,type:`target`,position:I.Left,isConnectable:r,className:`pb-workflow-exec`,style:{top:X[0]}}),f&&(0,H.jsx)(Nn,{condition:i.state.Condition}),(0,H.jsx)(jn,{name:i.name,kind:a,problems:o.length,first:i.first&&i.parent!==void 0,trace:c,warnings:[...l?[S(`cacheForcedAgainst`)]:[],...u.map(e=>e.message)]}),!f&&(0,H.jsx)(En,{state:i.state,path:i.id,editable:r}),d&&h(i.state)&&(0,H.jsx)(_n,{inputs:d.inputs,outputs:d.outputs,connectable:r})]}),d&&!h(i.state)&&(0,H.jsx)(yn,{node:i.id,inputs:d.inputs,outputs:d.outputs,folded:d.folded,open:d.open,editable:r})]}):null},Fn=({id:e,data:t,selected:n,isConnectable:r})=>{let{node:i,kind:a,problems:o,pins:c,dataOrder:l,moved:u}=t,d=wn({kind:`start`,source:i.id},r&&!l);return i.kind===`trigger`?(0,H.jsxs)(`div`,{className:s(An(n,o.length),`h-full border-dashed`),children:[u&&(0,H.jsx)(Sn,{node:e,name:S(`trigger`)}),(0,H.jsxs)(`div`,{className:`relative h-[52px] py-2 pr-6 pl-4`,children:[(0,H.jsx)(jn,{name:a,kind:S(`trigger`),problems:o.length}),l?(0,H.jsx)(L,{id:`out`,type:`source`,position:I.Right,isConnectable:!1,className:`pb-workflow-side`,style:{top:X[0]}}):(0,H.jsx)(L,{id:`start`,type:`source`,position:I.Right,isConnectable:r,className:`pb-workflow-exec`,style:{top:X[0]},...d})]}),c&&(0,H.jsx)(yn,{node:i.id,inputs:[],outputs:c.outputs,folded:0,open:!1,editable:r,trigger:!0})]}):null},In=`protobase:workflow-graph-view`,Ln=e=>r(()=>e().getItem(`protobase:workflow-graph-view`),null)===`simple`?`simple`:`pins`,Rn=(e,t)=>r(()=>t===`pins`?e().removeItem(In):e().setItem(In,t),void 0),zn=()=>localStorage,Bn=()=>{let[e,t]=(0,R.useState)(()=>Ln(zn));return[e,e=>{t(e),Rn(zn,e)}]},Vn=(e,t)=>e.part.kind===`not`?S(`conditionNotSide`):e.part.kind===`matches`?S(t===`0`?`conditionMatchesText`:`conditionMatchesPattern`):e.part.kind===`logic`?String.fromCharCode(65+Number(t)%26):S(t===`0`?`conditionSideA`:`conditionSideB`),Hn=({node:e,source:t})=>{let n=Y(),[r,i]=(0,R.useState)(),a=t.trim();return(0,H.jsx)(`textarea`,{"aria-label":S(`conditionExpressionText`),className:`nodrag nopan nowheel block w-full resize-none rounded border border-border bg-background px-1.5 py-1 font-mono text-xs text-foreground`,style:{height:64},spellCheck:!1,readOnly:!n,value:r??a,onChange:e=>i(e.target.value),onBlur:()=>{i(void 0);let t=r?.trim();t!==void 0&&t!==a&&n?.setCondition(e.target,t===``?void 0:`{% ${t} %}`)}})},Un=e=>e.replace(/^\$states\.context\.Steps\./,``).replace(/^\$states\.context\.Execution\.Input/,`input`),Wn=({node:e,editable:t})=>{let n=Y(),[r,i]=(0,R.useState)(),a=S(`conditionMatchesPattern`),o=String(e.inputs[1]?.value??``);return(0,H.jsxs)(`div`,{className:`relative flex h-[26px] items-center gap-1.5 pr-2 pl-3`,children:[(0,H.jsx)(`span`,{className:`min-w-0 shrink truncate text-xs text-body`,children:a}),(0,H.jsx)(f,{"aria-label":S(`inputValue`,{label:a}),wrapperClassName:`nodrag nopan nowheel ml-auto h-6 w-[60%] min-w-0 px-1.5`,className:`font-mono text-xs`,value:r??o,disabled:!n||!t,onChange:t=>{i(t.target.value),t.target.value!==``&&n?.setConditionSide(e.target,[...e.at,1],t.target.value)},onBlur:()=>i(void 0)})]})},Gn=({node:e,editable:t})=>{let n=Y(),r=(0,H.jsx)(L,{id:tt,type:`source`,position:I.Right,isConnectable:!1,className:`pb-pin pb-pin-boolean`,style:{top:13}});return e.part.kind===`expression`?(0,H.jsxs)(`div`,{className:`relative grid gap-1 px-2 pt-1`,children:[r,(0,H.jsx)(Hn,{node:e,source:e.part.source}),(0,H.jsx)(`div`,{className:`-mx-2`,children:e.inputs.map(e=>(0,H.jsxs)(`div`,{className:`relative flex h-[26px] items-center pr-2 pl-3`,children:[(0,H.jsx)(L,{id:B(e.key),type:`target`,position:I.Left,isConnectable:!1,className:`pb-pin pb-pin-${G(e.type)}`}),(0,H.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-body`,title:S(`pinTypeTitle`,{label:e.key,type:W(e.type)}),children:Un(e.key)})]},e.key))})]}):(0,H.jsxs)(`div`,{className:`relative pt-1`,children:[r,e.inputs.map(r=>e.part.kind===`matches`&&r.key===`1`?(0,H.jsx)(Wn,{node:e,editable:t},r.key):(0,H.jsx)(hn,{pin:r,step:e.target,keys:[],name:Vn(e,r.key),bare:e.part.kind===`logic`&&Number(r.key)===e.part.sides.length,connectable:t,onValue:t=>n?.setConditionSide(e.target,[...e.at,Number(r.key)],t??``)},r.key))]})},Kn=(e,t)=>typeof t==`number`&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):typeof t==`boolean`&&(e===`true`||e===`false`)?e===`true`:e,qn=`nodrag nopan nowheel h-6 min-w-0 px-1.5`,Jn=({label:e,value:t,onChange:n,disabled:r})=>(0,H.jsx)(f,{"aria-label":e,wrapperClassName:`${qn} flex-1`,className:`text-xs`,value:String(t),disabled:r,onChange:e=>n(Kn(e.target.value,t))}),Yn=({node:e,editable:t})=>{let n=Y(),r=!n||!t,i=t=>n?.setArgument(e.target,[e.key],D(t)),{part:a}=e,o=(e,t)=>i({...a,cases:a.cases.map((n,r)=>r===e?{...n,...t}:n)});return(0,H.jsxs)(`div`,{className:`relative pt-1`,children:[(0,H.jsx)(L,{id:nt,type:`source`,position:I.Right,isConnectable:!1,className:`pb-pin pb-pin-${G(e.type)}`,style:{top:13}}),e.inputs.map(n=>(0,H.jsx)(hn,{pin:n,step:e.target,keys:[],name:S(`selectInput`),connectable:t,onValue:e=>i({...a,operand:{value:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:``}})},n.key)),a.cases.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex h-[26px] items-center gap-1 pr-2 pl-3`,children:[(0,H.jsx)(Jn,{label:S(`selectWhen`,{case:t+1}),value:e.when,disabled:r,onChange:e=>o(t,{when:e})}),(0,H.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs text-muted-foreground`,children:`→`}),(0,H.jsx)(Jn,{label:S(`selectThen`,{case:t+1}),value:e.then,disabled:r,onChange:e=>o(t,{then:e})}),(0,H.jsx)(`button`,{type:`button`,className:`nodrag shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-40`,"aria-label":S(`selectRemoveCase`,{case:t+1}),disabled:r||a.cases.length===1,onClick:()=>i({...a,cases:a.cases.filter((e,n)=>n!==t)}),children:(0,H.jsx)(b,{className:`size-3`,"aria-hidden":!0})})]},t)),(0,H.jsxs)(`div`,{className:`flex h-[26px] items-center gap-1 pr-2 pl-3`,children:[(0,H.jsx)(`span`,{className:`shrink-0 text-xs text-body`,children:S(`selectOtherwise`)}),(0,H.jsx)(Jn,{label:S(`selectOtherwise`),value:a.otherwise,disabled:r,onChange:e=>i({...a,otherwise:e})})]}),(0,H.jsx)(`button`,{type:`button`,className:`nodrag h-6 w-full px-3 text-left text-xs text-muted-foreground hover:text-foreground`,disabled:r,onClick:()=>i({...a,cases:[...a.cases,{when:``,then:``}]}),children:S(`selectAddCase`)})]})},Xn=e=>e.kind===`condition`?Pt(e):e.kind===`select`?S(`selectTitle`):e.kind===`break`?S(`breakTitle`,{type:W(e.type)}):S(`makeTitle`,{type:W(e.type)}),Zn=({pure:e})=>(0,H.jsx)(`div`,{className:`truncate border-b px-3 py-1.5 text-xs font-medium text-foreground`,children:Xn(e)}),Qn=({id:e,data:t,selected:n,isConnectable:r})=>{let{pureData:i,moved:a}=t;if(!i)return null;let{pure:o,shownInputs:c,shownOutputs:l,folded:u,open:d,foldable:f}=i;return(0,H.jsxs)(`div`,{className:s(`h-full rounded-lg border border-dashed border-border-strong bg-background text-body shadow-sm`,n&&`ring-2 ring-primary/40`),children:[a&&(0,H.jsx)(Sn,{node:e,name:Xn(o)}),(0,H.jsx)(Zn,{pure:o}),o.kind===`condition`?(0,H.jsx)(Gn,{node:o,editable:r}):o.kind===`select`?(0,H.jsx)(Yn,{node:o,editable:r}):o.kind===`break`?(0,H.jsxs)(`div`,{className:`relative pt-1`,children:[(0,H.jsx)(L,{id:$e,type:`target`,position:I.Left,isConnectable:!1,className:`pb-pin pb-pin-${G(o.type)}`,style:{top:13}}),l.map(e=>(0,H.jsx)(gn,{pin:e,connectable:r,field:!0},JSON.stringify(e.path))),f&&(0,H.jsx)(vn,{node:o.id,folded:u,open:d,fields:!0})]}):(0,H.jsxs)(`div`,{className:`relative pt-1`,children:[(0,H.jsx)(L,{id:et,type:`source`,position:I.Right,isConnectable:!1,className:`pb-pin pb-pin-${G(o.type)}`,style:{top:13}}),c.map(e=>(0,H.jsx)(hn,{pin:e,step:o.target,keys:[o.key,e.key],connectable:r},e.key)),(0,H.jsx)(vn,{node:o.id,folded:u,open:d})]})]})},$n=({offer:e,onClose:t})=>(0,H.jsxs)(`div`,{role:`dialog`,"aria-label":S(`pureOfferTitle`),className:`absolute z-10 grid gap-1 rounded-md border bg-background p-1 shadow-md`,style:{left:e.x,top:e.y},children:[e.choices.map((e,n)=>(0,H.jsx)(i,{size:`sm`,variant:`ghost`,className:`justify-start`,autoFocus:n===0,onClick:()=>{e.add(),t()},children:e.label},e.label)),(0,H.jsx)(i,{size:`sm`,variant:`ghost`,onClick:t,children:S(`pureOfferClose`)})]}),er=e=>typeof e==`object`&&!!e&&!Array.isArray(e),tr=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Z={kinds:[`boolean`]},nr=e=>e.sides.flatMap(e=>M(e)?nr(e):`read`in e?[e.read]:[]),rr=e=>!M(e)&&`read`in e&&`step`in e.read.base&&tr(e.read.path,[`Status`]),ir=(e,t)=>{if(t&&t.kinds!==`any`){let e=t.kinds.filter(e=>e!==`null`);if(e.length===1&&[`string`,`integer`,`number`,`boolean`].includes(e[0]))return{kinds:e}}return{kinds:[typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`]}},ar=e=>{let t=new Map;for(let[n,r]of ge(e.stateMachine)){let i=`Assign`in r&&er(r.Assign)?r.Assign:{};for(let[r,a]of Object.entries(i)){let i=a===`{% $states.result %}`?c(e.stateMachine,n)?.join(`/`):void 0;t.set(r,t.has(r)||i===void 0?null:i)}}return t},or=(e,t,n=[])=>{let r=new Map(ge(e.stateMachine).map(([t,n])=>[c(e.stateMachine,t).join(`/`),n])),i=ce(e)===`data`,a=new Map([[``,y(e,t)],...[...r].map(([e,n])=>[e,[...ee(n,t),...i?[x]:[]]])]),o=new Map([...r].filter(([,e])=>i||e.Type===`Task`).map(([e,n])=>[e,[...i?[g(n)]:[],...v(n,t)]])),s=e=>[...r.keys()].find(t=>t.split(`/`).at(-1)===e),l=new Map,u=new Map,d=[],f=[],p=new Map,m=ar(e),h=(e,t,n,r=!1)=>{let i=`data:${e.node}|${e.handle}->${t}|${n}`;r&&p.has(i)||p.set(i,{id:i,source:e.node,sourceHandle:e.handle,target:t,targetHandle:n,type:e.type,...r&&{expression:!0}})},te=(e,t)=>{let n=e.find(e=>tr(e.path,t));return n||(n={path:t,type:F(void 0)},e.push(n)),n},b=(e,t)=>{let n=a.get(e),r=n.find(e=>tr(e.path,t)),i=n.some(e=>e.path.length>0&&e.path[0]!==`#status`);if(r||t.length===0||i&&t.length===1){let i=r??te(n,t);return{node:e,handle:V(i.path),type:i.type}}let o=S(e,t.slice(0,-1)),s=te(o.outputs,t.slice(-1));return{node:o.id,handle:V(s.path),type:s.type}},S=(n,i)=>{let a=Ye(n,i),o=l.get(a);if(o)return o;let s=ae(e,r.get(n),t,i),c={kind:`break`,id:a,source:n,path:i,type:F(s),outputs:ne(s).map(([e,t])=>({path:[e],type:F(t)}))};return l.set(a,c),h(b(n,i),a,$e),c},re=(e,t,n)=>{let r=ie(e);if(r)return h(r,t,n);for(let r of pe(e)){let e=T(r);e&&h(e,t,n,!0)}},ie=e=>{let t=me(e);return t&&T(t)},T=e=>{if(`step`in e.base){let t=s(e.base.step);return t===void 0||!a.has(t)?void 0:b(t,[C,...e.path])}let t=`input`in e.base?``:m.get(e.base.variable);return t==null||!a.has(t)?void 0:b(t,e.path)},E=e=>{if(M(e)||!(`read`in e))return;if(!rr(e))return T(e.read);let t=s(e.read.base.step);return t===void 0||!a.has(t)?void 0:b(t,[C])},D=(e,t,n,r)=>{let i=Ze(e,n),a=t.sides,o=a.map(E),s=a.map((e,n)=>{let r=String(n);if(M(e))return{key:r,type:Z,required:!1,value:void 0,state:`made`};if(`read`in e)return{key:r,type:o[n]?.type??F(void 0),required:!1,value:fe(e.read),state:`wired`};if(`pattern`in e)return{key:r,type:{kinds:[`string`]},required:!1,value:e.pattern,state:`literal`};if(t.kind===`matches`)return{key:r,type:{kinds:[`string`]},required:!1,value:e.value,state:`literal`};if(t.kind!==`compare`)return{key:r,type:Z,required:!1,value:e.value,state:`literal`};let i=a[1-n];return rr(i)?{key:r,type:{kinds:[`string`]},required:!1,value:e.value,state:`literal`,options:j,statuses:!0}:{key:r,type:ir(e.value,o[1-n]?.type),required:!1,value:e.value,state:`literal`}});t.kind===`logic`&&s.push({key:String(a.length),type:Z,required:!1,value:void 0,state:`empty`}),d.push({kind:`condition`,id:i,target:e,at:n,part:t,inputs:s}),h({node:i,handle:tt,type:Z},r.node,r.handle),a.forEach((t,r)=>{M(t)?D(e,t,[...n,r],{node:i,handle:B(String(r))}):o[r]&&h(o[r],i,B(String(r)))})},O=(e,t)=>{let n=A(t),r={node:e,handle:B(w)};if(n&&nr(n).every(e=>E({read:e})))return D(e,n,[],r);let i=Ze(e,[]),a=pe(t).flatMap(e=>{let t=E({read:e});return t?[{read:e,source:t}]:[]});d.push({kind:`condition`,id:i,target:e,at:[],part:{kind:`expression`,source:se(t)},inputs:a.map(({read:e,source:t})=>({key:le(e),type:t.type,required:!1,value:fe(e),state:`wired`}))}),h({node:i,handle:tt,type:Z},r.node,r.handle);for(let{read:e,source:t}of a)h(t,i,B(le(e)),!0)},k=(e,t)=>{let n=oe(t.value),r=n&&E(n.operand);if(!n||`read`in n.operand&&!r)return!1;let i=Qe(e,t.key),a=`read`in n.operand?{key:rt,type:r.type,required:!1,value:fe(n.operand.read),state:`wired`}:{key:rt,type:{kinds:[`string`]},required:!1,value:n.operand.value,state:`literal`};return f.push({kind:`select`,id:i,target:e,key:t.key,part:n,type:t.type,inputs:[a]}),h({node:i,handle:nt,type:t.type},e,B(t.key)),r&&h(r,i,B(rt)),!0},N=(e,n)=>{let i=Xe(e,n),a=u.get(i);if(a)return a;let s=o.get(e)?.find(e=>e.key===n),c=r.get(e),l=he(ue(c,t),[n]),d=er(s?.value)?s.value:{},f=new Set(Array.isArray(l?.required)?l.required:[]),p=ne(l).map(([e,t])=>_(e,t,d[e],f.has(e))),m=Object.keys(d).filter(e=>!p.some(t=>t.key===e)).map(e=>_(e,he(l,[e])??{},d[e],!1)),g={kind:`make`,id:i,target:e,key:n,type:s?.type??F(l),inputs:[...p,...m]};u.set(i,g),h({node:i,handle:et,type:g.type},e,B(n));for(let e of g.inputs)re(e.value,i,B(e.key));return g};for(let[e,t]of o)for(let[n,r]of t.entries()){if(r.key===`#condition`&&r.state===`expression`){t[n]={...r,state:`made`},O(e,r.value);continue}if(r.state===`expression`&&k(e,r)){t[n]={...r,state:`made`};continue}r.state===`made`&&N(e,r.key),(r.state===`wired`||r.state===`expression`)&&re(r.value,e,B(r.key))}for(let e of n)e.kind===`break`&&a.has(e.source)&&S(e.source,e.path),e.kind===`make`&&o.get(e.target)?.some(t=>t.key===e.key&&t.state!==`wired`&&t.state!==`expression`)&&N(e.target,e.key);return{inputs:o,outputs:a,pure:[...l.values(),...u.values(),...d,...f],edges:[...p.values()]}},sr=e=>e.reason===`notBefore`?S(`refuseNotBefore`,{step:e.step}):e.reason===`otherScope`?S(`refuseOtherScope`,{step:e.step}):e.reason===`shapesOutput`?S(`refuseShaped`,{step:e.step}):e.reason===`type`?S(`refuseType`,{source:W(e.source),target:W(e.target)}):S(`refuseNotPins`),Q=e=>it(e)!==void 0||at(e)!==void 0,$=(e,t)=>({node:J(e),handle:t??``}),cr=e=>e!==`any`&&e.includes(`object`),lr=(e,t)=>e.map(e=>({label:Nt(e),add:()=>t(e)})),ur=(e,t)=>{let n=e=>e.kind===`break`?Ye(e.source,e.path):Xe(e.target,e.key),r=e=>e.kind===`break`&&t.some(t=>t.kind===`break`&&t.source===e.source&&t.path.every((t,n)=>e.path[n]===t));return e.filter(e=>!r(e)&&!t.some(t=>t.id===n(e)))},dr=(e,t,n,r,i)=>{let a=r?.edits,[o,s]=(0,R.useState)([]),[c,l]=(0,R.useState)(new Set),[u,d]=(0,R.useState)(),f=(0,R.useRef)({definition:e,editing:r});(0,R.useEffect)(()=>{f.current={definition:e,editing:r}});let p=(0,R.useMemo)(()=>n&&or(e,n,o),[e,n,o]),m=ce(e)===`data`,h=(0,R.useMemo)(()=>{if(p)return{sizes:Ut(t,p,c),pure:p.pure.map(e=>({id:e.id,parent:Jt(t,e)})),wires:p.edges.map(e=>({id:e.id,source:e.source,target:e.target,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),ports:qt(t,p,c),dataOrder:m}},[t,p,c,m]),g=r&&{setArgument:(t,n,i)=>r.onChange(r.edits.setArgument(e,t,n,i)),setConditionSide:(t,n,i)=>r.onChange(r.edits.setConditionSide(e,t,n,{value:i})),setCondition:(t,n)=>r.onChange(r.edits.setArgument(e,t,[`#condition`],n)),toggleOpen:e=>l(t=>t.has(e)?new Set([...t].filter(t=>t!==e)):new Set([...t,e]))},_=(t,n)=>{if(!p||!a||!Q(t.handle)||!Q(n.handle))return;let[r,i]=at(t.handle)?[t,n]:[n,t],o=a.wireRefusal(e,p,$(r.node,r.handle),$(i.node,i.handle));return o&&sr(o)},v=t=>!!(p&&a)&&a.wireRefusal(e,p,$(t.source,t.sourceHandle),$(t.target,t.targetHandle))===void 0,y=t=>{r&&p&&r.onChange(r.edits.connectData(e,p,$(t.source,t.sourceHandle),$(t.target,t.targetHandle)))},ee=(e,t,n)=>{if(!p||!a)return e;let r=e,i=n.flatMap(e=>{let t=e.data?.wire,n=t&&p.pure.find(e=>e.kind===`break`&&e.id===t.target||e.kind===`make`&&e.id===t.source);return n?[{id:n.id}]:[]}),o=[...t.filter(e=>q(e.id)),...i.filter(e=>!t.some(t=>t.id===e.id))],c=n.flatMap(e=>{let t=e.data?.wire;return t&&!o.some(e=>e.id===t.source||e.id===t.target)?[{wire:t}]:[]}),l=o.flatMap(e=>p.pure.filter(t=>t.id===e.id).map(e=>({pure:e}))),u=[...c,...l];for(let e of lt(p,u,e=>`wire`in e?ot(p,e.wire):st(e.pure)))r=`wire`in e?a.disconnectData(r,p,e.wire):a.removePure(r,p,e.pure);return o.length>0&&s(e=>ur(e,o.flatMap(e=>p.pure.filter(t=>t.id===e.id)))),r},te=(e,t)=>{let{definition:n,editing:r}=f.current;r?.onChange(r.edits.addSelect(n,e,t))},b=(e,t,n)=>{let{definition:r,editing:i}=f.current;i?.onChange(i.edits.addCondition(r,e,t,n))};return{data:p,open:c,layout:h,actions:g,check:_,isValid:v,connect:y,remove:ee,connectEnd:(e,t)=>{if(!p||!r||t.isValid||t.toHandle||!t.fromHandle?.id||!t.fromNode)return;let n=J(t.fromNode.id),a=t.fromHandle.id,o=`changedTouches`in e?e.changedTouches[0]:e,c=i.current?.getBoundingClientRect(),l={x:o.clientX-(c?.left??0),y:o.clientY-(c?.top??0)},u=at(a);if(u){let e=p.pure.find(e=>e.id===n),t=(e?.kind===`break`?e.outputs:p.outputs.get(n)??[]).find(e=>JSON.stringify(e.path)===JSON.stringify(u))?.type;if(!t||!cr(t.kinds))return;let r=e?.kind===`break`?{source:e.source,path:[...e.path,...u]}:{source:n,path:u};d({...l,choices:[{label:S(`breakTitle`,{type:W(t)}),add:()=>s(e=>[...e,{kind:`break`,...r}])}]});return}let f=it(a),m=p.pure.find(e=>e.id===n);if(m?.kind===`condition`){let e=m.inputs.find(e=>e.key===f);if(!e||e.state!==`literal`&&e.state!==`empty`||m.part.kind!==`logic`&&m.part.kind!==`not`)return;d({...l,choices:lr(r.edits.conditionChoices(!1),e=>b(m.target,[...m.at,Number(f)],e))});return}let h=f===void 0?void 0:p.inputs.get(n)?.find(e=>e.key===f);if(h?.key===`#condition`&&h.state===`empty`){d({...l,choices:lr(r.edits.conditionChoices(!0),e=>b(n,[],e))});return}if(h&&h.key!==`#condition`&&!cr(h.type.kinds)&&(h.state===`empty`||h.state===`literal`)){d({...l,choices:[{label:S(`selectOffer`),add:()=>te(n,h.key)}]});return}h&&cr(h.type.kinds)&&h.state!==`wired`&&h.state!==`expression`&&d({...l,choices:[{label:S(`makeTitle`,{type:W(h.type)}),add:()=>s(e=>[...e,{kind:`make`,target:n,key:h.key}])}]})},offer:u,closeOffer:()=>d(void 0)}},fr=(0,R.createContext)(void 0),pr=({fromX:e,fromY:t,toX:n,toY:r,fromPosition:i,toPosition:a,connectionStatus:o,fromNode:s,fromHandle:c,toNode:l,toHandle:u})=>{let d=(0,R.useContext)(fr),[f]=Ce({sourceX:e,sourceY:t,sourcePosition:i,targetX:n,targetY:r,targetPosition:a}),p=o===`invalid`&&l&&u?.id&&c.id?d?.({node:s.id,handle:c.id},{node:l.id,handle:u.id}):void 0;return(0,H.jsxs)(`g`,{className:p?`pb-wire-refused`:void 0,children:[(0,H.jsx)(`path`,{d:f,fill:`none`,className:`react-flow__connection-path`}),p&&(0,H.jsx)(`foreignObject`,{x:n+12,y:r-30,width:260,height:28,className:`overflow-visible`,children:(0,H.jsx)(`div`,{className:`inline-block rounded border border-danger bg-danger-soft px-1.5 py-0.5 text-xs whitespace-nowrap text-danger-text shadow`,children:p})})]})},mr=(e,t)=>{let n=De(),[r,i]=(0,R.useState)(),a=(0,R.useMemo)(()=>JSON.stringify(xt(e,t)),[e,t]);return(0,R.useEffect)(()=>{if(!n)return;let e=!0;return Ct(n,JSON.parse(a)).then(t=>{e&&i(t)}),()=>{e=!1}},[n,a]),r},hr={state:Pn,trigger:Fn,pure:Qn},gr=e=>e?.kind===`state`?e.scope.join(`/`):``,_r=({laidOut:e,tidied:t})=>{let n=ve();return(0,R.useEffect)(()=>{e&&n.fitView({maxZoom:1,padding:.1})},[e,t]),null},vr=()=>{let e=ve(),t=be(e=>e.width),n=(0,R.useRef)(t);return(0,R.useEffect)(()=>{let r=n.current;if(n.current=t,r===0||t===0||t===r)return;let{x:i,y:a,zoom:o}=e.getViewport();e.setViewport({x:i+(t-r)/2,y:a,zoom:o})},[t,e]),null},yr=({laidOut:e,ids:t})=>{let n=Ee();return(0,R.useEffect)(()=>{e&&n(t)},[e]),null},br=new Map,xr=({definition:e,problems:t,warnings:n,selected:r,onSelect:o,onChange:s,edits:c,onAddAt:l,traces:d,types:f,schemas:p,fills:h=!1,layout:g,onLayoutChange:_})=>{let v=s&&c&&{onChange:s,edits:c},y=(0,R.useMemo)(()=>ht(e),[e]),ee=(0,R.useRef)(null),[b,ne]=Bn(),x=dr(e,y,b===`pins`?p:void 0,v,ee),C=mr(y,x.layout),w=(0,R.useMemo)(()=>new Map(y.nodes.map(e=>[e.id,e])),[y]),T=JSON.stringify(g??{}),ae=(0,R.useMemo)(()=>re(T),[T]),E=ae[b],D=e=>_?.({...ae,[b]:e}),O=(0,R.useMemo)(()=>new Map([...y.nodes.map(e=>[e.id,ie(e.id)]),...(x.data?.pure??[]).map(e=>[e.id,ie(e.id,e)])]),[y,x.data]),k=(0,R.useMemo)(()=>new Map([...O].flatMap(([e,t])=>Object.hasOwn(E,t)?[[e,E[t]]]:[])),[O,E]),A=(0,R.useMemo)(()=>{if(!C)return;let e=new Map((x.data?.pure??[]).map(e=>[e.id,e]));return te(C,k,t=>{let n=w.get(t);return e.has(t)?Jt(y,e.get(t)):n?.kind===`state`?n.parent:void 0})},[C,k,w,y,x.data]),j=!!_,[M,oe]=(0,R.useState)(br),[se,N]=(0,R.useState)(0),P=ce(e)===`data`,[F,le]=(0,R.useState)(()=>new Set(r===void 0?[]:[K(r)]));(0,R.useEffect)(()=>{le(e=>r===void 0?e.size===1&&!q([...e][0])?new Set:e:e.has(K(r))?e:new Set([K(r)]))},[r]);let ue=(0,R.useMemo)(()=>[...Zt(y,A,t,r,d,f,n,x.data&&{data:x.data,open:x.open},P),...x.data?rn(y,x.data,A,x.open):[]].map(e=>{let t=M.get(e.id),n=k.has(J(e.id));return{...e,selected:F.has(e.id),draggable:j,...t&&{position:t},...n&&{data:{...e.data,moved:!0},...e.ariaLabel&&{ariaLabel:`${e.ariaLabel}, ${S(`movedByHand`)}`}}}}),[y,A,t,r,d,f,n,x.data,x.open,P,F,M,k,j]),[de,fe]=(0,R.useState)(),pe=(0,R.useMemo)(()=>[...P&&x.data?an(y,x.data):nn(y,P),...x.data?on(x.data):[]].map(e=>({...e,selected:e.id===de})),[y,x.data,de,P]),me=!!v,he=e=>{if(Q(e.sourceHandle)||Q(e.targetHandle))return Q(e.sourceHandle)&&Q(e.targetHandle)&&x.isValid(e);if(e.targetHandle!==`in`)return!1;let t=w.get(J(e.target)),n=w.get(J(e.source));return t?.kind===`state`&&gr(n)===gr(t)},ge=e=>{oe(br);let t=[...e].flatMap(([e,t])=>{let n=J(e),r=O.get(n),i=A?.get(n),a={x:Math.round(t.x),y:Math.round(t.y)};return r===void 0||!k.has(n)&&i&&Math.round(i.x)===a.x&&Math.round(i.y)===a.y?[]:[[r,a]]});t.length>0&&D({...E,...Object.fromEntries(t)})},_e=_&&(e=>{let t=O.get(J(e));t!==void 0&&D(m(E,t))}),ve=()=>{D({}),N(e=>e+1)},I=e=>{let t=new Map;for(let n of e){if(n.type!==`position`||!n.position||!j)continue;let e=n.position;n.dragging?oe(t=>new Map(t).set(n.id,e)):t.set(n.id,e)}t.size>0&&ge(t);let n=e.filter(e=>e.type===`select`);if(n.length===0)return;let i=new Set(F);for(let e of n)e.selected?i.add(e.id):i.delete(e.id);le(i);let[a]=i.size===1?[...i]:[],s=a===void 0||q(a)?void 0:J(a);if(s!==void 0&&(be||Ce.current))return r===void 0?void 0:o(void 0);s!==r&&o(s)},be=we(`Shift`),Ce=(0,R.useRef)(!1);return(0,H.jsx)(sn.Provider,{value:v?l:void 0,children:(0,H.jsx)(bn.Provider,{value:_e,children:(0,H.jsx)(ln.Provider,{value:x.actions,children:(0,H.jsx)(fr.Provider,{value:x.check,children:(0,H.jsxs)(`div`,{ref:ee,className:`relative h-full w-full`,children:[(0,H.jsxs)(Se,{className:`pb-workflow`,nodes:ue,edges:pe,nodeTypes:hr,nodesDraggable:j,nodeDragThreshold:4,selectNodesOnDrag:!1,nodesConnectable:me,connectOnClick:!1,connectionDragThreshold:4,edgesFocusable:me,elementsSelectable:!0,deleteKeyCode:me?[`Backspace`,`Delete`]:null,onNodesChange:I,onEdgesChange:e=>{for(let t of e)t.type===`select`&&(t.selected?fe(t.id):fe(e=>e===t.id?void 0:e))},isValidConnection:he,onConnect:t=>{if(v&&t.sourceHandle){if(Q(t.sourceHandle))return x.connect(t);v.onChange(v.edits.connect(e,t.sourceHandle,J(t.source),J(t.target)))}},onConnectEnd:x.connectEnd,connectionLineComponent:pr,onDelete:({nodes:t,edges:n})=>{if(!v)return;let r=t.filter(e=>!q(e.id)).map(e=>J(e.id)).filter(e=>e!==``),i=x.remove(e,t,n);for(let e of n){let t=e.data;t.kind!==`data`&&!r.includes(t.source)&&!r.includes(J(e.target))&&(i=v.edits.disconnect(i,t))}for(let e of r)r.some(t=>e.startsWith(`${t}/`))||(i=v.edits.removeState(i,e));v.onChange(i)},multiSelectionKeyCode:`Shift`,onSelectionStart:()=>void(Ce.current=!0),onSelectionEnd:()=>void(Ce.current=!1),onNodeClick:(e,t)=>!e.shiftKey&&!q(t.id)&&o(J(t.id)),onPaneClick:()=>o(void 0),zoomOnScroll:!0,panOnScroll:!1,panOnDrag:[0,1,2],selectionOnDrag:!1,selectionKeyCode:`Shift`,preventScrolling:!0,onPaneContextMenu:e=>e.preventDefault(),minZoom:.2,maxZoom:1.5,"aria-label":S(`canvas`),children:[(0,H.jsx)(Te,{gap:16}),p&&(0,H.jsx)(ye,{position:`top-left`,children:(0,H.jsx)(a,{label:S(`graphView`),value:b,onChange:ne,options:[{value:`pins`,label:S(`viewPins`)},{value:`simple`,label:S(`viewSimple`)}]})}),j&&Object.keys(E).length>0&&(0,H.jsx)(ye,{position:`top-right`,children:(0,H.jsxs)(i,{title:S(`tidyUpHelp`),onClick:ve,children:[(0,H.jsx)(u,{className:`size-3.5`,"aria-hidden":!0}),S(`tidyUp`)]})}),(0,H.jsx)(xe,{showInteractive:!1}),(0,H.jsx)(_r,{laidOut:C,tidied:se}),h&&(0,H.jsx)(vr,{}),(0,H.jsx)(yr,{laidOut:A,ids:ue.map(e=>e.id)})]}),x.offer&&(0,H.jsx)($n,{offer:x.offer,onClose:x.closeOffer})]})})})})})},Sr=e=>(0,H.jsx)(_e,{children:(0,H.jsx)(xr,{...e})});export{it as a,Le as c,Pe as d,je as f,ze as g,Be as h,ot as i,Ue as l,Ve as m,cn as n,at as o,Me as p,lt as r,Ke as s,Sr as t,Fe as u};
|
|
4
|
-
//# debugId=
|
|
4
|
+
//# debugId=8da604ab-f6fd-4383-ba93-e511c08a6cac
|
package/dist/shell/assets/{workflow-graph-editor-sZa5WHEO.js → workflow-graph-editor-z38xU0ar.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{b as r}from"./api-provider-
|
|
2
|
-
//# debugId=
|
|
1
|
+
(function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{b as r}from"./api-provider-CcDtTh0D.js";import{vn as i}from"./app-CYep6fHL.js";import{E as a,S as o,_ as s,a as c,b as l,g as u,i as d,k as f,m as p,n as m,t as h,w as g,y as _}from"./step-catalog-BuUwSkK9.js";import{E as v,S as y,b,n as x,v as S}from"./checkbox-COOOlJPG.js";import{t as C}from"./workflow-canvas-CNpgSr9v.js";import{t as w}from"./search-picker-DAcPiMQA.js";import{n as T,t as E}from"./graph-frame-PVfWqgbJ.js";var D=e(t(),1),O=e(n(),1),k=(e,t)=>{if(t===void 0||t===``)return[];let n=t.split(`/`);return b(v(e,t))?n:n.slice(0,-1)},A=({value:e,types:t,onChange:n,notice:b,layout:A,onLayoutChange:j})=>{let M=JSON.stringify(e??null),N=(0,D.useMemo)(()=>S(JSON.parse(M)),[M]),P=d(t),F=(0,D.useMemo)(()=>_(s(N,t,P)),[N,t,P]),I=(0,D.useMemo)(()=>l(N),[N]),[L,R]=(0,D.useState)(),[z,B]=(0,D.useState)(),V=(0,D.useMemo)(()=>m(t),[t]),H=L===``||L!==void 0&&v(N,L)?L:void 0,U=k(N,H),W=(e,t)=>{if(!n)return;let r=a(N,x(`newStep`));n(t?g(N,e,r,x(`newStep`),t):o(N,U,e,r,x(`newStep`))),R(y(t?f(t):U,r)),B(void 0)};return(0,O.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n&&(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsxs)(r,{onClick:()=>B(z?void 0:{}),"aria-expanded":!!z,children:[(0,O.jsx)(i,{className:`size-3.5`,"aria-hidden":!0}),U.length>0?x(`addStepInside`,{map:U.join(`/`)}):x(`addStep`)]}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:x(`connectHelp`)})]}),(0,O.jsx)(u,{problems:F.whole}),(0,O.jsx)(E,{canvas:(0,O.jsx)(C,{definition:N,problems:F.byNode,warnings:I,selected:H,onSelect:R,onChange:n,edits:c,onAddAt:e=>B({at:e}),types:t,schemas:P,layout:A,onLayoutChange:j}),panel:(0,O.jsxs)(O.Fragment,{children:[b,z?(0,O.jsx)(w,{autoFocus:!0,groups:V,onPick:e=>W(h(e.id),z.at)}):H===void 0?(0,O.jsx)(T,{children:x(`pickNode`)}):(0,O.jsx)(p,{definition:N,types:t,selected:H,problems:F.byNode.get(H)??[],warnings:I.get(H)??[],onChange:n,onSelect:R})]})})]})};export{A as WorkflowGraphEditor};
|
|
2
|
+
//# debugId=33dfcc54-d1aa-46fc-b9aa-b8f52619f4e3
|