@panphora/clayjs 1.25.1 → 1.26.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/all.js +1 -1
- package/dist/clay-dom.js +1 -1
- package/dist/clay-events.js +1 -1
- package/dist/clay-internals.js +1 -1
- package/dist/clay-options.js +1 -1
- package/dist/clay-router.js +1 -1
- package/dist/clay-ui.js +1 -1
- package/dist/clay-utils.js +1 -1
- package/dist/clay.js +1 -1
- package/dist/clay.standalone.js +1141 -345
- package/dist/m/c-2EPHRF47.js +1 -0
- package/dist/m/{c-2GB34XL4.js → c-2SUFMUZX.js} +2 -2
- package/dist/m/{c-BHLYQGTA.js → c-3S3647J6.js} +1 -1
- package/dist/m/{c-QL4NYM2L.js → c-3S5TNRZA.js} +1 -1
- package/dist/m/{c-3Y234AUB.js → c-3XGLJAS7.js} +2 -2
- package/dist/m/{c-O4YIDULY.js → c-42WBOKFM.js} +1 -1
- package/dist/m/{c-42RLKGEY.js → c-4TP3UXBT.js} +1 -1
- package/dist/m/{c-ASGHHLFX.js → c-5ELELG2F.js} +1 -1
- package/dist/m/{c-T5IWJOMW.js → c-5ZYLTN3Q.js} +1 -1
- package/dist/m/{c-DDCYVLGG.js → c-67TBU56I.js} +1 -1
- package/dist/m/{c-WNOLMHI2.js → c-6BGJAJ67.js} +1 -1
- package/dist/m/{c-XS7G6U3Z.js → c-ABOBD7F3.js} +1 -1
- package/dist/m/{c-5IIEOPIV.js → c-ARO6CPMA.js} +1 -1
- package/dist/m/{c-XUZMRQ7O.js → c-BCS3AZQZ.js} +1 -1
- package/dist/m/c-BOS7GONO.js +1 -0
- package/dist/m/{c-NICICT4P.js → c-DEYHCYJB.js} +1 -1
- package/dist/m/{c-T7LOTEWO.js → c-DZT6W2NG.js} +1 -1
- package/dist/m/c-EHJWIGWN.js +1 -0
- package/dist/m/{c-V2V5FKXX.js → c-EIUKME3W.js} +1 -1
- package/dist/m/{c-ASMLERFA.js → c-EXZOA6XY.js} +1 -1
- package/dist/m/{c-STAPQ2X6.js → c-EYFMAR3M.js} +1 -1
- package/dist/m/{c-DVMDYRAE.js → c-FUN6AKFE.js} +1 -1
- package/dist/m/{c-XMIDHEKF.js → c-GY36NO7C.js} +1 -1
- package/dist/m/{c-TWB5ZQU4.js → c-H47C6PJZ.js} +1 -1
- package/dist/m/c-KD2ME5UN.js +2 -0
- package/dist/m/{c-GO635CRU.js → c-LAKBBJOU.js} +2 -2
- package/dist/m/{c-GNFDX6SU.js → c-LETPPG2F.js} +1 -1
- package/dist/m/{c-LS7IVQVW.js → c-MMV5JULA.js} +1 -1
- package/dist/m/{c-NEQRFC4O.js → c-MVVEIJUU.js} +1 -1
- package/dist/m/{c-XCOQNISP.js → c-N362HNGO.js} +1 -1
- package/dist/m/{c-7K4SCQB7.js → c-ND3W7D5U.js} +1 -1
- package/dist/m/{c-4NAYDOWH.js → c-NNHNXD6M.js} +1 -1
- package/dist/m/{c-DAUQ6JZ3.js → c-NYJ577NL.js} +1 -1
- package/dist/m/{c-3AAQJAKJ.js → c-PWILUN4T.js} +1 -1
- package/dist/m/{c-7Z2625LX.js → c-QA3Q3MDI.js} +1 -1
- package/dist/m/{c-2A2ATCIH.js → c-QKOKMQXA.js} +1 -1
- package/dist/m/{c-TGIMBAWE.js → c-RBWVF4N5.js} +1 -1
- package/dist/m/{c-A5IYL7JI.js → c-SPOEDIMP.js} +1 -1
- package/dist/m/{c-ZJ7726FO.js → c-SRW5OBCF.js} +1 -1
- package/dist/m/{c-A3OKSYRI.js → c-SYOA4T7V.js} +1 -1
- package/dist/m/{c-MHTO3QAD.js → c-TJ5PFOJ2.js} +1 -1
- package/dist/m/{c-NW4ZFKCY.js → c-TKV273YU.js} +1 -1
- package/dist/m/{c-D4N4UJCQ.js → c-UEKJWXCB.js} +2 -2
- package/dist/m/{c-44WITKWQ.js → c-V4DBV5ZV.js} +1 -1
- package/dist/m/c-WHMZCRQD.js +6 -0
- package/dist/m/{c-WMRJKQ2V.js → c-WHQUZM2V.js} +1 -1
- package/dist/m/{c-C27EVUQ6.js → c-XHD7XJTE.js} +1 -1
- package/dist/m/{c-PP3CUF3U.js → c-XONFK3WC.js} +1 -1
- package/dist/m/c-YYIN4NAF.js +30 -0
- package/dist/m/c-ZFAPQQIB.js +1 -0
- package/dist/m/core/{conflict-notice-Y2NTMDGJ.js → conflict-notice-UNDOD4BL.js} +1 -1
- package/dist/m/core/site-edits-C22O53GS.js +1 -0
- package/dist/m/loader-DCKCZKY6.js +1 -0
- package/dist/m/{manifest-A27A4278.js → manifest-7954CBE3.js} +1 -1
- package/dist/m/{manifest-edit-E8A61EB4.js → manifest-edit-93AA79D7.js} +1 -1
- package/dist/m/manifest.json +442 -441
- package/dist/m/page/{editor-HS2CAV3W.js → editor-UF3CIA6V.js} +2 -2
- package/dist/m/plugins/{cms-4KET6RZT.js → cms-KG6TCTR3.js} +1 -1
- package/dist/m/plugins/{live-CO4VJS46.js → live-DF5YS5AH.js} +1 -1
- package/dist/m/plugins/page-GZSU77JS.js +2 -0
- package/dist/m/plugins/{page-view-6KNTXABH.js → page-view-7MM3FEAR.js} +1 -1
- package/dist/m/plugins/{quickcrop-VNRXGRPC.js → quickcrop-UHURKA2F.js} +2 -2
- package/dist/m/plugins/richclay-MXH2GFAZ.js +549 -0
- package/dist/m/plugins/undo-KLHAGV75.js +1 -0
- package/dist/m/sync/{live-sync-DX4K5GDB.js → live-sync-RZQSDMZW.js} +1 -1
- package/dist/offline-manifest.json +360 -360
- package/package.json +1 -1
- package/src/core/site-edits.js +1 -1
- package/src/loader-logic.js +0 -13
- package/src/page/boot-pack.js +1 -0
- package/src/page/history-intent.js +111 -4
- package/src/page/ybind/bridge.js +14 -7
- package/src/page/ybind/moves.js +437 -3
- package/src/page/ybind/origins.js +1 -1
- package/src/page/ybind/recovery.js +1 -1
- package/src/plugins/page.js +48 -4
- package/src/plugins/richclay.js +136 -0
- package/src/plugins/undo.js +169 -7
- package/src/recovery/undo.js +14 -7
- package/src/sync/live-sync.js +24 -0
- package/src/ui/vendor-skin.js +9 -4
- package/dist/m/c-3XNTQQEJ.js +0 -1
- package/dist/m/c-4OZZ7ENT.js +0 -30
- package/dist/m/c-D2OPWOWO.js +0 -2
- package/dist/m/c-LUBZU4AZ.js +0 -6
- package/dist/m/c-LYNLY3MR.js +0 -1
- package/dist/m/c-MLMJUNRV.js +0 -1
- package/dist/m/c-V5L6HWVL.js +0 -1
- package/dist/m/core/site-edits-TIJDPG6H.js +0 -1
- package/dist/m/loader-7ORQVRCK.js +0 -1
- package/dist/m/plugins/page-L3VKIQU2.js +0 -2
- package/dist/m/plugins/richclay-V6WKJTUF.js +0 -549
- package/dist/m/plugins/undo-WUK2NLBA.js +0 -1
- /package/dist/m/plugins/{quickcrop-VNRXGRPC.js.LEGAL.txt → quickcrop-UHURKA2F.js.LEGAL.txt} +0 -0
- /package/dist/m/plugins/{richclay-V6WKJTUF.js.LEGAL.txt → richclay-MXH2GFAZ.js.LEGAL.txt} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{A as
|
|
1
|
+
import{A as Z,B as k,C as P,D as g,E as T,F as y,G as A,H as E,I as z,J as x,K as O,L as tt,M as et,N as ot,O as B,P as D,S as it,T as K,c as M,d as L,e as f,n as J,t as $,x as v,y as Q}from"./c-WHMZCRQD.js";import"./c-LAKBBJOU.js";import"./c-EIUKME3W.js";import"./c-DZT6W2NG.js";import"./c-SYOA4T7V.js";import"./c-ND3W7D5U.js";import"./c-WHQUZM2V.js";import{C as Y,d as N}from"./c-3XGLJAS7.js";import{N as G,d as V,z as X}from"./c-OH2FPYSY.js";import"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-57XDY6HC.js";import{a as j}from"./c-I2SCCUEW.js";import"./c-VHNSBD2M.js";var nt=`
|
|
2
2
|
.blockeditor-editor .blockeditor-table { position: relative; }
|
|
3
3
|
.blockeditor-table td { position: relative; }
|
|
4
4
|
.blockeditor-table th { position: relative; }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-FC5RUFPR.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-EHAR4RJJ.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-KU3PX7LL.js";import{e as we,k as wt}from"./c-EQ5NBOGA.js";import{b as mt,f as Z}from"./c-C7SUMNMI.js";import{f as gt,k as yt}from"./c-UW6MMZ4V.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-XUZMRQ7O.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
1
|
+
import{a as Tt,c as Rt,d as Pt,e as $t,f as be,g as Ct}from"./c-JKZJIUIP.js";import{a as ee}from"./c-TCCA5BZN.js";import{a as T,b as Fe,c as Ye,d as Be,e as ke,f as Mt,g as ze,h as Lt,i as G,j as Ae,k as R,l as _t,m as qt,n as Ve,o as ue}from"./c-3LDGIBMN.js";import{d as jt}from"./c-57XDY6HC.js";import{e as Ot}from"./c-LZJPNR2W.js";import{F as Je,K as Ue,g as Et,r as Ie}from"./c-FC5RUFPR.js";import{a as We}from"./c-I2SCCUEW.js";import{f as De,g as He,k as kt,l as At,m as St,y as xt}from"./c-EHAR4RJJ.js";import{a as vt}from"./c-LD6UVV5R.js";import{a as Ne}from"./c-PGSBXHUE.js";import{a as je,c as bt}from"./c-KU3PX7LL.js";import{e as we,k as wt}from"./c-EQ5NBOGA.js";import{b as mt,f as Z}from"./c-C7SUMNMI.js";import{f as gt,k as yt}from"./c-UW6MMZ4V.js";var gn=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),yn=/^(0|[1-9]\d*)$/,U=e=>e!==null&&typeof e=="object",te=e=>Array.isArray(e)?"a list":"an object";function J(e,t){let r=e;for(let o of t){if(!U(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var Se=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),vn=(e,t)=>R(e)===R(t);function Nt(e,t){let r=[];try{for(let o of t){let n=Mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Ke(r),null}}function Ke(e){let t;for(let r=e.length-1;r>=0;r--)t=ze(e[r]);return t}function wn(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let s=o.find(a=>a.path.length===n.path.length&&G(a.path,n.path));if(s){if(s.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(s.removed=!0);continue}if(o.some(a=>G(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=Se(n.at,n.key),n.had&&n.has&&n.removed||(n.into=J(r,n.path.slice(0,-1)),!U(n.into)||Array.isArray(n.into)||Se(n.into,n.key)!==n.had))return null;let s=n.path.slice(0,-1);for(let a of t){let i=a.op.path;if(G(n.path,i)||a.op.op==="del"&&i.length<=n.path.length&&G(i.slice(0,-1),n.path)&&Array.isArray(J(r,i.slice(0,-1))))return null;if(!n.had&&n.has&&i.length>s.length&&G(s,i)){let c=i[s.length];if(i.length===s.length+1&&a.op.op==="del"||!Se(n.at,String(c)))return null}}}return o}function bn(e,t){if(t.op==="set"){let r=J(e,t.path);if(U(r)&&U(t.value)&&Array.isArray(r)===Array.isArray(t.value)){Ae(r,T(t.value));return}}Be(e,t)}function Ge({name:e,value:t,ephemeral:r=!1}){if(!U(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=T(t),n=null,s=T(t),a=!0,i=[],c=1,d=null,h="file",w=new Set,A=new Set,b=new Set,x=new Set,E=new Set,v=new WeakMap;function O(l,u){let f={source:l,ops:u};for(let g of[...w])try{g(f)}catch(S){console.error(`clay.live("${e}"): a change listener threw`,S)}}function I(){let l=T(o),u=[];for(let f of i)try{Ye(l,f.op),l=Be(l,f.op),u.push(f)}catch{}i=u,Ae(s,l),a=!0}function N(l){for(let u of[...b])try{u(l)}catch(f){console.error(`clay.live("${e}"): a rebase listener threw`,f)}}function se(l,{source:u="remote",confirmed:f=0,through:g,drop:S,dropIds:$,frame:K=null,room:L=null,cause:ce=null}={}){if(!U(l)||te(l)!==te(s))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${te(s)}`),!1;L&&(n=L);let me=T(s),ge=o;if(o=T(l),S)i=i.filter(_=>_.id<S[0]||_.id>S[1]);else if($){let _=new Set($);i=i.filter(ye=>!_.has(ye.id))}else i=g===void 0?i.slice(f):i.filter(_=>_.id>g);return I(),N({source:u,frame:K,room:L,cause:ce,prev:ge,before:_=>J(ge,_),next:o}),_t(me,s)||O(u,null),!0}function ie(l){let u=T(o);for(let f=l.length-1;f>=0;f--){let g=l[f];ze({...g,at:J(u,g.path.slice(0,-1))})}return u}function ae(l){for(let u of[...A])try{u(l)}catch(f){console.error(`clay.live("${e}"): a transport threw`,f)}O("local",l)}function C(l){let u=l.map(Fe);for(let f of u)if(f.path.length===0&&te(f.value)!==te(s))throw new TypeError(`clay.live("${e}"): the whole value must stay ${te(s)}`);u.length===1?Ye(s,u[0]):ke(T(s),u);for(let f of u)bn(s,f);i.push(...u.map(f=>({id:c++,op:f}))),d?d.push(...u):ae(u)}function B(l,u){let f=v.get(l);f||v.set(l,f=new Map);let g=JSON.stringify(u),S=f.get(g);return S||(S=new Proxy(l,Ce(u)),f.set(g,S)),S}function Ce(l){return{get(u,f){if(Array.isArray(u)&&gn.has(f))return(...S)=>{let $=T(u),K=Array.prototype[f].apply($,S);return C([{op:"set",path:l,value:$}]),K===$?B(u,l):K};let g=u[f];return typeof f=="symbol"||!U(g)||!Object.prototype.hasOwnProperty.call(u,f)?g:B(g,[...l,Array.isArray(u)?Number(f):f])},set(u,f,g){if(typeof f=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(u)){if(f==="length"){let S=T(u);return S.length=g,C([{op:"set",path:l,value:S}]),!0}if(!yn.test(f))throw new TypeError(`clay.live("${e}"): "${f}" is not a list index`);return C([{op:"set",path:[...l,Number(f)],value:g}]),!0}return C([{op:"set",path:[...l,f],value:g}]),!0},deleteProperty(u,f){if(typeof f=="symbol")return!0;if(Array.isArray(u))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return C([{op:"del",path:[...l,f]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let le=B(s,[]),Q,Me=new Promise(l=>{Q=l}),y=Object.freeze({name:e,ephemeral:r,ready:Me,get data(){return le},get status(){return{mode:h}},set(l,u){C([{op:"set",path:l,value:u}])},delete(l){C([{op:"del",path:l}])},add(l,u=1){C([{op:"add",path:l,n:u}])},update(l){if(typeof l!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(d)return l(le);d=[];let u=i.length,f=c,g;try{if(g=l(le),g&&typeof g.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch($){throw d=null,i.length=u,c=f,I(),$}let S=Lt(d);return d=null,i.length=u,c=f,i.push(...S.map($=>({id:c++,op:$}))),S.length&&ae(S),g},on(l,u){if(l!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof u!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return w.add(u),()=>w.delete(u)},off(l,u){w.delete(u)},toJSON(){return T(s)}});return Q(y),{handle:y,name:e,ephemeral:r,get value(){return s},get authoritative(){return o},get room(){return n},get pending(){return i.map(l=>l.op)},pendingEntries(){return i.map(l=>({id:l.id,op:l.op}))},get mark(){return c-1},setMode(l){h=l,l!=="fast"&&(n=null)},onLocal(l){return A.add(l),()=>A.delete(l)},confirm(l){let u=i.filter(f=>f.id<=l);if(u.length){try{o=ke(T(o),u.map(f=>f.op))}catch{o=T(s),a=!1}i=i.filter(f=>f.id>l);for(let f of[...x])try{f({through:l})}catch(g){console.error(`clay.live("${e}"): a confirmation listener threw`,g)}}},onConfirm(l){return x.add(l),()=>x.delete(l)},rebase:se,checkOps(l){let u;try{u=l.map(Fe)}catch{return null}let f=Nt(o,u);return f?(Ke(f),u):null},rebaseOps(l,{source:u="remote",confirmed:f=0,through:g,frame:S=null,room:$=null,cause:K=null}={}){let L=Nt(o,l);if(!L)return!1;let ce=g===void 0?i.slice(f):i.filter(k=>k.id>g),me=i.length-ce.length,ge=L.some(k=>k.at===null),_=a&&!ge&&me===l.length&&l.every((k,D)=>vn(k,i[D].op)),ye=a&&!_&&me===0?wn(L,ce,s):null;if(!_&&!ye)return Ke(L),se(ke(T(o),l),{source:u,confirmed:f,through:g,frame:S,room:$,cause:K});i=ce;let Le=!1;for(let k of ye??[]){let D=k.into;if(k.has){let ht=k.at[k.key];(!k.had||R(k.old)!==R(ht))&&(Le=!0);let qe=k.had?D[k.key]:void 0,ve=T(ht),mn=U(qe)&&U(ve)&&Array.isArray(qe)===Array.isArray(ve);Object.defineProperty(D,k.key,{value:mn?Ae(qe,ve):ve,enumerable:!0,writable:!0,configurable:!0})}else k.had&&(Le=!0,delete D[k.key])}let dn=null,_e=()=>dn??=ie(L),pn=L.some(k=>Array.isArray(k.at)&&k.kind!=="put"),hn=k=>{if(pn)return J(_e(),k);for(let D of L)if(G(D.path,k))return D.path.length>k.length?J(_e(),k):J(D.old,k.slice(D.path.length));return J(o,k)};return $&&(n=$),N({source:u,frame:S,room:$,cause:K,get prev(){return _e()},before:hn,next:o}),Le&&O(u,null),!0},onRebase(l){return b.add(l),()=>b.delete(l)},onDelivery(l){return E.add(l),()=>E.delete(l)},deliver(l){for(let u of[...E])try{u(l)}catch(f){console.error(`clay.live("${e}"): a delivery listener threw`,f)}}}}function Dt({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:s=setTimeout,clearTimer:a=clearTimeout}){let i=null,c=null,d=!1,h=!1,w=0;function A(v){let O=v&&!v.ok&&v.msgType==="skipped";return w=v?.ok||O?0:n()+8e3,O?1e3:8e3}function b(v){i=v,c!==null&&a(c),c=s(E,Math.max(0,v-n()))}function x(){c!==null&&a(c),c=null,i=null}async function E(){if(c=null,i=null,!e())return;if(t()){b(n()+1e3);return}d=!0;let v=null;try{v=await r()}catch{v=null}finally{d=!1}let O=A(v);e()&&b(n()+O)}return{changed(){i===null&&!d&&b(n()+8e3)},flush(){d||!e()||t()||(x(),d=!0,h=!0,Promise.resolve().then(o).catch(()=>null).then(v=>{d=!1,h=!1;let O=A(v);e()&&b(n()+O)}))},soon(){if(d)return;let v=Math.max(n(),w);(i===null||v<i)&&b(v)},within(v){if(d)return;let O=Math.max(n()+v,w);(i===null||O<i)&&b(O)},get flushing(){return h},get deadline(){return i}}}var ne=[0,1e4,3e4],kn=6e3,An=2;async function Sn(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),s="";for(let a=0;a<n.length;a+=1)s+=n[a].toString(16).padStart(2,"0");return s}catch{return null}}function xn(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=An)break}return t}function En(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Ht({query:e,digest:t=Sn,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function s({captureId:a,html:i,attempts:c,initialOutcome:d,startedAt:h,onApplied:w,onUnknown:A}){let b=h+45e3,x=xn(c),E=new Set,v=new Set,O=i,I=null,N=!1;function se(y,l){try{typeof y=="function"&&y(l)}catch(u){console.error("clayjs: save-history callback failed:",u)}}function ie(){N=!0,O=null;for(let y of E)n(y);E.clear();for(let y of v)y.abort();v.clear()}function ae(y,l){N||(ie(),se(w,{captureId:a,saveId:y,requestHash:l}))}function C(y){N||(ie(),se(A,{captureId:a,reason:y}))}function B(y,l){let u=null;return u=o(()=>{u!==null&&E.delete(u),y()},Math.max(0,l)),E.add(u),u}function Ce(y){y!==null&&(n(y),E.delete(y))}async function le(y){if(N)return;let l=b-r();if(l<=0)return;let u=new AbortController;v.add(u);let f=B(()=>u.abort(),Math.min(kn,l)),g=null;try{g=await e({saveId:y,requestHash:I,signal:u.signal})}catch{g=null}finally{Ce(f),v.delete(u)}N||En(g,y,I)&&ae(y,I)}function Q(){if(!N&&!(r()>=b))for(let y of x)le(y)}async function Me(){let y=null;try{y=await t(O)}catch{y=null}if(O=null,N)return;if(typeof y!="string"||!y){C("unavailable");return}if(I=y,d&&typeof d=="object"&&d.status==="applied"&&d.requestHash===I&&x.includes(d.saveId)){ae(d.saveId,I);return}let l=r()-h;if(l>=45e3){C("expired");return}let u=-1;for(let f=0;f<ne.length;f+=1)ne[f]<=l&&(u=f);if(u<0){for(let f=0;f<ne.length;f+=1)B(Q,h+ne[f]-r());return}Q();for(let f=u+1;f<ne.length;f+=1)B(Q,h+ne[f]-r())}return B(()=>C("expired"),b-r()),Me(),{cancel(){ie()}}}return{start:s}}var On="/_/sync/data";function It(){return new URL(On,window.location.origin)}async function Tn(e,t){let r=It();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Ne]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let s=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:s}}catch{return{status:0,body:null,retryAfter:0}}}async function Rn(e,t=null,{signal:r}={}){let o=It();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`),o.searchParams.set("compaction","1");try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Ne]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let s=await n.json();return s&&typeof s.epoch=="string"&&s.conn===null?null:s}catch{return null}}function Jt(){return{start(e){return Ot({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Tn,fetchState:Rn}}var $n=()=>Promise.all([import("./c-IXO7EI2Q.js"),import("./c-BCS3AZQZ.js")]).then(([e,t])=>({createFastLane:e.createFastLane,localTransport:t.localTransport,localLaneSupported:t.localLaneSupported})),Cn=/^[A-Za-z0-9_.:-]{1,64}$/,m=new Map,Gt="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Qe=0,Mn=0,Ln=45e3;function rt(e){let t=ue(e.getAttribute("live-at"));if(!t||t.hash!==Zn(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:be(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:Pt(o),ancestors:$t(o)}}function _n(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=p?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Tt(r.frames??[],o.frames),s=r.ancestors??[],a=R(e.store.value),i=JSON.stringify([r.epoch,r.seq,n,s,e.store.mark,a]);if(e.capture?.key===i)return e.capture.value;let c={v:2,frames:n,ancestors:s,capture:[Gt,Qe+1]},d=Ct(c),h=d?{at:Ve(r.epoch,r.seq,a),by:d}:null;return e.capture={key:i,value:h},h}var V=new Map,F=null,q=null,H=null,qn=Ht({query:e=>wt?.(e)??null}),j=new Map;function Xt(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||pe(e)}var Qt=(e,t)=>F===null||!He()?!1:V.get(F)?.get(e)?.key===t;function fe(e){let t=m.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,s]of t.captureOps)if(!(!s.ended&&!Qt(e,n)))for(let a of s.ids)r.has(a)&&o.add(a);return[...o]}function ot(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}We({id:"live:held",isPending:()=>[...m.values()].some(e=>ot(e))});var Ut=e=>[...e.captureOps].some(([t,r])=>!r.ended&&Qt(e.store.name,t));function jn({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",s=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return s.length>60?`${s.slice(0,57)}...`:s}function st(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,re(e)},Ln)}function pe(e){clearTimeout(e.timer),e.timer=null}function re(e,{read:t=!0}={}){let r=e.store.name,o=fe(r);if(pe(e),e.withheld=!1,e.reading=!1,tn(e),o.length){let n=e.store.pendingEntries().filter(c=>o.includes(c.id)).map(c=>c.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let s=n.slice(0,5).map(jn).join("; "),a=n.length>5?` and ${n.length-5} more`:"",i=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${s}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${i}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:i}}))}t&&p?.release(r,{read:p.roomBound(r)})}function de(e){Xt(e);let t=e.store.name;if(e.recovery&&!Dn(e)&&tn(e),!(!e.withheld||e.reading||fe(t).length)){if(!p?.roomBound(t)){e.withheld=!1,pe(e);return}e.reading=!0,st(e),p.release(t,{read:!0})}}function Nn(e){let t=m.get(e);t&&(it(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||pe(t)))}function Zt(){for(let e of m.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function Dn(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function Hn(e){if(!H||H.captureId!==e||typeof H.html!="string")return null;let t=[];for(let[r,o]of H.qualified)!m.get(r)||!o.length||t.push({name:r,ids:[...o],saved:H.saved.get(r)});return t.length?{captureId:e,html:H.html,targets:t}:null}function Ee(){H&&(H.html=null)}function Wn(e,t){en(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function it(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,en(e))}function en(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function tn(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>m.get(r.name)?.recovery===t)&&(j.delete(t.captureId),t.run?.cancel()))}function nn(e){if(e==null)return;let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function In(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:s}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};j.set(n,a);for(let i of e.targets){let c=m.get(i.name);pe(c),c.recovery=a}we("save-history").then(i=>{if(j.get(n)===a){if(e.html=null,!i)return Ft(n);a.run=qn.start({captureId:n,html:s,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:c,requestHash:d})=>Jn(n,c,d),onUnknown:({reason:c})=>Un(n,c)})}},()=>{e.html=null,Ft(n)})}function Jn(e,t,r){let o=j.get(e);if(o){j.delete(e);for(let n of o.targets){let s=m.get(n.name);if(!s||s.recovery!==o)continue;s.recovery=null,s.historicalRefreshPending=!0;let a=new Set(s.store.pendingEntries().map(c=>c.id)),i=n.ids.filter(c=>a.has(c));if(s.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:i}),!p){it(s);continue}p.release(s.store.name,{read:!0}),Wn(s,o.deadline)}}}function Ft(e){let t=j.get(e);if(t){j.delete(e);for(let r of t.targets){let o=m.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!p?.roomBound(o.store.name)){re(o,{read:!1});continue}o.withheld=!0,o.reading=!0,st(o),p.release(o.store.name,{read:!0})}}}}function Un(e,t){let r=j.get(e);if(r){j.delete(e);for(let o of r.targets){let n=m.get(o.name);!n||n.recovery!==r||(n.recovery=null,re(n))}}}function Fn(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!p?.roomBound(n)){re(e,{read:!1});return}e.withheld=!0,e.reading=!0,st(e),p.release(n,{read:!0})}function Ze(e){if(Array.isArray(e))return e.map(Ze);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ze(e[r]);return t}function at(e){try{return JSON.stringify(Ze(ee(e)))}catch{return null}}var P=null,he=()=>!P||P.admitted;function Yn(){if(!Z||!he())return!1;for(let e of m.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(p?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var et=new Set;function rn(){for(let e of[...et])e()}var M=Dt({needsSave:Yn,blocked:()=>!he()||!Ue()||Ie()||Et()||Zt(),save:()=>Je().finally(rn),saveNow:()=>De(!0,()=>Je())}),p=null,tt=!1,xe=0,Oe=null,lt=!1,W=null,ct=!1;function Re(){return[...m.values()].filter(e=>!e.store.ephemeral)}function on(){if(!P||P.admitted||!p||p.status.stopped)return!1;for(let e of Re())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function sn({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Re())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&p?.release(o.store.name)};for(r();on();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}We({id:"live:writer",isPending:on,flush:sn});function Bn(){for(let e of m.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function zn(){let e=p;p=null,tt=!1,xe++,Oe=null,W=null,lt=!1,Te=null,ut=null,X=null,z=null,e?.stop()}function $r(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return P||(P={admitted:!0}),Bt(P,{adopted:!0});an();let t={admitted:!1,wantsLane:!0};return P=t,Bn(),Pe(),Bt(t)}}}function Yt(){for(let e of Re())e.store.pending.length>0&&p?.release(e.store.name)}function Bt(e,{adopted:t=!1}={}){return{enable(){t||P!==e||(e.admitted=!0,Pe(),Yt())},quiesce(){if(P===e)return e.admitted=!1,sn()},resume(){P===e&&(e.admitted=!0,Yt())},dispose(){P===e&&(P=null,zn())}}}var Te=null,ut=null,X=null,z=null;function an(){Te=new Promise(e=>{X=e}),ut=new Promise(e=>{z=e})}function ft(){return Te||an(),{laneReady:Te,writerReady:ut}}function Cr(){return ft().laneReady}function Mr(){return ft().writerReady}function zt(){for(let e of m.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){M.soon();return}M.changed()}function Xe(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function dt(e,t,r=null){if(e)for(let[o,n]of e){let s=m.get(o);!s||n.mode!=="file"||(t||n.maybeLanded?Fn(s,n.key,r):(s.captureOps.delete(n.key),de(s)),s.store.handle.status.mode==="fast"&&p?.release(o))}}function oe(e){let t=V.get(e);return V.delete(e),F===e&&(F=null),q===e&&(q=null),t}function ln(e,t=null){let r=t??F??q;r!==null&&dt(oe(r),e)}function Vn(e,t){if(e?.code==="draft-storage"||e?.code==="draft-not-ready")return!1;let r=e?.code,o=r==="blockeditor-converting"||r==="blockeditor-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vt(e){return{transport:e,entries:m,onWriter:()=>{M.changed(),p&&p.status.writer!==null&&z?.(p)},onApplied:zt,onLanded:()=>{zt(),rn()},onCheckpoint:()=>M.soon(),onLeave:(t,r)=>{let o=m.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>fe(t).length>0,heldIds:fe,hold:t=>{let r=m.get(t);return r?r.recovery?!0:Ut(r)?(r.withheld=!0,!0):(re(r,{read:!1}),!1):!1},taken:Nn,onStop:()=>{for(let t of m.values())it(t),!t.recovery&&(Ut(t)||re(t,{read:!1}))}}}function Kn(){let e=new Map;for(let[t,r]of Y(document,{warn:!1})){let o=m.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=ee(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}for(let[t,r]of m)r.staged||e.set(t,{value:r.store.authoritative,ephemeral:r.store.ephemeral});return e}function Pe(){if(ft(),tt||!(P?P.admitted||P.wantsLane:Z))return;if(tt=!0,mt){X?.(null),z?.(null);return}let e=++xe;we("live-data").then(async t=>{let r=t&&await we("live-provenance");if(e!==xe)return;Oe=t,lt=r;let o=await $n().catch(()=>null);if(e===xe){if(!o){X?.(null),z?.(null);return}if(t)p=o.createFastLane(Vt(Jt()));else if(o.localLaneSupported())W=o.localTransport({seed:Kn,rooms:!0,floor:document.querySelector('meta[name="clay-blockeditor-format"]')?.getAttribute("content")}),p=o.createFastLane(Vt(W));else{X?.(null),z?.(null);return}for(let n of Y(document,{warn:!1}).keys())if(!m.has(n))try{un(n)}catch{}for(let[n,s]of m)s.historicalRefreshPending&&p.release(n,{read:!0});p.start(),X?.(p),p.status.writer!==null&&z?.(p)}}).catch(()=>{X?.(null),z?.(null)})}function Gn(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Y(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!Gn(n.getAttribute("type")))continue;let s=n.getAttribute("merge");if(Cn.test(s)){if(r.has(s)){o.add(s);continue}r.set(s,{name:s,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function $e(e){return new DOMParser().parseFromString(e,"text/html")}function Xn(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^blockeditor(\.[0-9]+)?$/.test(e.store.name)?jt(r):r;return e.layout==="lines"?Qn(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):R(o)}var Kt=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Qn(e){return Kt(e)?`{${Object.entries(e).map(([r,o])=>!Kt(o)||!Object.keys(o).length?`${R(r)}:${R(o)}`:`${R(r)}:{
|
|
2
2
|
${Object.entries(o).map(([n,s])=>`${R(n)}:${R(s)}`).join(`,
|
|
3
3
|
`)}
|
|
4
4
|
}`).join(`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as H,D as X,d as M,g as L,h as O,j as D,m as I,n as R,o as k,p as C,q as A,r as N,t as $}from"./c-
|
|
1
|
+
import{C as H,D as X,d as M,g as L,h as O,j as D,m as I,n as R,o as k,p as C,q as A,r as N,t as $}from"./c-3XGLJAS7.js";import{d as B}from"./c-OH2FPYSY.js";var _=new WeakMap;function g(s){let t=_.get(s);return t||_.set(s,t=O(s)),t}var F=B.nodes,w=s=>s.type===F.list_item,S=s=>s.type===F.toggle,y=s=>s.attrs.parent??null;function J(s,t,e){if(e<0)return[null];let n=[],i=s[e].node;S(i)&&i.attrs.open&&!s[e].hidden&&n.unshift(i.attrs.id);for(let r=y(i);r!==null&&!n.includes(r);){let c=s[t.get(r)];if(!c)break;n.unshift(r),r=y(c.node)}let o=[null];for(let r of n){let c=s[t.get(r)];if(!c.node.attrs.open||c.hidden)break;o.push(r)}return o}function Y(s,t,e,n){let i=y(s[t].node),o=w(s[t].node)?n.indent-s[t].node.attrs.indent:0;return r=>r.i<t||r.i>e||y(r.node)!==i?null:w(r.node)?{parent:n.parent,indent:r.node.attrs.indent+o}:{parent:n.parent}}function Q(s,t){let e=null;s.doc.forEach((n,i)=>{n.attrs.id===t&&S(n)&&(e={n,off:i})}),e&&!e.n.attrs.open&&s.setNodeMarkup(e.off,null,{...e.n.attrs,open:!0})}function P(s,t,e,n,i,o=null){let r=Y(t,e,n,i),c=t[e].at,d=t[n].end,h=o??new C(s.doc.resolve(c),s.doc.resolve(d)),a;if(i.at===c||i.at===d){a=s.tr;for(let l=e;l<=n;l++){let p=r(t[l]);p&&a.setNodeMarkup(t[l].at,null,{...t[l].node.attrs,...p})}a.setSelection(h.map(a.doc,a.mapping)),a.setMeta(L,A(t,e,n,i.at,r))}else a=N(s,t,e,n,i.at,r,h);if(i.open){Q(a,i.open);let l=a.getMeta(L);l&&a.setMeta(L,{...l,attrs:{...l.attrs,[i.open]:{open:!0}}})}return a}function K(s,t,e,n,i){if(i.parent!=null&&t.slice(e,n+1).some(a=>a.node.attrs.id===i.parent))return!1;let o=t[n].end-t[e].at,r=Y(t,e,n,i);for(let a=e;a<=n;a++)if(w(t[a].node)&&(r(t[a])?.indent??t[a].node.attrs.indent)>$)return!1;let c=P(s,t,e,n,i),h=i.at===t[e].at||i.at===t[n].end?t[e].at:i.at>t[e].at?i.at-o:i.at;return D(c.doc,s.doc).every(a=>a.at>=h&&a.at<h+o)}function U(s,t,e,n,i){let o=new Map;t.forEach(l=>{S(l.node)&&l.node.attrs.id&&o.set(l.node.attrs.id,l.i)});let r=i<0?s.doc.content.size:t[i].at;if(r>t[e].at&&r<t[n].end)return[];let c=(i<0?t.length:i)-1,d=J(t,o,c),h=d.indexOf(i<0?null:y(t[i].node)),a=[];for(let l of d.slice(Math.max(0,h))){let p=l===null?0:t[o.get(l)].depth+1,E=c>=0&&w(t[c].node)&&y(t[c].node)===l?t[c].node:null,f=w(t[e].node)&&E?E.attrs.indent+1:0;for(let u=0;u<=f;u++){let m={at:r,parent:l,indent:u,depth:p+(w(t[e].node)?u:0)};K(s,t,e,n,m)&&a.push(m)}}return a}function q(s,t,e,n,i){let o=t[i];if(!o||!S(o.node)||o.node.attrs.open||o.hidden||i>=e&&i<=n||o.at>t[e].at&&o.at<t[n].end)return null;let r=o.node.attrs.id,c={at:t[o.subEnd].end,parent:r,indent:0,depth:o.depth+1,open:r};return K(s,t,e,n,c)?c:null}function z(s,t){let e=null;for(let n of s)(!e||Math.abs(n.depth-t)<Math.abs(e.depth-t))&&(e=n);return e}var Z=4,tt=250,V=8,b=56,W=18;function et(s){for(let t=s.parentElement;t;t=t.parentElement){let e=getComputedStyle(t).overflowY;if((e==="auto"||e==="scroll")&&t.scrollHeight>t.clientHeight)return t}return s.ownerDocument.scrollingElement}var j=new WeakMap;function nt(s,t){let e=j.get(s);if(!e){e=[];for(let n of s){if(n.hidden)continue;let i=t.nodeDOM(n.at);i?.getBoundingClientRect&&e.push({i:n.i,dom:i})}j.set(s,e)}return e}function it(s,t){let e=0,n=s.length;for(;e<n;){let i=e+n>>1,o=s[i].dom.getBoundingClientRect();t<o.top+o.height/2?n=i:e=i+1}return e<s.length?e:-1}var G=class{constructor(t,e,{index:n,onClick:i}){this.view=t,this.grip=e,this.index=n,this.onClick=i,this.shell=t.dom.parentElement,this.line=document.createElement("div"),this.line.className="blockeditor-drop",this.line.hidden=!0,this.line.setAttribute("aria-hidden","true"),this.shell.append(this.line),this.state=null,this.onMove=o=>this.move(o),this.onUp=o=>this.end(o),this.onCancel=o=>{o.pointerId===this.state?.pointer&&this.cancel()},this.onKey=o=>{o.key==="Escape"&&this.state?.active&&(o.preventDefault(),o.stopPropagation(),this.cancel())},this.onOther=o=>{this.state&&o.pointerId!==this.state.pointer&&this.cancel()},this.onBlur=()=>this.cancel(),this.onScroll=()=>{this.state&&!this.state.active&&this.stop()},e.addEventListener("pointerdown",o=>this.start(o))}start(t){if(t.button!==0||this.state)return;let e=this.view.state,n=g(e.doc),i=e.selection,o=Math.min(this.index(),n.length-1),r=i instanceof C&&n[o].at>=i.from&&n[o].end<=i.to,{lo:c,hi:d}=r?i.span(e.doc):I(n,o,o);if(this.state={index:o,span:R(n,c,d),touch:t.pointerType==="touch",pointer:t.pointerId,x0:t.clientX,y0:t.clientY,x:t.clientX,y:t.clientY,hold:0,active:!1,raf:0,gap:void 0,targets:[],target:null},this.grip.setPointerCapture?.(t.pointerId),this.grip.addEventListener("pointermove",this.onMove),this.grip.addEventListener("pointerup",this.onUp),this.grip.addEventListener("pointercancel",this.onCancel),this.grip.addEventListener("lostpointercapture",this.onCancel),this.state.touch){let h=this.state;h.hold=setTimeout(()=>this.held(h),tt),window.addEventListener("pointerdown",this.onOther,!0),window.addEventListener("blur",this.onBlur),window.addEventListener("scroll",this.onScroll,!0)}t.preventDefault()}held(t){if(!(this.state!==t||t.active)){if(t.hold=0,Math.hypot(t.x-t.x0,t.y-t.y0)>V||!this.view.editable)return this.stop();this.begin()}}move(t){let e=this.state;if(!(!e||t.pointerId!==e.pointer)){if(e.x=t.clientX,e.y=t.clientY,e.touch&&!this.view.editable)return e.active?this.cancel():this.stop();if(!e.active){let n=Math.hypot(e.x-e.x0,e.y-e.y0);if(e.touch){n>V&&this.stop();return}if(n<=Z)return;this.begin()}this.track()}}begin(){let t=this.state;if(!t||t.active)return;let e=this.view.state,n=g(e.doc),i=k(n,t.span);if(!i)return this.cancel();t.active=!0,this.view.dispatch(e.tr.setSelection(X(e.doc,i.lo,i.hi))),this.shell.classList.add("is-dragging");let o=this.shell.appendChild(document.createElement("div"));o.style.cssText="position:absolute;visibility:hidden;width:var(--blockeditor-indent)",this.indentPx=o.getBoundingClientRect().width||27,o.remove(),this.scroller=et(this.view.dom),window.addEventListener("keydown",this.onKey,!0),this.loop(),this.track()}track(){let t=this.state,e=this.view,n=e.state;if(!t)return;let i=g(n.doc),o=k(i,t.span);if(!o)return this.cancel();let{lo:r,hi:c}=o,d=nt(i,e),h=it(d,t.y),a=-1,l=null,p=null,E=h<0?d.length:h+1;for(let x=Math.max(0,E-2);x<E;x++){let v=d[x].dom.getBoundingClientRect();t.y>=v.top+v.height/4&&t.y<=v.bottom-v.height/4&&(p={i:d[x].i,bottom:v.bottom}),l=v.bottom+2}h>=0&&(a=d[h].i,l=d[h].dom.getBoundingClientRect().top-2);let f=r<0?null:p&&q(n,i,r,c,p.i),u=f?`summary:${p.i}`:a;(u!==t.gap||n.doc!==t.doc)&&(t.gap=u,t.doc=n.doc,t.targets=r<0?[]:f?[f]:U(n,i,r,c,a)),f&&(l=p.bottom+2);let m=e.dom.getBoundingClientRect().left;t.target=z(t.targets,(t.x-m)/this.indentPx);let T=this.shell.getBoundingClientRect();if(!t.target||l===null){this.line.hidden=!0,this.shell.dataset.drop="none";return}this.shell.dataset.drop="ok",this.line.hidden=!1,this.line.style.setProperty("--blockeditor-drop-y",`${l-T.top}px`),this.line.style.setProperty("--blockeditor-drop-x",`${m-T.left+t.target.depth*this.indentPx}px`),this.line.style.setProperty("--blockeditor-drop-w",`${e.dom.getBoundingClientRect().right-m-t.target.depth*this.indentPx}px`)}loop(){let t=()=>{let e=this.state;if(!e?.active)return;if(e.touch&&!this.view.editable)return this.cancel();let n=this.scroller,i=n===n.ownerDocument.scrollingElement?{top:0,bottom:window.innerHeight}:n.getBoundingClientRect(),o=0;e.y<i.top+b?o=-W*Math.min(1,(i.top+b-e.y)/b):e.y>i.bottom-b&&(o=W*Math.min(1,(e.y-(i.bottom-b))/b)),o&&(n.scrollTop+=o,this.track()),e.raf=requestAnimationFrame(t)};this.state.raf=requestAnimationFrame(t)}end(t){let e=this.state;if(!e||t.pointerId!==e.pointer)return;if(!e.active){if(this.stop(),t.type==="pointerup"){let l=g(this.view.state.doc),p=k(l,e.span);p&&this.onClick(p.lo)}return}if(this.track(),this.state!==e)return;let n=e.target,i=this.view.state,o=g(i.doc),r=k(o,e.span);if(this.stop(),!n||!r)return;let{lo:c,hi:d}=r;if(!n.open&&(n.at===o[c].at||n.at===o[d].end)&&n.parent===(o[c].node.attrs.parent??null)&&(o[c].node.type.name!=="list_item"||n.indent===o[c].node.attrs.indent))return;if(this.view.dispatch(H(P(i,o,c,d,n)).scrollIntoView()),this.view.state.doc===i.doc)return M(this.view,"Move cancelled");let a=d-c+1;M(this.view,`Moved ${a} ${a===1?"block":"blocks"}`),this.view.focus()}cancel(){this.stop(),M(this.view,"Move cancelled")}stop(){let t=this.state;t&&(this.state=null,clearTimeout(t.hold),cancelAnimationFrame(t.raf),this.grip.removeEventListener("pointermove",this.onMove),this.grip.removeEventListener("pointerup",this.onUp),this.grip.removeEventListener("pointercancel",this.onCancel),this.grip.removeEventListener("lostpointercapture",this.onCancel),this.grip.releasePointerCapture?.(t.pointer),window.removeEventListener("pointerdown",this.onOther,!0),window.removeEventListener("blur",this.onBlur),window.removeEventListener("scroll",this.onScroll,!0),window.removeEventListener("keydown",this.onKey,!0),this.shell.classList.remove("is-dragging"),delete this.shell.dataset.drop,this.line.hidden=!0)}destroy(){this.stop(),this.line.remove()}};export{g as a,et as b,G as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./c-BKM46LUJ.js";import{d as h,h as p,w as g}from"./c-
|
|
1
|
+
import{a as d}from"./c-BKM46LUJ.js";import{d as h,h as p,w as g}from"./c-3XGLJAS7.js";import{E as u,X as c,d as m,ea as f}from"./c-OH2FPYSY.js";import{b as l}from"./c-RETTCOWO.js";import"./c-VHNSBD2M.js";var{TextSelection:b}=l;function T(r,t){let e=p(r.state.doc),n=e.findIndex(o=>o.node.attrs.id===t);if(n<0)return h(r,"That link's block is gone"),null;let s=[];for(let o=e[n].up;o>=0;o=e[o].up)e[o].node.type===m.nodes.toggle&&!e[o].open&&s.push(e[o].node.attrs.id);let i=r.state.tr.setSelection(b.create(r.state.doc,e[n].at+1)).setMeta("addToHistory",!1);return r.dispatch(g(i,s).scrollIntoView()),e[n]}var a=class{constructor(t,e){this.node=t,this.view=e,this.doc=e.state.doc;let n=e.dom.ownerDocument;this.dom=n.createElement("div"),this.dom.className="blockeditor-toc",this.dom.contentEditable="false",this.dom.setAttribute("role","group"),this.dom.setAttribute("aria-label","Table of contents"),this.dom.addEventListener("mousedown",s=>{s.target.closest?.("a")&&s.preventDefault()}),this.dom.addEventListener("click",s=>{let i=s.target.closest?.("a");if(!i)return;s.preventDefault();let o=d(i.getAttribute("href"));o!==null&&T(this.view,o)}),this.render()}update(t){return this.node=t,this.view.state.doc!==this.doc&&(this.doc=this.view.state.doc,this.render()),!0}render(){let t=c(this.node.attrs,f(u(this.doc)));this.dom.innerHTML!==t&&(this.dom.innerHTML=t)}stopEvent(t){return!!t.target.closest?.("a")}ignoreMutation(){return!0}};function I(){return{id:"toc",nodeViews:{toc:(r,t)=>new a(r,t)},css:null,dispose(){}}}export{a as TocView,I as createFeature,T as followTocLink};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as M,g as _,h as A,w as q}from"./c-LUBZU4AZ.js";import{C as G}from"./c-3Y234AUB.js";import{A as B,D as R,Q as j,R as U,d as p,ea as F,u as O,x as $,z as y}from"./c-OH2FPYSY.js";import{b as z}from"./c-RETTCOWO.js";import{a as x}from"./c-JC4RZW4E.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function k(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),o=s.filter(a=>a!==s[0]&&i[a]==="number");return o.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:o,title:"",highlight:null}:null}function gt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,o=e.maybeChild(e.resolve(i).index(0)),a=Q(s,$(s.attrs.pos,o?.attrs.pos??null),s.attrs.parent);return a?(D.add(a.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(a))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!k(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let o=0;for(let b=0;b<t;b++)o+=i.doc.child(b).nodeSize;let a=i.doc.child(t),c=a.isTextblock&&a.content.size===0,h=i.doc.maybeChild(t+1),f=c?a.attrs.pos:$(a.attrs.pos,h?.attrs.pos??null),d=Q(e,f,a.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let g=p.nodes.chart.create(d);return i=c?i.replaceWith(o,o+a.nodeSize,g):i.insert(o+a.nodeSize,g),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function wt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,o=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,o,s.map(a=>({label:A(i,a.attrs.id)??"",description:`${a.childCount} ${a.childCount===1?"row":"rows"} \xB7 ${X(a)}`,icon:"\u25A6",run:()=>W(n,t,a,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function ot(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(o=>e[o]!=="number")??t[0],i=t.filter(o=>o!==s&&e[o]==="number");return{x:s,series:i.length?i:t.filter(o=>o!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","blockeditor-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="blockeditor-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","blockeditor-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","blockeditor-chart-title"),this.chip=l(i,"button","blockeditor-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","blockeditor-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","blockeditor-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","blockeditor-chart-plot"),this.broken=l(i,"div","blockeditor-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",o=>this.brokenClick(o)),this.panel=l(i,"div","blockeditor-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",o=>this.panelClick(o)),this.panel.addEventListener("change",o=>this.panelChange(o)),this.panel.addEventListener("mousedown",o=>{o.target.closest?.("button")&&o.preventDefault()}),this.outside=o=>{!this.panel.isConnected||this.dom.contains(o.target)||(this.commitTitle(),this.closePanel())},this.escape=o=>{!this.panel.isConnected||o.key!=="Escape"||(o.preventDefault(),o.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=k(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let o=this.doc;this.broken.textContent="",this.broken.append(l(o,"div","blockeditor-chart-broken-head","This chart's table was deleted"),l(o,"p","blockeditor-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let a=l(o,"div","blockeditor-chart-broken-actions");if(s.length){let h=T(o,"rescue","Source table");for(let d of s)h.append(C(o,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(o,"button","blockeditor-chart-use","Use this table");f.type="button",f.dataset.action="use",a.append(h,f)}let c=l(o,"button","blockeditor-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",a.append(c),this.broken.append(a)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!k(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","blockeditor-chart-row");return t&&s.append(l(this.doc,"span","blockeditor-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(k(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let o=[...this.panel.querySelectorAll("button, input, select")].find(a=>["field","kind","col","action"].every(c=>a.dataset[c]===e[c]));if(!o)return this.panel.focus();o.focus(),i&&o===this.titleInput&&o.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],o=s?.rows??[],a=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","blockeditor-chart-types");for(let[r,P]of st){let m=l(t,"button","blockeditor-chart-type",P);m.type="button",m.dataset.kind=r,m.setAttribute("aria-pressed",String(e.kind===r)),c.append(m)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let r of E(this.view.state.doc))h.append(C(t,r.id,`${r.name} (${r.rows} ${r.rows===1?"row":"rows"})`,r.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let r of i)f.append(C(t,r.id,r.name||r.id,r.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","blockeditor-chart-values");i.filter(r=>r.id!==e.x).forEach((r,P)=>{let m=l(t,"label","blockeditor-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=r.id,v.checked=e.series.includes(r.id);let I=l(t,"span","blockeditor-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),m.append(v,I,l(t,"span","blockeditor-chart-value-name",r.name||r.id)),d.append(m)});let g=this.row(a?"Value column":"Value columns",d);a&&g.append(l(t,"span","blockeditor-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(g);let b=T(t,"highlight","Highlight row");b.append(C(t,"","None",!e.highlight));for(let r of o)b.append(C(t,r.id,O(r.cells?.[e.x])||r.id,r.id===e.highlight));this.panel.append(this.row("Highlight row",b));let u=l(t,"input","blockeditor-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&(r.preventDefault(),r.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","blockeditor-chart-foot"),w=l(t,"button","blockeditor-chart-remove");w.type="button",w.dataset.action="remove",w.innerHTML=et,w.append("Remove");let L=l(t,"button","blockeditor-chart-done","Done");L.type="button",L.dataset.action="done",H.append(w,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=k(this.view.state.doc,t),s=e?ot(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=k(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".blockeditor-chart-head, .blockeditor-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{gt as a,X as b,wt as c,Y as d,vt as e};
|
|
1
|
+
import{c as M,g as _,h as A,x as q}from"./c-WHMZCRQD.js";import{C as G}from"./c-3XGLJAS7.js";import{A as B,D as R,Q as j,R as U,d as p,ea as F,u as O,x as $,z as y}from"./c-OH2FPYSY.js";import{b as z}from"./c-RETTCOWO.js";import{a as x}from"./c-JC4RZW4E.js";import{a as K}from"./c-I2SCCUEW.js";var{TextSelection:J}=z,S=new WeakMap,D=new Set;function k(n,t){let e=null;return n.forEach(s=>{s.type===p.nodes.table&&s.attrs.id===t&&(e=s)}),e}function N(n){return n?F({[n.attrs.id]:R(n)})[0]:null}function Q(n,t,e){let s=y(n.attrs.cols);if(!s.length)return null;let i=M(n),o=s.filter(a=>a!==s[0]&&i[a]==="number");return o.length?{id:B(),pos:t,parent:e,source:n.attrs.id,kind:"bar",x:s[0],series:o,title:"",highlight:null}:null}function gt(n,t){let e=n.state.doc,s=e.nodeAt(t);if(s?.type!==p.nodes.table)return!1;let i=t+s.nodeSize,o=e.maybeChild(e.resolve(i).index(0)),a=Q(s,$(s.attrs.pos,o?.attrs.pos??null),s.attrs.parent);return a?(D.add(a.id),n.dispatch(n.state.tr.insert(i,p.nodes.chart.create(a))),!0):(x("This table has no number column to chart yet."),!0)}function W(n,t,e,s){let i=n.state.tr;if(s&&i.delete(s.from,s.to),!k(i.doc,e.attrs.id)||t>=i.doc.childCount)return!1;let o=0;for(let b=0;b<t;b++)o+=i.doc.child(b).nodeSize;let a=i.doc.child(t),c=a.isTextblock&&a.content.size===0,h=i.doc.maybeChild(t+1),f=c?a.attrs.pos:$(a.attrs.pos,h?.attrs.pos??null),d=Q(e,f,a.attrs.parent??null);if(!d)return s&&n.dispatch(n.state.tr.delete(s.from,s.to)),x("This table has no number column to chart yet."),!0;let g=p.nodes.chart.create(d);return i=c?i.replaceWith(o,o+a.nodeSize,g):i.insert(o+a.nodeSize,g),D.add(d.id),n.dispatch(i.scrollIntoView()),!0}var X=n=>y(n.attrs.cols).map(t=>n.attrs.cols[t].name||"Untitled").join(", ");function wt(n,t,e=null){let s=_(n.state.doc);if(!s.length)return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),x("Add a table first: a chart plots the numbers in a table on this page."),!0;if(s.length===1)return W(n,t,s[0],e);let i=n.state.doc,o=n.nodeDOM(i.resolve(n.state.selection.head).before(1))??n.dom;return q(n,o,s.map(a=>({label:A(i,a.attrs.id)??"",description:`${a.childCount} ${a.childCount===1?"row":"rows"} \xB7 ${X(a)}`,icon:"\u25A6",run:()=>W(n,t,a,e)})))}var V=n=>`<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,Z=V('<rect x="2.5" y="3" width="11" height="10" rx="1.5"/><path d="M2.5 6.5h11M6 6.5V13"/>'),tt=V('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),et=V('<path d="M2.75 4.5h10.5M6.25 4.5V2.75h3.5V4.5M4.25 4.5l.6 8.75h6.3l.6-8.75"/>'),st=[["bar","Bar"],["line","Line"],["pie","Pie"]],it="Untitled chart";function nt(n,t){let e=null;return n.forEach((s,i)=>{e===null&&s.type===p.nodes.table&&s.attrs.id===t&&(e=i)}),e}function E(n){let t=[];return n.forEach(e=>{e.type===p.nodes.table&&y(e.attrs.cols).length>1&&t.push(e)}),t.map(e=>({id:e.attrs.id,name:A(n,e.attrs.id),rows:e.childCount}))}function ot(n){let t=y(n.attrs.cols);if(!t.length)return null;let e=M(n),s=t.find(o=>e[o]!=="number")??t[0],i=t.filter(o=>o!==s&&e[o]==="number");return{x:s,series:i.length?i:t.filter(o=>o!==s).slice(0,1)}}function l(n,t,e,s=null){let i=n.createElement(t);return e&&(i.className=e),s!==null&&(i.textContent=s),i}function C(n,t,e,s=!1){let i=l(n,"option","",e);return i.value=t,i.selected=s,i}function T(n,t,e){let s=l(n,"select","blockeditor-chart-select");return s.dataset.field=t,s.setAttribute("aria-label",e),s}var Y=class{constructor(t,e,s){this.node=t,this.view=e,this.getPos=s,this.source=void 0,this.tables=null,this.frame=null,this.unsaved=null,this.titleInput=null;let i=e.dom.ownerDocument;this.doc=i,this.dom=i.createElement("figure"),this.dom.className="blockeditor-chart",this.dom.dataset.id=t.attrs.id??"",this.dom.dataset.type="chart",this.head=l(i,"div","blockeditor-chart-head"),this.head.contentEditable="false",this.title=l(i,"span","blockeditor-chart-title"),this.chip=l(i,"button","blockeditor-chart-source"),this.chip.type="button",this.chip.contentEditable="false",this.chip.setAttribute("aria-label","Go to source table"),this.chip.innerHTML=Z,this.chipName=l(i,"span","blockeditor-chart-source-name"),this.chip.append(this.chipName),this.chip.addEventListener("click",()=>this.goToSource()),this.edit=l(i,"button","blockeditor-chart-edit"),this.edit.type="button",this.edit.contentEditable="false",this.edit.setAttribute("aria-haspopup","dialog"),this.edit.setAttribute("aria-expanded","false"),this.edit.innerHTML=tt,this.edit.append("Edit chart"),this.edit.addEventListener("click",()=>this.panel.isConnected?this.closePanel(!0):this.openPanel()),this.head.append(this.title,this.chip,this.edit),this.plot=l(i,"div","blockeditor-chart-plot"),this.broken=l(i,"div","blockeditor-chart-broken"),this.broken.hidden=!0,this.broken.contentEditable="false",this.brokenKey=null,this.brokenSelect=null,this.broken.addEventListener("click",o=>this.brokenClick(o)),this.panel=l(i,"div","blockeditor-chart-panel"),this.panel.tabIndex=-1,this.panel.contentEditable="false",this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Chart settings"),this.panel.addEventListener("click",o=>this.panelClick(o)),this.panel.addEventListener("change",o=>this.panelChange(o)),this.panel.addEventListener("mousedown",o=>{o.target.closest?.("button")&&o.preventDefault()}),this.outside=o=>{!this.panel.isConnected||this.dom.contains(o.target)||(this.commitTitle(),this.closePanel())},this.escape=o=>{!this.panel.isConnected||o.key!=="Escape"||(o.preventDefault(),o.stopPropagation(),this.closePanel(!0))},i.addEventListener("mousedown",this.outside,!0),i.addEventListener("keydown",this.escape,!0),this.dom.append(this.head,this.plot,this.broken),S.has(e)||S.set(e,new Set),S.get(e).add(this),this.refresh(),D.delete(t.attrs.id)&&this.openSoon()}refresh(){this.renderHead(),this.panel.isConnected&&this.panelKey()!==this.renderedKey&&this.redrawPanel();let t=this.view.state.doc,e=k(t,this.node.attrs.source),s=E(t).map(i=>`${i.id}:${i.name}:${i.rows}`).join("|");e===this.source&&s===this.tables||(this.source=e,this.tables=s,this.schedule())}schedule(){if(this.frame!==null)return;let t=this.dom.ownerDocument.defaultView,e=t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0));this.frame=e(()=>{this.frame=null,this.draw()})}draw(){let t=this.node.attrs,e=j({id:t.id,type:t.kind,x:t.x,series:t.series,title:t.title,highlight:t.highlight},N(this.source));this.plot.innerHTML=U(e,{width:640,height:320,narrow:this.dom.getBoundingClientRect().width<480}),this.renderBroken(e)}renderBroken(t){let e=t.state==="missing"&&t.reason==="table";if(this.plot.hidden=e,this.broken.hidden=!e,!e){this.brokenKey!==null&&(this.broken.textContent="",this.brokenKey=null,this.brokenSelect=null);return}let s=E(this.view.state.doc),i=s.map(h=>`${h.id}:${h.name}:${h.rows}`).join("|");if(this.brokenKey===i)return;this.brokenKey=i,this.brokenSelect=null;let o=this.doc;this.broken.textContent="",this.broken.append(l(o,"div","blockeditor-chart-broken-head","This chart's table was deleted"),l(o,"p","blockeditor-chart-broken-text","Pick another table in this document, or delete the chart. Undo brings the table back."));let a=l(o,"div","blockeditor-chart-broken-actions");if(s.length){let h=T(o,"rescue","Source table");for(let d of s)h.append(C(o,d.id,`${d.name} (${d.rows} ${d.rows===1?"row":"rows"})`));this.brokenSelect=h;let f=l(o,"button","blockeditor-chart-use","Use this table");f.type="button",f.dataset.action="use",a.append(h,f)}let c=l(o,"button","blockeditor-chart-delete","Delete chart");c.type="button",c.dataset.action="delete",a.append(c),this.broken.append(a)}brokenClick(t){let e=t.target.closest?.("button[data-action]");e&&(e.dataset.action==="delete"?this.removeChart():e.dataset.action==="use"&&this.switchSource(this.brokenSelect?.value??""))}openSoon(){let t=this.dom.ownerDocument.defaultView;(t.requestAnimationFrame?.bind(t)??(s=>t.setTimeout(s,0)))(()=>{!this.view.isDestroyed&&this.dom.isConnected&&this.openPanel()})}renderHead(){let t=this.node.attrs,e=A(this.view.state.doc,t.source),s=!k(this.view.state.doc,t.source);this.title.textContent=t.title||it,this.title.classList.toggle("is-empty",!t.title),this.chipName.textContent=s?"No table":e??"",this.chip.disabled=s}setAttrs(t){let e=this.getPos();if(e==null)return;let s=this.view.state.doc.nodeAt(e);s?.type===p.nodes.chart&&this.view.dispatch(this.view.state.tr.setNodeMarkup(e,null,{...s.attrs,...t}))}row(t,...e){let s=l(this.doc,"div","blockeditor-chart-row");return t&&s.append(l(this.doc,"span","blockeditor-chart-label",t)),s.append(...e),s}panelKey(){let t=this.view.state.doc,e=E(t).map(s=>`${s.id}:${s.name}:${s.rows}`).join("|");return JSON.stringify([this.node.attrs,e,N(k(t,this.node.attrs.source))])}redrawPanel(){let t=this.doc.activeElement,e=t&&this.panel.contains(t)?t.dataset??{}:null,s=this.titleInput,i=s&&s.value!==this.renderedTitle?{value:s.value,start:s.selectionStart,end:s.selectionEnd}:null;if(this.renderPanel(),i&&this.titleInput&&(this.titleInput.value=i.value),!e)return;let o=[...this.panel.querySelectorAll("button, input, select")].find(a=>["field","kind","col","action"].every(c=>a.dataset[c]===e[c]));if(!o)return this.panel.focus();o.focus(),i&&o===this.titleInput&&o.setSelectionRange?.(i.start,i.end)}renderPanel(){let t=this.doc;this.renderedKey=this.panelKey(),this.renderedTitle=this.node.attrs.title??"";let e=this.node.attrs,s=N(this.source),i=s?.cols??[],o=s?.rows??[],a=e.kind==="pie";this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.textContent="";let c=l(t,"div","blockeditor-chart-types");for(let[r,P]of st){let m=l(t,"button","blockeditor-chart-type",P);m.type="button",m.dataset.kind=r,m.setAttribute("aria-pressed",String(e.kind===r)),c.append(m)}this.panel.append(this.row("Chart type",c));let h=T(t,"source","Source table");for(let r of E(this.view.state.doc))h.append(C(t,r.id,`${r.name} (${r.rows} ${r.rows===1?"row":"rows"})`,r.id===e.source));this.panel.append(this.row("Source table",h));let f=T(t,"labels","Labels column");for(let r of i)f.append(C(t,r.id,r.name||r.id,r.id===e.x));this.panel.append(this.row("Labels column",f));let d=l(t,"div","blockeditor-chart-values");i.filter(r=>r.id!==e.x).forEach((r,P)=>{let m=l(t,"label","blockeditor-chart-value"),v=l(t,"input");v.type="checkbox",v.dataset.field="series",v.dataset.col=r.id,v.checked=e.series.includes(r.id);let I=l(t,"span","blockeditor-chart-swatch");I.style.background=`var(--chart-${P%6+1})`,I.setAttribute("aria-hidden","true"),m.append(v,I,l(t,"span","blockeditor-chart-value-name",r.name||r.id)),d.append(m)});let g=this.row(a?"Value column":"Value columns",d);a&&g.append(l(t,"span","blockeditor-chart-hint","Pie charts plot the first value column across rows.")),this.panel.append(g);let b=T(t,"highlight","Highlight row");b.append(C(t,"","None",!e.highlight));for(let r of o)b.append(C(t,r.id,O(r.cells?.[e.x])||r.id,r.id===e.highlight));this.panel.append(this.row("Highlight row",b));let u=l(t,"input","blockeditor-chart-title-input");u.type="text",u.dataset.field="title",u.setAttribute("aria-label","Chart title"),u.value=e.title??"",u.addEventListener("keydown",r=>{r.isComposing||r.keyCode===229||r.key==="Enter"&&(r.preventDefault(),r.stopPropagation(),this.commitTitle())}),u.addEventListener("change",()=>this.commitTitle()),u.addEventListener("blur",()=>this.commitTitle()),this.titleInput=u,this.panel.append(this.row("Chart title",u));let H=l(t,"div","blockeditor-chart-foot"),w=l(t,"button","blockeditor-chart-remove");w.type="button",w.dataset.action="remove",w.innerHTML=et,w.append("Remove");let L=l(t,"button","blockeditor-chart-done","Done");L.type="button",L.dataset.action="done",H.append(w,L),this.panel.append(H),this.unsaved=K({id:"chart-title",isPending:()=>u.isConnected&&u.value!==(this.node.attrs.title??"")})}openPanel(){this.panel.isConnected||(this.renderPanel(),this.dom.append(this.panel),this.edit.setAttribute("aria-expanded","true"),this.panel.focus())}closePanel(t=!1){this.panel.isConnected&&(this.unsaved?.dispose(),this.unsaved=null,this.titleInput=null,this.panel.remove(),this.edit.setAttribute("aria-expanded","false"),t&&this.edit.focus())}panelClick(t){let e=t.target.closest?.("button");e&&(e.dataset.action==="done"?(this.commitTitle(),this.closePanel(!0)):e.dataset.action==="remove"?this.removeChart():e.dataset.kind&&this.setAttrs({kind:e.dataset.kind}))}panelChange(t){let e=t.target;if(e?.dataset){if(e.dataset.field==="source")this.switchSource(e.value);else if(e.dataset.field==="labels")this.setAttrs({x:e.value,series:this.node.attrs.series.filter(s=>s!==e.value)});else if(e.dataset.field==="highlight")this.setAttrs({highlight:e.value||null});else if(e.dataset.field==="series"){let s=this.node.attrs.series.filter(i=>i!==e.dataset.col);this.setAttrs({series:e.checked?[...s,e.dataset.col]:s})}}}switchSource(t){let e=k(this.view.state.doc,t),s=e?ot(e):null;s&&this.setAttrs({source:t,x:s.x,series:s.series})}commitTitle(){let t=this.titleInput;!t||t.value===(this.node.attrs.title??"")||this.setAttrs({title:t.value})}goToSource(){let t=this.view.state.doc,e=nt(t,this.node.attrs.source),s=e===null?null:t.nodeAt(e);if(!s?.childCount||!s.child(0).childCount)return;let i=e+3;this.view.dispatch(this.view.state.tr.setSelection(J.create(t,i)).scrollIntoView()),this.view.focus?.()}removeChart(){let t=this.getPos();if(t==null)return;let e=this.view.state.doc.nodeAt(t);if(e?.type!==p.nodes.chart)return;this.closePanel();let s=this.view.state.tr.delete(t,t+e.nodeSize);s.setSelection(J.near(s.doc.resolve(Math.min(t,s.doc.content.size)),-1)),this.view.dispatch(G(s).scrollIntoView())}update(t){if(t.type!==p.nodes.chart)return!1;let e=!t.sameMarkup(this.node);return this.node=t,this.dom.dataset.id=t.attrs.id??"",e&&(this.source=k(this.view.state.doc,t.attrs.source),this.renderHead(),this.schedule()),!0}stopEvent(t){return!!t.target.closest?.(".blockeditor-chart-head, .blockeditor-chart-panel")}destroy(){if(this.unsaved?.dispose(),this.unsaved=null,this.doc.removeEventListener("mousedown",this.outside,!0),this.doc.removeEventListener("keydown",this.escape,!0),S.get(this.view)?.delete(this),this.frame!==null){let t=this.dom.ownerDocument.defaultView;t.cancelAnimationFrame?t.cancelAnimationFrame(this.frame):t.clearTimeout(this.frame)}}};function vt(n){for(let t of S.get(n)??[])t.refresh()}export{gt as a,X as b,wt as c,Y as d,vt as e};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as me,b as pe,c as he}from"./c-SIM7Z3U7.js";import{a as de,b as fe}from"./c-OYW5MFPZ.js";import{a as F,b as U,c as ue}from"./c-H3FNLBHN.js";import{C as X,E as le,h as z,l as ce,m as Y}from"./c-3Y234AUB.js";import{A as se,d as N,x as oe}from"./c-OH2FPYSY.js";import"./c-VPXCXBDT.js";import{b as $,c as ae,d as R}from"./c-Z6MROEQ4.js";import{b as ie}from"./c-Q26XHBLQ.js";import{a as H,b as V}from"./c-RETTCOWO.js";import{a as re}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var ge=16384,we=i=>new TextEncoder().encode(JSON.stringify(i)).length,G=class extends Error{constructor(n,t=n){super(t),this.name="ToolRequestError",this.code=n}};function Oe(i){let n=re(i);for(Array.isArray(n.tables)||(n.tables=[]),Array.isArray(n.outline)||(n.outline=[]);we(n)>ge;){let t=[...n.tables].reverse().find(r=>Array.isArray(r.rows)&&r.rows.length);if(t)t.rows.pop();else if(n.outline.length)n.outline.pop();else break}if(we(n)>ge)throw new G("context-too-large");return n}var Me=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function ve({transport:i,newId:n=Me}){let t=null,r=s=>{!s||s.discarded||s.done||(s.discarded=!0,t===s&&(t=null),i.cancel(s.requestId),s.resolve({requestId:s.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(s,a,v=null,h=null){let o=Oe(a);t&&r(t);let m=n(),l={requestId:m,discarded:!1,done:!1};l.promise=new Promise(u=>{l.resolve=u}),t=l;let e={protocol:"blockeditor-tool/1",requestId:m,prompt:s,context:o,target:v,current:h};l.request=e;let f=u=>{if(!(l.discarded||l.done||u?.requestId!==m))if(l.done=!0,t===l&&(t=null),u?.artifact!==void 0){let g=F(u.artifact),d=U(u.state),p=g.ok?d.ok?null:d:g;l.resolve(p?{requestId:m,code:p.code,message:p.code}:u)}else l.resolve(typeof u?.code=="string"?u:{requestId:m,code:"invalid-result",message:"invalid-result"})};try{let u=g=>f({requestId:m,code:typeof g?.code=="string"?g.code:"transport-error",message:String(g?.message??g)});Promise.resolve(i.request(e)).then(f,u)}catch(u){f({requestId:m,code:typeof u?.code=="string"?u.code:"transport-error",message:String(u?.message??u)})}return l},discard:r,async wait(s,{signal:a}={}){if(a?.aborted)throw new DOMException("Aborted","AbortError");let v,h=await(a?Promise.race([s.promise,new Promise((o,m)=>{v=()=>m(new DOMException("Aborted","AbortError")),a.addEventListener("abort",v,{once:!0})})]).finally(()=>a.removeEventListener("abort",v)):s.promise);if(h?.code)throw new G(h.code,h.message);return h}}}var J=class extends Error{constructor(n){super(n),this.name="ToolTransportError",this.code=n}};function ye({getWire:i=()=>globalThis.window?.clay?.wire??null}={}){let n=new Map;return{request(t,{onStatus:r=null}={}){let s=i();if(!s||typeof s.send!="function")return Promise.reject(new J("no-wire"));let a=t?.requestId,v;try{v=s.send(t,{helper:"blockeditor-tool",document:"none",id:a,onStatus:r})}catch{return Promise.reject(new J("no-wire"))}return n.set(a,v),Promise.resolve(v.done).then(h=>{if(n.get(a)===v&&n.delete(a),h?.state==="done"){let o=h.result??{};return{requestId:typeof o.requestId=="string"?o.requestId:a,artifact:o.artifact,state:o.state,model:o.model}}return{requestId:a,code:h?.errorCode||(h?.state==="cancelled"?"cancelled":"transport-error"),message:h?.error||"the helper reported an error"}},()=>({requestId:a,code:"transport-error",message:"the helper reported an error"}))},cancel(t){let r=n.get(t);n.delete(t),r?.cancel?.()}}}var{Selection:Be}=V,W="This page is not open for editing any more.",Ie="AI tool making isn't available on this page right now.",Te="This document can't save tool data.",K="The place for this tool moved. Close this and run /ai where you want the tool.",be="This tool changed while you were revising, so nothing was replaced. Ask again.",Q="AI did not make a usable tool. Try again.",Ne="The tool data from AI is too large or not usable. Try again.",xe="This tool's data changed while AI was working, so it was not replaced. Ask again to include the latest data.",Ae="The tool could not be saved, so it was not added. Try again.",Re="Your tool is in the document, but saving failed. It will be saved with your next edit.";function _(i,n){let t=null;return i.forEach((r,s,a)=>{r.attrs.id===n&&(t={node:r,at:s,index:a})}),t}function Pe(i,n){let t=i.selection.$head,r=Math.min(Math.max(t.index(0),0),i.doc.childCount-1);return{hostId:i.doc.child(r)?.attrs.id??null,slashText:n?i.doc.textBetween(n.from,n.to):null,slashOffset:n&&t.depth?n.from-t.before(1)-1:null}}function Z(i,n){let t=n?.hostId?_(i.doc,n.hostId):null;if(!t)return null;let r=i.doc.maybeChild(t.index+1),s=t.node.isTextblock&&(t.node.content.size===0||t.node.textContent===n.slashText);return{...t,replace:s,pos:s?t.node.attrs.pos:oe(t.node.attrs.pos,r?.attrs.pos??null),insertAt:s?t.at:t.at+t.node.nodeSize}}function _e(i,n,t){let r=i.state,s=Z(r,t);if(!s)return!1;let{node:a,at:v,insertAt:h,replace:o}=s,m=N.nodes.tool.create({id:n.id,pos:s.pos,parent:a.attrs.parent??null,artifact:n.artifact,rev:n.rev,state:n.state}),l=r.tr;if(!o&&t?.hostId===a.attrs.id&&t.slashText&&t.slashOffset>=0){let f=v+1+t.slashOffset,u=f+t.slashText.length;u<=v+a.nodeSize-1&&r.doc.textBetween(f,u)===t.slashText&&l.delete(f,u)}let e=l.mapping.map(h);return l.replaceWith(e,o?l.mapping.map(v+a.nodeSize):e,m),l.setSelection(Be.near(l.doc.resolve(Math.min(e+m.nodeSize,l.doc.content.size)))),i.dispatch(X(l).scrollIntoView()),!0}var Se=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Ee({getView:i,store:n=()=>null,acceptState:t=()=>globalThis.clay?.save?.flush?.(),newId:r=se,transport:s=ye()}={}){let a=()=>{let e=i();return e&&!e.isDestroyed?e:null},v=()=>typeof n=="function"?n():n,h=(e,f)=>{let u=v()?.data?.[e]?.[f];return u===void 0?{}:u},o=new Map,m=e=>Array.isArray(e)?`[${e.map(m).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(u=>`${JSON.stringify(u)}:${m(e[u])}`).join(",")}}`:JSON.stringify(e)??"null";function l(e=null,f=null){let u=a(),g=e||!u?null:Pe(u.state,f),d=null,p=ve({transport:{request:c=>s.request(c,{onStatus:T=>d?.(T)}),cancel:c=>s.cancel(c)}}),b=null,w=null,y=null,M=!1,k=null,O=null,C=()=>{y?.host?.dispose(),y=null},L=()=>{let c=a();return c&&e?ie.get(c)?.get(e)??null:null},j=()=>L()?.suspend(),B=()=>L()?.resume(),q=c=>{M=!1;let T=a();return C(),T&&R(T),B(),{status:"failed",message:c}},ne={aiTarget:!0,label:e?"This tool":"New tool",ref:e?[e]:[],placeholder:e?"What should change?":"Describe the tool",get isConnected(){let c=a();return c?e?!!_(c.state.doc,e):!0:!1},getBoundingClientRect(){let c=a();if(!c)return Se();if(y)return y.dom.getBoundingClientRect();let T=e??g?.hostId,A=T?_(c.state.doc,T):null,E=A?c.nodeDOM(A.at):null;return E&&typeof E.getBoundingClientRect=="function"?E.getBoundingClientRect():Se()},async start(c){w=null,M=!1;let T=a();if(!T)return{status:"refused",code:"gone",message:W};if(!globalThis.window?.clay?.wire)return{status:"refused",code:"no-wire",message:Ie};let A=null,E=null;if(e){let x=_(T.state.doc,e);if(x?.node.type!==N.nodes.tool)return{status:"refused",code:"gone",message:W};k=x.node.attrs.rev,A={toolId:e,rev:k},j(),E={artifact:x.node.attrs.artifact,state:h(e,k)},O=m(E.state)}return b=p.request(c,fe(T.state.doc,T.dom.ownerDocument.title),A,E),{status:"ok",id:b.requestId,send:(x={})=>(d=typeof x.onStatus=="function"?x.onStatus:null,{done:p.wait(b).then(S=>(w={id:e,rev:null,artifact:S.artifact,state:S.state},{state:"done",result:S}),S=>(B(),{state:"error",error:S?.message||S?.code||"the helper reported an error",code:S?.code??null})),cancel:()=>{B(),p.discard(b)}})}},async propose(c){let T=a();if(!T||!c)return{status:"refused",message:W};if(!F(c.artifact).ok)return{status:"refused",message:Q};if(!U(c.state).ok)return{status:"refused",message:Ne};w={id:e,rev:null,artifact:c.artifact,state:c.state};let x=De(T);return x.status!=="ready"&&(w=null),x},async keep(){if(!w||M)return q(be);let c=a();if(!c)return q(W);let T=v();if(!T)return q(Te);let A=()=>e&&O!==null&&m(h(e,k))!==O;if(A())return q(xe);M=!0;let E=w.id??r("b"),x=r("rev"),I={...w,id:E,rev:x};try{await T.set([E,x],I.state)}catch(D){return q(D?.message??Te)}let S=null;try{S=await t()}catch{return q(Ae)}if(S?.ok!==!0&&!["saved","clean"].includes(S?.state))return q(S?.msg??S?.message??Ae);if(e){let D=_(c.state.doc,e);if(D?.node.type!==N.nodes.tool||D.node.attrs.rev!==k)return q(be)}else if(!Z(c.state,g))return q(K);if(A())return q(xe);if(C(),R(c),e){let D=_(c.state.doc,e);c.dispatch(X(c.state.tr.setNodeMarkup(D.at,null,{...D.node.attrs,artifact:I.artifact,rev:I.rev})))}else if(!_e(c,I,g))return q(K);let P=!1;for(let D=0;D<2&&!P;D++)try{P=(await t())?.ok!==!1}catch{P=!1}return P?(o.delete(e??"new"),{status:"kept"}):{status:"failed",message:Re}},discard(){C();let c=a();c&&R(c),p.discard(b),B(),o.delete(e??"new")}};function De(c){C();let T=ue({mode:"view",tables:()=>de(c.state.doc).map(({id:I,cols:S,rows:P})=>({id:I,cols:S,rows:P}))}),A=c.dom.ownerDocument.createElement("div");A.className="blockeditor-ai-preview";let E=null;try{E=T.mount(A,{id:"preview",rev:"preview",artifact:w.artifact,seed:w.state})}catch{return T.dispose(),{status:"refused",message:Q}}if(E.failed)return T.dispose(),{status:"refused",message:Q};if(y={host:T,dom:A},e)return $(c,{ids:[e],dom:A}),{status:"ready"};let x=Z(c.state,g);return x?(x.replace?$(c,{ids:[x.node.attrs.id],dom:A}):ae(c,{at:x.insertAt,dom:A}),{status:"ready"}):(C(),{status:"refused",message:K})}return e&&o.set(e,ne),ne}return{newTool(e=null){return l(null,e)},reviseTool(e){let f=o.get(e);return f?.isConnected?f:(o.delete(e),l(e))}}}var{TextSelection:$e}=V,ze="ai-edit",Le="page area",je="This section is too large for AI editing. Select a smaller part.",Ce="Someone changed this area while AI was working, so nothing was changed.",Ve="This page is not open for editing any more.",Fe="AI editing isn't available on this page right now.",Ue=0;function te(i,n){let t=null;return i.forEach((r,s)=>{r.attrs?.id===n&&(t={node:r,at:s})}),t}var qe=(i,n)=>te(i,n)?.node?.type===N.nodes.tool,ee=(i,n,t)=>i.slice(n,t+1).map(r=>r.node.attrs.id).filter(Boolean),Ge=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,ke=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Je(i){if(!i.length)return ke();let n=Math.min(...i.map(a=>a.left)),t=Math.min(...i.map(a=>a.top)),r=Math.max(...i.map(a=>a.right)),s=Math.max(...i.map(a=>a.bottom));return{x:n,y:t,left:n,top:t,right:r,bottom:s,width:r-n,height:s-t}}function We(i,n,t){let r=i.selection;if(!(r instanceof $e)||r.empty)return null;let[s,a]=ce(i.doc,r,n);if(s!==a||t.lo!==s||t.hi!==s)return null;let v=n[s];if(r.from<v.at||r.to>v.end)return null;let h=i.doc.textBetween(r.from,r.to," ");if(!h.trim())return null;let o=i.doc.textBetween(v.at+1,r.from," ").length;return{text:h,start:o,end:o+h.length}}function Tt({getView:i,store:n=()=>null,acceptState:t}={}){let r=()=>{let o=i();return o&&!o.isDestroyed?o:null},s=new Map,a=Ee({getView:r,store:n,acceptState:t}),v=o=>a.reviseTool(o);function h(o,{quote:m=null,label:l=null}={}){for(let[d,p]of s)p.isConnected||s.delete(d);let e=s.get(o.join(","));if(e)return e.quote=m??void 0,e;let f=null,u=null,g={aiTarget:!0,label:l??(o.length===1?"This block":`${o.length} blocks`),ref:[...o],get isConnected(){let d=r();return!!d&&o.some(p=>te(d.state.doc,p))},getBoundingClientRect(){let d=r();if(!d)return ke();let p=d.dom.querySelector(".blockeditor-ai-preview");if(p)return p.getBoundingClientRect();let w=[g.ref[0],g.ref[g.ref.length-1]].map(y=>te(d.state.doc,y)).map(y=>y?d.nodeDOM(y.at):null).filter(y=>y&&typeof y.getBoundingClientRect=="function").map(y=>y.getBoundingClientRect());return Je(w)},async start(d,p){let b=r();if(!b)return{status:"refused",code:"gone",message:Ve};let w=window.clay?.wire;if(!w)return{status:"refused",code:"no-wire",message:Fe};let{captureArea:y,AREA_GUIDE:M}=await import("./c-TWB5ZQU4.js"),k=y(b.state.doc,g.ref);if(f=null,u=null,k.status!=="ok")return{status:"refused",code:k.code,message:k.message};let O=p??g.quote,C={id:"req-"+Date.now().toString(36)+"-"+ ++Ue,editId:Le,tag:"div",elementHTML:k.capture.html,comment:d+`
|
|
1
|
+
import{a as me,b as pe,c as he}from"./c-SIM7Z3U7.js";import{a as de,b as fe}from"./c-OYW5MFPZ.js";import{a as F,b as U,c as ue}from"./c-H3FNLBHN.js";import{C as X,E as le,h as z,l as ce,m as Y}from"./c-3XGLJAS7.js";import{A as se,d as N,x as oe}from"./c-OH2FPYSY.js";import"./c-VPXCXBDT.js";import{b as $,c as ae,d as R}from"./c-Z6MROEQ4.js";import{b as ie}from"./c-Q26XHBLQ.js";import{a as H,b as V}from"./c-RETTCOWO.js";import{a as re}from"./c-3LDGIBMN.js";import"./c-VHNSBD2M.js";var ge=16384,we=i=>new TextEncoder().encode(JSON.stringify(i)).length,G=class extends Error{constructor(n,t=n){super(t),this.name="ToolRequestError",this.code=n}};function Oe(i){let n=re(i);for(Array.isArray(n.tables)||(n.tables=[]),Array.isArray(n.outline)||(n.outline=[]);we(n)>ge;){let t=[...n.tables].reverse().find(r=>Array.isArray(r.rows)&&r.rows.length);if(t)t.rows.pop();else if(n.outline.length)n.outline.pop();else break}if(we(n)>ge)throw new G("context-too-large");return n}var Me=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function ve({transport:i,newId:n=Me}){let t=null,r=s=>{!s||s.discarded||s.done||(s.discarded=!0,t===s&&(t=null),i.cancel(s.requestId),s.resolve({requestId:s.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(s,a,v=null,h=null){let o=Oe(a);t&&r(t);let m=n(),l={requestId:m,discarded:!1,done:!1};l.promise=new Promise(u=>{l.resolve=u}),t=l;let e={protocol:"blockeditor-tool/1",requestId:m,prompt:s,context:o,target:v,current:h};l.request=e;let f=u=>{if(!(l.discarded||l.done||u?.requestId!==m))if(l.done=!0,t===l&&(t=null),u?.artifact!==void 0){let g=F(u.artifact),d=U(u.state),p=g.ok?d.ok?null:d:g;l.resolve(p?{requestId:m,code:p.code,message:p.code}:u)}else l.resolve(typeof u?.code=="string"?u:{requestId:m,code:"invalid-result",message:"invalid-result"})};try{let u=g=>f({requestId:m,code:typeof g?.code=="string"?g.code:"transport-error",message:String(g?.message??g)});Promise.resolve(i.request(e)).then(f,u)}catch(u){f({requestId:m,code:typeof u?.code=="string"?u.code:"transport-error",message:String(u?.message??u)})}return l},discard:r,async wait(s,{signal:a}={}){if(a?.aborted)throw new DOMException("Aborted","AbortError");let v,h=await(a?Promise.race([s.promise,new Promise((o,m)=>{v=()=>m(new DOMException("Aborted","AbortError")),a.addEventListener("abort",v,{once:!0})})]).finally(()=>a.removeEventListener("abort",v)):s.promise);if(h?.code)throw new G(h.code,h.message);return h}}}var J=class extends Error{constructor(n){super(n),this.name="ToolTransportError",this.code=n}};function ye({getWire:i=()=>globalThis.window?.clay?.wire??null}={}){let n=new Map;return{request(t,{onStatus:r=null}={}){let s=i();if(!s||typeof s.send!="function")return Promise.reject(new J("no-wire"));let a=t?.requestId,v;try{v=s.send(t,{helper:"blockeditor-tool",document:"none",id:a,onStatus:r})}catch{return Promise.reject(new J("no-wire"))}return n.set(a,v),Promise.resolve(v.done).then(h=>{if(n.get(a)===v&&n.delete(a),h?.state==="done"){let o=h.result??{};return{requestId:typeof o.requestId=="string"?o.requestId:a,artifact:o.artifact,state:o.state,model:o.model}}return{requestId:a,code:h?.errorCode||(h?.state==="cancelled"?"cancelled":"transport-error"),message:h?.error||"the helper reported an error"}},()=>({requestId:a,code:"transport-error",message:"the helper reported an error"}))},cancel(t){let r=n.get(t);n.delete(t),r?.cancel?.()}}}var{Selection:Be}=V,W="This page is not open for editing any more.",Ie="AI tool making isn't available on this page right now.",Te="This document can't save tool data.",K="The place for this tool moved. Close this and run /ai where you want the tool.",be="This tool changed while you were revising, so nothing was replaced. Ask again.",Q="AI did not make a usable tool. Try again.",Ne="The tool data from AI is too large or not usable. Try again.",xe="This tool's data changed while AI was working, so it was not replaced. Ask again to include the latest data.",Ae="The tool could not be saved, so it was not added. Try again.",Re="Your tool is in the document, but saving failed. It will be saved with your next edit.";function _(i,n){let t=null;return i.forEach((r,s,a)=>{r.attrs.id===n&&(t={node:r,at:s,index:a})}),t}function Pe(i,n){let t=i.selection.$head,r=Math.min(Math.max(t.index(0),0),i.doc.childCount-1);return{hostId:i.doc.child(r)?.attrs.id??null,slashText:n?i.doc.textBetween(n.from,n.to):null,slashOffset:n&&t.depth?n.from-t.before(1)-1:null}}function Z(i,n){let t=n?.hostId?_(i.doc,n.hostId):null;if(!t)return null;let r=i.doc.maybeChild(t.index+1),s=t.node.isTextblock&&(t.node.content.size===0||t.node.textContent===n.slashText);return{...t,replace:s,pos:s?t.node.attrs.pos:oe(t.node.attrs.pos,r?.attrs.pos??null),insertAt:s?t.at:t.at+t.node.nodeSize}}function _e(i,n,t){let r=i.state,s=Z(r,t);if(!s)return!1;let{node:a,at:v,insertAt:h,replace:o}=s,m=N.nodes.tool.create({id:n.id,pos:s.pos,parent:a.attrs.parent??null,artifact:n.artifact,rev:n.rev,state:n.state}),l=r.tr;if(!o&&t?.hostId===a.attrs.id&&t.slashText&&t.slashOffset>=0){let f=v+1+t.slashOffset,u=f+t.slashText.length;u<=v+a.nodeSize-1&&r.doc.textBetween(f,u)===t.slashText&&l.delete(f,u)}let e=l.mapping.map(h);return l.replaceWith(e,o?l.mapping.map(v+a.nodeSize):e,m),l.setSelection(Be.near(l.doc.resolve(Math.min(e+m.nodeSize,l.doc.content.size)))),i.dispatch(X(l).scrollIntoView()),!0}var Se=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Ee({getView:i,store:n=()=>null,acceptState:t=()=>globalThis.clay?.save?.flush?.(),newId:r=se,transport:s=ye()}={}){let a=()=>{let e=i();return e&&!e.isDestroyed?e:null},v=()=>typeof n=="function"?n():n,h=(e,f)=>{let u=v()?.data?.[e]?.[f];return u===void 0?{}:u},o=new Map,m=e=>Array.isArray(e)?`[${e.map(m).join(",")}]`:e&&typeof e=="object"?`{${Object.keys(e).sort().map(u=>`${JSON.stringify(u)}:${m(e[u])}`).join(",")}}`:JSON.stringify(e)??"null";function l(e=null,f=null){let u=a(),g=e||!u?null:Pe(u.state,f),d=null,p=ve({transport:{request:c=>s.request(c,{onStatus:T=>d?.(T)}),cancel:c=>s.cancel(c)}}),b=null,w=null,y=null,M=!1,k=null,O=null,C=()=>{y?.host?.dispose(),y=null},L=()=>{let c=a();return c&&e?ie.get(c)?.get(e)??null:null},j=()=>L()?.suspend(),B=()=>L()?.resume(),q=c=>{M=!1;let T=a();return C(),T&&R(T),B(),{status:"failed",message:c}},ne={aiTarget:!0,label:e?"This tool":"New tool",ref:e?[e]:[],placeholder:e?"What should change?":"Describe the tool",get isConnected(){let c=a();return c?e?!!_(c.state.doc,e):!0:!1},getBoundingClientRect(){let c=a();if(!c)return Se();if(y)return y.dom.getBoundingClientRect();let T=e??g?.hostId,A=T?_(c.state.doc,T):null,E=A?c.nodeDOM(A.at):null;return E&&typeof E.getBoundingClientRect=="function"?E.getBoundingClientRect():Se()},async start(c){w=null,M=!1;let T=a();if(!T)return{status:"refused",code:"gone",message:W};if(!globalThis.window?.clay?.wire)return{status:"refused",code:"no-wire",message:Ie};let A=null,E=null;if(e){let x=_(T.state.doc,e);if(x?.node.type!==N.nodes.tool)return{status:"refused",code:"gone",message:W};k=x.node.attrs.rev,A={toolId:e,rev:k},j(),E={artifact:x.node.attrs.artifact,state:h(e,k)},O=m(E.state)}return b=p.request(c,fe(T.state.doc,T.dom.ownerDocument.title),A,E),{status:"ok",id:b.requestId,send:(x={})=>(d=typeof x.onStatus=="function"?x.onStatus:null,{done:p.wait(b).then(S=>(w={id:e,rev:null,artifact:S.artifact,state:S.state},{state:"done",result:S}),S=>(B(),{state:"error",error:S?.message||S?.code||"the helper reported an error",code:S?.code??null})),cancel:()=>{B(),p.discard(b)}})}},async propose(c){let T=a();if(!T||!c)return{status:"refused",message:W};if(!F(c.artifact).ok)return{status:"refused",message:Q};if(!U(c.state).ok)return{status:"refused",message:Ne};w={id:e,rev:null,artifact:c.artifact,state:c.state};let x=De(T);return x.status!=="ready"&&(w=null),x},async keep(){if(!w||M)return q(be);let c=a();if(!c)return q(W);let T=v();if(!T)return q(Te);let A=()=>e&&O!==null&&m(h(e,k))!==O;if(A())return q(xe);M=!0;let E=w.id??r("b"),x=r("rev"),I={...w,id:E,rev:x};try{await T.set([E,x],I.state)}catch(D){return q(D?.message??Te)}let S=null;try{S=await t()}catch{return q(Ae)}if(S?.ok!==!0&&!["saved","clean"].includes(S?.state))return q(S?.msg??S?.message??Ae);if(e){let D=_(c.state.doc,e);if(D?.node.type!==N.nodes.tool||D.node.attrs.rev!==k)return q(be)}else if(!Z(c.state,g))return q(K);if(A())return q(xe);if(C(),R(c),e){let D=_(c.state.doc,e);c.dispatch(X(c.state.tr.setNodeMarkup(D.at,null,{...D.node.attrs,artifact:I.artifact,rev:I.rev})))}else if(!_e(c,I,g))return q(K);let P=!1;for(let D=0;D<2&&!P;D++)try{P=(await t())?.ok!==!1}catch{P=!1}return P?(o.delete(e??"new"),{status:"kept"}):{status:"failed",message:Re}},discard(){C();let c=a();c&&R(c),p.discard(b),B(),o.delete(e??"new")}};function De(c){C();let T=ue({mode:"view",tables:()=>de(c.state.doc).map(({id:I,cols:S,rows:P})=>({id:I,cols:S,rows:P}))}),A=c.dom.ownerDocument.createElement("div");A.className="blockeditor-ai-preview";let E=null;try{E=T.mount(A,{id:"preview",rev:"preview",artifact:w.artifact,seed:w.state})}catch{return T.dispose(),{status:"refused",message:Q}}if(E.failed)return T.dispose(),{status:"refused",message:Q};if(y={host:T,dom:A},e)return $(c,{ids:[e],dom:A}),{status:"ready"};let x=Z(c.state,g);return x?(x.replace?$(c,{ids:[x.node.attrs.id],dom:A}):ae(c,{at:x.insertAt,dom:A}),{status:"ready"}):(C(),{status:"refused",message:K})}return e&&o.set(e,ne),ne}return{newTool(e=null){return l(null,e)},reviseTool(e){let f=o.get(e);return f?.isConnected?f:(o.delete(e),l(e))}}}var{TextSelection:$e}=V,ze="ai-edit",Le="page area",je="This section is too large for AI editing. Select a smaller part.",Ce="Someone changed this area while AI was working, so nothing was changed.",Ve="This page is not open for editing any more.",Fe="AI editing isn't available on this page right now.",Ue=0;function te(i,n){let t=null;return i.forEach((r,s)=>{r.attrs?.id===n&&(t={node:r,at:s})}),t}var qe=(i,n)=>te(i,n)?.node?.type===N.nodes.tool,ee=(i,n,t)=>i.slice(n,t+1).map(r=>r.node.attrs.id).filter(Boolean),Ge=()=>globalThis.crypto?.randomUUID?.()??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,ke=()=>({x:0,y:0,left:0,top:0,right:0,bottom:0,width:0,height:0});function Je(i){if(!i.length)return ke();let n=Math.min(...i.map(a=>a.left)),t=Math.min(...i.map(a=>a.top)),r=Math.max(...i.map(a=>a.right)),s=Math.max(...i.map(a=>a.bottom));return{x:n,y:t,left:n,top:t,right:r,bottom:s,width:r-n,height:s-t}}function We(i,n,t){let r=i.selection;if(!(r instanceof $e)||r.empty)return null;let[s,a]=ce(i.doc,r,n);if(s!==a||t.lo!==s||t.hi!==s)return null;let v=n[s];if(r.from<v.at||r.to>v.end)return null;let h=i.doc.textBetween(r.from,r.to," ");if(!h.trim())return null;let o=i.doc.textBetween(v.at+1,r.from," ").length;return{text:h,start:o,end:o+h.length}}function Tt({getView:i,store:n=()=>null,acceptState:t}={}){let r=()=>{let o=i();return o&&!o.isDestroyed?o:null},s=new Map,a=Ee({getView:r,store:n,acceptState:t}),v=o=>a.reviseTool(o);function h(o,{quote:m=null,label:l=null}={}){for(let[d,p]of s)p.isConnected||s.delete(d);let e=s.get(o.join(","));if(e)return e.quote=m??void 0,e;let f=null,u=null,g={aiTarget:!0,label:l??(o.length===1?"This block":`${o.length} blocks`),ref:[...o],get isConnected(){let d=r();return!!d&&o.some(p=>te(d.state.doc,p))},getBoundingClientRect(){let d=r();if(!d)return ke();let p=d.dom.querySelector(".blockeditor-ai-preview");if(p)return p.getBoundingClientRect();let w=[g.ref[0],g.ref[g.ref.length-1]].map(y=>te(d.state.doc,y)).map(y=>y?d.nodeDOM(y.at):null).filter(y=>y&&typeof y.getBoundingClientRect=="function").map(y=>y.getBoundingClientRect());return Je(w)},async start(d,p){let b=r();if(!b)return{status:"refused",code:"gone",message:Ve};let w=window.clay?.wire;if(!w)return{status:"refused",code:"no-wire",message:Fe};let{captureArea:y,AREA_GUIDE:M}=await import("./c-H47C6PJZ.js"),k=y(b.state.doc,g.ref);if(f=null,u=null,k.status!=="ok")return{status:"refused",code:k.code,message:k.message};let O=p??g.quote,C={id:"req-"+Date.now().toString(36)+"-"+ ++Ue,editId:Le,tag:"div",elementHTML:k.capture.html,comment:d+`
|
|
2
2
|
|
|
3
|
-
`+M,contextRefs:pe(d)};return O&&(C.quote=O.text,Number.isInteger(O.start)&&(C.selection={start:O.start,end:O.end})),he(d)&&(C.page=!0),new Blob([JSON.stringify(C)]).size>921600?{status:"refused",code:"too-large",message:je}:(f=k.capture,{status:"ok",id:C.id,send:(L={})=>{let j=!0,B=null;return{done:(async()=>(C.page&&await window.clay?.save?.(),j?(B=w.send(C,{helper:ze,onStatus:L.onStatus}),B.done):{state:"cancelled"}))(),cancel(){j=!1,B?.cancel()}}}})},async propose(d){let p=r();if(!p||!f)return{status:"refused",message:"This area is no longer open for AI editing."};let{proposeArea:b}=await import("./c-
|
|
3
|
+
`+M,contextRefs:pe(d)};return O&&(C.quote=O.text,Number.isInteger(O.start)&&(C.selection={start:O.start,end:O.end})),he(d)&&(C.page=!0),new Blob([JSON.stringify(C)]).size>921600?{status:"refused",code:"too-large",message:je}:(f=k.capture,{status:"ok",id:C.id,send:(L={})=>{let j=!0,B=null;return{done:(async()=>(C.page&&await window.clay?.save?.(),j?(B=w.send(C,{helper:ze,onStatus:L.onStatus}),B.done):{state:"cancelled"}))(),cancel(){j=!1,B?.cancel()}}}})},async propose(d){let p=r();if(!p||!f)return{status:"refused",message:"This area is no longer open for AI editing."};let{proposeArea:b}=await import("./c-H47C6PJZ.js"),w=b(p.state,f,d?.html??"",{seed:Ge()});if(w.status!=="ready")return{status:"refused",message:w.message};u=w;let y=p.dom.ownerDocument.createElement("div");y.className="blockeditor-ai-preview";let M=H.DOMSerializer.fromSchema(N);return y.appendChild(M.serializeFragment(H.Fragment.from(w.nodes),{document:p.dom.ownerDocument})),$(p,{ids:f.ids,dom:y}),{status:"ready"}},async keep(){let d=r();if(!d||!f||!u)return{status:"failed",message:Ce};let{keepAreaTransaction:p}=await import("./c-H47C6PJZ.js"),b=p(d.state,f,u);if(R(d),b.status!=="ok")return{status:"failed",message:Ce};d.dispatch(b.tr),d.dom.isConnected&&d.focus();try{await window.clay?.save?.flush?.()}catch{return{status:"failed",message:"Your change is in the document, but saving failed. It will be saved with your next edit."}}return{status:"kept"}},discard(){let d=r();d&&(R(d),d.dom.isConnected&&d.focus())}};return g.quote=m??void 0,s.set(o.join(","),g),g}return{active:()=>!!r(),targetFromSelection(){let o=r();if(!o)return null;let m=z(o.state.doc);if(!m.length)return null;let l=le(o.state,m),e=ee(m,l.lo,l.hi);return e.length?e.length===1&&qe(o.state.doc,e[0])?v(e[0]):h(e,{quote:We(o.state,m,l)}):null},targetAt(o,m){let l=r();if(!l)return null;let e=l.posAtCoords({left:o,top:m});if(!e)return null;let f=z(l.state.doc);if(!f.length)return null;let u=e.inside>=0?e.inside:e.pos,g=f.findIndex(y=>y.node.type===N.nodes.tool&&y.end===u),d=g>=0?g:Math.min(Math.max(l.state.doc.resolve(u).index(0),0),f.length-1),{lo:p,hi:b}=Y(f,d,d),w=ee(f,p,b);return w.length?w.length===1&&qe(l.state.doc,w[0])?v(w[0]):h(w):null},between(o,m){let l=r();if(!l)return null;let e=z(l.state.doc),f=[...o?.ref??[],...m?.ref??[]].map(p=>e.findIndex(b=>b.node.attrs.id===p)).filter(p=>p>=0);if(!f.length)return null;let{lo:u,hi:g}=Y(e,Math.min(...f),Math.max(...f)),d=ee(e,u,g);return d.length?h(d):null},wholePage(){let o=r(),m=o?z(o.state.doc).map(l=>l.node.attrs.id).filter(Boolean):[];return h(m,{label:"This page"})},newTool(o){return a.newTool(o??null)},reviseTool(o){return a.reviseTool(o)}}}export{Tt as createPageAi};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as p}from"./c-H3FNLBHN.js";import{
|
|
1
|
+
import{c as p}from"./c-H3FNLBHN.js";import{x as u}from"./c-WHMZCRQD.js";import"./c-LAKBBJOU.js";import"./c-EIUKME3W.js";import"./c-DZT6W2NG.js";import"./c-SYOA4T7V.js";import"./c-ND3W7D5U.js";import"./c-WHQUZM2V.js";import"./c-3XGLJAS7.js";import{d as h}from"./c-OH2FPYSY.js";import{a as n,b as r}from"./c-Q26XHBLQ.js";import"./c-FSQXFG5T.js";import"./c-RETTCOWO.js";import"./c-JC4RZW4E.js";import"./c-3LDGIBMN.js";import"./c-57XDY6HC.js";import"./c-VHNSBD2M.js";var m=`
|
|
2
2
|
.blockeditor-tool-block { position: relative; min-height: 48px; border: 1px solid var(--blockeditor-rule); border-radius: 8px; padding: 12px; }
|
|
3
3
|
.blockeditor-tool-settings { position: absolute; top: 4px; inset-inline-end: 4px; border: 0; border-radius: 5px; background: var(--blockeditor-pop-bg); color: var(--blockeditor-ink-soft); font: 12px var(--blockeditor-font); padding: 5px 8px; cursor: pointer; opacity: 0; }
|
|
4
4
|
.blockeditor-tool-block:hover .blockeditor-tool-settings, .blockeditor-tool-block:focus-within .blockeditor-tool-settings { opacity: 1; }
|