Skip to content

Commit 432b442

Browse files
committed
[css-navigation-1] Initial draft of a simpler alternative to navigation-param().
This is a first draft of attempting to replace navigation-param() with a simpler syntax that allows just a 3x4 space of alternatives: 3 matching types (that replace navigation-param()) and 4 match targets (which are actually a new feature relative to navigation-param()). This is a start to addressing the feedback in #13163 (but I expect further changes before the draft is ready for another round of review).
1 parent bd884c2 commit 432b442

File tree

1 file changed

+88
-68
lines changed

1 file changed

+88
-68
lines changed

css-navigation-1/Overview.bs

Lines changed: 88 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,14 @@ by matching the relevant parts of the navigation URL to the link URL.
393393
navigation: auto;
394394
}
395395

396-
@route --movie-details {
396+
@route --movie-details-with-id {
397397
/* match URLs like /en/movie/123 which is the English page
398-
about a movie with ID 123 */
399-
pattern: url-pattern("/:lang/movie/:id");
398+
about a movie with ID 123. Be careful to specify the
399+
language part with a "*" but the ID part with a named
400+
:id parameter so that matching using the 'match-params'
401+
keyword (the default) will require equal IDs but allow
402+
differences of language. */
403+
pattern: url-pattern("/*/movie/:id");
400404
}
401405

402406
/* capture the overall area representing the movie, and a
@@ -407,19 +411,20 @@ by matching the relevant parts of the navigation URL to the link URL.
407411
movie we are currently navigating to or from. (lang can
408412
be different, though.)
409413

410-
Just :link-to(--movie-details) requires that the target
411-
of the link match the URL pattern defined by the "@route
412-
--movie-details" rule.
414+
This depends on the --movie-details-with-id route
415+
declaring the ID but not the language with a named
416+
parameter, and the use of match-params(navigation-other).
413417

414-
The navigation-param(id) further requires that either the
415-
from or the to URL of the current navigation also match
416-
the URL pattern represented by the "@route
417-
--movie-details" rule, and that that the 'id' named group
418-
from that match be the same as the 'id' named group from
419-
the match with the link's target.
418+
This means that both the of the link and the other URL of
419+
the current navigation match the URL pattern defined by
420+
the "@route --movie-details-with-id" rule, and that the
421+
id named group from both matches be the same. (However,
422+
the URLs can be different because the * part of the
423+
match, containing the language, can be different.)
420424
*/
421-
.movie-container:has(> .movie-title:link-to(
422-
--movie-details with navigation-param(id))) {
425+
.movie-container:has(
426+
> .movie-title:link-to(--movie-details-with-id
427+
with match-params(navigation-other))) {
423428

424429
view-transition-name: movie-container;
425430

@@ -440,24 +445,22 @@ and the pseudo-class matches any element where:
440445
* the target of link matches the <<link-condition>>, as defined below.
441446

442447
<pre class="prod def" dfn-type="type" nohighlight>
443-
<dfn><<link-condition>></dfn> = <<link-condition-base>> [ with <<navigation-param-expression>> ]?
448+
<dfn><<link-condition>></dfn> = <<link-condition-base>> [ with <<navigation-match>> ]?
444449
<dfn><<link-condition-base>></dfn> = <<navigation-location>>
445-
<dfn><<navigation-param-expression>></dfn> = ( <<navigation-param-and>> ) |
446-
( <<navigation-param-or>> ) |
447-
<<navigation-param>>
448-
<dfn><<navigation-param-and>></dfn> = <<navigation-param-expression>>
449-
[ "and" <<navigation-param-expression>> ]*
450-
<dfn><<navigation-param-or>></dfn> = <<navigation-param-expression>>
451-
[ "or" <<navigation-param-expression>> ]*
452-
<dfn><<navigation-param>></dfn> = <<navigation-param-key-value>> | <<navigation-param-function>>
453-
<dfn><<navigation-param-key-value>></dfn> = ( <<ident>> : <<string>> )
454-
<dfn><<navigation-param-function>></dfn> = navigation-param( <<ident>> )
450+
// Note: <<navigation-match>> is defining three functions
451+
// with identical syntax.
452+
<dfn><<navigation-match>></dfn> = <<pattern-match-type>>( <<navigation-match-target>> )
453+
<dfn><<pattern-match-type>></dfn> = match-pattern | match-params | match-url
454+
<dfn><<navigation-match-target>></dfn> = navigation-other | navigation-current |
455+
navigation-from | navigation-to
455456
</pre>
456457

457458
A <<link-condition>> matches the target of the link when both:
458459
* the <<link-condition-base>> matches the target of the link, and
459-
* the <<navigation-param-expression>> matches the target of the link,
460-
with the [=URL pattern=] represented by the <<link-condition-base>> as context
460+
* either:
461+
* a <<navigation-match>> is not present, or
462+
* the <<navigation-match>> matches the target of the link,
463+
with the [=URL pattern=] represented by the <<link-condition-base>> as context
461464

462465
A <<link-condition-base>> represents a [=URL pattern=].
463466
If the <<link-condition-base>> is a <<url-pattern()>>,
@@ -473,52 +476,59 @@ given <var>urlPattern</var> as
473476
the [=URL pattern=] that it represents and
474477
<var>input</var> as the given URL.
475478

476-
A <<navigation-param-expression>> matches a URL
477-
(with a [=URL Pattern=] as context)
478-
based on standard boolean logic for <code>and</code> and <code>or</code>,
479-
and based on whether each <<navigation-param>> matches the URL
480-
(with the URL Pattern as context).
481-
482-
A <<navigation-param>> matches the URL <var>input</var> (with a URL Pattern <var>urlPattern</var> as context)
479+
A <<navigation-match>> matches the URL <var>linkTarget</var>
480+
(with a URL Pattern <var>urlPattern</var> as context)
483481
if the following steps return true:
484-
1. Let <var>matchResult</var> be the result of
482+
1. Let <var>targetMatchResult</var> be the result of
485483
[=URL pattern/match|match a URL pattern=]
486-
given <var>urlPattern</var> and <var>input</var>.
487-
the [=URL pattern=]
488-
represented by the <<url-pattern()>> function in the <<link-condition-base>>
489-
(see [=create a URL pattern for url-pattern()=])
490-
1. If <var>matchResult</var> is null, return false.
484+
given <var>urlPattern</var> and <var>linkTarget</var>.
485+
1. If <var>targetMatchResult</var> is null, return false.
491486

492487
NOTE: This doesn't really matter because
493488
in this case the <<link-condition-base>> also doesn't match.
494-
1. For each property <var>prop</var> of <var>matchResult</var> (a {{URLPatternResult}})
495-
that is a {{URLPatternComponentResult}}:
496-
1. For each [=map/entry=] <var>entry</var> in its {{URLPatternComponentResult/groups}},
497-
then:
498-
1. If <<navigation-param>> is a <<navigation-param-key-value>>,
499-
return true if
500-
<var>entry</var>'s [=map/key=] is the <<ident>>
501-
and <var>entry</var>'s [=map/value=] is the <<string>>.
502-
1. If <<navigation-param>> is a <<navigation-param-function>>,
503-
and <var>entry</var>'s [=map/key=] is the function's <<ident>>,
504-
then for each <var>navigationUrl</var> of the
505-
[=current to URL=]
506-
and [=current from URL=]:
507-
1. Let <var>navigationMatchResult</var> be the result of
508-
[=URL pattern/match|match a URL pattern=]
509-
given <var>urlPattern</var> and <var>navigationUrl</var>.
510-
1. If <var>navigationMatchResult</var> is null, [=continue=].
511-
1. Return true if <var>navigationMatchResult</var>'s
512-
property <var>prop</var>
513-
has an [=map/entry=]
514-
whose [=map/key=] is the same as <var>entry</var>'s key
515-
and whose [=map/value=] is the same as <var>entry</var>'s value.
516-
517-
NOTE: This step makes the ''navigation-param()'' function
518-
perform what is essentially a three-way match,
519-
between the target of the link,
520-
the provided URL pattern,
521-
and the from or to URL of the current navigation.
489+
1. Let <var>matchType</var> be the <<pattern-match-type>> of the
490+
<<navigation-match>>.
491+
1. Let <var>matchTarget</var> be the <<navigation-match-target>> argument
492+
of the <<navigation-match>>.
493+
1. Let <var>navigationURL</var> be:
494+
: If <var>matchTarget</var> is ''navigation-other'',
495+
:: the <a>current other URL</a> of the document.
496+
: Otherwise, if <var>matchTarget</var> is ''navigation-current'',
497+
:: the <a>current URL</a> of the document.
498+
: Otherwise, if <var>matchTarget</var> is ''navigation-from'',
499+
:: the <a>current from URL</a> of the document.
500+
: Otherwise (Assert: <var>matchTarget</var> is ''navigation-to''),
501+
:: the <a>current to URL</a> of the document.
502+
1. If <var>navigationURL</var> is null, return false.
503+
1. : If <var>matchType</var> is ''match-pattern''
504+
:: Return true if
505+
the result of [=URL pattern/match|match a URL pattern=] given
506+
<var>urlPattern</var> and <var>navigationURL</var> is not null;
507+
otherwise return false.
508+
509+
: If <var>matchType</var> is ''match-params''
510+
:: 1. Let <var>navigationMatchResult</var> be the result of
511+
[=URL pattern/match|match a URL pattern=] given
512+
<var>navigationURL</var> and <var>urlPattern</var>.
513+
514+
1. If either <var>navigationMatchResult</var> is null, return false.
515+
516+
1. For each property <var>prop</var> of {{URLPatternResult}} that is a
517+
{{URLPatternComponentResult}}:
518+
519+
1. If {{URLPatternComponentResult/groups}} of <var>prop</var> of
520+
<var>targetMatchResult</var> is not equal to
521+
{{URLPatternComponentResult/groups}} of <var>prop</var> of
522+
<var>navigationMatchResult</var>,
523+
then return false.
524+
525+
ISSUE: Need to formally define equality of ordered maps.
526+
527+
1. Return true.
528+
529+
: If <var>matchType</var> is ''match-url''
530+
:: Return true if <var>linkTarget</var> equals <var>navigationURL</var>;
531+
otherwise return false.
522532

523533
NOTE: Some of the design discussion for this feature has been in
524534
<a href="https://github.com/w3c/csswg-drafts/issues/13163">w3c/csswg-drafts#13163</a>.
@@ -618,6 +628,16 @@ ISSUE: The above definitions of from and to apparently don't work right
618628
if you start a same-document navigation (e.g., with {{History/pushState}})
619629
in the middle of a cross-document navigation.
620630

631+
The <dfn>current URL</dfn> of a [=/document=] is a URL.
632+
It is defined as follows:
633+
634+
1. ISSUE: Write this!
635+
636+
The <dfn>current other URL</dfn> of a [=/document=] is a URL or null.
637+
It is defined as follows:
638+
639+
1. ISSUE: Write this!
640+
621641
The <dfn>current navigation type</dfn> of a [=/document=] is a {{NavigationType}} or null.
622642
It is defined as follows:
623643

0 commit comments

Comments
 (0)