@loadbare/app 0.10.0 → 0.11.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.
- package/dist/build/assemble.d.ts.map +1 -1
- package/dist/build/assemble.js +46 -37
- package/dist/build/assemble.js.map +1 -1
- package/dist/build/expand.d.ts +6 -1
- package/dist/build/expand.d.ts.map +1 -1
- package/dist/build/expand.js +92 -7
- package/dist/build/expand.js.map +1 -1
- package/dist/core/lb-constants.d.ts +2 -0
- package/dist/core/lb-constants.d.ts.map +1 -1
- package/dist/core/lb-constants.js +8 -0
- package/dist/core/lb-constants.js.map +1 -1
- package/dist/hub/lb-apply.d.ts.map +1 -1
- package/dist/hub/lb-apply.js +31 -16
- package/dist/hub/lb-apply.js.map +1 -1
- package/dist/hub/lb-hub.browser.d.ts.map +1 -1
- package/dist/hub/lb-hub.browser.js +6 -7
- package/dist/hub/lb-hub.browser.js.map +1 -1
- package/docs/TECHREF-1.0.md +50 -1
- package/docs/comparison.md +25 -4
- package/docs/reference/custom-elements.md +101 -9
- package/docs/reference/data-binding.md +9 -2
- package/docs/reference/page-files.md +29 -0
- package/docs/what-does-loadbare-extend.md +124 -0
- package/package.json +1 -1
- package/skills/loadbare-app/SKILL.md +27 -5
- package/skills/loadbare-app/references/TECHREF-1.0.md +50 -1
- package/skills/loadbare-app/references/custom-elements.md +101 -9
- package/skills/loadbare-app/references/data-binding.md +9 -2
- package/skills/loadbare-app/references/page-files.md +29 -0
|
@@ -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;A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qE;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 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,0EAA0E;AAC1E,2EAA2E;AAC3E,yBAAyB;AACzB,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,0EAA0E;AAC1E,wEAAwE;AACxE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC;AAE7C,2EAA2E;AAC3E,sEAAsE;AACtE,4EAA4E;AAC5E,qEAAqE;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C,4EAA4E;AAC5E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,aAAa,GAAG,CAAC;AAE7C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;AACrE,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C,2EAA2E;AAC3E,kCAAkC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAEjD,2EAA2E;AAC3E,0EAA0E;AAC1E,4EAA4E;AAC5E,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC;AAE3C,6EAA6E;AAC7E,wEAAwE;AACxE,kEAAkE;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;AAEnC,wEAAwE;AACxE,+CAA+C;AAC/C,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAE/C,yEAAyE;AACzE,sEAAsE;AACtE,0CAA0C;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,UAAU;IACV,WAAW;IACX,SAAS;IACT,YAAY;IACZ,aAAa;IACb,aAAa;IACb,gBAAgB;CACR,CAAC;AAEX,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-apply.d.ts","sourceRoot":"","sources":["../../hub/lb-apply.ts"],"names":[],"mappings":"
|
|
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;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE,CAMjE;AA8DD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,UAAQ,GAAG,IAAI,CAgBvE;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;AAyBD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,YAAY,EAAE,EACrB,KAAK,GAAE,SAAS,MAAM,EAAO,GAC5B,IAAI,CAWN"}
|
package/dist/hub/lb-apply.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* landing reaches in there as it reaches everywhere else, so a branch that
|
|
22
22
|
* returns is already current. Nothing but landing reaches in.
|
|
23
23
|
*/
|
|
24
|
-
import { ATTR_COLUMN, ATTR_COLUMN_VALUE, ATTR_KEY_VALUE, ATTR_QUERY, ATTR_QUERY_ROW_COUNT, ATTR_SHOW, KIND_ROW, } from "../core/lb-constants.js";
|
|
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";
|
|
25
25
|
import { isPatch, } from "../core/lb-types.js";
|
|
26
26
|
/** The template holding an absent branch — see ATTR_SHOW. */
|
|
27
27
|
const PARKED = `template[${ATTR_SHOW}]`;
|
|
@@ -223,14 +223,27 @@ export function templateIn(el) {
|
|
|
223
223
|
return template ?? null;
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
|
-
* The live rows
|
|
227
|
-
* query is that query's.
|
|
226
|
+
* The live rows of the element's query, in document order. A row of a nested
|
|
227
|
+
* query is that query's. An element a `row` query landed on carries a key and
|
|
228
|
+
* is not a live row, so a `row` shown in a table's head or foot is not one of
|
|
229
|
+
* the table's rows.
|
|
230
|
+
*/
|
|
231
|
+
function liveRows(el) {
|
|
232
|
+
return [...el.querySelectorAll(LIVE_ROW)].filter((row) => inScope(el, row));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* The live rows already showing, by the key each carries. Two live rows with
|
|
236
|
+
* one key are a mistake nothing downstream can recover from: only one of them
|
|
237
|
+
* would ever be matched, and the other would stay until the page goes.
|
|
228
238
|
*/
|
|
229
239
|
function showing(el) {
|
|
230
240
|
const rows = new Map();
|
|
231
|
-
for (const row of el
|
|
232
|
-
|
|
233
|
-
|
|
241
|
+
for (const row of liveRows(el)) {
|
|
242
|
+
const key = row.getAttribute(ATTR_KEY_VALUE);
|
|
243
|
+
if (rows.has(key)) {
|
|
244
|
+
console.error(`lb-hub: <${el.localName}> shows two rows with the key '${key}'`);
|
|
245
|
+
}
|
|
246
|
+
rows.set(key, row);
|
|
234
247
|
}
|
|
235
248
|
return rows;
|
|
236
249
|
}
|
|
@@ -251,6 +264,7 @@ export function applyRows(el, template, keyColumn, result) {
|
|
|
251
264
|
const shown = showing(el);
|
|
252
265
|
const host = el;
|
|
253
266
|
const whole = !isPatch(result);
|
|
267
|
+
const landed = new Set();
|
|
254
268
|
const place = (row, data) => {
|
|
255
269
|
if (host.lbPlaceRow)
|
|
256
270
|
host.lbPlaceRow(row, data, template);
|
|
@@ -260,11 +274,16 @@ export function applyRows(el, template, keyColumn, result) {
|
|
|
260
274
|
const upsert = (data) => {
|
|
261
275
|
if (data[keyColumn] === undefined) {
|
|
262
276
|
console.error(`lb-hub: a row for <${el.localName}> has no '${keyColumn}' column`);
|
|
263
|
-
return
|
|
277
|
+
return;
|
|
264
278
|
}
|
|
265
279
|
// The key is stored on the row as an attribute and read back from
|
|
266
280
|
// there, so it is compared as the string the attribute holds.
|
|
267
281
|
const key = String(data[keyColumn]);
|
|
282
|
+
if (landed.has(key)) {
|
|
283
|
+
console.error(`lb-hub: two rows for <${el.localName}> have the key '${key}'; ` +
|
|
284
|
+
`the last one shows`);
|
|
285
|
+
}
|
|
286
|
+
landed.add(key);
|
|
268
287
|
let row = shown.get(key);
|
|
269
288
|
const fresh = row === undefined;
|
|
270
289
|
if (!row) {
|
|
@@ -273,6 +292,7 @@ export function applyRows(el, template, keyColumn, result) {
|
|
|
273
292
|
// until inserted, and a form-associated control would be filled as if
|
|
274
293
|
// it were not one.
|
|
275
294
|
row = el.ownerDocument.importNode(template.content.firstElementChild, true);
|
|
295
|
+
row.setAttribute(ATTR_ROW_LIVE, "");
|
|
276
296
|
row.setAttribute(ATTR_KEY_VALUE, key);
|
|
277
297
|
shown.set(key, row);
|
|
278
298
|
}
|
|
@@ -282,17 +302,12 @@ export function applyRows(el, template, keyColumn, result) {
|
|
|
282
302
|
applyRow(row, data, true);
|
|
283
303
|
if (fresh || whole)
|
|
284
304
|
place(row, data);
|
|
285
|
-
return key;
|
|
286
305
|
};
|
|
287
306
|
if (Array.isArray(result)) {
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
const key = upsert(data);
|
|
291
|
-
if (key !== null)
|
|
292
|
-
arrived.add(key);
|
|
293
|
-
}
|
|
307
|
+
for (const data of result)
|
|
308
|
+
upsert(data);
|
|
294
309
|
for (const [key, row] of shown)
|
|
295
|
-
if (!
|
|
310
|
+
if (!landed.has(key))
|
|
296
311
|
row.remove();
|
|
297
312
|
}
|
|
298
313
|
else {
|
|
@@ -305,7 +320,7 @@ export function applyRows(el, template, keyColumn, result) {
|
|
|
305
320
|
// and a patch report the same fact the same way. Only here is the count
|
|
306
321
|
// known: the server answers with rows and says nothing about how many
|
|
307
322
|
// survived reconciliation.
|
|
308
|
-
el.setAttribute(ATTR_QUERY_ROW_COUNT, String(
|
|
323
|
+
el.setAttribute(ATTR_QUERY_ROW_COUNT, String(liveRows(el).length));
|
|
309
324
|
// Derived scaffolding — a section heading, an <optgroup> — goes when its
|
|
310
325
|
// last row does, and only the custom element knows it exists.
|
|
311
326
|
host.lbRowsLanded?.();
|
package/dist/hub/lb-apply.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-apply.js","sourceRoot":"","sources":["../../hub/lb-apply.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,QAAQ,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,OAAO,GAKR,MAAM,qBAAqB,CAAC;AAE7B,6DAA6D;AAC7D,MAAM,MAAM,GAAG,YAAY,SAAS,GAAG,CAAC;AAExC,kFAAk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AAE,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO;IACT,CAAC;IACD,0EAA0E;IAC1E,oDAAoD;IACpD,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;IAC7C,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAgB,EAChB,KAAqB,EACrB,QAA2B,EAAE;IAE7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QACpE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,0BAA0B,IAAI,CAAC,KAAK,aAAa,CAAC,CAAC;YAClE,CAAC;YACD,SAAS;QACX,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,OAAO;YAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\n/**\n * Landing — see docs/reference/data-binding.md.\n *\n * The hub lands a response item's rows on every element whose `lb-query`\n * names its query. The item says the query's kind and key, so the markup\n * says neither:\n *\n * kind row template the hub\n * row no lands the row on the element itself\n * row yes lands one live row\n * rows yes lands one live row per row\n * rows no lands nothing\n *\n * Filling a live row and filling an element a `row` lands on are the same\n * operation, and the only difference is how much of the page the root\n * covers.\n *\n * A condition is the one other thing landing moves. An element whose\n * `lb-show` column is off stands in the document inside a template, and\n * landing reaches in there as it reaches everywhere else, so a branch that\n * returns is already current. Nothing but landing reaches in.\n */\n\nimport {\n ATTR_COLUMN,\n ATTR_COLUMN_VALUE,\n ATTR_KEY_VALUE,\n ATTR_QUERY,\n ATTR_QUERY_ROW_COUNT,\n ATTR_SHOW,\n KIND_ROW,\n} from \"../core/lb-constants.js\";\nimport {\n isPatch,\n type ResponseItem,\n type Row,\n type RowsHost,\n type RowsResult,\n} from \"../core/lb-types.js\";\n\n/** The template holding an absent branch — see ATTR_SHOW. */\nconst PARKED = `template[${ATTR_SHOW}]`;\n\n/** A DocumentFragment's nodeType. Tier 3 has no `Node` global to read it from. */\nconst FRAGMENT_NODE = 11;\n\n/** The input types whose state is not their `value`, or cannot be set. */\nconst UNLANDED_INPUTS = [\"checkbox\", \"radio\", \"file\"];\n\n/** A control's value, whether it is native or a custom element. */\nexport interface Control extends Element {\n value: string;\n}\n\n/**\n * A native control whose state is its `value`: a `<select>`, a\n * `<textarea>`, or an `<input>` of any type but checkbox, radio and file.\n *\n * Told apart by tag name and type rather than by class, so it holds for an\n * element from any document.\n */\nfunction isNativeControl(el: Element): boolean {\n if (el.localName === \"select\" || el.localName === \"textarea\") return true;\n return (\n el.localName === \"input\" &&\n !UNLANDED_INPUTS.includes((el as HTMLInputElement).type)\n );\n}\n\n/**\n * A form-associated custom element with a `value` property. HTML marks one\n * with `static formAssociated = true` on its class, and a control has a value.\n */\nexport function isFormAssociated(el: Element): boolean {\n const ctor = el.constructor as { formAssociated?: unknown };\n return ctor.formAssociated === true && \"value\" in el;\n}\n\n/**\n * A control: an `<input>`, `<select>` or `<textarea>`, or a form-associated\n * custom element with a `value` property. Landing and gathering draw the\n * same line, so a value read back is the one that landed there.\n */\nexport function isControl(el: Element): el is Control {\n return isNativeControl(el) || isFormAssociated(el);\n}\n\n/**\n * Set an element from a column. A control's `value` is set. A custom element\n * that is not a control keeps its content, which the builder placed there\n * from its element file, and renders the stamp instead. Any other element's\n * text content is set. Every one carries the value as `lb-column-value`.\n */\nfunction land(el: Element, value: unknown): void {\n // Untouched, whatever the server sent: the browser decides what a\n // non-string looks like. See Row in core/lb-types.ts.\n if (value === null || value === undefined) {\n if (isControl(el)) el.value = \"\";\n else if (!el.localName.includes(\"-\") && el.localName !== \"input\") {\n el.textContent = \"\";\n }\n el.removeAttribute(ATTR_COLUMN_VALUE);\n return;\n }\n if (isControl(el)) {\n el.value = value as string;\n } else if (el.localName === \"input\") {\n console.warn(\n `lb-hub: a value does not land on <input type=\"${(el as HTMLInputElement).type}\">, ignoring`,\n el,\n );\n return;\n } else if (!el.localName.includes(\"-\")) {\n el.textContent = value as string;\n }\n el.setAttribute(ATTR_COLUMN_VALUE, value as string);\n}\n\n/**\n * Whether an element under `root` belongs to root's query, rather than to a\n * query nested inside it.\n *\n * A descendant is root's unless something between it and root carries\n * `lb-query`. The element's own `lb-query` does not count: it names what the\n * element holds, and the row it reads from is its ancestors'. So a picker\n * carrying `lb-query` and `lb-column` is set from the row around it. Root's\n * own attribute does not count either: root is what is being filled.\n *\n * Root may be the content of a template holding an absent branch. The walk\n * up from an element inside it stops at the top of that content, which has\n * no parent, and the template it stands for was in scope already.\n */\nfunction inScope(root: Element | DocumentFragment, el: Element): boolean {\n for (let node = el.parentElement; node && node !== root;) {\n if (node.hasAttribute(ATTR_QUERY)) return false;\n node = node.parentElement;\n }\n return true;\n}\n\n/**\n * Root if it matches, then every descendant in root's query that does.\n * Gathering finds columns through here. It does not reach into an absent\n * branch, so a live row is read back from the places a row lands that are\n * showing.\n */\nexport function within(root: Element, selector: string): Element[] {\n const found: Element[] = root.matches(selector) ? [root] : [];\n for (const el of root.querySelectorAll(selector)) {\n if (inScope(root, el)) found.push(el);\n }\n return found;\n}\n\n/**\n * Every descendant in root's query that matches, absent branches included.\n *\n * `querySelectorAll` does not enter template content, so an element that is\n * off would otherwise miss everything landed while it was away, and return\n * stale or with its rows empty. A template holding one is in root's query by\n * the ordinary rule, and its content is searched as if it stood there.\n */\nfunction below(root: Element | DocumentFragment, selector: string): Element[] {\n const found: Element[] = [];\n for (const el of root.querySelectorAll(selector)) {\n if (inScope(root, el)) found.push(el);\n }\n for (const parked of root.querySelectorAll(PARKED)) {\n if (inScope(root, parked)) {\n found.push(...below((parked as HTMLTemplateElement).content, selector));\n }\n }\n return found;\n}\n\n/**\n * Every element in root that matches, absent branches included. A query is\n * looked up this way before any row is known, so nothing is filtered out.\n */\nfunction everywhere(root: ParentNode, selector: string): Element[] {\n const found = [...root.querySelectorAll(selector)];\n for (const parked of root.querySelectorAll(PARKED)) {\n const content = (parked as HTMLTemplateElement).content;\n found.push(...everywhere(content, selector));\n }\n return found;\n}\n\n/**\n * Put an element in the document or take it out, as its `lb-show` column\n * says.\n *\n * Off is inside a template that stands where the element stood, carrying the\n * same `lb-show`. The element is moved rather than rebuilt, so a custom\n * element keeps its instance and a control keeps what was typed into it. On\n * moves it back and the template goes.\n *\n * Landing reaches into that template, so both it and the element it holds\n * arrive here. The template decides; the element it holds, whose parent is\n * the template's content, is left to it.\n */\nfunction present(el: Element, on: boolean): void {\n if (el.localName === \"template\") {\n const branch = (el as HTMLTemplateElement).content.firstElementChild;\n if (on && branch) el.replaceWith(branch);\n return;\n }\n if (on || el.parentNode?.nodeType === FRAGMENT_NODE) return;\n const parked = el.ownerDocument.createElement(\"template\");\n parked.setAttribute(ATTR_SHOW, el.getAttribute(ATTR_SHOW)!);\n el.replaceWith(parked);\n parked.content.append(el);\n}\n\n/**\n * Fill from one row: every `lb-column` and `lb-show` in root's query.\n *\n * A live row is its own row, so its root counts when it carries\n * `lb-column`: `<option>`'s content model is text, so an option row has to\n * be the column it displays. An element a `row` lands on is not its own\n * ancestor, so its own `lb-column` reads from the row around it and is left\n * alone here.\n */\nexport function applyRow(root: Element, row: Row, liveRow = false): void {\n for (const [column, value] of Object.entries(row)) {\n const selector = `[${ATTR_COLUMN}=\"${column}\"]`;\n const columns = below(root, selector);\n if (liveRow && root.matches(selector)) columns.unshift(root);\n for (const el of columns) land(el, value);\n // Only null and false are off. A string is never read, so \"false\" is on,\n // and the query spells a condition as a boolean or a null.\n //\n // Never the root's own: a row template's root carries none, and the\n // element a row lands on reads its condition from the row around it.\n const on = value !== null && value !== false;\n for (const el of below(root, `[${ATTR_SHOW}=\"${column}\"]`)) {\n present(el, on);\n }\n }\n}\n\n/**\n * The row template: the first `<template>` among the element's descendants,\n * outside any nested `lb-query`. A template holding an absent branch is not a\n * row template: rows land before the row template, so one inside the first\n * live row comes first in document order.\n */\nexport function templateIn(el: Element): HTMLTemplateElement | null {\n const template = within(el, `template:not([${ATTR_SHOW}])`).find(\n (t) => t !== el,\n );\n return (template as HTMLTemplateElement | undefined) ?? null;\n}\n\n/**\n * The live rows already showing, by the key each carries. A row of a nested\n * query is that query's.\n */\nfunction showing(el: Element): Map<string, Element> {\n const rows = new Map<string, Element>();\n for (const row of el.querySelectorAll(`[${ATTR_KEY_VALUE}]`)) {\n if (inScope(el, row)) rows.set(row.getAttribute(ATTR_KEY_VALUE)!, row);\n }\n return rows;\n}\n\n/**\n * Land rows through a row template.\n *\n * All rows decide membership and order: every row is placed in the order\n * given, and a row whose key did not arrive is gone. A patch disturbs only\n * what it names — a row it did not mention keeps its contents and its\n * position.\n *\n * A custom element that carries `lbPlaceRow` decides where a row goes,\n * because only it knows whether it sorts or groups. Without it a row lands\n * immediately before the template, so rows accumulate in the order they\n * arrive and the template stays put as the insertion marker.\n */\nexport function applyRows(\n el: Element,\n template: HTMLTemplateElement,\n keyColumn: string,\n result: RowsResult,\n): void {\n const shown = showing(el);\n const host = el as Element & RowsHost;\n const whole = !isPatch(result);\n\n const place = (row: Element, data: Row): void => {\n if (host.lbPlaceRow) host.lbPlaceRow(row, data, template);\n else template.parentElement!.insertBefore(row, template);\n };\n\n const upsert = (data: Row): string | null => {\n if (data[keyColumn] === undefined) {\n console.error(\n `lb-hub: a row for <${el.localName}> has no '${keyColumn}' column`,\n );\n return null;\n }\n // The key is stored on the row as an attribute and read back from\n // there, so it is compared as the string the attribute holds.\n const key = String(data[keyColumn]);\n let row = shown.get(key);\n const fresh = row === undefined;\n if (!row) {\n // Imported rather than cloned: template content belongs to a document\n // with no custom element definitions, so a clone would not upgrade\n // until inserted, and a form-associated control would be filled as if\n // it were not one.\n row = el.ownerDocument.importNode(\n template.content.firstElementChild!,\n true,\n );\n row.setAttribute(ATTR_KEY_VALUE, key);\n shown.set(key, row);\n }\n // Fill before insertion. The attributes are already there when the row\n // upgrades, which is the same thing that makes a first landing and a\n // refresh one operation everywhere else.\n applyRow(row, data, true);\n if (fresh || whole) place(row, data);\n return key;\n };\n\n if (Array.isArray(result)) {\n const arrived = new Set<string>();\n for (const data of result) {\n const key = upsert(data);\n if (key !== null) arrived.add(key);\n }\n for (const [key, row] of shown) if (!arrived.has(key)) row.remove();\n } else {\n for (const data of result.rows ?? []) upsert(data);\n for (const key of result.drop ?? []) shown.get(String(key))?.remove();\n }\n\n // Counted from the DOM rather than from either branch above, so all rows\n // and a patch report the same fact the same way. Only here is the count\n // known: the server answers with rows and says nothing about how many\n // survived reconciliation.\n el.setAttribute(ATTR_QUERY_ROW_COUNT, String(showing(el).size));\n\n // Derived scaffolding — a section heading, an <optgroup> — goes when its\n // last row does, and only the custom element knows it exists.\n host.lbRowsLanded?.();\n}\n\n/** Land one response item on one element that names its query. */\nfunction landItem(el: Element, item: ResponseItem): void {\n const template = templateIn(el);\n if (item.kind === KIND_ROW) {\n const row = item.row ?? {};\n if (template) {\n applyRows(el, template, item.key, [row]);\n return;\n }\n applyRow(el, row);\n const key = row[item.key];\n if (key !== undefined && key !== null) {\n el.setAttribute(ATTR_KEY_VALUE, String(key));\n }\n return;\n }\n // A `rows` query with no row template lands nothing: an insert form names\n // the query it adds to, and shows none of its rows.\n if (!template) return;\n const result = item.patch ?? item.rows ?? [];\n applyRows(el, template, item.key, result);\n}\n\n/**\n * Land response items. Every answer arrives through here.\n *\n * `quiet` names queries that may have nowhere to land without a warning: the\n * hub's own `lb-url` lands wherever a chrome or page names it, and nowhere\n * otherwise.\n */\nexport function applyResponse(\n root: ParentNode,\n items: ResponseItem[],\n quiet: readonly string[] = [],\n): void {\n for (const item of items) {\n const targets = everywhere(root, `[${ATTR_QUERY}=\"${item.query}\"]`);\n if (targets.length === 0) {\n if (!quiet.includes(item.query)) {\n console.warn(`lb-hub: nothing names '${item.query}', skipping`);\n }\n continue;\n }\n for (const el of targets) landItem(el, item);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lb-apply.js","sourceRoot":"","sources":["../../hub/lb-apply.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,QAAQ,EACR,QAAQ,GACT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,OAAO,GAKR,MAAM,qBAAqB,CAAC;AAE7B,6DAA6D;AAC7D,MAAM,MAAM,GAAG,YAAY,SAAS,GAAG,CAAC;AAExC,kFAAkF;AAClF,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,0EAA0E;AAC1E,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAOtD;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,EAAW;IAClC,IAAI,EAAE,CAAC,SAAS,KAAK,QAAQ,IAAI,EAAE,CAAC,SAAS,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC1E,OAAO,CACL,EAAE,CAAC,SAAS,KAAK,OAAO;QACxB,CAAC,eAAe,CAAC,QAAQ,CAAE,EAAuB,CAAC,IAAI,CAAC,CACzD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAAW;IAC1C,MAAM,IAAI,GAAG,EAAE,CAAC,WAA2C,CAAC;IAC5D,OAAO,IAAI,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,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO;IACT,CAAC;IACD,0EAA0E;IAC1E,oDAAoD;IACpD,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;IAC7C,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAgB,EAChB,KAAqB,EACrB,QAA2B,EAAE;IAE7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,UAAU,KAAK,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QACpE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,OAAO,CAAC,IAAI,CAAC,0BAA0B,IAAI,CAAC,KAAK,aAAa,CAAC,CAAC;YAClE,CAAC;YACD,SAAS;QACX,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,OAAO;YAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;AACH,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\n/**\n * Landing — see docs/reference/data-binding.md.\n *\n * The hub lands a response item's rows on every element whose `lb-query`\n * names its query. The item says the query's kind and key, so the markup\n * says neither:\n *\n * kind row template the hub\n * row no lands the row on the element itself\n * row yes lands one live row\n * rows yes lands one live row per row\n * rows no lands nothing\n *\n * Filling a live row and filling an element a `row` lands on are the same\n * operation, and the only difference is how much of the page the root\n * covers.\n *\n * A condition is the one other thing landing moves. An element whose\n * `lb-show` column is off stands in the document inside a template, and\n * landing reaches in there as it reaches everywhere else, so a branch that\n * returns is already current. Nothing but landing reaches in.\n */\n\nimport {\n ATTR_COLUMN,\n ATTR_COLUMN_VALUE,\n ATTR_KEY_VALUE,\n ATTR_QUERY,\n ATTR_QUERY_ROW_COUNT,\n ATTR_ROW_LIVE,\n ATTR_SHOW,\n KIND_ROW,\n LIVE_ROW,\n} from \"../core/lb-constants.js\";\nimport {\n isPatch,\n type ResponseItem,\n type Row,\n type RowsHost,\n type RowsResult,\n} from \"../core/lb-types.js\";\n\n/** The template holding an absent branch — see ATTR_SHOW. */\nconst PARKED = `template[${ATTR_SHOW}]`;\n\n/** A DocumentFragment's nodeType. Tier 3 has no `Node` global to read it from. */\nconst FRAGMENT_NODE = 11;\n\n/** The input types whose state is not their `value`, or cannot be set. */\nconst UNLANDED_INPUTS = [\"checkbox\", \"radio\", \"file\"];\n\n/** A control's value, whether it is native or a custom element. */\nexport interface Control extends Element {\n value: string;\n}\n\n/**\n * A native control whose state is its `value`: a `<select>`, a\n * `<textarea>`, or an `<input>` of any type but checkbox, radio and file.\n *\n * Told apart by tag name and type rather than by class, so it holds for an\n * element from any document.\n */\nfunction isNativeControl(el: Element): boolean {\n if (el.localName === \"select\" || el.localName === \"textarea\") return true;\n return (\n el.localName === \"input\" &&\n !UNLANDED_INPUTS.includes((el as HTMLInputElement).type)\n );\n}\n\n/**\n * A form-associated custom element with a `value` property. HTML marks one\n * with `static formAssociated = true` on its class, and a control has a value.\n */\nexport function isFormAssociated(el: Element): boolean {\n const ctor = el.constructor as { formAssociated?: unknown };\n return ctor.formAssociated === true && \"value\" in el;\n}\n\n/**\n * A control: an `<input>`, `<select>` or `<textarea>`, or a form-associated\n * custom element with a `value` property. Landing and gathering draw the\n * same line, so a value read back is the one that landed there.\n */\nexport function isControl(el: Element): el is Control {\n return isNativeControl(el) || isFormAssociated(el);\n}\n\n/**\n * Set an element from a column. A control's `value` is set. A custom element\n * that is not a control keeps its content, which the builder placed there\n * from its element file, and renders the stamp instead. Any other element's\n * text content is set. Every one carries the value as `lb-column-value`.\n */\nfunction land(el: Element, value: unknown): void {\n // Untouched, whatever the server sent: the browser decides what a\n // non-string looks like. See Row in core/lb-types.ts.\n if (value === null || value === undefined) {\n if (isControl(el)) el.value = \"\";\n else if (!el.localName.includes(\"-\") && el.localName !== \"input\") {\n el.textContent = \"\";\n }\n el.removeAttribute(ATTR_COLUMN_VALUE);\n return;\n }\n if (isControl(el)) {\n el.value = value as string;\n } else if (el.localName === \"input\") {\n console.warn(\n `lb-hub: a value does not land on <input type=\"${(el as HTMLInputElement).type}\">, ignoring`,\n el,\n );\n return;\n } else if (!el.localName.includes(\"-\")) {\n el.textContent = value as string;\n }\n el.setAttribute(ATTR_COLUMN_VALUE, value as string);\n}\n\n/**\n * Whether an element under `root` belongs to root's query, rather than to a\n * query nested inside it.\n *\n * A descendant is root's unless something between it and root carries\n * `lb-query`. The element's own `lb-query` does not count: it names what the\n * element holds, and the row it reads from is its ancestors'. So a picker\n * carrying `lb-query` and `lb-column` is set from the row around it. Root's\n * own attribute does not count either: root is what is being filled.\n *\n * Root may be the content of a template holding an absent branch. The walk\n * up from an element inside it stops at the top of that content, which has\n * no parent, and the template it stands for was in scope already.\n */\nfunction inScope(root: Element | DocumentFragment, el: Element): boolean {\n for (let node = el.parentElement; node && node !== root;) {\n if (node.hasAttribute(ATTR_QUERY)) return false;\n node = node.parentElement;\n }\n return true;\n}\n\n/**\n * Root if it matches, then every descendant in root's query that does.\n * Gathering finds columns through here. It does not reach into an absent\n * branch, so a live row is read back from the places a row lands that are\n * showing.\n */\nexport function within(root: Element, selector: string): Element[] {\n const found: Element[] = root.matches(selector) ? [root] : [];\n for (const el of root.querySelectorAll(selector)) {\n if (inScope(root, el)) found.push(el);\n }\n return found;\n}\n\n/**\n * Every descendant in root's query that matches, absent branches included.\n *\n * `querySelectorAll` does not enter template content, so an element that is\n * off would otherwise miss everything landed while it was away, and return\n * stale or with its rows empty. A template holding one is in root's query by\n * the ordinary rule, and its content is searched as if it stood there.\n */\nfunction below(root: Element | DocumentFragment, selector: string): Element[] {\n const found: Element[] = [];\n for (const el of root.querySelectorAll(selector)) {\n if (inScope(root, el)) found.push(el);\n }\n for (const parked of root.querySelectorAll(PARKED)) {\n if (inScope(root, parked)) {\n found.push(...below((parked as HTMLTemplateElement).content, selector));\n }\n }\n return found;\n}\n\n/**\n * Every element in root that matches, absent branches included. A query is\n * looked up this way before any row is known, so nothing is filtered out.\n */\nfunction everywhere(root: ParentNode, selector: string): Element[] {\n const found = [...root.querySelectorAll(selector)];\n for (const parked of root.querySelectorAll(PARKED)) {\n const content = (parked as HTMLTemplateElement).content;\n found.push(...everywhere(content, selector));\n }\n return found;\n}\n\n/**\n * Put an element in the document or take it out, as its `lb-show` column\n * says.\n *\n * Off is inside a template that stands where the element stood, carrying the\n * same `lb-show`. The element is moved rather than rebuilt, so a custom\n * element keeps its instance and a control keeps what was typed into it. On\n * moves it back and the template goes.\n *\n * Landing reaches into that template, so both it and the element it holds\n * arrive here. The template decides; the element it holds, whose parent is\n * the template's content, is left to it.\n */\nfunction present(el: Element, on: boolean): void {\n if (el.localName === \"template\") {\n const branch = (el as HTMLTemplateElement).content.firstElementChild;\n if (on && branch) el.replaceWith(branch);\n return;\n }\n if (on || el.parentNode?.nodeType === FRAGMENT_NODE) return;\n const parked = el.ownerDocument.createElement(\"template\");\n parked.setAttribute(ATTR_SHOW, el.getAttribute(ATTR_SHOW)!);\n el.replaceWith(parked);\n parked.content.append(el);\n}\n\n/**\n * Fill from one row: every `lb-column` and `lb-show` in root's query.\n *\n * A live row is its own row, so its root counts when it carries\n * `lb-column`: `<option>`'s content model is text, so an option row has to\n * be the column it displays. An element a `row` lands on is not its own\n * ancestor, so its own `lb-column` reads from the row around it and is left\n * alone here.\n */\nexport function applyRow(root: Element, row: Row, liveRow = false): void {\n for (const [column, value] of Object.entries(row)) {\n const selector = `[${ATTR_COLUMN}=\"${column}\"]`;\n const columns = below(root, selector);\n if (liveRow && root.matches(selector)) columns.unshift(root);\n for (const el of columns) land(el, value);\n // Only null and false are off. A string is never read, so \"false\" is on,\n // and the query spells a condition as a boolean or a null.\n //\n // Never the root's own: a row template's root carries none, and the\n // element a row lands on reads its condition from the row around it.\n const on = value !== null && value !== false;\n for (const el of below(root, `[${ATTR_SHOW}=\"${column}\"]`)) {\n present(el, on);\n }\n }\n}\n\n/**\n * The row template: the first `<template>` among the element's descendants,\n * outside any nested `lb-query`. A template holding an absent branch is not a\n * row template: rows land before the row template, so one inside the first\n * live row comes first in document order.\n */\nexport function templateIn(el: Element): HTMLTemplateElement | null {\n const template = within(el, `template:not([${ATTR_SHOW}])`).find(\n (t) => t !== el,\n );\n return (template as HTMLTemplateElement | undefined) ?? null;\n}\n\n/**\n * The live rows of the element's query, in document order. A row of a nested\n * query is that query's. An element a `row` query landed on carries a key and\n * is not a live row, so a `row` shown in a table's head or foot is not one of\n * the table's rows.\n */\nfunction liveRows(el: Element): Element[] {\n return [...el.querySelectorAll(LIVE_ROW)].filter((row) => inScope(el, row));\n}\n\n/**\n * The live rows already showing, by the key each carries. Two live rows with\n * one key are a mistake nothing downstream can recover from: only one of them\n * would ever be matched, and the other would stay until the page goes.\n */\nfunction showing(el: Element): Map<string, Element> {\n const rows = new Map<string, Element>();\n for (const row of liveRows(el)) {\n const key = row.getAttribute(ATTR_KEY_VALUE)!;\n if (rows.has(key)) {\n console.error(\n `lb-hub: <${el.localName}> shows two rows with the key '${key}'`,\n );\n }\n rows.set(key, row);\n }\n return rows;\n}\n\n/**\n * Land rows through a row template.\n *\n * All rows decide membership and order: every row is placed in the order\n * given, and a row whose key did not arrive is gone. A patch disturbs only\n * what it names — a row it did not mention keeps its contents and its\n * position.\n *\n * A custom element that carries `lbPlaceRow` decides where a row goes,\n * because only it knows whether it sorts or groups. Without it a row lands\n * immediately before the template, so rows accumulate in the order they\n * arrive and the template stays put as the insertion marker.\n */\nexport function applyRows(\n el: Element,\n template: HTMLTemplateElement,\n keyColumn: string,\n result: RowsResult,\n): void {\n const shown = showing(el);\n const host = el as Element & RowsHost;\n const whole = !isPatch(result);\n const landed = new Set<string>();\n\n const place = (row: Element, data: Row): void => {\n if (host.lbPlaceRow) host.lbPlaceRow(row, data, template);\n else template.parentElement!.insertBefore(row, template);\n };\n\n const upsert = (data: Row): void => {\n if (data[keyColumn] === undefined) {\n console.error(\n `lb-hub: a row for <${el.localName}> has no '${keyColumn}' column`,\n );\n return;\n }\n // The key is stored on the row as an attribute and read back from\n // there, so it is compared as the string the attribute holds.\n const key = String(data[keyColumn]);\n if (landed.has(key)) {\n console.error(\n `lb-hub: two rows for <${el.localName}> have the key '${key}'; ` +\n `the last one shows`,\n );\n }\n landed.add(key);\n let row = shown.get(key);\n const fresh = row === undefined;\n if (!row) {\n // Imported rather than cloned: template content belongs to a document\n // with no custom element definitions, so a clone would not upgrade\n // until inserted, and a form-associated control would be filled as if\n // it were not one.\n row = el.ownerDocument.importNode(\n template.content.firstElementChild!,\n true,\n );\n row.setAttribute(ATTR_ROW_LIVE, \"\");\n row.setAttribute(ATTR_KEY_VALUE, key);\n shown.set(key, row);\n }\n // Fill before insertion. The attributes are already there when the row\n // upgrades, which is the same thing that makes a first landing and a\n // refresh one operation everywhere else.\n applyRow(row, data, true);\n if (fresh || whole) place(row, data);\n };\n\n if (Array.isArray(result)) {\n for (const data of result) upsert(data);\n for (const [key, row] of shown) if (!landed.has(key)) row.remove();\n } else {\n for (const data of result.rows ?? []) upsert(data);\n for (const key of result.drop ?? []) shown.get(String(key))?.remove();\n }\n\n // Counted from the DOM rather than from either branch above, so all rows\n // and a patch report the same fact the same way. Only here is the count\n // known: the server answers with rows and says nothing about how many\n // survived reconciliation.\n el.setAttribute(ATTR_QUERY_ROW_COUNT, String(liveRows(el).length));\n\n // Derived scaffolding — a section heading, an <optgroup> — goes when its\n // last row does, and only the custom element knows it exists.\n host.lbRowsLanded?.();\n}\n\n/** Land one response item on one element that names its query. */\nfunction landItem(el: Element, item: ResponseItem): void {\n const template = templateIn(el);\n if (item.kind === KIND_ROW) {\n const row = item.row ?? {};\n if (template) {\n applyRows(el, template, item.key, [row]);\n return;\n }\n applyRow(el, row);\n const key = row[item.key];\n if (key !== undefined && key !== null) {\n el.setAttribute(ATTR_KEY_VALUE, String(key));\n }\n return;\n }\n // A `rows` query with no row template lands nothing: an insert form names\n // the query it adds to, and shows none of its rows.\n if (!template) return;\n const result = item.patch ?? item.rows ?? [];\n applyRows(el, template, item.key, result);\n}\n\n/**\n * Land response items. Every answer arrives through here.\n *\n * `quiet` names queries that may have nowhere to land without a warning: the\n * hub's own `lb-url` lands wherever a chrome or page names it, and nowhere\n * otherwise.\n */\nexport function applyResponse(\n root: ParentNode,\n items: ResponseItem[],\n quiet: readonly string[] = [],\n): void {\n for (const item of items) {\n const targets = everywhere(root, `[${ATTR_QUERY}=\"${item.query}\"]`);\n if (targets.length === 0) {\n if (!quiet.includes(item.query)) {\n console.warn(`lb-hub: nothing names '${item.query}', skipping`);\n }\n continue;\n }\n for (const el of targets) landItem(el, item);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-hub.browser.d.ts","sourceRoot":"","sources":["../../hub/lb-hub.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lb-hub.browser.d.ts","sourceRoot":"","sources":["../../hub/lb-hub.browser.ts"],"names":[],"mappings":"AA+CA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
import { ATTR_COLUMN, ATTR_COLUMN_VALUE, ATTR_KEY_VALUE, ATTR_PAGE, ATTR_PAGE_TITLE, ATTR_QUERY, ATTR_REQUEST, ATTR_REQUEST_ERROR, ATTR_REQUEST_PENDING, ATTR_URL_LINK, ATTR_URL_PUSH, ATTR_URL_UNKNOWN, HUB_TAG_NAME, KIND_ROW, LB_ENDPOINT, LB_EVENT_NAME, LB_REQUEST_TIMEOUT_MS, LB_RESERVED_PREFIX, REQUEST_ROW_DELETE, REQUEST_ROW_INSERT, REQUEST_ROW_UPDATE, URL_COLUMN_PAGE_LABEL, URL_COLUMN_PAGE_UNKNOWN, URL_COLUMN_PATH, URL_QUERY, } from "../core/lb-constants.js";
|
|
2
|
+
import { ATTR_COLUMN, ATTR_COLUMN_VALUE, ATTR_KEY_VALUE, ATTR_PAGE, ATTR_PAGE_TITLE, ATTR_QUERY, ATTR_REQUEST, ATTR_REQUEST_ERROR, ATTR_REQUEST_PENDING, ATTR_URL_LINK, ATTR_URL_PUSH, ATTR_URL_UNKNOWN, HUB_TAG_NAME, KIND_ROW, LB_ENDPOINT, LB_EVENT_NAME, LB_REQUEST_TIMEOUT_MS, LB_RESERVED_PREFIX, LIVE_ROW, REQUEST_ROW_DELETE, REQUEST_ROW_INSERT, REQUEST_ROW_UPDATE, URL_COLUMN_PAGE_LABEL, URL_COLUMN_PAGE_UNKNOWN, URL_COLUMN_PATH, URL_QUERY, } from "../core/lb-constants.js";
|
|
3
3
|
import { isRowRequest, nextLocation, pageNameFor, } from "../core/lb-types.js";
|
|
4
4
|
import { applyResponse, isControl, isFormAssociated, within, } from "./lb-apply.js";
|
|
5
5
|
export { applyResponse, applyRow } from "./lb-apply.js";
|
|
@@ -13,11 +13,6 @@ const NEEDS = {
|
|
|
13
13
|
function queryOf(el) {
|
|
14
14
|
return el.parentElement?.closest(`[${ATTR_QUERY}]`) ?? null;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* A live row: an element the hub cloned from a row template. It carries a
|
|
18
|
-
* key and no `lb-query`; an element a `row` lands on carries both.
|
|
19
|
-
*/
|
|
20
|
-
const LIVE_ROW = `[${ATTR_KEY_VALUE}]:not([${ATTR_QUERY}])`;
|
|
21
16
|
/** The live row an element is, or is in. */
|
|
22
17
|
function liveRowOf(el) {
|
|
23
18
|
return el.closest(LIVE_ROW);
|
|
@@ -33,7 +28,11 @@ function keyFrom(el, query) {
|
|
|
33
28
|
: el.parentElement?.closest(`[${ATTR_KEY_VALUE}]`);
|
|
34
29
|
if (!row)
|
|
35
30
|
return undefined;
|
|
36
|
-
|
|
31
|
+
// A live row's key is its outer query's, even when the row names a query
|
|
32
|
+
// of its own. Any other element's key is its own query's.
|
|
33
|
+
const ofQuery = row.matches(LIVE_ROW)
|
|
34
|
+
? queryOf(row) === query
|
|
35
|
+
: row === query;
|
|
37
36
|
return ofQuery ? (row.getAttribute(ATTR_KEY_VALUE) ?? undefined) : undefined;
|
|
38
37
|
}
|
|
39
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lb-hub.browser.js","sourceRoot":"","sources":["../../hub/lb-hub.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,eAAe,EACf,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,GAKZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,MAAM,GAEP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAExD,oEAAoE;AACpE,MAAM,KAAK,GAAkD;IAC3D,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IACzC,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;IAChD,CAAC,kBAAkB,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VALUE,\n ATTR_KEY_VALUE,\n ATTR_PAGE,\n ATTR_PAGE_TITLE,\n ATTR_QUERY,\n ATTR_REQUEST,\n ATTR_REQUEST_ERROR,\n ATTR_REQUEST_PENDING,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n HUB_TAG_NAME,\n KIND_ROW,\n LB_ENDPOINT,\n LB_EVENT_NAME,\n LB_REQUEST_TIMEOUT_MS,\n LB_RESERVED_PREFIX,\n REQUEST_ROW_DELETE,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n URL_COLUMN_PAGE_LABEL,\n URL_COLUMN_PAGE_UNKNOWN,\n URL_COLUMN_PATH,\n URL_QUERY,\n} from \"../core/lb-constants.js\";\nimport {\n isRowRequest,\n nextLocation,\n pageNameFor,\n type HubRequest,\n type HubResponse,\n type ResponseItem,\n type Row,\n} from \"../core/lb-types.js\";\nimport {\n applyResponse,\n isControl,\n isFormAssociated,\n within,\n type Control,\n} from \"./lb-apply.js\";\n\nexport { applyResponse, applyRow } from \"./lb-apply.js\";\n\n/** What each request Loadbare provides cannot be issued without. */\nconst NEEDS: Record<string, readonly (keyof HubRequest)[]> = {\n [REQUEST_ROW_INSERT]: [\"query\", \"values\"],\n [REQUEST_ROW_UPDATE]: [\"query\", \"key\", \"values\"],\n [REQUEST_ROW_DELETE]: [\"query\", \"key\"],\n};\n\n/** The nearest ancestor carrying `lb-query`. An element is not its own. */\nfunction queryOf(el: Element): Element | null {\n return el.parentElement?.closest(`[${ATTR_QUERY}]`) ?? null;\n}\n\n/**\n * A live row: an element the hub cloned from a row template. It carries a\n * key and no `lb-query`; an element a `row` lands on carries both.\n */\nconst LIVE_ROW = `[${ATTR_KEY_VALUE}]:not([${ATTR_QUERY}])`;\n\n/** The live row an element is, or is in. */\nfunction liveRowOf(el: Element): Element | null {\n return el.closest(LIVE_ROW);\n}\n\n/**\n * The key of the nearest ancestor row, when that row is of `query`: a live\n * row whose query it is, or the element a `row` of it landed on.\n */\nfunction keyFrom(el: Element, query: Element): string | undefined {\n // A live row is its own row; any other element's row is an ancestor.\n const row = el.matches(LIVE_ROW)\n ? el\n : el.parentElement?.closest(`[${ATTR_KEY_VALUE}]`);\n if (!row) return undefined;\n const ofQuery = row === query || queryOf(row) === query;\n return ofQuery ? (row.getAttribute(ATTR_KEY_VALUE) ?? undefined) : undefined;\n}\n\n/**\n * Every control whose form owner is `form`: HTML's own list, which holds a\n * control nested in the form or joined to it by the `form` attribute, and a\n * form-associated custom element as well as a native control.\n */\nfunction controlsOf(form: HTMLFormElement): Element[] {\n return [...(form.elements as unknown as Iterable<Element>)];\n}\n\n/**\n * The form owner of an element that has one, as HTML reports it on the\n * element's `form` property.\n */\nfunction formOwnerOf(el: Element): HTMLFormElement | null {\n const owner = (el as { form?: unknown }).form;\n return owner && (owner as Element).localName === \"form\"\n ? (owner as HTMLFormElement)\n : null;\n}\n\n/** The group a request gathers from. */\ninterface Group {\n controls: Element[];\n /** Set when the group is a form, so a successful insert resets it. */\n form?: HTMLFormElement;\n /** What the group is: the form or the live row. */\n root: Element;\n}\n\n/**\n * The controls a request gathers — see docs/reference/data-binding.md,\n * \"Gathering\":\n *\n * 1. the element carrying `lb-request` has `lb-column`: it alone;\n * 2. the element is a `<form>`: the controls whose form owner it is;\n * 3. the element is in a live row: the controls in that live row;\n * 4. otherwise: the controls whose form owner is the element's.\n *\n * A control whose nearest `lb-query` is inside the group belongs to a query\n * nested in it, and is skipped.\n */\nfunction groupFor(el: Element): Group | null {\n if (el.hasAttribute(ATTR_COLUMN)) return { controls: [el], root: el };\n if (el.localName === \"form\") {\n const form = el as HTMLFormElement;\n return { controls: controlsOf(form), form, root: form };\n }\n const live = liveRowOf(el);\n if (live) return { controls: within(live, `[${ATTR_COLUMN}]`), root: live };\n const form = formOwnerOf(el);\n if (form) return { controls: controlsOf(form), form, root: form };\n return null;\n}\n\n/** The gathered controls, with their values under their columns. */\nfunction gather(group: Group | null): {\n controls: Control[];\n values: Record<string, string>;\n} {\n const controls: Control[] = [];\n const values: Record<string, string> = {};\n for (const el of group?.controls ?? []) {\n const column = el.getAttribute(ATTR_COLUMN);\n if (column === null || !isControl(el)) continue;\n const nested = queryOf(el);\n if (nested && nested !== group!.root && group!.root.contains(nested)) {\n continue;\n }\n controls.push(el);\n values[column] = el.value;\n }\n return { controls, values };\n}\n\n/** The form each insert gathered from, until its round trip succeeds. */\nconst insertedFrom = new WeakMap<HubRequest, HTMLFormElement>();\n\n/**\n * Complete a request from where its element sits. Every request passes\n * through here, whoever issued it; a field it already carries is its\n * issuer's to decide and is left as it is.\n *\n * False when the request cannot be issued, having said why.\n */\nfunction complete(request: HubRequest | undefined, el: Element): boolean {\n if (!request?.name) {\n console.warn(`lb-hub: a request without a name, ignoring`, request);\n return false;\n }\n const { name } = request;\n if (name.startsWith(LB_RESERVED_PREFIX) && !isRowRequest(name)) {\n console.error(\n `lb-hub: '${name}' begins with '${LB_RESERVED_PREFIX}' but names no ` +\n `request Loadbare provides, ignoring`,\n );\n return false;\n }\n\n const group = groupFor(el);\n const { controls, values } = gather(group);\n if (request.values === undefined && controls.length > 0) {\n request.values = values;\n }\n\n // The request is for the nearest `lb-query` of what it gathered, or of the\n // element itself when it gathered nothing.\n const queries = new Set(controls.map(queryOf));\n if (queries.size > 1) {\n console.error(\n `lb-hub: '${name}' gathered controls of more than one query, not sent`,\n el,\n );\n return false;\n }\n const from = controls[0] ?? el;\n const query = controls.length > 0 ? [...queries][0]! : queryOf(el);\n if (query) {\n request.query ??= query.getAttribute(ATTR_QUERY)!;\n const key = keyFrom(from, query);\n if (key !== undefined) request.key ??= key;\n }\n\n if (name === REQUEST_ROW_INSERT && group?.form) {\n insertedFrom.set(request, group.form);\n }\n\n const needs = NEEDS[name];\n if (needs) {\n const missing = needs.filter(\n (field) =>\n request[field] === undefined ||\n (field === \"values\" && Object.keys(request.values!).length === 0),\n );\n if (missing.length > 0) {\n console.error(\n `lb-hub: '${name}' from <${el.localName}> has no ` +\n `${missing.join(\", \")}, not sent`,\n el,\n );\n return false;\n }\n }\n return true;\n}\n\n/**\n * Commit: dispatch the request an element names, for the hub to complete. A\n * commit on an element whose round trip is in flight is ignored.\n */\nfunction commit(el: Element): void {\n if (el.hasAttribute(ATTR_REQUEST_PENDING)) return;\n const detail: HubRequest = { name: el.getAttribute(ATTR_REQUEST)! };\n el.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));\n}\n\n/** A submit button with a form owner commits with its form, never on click. */\nfunction isSubmitButton(el: Element): boolean {\n const type = (el as HTMLInputElement).type as string;\n const submits =\n (el.localName === \"button\" && type === \"submit\") ||\n (el.localName === \"input\" && (type === \"submit\" || type === \"image\"));\n return submits && formOwnerOf(el) !== null;\n}\n\n/**\n * HTML's interactive content: elements a click already means something to.\n * HTML forbids nesting them inside `<a>` or `<button>` so a click means one\n * thing, and the hub draws the same line.\n */\nconst INTERACTIVE = [\n \"a[href]\",\n \"button\",\n \"input:not([type=hidden])\",\n \"select\",\n \"textarea\",\n \"label\",\n \"details\",\n \"iframe\",\n \"embed\",\n \"audio[controls]\",\n \"video[controls]\",\n \"img[usemap]\",\n].join(\", \");\n\n/**\n * Whether a click on `target` is the click of `el`, the element carrying\n * `lb-request` above it: no interactive content lies between them. A click on\n * a control, link or button inside `el` belongs to that element.\n */\nfunction clicks(target: Element, el: Element): boolean {\n for (let node: Element | null = target; node && node !== el;) {\n if (node.matches(INTERACTIVE) || isFormAssociated(node)) return false;\n node = node.parentElement;\n }\n return true;\n}\n\n/** The page file's title, or its stub when it has none. */\nfunction titleOf(template: HTMLTemplateElement | null, page: string): string {\n return template?.getAttribute(ATTR_PAGE_TITLE) || page;\n}\n\n/**\n * The `<template>` a page ships in. The builder guarantees one per stub\n * (build/locations.ts refuses two page files sharing one), so a second match\n * here means the document was assembled by something else.\n */\nfunction pageHostFor(page: string): HTMLTemplateElement | null {\n const hosts: HTMLTemplateElement[] = [];\n for (const el of document.querySelectorAll(`template[${ATTR_PAGE}]`)) {\n if (el.getAttribute(ATTR_PAGE) === page) {\n hosts.push(el as HTMLTemplateElement);\n }\n }\n if (hosts.length > 1) {\n console.error(\n `lb-hub: ${hosts.length} pages carry ${ATTR_PAGE}=\"${page}\", ` +\n `using the first`,\n );\n }\n return hosts[0] ?? null;\n}\n\n/**\n * One round trip against the client-side deadline. Throws on a non-ok\n * response, a network failure or a timeout, so a caller can tell a failed\n * request from an empty answer.\n *\n * The stub names the path below the endpoint and the query string the\n * browser is showing rides after it verbatim, so every round trip reaches\n * the server with the query parms in hand.\n */\nasync function fetchItems(\n page: string,\n request?: HubRequest,\n): Promise<HubResponse> {\n const path = page.split(\"/\").map(encodeURIComponent).join(\"/\");\n const url = `${LB_ENDPOINT}/${path}${location.search}`;\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), LB_REQUEST_TIMEOUT_MS);\n try {\n // An empty body is how the hub asks for the page's queries.\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(request ?? {}),\n signal: controller.signal,\n });\n if (!res.ok) {\n throw new Error(`lb-hub: server responded ${res.status} for ${url}`);\n }\n return (await res.json()) as HubResponse;\n } finally {\n clearTimeout(timeout);\n }\n}\n\n/** An element's round trip is in flight, or is not. */\nfunction pending(el: Element | undefined, on: boolean): void {\n if (!el) return;\n if (on) {\n el.removeAttribute(ATTR_REQUEST_ERROR);\n el.setAttribute(ATTR_REQUEST_PENDING, \"\");\n el.setAttribute(\"aria-busy\", \"true\");\n } else {\n el.removeAttribute(ATTR_REQUEST_PENDING);\n el.removeAttribute(\"aria-busy\");\n }\n}\n\n/** A plain primary click: no other button, no modifier, not yet handled. */\nfunction isPlainClick(e: MouseEvent): boolean {\n return (\n e.button === 0 &&\n !e.defaultPrevented &&\n !e.metaKey &&\n !e.ctrlKey &&\n !e.shiftKey &&\n !e.altKey\n );\n}\n\n/** The URL a row for `lb-url` leads to, by the rule the server follows. */\nfunction nextUrl(row: Row): { url: URL; moved: boolean } {\n const url = new URL(location.href);\n const next = nextLocation(pageNameFor(url.pathname), url.searchParams, row);\n const path = row[URL_COLUMN_PATH];\n if (typeof path === \"string\") url.pathname = path;\n url.search = next.parms.toString();\n return { url, moved: next.moved };\n}\n\n/**\n * The hub is a singleton outside <main>. It survives every page change,\n * so it needs no id to disambiguate it.\n */\nclass LbHub extends HTMLElement {\n private main!: HTMLElement;\n\n /**\n * The stub of the page in <main>. A page declares its own requests, so a\n * request says which page it came from, on the path below the endpoint.\n */\n private page = \"\";\n\n connectedCallback() {\n this.main = this.querySelector(\"main\")!;\n\n // Completed in the capture phase, on the way down, so every ancestor\n // that sees the request on its way back up sees it whole. A request that\n // cannot be issued is stopped here, before anything sees it at all.\n this.addEventListener(\n LB_EVENT_NAME,\n (e: Event) => {\n const origin = e.target as Element;\n const request = (e as CustomEvent<HubRequest>).detail;\n if (!complete(request, origin)) e.stopPropagation();\n },\n { capture: true },\n );\n\n this.addEventListener(LB_EVENT_NAME, (e: Event) => {\n const request = (e as CustomEvent<HubRequest>).detail;\n // The element that issued the request, not e.currentTarget (the hub\n // itself, since the event bubbles).\n const origin = (e.target as Element | null) ?? undefined;\n if (request.query?.startsWith(LB_RESERVED_PREFIX)) {\n this.answer(request, origin);\n return;\n }\n void this.send(request, origin);\n });\n\n // A form commits on submit. The submitter's own lb-request replaces the\n // form's, the way `formaction` replaces `action`.\n this.addEventListener(\"submit\", (e: SubmitEvent) => {\n const form = e.target as Element | null;\n if (!form) return;\n const submitter = e.submitter;\n const el = submitter?.hasAttribute(ATTR_REQUEST)\n ? submitter\n : form.hasAttribute(ATTR_REQUEST)\n ? form\n : null;\n if (!el) return;\n e.preventDefault();\n commit(el);\n });\n\n // A reset returns a form's controls to their defaults, so none of them\n // shows what landed any longer. The browser resets the controls; the\n // hub drops its own stamp from the same controls a submit gathers.\n this.addEventListener(\"reset\", (e: Event) => {\n if (e.defaultPrevented) return;\n for (const el of controlsOf(e.target as HTMLFormElement)) {\n el.removeAttribute(ATTR_COLUMN_VALUE);\n }\n });\n\n // A control commits on change.\n this.addEventListener(\"change\", (e: Event) => {\n const el = e.target as Element | null;\n if (!el || !el.hasAttribute(ATTR_REQUEST) || !isControl(el)) return;\n commit(el);\n });\n\n // Anything else commits on click. A form commits on submit, a control on\n // change, and a submit button with its form. A click on interactive\n // content inside the element is that content's own.\n this.addEventListener(\"click\", (e: MouseEvent) => {\n const target = e.target as Element | null;\n const el = target?.closest(`[${ATTR_REQUEST}]`);\n if (!target || !el || !this.contains(el)) return;\n if (el.localName === \"form\" || isControl(el) || isSubmitButton(el)) {\n return;\n }\n if (!clicks(target, el)) return;\n e.preventDefault();\n commit(el);\n });\n\n // A link that opted in. Everything else is a real link, and so is a\n // click that opens a new tab or window. The link's URL is a row for\n // lb-url: its path, its query parms, and every other parm emptied. A\n // link pushes a history entry, as a link does.\n this.addEventListener(\"click\", (e: MouseEvent) => {\n const link = (e.target as Element | null)?.closest(`a[${ATTR_URL_LINK}]`);\n if (!link || !isPlainClick(e)) return;\n e.preventDefault();\n const href = new URL((link as HTMLAnchorElement).href);\n const row: Row = {};\n for (const name of new URLSearchParams(location.search).keys()) {\n row[name] = \"\";\n }\n for (const [name, value] of href.searchParams) row[name] = value;\n row[URL_COLUMN_PATH] = href.pathname;\n this.moveTo(row, true);\n void this.navigate();\n });\n\n addEventListener(\"popstate\", () => void this.navigate());\n\n void this.navigate();\n }\n\n /**\n * Send a request to the server and land its answer. An answer naming\n * `lb-url` moves the URL first; the server has already loaded the page\n * there, in the same round trip.\n */\n private async send(request: HubRequest, origin?: Element): Promise<void> {\n const page = this.page;\n const items = await this.roundTrip(page, request, origin);\n if (items === null) return;\n const url = items.find((item) => item.query === URL_QUERY);\n const load = items.filter((item) => item !== url);\n if (url === undefined) applyResponse(this, load);\n else await this.follow(page, url, load, origin);\n insertedFrom.get(request)?.reset();\n }\n\n /**\n * One round trip for a page: a request, or with none a page load. The\n * element that issued it carries `lb-request-pending` while it is in\n * flight, and `lb-request-error` when it fails. Null on failure.\n */\n private async roundTrip(\n page: string,\n request: HubRequest | undefined,\n origin: Element | undefined,\n ): Promise<HubResponse | null> {\n pending(origin, true);\n try {\n return await fetchItems(page, request);\n } catch (err) {\n console.error(`lb-hub: request failed for '${page}'`, err);\n origin?.setAttribute(ATTR_REQUEST_ERROR, \"\");\n return null;\n } finally {\n pending(origin, false);\n }\n }\n\n /**\n * Answer a request for a query the hub serves, with no round trip. The\n * hub serves `lb-url`, and updates it.\n */\n private answer(request: HubRequest, origin?: Element): void {\n if (request.query !== URL_QUERY || request.name !== REQUEST_ROW_UPDATE) {\n console.error(\n `lb-hub: '${request.name}' for '${request.query}' is not a request ` +\n `the hub answers, ignoring`,\n );\n return;\n }\n const pushed = origin?.hasAttribute(ATTR_URL_PUSH) ?? false;\n if (this.moveTo(request.values ?? {}, pushed)) void this.navigate(origin);\n }\n\n /**\n * Write a row for `lb-url` into the URL. A new page pushes a history\n * entry, and so does `push`; a change of query parms replaces the entry.\n * False when the URL is already the row's.\n */\n private moveTo(row: Row, push: boolean): boolean {\n const { url, moved } = nextUrl(row);\n if (url.href === location.href) return false;\n if (moved || push) history.pushState(null, \"\", url);\n else history.replaceState(null, \"\", url);\n return true;\n }\n\n /**\n * A server answer named `lb-url`: write the URL, then land the page the\n * server loaded there. A load that did not come back is asked for again,\n * without marking the element that issued the request: its write\n * succeeded, and an error would invite sending it twice.\n *\n * `page` is where the request was sent from. A user who left it while the\n * request was in flight is on a URL that is not the server's to change.\n */\n private async follow(\n page: string,\n item: ResponseItem,\n load: ResponseItem[],\n origin?: Element,\n ): Promise<void> {\n if (pageNameFor(location.pathname) !== page) return;\n this.moveTo(item.row ?? {}, origin?.hasAttribute(ATTR_URL_PUSH) ?? false);\n if (load.length === 0) return this.navigate();\n const template = this.arrive();\n if (template) applyResponse(this, load);\n }\n\n /**\n * Load the page at the URL the browser is showing. Every way of arriving\n * comes through here — a cold load, a link, Back, a new query parm — so\n * each is the same page load and a URL always shows the same thing.\n *\n * Entering a page is the one operation that replaces what <main> holds.\n * Staying on it, with only the query parms changed, keeps what it has: the\n * queries re-run and land by key, so rows that come back keep their place.\n *\n * `origin` is the element whose request changed the URL, if one did, and\n * carries the round trip's pending and error state.\n */\n private async navigate(origin?: Element): Promise<void> {\n const template = this.arrive();\n if (!template) return;\n const items = await this.roundTrip(this.page, undefined, origin);\n applyResponse(this, items ?? []);\n }\n\n /**\n * Show the page the path names, and land `lb-url`. Null when no page's\n * stub matches the path.\n */\n private arrive(): HTMLTemplateElement | null {\n const page = pageNameFor(location.pathname);\n const template = pageHostFor(page);\n if (template && page !== this.page) {\n this.page = page;\n // The template is already in the document, so the page's markup goes\n // in before its data arrives rather than leaving <main> empty.\n this.main.replaceChildren(template.content.cloneNode(true));\n }\n this.landUrl(template ? titleOf(template, page) : null);\n // An app that ships `<body hidden>` (docs/reference/chrome.md) stays\n // invisible until there is something coherent to show.\n document.body.hidden = false;\n if (!template) {\n console.error(`lb-hub: no page for '${page}'`);\n const dialog = this.querySelector(`dialog[${ATTR_URL_UNKNOWN}]`);\n if (dialog && !(dialog as HTMLDialogElement).open) {\n (dialog as HTMLDialogElement).showModal();\n }\n }\n return template;\n }\n\n /**\n * The hub's own query: one row, keyed by the path, whose other columns are\n * the query parms.\n *\n * The one exception to landing. A row sets the columns it names and\n * leaves the rest as they were, and a URL names only the parms it carries.\n * So the row also names, as empty, every column an element under\n * `lb-query=\"lb-url\"` shows: a control then shows what the address bar\n * says after Back as well as after a reload, and never a parm the URL has\n * dropped.\n */\n private landUrl(label: string | null): void {\n if (label !== null) document.title = label;\n const scopes = this.querySelectorAll(`[${ATTR_QUERY}=\"${URL_QUERY}\"]`);\n if (scopes.length === 0) return;\n const row: Row = {};\n for (const scope of scopes) {\n for (const el of within(scope, `[${ATTR_COLUMN}]`)) {\n if (el === scope) continue;\n row[el.getAttribute(ATTR_COLUMN)!] = \"\";\n }\n }\n for (const [name, value] of new URLSearchParams(location.search)) {\n row[name] = value;\n }\n row[URL_COLUMN_PATH] = location.pathname;\n row[URL_COLUMN_PAGE_LABEL] = label;\n row[URL_COLUMN_PAGE_UNKNOWN] = label === null;\n applyResponse(this, [\n { query: URL_QUERY, kind: KIND_ROW, key: URL_COLUMN_PATH, row },\n ]);\n }\n}\n\ncustomElements.define(HUB_TAG_NAME, LbHub);\n"]}
|
|
1
|
+
{"version":3,"file":"lb-hub.browser.js","sourceRoot":"","sources":["../../hub/lb-hub.browser.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,eAAe,EACf,UAAU,EACV,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,EACvB,eAAe,EACf,SAAS,GACV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,WAAW,GAKZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,MAAM,GAEP,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAExD,oEAAoE;AACpE,MAAM,KAAK,GAAkD;IAC3D,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IACzC,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;IAChD,CAAC,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC;CACvC,CAAC;AAEF,2EAA2E;AAC3E,SAAS,OAAO,CAAC,EAAW;IAC1B,OAAO,EAAE,CAAC,aAAa,EAAE,OAAO,CAA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ST_PENDING,\n ATTR_URL_LINK,\n ATTR_URL_PUSH,\n ATTR_URL_UNKNOWN,\n HUB_TAG_NAME,\n KIND_ROW,\n LB_ENDPOINT,\n LB_EVENT_NAME,\n LB_REQUEST_TIMEOUT_MS,\n LB_RESERVED_PREFIX,\n LIVE_ROW,\n REQUEST_ROW_DELETE,\n REQUEST_ROW_INSERT,\n REQUEST_ROW_UPDATE,\n URL_COLUMN_PAGE_LABEL,\n URL_COLUMN_PAGE_UNKNOWN,\n URL_COLUMN_PATH,\n URL_QUERY,\n} from \"../core/lb-constants.js\";\nimport {\n isRowRequest,\n nextLocation,\n pageNameFor,\n type HubRequest,\n type HubResponse,\n type ResponseItem,\n type Row,\n} from \"../core/lb-types.js\";\nimport {\n applyResponse,\n isControl,\n isFormAssociated,\n within,\n type Control,\n} from \"./lb-apply.js\";\n\nexport { applyResponse, applyRow } from \"./lb-apply.js\";\n\n/** What each request Loadbare provides cannot be issued without. */\nconst NEEDS: Record<string, readonly (keyof HubRequest)[]> = {\n [REQUEST_ROW_INSERT]: [\"query\", \"values\"],\n [REQUEST_ROW_UPDATE]: [\"query\", \"key\", \"values\"],\n [REQUEST_ROW_DELETE]: [\"query\", \"key\"],\n};\n\n/** The nearest ancestor carrying `lb-query`. An element is not its own. */\nfunction queryOf(el: Element): Element | null {\n return el.parentElement?.closest(`[${ATTR_QUERY}]`) ?? null;\n}\n\n/** The live row an element is, or is in. */\nfunction liveRowOf(el: Element): Element | null {\n return el.closest(LIVE_ROW);\n}\n\n/**\n * The key of the nearest ancestor row, when that row is of `query`: a live\n * row whose query it is, or the element a `row` of it landed on.\n */\nfunction keyFrom(el: Element, query: Element): string | undefined {\n // A live row is its own row; any other element's row is an ancestor.\n const row = el.matches(LIVE_ROW)\n ? el\n : el.parentElement?.closest(`[${ATTR_KEY_VALUE}]`);\n if (!row) return undefined;\n // A live row's key is its outer query's, even when the row names a query\n // of its own. Any other element's key is its own query's.\n const ofQuery = row.matches(LIVE_ROW)\n ? queryOf(row) === query\n : row === query;\n return ofQuery ? (row.getAttribute(ATTR_KEY_VALUE) ?? undefined) : undefined;\n}\n\n/**\n * Every control whose form owner is `form`: HTML's own list, which holds a\n * control nested in the form or joined to it by the `form` attribute, and a\n * form-associated custom element as well as a native control.\n */\nfunction controlsOf(form: HTMLFormElement): Element[] {\n return [...(form.elements as unknown as Iterable<Element>)];\n}\n\n/**\n * The form owner of an element that has one, as HTML reports it on the\n * element's `form` property.\n */\nfunction formOwnerOf(el: Element): HTMLFormElement | null {\n const owner = (el as { form?: unknown }).form;\n return owner && (owner as Element).localName === \"form\"\n ? (owner as HTMLFormElement)\n : null;\n}\n\n/** The group a request gathers from. */\ninterface Group {\n controls: Element[];\n /** Set when the group is a form, so a successful insert resets it. */\n form?: HTMLFormElement;\n /** What the group is: the form or the live row. */\n root: Element;\n}\n\n/**\n * The controls a request gathers — see docs/reference/data-binding.md,\n * \"Gathering\":\n *\n * 1. the element carrying `lb-request` has `lb-column`: it alone;\n * 2. the element is a `<form>`: the controls whose form owner it is;\n * 3. the element is in a live row: the controls in that live row;\n * 4. otherwise: the controls whose form owner is the element's.\n *\n * A control whose nearest `lb-query` is inside the group belongs to a query\n * nested in it, and is skipped.\n */\nfunction groupFor(el: Element): Group | null {\n if (el.hasAttribute(ATTR_COLUMN)) return { controls: [el], root: el };\n if (el.localName === \"form\") {\n const form = el as HTMLFormElement;\n return { controls: controlsOf(form), form, root: form };\n }\n const live = liveRowOf(el);\n if (live) return { controls: within(live, `[${ATTR_COLUMN}]`), root: live };\n const form = formOwnerOf(el);\n if (form) return { controls: controlsOf(form), form, root: form };\n return null;\n}\n\n/** The gathered controls, with their values under their columns. */\nfunction gather(group: Group | null): {\n controls: Control[];\n values: Record<string, string>;\n} {\n const controls: Control[] = [];\n const values: Record<string, string> = {};\n for (const el of group?.controls ?? []) {\n const column = el.getAttribute(ATTR_COLUMN);\n if (column === null || !isControl(el)) continue;\n const nested = queryOf(el);\n if (nested && nested !== group!.root && group!.root.contains(nested)) {\n continue;\n }\n controls.push(el);\n values[column] = el.value;\n }\n return { controls, values };\n}\n\n/** The form each insert gathered from, until its round trip succeeds. */\nconst insertedFrom = new WeakMap<HubRequest, HTMLFormElement>();\n\n/**\n * Complete a request from where its element sits. Every request passes\n * through here, whoever issued it; a field it already carries is its\n * issuer's to decide and is left as it is.\n *\n * False when the request cannot be issued, having said why.\n */\nfunction complete(request: HubRequest | undefined, el: Element): boolean {\n if (!request?.name) {\n console.warn(`lb-hub: a request without a name, ignoring`, request);\n return false;\n }\n const { name } = request;\n if (name.startsWith(LB_RESERVED_PREFIX) && !isRowRequest(name)) {\n console.error(\n `lb-hub: '${name}' begins with '${LB_RESERVED_PREFIX}' but names no ` +\n `request Loadbare provides, ignoring`,\n );\n return false;\n }\n\n const group = groupFor(el);\n const { controls, values } = gather(group);\n if (request.values === undefined && controls.length > 0) {\n request.values = values;\n }\n\n // The request is for the nearest `lb-query` of what it gathered, or of the\n // element itself when it gathered nothing.\n const queries = new Set(controls.map(queryOf));\n if (queries.size > 1) {\n console.error(\n `lb-hub: '${name}' gathered controls of more than one query, not sent`,\n el,\n );\n return false;\n }\n const from = controls[0] ?? el;\n const query = controls.length > 0 ? [...queries][0]! : queryOf(el);\n if (query) {\n request.query ??= query.getAttribute(ATTR_QUERY)!;\n const key = keyFrom(from, query);\n if (key !== undefined) request.key ??= key;\n }\n\n if (name === REQUEST_ROW_INSERT && group?.form) {\n insertedFrom.set(request, group.form);\n }\n\n const needs = NEEDS[name];\n if (needs) {\n const missing = needs.filter(\n (field) =>\n request[field] === undefined ||\n (field === \"values\" && Object.keys(request.values!).length === 0),\n );\n if (missing.length > 0) {\n console.error(\n `lb-hub: '${name}' from <${el.localName}> has no ` +\n `${missing.join(\", \")}, not sent`,\n el,\n );\n return false;\n }\n }\n return true;\n}\n\n/**\n * Commit: dispatch the request an element names, for the hub to complete. A\n * commit on an element whose round trip is in flight is ignored.\n */\nfunction commit(el: Element): void {\n if (el.hasAttribute(ATTR_REQUEST_PENDING)) return;\n const detail: HubRequest = { name: el.getAttribute(ATTR_REQUEST)! };\n el.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));\n}\n\n/** A submit button with a form owner commits with its form, never on click. */\nfunction isSubmitButton(el: Element): boolean {\n const type = (el as HTMLInputElement).type as string;\n const submits =\n (el.localName === \"button\" && type === \"submit\") ||\n (el.localName === \"input\" && (type === \"submit\" || type === \"image\"));\n return submits && formOwnerOf(el) !== null;\n}\n\n/**\n * HTML's interactive content: elements a click already means something to.\n * HTML forbids nesting them inside `<a>` or `<button>` so a click means one\n * thing, and the hub draws the same line.\n */\nconst INTERACTIVE = [\n \"a[href]\",\n \"button\",\n \"input:not([type=hidden])\",\n \"select\",\n \"textarea\",\n \"label\",\n \"details\",\n \"iframe\",\n \"embed\",\n \"audio[controls]\",\n \"video[controls]\",\n \"img[usemap]\",\n].join(\", \");\n\n/**\n * Whether a click on `target` is the click of `el`, the element carrying\n * `lb-request` above it: no interactive content lies between them. A click on\n * a control, link or button inside `el` belongs to that element.\n */\nfunction clicks(target: Element, el: Element): boolean {\n for (let node: Element | null = target; node && node !== el;) {\n if (node.matches(INTERACTIVE) || isFormAssociated(node)) return false;\n node = node.parentElement;\n }\n return true;\n}\n\n/** The page file's title, or its stub when it has none. */\nfunction titleOf(template: HTMLTemplateElement | null, page: string): string {\n return template?.getAttribute(ATTR_PAGE_TITLE) || page;\n}\n\n/**\n * The `<template>` a page ships in. The builder guarantees one per stub\n * (build/locations.ts refuses two page files sharing one), so a second match\n * here means the document was assembled by something else.\n */\nfunction pageHostFor(page: string): HTMLTemplateElement | null {\n const hosts: HTMLTemplateElement[] = [];\n for (const el of document.querySelectorAll(`template[${ATTR_PAGE}]`)) {\n if (el.getAttribute(ATTR_PAGE) === page) {\n hosts.push(el as HTMLTemplateElement);\n }\n }\n if (hosts.length > 1) {\n console.error(\n `lb-hub: ${hosts.length} pages carry ${ATTR_PAGE}=\"${page}\", ` +\n `using the first`,\n );\n }\n return hosts[0] ?? null;\n}\n\n/**\n * One round trip against the client-side deadline. Throws on a non-ok\n * response, a network failure or a timeout, so a caller can tell a failed\n * request from an empty answer.\n *\n * The stub names the path below the endpoint and the query string the\n * browser is showing rides after it verbatim, so every round trip reaches\n * the server with the query parms in hand.\n */\nasync function fetchItems(\n page: string,\n request?: HubRequest,\n): Promise<HubResponse> {\n const path = page.split(\"/\").map(encodeURIComponent).join(\"/\");\n const url = `${LB_ENDPOINT}/${path}${location.search}`;\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), LB_REQUEST_TIMEOUT_MS);\n try {\n // An empty body is how the hub asks for the page's queries.\n const res = await fetch(url, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(request ?? {}),\n signal: controller.signal,\n });\n if (!res.ok) {\n throw new Error(`lb-hub: server responded ${res.status} for ${url}`);\n }\n return (await res.json()) as HubResponse;\n } finally {\n clearTimeout(timeout);\n }\n}\n\n/** An element's round trip is in flight, or is not. */\nfunction pending(el: Element | undefined, on: boolean): void {\n if (!el) return;\n if (on) {\n el.removeAttribute(ATTR_REQUEST_ERROR);\n el.setAttribute(ATTR_REQUEST_PENDING, \"\");\n el.setAttribute(\"aria-busy\", \"true\");\n } else {\n el.removeAttribute(ATTR_REQUEST_PENDING);\n el.removeAttribute(\"aria-busy\");\n }\n}\n\n/** A plain primary click: no other button, no modifier, not yet handled. */\nfunction isPlainClick(e: MouseEvent): boolean {\n return (\n e.button === 0 &&\n !e.defaultPrevented &&\n !e.metaKey &&\n !e.ctrlKey &&\n !e.shiftKey &&\n !e.altKey\n );\n}\n\n/** The URL a row for `lb-url` leads to, by the rule the server follows. */\nfunction nextUrl(row: Row): { url: URL; moved: boolean } {\n const url = new URL(location.href);\n const next = nextLocation(pageNameFor(url.pathname), url.searchParams, row);\n const path = row[URL_COLUMN_PATH];\n if (typeof path === \"string\") url.pathname = path;\n url.search = next.parms.toString();\n return { url, moved: next.moved };\n}\n\n/**\n * The hub is a singleton outside <main>. It survives every page change,\n * so it needs no id to disambiguate it.\n */\nclass LbHub extends HTMLElement {\n private main!: HTMLElement;\n\n /**\n * The stub of the page in <main>. A page declares its own requests, so a\n * request says which page it came from, on the path below the endpoint.\n */\n private page = \"\";\n\n connectedCallback() {\n this.main = this.querySelector(\"main\")!;\n\n // Completed in the capture phase, on the way down, so every ancestor\n // that sees the request on its way back up sees it whole. A request that\n // cannot be issued is stopped here, before anything sees it at all.\n this.addEventListener(\n LB_EVENT_NAME,\n (e: Event) => {\n const origin = e.target as Element;\n const request = (e as CustomEvent<HubRequest>).detail;\n if (!complete(request, origin)) e.stopPropagation();\n },\n { capture: true },\n );\n\n this.addEventListener(LB_EVENT_NAME, (e: Event) => {\n const request = (e as CustomEvent<HubRequest>).detail;\n // The element that issued the request, not e.currentTarget (the hub\n // itself, since the event bubbles).\n const origin = (e.target as Element | null) ?? undefined;\n if (request.query?.startsWith(LB_RESERVED_PREFIX)) {\n this.answer(request, origin);\n return;\n }\n void this.send(request, origin);\n });\n\n // A form commits on submit. The submitter's own lb-request replaces the\n // form's, the way `formaction` replaces `action`.\n this.addEventListener(\"submit\", (e: SubmitEvent) => {\n const form = e.target as Element | null;\n if (!form) return;\n const submitter = e.submitter;\n const el = submitter?.hasAttribute(ATTR_REQUEST)\n ? submitter\n : form.hasAttribute(ATTR_REQUEST)\n ? form\n : null;\n if (!el) return;\n e.preventDefault();\n commit(el);\n });\n\n // A reset returns a form's controls to their defaults, so none of them\n // shows what landed any longer. The browser resets the controls; the\n // hub drops its own stamp from the same controls a submit gathers.\n this.addEventListener(\"reset\", (e: Event) => {\n if (e.defaultPrevented) return;\n for (const el of controlsOf(e.target as HTMLFormElement)) {\n el.removeAttribute(ATTR_COLUMN_VALUE);\n }\n });\n\n // A control commits on change.\n this.addEventListener(\"change\", (e: Event) => {\n const el = e.target as Element | null;\n if (!el || !el.hasAttribute(ATTR_REQUEST) || !isControl(el)) return;\n commit(el);\n });\n\n // Anything else commits on click. A form commits on submit, a control on\n // change, and a submit button with its form. A click on interactive\n // content inside the element is that content's own.\n this.addEventListener(\"click\", (e: MouseEvent) => {\n const target = e.target as Element | null;\n const el = target?.closest(`[${ATTR_REQUEST}]`);\n if (!target || !el || !this.contains(el)) return;\n if (el.localName === \"form\" || isControl(el) || isSubmitButton(el)) {\n return;\n }\n if (!clicks(target, el)) return;\n e.preventDefault();\n commit(el);\n });\n\n // A link that opted in. Everything else is a real link, and so is a\n // click that opens a new tab or window. The link's URL is a row for\n // lb-url: its path, its query parms, and every other parm emptied. A\n // link pushes a history entry, as a link does.\n this.addEventListener(\"click\", (e: MouseEvent) => {\n const link = (e.target as Element | null)?.closest(`a[${ATTR_URL_LINK}]`);\n if (!link || !isPlainClick(e)) return;\n e.preventDefault();\n const href = new URL((link as HTMLAnchorElement).href);\n const row: Row = {};\n for (const name of new URLSearchParams(location.search).keys()) {\n row[name] = \"\";\n }\n for (const [name, value] of href.searchParams) row[name] = value;\n row[URL_COLUMN_PATH] = href.pathname;\n this.moveTo(row, true);\n void this.navigate();\n });\n\n addEventListener(\"popstate\", () => void this.navigate());\n\n void this.navigate();\n }\n\n /**\n * Send a request to the server and land its answer. An answer naming\n * `lb-url` moves the URL first; the server has already loaded the page\n * there, in the same round trip.\n */\n private async send(request: HubRequest, origin?: Element): Promise<void> {\n const page = this.page;\n const items = await this.roundTrip(page, request, origin);\n if (items === null) return;\n const url = items.find((item) => item.query === URL_QUERY);\n const load = items.filter((item) => item !== url);\n if (url === undefined) applyResponse(this, load);\n else await this.follow(page, url, load, origin);\n insertedFrom.get(request)?.reset();\n }\n\n /**\n * One round trip for a page: a request, or with none a page load. The\n * element that issued it carries `lb-request-pending` while it is in\n * flight, and `lb-request-error` when it fails. Null on failure.\n */\n private async roundTrip(\n page: string,\n request: HubRequest | undefined,\n origin: Element | undefined,\n ): Promise<HubResponse | null> {\n pending(origin, true);\n try {\n return await fetchItems(page, request);\n } catch (err) {\n console.error(`lb-hub: request failed for '${page}'`, err);\n origin?.setAttribute(ATTR_REQUEST_ERROR, \"\");\n return null;\n } finally {\n pending(origin, false);\n }\n }\n\n /**\n * Answer a request for a query the hub serves, with no round trip. The\n * hub serves `lb-url`, and updates it.\n */\n private answer(request: HubRequest, origin?: Element): void {\n if (request.query !== URL_QUERY || request.name !== REQUEST_ROW_UPDATE) {\n console.error(\n `lb-hub: '${request.name}' for '${request.query}' is not a request ` +\n `the hub answers, ignoring`,\n );\n return;\n }\n const pushed = origin?.hasAttribute(ATTR_URL_PUSH) ?? false;\n if (this.moveTo(request.values ?? {}, pushed)) void this.navigate(origin);\n }\n\n /**\n * Write a row for `lb-url` into the URL. A new page pushes a history\n * entry, and so does `push`; a change of query parms replaces the entry.\n * False when the URL is already the row's.\n */\n private moveTo(row: Row, push: boolean): boolean {\n const { url, moved } = nextUrl(row);\n if (url.href === location.href) return false;\n if (moved || push) history.pushState(null, \"\", url);\n else history.replaceState(null, \"\", url);\n return true;\n }\n\n /**\n * A server answer named `lb-url`: write the URL, then land the page the\n * server loaded there. A load that did not come back is asked for again,\n * without marking the element that issued the request: its write\n * succeeded, and an error would invite sending it twice.\n *\n * `page` is where the request was sent from. A user who left it while the\n * request was in flight is on a URL that is not the server's to change.\n */\n private async follow(\n page: string,\n item: ResponseItem,\n load: ResponseItem[],\n origin?: Element,\n ): Promise<void> {\n if (pageNameFor(location.pathname) !== page) return;\n this.moveTo(item.row ?? {}, origin?.hasAttribute(ATTR_URL_PUSH) ?? false);\n if (load.length === 0) return this.navigate();\n const template = this.arrive();\n if (template) applyResponse(this, load);\n }\n\n /**\n * Load the page at the URL the browser is showing. Every way of arriving\n * comes through here — a cold load, a link, Back, a new query parm — so\n * each is the same page load and a URL always shows the same thing.\n *\n * Entering a page is the one operation that replaces what <main> holds.\n * Staying on it, with only the query parms changed, keeps what it has: the\n * queries re-run and land by key, so rows that come back keep their place.\n *\n * `origin` is the element whose request changed the URL, if one did, and\n * carries the round trip's pending and error state.\n */\n private async navigate(origin?: Element): Promise<void> {\n const template = this.arrive();\n if (!template) return;\n const items = await this.roundTrip(this.page, undefined, origin);\n applyResponse(this, items ?? []);\n }\n\n /**\n * Show the page the path names, and land `lb-url`. Null when no page's\n * stub matches the path.\n */\n private arrive(): HTMLTemplateElement | null {\n const page = pageNameFor(location.pathname);\n const template = pageHostFor(page);\n if (template && page !== this.page) {\n this.page = page;\n // The template is already in the document, so the page's markup goes\n // in before its data arrives rather than leaving <main> empty.\n this.main.replaceChildren(template.content.cloneNode(true));\n }\n this.landUrl(template ? titleOf(template, page) : null);\n // An app that ships `<body hidden>` (docs/reference/chrome.md) stays\n // invisible until there is something coherent to show.\n document.body.hidden = false;\n if (!template) {\n console.error(`lb-hub: no page for '${page}'`);\n const dialog = this.querySelector(`dialog[${ATTR_URL_UNKNOWN}]`);\n if (dialog && !(dialog as HTMLDialogElement).open) {\n (dialog as HTMLDialogElement).showModal();\n }\n }\n return template;\n }\n\n /**\n * The hub's own query: one row, keyed by the path, whose other columns are\n * the query parms.\n *\n * The one exception to landing. A row sets the columns it names and\n * leaves the rest as they were, and a URL names only the parms it carries.\n * So the row also names, as empty, every column an element under\n * `lb-query=\"lb-url\"` shows: a control then shows what the address bar\n * says after Back as well as after a reload, and never a parm the URL has\n * dropped.\n */\n private landUrl(label: string | null): void {\n if (label !== null) document.title = label;\n const scopes = this.querySelectorAll(`[${ATTR_QUERY}=\"${URL_QUERY}\"]`);\n if (scopes.length === 0) return;\n const row: Row = {};\n for (const scope of scopes) {\n for (const el of within(scope, `[${ATTR_COLUMN}]`)) {\n if (el === scope) continue;\n row[el.getAttribute(ATTR_COLUMN)!] = \"\";\n }\n }\n for (const [name, value] of new URLSearchParams(location.search)) {\n row[name] = value;\n }\n row[URL_COLUMN_PATH] = location.pathname;\n row[URL_COLUMN_PAGE_LABEL] = label;\n row[URL_COLUMN_PAGE_UNKNOWN] = label === null;\n applyResponse(this, [\n { query: URL_QUERY, kind: KIND_ROW, key: URL_COLUMN_PATH, row },\n ]);\n }\n}\n\ncustomElements.define(HUB_TAG_NAME, LbHub);\n"]}
|