brumate 0.4.3 → 0.4.4
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 +2 -2
- package/dist/{client-AXNULmRZ.js → client-iZ9a1Nut.js} +17 -8
- package/dist/client-iZ9a1Nut.js.map +1 -0
- package/dist/{defer-D3YMPgkX.js → defer-DP7dMS2y.js} +2 -2
- package/dist/{defer-D3YMPgkX.js.map → defer-DP7dMS2y.js.map} +1 -1
- package/dist/{devtools-BiP5fDiB.js → devtools-BJB_MMeL.js} +4 -4
- package/dist/{devtools-BiP5fDiB.js.map → devtools-BJB_MMeL.js.map} +1 -1
- package/dist/{devtools-panel-EQhLm39H.js → devtools-panel-CUV6A4ZE.js} +2 -2
- package/dist/{devtools-panel-EQhLm39H.js.map → devtools-panel-CUV6A4ZE.js.map} +1 -1
- package/dist/{files-BUjvEO_o.js → files-BZRjz9Mx.js} +2 -2
- package/dist/{files-BUjvEO_o.js.map → files-BZRjz9Mx.js.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/{inspect-BvPTZs6k.js → inspect-BLOdfj7o.js} +2 -1
- package/dist/inspect-BLOdfj7o.js.map +1 -0
- package/dist/{loader-DgMk6p9M.js → loader-CheV6t0N.js} +2 -2
- package/dist/{loader-DgMk6p9M.js.map → loader-CheV6t0N.js.map} +1 -1
- package/dist/{rpc-Bxv7DYGe.js → rpc-DvTwGfL_.js} +2 -2
- package/dist/{rpc-Bxv7DYGe.js.map → rpc-DvTwGfL_.js.map} +1 -1
- package/dist/runtime/client.js +1 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.js +1 -1
- package/dist/{static-loader-U_x-ctJI.js → static-loader-BLJYvTKc.js} +2 -2
- package/dist/{static-loader-U_x-ctJI.js.map → static-loader-BLJYvTKc.js.map} +1 -1
- package/dist/vite.js +2 -2
- package/package.json +1 -1
- package/skills/brumate/references/errors.md +20 -0
- package/dist/client-AXNULmRZ.js.map +0 -1
- package/dist/inspect-BvPTZs6k.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as ROUTE_KEY, t as NAVIGATION_KEY } from "./context-CTiSzQRc.js";
|
|
2
|
-
import { n as boot, r as importCore } from "./static-loader-
|
|
2
|
+
import { n as boot, r as importCore } from "./static-loader-BLJYvTKc.js";
|
|
3
3
|
//#region src/runtime/loader.ts
|
|
4
4
|
/**
|
|
5
5
|
* Starts resuming the page. Listens to the events in `b-on` attributes
|
|
@@ -140,4 +140,4 @@ function navigation({ options, listen, core, start: startCore, scan }) {
|
|
|
140
140
|
//#endregion
|
|
141
141
|
export { start as t };
|
|
142
142
|
|
|
143
|
-
//# sourceMappingURL=loader-
|
|
143
|
+
//# sourceMappingURL=loader-CheV6t0N.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader-DgMk6p9M.js","names":[],"sources":["../src/runtime/loader.ts"],"sourcesContent":["import type * as Routes from './client-routes.ts';\nimport { boot, importCore } from './boot.ts';\nimport { NAVIGATION_KEY, ROUTE_KEY } from './context.ts';\nimport type { Core, LoaderOptions, Navigation } from './boot.ts';\n\nexport type { LoaderOptions, NavigateOptions } from './boot.ts';\nexport { startWithoutNavigation } from './static-loader.ts';\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function start(options: LoaderOptions): () => void {\n return boot(options, options.navigate === false ? undefined : navigation);\n}\n\n/** Starts loading the page of a link, unless the link asks not to. */\nfunction prefetch(link: HTMLAnchorElement | undefined): void {\n if (link && link.getAttribute('data-prefetch') !== 'none') {\n void import('./navigate.ts').then((module) => module.prefetch(link.href));\n }\n}\n\n/**\n * Imports the code with which the core reads the pages that navigation adds.\n * A core that runs loads it when the loader navigates. A core that starts\n * later loads it with the core, when the page has records that navigation\n * marked.\n */\nfunction routes(): (typeof Routes)['ready'] {\n return import('./client-routes.ts').then((module) => module.ready);\n}\n\n/**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Returns how the loader imports\n * the core.\n */\nfunction navigation({\n options,\n listen,\n core,\n start: startCore,\n scan,\n}: Navigation): () => Promise<Core> {\n const rpc = `${options.rpc ?? '/_brumate'}/`;\n const settings = typeof options.navigate === 'object' ? options.navigate : {};\n // The page without its hash, to tell a change of the hash from a change of the page.\n let page = String(location.href).split('#')[0];\n // True once the site changed since the page loaded: the next page loads in full, with new code.\n let skewed = false;\n listen(document, 'brumate:skew', () => {\n skewed = true;\n });\n // The core when the page reads a context of navigation, which it starts for them, or when it runs.\n function reader(key: string): Promise<Core> | undefined {\n const running = core();\n if (running) {\n return running;\n }\n for (const script of document.querySelectorAll('script[b-state]')) {\n if (script.textContent?.includes(key)) {\n return startCore();\n }\n }\n return undefined;\n }\n function state(value: { pending: boolean; from?: string; to?: string }): void {\n void reader(NAVIGATION_KEY)?.then((client) => client.setGlobal(NAVIGATION_KEY, value));\n }\n function go(\n url: string,\n init?: RequestInit,\n push = true,\n reload = false,\n scroll = true,\n ): Promise<void> {\n const from = location.href;\n if (skewed) {\n // A form post cannot be a full page load: the page loads again, and the form is lost with\n // the rest of the state of the page.\n if (init) {\n location.reload();\n } else {\n location.assign(url);\n }\n return Promise.resolve();\n }\n page = url.split('#')[0]!;\n if (core()) {\n void routes();\n }\n // CSS can show a progress bar while a page loads, with no client code in the page.\n document.documentElement.setAttribute('data-navigating', '');\n state({ pending: true, from, to: new URL(url, from).href });\n function done(): void {\n document.documentElement.removeAttribute('data-navigating');\n state({ pending: false });\n }\n return import('./navigate.ts')\n .then((module) =>\n module.navigate({\n url,\n init,\n push,\n reload,\n scroll,\n build: options.build,\n focus: settings.focus !== false,\n transition: settings.transition === true,\n // The core forgets the old page, or only stops reading, when layouts stay.\n leave: async (partial) => {\n if (core()) {\n (await routes())(partial);\n }\n },\n enter: () => {\n // The core took the serial entry when it started.\n void core()?.then((client) =>\n client.init({ ...options, serial: undefined, listen: scan }),\n );\n // Code that reads the route, such as in a layout that stays, gets the new one.\n void reader(ROUTE_KEY)?.then((client) => client.updateRoute());\n page = location.href.split('#')[0]!;\n },\n }),\n )\n .finally(done);\n }\n // `navigate(href, options)` from `brumate/routes`.\n listen(document, 'brumate:navigate', (event) => {\n const detail = (\n event as CustomEvent<{ url: string; replace: boolean; scroll: boolean; done: () => void }>\n ).detail;\n event.preventDefault();\n void go(detail.url, undefined, !detail.replace, false, detail.scroll).then(detail.done);\n });\n // A link to another page of this site, which the loader loads itself.\n function pageLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n const link = (target as Element | null)?.closest?.('a[href]') as HTMLAnchorElement | null;\n return link &&\n !link.target &&\n !link.matches('[download],[data-reload]') &&\n link.origin === location.origin &&\n // A link to a place in the same page scrolls there.\n !(link.hash && link.href.split('#')[0] === page)\n ? link\n : undefined;\n }\n listen(document, 'click', (event) => {\n const mouse = event as MouseEvent;\n const link = pageLink(event.target);\n if (\n !link ||\n event.defaultPrevented ||\n mouse.button ||\n mouse.metaKey ||\n mouse.ctrlKey ||\n mouse.shiftKey ||\n mouse.altKey\n ) {\n return;\n }\n event.preventDefault();\n void go(link.href);\n });\n // A page loads when the pointer rests on its link, or the link gets focus, so a click finds it loading.\n let resting: ReturnType<typeof setTimeout> | undefined;\n listen(\n document,\n 'pointerover',\n (event) => {\n const link = pageLink(event.target);\n if (link) {\n clearTimeout(resting);\n resting = setTimeout(() => prefetch(link), 80);\n }\n },\n { passive: true },\n );\n listen(document, 'pointerout', () => clearTimeout(resting), { passive: true });\n listen(document, 'focusin', (event) => prefetch(pageLink(event.target)));\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n const submitter = (event as SubmitEvent).submitter;\n const action = submitter?.getAttribute('formaction') ?? form.getAttribute('action') ?? '';\n const method = submitter?.getAttribute('formmethod') ?? form.getAttribute('method');\n if (\n event.defaultPrevented ||\n method?.toLowerCase() !== 'post' ||\n !action.startsWith(rpc) ||\n // After a deploy, the browser posts the form itself, and the page that answers is new.\n skewed\n ) {\n return;\n }\n event.preventDefault();\n void go(action, { method: 'POST', body: new FormData(form, submitter) });\n });\n // A server function that redirects, from `rpc.ts`. Another site loads in full.\n listen(document, 'brumate:redirect', (event) => {\n const url = new URL((event as CustomEvent<string>).detail, location.href);\n if (url.origin === location.origin) {\n event.preventDefault();\n void go(url.href, undefined, true, true);\n }\n });\n // A hot update whose markup changed loads the page again, in place. With `init`, the whole\n // page is replaced, as for a form, so layouts render again too, and it keeps the scroll.\n listen(document, 'brumate:reload', () => void go(location.href, { method: 'GET' }, false));\n listen(window, 'popstate', () => {\n // A change of the hash only stays on the page.\n if (location.href.split('#')[0] !== page) {\n void go(location.href, undefined, false);\n }\n });\n return () =>\n Promise.all([importCore(), document.querySelector('[b-offset],[b-roots]') && routes()]).then(\n ([client]) => client,\n );\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,MAAM,SAAoC;CACxD,OAAO,KAAK,SAAS,QAAQ,aAAa,QAAQ,KAAA,IAAY,UAAU;AAC1E;;AAGA,SAAS,SAAS,MAA2C;CAC3D,IAAI,QAAQ,KAAK,aAAa,eAAe,MAAM,QACjD,OAAY,yBAAgB,CAAC,MAAM,WAAW,OAAO,SAAS,KAAK,IAAI,CAAC;AAE5E;;;;;;;AAQA,SAAS,SAAmC;CAC1C,OAAO,OAAO,8BAAqB,CAAC,MAAM,WAAW,OAAO,KAAK;AACnE;;;;;;;AAQA,SAAS,WAAW,EAClB,SACA,QACA,MACA,OAAO,WACP,QACkC;CAClC,MAAM,MAAM,GAAG,QAAQ,OAAO,YAAY;CAC1C,MAAM,WAAW,OAAO,QAAQ,aAAa,WAAW,QAAQ,WAAW,CAAC;CAE5E,IAAI,OAAO,OAAO,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;CAE5C,IAAI,SAAS;CACb,OAAO,UAAU,sB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AAM,SAAS,WAAW,aAAa,YAAY,KAAK,KAAK,aAAa,QAAQ;EAClF,IACE,MAAM,oBACN,QAAQ,YAAY,MAAM,UAC1B,CAAC,OAAO,WAAW,GAAG,KAEtB,QAEA;EAEF,MAAM,eAAe;EACrB,GAAQ,QAAQ;GAAE,QAAQ;GAAQ,MAAM,IAAI,SAAS,MAAM,SAAS;EAAE,CAAC;CACzE,CAAC;CAED,OAAO,UAAU,qBAAqB,UAAU;EAC9C,MAAM,MAAM,IAAI,IAAK,MAA8B,QAAQ,SAAS,IAAI;EACxE,IAAI,IAAI,WAAW,SAAS,QAAQ;GAClC,MAAM,eAAe;GACrB,GAAQ,IAAI,MAAM,KAAA,GAAW,MAAM,IAAI;EACzC;CACF,CAAC;CAGD,OAAO,UAAU,wBAAwB,KAAK,GAAG,SAAS,MAAM,EAAE,QAAQ,MAAM,GAAG,KAAK,CAAC;CACzF,OAAO,QAAQ,kBAAkB;EAE/B,IAAI,SAAS,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,MAClC,GAAQ,SAAS,MAAM,KAAA,GAAW,KAAK;CAE3C,CAAC;CACD,aACE,QAAQ,IAAI,CAAC,WAAW,GAAG,SAAS,cAAc,sBAAsB,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,MACrF,CAAC,YAAY,MAChB;AACJ"}
|
|
1
|
+
{"version":3,"file":"loader-CheV6t0N.js","names":[],"sources":["../src/runtime/loader.ts"],"sourcesContent":["import type * as Routes from './client-routes.ts';\nimport { boot, importCore } from './boot.ts';\nimport { NAVIGATION_KEY, ROUTE_KEY } from './context.ts';\nimport type { Core, LoaderOptions, Navigation } from './boot.ts';\n\nexport type { LoaderOptions, NavigateOptions } from './boot.ts';\nexport { startWithoutNavigation } from './static-loader.ts';\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function start(options: LoaderOptions): () => void {\n return boot(options, options.navigate === false ? undefined : navigation);\n}\n\n/** Starts loading the page of a link, unless the link asks not to. */\nfunction prefetch(link: HTMLAnchorElement | undefined): void {\n if (link && link.getAttribute('data-prefetch') !== 'none') {\n void import('./navigate.ts').then((module) => module.prefetch(link.href));\n }\n}\n\n/**\n * Imports the code with which the core reads the pages that navigation adds.\n * A core that runs loads it when the loader navigates. A core that starts\n * later loads it with the core, when the page has records that navigation\n * marked.\n */\nfunction routes(): (typeof Routes)['ready'] {\n return import('./client-routes.ts').then((module) => module.ready);\n}\n\n/**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Returns how the loader imports\n * the core.\n */\nfunction navigation({\n options,\n listen,\n core,\n start: startCore,\n scan,\n}: Navigation): () => Promise<Core> {\n const rpc = `${options.rpc ?? '/_brumate'}/`;\n const settings = typeof options.navigate === 'object' ? options.navigate : {};\n // The page without its hash, to tell a change of the hash from a change of the page.\n let page = String(location.href).split('#')[0];\n // True once the site changed since the page loaded: the next page loads in full, with new code.\n let skewed = false;\n listen(document, 'brumate:skew', () => {\n skewed = true;\n });\n // The core when the page reads a context of navigation, which it starts for them, or when it runs.\n function reader(key: string): Promise<Core> | undefined {\n const running = core();\n if (running) {\n return running;\n }\n for (const script of document.querySelectorAll('script[b-state]')) {\n if (script.textContent?.includes(key)) {\n return startCore();\n }\n }\n return undefined;\n }\n function state(value: { pending: boolean; from?: string; to?: string }): void {\n void reader(NAVIGATION_KEY)?.then((client) => client.setGlobal(NAVIGATION_KEY, value));\n }\n function go(\n url: string,\n init?: RequestInit,\n push = true,\n reload = false,\n scroll = true,\n ): Promise<void> {\n const from = location.href;\n if (skewed) {\n // A form post cannot be a full page load: the page loads again, and the form is lost with\n // the rest of the state of the page.\n if (init) {\n location.reload();\n } else {\n location.assign(url);\n }\n return Promise.resolve();\n }\n page = url.split('#')[0]!;\n if (core()) {\n void routes();\n }\n // CSS can show a progress bar while a page loads, with no client code in the page.\n document.documentElement.setAttribute('data-navigating', '');\n state({ pending: true, from, to: new URL(url, from).href });\n function done(): void {\n document.documentElement.removeAttribute('data-navigating');\n state({ pending: false });\n }\n return import('./navigate.ts')\n .then((module) =>\n module.navigate({\n url,\n init,\n push,\n reload,\n scroll,\n build: options.build,\n focus: settings.focus !== false,\n transition: settings.transition === true,\n // The core forgets the old page, or only stops reading, when layouts stay.\n leave: async (partial) => {\n if (core()) {\n (await routes())(partial);\n }\n },\n enter: () => {\n // The core took the serial entry when it started.\n void core()?.then((client) =>\n client.init({ ...options, serial: undefined, listen: scan }),\n );\n // Code that reads the route, such as in a layout that stays, gets the new one.\n void reader(ROUTE_KEY)?.then((client) => client.updateRoute());\n page = location.href.split('#')[0]!;\n },\n }),\n )\n .finally(done);\n }\n // `navigate(href, options)` from `brumate/routes`.\n listen(document, 'brumate:navigate', (event) => {\n const detail = (\n event as CustomEvent<{ url: string; replace: boolean; scroll: boolean; done: () => void }>\n ).detail;\n event.preventDefault();\n void go(detail.url, undefined, !detail.replace, false, detail.scroll).then(detail.done);\n });\n // A link to another page of this site, which the loader loads itself.\n function pageLink(target: EventTarget | null): HTMLAnchorElement | undefined {\n const link = (target as Element | null)?.closest?.('a[href]') as HTMLAnchorElement | null;\n return link &&\n !link.target &&\n !link.matches('[download],[data-reload]') &&\n link.origin === location.origin &&\n // A link to a place in the same page scrolls there.\n !(link.hash && link.href.split('#')[0] === page)\n ? link\n : undefined;\n }\n listen(document, 'click', (event) => {\n const mouse = event as MouseEvent;\n const link = pageLink(event.target);\n if (\n !link ||\n event.defaultPrevented ||\n mouse.button ||\n mouse.metaKey ||\n mouse.ctrlKey ||\n mouse.shiftKey ||\n mouse.altKey\n ) {\n return;\n }\n event.preventDefault();\n void go(link.href);\n });\n // A page loads when the pointer rests on its link, or the link gets focus, so a click finds it loading.\n let resting: ReturnType<typeof setTimeout> | undefined;\n listen(\n document,\n 'pointerover',\n (event) => {\n const link = pageLink(event.target);\n if (link) {\n clearTimeout(resting);\n resting = setTimeout(() => prefetch(link), 80);\n }\n },\n { passive: true },\n );\n listen(document, 'pointerout', () => clearTimeout(resting), { passive: true });\n listen(document, 'focusin', (event) => prefetch(pageLink(event.target)));\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n const submitter = (event as SubmitEvent).submitter;\n const action = submitter?.getAttribute('formaction') ?? form.getAttribute('action') ?? '';\n const method = submitter?.getAttribute('formmethod') ?? form.getAttribute('method');\n if (\n event.defaultPrevented ||\n method?.toLowerCase() !== 'post' ||\n !action.startsWith(rpc) ||\n // After a deploy, the browser posts the form itself, and the page that answers is new.\n skewed\n ) {\n return;\n }\n event.preventDefault();\n void go(action, { method: 'POST', body: new FormData(form, submitter) });\n });\n // A server function that redirects, from `rpc.ts`. Another site loads in full.\n listen(document, 'brumate:redirect', (event) => {\n const url = new URL((event as CustomEvent<string>).detail, location.href);\n if (url.origin === location.origin) {\n event.preventDefault();\n void go(url.href, undefined, true, true);\n }\n });\n // A hot update whose markup changed loads the page again, in place. With `init`, the whole\n // page is replaced, as for a form, so layouts render again too, and it keeps the scroll.\n listen(document, 'brumate:reload', () => void go(location.href, { method: 'GET' }, false));\n listen(window, 'popstate', () => {\n // A change of the hash only stays on the page.\n if (location.href.split('#')[0] !== page) {\n void go(location.href, undefined, false);\n }\n });\n return () =>\n Promise.all([importCore(), document.querySelector('[b-offset],[b-roots]') && routes()]).then(\n ([client]) => client,\n );\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,MAAM,SAAoC;CACxD,OAAO,KAAK,SAAS,QAAQ,aAAa,QAAQ,KAAA,IAAY,UAAU;AAC1E;;AAGA,SAAS,SAAS,MAA2C;CAC3D,IAAI,QAAQ,KAAK,aAAa,eAAe,MAAM,QACjD,OAAY,yBAAgB,CAAC,MAAM,WAAW,OAAO,SAAS,KAAK,IAAI,CAAC;AAE5E;;;;;;;AAQA,SAAS,SAAmC;CAC1C,OAAO,OAAO,8BAAqB,CAAC,MAAM,WAAW,OAAO,KAAK;AACnE;;;;;;;AAQA,SAAS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as build, en as skew } from "./client-iZ9a1Nut.js";
|
|
3
3
|
import { toJSONAsync } from "seroval";
|
|
4
4
|
//#region src/runtime/rpc.ts
|
|
5
5
|
/**
|
|
@@ -146,4 +146,4 @@ function sendAction(form, submitter) {
|
|
|
146
146
|
//#endregion
|
|
147
147
|
export { call, sendAction };
|
|
148
148
|
|
|
149
|
-
//# sourceMappingURL=rpc-
|
|
149
|
+
//# sourceMappingURL=rpc-DvTwGfL_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc-Bxv7DYGe.js","names":[],"sources":["../src/runtime/rpc.ts"],"sourcesContent":["import { toJSONAsync } from 'seroval';\nimport { build, skew } from './client.ts';\nimport type { Scope } from './client.ts';\nimport { callPlugins, serialOptions } from './serial.ts';\nimport { fromChunkStream } from './stream.ts';\n\n/**\n * Calls a server function. It is a separate module, so pages that never call\n * one never load seroval's serializer.\n *\n * Files and blobs in the arguments, anywhere in them, go as parts of\n * multipart form data. `signal` aborts the call.\n */\nexport async function call(\n prefix: string,\n id: string,\n args: unknown[],\n signal?: AbortSignal,\n): Promise<unknown> {\n // The plugin of uploads takes each file and blob in the arguments, wherever it is.\n const files: Blob[] = [];\n const json = JSON.stringify(\n await toJSONAsync(args, { plugins: callPlugins(files), ...serialOptions() }),\n );\n let init: RequestInit;\n if (files.length > 0) {\n const form = new FormData();\n form.set('args', json);\n // A blob of another DOM is copied, because form data takes only its own.\n const copies: (Blob | Promise<Blob>)[] = [];\n for (const file of files) {\n // Typed as a Blob, so the check narrows a blob of another DOM to never.\n copies.push(\n file instanceof Blob\n ? file\n : (file as Blob)\n .arrayBuffer()\n .then((data) => new Blob([data], { type: (file as Blob).type })),\n );\n }\n const blobs = await Promise.all(copies);\n for (const [index, blob] of blobs.entries()) {\n form.set(`file${index}`, blob, (files[index] as Partial<File>).name ?? 'blob');\n }\n init = { headers: { 'x-brumate-args': 'form' }, body: form };\n } else {\n init = { headers: { 'content-type': 'application/json' }, body: json };\n }\n return post(prefix, id, { ...init, signal });\n}\n\n/**\n * Sends a form to a server function, and returns its result. The form data\n * goes as it is, files included, as when the browser posts the form.\n */\nexport async function submit(\n prefix: string,\n id: string,\n form: FormData,\n key?: string | null,\n): Promise<unknown> {\n return post(prefix, id, { headers: { 'x-brumate-result': '1' }, body: form }, key);\n}\n\n/** Posts to a server function, and reads its answer. */\nasync function post(\n prefix: string,\n id: string,\n init: RequestInit,\n key?: string | null,\n): Promise<unknown> {\n const headers = new Headers(init.headers);\n // The build of the page, so the server can tell a call from before a deploy.\n if (build !== undefined) {\n headers.set('x-brumate-build', build);\n }\n // The key of a form of a function that `idempotent` made.\n const query = key ? `?__key=${encodeURIComponent(key)}` : '';\n return answer(\n id,\n await fetch(`${prefix}/${encodeURIComponent(id)}${query}`, {\n ...init,\n headers,\n method: 'POST',\n }),\n );\n}\n\n/** Reads the answer of a server function: its result, a redirect or an error. */\nasync function answer(id: string, response: Response): Promise<unknown> {\n // The server functions whose memos load again, from `refresh` on the server.\n const refreshed = response.headers.get('x-brumate-refresh');\n if (refreshed) {\n const ids = refreshed.split(',');\n void refreshMemos(ids);\n document.dispatchEvent(new CustomEvent('brumate:refresh', { detail: ids }));\n }\n const location = response.headers.get('x-brumate-redirect');\n if (location !== null) {\n // The loader navigates on the client when it can. Without client navigation, the page loads in full.\n const redirect = new CustomEvent('brumate:redirect', { detail: location, cancelable: true });\n if (document.dispatchEvent(redirect)) {\n window.location.assign(location);\n }\n // The page is leaving, so the call never settles.\n return new Promise(() => {});\n }\n if (!response.ok) {\n // The site changed, and this page is from before. The next page loads in full.\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n skew('call');\n }\n let message = `Server function \"${id}\" failed with status ${response.status}`;\n try {\n message = ((await response.json()) as { error: string }).error;\n } catch {\n // The body is not the error of a server function.\n }\n const retryAfter = Number(response.headers.get('retry-after'));\n throw Object.assign(new Error(message), {\n name: 'ServerError',\n status: response.status,\n // The seconds to wait, for a call that a rate limit refused.\n ...(retryAfter > 0 ? { retryAfter } : {}),\n });\n }\n // Promises and async iterables in the result settle as the rest of the answer arrives.\n return fromChunkStream(response.body!);\n}\n\n// The code below reads the core with `import()`, not a static import: a module that imports\n// the core statically would make the package build move the core into a chunk of its own, behind\n// a module that only re-exports it, which a page loads one after the other. The core is loaded\n// already when it runs, so the import costs no request. It names the exports it uses, so a build\n// keeps only them.\n\n/**\n * Loads again the memos that call these server functions, after a server\n * function named them with `refresh`. Each component on the page knows its\n * own memos, from its client module. It is here, and not in the core, because\n * only the answer of a server call starts it.\n */\nexport function refreshMemos(ids: string[]): Promise<void> {\n return import('./client.ts').then(({ descendants, loadModule, loadPart, scopes }) => {\n for (const root of scopes.values()) {\n if (!root.m) {\n continue;\n }\n void loadModule(root.m).then(async (module) => {\n const entries: NonNullable<typeof module.refresh>[string] = [];\n for (const id of ids) {\n entries.push(...(module.refresh?.[id] ?? []));\n }\n if (entries.length === 0) {\n return;\n }\n const updates = await loadPart(module, 'update');\n for (const [kind, name] of entries) {\n for (const target of kind === root.k ? [root] : descendants(root, kind)) {\n if (scopes.has(target.id)) {\n (updates[name] as (scope: Scope) => void)(target);\n }\n }\n }\n });\n }\n });\n}\n\n/** Gives a form a new key in its URL, for its next post. */\nfunction renewKey(form: HTMLFormElement, url: URL): void {\n url.searchParams.set('__key', crypto.randomUUID());\n form.setAttribute('action', `${url.pathname}${url.search}`);\n}\n\n/**\n * Sends a form to the server function of its `$action`, and writes the\n * result into the `$action` when it arrives. It is pending until then. See\n * `submitAction` in the core.\n */\nexport function sendAction(form: HTMLFormElement, submitter: HTMLElement | null): Promise<void> {\n const [scopeText, slotText] = form.getAttribute('b-result')!.split(':') as [string, string];\n const scopeId = Number(scopeText);\n const slot = Number(slotText);\n const data = new FormData(form, submitter);\n const action = form.getAttribute('b-action')!;\n return import('./client.ts').then(({ asyncMemo, rpcPrefix, scopes, track }) => {\n const scope = scopes.get(scopeId);\n if (scope) {\n // A form of a function that `idempotent` made sends its key, and gets a new one once the\n // server answered, so a post that the user means again runs again.\n const url = new URL(form.getAttribute('action') ?? '', location.href);\n const key = url.searchParams.get('__key');\n const result = submit(rpcPrefix, action, data, key);\n if (key) {\n void result.then(\n () => renewKey(form, url),\n () => {},\n );\n }\n const answered = result.catch((error: unknown) => {\n // The site changed since the page loaded. The form posts again without scripts, and the\n // page that answers is of the new build.\n if ((error as { status?: number }).status === 409 && build !== undefined) {\n form.submit();\n return new Promise(() => {});\n }\n throw error;\n });\n asyncMemo(scope, slot, track(answered));\n }\n });\n}\n"],"mappings":";;;;;;;;;;;AAaA,eAAsB,KACpB,QACA,IACA,MACA,QACkB;CAElB,MAAM,QAAgB,CAAC;CACvB,MAAM,OAAO,KAAK,UAChB,MAAM,YAAY,MAAM;EAAE,SAAS,YAAY,KAAK;EAAG,GAAG,cAAc;CAAE,CAAC,CAC7E;CACA,IAAI;CACJ,IAAI,MAAM,SAAS,GAAG;EACpB,MAAM,OAAO,IAAI,SAAS;EAC1B,KAAK,IAAI,QAAQ,IAAI;EAErB,MAAM,SAAmC,CAAC;EAC1C,KAAK,MAAM,QAAQ,OAEjB,OAAO,KACL,gBAAgB,OACZ,OACC,KACE,YAAY,CAAC,CACb,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAO,KAAc,KAAK,CAAC,CAAC,CACvE;EAEF,MAAM,QAAQ,MAAM,QAAQ,IAAI,MAAM;EACtC,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GACxC,KAAK,IAAI,OAAO,SAAS,MAAO,MAAM,MAAM,CAAmB,QAAQ,MAAM;EAE/E,OAAO;GAAE,SAAS,EAAE,kBAAkB,OAAO;GAAG,MAAM;EAAK;CAC7D,OACE,OAAO;EAAE,SAAS,EAAE,gBAAgB,mBAAmB;EAAG,MAAM;CAAK;CAEvE,OAAO,KAAK,QAAQ,IAAI;EAAE,GAAG;EAAM;CAAO,CAAC;AAC7C;;;;;AAMA,eAAsB,OACpB,QACA,IACA,MACA,KACkB;CAClB,OAAO,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AM,QAAQ,OAAO,IAAI,OAAO;EAChC,IAAI,OAAO;GAGT,MAAM,MAAM,IAAI,IAAI,KAAK,aAAa,QAAQ,KAAK,IAAI,SAAS,IAAI;GACpE,MAAM,MAAM,IAAI,aAAa,IAAI,OAAO;GACxC,MAAM,SAAS,OAAO,WAAW,QAAQ,MAAM,GAAG;GAClD,IAAI,KACF,OAAY,WACJ,SAAS,MAAM,GAAG,SAClB,CAAC,CACT;GAEF,MAAM,WAAW,OAAO,OAAO,UAAmB;IAGhD,IAAK,MAA8B,WAAW,OAAO,UAAU,KAAA,GAAW;KACxE,KAAK,OAAO;KACZ,OAAO,IAAI,cAAc,CAAC,CAAC;IAC7B;IACA,MAAM;GACR,CAAC;GACD,UAAU,OAAO,MAAM,MAAM,QAAQ,CAAC;EACxC;CACF,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"rpc-DvTwGfL_.js","names":[],"sources":["../src/runtime/rpc.ts"],"sourcesContent":["import { toJSONAsync } from 'seroval';\nimport { build, skew } from './client.ts';\nimport type { Scope } from './client.ts';\nimport { callPlugins, serialOptions } from './serial.ts';\nimport { fromChunkStream } from './stream.ts';\n\n/**\n * Calls a server function. It is a separate module, so pages that never call\n * one never load seroval's serializer.\n *\n * Files and blobs in the arguments, anywhere in them, go as parts of\n * multipart form data. `signal` aborts the call.\n */\nexport async function call(\n prefix: string,\n id: string,\n args: unknown[],\n signal?: AbortSignal,\n): Promise<unknown> {\n // The plugin of uploads takes each file and blob in the arguments, wherever it is.\n const files: Blob[] = [];\n const json = JSON.stringify(\n await toJSONAsync(args, { plugins: callPlugins(files), ...serialOptions() }),\n );\n let init: RequestInit;\n if (files.length > 0) {\n const form = new FormData();\n form.set('args', json);\n // A blob of another DOM is copied, because form data takes only its own.\n const copies: (Blob | Promise<Blob>)[] = [];\n for (const file of files) {\n // Typed as a Blob, so the check narrows a blob of another DOM to never.\n copies.push(\n file instanceof Blob\n ? file\n : (file as Blob)\n .arrayBuffer()\n .then((data) => new Blob([data], { type: (file as Blob).type })),\n );\n }\n const blobs = await Promise.all(copies);\n for (const [index, blob] of blobs.entries()) {\n form.set(`file${index}`, blob, (files[index] as Partial<File>).name ?? 'blob');\n }\n init = { headers: { 'x-brumate-args': 'form' }, body: form };\n } else {\n init = { headers: { 'content-type': 'application/json' }, body: json };\n }\n return post(prefix, id, { ...init, signal });\n}\n\n/**\n * Sends a form to a server function, and returns its result. The form data\n * goes as it is, files included, as when the browser posts the form.\n */\nexport async function submit(\n prefix: string,\n id: string,\n form: FormData,\n key?: string | null,\n): Promise<unknown> {\n return post(prefix, id, { headers: { 'x-brumate-result': '1' }, body: form }, key);\n}\n\n/** Posts to a server function, and reads its answer. */\nasync function post(\n prefix: string,\n id: string,\n init: RequestInit,\n key?: string | null,\n): Promise<unknown> {\n const headers = new Headers(init.headers);\n // The build of the page, so the server can tell a call from before a deploy.\n if (build !== undefined) {\n headers.set('x-brumate-build', build);\n }\n // The key of a form of a function that `idempotent` made.\n const query = key ? `?__key=${encodeURIComponent(key)}` : '';\n return answer(\n id,\n await fetch(`${prefix}/${encodeURIComponent(id)}${query}`, {\n ...init,\n headers,\n method: 'POST',\n }),\n );\n}\n\n/** Reads the answer of a server function: its result, a redirect or an error. */\nasync function answer(id: string, response: Response): Promise<unknown> {\n // The server functions whose memos load again, from `refresh` on the server.\n const refreshed = response.headers.get('x-brumate-refresh');\n if (refreshed) {\n const ids = refreshed.split(',');\n void refreshMemos(ids);\n document.dispatchEvent(new CustomEvent('brumate:refresh', { detail: ids }));\n }\n const location = response.headers.get('x-brumate-redirect');\n if (location !== null) {\n // The loader navigates on the client when it can. Without client navigation, the page loads in full.\n const redirect = new CustomEvent('brumate:redirect', { detail: location, cancelable: true });\n if (document.dispatchEvent(redirect)) {\n window.location.assign(location);\n }\n // The page is leaving, so the call never settles.\n return new Promise(() => {});\n }\n if (!response.ok) {\n // The site changed, and this page is from before. The next page loads in full.\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n skew('call');\n }\n let message = `Server function \"${id}\" failed with status ${response.status}`;\n try {\n message = ((await response.json()) as { error: string }).error;\n } catch {\n // The body is not the error of a server function.\n }\n const retryAfter = Number(response.headers.get('retry-after'));\n throw Object.assign(new Error(message), {\n name: 'ServerError',\n status: response.status,\n // The seconds to wait, for a call that a rate limit refused.\n ...(retryAfter > 0 ? { retryAfter } : {}),\n });\n }\n // Promises and async iterables in the result settle as the rest of the answer arrives.\n return fromChunkStream(response.body!);\n}\n\n// The code below reads the core with `import()`, not a static import: a module that imports\n// the core statically would make the package build move the core into a chunk of its own, behind\n// a module that only re-exports it, which a page loads one after the other. The core is loaded\n// already when it runs, so the import costs no request. It names the exports it uses, so a build\n// keeps only them.\n\n/**\n * Loads again the memos that call these server functions, after a server\n * function named them with `refresh`. Each component on the page knows its\n * own memos, from its client module. It is here, and not in the core, because\n * only the answer of a server call starts it.\n */\nexport function refreshMemos(ids: string[]): Promise<void> {\n return import('./client.ts').then(({ descendants, loadModule, loadPart, scopes }) => {\n for (const root of scopes.values()) {\n if (!root.m) {\n continue;\n }\n void loadModule(root.m).then(async (module) => {\n const entries: NonNullable<typeof module.refresh>[string] = [];\n for (const id of ids) {\n entries.push(...(module.refresh?.[id] ?? []));\n }\n if (entries.length === 0) {\n return;\n }\n const updates = await loadPart(module, 'update');\n for (const [kind, name] of entries) {\n for (const target of kind === root.k ? [root] : descendants(root, kind)) {\n if (scopes.has(target.id)) {\n (updates[name] as (scope: Scope) => void)(target);\n }\n }\n }\n });\n }\n });\n}\n\n/** Gives a form a new key in its URL, for its next post. */\nfunction renewKey(form: HTMLFormElement, url: URL): void {\n url.searchParams.set('__key', crypto.randomUUID());\n form.setAttribute('action', `${url.pathname}${url.search}`);\n}\n\n/**\n * Sends a form to the server function of its `$action`, and writes the\n * result into the `$action` when it arrives. It is pending until then. See\n * `submitAction` in the core.\n */\nexport function sendAction(form: HTMLFormElement, submitter: HTMLElement | null): Promise<void> {\n const [scopeText, slotText] = form.getAttribute('b-result')!.split(':') as [string, string];\n const scopeId = Number(scopeText);\n const slot = Number(slotText);\n const data = new FormData(form, submitter);\n const action = form.getAttribute('b-action')!;\n return import('./client.ts').then(({ asyncMemo, rpcPrefix, scopes, track }) => {\n const scope = scopes.get(scopeId);\n if (scope) {\n // A form of a function that `idempotent` made sends its key, and gets a new one once the\n // server answered, so a post that the user means again runs again.\n const url = new URL(form.getAttribute('action') ?? '', location.href);\n const key = url.searchParams.get('__key');\n const result = submit(rpcPrefix, action, data, key);\n if (key) {\n void result.then(\n () => renewKey(form, url),\n () => {},\n );\n }\n const answered = result.catch((error: unknown) => {\n // The site changed since the page loaded. The form posts again without scripts, and the\n // page that answers is of the new build.\n if ((error as { status?: number }).status === 409 && build !== undefined) {\n form.submit();\n return new Promise(() => {});\n }\n throw error;\n });\n asyncMemo(scope, slot, track(answered));\n }\n });\n}\n"],"mappings":";;;;;;;;;;;AAaA,eAAsB,KACpB,QACA,IACA,MACA,QACkB;CAElB,MAAM,QAAgB,CAAC;CACvB,MAAM,OAAO,KAAK,UAChB,MAAM,YAAY,MAAM;EAAE,SAAS,YAAY,KAAK;EAAG,GAAG,cAAc;CAAE,CAAC,CAC7E;CACA,IAAI;CACJ,IAAI,MAAM,SAAS,GAAG;EACpB,MAAM,OAAO,IAAI,SAAS;EAC1B,KAAK,IAAI,QAAQ,IAAI;EAErB,MAAM,SAAmC,CAAC;EAC1C,KAAK,MAAM,QAAQ,OAEjB,OAAO,KACL,gBAAgB,OACZ,OACC,KACE,YAAY,CAAC,CACb,MAAM,SAAS,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,MAAO,KAAc,KAAK,CAAC,CAAC,CACvE;EAEF,MAAM,QAAQ,MAAM,QAAQ,IAAI,MAAM;EACtC,KAAK,MAAM,CAAC,OAAO,SAAS,MAAM,QAAQ,GACxC,KAAK,IAAI,OAAO,SAAS,MAAO,MAAM,MAAM,CAAmB,QAAQ,MAAM;EAE/E,OAAO;GAAE,SAAS,EAAE,kBAAkB,OAAO;GAAG,MAAM;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,OAAO,SAAS;CAChC,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,OAAO,IAAI,SAAS,MAAM,SAAS;CACzC,MAAM,SAAS,KAAK,aAAa,UAAU;CAC3C,OAAO,OAAO,sBAAc,CAAC,MAAM,EAAE,WAAW,WAAW,QAAQ,YAAY;EAC7E,MAAM,QAAQ,OAAO,IAAI,OAAO;EAChC,IAAI,OAAO;GAGT,MAAM,MAAM,IAAI,IAAI,KAAK,aAAa,QAAQ,KAAK,IAAI,SAAS,IAAI;GACpE,MAAM,MAAM,IAAI,aAAa,IAAI,OAAO;GACxC,MAAM,SAAS,OAAO,WAAW,QAAQ,MAAM,GAAG;GAClD,IAAI,KACF,OAAY,WACJ,SAAS,MAAM,GAAG,SAClB,CAAC,CACT;GAEF,MAAM,WAAW,OAAO,OAAO,UAAmB;IAGhD,IAAK,MAA8B,WAAW,OAAO,UAAU,KAAA,GAAW;KACxE,KAAK,OAAO;KACZ,OAAO,IAAI,cAAc,CAAC,CAAC;IAC7B;IACA,MAAM;GACR,CAAC;GACD,UAAU,OAAO,MAAM,MAAM,QAAQ,CAAC;EACxC;CACF,CAAC;AACH"}
|
package/dist/runtime/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { E as vars, _ as mergeAttributes, a as attribute, c as classAttribute, i as affix, m as internal, u as escape, v as onAttribute, x as raw } from "../html-t1JpkODI.js";
|
|
2
2
|
import { S as unbind, t as produce, u as SCOPE_IDS } from "../produce-DS-dQaUX.js";
|
|
3
3
|
import { a as routeContext, i as navigationContext, r as createContext } from "../context-CTiSzQRc.js";
|
|
4
|
-
import { $ as dispose, $t as scopes, A as branchNodes, At as timed, B as putText, Bt as descendants, C as dynamicNodes, Ct as effect, D as setItem, Dt as pending, E as place, Et as memo, F as keep, Ft as children, G as setSpread, Gt as sink, H as setAttrText, Ht as makeId, I as keepText, It as insert, J as fill, Jt as nameComment, K as template, Kt as loadModule, L as listNodes, Lt as title, M as fillBranch, Mt as update, N as fillList, Nt as updated, O as setSlots, Ot as resolve, P as fillSettled, Pt as fail, Q as retag, Qt as rpcPrefix, R as markBlock, Rt as afterInsert, S as dynamic, St as cells, T as foreignNodes, Tt as isBound, U as setContent, Ut as removeScope, V as setAttr, Vt as getScope, W as setOn, Wt as setOwner, X as rekey, Xt as build, Y as offscreen, Yt as DEVTOOLS, Z as reset, Zt as hooks, _ as writeText, _t as updateContext, a as deferInBrowser, at as removeRoot, b as component, bt as binding, c as toList, ct as handlerProp, d as attr, dt as submitAction, en as skew, et as forget, f as attrs, ft as guess, g as text, gt as setGlobal, h as restRef, ht as provideValue, i as addStyle, it as remount, j as clone, jt as unreadMemo, k as appendText, kt as set, l as windowList, lt as rpc, m as portalTo, mt as consumeContext, n as addHead, nt as leavePage, o as setVar, ot as action, p as content, pt as track, q as branch, qt as loadPart, r as addPortal, rt as leaveRoutes, s as list, st as handle, t as loader, tt as init, u as windowStart, ut as spread, v as prop, vt as updateRoute, w as elementAt, wt as get, x as componentNodes, xt as bindings, y as spreadProps, yt as asyncMemo, z as nodes, zt as createScope } from "../client-
|
|
4
|
+
import { $ as dispose, $t as scopes, A as branchNodes, At as timed, B as putText, Bt as descendants, C as dynamicNodes, Ct as effect, D as setItem, Dt as pending, E as place, Et as memo, F as keep, Ft as children, G as setSpread, Gt as sink, H as setAttrText, Ht as makeId, I as keepText, It as insert, J as fill, Jt as nameComment, K as template, Kt as loadModule, L as listNodes, Lt as title, M as fillBranch, Mt as update, N as fillList, Nt as updated, O as setSlots, Ot as resolve, P as fillSettled, Pt as fail, Q as retag, Qt as rpcPrefix, R as markBlock, Rt as afterInsert, S as dynamic, St as cells, T as foreignNodes, Tt as isBound, U as setContent, Ut as removeScope, V as setAttr, Vt as getScope, W as setOn, Wt as setOwner, X as rekey, Xt as build, Y as offscreen, Yt as DEVTOOLS, Z as reset, Zt as hooks, _ as writeText, _t as updateContext, a as deferInBrowser, at as removeRoot, b as component, bt as binding, c as toList, ct as handlerProp, d as attr, dt as submitAction, en as skew, et as forget, f as attrs, ft as guess, g as text, gt as setGlobal, h as restRef, ht as provideValue, i as addStyle, it as remount, j as clone, jt as unreadMemo, k as appendText, kt as set, l as windowList, lt as rpc, m as portalTo, mt as consumeContext, n as addHead, nt as leavePage, o as setVar, ot as action, p as content, pt as track, q as branch, qt as loadPart, r as addPortal, rt as leaveRoutes, s as list, st as handle, t as loader, tt as init, u as windowStart, ut as spread, v as prop, vt as updateRoute, w as elementAt, wt as get, x as componentNodes, xt as bindings, y as spreadProps, yt as asyncMemo, z as nodes, zt as createScope } from "../client-iZ9a1Nut.js";
|
|
5
5
|
export { DEVTOOLS, action, addHead, addPortal, addStyle, affix, afterInsert, appendText, asyncMemo, attr, attribute, attrs, binding, bindings, branch, branchNodes, build, cells, children, classAttribute, clone, component, componentNodes, consumeContext, content, createContext, createScope, deferInBrowser, descendants, dispose, dynamic, dynamicNodes, effect, elementAt, escape, fail, fill, fillBranch, fillList, fillSettled, foreignNodes, forget, get, getScope, guess, handle, handlerProp, hooks, init, insert, internal, isBound, keep, keepText, leavePage, leaveRoutes, list, listNodes, loadModule, loadPart, loader, makeId, markBlock, memo, mergeAttributes, nameComment, navigationContext, nodes, offscreen, onAttribute, pending, place, portalTo, produce, prop, provideValue, putText, raw, rekey, remount, removeRoot, removeScope, reset, resolve, restRef, retag, routeContext, rpc, rpcPrefix, SCOPE_IDS as scopeIds, scopes, set, setAttr, setAttrText, setContent, setGlobal, setItem, setOn, setOwner, setSlots, setSpread, setVar, sink, skew, spread, spreadProps, submitAction, template, text, timed, title, toList, track, unbind, unreadMemo, update, updateContext, updateRoute, updated, vars, windowList, windowStart, writeText };
|
package/dist/runtime/devtools.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { t as LOGO } from "../logo-DQ_OYhBi.js";
|
|
2
|
-
import { a as scanBlocks, i as reportError, n as installDevtools, r as preview, t as findRootScope } from "../devtools-
|
|
2
|
+
import { a as scanBlocks, i as reportError, n as installDevtools, r as preview, t as findRootScope } from "../devtools-BJB_MMeL.js";
|
|
3
3
|
export { LOGO, findRootScope, installDevtools, preview, reportError, scanBlocks };
|
package/dist/runtime/loader.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as startWithoutNavigation } from "../static-loader-
|
|
2
|
-
import { t as start } from "../loader-
|
|
1
|
+
import { t as startWithoutNavigation } from "../static-loader-BLJYvTKc.js";
|
|
2
|
+
import { t as start } from "../loader-CheV6t0N.js";
|
|
3
3
|
export { start, startWithoutNavigation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
export { t as startWithoutNavigation } from "../static-loader-BLJYvTKc.js";
|
package/dist/runtime/testing.js
CHANGED
|
@@ -213,7 +213,7 @@ function boot(options, navigate) {
|
|
|
213
213
|
run(template, ref);
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
const done = import("./defer-
|
|
216
|
+
const done = import("./defer-DP7dMS2y.js").then((module) => module.loadDeferred(template));
|
|
217
217
|
if (DEV) devtools()?.defer?.(template, done);
|
|
218
218
|
};
|
|
219
219
|
const near = template.getAttribute("b-near");
|
|
@@ -310,4 +310,4 @@ function startWithoutNavigation(options) {
|
|
|
310
310
|
//#endregion
|
|
311
311
|
export { boot as n, importCore as r, startWithoutNavigation as t };
|
|
312
312
|
|
|
313
|
-
//# sourceMappingURL=static-loader-
|
|
313
|
+
//# sourceMappingURL=static-loader-BLJYvTKc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-loader-U_x-ctJI.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks, Part } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /**\n * Loads the bundle of a root component of the page, such as a route: the client modules of\n * the components that it can render, in one chunk. Undefined for a component that is not a\n * root.\n */\n loadBundle?: (id: string) => Promise<unknown> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules and parts that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n const partLoads = new Map<string, Promise<Part>>();\n const loadPart = (module: ClientModule, part: string): Promise<Part> => {\n const key = `${module.id}#${part}`;\n let promise = partLoads.get(key);\n if (!promise) {\n promise = module.load!(part);\n partLoads.set(key, promise);\n promise.catch(() => partLoads.delete(key));\n }\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, loadPart, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n if ((event.key === ' ' ? 'Space' : event.key) !== (plus > 0 ? key.slice(plus + 1) : key)) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref` (`b-b`), or that a component\n // forwards to its signal (`b-r`), or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const selector = `[b-b=\"${near}\"],[b-r=\"${near}\"]`;\n const next =\n (near && (root.querySelector(selector) ?? document.querySelector(selector))) || after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n // The bundles of the components in the state start with it, so the code of the page comes in\n // the same round trip as the core. The core asks for them again when it reads the state.\n const bundled = new Set<string>();\n const loadBundles = (): void => {\n for (const script of document.querySelectorAll('script[b-state]')) {\n for (const [, id] of script.textContent?.matchAll(/\\bm:\"([^\"]+)\"/g) ?? []) {\n if (!bundled.has(id!)) {\n bundled.add(id!);\n void options.loadBundle?.(id!)?.catch(() => {});\n }\n }\n }\n };\n if (options.loadBundle) {\n loadBundles();\n if (document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', loadBundles);\n }\n }\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IA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/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks, Part } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /**\n * Loads the bundle of a root component of the page, such as a route: the client modules of\n * the components that it can render, in one chunk. Undefined for a component that is not a\n * root.\n */\n loadBundle?: (id: string) => Promise<unknown> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules and parts that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n const partLoads = new Map<string, Promise<Part>>();\n const loadPart = (module: ClientModule, part: string): Promise<Part> => {\n const key = `${module.id}#${part}`;\n let promise = partLoads.get(key);\n if (!promise) {\n promise = module.load!(part);\n partLoads.set(key, promise);\n promise.catch(() => partLoads.delete(key));\n }\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, loadPart, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n if ((event.key === ' ' ? 'Space' : event.key) !== (plus > 0 ? key.slice(plus + 1) : key)) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref` (`b-b`), or that a component\n // forwards to its signal (`b-r`), or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const selector = `[b-b=\"${near}\"],[b-r=\"${near}\"]`;\n const next =\n (near && (root.querySelector(selector) ?? document.querySelector(selector))) || after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n // The bundles of the components in the state start with it, so the code of the page comes in\n // the same round trip as the core. The core asks for them again when it reads the state.\n const bundled = new Set<string>();\n const loadBundles = (): void => {\n for (const script of document.querySelectorAll('script[b-state]')) {\n for (const [, id] of script.textContent?.matchAll(/\\bm:\"([^\"]+)\"/g) ?? []) {\n if (!bundled.has(id!)) {\n bundled.add(id!);\n void options.loadBundle?.(id!)?.catch(() => {});\n }\n }\n }\n };\n if (options.loadBundle) {\n loadBundles();\n if (document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', loadBundles);\n }\n }\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AAgEA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ,aAAa,MAAM,KAAK;CAC9C,OAAQ,OAAO,IAAI,KAAK,KACtB,OACG,IACC,OACA,MACG,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CAAC,CACf,KAAK,UAAU;EACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;EACnC,MAAM,CAAC,MAAM,GAAG,aAAa,KAAK,MAAM,GAAG;EAC3C,OAAO;GAAE,KAAK;GAAO;GAAM;GAAW;EAAI;CAC5C,CAAC,CACL,CAAC,CACA,IAAI,KAAK;AAChB;;;;;AASA,IAAI;AACJ,MAAa,mBACV,gBAAgB,OAAO,sBAAc,CAAC,MACpC,WAAW,OAAO,SAClB,UAAmB;CAElB,cAAc,KAAA;CACd,MAAM;AACR,CACF;;AAGF,MAAM,QAAQ,QAA6B,OAAO,uBAAuB,WAAA,CAAY,EAAE;;;;;;;AAuBvF,SAAgB,KACd,SACA,UACY;CACZ,IAAI;CAIJ,IAAI,UAAU;;CAEd,MAAM,wBAAQ,IAAI,IAAqB;CACvC,MAAM,WAA2B,CAAC;CAClC,MAAM,UACJ,QACA,MACA,UACA,UACS;EACT,OAAO,iBAAiB,MAAM,UAAU,KAAK;EAC7C,SAAS,WAAW,OAAO,oBAAoB,MAAM,UAAU,KAAK,CAAC;CACvE;CAGA,IAAI,OAAO;CAIX,MAAM,0BAAU,IAAI,IAA+C;CACnE,MAAM,cAAc,OAAkD;EACpE,IAAI,QAAQ,IAAI,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ACrB,KAAK,MAAM,UAAU,SAAS,OAAO,CAAC,GACpC,OAAO;EAET,MAAW,MAAM,WAAW,OAAO,QAAQ,CAAC;CAC9C;AACF;;;;;;;;AC9iBA,SAAgB,uBAAuB,SAAoC;CACzE,OAAO,KAAK,OAAO;AACrB"}
|
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as analyzeProject, B as getLocation, C as isReactiveModule, E as originalPosition, I as parse, J as walk, M as importSource, N as importedComponents, O as entryClasses, P as resolveRelative, R as forEachNode, T as builtin, U as analyze, _ as functionId, a as scopeLabel, b as SHARED_QUERY, f as instanceScope, i as report, k as refreshedNames, n as formatReport, p as slotIndex, q as resolveMacros, s as compile, t as anchorLabel, v as getComponentName, w as resolveFromDisk, x as generateShared, y as hash } from "./inspect-
|
|
1
|
+
import { A as analyzeProject, B as getLocation, C as isReactiveModule, E as originalPosition, I as parse, J as walk, M as importSource, N as importedComponents, O as entryClasses, P as resolveRelative, R as forEachNode, T as builtin, U as analyze, _ as functionId, a as scopeLabel, b as SHARED_QUERY, f as instanceScope, i as report, k as refreshedNames, n as formatReport, p as slotIndex, q as resolveMacros, s as compile, t as anchorLabel, v as getComponentName, w as resolveFromDisk, x as generateShared, y as hash } from "./inspect-BLOdfj7o.js";
|
|
2
2
|
import { s as toNodeHeaders } from "./cookies-Cnbf4w-S.js";
|
|
3
3
|
import { t as LOGO } from "./logo-DQ_OYhBi.js";
|
|
4
|
-
import { _ as reachableFiles, a as findServerFiles, c as hasServerMiddleware, d as serverExports, f as serverModule, g as packageFileName, h as findPackages, i as findScripts, l as hasUseServer, m as findPackage, n as defaultExclude, o as findPackageServerFile, p as serverStubs, r as findFiles, u as isScriptFile, v as resolveComponentPackage } from "./files-
|
|
4
|
+
import { _ as reachableFiles, a as findServerFiles, c as hasServerMiddleware, d as serverExports, f as serverModule, g as packageFileName, h as findPackages, i as findScripts, l as hasUseServer, m as findPackage, n as defaultExclude, o as findPackageServerFile, p as serverStubs, r as findFiles, u as isScriptFile, v as resolveComponentPackage } from "./files-BZRjz9Mx.js";
|
|
5
5
|
import { parseSync } from "oxc-parser";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
package/package.json
CHANGED
|
@@ -324,6 +324,26 @@ https://brumate-docs.vercel.app/docs/errors#brm185
|
|
|
324
324
|
</div>
|
|
325
325
|
```
|
|
326
326
|
|
|
327
|
+
## BRM187: The {kind} {name} of {component} did not settle: it writes a value that it reads, and runs again without end. Wrap the read or the write in $untrack, or write only when the value changes
|
|
328
|
+
|
|
329
|
+
In the browser, an effect or an update writes a value that it reads, so each run schedules the next. Past 1000 rounds of effects, or 10000 rounds of updates, in one change, the page stops the loop and sends this error to the nearest `#try` in place of hanging the tab. A production build sends the short form `Update loop {scope}:{name} [BRM187]`.
|
|
330
|
+
|
|
331
|
+
https://brumate-docs.vercel.app/docs/errors#brm187
|
|
332
|
+
|
|
333
|
+
```brm fragment
|
|
334
|
+
<script>
|
|
335
|
+
import { $effect, $signal, $untrack } from 'brumate/signals';
|
|
336
|
+
|
|
337
|
+
let query = $signal('');
|
|
338
|
+
let saves = $signal(0);
|
|
339
|
+
|
|
340
|
+
$effect(() => {
|
|
341
|
+
void query;
|
|
342
|
+
$untrack(saves++);
|
|
343
|
+
});
|
|
344
|
+
</script>
|
|
345
|
+
```
|
|
346
|
+
|
|
327
347
|
## BRM023: Modifiers apply to elements. Put ":{modifier}" on the element that the component renders
|
|
328
348
|
|
|
329
349
|
An event modifier is on a component, which only passes the handler on.
|