2 lines
5.3 KiB
JavaScript
2 lines
5.3 KiB
JavaScript
import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t,ti as n}from"./control-ui-foundation-CeFMP1Ly.js";import{$t as r,Cn as i,En as a,en as o,fl as s,fs as c,ml as l,ms as u,vr as d,wn as f,yr as p}from"./control-ui-core-pH6nakZ-.js";import{Z as m,at as h}from"./lit-runtime-BEtFSUCp.js";import{m as g,p as _}from"./control-ui-core-DGVkFhVB.js";import{F as v,I as y,In as b,L as x,Ln as S,z as C}from"./control-ui-boot-wpHCbPL9.js";import{i as w,t as T}from"./normalization-m-N_6hXH.js";import{a as E,o as D}from"./mutations-BYbn2CZG.js";function O(e,t){let n=M.get(e);return n||(n={host:{},listeners:new Set},M.set(e,n)),n.listeners.add(t),n}function k(e,t,n){t.listeners.delete(n),t.listeners.size===0&&M.get(e)===t&&M.delete(e)}function A(e,t){if(t.loadPromise)return t.loadPromise;let n=e.request(`workboard.cards.list`,{}).then(w);t.loadPromise=n;let r=()=>{t.loadPromise===n&&(t.loadPromise=void 0)};return n.then(e=>{r(),t.snapshot=e;for(let n of t.listeners)n(e)},r),n}function j(e,t){let n=N.get(e);if(!n){let t=new Set;n={listeners:t,unsubscribe:e.subscribeEvents(n=>{if(n.event===`plugin.workboard.changed`&&e.snapshot.phase===`connected`)for(let e of t)e()})},N.set(e,n)}return n.listeners.add(t),()=>{n.listeners.delete(t),n.listeners.size===0&&N.get(e)===n&&(n.unsubscribe(),N.delete(e))}}var M,N,P;function F(){return(F=e((()=>{S(),v(),m(),g(),l(),p(),u(),i(),E(),T(),o(),n(),M=new WeakMap,N=new WeakMap,P=class extends s{constructor(...e){super(...e),this.sessionKey=``,this.active=!0,this.canMutate=!0,this.cards=[],this.statuses=[],this.loaded=!1,this.error=``,this.allCards=[],this.workboardHost={},this.client=null,this.sharedRuntime=null,this.refreshTask=new y(this,{autoRun:!1,args:()=>[this.client,this.sharedRuntime,!1,!1],task:async([e,t,n,r])=>{if(!e||!t)return x;if(!n&&t.snapshot)return t.snapshot;let i=t.loadPromise;try{let n=await A(e,t);return r&&i?A(e,t):n}catch(n){if(!r||!i)throw n;return A(e,t)}},onError:e=>{this.error=c(e),this.requestRender()}}),this.applySharedSnapshot=e=>{this.allCards=e.cards,this.cards=e.cards.filter(f),this.statuses=e.statuses;let t=r(this.workboardHost);t.cards=[...e.cards],t.statuses=e.statuses,t.loaded=!0,t.loadAttempted=!0,t.mutationReadiness=`ready`,this.loaded=!0,this.error=``,this.requestRender()},this.subscriptions=new d(this).effect(()=>this.context?.gateway,e=>{let t=()=>this.syncGateway(e.snapshot);t();let n=e.subscribe(t),r=j(e,()=>{this.active&&this.refresh(!0)});return()=>{n(),r()}})}connectedCallback(){super.connectedCallback(),this.syncGateway(this.context?.gateway.snapshot)}shouldUpdate(){return this.active}updated(e){if(e.get(`active`)===!1&&this.active){this.refresh(!0);return}this.active&&!this.loaded&&this.refreshTask.status===C.INITIAL&&this.refresh()}disconnectedCallback(){this.client&&this.sharedRuntime&&k(this.client,this.sharedRuntime,this.applySharedSnapshot),this.refreshTask.run([null,null,!1,!1]),this.client=null,this.sharedRuntime=null,this.allCards=[],this.cards=[],this.workboardHost={},this.loaded=!1,this.error=``,this.subscriptions.clear(),super.disconnectedCallback()}readStringProp(e){let t=this.widget?.props?.[e];return typeof t==`string`&&t.trim()?t.trim():void 0}readPositiveIntegerProp(e,t){let n=this.widget?.props?.[e];return typeof n==`number`&&Number.isInteger(n)&&n>0?n:t}retryLoad(){this.refresh(!0)}get loading(){return this.refreshTask.status===C.PENDING}get workboardClient(){return this.client}get workboardStateHost(){return this.workboardHost}async moveCard(e,t){let n=this.client;if(!this.active||!n||!this.canMutate||!f(e)||e.status===t)return;let i=this.workboardHost,o=r(i);o.cards=[...this.allCards],o.statuses=this.statuses,o.loaded=!0,o.loadAttempted=!0,o.mutationReadiness=`ready`,await D({host:i,client:n,cardId:e.id,status:t,position:a(o.cards,e,t),requestUpdate:()=>{this.client===n&&this.workboardHost===i&&this.syncFromHost()}}),this.client===n&&this.workboardHost===i&&this.syncFromHost()}syncGateway(e){let t=e?.phase===`connected`?e.client:null;this.client!==t&&(this.client&&this.sharedRuntime&&k(this.client,this.sharedRuntime,this.applySharedSnapshot),this.client=t,this.sharedRuntime=t?O(t,this.applySharedSnapshot):null,this.workboardHost=this.sharedRuntime?.host??{},this.allCards=[],this.cards=[],this.refreshTask.run([null,null,!1,!1]),this.loaded=!1,this.error=``,this.sharedRuntime?.snapshot&&this.applySharedSnapshot(this.sharedRuntime.snapshot),this.requestRender(),t&&!this.sharedRuntime?.snapshot&&this.refresh())}async refresh(e=!1){let t=this.client,n=this.sharedRuntime;if(!this.active||!t||!n||!e&&this.loaded)return;let r=e&&this.refreshTask.status===C.PENDING;!e&&this.refreshTask.status===C.PENDING||(this.error=``,this.requestRender(),await this.refreshTask.run([t,n,e,r]))}syncFromHost(){let e=r(this.workboardHost);this.allCards=[...e.cards],this.cards=this.allCards.filter(f),this.statuses=e.statuses,this.error=e.error??``,this.requestRender()}requestRender(){this.active&&(this.requestUpdate(),this.hostRequestUpdate?.())}},t([b({context:_,subscribe:!0})],P.prototype,`context`,void 0),t([h({attribute:!1})],P.prototype,`widget`,void 0),t([h({attribute:!1})],P.prototype,`sessionKey`,void 0),t([h({type:Boolean})],P.prototype,`active`,void 0),t([h({type:Boolean})],P.prototype,`canMutate`,void 0),t([h({attribute:!1})],P.prototype,`hostRequestUpdate`,void 0)})))()}export{F as n,P as t};
|
|
//# sourceMappingURL=workboard-widget-CLPt7UPr.js.map
|