@microsoft/fast-router 0.4.5 → 1.0.0-alpha.10

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.
Files changed (44) hide show
  1. package/.eslintrc.json +0 -4
  2. package/CHANGELOG.json +224 -11
  3. package/CHANGELOG.md +88 -5
  4. package/README.md +3 -32
  5. package/dist/dts/commands.d.ts +5 -5
  6. package/dist/dts/configuration.d.ts +1 -1
  7. package/dist/dts/contributors.d.ts +23 -6
  8. package/dist/dts/events.d.ts +2 -2
  9. package/dist/dts/fast-router.d.ts +1 -1
  10. package/dist/dts/links.d.ts +2 -2
  11. package/dist/dts/navigation.d.ts +7 -7
  12. package/dist/dts/phases.d.ts +6 -6
  13. package/dist/dts/process.d.ts +2 -2
  14. package/dist/dts/query-string.d.ts +2 -2
  15. package/dist/dts/recognizer.d.ts +6 -6
  16. package/dist/dts/router.d.ts +6 -6
  17. package/dist/dts/routes.d.ts +26 -26
  18. package/dist/dts/titles.d.ts +2 -2
  19. package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +1 -1
  20. package/dist/dts/view.d.ts +11 -16
  21. package/dist/esm/commands.js +10 -8
  22. package/dist/esm/configuration.js +1 -1
  23. package/dist/esm/contributors.js +25 -21
  24. package/dist/esm/events.js +1 -1
  25. package/dist/esm/fast-router.js +1 -1
  26. package/dist/esm/links.js +1 -1
  27. package/dist/esm/navigation.js +4 -4
  28. package/dist/esm/process.js +1 -1
  29. package/dist/esm/query-string.js +1 -1
  30. package/dist/esm/recognizer.js +16 -16
  31. package/dist/esm/router.js +6 -21
  32. package/dist/esm/routes.js +1 -1
  33. package/dist/esm/titles.js +1 -1
  34. package/dist/esm/view.js +9 -27
  35. package/dist/fast-router.api.json +9674 -2
  36. package/dist/fast-router.d.ts +105 -93
  37. package/dist/fast-router.untrimmed.d.ts +819 -0
  38. package/docs/api-report.md +95 -94
  39. package/karma.conf.cjs +6 -17
  40. package/package.json +12 -16
  41. package/dist/dts/index-rollup.d.ts +0 -2
  42. package/dist/esm/index-rollup.js +0 -2
  43. package/dist/fast-router.js +0 -6793
  44. package/dist/fast-router.min.js +0 -1
@@ -2,7 +2,7 @@ import { __awaiter } from "tslib";
2
2
  import { QueryString } from "./query-string.js";
3
3
  const defaultParameterConverter = (value) => value;
4
4
  /**
5
- * @alpha
5
+ * @beta
6
6
  */
