@stacksjs/stx 0.2.500 → 0.2.502
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-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{U}from"./chunk-m9nr12a1.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-81t6zr3m.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import"./chunk-cp7hph6f.js";import"./chunk-0egg3666.js";import"./chunk-298s08st.js";import"./chunk-67actssw.js";import"./chunk-z9tvn738.js";import"./chunk-z9fz5dby.js";import"./chunk-vtn0gmen.js";import"./chunk-71bbv43t.js";import"./chunk-stvqwzen.js";import"./chunk-25m2wqsd.js";import"./chunk-rhrv2j36.js";import"./chunk-h6q8jafh.js";import"./chunk-93sr9q8g.js";import"./chunk-01rz8h7x.js";import"./chunk-40jd0b4h.js";import"./chunk-1v86h5vn.js";import"./chunk-4mrgy3ve.js";import"./chunk-tdetcthb.js";import"./chunk-b5mcvm6y.js";import"./chunk-1c407nky.js";import"./chunk-3s9s1mdt.js";import"./chunk-s9mq9x2k.js";import"./chunk-2hc5mbw8.js";import{mt,ht}from"./chunk-dve4q9tg.js";import"./chunk-15w4adyd.js";import"./chunk-zqxqdns1.js";import"./chunk-vp827ah7.js";import"./chunk-3mynjdqr.js";import"./chunk-vg9dyc4y.js";import"./chunk-zv0vgamy.js";import"./chunk-8fb1mqw1.js";import"./chunk-33snwgdy.js";import"./chunk-4ssg2hn4.js";import{Ks,Xs,Gs,Js,hr,Ys,Zs,Qs,yr,br,Cn,$n,En}from"./chunk-b90y5phw.js";import"./chunk-8qdvhbv7.js";import"./chunk-er7y8hk9.js";import{yi}from"./chunk-szry3s17.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.
|
|
3
|
+
import"./chunk-2pph3dh0.js";import"./chunk-c57j92td.js";import"./chunk-rmavqxd8.js";import"./chunk-v7vkqg8f.js";import"./chunk-d4k4nyj0.js";import{U}from"./chunk-m9nr12a1.js";import"./chunk-b77v56fz.js";import"./chunk-qmcmjdy7.js";import"./chunk-1erc0vrb.js";import"./chunk-81t6zr3m.js";import"./chunk-e6y6s7q8.js";import"./chunk-kp4mzspk.js";import"./chunk-cp7hph6f.js";import"./chunk-0egg3666.js";import"./chunk-298s08st.js";import"./chunk-67actssw.js";import"./chunk-z9tvn738.js";import"./chunk-z9fz5dby.js";import"./chunk-vtn0gmen.js";import"./chunk-71bbv43t.js";import"./chunk-stvqwzen.js";import"./chunk-25m2wqsd.js";import"./chunk-rhrv2j36.js";import"./chunk-h6q8jafh.js";import"./chunk-93sr9q8g.js";import"./chunk-01rz8h7x.js";import"./chunk-40jd0b4h.js";import"./chunk-1v86h5vn.js";import"./chunk-4mrgy3ve.js";import"./chunk-tdetcthb.js";import"./chunk-b5mcvm6y.js";import"./chunk-1c407nky.js";import"./chunk-3s9s1mdt.js";import"./chunk-s9mq9x2k.js";import"./chunk-2hc5mbw8.js";import{mt,ht}from"./chunk-dve4q9tg.js";import"./chunk-15w4adyd.js";import"./chunk-zqxqdns1.js";import"./chunk-vp827ah7.js";import"./chunk-3mynjdqr.js";import"./chunk-vg9dyc4y.js";import"./chunk-zv0vgamy.js";import"./chunk-8fb1mqw1.js";import"./chunk-33snwgdy.js";import"./chunk-4ssg2hn4.js";import{Ks,Xs,Gs,Js,hr,Ys,Zs,Qs,yr,br,Cn,$n,En}from"./chunk-b90y5phw.js";import"./chunk-8qdvhbv7.js";import"./chunk-er7y8hk9.js";import{yi}from"./chunk-szry3s17.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.502";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 $n(t,p))n.exit(1)}catch(x){console.error("Failed to process files:",x),n.exit(1)}else Cn(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 Js(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:
|
|
@@ -170,6 +170,7 @@ export declare interface ApiRequestPayload {
|
|
|
170
170
|
module: string
|
|
171
171
|
method: string
|
|
172
172
|
args: unknown[]
|
|
173
|
+
untimed?: true
|
|
173
174
|
}
|
|
174
175
|
/**
|
|
175
176
|
* The single argument of a `Network.fetch` capability request. The bundle's
|
|
@@ -180,6 +181,7 @@ export declare interface NativeFetchRequest {
|
|
|
180
181
|
method: string
|
|
181
182
|
headers: Record<string, string>
|
|
182
183
|
body: string | null
|
|
184
|
+
form?: NativeFormPart[]
|
|
183
185
|
}
|
|
184
186
|
/**
|
|
185
187
|
* The `API_RESPONSE` data for `Network.fetch`. HTTP error statuses are
|
|
@@ -303,6 +305,9 @@ export type NativeMutationOperation = | { op: 'createNode', id: string, node: Na
|
|
|
303
305
|
| { op: 'insertChild', parentId: string, childId: string, index: number }
|
|
304
306
|
| { op: 'moveChild', parentId: string, childId: string, index: number }
|
|
305
307
|
| { op: 'removeNode', id: string }
|
|
308
|
+
/** One field of a form sent through `Network.fetch`. */
|
|
309
|
+
export type NativeFormPart = | { name: string, value: string }
|
|
310
|
+
| { name: string, path: string, filename: string, type: string }
|
|
306
311
|
// ============================================================================
|
|
307
312
|
// Bridge Implementation
|
|
308
313
|
// ============================================================================
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { STXBridge } from "../bridge/protocol.js";
|
|
2
2
|
import { createEventSourceClass, createStreamingBody } from "./event-stream.js";
|
|
3
|
-
import { abortError } from "./jsc-globals.js";
|
|
3
|
+
import { abortError, NativeFormData, nativeFormParts } from "./jsc-globals.js";
|
|
4
4
|
function capabilityFlags(capabilities) {
|
|
5
5
|
return {
|
|
6
6
|
haptics: capabilities.has("haptics"),
|
|
7
7
|
speechRecognition: !1,
|
|
8
8
|
share: capabilities.has("share"),
|
|
9
|
-
camera:
|
|
9
|
+
camera: capabilities.has("camera"),
|
|
10
|
+
files: capabilities.has("files"),
|
|
10
11
|
biometric: capabilities.has("biometric"),
|
|
11
12
|
pushNotifications: capabilities.has("push"),
|
|
12
13
|
secureStorage: capabilities.has("secureStorage"),
|
|
@@ -292,6 +293,37 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
292
293
|
readRecording: (options = {}) => strap("readRecording", { since: typeof options.since === "number" ? options.since : null })
|
|
293
294
|
};
|
|
294
295
|
}
|
|
296
|
+
if (capabilities.has("files")) {
|
|
297
|
+
craft.files = {
|
|
298
|
+
pickImage: (options = {}) => ask("Files", "pickImage", [{
|
|
299
|
+
source: options.source === "camera" ? "camera" : "library",
|
|
300
|
+
...typeof options.maxPixels === "number" ? { maxPixels: options.maxPixels } : {},
|
|
301
|
+
...typeof options.quality === "number" ? { quality: options.quality } : {}
|
|
302
|
+
}]).then((file) => file ?? null),
|
|
303
|
+
download: (url, options = {}) => {
|
|
304
|
+
if (typeof url !== "string" || !url)
|
|
305
|
+
return Promise.reject(TypeError("files.download needs a URL"));
|
|
306
|
+
const headers = {}, given = options.headers;
|
|
307
|
+
if (given && typeof given === "object")
|
|
308
|
+
Object.keys(given).forEach((name) => {
|
|
309
|
+
headers[name] = String(given[name]);
|
|
310
|
+
});
|
|
311
|
+
return request("Files", "download", [url, { headers, ...typeof options.name === "string" ? { name: options.name } : {} }]);
|
|
312
|
+
},
|
|
313
|
+
write: (name, data, options = {}) => {
|
|
314
|
+
if (typeof name !== "string" || !name.trim())
|
|
315
|
+
return Promise.reject(TypeError("files.write needs a file name"));
|
|
316
|
+
if (typeof data !== "string")
|
|
317
|
+
return Promise.reject(TypeError("files.write needs its contents as a string"));
|
|
318
|
+
return request("Files", "write", [name, data, {
|
|
319
|
+
encoding: options.encoding === "base64" ? "base64" : "utf8",
|
|
320
|
+
...typeof options.type === "string" ? { type: options.type } : {}
|
|
321
|
+
}]);
|
|
322
|
+
},
|
|
323
|
+
remove: (file) => request("Files", "remove", [typeof file === "string" ? file : file?.path]).then(Boolean)
|
|
324
|
+
};
|
|
325
|
+
target.FormData ??= NativeFormData;
|
|
326
|
+
}
|
|
295
327
|
protocol.on("CRAFT_EVENT", ({ payload }) => {
|
|
296
328
|
if (typeof payload?.event !== "string" || typeof target.dispatchEvent !== "function" || typeof target.CustomEvent !== "function")
|
|
297
329
|
return;
|
|
@@ -504,7 +536,16 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
504
536
|
inputHeaders.forEach(addHeader);
|
|
505
537
|
else if (inputHeaders && typeof inputHeaders === "object")
|
|
506
538
|
Object.keys(inputHeaders).forEach((name) => addHeader(name, inputHeaders[name]));
|
|
507
|
-
|
|
539
|
+
let body = init.body !== void 0 ? init.body : source.body, form;
|
|
540
|
+
if (body instanceof NativeFormData) {
|
|
541
|
+
if (!capabilities.has("files"))
|
|
542
|
+
return Promise.reject(TypeError("This app cannot send a form from a native screen"));
|
|
543
|
+
if (method === "GET" || method === "HEAD")
|
|
544
|
+
return Promise.reject(TypeError("A GET or HEAD request cannot have a body"));
|
|
545
|
+
form = nativeFormParts(body);
|
|
546
|
+
body = null;
|
|
547
|
+
delete headers["content-type"];
|
|
548
|
+
}
|
|
508
549
|
if (body != null && typeof body !== "string")
|
|
509
550
|
return Promise.reject(TypeError("fetch in a native screen sends string bodies only"));
|
|
510
551
|
if (body != null && (method === "GET" || method === "HEAD"))
|
|
@@ -512,9 +553,9 @@ export function installCraftBridge(protocol, nativeBridge, target = globalThis,
|
|
|
512
553
|
const signal = init.signal || source.signal;
|
|
513
554
|
if (signal?.aborted)
|
|
514
555
|
return Promise.reject(abortError(signal.reason));
|
|
515
|
-
if (streaming && /text\/event-stream/i.test(headers.accept || ""))
|
|
556
|
+
if (streaming && !form && /text\/event-stream/i.test(headers.accept || ""))
|
|
516
557
|
return streamingFetch(url, method, headers, body == null ? null : body, signal);
|
|
517
|
-
const answer = request("Network", "fetch", [{ url, method, headers, body: body == null ? null : body }]).then((data) => {
|
|
558
|
+
const answer = request("Network", "fetch", [{ url, method, headers, body: body == null ? null : body, ...form ? { form } : {} }]).then((data) => {
|
|
518
559
|
const responseBody = data?.body == null ? "" : String(data.body);
|
|
519
560
|
let bodyUsed = !1;
|
|
520
561
|
return response(data, { get bodyUsed() {
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
declare function nativeBtoa(input: unknown): string;
|
|
7
7
|
/** `atob`, the other way, with a browser's forgiveness: whitespace ignored, padding optional. */
|
|
8
8
|
declare function nativeAtob(input: unknown): string;
|
|
9
|
+
export declare function isNativeFile(value: unknown): value is NativeFile;
|
|
10
|
+
/** A form as `Network.fetch` sends it: text fields and file paths. */
|
|
11
|
+
export declare function nativeFormParts(form: NativeFormData): Array<{ name: string, value: string } | { name: string, path: string, filename: string, type: string }>;
|
|
9
12
|
/** The error an aborted `fetch` rejects with, named as the web names it. */
|
|
10
13
|
export declare function abortError(reason?: unknown): Error;
|
|
11
14
|
/**
|
|
@@ -20,7 +23,19 @@ export declare function nativeAnimationFrame(target: AnyRecord, callback: (time:
|
|
|
20
23
|
export declare function installJSCGlobals(target?: AnyRecord): void;
|
|
21
24
|
/** A display's frame, in milliseconds: 60 a second. */
|
|
22
25
|
export declare const NATIVE_FRAME_MS: unknown;
|
|
26
|
+
/**
|
|
27
|
+
* A file `craft.files` made on the phone (a picked photo, a download): a path
|
|
28
|
+
* the host reads itself, so its bytes never pass through JavaScriptCore.
|
|
29
|
+
*/
|
|
30
|
+
export declare interface NativeFile {
|
|
31
|
+
path: string
|
|
32
|
+
name: string
|
|
33
|
+
type: string
|
|
34
|
+
size: number
|
|
35
|
+
[key: string]: unknown
|
|
36
|
+
}
|
|
23
37
|
declare type AnyRecord = Record<string, any> // eslint-disable-line ts/no-explicit-any;
|
|
38
|
+
declare type FormValue = string | NativeFile;
|
|
24
39
|
declare class NativeEvent {
|
|
25
40
|
type: string;
|
|
26
41
|
detail: unknown;
|
|
@@ -107,6 +122,29 @@ declare class NativeURL {
|
|
|
107
122
|
toString(): string;
|
|
108
123
|
toJSON(): string;
|
|
109
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* `FormData`, which JavaScriptCore does not have: the web's shape, holding
|
|
127
|
+
* text and the files `craft.files` made (a `File` on the page). `fetch` on a
|
|
128
|
+
* native screen sends it as multipart/form-data, built by the host, so code
|
|
129
|
+
* shared with the page posts a photo the same way on both
|
|
130
|
+
* (`form.append('photo', file)`). Installed where the host can send one (the
|
|
131
|
+
* `files` capability).
|
|
132
|
+
*/
|
|
133
|
+
export declare class NativeFormData {
|
|
134
|
+
constructor(form?: unknown);
|
|
135
|
+
append(name: string, value: unknown, filename?: string): void;
|
|
136
|
+
set(name: string, value: unknown, filename?: string): void;
|
|
137
|
+
get(name: string): FormValue | null;
|
|
138
|
+
getAll(name: string): FormValue[];
|
|
139
|
+
has(name: string): boolean;
|
|
140
|
+
delete(name: string): void;
|
|
141
|
+
forEach(callback: (value: FormValue, name: string, form: NativeFormData) => void): void;
|
|
142
|
+
entries(): IterableIterator<[string, FormValue]>;
|
|
143
|
+
keys(): IterableIterator<string>;
|
|
144
|
+
values(): IterableIterator<FormValue>;
|
|
145
|
+
[Symbol.iterator](): IterableIterator<[string, FormValue]>;
|
|
146
|
+
get [Symbol.toStringTag](): string;
|
|
147
|
+
}
|
|
110
148
|
/**
|
|
111
149
|
* `AbortController` and `AbortSignal`, which are DOM APIs JavaScriptCore does
|
|
112
150
|
* not have. Code shared with the page cancels its requests with them (a
|
|
@@ -475,6 +475,72 @@ function nativeAtob(input) {
|
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
export { nativeAtob, nativeBtoa };
|
|
478
|
+
export function isNativeFile(value) {
|
|
479
|
+
return !!value && typeof value === "object" && typeof value.path === "string" && typeof value.name === "string";
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export class NativeFormData {
|
|
483
|
+
list = [];
|
|
484
|
+
constructor(form) {
|
|
485
|
+
if (form !== void 0)
|
|
486
|
+
throw TypeError("FormData on a native screen is built with append(); there is no <form> to read");
|
|
487
|
+
}
|
|
488
|
+
append(name, value, filename) {
|
|
489
|
+
this.list.push([String(name), formValue(value, filename)]);
|
|
490
|
+
}
|
|
491
|
+
set(name, value, filename) {
|
|
492
|
+
const key = String(name), entry = [key, formValue(value, filename)], first = this.list.findIndex(([at]) => at === key);
|
|
493
|
+
if (first === -1) {
|
|
494
|
+
this.list.push(entry);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
this.list = this.list.filter(([at], index) => index === first || at !== key);
|
|
498
|
+
this.list[first] = entry;
|
|
499
|
+
}
|
|
500
|
+
get(name) {
|
|
501
|
+
return this.list.find(([at]) => at === String(name))?.[1] ?? null;
|
|
502
|
+
}
|
|
503
|
+
getAll(name) {
|
|
504
|
+
return this.list.filter(([at]) => at === String(name)).map(([, value]) => value);
|
|
505
|
+
}
|
|
506
|
+
has(name) {
|
|
507
|
+
return this.list.some(([at]) => at === String(name));
|
|
508
|
+
}
|
|
509
|
+
delete(name) {
|
|
510
|
+
this.list = this.list.filter(([at]) => at !== String(name));
|
|
511
|
+
}
|
|
512
|
+
forEach(callback) {
|
|
513
|
+
for (const [name, value] of [...this.list])
|
|
514
|
+
callback(value, name, this);
|
|
515
|
+
}
|
|
516
|
+
entries() {
|
|
517
|
+
return this.list.map(([name, value]) => [name, value])[Symbol.iterator]();
|
|
518
|
+
}
|
|
519
|
+
keys() {
|
|
520
|
+
return this.list.map(([name]) => name)[Symbol.iterator]();
|
|
521
|
+
}
|
|
522
|
+
values() {
|
|
523
|
+
return this.list.map(([, value]) => value)[Symbol.iterator]();
|
|
524
|
+
}
|
|
525
|
+
[Symbol.iterator]() {
|
|
526
|
+
return this.entries();
|
|
527
|
+
}
|
|
528
|
+
get [Symbol.toStringTag]() {
|
|
529
|
+
return "FormData";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
function formValue(value, filename) {
|
|
533
|
+
if (isNativeFile(value))
|
|
534
|
+
return { ...value, name: filename === void 0 ? value.name : String(filename) };
|
|
535
|
+
return String(value);
|
|
536
|
+
}
|
|
537
|
+
export function nativeFormParts(form) {
|
|
538
|
+
const parts = [];
|
|
539
|
+
form.forEach((value, name) => {
|
|
540
|
+
parts.push(typeof value === "string" ? { name, value } : { name, path: value.path, filename: value.name, type: typeof value.type === "string" && value.type ? value.type : "application/octet-stream" });
|
|
541
|
+
});
|
|
542
|
+
return parts;
|
|
543
|
+
}
|
|
478
544
|
export function abortError(reason) {
|
|
479
545
|
if (reason instanceof Error)
|
|
480
546
|
return reason;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.502",
|
|
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.
|
|
126
|
-
"@stacksjs/sanitizer": "0.2.
|
|
125
|
+
"@stacksjs/desktop": "0.2.502",
|
|
126
|
+
"@stacksjs/sanitizer": "0.2.502",
|
|
127
127
|
"@stacksjs/ts-i18n": "^0.1.11",
|
|
128
|
-
"bun-plugin-stx": "0.2.
|
|
128
|
+
"bun-plugin-stx": "0.2.502",
|
|
129
129
|
"bunfig": "^0.15.19",
|
|
130
|
-
"stx-router": "0.2.
|
|
130
|
+
"stx-router": "0.2.502",
|
|
131
131
|
"ts-broadcasting": "^0.0.11",
|
|
132
132
|
"ts-images": "^0.2.22",
|
|
133
133
|
"ts-syntax-highlighter": "^0.2.1"
|