@microsoft/fast-router 1.0.0-alpha.2 → 1.0.0-alpha.21

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.
@@ -17,34 +17,38 @@ class NavigationContributorDirective {
17
17
  createHTML(add) {
18
18
  return Markup.attribute(add(this));
19
19
  }
20
- createBehavior(targets) {
21
- return new NavigationContributorBehavior(targets[this.nodeId], this.options);
20
+ createBehavior() {
21
+ return new NavigationContributorBehavior(this);
22
22
  }
23
23
  }
24
24
  HTMLDirective.define(NavigationContributorDirective);
25
25
  class NavigationContributorBehavior {
26
- constructor(contributor, options) {
27
- this.contributor = contributor;
28
- this.options = options;
26
+ constructor(directive) {
27
+ this.directive = directive;
29
28
  this.router = null;
30
29
  }
31
- bind(source, context) {
32
- if (this.options.lifecycle) {
33
- this.router = context.router || Router.find(this.contributor);
34
- this.router.addContributor(this.contributor);
30
+ bind(controller) {
31
+ var _a;
32
+ const context = controller.context;
33
+ const options = this.directive.options;
34
+ this.contributor = controller.targets[this.directive.targetNodeId];
35
+ if (options.lifecycle) {
36
+ this.router = (_a = context.router) !== null && _a !== void 0 ? _a : Router.find(this.contributor);
37
+ if (this.router) {
38
+ this.router.addContributor(this.contributor);
39
+ controller.onUnbind(this);
40
+ }
35
41
  }
36
- if (this.options.parameters) {
42
+ if (options.parameters) {
37
43
  const contributor = this.contributor;
38
- const routeParams = source;
44
+ const routeParams = controller.source;
39
45
  for (const key in routeParams) {
40
46
  contributor[key] = routeParams[key];
41
47
  }
42
48
  }
43
49
  }
44
50
  unbind(source) {
45
- if (this.router !== null) {
46
- this.router.removeContributor(this.contributor);
47
- }
51
+ this.router.removeContributor(this.contributor);
48
52
  }
49
53
  }
50
54
  /**
@@ -1,6 +1,8 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import { QueryString } from "./query-string.js";
3
- const defaultParameterConverter = (value) => value;
3
+ const defaultParameterConverter = (name, value, context) => {
4
+ return value;
5
+ };
4
6
  /**
5
7
  * @beta
6
8
  */
@@ -35,7 +37,7 @@ export class RecognizedRoute {
35
37
  this.typedParams = typedParams;
36
38
  this.queryParams = queryParams;
37
39
  this.allParams = Object.assign(Object.assign({}, params), queryParams);
38
- this.allTypedParams = Object.assign(Object.assign({}, typedParams), queryParams);
40
+ this.allTypedParams = Object.assign(Object.assign({}, queryParams), typedParams);
39
41
  }
40
42
  get settings() {
41
43
  return this.endpoint.settings;
@@ -386,12 +388,17 @@ export class DefaultRouteRecognizer {
386
388
  const paramTypes = endpoint.paramTypes;
387
389
  const params = candidate.getParams();
388
390
  const typedParams = {};
391
+ const converterContext = {
392
+ endpoint,
393
+ params,
394
+ typedParams,
395
+ queryParams,
396
+ };
389
397
  for (let i = 0, ii = paramNames.length; i < ii; ++i) {
390
- const name = paramNames[i];
398
+ const paramName = paramNames[i];
399
+ const paramValue = params[paramName];
391
400
  const convert = converters[paramTypes[i]] || defaultParameterConverter;
392
- const untypedValue = params[name];
393
- const typedValue = yield convert(untypedValue);
394
- typedParams[name] = typedValue;
401
+ typedParams[paramName] = yield convert(paramName, paramValue, converterContext);
395
402
  }
396
403
  return new RecognizedRoute(endpoint, params, typedParams, queryParams);
397
404
  });
@@ -3,7 +3,6 @@ import { FASTElement } from "@microsoft/fast-element";
3
3
  import { composedParent } from "@microsoft/fast-element/utilities";
4
4
  import { NavigationMessage } from "./navigation.js";
5
5
  import { childRouteParameter } from "./routes.js";
6
- import { RouterExecutionContext } from "./view.js";
7
6
  const routerProperty = "$router";
8
7
  function findParentRouterForElement(element) {
9
8
  let parent = element;
@@ -32,13 +31,20 @@ export const Router = Object.freeze({
32
31
  class RouterBase extends BaseType {
33
32
  constructor() {
34
33
  super();
35
- Router.getOrCreateFor(this);
36
- }
37
- get config() {
38
- return this[routerProperty].config;
39
- }
40
- set config(value) {
41
- this[routerProperty].config = value;
34
+ const router = Router.getOrCreateFor(this);
35
+ const config = this.config || null;
36
+ delete this.config;
37
+ Reflect.defineProperty(this, "config", {
38
+ get() {
39
+ return router.config;
40
+ },
41
+ set(value) {
42
+ router.config = value;
43
+ },
44
+ });
45
+ if (config !== null) {
46
+ router.config = config;
47
+ }
42
48
  }
43
49
  }
44
50
  const proto = RouterBase.prototype;
@@ -114,7 +120,7 @@ export class DefaultRouter {
114
120
  }
115
121
  this.parentRouter = findParentRouterForElement(this.host);
116
122
  }
117
- return this.parentRouter || null;
123
+ return this.parentRouter;
118
124
  }
119
125
  get level() {
120
126
  if (this.parent === null) {
@@ -137,7 +143,8 @@ export class DefaultRouter {
137
143
  return __awaiter(this, void 0, void 0, function* () {
138
144
  this.newRoute = route;
139
145
  this.newView = yield command.createView();
140
- this.newView.bind(route.allTypedParams, RouterExecutionContext.create(this));
146
+ this.newView.context.router = this;
147
+ this.newView.bind(route.allTypedParams);
141
148
  this.newView.appendTo(this.host);
142
149
  yield command.transition.begin(this.host, this.view, this.newView);
143
150
  return {
@@ -17,7 +17,7 @@ function getFallbackCommand(config, definition) {
17
17
  return Render.fromDefinition(config, definition);
18
18
  }
19
19
  }
20
- const booleanConverter = value => {
20
+ const booleanConverter = (name, value) => {
21
21
  if (value === void 0 || value === null) {
22
22
  return false;
23
23
  }
@@ -31,11 +31,11 @@ const booleanConverter = value => {
31
31
  }
32
32
  };
33
33
  const defaultConverters = {
34
- number: value => (value === void 0 ? NaN : parseFloat(value)),
35
- float: value => (value === void 0 ? NaN : parseFloat(value)),
36
- int: value => (value === void 0 ? NaN : parseInt(value)),
37
- integer: value => (value === void 0 ? NaN : parseInt(value)),
38
- Date: value => (value === void 0 ? new Date(Date.now()) : new Date(value)),
34
+ number: (name, value) => (value === void 0 ? NaN : parseFloat(value)),
35
+ float: (name, value) => (value === void 0 ? NaN : parseFloat(value)),
36
+ int: (name, value) => (value === void 0 ? NaN : parseInt(value)),
37
+ integer: (name, value) => (value === void 0 ? NaN : parseInt(value)),
38
+ Date: (name, value) => value === void 0 ? new Date(Date.now()) : new Date(value),
39
39
  boolean: booleanConverter,
40
40
  bool: booleanConverter,
41
41
  };
@@ -129,9 +129,9 @@ export class RouteCollection {
129
129
  normalizedConverter = converter.convert.bind(converter);
130
130
  }
131
131
  else if (converter.prototype && "convert" in converter.prototype) {
132
- normalizedConverter = (value) => {
132
+ normalizedConverter = (name, value, context) => {
133
133
  const obj = this.owner.construct(converter);
134
- return obj.convert(value);
134
+ return obj.convert(name, value, context);
135
135
  };
136
136
  }
137
137
  else {
package/dist/esm/view.js CHANGED
@@ -1,18 +1,6 @@
1
1
  import { __awaiter } from "tslib";
2
- import { ElementStyles, ExecutionContext, html, } from "@microsoft/fast-element";
2
+ import { ElementStyles, html, } from "@microsoft/fast-element";
3
3
  import { isFASTElementHost } from "./router.js";
4
- /**
5
- * @beta
6
- */
7
- export const RouterExecutionContext = Object.freeze({
8
- create(router) {
9
- return Object.create(ExecutionContext.default, {
10
- router: {
11
- value: router,
12
- },
13
- });
14
- },
15
- });
16
4
  /**
17
5
  * @beta
18
6
  */
@@ -33,17 +21,11 @@ export const Transition = Object.freeze({
33
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
- ? new ElementStyles(styles)
44
- : styles instanceof ElementStyles
45
- ? styles
46
- : new ElementStyles([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,8 +46,8 @@ 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
  }