@firsthandjs/dom 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ function z(n,o,e){return n}var N={current:null};function K(n){let o=n.firstChild,e=N.current;return e===null?o:e.step(o)}function Q(n){let o=n.nextSibling,e=N.current;return e===null?o:e.step(o)}function m(n,o,e,t){let i=0,l=0,r=e.length-1,d=t.length-1;for(;i<=r&&l<=d&&e[i]===t[l];)i++,l++;for(;i<=r&&l<=d&&e[r]===t[d];)r--,d--;let u=d+1<t.length?t[d+1]:o;if(i>r){for(let s=l;s<=d;s++)n.insertBefore(t[s],u);return}if(l>d){for(let s=i;s<=r;s++)n.removeChild(e[s]);return}R(n,t,u,{a:e,aStart:i,aEnd:r,bStart:l,bEnd:d})}function R(n,o,e,t){let i=t.bEnd-t.bStart+1,l=k(n,o,t),r=P(l),d=r.length-1,u=e;for(let s=i-1;s>=0;s--){let a=o[t.bStart+s];d>=0&&r[d]===s?d--:n.insertBefore(a,u),u=a}}function k(n,o,e){let{a:t,aStart:i,aEnd:l,bStart:r,bEnd:d}=e,u=new Map;for(let f=i;f<=l;f++)u.set(t[f],f);let s=d-r+1,a=new Int32Array(s).fill(-1);for(let f=0;f<s;f++){let c=o[r+f],w=u.get(c);w!==void 0&&(a[f]=w,u.delete(c))}for(let f of u.keys())n.removeChild(f);return a}function P(n){let o=n.length,e=new Int32Array(o).fill(-1),t=[];for(let r=0;r<o;r++){let d=n[r];if(d===-1)continue;let u=0,s=t.length;for(;u<s;){let a=u+s>>1;n[t[a]]<d?u=a+1:s=a}u>0&&(e[r]=t[u-1]),t[u]=r}let i=[],l=t.length>0?t[t.length-1]:-1;for(;l!==-1;)i.push(l),l=e[l];return i.reverse()}import{bind as A,getOwner as _,onCleanup as j,runWithOwner as F}from"@firsthandjs/core";function g(n){return typeof n.nodeType=="number"}function S(n){let o=n.parentNode;o!==null&&o.removeChild(n)}function h(n,o,e){return o===null&&Array.isArray(e)&&e.length>1&&n.childNodes.length===e.length?(n.textContent="",null):p(e)}function p(n){if(n!==null)if(Array.isArray(n))for(let o=0;o<n.length;o++)S(n[o]);else S(n);return null}function x(n,o,e,t){return e===t?t:e!==null&&!Array.isArray(e)?(n.replaceChild(t,e),t):(p(e),n.insertBefore(t,o),t)}var C=0;function rn(n){C++;try{n()}finally{C--}}var E=Symbol("firsthand.part"),M=Symbol("firsthand.flat"),q=Symbol("firsthand.pending"),b=new WeakSet;function dn(n){return{[E]:!0,anchor:document.createTextNode(""),thunk:n,owner:_()}}function O(n){return E in n}function D(n,o,e=null,t){if(typeof o!="function"){y(n,e,null,o);return}let i=G(n,e,t?.seed),l=i===null?null:i.nodes,r=i?.text,d=i!==null,u=()=>{let a=o(),f=typeof a;if(f==="string"||f==="number"){let c=String(a);c!==r&&(r=c,l=y(n,e,l,c));return}if(r=void 0,f==="function"){l=d?null:p(l),D(n,a,e,{seed:d?i:null});return}l=y(n,e,l,a)},s=t?.report;H(i,s===void 0?u:()=>{u(),s(B(l,e))}),d=!1,j(()=>{l=C>0?null:p(l)})}function B(n,o){let e=n===null?[]:Array.isArray(n)?[...n]:[n];return e.push(o),e}function G(n,o,e){return e!==void 0?e:N.current===null?null:N.current.claim(n,o)}function H(n,o){if(n===null){A(o);return}N.current.within(n.region,()=>{A(o)})}function y(n,o,e,t){let i=typeof t;if(t==null||i==="boolean")return h(n,o,e);if(i==="string"||i==="number"){let l=String(t);return e!==null&&!Array.isArray(e)&&e.nodeType===3?(e.data=l,e):x(n,o,e,document.createTextNode(l))}return L(n,o,e,t)}function L(n,o,e,t){return typeof t=="function"?y(n,o,e,t()):Array.isArray(t)?T(n,o,e,t):O(t)?T(n,o,e,[t]):g(t)?x(n,o,e,t):y(n,o,e,String(t))}function v(n){return n===null?[]:Array.isArray(n)?n:[n]}function T(n,o,e,t){if(M in t){let r=t;return r.length===0?h(n,o,e):(m(n,o,v(e),r),t[q]?.(n),r)}let i=[],l=[];if(I(t,i,l),i.length===0)return h(n,o,e);m(n,o,v(e),i);for(let r=0;r<l.length;r++)X(l[r],n);return i}function X(n,o,e){b.has(n)||(b.add(n),F(n.owner??_(),()=>{D(o,n.thunk,n.anchor,e===void 0?void 0:{report:e}),j(()=>{b.delete(n)})}))}function I(n,o,e){for(let t=0;t<n.length;t++){let i=n[t];if(typeof i=="object"&&i!==null&&O(i)){o.push(i.anchor),e.push(i);continue}for(;typeof i=="function";)i=i();i==null||typeof i=="boolean"||(Array.isArray(i)?I(i,o,e):typeof i=="object"&&g(i)?o.push(i):o.push(document.createTextNode(String(i))))}}export{z as a,N as b,K as c,Q as d,m as e,rn as f,M as g,q as h,dn as i,O as j,D as k,y as l,X as m};
@@ -0,0 +1 @@
1
+ import{b as E,f as P,g as x,h as T,i as f,j as v,l as O,m as $}from"./chunk-467WEPXM.js";var g=null,y=new WeakMap;function vn(n){g=n,y=new WeakMap}var h=class extends Error{constructor(e){super(`${e} is not a Firsthand component. If it is a React component, import '@firsthandjs/react/auto' once at startup to render React components directly, or wrap it with fromReact(). Otherwise, declare it with component().`),this.name="FirsthandComponentError"}};function A(n){let e=y.get(n);if(e!==void 0)return e;if(g===null){let o=typeof n=="function"&&n.name!==""?n.name:"The value";throw new h(o)}let t=g(n);return y.set(n,t),t}import{signal as tn,createOwner as N,devEnterSetup as S,devExitSetup as p,disposeOwner as on,getOwner as j,handleError as L,setOwner as a,untrack as H}from"@firsthandjs/core";var M=Symbol.for("firsthand.component"),D=Symbol.for("firsthand.view"),rn=0,V="firsthand";function Hn(n){V=n}function Mn(n,e,t,o){let s=Object.assign(i=>sn(s,i),{[M]:!0,setup:n,options:e,id:t??`c${String(++rn)}`,tag:void 0});return Object.defineProperty(s,"name",{configurable:!0,value:o??(n.name===""?"Component":n.name)}),t===void 0&&(`${s.name}`,void 0),(e?.tag!==void 0||e?.shadow===!0)&&un(s,typeof e.tag=="string"?e.tag:void 0),s}function Dn(n){return typeof n=="function"&&M in n}function Vn(n){return n[D]=!0,n}function sn(n,e){if(Object.freeze(e),n.setup===void 0)return D in n?f(()=>n(e)):A(n)(e);if(n.tag!==void 0)return an(n,e);let t=N(j());n.name;let o=a(t);try{S(n.id);let r=H(()=>n.setup(e));return p(),a(o),r}catch(r){return p(),a(o),L(r,t),null}}function dn(n){let e=n.name.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9-]/g,"-").toLowerCase();return`${V}-${e}`}function un(n,e){let t=n;if(t.tag!==void 0)return t.tag;let o=e??dn(t);return customElements.get(o)!==void 0&&(o=`${o}-${t.id.replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}`),t.tag=o,customElements.define(o,cn(t)),o}function cn(n){let e=n.options?.shadow===!0,t=n.options?.attributes,o=t!==void 0?Object.keys(t):[];return class extends HTMLElement{static observedAttributes=o;constructor(){super(),this.$owner=null,this.$props=null,this.$attrs=null,this.$standalone=!1}connectedCallback(){this.$owner===null&&(this.$standalone=!0,this.$attrs={},this.$props=ln(this,t,this.$attrs),F(this,n,e))}disconnectedCallback(){!this.$standalone||this.$owner===null||(on(this.$owner),this.$owner=null)}attributeChangedCallback(s,i,d){let u=this.$attrs?.[s];u!==void 0&&(u.value=t[s]?.(d))}}}function ln(n,e,t){let o={};if(e!==void 0)for(let r in e){let s=tn(e[r](n.getAttribute(r)));t[r]=s,Object.defineProperty(o,r,{enumerable:!0,get:()=>s.value})}return Object.freeze(o)}function F(n,e,t){let o=N(j());e.name,n.$owner=o;let r=a(o);try{S(e.id);let s=t?n.attachShadow({mode:"open"}):n,i=H(()=>e.setup(n.$props));p(),O(s,null,null,i)}catch(s){p(),L(s,o)}finally{a(r)}}function an(n,e){let t=document.createElement(n.tag);return t.$props=e,F(t,n,n.options?.shadow===!0),t}import{batch as fn,createOwner as z,disposeOwner as pn,getOwner as mn,setOwner as W,signal as I,untrack as K}from"@firsthandjs/core";function Bn(n,e,t){let o=z(mn()),r=new Map,s,i=!1;return()=>{i&&s!==void 0&&wn(s,r);let d=[];d[x]=!0;let u={items:n(),rows:r,next:new Map,nodes:d,host:o,keyOf:e,render:t,pending:void 0,views:i};K(()=>{fn(()=>{gn(u)})}),i=u.views,r=u.next,s=d;let c=u.pending;return c!==void 0&&(d[T]=l=>{for(let en of c)q(en,l)}),d}}function wn(n,e){n.length=0;for(let t of e.values())for(let o of t.pieces===void 0?t.nodes:B(t))n.push(o)}function gn(n){let{items:e,rows:t,next:o,nodes:r}=n;for(let s=0;s<e.length;s++){let i=e[s],d=n.keyOf(i,s);if(o.has(d)){`${String(d)}`;continue}let u=t.get(d)??yn(n,i,s);t.delete(d)&&(u.item.value=i,u.index.value=s),o.set(d,u);let c=u.pieces===void 0?u.nodes:B(u);for(let l=0;l<c.length;l++)r.push(c[l])}P(()=>{for(let s of t.values())pn(s.owner)})}function yn(n,e,t){let o=hn(n.host,e,t,n.render);return o.pieces!==void 0&&(n.views=!0,q(o,null)||(n.pending=n.pending===void 0?[o]:[...n.pending,o])),o}function Z(n){return typeof n.nodeType=="number"}function q(n,e){let t=n.pieces;for(let o of t){if(Z(o))continue;let r=e??E.current?.place(o.child.anchor)??null;if(r===null)return!1;$(o.child,r,s=>{o.nodes=s})}return!0}function B(n){let e=[];for(let t of n.pieces)if(Z(t))e.push(t);else for(let o of t.nodes)e.push(o);return e}function hn(n,e,t,o){let r=z(n),s=I(e),i=I(t),d=W(r),u=[],c;try{c=G(K(()=>o(s,i)),u)}finally{W(d)}return c?{owner:r,item:s,index:i,nodes:[],pieces:u}:{owner:r,item:s,index:i,nodes:u}}function G(n,e){if(n==null||typeof n=="boolean")return!1;if(Array.isArray(n)){let t=!1;for(let o=0;o<n.length;o++)t=G(n[o],e)||t;return t}if(typeof n=="function"){let t=f(n);return e.push({child:t,nodes:[t.anchor]}),!0}if(typeof n=="object"){if(v(n))return e.push({child:n,nodes:[n.anchor]}),!0;if(typeof n.nodeType=="number")return e.push(n),!1}return e.push(document.createTextNode(String(n))),!1}var bn=new Set(["click","dblclick","contextmenu","input","beforeinput","change","keydown","keyup","keypress","pointerdown","pointerup","pointermove","mousedown","mouseup","mouseover","mouseout","submit","focusin","focusout","touchstart","touchend"]),_=new Set;function m(n){return`$firsthand$${n}`}function kn(n){let e=m(n.type),t=n.composedPath(),o=null;Object.defineProperty(n,"currentTarget",{configurable:!0,get:()=>o});for(let r=0;r<t.length;r++){let s=t[r],i=s[e];if(i!==void 0&&(o=s,i.call(s,n),n.cancelBubble)||s===document)break}o=null}function w(n,e,t,o){if(o!==void 0||!bn.has(e)){let r=n,s=o===!0?void 0:o,i=`${m(e)}$${s===void 0?"":Object.keys(s).sort().join(",")}`,d=r[i];d!==void 0&&n.removeEventListener(e,d.handler,d.options),r[i]={handler:t,options:s},n.addEventListener(e,t,s);return}n[m(e)]=t,_.has(e)||(_.add(e),document.addEventListener(e,kn))}function _n(n,e){n[m(e)]=void 0}var Rn={class:"className",for:"htmlFor"};function k(n,e,t){t==null||t===!1?n.removeAttribute(e):n.setAttribute(e,t===!0?"":String(t))}function Un(n,e,t,o){o==null||o===!1?n.removeAttributeNS(e,t):n.setAttributeNS(e,t,o===!0?"":String(o))}function R(n,e,t){n[Rn[e]??e]=t}function Xn(n,e,t){n[e]=!!t}function C(n,e){e==null?n.removeAttribute("class"):n.className=String(e)}function J(n,e,t){let o=n.classList;if(t!==void 0)for(let r in t)r in e||o.remove(r);for(let r in e){let s=!!e[r];(t===void 0||!!t[r]!==s)&&o.toggle(r,s)}}function Q(n,e){e==null?n.style.cssText="":n.style.cssText=String(e)}function U(n,e,t){let o=n.style;if(t!==void 0)for(let r in t)r in e||o.removeProperty(b(r));for(let r in e){let s=e[r];(t===void 0||t[r]!==s)&&(s==null?o.removeProperty(b(r)):o.setProperty(b(r),String(s)))}}var Cn=/[A-Z]/g,Y=new Map;function b(n){let e=Y.get(n);return e===void 0&&(e=n.startsWith("--")?n:n.replace(Cn,t=>`-${t.toLowerCase()}`),Y.set(n,e)),e}function En(n,e,t){if(e==="class"||e==="className"){Pn(n,t);return}if(e==="style"){xn(n,t);return}if(e==="ref"){t(n);return}if(e.startsWith("prop:")){R(n,e.slice(5),t);return}if(e.startsWith("attr:")){k(n,e.slice(5),t);return}if(e.startsWith("on")&&e.length>2&&/[A-Z:]/.test(e[2])){Tn(n,e,t);return}if(e in n&&typeof t!="string"){R(n,e,t);return}k(n,e,t)}function Pn(n,e){if(Array.isArray(e)){C(n,e.filter(Boolean).join(" "));return}if(e!==null&&typeof e=="object"){J(n,e,nn(n,"class",e));return}C(n,e)}function xn(n,e){let t=n;if(e!==null&&typeof e=="object"){U(t,e,nn(n,"style",e));return}Q(t,e)}function Tn(n,e,t){let o=e.slice(2).split(":"),r=o[0]==="",s=r?o[1]:o[0].toLowerCase(),i=o[r?2:1];i===void 0?w(n,s,t):i==="native"?w(n,s,t,!0):w(n,s,t,{[i]:!0})}function oe(n,e){for(let t in e)t!=="children"&&En(n,t,e[t])}function re(...n){let e={};for(let t=0;t<n.length;t++){let o=n[t];for(let r of Object.keys(o))Object.defineProperty(e,r,{enumerable:!0,configurable:!0,get:()=>o[r]})}return e}function se(n,e){let t={};for(let o of Object.keys(n))e.includes(o)||Object.defineProperty(t,o,{enumerable:!0,get:()=>n[o]});return Object.freeze(t)}var X=new WeakMap;function nn(n,e,t){let o=X.get(n);o===void 0&&(o={},X.set(n,o));let r=o[e];return o[e]=t,r}export{vn as a,h as b,M as c,D as d,Hn as e,Mn as f,Dn as g,Vn as h,sn as i,un as j,Bn as k,w as l,_n as m,k as n,Un as o,R as p,Xn as q,C as r,J as s,Q as t,U as u,En as v,oe as w,re as x,se as y};
@@ -1 +1 @@
1
- import{p as d,q as i}from"./chunk-NNHZJMZS.js";import{createRoot as r,onCleanup as s,untrack as u}from"@firsthandjs/core";function y(o,e=document.body){return f(o,e,null)}function f(o,e,l){let t;return r(n=>{t=n;let p=()=>{c(e,u(o),l!==null)};l===null?p():l(p)}),t}function c(o,e,l){if(typeof e=="function"){d(o,e);return}let t=null;if(l){let n=[...o.childNodes];t=n.length===1?n[0]:n}t=i(o,null,t,e),s(()=>{i(o,null,t,null)})}export{y as a,f as b};
1
+ import{k as d,l as i}from"./chunk-467WEPXM.js";import{createRoot as r,onCleanup as s,untrack as u}from"@firsthandjs/core";function y(o,e=document.body){return f(o,e,null)}function f(o,e,l){let t;return r(n=>{t=n;let p=()=>{c(e,u(o),l!==null)};l===null?p():l(p)}),t}function c(o,e,l){if(typeof e=="function"){d(o,e);return}let t=null;if(l){let n=[...o.childNodes];t=n.length===1?n[0]:n}t=i(o,null,t,e),s(()=>{i(o,null,t,null)})}export{y as a,f as b};
package/dist/claim.d.ts CHANGED
@@ -53,6 +53,16 @@ export type Claimer = {
53
53
  within<T>(region: Region, body: () => T): T;
54
54
  /** A step through the template that goes over a whole region at a time. */
55
55
  step(node: Node): Node;
56
+ /**
57
+ * Puts `anchor` where hydration has got to, and says what it went into.
58
+ *
59
+ * What a keyed list needs to adopt a row that is a view: the row has
60
+ * nothing of its own until it runs, and it has to run where its markup is,
61
+ * in the order the rows come in — not after the list has decided what goes
62
+ * where. Null when the region is used up, which is a list with more rows
63
+ * than the server sent: those are built.
64
+ */
65
+ place(anchor: Node): Node | null;
56
66
  };
