@fluixi/dom 1.0.0-alpha.53
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/LICENSE +21 -0
- package/README.md +657 -0
- package/dist/cdn/dom.cjs +1 -0
- package/dist/cdn/dom.d.ts +16 -0
- package/dist/cdn/dom.d.ts.map +1 -0
- package/dist/cdn/dom.global.js +1 -0
- package/dist/cdn/dom.js +15 -0
- package/dist/cdn/dom.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/component/index.cjs +1 -0
- package/dist/lib/component/index.d.ts +2 -0
- package/dist/lib/component/index.d.ts.map +1 -0
- package/dist/lib/component/index.js +1 -0
- package/dist/lib/component/index.mjs +1 -0
- package/dist/lib/component/modifiers.cjs +1 -0
- package/dist/lib/component/modifiers.d.ts +21 -0
- package/dist/lib/component/modifiers.d.ts.map +1 -0
- package/dist/lib/component/modifiers.js +171 -0
- package/dist/lib/component/modifiers.mjs +1 -0
- package/dist/lib/dom/delegate.cjs +1 -0
- package/dist/lib/dom/delegate.d.ts +17 -0
- package/dist/lib/dom/delegate.d.ts.map +1 -0
- package/dist/lib/dom/delegate.js +50 -0
- package/dist/lib/dom/delegate.mjs +1 -0
- package/dist/lib/dom/hydration-state.cjs +1 -0
- package/dist/lib/dom/hydration-state.d.ts +45 -0
- package/dist/lib/dom/hydration-state.d.ts.map +1 -0
- package/dist/lib/dom/hydration-state.js +94 -0
- package/dist/lib/dom/hydration-state.mjs +1 -0
- package/dist/lib/dom/hydration.cjs +1 -0
- package/dist/lib/dom/hydration.d.ts +10 -0
- package/dist/lib/dom/hydration.d.ts.map +1 -0
- package/dist/lib/dom/hydration.js +143 -0
- package/dist/lib/dom/hydration.mjs +1 -0
- package/dist/lib/dom/index.cjs +1 -0
- package/dist/lib/dom/index.d.ts +9 -0
- package/dist/lib/dom/index.d.ts.map +1 -0
- package/dist/lib/dom/index.js +12 -0
- package/dist/lib/dom/index.mjs +1 -0
- package/dist/lib/dom/integration.cjs +1 -0
- package/dist/lib/dom/integration.d.ts +16 -0
- package/dist/lib/dom/integration.d.ts.map +1 -0
- package/dist/lib/dom/integration.js +25 -0
- package/dist/lib/dom/integration.mjs +1 -0
- package/dist/lib/dom/island.cjs +1 -0
- package/dist/lib/dom/island.d.ts +23 -0
- package/dist/lib/dom/island.d.ts.map +1 -0
- package/dist/lib/dom/island.js +100 -0
- package/dist/lib/dom/island.mjs +1 -0
- package/dist/lib/dom/runtime.cjs +1 -0
- package/dist/lib/dom/runtime.d.ts +131 -0
- package/dist/lib/dom/runtime.d.ts.map +1 -0
- package/dist/lib/dom/runtime.js +1425 -0
- package/dist/lib/dom/runtime.mjs +1 -0
- package/dist/lib/dom/server/fx-data.cjs +1 -0
- package/dist/lib/dom/server/fx-data.d.ts +36 -0
- package/dist/lib/dom/server/fx-data.d.ts.map +1 -0
- package/dist/lib/dom/server/fx-data.js +60 -0
- package/dist/lib/dom/server/fx-data.mjs +1 -0
- package/dist/lib/dom/server/host.cjs +1 -0
- package/dist/lib/dom/server/host.d.ts +14 -0
- package/dist/lib/dom/server/host.d.ts.map +1 -0
- package/dist/lib/dom/server/host.js +38 -0
- package/dist/lib/dom/server/host.mjs +1 -0
- package/dist/lib/dom/server/index.cjs +1 -0
- package/dist/lib/dom/server/index.d.ts +13 -0
- package/dist/lib/dom/server/index.d.ts.map +1 -0
- package/dist/lib/dom/server/index.js +12 -0
- package/dist/lib/dom/server/index.mjs +1 -0
- package/dist/lib/dom/server/nodes.cjs +1 -0
- package/dist/lib/dom/server/nodes.d.ts +105 -0
- package/dist/lib/dom/server/nodes.d.ts.map +1 -0
- package/dist/lib/dom/server/nodes.js +304 -0
- package/dist/lib/dom/server/nodes.mjs +1 -0
- package/dist/lib/dom/server/render.cjs +1 -0
- package/dist/lib/dom/server/render.d.ts +45 -0
- package/dist/lib/dom/server/render.d.ts.map +1 -0
- package/dist/lib/dom/server/render.js +174 -0
- package/dist/lib/dom/server/render.mjs +1 -0
- package/dist/lib/dom/server/request-context.cjs +1 -0
- package/dist/lib/dom/server/request-context.d.ts +85 -0
- package/dist/lib/dom/server/request-context.d.ts.map +1 -0
- package/dist/lib/dom/server/request-context.js +122 -0
- package/dist/lib/dom/server/request-context.mjs +1 -0
- package/dist/lib/dom/server/serialize.cjs +1 -0
- package/dist/lib/dom/server/serialize.d.ts +2 -0
- package/dist/lib/dom/server/serialize.d.ts.map +1 -0
- package/dist/lib/dom/server/serialize.js +98 -0
- package/dist/lib/dom/server/serialize.mjs +1 -0
- package/dist/lib/dom/server-renderer.cjs +1 -0
- package/dist/lib/dom/server-renderer.d.ts +2 -0
- package/dist/lib/dom/server-renderer.d.ts.map +1 -0
- package/dist/lib/dom/server-renderer.js +5 -0
- package/dist/lib/dom/server-renderer.mjs +1 -0
- package/dist/lib/dom/types.cjs +1 -0
- package/dist/lib/dom/types.d.ts +119 -0
- package/dist/lib/dom/types.d.ts.map +1 -0
- package/dist/lib/dom/types.js +1 -0
- package/dist/lib/dom/types.mjs +0 -0
- package/dist/lib/dom/utils.cjs +1 -0
- package/dist/lib/dom/utils.d.ts +411 -0
- package/dist/lib/dom/utils.d.ts.map +1 -0
- package/dist/lib/dom/utils.js +746 -0
- package/dist/lib/dom/utils.mjs +1 -0
- package/dist/lib/element/index.cjs +1 -0
- package/dist/lib/element/index.d.ts +2 -0
- package/dist/lib/element/index.d.ts.map +1 -0
- package/dist/lib/element/index.js +1 -0
- package/dist/lib/element/index.mjs +0 -0
- package/dist/lib/element/types.cjs +1 -0
- package/dist/lib/element/types.d.ts +129 -0
- package/dist/lib/element/types.d.ts.map +1 -0
- package/dist/lib/element/types.js +5 -0
- package/dist/lib/element/types.mjs +0 -0
- package/dist/lib/flow/class-map.cjs +1 -0
- package/dist/lib/flow/class-map.d.ts +40 -0
- package/dist/lib/flow/class-map.d.ts.map +1 -0
- package/dist/lib/flow/class-map.js +44 -0
- package/dist/lib/flow/class-map.mjs +1 -0
- package/dist/lib/flow/dynamic.cjs +1 -0
- package/dist/lib/flow/dynamic.d.ts +27 -0
- package/dist/lib/flow/dynamic.d.ts.map +1 -0
- package/dist/lib/flow/dynamic.js +30 -0
- package/dist/lib/flow/dynamic.mjs +1 -0
- package/dist/lib/flow/error-boundary.cjs +1 -0
- package/dist/lib/flow/error-boundary.d.ts +34 -0
- package/dist/lib/flow/error-boundary.d.ts.map +1 -0
- package/dist/lib/flow/error-boundary.js +49 -0
- package/dist/lib/flow/error-boundary.mjs +1 -0
- package/dist/lib/flow/for.cjs +1 -0
- package/dist/lib/flow/for.d.ts +64 -0
- package/dist/lib/flow/for.d.ts.map +1 -0
- package/dist/lib/flow/for.js +28 -0
- package/dist/lib/flow/for.mjs +1 -0
- package/dist/lib/flow/index-flow.cjs +1 -0
- package/dist/lib/flow/index-flow.d.ts +34 -0
- package/dist/lib/flow/index-flow.d.ts.map +1 -0
- package/dist/lib/flow/index-flow.js +27 -0
- package/dist/lib/flow/index-flow.mjs +1 -0
- package/dist/lib/flow/index.cjs +1 -0
- package/dist/lib/flow/index.d.ts +20 -0
- package/dist/lib/flow/index.d.ts.map +1 -0
- package/dist/lib/flow/index.js +11 -0
- package/dist/lib/flow/index.mjs +1 -0
- package/dist/lib/flow/portal.cjs +1 -0
- package/dist/lib/flow/portal.d.ts +30 -0
- package/dist/lib/flow/portal.d.ts.map +1 -0
- package/dist/lib/flow/portal.js +44 -0
- package/dist/lib/flow/portal.mjs +1 -0
- package/dist/lib/flow/show.cjs +1 -0
- package/dist/lib/flow/show.d.ts +35 -0
- package/dist/lib/flow/show.d.ts.map +1 -0
- package/dist/lib/flow/show.js +162 -0
- package/dist/lib/flow/show.mjs +1 -0
- package/dist/lib/flow/style-map.cjs +1 -0
- package/dist/lib/flow/style-map.d.ts +49 -0
- package/dist/lib/flow/style-map.d.ts.map +1 -0
- package/dist/lib/flow/style-map.js +58 -0
- package/dist/lib/flow/style-map.mjs +1 -0
- package/dist/lib/flow/switch.cjs +1 -0
- package/dist/lib/flow/switch.d.ts +63 -0
- package/dist/lib/flow/switch.d.ts.map +1 -0
- package/dist/lib/flow/switch.js +69 -0
- package/dist/lib/flow/switch.mjs +1 -0
- package/dist/lib/flow/utils.cjs +1 -0
- package/dist/lib/flow/utils.d.ts +19 -0
- package/dist/lib/flow/utils.d.ts.map +1 -0
- package/dist/lib/flow/utils.js +34 -0
- package/dist/lib/flow/utils.mjs +1 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.ts +21 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +30 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/jsx/control-flow/flow.cjs +1 -0
- package/dist/lib/jsx/control-flow/flow.d.ts +2 -0
- package/dist/lib/jsx/control-flow/flow.d.ts.map +1 -0
- package/dist/lib/jsx/control-flow/flow.js +627 -0
- package/dist/lib/jsx/control-flow/flow.mjs +0 -0
- package/dist/lib/jsx/control-flow/for-flow.cjs +1 -0
- package/dist/lib/jsx/control-flow/for-flow.d.ts +2 -0
- package/dist/lib/jsx/control-flow/for-flow.d.ts.map +1 -0
- package/dist/lib/jsx/control-flow/for-flow.js +1 -0
- package/dist/lib/jsx/control-flow/for-flow.mjs +0 -0
- package/dist/lib/shared/types.cjs +1 -0
- package/dist/lib/shared/types.d.ts +47 -0
- package/dist/lib/shared/types.d.ts.map +1 -0
- package/dist/lib/shared/types.js +1 -0
- package/dist/lib/shared/types.mjs +0 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { indexArray } from '@fluixi/reactive/signal';
|
|
2
|
+
import { resolveReactiveProp } from './utils.js';
|
|
3
|
+
import { hydrateAdvancePast } from '../dom/hydration-state.js';
|
|
4
|
+
/**
|
|
5
|
+
* Non-keyed list rendering — mirrors SolidJS `<Index>`.
|
|
6
|
+
*
|
|
7
|
+
* Keyed by position. When the list grows, new slots are created.
|
|
8
|
+
* When it shrinks, trailing slots are disposed. When an item at a
|
|
9
|
+
* given index changes value, only the `item` signal updates (no re-render).
|
|
10
|
+
* Returns a memo of the rendered array — works in both JSX and lit-html.
|
|
11
|
+
*
|
|
12
|
+
* @example JSX
|
|
13
|
+
* <Index each={items()} fallback={<p>Empty</p>}>
|
|
14
|
+
* {(item, index) => <li>{index} — {item().name}</li>}
|
|
15
|
+
* </Index>
|
|
16
|
+
*
|
|
17
|
+
* @example lit-html
|
|
18
|
+
* Index({ each: items, children: (item, i) => html`<li>${i} — ${item().name}</li>` })
|
|
19
|
+
*/
|
|
20
|
+
export function Index(props) {
|
|
21
|
+
const each = resolveReactiveProp(() => props.each);
|
|
22
|
+
return indexArray(each, (item, index) => {
|
|
23
|
+
const rendered = props.children(item, index);
|
|
24
|
+
hydrateAdvancePast(rendered); // ascend cursor past this item (hydration)
|
|
25
|
+
return rendered;
|
|
26
|
+
}, { fallback: () => props.fallback ?? null });
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{indexArray as l}from"@fluixi/reactive/signal";function o(r){return()=>{let e=r();return typeof e=="function"?e():e}}var t={active:!1,cursor:null,parents:[]};function c(r){let e=t.parents.lastIndexOf(r);e!==-1&&(t.parents.length=e),t.cursor=r.nextSibling}function a(r){if(!t.active||r==null)return;let e=Array.isArray(r)?r[r.length-1]:r;e&&typeof e.nodeType=="number"&&c(e)}function x(r){let e=o(()=>r.each);return l(e,(s,i)=>{let n=r.children(s,i);return a(n),n},{fallback:()=>r.fallback??null})}export{x as Index};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var j=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var he=(e,n)=>{for(var t in n)j(e,t,{get:n[t],enumerable:!0})},me=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of ye(n))!pe.call(e,a)&&a!==t&&j(e,a,{get:()=>n[a],enumerable:!(o=de(n,a))||o.enumerable});return e};var xe=e=>me(j({},"__esModule",{value:!0}),e);var Ee={};he(Ee,{Dynamic:()=>J,ErrorBoundary:()=>se,For:()=>V,Index:()=>B,Match:()=>z,Portal:()=>ie,Show:()=>I,Switch:()=>G,classMap:()=>ae,indexArray:()=>w.indexArray,keyArray:()=>w.keyArray,mapArray:()=>w.mapArray,styleMap:()=>le});module.exports=xe(Ee);var N=require("@fluixi/reactive/signal");function U(e){return typeof e=="function"?e:(()=>e)}function x(e){return()=>{let n=e();return typeof n=="function"?n():n}}function H(e){return e!=null&&e!==!1}function O(e){return!e||typeof e!="object"?!1:!!(typeof e._$litType$<"u"||typeof e._$litDirective$<"u"||Array.isArray(e.strings)&&Array.isArray(e.values))}function I(e){let n=x(()=>e.when),t=(0,N.createMemo)(n,void 0),o=(0,N.createMemo)(t,void 0);return(0,N.createMemo)(()=>{if(o()){let s=e.children;return typeof s=="function"&&!O(s)?typeof t=="function"?(0,N.untrack)(()=>(0,N.untrack)(t)?s(t()):e.fallback):s(t):s}return e.fallback},void 0,{name:"show"})}var v=require("@fluixi/reactive/signal");var g={active:!1,cursor:null,parents:[]},ge=null;function K(){return ge}function $(e,n){return g.active&&n.parentNode===e}function F(e){let n=g.parents.lastIndexOf(e);n!==-1&&(g.parents.length=n),g.cursor=e.nextSibling}function P(e){if(!g.active||e==null)return;let n=Array.isArray(e)?e[e.length-1]:e;n&&typeof n.nodeType=="number"&&F(n)}function V(e){let n=x(()=>e.each),t=()=>e.fallback??null,o=(a,s)=>{let f=e.children,i=Array.isArray(f)?f.map(r=>typeof r=="function"?r(a,s):r):typeof f=="function"?f(a,s):f;return P(i),i};return e.by?(0,v.keyArray)(n,e.by,(a,s)=>o(a,s),{fallback:t}):(0,v.mapArray)(n,(a,s)=>o(a,s),{fallback:t})}var W=require("@fluixi/reactive/signal");function B(e){let n=x(()=>e.each);return(0,W.indexArray)(n,(t,o)=>{let a=e.children(t,o);return P(a),a},{fallback:()=>e.fallback??null})}var w=require("@fluixi/reactive/signal");var q=require("@fluixi/reactive/signal");var _=Symbol("match");function z(e){return{[_]:!0,when:x(()=>e.when),children:e.children}}function G(e){let n=Array.isArray(e.children)?e.children:[e.children];return(0,q.createMemo)(()=>{for(let t of n){let o=t,a=0;for(;typeof o=="function"&&!o[_]&&a++<10;)o=o();if(!o||typeof o!="object"||o[_]!==!0)continue;let s=o.when();if(H(s))return typeof o.children=="function"?o.children(s):o.children}return e.fallback??null})}var X=require("@fluixi/reactive/signal");function J(e){let n=U(e.component),{component:t,...o}=e;return(0,X.createMemo)(()=>{let a=n();return a==null?null:typeof a=="string"?{tag:a,props:o}:a(o)})}var R=require("@fluixi/reactive/signal");var p=require("@fluixi/reactive/signal");function A(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}var b=require("@fluixi/reactive/signal");var Z=typeof document>"u";var Q=Symbol.for("fluixi.server-node"),Y=null;function ee(){if(!Y)throw new Error("[fluixi] server render ran before @fluixi/dom/server loaded");return Y}function C(e){return e!=null&&e[Q]===!0?!0:typeof Node<"u"&&e instanceof Node}function ne(e){return e!=null&&e[Q]===!0?e.nodeType===3:typeof Text<"u"&&e instanceof Text}function T(e){if(Z)return ee().createText(e);if(g.active){let n=K()?.hydrateText(e);if(n)return n}return document.createTextNode(e)}var m=0,Te=200;function be(e,n,t,o,a){let s=o,f=new Map;return(0,b.createRenderEffect)(()=>{let i;if(A(e)&&!(0,p.isSignal)(e)){if(!f.has(e)){m++;try{let r=e();f.set(e,r)}finally{m--}}for(i=f.get(e);typeof i=="function"&&(0,p.isSignal)(i);)i=i()}else for(i=e();typeof i=="function"&&(0,p.isSignal)(i);)i=i();{let r=0;for(;typeof i=="function"&&r++<50;)if(A(i)){if(!f.has(i)){let c=i;m++;try{let l=c();f.set(c,l)}finally{m--}}i=f.get(i)}else if((0,p.isSignal)(i))i=i();else if(i=i(),typeof i!="function"||!(0,p.isSignal)(i)&&!A(i))break}m++;try{s=S(n,i,t,s,f),a(s)}finally{m--}})}function D(e,n,t,o){if(m>Te)return console.error("[insert] Exceeded max call depth — possible infinite loop."),()=>null;t!==void 0&&!t&&(t=T(""),e.appendChild(t));let a=o??null;if(typeof n!="function"){m++;try{a=S(e,n,t,null)}finally{m--}return()=>a}let s=be(n,e,t,a,f=>{a=f});return()=>(s?.(),a)}function S(e,n,t,o,a){if(n==null||typeof n=="boolean")return E(e,o,t);if(typeof n=="function")for(;typeof n=="function";)n=n();if(n==null||typeof n=="boolean")return E(e,o,t);if(M(n)){let f=T("");return Array.isArray(o)?o.length>0?(e.replaceChild(f,o[0]),E(e,o.slice(1),t)):y(e,f,t):o?e.replaceChild(f,o):y(e,f,t),n.then(i=>{f.parentNode===e&&S(e,i,f.nextSibling,f)}).catch(i=>{console.error("Error resolving promise in insertExpression:",i)}),f}let s=typeof n;if(s==="string"||s==="number"){if(s==="number"&&(n=String(n)),Array.isArray(o)){if(o.length===0){let i=T(n);return y(e,i,t),i}if(o.length===1&&o[0].nodeType===3)return o[0].data=n,o;o=E(e,o,t)}if(o&&ne(o))return o.data=n,o;let f=T(n);return o&&o.parentNode===e?e.replaceChild(f,o):$(e,f)||y(e,f,t),f}if(C(n))return $(e,n)?(F(n),n):Array.isArray(o)?(o.length===0?y(e,n,t):o[0].parentNode===e?(e.replaceChild(n,o[0]),E(e,o.slice(1),t)):y(e,n,t),n):(o?o!==n&&(o.parentNode===e?e.replaceChild(n,o):y(e,n,t)):y(e,n,t),n);if(Array.isArray(n)){let f=[],i=Array.isArray(o)?o:o?[o]:[],r=[];h(n,f,e,t,!0,a,r);let c=Ne(e,i,f,t);for(let l of r){let u=D(e,l.sig,l.marker);(0,b.onCleanup)(()=>{E(e,u()),l.marker.parentNode===e&&e.removeChild(l.marker)})}return c}if(s==="object"&&n!==null&&typeof n=="object"){let f=n;if("_$litType$"in f||"_$litDirective$"in f)return S(e,re(n),t,o);if("type"in f&&"props"in f){let i=f;if(typeof i.type=="function"){let r=i.type(i.props||{});return S(e,r,t,o)}}}return E(e,o,t)}function h(e,n,t,o,a=!0,s,f){for(let i=0;i<e.length;i++){let r=e[i];if(!(r==null||typeof r=="boolean")){for(;typeof r=="function"&&!M(r)&&!(0,p.isSignal)(r)&&!A(r)&&(r=r(),!(r==null||typeof r=="boolean")););if(!(r==null||typeof r=="boolean")){if(typeof r=="function"){let c;for(A(r)&&!(0,p.isSignal)(r)?(s||(s=new Map),s.has(r)||s.set(r,r()),c=s.get(r)):c=r();typeof c=="function"&&!M(c)&&!(0,p.isSignal)(c)&&!A(c);)s||(s=new Map),s.has(c)||s.set(c,c()),c=s.get(c);if(c==null||typeof c=="boolean")continue;if(typeof c=="function"){if((0,p.isSignal)(c)){if(f){let u=T("");n.push(u),f.push({marker:u,sig:c});continue}let l=c();for(;typeof l=="function"&&(0,p.isSignal)(l);)l=l();if(l==null||typeof l=="boolean")continue;Array.isArray(l)?h(l,n,t,o,a,s):h([l],n,t,o,a,s);continue}continue}Array.isArray(c)?h(c,n,t,o,a,s,f):h([c],n,t,o,a,s,f);continue}if(M(r)){let c=T("");n.push(c),r.then(l=>{if(c.parentNode){let u=[];if(h([l],u,c.parentNode,void 0,!1,s),u.length>0){c.parentNode.replaceChild(u[0],c);for(let d=1;d<u.length;d++)c.parentNode?.insertBefore(u[d],u[d-1].nextSibling)}}}).catch(l=>console.error("Error resolving promise in array:",l));continue}if(Array.isArray(r)){h(r,n,t,o,a,s,f);continue}if(C(r)){n.push(r);continue}if(typeof r=="object"&&r!==null&&("_$litType$"in r||"_$litDirective$"in r)){let c=re(r);for(let l of c)n.push(l);continue}if(typeof r=="object"&&r!==null&&"type"in r&&"props"in r){let c=r;if(typeof c.type=="function"){let l=c.type(c.props||{});Array.isArray(l)?h(l,n,t,o,!1,s):h([l],n,t,o,!1,s);continue}}if(typeof r=="string"||typeof r=="number"){let c=String(r);if(c.trim()===""&&c!==" ")continue;n.push(T(c));continue}n.push(T(String(r)))}}}}function Ne(e,n,t,o){for(let u=0;u<t.length;u++)t[u].parentNode!==null&&t[u].parentNode!==e&&(t=t.slice(),t[u]=t[u].cloneNode(!0));let a=t.length,s=n.length,f=a,i=0,r=0,c=s>0?n[s-1].nextSibling??void 0:o,l=null;for(;i<s||r<f;){if(n[i]===t[r]){i++,r++;continue}for(;s>i&&f>r&&n[s-1]===t[f-1];)s--,f--;if(s===i){let u=f<a?r?t[r-1].nextSibling??void 0:t[f-r]:c;for(;r<f;)y(e,t[r++],u)}else if(f===r)for(;i<s;)(!l||!l.has(n[i]))&&n[i].parentNode===e&&e.removeChild(n[i]),i++;else if(n[i]===t[f-1]&&t[r]===n[s-1]){let u=n[--s].nextSibling;y(e,t[r++],n[i++].nextSibling),y(e,t[--f],u),n[s]=n[i-1]}else{if(!l){l=new Map;let d=r;for(;d<f;)l.set(t[d],d++)}let u=l.get(n[i]);if(u!=null)if(r<u&&u<f){let d=i,L=1;for(;++d<s&&d<f&&!(!l.has(n[d])||l.get(n[d])!==u+L);)L++;if(L>u-r){let ue=n[i];for(;r<u;)y(e,t[r++],ue)}else n[i].parentNode===e?e.replaceChild(t[r++],n[i++]):(y(e,t[r++],c),i++)}else i++;else n[i].parentNode===e&&e.removeChild(n[i]),i++}}return t}function E(e,n,t){if(n)if(Array.isArray(n))for(let o=0;o<n.length;o++)n[o].parentNode===e&&e.removeChild(n[o]);else n.parentNode===e&&e.removeChild(n);return null}function y(e,n,t){g.active&&n.parentNode===e||(t&&t.parentNode===e?e.insertBefore(n,t):e.appendChild(n))}function oe(e,n){if(e){if(C(e)){let t=n,o=e;if(!t)return;typeof t=="function"?t(o):typeof t=="object"&&"current"in t&&(t.current=o);return}typeof e=="function"?e(n):typeof e=="object"&&"current"in e&&(e.current=n)}}var te=null;function re(e){let n=[];if(!te)return console.warn("Lit render not registered. Call registerLitRender first."),n;try{let t=document.createElement("div");for(te(e,t);t.firstChild;)n.push(t.firstChild),t.removeChild(t.firstChild)}catch(t){console.warn("Could not render Lit template:",t)}return n}function M(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"||e instanceof Promise}function ie(e){let n=()=>e.mount?typeof e.mount=="function"?e.mount():e.mount:document.body,t,o;return(0,R.createRoot)(a=>{t=a,o=document.createElement("div"),o.style.display="contents",n().appendChild(o),D(o,e.children)&&oe(e.ref,o)}),(0,R.onCleanup)(()=>{t(),o.remove()}),null}var k=require("@fluixi/reactive/signal");function se(e){let[n,t]=(0,k.createSignal)(null),o=()=>t(null);return(0,k.createMemo)(()=>{let a=n();if(a!==null)return typeof e.fallback=="function"?e.fallback(a,o):e.fallback;try{return typeof e.children=="function"?e.children():e.children}catch(s){return t(s),typeof e.fallback=="function"?e.fallback(s,o):e.fallback}})}var fe=require("@fluixi/reactive/signal");function ae(e){return(0,fe.createMemo)(()=>{let n=typeof e=="function"?e():e,t=[];for(let[o,a]of Object.entries(n)){if(!o)continue;(typeof a=="function"?a():a)&&t.push(o)}return t.join(" ")})}var ce=require("@fluixi/reactive/signal");function Ae(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}function le(e){return(0,ce.createMemo)(()=>{let n=typeof e=="function"?e():e,t=[];for(let[o,a]of Object.entries(n)){if(!o)continue;let s=typeof a=="function"?a():a;s!=null&&t.push(`${Ae(o)}: ${s}`)}return t.join("; ")})}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { Show } from './show.js';
|
|
2
|
+
export type { ShowProps } from './show.js';
|
|
3
|
+
export { For } from './for.js';
|
|
4
|
+
export type { ForProps, ForPropsKeyed, ForPropsUnkeyed } from './for.js';
|
|
5
|
+
export { Index } from './index-flow.js';
|
|
6
|
+
export type { IndexProps } from './index-flow.js';
|
|
7
|
+
export { mapArray, keyArray, indexArray } from '@fluixi/reactive/signal';
|
|
8
|
+
export { Switch, Match } from './switch.js';
|
|
9
|
+
export type { SwitchProps, MatchProps, MatchNode } from './switch.js';
|
|
10
|
+
export { Dynamic } from './dynamic.js';
|
|
11
|
+
export type { DynamicProps } from './dynamic.js';
|
|
12
|
+
export { Portal } from './portal.js';
|
|
13
|
+
export type { PortalProps } from './portal.js';
|
|
14
|
+
export { ErrorBoundary } from './error-boundary.js';
|
|
15
|
+
export type { ErrorBoundaryProps } from './error-boundary.js';
|
|
16
|
+
export { classMap } from './class-map.js';
|
|
17
|
+
export type { ClassMapInput, ClassCondition } from './class-map.js';
|
|
18
|
+
export { styleMap } from './style-map.js';
|
|
19
|
+
export type { StyleMapInput, StyleValue } from './style-map.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEzE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEzE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Show } from './show.js';
|
|
2
|
+
export { For } from './for.js';
|
|
3
|
+
export { Index } from './index-flow.js';
|
|
4
|
+
// The reactive list-reconciliation primitives that back <For>/<Index>.
|
|
5
|
+
export { mapArray, keyArray, indexArray } from '@fluixi/reactive/signal';
|
|
6
|
+
export { Switch, Match } from './switch.js';
|
|
7
|
+
export { Dynamic } from './dynamic.js';
|
|
8
|
+
export { Portal } from './portal.js';
|
|
9
|
+
export { ErrorBoundary } from './error-boundary.js';
|
|
10
|
+
export { classMap } from './class-map.js';
|
|
11
|
+
export { styleMap } from './style-map.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as v,untrack as F}from"@fluixi/reactive/signal";function L(e){return typeof e=="function"?e:(()=>e)}function x(e){return()=>{let n=e();return typeof n=="function"?n():n}}function j(e){return e!=null&&e!==!1}function $(e){return!e||typeof e!="object"?!1:!!(typeof e._$litType$<"u"||typeof e._$litDirective$<"u"||Array.isArray(e.strings)&&Array.isArray(e.values))}function q(e){let n=x(()=>e.when),t=v(n,void 0),o=v(t,void 0);return v(()=>{if(o()){let s=e.children;return typeof s=="function"&&!$(s)?typeof t=="function"?F(()=>F(t)?s(t()):e.fallback):s(t):s}return e.fallback},void 0,{name:"show"})}import{mapArray as G,keyArray as X}from"@fluixi/reactive/signal";var g={active:!1,cursor:null,parents:[]},z=null;function _(){return z}function C(e,n){return g.active&&n.parentNode===e}function M(e){let n=g.parents.lastIndexOf(e);n!==-1&&(g.parents.length=n),g.cursor=e.nextSibling}function E(e){if(!g.active||e==null)return;let n=Array.isArray(e)?e[e.length-1]:e;n&&typeof n.nodeType=="number"&&M(n)}function J(e){let n=x(()=>e.each),t=()=>e.fallback??null,o=(a,s)=>{let f=e.children,i=Array.isArray(f)?f.map(r=>typeof r=="function"?r(a,s):r):typeof f=="function"?f(a,s):f;return E(i),i};return e.by?X(n,e.by,(a,s)=>o(a,s),{fallback:t}):G(n,(a,s)=>o(a,s),{fallback:t})}import{indexArray as Y}from"@fluixi/reactive/signal";function Z(e){let n=x(()=>e.each);return Y(n,(t,o)=>{let a=e.children(t,o);return E(a),a},{fallback:()=>e.fallback??null})}import{mapArray as Pn,keyArray as vn,indexArray as Cn}from"@fluixi/reactive/signal";import{createMemo as Q}from"@fluixi/reactive/signal";var R=Symbol("match");function ee(e){return{[R]:!0,when:x(()=>e.when),children:e.children}}function ne(e){let n=Array.isArray(e.children)?e.children:[e.children];return Q(()=>{for(let t of n){let o=t,a=0;for(;typeof o=="function"&&!o[R]&&a++<10;)o=o();if(!o||typeof o!="object"||o[R]!==!0)continue;let s=o.when();if(j(s))return typeof o.children=="function"?o.children(s):o.children}return e.fallback??null})}import{createMemo as te}from"@fluixi/reactive/signal";function oe(e){let n=L(e.component),{component:t,...o}=e;return te(()=>{let a=n();return a==null?null:typeof a=="string"?{tag:a,props:o}:a(o)})}import{createRoot as ce,onCleanup as le}from"@fluixi/reactive/signal";import{isSignal as p}from"@fluixi/reactive/signal";function b(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}import{batch as Ze,createEffect as Qe,createRenderEffect as re,createRoot as en,onCleanup as ie,readChildren as nn}from"@fluixi/reactive/signal";var U=typeof document>"u";var H=Symbol.for("fluixi.server-node"),D=null;function O(){if(!D)throw new Error("[fluixi] server render ran before @fluixi/dom/server loaded");return D}function w(e){return e!=null&&e[H]===!0?!0:typeof Node<"u"&&e instanceof Node}function I(e){return e!=null&&e[H]===!0?e.nodeType===3:typeof Text<"u"&&e instanceof Text}function T(e){if(U)return O().createText(e);if(g.active){let n=_()?.hydrateText(e);if(n)return n}return document.createTextNode(e)}var m=0,se=200;function fe(e,n,t,o,a){let s=o,f=new Map;return re(()=>{let i;if(b(e)&&!p(e)){if(!f.has(e)){m++;try{let r=e();f.set(e,r)}finally{m--}}for(i=f.get(e);typeof i=="function"&&p(i);)i=i()}else for(i=e();typeof i=="function"&&p(i);)i=i();{let r=0;for(;typeof i=="function"&&r++<50;)if(b(i)){if(!f.has(i)){let c=i;m++;try{let l=c();f.set(c,l)}finally{m--}}i=f.get(i)}else if(p(i))i=i();else if(i=i(),typeof i!="function"||!p(i)&&!b(i))break}m++;try{s=A(n,i,t,s,f),a(s)}finally{m--}})}function k(e,n,t,o){if(m>se)return console.error("[insert] Exceeded max call depth — possible infinite loop."),()=>null;t!==void 0&&!t&&(t=T(""),e.appendChild(t));let a=o??null;if(typeof n!="function"){m++;try{a=A(e,n,t,null)}finally{m--}return()=>a}let s=fe(n,e,t,a,f=>{a=f});return()=>(s?.(),a)}function A(e,n,t,o,a){if(n==null||typeof n=="boolean")return N(e,o,t);if(typeof n=="function")for(;typeof n=="function";)n=n();if(n==null||typeof n=="boolean")return N(e,o,t);if(S(n)){let f=T("");return Array.isArray(o)?o.length>0?(e.replaceChild(f,o[0]),N(e,o.slice(1),t)):y(e,f,t):o?e.replaceChild(f,o):y(e,f,t),n.then(i=>{f.parentNode===e&&A(e,i,f.nextSibling,f)}).catch(i=>{console.error("Error resolving promise in insertExpression:",i)}),f}let s=typeof n;if(s==="string"||s==="number"){if(s==="number"&&(n=String(n)),Array.isArray(o)){if(o.length===0){let i=T(n);return y(e,i,t),i}if(o.length===1&&o[0].nodeType===3)return o[0].data=n,o;o=N(e,o,t)}if(o&&I(o))return o.data=n,o;let f=T(n);return o&&o.parentNode===e?e.replaceChild(f,o):C(e,f)||y(e,f,t),f}if(w(n))return C(e,n)?(M(n),n):Array.isArray(o)?(o.length===0?y(e,n,t):o[0].parentNode===e?(e.replaceChild(n,o[0]),N(e,o.slice(1),t)):y(e,n,t),n):(o?o!==n&&(o.parentNode===e?e.replaceChild(n,o):y(e,n,t)):y(e,n,t),n);if(Array.isArray(n)){let f=[],i=Array.isArray(o)?o:o?[o]:[],r=[];h(n,f,e,t,!0,a,r);let c=ae(e,i,f,t);for(let l of r){let u=k(e,l.sig,l.marker);ie(()=>{N(e,u()),l.marker.parentNode===e&&e.removeChild(l.marker)})}return c}if(s==="object"&&n!==null&&typeof n=="object"){let f=n;if("_$litType$"in f||"_$litDirective$"in f)return A(e,W(n),t,o);if("type"in f&&"props"in f){let i=f;if(typeof i.type=="function"){let r=i.type(i.props||{});return A(e,r,t,o)}}}return N(e,o,t)}function h(e,n,t,o,a=!0,s,f){for(let i=0;i<e.length;i++){let r=e[i];if(!(r==null||typeof r=="boolean")){for(;typeof r=="function"&&!S(r)&&!p(r)&&!b(r)&&(r=r(),!(r==null||typeof r=="boolean")););if(!(r==null||typeof r=="boolean")){if(typeof r=="function"){let c;for(b(r)&&!p(r)?(s||(s=new Map),s.has(r)||s.set(r,r()),c=s.get(r)):c=r();typeof c=="function"&&!S(c)&&!p(c)&&!b(c);)s||(s=new Map),s.has(c)||s.set(c,c()),c=s.get(c);if(c==null||typeof c=="boolean")continue;if(typeof c=="function"){if(p(c)){if(f){let u=T("");n.push(u),f.push({marker:u,sig:c});continue}let l=c();for(;typeof l=="function"&&p(l);)l=l();if(l==null||typeof l=="boolean")continue;Array.isArray(l)?h(l,n,t,o,a,s):h([l],n,t,o,a,s);continue}continue}Array.isArray(c)?h(c,n,t,o,a,s,f):h([c],n,t,o,a,s,f);continue}if(S(r)){let c=T("");n.push(c),r.then(l=>{if(c.parentNode){let u=[];if(h([l],u,c.parentNode,void 0,!1,s),u.length>0){c.parentNode.replaceChild(u[0],c);for(let d=1;d<u.length;d++)c.parentNode?.insertBefore(u[d],u[d-1].nextSibling)}}}).catch(l=>console.error("Error resolving promise in array:",l));continue}if(Array.isArray(r)){h(r,n,t,o,a,s,f);continue}if(w(r)){n.push(r);continue}if(typeof r=="object"&&r!==null&&("_$litType$"in r||"_$litDirective$"in r)){let c=W(r);for(let l of c)n.push(l);continue}if(typeof r=="object"&&r!==null&&"type"in r&&"props"in r){let c=r;if(typeof c.type=="function"){let l=c.type(c.props||{});Array.isArray(l)?h(l,n,t,o,!1,s):h([l],n,t,o,!1,s);continue}}if(typeof r=="string"||typeof r=="number"){let c=String(r);if(c.trim()===""&&c!==" ")continue;n.push(T(c));continue}n.push(T(String(r)))}}}}function ae(e,n,t,o){for(let u=0;u<t.length;u++)t[u].parentNode!==null&&t[u].parentNode!==e&&(t=t.slice(),t[u]=t[u].cloneNode(!0));let a=t.length,s=n.length,f=a,i=0,r=0,c=s>0?n[s-1].nextSibling??void 0:o,l=null;for(;i<s||r<f;){if(n[i]===t[r]){i++,r++;continue}for(;s>i&&f>r&&n[s-1]===t[f-1];)s--,f--;if(s===i){let u=f<a?r?t[r-1].nextSibling??void 0:t[f-r]:c;for(;r<f;)y(e,t[r++],u)}else if(f===r)for(;i<s;)(!l||!l.has(n[i]))&&n[i].parentNode===e&&e.removeChild(n[i]),i++;else if(n[i]===t[f-1]&&t[r]===n[s-1]){let u=n[--s].nextSibling;y(e,t[r++],n[i++].nextSibling),y(e,t[--f],u),n[s]=n[i-1]}else{if(!l){l=new Map;let d=r;for(;d<f;)l.set(t[d],d++)}let u=l.get(n[i]);if(u!=null)if(r<u&&u<f){let d=i,P=1;for(;++d<s&&d<f&&!(!l.has(n[d])||l.get(n[d])!==u+P);)P++;if(P>u-r){let B=n[i];for(;r<u;)y(e,t[r++],B)}else n[i].parentNode===e?e.replaceChild(t[r++],n[i++]):(y(e,t[r++],c),i++)}else i++;else n[i].parentNode===e&&e.removeChild(n[i]),i++}}return t}function N(e,n,t){if(n)if(Array.isArray(n))for(let o=0;o<n.length;o++)n[o].parentNode===e&&e.removeChild(n[o]);else n.parentNode===e&&e.removeChild(n);return null}function y(e,n,t){g.active&&n.parentNode===e||(t&&t.parentNode===e?e.insertBefore(n,t):e.appendChild(n))}function V(e,n){if(e){if(w(e)){let t=n,o=e;if(!t)return;typeof t=="function"?t(o):typeof t=="object"&&"current"in t&&(t.current=o);return}typeof e=="function"?e(n):typeof e=="object"&&"current"in e&&(e.current=n)}}var K=null;function W(e){let n=[];if(!K)return console.warn("Lit render not registered. Call registerLitRender first."),n;try{let t=document.createElement("div");for(K(e,t);t.firstChild;)n.push(t.firstChild),t.removeChild(t.firstChild)}catch(t){console.warn("Could not render Lit template:",t)}return n}function S(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"||e instanceof Promise}function ue(e){let n=()=>e.mount?typeof e.mount=="function"?e.mount():e.mount:document.body,t,o;return ce(a=>{t=a,o=document.createElement("div"),o.style.display="contents",n().appendChild(o),k(o,e.children)&&V(e.ref,o)}),le(()=>{t(),o.remove()}),null}import{createMemo as de,createSignal as ye}from"@fluixi/reactive/signal";function pe(e){let[n,t]=ye(null),o=()=>t(null);return de(()=>{let a=n();if(a!==null)return typeof e.fallback=="function"?e.fallback(a,o):e.fallback;try{return typeof e.children=="function"?e.children():e.children}catch(s){return t(s),typeof e.fallback=="function"?e.fallback(s,o):e.fallback}})}import{createMemo as he}from"@fluixi/reactive/signal";function me(e){return he(()=>{let n=typeof e=="function"?e():e,t=[];for(let[o,a]of Object.entries(n)){if(!o)continue;(typeof a=="function"?a():a)&&t.push(o)}return t.join(" ")})}import{createMemo as xe}from"@fluixi/reactive/signal";function ge(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`)}function Te(e){return xe(()=>{let n=typeof e=="function"?e():e,t=[];for(let[o,a]of Object.entries(n)){if(!o)continue;let s=typeof a=="function"?a():a;s!=null&&t.push(`${ge(o)}: ${s}`)}return t.join("; ")})}export{oe as Dynamic,pe as ErrorBoundary,J as For,Z as Index,ee as Match,ue as Portal,q as Show,ne as Switch,me as classMap,Cn as indexArray,vn as keyArray,Pn as mapArray,Te as styleMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var v=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var B=(e,n)=>{for(var t in n)v(e,t,{get:n[t],enumerable:!0})},q=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let c of W(n))!V.call(e,c)&&c!==t&&v(e,c,{get:()=>n[c],enumerable:!(o=K(n,c))||o.enumerable});return e};var G=e=>q(v({},"__esModule",{value:!0}),e);var Q={};B(Q,{Portal:()=>z});module.exports=G(Q);var A=require("@fluixi/reactive/signal");var p=require("@fluixi/reactive/signal");function N(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}var m=require("@fluixi/reactive/signal");var $=typeof document>"u";var _=Symbol.for("fluixi.server-node"),M=null;function R(){if(!M)throw new Error("[fluixi] server render ran before @fluixi/dom/server loaded");return M}function w(e){return e!=null&&e[_]===!0?!0:typeof Node<"u"&&e instanceof Node}function D(e){return e!=null&&e[_]===!0?e.nodeType===3:typeof Text<"u"&&e instanceof Text}var E={active:!1,cursor:null,parents:[]},U=null;function H(){return U}function C(e,n){return E.active&&n.parentNode===e}function j(e){let n=E.parents.lastIndexOf(e);n!==-1&&(E.parents.length=n),E.cursor=e.nextSibling}function g(e){if($)return R().createText(e);if(E.active){let n=H()?.hydrateText(e);if(n)return n}return document.createTextNode(e)}var x=0,X=200;function J(e,n,t,o,c){let l=o,s=new Map;return(0,m.createRenderEffect)(()=>{let r;if(N(e)&&!(0,p.isSignal)(e)){if(!s.has(e)){x++;try{let i=e();s.set(e,i)}finally{x--}}for(r=s.get(e);typeof r=="function"&&(0,p.isSignal)(r);)r=r()}else for(r=e();typeof r=="function"&&(0,p.isSignal)(r);)r=r();{let i=0;for(;typeof r=="function"&&i++<50;)if(N(r)){if(!s.has(r)){let f=r;x++;try{let u=f();s.set(f,u)}finally{x--}}r=s.get(r)}else if((0,p.isSignal)(r))r=r();else if(r=r(),typeof r!="function"||!(0,p.isSignal)(r)&&!N(r))break}x++;try{l=T(n,r,t,l,s),c(l)}finally{x--}})}function L(e,n,t,o){if(x>X)return console.error("[insert] Exceeded max call depth — possible infinite loop."),()=>null;t!==void 0&&!t&&(t=g(""),e.appendChild(t));let c=o??null;if(typeof n!="function"){x++;try{c=T(e,n,t,null)}finally{x--}return()=>c}let l=J(n,e,t,c,s=>{c=s});return()=>(l?.(),c)}function T(e,n,t,o,c){if(n==null||typeof n=="boolean")return b(e,o,t);if(typeof n=="function")for(;typeof n=="function";)n=n();if(n==null||typeof n=="boolean")return b(e,o,t);if(S(n)){let s=g("");return Array.isArray(o)?o.length>0?(e.replaceChild(s,o[0]),b(e,o.slice(1),t)):y(e,s,t):o?e.replaceChild(s,o):y(e,s,t),n.then(r=>{s.parentNode===e&&T(e,r,s.nextSibling,s)}).catch(r=>{console.error("Error resolving promise in insertExpression:",r)}),s}let l=typeof n;if(l==="string"||l==="number"){if(l==="number"&&(n=String(n)),Array.isArray(o)){if(o.length===0){let r=g(n);return y(e,r,t),r}if(o.length===1&&o[0].nodeType===3)return o[0].data=n,o;o=b(e,o,t)}if(o&&D(o))return o.data=n,o;let s=g(n);return o&&o.parentNode===e?e.replaceChild(s,o):C(e,s)||y(e,s,t),s}if(w(n))return C(e,n)?(j(n),n):Array.isArray(o)?(o.length===0?y(e,n,t):o[0].parentNode===e?(e.replaceChild(n,o[0]),b(e,o.slice(1),t)):y(e,n,t),n):(o?o!==n&&(o.parentNode===e?e.replaceChild(n,o):y(e,n,t)):y(e,n,t),n);if(Array.isArray(n)){let s=[],r=Array.isArray(o)?o:o?[o]:[],i=[];h(n,s,e,t,!0,c,i);let f=Y(e,r,s,t);for(let u of i){let a=L(e,u.sig,u.marker);(0,m.onCleanup)(()=>{b(e,a()),u.marker.parentNode===e&&e.removeChild(u.marker)})}return f}if(l==="object"&&n!==null&&typeof n=="object"){let s=n;if("_$litType$"in s||"_$litDirective$"in s)return T(e,k(n),t,o);if("type"in s&&"props"in s){let r=s;if(typeof r.type=="function"){let i=r.type(r.props||{});return T(e,i,t,o)}}}return b(e,o,t)}function h(e,n,t,o,c=!0,l,s){for(let r=0;r<e.length;r++){let i=e[r];if(!(i==null||typeof i=="boolean")){for(;typeof i=="function"&&!S(i)&&!(0,p.isSignal)(i)&&!N(i)&&(i=i(),!(i==null||typeof i=="boolean")););if(!(i==null||typeof i=="boolean")){if(typeof i=="function"){let f;for(N(i)&&!(0,p.isSignal)(i)?(l||(l=new Map),l.has(i)||l.set(i,i()),f=l.get(i)):f=i();typeof f=="function"&&!S(f)&&!(0,p.isSignal)(f)&&!N(f);)l||(l=new Map),l.has(f)||l.set(f,f()),f=l.get(f);if(f==null||typeof f=="boolean")continue;if(typeof f=="function"){if((0,p.isSignal)(f)){if(s){let a=g("");n.push(a),s.push({marker:a,sig:f});continue}let u=f();for(;typeof u=="function"&&(0,p.isSignal)(u);)u=u();if(u==null||typeof u=="boolean")continue;Array.isArray(u)?h(u,n,t,o,c,l):h([u],n,t,o,c,l);continue}continue}Array.isArray(f)?h(f,n,t,o,c,l,s):h([f],n,t,o,c,l,s);continue}if(S(i)){let f=g("");n.push(f),i.then(u=>{if(f.parentNode){let a=[];if(h([u],a,f.parentNode,void 0,!1,l),a.length>0){f.parentNode.replaceChild(a[0],f);for(let d=1;d<a.length;d++)f.parentNode?.insertBefore(a[d],a[d-1].nextSibling)}}}).catch(u=>console.error("Error resolving promise in array:",u));continue}if(Array.isArray(i)){h(i,n,t,o,c,l,s);continue}if(w(i)){n.push(i);continue}if(typeof i=="object"&&i!==null&&("_$litType$"in i||"_$litDirective$"in i)){let f=k(i);for(let u of f)n.push(u);continue}if(typeof i=="object"&&i!==null&&"type"in i&&"props"in i){let f=i;if(typeof f.type=="function"){let u=f.type(f.props||{});Array.isArray(u)?h(u,n,t,o,!1,l):h([u],n,t,o,!1,l);continue}}if(typeof i=="string"||typeof i=="number"){let f=String(i);if(f.trim()===""&&f!==" ")continue;n.push(g(f));continue}n.push(g(String(i)))}}}}function Y(e,n,t,o){for(let a=0;a<t.length;a++)t[a].parentNode!==null&&t[a].parentNode!==e&&(t=t.slice(),t[a]=t[a].cloneNode(!0));let c=t.length,l=n.length,s=c,r=0,i=0,f=l>0?n[l-1].nextSibling??void 0:o,u=null;for(;r<l||i<s;){if(n[r]===t[i]){r++,i++;continue}for(;l>r&&s>i&&n[l-1]===t[s-1];)l--,s--;if(l===r){let a=s<c?i?t[i-1].nextSibling??void 0:t[s-i]:f;for(;i<s;)y(e,t[i++],a)}else if(s===i)for(;r<l;)(!u||!u.has(n[r]))&&n[r].parentNode===e&&e.removeChild(n[r]),r++;else if(n[r]===t[s-1]&&t[i]===n[l-1]){let a=n[--l].nextSibling;y(e,t[i++],n[r++].nextSibling),y(e,t[--s],a),n[l]=n[r-1]}else{if(!u){u=new Map;let d=i;for(;d<s;)u.set(t[d],d++)}let a=u.get(n[r]);if(a!=null)if(i<a&&a<s){let d=r,P=1;for(;++d<l&&d<s&&!(!u.has(n[d])||u.get(n[d])!==a+P);)P++;if(P>a-i){let I=n[r];for(;i<a;)y(e,t[i++],I)}else n[r].parentNode===e?e.replaceChild(t[i++],n[r++]):(y(e,t[i++],f),r++)}else r++;else n[r].parentNode===e&&e.removeChild(n[r]),r++}}return t}function b(e,n,t){if(n)if(Array.isArray(n))for(let o=0;o<n.length;o++)n[o].parentNode===e&&e.removeChild(n[o]);else n.parentNode===e&&e.removeChild(n);return null}function y(e,n,t){E.active&&n.parentNode===e||(t&&t.parentNode===e?e.insertBefore(n,t):e.appendChild(n))}function O(e,n){if(e){if(w(e)){let t=n,o=e;if(!t)return;typeof t=="function"?t(o):typeof t=="object"&&"current"in t&&(t.current=o);return}typeof e=="function"?e(n):typeof e=="object"&&"current"in e&&(e.current=n)}}var F=null;function k(e){let n=[];if(!F)return console.warn("Lit render not registered. Call registerLitRender first."),n;try{let t=document.createElement("div");for(F(e,t);t.firstChild;)n.push(t.firstChild),t.removeChild(t.firstChild)}catch(t){console.warn("Could not render Lit template:",t)}return n}function S(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"||e instanceof Promise}function z(e){let n=()=>e.mount?typeof e.mount=="function"?e.mount():e.mount:document.body,t,o;return(0,A.createRoot)(c=>{t=c,o=document.createElement("div"),o.style.display="contents",n().appendChild(o),L(o,e.children)&&O(e.ref,o)}),(0,A.onCleanup)(()=>{t(),o.remove()}),null}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface PortalProps<Children = any> {
|
|
2
|
+
/**
|
|
3
|
+
* The DOM node to mount content into.
|
|
4
|
+
* Defaults to `document.body`.
|
|
5
|
+
*/
|
|
6
|
+
mount?: Element | (() => Element);
|
|
7
|
+
/** Content to render inside the portal. */
|
|
8
|
+
children: Children;
|
|
9
|
+
ref?: {
|
|
10
|
+
current: Element | HTMLElement | HTMLDivElement | null;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Renders children into a DOM node outside the current component tree.
|
|
15
|
+
*
|
|
16
|
+
* Useful for modals, tooltips, and overlays. The portal is disposed when
|
|
17
|
+
* the parent component unmounts. Returns null (no in-place DOM output).
|
|
18
|
+
*
|
|
19
|
+
* Works in both JSX and lit-html contexts.
|
|
20
|
+
*
|
|
21
|
+
* @example JSX
|
|
22
|
+
* <Portal mount={document.getElementById('modal-root')!}>
|
|
23
|
+
* <Modal />
|
|
24
|
+
* </Portal>
|
|
25
|
+
*
|
|
26
|
+
* @example lit-html
|
|
27
|
+
* Portal({ mount: () => document.getElementById('modal-root')!, children: html`<p>Hello</p>` })
|
|
28
|
+
*/
|
|
29
|
+
export declare function Portal(props: PortalProps): null;
|
|
30
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/portal.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW,CAAC,QAAQ,GAAG,GAAG;IACzC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IAClC,2CAA2C;IAC3C,QAAQ,EAAE,QAAQ,CAAC;IACnB,GAAG,CAAC,EAAE;QAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,cAAc,GAAG,IAAI,CAAA;KAAC,CAAC;CAChE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CA4B/C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createRoot, onCleanup } from '@fluixi/reactive/signal';
|
|
2
|
+
import { handleRef, insert } from '../dom/runtime.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders children into a DOM node outside the current component tree.
|
|
5
|
+
*
|
|
6
|
+
* Useful for modals, tooltips, and overlays. The portal is disposed when
|
|
7
|
+
* the parent component unmounts. Returns null (no in-place DOM output).
|
|
8
|
+
*
|
|
9
|
+
* Works in both JSX and lit-html contexts.
|
|
10
|
+
*
|
|
11
|
+
* @example JSX
|
|
12
|
+
* <Portal mount={document.getElementById('modal-root')!}>
|
|
13
|
+
* <Modal />
|
|
14
|
+
* </Portal>
|
|
15
|
+
*
|
|
16
|
+
* @example lit-html
|
|
17
|
+
* Portal({ mount: () => document.getElementById('modal-root')!, children: html`<p>Hello</p>` })
|
|
18
|
+
*/
|
|
19
|
+
export function Portal(props) {
|
|
20
|
+
const getMount = () => {
|
|
21
|
+
if (!props.mount)
|
|
22
|
+
return document.body;
|
|
23
|
+
return typeof props.mount === 'function' ? props.mount() : props.mount;
|
|
24
|
+
};
|
|
25
|
+
let dispose;
|
|
26
|
+
let container;
|
|
27
|
+
// Use a dedicated container so we can remove the exact node on cleanup.
|
|
28
|
+
createRoot((d) => {
|
|
29
|
+
dispose = d;
|
|
30
|
+
container = document.createElement('div');
|
|
31
|
+
container.style.display = 'contents';
|
|
32
|
+
const target = getMount();
|
|
33
|
+
target.appendChild(container);
|
|
34
|
+
const inserted = insert(container, props.children);
|
|
35
|
+
if (inserted) {
|
|
36
|
+
handleRef(props.ref, container);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
onCleanup(() => {
|
|
40
|
+
dispose();
|
|
41
|
+
container.remove();
|
|
42
|
+
});
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRoot as B,onCleanup as q}from"@fluixi/reactive/signal";import{isSignal as p}from"@fluixi/reactive/signal";function m(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}import{batch as Z,createEffect as ee,createRenderEffect as k,createRoot as ne,onCleanup as I,readChildren as te}from"@fluixi/reactive/signal";var C=typeof document>"u";var L=Symbol.for("fluixi.server-node"),v=null;function M(){if(!v)throw new Error("[fluixi] server render ran before @fluixi/dom/server loaded");return v}function T(e){return e!=null&&e[L]===!0?!0:typeof Node<"u"&&e instanceof Node}function $(e){return e!=null&&e[L]===!0?e.nodeType===3:typeof Text<"u"&&e instanceof Text}var N={active:!1,cursor:null,parents:[]},O=null;function _(){return O}function A(e,n){return N.active&&n.parentNode===e}function R(e){let n=N.parents.lastIndexOf(e);n!==-1&&(N.parents.length=n),N.cursor=e.nextSibling}function g(e){if(C)return M().createText(e);if(N.active){let n=_()?.hydrateText(e);if(n)return n}return document.createTextNode(e)}var x=0,K=200;function W(e,n,t,i,c){let l=i,s=new Map;return k(()=>{let r;if(m(e)&&!p(e)){if(!s.has(e)){x++;try{let o=e();s.set(e,o)}finally{x--}}for(r=s.get(e);typeof r=="function"&&p(r);)r=r()}else for(r=e();typeof r=="function"&&p(r);)r=r();{let o=0;for(;typeof r=="function"&&o++<50;)if(m(r)){if(!s.has(r)){let f=r;x++;try{let u=f();s.set(f,u)}finally{x--}}r=s.get(r)}else if(p(r))r=r();else if(r=r(),typeof r!="function"||!p(r)&&!m(r))break}x++;try{l=b(n,r,t,l,s),c(l)}finally{x--}})}function P(e,n,t,i){if(x>K)return console.error("[insert] Exceeded max call depth — possible infinite loop."),()=>null;t!==void 0&&!t&&(t=g(""),e.appendChild(t));let c=i??null;if(typeof n!="function"){x++;try{c=b(e,n,t,null)}finally{x--}return()=>c}let l=W(n,e,t,c,s=>{c=s});return()=>(l?.(),c)}function b(e,n,t,i,c){if(n==null||typeof n=="boolean")return E(e,i,t);if(typeof n=="function")for(;typeof n=="function";)n=n();if(n==null||typeof n=="boolean")return E(e,i,t);if(w(n)){let s=g("");return Array.isArray(i)?i.length>0?(e.replaceChild(s,i[0]),E(e,i.slice(1),t)):y(e,s,t):i?e.replaceChild(s,i):y(e,s,t),n.then(r=>{s.parentNode===e&&b(e,r,s.nextSibling,s)}).catch(r=>{console.error("Error resolving promise in insertExpression:",r)}),s}let l=typeof n;if(l==="string"||l==="number"){if(l==="number"&&(n=String(n)),Array.isArray(i)){if(i.length===0){let r=g(n);return y(e,r,t),r}if(i.length===1&&i[0].nodeType===3)return i[0].data=n,i;i=E(e,i,t)}if(i&&$(i))return i.data=n,i;let s=g(n);return i&&i.parentNode===e?e.replaceChild(s,i):A(e,s)||y(e,s,t),s}if(T(n))return A(e,n)?(R(n),n):Array.isArray(i)?(i.length===0?y(e,n,t):i[0].parentNode===e?(e.replaceChild(n,i[0]),E(e,i.slice(1),t)):y(e,n,t),n):(i?i!==n&&(i.parentNode===e?e.replaceChild(n,i):y(e,n,t)):y(e,n,t),n);if(Array.isArray(n)){let s=[],r=Array.isArray(i)?i:i?[i]:[],o=[];h(n,s,e,t,!0,c,o);let f=V(e,r,s,t);for(let u of o){let a=P(e,u.sig,u.marker);I(()=>{E(e,a()),u.marker.parentNode===e&&e.removeChild(u.marker)})}return f}if(l==="object"&&n!==null&&typeof n=="object"){let s=n;if("_$litType$"in s||"_$litDirective$"in s)return b(e,j(n),t,i);if("type"in s&&"props"in s){let r=s;if(typeof r.type=="function"){let o=r.type(r.props||{});return b(e,o,t,i)}}}return E(e,i,t)}function h(e,n,t,i,c=!0,l,s){for(let r=0;r<e.length;r++){let o=e[r];if(!(o==null||typeof o=="boolean")){for(;typeof o=="function"&&!w(o)&&!p(o)&&!m(o)&&(o=o(),!(o==null||typeof o=="boolean")););if(!(o==null||typeof o=="boolean")){if(typeof o=="function"){let f;for(m(o)&&!p(o)?(l||(l=new Map),l.has(o)||l.set(o,o()),f=l.get(o)):f=o();typeof f=="function"&&!w(f)&&!p(f)&&!m(f);)l||(l=new Map),l.has(f)||l.set(f,f()),f=l.get(f);if(f==null||typeof f=="boolean")continue;if(typeof f=="function"){if(p(f)){if(s){let a=g("");n.push(a),s.push({marker:a,sig:f});continue}let u=f();for(;typeof u=="function"&&p(u);)u=u();if(u==null||typeof u=="boolean")continue;Array.isArray(u)?h(u,n,t,i,c,l):h([u],n,t,i,c,l);continue}continue}Array.isArray(f)?h(f,n,t,i,c,l,s):h([f],n,t,i,c,l,s);continue}if(w(o)){let f=g("");n.push(f),o.then(u=>{if(f.parentNode){let a=[];if(h([u],a,f.parentNode,void 0,!1,l),a.length>0){f.parentNode.replaceChild(a[0],f);for(let d=1;d<a.length;d++)f.parentNode?.insertBefore(a[d],a[d-1].nextSibling)}}}).catch(u=>console.error("Error resolving promise in array:",u));continue}if(Array.isArray(o)){h(o,n,t,i,c,l,s);continue}if(T(o)){n.push(o);continue}if(typeof o=="object"&&o!==null&&("_$litType$"in o||"_$litDirective$"in o)){let f=j(o);for(let u of f)n.push(u);continue}if(typeof o=="object"&&o!==null&&"type"in o&&"props"in o){let f=o;if(typeof f.type=="function"){let u=f.type(f.props||{});Array.isArray(u)?h(u,n,t,i,!1,l):h([u],n,t,i,!1,l);continue}}if(typeof o=="string"||typeof o=="number"){let f=String(o);if(f.trim()===""&&f!==" ")continue;n.push(g(f));continue}n.push(g(String(o)))}}}}function V(e,n,t,i){for(let a=0;a<t.length;a++)t[a].parentNode!==null&&t[a].parentNode!==e&&(t=t.slice(),t[a]=t[a].cloneNode(!0));let c=t.length,l=n.length,s=c,r=0,o=0,f=l>0?n[l-1].nextSibling??void 0:i,u=null;for(;r<l||o<s;){if(n[r]===t[o]){r++,o++;continue}for(;l>r&&s>o&&n[l-1]===t[s-1];)l--,s--;if(l===r){let a=s<c?o?t[o-1].nextSibling??void 0:t[s-o]:f;for(;o<s;)y(e,t[o++],a)}else if(s===o)for(;r<l;)(!u||!u.has(n[r]))&&n[r].parentNode===e&&e.removeChild(n[r]),r++;else if(n[r]===t[s-1]&&t[o]===n[l-1]){let a=n[--l].nextSibling;y(e,t[o++],n[r++].nextSibling),y(e,t[--s],a),n[l]=n[r-1]}else{if(!u){u=new Map;let d=o;for(;d<s;)u.set(t[d],d++)}let a=u.get(n[r]);if(a!=null)if(o<a&&a<s){let d=r,S=1;for(;++d<l&&d<s&&!(!u.has(n[d])||u.get(n[d])!==a+S);)S++;if(S>a-o){let F=n[r];for(;o<a;)y(e,t[o++],F)}else n[r].parentNode===e?e.replaceChild(t[o++],n[r++]):(y(e,t[o++],f),r++)}else r++;else n[r].parentNode===e&&e.removeChild(n[r]),r++}}return t}function E(e,n,t){if(n)if(Array.isArray(n))for(let i=0;i<n.length;i++)n[i].parentNode===e&&e.removeChild(n[i]);else n.parentNode===e&&e.removeChild(n);return null}function y(e,n,t){N.active&&n.parentNode===e||(t&&t.parentNode===e?e.insertBefore(n,t):e.appendChild(n))}function H(e,n){if(e){if(T(e)){let t=n,i=e;if(!t)return;typeof t=="function"?t(i):typeof t=="object"&&"current"in t&&(t.current=i);return}typeof e=="function"?e(n):typeof e=="object"&&"current"in e&&(e.current=n)}}var D=null;function j(e){let n=[];if(!D)return console.warn("Lit render not registered. Call registerLitRender first."),n;try{let t=document.createElement("div");for(D(e,t);t.firstChild;)n.push(t.firstChild),t.removeChild(t.firstChild)}catch(t){console.warn("Could not render Lit template:",t)}return n}function w(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"||e instanceof Promise}function ue(e){let n=()=>e.mount?typeof e.mount=="function"?e.mount():e.mount:document.body,t,i;return B(c=>{t=c,i=document.createElement("div"),i.style.display="contents",n().appendChild(i),P(i,e.children)&&H(e.ref,i)}),q(()=>{t(),i.remove()}),null}export{ue as Portal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var y=(e,n)=>{for(var r in n)a(e,r,{get:n[r],enumerable:!0})},d=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of l(n))!T.call(e,o)&&o!==r&&a(e,o,{get:()=>n[o],enumerable:!(s=u(n,o))||s.enumerable});return e};var m=e=>d(a({},"__esModule",{value:!0}),e);var A={};y(A,{Show:()=>p});module.exports=m(A);var t=require("@fluixi/reactive/signal");function c(e){return()=>{let n=e();return typeof n=="function"?n():n}}function f(e){return!e||typeof e!="object"?!1:!!(typeof e._$litType$<"u"||typeof e._$litDirective$<"u"||Array.isArray(e.strings)&&Array.isArray(e.values))}function p(e){let n=c(()=>e.when),r=(0,t.createMemo)(n,void 0),s=(0,t.createMemo)(r,void 0);return(0,t.createMemo)(()=>{if(s()){let i=e.children;return typeof i=="function"&&!f(i)?typeof r=="function"?(0,t.untrack)(()=>(0,t.untrack)(r)?i(r()):e.fallback):i(r):i}return e.fallback},void 0,{name:"show"})}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the resolved value type from Show's `when` prop.
|
|
4
|
+
*/
|
|
5
|
+
export type ShowValue<T> = T extends () => infer V ? V : NonNullable<T extends () => infer V ? V : T>;
|
|
6
|
+
export interface ShowProps<T, W = any> {
|
|
7
|
+
/** Reactive condition. When truthy, renders children. */
|
|
8
|
+
when: T | Accessor<T> | null | undefined | false;
|
|
9
|
+
/** Content rendered when `when` is falsy. */
|
|
10
|
+
fallback?: any;
|
|
11
|
+
/**
|
|
12
|
+
* Content when `when` is truthy.
|
|
13
|
+
* Can be a function receiving the truthy value (useful to narrow types).
|
|
14
|
+
*
|
|
15
|
+
* JSX: <Show when={user()}>{(u) => <span>{u.name}</span>}</Show>
|
|
16
|
+
* lit: Show({ when: user, children: (u) => html`<span>${u.name}</span>` })
|
|
17
|
+
*/
|
|
18
|
+
children: W | ((val: ShowValue<T>) => any);
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Conditionally renders content based on a reactive condition.
|
|
23
|
+
*
|
|
24
|
+
* Returns a memo — works in both JSX and lit-html templates.
|
|
25
|
+
*
|
|
26
|
+
* @example JSX
|
|
27
|
+
* <Show when={isLoggedIn()} fallback={<Login />}>
|
|
28
|
+
* <Dashboard />
|
|
29
|
+
* </Show>
|
|
30
|
+
*
|
|
31
|
+
* @example lit-html
|
|
32
|
+
* Show({ when: isLoggedIn, fallback: html`<p>Login</p>`, children: html`<p>Dashboard</p>` })
|
|
33
|
+
*/
|
|
34
|
+
export declare function Show<T>(props: ShowProps<T>): any;
|
|
35
|
+
//# sourceMappingURL=show.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/show.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,SAAS,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AAGtG,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG;IACnC,yDAAyD;IACzD,IAAI,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC;IACjD,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;;;;;;;;;;;GAYG;AAcH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAyEhD"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createMemo, untrack } from '@fluixi/reactive/signal';
|
|
2
|
+
import { resolveReactiveProp, isLitResult } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Conditionally renders content based on a reactive condition.
|
|
5
|
+
*
|
|
6
|
+
* Returns a memo — works in both JSX and lit-html templates.
|
|
7
|
+
*
|
|
8
|
+
* @example JSX
|
|
9
|
+
* <Show when={isLoggedIn()} fallback={<Login />}>
|
|
10
|
+
* <Dashboard />
|
|
11
|
+
* </Show>
|
|
12
|
+
*
|
|
13
|
+
* @example lit-html
|
|
14
|
+
* Show({ when: isLoggedIn, fallback: html`<p>Login</p>`, children: html`<p>Dashboard</p>` })
|
|
15
|
+
*/
|
|
16
|
+
// export function Show<T>(props: ShowProps<T>): Accessor<any> {
|
|
17
|
+
// const when = normalizeAccessor(props.when);
|
|
18
|
+
// return createMemo(() => {
|
|
19
|
+
// const value = when();
|
|
20
|
+
// if (isTruthy(value)) {
|
|
21
|
+
// return typeof props.children === 'function'
|
|
22
|
+
// ? props.children(value)
|
|
23
|
+
// : props.children;
|
|
24
|
+
// }
|
|
25
|
+
// return props.fallback ?? null;
|
|
26
|
+
// });
|
|
27
|
+
// }
|
|
28
|
+
export function Show(props) {
|
|
29
|
+
// Read `when` lazily through the prop getter so `when={cond()}` re-runs the caller's
|
|
30
|
+
// expression inside these memos (reactive), while `when={cond}` / `when={() => cond}`
|
|
31
|
+
// still work — resolveReactiveProp unwraps the accessor form once.
|
|
32
|
+
const when = resolveReactiveProp(() => props.when);
|
|
33
|
+
// const {when} = props
|
|
34
|
+
const value = createMemo(when, undefined);
|
|
35
|
+
const cond = createMemo(value, undefined);
|
|
36
|
+
return createMemo(() => {
|
|
37
|
+
// if (isResource(when)) {
|
|
38
|
+
// if (when.loading) {
|
|
39
|
+
// return props.fallback ?? null;
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
// const value = when();
|
|
43
|
+
const evaluate = cond();
|
|
44
|
+
if (evaluate) {
|
|
45
|
+
let children = props.children;
|
|
46
|
+
if (typeof children === 'function' && !isLitResult(children)) {
|
|
47
|
+
if (typeof value === 'function') {
|
|
48
|
+
// value = (value as any)() as any;
|
|
49
|
+
return untrack(() => {
|
|
50
|
+
if (!untrack(value))
|
|
51
|
+
return props.fallback;
|
|
52
|
+
return children(value());
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return children(value);
|
|
56
|
+
}
|
|
57
|
+
return children;
|
|
58
|
+
}
|
|
59
|
+
return props.fallback;
|
|
60
|
+
// if (isTruthy(value)) {
|
|
61
|
+
// let children = props.children;
|
|
62
|
+
// // handle children on jsx
|
|
63
|
+
// // if(Array.isArray(children)) {
|
|
64
|
+
// // children = makeArrayFlat(children);
|
|
65
|
+
// // // console.log('is truthy', children);
|
|
66
|
+
// // // if(children)
|
|
67
|
+
// // // children = (children as any[]).map((c: any) => typeof c === 'function' ? c(value) : c) as any;
|
|
68
|
+
// // // return children;
|
|
69
|
+
// // }
|
|
70
|
+
// if (typeof children === 'function' && !isLitResult(children)) {
|
|
71
|
+
// if (isSignal<any>(value)) {
|
|
72
|
+
// // value = (value as any)() as any;
|
|
73
|
+
// return (children as (item: T) => any)((value as any)());
|
|
74
|
+
// }
|
|
75
|
+
// return (children as (item: T) => any)(value as T);
|
|
76
|
+
// }
|
|
77
|
+
// return children;
|
|
78
|
+
// // return typeof props.children === 'function'
|
|
79
|
+
// // ? props.children(value)
|
|
80
|
+
// // : props.children;
|
|
81
|
+
// }
|
|
82
|
+
// let value =
|
|
83
|
+
// typeof condition === 'function' ? (condition as () => T)() : condition;
|
|
84
|
+
// if (value != null && value !== false) {
|
|
85
|
+
// // console.log('value', value);
|
|
86
|
+
// const children = props.children;
|
|
87
|
+
// if (typeof children === 'function' && !isLitResult(children)) {
|
|
88
|
+
// if (isSignal<any>(value)) {
|
|
89
|
+
// value = (value as any)() as any;
|
|
90
|
+
// }
|
|
91
|
+
// return (children as (item: T) => any)(value as T);
|
|
92
|
+
// }
|
|
93
|
+
// return children;
|
|
94
|
+
// }
|
|
95
|
+
return props.fallback ?? null;
|
|
96
|
+
}, undefined, { name: 'show' });
|
|
97
|
+
}
|
|
98
|
+
// export function Show1<T>(props: ShowProps<T>): any {
|
|
99
|
+
// const when = normalizeAccessor(props.when);
|
|
100
|
+
// return createMemo(
|
|
101
|
+
// () => {
|
|
102
|
+
// if (isResource(when)) {
|
|
103
|
+
// if (when.loading) {
|
|
104
|
+
// return props.fallback ?? null;
|
|
105
|
+
// }
|
|
106
|
+
// }
|
|
107
|
+
// const value = when();
|
|
108
|
+
// if (isTruthy(value)) {
|
|
109
|
+
// let children = props.children;
|
|
110
|
+
// // handle children on jsx
|
|
111
|
+
// // if(Array.isArray(children)) {
|
|
112
|
+
// // children = makeArrayFlat(children);
|
|
113
|
+
// // // console.log('is truthy', children);
|
|
114
|
+
// // // if(children)
|
|
115
|
+
// // // children = (children as any[]).map((c: any) => typeof c === 'function' ? c(value) : c) as any;
|
|
116
|
+
// // // return children;
|
|
117
|
+
// // }
|
|
118
|
+
// if (typeof children === 'function' && !isLitResult(children)) {
|
|
119
|
+
// if (isSignal<any>(value)) {
|
|
120
|
+
// // value = (value as any)() as any;
|
|
121
|
+
// return (children as (item: T) => any)((value as any)());
|
|
122
|
+
// }
|
|
123
|
+
// return (children as (item: T) => any)(value as T);
|
|
124
|
+
// }
|
|
125
|
+
// return children;
|
|
126
|
+
// // return typeof props.children === 'function'
|
|
127
|
+
// // ? props.children(value)
|
|
128
|
+
// // : props.children;
|
|
129
|
+
// }
|
|
130
|
+
// // let value =
|
|
131
|
+
// // typeof condition === 'function' ? (condition as () => T)() : condition;
|
|
132
|
+
// // if (value != null && value !== false) {
|
|
133
|
+
// // // console.log('value', value);
|
|
134
|
+
// // const children = props.children;
|
|
135
|
+
// // if (typeof children === 'function' && !isLitResult(children)) {
|
|
136
|
+
// // if (isSignal<any>(value)) {
|
|
137
|
+
// // value = (value as any)() as any;
|
|
138
|
+
// // }
|
|
139
|
+
// // return (children as (item: T) => any)(value as T);
|
|
140
|
+
// // }
|
|
141
|
+
// // return children;
|
|
142
|
+
// // }
|
|
143
|
+
// return props.fallback ?? null;
|
|
144
|
+
// },
|
|
145
|
+
// undefined,
|
|
146
|
+
// { name: 'show' }
|
|
147
|
+
// );
|
|
148
|
+
// }
|
|
149
|
+
// if (isTruthy(value)) {
|
|
150
|
+
// const children = props.children;
|
|
151
|
+
// if (typeof children === 'function' && !isLitResult(children)) {
|
|
152
|
+
// if (isSignal<any>(value)) {
|
|
153
|
+
// // value = (value as any)() as any;
|
|
154
|
+
// return (children as (item: T) => any)((value as any)());
|
|
155
|
+
// }
|
|
156
|
+
// return (children as (item: T) => any)(value as T);
|
|
157
|
+
// }
|
|
158
|
+
// return children;
|
|
159
|
+
// // return typeof props.children === 'function'
|
|
160
|
+
// // ? props.children(value)
|
|
161
|
+
// // : props.children;
|
|
162
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as o,untrack as a}from"@fluixi/reactive/signal";function i(e){return()=>{let n=e();return typeof n=="function"?n():n}}function s(e){return!e||typeof e!="object"?!1:!!(typeof e._$litType$<"u"||typeof e._$litDirective$<"u"||Array.isArray(e.strings)&&Array.isArray(e.values))}function p(e){let n=i(()=>e.when),r=o(n,void 0),c=o(r,void 0);return o(()=>{if(c()){let t=e.children;return typeof t=="function"&&!s(t)?typeof r=="function"?a(()=>a(r)?t(r()):e.fallback):t(r):t}return e.fallback},void 0,{name:"show"})}export{p as Show};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})},d=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of c(t))!a.call(e,n)&&n!==r&&o(e,n,{get:()=>t[n],enumerable:!(s=i(t,n))||s.enumerable});return e};var g=e=>d(o({},"__esModule",{value:!0}),e);var m={};f(m,{styleMap:()=>y});module.exports=g(m);var l=require("@fluixi/reactive/signal");function p(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function y(e){return(0,l.createMemo)(()=>{let t=typeof e=="function"?e():e,r=[];for(let[s,n]of Object.entries(t)){if(!s)continue;let u=typeof n=="function"?n():n;u!=null&&r.push(`${p(s)}: ${u}`)}return r.join("; ")})}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
/**
|
|
3
|
+
* A single style property value — static or reactive.
|
|
4
|
+
* Numbers are converted to strings as-is (no `px` appended automatically).
|
|
5
|
+
*/
|
|
6
|
+
export type StyleValue = string | number | null | undefined | Accessor<string | number | null | undefined> | (() => string | number | null | undefined);
|
|
7
|
+
/**
|
|
8
|
+
* The styleMap argument.
|
|
9
|
+
* Can be a plain object (values may be reactive) or a function / signal
|
|
10
|
+
* that returns the entire object reactively.
|
|
11
|
+
*
|
|
12
|
+
* Keys should be camelCase (`backgroundColor`) or CSS custom properties
|
|
13
|
+
* (`--my-color`). camelCase keys are converted to kebab-case automatically.
|
|
14
|
+
*/
|
|
15
|
+
export type StyleMapInput = Record<string, StyleValue> | Accessor<Record<string, StyleValue>> | (() => Record<string, StyleValue>);
|
|
16
|
+
/**
|
|
17
|
+
* Framework-agnostic reactive style map.
|
|
18
|
+
*
|
|
19
|
+
* Returns a `createMemo` accessor that resolves to an inline style string.
|
|
20
|
+
* The memo re-evaluates whenever any reactive dependency inside the map
|
|
21
|
+
* changes.
|
|
22
|
+
*
|
|
23
|
+
* Works in both JSX and lit-html without any renderer-specific code:
|
|
24
|
+
* - JSX: `<div style={styleMap({ color: textColor })} />`
|
|
25
|
+
* - lit-html: `style=${styleMap({ color: textColor })}`
|
|
26
|
+
*
|
|
27
|
+
* For lit-html the `processValues` helper detects the memo (via `$SIGNAL`)
|
|
28
|
+
* and wraps it with `litrx` automatically.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Static
|
|
32
|
+
* styleMap({ color: 'red', fontSize: '14px' })
|
|
33
|
+
*
|
|
34
|
+
* // Per-property reactive values
|
|
35
|
+
* styleMap({ color: textColor, opacity: () => opacity() })
|
|
36
|
+
*
|
|
37
|
+
* // Whole map reactive
|
|
38
|
+
* styleMap(() => ({ color: textColor(), '--accent': brand() }))
|
|
39
|
+
*
|
|
40
|
+
* // camelCase is converted automatically
|
|
41
|
+
* styleMap({ backgroundColor: '#fff', fontSize: '1rem' })
|
|
42
|
+
* // → "background-color: #fff; font-size: 1rem"
|
|
43
|
+
*
|
|
44
|
+
* // CSS custom properties pass through unchanged
|
|
45
|
+
* styleMap({ '--radius': radius })
|
|
46
|
+
* // → "--radius: 8px"
|
|
47
|
+
*/
|
|
48
|
+
export declare function styleMap(input: StyleMapInput): Accessor<string>;
|
|
49
|
+
//# sourceMappingURL=style-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-map.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/style-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,MAAM,GACN,IAAI,GACJ,SAAS,GACT,QAAQ,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,GAC5C,CAAC,MAAM,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAC1B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,GACpC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AASvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAsB/D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createMemo } from '@fluixi/reactive/signal';
|
|
2
|
+
/** camelCase → kebab-case; CSS custom properties (--) pass through unchanged. */
|
|
3
|
+
function toKebab(prop) {
|
|
4
|
+
return prop.startsWith('--')
|
|
5
|
+
? prop
|
|
6
|
+
: prop.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Framework-agnostic reactive style map.
|
|
10
|
+
*
|
|
11
|
+
* Returns a `createMemo` accessor that resolves to an inline style string.
|
|
12
|
+
* The memo re-evaluates whenever any reactive dependency inside the map
|
|
13
|
+
* changes.
|
|
14
|
+
*
|
|
15
|
+
* Works in both JSX and lit-html without any renderer-specific code:
|
|
16
|
+
* - JSX: `<div style={styleMap({ color: textColor })} />`
|
|
17
|
+
* - lit-html: `style=${styleMap({ color: textColor })}`
|
|
18
|
+
*
|
|
19
|
+
* For lit-html the `processValues` helper detects the memo (via `$SIGNAL`)
|
|
20
|
+
* and wraps it with `litrx` automatically.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Static
|
|
24
|
+
* styleMap({ color: 'red', fontSize: '14px' })
|
|
25
|
+
*
|
|
26
|
+
* // Per-property reactive values
|
|
27
|
+
* styleMap({ color: textColor, opacity: () => opacity() })
|
|
28
|
+
*
|
|
29
|
+
* // Whole map reactive
|
|
30
|
+
* styleMap(() => ({ color: textColor(), '--accent': brand() }))
|
|
31
|
+
*
|
|
32
|
+
* // camelCase is converted automatically
|
|
33
|
+
* styleMap({ backgroundColor: '#fff', fontSize: '1rem' })
|
|
34
|
+
* // → "background-color: #fff; font-size: 1rem"
|
|
35
|
+
*
|
|
36
|
+
* // CSS custom properties pass through unchanged
|
|
37
|
+
* styleMap({ '--radius': radius })
|
|
38
|
+
* // → "--radius: 8px"
|
|
39
|
+
*/
|
|
40
|
+
export function styleMap(input) {
|
|
41
|
+
return createMemo(() => {
|
|
42
|
+
const map = typeof input === 'function'
|
|
43
|
+
? input()
|
|
44
|
+
: input;
|
|
45
|
+
const parts = [];
|
|
46
|
+
for (const [prop, val] of Object.entries(map)) {
|
|
47
|
+
if (!prop)
|
|
48
|
+
continue;
|
|
49
|
+
const resolved = typeof val === 'function'
|
|
50
|
+
? val()
|
|
51
|
+
: val;
|
|
52
|
+
if (resolved != null) {
|
|
53
|
+
parts.push(`${toKebab(prop)}: ${resolved}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return parts.join('; ');
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as u}from"@fluixi/reactive/signal";function l(e){return e.startsWith("--")?e:e.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function a(e){return u(()=>{let t=typeof e=="function"?e():e,r=[];for(let[s,n]of Object.entries(t)){if(!s)continue;let o=typeof n=="function"?n():n;o!=null&&r.push(`${l(s)}: ${o}`)}return r.join("; ")})}export{a as styleMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(e,n)=>{for(var c in n)o(e,c,{get:n[c],enumerable:!0})},y=(e,n,c,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of h(n))!T.call(e,t)&&t!==c&&o(e,t,{get:()=>n[t],enumerable:!(r=u(n,t))||r.enumerable});return e};var A=e=>y(o({},"__esModule",{value:!0}),e);var b={};d(b,{Match:()=>p,Switch:()=>M});module.exports=A(b);var f=require("@fluixi/reactive/signal");function a(e){return()=>{let n=e();return typeof n=="function"?n():n}}function l(e){return e!=null&&e!==!1}var i=Symbol("match");function p(e){return{[i]:!0,when:a(()=>e.when),children:e.children}}function M(e){let n=Array.isArray(e.children)?e.children:[e.children];return(0,f.createMemo)(()=>{for(let c of n){let r=c,t=0;for(;typeof r=="function"&&!r[i]&&t++<10;)r=r();if(!r||typeof r!="object"||r[i]!==!0)continue;let s=r.when();if(l(s))return typeof r.children=="function"?r.children(s):r.children}return e.fallback??null})}
|