@uniweb/core 0.35.3 → 0.36.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/core",
3
- "version": "0.35.3",
3
+ "version": "0.36.0",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
package/src/data-keys.js CHANGED
@@ -37,7 +37,14 @@ export const WHOLE_SUFFIX = '/*'
37
37
  * 2026-09-27 [Diego]). The runtime asks each key's question accordingly; a key declared whole
38
38
  * that its fetch cannot fill whole is `null`.
39
39
  *
40
- * @param {*} value - one `data:` entry's value, authored or leaned
40
+ * Who passes what. The runtime: a section type's LEAN `data` — a ref string or null, from the
41
+ * runtime schema the build extracts (`@uniweb/build`'s `runtime-schema.js`) — and the foundation's
42
+ * own `main.js` `data:` as written. A build-time reader: a `meta.js` value as written, or a
43
+ * registered foundation schema's in its normalized form (`schemaFormat: 3`, `@uniweb/schemas`'s
44
+ * `normalizeFoundationSchema`), which writes every ref as `{ kind: 'schema', schema, whole }` — the
45
+ * ref qualified and `whole` said outright.
46
+ *
47
+ * @param {*} value - one `data:` entry's value, authored, leaned or normalized
41
48
  * @returns {{ ref: string|null, whole: boolean }}
42
49
  */