57
67
  /**
58
68
  * The installed claimer, or nothing.
@@ -1 +1 @@
1
- {"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../src/claim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,yDAAyD;AACzD,MAAM,MAAM,OAAO,GAAG;IACpB,mDAAmD;IACnD,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC5B,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,MAAM,GAAG;IACnB,mEAAmE;IACnE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,wCAAwC;IACxC,GAAG,EAAE,IAA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AAG,IAAI,CAAA;CAAsB,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAItC;AAED,2EAA2E;AAC3E,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAIrC"}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  applyChild,
3
3
  insert
4
- } from "./dev-chunk-HTXIHAW7.js";
4
+ } from "./dev-chunk-U46CIJCO.js";
5
5
 
6
6
  // packages/dom/src/render.ts
7
7
  import { createRoot, onCleanup, untrack } from "@firsthandjs/core";
@@ -1,13 +1,17 @@
1
1
  import {
2
2
  FLAT,
3
+ PENDING,
3
4
  applyChild,
5
+ bindPart,
4
6
  devComponent,
5
7
  devPart,
6
8
  devWarn,
7
9
  devWarnOnce,
8
10
  discard,
11
+ hydration,
12
+ isDynamicChild,
9
13
  part
10
- } from "./dev-chunk-HTXIHAW7.js";
14
+ } from "./dev-chunk-U46CIJCO.js";
11
15
 
12
16
  // packages/dom/src/adapter.ts
13
17
  var adapter = null;
@@ -226,81 +230,165 @@ import {
226
230
  function list(each, keyOf, render) {
227
231
  const host = createOwner2(getOwner2());
228
232
  let rows = /* @__PURE__ */ new Map();
