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

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.
@@ -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
  }
@@ -461,40 +461,6 @@
461
461
  "endIndex": 2
462
462
  }
463
463
  },
464
- {
465
- "kind": "TypeAlias",
466
- "canonicalReference": "@microsoft/fast-router!ConverterObject:type",
467
- "docComment": "/**\n * @beta\n */\n",
468
- "excerptTokens": [
469
- {
470
- "kind": "Content",
471
- "text": "export declare type ConverterObject = "
472
- },
473
- {
474
- "kind": "Content",
475
- "text": "{\n convert: "
476
- },
477
- {
478
- "kind": "Reference",
479
- "text": "RouteParameterConverter",
480
- "canonicalReference": "@microsoft/fast-router!RouteParameterConverter:type"
481
- },
482
- {
483
- "kind": "Content",
484
- "text": ";\n}"
485
- },
486
- {
487
- "kind": "Content",
488
- "text": ";"
489
- }
490
- ],
491
- "releaseTag": "Beta",
492
- "name": "ConverterObject",
493
- "typeTokenRange": {
494
- "startIndex": 1,
495
- "endIndex": 4
496
- }
497
- },
498
464
  {
499
465
  "kind": "Class",
500
466
  "canonicalReference": "@microsoft/fast-router!DefaultLinkHandler:class",
@@ -2410,7 +2376,7 @@
2410
2376
  },
2411
2377
  {
2412
2378
  "kind": "Content",
2413
- "text": "[] | null"
2379
+ "text": "[] | undefined"
2414
2380
  },
2415
2381
  {
2416
2382
  "kind": "Content",
@@ -3674,7 +3640,7 @@
3674
3640
  },
3675
3641
  {
3676
3642
  "kind": "Content",
3677
- "text": "any"
3643
+ "text": "void"
3678
3644
  },
3679
3645
  {
3680
3646
  "kind": "Content",
@@ -4817,8 +4783,8 @@
4817
4783
  },
4818
4784
  {
4819
4785
  "kind": "Reference",
4820
- "text": "ConverterObject",
4821
- "canonicalReference": "@microsoft/fast-router!ConverterObject:type"
4786
+ "text": "RouteParameterConverterObject",
4787
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterObject:type"
4822
4788
  },
4823
4789
  {
4824
4790
  "kind": "Content",
@@ -4835,8 +4801,8 @@
4835
4801
  },
4836
4802
  {
4837
4803
  "kind": "Reference",
4838
- "text": "ConverterObject",
4839
- "canonicalReference": "@microsoft/fast-router!ConverterObject:type"
4804
+ "text": "RouteParameterConverterObject",
4805
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterObject:type"
4840
4806
  },
4841
4807
  {
4842
4808
  "kind": "Content",
@@ -4999,12 +4965,12 @@
4999
4965
  },
5000
4966
  {
5001
4967
  "kind": "Reference",
5002
- "text": "Object",
5003
- "canonicalReference": "!Object:interface"
4968
+ "text": "Record",
4969
+ "canonicalReference": "!Record:type"
5004
4970
  },
5005
4971
  {
5006
4972
  "kind": "Content",
5007
- "text": ", traditional?: boolean): string;\n separate(path: string): "
4973
+ "text": "<string, string>, traditional?: boolean): string;\n separate(path: string): "
5008
4974
  },
5009
4975
  {
5010
4976
  "kind": "Reference",
@@ -7187,7 +7153,16 @@
7187
7153
  },
7188
7154
  {
7189
7155
  "kind": "Content",
7190
- "text": "(value: string | undefined) => any | "
7156
+ "text": "(name: string, value: string | undefined, context: "
7157
+ },
7158
+ {
7159
+ "kind": "Reference",
7160
+ "text": "RouteParameterConverterContext",
7161
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext:interface"
7162
+ },
7163
+ {
7164
+ "kind": "Content",
7165
+ "text": ") => any | "
7191
7166
  },
