@loadbare/app 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"assemble.d.ts","sourceRoot":"","sources":["../../build/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAwBH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA6M/C,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,8EAA8E;IAC9E,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,wBAAsB,QAAQ,CAAC,EAC7B,UAAU,EACV,KAAK,EACL,KAAK,GACN,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAsDtC"}
1
+ {"version":3,"file":"assemble.d.ts","sourceRoot":"","sources":["../../build/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAyBH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAkN/C,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,8EAA8E;IAC9E,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACvB;AAED,wBAAsB,QAAQ,CAAC,EAC7B,UAAU,EACV,KAAK,EACL,KAAK,GACN,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAsDtC"}
@@ -19,7 +19,7 @@
19
19
  import { readFile } from "node:fs/promises";
20
20
  import { addDefinitions, customElementTags, expandTree, } from "./expand.js";
21
21
  import { formatHtml } from "./format.js";
22
- import { ATTR_PAGE, ATTR_PAGE_TITLE, ATTR_QUERY, ATTR_REQUEST, ATTR_SHOW, ATTR_URL_LINK, ATTR_URL_PUSH, ATTR_URL_UNKNOWN, DEVELOPER_ATTRIBUTES, HUB_TAG_NAME, LB_RESERVED_PREFIX, } from "../core/lb-constants.js";
22
+ import { ATTR_PAGE, ATTR_PAGE_TITLE, ATTR_QUERY, ATTR_REQUEST, ATTR_SHOW, ATTR_URL_LINK, ATTR_URL_PUSH, ATTR_URL_UNKNOWN, DEVELOPER_ATTRIBUTES, HUB_TAG_NAME, LB_RESERVED_PREFIX, SHOW_NOT, } from "../core/lb-constants.js";
23
23
  import { isRowRequest } from "../core/lb-types.js";
24
24
  /**
25
25
  * The hub calls showModal() on the `<dialog>` carrying lb-url-unknown
@@ -91,6 +91,10 @@ function walkMarkup(node, scope, problems) {
91
91
  problems.push(`<${tag}> carries ${ATTR_SHOW}="${show}" with no row around it ` +
92
92
  `to take the value from`);
93
93
  }
94
+ else if (show === SHOW_NOT || show.startsWith(SHOW_NOT + SHOW_NOT)) {
95
+ problems.push(`<${tag}> carries ${ATTR_SHOW}="${show}"; write one ` +
96
+ `${SHOW_NOT} and then the column it reverses`);
97
+ }
94
98
  }
95
99
  walkMarkup(el, here, problems);
96
100
  // By tag name rather than by instanceof: template content belongs to a
@@ -1 +1 @@
1
- {"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../build/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,cAA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E,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CACpC,KAAM,EACN,GAAG,EAAE,CACH,QAAQ,SAAS,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAChF,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;AACzD,CAAC","sourcesContent":["/**\n * Assembling one document out of a chrome file and a set of pages.\n *\n * Every `.html` file in play — the chrome and each page — goes through the\n * same `expand()` (see build/expand.ts) against the same definitions: the\n * built-in widgets and whatever definitions were found in the caller's own\n * source tree. `expand()` only ever sees a fragment, so the chrome's own is\n * the text between its `<body>` tags; a page's is the whole file. A page's\n * expanded host is wrapped in `<template lb-page=\"<name>\">` and, together\n * with the chrome's own expanded body content, spliced back into the\n * chrome's `<body>`. The result is the one document a server has to serve\n * for every route — see docs/tutorials/000-getting-started.md and\n * docs/reference/builder.md.\n *\n * Every path here is a parameter, resolved once by build/locations.ts — this\n * module never reconstructs one of its own, and never reads a directory\n * looking for pages or widgets; it is handed exactly which files those are.\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport {\n addDefinitions,\n customElementTags,\n expandTree,\n type Definitions,\n} from \"./expand.js\";\nimport { formatHtml } from \"./format.js\";\nimport {\n ATTR_PAGE,\n ATTR_PAGE_TITLE,\n ATTR_QUERY,\n ATTR_REQUEST,\n ATTR_SHOW,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n DEVELOPER_ATTRIBUTES,\n HUB_TAG_NAME,\n LB_RESERVED_PREFIX,\n} from \"../core/lb-constants.js\";\nimport { isRowRequest } from \"../core/lb-types.js\";\nimport type { PageFile } from \"./locations.js\";\nimport type { OriginScan } from \"./origins.js\";\n\n/**\n * The hub calls showModal() on the `<dialog>` carrying lb-url-unknown\n * (hub/lb-hub.browser.ts), and looks for it inside itself, as it does for\n * everything else it acts on. A dialog elsewhere in the body would never open\n * and would say nothing about why.\n */\nfunction checkUnknownPageDialog(chromeFile: string, body: ParentNode): void {\n const el = body.querySelector(`[${ATTR_URL_UNKNOWN}]`);\n if (!el) return;\n if (!el.closest(HUB_TAG_NAME)) {\n throw new Error(\n `assemble: '${chromeFile}' declares ${ATTR_URL_UNKNOWN} outside ` +\n `<${HUB_TAG_NAME}>, where the hub cannot reach it`,\n );\n }\n}\n\n/**\n * Where the markup stands while the check walks it: inside some `lb-query`,\n * and whether there is a row there to take a value from. Inside a row\n * template there always is. Inside an `lb-query` outside one, there is when\n * the query is of kind `row`, which only the server knows.\n */\ninterface Scope {\n row: boolean | \"unknown\";\n}\n\n/**\n * The markup, checked once against the finished document rather than\n * discovered one console error at a time in a browser.\n *\n * Every rule here is a fact the markup states about itself. The developer\n * writes `lb-*` attributes in markup, and script never assigns them, which is\n * what makes checking the markup sound. See docs/reference/data-binding.md.\n *\n * A `<template>`'s children are walked in the scope that encloses the\n * template, because a row template's clones land in the element around it.\n */\nfunction walkMarkup(\n node: ParentNode,\n scope: Scope | null,\n problems: string[],\n): void {\n for (const el of node.children) {\n const tag = el.localName;\n let here = scope;\n if (el.hasAttribute(ATTR_QUERY)) here = { row: \"unknown\" };\n\n for (const { name } of el.attributes) {\n if (\n name.startsWith(LB_RESERVED_PREFIX) &&\n !(DEVELOPER_ATTRIBUTES as readonly string[]).includes(name)\n ) {\n problems.push(\n `<${tag}> carries ${name}, which is not an attribute a developer ` +\n `writes`,\n );\n }\n }\n\n const request = el.getAttribute(ATTR_REQUEST);\n if (\n request !== null &&\n request.startsWith(LB_RESERVED_PREFIX) &&\n !isRowRequest(request)\n ) {\n problems.push(\n `<${tag}> carries ${ATTR_REQUEST}=\"${request}\", which begins with ` +\n `'${LB_RESERVED_PREFIX}' but names no request Loadbare provides`,\n );\n }\n if (el.hasAttribute(ATTR_URL_LINK) && tag !== \"a\") {\n problems.push(`<${tag}> carries ${ATTR_URL_LINK}; it goes on an <a>`);\n }\n if (el.hasAttribute(ATTR_URL_PUSH) && request === null) {\n problems.push(\n `<${tag}> carries ${ATTR_URL_PUSH} and no ${ATTR_REQUEST}; it goes ` +\n `on an element with ${ATTR_REQUEST}`,\n );\n }\n if (el.hasAttribute(ATTR_URL_UNKNOWN) && tag !== \"dialog\") {\n problems.push(\n `<${tag}> carries ${ATTR_URL_UNKNOWN}; it goes on a <dialog>`,\n );\n }\n\n // Judged by the scope around the element, not one the element carries:\n // its condition is a column of the row around it. With no lb-query\n // around it at all, nothing ever lands on it, and the element never\n // shows.\n const show = el.getAttribute(ATTR_SHOW);\n if (show !== null) {\n if (tag === \"template\") {\n problems.push(\n `a <template> carries ${ATTR_SHOW}=\"${show}\"; write it on the ` +\n `element it shows, and Loadbare supplies the template`,\n );\n } else if (scope === null || scope.row === false) {\n problems.push(\n `<${tag}> carries ${ATTR_SHOW}=\"${show}\" with no row around it ` +\n `to take the value from`,\n );\n }\n }\n\n walkMarkup(el, here, problems);\n // By tag name rather than by instanceof: template content belongs to a\n // document with no window, so the constructor is not reachable from the\n // node.\n if (tag === \"template\") {\n const content = (el as HTMLTemplateElement).content;\n const isRowTemplate =\n scope !== null && !!el.parentElement?.closest(`[${ATTR_QUERY}]`);\n if (isRowTemplate) {\n for (const root of content.children) {\n if (root.hasAttribute(ATTR_SHOW)) {\n problems.push(\n `<${root.localName}> is a row template's root and carries ` +\n `${ATTR_SHOW}; a row that should not show is left out by ` +\n `the query`,\n );\n }\n }\n }\n walkMarkup(content, isRowTemplate ? { row: true } : here, problems);\n }\n }\n}\n\n/**\n * Ship every `lb-show` element already inside the template the hub keeps an\n * absent branch in, so nothing conditional shows until its value says so.\n * A page is in the document before its data arrives, and a value that has not\n * arrived is no value.\n *\n * Elements are collected before any is moved, and a wrapped element is still\n * reached once its outer one has gone into a template, because the references\n * are held.\n */\nfunction wrapShown(holder: HTMLTemplateElement): void {\n const doc = holder.ownerDocument;\n const shown: Element[] = [];\n const collect = (root: ParentNode): void => {\n shown.push(...root.querySelectorAll(`[${ATTR_SHOW}]`));\n for (const t of root.querySelectorAll(\"template\")) {\n collect((t as HTMLTemplateElement).content);\n }\n };\n collect(holder.content);\n for (const el of shown) {\n const parked = doc.createElement(\"template\");\n parked.setAttribute(ATTR_SHOW, el.getAttribute(ATTR_SHOW)!);\n el.replaceWith(parked);\n parked.content.append(el);\n }\n}\n\n/**\n * Expand one file's markup, naming the file if expansion refuses it.\n *\n * What comes back is the tree the browser will build, so every pass after\n * this reads and changes it in place, and it is serialized once, when it\n * ships.\n */\nfunction expandFile(\n file: string,\n source: string,\n defs: Definitions,\n): HTMLTemplateElement {\n try {\n return expandTree(source, defs);\n } catch (e) {\n throw new Error(`assemble: '${file}': ${(e as Error).message}`);\n }\n}\n\n/** Check one expanded fragment, and name the file if anything is wrong. */\nfunction checkMarkup(file: string, root: ParentNode): void {\n const problems: string[] = [];\n walkMarkup(root, null, problems);\n if (problems.length > 0) {\n throw new Error(`assemble: '${file}' markup:\\n ` + problems.join(`\\n `));\n }\n}\n\n/**\n * A page file's `<title>` names the page. It is lifted out, since a page is\n * a fragment inside `<main>` and a `<title>` belongs in a document's head,\n * and its text content is stamped on the page as ATTR_PAGE_TITLE.\n */\nfunction liftTitle(holder: HTMLTemplateElement): string | null {\n const title = holder.content.querySelector(\"title\");\n if (!title) return null;\n const text = title.textContent?.trim() ?? \"\";\n title.remove();\n return text;\n}\n\n/** An attribute value, escaped for a double-quoted attribute. */\nfunction attributeValue(text: string): string {\n return text.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n}\n\nexport interface AssembleOptions {\n chromeFile: string;\n pages: PageFile[];\n /** Every origin, already scanned, in cascade order — see build/origins.ts. */\n scans: OriginScan[];\n}\n\nexport interface Assembled {\n html: string;\n /** Every custom element tag left in the document once expansion is done. */\n usedTags: Set<string>;\n}\n\nexport async function assemble({\n chromeFile,\n pages,\n scans,\n}: AssembleOptions): Promise<Assembled> {\n // One layer per origin, in order, so a later origin's definition overrides\n // an earlier one's for the same tag. Each layer is checked for cycles as it\n // lands, against everything merged so far.\n let defs: Definitions = {};\n for (const scan of scans) {\n defs = await addDefinitions(defs, scan.definitions);\n }\n\n // Tags are collected from each tree as it goes by. What ships is these\n // trees and the chrome around its body, which is collected on its own.\n const usedTags = new Set<string>();\n const templates: string[] = [];\n for (const { name, file } of pages) {\n const authored = await readFile(file, \"utf-8\");\n const host = expandFile(file, authored, defs);\n const title = liftTitle(host);\n checkMarkup(file, host.content);\n wrapShown(host);\n customElementTags(host.content, usedTags);\n const titled =\n title === null ? \"\" : ` ${ATTR_PAGE_TITLE}=\"${attributeValue(title)}\"`;\n templates.push(\n `<template ${ATTR_PAGE}=\"${name}\"${titled}>${host.innerHTML}</template>`,\n );\n }\n\n let chromeSource: string;\n try {\n chromeSource = await readFile(chromeFile, \"utf-8\");\n } catch {\n throw new Error(`assemble: no chrome file at '${chromeFile}'`);\n }\n\n const body = /<body([^>]*)>([\\s\\S]*)<\\/body>/i.exec(chromeSource);\n if (!body) {\n throw new Error(\n `assemble: '${chromeFile}' has no <body>...</body> to expand`,\n );\n }\n const [whole, bodyAttrs, bodyContent] = body;\n const chromeBody = expandFile(chromeFile, bodyContent!, defs);\n checkUnknownPageDialog(chromeFile, chromeBody.content);\n checkMarkup(chromeFile, chromeBody.content);\n wrapShown(chromeBody);\n customElementTags(chromeBody.content, usedTags);\n customElementTags(chromeSource.replace(whole!, \"\"), usedTags);\n const withPages = chromeSource.replace(\n whole!,\n () =>\n `<body${bodyAttrs}>${chromeBody.innerHTML}\\n${templates.join(\"\\n\")}\\n</body>`,\n );\n\n return { html: await formatHtml(withPages), usedTags };\n}\n"]}
1
+ {"version":3,"file":"assemble.js","sourceRoot":"","sources":["../../build/assemble.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,cAAc,E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C,OAAO,CAAC,CAAC;IACvD,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAC5C,SAAS,CAAC,UAAU,CAAC,CAAC;IACtB,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChD,iBAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,KAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9D,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CACpC,KAAM,EACN,GAAG,EAAE,CACH,QAAQ,SAAS,IAAI,UAAU,CAAC,SAAS,KAAK,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAChF,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;AACzD,CAAC","sourcesContent":["/**\n * Assembling one document out of a chrome file and a set of pages.\n *\n * Every `.html` file in play — the chrome and each page — goes through the\n * same `expand()` (see build/expand.ts) against the same definitions: the\n * built-in widgets and whatever definitions were found in the caller's own\n * source tree. `expand()` only ever sees a fragment, so the chrome's own is\n * the text between its `<body>` tags; a page's is the whole file. A page's\n * expanded host is wrapped in `<template lb-page=\"<name>\">` and, together\n * with the chrome's own expanded body content, spliced back into the\n * chrome's `<body>`. The result is the one document a server has to serve\n * for every route — see docs/tutorials/000-getting-started.md and\n * docs/reference/builder.md.\n *\n * Every path here is a parameter, resolved once by build/locations.ts — this\n * module never reconstructs one of its own, and never reads a directory\n * looking for pages or widgets; it is handed exactly which files those are.\n */\n\nimport { readFile } from \"node:fs/promises\";\nimport {\n addDefinitions,\n customElementTags,\n expandTree,\n type Definitions,\n} from \"./expand.js\";\nimport { formatHtml } from \"./format.js\";\nimport {\n ATTR_PAGE,\n ATTR_PAGE_TITLE,\n ATTR_QUERY,\n ATTR_REQUEST,\n ATTR_SHOW,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n DEVELOPER_ATTRIBUTES,\n HUB_TAG_NAME,\n LB_RESERVED_PREFIX,\n SHOW_NOT,\n} from \"../core/lb-constants.js\";\nimport { isRowRequest } from \"../core/lb-types.js\";\nimport type { PageFile } from \"./locations.js\";\nimport type { OriginScan } from \"./origins.js\";\n\n/**\n * The hub calls showModal() on the `<dialog>` carrying lb-url-unknown\n * (hub/lb-hub.browser.ts), and looks for it inside itself, as it does for\n * everything else it acts on. A dialog elsewhere in the body would never open\n * and would say nothing about why.\n */\nfunction checkUnknownPageDialog(chromeFile: string, body: ParentNode): void {\n const el = body.querySelector(`[${ATTR_URL_UNKNOWN}]`);\n if (!el) return;\n if (!el.closest(HUB_TAG_NAME)) {\n throw new Error(\n `assemble: '${chromeFile}' declares ${ATTR_URL_UNKNOWN} outside ` +\n `<${HUB_TAG_NAME}>, where the hub cannot reach it`,\n );\n }\n}\n\n/**\n * Where the markup stands while the check walks it: inside some `lb-query`,\n * and whether there is a row there to take a value from. Inside a row\n * template there always is. Inside an `lb-query` outside one, there is when\n * the query is of kind `row`, which only the server knows.\n */\ninterface Scope {\n row: boolean | \"unknown\";\n}\n\n/**\n * The markup, checked once against the finished document rather than\n * discovered one console error at a time in a browser.\n *\n * Every rule here is a fact the markup states about itself. The developer\n * writes `lb-*` attributes in markup, and script never assigns them, which is\n * what makes checking the markup sound. See docs/reference/data-binding.md.\n *\n * A `<template>`'s children are walked in the scope that encloses the\n * template, because a row template's clones land in the element around it.\n */\nfunction walkMarkup(\n node: ParentNode,\n scope: Scope | null,\n problems: string[],\n): void {\n for (const el of node.children) {\n const tag = el.localName;\n let here = scope;\n if (el.hasAttribute(ATTR_QUERY)) here = { row: \"unknown\" };\n\n for (const { name } of el.attributes) {\n if (\n name.startsWith(LB_RESERVED_PREFIX) &&\n !(DEVELOPER_ATTRIBUTES as readonly string[]).includes(name)\n ) {\n problems.push(\n `<${tag}> carries ${name}, which is not an attribute a developer ` +\n `writes`,\n );\n }\n }\n\n const request = el.getAttribute(ATTR_REQUEST);\n if (\n request !== null &&\n request.startsWith(LB_RESERVED_PREFIX) &&\n !isRowRequest(request)\n ) {\n problems.push(\n `<${tag}> carries ${ATTR_REQUEST}=\"${request}\", which begins with ` +\n `'${LB_RESERVED_PREFIX}' but names no request Loadbare provides`,\n );\n }\n if (el.hasAttribute(ATTR_URL_LINK) && tag !== \"a\") {\n problems.push(`<${tag}> carries ${ATTR_URL_LINK}; it goes on an <a>`);\n }\n if (el.hasAttribute(ATTR_URL_PUSH) && request === null) {\n problems.push(\n `<${tag}> carries ${ATTR_URL_PUSH} and no ${ATTR_REQUEST}; it goes ` +\n `on an element with ${ATTR_REQUEST}`,\n );\n }\n if (el.hasAttribute(ATTR_URL_UNKNOWN) && tag !== \"dialog\") {\n problems.push(\n `<${tag}> carries ${ATTR_URL_UNKNOWN}; it goes on a <dialog>`,\n );\n }\n\n // Judged by the scope around the element, not one the element carries:\n // its condition is a column of the row around it. With no lb-query\n // around it at all, nothing ever lands on it, and the element never\n // shows.\n const show = el.getAttribute(ATTR_SHOW);\n if (show !== null) {\n if (tag === \"template\") {\n problems.push(\n `a <template> carries ${ATTR_SHOW}=\"${show}\"; write it on the ` +\n `element it shows, and Loadbare supplies the template`,\n );\n } else if (scope === null || scope.row === false) {\n problems.push(\n `<${tag}> carries ${ATTR_SHOW}=\"${show}\" with no row around it ` +\n `to take the value from`,\n );\n } else if (show === SHOW_NOT || show.startsWith(SHOW_NOT + SHOW_NOT)) {\n problems.push(\n `<${tag}> carries ${ATTR_SHOW}=\"${show}\"; write one ` +\n `${SHOW_NOT} and then the column it reverses`,\n );\n }\n }\n\n walkMarkup(el, here, problems);\n // By tag name rather than by instanceof: template content belongs to a\n // document with no window, so the constructor is not reachable from the\n // node.\n if (tag === \"template\") {\n const content = (el as HTMLTemplateElement).content;\n const isRowTemplate =\n scope !== null && !!el.parentElement?.closest(`[${ATTR_QUERY}]`);\n if (isRowTemplate) {\n for (const root of content.children) {\n if (root.hasAttribute(ATTR_SHOW)) {\n problems.push(\n `<${root.localName}> is a row template's root and carries ` +\n `${ATTR_SHOW}; a row that should not show is left out by ` +\n `the query`,\n );\n }\n }\n }\n walkMarkup(content, isRowTemplate ? { row: true } : here, problems);\n }\n }\n}\n\n/**\n * Ship every `lb-show` element already inside the template the hub keeps an\n * absent branch in, so nothing conditional shows until its value says so.\n * A page is in the document before its data arrives, and a value that has not\n * arrived is no value.\n *\n * Elements are collected before any is moved, and a wrapped element is still\n * reached once its outer one has gone into a template, because the references\n * are held.\n */\nfunction wrapShown(holder: HTMLTemplateElement): void {\n const doc = holder.ownerDocument;\n const shown: Element[] = [];\n const collect = (root: ParentNode): void => {\n shown.push(...root.querySelectorAll(`[${ATTR_SHOW}]`));\n for (const t of root.querySelectorAll(\"template\")) {\n collect((t as HTMLTemplateElement).content);\n }\n };\n collect(holder.content);\n for (const el of shown) {\n const parked = doc.createElement(\"template\");\n parked.setAttribute(ATTR_SHOW, el.getAttribute(ATTR_SHOW)!);\n el.replaceWith(parked);\n parked.content.append(el);\n }\n}\n\n/**\n * Expand one file's markup, naming the file if expansion refuses it.\n *\n * What comes back is the tree the browser will build, so every pass after\n * this reads and changes it in place, and it is serialized once, when it\n * ships.\n */\nfunction expandFile(\n file: string,\n source: string,\n defs: Definitions,\n): HTMLTemplateElement {\n try {\n return expandTree(source, defs);\n } catch (e) {\n throw new Error(`assemble: '${file}': ${(e as Error).message}`);\n }\n}\n\n/** Check one expanded fragment, and name the file if anything is wrong. */\nfunction checkMarkup(file: string, root: ParentNode): void {\n const problems: string[] = [];\n walkMarkup(root, null, problems);\n if (problems.length > 0) {\n throw new Error(`assemble: '${file}' markup:\\n ` + problems.join(`\\n `));\n }\n}\n\n/**\n * A page file's `<title>` names the page. It is lifted out, since a page is\n * a fragment inside `<main>` and a `<title>` belongs in a document's head,\n * and its text content is stamped on the page as ATTR_PAGE_TITLE.\n */\nfunction liftTitle(holder: HTMLTemplateElement): string | null {\n const title = holder.content.querySelector(\"title\");\n if (!title) return null;\n const text = title.textContent?.trim() ?? \"\";\n title.remove();\n return text;\n}\n\n/** An attribute value, escaped for a double-quoted attribute. */\nfunction attributeValue(text: string): string {\n return text.replace(/&/g, \"&amp;\").replace(/\"/g, \"&quot;\");\n}\n\nexport interface AssembleOptions {\n chromeFile: string;\n pages: PageFile[];\n /** Every origin, already scanned, in cascade order — see build/origins.ts. */\n scans: OriginScan[];\n}\n\nexport interface Assembled {\n html: string;\n /** Every custom element tag left in the document once expansion is done. */\n usedTags: Set<string>;\n}\n\nexport async function assemble({\n chromeFile,\n pages,\n scans,\n}: AssembleOptions): Promise<Assembled> {\n // One layer per origin, in order, so a later origin's definition overrides\n // an earlier one's for the same tag. Each layer is checked for cycles as it\n // lands, against everything merged so far.\n let defs: Definitions = {};\n for (const scan of scans) {\n defs = await addDefinitions(defs, scan.definitions);\n }\n\n // Tags are collected from each tree as it goes by. What ships is these\n // trees and the chrome around its body, which is collected on its own.\n const usedTags = new Set<string>();\n const templates: string[] = [];\n for (const { name, file } of pages) {\n const authored = await readFile(file, \"utf-8\");\n const host = expandFile(file, authored, defs);\n const title = liftTitle(host);\n checkMarkup(file, host.content);\n wrapShown(host);\n customElementTags(host.content, usedTags);\n const titled =\n title === null ? \"\" : ` ${ATTR_PAGE_TITLE}=\"${attributeValue(title)}\"`;\n templates.push(\n `<template ${ATTR_PAGE}=\"${name}\"${titled}>${host.innerHTML}</template>`,\n );\n }\n\n let chromeSource: string;\n try {\n chromeSource = await readFile(chromeFile, \"utf-8\");\n } catch {\n throw new Error(`assemble: no chrome file at '${chromeFile}'`);\n }\n\n const body = /<body([^>]*)>([\\s\\S]*)<\\/body>/i.exec(chromeSource);\n if (!body) {\n throw new Error(\n `assemble: '${chromeFile}' has no <body>...</body> to expand`,\n );\n }\n const [whole, bodyAttrs, bodyContent] = body;\n const chromeBody = expandFile(chromeFile, bodyContent!, defs);\n checkUnknownPageDialog(chromeFile, chromeBody.content);\n checkMarkup(chromeFile, chromeBody.content);\n wrapShown(chromeBody);\n customElementTags(chromeBody.content, usedTags);\n customElementTags(chromeSource.replace(whole!, \"\"), usedTags);\n const withPages = chromeSource.replace(\n whole!,\n () =>\n `<body${bodyAttrs}>${chromeBody.innerHTML}\\n${templates.join(\"\\n\")}\\n</body>`,\n );\n\n return { html: await formatHtml(withPages), usedTags };\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  export declare const ATTR_QUERY = "lb-query";
2
2
  export declare const ATTR_COLUMN = "lb-column";
3
3
  export declare const ATTR_SHOW = "lb-show";
4
+ export declare const SHOW_NOT = "!";
4
5
  export declare const ATTR_COLUMN_VALUE = "lb-column-value";
5
6
  export declare const ATTR_KEY_VALUE = "lb-key-value";
6
7
  export declare const ATTR_ROW_LIVE = "lb-row-live";
@@ -8,6 +9,7 @@ export declare const LIVE_ROW = "[lb-row-live]";
8
9
  export declare const ATTR_QUERY_ROW_COUNT = "lb-query-row-count";
9
10
  export declare const ATTR_REQUEST = "lb-request";
10
11
  export declare const LB_EVENT_NAME = "lb-request";
12
+ export declare const LB_DONE_EVENT_NAME = "lb-request-done";
11
13
  export declare const ATTR_REQUEST_PENDING = "lb-request-pending";
12
14
  export declare const ATTR_REQUEST_ERROR = "lb-request-error";
13
15
  export declare const LB_RESERVED_PREFIX = "lb-";
@@ -1 +1 @@
1
- {"version":3,"file":"lb-constants.d.ts","sourceRoot":"","sources":["../../core/lb-constants.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,aAAa,CAAC;AAKrC,eAAO,MAAM,WAAW,cAAc,CAAC;AAavC,eAAO,MAAM,SAAS,YAAY,CAAC;AAKnC,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AAKnD,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAM7C,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAI3C,eAAO,MAAM,QAAQ,kBAAuB,CAAC;AAK7C,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AAKzD,eAAO,MAAM,YAAY,eAAe,CAAC;AAIz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qBAAqB,QAAS,CAAC"}
@@ -25,6 +25,9 @@ export const ATTR_COLUMN = "lb-column";
25
25
  // branch in the document so the hub holds nothing. Landing reaches inside it,
26
26
  // so a branch that returns is already current; nothing else does.
27
27
  export const ATTR_SHOW = "lb-show";
28
+ // Written before the column in ATTR_SHOW, it reverses the condition:
29
+ // `lb-show="!chosen"` is present while `chosen` is null or false.
30
+ export const SHOW_NOT = "!";
28
31
  // Stamped by the hub on every element it sets from a column: the value it
29
32
  // set, so a stylesheet can select on it and a custom element that is not a
30
33
  // control can render it.
@@ -52,6 +55,11 @@ export const ATTR_REQUEST = "lb-request";
52
55
  // Every request travels as one bubbling event of this name, whoever issued
53
56
  // it, so an ancestor may stop it.
54
57
  export const LB_EVENT_NAME = "lb-request";
58
+ // The counterpart of LB_EVENT_NAME: raised on the element that committed,
59
+ // once what the request brought back has landed or the round trip has
60
+ // failed. It bubbles, so the element that cares about the outcome need not
61
+ // be the one that committed.
62
+ export const LB_DONE_EVENT_NAME = "lb-request-done";
55
63
  // Stamped on the element that issued a request while its round trip is in
56
64
  // flight, alongside aria-busy. A commit on an element carrying it is ignored.
57
65
  export const ATTR_REQUEST_PENDING = "lb-request-pending";
@@ -1 +1 @@
1
- {"version":3,"file":"lb-constants.js","sourceRoot":"","sources":["../../core/lb-constants.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2DAA2D;AAC3D,kCAAkC;AAElC,4EAA4E;AAC5E,wEAAwE;AACxE,uEAAuE;AACvE,2EAA2E;AAC3E,2BAA2B;AAE3B,wEAAwE;AACxE,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AAErC,wEAAwE;AACxE,2EAA2E;AAC3E,mCAAmC;AACnC,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AAEvC,4EAA4E;AAC5E,2EAA2E;AAC3E,4BAA4B;AAC5B,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2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AEX,qEAAqE;AACrE,iFAAiF;AACjF,uEAAuE;AACvE,4EAA4E;AAC5E,qEAAqE;AACrE,qCAAqC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,0EAA0E;AAC1E,wEAAwE;AACxE,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,0EAA0E;AAC1E,iEAAiE;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AAEjC,4EAA4E;AAC5E,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC","sourcesContent":["// Every Loadbare attribute name lives here. Nothing writes one as a string\n// literal — not a widget, not a page host, not a test. See\n// docs/reference/data-binding.md.\n\n// --- Landing (docs/reference/data-binding.md) ----------------------------\n// Everything is a query. The server answers every request with response\n// items, one per query, and each carries the query's kind and key. The\n// markup names a query and the columns it shows; it never repeats what the\n// server already declared.\n\n// Names the query whose rows land in an element's content. A nested one\n// begins a new query: what is inside it is that query's.\nexport const ATTR_QUERY = \"lb-query\";\n\n// The column an element shows, read from the nearest ancestor row. On a\n// control the hub sets its value, and gathers it back under this name when\n// the control's request is issued.\nexport const ATTR_COLUMN = \"lb-column\";\n\n// The column that decides whether an element is present: `null` and `false`\n// are off, and every other value is on. It reads from the nearest ancestor\n// row, as ATTR_COLUMN does.\n//\n// An element that is off is moved into a `<template>` carrying this attribute\n// and the same column, standing where the element stood, and moved back out\n// when the column turns on. The builder ships every such element already\n// inside its template. A developer writes this attribute on an element and\n// never on a template: the template form is Loadbare's, and holds the absent\n// branch in the document so the hub holds nothing. Landing reaches inside it,\n// so a branch that returns is already current; nothing else does.\nexport const ATTR_SHOW = \"lb-show\";\n\n// Stamped by the hub on every element it sets from a column: the value it\n// set, so a stylesheet can select on it and a custom element that is not a\n// control can render it.\nexport const ATTR_COLUMN_VALUE = \"lb-column-value\";\n\n// Stamped by the hub on each live row, and on an element a `row` lands on\n// itself: the row's key. The key column is the query's, declared by the\n// server and carried by every response item.\nexport const ATTR_KEY_VALUE = \"lb-key-value\";\n\n// Stamped by the hub on each live row, and on nothing else: the element it\n// cloned from a row template. A key alone does not say so, because an\n// element a `row` lands on carries one too, and a live row may name a query\n// of its own, so neither the key nor `lb-query` tells the two apart.\nexport const ATTR_ROW_LIVE = \"lb-row-live\";\n\n// Selects a live row. Anything that walks rows — reconciliation, gathering,\n// a custom element's own placement — finds them with this and nothing else.\nexport const LIVE_ROW = `[${ATTR_ROW_LIVE}]`;\n\n// Stamped by the hub on an element with a row template: how many live rows\n// it holds, so \"no members yet\" is a stylesheet rule rather than a\n// conditional in every widget.\nexport const ATTR_QUERY_ROW_COUNT = \"lb-query-row-count\";\n\n// --- Requests (docs/reference/data-binding.md) --------------------------\n// Names the request an element issues when it commits: a form on submit, a\n// control on change, anything else on click.\nexport const ATTR_REQUEST = \"lb-request\";\n\n// Every request travels as one bubbling event of this name, whoever issued\n// it, so an ancestor may stop it.\nexport const LB_EVENT_NAME = \"lb-request\";\n\n// Stamped on the element that issued a request while its round trip is in\n// flight, alongside aria-busy. A commit on an element carrying it is ignored.\nexport const ATTR_REQUEST_PENDING = \"lb-request-pending\";\n\n// Stamped on the element that issued a request when its round trip failed —\n// a non-2xx response, a thrown application error, or a timeout, all alike.\n// Cleared at the start of that element's next request.\nexport const ATTR_REQUEST_ERROR = \"lb-request-error\";\n\n// --- Reserved names ----------------------------------------------------\n// Loadbare owns every name beginning with this prefix: attribute names, the\n// values of its attributes, query names, request names, the column names of\n// its own queries, custom element names and event names. The server refuses\n// a page that declares a query or a request so named.\nexport const LB_RESERVED_PREFIX = \"lb-\";\n\n// The requests Loadbare provides. Each runs the page's crud declaration for\n// the request's query.\nexport const REQUEST_ROW_INSERT = \"lb-row-insert\";\nexport const REQUEST_ROW_UPDATE = \"lb-row-update\";\nexport const REQUEST_ROW_DELETE = \"lb-row-delete\";\n\nexport const LB_ROW_REQUESTS = [\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n REQUEST_ROW_DELETE,\n] as const;\n\n// --- Kinds --------------------------------------------------------------\nexport const KIND_ROW = \"row\";\nexport const KIND_ROWS = \"rows\";\n\n// --- The URL (docs/reference/chrome.md) ---------------------------------\n// The query the hub serves: one row, keyed by the path, whose other columns\n// are the query parms.\nexport const URL_QUERY = \"lb-url\";\nexport const URL_COLUMN_PATH = \"lb-path\";\nexport const URL_COLUMN_PAGE_LABEL = \"lb-page-label\";\nexport const URL_COLUMN_PAGE_UNKNOWN = \"lb-page-unknown\";\n\n// On an `<a>`: a plain primary click sets `lb-path` from the `href`.\nexport const ATTR_URL_LINK = \"lb-url-link\";\n\n// On an element with `lb-request`: its update of `lb-url` pushes a history\n// entry instead of replacing one.\nexport const ATTR_URL_PUSH = \"lb-url-push\";\n\n// On a `<dialog>`: the hub calls showModal() when `lb-page-unknown` is true.\nexport const ATTR_URL_UNKNOWN = \"lb-url-unknown\";\n\n// --- Build time (docs/reference/custom-elements.md) ---------------------\n// Marks the element in an element file whose children receive the rest of\n// the custom element's content. An attribute rather than an element because\n// HTML content models discard foreign elements inside <select> and <table>.\nexport const ATTR_EXP_SLOT = \"lb-exp-slot\";\n\n// One name in two positions. In an element file it marks a destination; on a\n// `<template>` in the custom element's content it names the destination\n// that template is for, and the template's content moves into it.\nexport const ATTR_EXP_TEMPLATE = \"lb-exp-template\";\n\n// A page ships as <template lb-page=\"<stub>\">.\nexport const ATTR_PAGE = \"lb-page\";\n\n// Stamped by the builder beside ATTR_PAGE: the text content of the page\n// file's `<title>`, which the builder removes.\nexport const ATTR_PAGE_TITLE = \"lb-page-title\";\n\n// The attributes a developer writes. The builder refuses any other `lb-`\n// attribute in markup: the rest are stamps, written by the hub or the\n// builder and never by hand or by script.\nexport const DEVELOPER_ATTRIBUTES = [\n ATTR_QUERY,\n ATTR_COLUMN,\n ATTR_SHOW,\n ATTR_REQUEST,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n] as const;\n\n// The hub's own tag. It is exempt from the rule every other LB-* tag\n// follows: expansion does not require it to have a definition (build/expand.ts),\n// and the client build does not require it to have a script of its own\n// (build/elements.ts) — it is the framework's live element, always present,\n// registered once by the package's main entry point, not a widget an\n// application discovers or declares.\nexport const HUB_TAG_NAME = \"lb-hub\";\n\n// --- Wire --------------------------------------------------------------\n// One path, one method: everything the hub asks of the server is a POST\n// below this path. The page's stub follows it, and the query string the\n// browser is showing rides after that verbatim, so `/accounts?acct=23` asks\n// as `POST /lb/accounts?acct=23` and the server always knows what URL the\n// browser is showing. Navigation is therefore the only GET an application\n// serves, which is what leaves the page name space unrestricted.\nexport const LB_ENDPOINT = \"/lb\";\n\n// A client-side deadline for one round trip. fetch() has no deadline of its\n// own; past this the request is aborted and treated as a failure.\nexport const LB_REQUEST_TIMEOUT_MS = 10_000;\n"]}
1
+ {"version":3,"file":"lb-constants.js","sourceRoot":"","sources":["../../core/lb-constants.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2DAA2D;AAC3D,kCAAkC;AAElC,4EAA4E;AAC5E,wEAAwE;AACxE,uEAAuE;AACvE,2EAA2E;AAC3E,2BAA2B;AAE3B,wEAAwE;AACxE,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AAErC,wEAAwE;AACxE,2EAA2E;AAC3E,mCAAmC;AACnC,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AAEvC,4EAA4E;AAC5E,2EAA2E;AAC3E,4BAA4B;AAC5B,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,8EAA8E;AAC9E,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;AAEnC,qEAAqE;AACrE,kEAAkE;AAClE,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAE5B,0EAA0E;AAC1E,2EAA2E;AAC3E,yBAAyB;AACzB,MAAM,C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AACvE,4EAA4E;AAC5E,qEAAqE;AACrE,qCAAqC;AACrC,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,0EAA0E;AAC1E,wEAAwE;AACxE,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,0EAA0E;AAC1E,iEAAiE;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AAEjC,4EAA4E;AAC5E,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC","sourcesContent":["// Every Loadbare attribute name lives here. Nothing writes one as a string\n// literal — not a widget, not a page host, not a test. See\n// docs/reference/data-binding.md.\n\n// --- Landing (docs/reference/data-binding.md) ----------------------------\n// Everything is a query. The server answers every request with response\n// items, one per query, and each carries the query's kind and key. The\n// markup names a query and the columns it shows; it never repeats what the\n// server already declared.\n\n// Names the query whose rows land in an element's content. A nested one\n// begins a new query: what is inside it is that query's.\nexport const ATTR_QUERY = \"lb-query\";\n\n// The column an element shows, read from the nearest ancestor row. On a\n// control the hub sets its value, and gathers it back under this name when\n// the control's request is issued.\nexport const ATTR_COLUMN = \"lb-column\";\n\n// The column that decides whether an element is present: `null` and `false`\n// are off, and every other value is on. It reads from the nearest ancestor\n// row, as ATTR_COLUMN does.\n//\n// An element that is off is moved into a `<template>` carrying this attribute\n// and the same column, standing where the element stood, and moved back out\n// when the column turns on. The builder ships every such element already\n// inside its template. A developer writes this attribute on an element and\n// never on a template: the template form is Loadbare's, and holds the absent\n// branch in the document so the hub holds nothing. Landing reaches inside it,\n// so a branch that returns is already current; nothing else does.\nexport const ATTR_SHOW = \"lb-show\";\n\n// Written before the column in ATTR_SHOW, it reverses the condition:\n// `lb-show=\"!chosen\"` is present while `chosen` is null or false.\nexport const SHOW_NOT = \"!\";\n\n// Stamped by the hub on every element it sets from a column: the value it\n// set, so a stylesheet can select on it and a custom element that is not a\n// control can render it.\nexport const ATTR_COLUMN_VALUE = \"lb-column-value\";\n\n// Stamped by the hub on each live row, and on an element a `row` lands on\n// itself: the row's key. The key column is the query's, declared by the\n// server and carried by every response item.\nexport const ATTR_KEY_VALUE = \"lb-key-value\";\n\n// Stamped by the hub on each live row, and on nothing else: the element it\n// cloned from a row template. A key alone does not say so, because an\n// element a `row` lands on carries one too, and a live row may name a query\n// of its own, so neither the key nor `lb-query` tells the two apart.\nexport const ATTR_ROW_LIVE = \"lb-row-live\";\n\n// Selects a live row. Anything that walks rows — reconciliation, gathering,\n// a custom element's own placement — finds them with this and nothing else.\nexport const LIVE_ROW = `[${ATTR_ROW_LIVE}]`;\n\n// Stamped by the hub on an element with a row template: how many live rows\n// it holds, so \"no members yet\" is a stylesheet rule rather than a\n// conditional in every widget.\nexport const ATTR_QUERY_ROW_COUNT = \"lb-query-row-count\";\n\n// --- Requests (docs/reference/data-binding.md) --------------------------\n// Names the request an element issues when it commits: a form on submit, a\n// control on change, anything else on click.\nexport const ATTR_REQUEST = \"lb-request\";\n\n// Every request travels as one bubbling event of this name, whoever issued\n// it, so an ancestor may stop it.\nexport const LB_EVENT_NAME = \"lb-request\";\n\n// The counterpart of LB_EVENT_NAME: raised on the element that committed,\n// once what the request brought back has landed or the round trip has\n// failed. It bubbles, so the element that cares about the outcome need not\n// be the one that committed.\nexport const LB_DONE_EVENT_NAME = \"lb-request-done\";\n\n// Stamped on the element that issued a request while its round trip is in\n// flight, alongside aria-busy. A commit on an element carrying it is ignored.\nexport const ATTR_REQUEST_PENDING = \"lb-request-pending\";\n\n// Stamped on the element that issued a request when its round trip failed —\n// a non-2xx response, a thrown application error, or a timeout, all alike.\n// Cleared at the start of that element's next request.\nexport const ATTR_REQUEST_ERROR = \"lb-request-error\";\n\n// --- Reserved names ----------------------------------------------------\n// Loadbare owns every name beginning with this prefix: attribute names, the\n// values of its attributes, query names, request names, the column names of\n// its own queries, custom element names and event names. The server refuses\n// a page that declares a query or a request so named.\nexport const LB_RESERVED_PREFIX = \"lb-\";\n\n// The requests Loadbare provides. Each runs the page's crud declaration for\n// the request's query.\nexport const REQUEST_ROW_INSERT = \"lb-row-insert\";\nexport const REQUEST_ROW_UPDATE = \"lb-row-update\";\nexport const REQUEST_ROW_DELETE = \"lb-row-delete\";\n\nexport const LB_ROW_REQUESTS = [\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n REQUEST_ROW_DELETE,\n] as const;\n\n// --- Kinds --------------------------------------------------------------\nexport const KIND_ROW = \"row\";\nexport const KIND_ROWS = \"rows\";\n\n// --- The URL (docs/reference/chrome.md) ---------------------------------\n// The query the hub serves: one row, keyed by the path, whose other columns\n// are the query parms.\nexport const URL_QUERY = \"lb-url\";\nexport const URL_COLUMN_PATH = \"lb-path\";\nexport const URL_COLUMN_PAGE_LABEL = \"lb-page-label\";\nexport const URL_COLUMN_PAGE_UNKNOWN = \"lb-page-unknown\";\n\n// On an `<a>`: a plain primary click sets `lb-path` from the `href`.\nexport const ATTR_URL_LINK = \"lb-url-link\";\n\n// On an element with `lb-request`: its update of `lb-url` pushes a history\n// entry instead of replacing one.\nexport const ATTR_URL_PUSH = \"lb-url-push\";\n\n// On a `<dialog>`: the hub calls showModal() when `lb-page-unknown` is true.\nexport const ATTR_URL_UNKNOWN = \"lb-url-unknown\";\n\n// --- Build time (docs/reference/custom-elements.md) ---------------------\n// Marks the element in an element file whose children receive the rest of\n// the custom element's content. An attribute rather than an element because\n// HTML content models discard foreign elements inside <select> and <table>.\nexport const ATTR_EXP_SLOT = \"lb-exp-slot\";\n\n// One name in two positions. In an element file it marks a destination; on a\n// `<template>` in the custom element's content it names the destination\n// that template is for, and the template's content moves into it.\nexport const ATTR_EXP_TEMPLATE = \"lb-exp-template\";\n\n// A page ships as <template lb-page=\"<stub>\">.\nexport const ATTR_PAGE = \"lb-page\";\n\n// Stamped by the builder beside ATTR_PAGE: the text content of the page\n// file's `<title>`, which the builder removes.\nexport const ATTR_PAGE_TITLE = \"lb-page-title\";\n\n// The attributes a developer writes. The builder refuses any other `lb-`\n// attribute in markup: the rest are stamps, written by the hub or the\n// builder and never by hand or by script.\nexport const DEVELOPER_ATTRIBUTES = [\n ATTR_QUERY,\n ATTR_COLUMN,\n ATTR_SHOW,\n ATTR_REQUEST,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n] as const;\n\n// The hub's own tag. It is exempt from the rule every other LB-* tag\n// follows: expansion does not require it to have a definition (build/expand.ts),\n// and the client build does not require it to have a script of its own\n// (build/elements.ts) — it is the framework's live element, always present,\n// registered once by the package's main entry point, not a widget an\n// application discovers or declares.\nexport const HUB_TAG_NAME = \"lb-hub\";\n\n// --- Wire --------------------------------------------------------------\n// One path, one method: everything the hub asks of the server is a POST\n// below this path. The page's stub follows it, and the query string the\n// browser is showing rides after that verbatim, so `/accounts?acct=23` asks\n// as `POST /lb/accounts?acct=23` and the server always knows what URL the\n// browser is showing. Navigation is therefore the only GET an application\n// serves, which is what leaves the page name space unrestricted.\nexport const LB_ENDPOINT = \"/lb\";\n\n// A client-side deadline for one round trip. fetch() has no deadline of its\n// own; past this the request is aborted and treated as a failure.\nexport const LB_REQUEST_TIMEOUT_MS = 10_000;\n"]}
@@ -63,6 +63,17 @@ export interface HubRequest {
63
63
  key?: string;
64
64
  values?: Record<string, string>;
65
65
  }
66
+ /**
67
+ * The detail of the `lb-request-done` event: the request as the hub
68
+ * completed and sent it, and what came of it. `items` is every response
69
+ * item that landed because of it, in the order it landed. `error` is set
70
+ * when the request's own round trip failed, and then nothing landed.
71
+ */
72
+ export interface HubRequestDone {
73
+ request: HubRequest;
74
+ items: ResponseItem[];
75
+ error?: Error;
76
+ }
66
77
  /** The fields a handler receives: the request, less its name. */
67
78
  export type RequestFields = Omit<HubRequest, "name">;
68
79
  /** Whether a name is one of the requests Loadbare provides. */
@@ -1 +1 @@
1
- {"version":3,"file":"lb-types.d.ts","sourceRoot":"","sources":["../../core/lb-types.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,QAAQ,EACR,SAAS,EAIV,MAAM,mBAAm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\" />\n\n// The wire vocabulary. Shared by browser and server.\n\nimport {\n KIND_ROW,\n KIND_ROWS,\n LB_RESERVED_PREFIX,\n LB_ROW_REQUESTS,\n URL_COLUMN_PATH,\n} from \"./lb-constants.js\";\n\n/**\n * One row: its columns, by name.\n *\n * A value is whatever the server serialized. The hub knows nothing about its\n * type and enforces nothing: it hands each value to the browser untouched,\n * and the browser renders it as it sees fit. What a number, a date or a null\n * should look like is the application's decision, made in the query.\n */\nexport type Row = Record<string, unknown>;\n\n/**\n * Part of a `rows` query's answer — see docs/reference/server.md, \"Queries\".\n *\n * Rows named here are added or updated, keys in `drop` are removed, and\n * anything unnamed is left alone: its contents, and its place in whatever\n * order the widget is keeping. Add and remove are one result rather than two\n * because the interesting cases are both at once — a row whose sort key\n * changed has to move, a swap is one out and one in — and two messages would\n * paint the intermediate state.\n */\nexport interface Patch {\n rows?: Row[];\n drop?: unknown[];\n}\n\n/** A query's kind, declared by the server and carried by every answer. */\nexport type Kind = typeof KIND_ROW | typeof KIND_ROWS;\n\n/**\n * What a `rows` query answers with: all rows, which is also their order, or\n * a patch. `Array.isArray` tells the two apart.\n */\nexport type RowsResult = Row[] | Patch;\n\nexport function isPatch(result: RowsResult): result is Patch {\n return !Array.isArray(result);\n}\n\n/** What any one query answers with, as the application writes it. */\nexport type HubResult = Row | RowsResult;\n\n/**\n * What application code hands the engine: answers by query name. The engine\n * turns each into a response item, adding the kind and key the query\n * declared.\n */\nexport type HubData = Record<string, HubResult>;\n\n/**\n * One query's answer on the wire: its name, its kind, its key's column name,\n * and exactly one of a row, all rows, or a patch. A patch answers a `rows`\n * query only.\n */\nexport interface ResponseItem {\n query: string;\n kind: Kind;\n key: string;\n row?: Row;\n rows?: Row[];\n patch?: Patch;\n}\n\n/** Every response the server sends: a page load and a request alike. */\nexport type HubResponse = ResponseItem[];\n\n/**\n * Every request has one shape. The name picks the handler; the rest is\n * present when the hub found it.\n */\nexport interface HubRequest {\n name: string;\n query?: string;\n key?: string;\n values?: Record<string, string>;\n}\n\n/** The fields a handler receives: the request, less its name. */\nexport type RequestFields = Omit<HubRequest, \"name\">;\n\n/** Whether a name is one of the requests Loadbare provides. */\nexport function isRowRequest(name: string): boolean {\n return (LB_ROW_REQUESTS as readonly string[]).includes(name);\n}\n\n/**\n * A query string with some parms set, and the rest as they were. An empty\n * value takes its parm out, since empty is every parm's default and a\n * default is left out of the URL.\n *\n * One rule on both sides of the wire: the hub applies it to the address bar,\n * and the server to the query string it loads the page at after a request\n * returned `lb-url`. The two must agree, or what the page shows would differ\n * from what the address bar says.\n */\nexport function withQueryParms(\n search: URLSearchParams,\n parms: Record<string, string>,\n): URLSearchParams {\n const next = new URLSearchParams(search);\n for (const [name, value] of Object.entries(parms)) {\n if (value === \"\") next.delete(name);\n else next.set(name, value);\n }\n return next;\n}\n\n/**\n * A path names a page by its stub, and nothing finer. The bare path resolves\n * to `index`, the same convention a static file server follows.\n */\nexport function pageNameFor(path: string): string {\n const name = path.replace(/^\\/+|\\/+$/g, \"\");\n return name === \"\" ? \"index\" : name;\n}\n\n/**\n * Where a row for `lb-url` leads, from a page and its query parms.\n *\n * A column whose name begins with `lb-` is Loadbare's, and never a query\n * parm; every other column is one. An `lb-path` naming another page enters\n * it with only the parms the row names. Otherwise the named parms are set,\n * or taken out when empty, and the rest are kept.\n *\n * One rule on both sides of the wire: the server loads the page it names,\n * and the hub writes the URL it names. The two must agree, or what the page\n * shows would differ from what the address bar says.\n */\nexport function nextLocation(\n page: string,\n parms: URLSearchParams,\n row: Row,\n): { page: string; parms: URLSearchParams; moved: boolean } {\n const named: Record<string, string> = {};\n for (const [name, value] of Object.entries(row)) {\n if (name.startsWith(LB_RESERVED_PREFIX)) continue;\n named[name] = value === null || value === undefined ? \"\" : String(value);\n }\n const path = row[URL_COLUMN_PATH];\n const next = typeof path === \"string\" ? pageNameFor(path) : page;\n const moved = next !== page;\n return {\n page: next,\n parms: withQueryParms(moved ? new URLSearchParams() : parms, named),\n moved,\n };\n}\n\n/**\n * The two hooks a custom element holding rows may implement, both optional.\n *\n * The hub reconciles every row template itself, so a custom element supplies\n * placement and scaffolding and nothing else. They are methods on an element\n * the hub does not own, so they carry the `lb` prefix Loadbare reserves for\n * exactly that — see docs/reference/custom-elements.md.\n */\nexport interface RowsHost {\n /**\n * Where a live row belongs, called with the row detached on its first\n * appearance. Without it a row lands immediately before the template, so\n * rows accumulate in the order they arrive.\n */\n lbPlaceRow?(el: Element, row: Row, template: HTMLTemplateElement): void;\n\n /** Called once after a whole result has landed, for derived scaffolding. */\n lbRowsLanded?(): void;\n}\n"]}
1
+ {"version":3,"file":"lb-types.js","sourceRoot":"","sources":["../../core/lb-types.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,qDAAqD;AAErD,OAAO,EAGL,kBAAkB,EAClB,eAAe,EACf,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAoC3B,MAAM,UAAU,OAAO,CAAC,MAAkB;IACxC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAuDD,+DAA+D;AAC/D,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAQ,eAAqC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAuB,EACvB,KAA6B;IAE7B,MAAM,IAAI,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,EAAE;YAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;;YAC/B,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAC5C,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,KAAsB,EACtB,GAAQ;IAER,MAAM,KAAK,GAA2B,EAAE,CAAC;IACzC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,IAAI,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC;YAAE,SAAS;QAClD,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3E,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,eAAe,CAAC,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,KAAK,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5B,OAAO;QACL,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC;QACnE,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\n// The wire vocabulary. Shared by browser and server.\n\nimport {\n KIND_ROW,\n KIND_ROWS,\n LB_RESERVED_PREFIX,\n LB_ROW_REQUESTS,\n URL_COLUMN_PATH,\n} from \"./lb-constants.js\";\n\n/**\n * One row: its columns, by name.\n *\n * A value is whatever the server serialized. The hub knows nothing about its\n * type and enforces nothing: it hands each value to the browser untouched,\n * and the browser renders it as it sees fit. What a number, a date or a null\n * should look like is the application's decision, made in the query.\n */\nexport type Row = Record<string, unknown>;\n\n/**\n * Part of a `rows` query's answer — see docs/reference/server.md, \"Queries\".\n *\n * Rows named here are added or updated, keys in `drop` are removed, and\n * anything unnamed is left alone: its contents, and its place in whatever\n * order the widget is keeping. Add and remove are one result rather than two\n * because the interesting cases are both at once — a row whose sort key\n * changed has to move, a swap is one out and one in — and two messages would\n * paint the intermediate state.\n */\nexport interface Patch {\n rows?: Row[];\n drop?: unknown[];\n}\n\n/** A query's kind, declared by the server and carried by every answer. */\nexport type Kind = typeof KIND_ROW | typeof KIND_ROWS;\n\n/**\n * What a `rows` query answers with: all rows, which is also their order, or\n * a patch. `Array.isArray` tells the two apart.\n */\nexport type RowsResult = Row[] | Patch;\n\nexport function isPatch(result: RowsResult): result is Patch {\n return !Array.isArray(result);\n}\n\n/** What any one query answers with, as the application writes it. */\nexport type HubResult = Row | RowsResult;\n\n/**\n * What application code hands the engine: answers by query name. The engine\n * turns each into a response item, adding the kind and key the query\n * declared.\n */\nexport type HubData = Record<string, HubResult>;\n\n/**\n * One query's answer on the wire: its name, its kind, its key's column name,\n * and exactly one of a row, all rows, or a patch. A patch answers a `rows`\n * query only.\n */\nexport interface ResponseItem {\n query: string;\n kind: Kind;\n key: string;\n row?: Row;\n rows?: Row[];\n patch?: Patch;\n}\n\n/** Every response the server sends: a page load and a request alike. */\nexport type HubResponse = ResponseItem[];\n\n/**\n * Every request has one shape. The name picks the handler; the rest is\n * present when the hub found it.\n */\nexport interface HubRequest {\n name: string;\n query?: string;\n key?: string;\n values?: Record<string, string>;\n}\n\n/**\n * The detail of the `lb-request-done` event: the request as the hub\n * completed and sent it, and what came of it. `items` is every response\n * item that landed because of it, in the order it landed. `error` is set\n * when the request's own round trip failed, and then nothing landed.\n */\nexport interface HubRequestDone {\n request: HubRequest;\n items: ResponseItem[];\n error?: Error;\n}\n\n/** The fields a handler receives: the request, less its name. */\nexport type RequestFields = Omit<HubRequest, \"name\">;\n\n/** Whether a name is one of the requests Loadbare provides. */\nexport function isRowRequest(name: string): boolean {\n return (LB_ROW_REQUESTS as readonly string[]).includes(name);\n}\n\n/**\n * A query string with some parms set, and the rest as they were. An empty\n * value takes its parm out, since empty is every parm's default and a\n * default is left out of the URL.\n *\n * One rule on both sides of the wire: the hub applies it to the address bar,\n * and the server to the query string it loads the page at after a request\n * returned `lb-url`. The two must agree, or what the page shows would differ\n * from what the address bar says.\n */\nexport function withQueryParms(\n search: URLSearchParams,\n parms: Record<string, string>,\n): URLSearchParams {\n const next = new URLSearchParams(search);\n for (const [name, value] of Object.entries(parms)) {\n if (value === \"\") next.delete(name);\n else next.set(name, value);\n }\n return next;\n}\n\n/**\n * A path names a page by its stub, and nothing finer. The bare path resolves\n * to `index`, the same convention a static file server follows.\n */\nexport function pageNameFor(path: string): string {\n const name = path.replace(/^\\/+|\\/+$/g, \"\");\n return name === \"\" ? \"index\" : name;\n}\n\n/**\n * Where a row for `lb-url` leads, from a page and its query parms.\n *\n * A column whose name begins with `lb-` is Loadbare's, and never a query\n * parm; every other column is one. An `lb-path` naming another page enters\n * it with only the parms the row names. Otherwise the named parms are set,\n * or taken out when empty, and the rest are kept.\n *\n * One rule on both sides of the wire: the server loads the page it names,\n * and the hub writes the URL it names. The two must agree, or what the page\n * shows would differ from what the address bar says.\n */\nexport function nextLocation(\n page: string,\n parms: URLSearchParams,\n row: Row,\n): { page: string; parms: URLSearchParams; moved: boolean } {\n const named: Record<string, string> = {};\n for (const [name, value] of Object.entries(row)) {\n if (name.startsWith(LB_RESERVED_PREFIX)) continue;\n named[name] = value === null || value === undefined ? \"\" : String(value);\n }\n const path = row[URL_COLUMN_PATH];\n const next = typeof path === \"string\" ? pageNameFor(path) : page;\n const moved = next !== page;\n return {\n page: next,\n parms: withQueryParms(moved ? new URLSearchParams() : parms, named),\n moved,\n };\n}\n\n/**\n * The two hooks a custom element holding rows may implement, both optional.\n *\n * The hub reconciles every row template itself, so a custom element supplies\n * placement and scaffolding and nothing else. They are methods on an element\n * the hub does not own, so they carry the `lb` prefix Loadbare reserves for\n * exactly that — see docs/reference/custom-elements.md.\n */\nexport interface RowsHost {\n /**\n * Where a live row belongs, called with the row detached on its first\n * appearance. Without it a row lands immediately before the template, so\n * rows accumulate in the order they arrive.\n */\n lbPlaceRow?(el: Element, row: Row, template: HTMLTemplateElement): void;\n\n /** Called once after a whole result has landed, for derived scaffolding. */\n lbRowsLanded?(): void;\n}\n"]}
@@ -53,7 +53,13 @@ export declare function templateIn(el: Element): HTMLTemplateElement | null;
53
53
  */
54
54
  export declare function applyRows(el: Element, template: HTMLTemplateElement, keyColumn: string, result: RowsResult): void;
55
55
  /**
56
- * Land response items. Every answer arrives through here.
56
+ * Drop what landing kept for a root. The hub calls it when it replaces the
57
+ * page, since another page's query of the same name is another query.
58
+ */
59
+ export declare function forget(root: ParentNode): void;
60
+ /**
61
+ * Land response items. Every answer arrives through here, and is kept for
62
+ * `root`, so that what arrives after it is filled from it — see forget().
57
63
  *
58
64
  * `quiet` names queries that may have nowhere to land without a warning: the
59
65
  * hub's own `lb-url` lands wherever a chrome or page names it, and nowhere
@@ -1 +1 @@
1
- {"version":3,"file":"lb-apply.d.ts","sourceRoot":"","sources":["../../hub/lb-apply.ts"],"names":[],"mappings":"AAoCA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,GAAG,EAER,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAC;AAW7B,mEAAmE;AACnE,MAAM,WAAW,OAAQ,SAAQ,OAAO;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAiBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAGrD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,OAAO,CAEpD;AAuDD;;;;;GAK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AE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,UAAQ,GAAG,IAAI,CAmBvE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,OAAO,GAAG,mBAAmB,GAAG,IAAI,CAKlE;AA+BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACvB,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,mBAAmB,EAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,GACjB,IAAI,CAmEN;AA6CD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAE7C;AAwED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,YAAY,EAAE,EACrB,KAAK,GAAE,SAAS,MAAM,EAAO,GAC5B,IAAI,CAiBN"}
@@ -16,12 +16,20 @@
16
16
  * operation, and the only difference is how much of the page the root
17
17
  * covers.
18
18
  *
19
+ * An answer is kept after it lands. An element that names a query and
20
+ * arrives after that query's answer — a picker in a new live row, a ghost
21
+ * row a custom element built — is filled from the kept answer at the end of
22
+ * the next landing, so a query need not land again, and need not land after
23
+ * the one whose rows hold it, just to fill what is new. A custom element
24
+ * shipped inside an absent branch has not upgraded, so it is filled again
25
+ * once it has, and places its rows itself.
26
+ *
19
27
  * A condition is the one other thing landing moves. An element whose
20
28
  * `lb-show` column is off stands in the document inside a template, and
21
29
  * landing reaches in there as it reaches everywhere else, so a branch that
22
30
  * returns is already current. Nothing but landing reaches in.
23
31
  */
24
- import { ATTR_COLUMN, ATTR_COLUMN_VALUE, ATTR_KEY_VALUE, ATTR_QUERY, ATTR_QUERY_ROW_COUNT, ATTR_ROW_LIVE, ATTR_SHOW, KIND_ROW, LIVE_ROW, } from "../core/lb-constants.js";
32
+ import { ATTR_COLUMN, ATTR_COLUMN_VALUE, ATTR_KEY_VALUE, ATTR_QUERY, ATTR_QUERY_ROW_COUNT, ATTR_ROW_LIVE, ATTR_SHOW, KIND_ROW, LIVE_ROW, SHOW_NOT, } from "../core/lb-constants.js";
25
33
  import { isPatch, } from "../core/lb-types.js";
26
34
  /** The template holding an absent branch — see ATTR_SHOW. */
27
35
  const PARKED = `template[${ATTR_SHOW}]`;
@@ -210,6 +218,9 @@ export function applyRow(root, row, liveRow = false) {
210
218
  for (const el of below(root, `[${ATTR_SHOW}="${column}"]`)) {
211
219
  present(el, on);
212
220
  }
221
+ for (const el of below(root, `[${ATTR_SHOW}="${SHOW_NOT}${column}"]`)) {
222
+ present(el, !on);
223
+ }
213
224
  }
214
225
  }
215
226
  /**
@@ -348,15 +359,103 @@ function landItem(el, item) {
348
359
  const result = item.patch ?? item.rows ?? [];
349
360
  applyRows(el, template, item.key, result);
350
361
  }
362
+ const kept = new WeakMap();
363
+ function keptFor(root) {
364
+ let found = kept.get(root);
365
+ if (!found) {
366
+ found = { answers: new Map(), landed: new WeakSet() };
367
+ kept.set(root, found);
368
+ }
369
+ return found;
370
+ }
371
+ /**
372
+ * Drop what landing kept for a root. The hub calls it when it replaces the
373
+ * page, since another page's query of the same name is another query.
374
+ */
375
+ export function forget(root) {
376
+ kept.delete(root);
377
+ }
351
378
  /**
352
- * Land response items. Every answer arrives through here.
379
+ * All rows after a patch, as the elements it landed on now show them: a row
380
+ * it names takes the columns it sends and keeps its place, a new one goes
381
+ * last, and a dropped one goes.
382
+ */
383
+ function patched(rows, key, patch) {
384
+ const byKey = new Map(rows.map((row) => [String(row[key]), row]));
385
+ for (const row of patch.rows ?? []) {
386
+ const k = String(row[key]);
387
+ byKey.set(k, { ...byKey.get(k), ...row });
388
+ }
389
+ for (const k of patch.drop ?? [])
390
+ byKey.delete(String(k));
391
+ return [...byKey.values()];
392
+ }
393
+ /**
394
+ * Keep an answer as all of the query's rows. A patch is applied to the
395
+ * answer already kept; with none, it is not the whole of anything, and
396
+ * nothing is kept.
397
+ */
398
+ function keep(answers, item) {
399
+ if (!item.patch) {
400
+ answers.set(item.query, item);
401
+ return;
402
+ }
403
+ const before = answers.get(item.query);
404
+ if (!before)
405
+ return;
406
+ const { patch: _, ...whole } = item;
407
+ answers.set(item.query, {
408
+ ...whole,
409
+ rows: patched(before.rows ?? [], item.key, item.patch),
410
+ });
411
+ }
412
+ /**
413
+ * A custom element whose class is defined and has not yet run on it: one the
414
+ * builder shipped inside an absent branch's template, where nothing upgrades.
415
+ * It has none of the hooks landing calls, so rows that land on it are not
416
+ * placed by it. A landing on it does not count, and once `lb-show` brings it
417
+ * into the document and it upgrades, it is filled again from the kept answer.
418
+ *
419
+ * An element with no class, such as one defined by an element file alone,
420
+ * never upgrades, and is never waiting.
421
+ */
422
+ function waiting(el) {
423
+ const registry = globalThis
424
+ .customElements;
425
+ const upgraded = registry?.get(el.localName);
426
+ return upgraded !== undefined && !(el instanceof upgraded);
427
+ }
428
+ /**
429
+ * Fill every element that names a kept query and has had nothing land on it.
430
+ * Filling one can build more — a live row holding a picker of its own — so
431
+ * it goes round until a pass finds nothing new.
432
+ */
433
+ function fillArrivals(root, { answers, landed }) {
434
+ for (let filled = true; filled;) {
435
+ filled = false;
436
+ for (const [query, item] of answers) {
437
+ for (const el of everywhere(root, `[${ATTR_QUERY}="${query}"]`)) {
438
+ if (landed.has(el) || waiting(el))
439
+ continue;
440
+ landed.add(el);
441
+ landItem(el, item);
442
+ filled = true;
443
+ }
444
+ }
445
+ }
446
+ }
447
+ /**
448
+ * Land response items. Every answer arrives through here, and is kept for
449
+ * `root`, so that what arrives after it is filled from it — see forget().
353
450
  *
354
451
  * `quiet` names queries that may have nowhere to land without a warning: the
355
452
  * hub's own `lb-url` lands wherever a chrome or page names it, and nowhere
356
453
  * otherwise.
357
454
  */
358
455
  export function applyResponse(root, items, quiet = []) {
456
+ const kept = keptFor(root);
359
457
  for (const item of items) {
458
+ keep(kept.answers, item);
360
459
  const targets = everywhere(root, `[${ATTR_QUERY}="${item.query}"]`);
361
460
  if (targets.length === 0) {
362
461
  if (!quiet.includes(item.query)) {
@@ -364,8 +463,12 @@ export function applyResponse(root, items, quiet = []) {
364
463
  }
365
464
  continue;
366
465
  }
367
- for (const el of targets)
466
+ for (const el of targets) {
467
+ if (!waiting(el))
468
+ kept.landed.add(el);
368
469
  landItem(el, item);
470
+ }
369
471
  }
472
+ fillArrivals(root, kept);
370
473
  }
371
474
  //# sourceMappingURL=lb-apply.js.map