@stacksjs/stx 0.2.452 → 0.2.454

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/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import"./chunk-5xj1df83.js";import"./chunk-73h7qjgq.js";import"./chunk-s59r34p5.js";import"./chunk-afhkvj3k.js";import"./chunk-axydabse.js";import{U}from"./chunk-nrp8qg9j.js";import"./chunk-zqzv5jy2.js";import"./chunk-g8k5rsqq.js";import"./chunk-jwpcck1b.js";import"./chunk-aem9hs8n.js";import"./chunk-dqr5n49p.js";import"./chunk-yx37nrgr.js";import"./chunk-pkpmyr0x.js";import"./chunk-fmj4xvqm.js";import"./chunk-g3h7j2n7.js";import"./chunk-7mbx7dzg.js";import"./chunk-x4ztj64h.js";import"./chunk-tehvry9a.js";import"./chunk-9zbjk8pg.js";import"./chunk-0vbpcef6.js";import"./chunk-d1xbamr1.js";import"./chunk-2428rqy1.js";import"./chunk-g2afpsw0.js";import"./chunk-n9jn3qzw.js";import"./chunk-1kmd0g1k.js";import"./chunk-8fj8sm1a.js";import"./chunk-z68rb7qp.js";import"./chunk-nw8p8eg9.js";import"./chunk-qbhbe9cw.js";import"./chunk-hd75916k.js";import"./chunk-3nydw825.js";import"./chunk-mnz6bdp3.js";import"./chunk-dwp3knc4.js";import"./chunk-hqywyyez.js";import{ft,gt}from"./chunk-6sw7sxh2.js";import"./chunk-bemksdz5.js";import"./chunk-697zcjzg.js";import"./chunk-0tchj3ct.js";import"./chunk-s5drjm2j.js";import"./chunk-19h1j59a.js";import"./chunk-b1q5sh7x.js";import"./chunk-yfd0e7dr.js";import"./chunk-ph6xg67j.js";import"./chunk-47jq9j1w.js";import{zs,Hs,Vs,Us,pr,Ws,qs,Ks,fr,gr,yn,bn,wn}from"./chunk-b5wh10s9.js";import"./chunk-vraddzkf.js";import"./chunk-849wf19d.js";import{di}from"./chunk-0xztxj98.js";import{u}from"./chunk-cg8hg6cs.js";import{spawn as R}from"child_process";import S from"fs";import M from"os";import f from"path";import n from"process";import{CLI as V}from"@stacksjs/clapp";var j="0.2.452";var __dirname="/home/runner/work/stx/stx/packages/stx/bin",y=new V("stx");function B(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(p<1024||p>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function A(h){try{if(!S.existsSync(h)){let x=f.dirname(h),t=f.basename(h);if(S.existsSync(x)){let o=S.readdirSync(x).filter((s)=>s.toLowerCase().includes(t.toLowerCase().substring(0,3))||s.endsWith(".stx")||s.endsWith(".md")),i=o.length>0?`File not found. Similar files in ${x}: ${o.slice(0,3).join(", ")}`:`File not found. Directory ${x} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${h}`,suggestion:i}}return{isValid:!1,error:`File does not exist: ${h}`,suggestion:"Check the file path and try again"}}if(S.statSync(h).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${h}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(p){return{isValid:!1,error:`Cannot access file: ${h}`,suggestion:"Check file permissions and path"}}}function z(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(p<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(p>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var O=(h)=>h.includes("*")||h.includes("?")||h.includes("{")||h.includes("["),H=(h)=>h.endsWith(".stx")||h.endsWith(".md");function F(h,p=1){if(console.error(`\u274C ${h.error}`),h.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${h.suggestion}`);n.exit(p)}function L(h){if(!h)return;let p;try{p=JSON.parse(h)}catch(x){console.error(`\u274C --info-plist is not valid JSON: ${x.message}`),n.exit(1)}if(typeof p!=="object"||p===null||Array.isArray(p))console.error(`\u274C --info-plist must be a JSON object, e.g. '{"NSFocusStatusUsageDescription":"\u2026"}'`),n.exit(1);for(let[x,t]of Object.entries(p))if(typeof t!=="string"&&typeof t!=="number"&&typeof t!=="boolean")console.error(`\u274C --info-plist value for "${x}" must be a string, number or boolean`),n.exit(1);return p}async function G(h,p){try{let x=["test"],t=[];if(h&&h.length>0)for(let c of h)if(O(c))try{let r=await Array.fromAsync(new Bun.Glob(c).scan({onlyFiles:!0,absolute:!0}));if(r.length===0)console.warn(`Warning: No files found matching pattern: ${c}`);else if(t.push(...r),p.verbose)console.log(`Found ${r.length} file(s) matching pattern: ${c}`)}catch(r){return console.error(`Error expanding glob pattern ${c}:`,r),!1}else t.push(c);if(t.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(x.push(...t),p.filter)x.push("--pattern",p.filter);if(p.timeout)x.push("--timeout",p.timeout.toString());if(p.reporter&&p.reporter!=="default")if(p.reporter==="junit"){let c=f.join(M.tmpdir(),`stx-test-report-${Date.now()}.xml`);x.push("--reporter",p.reporter),x.push("--reporter-outfile",c)}else console.warn(`Warning: Reporter '${p.reporter}' is not supported. Using default reporter.`);if(p.coverage)x.push("--coverage");if(p.watch)x.push("--watch");x.push("--preload",f.join(__dirname,"../../../test-utils/happy-dom.ts"));let e={...n.env,STX_TEST_MODE:"true",STX_TEST_UI:p.ui?"true":"false",STX_TEST_VERBOSE:p.verbose?"true":"false"},o="bun";if(p.verbose)console.log(`Running: ${o} ${x.join(" ")}`);let i=performance.now(),s=R(o,x,{stdio:"inherit",shell:!1,env:e});return new Promise((c)=>{s.on("close",(r)=>{let d=((performance.now()-i)/1000).toFixed(2);if(r===0)c(!0);else c(!1)}),n.on("SIGINT",()=>{console.log(`
3
+ import"./chunk-5xj1df83.js";import"./chunk-73h7qjgq.js";import"./chunk-s59r34p5.js";import"./chunk-afhkvj3k.js";import"./chunk-axydabse.js";import{U}from"./chunk-nrp8qg9j.js";import"./chunk-zqzv5jy2.js";import"./chunk-g8k5rsqq.js";import"./chunk-jwpcck1b.js";import"./chunk-aem9hs8n.js";import"./chunk-dqr5n49p.js";import"./chunk-yx37nrgr.js";import"./chunk-pkpmyr0x.js";import"./chunk-fmj4xvqm.js";import"./chunk-g3h7j2n7.js";import"./chunk-7mbx7dzg.js";import"./chunk-x4ztj64h.js";import"./chunk-tehvry9a.js";import"./chunk-9zbjk8pg.js";import"./chunk-0vbpcef6.js";import"./chunk-d1xbamr1.js";import"./chunk-2428rqy1.js";import"./chunk-g2afpsw0.js";import"./chunk-n9jn3qzw.js";import"./chunk-1kmd0g1k.js";import"./chunk-8fj8sm1a.js";import"./chunk-z68rb7qp.js";import"./chunk-nw8p8eg9.js";import"./chunk-qbhbe9cw.js";import"./chunk-hd75916k.js";import"./chunk-3nydw825.js";import"./chunk-mnz6bdp3.js";import"./chunk-dwp3knc4.js";import"./chunk-hqywyyez.js";import{ft,gt}from"./chunk-6sw7sxh2.js";import"./chunk-bemksdz5.js";import"./chunk-697zcjzg.js";import"./chunk-0tchj3ct.js";import"./chunk-s5drjm2j.js";import"./chunk-19h1j59a.js";import"./chunk-b1q5sh7x.js";import"./chunk-yfd0e7dr.js";import"./chunk-ph6xg67j.js";import"./chunk-47jq9j1w.js";import{zs,Hs,Vs,Us,pr,Ws,qs,Ks,fr,gr,yn,bn,wn}from"./chunk-b5wh10s9.js";import"./chunk-vraddzkf.js";import"./chunk-849wf19d.js";import{di}from"./chunk-0xztxj98.js";import{u}from"./chunk-cg8hg6cs.js";import{spawn as R}from"child_process";import S from"fs";import M from"os";import f from"path";import n from"process";import{CLI as V}from"@stacksjs/clapp";var j="0.2.454";var __dirname="/home/runner/work/stx/stx/packages/stx/bin",y=new V("stx");function B(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(p<1024||p>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function A(h){try{if(!S.existsSync(h)){let x=f.dirname(h),t=f.basename(h);if(S.existsSync(x)){let o=S.readdirSync(x).filter((s)=>s.toLowerCase().includes(t.toLowerCase().substring(0,3))||s.endsWith(".stx")||s.endsWith(".md")),i=o.length>0?`File not found. Similar files in ${x}: ${o.slice(0,3).join(", ")}`:`File not found. Directory ${x} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${h}`,suggestion:i}}return{isValid:!1,error:`File does not exist: ${h}`,suggestion:"Check the file path and try again"}}if(S.statSync(h).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${h}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(p){return{isValid:!1,error:`Cannot access file: ${h}`,suggestion:"Check file permissions and path"}}}function z(h){let p=typeof h==="string"?Number.parseInt(h,10):h;if(Number.isNaN(p))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(p<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(p>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var O=(h)=>h.includes("*")||h.includes("?")||h.includes("{")||h.includes("["),H=(h)=>h.endsWith(".stx")||h.endsWith(".md");function F(h,p=1){if(console.error(`\u274C ${h.error}`),h.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${h.suggestion}`);n.exit(p)}function L(h){if(!h)return;let p;try{p=JSON.parse(h)}catch(x){console.error(`\u274C --info-plist is not valid JSON: ${x.message}`),n.exit(1)}if(typeof p!=="object"||p===null||Array.isArray(p))console.error(`\u274C --info-plist must be a JSON object, e.g. '{"NSFocusStatusUsageDescription":"\u2026"}'`),n.exit(1);for(let[x,t]of Object.entries(p))if(typeof t!=="string"&&typeof t!=="number"&&typeof t!=="boolean")console.error(`\u274C --info-plist value for "${x}" must be a string, number or boolean`),n.exit(1);return p}async function G(h,p){try{let x=["test"],t=[];if(h&&h.length>0)for(let c of h)if(O(c))try{let r=await Array.fromAsync(new Bun.Glob(c).scan({onlyFiles:!0,absolute:!0}));if(r.length===0)console.warn(`Warning: No files found matching pattern: ${c}`);else if(t.push(...r),p.verbose)console.log(`Found ${r.length} file(s) matching pattern: ${c}`)}catch(r){return console.error(`Error expanding glob pattern ${c}:`,r),!1}else t.push(c);if(t.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(x.push(...t),p.filter)x.push("--pattern",p.filter);if(p.timeout)x.push("--timeout",p.timeout.toString());if(p.reporter&&p.reporter!=="default")if(p.reporter==="junit"){let c=f.join(M.tmpdir(),`stx-test-report-${Date.now()}.xml`);x.push("--reporter",p.reporter),x.push("--reporter-outfile",c)}else console.warn(`Warning: Reporter '${p.reporter}' is not supported. Using default reporter.`);if(p.coverage)x.push("--coverage");if(p.watch)x.push("--watch");x.push("--preload",f.join(__dirname,"../../../test-utils/happy-dom.ts"));let e={...n.env,STX_TEST_MODE:"true",STX_TEST_UI:p.ui?"true":"false",STX_TEST_VERBOSE:p.verbose?"true":"false"},o="bun";if(p.verbose)console.log(`Running: ${o} ${x.join(" ")}`);let i=performance.now(),s=R(o,x,{stdio:"inherit",shell:!1,env:e});return new Promise((c)=>{s.on("close",(r)=>{let d=((performance.now()-i)/1000).toFixed(2);if(r===0)c(!0);else c(!1)}),n.on("SIGINT",()=>{console.log(`
4
4
  Test run interrupted`),s.kill("SIGINT"),n.exit(1)})})}catch(x){return console.error("Error running tests:",x instanceof Error?x.message:String(x)),!1}}var J=n.argv.length>=3&&(H(n.argv[2])&&S.existsSync(n.argv[2])||O(n.argv[2]));if(J){let h=n.argv[2],p={port:3000,watch:!0,cache:!0,markdown:{syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}}};for(let x=3;x<n.argv.length;x++){let t=n.argv[x];if(t==="--port"&&x+1<n.argv.length){let e=B(n.argv[++x]);if(!e.isValid)F(e);p.port=Number.parseInt(n.argv[x],10)}else if(t==="--no-watch")p.watch=!1;else if(t==="--highlight-theme"&&x+1<n.argv.length){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.defaultTheme=n.argv[++x]}else if(t==="--no-highlight"){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.enabled=!1}else if(t==="--no-highlight-unknown"){if(!p.markdown)p.markdown={};if(!p.markdown.syntaxHighlighting)p.markdown.syntaxHighlighting={};p.markdown.syntaxHighlighting.highlightUnknownLanguages=!1}else if(t==="--no-cache")p.cache=!1;else if(t==="--native")p.native=!0}if(O(h))try{let x=await Array.fromAsync(new Bun.Glob(h).scan({onlyFiles:!0,absolute:!0})),t=h.endsWith(".stx")?x.filter((s)=>s.endsWith(".stx")):h.endsWith(".md")?x.filter((s)=>s.endsWith(".md")):x.filter((s)=>s.endsWith(".stx")||s.endsWith(".md")),e=h.split("*")[0].replace(/\/$/,"")||".",o=f.resolve(e);try{let s=new Bun.Glob("**/*.stx"),r=(await Array.fromAsync(s.scan({cwd:o,onlyFiles:!0,absolute:!0}))).filter((l)=>/\[.+\]/.test(f.basename(l)));for(let l of r)if(!t.includes(l))t.push(l)}catch{}if(t.length===0)console.error(`Error: No STX or Markdown files found matching pattern: ${h}`),n.exit(1);if(!await bn(t,p))n.exit(1)}catch(x){console.error("Failed to process files:",x),n.exit(1)}else yn(h,p).catch((x)=>{console.error("Failed to start dev server:",x),n.exit(1)})}else{let h=function(t,e){let o=[];for(let i=0;i<=e.length;i++)o[i]=[i];for(let i=0;i<=t.length;i++)o[0][i]=i;for(let i=1;i<=e.length;i++)for(let s=1;s<=t.length;s++)if(e.charAt(i-1)===t.charAt(s-1))o[i][s]=o[i-1][s-1];else o[i][s]=Math.min(o[i-1][s-1]+1,o[i][s-1]+1,o[i-1][s]+1);return o[e.length][t.length]};y.command("docs","Generate documentation for components, templates, and directives").option("--output <dir>","Output directory for documentation",{default:"docs"}).option("--format <format>","Documentation format (markdown, html, json)",{default:"markdown"}).option("--components-dir <dir>","Components directory",{default:"components"}).option("--templates-dir <dir>","Templates directory",{default:"."}).option("--no-components","Disable components documentation").option("--no-templates","Disable templates documentation").option("--no-directives","Disable directives documentation").option("--extra-content <content>","Extra content to include in documentation").example("stx docs --output docs --format html").action(async(t)=>{try{if(await Us(t))console.log("Documentation generated successfully."),n.exit(0);else console.error("Documentation generation failed."),n.exit(1)}catch(e){console.error("Error generating documentation:",e),n.exit(1)}}),y.command("iconify <command>","Generate Iconify icon packages").option("--output <dir>","Output directory for generated packages",{default:"packages"}).option("--icons <icons>","Comma-separated list of specific icons to generate").example("stx iconify list").example("stx iconify generate mdi").example("stx iconify generate lucide --icons home,settings,user").action(async(t,e)=>{try{let{fetchCollections:o,generatePackage:i}=await import("./chunk-t61vdbje.js");if(t==="list"){console.log(`
5
5
  \uD83D\uDCDA Fetching available icon collections...
6
6
  `);let s=await o(),c=Object.entries(s).sort((r,l)=>l[1].total-r[1].total);console.log(`Available collections:
@@ -34,4 +34,5 @@ export declare interface NativeHost {
34
34
  flush: () => void
35
35
  dispatch: (handlerId: string, payload?: unknown) => void
36
36
  pending: () => number
37
+ snapshot: (root: NativeNode) => STXNode
37
38
  }
@@ -78,7 +78,7 @@ export function createNativeHost(options) {
78
78
  }
79
79
  }
80
80
  function recordOf(node) {
81
- let record = records.get(node.__stxId);
81
+ let record = records.get(node.__stxId) ?? revive(node);
82
82
  if (!record) {
83
83
  record = { type: "View", props: {}, style: {}, baseStyle: {}, classes: "", events: {}, children: [], visible: !0, materialized: !0 };
84
84
  records.set(node.__stxId, record);
@@ -100,9 +100,29 @@ export function createNativeHost(options) {
100
100
  const record = descriptorOf(node);
101
101
  if (!record)
102
102
  return;
103
- Object.values(record.events).forEach((handlerId) => handlers.delete(handlerId));
103
+ for (const handlerId of Object.values(record.events)) {
104
+ const handler = handlers.get(handlerId);
105
+ if (!handler)
106
+ continue;
107
+ (record.parkedHandlers ??= new Map).set(handlerId, handler);
108
+ handlers.delete(handlerId);
109
+ }
104
110
  record.children.forEach(releaseHandlers);
105
111
  }
112
+ function revive(node) {
113
+ const retained = node, record = retained.__stxDetachedRecord;
114
+ if (!record)
115
+ return;
116
+ delete retained.__stxDetachedRecord;
117
+ record.materialized = !1;
118
+ if (record.parkedHandlers) {
119
+ for (const [handlerId, handler] of record.parkedHandlers)
120
+ handlers.set(handlerId, handler);
121
+ record.parkedHandlers = void 0;
122
+ }
123
+ records.set(node.__stxId, record);
124
+ return record;
125
+ }
106
126
  function materialize(node) {
107
127
  const record = recordOf(node);
108
128
  if (record.materialized || node.__stxAnchor !== void 0)
@@ -116,6 +136,7 @@ export function createNativeHost(options) {
116
136
  type: record.type,
117
137
  props: { ...record.props },
118
138
  style: { ...record.style },
139
+ ...Object.keys(record.events).length ? { events: { ...record.events } } : {},
119
140
  ...record.text === void 0 ? {} : { children: [record.text] }
120
141
  }
121
142
  });
@@ -254,10 +275,30 @@ export function createNativeHost(options) {
254
275
  },
255
276
  pending: () => queue.length,
256
277
  flush,
278
+ snapshot(root) {
279
+ queue = [];
280
+ const describe = (node) => {
281
+ const record = recordOf(node);
282
+ if (!record.materialized)
283
+ record.style = resolveStyle(record);
284
+ record.materialized = !0;
285
+ const children = record.children.filter((child) => child.__stxAnchor === void 0).map(describe);
286
+ return {
287
+ id: node.__stxId,
288
+ type: record.type,
289
+ props: { ...record.props },
290
+ style: { ...record.style },
291
+ events: { ...record.events },
292
+ children: record.text === void 0 ? children : [record.text]
293
+ };
294
+ };
295
+ return describe(root);
296
+ },
257
297
  setText(node, value) {
258
- const text = value == null ? "" : String(value);
259
- recordOf(node).text = text;
260
- emit({ op: "updateNode", id: node.__stxId, patch: { children: [text] } });
298
+ const text = value == null ? "" : String(value), record = recordOf(node);
299
+ record.text = text;
300
+ if (record.materialized)
301
+ emit({ op: "updateNode", id: node.__stxId, patch: { children: [text] } });
261
302
  },
262
303
  setAttribute(node, name, value) {
263
304
  if (name === "class" || name === "className") {
@@ -270,7 +311,8 @@ export function createNativeHost(options) {
270
311
  recordOf(node).props[prop] = value;
271
312
  if (recordOf(node).type === "Icon" && prop === "name")
272
313
  this.setAttribute(node, "symbol", resolveIconName(String(value ?? "")).symbol);
273
- emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: value } } });
314
+ if (recordOf(node).materialized)
315
+ emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: value } } });
274
316
  },
275
317
  removeAttribute(node, name) {
276
318
  if (name === "class" || name === "className") {
@@ -279,7 +321,8 @@ export function createNativeHost(options) {
279
321
  }
280
322
  const prop = nativePropName(name);
281
323
  delete recordOf(node).props[prop];
282
- emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: null } } });
324
+ if (recordOf(node).materialized)
325
+ emit({ op: "updateNode", id: node.__stxId, patch: { props: { [prop]: null } } });
283
326
  },
284
327
  setStyle(node, value) {
285
328
  if (typeof value !== "object" || value === null || Array.isArray(value))
@@ -287,13 +330,16 @@ export function createNativeHost(options) {
287
330
  const style = value;
288
331
  Object.assign(recordOf(node).baseStyle, style);
289
332
  Object.assign(recordOf(node).style, style);
290
- emit({ op: "updateNode", id: node.__stxId, patch: { style } });
333
+ if (recordOf(node).materialized)
334
+ emit({ op: "updateNode", id: node.__stxId, patch: { style } });
291
335
  },
292
336
  listen(node, event, handler) {
293
337
  const id = nextId("h"), nativeEvent = NATIVE_EVENT_NAMES[event.toLowerCase()] ?? event;
294
338
  handlers.set(id, handler);
295
- recordOf(node).events[nativeEvent] = id;
296
- emit({ op: "updateNode", id: node.__stxId, patch: { events: { [nativeEvent]: id } } });
339
+ const record = recordOf(node);
340
+ record.events[nativeEvent] = id;
341
+ if (record.materialized)
342
+ emit({ op: "updateNode", id: node.__stxId, patch: { events: { [nativeEvent]: id } } });
297
343
  },
298
344
  dispatch(handlerId, payload) {
299
345
  handlers.get(handlerId)?.(payload);
@@ -311,7 +357,8 @@ export function createNativeHost(options) {
311
357
  const record = recordOf(node), was = record.visible;
312
358
  record.visible = visible;
313
359
  record.baseStyle.display = visible ? "flex" : "none";
314
- emit({ op: "updateNode", id: node.__stxId, patch: { style: { display: visible ? "flex" : "none" } } });
360
+ if (record.materialized)
361
+ emit({ op: "updateNode", id: node.__stxId, patch: { style: { display: visible ? "flex" : "none" } } });
315
362
  return was;
316
363
  },
317
364
  anchor(label) {
@@ -372,11 +419,15 @@ export function createNativeHost(options) {
372
419
  if (node.__stxAnchor !== void 0 || !record.materialized)
373
420
  return;
374
421
  materialize(node);
422
+ let nativeIndex = 0;
423
+ for (let i = 0;i < index; i++)
424
+ if (record.children[i].__stxAnchor === void 0)
425
+ nativeIndex++;
375
426
  emit({
376
427
  op: existing === -1 ? "insertChild" : "moveChild",
377
428
  parentId: parent.__stxId,
378
429
  childId: node.__stxId,
379
- index
430
+ index: nativeIndex
380
431
  });
381
432
  },
382
433
  descendants: collectDescendants,
@@ -3,7 +3,7 @@ import { materializeNativeBindingTree } from "./binding-tree.js";
3
3
  import { installCraftBridge } from "./craft-bridge.js";
4
4
  import { createNativeHost } from "./native-host.js";
5
5
  export function prepareSharedNativeScreen(document, manifest, bridge, options = {}) {
6
- let revision = 0;
6
+ let revision = 0, generation = 0;
7
7
  const protocol = new STXBridge;
8
8
  protocol.initialize(bridge);
9
9
  installCraftBridge(protocol, bridge, globalThis, options);
@@ -14,7 +14,7 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
14
14
  revision++;
15
15
  protocol.mutate({
16
16
  version: 1,
17
- batchId: `mutation_${revision}`,
17
+ batchId: `mutation_${generation}_${revision}`,
18
18
  baseRevision,
19
19
  revision,
20
20
  operations
@@ -30,6 +30,15 @@ export function prepareSharedNativeScreen(document, manifest, bridge, options =
30
30
  });
31
31
  const tree = materializeNativeBindingTree(document, manifest, host);
32
32
  let dispose = null;
33
+ protocol.on("MUTATION_ERROR", (message) => {
34
+ const payload = message.payload ?? {}, batch = String(payload.batchId ?? "");
35
+ if (batch && !batch.startsWith(`mutation_${generation}_`))
36
+ return;
37
+ console.error(`[stx native] the screen refused ${batch || "a mutation batch"} (${payload.code ?? "error"}: ${payload.message ?? ""}); redrawing it`);
38
+ generation++;
39
+ revision = 0;
40
+ protocol.render(host.snapshot(tree.root));
41
+ });
33
42
  protocol.on("EVENT", (message) => {
34
43
  const handlerId = message.payload?.handlerId ?? message.payload?.handlerName;
35
44
  if (typeof handlerId === "string")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.452",
4
+ "version": "0.2.454",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -122,12 +122,12 @@
122
122
  "dependencies": {
123
123
  "@stacksjs/ts-css": "^0.3.2",
124
124
  "@stacksjs/clapp": "^0.2.16",
125
- "@stacksjs/desktop": "0.2.452",
126
- "@stacksjs/sanitizer": "0.2.452",
125
+ "@stacksjs/desktop": "0.2.454",
126
+ "@stacksjs/sanitizer": "0.2.454",
127
127
  "@stacksjs/ts-i18n": "^0.1.11",
128
- "bun-plugin-stx": "0.2.452",
128
+ "bun-plugin-stx": "0.2.454",
129
129
  "bunfig": "^0.15.19",
130
- "stx-router": "0.2.452",
130
+ "stx-router": "0.2.454",
131
131
  "ts-broadcasting": "^0.0.11",
132
132
  "ts-images": "^0.2.22",
133
133
  "ts-syntax-highlighter": "^0.2.1"