vomebook commited on
Commit ยท
93d902f
1
Parent(s): de6eb19
Layer search route projection and navigation policy
Browse files- config/types/jsconfig.check.json +3 -0
- config/types/jsconfig.search-exact.json +3 -0
- config/types/jsconfig.strict.json +3 -0
- eslint.config.mjs +1 -1
- scripts/build/check_reader_release.mjs +1 -0
- scripts/build/compose_app.mjs +1 -0
- static/app.js +51 -106
- static/index.html +2 -0
- static/reader-resources.js +1 -0
- static/search/routing/application/router.js +39 -0
- static/search/routing/domain/route.js +56 -0
- static/sw.js +2 -0
- tests/gates/test_static_contract.py +9 -5
- tests/search/reader-navigation/routing_contracts.mjs +157 -0
- tests/search/reader-navigation/test_search_history_races.mjs +1 -0
- tests/support/classic_search_modules.js +1 -0
- typings/search-routing.d.ts +34 -0
config/types/jsconfig.check.json
CHANGED
|
@@ -97,6 +97,9 @@
|
|
| 97 |
"../../typings/search-restoration.d.ts",
|
| 98 |
"../../typings/search-results.d.ts",
|
| 99 |
"../../typings/search-discovery.d.ts",
|
|
|
|
|
|
|
|
|
|
| 100 |
"../../typings/search-shell.d.ts",
|
| 101 |
"../../static/search/shell/presentation/view.js",
|
| 102 |
"../../static/search/shell/application/controller.js",
|
|
|
|
| 97 |
"../../typings/search-restoration.d.ts",
|
| 98 |
"../../typings/search-results.d.ts",
|
| 99 |
"../../typings/search-discovery.d.ts",
|
| 100 |
+
"../../typings/search-routing.d.ts",
|
| 101 |
+
"../../static/search/routing/domain/route.js",
|
| 102 |
+
"../../static/search/routing/application/router.js",
|
| 103 |
"../../typings/search-shell.d.ts",
|
| 104 |
"../../static/search/shell/presentation/view.js",
|
| 105 |
"../../static/search/shell/application/controller.js",
|
config/types/jsconfig.search-exact.json
CHANGED
|
@@ -20,6 +20,9 @@
|
|
| 20 |
"../../typings/search-restoration.d.ts",
|
| 21 |
"../../typings/search-results.d.ts",
|
| 22 |
"../../typings/search-discovery.d.ts",
|
|
|
|
|
|
|
|
|
|
| 23 |
"../../typings/search-shell.d.ts",
|
| 24 |
"../../static/search/shell/presentation/view.js",
|
| 25 |
"../../static/search/shell/application/controller.js",
|
|
|
|
| 20 |
"../../typings/search-restoration.d.ts",
|
| 21 |
"../../typings/search-results.d.ts",
|
| 22 |
"../../typings/search-discovery.d.ts",
|
| 23 |
+
"../../typings/search-routing.d.ts",
|
| 24 |
+
"../../static/search/routing/domain/route.js",
|
| 25 |
+
"../../static/search/routing/application/router.js",
|
| 26 |
"../../typings/search-shell.d.ts",
|
| 27 |
"../../static/search/shell/presentation/view.js",
|
| 28 |
"../../static/search/shell/application/controller.js",
|
config/types/jsconfig.strict.json
CHANGED
|
@@ -73,6 +73,9 @@
|
|
| 73 |
"../../typings/search-restoration.d.ts",
|
| 74 |
"../../typings/search-results.d.ts",
|
| 75 |
"../../typings/search-discovery.d.ts",
|
|
|
|
|
|
|
|
|
|
| 76 |
"../../typings/search-shell.d.ts",
|
| 77 |
"../../static/search/shell/presentation/view.js",
|
| 78 |
"../../static/search/shell/application/controller.js",
|
|
|
|
| 73 |
"../../typings/search-restoration.d.ts",
|
| 74 |
"../../typings/search-results.d.ts",
|
| 75 |
"../../typings/search-discovery.d.ts",
|
| 76 |
+
"../../typings/search-routing.d.ts",
|
| 77 |
+
"../../static/search/routing/domain/route.js",
|
| 78 |
+
"../../static/search/routing/application/router.js",
|
| 79 |
"../../typings/search-shell.d.ts",
|
| 80 |
"../../static/search/shell/presentation/view.js",
|
| 81 |
"../../static/search/shell/application/controller.js",
|
eslint.config.mjs
CHANGED
|
@@ -20,7 +20,7 @@ export default [
|
|
| 20 |
globals: { ...globals.browser, ...globals.serviceworker, ...globals.worker,
|
| 21 |
module: "readonly", require: "readonly",
|
| 22 |
...Object.fromEntries(["VoiceOfMLReaderSecurity", "VoiceOfMLReader", "VoiceOfMLReaderResources",
|
| 23 |
-
"VoiceOfMLShell", "VoiceOfMLShellView", "VoiceOfMLReaderStore", "VoiceOfMLReaderChapters", "VoiceOfMLReaderVirtual", "VoiceOfMLReaderNavigation", "VoiceOfMLReaderHost", "VoiceOfMLReaderReturn",
|
| 24 |
"VoiceOfMLDownloadController", "VoiceOfMLDownloadBatch", "VoiceOfMLDownloadQueue", "VoiceOfMLSearchSession", "VoiceOfMLPositionPolicy", "VoiceOfMLPositionStorage", "VoiceOfMLSearchPositions", "VoiceOfMLPositionRestoration", "VoiceOfMLResultRows", "VoiceOfMLResultInteractions", "VoiceOfMLRandomDiscovery", "VoiceOfMLSearchHistoryStore", "VoiceOfMLSearchHistory", "VoiceOfMLQuotation", "VoiceOfMLSnapshotPolicy", "VoiceOfMLResultSnapshots", "VoiceOfMLSearchWindowPage", "VoiceOfMLReaderRequests", "VoiceOfMLReaderRuntime",
|
| 25 |
"VoiceOfMLReaderAdapters", "VoiceOfMLReaderScroll", "VoiceOfMLSearchSidebarRender", "DOMPurify", "marked"]
|
| 26 |
.map(name => [name, "readonly"])) }
|
|
|
|
| 20 |
globals: { ...globals.browser, ...globals.serviceworker, ...globals.worker,
|
| 21 |
module: "readonly", require: "readonly",
|
| 22 |
...Object.fromEntries(["VoiceOfMLReaderSecurity", "VoiceOfMLReader", "VoiceOfMLReaderResources",
|
| 23 |
+
"VoiceOfMLRoute", "VoiceOfMLRouter", "VoiceOfMLShell", "VoiceOfMLShellView", "VoiceOfMLReaderStore", "VoiceOfMLReaderChapters", "VoiceOfMLReaderVirtual", "VoiceOfMLReaderNavigation", "VoiceOfMLReaderHost", "VoiceOfMLReaderReturn",
|
| 24 |
"VoiceOfMLDownloadController", "VoiceOfMLDownloadBatch", "VoiceOfMLDownloadQueue", "VoiceOfMLSearchSession", "VoiceOfMLPositionPolicy", "VoiceOfMLPositionStorage", "VoiceOfMLSearchPositions", "VoiceOfMLPositionRestoration", "VoiceOfMLResultRows", "VoiceOfMLResultInteractions", "VoiceOfMLRandomDiscovery", "VoiceOfMLSearchHistoryStore", "VoiceOfMLSearchHistory", "VoiceOfMLQuotation", "VoiceOfMLSnapshotPolicy", "VoiceOfMLResultSnapshots", "VoiceOfMLSearchWindowPage", "VoiceOfMLReaderRequests", "VoiceOfMLReaderRuntime",
|
| 25 |
"VoiceOfMLReaderAdapters", "VoiceOfMLReaderScroll", "VoiceOfMLSearchSidebarRender", "DOMPurify", "marked"]
|
| 26 |
.map(name => [name, "readonly"])) }
|
scripts/build/check_reader_release.mjs
CHANGED
|
@@ -283,6 +283,7 @@ function crossCheck(githubRoot, hfRoot) {
|
|
| 283 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 284 |
"search/discovery/application/random.js",
|
| 285 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
|
|
|
| 286 |
"search/history/infrastructure/store.js",
|
| 287 |
"search/history/application/controller.js",
|
| 288 |
"search/ambient/application/quotation.js",
|
|
|
|
| 283 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 284 |
"search/discovery/application/random.js",
|
| 285 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
| 286 |
+
"search/routing/domain/route.js", "search/routing/application/router.js",
|
| 287 |
"search/history/infrastructure/store.js",
|
| 288 |
"search/history/application/controller.js",
|
| 289 |
"search/ambient/application/quotation.js",
|
scripts/build/compose_app.mjs
CHANGED
|
@@ -11,6 +11,7 @@ export const APP_DEPENDENCIES = Object.freeze([
|
|
| 11 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 12 |
"search/discovery/application/random.js",
|
| 13 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
|
|
|
| 14 |
"search/history/infrastructure/store.js",
|
| 15 |
"search/history/application/controller.js",
|
| 16 |
"search/ambient/application/quotation.js",
|
|
|
|
| 11 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 12 |
"search/discovery/application/random.js",
|
| 13 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
| 14 |
+
"search/routing/domain/route.js", "search/routing/application/router.js",
|
| 15 |
"search/history/infrastructure/store.js",
|
| 16 |
"search/history/application/controller.js",
|
| 17 |
"search/ambient/application/quotation.js",
|
static/app.js
CHANGED
|
@@ -2012,20 +2012,35 @@ function normalizeSearchSort(value) {
|
|
| 2012 |
}
|
| 2013 |
|
| 2014 |
function buildSearchURLParams() {
|
| 2015 |
-
|
| 2016 |
-
|
| 2017 |
-
|
| 2018 |
-
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
|
| 2022 |
-
|
| 2023 |
-
|
| 2024 |
-
|
| 2025 |
-
|
| 2026 |
-
|
| 2027 |
-
|
| 2028 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2029 |
}
|
| 2030 |
|
| 2031 |
let routeInitialized = false;
|
|
@@ -2071,27 +2086,8 @@ function returnFromSidebar() {
|
|
| 2071 |
function closeLeftSidebar() { getShell().closeLeftSidebar(); }
|
| 2072 |
function closeRightSidebar() { getShell().closeRightSidebar(); }
|
| 2073 |
const ROUTER = {
|
| 2074 |
-
parse()
|
| 2075 |
-
|
| 2076 |
-
if (!path || path === "/") return { mode: "global", repo: null };
|
| 2077 |
-
const parts = path.split("/").filter(Boolean);
|
| 2078 |
-
if (parts.length === 1) return { mode: "repo", repo: parts[0] };
|
| 2079 |
-
return { mode: "global", repo: null };
|
| 2080 |
-
},
|
| 2081 |
-
navigate(mode, repo, folder) {
|
| 2082 |
-
const params = buildSearchURLParams();
|
| 2083 |
-
if (mode === "repo" && STATE.mode === "repo" && repo === STATE.repo) {
|
| 2084 |
-
STATE.filterFolderSelfs.forEach(path => params.append("folder_self", path));
|
| 2085 |
-
STATE.filterFolderSubtrees.forEach(path => params.append("folder_subtree", path));
|
| 2086 |
-
}
|
| 2087 |
-
if (mode !== "global" && folder) params.set("path", folder);
|
| 2088 |
-
else if (mode !== "global" && folder === undefined && STATE.browserPath) params.set("path", STATE.browserPath);
|
| 2089 |
-
var qs = params.toString();
|
| 2090 |
-
var url = mode === "global" ? "/" : "/" + repo;
|
| 2091 |
-
if (qs) url += "?" + qs;
|
| 2092 |
-
history.pushState(null, "", url);
|
| 2093 |
-
this.apply();
|
| 2094 |
-
},
|
| 2095 |
apply(preserveSameView = false) {
|
| 2096 |
appliedSearchRoute = location.pathname + location.search;
|
| 2097 |
const route = this.parse();
|
|
@@ -2180,56 +2176,19 @@ const ROUTER = {
|
|
| 2180 |
},
|
| 2181 |
};
|
| 2182 |
|
| 2183 |
-
function syncStateToURL(replace = true) {
|
| 2184 |
-
if (readerHost.overlay) return;
|
| 2185 |
-
const params = buildSearchURLParams();
|
| 2186 |
-
if (STATE.mode === "global") {
|
| 2187 |
-
STATE.filterRepos.forEach(r => {
|
| 2188 |
-
const short = r.split("/").pop();
|
| 2189 |
-
params.append("repo", short);
|
| 2190 |
-
});
|
| 2191 |
-
}
|
| 2192 |
-
if (STATE.mode !== "global" && STATE.browserPath) {
|
| 2193 |
-
params.set("path", STATE.browserPath);
|
| 2194 |
-
}
|
| 2195 |
-
if (STATE.mode !== "global") {
|
| 2196 |
-
STATE.filterFolderSelfs.forEach(folder => params.append("folder_self", folder));
|
| 2197 |
-
STATE.filterFolderSubtrees.forEach(folder => params.append("folder_subtree", folder));
|
| 2198 |
-
}
|
| 2199 |
-
const qs = params.toString();
|
| 2200 |
-
const path = STATE.mode === "global" ? "/" : `/${STATE.repo}`;
|
| 2201 |
-
const url = qs ? `${path}?${qs}` : path;
|
| 2202 |
-
if (replace) {
|
| 2203 |
-
history.replaceState(history.state, "", url);
|
| 2204 |
-
} else {
|
| 2205 |
-
history.pushState(null, "", url);
|
| 2206 |
-
}
|
| 2207 |
-
appliedSearchRoute = location.pathname + location.search;
|
| 2208 |
-
persistSearchSession();
|
| 2209 |
-
}
|
| 2210 |
|
| 2211 |
function syncURLToState() {
|
| 2212 |
const params = new URLSearchParams(window.location.search);
|
| 2213 |
-
|
| 2214 |
-
|
| 2215 |
-
|
| 2216 |
-
showToast("ๆ็ดขๅ
ๅฎนๅทฒ้ๅถไธบ 256 ไธชๅญ็ฌฆ");
|
| 2217 |
-
}
|
| 2218 |
if (!searchComposing && !initialSearchDraft) setSearchInputValue(STATE.query);
|
| 2219 |
-
STATE.filterRepos =
|
| 2220 |
-
STATE.browserPath =
|
| 2221 |
-
|
| 2222 |
-
|
| 2223 |
-
|
| 2224 |
-
if (extStr !== null) {
|
| 2225 |
-
STATE.filterExtensions = extStr ? extStr.split(",").filter(Boolean) : [];
|
| 2226 |
-
saveStoredExtensionFilters();
|
| 2227 |
-
} else if (!routeInitialized) {
|
| 2228 |
-
STATE.filterExtensions = loadStoredExtensionFilters();
|
| 2229 |
-
} else {
|
| 2230 |
-
STATE.filterExtensions = [];
|
| 2231 |
-
saveStoredExtensionFilters();
|
| 2232 |
-
}
|
| 2233 |
const minSize = params.get("min_size");
|
| 2234 |
if (minSize) {
|
| 2235 |
var parsed = parseSizeStr(minSize);
|
|
@@ -2254,39 +2213,25 @@ function syncURLToState() {
|
|
| 2254 |
DOM.filterMaxSize.value = "";
|
| 2255 |
DOM.filterMaxUnit.value = "MB";
|
| 2256 |
}
|
| 2257 |
-
|
| 2258 |
-
STATE.searchFolders = searchFolders !== "false";
|
| 2259 |
DOM.searchFoldersToggle.checked = STATE.searchFolders;
|
| 2260 |
-
|
| 2261 |
-
|
| 2262 |
-
|
| 2263 |
-
|
| 2264 |
-
|
| 2265 |
-
STATE.filterFolderSubtrees = urlSubtrees;
|
| 2266 |
-
STATE.filterFolders = mergeFolderFilters(STATE.filterFolderSelfs, STATE.filterFolderSubtrees);
|
| 2267 |
-
} else {
|
| 2268 |
-
STATE.filterFolderSelfs = [];
|
| 2269 |
-
STATE.filterFolderSubtrees = [];
|
| 2270 |
-
STATE.filterFolders = [];
|
| 2271 |
-
}
|
| 2272 |
-
} else {
|
| 2273 |
-
STATE.filterFolderSelfs = [];
|
| 2274 |
-
STATE.filterFolderSubtrees = [];
|
| 2275 |
-
STATE.filterFolders = [];
|
| 2276 |
-
}
|
| 2277 |
-
STATE.exact = params.get("exact") !== "0";
|
| 2278 |
DOM.exactSearchToggle.checked = STATE.exact;
|
| 2279 |
-
STATE.recordHistory =
|
| 2280 |
if (DOM.historyToggle) DOM.historyToggle.checked = STATE.recordHistory;
|
| 2281 |
-
STATE.useMirrorLinks =
|
| 2282 |
if (DOM.mirrorLinksToggle) DOM.mirrorLinksToggle.checked = STATE.useMirrorLinks;
|
| 2283 |
-
if (
|
| 2284 |
setSidebarExpanded(true);
|
| 2285 |
} else {
|
| 2286 |
setSidebarExpanded(false);
|
| 2287 |
}
|
| 2288 |
-
STATE.leftSidebarOpen =
|
| 2289 |
-
STATE.rightSidebarOpen =
|
| 2290 |
updateSidebarVisibility();
|
| 2291 |
updateSidebarHeader();
|
| 2292 |
STATE.page = 1;
|
|
|
|
| 2012 |
}
|
| 2013 |
|
| 2014 |
function buildSearchURLParams() {
|
| 2015 |
+
return VoiceOfMLRoute.buildParams(readRouteState(), fmtSizeUrl);
|
| 2016 |
+
}
|
| 2017 |
+
|
| 2018 |
+
// Only URL-facing state crosses the routing boundary; result/scroll ownership stays here.
|
| 2019 |
+
function readRouteState() {
|
| 2020 |
+
return {
|
| 2021 |
+
mode: STATE.mode, repo: STATE.repo, browserPath: STATE.browserPath,
|
| 2022 |
+
query: STATE.query, sort: DOM.sortSelect.value,
|
| 2023 |
+
filterRepos: STATE.filterRepos.slice(), filterExtensions: STATE.filterExtensions.slice(),
|
| 2024 |
+
filterFolderSelfs: STATE.filterFolderSelfs.slice(), filterFolderSubtrees: STATE.filterFolderSubtrees.slice(),
|
| 2025 |
+
filterMinSize: STATE.filterMinSize, filterMaxSize: STATE.filterMaxSize,
|
| 2026 |
+
searchFolders: STATE.searchFolders, exact: STATE.exact,
|
| 2027 |
+
recordHistory: STATE.recordHistory, useMirrorLinks: STATE.useMirrorLinks,
|
| 2028 |
+
leftSidebarOpen: STATE.leftSidebarOpen, rightSidebarOpen: STATE.rightSidebarOpen,
|
| 2029 |
+
wide: DOM.leftSidebar.classList.contains("expanded-wide"),
|
| 2030 |
+
};
|
| 2031 |
+
}
|
| 2032 |
+
let routeNavigation;
|
| 2033 |
+
function getRouteNavigation() {
|
| 2034 |
+
return routeNavigation || (routeNavigation = VoiceOfMLRouter.create({
|
| 2035 |
+
readState: readRouteState, buildParams: () => buildSearchURLParams(),
|
| 2036 |
+
readerOpen: () => !!readerHost.overlay,
|
| 2037 |
+
currentURL: () => location.pathname + location.search,
|
| 2038 |
+
replaceURL: url => history.replaceState(history.state, "", url),
|
| 2039 |
+
pushURL: url => history.pushState(null, "", url),
|
| 2040 |
+
applyRoute: () => ROUTER.apply(),
|
| 2041 |
+
commitAppliedURL: url => { appliedSearchRoute = url; },
|
| 2042 |
+
persistSession: () => persistSearchSession(),
|
| 2043 |
+
}));
|
| 2044 |
}
|
| 2045 |
|
| 2046 |
let routeInitialized = false;
|
|
|
|
| 2086 |
function closeLeftSidebar() { getShell().closeLeftSidebar(); }
|
| 2087 |
function closeRightSidebar() { getShell().closeRightSidebar(); }
|
| 2088 |
const ROUTER = {
|
| 2089 |
+
parse: () => VoiceOfMLRoute.parse(window.location.pathname),
|
| 2090 |
+
navigate: (mode, repo, folder) => getRouteNavigation().navigate(mode, repo, folder),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2091 |
apply(preserveSameView = false) {
|
| 2092 |
appliedSearchRoute = location.pathname + location.search;
|
| 2093 |
const route = this.parse();
|
|
|
|
| 2176 |
},
|
| 2177 |
};
|
| 2178 |
|
| 2179 |
+
function syncStateToURL(replace = true) { getRouteNavigation().sync(replace); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2180 |
|
| 2181 |
function syncURLToState() {
|
| 2182 |
const params = new URLSearchParams(window.location.search);
|
| 2183 |
+
const projected = VoiceOfMLRoute.project(params, STATE.mode, routeInitialized);
|
| 2184 |
+
STATE.query = projected.query;
|
| 2185 |
+
if (projected.queryTruncated) showToast("ๆ็ดขๅ
ๅฎนๅทฒ้ๅถไธบ 256 ไธชๅญ็ฌฆ");
|
|
|
|
|
|
|
| 2186 |
if (!searchComposing && !initialSearchDraft) setSearchInputValue(STATE.query);
|
| 2187 |
+
STATE.filterRepos = projected.filterRepos;
|
| 2188 |
+
STATE.browserPath = projected.browserPath;
|
| 2189 |
+
DOM.sortSelect.value = projected.sort;
|
| 2190 |
+
STATE.filterExtensions = projected.filterExtensions === null ? loadStoredExtensionFilters() : projected.filterExtensions;
|
| 2191 |
+
if (projected.filterExtensions !== null) saveStoredExtensionFilters();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2192 |
const minSize = params.get("min_size");
|
| 2193 |
if (minSize) {
|
| 2194 |
var parsed = parseSizeStr(minSize);
|
|
|
|
| 2213 |
DOM.filterMaxSize.value = "";
|
| 2214 |
DOM.filterMaxUnit.value = "MB";
|
| 2215 |
}
|
| 2216 |
+
STATE.searchFolders = projected.searchFolders;
|
|
|
|
| 2217 |
DOM.searchFoldersToggle.checked = STATE.searchFolders;
|
| 2218 |
+
STATE.filterFolderSelfs = projected.filterFolderSelfs;
|
| 2219 |
+
STATE.filterFolderSubtrees = projected.filterFolderSubtrees;
|
| 2220 |
+
STATE.filterFolders = STATE.filterFolderSelfs.length || STATE.filterFolderSubtrees.length
|
| 2221 |
+
? mergeFolderFilters(STATE.filterFolderSelfs, STATE.filterFolderSubtrees) : [];
|
| 2222 |
+
STATE.exact = projected.exact;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2223 |
DOM.exactSearchToggle.checked = STATE.exact;
|
| 2224 |
+
STATE.recordHistory = projected.recordHistory;
|
| 2225 |
if (DOM.historyToggle) DOM.historyToggle.checked = STATE.recordHistory;
|
| 2226 |
+
STATE.useMirrorLinks = projected.useMirrorLinks;
|
| 2227 |
if (DOM.mirrorLinksToggle) DOM.mirrorLinksToggle.checked = STATE.useMirrorLinks;
|
| 2228 |
+
if (projected.wide) {
|
| 2229 |
setSidebarExpanded(true);
|
| 2230 |
} else {
|
| 2231 |
setSidebarExpanded(false);
|
| 2232 |
}
|
| 2233 |
+
STATE.leftSidebarOpen = projected.leftSidebarOpen;
|
| 2234 |
+
STATE.rightSidebarOpen = projected.rightSidebarOpen;
|
| 2235 |
updateSidebarVisibility();
|
| 2236 |
updateSidebarHeader();
|
| 2237 |
STATE.page = 1;
|
static/index.html
CHANGED
|
@@ -349,6 +349,8 @@ if ("serviceWorker" in navigator) {
|
|
| 349 |
<script src="/static/search/discovery/application/random.js"></script>
|
| 350 |
<script src="/static/search/shell/presentation/view.js"></script>
|
| 351 |
<script src="/static/search/shell/application/controller.js"></script>
|
|
|
|
|
|
|
| 352 |
<script src="/static/search/history/infrastructure/store.js"></script>
|
| 353 |
<script src="/static/search/history/application/controller.js"></script>
|
| 354 |
<script src="/static/search/ambient/application/quotation.js"></script>
|
|
|
|
| 349 |
<script src="/static/search/discovery/application/random.js"></script>
|
| 350 |
<script src="/static/search/shell/presentation/view.js"></script>
|
| 351 |
<script src="/static/search/shell/application/controller.js"></script>
|
| 352 |
+
<script src="/static/search/routing/domain/route.js"></script>
|
| 353 |
+
<script src="/static/search/routing/application/router.js"></script>
|
| 354 |
<script src="/static/search/history/infrastructure/store.js"></script>
|
| 355 |
<script src="/static/search/history/application/controller.js"></script>
|
| 356 |
<script src="/static/search/ambient/application/quotation.js"></script>
|
static/reader-resources.js
CHANGED
|
@@ -132,6 +132,7 @@
|
|
| 132 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 133 |
"search/discovery/application/random.js",
|
| 134 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
|
|
|
| 135 |
"search/history/infrastructure/store.js",
|
| 136 |
"search/history/application/controller.js",
|
| 137 |
"search/ambient/application/quotation.js",
|
|
|
|
| 132 |
"search/results/presentation/row.js", "search/results/application/interactions.js",
|
| 133 |
"search/discovery/application/random.js",
|
| 134 |
"search/shell/presentation/view.js", "search/shell/application/controller.js",
|
| 135 |
+
"search/routing/domain/route.js", "search/routing/application/router.js",
|
| 136 |
"search/history/infrastructure/store.js",
|
| 137 |
"search/history/application/controller.js",
|
| 138 |
"search/ambient/application/quotation.js",
|
static/search/routing/application/router.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Navigation owns URL effects; route application and result ownership stay in the host.
|
| 2 |
+
(function () {
|
| 3 |
+
/** @param {VoiceOfMLRouterDependencies} deps */
|
| 4 |
+
function create(deps) {
|
| 5 |
+
/** @param {string} mode @param {string | null} [repo] @param {string} [folder] */
|
| 6 |
+
function navigate(mode, repo, folder) {
|
| 7 |
+
const state = deps.readState();
|
| 8 |
+
const params = deps.buildParams();
|
| 9 |
+
if (mode === "repo" && state.mode === "repo" && repo === state.repo) {
|
| 10 |
+
state.filterFolderSelfs.forEach(path => params.append("folder_self", path));
|
| 11 |
+
state.filterFolderSubtrees.forEach(path => params.append("folder_subtree", path));
|
| 12 |
+
}
|
| 13 |
+
if (mode !== "global" && folder) params.set("path", folder);
|
| 14 |
+
else if (mode !== "global" && folder === undefined && state.browserPath) params.set("path", state.browserPath);
|
| 15 |
+
deps.pushURL(VoiceOfMLRoute.url(mode, repo, params));
|
| 16 |
+
deps.applyRoute();
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/** @param {boolean} [replace] */
|
| 20 |
+
function sync(replace = true) {
|
| 21 |
+
if (deps.readerOpen()) return;
|
| 22 |
+
const state = deps.readState();
|
| 23 |
+
const params = deps.buildParams();
|
| 24 |
+
if (state.mode === "global") state.filterRepos.forEach(repo => params.append("repo", repo.split("/").pop() || ""));
|
| 25 |
+
if (state.mode !== "global" && state.browserPath) params.set("path", state.browserPath);
|
| 26 |
+
if (state.mode !== "global") {
|
| 27 |
+
state.filterFolderSelfs.forEach(folder => params.append("folder_self", folder));
|
| 28 |
+
state.filterFolderSubtrees.forEach(folder => params.append("folder_subtree", folder));
|
| 29 |
+
}
|
| 30 |
+
const url = VoiceOfMLRoute.url(state.mode, state.repo, params);
|
| 31 |
+
if (replace) deps.replaceURL(url);
|
| 32 |
+
else deps.pushURL(url);
|
| 33 |
+
deps.commitAppliedURL(deps.currentURL());
|
| 34 |
+
deps.persistSession();
|
| 35 |
+
}
|
| 36 |
+
return { navigate, sync };
|
| 37 |
+
}
|
| 38 |
+
globalThis.VoiceOfMLRouter = { create };
|
| 39 |
+
})();
|
static/search/routing/domain/route.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Space pathname routes: URLSearchParams.get uses the first scalar occurrence.
|
| 2 |
+
(function () {
|
| 3 |
+
/** @param {string} pathname */
|
| 4 |
+
function parse(pathname) {
|
| 5 |
+
const path = pathname.replace(/\/+$/, "");
|
| 6 |
+
if (!path || path === "/") return { mode: "global", repo: null };
|
| 7 |
+
const parts = path.split("/").filter(Boolean);
|
| 8 |
+
if (parts.length === 1) return { mode: "repo", repo: /** @type {string} */ (parts[0]) };
|
| 9 |
+
return { mode: "global", repo: null };
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
/** @param {VoiceOfMLRouteState} state @param {(value: number) => string} formatSize */
|
| 13 |
+
function buildParams(state, formatSize) {
|
| 14 |
+
const params = new URLSearchParams();
|
| 15 |
+
if (state.query) params.set("q", state.query);
|
| 16 |
+
if (state.filterMinSize !== null) params.set("min_size", formatSize(state.filterMinSize));
|
| 17 |
+
if (state.filterMaxSize !== null) params.set("max_size", formatSize(state.filterMaxSize));
|
| 18 |
+
if (state.filterExtensions.length > 0) params.set("ext", state.filterExtensions.join(","));
|
| 19 |
+
if (!state.recordHistory) params.set("history", "0");
|
| 20 |
+
if (!state.useMirrorLinks) params.set("mirror", "0");
|
| 21 |
+
if (state.sort !== "relevance") params.set("sort", state.sort);
|
| 22 |
+
if (!state.searchFolders) params.set("search_folders", "false");
|
| 23 |
+
if (!state.exact) params.set("exact", "0");
|
| 24 |
+
if (!state.leftSidebarOpen) params.set("sidebar", "0");
|
| 25 |
+
if (state.rightSidebarOpen) params.set("filters", "1");
|
| 26 |
+
if (state.wide) params.set("wide", "1");
|
| 27 |
+
return params;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/** @param {string} mode @param {string | null | undefined} repo @param {URLSearchParams} params */
|
| 31 |
+
function url(mode, repo, params) {
|
| 32 |
+
const path = mode === "global" ? "/" : "/" + repo;
|
| 33 |
+
const query = params.toString();
|
| 34 |
+
return query ? path + "?" + query : path;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/** @param {URLSearchParams} params @param {string} mode @param {boolean} initialized */
|
| 38 |
+
function project(params, mode, initialized) {
|
| 39 |
+
const query = params.get("q") || "";
|
| 40 |
+
const ext = params.get("ext");
|
| 41 |
+
const sort = params.get("sort");
|
| 42 |
+
return {
|
| 43 |
+
query: Array.from(query).slice(0, 256).join(""), queryTruncated: Array.from(query).length > 256,
|
| 44 |
+
filterRepos: params.getAll("repo").map(repo => "VoiceOfML/" + repo),
|
| 45 |
+
filterExtensions: ext === null && !initialized ? null : (ext ? ext.split(",").filter(Boolean) : []),
|
| 46 |
+
browserPath: params.get("path") || "",
|
| 47 |
+
filterFolderSelfs: mode === "global" ? [] : params.getAll("folder_self"),
|
| 48 |
+
filterFolderSubtrees: mode === "global" ? [] : params.getAll("folder_subtree").filter(Boolean),
|
| 49 |
+
sort: sort === "name" || sort === "size" ? sort : "relevance",
|
| 50 |
+
searchFolders: params.get("search_folders") !== "false", exact: params.get("exact") !== "0",
|
| 51 |
+
recordHistory: params.get("history") !== "0", useMirrorLinks: params.get("mirror") !== "0",
|
| 52 |
+
leftSidebarOpen: params.get("sidebar") !== "0", rightSidebarOpen: params.get("filters") === "1", wide: params.get("wide") === "1",
|
| 53 |
+
};
|
| 54 |
+
}
|
| 55 |
+
globalThis.VoiceOfMLRoute = { parse, buildParams, url, project };
|
| 56 |
+
})();
|
static/sw.js
CHANGED
|
@@ -105,6 +105,8 @@ const PRECACHE_URLS = [
|
|
| 105 |
"/static/search/discovery/application/random.js",
|
| 106 |
"/static/search/shell/presentation/view.js",
|
| 107 |
"/static/search/shell/application/controller.js",
|
|
|
|
|
|
|
| 108 |
"/static/search/history/infrastructure/store.js",
|
| 109 |
"/static/search/history/application/controller.js",
|
| 110 |
"/static/search/ambient/application/quotation.js",
|
|
|
|
| 105 |
"/static/search/discovery/application/random.js",
|
| 106 |
"/static/search/shell/presentation/view.js",
|
| 107 |
"/static/search/shell/application/controller.js",
|
| 108 |
+
"/static/search/routing/domain/route.js",
|
| 109 |
+
"/static/search/routing/application/router.js",
|
| 110 |
"/static/search/history/infrastructure/store.js",
|
| 111 |
"/static/search/history/application/controller.js",
|
| 112 |
"/static/search/ambient/application/quotation.js",
|
tests/gates/test_static_contract.py
CHANGED
|
@@ -725,11 +725,15 @@ console.log('Chapter adapter contract passed; 5 negative controls rejected');
|
|
| 725 |
assert_source_contains(self, 'if (pageRect.bottom > viewportRect.top && pageRect.top < viewportRect.bottom) return 2', reader)
|
| 726 |
|
| 727 |
def test_legacy_url_and_sidebar_field_compatibility_are_retired(self):
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
self.
|
| 731 |
-
self.
|
| 732 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
self.assertNotIn("legacyFolders", self.js)
|
| 734 |
self.assertNotIn("data.folders || data.d", self.js)
|
| 735 |
self.assertNotIn("data.files || data.f", self.js)
|
|
|
|
| 725 |
assert_source_contains(self, 'if (pageRect.bottom > viewportRect.top && pageRect.top < viewportRect.bottom) return 2', reader)
|
| 726 |
|
| 727 |
def test_legacy_url_and_sidebar_field_compatibility_are_retired(self):
|
| 728 |
+
routing = (ROOT / "static/search/routing/application/router.js").read_text(encoding="utf-8")
|
| 729 |
+
route = (ROOT / "static/search/routing/domain/route.js").read_text(encoding="utf-8")
|
| 730 |
+
self.assertNotIn('params.getAll("folder")', self.js + route)
|
| 731 |
+
self.assertIn('params.append("folder_self", folder)', routing)
|
| 732 |
+
self.assertIn('params.append("folder_subtree", folder)', routing)
|
| 733 |
+
self.assertNotIn('params.delete("folder_self")', self.js + routing)
|
| 734 |
+
self.assertNotIn('params.delete("folder_subtree")', self.js + routing)
|
| 735 |
+
self.assertIn('getRouteNavigation().sync(replace)', self.js)
|
| 736 |
+
self.assertIn('VoiceOfMLRoute.project(params, STATE.mode, routeInitialized)', self.js)
|
| 737 |
self.assertNotIn("legacyFolders", self.js)
|
| 738 |
self.assertNotIn("data.folders || data.d", self.js)
|
| 739 |
self.assertNotIn("data.files || data.f", self.js)
|
tests/search/reader-navigation/routing_contracts.mjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import assert from 'node:assert/strict';
|
| 2 |
+
import fs from 'node:fs';
|
| 3 |
+
import vm from 'node:vm';
|
| 4 |
+
import test from 'node:test';
|
| 5 |
+
import { APP_DEPENDENCIES, stripBundledScripts } from '../../../scripts/build/compose_app.mjs';
|
| 6 |
+
|
| 7 |
+
const current = fs.readFileSync('static/app.js', 'utf8');
|
| 8 |
+
// The same literal contracts can also run against the exact pre-extraction host.
|
| 9 |
+
const source = process.env.ROUTING_BASELINE_SOURCE ? fs.readFileSync(process.env.ROUTING_BASELINE_SOURCE, 'utf8') : current;
|
| 10 |
+
const pages = current.includes('appliedRouteHash');
|
| 11 |
+
const modules = ['search/routing/domain/route.js', 'search/routing/application/router.js'];
|
| 12 |
+
const plain = value => JSON.parse(JSON.stringify(value));
|
| 13 |
+
function fixture(route = '', overrides = {}) {
|
| 14 |
+
const events = [];
|
| 15 |
+
const location = new URL('https://example.test' + (pages ? '/search/#/' : '/') + route);
|
| 16 |
+
const state = {mode:'repo',repo:'Test',repoFull:'VoiceOfML/Test',browserPath:'old',query:'hello +ไธญ',sort:'name',
|
| 17 |
+
filterRepos:['VoiceOfML/A','VoiceOfML/B'],filterExtensions:['txt','epub'],filterFolderSelfs:['','a+b','a+b'],filterFolderSubtrees:['ๆ /ๅถ'],filterFolders:[],
|
| 18 |
+
filterMinSize:1024,filterMaxSize:0,searchFolders:false,exact:false,useLocalMode:false,recordHistory:false,useMirrorLinks:false,
|
| 19 |
+
leftSidebarOpen:false,rightSidebarOpen:true,isMobile:false,page:4,results:[{}],total:9,...overrides};
|
| 20 |
+
const classes = new Set(['expanded-wide']);
|
| 21 |
+
const dom = {sortSelect:{value:'name'},leftSidebar:{classList:{contains:value=>classes.has(value),toggle(value,on){if(on) classes.add(value);else classes.delete(value);}}}};
|
| 22 |
+
for (const name of ['filterMinSize','filterMinUnit','filterMaxSize','filterMaxUnit','searchFoldersToggle','exactSearchToggle','localModeToggle','historyToggle','mirrorLinksToggle']) dom[name]={};
|
| 23 |
+
const history = {state:{entry:7},replaceState(data,unused,url){events.push(['replace',data,url]);location.href=new URL(url,location).href;},
|
| 24 |
+
pushState(data,unused,url){events.push(['push',data,url]);location.href=new URL(url,location).href;}};
|
| 25 |
+
const c = vm.createContext({URLSearchParams,window:{location},location,history,STATE:state,DOM:dom,readerHost:{overlay:null},
|
| 26 |
+
routeInitialized:false,appliedRouteHash:location.hash,appliedSearchRoute:location.pathname+location.search,routeNavigation:undefined,
|
| 27 |
+
searchComposing:false,initialSearchDraft:false,routeRenderId:2,searchId:10,folderContentsCache:{clear(){}},API:{},
|
| 28 |
+
fmtSizeUrl:value=>value===1024?'1KB':String(value),parseSizeStr:value=>value==='1KB'?1024:Number(value),bytesToDisplay:value=>({value:String(value),unit:'B'}),
|
| 29 |
+
mergeFolderFilters:(a,b)=>[...new Set([...a,...b])],showToast:text=>events.push(['toast',text]),
|
| 30 |
+
setSearchInputValue:value=>events.push(['input',value]),loadStoredExtensionFilters:()=>{events.push(['loadExt']);return ['pdf'];},
|
| 31 |
+
saveStoredExtensionFilters:()=>events.push(['saveExt',plain(state)]),setExactSearchSectionVisible(){},
|
| 32 |
+
updateSidebarVisibility(){},updateSidebarHeader(){},updateRandomTxtVisibility(){},
|
| 33 |
+
setSidebarExpanded(value){dom.leftSidebar.classList.toggle('expanded-wide',value);},
|
| 34 |
+
getSearchViewKey:()=>JSON.stringify([state.mode,state.repo,state.query,state.filterExtensions,state.filterFolderSelfs,state.filterFolderSubtrees]),
|
| 35 |
+
saveSearchViewSnapshot:()=>events.push(['snapshot',state.query]),prepareRouteTransitionResults(){},
|
| 36 |
+
searchInputController:{invalidateVisit:()=>events.push(['intent'])},cancelPendingSearchControls:()=>events.push(['controls']),
|
| 37 |
+
readerReturnPosition:{invalidate:()=>events.push(['reader'])},cancelActiveSearch:()=>{events.push(['cancel']);return true;},
|
| 38 |
+
cancelPositionRestore:()=>events.push(['position']),renderBrowser:(path,id)=>events.push(['browser',path,id]),
|
| 39 |
+
retainFilterRenderingForRoute:id=>events.push(['retain',id]),searchWithInitialFallback:()=>events.push(['search']),
|
| 40 |
+
renderSidebarAndFiltersDeferred:id=>events.push(['filters',id]),renderSidebar:id=>events.push(['sidebar',id]),renderFilters:id=>events.push(['filters',id]),
|
| 41 |
+
persistSearchSession:()=>events.push(['persist']),
|
| 42 |
+
});
|
| 43 |
+
for (const file of modules) vm.runInContext(fs.readFileSync('static/'+file,'utf8'),c);
|
| 44 |
+
for (const name of ['normalizeSearchSort','buildSearchURLParams','readRouteState','getRouteNavigation','syncStateToURL','syncURLToState']) {
|
| 45 |
+
const match=source.match(new RegExp('^function '+name+'\\([^]*?^}', 'm'));
|
| 46 |
+
// syncStateToURL is intentionally a one-line host adapter after extraction.
|
| 47 |
+
const line=source.match(new RegExp('^function '+name+'\\([^\\n]*\\}$','m'));
|
| 48 |
+
if(line || match) vm.runInContext((line || match)[0],c);
|
| 49 |
+
}
|
| 50 |
+
const router=source.match(/^const ROUTER = \{[^]*?^};/m);
|
| 51 |
+
assert.ok(router);vm.runInContext(router[0]+'\nglobalThis.router=ROUTER;',c);
|
| 52 |
+
c.router.updateUI=()=>events.push(['ui']);c.router.onModeChanged=()=>events.push(['mode']);
|
| 53 |
+
return {c,state,dom,events,location,classes};
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
test('routing modules are in HTML, composition, resources, service worker and strict projects',()=>{
|
| 57 |
+
const html=fs.readFileSync('static/index.html','utf8'),c=vm.createContext({});
|
| 58 |
+
vm.runInContext(fs.readFileSync('static/reader-resources.js','utf8'),c);
|
| 59 |
+
for(const path of modules){
|
| 60 |
+
assert.ok(APP_DEPENDENCIES.includes(path));assert.ok(html.indexOf(path)<html.indexOf('static/app.js'));
|
| 61 |
+
assert.ok(html.includes(path));assert.ok(!stripBundledScripts(html).includes(path));
|
| 62 |
+
assert.ok(fs.readFileSync('static/sw.js','utf8').includes('/static/'+path));
|
| 63 |
+
for(const site of ['github','huggingface']) assert.ok(c.VoiceOfMLReaderResources.buildFiles(site).includes(path));
|
| 64 |
+
for(const config of ['check','strict','search-exact']) assert.ok(fs.readFileSync('config/types/jsconfig.'+config+'.json','utf8').includes(path));
|
| 65 |
+
assert.doesNotMatch(fs.readFileSync('static/'+path,'utf8'),/\bSTATE\b|\bVSCROLL\b|\bDOM\b|new Proxy/);
|
| 66 |
+
}
|
| 67 |
+
});
|
| 68 |
+
|
| 69 |
+
test('literal URL serialization preserves site ordering, encoding, size and navigation query policy',()=>{
|
| 70 |
+
const f=fixture();
|
| 71 |
+
const flags='search_folders=false&exact=0&'+(pages?'local=0&':'')+'history=0&mirror=0&sidebar=0&filters=1&wide=1';
|
| 72 |
+
const params=pages?'q=hello+%2B%E4%B8%AD&ext=txt%2Cepub&sort=name&min_size=1024&max_size=0&'+flags
|
| 73 |
+
:'q=hello+%2B%E4%B8%AD&min_size=1KB&max_size=0&ext=txt%2Cepub&history=0&mirror=0&sort=name&search_folders=false&exact=0&sidebar=0&filters=1&wide=1';
|
| 74 |
+
assert.equal(f.c.buildSearchURLParams().toString(),params);
|
| 75 |
+
f.c.router.navigate('repo','Test','a b/ไธญ');
|
| 76 |
+
const nav=pages?'ext=txt%2Cepub&sort=name&min_size=1KB&max_size=0&'+flags:params;
|
| 77 |
+
const suffix='&folder_self=&folder_self=a%2Bb&folder_self=a%2Bb&folder_subtree=%E6%A0%91%2F%E5%8F%B6&path=a+b%2F%E4%B8%AD';
|
| 78 |
+
// HF navigate applies immediately; observe the actual pushed URL before application effects.
|
| 79 |
+
assert.equal(pages?f.location.hash:f.events.find(e=>e[0]==='push')[2],(pages?'#/Test?':'/Test?')+nav+suffix);
|
| 80 |
+
assert.equal(f.events.filter(e=>e[0]==='persist').length,pages?0:1);
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
test('navigate preserves raw repo segments and undefined versus empty folder semantics',()=>{
|
| 84 |
+
for(const folder of [undefined,'','next']){
|
| 85 |
+
const f=fixture();f.c.router.apply=()=>f.events.push(['apply']);
|
| 86 |
+
f.c.router.navigate('repo','A%2FB',folder);
|
| 87 |
+
const raw=pages?f.location.hash:f.events.find(e=>e[0]==='push')[2];
|
| 88 |
+
assert.ok(raw.startsWith((pages?'#/':'/')+'A%2FB?'));
|
| 89 |
+
const params=new URLSearchParams(raw.split('?')[1]);
|
| 90 |
+
assert.equal(params.get('path'),folder===undefined?'old':folder || null);
|
| 91 |
+
assert.equal(params.has('folder_self'),false);
|
| 92 |
+
assert.deepEqual(f.events.map(e=>e[0]),pages?[]:['push','apply']);
|
| 93 |
+
}
|
| 94 |
+
const f=fixture();f.c.router.apply=()=>{};f.c.router.navigate('global');
|
| 95 |
+
assert.equal(f.state.browserPath,pages?'':'old');
|
| 96 |
+
assert.equal(f.events.some(e=>e[0]==='persist'),false);
|
| 97 |
+
});
|
| 98 |
+
|
| 99 |
+
test('parse and projection retain duplicate, empty, legacy and first/last parameter rules',()=>{
|
| 100 |
+
const query='?q=first&q=last+%2B&repo=A&repo=Org%2FB&repo=&ext=pdf&ext=&sort=size&sort=unknown&folder=legacy&folder_self=&folder_self=x&folder_subtree=&folder_subtree=y&exact=0&exact=&local=0&history=0&mirror=0&search_folders=false&sidebar=0&filters=1&wide=1';
|
| 101 |
+
const f=fixture('Test'+query,{mode:'repo',repo:'Test'});
|
| 102 |
+
const parsed=plain(f.c.router.parse());assert.equal(parsed.repo,'Test');
|
| 103 |
+
if(pages) assert.deepEqual(parsed.params.folder,['legacy']);
|
| 104 |
+
f.c.router.apply();
|
| 105 |
+
assert.equal(f.state.query,pages?'last +':'first');
|
| 106 |
+
assert.deepEqual(plain(f.state.filterRepos),pages?['VoiceOfML/A','Org/B','VoiceOfML/']:['VoiceOfML/A','VoiceOfML/Org/B','VoiceOfML/']);
|
| 107 |
+
assert.deepEqual(plain(f.state.filterExtensions),pages?[]:['pdf']);
|
| 108 |
+
assert.equal(pages?f.state.sort:f.dom.sortSelect.value,pages?'relevance':'size');
|
| 109 |
+
assert.deepEqual(plain(f.state.filterFolderSelfs),['','x']);
|
| 110 |
+
assert.deepEqual(plain(f.state.filterFolderSubtrees),pages?['','y']:['y']);
|
| 111 |
+
assert.equal(f.state.exact,pages);assert.equal(f.state.searchFolders,false);
|
| 112 |
+
assert.equal(f.state.recordHistory,false);assert.equal(f.state.useMirrorLinks,false);
|
| 113 |
+
assert.equal(f.state.leftSidebarOpen,false);assert.equal(f.state.rightSidebarOpen,true);
|
| 114 |
+
if(pages) assert.equal(f.state.useLocalMode,false);
|
| 115 |
+
assert.equal(f.classes.has('expanded-wide'),true);
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
+
test('initial-only saved extensions, Unicode limit, IME draft and default flags survive host commits',()=>{
|
| 119 |
+
const f=fixture('Test?q='+encodeURIComponent('๐'.repeat(257)),{mode:'repo',repo:'Test'});
|
| 120 |
+
f.c.searchComposing=true;f.c.router.apply();
|
| 121 |
+
assert.equal(Array.from(f.state.query).length,256);assert.equal(f.state.query,'๐'.repeat(256));
|
| 122 |
+
assert.deepEqual(plain(f.state.filterExtensions),['pdf']);
|
| 123 |
+
assert.equal(f.events.some(e=>e[0]==='input'),false);assert.equal(f.events.filter(e=>e[0]==='loadExt').length,1);
|
| 124 |
+
assert.equal(f.events.filter(e=>e[0]==='saveExt').length,0);
|
| 125 |
+
for(const key of ['searchFolders','exact','recordHistory','useMirrorLinks','leftSidebarOpen']) assert.equal(f.state[key],true);
|
| 126 |
+
assert.equal(f.state.rightSidebarOpen,false);
|
| 127 |
+
f.c.router.apply();assert.deepEqual(plain(f.state.filterExtensions),[]);
|
| 128 |
+
assert.equal(f.events.filter(e=>e[0]==='saveExt').length,1);
|
| 129 |
+
const saved=f.events.find(e=>e[0]==='saveExt')[1];assert.equal(saved.query,'๐'.repeat(256));
|
| 130 |
+
});
|
| 131 |
+
|
| 132 |
+
test('same-view path-only navigation retains active work and geometry; changed views respect cancel reentry',()=>{
|
| 133 |
+
const f=fixture('Test?q=hello&ext=txt',{mode:'repo',repo:'Test'});f.c.router.apply();f.events.length=0;
|
| 134 |
+
f.state.page=7;
|
| 135 |
+
if(pages) f.location.hash+='&path=next';else f.location.search+='&path=next';
|
| 136 |
+
f.c.router.apply();
|
| 137 |
+
for(const forbidden of ['intent','controls','reader','cancel','position','search']) assert.equal(f.events.some(e=>e[0]===forbidden),false,forbidden);
|
| 138 |
+
assert.equal(f.state.page,7);assert.ok(f.events.some(e=>e[0]==='browser'));assert.ok(f.events.some(e=>e[0]==='retain'));
|
| 139 |
+
assert.equal(f.events.at(-1)[0],'persist');
|
| 140 |
+
f.events.length=0;f.c.router.apply(true);
|
| 141 |
+
assert.equal(f.events.some(e=>e[0]==='position'),false);assert.ok(f.events.some(e=>e[0]==='retain'));
|
| 142 |
+
for(const edge of ['cancel','position']){
|
| 143 |
+
f.events.length=0;if(pages) f.location.hash+='&q=changed';else f.location.search='?q=changed';
|
| 144 |
+
f.c.cancelActiveSearch=()=>{f.events.push(['cancel']);return edge!=='cancel';};
|
| 145 |
+
f.c.cancelPositionRestore=()=>{f.events.push(['position']);f.c.searchId++;};
|
| 146 |
+
f.c.router.apply();assert.equal(f.events.some(e=>e[0]==='persist'),false);assert.equal(f.events.some(e=>e[0]==='ui'),false);
|
| 147 |
+
}
|
| 148 |
+
});
|
| 149 |
+
|
| 150 |
+
test('URL sync guards Reader and commits URL before persistence, including unchanged URLs',()=>{
|
| 151 |
+
const f=fixture();f.c.readerHost.overlay={};f.c.syncStateToURL();assert.deepEqual(f.events,[]);
|
| 152 |
+
f.c.readerHost.overlay=null;f.c.syncStateToURL();
|
| 153 |
+
assert.equal(f.events[0][0],'replace');assert.deepEqual(f.events[0][1],{entry:7});assert.equal(f.events.at(-1)[0],'persist');
|
| 154 |
+
assert.equal(pages?f.c.appliedRouteHash:f.c.appliedSearchRoute,pages?f.location.hash:f.location.pathname+f.location.search);
|
| 155 |
+
f.events.length=0;f.c.syncStateToURL();assert.deepEqual(f.events.map(e=>e[0]),pages?['persist']:['replace','persist']);
|
| 156 |
+
if(!pages){f.events.length=0;f.c.syncStateToURL(false);assert.deepEqual(f.events.map(e=>e[0]),['push','persist']);assert.equal(f.events[0][1],null);}
|
| 157 |
+
});
|
tests/search/reader-navigation/test_search_history_races.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import fs from 'node:fs';
|
|
| 5 |
import vm from 'node:vm';
|
| 6 |
import test from 'node:test';
|
| 7 |
import './host_contracts.mjs';
|
|
|
|
| 8 |
import '../paging/result_window_contracts.mjs';
|
| 9 |
import '../session/test_positions_persistence.mjs';
|
| 10 |
import '../session/test_result_snapshots.mjs';
|
|
|
|
| 5 |
import vm from 'node:vm';
|
| 6 |
import test from 'node:test';
|
| 7 |
import './host_contracts.mjs';
|
| 8 |
+
import './routing_contracts.mjs';
|
| 9 |
import '../paging/result_window_contracts.mjs';
|
| 10 |
import '../session/test_positions_persistence.mjs';
|
| 11 |
import '../session/test_result_snapshots.mjs';
|
tests/support/classic_search_modules.js
CHANGED
|
@@ -10,6 +10,7 @@ const MODULES = ["static/search/execution/domain/policy.js", "static/search/exec
|
|
| 10 |
"static/search/results/presentation/row.js", "static/search/results/application/interactions.js",
|
| 11 |
"static/search/discovery/application/random.js",
|
| 12 |
"static/search/shell/presentation/view.js", "static/search/shell/application/controller.js",
|
|
|
|
| 13 |
"static/search/history/infrastructure/store.js", "static/search/history/application/controller.js",
|
| 14 |
"static/search/ambient/application/quotation.js",
|
| 15 |
"static/search/results/snapshots/domain/copy-budget.js", "static/search/results/snapshots/application/store.js",
|
|
|
|
| 10 |
"static/search/results/presentation/row.js", "static/search/results/application/interactions.js",
|
| 11 |
"static/search/discovery/application/random.js",
|
| 12 |
"static/search/shell/presentation/view.js", "static/search/shell/application/controller.js",
|
| 13 |
+
"static/search/routing/domain/route.js", "static/search/routing/application/router.js",
|
| 14 |
"static/search/history/infrastructure/store.js", "static/search/history/application/controller.js",
|
| 15 |
"static/search/ambient/application/quotation.js",
|
| 16 |
"static/search/results/snapshots/domain/copy-budget.js", "static/search/results/snapshots/application/store.js",
|
typings/search-routing.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
interface VoiceOfMLRouteState {
|
| 2 |
+
mode: string; repo: string | null; browserPath: string; query: string; sort: string;
|
| 3 |
+
filterRepos: string[]; filterExtensions: string[]; filterFolderSelfs: string[]; filterFolderSubtrees: string[];
|
| 4 |
+
filterMinSize: number | null; filterMaxSize: number | null;
|
| 5 |
+
searchFolders: boolean; exact: boolean; recordHistory: boolean; useMirrorLinks: boolean;
|
| 6 |
+
leftSidebarOpen: boolean; rightSidebarOpen: boolean; wide: boolean;
|
| 7 |
+
}
|
| 8 |
+
interface VoiceOfMLRouteProjection {
|
| 9 |
+
query: string; queryTruncated: boolean; filterRepos: string[]; filterExtensions: string[] | null;
|
| 10 |
+
browserPath: string; filterFolderSelfs: string[]; filterFolderSubtrees: string[]; sort: string;
|
| 11 |
+
searchFolders: boolean; exact: boolean; recordHistory: boolean; useMirrorLinks: boolean;
|
| 12 |
+
leftSidebarOpen: boolean; rightSidebarOpen: boolean; wide: boolean;
|
| 13 |
+
}
|
| 14 |
+
interface VoiceOfMLRouterDependencies {
|
| 15 |
+
readState(): VoiceOfMLRouteState;
|
| 16 |
+
buildParams(): URLSearchParams;
|
| 17 |
+
readerOpen(): boolean;
|
| 18 |
+
currentURL(): string;
|
| 19 |
+
replaceURL(url: string): void;
|
| 20 |
+
pushURL(url: string): void;
|
| 21 |
+
applyRoute(): void;
|
| 22 |
+
commitAppliedURL(url: string): void;
|
| 23 |
+
persistSession(): void;
|
| 24 |
+
}
|
| 25 |
+
declare var VoiceOfMLRoute: {
|
| 26 |
+
parse(pathname: string): { mode: string; repo: string | null };
|
| 27 |
+
buildParams(state: VoiceOfMLRouteState, formatSize: (value: number) => string): URLSearchParams;
|
| 28 |
+
url(mode: string, repo: string | null | undefined, params: URLSearchParams): string;
|
| 29 |
+
project(params: URLSearchParams, mode: string, initialized: boolean): VoiceOfMLRouteProjection;
|
| 30 |
+
};
|
| 31 |
+
declare var VoiceOfMLRouter: { create(deps: VoiceOfMLRouterDependencies): {
|
| 32 |
+
navigate(mode: string, repo?: string | null, folder?: string): void;
|
| 33 |
+
sync(replace?: boolean): void;
|
| 34 |
+
}};
|