7192
7167
  {
7193
7168
  "kind": "Reference",
@@ -7205,6 +7180,210 @@
7205
7180
  ],
7206
7181
  "releaseTag": "Beta",
7207
7182
  "name": "RouteParameterConverter",
7183
+ "typeTokenRange": {
7184
+ "startIndex": 1,
7185
+ "endIndex": 6
7186
+ }
7187
+ },
7188
+ {
7189
+ "kind": "Interface",
7190
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext:interface",
7191
+ "docComment": "/**\n * @beta\n */\n",
7192
+ "excerptTokens": [
7193
+ {
7194
+ "kind": "Content",
7195
+ "text": "export interface RouteParameterConverterContext<TSettings = "
7196
+ },
7197
+ {
7198
+ "kind": "Content",
7199
+ "text": "any"
7200
+ },
7201
+ {
7202
+ "kind": "Content",
7203
+ "text": "> "
7204
+ }
7205
+ ],
7206
+ "releaseTag": "Beta",
7207
+ "typeParameters": [
7208
+ {
7209
+ "typeParameterName": "TSettings",
7210
+ "constraintTokenRange": {
7211
+ "startIndex": 0,
7212
+ "endIndex": 0
7213
+ },
7214
+ "defaultTypeTokenRange": {
7215
+ "startIndex": 1,
7216
+ "endIndex": 2
7217
+ }
7218
+ }
7219
+ ],
7220
+ "name": "RouteParameterConverterContext",
7221
+ "members": [
7222
+ {
7223
+ "kind": "PropertySignature",
7224
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext#endpoint:member",
7225
+ "docComment": "",
7226
+ "excerptTokens": [
7227
+ {
7228
+ "kind": "Content",
7229
+ "text": "readonly endpoint: "
7230
+ },
7231
+ {
7232
+ "kind": "Reference",
7233
+ "text": "Endpoint",
7234
+ "canonicalReference": "@microsoft/fast-router!Endpoint:class"
7235
+ },
7236
+ {
7237
+ "kind": "Content",
7238
+ "text": "<TSettings>"
7239
+ },
7240
+ {
7241
+ "kind": "Content",
7242
+ "text": ";"
7243
+ }
7244
+ ],
7245
+ "isOptional": false,
7246
+ "releaseTag": "Beta",
7247
+ "name": "endpoint",
7248
+ "propertyTypeTokenRange": {
7249
+ "startIndex": 1,
7250
+ "endIndex": 3
7251
+ }
7252
+ },
7253
+ {
7254
+ "kind": "PropertySignature",
7255
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext#params:member",
7256
+ "docComment": "",
7257
+ "excerptTokens": [
7258
+ {
7259
+ "kind": "Content",
7260
+ "text": "readonly params: "
7261
+ },
7262
+ {
7263
+ "kind": "Reference",
7264
+ "text": "Readonly",
7265
+ "canonicalReference": "!Readonly:type"
7266
+ },
7267
+ {
7268
+ "kind": "Content",
7269
+ "text": "<"
7270
+ },
7271
+ {
7272
+ "kind": "Reference",
7273
+ "text": "Record",
7274
+ "canonicalReference": "!Record:type"
7275
+ },
7276
+ {
7277
+ "kind": "Content",
7278
+ "text": "<string, string | undefined>>"
7279
+ },
7280
+ {
7281
+ "kind": "Content",
7282
+ "text": ";"
7283
+ }
7284
+ ],
7285
+ "isOptional": false,
7286
+ "releaseTag": "Beta",
7287
+ "name": "params",
7288
+ "propertyTypeTokenRange": {
7289
+ "startIndex": 1,
7290
+ "endIndex": 5
7291
+ }
7292
+ },
7293
+ {
7294
+ "kind": "PropertySignature",
7295
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext#queryParams:member",
7296
+ "docComment": "",
7297
+ "excerptTokens": [
7298
+ {
7299
+ "kind": "Content",
7300
+ "text": "readonly queryParams: "
7301
+ },
7302
+ {
7303
+ "kind": "Reference",
7304
+ "text": "Record",
7305
+ "canonicalReference": "!Record:type"
7306
+ },
7307
+ {
7308
+ "kind": "Content",
7309
+ "text": "<string, string>"
7310
+ },
7311
+ {
7312
+ "kind": "Content",
7313
+ "text": ";"
7314
+ }
7315
+ ],
7316
+ "isOptional": false,
7317
+ "releaseTag": "Beta",
7318
+ "name": "queryParams",
7319
+ "propertyTypeTokenRange": {
7320
+ "startIndex": 1,
7321
+ "endIndex": 3
7322
+ }
7323
+ },
7324
+ {
7325
+ "kind": "PropertySignature",
7326
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterContext#typedParams:member",
7327
+ "docComment": "",
7328
+ "excerptTokens": [
7329
+ {
7330
+ "kind": "Content",
7331
+ "text": "readonly typedParams: "
7332
+ },
7333
+ {
7334
+ "kind": "Reference",
7335
+ "text": "Record",
7336
+ "canonicalReference": "!Record:type"
7337
+ },
7338
+ {
7339
+ "kind": "Content",
7340
+ "text": "<string, any>"
7341
+ },
7342
+ {
7343
+ "kind": "Content",
7344
+ "text": ";"
7345
+ }
7346
+ ],
7347
+ "isOptional": false,
7348
+ "releaseTag": "Beta",
7349
+ "name": "typedParams",
7350
+ "propertyTypeTokenRange": {
7351
+ "startIndex": 1,
7352
+ "endIndex": 3
7353
+ }
7354
+ }
7355
+ ],
7356
+ "extendsTokenRanges": []
7357
+ },
7358
+ {
7359
+ "kind": "TypeAlias",
7360
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverterObject:type",
7361
+ "docComment": "/**\n * @beta\n */\n",
7362
+ "excerptTokens": [
7363
+ {
7364
+ "kind": "Content",
7365
+ "text": "export declare type RouteParameterConverterObject = "
7366
+ },
7367
+ {
7368
+ "kind": "Content",
7369
+ "text": "{\n convert: "
7370
+ },
7371
+ {
7372
+ "kind": "Reference",
7373
+ "text": "RouteParameterConverter",
7374
+ "canonicalReference": "@microsoft/fast-router!RouteParameterConverter:type"
7375
+ },
7376
+ {
7377
+ "kind": "Content",
7378
+ "text": ";\n}"
7379
+ },
7380
+ {
7381
+ "kind": "Content",
7382
+ "text": ";"
7383
+ }
7384
+ ],
7385
+ "releaseTag": "Beta",
7386
+ "name": "RouteParameterConverterObject",
7208
7387
  "typeTokenRange": {
7209
7388
  "startIndex": 1,
7210
7389
  "endIndex": 4
@@ -9032,7 +9211,7 @@
9032
9211
  },
9033
9212
  {
9034
9213
  "kind": "Content",
9035
- "text": "any"
9214
+ "text": "void"
9036
9215
  },
9037
9216
  {
9038
9217
  "kind": "Content",
@@ -9060,7 +9239,7 @@
9060
9239
  },
9061
9240
  {
9062
9241
  "kind": "Content",
9063
- "text": "any"
9242
+ "text": "void"
9064
9243
  },
9065
9244
  {
9066
9245
  "kind": "Content",
@@ -9097,11 +9276,11 @@
9097
9276
  {
9098
9277
  "kind": "Reference",
9099
9278
  "text": "ExecutionContext",
9100
- "canonicalReference": "@microsoft/fast-element!ExecutionContext:class"
9279
+ "canonicalReference": "@microsoft/fast-element!ExecutionContext:interface"
9101
9280
  },
9102
9281
  {
9103
9282
  "kind": "Content",
9104
- "text": " & {\n router: "
9283
+ "text": " & {\n router?: "
9105
9284
  },
9106
9285
  {
9107
9286
  "kind": "Reference",
@@ -9124,41 +9303,6 @@
9124
9303
  "endIndex": 5
9125
9304
  }
9126
9305
  },
9127
- {
9128
- "kind": "Variable",
9129
- "canonicalReference": "@microsoft/fast-router!RouterExecutionContext:var",
9130
- "docComment": "/**\n * @beta\n */\n",
9131
- "excerptTokens": [
9132
- {
9133
- "kind": "Content",
9134
- "text": "RouterExecutionContext: "
9135
- },
9136
- {
9137
- "kind": "Reference",
9138
- "text": "Readonly",
9139
- "canonicalReference": "!Readonly:type"
9140
- },
9141
- {
9142
- "kind": "Content",
9143
- "text": "<{\n create(router: "
9144
- },
9145
- {
9146
- "kind": "Reference",
9147
- "text": "Router",
9148
- "canonicalReference": "@microsoft/fast-router!Router:interface"
9149
- },
9150
- {
9151
- "kind": "Content",
9152
- "text": "): any;\n}>"
9153
- }
9154
- ],
9155
- "releaseTag": "Beta",
9156
- "name": "RouterExecutionContext",
9157
- "variableTypeTokenRange": {
9158
- "startIndex": 1,
9159
- "endIndex": 5
9160
- }
9161
- },
9162
9306
  {
9163
9307
  "kind": "Interface",
9164
9308
  "canonicalReference": "@microsoft/fast-router!RouteView:interface",
@@ -9245,15 +9389,6 @@
9245
9389
  "kind": "Content",
9246
9390
  "text": "<string, any>>"
9247
9391
  },
9248
- {
9249
- "kind": "Content",
9250
- "text": ", context: "
9251
- },
9252
- {
9253
- "kind": "Reference",
9254
- "text": "RouterExecutionContext",
9255
- "canonicalReference": "@microsoft/fast-router!RouterExecutionContext:type"
9256
- },
9257
9392
  {
9258
9393
  "kind": "Content",
9259
9394
  "text": "): "
@@ -9269,8 +9404,8 @@
9269
9404
  ],
9270
9405
  "isOptional": false,
9271
9406
  "returnTypeTokenRange": {
9272
- "startIndex": 8,
9273
- "endIndex": 9
9407
+ "startIndex": 6,
9408
+ "endIndex": 7
9274
9409
  },
9275
9410
  "releaseTag": "Beta",
9276
9411
  "overloadIndex": 1,
@@ -9282,17 +9417,36 @@
9282
9417
  "endIndex": 5
9283
9418
  },
