jq79 0.7.8 → 0.7.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jq79",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "Mini reactive component library: single-file .html components, Svelte-style setup scripts, fine-grained proxy reactivity. No compiler, no bundler, no dependencies — works from any static host.",
5
5
  "keywords": [
6
6
  "reactive",
package/src/jq79.ts CHANGED
@@ -4330,7 +4330,7 @@ export class Component79 {
4330
4330
  return Promise.all(steps).then(() => undefined)
4331
4331
  }
4332
4332
 
4333
- // whether fetch(), fetchAll() and a setup script's import() of an .html
4333
+ // whether fetch(), fetchAll(), importAll() and a setup script's import() of an .html
4334
4334
  // download a file once and reuse its source after that. On by default:
4335
4335
  //
4336
4336
  // Component79.cache() // true - is it on?
@@ -4361,6 +4361,16 @@ export class Component79 {
4361
4361
  return Promise.all(urls.map(fetchComponent))
4362
4362
  }
4363
4363
 
4364
+ // a page's Promise.all([import(…), …]), as a setup script's import() reads
4365
+ // each one: an .html is the component (fetchAll's way, cache included),
4366
+ // anything else the module. The page has no file of its own, so a relative
4367
+ // specifier means the page - never jq79.js, which is what the native import()
4368
+ // in here would otherwise resolve it against (see resolveSpecifier)
4369
+ static importAll<const T extends readonly string[]>(specifiers: T): Promise<ImportedAll<T>> {
4370
+ if (!Array.isArray(specifiers)) throw new TypeError("Component79.importAll takes an array; use import() for one")
4371
+ return Promise.all(specifiers.map(spec => importResource(resolveSpecifier(spec, undefined)))) as Promise<ImportedAll<T>>
4372
+ }
4373
+
4364
4374
  // subscribes to this instance's $emit events, on top of the DOM CustomEvent
4365
4375
  // dispatch - so it hears emits even while the component is detached (where
4366
4376
  // the event has no ancestors to bubble to). Chainable; can be called before
@@ -5073,6 +5083,12 @@ export type Component<P = any, E extends string = never, S extends string = neve
5073
5083
  readonly "~slots"?: (slot: S) => void
5074
5084
  }
5075
5085
 
5086
+ // what importAll resolves to, entry by entry: a literal .html (or .htm) is a
5087
+ // component, anything else a module namespace jq79 has no types for
5088
+ export type ImportedAll<T extends readonly string[]> = {
5089
+ -readonly [K in keyof T]: T[K] extends `${string}.html` | `${string}.htm` ? Component79 : any
5090
+ }
5091
+
5076
5092
  export const parseComponent = (component: string): Component79 => new Component79(component)
5077
5093
 
5078
5094
  // one broken hook must not leave the others' timers running, or the
@@ -5104,7 +5120,7 @@ let settleQueued = false
5104
5120
  // declaration) shadows them. Their names, in this order, are also
5105
5121
  // SETUP_HELPER_NAMES (source.ts) - what precompile compiles scripts with, so
5106
5122
  // the two change together
5107
- const SETUP_HELPERS: Record<string, any> = { $, $$, $create, $reactive, $toRaw, Component79 }
5123
+ const SETUP_HELPERS: Record<string, any> = { $, $$, $create, $reactive, $toRaw, Component79, C79: Component79 }
5108
5124
 
5109
5125
  // the hot-reload handshake. jq79/dev serves a classic script that sets the flag
5110
5126
  // below; classic scripts run before deferred module ones, so the flag is always
package/src/source.ts CHANGED
@@ -369,7 +369,7 @@ export const declaredPropNames = (scripts: TagBlock[], signature: (script: TagBl
369
369
  // $emit, $updateModel and $slots. They are positional parameters, so the order is part of what
370
370
  // precompile has to reproduce; change one side and precompiled scripts stop
371
371
  // matching, which tests/precompile.test.ts and `npm run check:precompile` catch
372
- export const SETUP_HELPER_NAMES = ["$", "$$", "$create", "$reactive", "$toRaw", "Component79"]
372
+ export const SETUP_HELPER_NAMES = ["$", "$$", "$create", "$reactive", "$toRaw", "Component79", "C79"]
373
373
  export const INSTANCE_HELPER_NAMES = ["$mounted", "$destroyed", "$attached", "$detached", "$computed", "$self", "$$self", "$emit", "$updateModel", "$slots"]
374
374
 
375
375
  // the global a precompiled script leaves its functions on, for the runtime to