43
50
  export function dataRefOf(value) {
@@ -46,7 +53,7 @@ export function dataRefOf(value) {
46
53
  : (value && typeof value === 'object' && typeof value.schema === 'string' ? value.schema : '')
47
54
  if (!raw) return { ref: null, whole: false }
48
55
  if (raw.endsWith(WHOLE_SUFFIX)) return { ref: raw.slice(0, -WHOLE_SUFFIX.length) || null, whole: true }
49
- return { ref: raw, whole: false }
56
+ return { ref: raw, whole: typeof value === 'object' && value.whole === true }
50
57
  }
51
58
 
52
59
  /**
@@ -79,13 +86,15 @@ export function declaredKeys(componentData, foundationData = null) {
79
86
  /**
80
87
  * Do two schema refs name the same schema?
81
88
  *
82
- * ⭐ `@/<name>` is "this project's own `<name>`", and what that project is differs by who
83
- * wrote it: in a foundation's `meta.js` it is the foundation's schema, in a site's
84
- * `queries.yml` the site's — and a site synced to a host has its queries' `@/` refs
85
- * qualified with its org (`@acme/member`). So a local ref matches a ref of ANY scope with
86
- * the same name; two scoped refs match only when their scopes agree. Decided 2026-09-14
87
- * (the plan's §7 left it to framework): `@/member` and `@acme/member` match,
88
- * `@std/person` and `@acme/person` do not.
89
+ * ⭐ `@/<name>` is `<name>` in the FOUNDATION's own scope — the one in its name
90
+ * (`@acme/marketing` → `@acme/member`) — in its `meta.js` and in a site's `queries.yml`
91
+ * alike. A push qualifies a site's `@/` refs with that scope (`@uniweb/build`'s
92
+ * `uwx/self-scope.js`, ruled 2026-09-22), never with the org that owns the site. This match
93
+ * does not know the scope, so a local ref matches a ref of ANY scope with the same name; two
94
+ * scoped refs match only when their scopes agree. Decided 2026-09-14 (the plan's §7 left it
95
+ * to framework): `@/member` and `@acme/member` match, `@std/person` and `@acme/person` do not.
96
+ * ⛔ Until 2026-10-01 this said a site's `@/` meant the site's own schema, qualified with the
97
+ * site's org — the rule before 2026-09-22 — which read as if `@/` had two meanings.
89
98
  *
90
99
  * @param {string|null|undefined} a
91
100
  * @param {string|null|undefined} b
@@ -44,10 +44,10 @@ function collectTransports(decl, { source, dev }) {
44
44
 
45
45
  let raw
46
46
  try {
47
- // A built foundation carries its declarations under `default.capabilities`
48
- // — framework/build/src/generate-entry.js spreads the source `main.js`
49
- // default (props, transports, …) into `capabilities`, and `decl` here is
50
- // that built `default` (= { meta, capabilities, layoutMeta }). Transports
47
+ // A built foundation carries what the runtime reads of its `main.js` under
48
+ // `default.capabilities` — framework/build/src/generate-entry.js references
49
+ // the code keys there, `transports` among them — and `decl` here is that
50
+ // built `default` (= { meta, capabilities, layoutMeta }). Transports
51
51
  // therefore live at `default.capabilities.transports`: a single direct
52
52
  // read, no fallback chain (the runtime only ever sees the built shape).
53
53
  raw = decl.capabilities?.transports
@@ -34,7 +34,8 @@ export const RESOLUTION_STATUS = Object.freeze({
34
34
  // A page's redirect — authored, or a page with no content going to its content. Temporary:
35
35
  // what a container lands on changes when its pages do.
36
36
  pageRedirect: 302,
37
- // The locale a host serves unprefixed, asked for with its prefix: the same page, for good.
37
+ // A URL other than the locale's own, for the same page, for good: the unprefixed locale asked
38
+ // for with its prefix, or a page asked for at another route than the locale shows it at.
38
39
  localeRedirect: 301,
39
40
  })
40
41
 
@@ -208,25 +209,31 @@ export function localeOfPath(path, config = {}) {
208
209
  return { locale: unprefixed, prefixed: false, path: raw }
209
210
  }
210
211
 
212
+ /** The route a path asks for: decoded, the active locale's prefix off, no trailing slash. */
213
+ function askedRoute(path, activeLocale, defaultLocale) {
214
+ let stripped = decodeRouteValue(path)
215
+ if (activeLocale && activeLocale !== defaultLocale) {
216
+ const prefix = `/${activeLocale}`
217
+ if (stripped === prefix || stripped === `${prefix}/`) stripped = '/'
218
+ else if (stripped.startsWith(`${prefix}/`)) stripped = stripped.slice(prefix.length)
219
+ }
220
+ return stripped === '/' ? '/' : stripped.replace(/\/$/, '')
221
+ }
222
+
211
223
  /**
212
224
  * The page a path names — as `Website#getPage` has always found it — or null.
213
225
  *
214
226
  * In order: the active locale's prefix comes off; the page whose route is the path as given (a
215
227
  * published payload may carry a locale's own routes); else the path reverse-translated and the
216
- * page of that canonical route (a folder resolving to its `isIndex` child either way); else an
217
- * index page whose own URL is the path; else the parametric pages in page order, against the
218
- * canonical route and then the path as given. A static page always wins.
228
+ * page of that canonical route (a folder resolving to its `isIndex` child either way); else that
229
+ * canonical route as this locale shows it, on a payload of the locale's own routes; else an index
230
+ * page whose own URL is one of them; else the parametric pages in page order, against the
231
+ * canonical route, the path as given and the locale's route. A static page always wins.
219
232
  *
220
233
  * @returns {{ page: Object, route: string, params: Object, template: string|null } | null}
221
234
  */
222
235
  function findPage(index, path, { activeLocale, defaultLocale }) {
223
- let stripped = decodeRouteValue(path)
224
- if (activeLocale && activeLocale !== defaultLocale) {
225
- const prefix = `/${activeLocale}`
226
- if (stripped === prefix || stripped === `${prefix}/`) stripped = '/'
227
- else if (stripped.startsWith(`${prefix}/`)) stripped = stripped.slice(prefix.length)
228
- }
229
- const asGiven = stripped === '/' ? '/' : stripped.replace(/\/$/, '')
236
+ const asGiven = askedRoute(path, activeLocale, defaultLocale)
230
237
 
231
238
  const promoted = (page) => (index.childrenOf.get(page.route) || []).find(isIndex) || page
232
239
  const exactly = (route) => index.byRoute.get(route)
@@ -245,10 +252,18 @@ function findPage(index, path, { activeLocale, defaultLocale }) {
245
252
  return { page, route: page.route, params: {}, template: null }
246
253
  }
247
254
 
248
- const indexPage = index.pages.find((p) => isIndex(p) && navRoute(p) === canonical)
255
+ // A canonical route asked for on a payload whose pages carry this locale's own routes.
256
+ const shown = translateRoute(index, canonical, activeLocale)
257
+ const translated = shown !== asGiven ? exactly(shown) : null
258
+ if (translated) {
259
+ const page = promoted(translated)
260
+ return { page, route: page.route, params: {}, template: null }
261
+ }
262
+
263
+ const indexPage = index.pages.find((p) => isIndex(p) && (navRoute(p) === canonical || navRoute(p) === shown))
249
264
  if (indexPage) return { page: indexPage, route: indexPage.route, params: {}, template: null }
250
265
 
251
- for (const candidate of new Set([canonical, asGiven])) {
266
+ for (const candidate of new Set([canonical, asGiven, shown])) {
252
267
  for (const page of index.pages) {
253
268
  if (!page.route.includes(':')) continue
254
269
  const hit = matchDynamicRoute(page.route, candidate)
@@ -293,8 +308,10 @@ export function landingRoute(site, page, seen = new Set()) {
293
308
  *
294
309
  * In order:
295
310
  * 1. **The locale served unprefixed, asked for with its prefix** — `/en/docs` where `en` is the
296
- * default (or the host's own locale) — is a `301` to the path without it. Ruled 2026-09-30
297
- * [Diego]; until then no page matched it.
311
+ * default (or the host's own locale) — is a `301` to the path without it, and when the rest names
312
+ * a page, to this locale's own URL for it: `/fr/about` on a French host is `/a-propos`, in one
313
+ * hop. Ruled 2026-09-30 [Diego]; until then no page matched it. ⛔ Until 2026-10-01 it went to the
314
+ * rest as written, and `/about` was a second `301`.
298
315
  * 2. **The page** (`findPage`). None ⇒ `notFound`, with the site's not-found page: its
299
316
  * `notFound` content, else the page at `/404`.
300
317
  * 3. **An authored `redirect:`** ⇒ a `302` to it: a page of the site in this locale, anything
@@ -305,6 +322,12 @@ export function landingRoute(site, page, seen = new Set()) {
305
322
  * 6. Otherwise the page. A parametric page's record may still not exist; that is the render's
306
323
  * data step to say.
307
324
  *
325
+ * ⭐ **One URL per page per language** (ruled 2026-10-01): a page asked for at another route than
326
+ * this locale shows it at — `/fr/blog` where French shows `/fr/blogue` — is a `301` there
327
+ * (`localeOwnUrl`), before 4 and 6, and folded into 1. A redirect (3) and a container (5) already
328
+ * send the visitor to this locale's URL for their destination, in one hop. Only `301`s fold: a
329
+ * `302` is temporary, so a prefixed path to one is two hops, the `302` its own.
330
+ *
308
331
  * `status` is what a host that sends one sends. A static host has its own ways to say each kind.
309
332
  *
310
333
  * @param {Object} site - one locale's site content (`{ pages, config, notFound? }`), or its `routeIndex`
@@ -319,11 +342,19 @@ export function resolveRoute(site, path, context = {}) {
319
342
  const defaultLocale = context.defaultLocale ?? index.defaultLocale
320
343
  const raw = typeof path === 'string' && path ? path : '/'
321
344
 
322
- // 1 · the unprefixed locale, asked for with its prefix. The rest of the path goes as written.
345
+ // 1 · the unprefixed locale, asked for with its prefix: to the locale's own URL for the page the
346
+ // rest of the path names, in ONE 301 — `/fr/about` on a French host is `/a-propos`, never `/about`
347
+ // first (ruled 2026-10-01 [Diego]: "fold them into a single 301"). The rest as written when it names
348
+ // no page. Only 301s fold: a container's or an authored 302 is temporary, and stays its own hop.
349
+ // The redirect names no page, as before.
323
350
  if (defaultLocale) {
324
351
  const prefix = `/${defaultLocale}`
325
- if (raw === prefix || raw === `${prefix}/`) return redirect('/', RESOLUTION_STATUS.localeRedirect, 'locale')
326
- if (raw.startsWith(`${prefix}/`)) return redirect(raw.slice(prefix.length), RESOLUTION_STATUS.localeRedirect, 'locale')
352
+ const rest = raw === prefix || raw === `${prefix}/` ? '/' : raw.startsWith(`${prefix}/`) ? raw.slice(prefix.length) : null
353
+ if (rest !== null) {
354
+ const ctx = { activeLocale, defaultLocale }
355
+ const own = findPage(index, rest, ctx) ? localeOwnUrl(index, rest, ctx) : null
356
+ return redirect(own || rest, RESOLUTION_STATUS.localeRedirect, 'locale')
357
+ }
327
358
  }
328
359
 
329
360
  // 2 · the page
@@ -331,17 +362,24 @@ export function resolveRoute(site, path, context = {}) {
331
362
  if (!found) return { kind: 'notFound', status: RESOLUTION_STATUS.notFound, page: index.notFound }
332
363
  const { page } = found
333
364
 
334
- // 3 · 4 · what an author wrote on the page
365
+ // 3 · what an author wrote on the page: a redirect goes to its own destination, in one hop
335
366
  if (typeof page.redirect === 'string' && page.redirect) {
336
367
  const location = authoredRedirectLocation(index, found.route, page.redirect, { activeLocale, defaultLocale })
337
368
  return { ...redirect(location, RESOLUTION_STATUS.pageRedirect, 'authored'), ...found }
338
369
  }
370
+
371
+ // 4 · 6 · asked for at another route than this locale shows the page at: there, for good. The
372
+ // redirect still names the page, so a Website still finds it.
373
+ const ownUrl = () => {
374
+ const location = localeOwnUrl(index, raw, { activeLocale, defaultLocale })
375
+ return location && { ...redirect(location, RESOLUTION_STATUS.localeRedirect, 'locale'), ...found }
376
+ }
339
377
  if (typeof page.rewrite === 'string' && page.rewrite) {
340
- return { kind: 'rewrite', target: page.rewrite, ...found }
378
+ return ownUrl() || { kind: 'rewrite', target: page.rewrite, ...found }
341
379
  }
342
380
 
343
381
  // 5 · a page with no content goes to its content. The DECISION is canonical (`page.route`);
344
- // the DESTINATION is this locale's URL for it.
382
+ // the DESTINATION is this locale's URL for it, in one hop.
345
383
  if (!hasContent(page)) {
346
384
  const landing = landingRoute(index, page)
347
385
  if (landing && landing !== page.route) {
@@ -350,7 +388,27 @@ export function resolveRoute(site, path, context = {}) {
350
388
  }
351
389
  }
352
390
 
353
- return { kind: 'page', status: RESOLUTION_STATUS.page, ...found }
391
+ return ownUrl() || { kind: 'page', status: RESOLUTION_STATUS.page, ...found }
392
+ }
393
+
394
+ /**
395
+ * ⭐ THE URL THIS LOCALE SHOWS A PAGE AT, when the path asked for it at another route — the
396
+ * canonical route under a translated locale (`/fr/blog` where French shows `/fr/blogue`), or a
397
+ * translated folder with an untranslated child (`/fr/documents/intro`). Null when the path is that
398
+ * route already, which it always is in the site's default locale, whose routes are the canonical
399
+ * ones. A trailing slash or a percent-encoding is not another route.
400
+ *
401
+ * Ruled 2026-10-01 [Diego]: one URL per page per language, a `301` like the unprefixed locale's
402
+ * own prefix. ⛔ Until then `/fr/blog` was the French page on a payload of canonical routes and
403
+ * not found on one whose pages carry the French routes.
404
+ *
405
+ * @returns {string|null}
406
+ */
407
+ function localeOwnUrl(index, path, { activeLocale, defaultLocale }) {
408
+ const asked = askedRoute(path, activeLocale, defaultLocale)
409
+ const canonical = reverseTranslateRoute(index, asked, activeLocale)
410
+ if (translateRoute(index, canonical, activeLocale) === asked) return null
411
+ return localeUrl(index, activeLocale, canonical, { activeLocale, defaultLocale })
354
412
  }
355
413
 
356
414
  function redirect(location, status, reason) {
package/src/website.js CHANGED
@@ -772,13 +772,6 @@ export default class Website {
772
772
  return globalThis.uniweb.foundationConfig?.viewTransitions !== false
773
773
  }
774
774
 
775
- /**
776
- * Get remote props from foundation config
777
- */
778
- getRemoteProps() {
779
- return globalThis.uniweb?.foundationConfig?.props || null
780
- }
781
-
782
775
  /**
783
776
  * Get routing components (Link, useNavigate, etc.)
784
777
  */