@uniweb/core 1.6.0 → 1.6.2

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": "1.6.0",
3
+ "version": "1.6.2",
4
4
  "description": "Core classes for the Uniweb platform - Uniweb, Website, Page, Block",
5
5
  "type": "module",
6
6
  "exports": {
@@ -21,7 +21,7 @@
21
21
  * @module @uniweb/core/resolve-route
22
22
  */
23
23
 
24
- import { decodeRouteValue, matchDynamicRoute, parentRouteOf } from './route-match.js'
24
+ import { decodeRouteValue, isDynamicRoute, matchDynamicRoute, parentRouteOf } from './route-match.js'
25
25
  import { resolveDefaultLocale } from './locale-config.js'
26
26
  import { siteAddress } from './site-address.js'
27
27
 
@@ -313,7 +313,7 @@ function findPage(index, path, { activeLocale, defaultLocale }) {
313
313
 
314
314
  for (const candidate of new Set([canonical, asGiven, shown])) {
315
315
  for (const page of index.pages) {
316
- if (!page.route.includes(':')) continue
316
+ if (!isDynamicRoute(page.route)) continue
317
317
  const hit = matchDynamicRoute(page.route, candidate)
318
318
  if (hit) return { page, route: candidate, params: hit.params, template: page.route }
319
319
  }
@@ -11,10 +11,9 @@
11
11
  * question, neither wrong on the routes anyone had tried.
12
12
  *
13
13
  * That is already bad inside one repo. It is worse across them, because the
14
- * matcher answers a question more than one lane asks: *which page does this
15
- * path name?* A consumer outside this repo routes with these patterns —
16
- * `hosting/framework-surface.json` declares `routePatternToRegex`,
17
- * `isDynamicRoute` and `normalizeRoute` read by its `src/routes.js`. Two copies
14
+ * matcher answers a question more than one program asks: *which page does this
15
+ * path name?* A host that serves a site asks it too, before it renders anything,
16
+ * which is why this leaf can be imported on its own. Two copies
18
17
  * that disagree by a single route give two answers to page identity, silently,
19
18
  * and only on the paths that have a pattern — which are exactly the interesting
20
19
  * ones. So this is a cross-boundary contract, not an implementation detail, and
@@ -33,7 +32,10 @@
33
32
  *
34
33
  * ## The syntax, in full
35
34
  *
36
- * `:param` captures exactly one non-empty path segment. `:param*` — the ONE
35
+ * `:param` captures exactly one non-empty path segment, and starts it: literal
36
+ * text may follow the name in its segment (`/files/:name.json`), while a `:`
37
+ * anywhere else in a segment is the character itself (`/Note:-a-thing` is a page,
38
+ * not a pattern). `:param*` — the ONE
37
39
  * multi-segment construct, admitted 2026-09-04 by ruling [Diego] for the
38
40
  * `[...path]` route folder — captures one or more segments, slashes intact, and
39
41
  * only as the FINAL segment of a pattern; anywhere else the `*` is the literal it
@@ -84,13 +86,27 @@ export function normalizeRoute(route) {
84
86
  }
85
87
 
86
88
  /**
87
- * Whether a route is a dynamic template rather than a concrete path.
89
+ * A parameter, wherever a pattern may hold one: `:name` at the START of a segment.
90
+ * Literal text may follow the name in that segment (`/files/:name.json`), and a `:`
91
+ * anywhere else in a segment is the character itself. `lead` is what precedes the
92
+ * `:`, a `/` or the start of the pattern, kept by whoever replaces the parameter.
93
+ */
94
+ const PARAM_SOURCE = `(^|/):(${PARAM_NAME})`
95
+
96
+ /**
97
+ * Whether a route is a dynamic template rather than a concrete path: whether one
98
+ * of its segments starts with a parameter (`/blog/:slug`, `/files/:name.json`,
99
+ * `/docs/:path*`).
100
+ *
101
+ * A route is plain text, so a `:` an author typed into a slug is text too:
102
+ * `/Note:-a-thing` is a page. Until 2026-11-02 this asked whether a route held a
103
+ * `:` at all, so that page left every menu and `/Noteabc` resolved to it.
88
104
  *
89
105
  * @param {string} route
90
106
  * @returns {boolean}
91
107
  */
92
108
  export function isDynamicRoute(route) {
93
- return typeof route === 'string' && route.includes(':')
109
+ return typeof route === 'string' && new RegExp(PARAM_SOURCE).test(route)
94
110
  }
95
111
 
96
112
  /** The catch-all token, only as a pattern's final segment: `/:path*`. */
@@ -123,10 +139,10 @@ export function routePatternToRegex(pattern) {
123
139
  let source = head
124
140
  // Escape first: a `.` in a route is a literal `.`, not "any character".
125
141
  .replace(REGEX_SPECIALS, '\\$&')
126
- // Then each `:name` becomes one non-empty segment capture.
127
- .replace(new RegExp(`:(${PARAM_NAME})`, 'g'), (_, name) => {
142
+ // Then each `:name` that starts a segment becomes one non-empty segment capture.
143
+ .replace(new RegExp(PARAM_SOURCE, 'g'), (_, lead, name) => {
128
144
  paramNames.push(name)
129
- return '([^/]+)'
145
+ return `${lead}([^/]+)`
130
146
  })
131
147
  if (catchAll) {
132
148
  paramNames.push(catchAll)
@@ -557,7 +573,7 @@ export function parentRouteOf(route, { declared = null, has } = {}) {
557
573
  * when its route ENDS in a parameter. ⛔ A page nested inside a parametric one —
558
574
  * `/members/:slug/cv` — does not, and returns null: composing a record onto it would
559
575
  * produce `/members/:slug/alice`, a URL that ranks in an index and 404s on click
560
- * (the failure hosting measured in their own fixture, 2026-09-12). A static page
576
+ * (the failure a host measured in its own fixture, 2026-09-12). A static page
561
577
  * returns null too, so a page that merely fetches to render itself contributes
562
578
  * nothing to a record index.
563
579
  *
@@ -623,16 +639,16 @@ export function fillRoutePattern(pattern, values, { field = null } = {}) {
623
639
  tailHref = '/' + encodeURIComponent(String(handle))
624
640
  head = pattern.slice(0, tail.index)
625
641
  }
626
- const href = head.replace(new RegExp(`:(${PARAM_NAME})`, 'g'), (_, name) => {
642
+ const href = head.replace(new RegExp(PARAM_SOURCE, 'g'), (_, lead, name) => {
627
643
  // ⭐ THE FIRST MEMBER of a `multi` field — a record has ONE canonical href, and
628
644
  // every member routes to it (`routeParamValues`). Baked whole, a `['a','b']`
629
645
  // field produced `/tags/a%2Cb`, a URL no lane matches.
630
646
  const [value] = routeParamValues(values, name, name === 'slug' ? field : null)
631
647
  if (value === undefined) {
632
648
  missing = true
633
- return ''
649
+ return lead
634
650
  }
635
- return encodeURIComponent(value)
651
+ return lead + encodeURIComponent(value)
636
652
  })
637
653
  return missing ? null : href + tailHref
638
654
  }
package/src/tracker.js CHANGED
@@ -287,6 +287,12 @@ export default class Tracker {
287
287
  // after construction. Same reason `Uniweb.defaultInsets` is pre-declared.
288
288
  this.onGranted = null
289
289
 
290
+ // Told each new path, after its `page_view`. The runtime's on-demand listener
291
+ // chunk uses it to notice a page the site counts as a conversion, without
292
+ // every site paying for a route subscription. Declared here for the same
293
+ // reason as `onGranted`.
294
+ this.onPage = null
295
+
290
296
  if (isBrowser && this.isEnabled()) {
291
297
  this.acquisition = captureAcquisition()
292
298
  // Minted even when consent is pending: events buffered before the visitor
@@ -499,21 +505,27 @@ export default class Tracker {
499
505
  this.currentPath = path
500
506
  this.startTimeOnPage()
501
507
 
502
- if (!this.arms('page_view')) return
503
508
  // Promptly, rather than waiting out the batch window: a page view is the
504
509
  // event most likely to be the only one of a short visit.
505
510
  //
506
511
  // Emitted only when true, like `continues` — absent is the negative, and it
507
512
  // keeps every later view the size it already was.
508
- this.enqueue(
509
- {
510
- event: 'page_view',
511
- path,
512
- ...(this.acquisition || {}),
513
- ...(firstOfLoad ? { first_of_load: true } : {})
514
- },
515
- true
516
- )
513
+ if (this.arms('page_view')) {
514
+ this.enqueue(
515
+ {
516
+ event: 'page_view',
517
+ path,
518
+ ...(this.acquisition || {}),
519
+ ...(firstOfLoad ? { first_of_load: true } : {})
520
+ },
521
+ true
522
+ )
523
+ }
524
+
525
+ // After the view, so what it reports follows the arrival it belongs to. Not
526
+ // behind `page_view`'s selection, for the reason this method's first comment
527
+ // gives: a site can select one without the other.
528
+ this.onPage?.(path)
517
529
  }
518
530
 
519
531
  /**
package/src/uniweb.js CHANGED
@@ -94,7 +94,7 @@ export default class Uniweb {
94
94
  // which is not what this class is for; and the guard it bought was never
95
95
  // taken up — every reader in the workspace already optional-chains
96
96
  // (`block.js`'s `track()`, and the runtime's `usePageView`,
97
- // `useSectionViews`, `useOutboundClicks`, `useSectionClicks`), so the
97
+ // `useSectionViews`, `useDocumentEvents`), so the
98
98
  // invariant lived only in the comment. Cost of carrying it: 1,576 gzip in
99
99
  // core's chunk, which press, unipress, `@uniweb/api` and every SSR isolate
100
100
  // paid for a class they never wire.
package/src/website.js CHANGED
@@ -12,7 +12,7 @@ import ObservableState from './observable-state.js'
12
12
  import { normalizeSeo } from './seo.js'
13
13
  import { siteAddress, pageUrl } from './site-address.js'
14
14
  import { resolveDefaultLocale, localeLabel } from './locale-config.js'
15
- import { matchDynamicRoute, recordTitle, recordImage, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
15
+ import { isDynamicRoute, matchDynamicRoute, recordTitle, recordImage, routeBinding, routeParamName, parentRouteOf } from './route-match.js'
16
16
  import { resolveFetchConfigs, pageRouteQuery, recordPages } from './fetch-config.js'
17
17
  import { declaredKeys } from './data-keys.js'
18
18
  import { pageRecordConfig, planFor, runPlanSync } from './page-data.js'
@@ -179,7 +179,7 @@ export default class Website {
179
179
  // materialize concrete pages on demand (/blog/:slug → /blog/my-post).
180
180
  this._dynamicPageData = new Map()
181
181
  for (const pageData of regularPages) {
182
- if (pageData.isDynamic || pageData.route?.includes(':')) {
182
+ if (pageData.isDynamic || isDynamicRoute(pageData.route)) {
183
183
  this._dynamicPageData.set(pageData.route, pageData)
184
184
  }
185
185
  }
@@ -1399,7 +1399,7 @@ export default class Website {
1399
1399
  const isPageVisible = (page) => {
1400
1400
  // Always exclude dynamic route template pages (e.g., /blog/:slug)
1401
1401
  // These are templates for generating pages, not actual navigable pages
1402
- if (page.route.includes(':')) return false
1402
+ if (isDynamicRoute(page.route)) return false
1403
1403
 
1404
1404
  // ⭐ And the pages made from one — a record's own page (/blog/my-post). The SPA keeps
1405
1405
  // those out of `this.pages` (`_dynamicPageCache`), but a static build expands them into