9284
9419
  "isOptional": false
9420
+ }
9421
+ ],
9422
+ "name": "bind"
9423
+ },
9424
+ {
9425
+ "kind": "PropertySignature",
9426
+ "canonicalReference": "@microsoft/fast-router!RouteView#context:member",
9427
+ "docComment": "",
9428
+ "excerptTokens": [
9429
+ {
9430
+ "kind": "Content",
9431
+ "text": "context: "
9285
9432
  },
9286
9433
  {
9287
- "parameterName": "context",
9288
- "parameterTypeTokenRange": {
9289
- "startIndex": 6,
9290
- "endIndex": 7
9291
- },
9292
- "isOptional": false
9434
+ "kind": "Reference",
9435
+ "text": "RouterExecutionContext",
9436
+ "canonicalReference": "@microsoft/fast-router!RouterExecutionContext:type"
9437
+ },
9438
+ {
9439
+ "kind": "Content",
9440
+ "text": ";"
9293
9441
  }
9294
9442
  ],
9295
- "name": "bind"
9443
+ "isOptional": false,
9444
+ "releaseTag": "Beta",
9445
+ "name": "context",
9446
+ "propertyTypeTokenRange": {
9447
+ "startIndex": 1,
9448
+ "endIndex": 2
9449
+ }
9296
9450
  },
9297
9451
  {
9298
9452
  "kind": "MethodSignature",