@shane_il/pulse 0.3.0 → 0.4.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/README.md +2 -2
- package/dist/connect.d.ts +5 -1
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.cjs.map +1 -1
- package/dist/devtools.js +367 -337
- package/dist/devtools.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/pulse.cjs +1 -1
- package/dist/pulse.cjs.map +1 -1
- package/dist/pulse.js +305 -275
- package/dist/pulse.js.map +1 -1
- package/dist/vnode.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A render-driven UI framework with virtual DOM and immutable stores. Like React,
|
|
|
7
7
|
## Why Pulse?
|
|
8
8
|
|
|
9
9
|
- **No hooks.** All state lives in external stores. Components are `(props) => VNode`.
|
|
10
|
-
- **Stores are first-class.** Create, import, and share stores anywhere. They're framework-agnostic.
|
|
10
|
+
- **Stores are first-class.** Create, import, and share stores anywhere. They're framework-agnostic. Per-component local stores for UI-only state.
|
|
11
11
|
- **Render-driven.** Describe what the UI looks like for a given state. Pulse handles the rest.
|
|
12
12
|
- **Built-in routing.** Store-based client-side router — routes are just state.
|
|
13
13
|
- **Middleware.** Pluggable middleware for logging, action history, and custom logic.
|
|
@@ -94,7 +94,7 @@ Store dispatch → Notify subscribers → Schedule re-render → Expand componen
|
|
|
94
94
|
|
|
95
95
|
```bash
|
|
96
96
|
npm install
|
|
97
|
-
npm test #
|
|
97
|
+
npm test # 242 tests (vitest)
|
|
98
98
|
npm run typecheck # tsc --noEmit
|
|
99
99
|
npm run lint # eslint
|
|
100
100
|
npm run build # vite lib mode → dist/
|
package/dist/connect.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VNode, Bindings, Lifecycle, ComponentFunction } from './vnode';
|
|
1
|
+
import type { VNode, Bindings, Lifecycle, ComponentFunction, LocalStoreConfig } from './vnode';
|
|
2
2
|
export declare const CONNECTED: unique symbol;
|
|
3
3
|
export declare function __setComponentHooks(onMount: ((instance: ComponentInstance) => void) | null, onUnmount: ((instance: ComponentInstance) => void) | null): void;
|
|
4
4
|
export declare function connect(bindings: Bindings | null | undefined, lifecycle?: Lifecycle): (Component: ComponentFunction) => {
|
|
@@ -14,7 +14,11 @@ export declare class ComponentInstance {
|
|
|
14
14
|
parentDom: Node | null;
|
|
15
15
|
_renderCallback: (() => void) | null;
|
|
16
16
|
_mountCleanup: (() => void) | null;
|
|
17
|
+
_localState: Record<string, any> | null;
|
|
18
|
+
_localActions: Record<string, (state: any, payload?: any) => any> | null;
|
|
17
19
|
constructor(connectedFn: ComponentFunction, props: Record<string, any>);
|
|
20
|
+
_initLocalStore(config: LocalStoreConfig): void;
|
|
21
|
+
getLocalProps(): Record<string, any> | null;
|
|
18
22
|
mount(parentDom: Node, renderCallback: () => void): void;
|
|
19
23
|
_onStoreChange(): void;
|
|
20
24
|
updateSelected(): void;
|
package/dist/devtools.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var lt=Object.defineProperty;var at=(t,e,n)=>e in t?lt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var S=(t,e,n)=>at(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let A=!1;const R=new Set;function pt(t){R.add(t),A||(A=!0,queueMicrotask(ut))}function ut(){const t=[...R];R.clear(),A=!1;for(const e of t)e()}const q=Symbol("PULSE_CONNECTED"),F=globalThis;F.__PULSE_HOOKS__||(F.__PULSE_HOOKS__={onMount:null,onUnmount:null});const T=F.__PULSE_HOOKS__;function ft(t,e){T.onMount=t,T.onUnmount=e}function dt(t,e){return function(o){const s=t||{};function r(i){const a={};for(const p in s){const{store:l,selector:h}=s[p];a[p]=h(l.getState())}return o({...a,...i})}return r[q]=!0,r._bindings=s,r._innerComponent=o,r.displayName=`Connected(${o.displayName||o.name||"Anonymous"})`,r}}class ht{constructor(e,n){S(this,"connectedFn");S(this,"props");S(this,"prevSelected");S(this,"unsubscribers");S(this,"lastVTree");S(this,"parentDom");S(this,"_renderCallback");S(this,"_mountCleanup");this.connectedFn=e,this.props=n,this.prevSelected={},this.unsubscribers=[],this.lastVTree=null,this.parentDom=null,this._renderCallback=null,this._mountCleanup=null}mount(e,n){var r;this.parentDom=e,this._renderCallback=n;const o=this.connectedFn._bindings;for(const i in o){const{store:a,selector:p}=o[i];this.prevSelected[i]=p(a.getState())}for(const i in o){const{store:a}=o[i],p=a.subscribe(()=>{this._onStoreChange()});this.unsubscribers.push(p)}const s=this.connectedFn._lifecycle;if(s!=null&&s.onMount){const i=s.onMount({dom:(r=this.lastVTree)==null?void 0:r._dom,props:this.props});typeof i=="function"&&(this._mountCleanup=i)}T.onMount&&T.onMount(this)}_onStoreChange(){const e=this.connectedFn._bindings;let n=!1;for(const o in e){const{store:s,selector:r}=e[o],i=r(s.getState());if(!mt(i,this.prevSelected[o])){n=!0;break}}n&&pt(this._renderCallback)}updateSelected(){const e=this.connectedFn._bindings;for(const n in e){const{store:o,selector:s}=e[n];this.prevSelected[n]=s(o.getState())}}unmount(){T.onUnmount&&T.onUnmount(this),this._mountCleanup&&(this._mountCleanup(),this._mountCleanup=null);const e=this.connectedFn._lifecycle;e!=null&&e.onDestroy&&e.onDestroy({props:this.props});for(const n of this.unsubscribers)n();this.unsubscribers=[],this._renderCallback=null}}function mt(t,e){if(Object.is(t,e))return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(e,s)||!Object.is(t[s],e[s]))return!1;return!0}function J(t){let e=t.state;const n=t.actions,o=new Set,s=t.middleware;function r(){return e}function i(){for(const f of o)f(e)}function a(f,m){const b=n[f];if(!b)throw new Error(`[pulse] Unknown action: "${f}"`);const _=b(e,m);_!==e&&(e=_,i())}function p(f,m){if(f==="__devtools_replace__"){e=m,i();return}const b=n[f];if(!b)throw new Error(`[pulse] Unknown action: "${f}"`);const _={store:c,actionName:f,payload:m,prevState:e,nextState:void 0};let w=0;function G(){if(w<s.length){const C=s[w++];C(_,G)}else{const C=b(_.prevState,_.payload);_.nextState=C,C!==e&&(e=C,i())}}G()}const l=s&&s.length>0?p:a;function h(f){return o.add(f),()=>{o.delete(f)}}function g(f){return{store:c,selector:f}}const c={getState:r,dispatch:l,subscribe:h,select:g};return t.name&&(c.name=t.name),c}function yt(t,e){return(o,s)=>{s(),t.push({actionName:o.actionName,payload:o.payload,prevState:o.prevState,nextState:o.nextState??o.prevState,timestamp:Date.now()}),t.length>1/0&&t.splice(0,t.length-1/0)}}let gt=1;class Q{constructor(){S(this,"stores",new Map);S(this,"components",new Map);S(this,"listeners",new Set)}registerStore(e,n,o){const s=o||e.name||`store_${this.stores.size}`;this.stores.set(s,{store:e,history:n,name:s}),e.subscribe(()=>{this.emit({type:"action-dispatched",storeName:s})}),this.emit({type:"store-registered",storeName:s})}getStoreNames(){return Array.from(this.stores.keys())}getStoreState(e){var n;return(n=this.stores.get(e))==null?void 0:n.store.getState()}getTrackedStore(e){return this.stores.get(e)}getHistory(e){var o;if(e)return((o=this.stores.get(e))==null?void 0:o.history)??[];const n=[];for(const s of this.stores.values())n.push(...s.history);return n.sort((s,r)=>s.timestamp-r.timestamp)}trackComponent(e,n){const o=gt++;return this.components.set(o,{id:o,displayName:e,storeNames:n}),this.emit({type:"component-mounted",data:{id:o,displayName:e,storeNames:n}}),o}untrackComponent(e){const n=this.components.get(e);n&&(this.components.delete(e),this.emit({type:"component-unmounted",data:{id:e,displayName:n.displayName}}))}getComponents(){return Array.from(this.components.values())}on(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}emit(e){for(const n of this.listeners)n(e)}}function St(t,e){const n=[],o=yt(n),s=J({...e,middleware:[o,...e.middleware||[]]});return t.registerStore(s,n,e.name),{store:s,history:n}}const B=Symbol("TEXT_NODE"),bt=Symbol("FRAGMENT");function z(t){return{type:B,props:{nodeValue:String(t)},children:[],key:null}}function _t(t){return t==null||typeof t=="boolean"?null:typeof t=="string"||typeof t=="number"?z(t):t}function Y(t){const e=[];for(const n of t)if(Array.isArray(n))e.push(...Y(n));else{const o=_t(n);o!==null&&e.push(o)}return e}function u(t,e,...n){e=e||{};const o=e.key??null;e.key!==void 0&&(e={...e},delete e.key);const s=Y(n);return{type:t,props:e,children:s,key:o}}const y={CREATE:"CREATE",REMOVE:"REMOVE",REPLACE:"REPLACE",UPDATE:"UPDATE",TEXT:"TEXT",MOVE:"MOVE",CHILDREN:"CHILDREN"};function x(t,e){if(e==null&&t==null)return[];if(e==null)return[{type:y.REMOVE,target:t}];if(t==null)return[{type:y.CREATE,newVNode:e}];if(t.type!==e.type)return[{type:y.REPLACE,oldVNode:t,newVNode:e}];if(e._dom=t._dom,t.type===B)return t.props.nodeValue!==e.props.nodeValue?[{type:y.TEXT,oldVNode:t,newVNode:e}]:[];const n=[],o=xt(t.props,e.props);o&&n.push({type:y.UPDATE,target:t,propPatches:o});const s=Et(t.children,e.children);return s.length&&n.push({type:y.CHILDREN,parent:t,childPatches:s}),n}function xt(t,e){const n={},o=[];let s=!1;for(const r in e)r!=="children"&&t[r]!==e[r]&&(n[r]=e[r],s=!0);for(const r in t)r!=="children"&&(r in e||(o.push(r),s=!0));return s?{set:n,remove:o}:null}function O(t,e){return t==null||e==null?!1:t.type===e.type&&t.key===e.key}function K(t,e){const n=new Set;let o=0,s=0;for(const r of t)r!=null&&(r.key!=null?(o++,n.has(r.key)&&console.warn(`[pulse] Duplicate key "${String(r.key)}" in ${e} children. Keys must be unique among siblings.`),n.add(r.key)):s++);o>0&&s>0&&console.warn(`[pulse] Mixed keyed and unkeyed children in ${e} list (${o} keyed, ${s} unkeyed). Either all children should have keys or none should.`)}function Et(t,e){var g;process.env.NODE_ENV!=="production"&&(K(t,"old"),K(e,"new"));const n=[];let o=0,s=t.length-1,r=0,i=e.length-1,a=t[o],p=t[s],l=e[r],h=e[i];for(;o<=s&&r<=i;){if(a==null){a=t[++o];continue}if(p==null){p=t[--s];continue}if(O(a,l))n.push(...x(a,l)),a=t[++o],l=e[++r];else if(O(p,h))n.push(...x(p,h)),p=t[--s],h=e[--i];else if(O(a,h))n.push({type:y.MOVE,vnode:a,anchor:t[s+1]||null,childPatches:x(a,h)}),a=t[++o],h=e[--i];else if(O(p,l))n.push({type:y.MOVE,vnode:p,anchor:a,childPatches:x(p,l)}),p=t[--s],l=e[++r];else break}if(o<=s&&r<=i){const c=new Map;for(let f=o;f<=s;f++){const m=(g=t[f])==null?void 0:g.key;m!=null&&c.set(m,f)}for(;r<=i;){l=e[r];const f=l.key!=null?c.get(l.key):void 0;if(f!==void 0){const m=t[f];n.push({type:y.MOVE,vnode:m,anchor:t[o]||null,childPatches:x(m,l)}),t[f]=null,c.delete(l.key)}else n.push({type:y.CREATE,newVNode:l,anchor:t[o]||null});r++}for(let f=o;f<=s;f++)t[f]!=null&&n.push({type:y.REMOVE,target:t[f]})}if(o>s){const c=e[i+1]||null;for(let f=r;f<=i;f++)n.push({type:y.CREATE,newVNode:e[f],anchor:c})}else if(r>i)for(let c=o;c<=s;c++)t[c]!=null&&n.push({type:y.REMOVE,target:t[c]});return n}const Z="http://www.w3.org/2000/svg";function v(t,e){if(t.type===B){const o=document.createTextNode(t.props.nodeValue);return t._dom=o,o}if(t.type===bt){const o=document.createDocumentFragment();for(const s of t.children)o.appendChild(v(s,e));return t._dom=o,o}t.type==="svg"?e=Z:t.type==="foreignObject"&&(e=void 0);const n=e?document.createElementNS(e,t.type):document.createElement(t.type);Tt(n,{},t.props);for(const o of t.children)n.appendChild(v(o,e));return t._dom=n,n}function Tt(t,e,n){for(const o in e)o==="children"||o==="key"||o in n||et(t,o,e[o]);for(const o in n)o==="children"||o==="key"||e[o]!==n[o]&&tt(t,o,n[o],e[o])}function tt(t,e,n,o){if(e.startsWith("on")){const s=e.slice(2).toLowerCase();o&&t.removeEventListener(s,o),n&&t.addEventListener(s,n)}else if(e==="className"||e==="class")t instanceof SVGElement?t.setAttribute("class",n||""):t.className=n||"";else if(e==="style"&&typeof n=="object"){if(typeof o=="object"&&o)for(const s in o)s in n||(t.style[s]="");Object.assign(t.style,n)}else if(e==="dangerouslySetInnerHTML")n&&typeof n.__html=="string"&&(t.innerHTML=n.__html);else if(e==="ref")typeof n=="function"&&n(t);else if(e in t&&!(t instanceof SVGElement))try{t[e]=n??""}catch{t.setAttribute(e,n)}else n===!0?t.setAttribute(e,""):n===!1||n==null?t.removeAttribute(e):t.setAttribute(e,n)}function et(t,e,n){if(e.startsWith("on"))t.removeEventListener(e.slice(2).toLowerCase(),n);else if(e==="dangerouslySetInnerHTML")t.innerHTML="";else if(e==="className"||e==="class")t instanceof SVGElement?t.removeAttribute("class"):t.className="";else if(e in t&&!(t instanceof SVGElement))try{t[e]=""}catch{t.removeAttribute(e)}else t.removeAttribute(e)}function W(t){return t instanceof SVGElement?Z:void 0}function P(t,e){var n,o,s;for(const r of e)switch(r.type){case y.CREATE:{const i=v(r.newVNode,W(t));(n=r.anchor)!=null&&n._dom?t.insertBefore(i,r.anchor._dom):t.appendChild(i);break}case y.REMOVE:{const i=r.target._dom;i!=null&&i.parentNode&&i.parentNode.removeChild(i);break}case y.REPLACE:{const i=r.oldVNode._dom,a=i==null?void 0:i.parentNode,p=v(r.newVNode,a?W(a):void 0);a&&a.replaceChild(p,i);break}case y.UPDATE:{const i=r.target._dom,{set:a,remove:p}=r.propPatches;for(const l of p)et(i,l,r.target.props[l]);for(const l in a)tt(i,l,a[l],r.target.props[l]);break}case y.TEXT:{const i=r.oldVNode._dom;i&&(i.nodeValue=r.newVNode.props.nodeValue);break}case y.MOVE:{const i=r.vnode._dom;i&&((o=r.anchor)!=null&&o._dom?t.insertBefore(i,r.anchor._dom):t.appendChild(i)),(s=r.childPatches)!=null&&s.length&&i&&P(i,r.childPatches);break}case y.CHILDREN:{const i=r.parent._dom;i&&r.childPatches.length&&P(i,r.childPatches);break}}}const $=new WeakMap;function kt(t,e){const n=$.get(e);if(n){const o=E(t,e),s=[];M(n.vTree,s);const r=x(n.vTree,o);P(e,r);const i=[];o&&M(o,i);const a=new Set(i);for(const l of s)a.has(l)||l.unmount();const p=new Set(s);for(const l of i)p.has(l)||l.mount(e,()=>U(l,e));$.set(e,{vTree:o})}else{const o=E(t,e);if(!o)return;const s=v(o);e.appendChild(s);const r=[];M(o,r);for(const i of r)i.mount(e,()=>U(i,e));$.set(e,{vTree:o})}}function E(t,e){var n;if(t==null)return null;if(typeof t.type=="function"){if(t.type[q]){const s=t.type._lifecycle;try{const r=new ht(t.type,t.props),i=t.type(t.props),p=E(i,e)??z("");if(p._instance){const l={type:"div",props:{style:{display:"contents"}},children:[p],key:t.key};return l._instance=r,r.lastVTree=l,l}return p._instance=r,r.lastVTree=p,p}catch(r){if(s!=null&&s.onError){const i=s.onError({error:r,props:t.props});return E(i,e)}throw r}}const o=t.type({...t.props,children:t.children});return E(o,e)}return(n=t.children)!=null&&n.length&&(t.children=t.children.map(o=>E(o,e)).filter(o=>o!=null)),t}function U(t,e){var s,r;if(!t._renderCallback)return;const n=t.connectedFn,o=n._lifecycle;try{const i=n(t.props),p=E(i,e)??z("");let l;if(p._instance&&p._instance!==t?(l={type:"div",props:{style:{display:"contents"}},children:[p],key:null},l._instance=t):(p._instance=t,l=p),t.lastVTree){H(t.lastVTree,t);const m=x(t.lastVTree,l),b=((s=t.lastVTree._dom)==null?void 0:s.parentNode)||e;P(b,m),l._dom||(l._dom=t.lastVTree._dom)}const h=[];L(t.lastVTree,h,t);const g=[];L(l,g,t);const c=new Set(g);for(const m of h)c.has(m)||m.unmount();t.lastVTree=l;const f=new Set(h);for(const m of g)f.has(m)||m.mount(e,()=>U(m,e));o!=null&&o.onUpdate&&o.onUpdate({dom:l==null?void 0:l._dom,props:t.props}),t.updateSelected()}catch(i){if(o!=null&&o.onError){const a=o.onError({error:i,props:t.props}),p=E(a,e);if(t.lastVTree&&p){H(t.lastVTree,t);const h=x(t.lastVTree,p),g=((r=t.lastVTree._dom)==null?void 0:r.parentNode)||e;P(g,h),p._dom||(p._dom=t.lastVTree._dom)}const l=[];L(t.lastVTree,l,t);for(const h of l)h.unmount();t.lastVTree=p,t.updateSelected()}else throw i}}function H(t,e){if(!(!t||!t.children))for(let n=0;n<t.children.length;n++){const o=t.children[n];o._instance&&o._instance!==e&&o._instance.lastVTree&&o._instance.lastVTree!==o&&(t.children[n]=o._instance.lastVTree),H(t.children[n],e)}}function M(t,e){if(t&&(t._instance&&e.push(t._instance),t.children))for(const n of t.children)M(n,e)}function L(t,e,n){if(t&&(t._instance&&t._instance!==n&&e.push(t._instance),t.children))for(const o of t.children)L(o,e,n)}function j(t,e,n){const o=t.getTrackedStore(e);if(!o)throw new Error(`[pulse-devtools] Unknown store: "${e}"`);const{store:s,history:r}=o;if(n<0||n>=r.length)throw new Error(`[pulse-devtools] Index ${n} out of range (0..${r.length-1})`);const i=r[n].nextState;s.dispatch("__devtools_replace__",i),t.emit({type:"time-travel",storeName:e,data:{entryIndex:n}})}function wt(t,e,n){const o=t.getTrackedStore(e);if(!o)throw new Error(`[pulse-devtools] Unknown store: "${e}"`);const{store:s,history:r}=o;if(n<0||n>=r.length)throw new Error(`[pulse-devtools] Index ${n} out of range (0..${r.length-1})`);const i=r.slice(n),a=r[n].prevState;s.dispatch("__devtools_replace__",a);for(const p of i)s.dispatch(p.actionName,p.payload);t.emit({type:"time-travel",storeName:e,data:{replayFrom:n}})}const d={base:"#1e1e2e",surface0:"#313244",surface1:"#45475a",overlay0:"#6c7086",text:"#cdd6f4",subtext0:"#a6adc8",blue:"#89b4fa",green:"#a6e3a1",yellow:"#f9e2af",mauve:"#cba6f7",teal:"#94e2d5",peach:"#fab387"},Ct={position:"fixed",bottom:"0",left:"0",right:"0",height:"320px",backgroundColor:d.base,color:d.text,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"12px",lineHeight:"1.5",zIndex:"2147483647",display:"flex",flexDirection:"column",borderTop:`2px solid ${d.mauve}`,overflow:"hidden"},Nt={display:"flex",alignItems:"center",backgroundColor:d.surface0,borderBottom:`1px solid ${d.surface1}`,padding:"0 8px",height:"32px",flexShrink:"0"},vt=t=>({background:"none",border:"none",color:t?d.mauve:d.subtext0,fontFamily:"inherit",fontSize:"12px",padding:"6px 12px",cursor:"pointer",borderBottom:t?`2px solid ${d.mauve}`:"2px solid transparent",marginBottom:"-1px"}),Pt={background:"none",border:"none",color:d.overlay0,fontSize:"16px",cursor:"pointer",marginLeft:"auto",padding:"4px 8px",fontFamily:"inherit"},Vt={flex:"1",overflow:"auto",padding:"8px 12px"},Ot={display:"flex",height:"100%",gap:"1px"},It={width:"200px",flexShrink:"0",borderRight:`1px solid ${d.surface1}`,overflow:"auto",padding:"4px 0"},Mt={flex:"1",overflow:"auto",padding:"8px"},Lt=t=>({padding:"4px 12px",cursor:"pointer",backgroundColor:t?d.surface1:"transparent",color:t?d.blue:d.text}),X={color:d.mauve},I={color:d.green},$t={color:d.yellow},At={color:d.peach},k={color:d.overlay0,fontStyle:"italic"},Rt=t=>({padding:"4px 8px",cursor:"pointer",backgroundColor:t?d.surface1:"transparent",borderLeft:t?`3px solid ${d.blue}`:"3px solid transparent",display:"flex",justifyContent:"space-between",alignItems:"center"}),nt={color:d.blue,fontWeight:"bold"},Ft={color:d.overlay0,fontSize:"10px"},Ut={width:"100%",accentColor:d.mauve,margin:"4px 0 8px"},Ht={width:"100%",backgroundColor:d.surface0,border:`1px solid ${d.surface1}`,color:d.text,padding:"4px 8px",fontFamily:"inherit",fontSize:"12px",borderRadius:"4px",outline:"none",marginBottom:"8px",boxSizing:"border-box"},jt={padding:"4px 8px",borderBottom:`1px solid ${d.surface0}`},Dt={color:d.teal,fontWeight:"bold"},Bt={color:d.overlay0,fontSize:"10px",marginLeft:"8px"},ot={display:"inline-block",backgroundColor:d.surface1,color:d.subtext0,padding:"1px 6px",borderRadius:"8px",fontSize:"10px",marginLeft:"4px"},zt={color:d.mauve,fontWeight:"bold",fontSize:"12px",marginRight:"8px"};function D(t,e){if(t===null)return u("span",{style:k},"null");if(t===void 0)return u("span",{style:k},"undefined");if(typeof t=="string")return u("span",{style:$t},`"${t}"`);if(typeof t=="boolean")return u("span",{style:At},String(t));if(typeof t=="number")return u("span",{style:I},String(t));if(Array.isArray(t))return t.length===0?u("span",{style:I},"[]"):e>4?u("span",{style:k},"[…]"):u("div",{style:{paddingLeft:"12px"}},...t.map((n,o)=>u("div",{key:o},u("span",{style:X},`${o}: `),D(n,e+1))));if(typeof t=="object"){const n=Object.keys(t);return n.length===0?u("span",{style:I},"{}"):e>4?u("span",{style:k},"{…}"):u("div",{style:{paddingLeft:"12px"}},...n.map(o=>u("div",{key:o},u("span",{style:X},`${o}: `),D(t[o],e+1))))}return u("span",{style:I},String(t))}function Gt({storeNames:t,selectedStore:e,storeStates:n,onSelectStore:o}){const s=e?n[e]:null;return u("div",{style:Ot},u("div",{style:It},...t.map(r=>u("div",{key:r,style:Lt(r===e),onClick:()=>o(r)},r))),u("div",{style:Mt},e?u("div",null,u("div",{style:{marginBottom:"8px",color:d.subtext0}},"State of ",u("span",{style:nt},e)),s!=null?D(s,0):u("span",{style:k},"No state")):u("span",{style:k},"Select a store")))}function Kt(t){const e=new Date(t),n=o=>String(o).padStart(2,"0");return`${n(e.getHours())}:${n(e.getMinutes())}:${n(e.getSeconds())}`}function Wt({actionLog:t,timeTravelIndex:e,filter:n,onFilterChange:o,onTravelTo:s,onSliderChange:r}){const i=n?t.filter(a=>a.actionName.toLowerCase().includes(n.toLowerCase())):t;return u("div",{style:{height:"100%",display:"flex",flexDirection:"column"}},u("input",{style:Ht,placeholder:"Filter actions…",value:n,onInput:a=>o(a.target.value)}),t.length>0?u("div",{style:{flexShrink:"0"}},u("input",{type:"range",style:Ut,min:"0",max:String(t.length-1),value:String(e),onInput:a=>r(Number(a.target.value))}),u("div",{style:{color:d.overlay0,fontSize:"10px",marginBottom:"4px"}},`${e+1} / ${t.length}`)):null,u("div",{style:{flex:"1",overflow:"auto"}},...i.map(a=>{const p=t.indexOf(a);return u("div",{key:p,style:Rt(p===e),onClick:()=>s(p)},u("span",null,u("span",{style:nt},a.actionName),a.payload!==void 0?u("span",{style:{color:d.subtext0,marginLeft:"8px"}},typeof a.payload=="object"?JSON.stringify(a.payload):String(a.payload)):null),u("span",{style:Ft},Kt(a.timestamp)))}),i.length===0?u("div",{style:{color:d.overlay0,padding:"8px"}},t.length===0?"No actions yet":"No matching actions"):null))}function Xt({components:t}){return t.length===0?u("div",{style:{color:d.overlay0,padding:"8px"}},"No connected components mounted"):u("div",null,...t.map(e=>u("div",{key:e.id,style:jt},u("span",{style:Dt},e.displayName),e.storeNames.length>0?u("span",{style:Bt},e.storeNames.map(n=>u("span",{key:n,style:ot},n))):null)))}function qt(){return J({state:{open:!1,activeTab:"stores",selectedStore:null,timeTravelIndex:-1,storeNames:[],storeStates:{},actionLog:[],filter:"",components:[]},actions:{toggle:t=>({...t,open:!t.open}),open:t=>({...t,open:!0}),close:t=>({...t,open:!1}),setTab:(t,e)=>({...t,activeTab:e}),selectStore:(t,e)=>({...t,selectedStore:e}),setFilter:(t,e)=>({...t,filter:e}),setTimeTravelIndex:(t,e)=>({...t,timeTravelIndex:e}),sync:(t,e)=>({...t,...e})}})}function Jt({open:t,activeTab:e,selectedStore:n,timeTravelIndex:o,storeNames:s,storeStates:r,actionLog:i,filter:a,components:p,panelActions:l}){if(!t)return null;const h=[{id:"stores",label:"Stores"},{id:"actions",label:"Actions"},{id:"components",label:"Components"}];let g;return e==="stores"?g=Gt({storeNames:s,selectedStore:n,storeStates:r,onSelectStore:l.selectStore}):e==="actions"?g=Wt({actionLog:i,timeTravelIndex:o,filter:a,onFilterChange:l.setFilter,onTravelTo:l.travelTo,onSliderChange:l.sliderChange}):g=Xt({components:p}),u("div",{style:Ct},u("div",{style:Nt},u("span",{key:"title",style:zt},"Pulse"),...h.map(c=>u("button",{key:c.id,style:vt(c.id===e),onClick:()=>l.setTab(c.id)},c.label)),u("span",{key:"badge",style:ot},`${s.length} stores`),u("button",{key:"close",style:Pt,onClick:l.close},"×")),u("div",{style:Vt},g))}function Qt(t,e){const n=qt();e&&e(n);let o=!1;function s(){if(!o){o=!0;try{const c=t.getStoreNames(),f={};for(const w of c)f[w]=t.getStoreState(w);const b=n.getState().selectedStore||c[0]||null,_=b?t.getHistory(b):[];n.dispatch("sync",{storeNames:c,storeStates:f,actionLog:_,timeTravelIndex:_.length>0?_.length-1:-1,selectedStore:b,components:t.getComponents()})}finally{o=!1}}}t.on(c=>{c.type==="component-mounted"||c.type==="component-unmounted"||s()});const r={selectStore:c=>{n.dispatch("selectStore",c);const f=t.getHistory(c);n.dispatch("sync",{actionLog:f,timeTravelIndex:f.length>0?f.length-1:-1})},setTab:c=>n.dispatch("setTab",c),setFilter:c=>n.dispatch("setFilter",c),close:()=>n.dispatch("close"),travelTo:c=>{const f=n.getState().selectedStore;f&&(j(t,f,c),n.dispatch("setTimeTravelIndex",c))},sliderChange:c=>{const f=n.getState().selectedStore;f&&(j(t,f,c),n.dispatch("setTimeTravelIndex",c))}},i=dt({open:n.select(c=>c.open),activeTab:n.select(c=>c.activeTab),selectedStore:n.select(c=>c.selectedStore),timeTravelIndex:n.select(c=>c.timeTravelIndex),storeNames:n.select(c=>c.storeNames),storeStates:n.select(c=>c.storeStates),actionLog:n.select(c=>c.actionLog),filter:n.select(c=>c.filter),components:n.select(c=>c.components)})(c=>Jt({...c,panelActions:r}));let a=null;function p(){a||(a=document.createElement("div"),a.id="pulse-devtools-root",document.body.appendChild(a),kt(u(i,null),a),s())}function l(){p(),n.dispatch("open")}function h(){n.dispatch("close")}function g(){p(),n.dispatch("toggle")}return{openPanel:l,closePanel:h,togglePanel:g,panelStore:n}}const V=new Q,st=new WeakSet;function rt(t){st.add(t)}ft(t=>{const e=t.connectedFn._bindings||{},n=Object.values(e).map(i=>i.store);if(n.length>0&&n.every(i=>st.has(i)))return;const o=n.map(i=>i.name||"unnamed"),s=t.connectedFn.displayName||"Unknown",r=V.trackComponent(s,o);t._devtoolsId=r},t=>{const e=t._devtoolsId;e!=null&&V.untrackComponent(e)});let N=null;function it(){return N||(N=Qt(V,rt)),N}function Yt(){it().openPanel()}function Zt(){N&&N.closePanel()}function ct(){it().togglePanel()}typeof window<"u"&&(window.addEventListener("keydown",t=>{t.ctrlKey&&t.shiftKey&&t.key==="P"&&(t.preventDefault(),ct())}),window.__PULSE_DEVTOOLS__=V);exports.PulseDevtools=Q;exports._markInternalStore=rt;exports.closePanel=Zt;exports.devtools=V;exports.instrumentStore=St;exports.openPanel=Yt;exports.replayFrom=wt;exports.togglePanel=ct;exports.travelTo=j;
|
|
1
|
+
"use strict";var at=Object.defineProperty;var pt=(t,e,n)=>e in t?at(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var S=(t,e,n)=>pt(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let M=!1;const R=new Set;function G(t){R.add(t),M||(M=!0,queueMicrotask(ut))}function ut(){const t=[...R];R.clear(),M=!1;for(const e of t)e()}const J=Symbol("PULSE_CONNECTED"),F=globalThis;F.__PULSE_HOOKS__||(F.__PULSE_HOOKS__={onMount:null,onUnmount:null});const T=F.__PULSE_HOOKS__;function ft(t,e){T.onMount=t,T.onUnmount=e}function dt(t,e){return function(o){const s=t||{};function r(i){const l={};for(const u in s){const{store:f,selector:h}=s[u];l[u]=h(f.getState())}return o({...l,...i})}return r[J]=!0,r._bindings=s,r._innerComponent=o,r.displayName=`Connected(${o.displayName||o.name||"Anonymous"})`,r}}class ht{constructor(e,n){S(this,"connectedFn");S(this,"props");S(this,"prevSelected");S(this,"unsubscribers");S(this,"lastVTree");S(this,"parentDom");S(this,"_renderCallback");S(this,"_mountCleanup");S(this,"_localState");S(this,"_localActions");this.connectedFn=e,this.props=n,this.prevSelected={},this.unsubscribers=[],this.lastVTree=null,this.parentDom=null,this._renderCallback=null,this._mountCleanup=null,this._localState=null,this._localActions=null;const o=e._lifecycle;o!=null&&o.store&&this._initLocalStore(o.store)}_initLocalStore(e){this._localState={...e.state},this._localActions=e.actions;const n=this.connectedFn._bindings,o=this.connectedFn.displayName||"component",s=Object.keys(this._localState),r=Object.keys(this._localActions);for(const i of s)i in n&&console.warn(`[pulse] Local store state "${i}" shadows global binding in ${o}. Local value will be used.`);for(const i of r)i in n&&console.warn(`[pulse] Local store action "${i}" shadows global binding in ${o}. Local value will be used.`),i in this._localState&&console.warn(`[pulse] Local store action "${i}" shadows state key with same name in ${o}.`)}getLocalProps(){if(!this._localState)return null;const e={...this._localState};for(const n in this._localActions){const o=this._localActions[n];e[n]=s=>{const r=o(this._localState,s);r!==this._localState&&(this._localState=r,this._renderCallback&&G(this._renderCallback))}}return e}mount(e,n){var r;this.parentDom=e,this._renderCallback=n;const o=this.connectedFn._bindings;for(const i in o){const{store:l,selector:u}=o[i];this.prevSelected[i]=u(l.getState())}for(const i in o){const{store:l}=o[i],u=l.subscribe(()=>{this._onStoreChange()});this.unsubscribers.push(u)}const s=this.connectedFn._lifecycle;if(s!=null&&s.onMount){const i=s.onMount({dom:(r=this.lastVTree)==null?void 0:r._dom,props:this.props});typeof i=="function"&&(this._mountCleanup=i)}T.onMount&&T.onMount(this)}_onStoreChange(){const e=this.connectedFn._bindings;let n=!1;for(const o in e){const{store:s,selector:r}=e[o],i=r(s.getState());if(!mt(i,this.prevSelected[o])){n=!0;break}}n&&G(this._renderCallback)}updateSelected(){const e=this.connectedFn._bindings;for(const n in e){const{store:o,selector:s}=e[n];this.prevSelected[n]=s(o.getState())}}unmount(){T.onUnmount&&T.onUnmount(this),this._mountCleanup&&(this._mountCleanup(),this._mountCleanup=null);const e=this.connectedFn._lifecycle;e!=null&&e.onDestroy&&e.onDestroy({props:this.props});for(const n of this.unsubscribers)n();this.unsubscribers=[],this._renderCallback=null}}function mt(t,e){if(Object.is(t,e))return!0;if(typeof t!="object"||typeof e!="object"||t===null||e===null)return!1;const n=Object.keys(t),o=Object.keys(e);if(n.length!==o.length)return!1;for(const s of n)if(!Object.prototype.hasOwnProperty.call(e,s)||!Object.is(t[s],e[s]))return!1;return!0}function Q(t){let e=t.state;const n=t.actions,o=new Set,s=t.middleware;function r(){return e}function i(){for(const p of o)p(e)}function l(p,b){const _=n[p];if(!_)throw new Error(`[pulse] Unknown action: "${p}"`);const y=_(e,b);y!==e&&(e=y,i())}function u(p,b){if(p==="__devtools_replace__"){e=b,i();return}const _=n[p];if(!_)throw new Error(`[pulse] Unknown action: "${p}"`);const y={store:c,actionName:p,payload:b,prevState:e,nextState:void 0};let k=0;function K(){if(k<s.length){const C=s[k++];C(y,K)}else{const C=_(y.prevState,y.payload);y.nextState=C,C!==e&&(e=C,i())}}K()}const f=s&&s.length>0?u:l;function h(p){return o.add(p),()=>{o.delete(p)}}function m(p){return{store:c,selector:p}}const c={getState:r,dispatch:f,subscribe:h,select:m};return t.name&&(c.name=t.name),c}function yt(t,e){return(o,s)=>{s(),t.push({actionName:o.actionName,payload:o.payload,prevState:o.prevState,nextState:o.nextState??o.prevState,timestamp:Date.now()}),t.length>1/0&&t.splice(0,t.length-1/0)}}let gt=1;class Y{constructor(){S(this,"stores",new Map);S(this,"components",new Map);S(this,"listeners",new Set)}registerStore(e,n,o){const s=o||e.name||`store_${this.stores.size}`;this.stores.set(s,{store:e,history:n,name:s}),e.subscribe(()=>{this.emit({type:"action-dispatched",storeName:s})}),this.emit({type:"store-registered",storeName:s})}getStoreNames(){return Array.from(this.stores.keys())}getStoreState(e){var n;return(n=this.stores.get(e))==null?void 0:n.store.getState()}getTrackedStore(e){return this.stores.get(e)}getHistory(e){var o;if(e)return((o=this.stores.get(e))==null?void 0:o.history)??[];const n=[];for(const s of this.stores.values())n.push(...s.history);return n.sort((s,r)=>s.timestamp-r.timestamp)}trackComponent(e,n){const o=gt++;return this.components.set(o,{id:o,displayName:e,storeNames:n}),this.emit({type:"component-mounted",data:{id:o,displayName:e,storeNames:n}}),o}untrackComponent(e){const n=this.components.get(e);n&&(this.components.delete(e),this.emit({type:"component-unmounted",data:{id:e,displayName:n.displayName}}))}getComponents(){return Array.from(this.components.values())}on(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}emit(e){for(const n of this.listeners)n(e)}}function St(t,e){const n=[],o=yt(n),s=Q({...e,middleware:[o,...e.middleware||[]]});return t.registerStore(s,n,e.name),{store:s,history:n}}const B=Symbol("TEXT_NODE"),bt=Symbol("FRAGMENT");function z(t){return{type:B,props:{nodeValue:String(t)},children:[],key:null}}function _t(t){return t==null||typeof t=="boolean"?null:typeof t=="string"||typeof t=="number"?z(t):t}function Z(t){const e=[];for(const n of t)if(Array.isArray(n))e.push(...Z(n));else{const o=_t(n);o!==null&&e.push(o)}return e}function a(t,e,...n){e=e||{};const o=e.key??null;e.key!==void 0&&(e={...e},delete e.key);const s=Z(n);return{type:t,props:e,children:s,key:o}}const g={CREATE:"CREATE",REMOVE:"REMOVE",REPLACE:"REPLACE",UPDATE:"UPDATE",TEXT:"TEXT",MOVE:"MOVE",CHILDREN:"CHILDREN"};function x(t,e){if(e==null&&t==null)return[];if(e==null)return[{type:g.REMOVE,target:t}];if(t==null)return[{type:g.CREATE,newVNode:e}];if(t.type!==e.type)return[{type:g.REPLACE,oldVNode:t,newVNode:e}];if(e._dom=t._dom,t.type===B)return t.props.nodeValue!==e.props.nodeValue?[{type:g.TEXT,oldVNode:t,newVNode:e}]:[];const n=[],o=xt(t.props,e.props);o&&n.push({type:g.UPDATE,target:t,propPatches:o});const s=Et(t.children,e.children);return s.length&&n.push({type:g.CHILDREN,parent:t,childPatches:s}),n}function xt(t,e){const n={},o=[];let s=!1;for(const r in e)r!=="children"&&t[r]!==e[r]&&(n[r]=e[r],s=!0);for(const r in t)r!=="children"&&(r in e||(o.push(r),s=!0));return s?{set:n,remove:o}:null}function L(t,e){return t==null||e==null?!1:t.type===e.type&&t.key===e.key}function W(t,e){const n=new Set;let o=0,s=0;for(const r of t)r!=null&&(r.key!=null?(o++,n.has(r.key)&&console.warn(`[pulse] Duplicate key "${String(r.key)}" in ${e} children. Keys must be unique among siblings.`),n.add(r.key)):s++);o>0&&s>0&&console.warn(`[pulse] Mixed keyed and unkeyed children in ${e} list (${o} keyed, ${s} unkeyed). Either all children should have keys or none should.`)}function Et(t,e){var m;process.env.NODE_ENV!=="production"&&(W(t,"old"),W(e,"new"));const n=[];let o=0,s=t.length-1,r=0,i=e.length-1,l=t[o],u=t[s],f=e[r],h=e[i];for(;o<=s&&r<=i;){if(l==null){l=t[++o];continue}if(u==null){u=t[--s];continue}if(L(l,f))n.push(...x(l,f)),l=t[++o],f=e[++r];else if(L(u,h))n.push(...x(u,h)),u=t[--s],h=e[--i];else if(L(l,h))n.push({type:g.MOVE,vnode:l,anchor:t[s+1]||null,childPatches:x(l,h)}),l=t[++o],h=e[--i];else if(L(u,f))n.push({type:g.MOVE,vnode:u,anchor:l,childPatches:x(u,f)}),u=t[--s],f=e[++r];else break}if(o<=s&&r<=i){const c=new Map;for(let p=o;p<=s;p++){const b=(m=t[p])==null?void 0:m.key;b!=null&&c.set(b,p)}for(;r<=i;){f=e[r];const p=f.key!=null?c.get(f.key):void 0;if(p!==void 0){const b=t[p];n.push({type:g.MOVE,vnode:b,anchor:t[o]||null,childPatches:x(b,f)}),t[p]=null,c.delete(f.key)}else n.push({type:g.CREATE,newVNode:f,anchor:t[o]||null});r++}for(let p=o;p<=s;p++)t[p]!=null&&n.push({type:g.REMOVE,target:t[p]})}if(o>s){const c=e[i+1]||null;for(let p=r;p<=i;p++)n.push({type:g.CREATE,newVNode:e[p],anchor:c})}else if(r>i)for(let c=o;c<=s;c++)t[c]!=null&&n.push({type:g.REMOVE,target:t[c]});return n}const tt="http://www.w3.org/2000/svg";function P(t,e){if(t.type===B){const o=document.createTextNode(t.props.nodeValue);return t._dom=o,o}if(t.type===bt){const o=document.createDocumentFragment();for(const s of t.children)o.appendChild(P(s,e));return t._dom=o,o}t.type==="svg"?e=tt:t.type==="foreignObject"&&(e=void 0);const n=e?document.createElementNS(e,t.type):document.createElement(t.type);kt(n,{},t.props);for(const o of t.children)n.appendChild(P(o,e));return t._dom=n,n}function kt(t,e,n){for(const o in e)o==="children"||o==="key"||o in n||nt(t,o,e[o]);for(const o in n)o==="children"||o==="key"||e[o]!==n[o]&&et(t,o,n[o],e[o])}function et(t,e,n,o){if(e.startsWith("on")){const s=e.slice(2).toLowerCase();o&&t.removeEventListener(s,o),n&&t.addEventListener(s,n)}else if(e==="className"||e==="class")t instanceof SVGElement?t.setAttribute("class",n||""):t.className=n||"";else if(e==="style"&&typeof n=="object"){if(typeof o=="object"&&o)for(const s in o)s in n||(t.style[s]="");Object.assign(t.style,n)}else if(e==="dangerouslySetInnerHTML")n&&typeof n.__html=="string"&&(t.innerHTML=n.__html);else if(e==="ref")typeof n=="function"&&n(t);else if(e in t&&!(t instanceof SVGElement))try{t[e]=n??""}catch{t.setAttribute(e,n)}else n===!0?t.setAttribute(e,""):n===!1||n==null?t.removeAttribute(e):t.setAttribute(e,n)}function nt(t,e,n){if(e.startsWith("on"))t.removeEventListener(e.slice(2).toLowerCase(),n);else if(e==="dangerouslySetInnerHTML")t.innerHTML="";else if(e==="className"||e==="class")t instanceof SVGElement?t.removeAttribute("class"):t.className="";else if(e in t&&!(t instanceof SVGElement))try{t[e]=""}catch{t.removeAttribute(e)}else t.removeAttribute(e)}function X(t){return t instanceof SVGElement?tt:void 0}function v(t,e){var n,o,s;for(const r of e)switch(r.type){case g.CREATE:{const i=P(r.newVNode,X(t));(n=r.anchor)!=null&&n._dom?t.insertBefore(i,r.anchor._dom):t.appendChild(i);break}case g.REMOVE:{const i=r.target._dom;i!=null&&i.parentNode&&i.parentNode.removeChild(i);break}case g.REPLACE:{const i=r.oldVNode._dom,l=i==null?void 0:i.parentNode,u=P(r.newVNode,l?X(l):void 0);l&&l.replaceChild(u,i);break}case g.UPDATE:{const i=r.target._dom,{set:l,remove:u}=r.propPatches;for(const f of u)nt(i,f,r.target.props[f]);for(const f in l)et(i,f,l[f],r.target.props[f]);break}case g.TEXT:{const i=r.oldVNode._dom;i&&(i.nodeValue=r.newVNode.props.nodeValue);break}case g.MOVE:{const i=r.vnode._dom;i&&((o=r.anchor)!=null&&o._dom?t.insertBefore(i,r.anchor._dom):t.appendChild(i)),(s=r.childPatches)!=null&&s.length&&i&&v(i,r.childPatches);break}case g.CHILDREN:{const i=r.parent._dom;i&&r.childPatches.length&&v(i,r.childPatches);break}}}const A=new WeakMap;function Tt(t,e){const n=A.get(e);if(n){const o=E(t,e),s=[];I(n.vTree,s);const r=x(n.vTree,o);v(e,r);const i=[];o&&I(o,i);const l=new Set(i);for(const f of s)l.has(f)||f.unmount();const u=new Set(s);for(const f of i)u.has(f)||f.mount(e,()=>U(f,e));A.set(e,{vTree:o})}else{const o=E(t,e);if(!o)return;const s=P(o);e.appendChild(s);const r=[];I(o,r);for(const i of r)i.mount(e,()=>U(i,e));A.set(e,{vTree:o})}}function E(t,e){var n;if(t==null)return null;if(typeof t.type=="function"){if(t.type[J]){const s=t.type._lifecycle;try{const r=new ht(t.type,t.props),i=r.getLocalProps(),l=i?{...t.props,...i}:t.props,u=t.type(l),h=E(u,e)??z("");if(h._instance){const m={type:"div",props:{style:{display:"contents"}},children:[h],key:t.key};return m._instance=r,r.lastVTree=m,m}return h._instance=r,r.lastVTree=h,h}catch(r){if(s!=null&&s.onError){const i=s.onError({error:r,props:t.props});return E(i,e)}throw r}}const o=t.type({...t.props,children:t.children});return E(o,e)}return(n=t.children)!=null&&n.length&&(t.children=t.children.map(o=>E(o,e)).filter(o=>o!=null)),t}function U(t,e){var s,r;if(!t._renderCallback)return;const n=t.connectedFn,o=n._lifecycle;try{const i=t.getLocalProps(),l=i?{...t.props,...i}:t.props,u=n(l),h=E(u,e)??z("");let m;if(h._instance&&h._instance!==t?(m={type:"div",props:{style:{display:"contents"}},children:[h],key:null},m._instance=t):(h._instance=t,m=h),t.lastVTree){j(t.lastVTree,t);const y=x(t.lastVTree,m),k=((s=t.lastVTree._dom)==null?void 0:s.parentNode)||e;v(k,y),m._dom||(m._dom=t.lastVTree._dom)}const c=[];$(t.lastVTree,c,t);const p=[];$(m,p,t);const b=new Set(p);for(const y of c)b.has(y)||y.unmount();t.lastVTree=m;const _=new Set(c);for(const y of p)_.has(y)||y.mount(e,()=>U(y,e));o!=null&&o.onUpdate&&o.onUpdate({dom:m==null?void 0:m._dom,props:t.props}),t.updateSelected()}catch(i){if(o!=null&&o.onError){const l=o.onError({error:i,props:t.props}),u=E(l,e);if(t.lastVTree&&u){j(t.lastVTree,t);const h=x(t.lastVTree,u),m=((r=t.lastVTree._dom)==null?void 0:r.parentNode)||e;v(m,h),u._dom||(u._dom=t.lastVTree._dom)}const f=[];$(t.lastVTree,f,t);for(const h of f)h.unmount();t.lastVTree=u,t.updateSelected()}else throw i}}function j(t,e){if(!(!t||!t.children))for(let n=0;n<t.children.length;n++){const o=t.children[n];o._instance&&o._instance!==e&&o._instance.lastVTree&&o._instance.lastVTree!==o&&(t.children[n]=o._instance.lastVTree),j(t.children[n],e)}}function I(t,e){if(t&&(t._instance&&e.push(t._instance),t.children))for(const n of t.children)I(n,e)}function $(t,e,n){if(t&&(t._instance&&t._instance!==n&&e.push(t._instance),t.children))for(const o of t.children)$(o,e,n)}function H(t,e,n){const o=t.getTrackedStore(e);if(!o)throw new Error(`[pulse-devtools] Unknown store: "${e}"`);const{store:s,history:r}=o;if(n<0||n>=r.length)throw new Error(`[pulse-devtools] Index ${n} out of range (0..${r.length-1})`);const i=r[n].nextState;s.dispatch("__devtools_replace__",i),t.emit({type:"time-travel",storeName:e,data:{entryIndex:n}})}function wt(t,e,n){const o=t.getTrackedStore(e);if(!o)throw new Error(`[pulse-devtools] Unknown store: "${e}"`);const{store:s,history:r}=o;if(n<0||n>=r.length)throw new Error(`[pulse-devtools] Index ${n} out of range (0..${r.length-1})`);const i=r.slice(n),l=r[n].prevState;s.dispatch("__devtools_replace__",l);for(const u of i)s.dispatch(u.actionName,u.payload);t.emit({type:"time-travel",storeName:e,data:{replayFrom:n}})}const d={base:"#1e1e2e",surface0:"#313244",surface1:"#45475a",overlay0:"#6c7086",text:"#cdd6f4",subtext0:"#a6adc8",blue:"#89b4fa",green:"#a6e3a1",yellow:"#f9e2af",mauve:"#cba6f7",teal:"#94e2d5",peach:"#fab387"},Ct={position:"fixed",bottom:"0",left:"0",right:"0",height:"320px",backgroundColor:d.base,color:d.text,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace",fontSize:"12px",lineHeight:"1.5",zIndex:"2147483647",display:"flex",flexDirection:"column",borderTop:`2px solid ${d.mauve}`,overflow:"hidden"},Nt={display:"flex",alignItems:"center",backgroundColor:d.surface0,borderBottom:`1px solid ${d.surface1}`,padding:"0 8px",height:"32px",flexShrink:"0"},Pt=t=>({background:"none",border:"none",color:t?d.mauve:d.subtext0,fontFamily:"inherit",fontSize:"12px",padding:"6px 12px",cursor:"pointer",borderBottom:t?`2px solid ${d.mauve}`:"2px solid transparent",marginBottom:"-1px"}),vt={background:"none",border:"none",color:d.overlay0,fontSize:"16px",cursor:"pointer",marginLeft:"auto",padding:"4px 8px",fontFamily:"inherit"},Vt={flex:"1",overflow:"auto",padding:"8px 12px"},Lt={display:"flex",height:"100%",gap:"1px"},Ot={width:"200px",flexShrink:"0",borderRight:`1px solid ${d.surface1}`,overflow:"auto",padding:"4px 0"},It={flex:"1",overflow:"auto",padding:"8px"},$t=t=>({padding:"4px 12px",cursor:"pointer",backgroundColor:t?d.surface1:"transparent",color:t?d.blue:d.text}),q={color:d.mauve},O={color:d.green},At={color:d.yellow},Mt={color:d.peach},w={color:d.overlay0,fontStyle:"italic"},Rt=t=>({padding:"4px 8px",cursor:"pointer",backgroundColor:t?d.surface1:"transparent",borderLeft:t?`3px solid ${d.blue}`:"3px solid transparent",display:"flex",justifyContent:"space-between",alignItems:"center"}),ot={color:d.blue,fontWeight:"bold"},Ft={color:d.overlay0,fontSize:"10px"},Ut={width:"100%",accentColor:d.mauve,margin:"4px 0 8px"},jt={width:"100%",backgroundColor:d.surface0,border:`1px solid ${d.surface1}`,color:d.text,padding:"4px 8px",fontFamily:"inherit",fontSize:"12px",borderRadius:"4px",outline:"none",marginBottom:"8px",boxSizing:"border-box"},Ht={padding:"4px 8px",borderBottom:`1px solid ${d.surface0}`},Dt={color:d.teal,fontWeight:"bold"},Bt={color:d.overlay0,fontSize:"10px",marginLeft:"8px"},st={display:"inline-block",backgroundColor:d.surface1,color:d.subtext0,padding:"1px 6px",borderRadius:"8px",fontSize:"10px",marginLeft:"4px"},zt={color:d.mauve,fontWeight:"bold",fontSize:"12px",marginRight:"8px"};function D(t,e){if(t===null)return a("span",{style:w},"null");if(t===void 0)return a("span",{style:w},"undefined");if(typeof t=="string")return a("span",{style:At},`"${t}"`);if(typeof t=="boolean")return a("span",{style:Mt},String(t));if(typeof t=="number")return a("span",{style:O},String(t));if(Array.isArray(t))return t.length===0?a("span",{style:O},"[]"):e>4?a("span",{style:w},"[…]"):a("div",{style:{paddingLeft:"12px"}},...t.map((n,o)=>a("div",{key:o},a("span",{style:q},`${o}: `),D(n,e+1))));if(typeof t=="object"){const n=Object.keys(t);return n.length===0?a("span",{style:O},"{}"):e>4?a("span",{style:w},"{…}"):a("div",{style:{paddingLeft:"12px"}},...n.map(o=>a("div",{key:o},a("span",{style:q},`${o}: `),D(t[o],e+1))))}return a("span",{style:O},String(t))}function Kt({storeNames:t,selectedStore:e,storeStates:n,onSelectStore:o}){const s=e?n[e]:null;return a("div",{style:Lt},a("div",{style:Ot},...t.map(r=>a("div",{key:r,style:$t(r===e),onClick:()=>o(r)},r))),a("div",{style:It},e?a("div",null,a("div",{style:{marginBottom:"8px",color:d.subtext0}},"State of ",a("span",{style:ot},e)),s!=null?D(s,0):a("span",{style:w},"No state")):a("span",{style:w},"Select a store")))}function Gt(t){const e=new Date(t),n=o=>String(o).padStart(2,"0");return`${n(e.getHours())}:${n(e.getMinutes())}:${n(e.getSeconds())}`}function Wt({actionLog:t,timeTravelIndex:e,filter:n,onFilterChange:o,onTravelTo:s,onSliderChange:r}){const i=n?t.filter(l=>l.actionName.toLowerCase().includes(n.toLowerCase())):t;return a("div",{style:{height:"100%",display:"flex",flexDirection:"column"}},a("input",{style:jt,placeholder:"Filter actions…",value:n,onInput:l=>o(l.target.value)}),t.length>0?a("div",{style:{flexShrink:"0"}},a("input",{type:"range",style:Ut,min:"0",max:String(t.length-1),value:String(e),onInput:l=>r(Number(l.target.value))}),a("div",{style:{color:d.overlay0,fontSize:"10px",marginBottom:"4px"}},`${e+1} / ${t.length}`)):null,a("div",{style:{flex:"1",overflow:"auto"}},...i.map(l=>{const u=t.indexOf(l);return a("div",{key:u,style:Rt(u===e),onClick:()=>s(u)},a("span",null,a("span",{style:ot},l.actionName),l.payload!==void 0?a("span",{style:{color:d.subtext0,marginLeft:"8px"}},typeof l.payload=="object"?JSON.stringify(l.payload):String(l.payload)):null),a("span",{style:Ft},Gt(l.timestamp)))}),i.length===0?a("div",{style:{color:d.overlay0,padding:"8px"}},t.length===0?"No actions yet":"No matching actions"):null))}function Xt({components:t}){return t.length===0?a("div",{style:{color:d.overlay0,padding:"8px"}},"No connected components mounted"):a("div",null,...t.map(e=>a("div",{key:e.id,style:Ht},a("span",{style:Dt},e.displayName),e.storeNames.length>0?a("span",{style:Bt},e.storeNames.map(n=>a("span",{key:n,style:st},n))):null)))}function qt(){return Q({state:{open:!1,activeTab:"stores",selectedStore:null,timeTravelIndex:-1,storeNames:[],storeStates:{},actionLog:[],filter:"",components:[]},actions:{toggle:t=>({...t,open:!t.open}),open:t=>({...t,open:!0}),close:t=>({...t,open:!1}),setTab:(t,e)=>({...t,activeTab:e}),selectStore:(t,e)=>({...t,selectedStore:e}),setFilter:(t,e)=>({...t,filter:e}),setTimeTravelIndex:(t,e)=>({...t,timeTravelIndex:e}),sync:(t,e)=>({...t,...e})}})}function Jt({open:t,activeTab:e,selectedStore:n,timeTravelIndex:o,storeNames:s,storeStates:r,actionLog:i,filter:l,components:u,panelActions:f}){if(!t)return null;const h=[{id:"stores",label:"Stores"},{id:"actions",label:"Actions"},{id:"components",label:"Components"}];let m;return e==="stores"?m=Kt({storeNames:s,selectedStore:n,storeStates:r,onSelectStore:f.selectStore}):e==="actions"?m=Wt({actionLog:i,timeTravelIndex:o,filter:l,onFilterChange:f.setFilter,onTravelTo:f.travelTo,onSliderChange:f.sliderChange}):m=Xt({components:u}),a("div",{style:Ct},a("div",{style:Nt},a("span",{key:"title",style:zt},"Pulse"),...h.map(c=>a("button",{key:c.id,style:Pt(c.id===e),onClick:()=>f.setTab(c.id)},c.label)),a("span",{key:"badge",style:st},`${s.length} stores`),a("button",{key:"close",style:vt,onClick:f.close},"×")),a("div",{style:Vt},m))}function Qt(t,e){const n=qt();e&&e(n);let o=!1;function s(){if(!o){o=!0;try{const c=t.getStoreNames(),p={};for(const k of c)p[k]=t.getStoreState(k);const _=n.getState().selectedStore||c[0]||null,y=_?t.getHistory(_):[];n.dispatch("sync",{storeNames:c,storeStates:p,actionLog:y,timeTravelIndex:y.length>0?y.length-1:-1,selectedStore:_,components:t.getComponents()})}finally{o=!1}}}t.on(c=>{c.type==="component-mounted"||c.type==="component-unmounted"||s()});const r={selectStore:c=>{n.dispatch("selectStore",c);const p=t.getHistory(c);n.dispatch("sync",{actionLog:p,timeTravelIndex:p.length>0?p.length-1:-1})},setTab:c=>n.dispatch("setTab",c),setFilter:c=>n.dispatch("setFilter",c),close:()=>n.dispatch("close"),travelTo:c=>{const p=n.getState().selectedStore;p&&(H(t,p,c),n.dispatch("setTimeTravelIndex",c))},sliderChange:c=>{const p=n.getState().selectedStore;p&&(H(t,p,c),n.dispatch("setTimeTravelIndex",c))}},i=dt({open:n.select(c=>c.open),activeTab:n.select(c=>c.activeTab),selectedStore:n.select(c=>c.selectedStore),timeTravelIndex:n.select(c=>c.timeTravelIndex),storeNames:n.select(c=>c.storeNames),storeStates:n.select(c=>c.storeStates),actionLog:n.select(c=>c.actionLog),filter:n.select(c=>c.filter),components:n.select(c=>c.components)})(c=>Jt({...c,panelActions:r}));let l=null;function u(){l||(l=document.createElement("div"),l.id="pulse-devtools-root",document.body.appendChild(l),Tt(a(i,null),l),s())}function f(){u(),n.dispatch("open")}function h(){n.dispatch("close")}function m(){u(),n.dispatch("toggle")}return{openPanel:f,closePanel:h,togglePanel:m,panelStore:n}}const V=new Y,rt=new WeakSet;function it(t){rt.add(t)}ft(t=>{const e=t.connectedFn._bindings||{},n=Object.values(e).map(i=>i.store);if(n.length>0&&n.every(i=>rt.has(i)))return;const o=n.map(i=>i.name||"unnamed"),s=t.connectedFn.displayName||"Unknown",r=V.trackComponent(s,o);t._devtoolsId=r},t=>{const e=t._devtoolsId;e!=null&&V.untrackComponent(e)});let N=null;function ct(){return N||(N=Qt(V,it)),N}function Yt(){ct().openPanel()}function Zt(){N&&N.closePanel()}function lt(){ct().togglePanel()}typeof window<"u"&&(window.addEventListener("keydown",t=>{t.ctrlKey&&t.shiftKey&&t.key==="P"&&(t.preventDefault(),lt())}),window.__PULSE_DEVTOOLS__=V);exports.PulseDevtools=Y;exports._markInternalStore=it;exports.closePanel=Zt;exports.devtools=V;exports.instrumentStore=St;exports.openPanel=Yt;exports.replayFrom=wt;exports.togglePanel=lt;exports.travelTo=H;
|
|
2
2
|
//# sourceMappingURL=devtools.cjs.map
|