233
+ let placed;
234
+ let views = false;
229
235
  return () => {
230
- const items = each();
231
- const next = /* @__PURE__ */ new Map();
236
+ if (views && placed !== void 0) {
237
+ rewritePlaced(placed, rows);
238
+ }
232
239
  const nodes = [];
233
240
  nodes[FLAT] = true;
241
+ const pass = {
242
+ items: each(),
243
+ rows,
244
+ next: /* @__PURE__ */ new Map(),
245
+ nodes,
246
+ host,
247
+ keyOf,
248
+ render,
249
+ pending: void 0,
250
+ views
251
+ };
234
252
  untrack2(() => {
235
253
  batch(() => {
236
- buildRows();
254
+ buildRows(pass);
237
255
  });
238
256
  });
239
- rows = next;
240
- return nodes;
241
- function buildRows() {
242
- for (let i = 0; i < items.length; i++) {
243
- const item = items[i];
244
- const key2 = keyOf(item, i);
245
- if (next.has(key2)) {
246
- devWarn(
247
- `Duplicate list key ${String(key2)}. Keys must be unique, or rows will be dropped.`
248
- );
249
- continue;
250
- }
251
- let row = rows.get(key2);
252
- if (row === void 0) {
253
- row = createRow(host, item, i, render);
254
- } else {
255
- rows.delete(key2);
256
- row.item.value = item;
257
- row.index.value = i;
258
- }
259
- next.set(key2, row);
260
- for (let n = 0; n < row.nodes.length; n++) {
261
- nodes.push(row.nodes[n]);
257
+ views = pass.views;
258
+ rows = pass.next;
259
+ placed = nodes;
260
+ const made = pass.pending;
261
+ if (made !== void 0) {
262
+ nodes[PENDING] = (parent) => {
263
+ for (const row of made) {
264
+ bindRow(row, parent);
262
265
  }
263
- }
264
- discard(() => {
265
- for (const row of rows.values()) {
266
- disposeOwner2(row.owner);
267
- }
268
- });
266
+ };
269
267
  }
268
+ return nodes;
270
269
  };
271
270
  }
271
+ function rewritePlaced(placed, rows) {
272
+ placed.length = 0;
273
+ for (const row of rows.values()) {
274
+ for (const node of row.pieces === void 0 ? row.nodes : nodesOf(row)) {
275
+ placed.push(node);
276
+ }
277
+ }
278
+ }
279
+ function buildRows(pass) {
280
+ const { items, rows, next, nodes } = pass;
281
+ for (let i = 0; i < items.length; i++) {
282
+ const item = items[i];
283
+ const key2 = pass.keyOf(item, i);
284
+ if (next.has(key2)) {
285
+ devWarn(`Duplicate list key ${String(key2)}. Keys must be unique, or rows will be dropped.`);
286
+ continue;
287
+ }
288
+ const row = rows.get(key2) ?? newRow(pass, item, i);
289
+ if (rows.delete(key2)) {
290
+ row.item.value = item;
291
+ row.index.value = i;
292
+ }
293
+ next.set(key2, row);
294
+ const found = row.pieces === void 0 ? row.nodes : nodesOf(row);
295
+ for (let n = 0; n < found.length; n++) {
296
+ nodes.push(found[n]);
297
+ }
298
+ }
299
+ discard(() => {
300
+ for (const row of rows.values()) {
301
+ disposeOwner2(row.owner);
302
+ }
303
+ });
304
+ }
305
+ function newRow(pass, item, index) {
306
+ const row = createRow(pass.host, item, index, pass.render);
307
+ if (row.pieces !== void 0) {
308
+ pass.views = true;
309
+ if (!bindRow(row, null)) {
310
+ pass.pending = pass.pending === void 0 ? [row] : [...pass.pending, row];
311
+ }
312
+ }
313
+ return row;
314
+ }
315
+ function isNode(piece) {
316
+ return typeof piece.nodeType === "number";
317
+ }
318
+ function bindRow(row, into) {
319
+ const pieces = row.pieces;
320
+ for (const piece of pieces) {
321
+ if (isNode(piece)) {
322
+ continue;
323
+ }
324
+ const parent = into ?? hydration.current?.place(piece.child.anchor) ?? null;
325
+ if (parent === null) {
326
+ return false;
327
+ }
328
+ bindPart(piece.child, parent, (found) => {
329
+ piece.nodes = found;
330
+ });
331
+ }
332
+ return true;
333
+ }
334
+ function nodesOf(row) {
335
+ const nodes = [];
336
+ for (const piece of row.pieces) {
337
+ if (isNode(piece)) {
338
+ nodes.push(piece);
339
+ } else {
340
+ for (const node of piece.nodes) {
341
+ nodes.push(node);
342
+ }
343
+ }
344
+ }
345
+ return nodes;
346
+ }
272
347
  function createRow(host, item, index, render) {
273
348
  const owner = createOwner2(host);
274
349
  const itemCell = signal2(item);
275
350
  const indexCell = signal2(index);
276
351
  const previous = setOwner2(owner);
277
- let result;
352
+ const pieces = [];
353
+ let parts;
278
354
  try {
279
- result = untrack2(() => render(itemCell, indexCell));
280
- setOwner2(previous);
281
- } catch (error) {
355
+ parts = collect(
356
+ untrack2(() => render(itemCell, indexCell)),
357
+ pieces
358
+ );
359
+ } finally {
282
360
  setOwner2(previous);
283
- throw error;
284
361
  }
285
- const nodes = [];
286
- collect(result, nodes);
287
- return { owner, item: itemCell, index: indexCell, nodes };
362
+ return parts ? { owner, item: itemCell, index: indexCell, nodes: [], pieces } : { owner, item: itemCell, index: indexCell, nodes: pieces };
288
363
  }
289
364
  function collect(value, out) {
290
365
  if (value == null || typeof value === "boolean") {
291
- return;
366
+ return false;
292
367
  }
293
368
  if (Array.isArray(value)) {
369
+ let parts = false;
294
370
  for (let i = 0; i < value.length; i++) {
295
- collect(value[i], out);
371
+ parts = collect(value[i], out) || parts;
296
372
  }
297
- return;
373
+ return parts;
298
374
  }
299
- if (typeof value === "object" && typeof value.nodeType === "number") {
300
- out.push(value);
301
- return;
375
+ if (typeof value === "function") {
376
+ const child = part(value);
377
+ out.push({ child, nodes: [child.anchor] });
378
+ return true;
379
+ }
380
+ if (typeof value === "object") {
381
+ if (isDynamicChild(value)) {
382
+ out.push({ child: value, nodes: [value.anchor] });
383
+ return true;
384
+ }
385
+ if (typeof value.nodeType === "number") {
386
+ out.push(value);
387
+ return false;
388
+ }
302
389
  }
303
390
  out.push(document.createTextNode(String(value)));
391
+ return false;
304
392
  }
305
393
 
306
394
  // packages/dom/src/events.ts
@@ -472,25 +560,11 @@ function hyphenate(name) {
472
560
  // packages/dom/src/props.ts
473
561
  function applyProp(node, name, value) {
474
562
  if (name === "class" || name === "className") {
475
- if (Array.isArray(value)) {
476
- setClass(node, value.filter(Boolean).join(" "));
477
- } else if (value !== null && typeof value === "object") {
478
- setClassList(node, value, remember(node, "class", value));
479
- } else {
480
- setClass(node, value);
481
- }
563
+ applyClass(node, value);
482
564
  return;
483
565
  }
484
566
  if (name === "style") {
485
- if (value !== null && typeof value === "object") {
486
- setStyleObject(
487
- node,
488
- value,
489
- remember(node, "style", value)
490
- );
491
- } else {
492
- setStyle(node, value);
493
- }
567
+ applyStyle(node, value);
494
568
  return;
495
569
  }
496
570
  if (name === "ref") {
@@ -515,6 +589,29 @@ function applyProp(node, name, value) {
515
589
  }
516
590
  setAttribute(node, name, value);
517
591
  }
592
+ function applyClass(node, value) {
593
+ if (Array.isArray(value)) {
594
+ setClass(node, value.filter(Boolean).join(" "));
595
+ return;
596
+ }
597
+ if (value !== null && typeof value === "object") {
598
+ setClassList(node, value, remember(node, "class", value));
599
+ return;
600
+ }
601
+ setClass(node, value);
602
+ }
603
+ function applyStyle(node, value) {
604
+ const style = node;
605
+ if (value !== null && typeof value === "object") {
606
+ setStyleObject(
607
+ style,
608
+ value,
609
+ remember(node, "style", value)
610
+ );
611
+ return;
612
+ }
613
+ setStyle(style, value);
614
+ }
518
615
  function applyEvent(node, name, value) {
519
616
  const parts = name.slice(2).split(":");
520
617
  const literal = parts[0] === "";