7
7
  export class ConfigurableRoute {
8
8
  constructor(path, name, caseSensitive) {
@@ -12,7 +12,7 @@ export class ConfigurableRoute {
12
12
  }
13
13
  }
14
14
  /**
15
- * @alpha
15
+ * @beta
16
16
  */
17
17
  export class Endpoint {
18
18
  constructor(route, paramNames, paramTypes, settings) {
@@ -26,7 +26,7 @@ export class Endpoint {
26
26
  }
27
27
  }
28
28
  /**
29
- * @alpha
29
+ * @beta
30
30
  */
31
31
  export class RecognizedRoute {
32
32
  constructor(endpoint, params, typedParams, queryParams) {
@@ -279,7 +279,7 @@ class RecognizeResult {
279
279
  }
280
280
  }
281
281
  /**
282
- * @alpha
282
+ * @beta
283
283
  */
284
284
  export class DefaultRouteRecognizer {
285
285
  constructor() {
@@ -458,19 +458,19 @@ class State {
458
458
  this.nextStates = null;
459
459
  this.endpoint = null;
460
460
  switch (segment === null || segment === void 0 ? void 0 : segment.kind) {
461
- case 2 /* dynamic */:
461
+ case 2 /* SegmentKind.dynamic */:
462
462
  this.length = prevState.length + 1;
463
463
  this.isSeparator = false;
464
464
  this.isDynamic = true;
465
465
  this.isOptional = segment.optional;
466
466
  break;
467
- case 1 /* star */:
467
+ case 1 /* SegmentKind.star */:
468
468
  this.length = prevState.length + 1;
469
469
  this.isSeparator = false;
470
470
  this.isDynamic = true;
471
471
  this.isOptional = false;
472
472
  break;
473
- case 3 /* static */:
473
+ case 3 /* SegmentKind.static */:
474
474
  this.length = prevState.length + 1;
475
475
  this.isSeparator = false;
476
476
  this.isDynamic = false;
@@ -517,11 +517,11 @@ class State {
517
517
  isMatch(ch) {
518
518
  const segment = this.segment;
519
519
  switch (segment === null || segment === void 0 ? void 0 : segment.kind) {
520
- case 2 /* dynamic */:
520
+ case 2 /* SegmentKind.dynamic */:
521
521
  return !this.value.includes(ch);
522
- case 1 /* star */:
522
+ case 1 /* SegmentKind.star */:
523
523
  return true;
524
- case 3 /* static */:
524
+ case 3 /* SegmentKind.static */:
525
525
  case undefined:
526
526
  // segment separators (slashes) are non-segments. We could say return ch === '/' as well, technically.
527
527
  return this.value.includes(ch);
@@ -537,7 +537,7 @@ class StaticSegment {
537
537
  this.caseSensitive = caseSensitive;
538
538
  }
539
539
  get kind() {
540
- return 3 /* static */;
540
+ return 3 /* SegmentKind.static */;
541
541
  }
542
542
  appendTo(state) {
543
543
  const { value, value: { length }, } = this;
@@ -560,7 +560,7 @@ class StaticSegment {
560
560
  return this.value;
561
561
  }
562
562
  equals(b) {
563
- return (b.kind === 3 /* static */ &&
563
+ return (b.kind === 3 /* SegmentKind.static */ &&
564
564
  b.caseSensitive === this.caseSensitive &&
565
565
  b.value === this.value);
566
566
  }
@@ -571,7 +571,7 @@ class DynamicSegment {
571
571
  this.optional = optional;
572
572
  }
573
573
  get kind() {
574
- return 2 /* dynamic */;
574
+ return 2 /* SegmentKind.dynamic */;
575
575
  }
576
576
  appendTo(state) {
577
577
  state = state.append(/* segment */ this, /* value */ "/");
@@ -582,7 +582,7 @@ class DynamicSegment {
582
582
  return params[this.name];
583
583
  }
584
584
  equals(b) {
585
- return (b.kind === 2 /* dynamic */ &&
585
+ return (b.kind === 2 /* SegmentKind.dynamic */ &&
586
586
  b.optional === this.optional &&
587
587
  b.name === this.name);
588
588
  }
@@ -592,7 +592,7 @@ class StarSegment {
592
592
  this.name = name;
593
593
  }
594
594
  get kind() {
595
- return 1 /* star */;
595
+ return 1 /* SegmentKind.star */;
596
596
  }
597
597
  appendTo(state) {
598
598
  state = state.append(/* segment */ this, /* value */ "");
@@ -603,6 +603,6 @@ class StarSegment {
603
603
  return params[this.name];
604
604
  }
605
605
  equals(b) {
606
- return b.kind === 1 /* star */ && b.name === this.name;
606
+ return b.kind === 1 /* SegmentKind.star */ && b.name === this.name;
607
607
  }
608
608
  }
@@ -1,25 +1,9 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import { FASTElement } from "@microsoft/fast-element";
3
+ import { composedParent } from "@microsoft/fast-element/utilities";
3
4
  import { NavigationMessage } from "./navigation.js";
4
5
  import { childRouteParameter } from "./routes.js";
5
- import { RouterExecutionContext } from "./view.js";
6
6
  const routerProperty = "$router";
7
- // TODO: remove this from here and from fast-foundation
8
- // TODO: move this to fast-element so router and foundation can both use it
9
- function composedParent(element) {
10
- const parentNode = element.parentElement;
11
- if (parentNode) {
12
- return parentNode;
13
- }
14
- else {
15
- const rootNode = element.getRootNode();
16
- if (rootNode.host instanceof HTMLElement) {
17
- // this is shadow-root
18
- return rootNode.host;
19
- }
20
- }
21
- return null;
22
- }
23
7
  function findParentRouterForElement(element) {
24
8
  let parent = element;
25
9
  while ((parent = composedParent(parent))) {
@@ -30,7 +14,7 @@ function findParentRouterForElement(element) {
30
14
  return null;
31
15
  }
32
16
  /**
33
- * @alpha
17
+ * @beta
34
18
  */
35
19
  export const Router = Object.freeze({
36
20
  getOrCreateFor(element) {
@@ -85,13 +69,13 @@ export const Router = Object.freeze({
85
69
  },
86
70
  });
87
71
  /**
88
- * @alpha
72
+ * @beta
89
73
  */
90
74
  export function isFASTElementHost(host) {
91
75
  return host instanceof FASTElement;
92
76
  }
93
77
  /**
94
- * @alpha
78
+ * @beta
95
79
  */
96
80
  export class DefaultRouter {
97
81
  constructor(host) {
@@ -152,7 +136,8 @@ export class DefaultRouter {
152
136
  return __awaiter(this, void 0, void 0, function* () {
153
137
  this.newRoute = route;
154
138
  this.newView = yield command.createView();
155
- this.newView.bind(route.allTypedParams, RouterExecutionContext.create(this));
139
+ this.newView.context.router = this;
140
+ this.newView.bind(route.allTypedParams);
156
141
  this.newView.appendTo(this.host);
157
142
  yield command.transition.begin(this.host, this.view, this.newView);
158
143
  return {
@@ -40,7 +40,7 @@ const defaultConverters = {
40
40
  bool: booleanConverter,
41
41
  };
42
42
  /**
43
- * @alpha
43
+ * @beta
44
44
  */
45
45
  export class RouteCollection {
46
46
  constructor(owner) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @alpha
2
+ * @beta
3
3
  */
4
4
  export class DefaultTitleBuilder {
5
5
  constructor(segmentSeparator = " - ", fragmentSeparator = ":") {
package/dist/esm/view.js CHANGED
@@ -1,20 +1,8 @@
1
1
  import { __awaiter } from "tslib";
2
- import { defaultExecutionContext, ElementStyles, html, } from "@microsoft/fast-element";
2
+ import { ElementStyles, html, } from "@microsoft/fast-element";
3
3
  import { isFASTElementHost } from "./router.js";
4
4
  /**
5
- * @alpha
6
- */
7
- export const RouterExecutionContext = Object.freeze({
8
- create(router) {
9
- return Object.create(defaultExecutionContext, {
10
- router: {
11
- value: router,
12
- },
13
- });
14
- },
15
- });
16
- /**
17
- * @alpha
5
+ * @beta
18
6
  */
19
7
  export const Transition = Object.freeze({
20
8
  default: Object.freeze({
@@ -30,20 +18,14 @@ export const Transition = Object.freeze({
30
18
  }),
31
19
  });
32
20
  /**
33
- * @alpha
21
+ * @beta
34
22
  */
35
23
  export class FASTElementLayout {
36
- constructor(template = null, styles = null, runBeforeCommit = true) {
24
+ constructor(template = null, styles = undefined, runBeforeCommit = true) {
25
+ var _a;
37
26
  this.template = template;
38
27
  this.runBeforeCommit = runBeforeCommit;
39
- this.styles =
40
- styles === void 0 || styles === null
41
- ? null
42
- : Array.isArray(styles)
43
- ? ElementStyles.create(styles)
44
- : styles instanceof ElementStyles
45
- ? styles
46
- : ElementStyles.create([styles]);
28
+ this.styles = (_a = ElementStyles.normalize(styles)) !== null && _a !== void 0 ? _a : null;
47
29
  }
48
30
  beforeCommit(routerElement) {
49
31
  return __awaiter(this, void 0, void 0, function* () {
@@ -64,14 +46,14 @@ export class FASTElementLayout {
64
46
  if (routerElement.$fastController.template !== this.template) {
65
47
  routerElement.$fastController.template = this.template;
66
48
  }
67
- if (routerElement.$fastController.styles !== this.styles) {
68
- routerElement.$fastController.styles = this.styles;
49
+ if (routerElement.$fastController.mainStyles !== this.styles) {
50
+ routerElement.$fastController.mainStyles = this.styles;
69
51
  }
70
52
  }
71
53
  }
72
54
  }
73
55
  /**
74
- * @alpha
56
+ * @beta
75
57
  */
76
58
  export const Layout = Object.freeze({
77
59
  default: new FASTElementLayout(html `