@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 @@
|
|
|
1
|
+
function m(e){return e.startsWith("aria-")||e.startsWith("data-")?e:/[A-Z]/.test(e)?e.replace(/([A-Z])/g,"-$1").toLowerCase():e}function g(e){return e.startsWith("@")||e.startsWith("on")&&e.length>2}function E(e){return e.startsWith("@")?e.slice(1):e.startsWith("on")?e.slice(2).toLowerCase():e}function b(e,t){let n=new Set(["checked","value","selected","disabled","readonly","required","multiple","open","contenteditable","draggable","spellcheck"]),r={input:new Set(["value","checked","indeterminate"]),textarea:new Set(["value"]),select:new Set(["value"]),option:new Set(["selected","value"]),audio:new Set(["volume","currentTime","paused"]),video:new Set(["volume","currentTime","paused"]),img:new Set(["src","srcset"]),iframe:new Set(["src"]),a:new Set(["href"])};return n.has(t)||r[e]&&r[e].has(t)}var x=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),h=new Set(["svg","g","path","circle","rect","line","polyline","polygon","ellipse","text","tspan","use","defs","symbol","mask","clipPath","pattern","linearGradient","radialGradient","stop","filter","feGaussianBlur","feOffset","feMerge","feMergeNode","foreignObject"]),y="http://www.w3.org/2000/svg";function u(e){return e.localName.includes("-")}function w(e,t,n,r=!1){if(n==null){e.removeAttribute(t);return}if(u(e)){e[t]=n;return}c(e,t,n,r)}var T=new Set(["className","value","checked","selected","innerHTML","innerText","textContent","indeterminate","htmlFor"]);function a(e,t=document){return t.querySelector(e)}function v(e,t=document){return Array.from(t.querySelectorAll(e))}function S(e,t){return e.closest(t)}function A(e,...t){e.classList.add(...t)}function L(e,...t){e.classList.remove(...t)}function C(e,...t){t.forEach(n=>e.classList.toggle(n))}function N(e,t){return e.classList.contains(t)}function c(e,t,n,r=!1){if(n==null||n===!1){e.removeAttribute(t);return}if(n===!0){e.setAttribute(t,"");return}if(typeof n=="object"){e.setAttribute(t,JSON.stringify(n));return}e.setAttribute(t,String(n))}function M(e,t){return e.getAttribute(t)}function O(e,t){e.removeAttribute(t)}function f(e,t){Object.assign(e.style,t)}function I(e,t){return window.getComputedStyle(e).getPropertyValue(t)}function P(e,t={},...n){let r=document.createElement(e);return Object.entries(t).forEach(([o,i])=>{if(o==="class"||o==="className")r.className=i;else if(o==="style"&&typeof i=="object")f(r,i);else if(o.startsWith("on")&&typeof i=="function"){let s=o.slice(2).toLowerCase();r.addEventListener(s,i)}else c(r,o,i)}),n.forEach(o=>{typeof o=="string"?r.appendChild(document.createTextNode(o)):r.appendChild(o)}),r}function R(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function H(e,...t){t.forEach(n=>{typeof n=="string"?e.appendChild(document.createTextNode(n)):e.appendChild(n)})}function V(e){let t=e.getBoundingClientRect();return t.top>=0&&t.left>=0&&t.bottom<=window.innerHeight&&t.right<=window.innerWidth}function j(e,t={behavior:"smooth",block:"nearest"}){e.scrollIntoView(t)}function G(e){let t=e.getBoundingClientRect();return{top:t.top+window.pageYOffset,left:t.left+window.pageXOffset}}function W(e,t,n,r){let o=i=>{let s=i.target.closest(n);s&&e.contains(s)&&r(i,s)};return e.addEventListener(t,o),()=>{e.removeEventListener(t,o)}}function $(e,t=5e3){return new Promise((n,r)=>{let o=a(e);if(o){n(o);return}let i=new MutationObserver(()=>{let l=a(e);l&&(i.disconnect(),clearTimeout(s),n(l))});i.observe(document.body,{childList:!0,subtree:!0});let s=setTimeout(()=>{i.disconnect(),r(new Error(`Element ${e} not found within ${t}ms`))},t)})}function q(e,t,n={}){let r=new IntersectionObserver(o=>{o.forEach(i=>{t(i.isIntersecting)})},n);return r.observe(e),()=>{r.disconnect()}}function D(e,t){let n=new ResizeObserver(r=>{r.forEach(t)});return n.observe(e),()=>{n.disconnect()}}var d=typeof Symbol=="function"&&Symbol.for?Symbol.for("react.element"):60103;function F(e){return typeof e=="object"&&e!==null&&e.$$typeof===d}function p(e){return e&&typeof e=="object"&&e.strings&&Array.isArray(e.strings)&&e.values&&Array.isArray(e.values)}function z(e){if(typeof e!="function")return!1;try{let t=e();return p(t)}catch{return!1}}function B(e){return typeof e=="object"&&e!==null&&(e.$$typeof==="template"||typeof e.type=="function")}function J(e){return e instanceof Node}function X(e,t,n="Fluixi"){typeof globalThis<"u"&&(typeof globalThis[n]>"u"&&(globalThis[n]={}),typeof globalThis[n][e]>"u"&&(globalThis[n][e]=t))}function K(e,t,n="Fluixi"){return typeof globalThis<"u"&&typeof globalThis[n]<"u"&&typeof globalThis[n][e]<"u"?globalThis[n][e]:t}export{T as JSX_PROPERTIES,h as SVG_ELEMENTS,y as SVG_NAMESPACE,x as VOID_ELEMENTS,A as addClass,H as appendChildren,w as applyElementProp,S as closest,P as createElement,W as delegate,M as getAttribute,K as getGlobal,E as getLitEventName,G as getOffset,I as getStyle,N as hasClass,u as isCustomElement,J as isDOMNode,g as isEventHandler,B as isJSXTemplate,p as isLitTemplateResult,F as isReactElement,z as isTemplateFactory,V as isVisible,q as observeIntersection,D as observeResize,a as query,v as queryAll,X as registerGlobal,O as removeAttribute,R as removeChildren,L as removeClass,j as scrollIntoView,c as setAttribute,f as setStyles,b as shouldSetAsProperty,m as toAttributeName,C as toggleClass,$ as waitForElement};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var m=(p,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of f(e))!j.call(p,t)&&t!==s&&r(p,t,{get:()=>e[t],enumerable:!(o=y(e,t))||o.enumerable});return p};var x=p=>m(r({},"__esModule",{value:!0}),p);var a={};module.exports=x(a);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/element/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!d.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(i=s(e,n))||i.enumerable});return t};var a=t=>p(o({},"__esModule",{value:!0}),t);var f={};module.exports=a(f);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Advanced types for @fluixi/element
|
|
3
|
+
* @module @fluixi/dom/element/types
|
|
4
|
+
*/
|
|
5
|
+
export type PropTypeConstructor = typeof String | typeof Number | typeof Boolean | typeof Object | typeof Array;
|
|
6
|
+
export interface PropDefinition<T = unknown> {
|
|
7
|
+
type?: PropTypeConstructor;
|
|
8
|
+
default?: T;
|
|
9
|
+
attribute?: string | false;
|
|
10
|
+
}
|
|
11
|
+
/** Resolve the TS type from a PropDefinition's `type` constructor */
|
|
12
|
+
export type InferPropType<D extends PropDefinition> = D extends PropDefinition<infer Def> ? D['type'] extends typeof String ? string : D['type'] extends typeof Number ? number : D['type'] extends typeof Boolean ? boolean : D['type'] extends typeof Array ? unknown[] : D['type'] extends typeof Object ? Record<string, unknown> : Def extends undefined ? unknown : Def : unknown;
|
|
13
|
+
/** Signal tuple: [accessor, setter] — matches createSignal return */
|
|
14
|
+
export type SignalTuple<T> = [
|
|
15
|
+
get: () => T,
|
|
16
|
+
set: (v: T | ((prev: T) => T)) => void
|
|
17
|
+
];
|
|
18
|
+
/** Map prop defs to signal tuples with correct types */
|
|
19
|
+
export type PropsSignals<T extends Record<string, PropDefinition>> = {
|
|
20
|
+
[K in keyof T]: SignalTuple<InferPropType<T[K]>>;
|
|
21
|
+
};
|
|
22
|
+
/** Render function for defineElement — fully typed props and event context */
|
|
23
|
+
export type ElementRenderFn<T extends Record<string, PropDefinition>, E extends Record<string, EventDefinition> = Record<string, EventDefinition>> = (props: PropsSignals<T>, ctx: ElementRenderContext<E>) => unknown;
|
|
24
|
+
export interface EventDefinition<T = unknown> {
|
|
25
|
+
detail?: T;
|
|
26
|
+
}
|
|
27
|
+
/** Map event defs to typed onXxx handlers */
|
|
28
|
+
export type ElementEventHandlers<E extends Record<string, EventDefinition>> = {
|
|
29
|
+
[K in keyof E as K extends string ? `on${Capitalize<K>}` : never]?: (event: CustomEvent<E[K] extends EventDefinition<infer D> ? D : unknown>) => void;
|
|
30
|
+
};
|
|
31
|
+
/** Context object passed as second argument to defineElement render callback */
|
|
32
|
+
export interface ElementRenderContext<E extends Record<string, EventDefinition>> {
|
|
33
|
+
emit: <K extends string & keyof E>(name: K, ...args: E[K] extends EventDefinition<infer D> ? D extends undefined ? [] : [detail: D] : [detail?: unknown]) => void;
|
|
34
|
+
}
|
|
35
|
+
export interface ElementLifecycleCallbacks {
|
|
36
|
+
connectedCallback?: (host: HTMLElement) => void;
|
|
37
|
+
disconnectedCallback?: (host: HTMLElement) => void;
|
|
38
|
+
adoptedCallback?: (host: HTMLElement) => void;
|
|
39
|
+
formAssociatedCallback?: (host: HTMLElement, form: HTMLFormElement | null) => void;
|
|
40
|
+
formDisabledCallback?: (host: HTMLElement, disabled: boolean) => void;
|
|
41
|
+
formResetCallback?: (host: HTMLElement) => void;
|
|
42
|
+
formStateRestoreCallback?: (host: HTMLElement, state: unknown, mode: 'restore' | 'autocomplete') => void;
|
|
43
|
+
onAttributeChange?: (host: HTMLElement, name: string, oldVal: string | null, newVal: string | null) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface DefineElementOptions<P extends Record<string, PropDefinition> = Record<string, PropDefinition>, E extends Record<string, EventDefinition> = Record<string, EventDefinition>> {
|
|
46
|
+
shadow?: 'open' | 'closed' | 'none';
|
|
47
|
+
styles?: string | CSSStyleSheet | (string | CSSStyleSheet)[];
|
|
48
|
+
props?: P;
|
|
49
|
+
events?: E;
|
|
50
|
+
formAssociated?: boolean;
|
|
51
|
+
lifecycle?: ElementLifecycleCallbacks;
|
|
52
|
+
}
|
|
53
|
+
/** Convert prop defs into the attribute interface for JSX / vanilla / lit */
|
|
54
|
+
export type ElementAttributes<P extends Record<string, PropDefinition>> = {
|
|
55
|
+
[K in keyof P]?: InferPropType<P[K]> | (() => InferPropType<P[K]>);
|
|
56
|
+
};
|
|
57
|
+
/** HTMLElement with typed setProp/getProp */
|
|
58
|
+
export interface TypedFluixiElement<P extends Record<string, PropDefinition>> extends HTMLElement {
|
|
59
|
+
setProp<K extends string & keyof P>(name: K, value: InferPropType<P[K]>): void;
|
|
60
|
+
getProp<K extends string & keyof P>(name: K): InferPropType<P[K]>;
|
|
61
|
+
}
|
|
62
|
+
/** Constructor type returned by defineElement — carries tag name + prop types + event types */
|
|
63
|
+
export interface FluixiElementConstructor<Tag extends string = string, P extends Record<string, PropDefinition> = Record<string, PropDefinition>, E extends Record<string, EventDefinition> = Record<string, EventDefinition>> {
|
|
64
|
+
new (): TypedFluixiElement<P>;
|
|
65
|
+
observedAttributes: string[];
|
|
66
|
+
readonly prototype: TypedFluixiElement<P>;
|
|
67
|
+
readonly __tag: Tag;
|
|
68
|
+
readonly __props: P;
|
|
69
|
+
readonly __events: E;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Extract the JSX attributes interface from a FluixiElementConstructor.
|
|
73
|
+
* Use in `declare global { interface HTMLElementTagNameMap }`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const MyCounter = defineElement('my-counter', ..., { props: { name: { type: String } } });
|
|
78
|
+
* declare global {
|
|
79
|
+
* interface HTMLElementTagNameMap {
|
|
80
|
+
* 'my-counter': FluixiElementInstance<typeof MyCounter>;
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export type FluixiElementInstance<T> = T extends FluixiElementConstructor<any, infer P> ? TypedFluixiElement<P> : HTMLElement;
|
|
86
|
+
/**
|
|
87
|
+
* Extract JSX-compatible attributes from a FluixiElementConstructor.
|
|
88
|
+
* For use in JSX IntrinsicElements augmentation.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* declare module '@fluixi/jsx/jsx' {
|
|
93
|
+
* namespace JSX {
|
|
94
|
+
* interface IntrinsicElements {
|
|
95
|
+
* 'my-counter': FluixiElementJSXAttributes<typeof MyCounter>;
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export type FluixiElementJSXAttributes<T> = T extends FluixiElementConstructor<any, infer P, infer E> ? ElementAttributes<P> & ElementEventHandlers<E> & FluixiHTMLAttributes : FluixiHTMLAttributes;
|
|
102
|
+
/** Base HTML attributes for custom elements in JSX */
|
|
103
|
+
export interface FluixiHTMLAttributes {
|
|
104
|
+
id?: string;
|
|
105
|
+
class?: string;
|
|
106
|
+
className?: string;
|
|
107
|
+
style?: string | Record<string, string | number>;
|
|
108
|
+
slot?: string;
|
|
109
|
+
hidden?: boolean;
|
|
110
|
+
tabIndex?: number;
|
|
111
|
+
title?: string;
|
|
112
|
+
children?: unknown;
|
|
113
|
+
ref?: ((el: HTMLElement) => void) | {
|
|
114
|
+
current: HTMLElement | null;
|
|
115
|
+
};
|
|
116
|
+
[key: `on${string}`]: ((event: Event) => void) | undefined;
|
|
117
|
+
[key: `data-${string}`]: string | undefined;
|
|
118
|
+
}
|
|
119
|
+
/** Map to build HTML attribute keys from prop defs (uses attribute override or kebab-case) */
|
|
120
|
+
export type PropToAttribute<P extends Record<string, PropDefinition>> = {
|
|
121
|
+
[K in keyof P as P[K] extends {
|
|
122
|
+
attribute: false;
|
|
123
|
+
} ? never : P[K] extends {
|
|
124
|
+
attribute: infer A extends string;
|
|
125
|
+
} ? A : K extends string ? CamelToKebab<K> : never]?: InferPropType<P[K]>;
|
|
126
|
+
};
|
|
127
|
+
/** CamelCase → kebab-case at the type level */
|
|
128
|
+
export type CamelToKebab<S extends string> = S extends `${infer C}${infer Rest}` ? C extends Uppercase<C> ? `-${Lowercase<C>}${CamelToKebab<Rest>}` : `${C}${CamelToKebab<Rest>}` : S;
|
|
129
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/element/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MA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S,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,IAAI;KACrE,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QAAE,SAAS,EAAE,KAAK,CAAA;KAAE,GAC9C,KAAK,GACL,CAAC,CAAC,CAAC,CAAC,SAAS;QAAE,SAAS,EAAE,MAAM,CAAC,SAAS,MAAM,CAAA;KAAE,GAClD,CAAC,GACD,CAAC,SAAS,MAAM,GAChB,YAAY,CAAC,CAAC,CAAC,GACf,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,MAAM,IAAI,EAAE,GAC5E,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,GACpB,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,GACvC,GAAG,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,GAC7B,CAAC,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(n,o)=>{for(var e in o)i(n,e,{get:o[e],enumerable:!0})},u=(n,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of a(o))!l.call(n,s)&&s!==e&&i(n,s,{get:()=>o[s],enumerable:!(t=r(o,s))||t.enumerable});return n};var f=n=>u(i({},"__esModule",{value:!0}),n);var C={};d(C,{classMap:()=>p});module.exports=f(C);var c=require("@fluixi/reactive/signal");function p(n){return(0,c.createMemo)(()=>{let o=typeof n=="function"?n():n,e=[];for(let[t,s]of Object.entries(o)){if(!t)continue;(typeof s=="function"?s():s)&&e.push(t)}return e.join(" ")})}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
/**
|
|
3
|
+
* A single class condition — static boolean or a reactive function.
|
|
4
|
+
*/
|
|
5
|
+
export type ClassCondition = boolean | null | undefined | Accessor<boolean | null | undefined> | (() => boolean | null | undefined);
|
|
6
|
+
/**
|
|
7
|
+
* The classMap argument.
|
|
8
|
+
* Can be a plain object (values may be reactive) or a function / signal
|
|
9
|
+
* that returns the entire object reactively.
|
|
10
|
+
*/
|
|
11
|
+
export type ClassMapInput = Record<string, ClassCondition> | Accessor<Record<string, ClassCondition>> | (() => Record<string, ClassCondition>);
|
|
12
|
+
/**
|
|
13
|
+
* Framework-agnostic reactive class map.
|
|
14
|
+
*
|
|
15
|
+
* Returns a `createMemo` accessor that resolves to a space-separated
|
|
16
|
+
* class string. The memo re-evaluates whenever any reactive dependency
|
|
17
|
+
* inside the map changes.
|
|
18
|
+
*
|
|
19
|
+
* Works in both JSX and lit-html without any renderer-specific code:
|
|
20
|
+
* - JSX: `<div class={classMap({ active: isActive })} />`
|
|
21
|
+
* - lit-html: `class=${classMap({ active: isActive })}`
|
|
22
|
+
*
|
|
23
|
+
* For lit-html the `processValues` helper detects the memo (via `$SIGNAL`)
|
|
24
|
+
* and wraps it with `litrx` automatically.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Static
|
|
28
|
+
* classMap({ active: true, disabled: false }) // → "active"
|
|
29
|
+
*
|
|
30
|
+
* // Per-key reactive values
|
|
31
|
+
* classMap({ active: isActive, 'text-sm': () => size() === 'sm' })
|
|
32
|
+
*
|
|
33
|
+
* // Whole map reactive
|
|
34
|
+
* classMap(() => ({ active: isActive(), error: hasError() }))
|
|
35
|
+
*
|
|
36
|
+
* // Mixed — combine a static base class with reactive conditions
|
|
37
|
+
* classMap({ 'btn': true, 'btn-primary': isPrimary, 'btn-disabled': disabled })
|
|
38
|
+
*/
|
|
39
|
+
export declare function classMap(input: ClassMapInput): Accessor<string>;
|
|
40
|
+
//# sourceMappingURL=class-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-map.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/class-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,OAAO,GACP,IAAI,GACJ,SAAS,GACT,QAAQ,CAAC,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,GACpC,CAAC,MAAM,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEvC;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAC9B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,GACxC,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAkB/D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { createMemo } from '@fluixi/reactive/signal';
|
|
2
|
+
/**
|
|
3
|
+
* Framework-agnostic reactive class map.
|
|
4
|
+
*
|
|
5
|
+
* Returns a `createMemo` accessor that resolves to a space-separated
|
|
6
|
+
* class string. The memo re-evaluates whenever any reactive dependency
|
|
7
|
+
* inside the map changes.
|
|
8
|
+
*
|
|
9
|
+
* Works in both JSX and lit-html without any renderer-specific code:
|
|
10
|
+
* - JSX: `<div class={classMap({ active: isActive })} />`
|
|
11
|
+
* - lit-html: `class=${classMap({ active: isActive })}`
|
|
12
|
+
*
|
|
13
|
+
* For lit-html the `processValues` helper detects the memo (via `$SIGNAL`)
|
|
14
|
+
* and wraps it with `litrx` automatically.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Static
|
|
18
|
+
* classMap({ active: true, disabled: false }) // → "active"
|
|
19
|
+
*
|
|
20
|
+
* // Per-key reactive values
|
|
21
|
+
* classMap({ active: isActive, 'text-sm': () => size() === 'sm' })
|
|
22
|
+
*
|
|
23
|
+
* // Whole map reactive
|
|
24
|
+
* classMap(() => ({ active: isActive(), error: hasError() }))
|
|
25
|
+
*
|
|
26
|
+
* // Mixed — combine a static base class with reactive conditions
|
|
27
|
+
* classMap({ 'btn': true, 'btn-primary': isPrimary, 'btn-disabled': disabled })
|
|
28
|
+
*/
|
|
29
|
+
export function classMap(input) {
|
|
30
|
+
return createMemo(() => {
|
|
31
|
+
const map = typeof input === 'function'
|
|
32
|
+
? input()
|
|
33
|
+
: input;
|
|
34
|
+
const classes = [];
|
|
35
|
+
for (const [cls, cond] of Object.entries(map)) {
|
|
36
|
+
if (!cls)
|
|
37
|
+
continue;
|
|
38
|
+
const active = typeof cond === 'function' ? cond() : cond;
|
|
39
|
+
if (active)
|
|
40
|
+
classes.push(cls);
|
|
41
|
+
}
|
|
42
|
+
return classes.join(' ');
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as i}from"@fluixi/reactive/signal";function l(n){return i(()=>{let t=typeof n=="function"?n():n,s=[];for(let[e,o]of Object.entries(t)){if(!e)continue;(typeof o=="function"?o():o)&&s.push(e)}return s.join(" ")})}export{l as classMap};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var y=(n,r)=>{for(var o in r)s(n,o,{get:r[o],enumerable:!0})},u=(n,r,o,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of f(r))!p.call(n,e)&&e!==o&&s(n,e,{get:()=>r[e],enumerable:!(t=a(r,e))||t.enumerable});return n};var T=n=>u(s({},"__esModule",{value:!0}),n);var d={};y(d,{Dynamic:()=>l});module.exports=T(d);var i=require("@fluixi/reactive/signal");function c(n){return typeof n=="function"?n:(()=>n)}function l(n){let r=c(n.component),{component:o,...t}=n;return(0,i.createMemo)(()=>{let e=r();return e==null?null:typeof e=="string"?{tag:e,props:t}:e(t)})}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
export interface DynamicProps<T extends Record<string, any> = Record<string, any>> {
|
|
3
|
+
/**
|
|
4
|
+
* A component function (or null/undefined) to render.
|
|
5
|
+
* Can be a reactive accessor that changes over time.
|
|
6
|
+
*
|
|
7
|
+
* JSX: <Dynamic component={currentView()} {...props} />
|
|
8
|
+
* lit: Dynamic({ component: currentView, ...props })
|
|
9
|
+
*/
|
|
10
|
+
component: ((props: T) => any) | string | null | undefined | Accessor<((props: T) => any) | string | null | undefined>;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Renders a component dynamically — mirrors SolidJS `<Dynamic>`.
|
|
15
|
+
*
|
|
16
|
+
* The `component` prop can be a reactive accessor. When it changes,
|
|
17
|
+
* the old output is discarded and the new component is called.
|
|
18
|
+
* Returns a memo — works in both JSX and lit-html.
|
|
19
|
+
*
|
|
20
|
+
* @example JSX
|
|
21
|
+
* <Dynamic component={tab() === 'a' ? CompA : CompB} value={x()} />
|
|
22
|
+
*
|
|
23
|
+
* @example lit-html
|
|
24
|
+
* Dynamic({ component: () => tab() === 'a' ? CompA : CompB, value: x })
|
|
25
|
+
*/
|
|
26
|
+
export declare function Dynamic<T extends Record<string, any> = Record<string, any>>(props: DynamicProps<T>): Accessor<any>;
|
|
27
|
+
//# sourceMappingURL=dynamic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/dynamic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAG/D,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC/E;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IACvH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GACrB,QAAQ,CAAC,GAAG,CAAC,CAef"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createMemo } from '@fluixi/reactive/signal';
|
|
2
|
+
import { normalizeAccessor } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a component dynamically — mirrors SolidJS `<Dynamic>`.
|
|
5
|
+
*
|
|
6
|
+
* The `component` prop can be a reactive accessor. When it changes,
|
|
7
|
+
* the old output is discarded and the new component is called.
|
|
8
|
+
* Returns a memo — works in both JSX and lit-html.
|
|
9
|
+
*
|
|
10
|
+
* @example JSX
|
|
11
|
+
* <Dynamic component={tab() === 'a' ? CompA : CompB} value={x()} />
|
|
12
|
+
*
|
|
13
|
+
* @example lit-html
|
|
14
|
+
* Dynamic({ component: () => tab() === 'a' ? CompA : CompB, value: x })
|
|
15
|
+
*/
|
|
16
|
+
export function Dynamic(props) {
|
|
17
|
+
const getComponent = normalizeAccessor(props.component);
|
|
18
|
+
// Spread all props except `component` to the resolved component.
|
|
19
|
+
const { component: _c, ...rest } = props;
|
|
20
|
+
return createMemo(() => {
|
|
21
|
+
const C = getComponent();
|
|
22
|
+
if (C == null)
|
|
23
|
+
return null;
|
|
24
|
+
if (typeof C === 'string') {
|
|
25
|
+
// Intrinsic element — return a descriptor that the runtime can handle.
|
|
26
|
+
return { tag: C, props: rest };
|
|
27
|
+
}
|
|
28
|
+
return C(rest);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as s}from"@fluixi/reactive/signal";function o(n){return typeof n=="function"?n:(()=>n)}function y(n){let t=o(n.component),{component:c,...e}=n;return s(()=>{let r=t();return r==null?null:typeof r=="string"?{tag:r,props:e}:r(e)})}export{y as Dynamic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var y=(n,r)=>{for(var t in r)l(n,t,{get:r[t],enumerable:!0})},k=(n,r,t,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of u(r))!i.call(n,e)&&e!==t&&l(n,e,{get:()=>r[e],enumerable:!(c=f(r,e))||c.enumerable});return n};var d=n=>k(l({},"__esModule",{value:!0}),n);var h={};y(h,{ErrorBoundary:()=>b});module.exports=d(h);var a=require("@fluixi/reactive/signal");function b(n){let[r,t]=(0,a.createSignal)(null),c=()=>t(null);return(0,a.createMemo)(()=>{let e=r();if(e!==null)return typeof n.fallback=="function"?n.fallback(e,c):n.fallback;try{return typeof n.children=="function"?n.children():n.children}catch(o){return t(o),typeof n.fallback=="function"?n.fallback(o,c):n.fallback}})}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
export interface ErrorBoundaryProps {
|
|
3
|
+
/** Rendered when an error is caught. Receives the error as argument. */
|
|
4
|
+
fallback: any | ((err: unknown, reset: () => void) => any);
|
|
5
|
+
/** The children to try rendering. */
|
|
6
|
+
children: any;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Catches synchronous errors thrown during child rendering.
|
|
10
|
+
*
|
|
11
|
+
* When a child throws, renders `fallback` instead. `fallback` can be a
|
|
12
|
+
* static value or a function `(err, reset) => UI` — calling `reset()` clears
|
|
13
|
+
* the error state and retries rendering the children.
|
|
14
|
+
*
|
|
15
|
+
* Returns a memo — works in both JSX and lit-html.
|
|
16
|
+
*
|
|
17
|
+
* Note: Only catches errors thrown synchronously during the render phase
|
|
18
|
+
* (memo evaluation). Async errors inside effects are not caught here.
|
|
19
|
+
*
|
|
20
|
+
* @example JSX
|
|
21
|
+
* <ErrorBoundary fallback={(err, reset) => (
|
|
22
|
+
* <div>Error: {String(err)} <button onClick={reset}>Retry</button></div>
|
|
23
|
+
* )}>
|
|
24
|
+
* <RiskyComponent />
|
|
25
|
+
* </ErrorBoundary>
|
|
26
|
+
*
|
|
27
|
+
* @example lit-html
|
|
28
|
+
* ErrorBoundary({
|
|
29
|
+
* fallback: (err, reset) => html`<button @click=${reset}>Retry</button>`,
|
|
30
|
+
* children: html`${riskyContent}`,
|
|
31
|
+
* })
|
|
32
|
+
*/
|
|
33
|
+
export declare function ErrorBoundary(props: ErrorBoundaryProps): Accessor<any>;
|
|
34
|
+
//# sourceMappingURL=error-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/error-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmD,MAAM,yBAAyB,CAAC;AAEpG,MAAM,WAAW,kBAAkB;IACjC,wEAAwE;IACxE,QAAQ,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,CAAC;IAC3D,qCAAqC;IACrC,QAAQ,EAAE,GAAG,CAAC;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,QAAQ,CAAC,GAAG,CAAC,CA0BtE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createMemo, createSignal } from '@fluixi/reactive/signal';
|
|
2
|
+
/**
|
|
3
|
+
* Catches synchronous errors thrown during child rendering.
|
|
4
|
+
*
|
|
5
|
+
* When a child throws, renders `fallback` instead. `fallback` can be a
|
|
6
|
+
* static value or a function `(err, reset) => UI` — calling `reset()` clears
|
|
7
|
+
* the error state and retries rendering the children.
|
|
8
|
+
*
|
|
9
|
+
* Returns a memo — works in both JSX and lit-html.
|
|
10
|
+
*
|
|
11
|
+
* Note: Only catches errors thrown synchronously during the render phase
|
|
12
|
+
* (memo evaluation). Async errors inside effects are not caught here.
|
|
13
|
+
*
|
|
14
|
+
* @example JSX
|
|
15
|
+
* <ErrorBoundary fallback={(err, reset) => (
|
|
16
|
+
* <div>Error: {String(err)} <button onClick={reset}>Retry</button></div>
|
|
17
|
+
* )}>
|
|
18
|
+
* <RiskyComponent />
|
|
19
|
+
* </ErrorBoundary>
|
|
20
|
+
*
|
|
21
|
+
* @example lit-html
|
|
22
|
+
* ErrorBoundary({
|
|
23
|
+
* fallback: (err, reset) => html`<button @click=${reset}>Retry</button>`,
|
|
24
|
+
* children: html`${riskyContent}`,
|
|
25
|
+
* })
|
|
26
|
+
*/
|
|
27
|
+
export function ErrorBoundary(props) {
|
|
28
|
+
const [error, setError] = createSignal(null);
|
|
29
|
+
const reset = () => setError(null);
|
|
30
|
+
return createMemo(() => {
|
|
31
|
+
const err = error();
|
|
32
|
+
if (err !== null) {
|
|
33
|
+
return typeof props.fallback === 'function'
|
|
34
|
+
? props.fallback(err, reset)
|
|
35
|
+
: props.fallback;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const content = typeof props.children === 'function' ? props.children() : props.children;
|
|
39
|
+
return content;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
// Caught a synchronous render error — switch to fallback.
|
|
43
|
+
setError(e);
|
|
44
|
+
return typeof props.fallback === 'function'
|
|
45
|
+
? props.fallback(e, reset)
|
|
46
|
+
: props.fallback;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createMemo as o,createSignal as l}from"@fluixi/reactive/signal";function k(n){let[a,e]=l(null),t=()=>e(null);return o(()=>{let c=a();if(c!==null)return typeof n.fallback=="function"?n.fallback(c,t):n.fallback;try{return typeof n.children=="function"?n.children():n.children}catch(r){return e(r),typeof n.fallback=="function"?n.fallback(r,t):n.fallback}})}export{k as ErrorBoundary};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var x=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},v=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of T(e))!A.call(r,n)&&n!==t&&u(r,n,{get:()=>e[n],enumerable:!(a=f(e,n))||a.enumerable});return r};var U=r=>v(u({},"__esModule",{value:!0}),r);var b={};x(b,{For:()=>m});module.exports=U(b);var i=require("@fluixi/reactive/signal");function p(r){return()=>{let e=r();return typeof e=="function"?e():e}}var c={active:!1,cursor:null,parents:[]};function h(r){let e=c.parents.lastIndexOf(r);e!==-1&&(c.parents.length=e),c.cursor=r.nextSibling}function d(r){if(!c.active||r==null)return;let e=Array.isArray(r)?r[r.length-1]:r;e&&typeof e.nodeType=="number"&&h(e)}function m(r){let e=p(()=>r.each),t=()=>r.fallback??null,a=(n,o)=>{let s=r.children,y=Array.isArray(s)?s.map(l=>typeof l=="function"?l(n,o):l):typeof s=="function"?s(n,o):s;return d(y),y};return r.by?(0,i.keyArray)(e,r.by,(n,o)=>a(n,o),{fallback:t}):(0,i.mapArray)(e,(n,o)=>a(n,o),{fallback:t})}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
type EachSource<T> = ReadonlyArray<T> | (() => ReadonlyArray<T> | null | undefined) | Accessor<ReadonlyArray<T>> | null | undefined | false;
|
|
3
|
+
/** Props when `by` is NOT provided — item is the plain value `T`. */
|
|
4
|
+
export interface ForPropsUnkeyed<T, U = any> {
|
|
5
|
+
/** Reactive array to iterate over — static, readonly, accessor, or signal. */
|
|
6
|
+
each: EachSource<T>;
|
|
7
|
+
/** Rendered when the array is empty or nullish. */
|
|
8
|
+
fallback?: any;
|
|
9
|
+
/**
|
|
10
|
+
* Render function called once per unique item (keyed by object reference).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <For each={rows}>{(row, idx) => <tr>...</tr>}</For>
|
|
14
|
+
*/
|
|
15
|
+
children: (item: T, index: Accessor<number>) => U;
|
|
16
|
+
by?: undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Props when `by` IS provided — item is a reactive `Accessor<T>`. */
|
|
19
|
+
export interface ForPropsKeyed<T, U = any> {
|
|
20
|
+
/** Reactive array to iterate over — static, readonly, accessor, or signal. */
|
|
21
|
+
each: EachSource<T>;
|
|
22
|
+
/** Rendered when the array is empty or nullish. */
|
|
23
|
+
fallback?: any;
|
|
24
|
+
/**
|
|
25
|
+
* Render function called once per unique key.
|
|
26
|
+
* `item` is a reactive accessor — call `item()` inside to read the current value.
|
|
27
|
+
* The same DOM is reused whenever `by(item)` returns the same key, even if the
|
|
28
|
+
* object reference changes.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* <For each={rows} by={r => r.id}>{(row, idx) => <tr>{row().name}</tr>}</For>
|
|
32
|
+
*/
|
|
33
|
+
children: (item: Accessor<T>, index: Accessor<number>) => U;
|
|
34
|
+
/**
|
|
35
|
+
* Key function for stable DOM reuse across reference changes.
|
|
36
|
+
* When provided, `item` in the render function is an `Accessor<T>`.
|
|
37
|
+
*/
|
|
38
|
+
by: (item: T) => any;
|
|
39
|
+
}
|
|
40
|
+
export type ForProps<T, U = any> = ForPropsUnkeyed<T, U> | ForPropsKeyed<T, U>;
|
|
41
|
+
/**
|
|
42
|
+
* Keyed list rendering — mirrors SolidJS `<For>`.
|
|
43
|
+
*
|
|
44
|
+
* Default: keyed by object reference. Same object at new index → only index
|
|
45
|
+
* signal updates (no DOM re-render). Removed items are disposed.
|
|
46
|
+
*
|
|
47
|
+
* With `by`: keyed by the return value of `by(item)`. When the same key is
|
|
48
|
+
* found in the previous render, the DOM entry is reused and the index signal
|
|
49
|
+
* is updated. The item accessor is a live `createMemo(() => list[idx()])` so
|
|
50
|
+
* that reading `item().someField` inside a reactive context creates a
|
|
51
|
+
* fine-grained dependency on the store proxy property — not a frozen snapshot.
|
|
52
|
+
*
|
|
53
|
+
* @example Reference-keyed (default)
|
|
54
|
+
* <For each={items}>{(item, idx) => <li>{item.name}</li>}</For>
|
|
55
|
+
*
|
|
56
|
+
* @example Stable-key (by prop) — survives object recreation
|
|
57
|
+
* <For each={rows} by={r => r.id}>
|
|
58
|
+
* {(row, idx) => <tr><td>{() => row().name}</td></tr>}
|
|
59
|
+
* </For>
|
|
60
|
+
*/
|
|
61
|
+
export declare function For<T, U>(props: ForPropsKeyed<T, U>): Accessor<U[]>;
|
|
62
|
+
export declare function For<T, U>(props: ForPropsUnkeyed<T, U>): Accessor<U[]>;
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=for.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,yBAAyB,CAAC;AAIvE,KAAK,UAAU,CAAC,CAAC,IACb,aAAa,CAAC,CAAC,CAAC,GAChB,CAAC,MAAM,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAA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AAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mapArray, keyArray } from '@fluixi/reactive/signal';
|
|
2
|
+
import { resolveReactiveProp } from './utils.js';
|
|
3
|
+
import { hydrateAdvancePast } from '../dom/hydration-state.js';
|
|
4
|
+
export function For(props) {
|
|
5
|
+
// Read `each` lazily through the prop getter so `each={items()}` re-runs inside
|
|
6
|
+
// mapArray's tracking memo (fine-grained keyed diffing), while `each={items}` still
|
|
7
|
+
// works — resolveReactiveProp unwraps the accessor form once.
|
|
8
|
+
const each = resolveReactiveProp(() => props.each);
|
|
9
|
+
const fallback = () => props.fallback ?? null;
|
|
10
|
+
// Render the children (a fn, or an array of fn/values) for one item, then
|
|
11
|
+
// ascend the hydration cursor past what was placed.
|
|
12
|
+
const render = (item, index) => {
|
|
13
|
+
const children = props.children;
|
|
14
|
+
const rendered = (Array.isArray(children)
|
|
15
|
+
? children.map((c) => (typeof c === 'function' ? c(item, index) : c))
|
|
16
|
+
: typeof children === 'function'
|
|
17
|
+
? children(item, index)
|
|
18
|
+
: children);
|
|
19
|
+
hydrateAdvancePast(rendered);
|
|
20
|
+
return rendered;
|
|
21
|
+
};
|
|
22
|
+
// `by` → key-function reconciliation (item is a live accessor); default →
|
|
23
|
+
// reference reconciliation (item is the plain value). Both keep each item in
|
|
24
|
+
// its own root so list items stay owner-stable.
|
|
25
|
+
return props.by
|
|
26
|
+
? keyArray(each, props.by, (item, index) => render(item, index), { fallback })
|
|
27
|
+
: mapArray(each, (item, index) => render(item, index), { fallback });
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{mapArray as d,keyArray as f}from"@fluixi/reactive/signal";function u(r){return()=>{let e=r();return typeof e=="function"?e():e}}var a={active:!1,cursor:null,parents:[]};function p(r){let e=a.parents.lastIndexOf(r);e!==-1&&(a.parents.length=e),a.cursor=r.nextSibling}function y(r){if(!a.active||r==null)return;let e=Array.isArray(r)?r[r.length-1]:r;e&&typeof e.nodeType=="number"&&p(e)}function m(r){let e=u(()=>r.each),c=()=>r.fallback??null,i=(n,t)=>{let o=r.children,l=Array.isArray(o)?o.map(s=>typeof s=="function"?s(n,t):s):typeof o=="function"?o(n,t):o;return y(l),l};return r.by?f(e,r.by,(n,t)=>i(n,t),{fallback:c}):d(e,(n,t)=>i(n,t),{fallback:c})}export{m as For};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var n in e)s(r,n,{get:e[n],enumerable:!0})},y=(r,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of f(e))!p.call(r,t)&&t!==n&&s(r,t,{get:()=>e[t],enumerable:!(o=u(e,t))||o.enumerable});return r};var T=r=>y(s({},"__esModule",{value:!0}),r);var A={};d(A,{Index:()=>v});module.exports=T(A);var l=require("@fluixi/reactive/signal");function i(r){return()=>{let e=r();return typeof e=="function"?e():e}}var a={active:!1,cursor:null,parents:[]};function x(r){let e=a.parents.lastIndexOf(r);e!==-1&&(a.parents.length=e),a.cursor=r.nextSibling}function c(r){if(!a.active||r==null)return;let e=Array.isArray(r)?r[r.length-1]:r;e&&typeof e.nodeType=="number"&&x(e)}function v(r){let e=i(()=>r.each);return(0,l.indexArray)(e,(n,o)=>{let t=r.children(n,o);return c(t),t},{fallback:()=>r.fallback??null})}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Accessor } from '@fluixi/reactive/signal';
|
|
2
|
+
export interface IndexProps<T, U = any> {
|
|
3
|
+
/** Reactive array to iterate over. */
|
|
4
|
+
each: T[] | Accessor<T[]> | null | undefined;
|
|
5
|
+
/** Rendered when the array is empty or nullish. */
|
|
6
|
+
fallback?: any;
|
|
7
|
+
/**
|
|
8
|
+
* Render function called once per stable index slot.
|
|
9
|
+
* `item` is a reactive accessor — updates when the item at that index changes.
|
|
10
|
+
* `index` is a plain number (stable).
|
|
11
|
+
*
|
|
12
|
+
* JSX: <Index each={items()}>{(item, index) => <li>{item().name}</li>}</Index>
|
|
13
|
+
* lit: Index({ each: items, children: (item, index) => html`<li>${item().name}</li>` })
|
|
14
|
+
*/
|
|
15
|
+
children: (item: Accessor<T>, index: number) => U;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Non-keyed list rendering — mirrors SolidJS `<Index>`.
|
|
19
|
+
*
|
|
20
|
+
* Keyed by position. When the list grows, new slots are created.
|
|
21
|
+
* When it shrinks, trailing slots are disposed. When an item at a
|
|
22
|
+
* given index changes value, only the `item` signal updates (no re-render).
|
|
23
|
+
* Returns a memo of the rendered array — works in both JSX and lit-html.
|
|
24
|
+
*
|
|
25
|
+
* @example JSX
|
|
26
|
+
* <Index each={items()} fallback={<p>Empty</p>}>
|
|
27
|
+
* {(item, index) => <li>{index} — {item().name}</li>}
|
|
28
|
+
* </Index>
|
|
29
|
+
*
|
|
30
|
+
* @example lit-html
|
|
31
|
+
* Index({ each: items, children: (item, i) => html`<li>${i} — ${item().name}</li>` })
|
|
32
|
+
*/
|
|
33
|
+
export declare function Index<T, U = any>(props: IndexProps<T, U>): Accessor<U[] | any>;
|
|
34
|
+
//# sourceMappingURL=index-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-flow.d.ts","sourceRoot":"","sources":["../../../src/lib/flow/index-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAI/D,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG;IACpC,sCAAsC;IACtC,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7C,mDAAmD;IACnD,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf;;;;;;;OAOG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC;CACnD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAW9E"}
|