refactor: migrate legacy wire namespace to wrn
This commit is contained in:
@@ -111,11 +111,11 @@ Intercepts same-origin `<a>` clicks, fetches the target page, and swaps the `#ap
|
||||
|
||||
Connects to `/realtime/<name>` over WebSocket (`ws`/`wss` chosen from `location.protocol`). Two usage modes.
|
||||
|
||||
Programmatic API via `window.wire`:
|
||||
Programmatic API via `window.wrn`:
|
||||
|
||||
```ts
|
||||
wire.room(name): Room // open (or reuse) a room connection
|
||||
wire.bindRooms(root?) // (re)bind declarative [data-room] containers
|
||||
wrn.room(name): Room // open (or reuse) a room connection
|
||||
wrn.bindRooms(root?) // (re)bind declarative [data-room] containers
|
||||
|
||||
interface Room {
|
||||
name: string;
|
||||
@@ -211,7 +211,7 @@ A realtime chat, fully declarative:
|
||||
Or drive a room from code:
|
||||
|
||||
```ts
|
||||
const room = wire.room("lobby");
|
||||
const room = wrn.room("lobby");
|
||||
room.on("chat", (msg) => console.log(msg.user, msg.text));
|
||||
room.send({ type: "chat", user: "ada", text: "hi" });
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/csr",
|
||||
"version": "0.8.15",
|
||||
"version": "0.8.16",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -4,7 +4,7 @@ export const ACTION_RUNTIME = String.raw`
|
||||
window.__wrnexusActionsInstalled = true;
|
||||
|
||||
function csrf() {
|
||||
var match = document.cookie.match(/(?:^|;\s*)wire-csrf=([^;]+)/);
|
||||
var match = document.cookie.match(/(?:^|;\s*)wrn-csrf=([^;]+)/);
|
||||
return match ? decodeURIComponent(match[1]) : "";
|
||||
}
|
||||
|
||||
|
||||
@@ -437,11 +437,11 @@ export const NAV_RUNTIME = String.raw`
|
||||
|
||||
try {
|
||||
if (
|
||||
window.__wireValidate &&
|
||||
typeof window.__wireValidate.init ===
|
||||
window.__wrnValidate &&
|
||||
typeof window.__wrnValidate.init ===
|
||||
"function"
|
||||
) {
|
||||
window.__wireValidate.init(document);
|
||||
window.__wrnValidate.init(document);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
@@ -452,11 +452,11 @@ export const NAV_RUNTIME = String.raw`
|
||||
|
||||
try {
|
||||
if (
|
||||
window.wireTheme &&
|
||||
typeof window.wireTheme.bind ===
|
||||
window.wrnTheme &&
|
||||
typeof window.wrnTheme.bind ===
|
||||
"function"
|
||||
) {
|
||||
window.wireTheme.bind(document);
|
||||
window.wrnTheme.bind(document);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
|
||||
@@ -147,10 +147,10 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
* identical call in an inline handler works, which is a maddening
|
||||
* inconsistency.
|
||||
*
|
||||
* wireToast is the stable name. toast is the ergonomic alias and defers to
|
||||
* wrnToast is the stable name. toast is the ergonomic alias and defers to
|
||||
* an application that already defines one.
|
||||
*/
|
||||
window.wireToast = toastApi;
|
||||
window.wrnToast = toastApi;
|
||||
if (!window.toast) window.toast = toastApi;
|
||||
|
||||
// Read straight off window, no binding needed (objects, not functions).
|
||||
@@ -229,11 +229,11 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
Array.prototype.forEach.call(rules || [], function (rule) {
|
||||
var cssText = rule.cssText || "";
|
||||
var match;
|
||||
var pattern = /var\(\s*(--wire-[A-Za-z0-9_-]+)/g;
|
||||
var pattern = /var\(\s*(--wrn-[A-Za-z0-9_-]+)/g;
|
||||
while ((match = pattern.exec(cssText))) referenced[match[1]] = true;
|
||||
if (rule.style) {
|
||||
Array.prototype.forEach.call(rule.style, function (property) {
|
||||
if (String(property).indexOf("--wire-") === 0) declared[property] = true;
|
||||
if (String(property).indexOf("--wrn-") === 0) declared[property] = true;
|
||||
});
|
||||
}
|
||||
try {
|
||||
@@ -248,7 +248,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
});
|
||||
Array.prototype.forEach.call(document.querySelectorAll("[style]") || [], function (element) {
|
||||
Array.prototype.forEach.call(element.style || [], function (property) {
|
||||
if (String(property).indexOf("--wire-") === 0) declared[property] = true;
|
||||
if (String(property).indexOf("--wrn-") === 0) declared[property] = true;
|
||||
});
|
||||
});
|
||||
var rendered = window.getComputedStyle(document.documentElement);
|
||||
@@ -2225,7 +2225,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
Array.prototype.slice
|
||||
.call(el.querySelectorAll("[data-for]"))
|
||||
.forEach(function (tpl) {
|
||||
// Only top-level templates here; nested ones are wired by the item
|
||||
// Only top-level templates here; nested ones are connected by the item
|
||||
// that contains them, once it has values to give them.
|
||||
if (tpl.parentNode && tpl.parentNode.closest && tpl.parentNode.closest("[data-for]")) {
|
||||
return;
|
||||
@@ -2289,7 +2289,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
|
||||
// data-show="expr" — toggle visibility on truthiness. This directive is
|
||||
// intentionally non-destructive because popovers, selects and remote data
|
||||
// controls keep event wiring and state while closed. Use a compiled {#if}
|
||||
// controls keep event integration and state while closed. Use a compiled {#if}
|
||||
// block when the inactive branch must not be rendered.
|
||||
el.querySelectorAll("[data-show]").forEach(function (node) {
|
||||
if (!owns(node)) return;
|
||||
@@ -3367,9 +3367,9 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
nav.dispatchEvent(new CustomEvent("change", { detail: { href: href, label: label } }));
|
||||
}
|
||||
|
||||
function wireScrollspy(nav) {
|
||||
if (nav.__wrnScrollspyWired) return;
|
||||
nav.__wrnScrollspyWired = true;
|
||||
function bindScrollspy(nav) {
|
||||
if (nav.__wrnScrollspyBound) return;
|
||||
nav.__wrnScrollspyBound = true;
|
||||
|
||||
nav.addEventListener("click", function (event) {
|
||||
var t = event.target;
|
||||
@@ -3412,13 +3412,13 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
function setupScrollspy() {
|
||||
if (window.__wrnexusScrollspyBound) return;
|
||||
window.__wrnexusScrollspyBound = true;
|
||||
var wireAll = function () {
|
||||
var bindAll = function () {
|
||||
var navs = document.querySelectorAll("[data-wrn-scrollspy]");
|
||||
for (var index = 0; index < navs.length; index += 1) wireScrollspy(navs[index]);
|
||||
for (var index = 0; index < navs.length; index += 1) bindScrollspy(navs[index]);
|
||||
};
|
||||
wireAll();
|
||||
bindAll();
|
||||
watchDocument(function () {
|
||||
window.setTimeout(wireAll, 0);
|
||||
window.setTimeout(bindAll, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3605,7 +3605,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
switcher.addEventListener("toggle", function (event) {
|
||||
var opened = event.target;
|
||||
if (!opened || opened.tagName !== "DETAILS" || !opened.open) return;
|
||||
switcher.querySelectorAll(".wire-preferences__menu[open]").forEach(function (menu) {
|
||||
switcher.querySelectorAll(".wrn-preferences__menu[open]").forEach(function (menu) {
|
||||
if (menu !== opened) menu.removeAttribute("open");
|
||||
});
|
||||
}, true);
|
||||
@@ -3615,14 +3615,14 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
document.addEventListener("pointerdown", function (event) {
|
||||
document.querySelectorAll("[data-wrn-preferences]").forEach(function (switcher) {
|
||||
if (switcher.contains(event.target)) return;
|
||||
switcher.querySelectorAll(".wire-preferences__menu[open]").forEach(function (menu) {
|
||||
switcher.querySelectorAll(".wrn-preferences__menu[open]").forEach(function (menu) {
|
||||
menu.removeAttribute("open");
|
||||
});
|
||||
});
|
||||
});
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key !== "Escape") return;
|
||||
document.querySelectorAll("[data-wrn-preferences] .wire-preferences__menu[open]").forEach(function (menu) {
|
||||
document.querySelectorAll("[data-wrn-preferences] .wrn-preferences__menu[open]").forEach(function (menu) {
|
||||
menu.removeAttribute("open");
|
||||
var summary = menu.querySelector(":scope > summary");
|
||||
if (summary) summary.focus();
|
||||
@@ -3648,7 +3648,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
var current = window.location.pathname.replace(/\/+$/, "") || "/";
|
||||
var best = null;
|
||||
var bestLength = -1;
|
||||
navbar.querySelectorAll(".wire-navbar__menus a[href]").forEach(function (link) {
|
||||
navbar.querySelectorAll(".wrn-navbar__menus a[href]").forEach(function (link) {
|
||||
var url;
|
||||
try { url = new URL(link.getAttribute("href"), window.location.origin); } catch (_) { return; }
|
||||
if (url.origin !== window.location.origin) return;
|
||||
@@ -3658,12 +3658,12 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
best = link;
|
||||
bestLength = path.length;
|
||||
});
|
||||
navbar.querySelectorAll(".wire-navbar__menus [aria-current='page']").forEach(function (item) {
|
||||
navbar.querySelectorAll(".wrn-navbar__menus [aria-current='page']").forEach(function (item) {
|
||||
item.removeAttribute("aria-current");
|
||||
});
|
||||
if (best) {
|
||||
best.setAttribute("aria-current", "page");
|
||||
var parentMenu = best.closest(".wire-navbar__dropdown");
|
||||
var parentMenu = best.closest(".wrn-navbar__dropdown");
|
||||
var parentSummary = parentMenu && parentMenu.querySelector(":scope > summary");
|
||||
if (parentSummary) parentSummary.setAttribute("aria-current", "page");
|
||||
}
|
||||
@@ -3675,13 +3675,13 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
typeof window.matchMedia !== "function" ||
|
||||
window.matchMedia("(hover: hover) and (pointer: fine)").matches;
|
||||
if (hoverEnabled && hoverCapable) {
|
||||
navbar.querySelectorAll(".wire-navbar__dropdown").forEach(function (menu) {
|
||||
navbar.querySelectorAll(".wrn-navbar__dropdown").forEach(function (menu) {
|
||||
menu.addEventListener("pointerenter", function () {
|
||||
if (menu.__wrnNavbarCloseTimer) {
|
||||
clearTimeout(menu.__wrnNavbarCloseTimer);
|
||||
menu.__wrnNavbarCloseTimer = null;
|
||||
}
|
||||
navbar.querySelectorAll(".wire-navbar__dropdown[open]").forEach(function (candidate) {
|
||||
navbar.querySelectorAll(".wrn-navbar__dropdown[open]").forEach(function (candidate) {
|
||||
if (candidate !== menu) candidate.removeAttribute("open");
|
||||
});
|
||||
menu.setAttribute("open", "");
|
||||
@@ -3698,7 +3698,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
navbar.addEventListener("toggle", function (event) {
|
||||
var opened = event.target;
|
||||
if (!opened || opened.tagName !== "DETAILS" || !opened.open) return;
|
||||
navbar.querySelectorAll(".wire-navbar__dropdown[open]").forEach(function (menu) {
|
||||
navbar.querySelectorAll(".wrn-navbar__dropdown[open]").forEach(function (menu) {
|
||||
if (menu !== opened) menu.removeAttribute("open");
|
||||
});
|
||||
}, true);
|
||||
@@ -3709,14 +3709,14 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
document.addEventListener("pointerdown", function (event) {
|
||||
document.querySelectorAll("[data-wrn-navbar]").forEach(function (navbar) {
|
||||
if (navbar.contains(event.target)) return;
|
||||
navbar.querySelectorAll(".wire-navbar__dropdown[open]").forEach(function (menu) {
|
||||
navbar.querySelectorAll(".wrn-navbar__dropdown[open]").forEach(function (menu) {
|
||||
menu.removeAttribute("open");
|
||||
});
|
||||
});
|
||||
});
|
||||
document.addEventListener("keydown", function (event) {
|
||||
if (event.key !== "Escape") return;
|
||||
document.querySelectorAll("[data-wrn-navbar] .wire-navbar__dropdown[open]").forEach(function (menu) {
|
||||
document.querySelectorAll("[data-wrn-navbar] .wrn-navbar__dropdown[open]").forEach(function (menu) {
|
||||
menu.removeAttribute("open");
|
||||
var summary = menu.querySelector(":scope > summary");
|
||||
if (summary) summary.focus();
|
||||
@@ -3748,7 +3748,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
|
||||
function syncComboboxInput(root) {
|
||||
if (!root || !root.hasAttribute("data-wrn-combobox")) return;
|
||||
var input = root.querySelector(".wire-next__combobox-input");
|
||||
var input = root.querySelector(".wrn-next__combobox-input");
|
||||
var api = selectScopeApi(root);
|
||||
if (!input || !api) return;
|
||||
var value = api.call("inputText") || "";
|
||||
@@ -3782,17 +3782,17 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
}
|
||||
|
||||
function renderRemoteSelectOptions(root, options) {
|
||||
var list = root.querySelector(".wire-next__select-list");
|
||||
var list = root.querySelector(".wrn-next__select-list");
|
||||
if (!list) return;
|
||||
|
||||
list.querySelectorAll(".wire-next__option-group, .wire-next__select-option, .wire-next__select-message")
|
||||
list.querySelectorAll(".wrn-next__option-group, .wrn-next__select-option, .wrn-next__select-message")
|
||||
.forEach(function (node) { node.remove(); });
|
||||
|
||||
options.forEach(function (option) {
|
||||
if (!option || option.value == null) return;
|
||||
var button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.className = "wire-next__select-option";
|
||||
button.className = "wrn-next__select-option";
|
||||
button.setAttribute("role", "option");
|
||||
button.setAttribute("data-option-value", String(option.value));
|
||||
button.disabled = !!option.disabled;
|
||||
@@ -3809,7 +3809,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
button.appendChild(avatar);
|
||||
} else if (option.color) {
|
||||
var dot = document.createElement("i");
|
||||
dot.className = "wire-next__color-dot";
|
||||
dot.className = "wrn-next__color-dot";
|
||||
dot.style.setProperty("--option-color", String(option.color));
|
||||
button.appendChild(dot);
|
||||
}
|
||||
@@ -3826,7 +3826,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
button.appendChild(copy);
|
||||
|
||||
var check = document.createElement("i");
|
||||
check.className = "wire-next__check icon-[lucide--check]";
|
||||
check.className = "wrn-next__check icon-[lucide--check]";
|
||||
check.setAttribute("aria-hidden", "true");
|
||||
check.style.display = "none";
|
||||
button.appendChild(check);
|
||||
@@ -3837,7 +3837,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
api.call("chooseOption", option);
|
||||
window.setTimeout(function () {
|
||||
var selected = api.call("isSelected", option);
|
||||
button.classList.toggle("wire-next__select-option--selected", !!selected);
|
||||
button.classList.toggle("wrn-next__select-option--selected", !!selected);
|
||||
button.setAttribute("aria-selected", selected ? "true" : "false");
|
||||
check.style.display = selected ? "" : "none";
|
||||
syncComboboxInput(root);
|
||||
@@ -3853,8 +3853,8 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
|
||||
var remote = root.getAttribute("data-remote") === "true";
|
||||
var remoteUrl = root.getAttribute("data-remote-url") || "";
|
||||
var input = root.querySelector(".wire-next__select-search input, .wire-next__combobox-input");
|
||||
var list = root.querySelector(".wire-next__select-list");
|
||||
var input = root.querySelector(".wrn-next__select-search input, .wrn-next__combobox-input");
|
||||
var list = root.querySelector(".wrn-next__select-list");
|
||||
var loadMore = root.querySelector("[data-wrn-select-load-more]");
|
||||
var timer = 0;
|
||||
var requestId = 0;
|
||||
@@ -3968,12 +3968,12 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
|
||||
root.addEventListener("click", function (event) {
|
||||
if (!remote || !remoteUrl) return;
|
||||
if (!event.target.closest(".wire-next__select-trigger")) return;
|
||||
if (!event.target.closest(".wrn-next__select-trigger")) return;
|
||||
if (loadedOptions.length === 0) load(false);
|
||||
});
|
||||
root.__wrnexusSelectController.load = load;
|
||||
|
||||
var dropdown = root.querySelector(".wire-next__select-dropdown");
|
||||
var dropdown = root.querySelector(".wrn-next__select-dropdown");
|
||||
var lastOpen = !!(selectScopeApi(root) && selectScopeApi(root).get("open"));
|
||||
function emitOpenStateIfChanged() {
|
||||
var api = selectScopeApi(root);
|
||||
@@ -3998,7 +3998,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
}
|
||||
|
||||
root.addEventListener("click", function (event) {
|
||||
var optionButton = event.target.closest(".wire-next__select-option");
|
||||
var optionButton = event.target.closest(".wrn-next__select-option");
|
||||
if (optionButton) {
|
||||
window.setTimeout(function () {
|
||||
var api = selectScopeApi(root);
|
||||
@@ -4012,7 +4012,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
emitOpenStateIfChanged();
|
||||
}, 0);
|
||||
}
|
||||
if (event.target.closest(".wire-next__clear-select")) {
|
||||
if (event.target.closest(".wrn-next__clear-select")) {
|
||||
window.setTimeout(function () {
|
||||
emitSelectEvent(root, "clear");
|
||||
emitSelectEvent(root, "change", { reason: "clear" });
|
||||
@@ -4064,7 +4064,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
},
|
||||
};
|
||||
root.addEventListener("click", function (event) {
|
||||
if (!event.target.closest(".wire-next__select-option, .wire-next__clear-select")) return;
|
||||
if (!event.target.closest(".wrn-next__select-option, .wrn-next__clear-select")) return;
|
||||
window.setTimeout(function () { syncComboboxInput(root); }, 0);
|
||||
});
|
||||
if (input) {
|
||||
@@ -4093,7 +4093,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
if (!selectOutsideClickBound) {
|
||||
selectOutsideClickBound = true;
|
||||
document.addEventListener("pointerdown", function (event) {
|
||||
document.querySelectorAll("[data-wrn-select].wire-next--open").forEach(function (select) {
|
||||
document.querySelectorAll("[data-wrn-select].wrn-next--open").forEach(function (select) {
|
||||
if (select.contains(event.target)) return;
|
||||
var api = selectScopeApi(select);
|
||||
if (api) api.set("open", false);
|
||||
@@ -4139,7 +4139,7 @@ export const REACTIVE_RUNTIME = String.raw`
|
||||
|
||||
function callServerFunction(component, functionName, args) {
|
||||
var csrfMeta = document.querySelector('meta[name="wrnexus-csrf"]');
|
||||
var csrfMatch = /(?:^|;\s*)wire-csrf=([^;]+)/.exec(document.cookie || "");
|
||||
var csrfMatch = /(?:^|;\s*)wrn-csrf=([^;]+)/.exec(document.cookie || "");
|
||||
var csrf = csrfMeta
|
||||
? csrfMeta.getAttribute("content") || ""
|
||||
: csrfMatch
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* `data-room-reset` clear after send). Optional `data-room-user` identifies
|
||||
* the connection.
|
||||
*
|
||||
* 2. Programmatic: `const room = wire.room("chat"); room.on("chat", fn);
|
||||
* 2. Programmatic: `const room = wrn.room("chat"); room.on("chat", fn);
|
||||
* room.send({ type: "chat", text })`. Handles connect, JSON, reconnect.
|
||||
*
|
||||
* Rebinds on `wrnexus:navigated` (client-side nav) and closes rooms whose
|
||||
@@ -21,8 +21,8 @@
|
||||
export const REALTIME_RUNTIME = String.raw`
|
||||
(function () {
|
||||
if (!("WebSocket" in window)) return;
|
||||
var wire = (window.wire = window.wire || {});
|
||||
if (wire.room) return; // already installed
|
||||
var wrn = (window.wrn = window.wrn || {});
|
||||
if (wrn.room) return; // already installed
|
||||
var open = {}; // normalized room+query key -> room connection
|
||||
|
||||
function normalizedQuery(query) {
|
||||
@@ -107,7 +107,7 @@ export const REALTIME_RUNTIME = String.raw`
|
||||
connect();
|
||||
return api;
|
||||
}
|
||||
wire.room = openRoom;
|
||||
wrn.room = openRoom;
|
||||
|
||||
// --- Declarative binding ---------------------------------------------------
|
||||
|
||||
@@ -139,11 +139,11 @@ export const REALTIME_RUNTIME = String.raw`
|
||||
var user = el.getAttribute("data-room-user");
|
||||
var query = el.getAttribute("data-room-query") || (user ? "user=" + encodeURIComponent(user) : "");
|
||||
var key = roomKey(name, query);
|
||||
if (el.__wireRoomBound && el.__wireRoomKey === key) return;
|
||||
el.__wireRoomBound = true;
|
||||
el.__wireRoomKey = key;
|
||||
if (el.__wrnRoomBound && el.__wrnRoomKey === key) return;
|
||||
el.__wrnRoomBound = true;
|
||||
el.__wrnRoomKey = key;
|
||||
var room = openRoom(name, query);
|
||||
el.__wireRoom = room;
|
||||
el.__wrnRoom = room;
|
||||
|
||||
var log = el.querySelector("[data-room-log]");
|
||||
var status = el.querySelector("[data-room-status]");
|
||||
@@ -176,8 +176,8 @@ export const REALTIME_RUNTIME = String.raw`
|
||||
});
|
||||
|
||||
var form = el.querySelector("form[data-room-send]");
|
||||
if (form && !form.__wireRoomForm) {
|
||||
form.__wireRoomForm = true;
|
||||
if (form && !form.__wrnRoomForm) {
|
||||
form.__wrnRoomForm = true;
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault();
|
||||
var data = {};
|
||||
@@ -185,7 +185,7 @@ export const REALTIME_RUNTIME = String.raw`
|
||||
var input = form.elements[i];
|
||||
if (input.name) data[input.name] = input.value;
|
||||
}
|
||||
if (el.__wireRoom) el.__wireRoom.send(data);
|
||||
if (el.__wrnRoom) el.__wrnRoom.send(data);
|
||||
for (var j = 0; j < form.elements.length; j++) {
|
||||
if (form.elements[j].hasAttribute("data-room-reset")) form.elements[j].value = "";
|
||||
}
|
||||
@@ -198,13 +198,13 @@ export const REALTIME_RUNTIME = String.raw`
|
||||
var present = {};
|
||||
for (var i = 0; i < containers.length; i++) {
|
||||
bindContainer(containers[i]);
|
||||
if (containers[i].__wireRoomKey) present[containers[i].__wireRoomKey] = true;
|
||||
if (containers[i].__wrnRoomKey) present[containers[i].__wrnRoomKey] = true;
|
||||
}
|
||||
// Close rooms whose container has left the page (client-side navigation).
|
||||
for (var nm in open) if (!present[nm]) open[nm].close();
|
||||
}
|
||||
|
||||
wire.bindRooms = bindAll;
|
||||
wrn.bindRooms = bindAll;
|
||||
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", function () { bindAll(document); });
|
||||
else bindAll(document);
|
||||
window.addEventListener("wrnexus:navigated", function () { bindAll(document); });
|
||||
|
||||
@@ -17,7 +17,7 @@ export class WrnServerCallError extends Error {
|
||||
|
||||
function csrfFromCookie(): string | undefined {
|
||||
if (typeof document === "undefined") return undefined;
|
||||
const raw = /(?:^|;\s*)wire-csrf=([^;]+)/.exec(document.cookie)?.[1];
|
||||
const raw = /(?:^|;\s*)wrn-csrf=([^;]+)/.exec(document.cookie)?.[1];
|
||||
return raw ? decodeURIComponent(raw) : undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ afterEach(() => {
|
||||
|
||||
test("action runtime exposes pending, optimistic, success, and invalidation state", async () => {
|
||||
const win = new Window({ url: "https://example.test/users" });
|
||||
win.document.cookie = "wire-csrf=token";
|
||||
win.document.cookie = "wrn-csrf=token";
|
||||
win.document.body.innerHTML = `<form data-wrn-action="createUser"><input name="name" value="Ada"></form>`;
|
||||
const phases: string[] = [];
|
||||
["optimistic", "pending", "success"].forEach((phase) =>
|
||||
|
||||
@@ -129,14 +129,14 @@ test("exposes programmatic navigation", async () => {
|
||||
test("rebinds theme controls after swapping the page", async () => {
|
||||
install(`<div id="app"><a href="/about" id="lnk">About</a></div>`);
|
||||
let boundRoot: unknown;
|
||||
win.wireTheme = { bind: (root: unknown) => (boundRoot = root) };
|
||||
nextHtml = `<html><body><div id="app"><button data-wire-theme-toggle>Theme</button></div></body></html>`;
|
||||
win.wrnTheme = { bind: (root: unknown) => (boundRoot = root) };
|
||||
nextHtml = `<html><body><div id="app"><button data-wrn-theme-toggle>Theme</button></div></body></html>`;
|
||||
|
||||
win.document.getElementById("lnk").click();
|
||||
await flush();
|
||||
|
||||
expect(boundRoot).toBe(win.document);
|
||||
expect(win.document.querySelector("[data-wire-theme-toggle]")).not.toBeNull();
|
||||
expect(win.document.querySelector("[data-wrn-theme-toggle]")).not.toBeNull();
|
||||
});
|
||||
|
||||
test("unmounts and remounts package runtimes during client navigation", async () => {
|
||||
|
||||
@@ -809,7 +809,7 @@ test("component server calls send the CSRF cookie in the RPC header", async () =
|
||||
);
|
||||
Object.defineProperty(win.document, "cookie", {
|
||||
configurable: true,
|
||||
value: "wire-csrf=rpc%20token",
|
||||
value: "wrn-csrf=rpc%20token",
|
||||
});
|
||||
let request: RequestInit | undefined;
|
||||
const globals = globalThis as Record<string, unknown>;
|
||||
@@ -837,7 +837,7 @@ test("component server calls prefer the rendered CSRF token over stale cookies",
|
||||
);
|
||||
Object.defineProperty(win.document, "cookie", {
|
||||
configurable: true,
|
||||
value: "wire-csrf=stale-token",
|
||||
value: "wrn-csrf=stale-token",
|
||||
});
|
||||
let request: RequestInit | undefined;
|
||||
const globals = globalThis as Record<string, unknown>;
|
||||
@@ -902,8 +902,8 @@ test("development runtime warns when a component binding names a missing functio
|
||||
test("development runtime warns for referenced theme tokens absent from rendered CSS", () => {
|
||||
const win = new Window() as unknown as Window & Record<string, unknown>;
|
||||
win.document.head.innerHTML =
|
||||
`<style>:root { --wire-present-test: red; } .probe { ` +
|
||||
`color: var(--wire-present-test); background: var(--wire-missing-test); }</style>`;
|
||||
`<style>:root { --wrn-present-test: red; } .probe { ` +
|
||||
`color: var(--wrn-present-test); background: var(--wrn-missing-test); }</style>`;
|
||||
win.document.body.innerHTML = `<div class="probe" data-scope=""></div>`;
|
||||
(globalThis as Record<string, unknown>).window = win;
|
||||
(globalThis as Record<string, unknown>).document = win.document;
|
||||
@@ -930,15 +930,15 @@ test("development runtime warns for referenced theme tokens absent from rendered
|
||||
}
|
||||
expect(warnings).toHaveLength(1);
|
||||
expect(String(warnings[0]?.[0])).toContain("WRN-DEV-THEME-TOKEN-MISSING");
|
||||
expect(String(warnings[0]?.[0])).toContain("--wire-missing-test");
|
||||
expect(String(warnings[0]?.[0])).toContain("--wrn-missing-test");
|
||||
});
|
||||
|
||||
test("development runtime accepts component-local and inline wire variables", () => {
|
||||
test("development runtime accepts component-local and inline wrn variables", () => {
|
||||
const win = new Window() as unknown as Window & Record<string, unknown>;
|
||||
win.document.head.innerHTML =
|
||||
`<style>.component { --wire-component-local: red; color: var(--wire-component-local); ` +
|
||||
`background: var(--wire-inline-local); }</style>`;
|
||||
win.document.body.innerHTML = `<div class="component" style="--wire-inline-local: blue" data-scope=""></div>`;
|
||||
`<style>.component { --wrn-component-local: red; color: var(--wrn-component-local); ` +
|
||||
`background: var(--wrn-inline-local); }</style>`;
|
||||
win.document.body.innerHTML = `<div class="component" style="--wrn-inline-local: blue" data-scope=""></div>`;
|
||||
(globalThis as Record<string, unknown>).window = win;
|
||||
(globalThis as Record<string, unknown>).document = win.document;
|
||||
(globalThis as Record<string, unknown>).location = win.location;
|
||||
@@ -1076,9 +1076,9 @@ test("toast() falls back to the console when no toaster is mounted", () => {
|
||||
test("toast is reachable as a real global for compiled client modules", () => {
|
||||
const win = mount(`<div data-scope=""></div>`) as unknown as Window & {
|
||||
toast?: unknown;
|
||||
wireToast?: unknown;
|
||||
wrnToast?: unknown;
|
||||
};
|
||||
expect(typeof win.wireToast).toBe("function");
|
||||
expect(typeof win.wrnToast).toBe("function");
|
||||
expect(typeof win.toast).toBe("function");
|
||||
});
|
||||
|
||||
|
||||
@@ -103,9 +103,9 @@ test("submitting [data-room-send] sends JSON and clears reset fields", () => {
|
||||
expect((inputs[1] as unknown as HTMLInputElement).value).toBe("");
|
||||
});
|
||||
|
||||
test("programmatic wire.room() sends and receives", () => {
|
||||
test("programmatic wrn.room() sends and receives", () => {
|
||||
const win = boot(`<div></div>`) as unknown as Window & {
|
||||
wire: {
|
||||
wrn: {
|
||||
room: (n: string) => {
|
||||
on: (t: string, cb: (m: unknown) => void) => unknown;
|
||||
send: (o: unknown) => void;
|
||||
@@ -113,7 +113,7 @@ test("programmatic wire.room() sends and receives", () => {
|
||||
};
|
||||
};
|
||||
const got: unknown[] = [];
|
||||
const room = win.wire.room("lobby");
|
||||
const room = win.wrn.room("lobby");
|
||||
room.on("ping", (m: unknown) => got.push(m));
|
||||
sockets[0]!.fireOpen();
|
||||
room.send({ type: "hello" });
|
||||
@@ -137,11 +137,11 @@ test("declarative room reconnects when its user identity changes", () => {
|
||||
const win = boot(
|
||||
`<div id="room" data-room="teamspace" data-room-user="asha"></div>`,
|
||||
) as unknown as Window & {
|
||||
wire: { bindRooms: (root?: unknown) => void };
|
||||
wrn: { bindRooms: (root?: unknown) => void };
|
||||
};
|
||||
expect(sockets[0]?.url).toBe("ws://localhost/realtime/teamspace?user=asha");
|
||||
win.document.getElementById("room")!.setAttribute("data-room-user", "neha");
|
||||
win.wire.bindRooms(win.document);
|
||||
win.wrn.bindRooms(win.document);
|
||||
expect(sockets[0]?.readyState).toBe(3);
|
||||
expect(sockets[1]?.url).toBe("ws://localhost/realtime/teamspace?user=neha");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user