@microsoft/fast-element 2.4.1 → 2.6.0

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.
@@ -8566,6 +8566,15 @@
8566
8566
  "text": "compose",
8567
8567
  "canonicalReference": "@microsoft/fast-element!~compose:function"
8568
8568
  },
8569
+ {
8570
+ "kind": "Content",
8571
+ "text": ";\n defineAsync: typeof "
8572
+ },
8573
+ {
8574
+ "kind": "Reference",
8575
+ "text": "defineAsync",
8576
+ "canonicalReference": "@microsoft/fast-element!~defineAsync:function"
8577
+ },
8569
8578
  {
8570
8579
  "kind": "Content",
8571
8580
  "text": ";\n from: typeof "
@@ -8586,7 +8595,7 @@
8586
8595
  "name": "FASTElement",
8587
8596
  "variableTypeTokenRange": {
8588
8597
  "startIndex": 1,
8589
- "endIndex": 10
8598
+ "endIndex": 12
8590
8599
  }
8591
8600
  },
8592
8601
  {
@@ -9114,6 +9123,50 @@
9114
9123
  "isProtected": false,
9115
9124
  "isAbstract": false
9116
9125
  },
9126
+ {
9127
+ "kind": "Property",
9128
+ "canonicalReference": "@microsoft/fast-element!FASTElementDefinition.isRegistered:member",
9129
+ "docComment": "/**\n * The definition has been registered to the FAST element registry.\n */\n",
9130
+ "excerptTokens": [
9131
+ {
9132
+ "kind": "Content",
9133
+ "text": "static isRegistered: "
9134
+ },
9135
+ {
9136
+ "kind": "Reference",
9137
+ "text": "Record",
9138
+ "canonicalReference": "!Record:type"
9139
+ },
9140
+ {
9141
+ "kind": "Content",
9142
+ "text": "<string, "
9143
+ },
9144
+ {
9145
+ "kind": "Reference",
9146
+ "text": "Function",
9147
+ "canonicalReference": "!Function:interface"
9148
+ },
9149
+ {
9150
+ "kind": "Content",
9151
+ "text": ">"
9152
+ },
9153
+ {
9154
+ "kind": "Content",
9155
+ "text": ";"
9156
+ }
9157
+ ],
9158
+ "isReadonly": false,
9159
+ "isOptional": false,
9160
+ "releaseTag": "Public",
9161
+ "name": "isRegistered",
9162
+ "propertyTypeTokenRange": {
9163
+ "startIndex": 1,
9164
+ "endIndex": 5
9165
+ },
9166
+ "isStatic": true,
9167
+ "isProtected": false,
9168
+ "isAbstract": false
9169
+ },
9117
9170
  {
9118
9171
  "kind": "Property",
9119
9172
  "canonicalReference": "@microsoft/fast-element!FASTElementDefinition#name:member",
@@ -9188,6 +9241,54 @@
9188
9241
  "isProtected": false,
9189
9242
  "isAbstract": false
9190
9243
  },
9244
+ {
9245
+ "kind": "Property",
9246
+ "canonicalReference": "@microsoft/fast-element!FASTElementDefinition.registerAsync:member",
9247
+ "docComment": "/**\n * Indicates when a custom elements definition has been registered with the fastElementRegistry.\n *\n * @param name - The name of the defined custom element.\n *\n * @alpha\n */\n",
9248
+ "excerptTokens": [
9249
+ {
9250
+ "kind": "Content",
9251
+ "text": "static registerAsync: "
9252
+ },
9253
+ {
9254
+ "kind": "Content",
9255
+ "text": "(name: string) => "
9256
+ },
9257
+ {
9258
+ "kind": "Reference",
9259
+ "text": "Promise",
9260
+ "canonicalReference": "!Promise:interface"
9261
+ },
9262
+ {
9263
+ "kind": "Content",
9264
+ "text": "<"
9265
+ },
9266
+ {
9267
+ "kind": "Reference",
9268
+ "text": "Function",
9269
+ "canonicalReference": "!Function:interface"
9270
+ },
9271
+ {
9272
+ "kind": "Content",
9273
+ "text": ">"
9274
+ },
9275
+ {
9276
+ "kind": "Content",
9277
+ "text": ";"
9278
+ }
9279
+ ],
9280
+ "isReadonly": false,
9281
+ "isOptional": false,
9282
+ "releaseTag": "Alpha",
9283
+ "name": "registerAsync",
9284
+ "propertyTypeTokenRange": {
9285
+ "startIndex": 1,
9286
+ "endIndex": 6
9287
+ },
9288
+ "isStatic": true,
9289
+ "isProtected": false,
9290
+ "isAbstract": false
9291
+ },
9191
9292
  {
9192
9293
  "kind": "Property",
9193
9294
  "canonicalReference": "@microsoft/fast-element!FASTElementDefinition#registry:member",
@@ -9312,6 +9413,37 @@
9312
9413
  "isProtected": false,
9313
9414
  "isAbstract": false
9314
9415
  },
9416
+ {
9417
+ "kind": "Property",
9418
+ "canonicalReference": "@microsoft/fast-element!FASTElementDefinition#templateOptions:member",
9419
+ "docComment": "/**\n * The template options.\n *\n * @alpha\n */\n",
9420
+ "excerptTokens": [
9421
+ {
9422
+ "kind": "Content",
9423
+ "text": "templateOptions?: "
9424
+ },
9425
+ {
9426
+ "kind": "Reference",
9427
+ "text": "TemplateOptions",
9428
+ "canonicalReference": "@microsoft/fast-element!TemplateOptions:type"
9429
+ },
9430
+ {
9431
+ "kind": "Content",
9432
+ "text": ";"
9433
+ }
9434
+ ],
9435
+ "isReadonly": false,
9436
+ "isOptional": true,
9437
+ "releaseTag": "Alpha",
9438
+ "name": "templateOptions",
9439
+ "propertyTypeTokenRange": {
9440
+ "startIndex": 1,
9441
+ "endIndex": 2
9442
+ },
9443
+ "isStatic": false,
9444
+ "isProtected": false,
9445
+ "isAbstract": false
9446
+ },
9315
9447
  {
9316
9448
  "kind": "Property",
9317
9449
  "canonicalReference": "@microsoft/fast-element!FASTElementDefinition#type:member",
@@ -12266,6 +12398,85 @@
12266
12398
  "isAbstract": false,
12267
12399
  "name": "disconnect"
12268
12400
  },
12401
+ {
12402
+ "kind": "Method",
12403
+ "canonicalReference": "@microsoft/fast-element!HydratableElementController.forCustomElement:member(1)",
12404
+ "docComment": "",
12405
+ "excerptTokens": [
12406
+ {
12407
+ "kind": "Content",
12408
+ "text": "static forCustomElement(element: "
12409
+ },
12410
+ {
12411
+ "kind": "Reference",
12412
+ "text": "HTMLElement",
12413
+ "canonicalReference": "!HTMLElement:interface"
12414
+ },
12415
+ {
12416
+ "kind": "Content",
12417
+ "text": ", override?: "
12418
+ },
12419
+ {
12420
+ "kind": "Content",
12421
+ "text": "boolean"
12422
+ },
12423
+ {
12424
+ "kind": "Content",
12425
+ "text": "): "
12426
+ },
12427
+ {
12428
+ "kind": "Reference",
12429
+ "text": "ElementController",
12430
+ "canonicalReference": "@microsoft/fast-element!ElementController:class"
12431
+ },
12432
+ {
12433
+ "kind": "Content",
12434
+ "text": "<"
12435
+ },
12436
+ {
12437
+ "kind": "Reference",
12438
+ "text": "HTMLElement",
12439
+ "canonicalReference": "!HTMLElement:interface"
12440
+ },
12441
+ {
12442
+ "kind": "Content",
12443
+ "text": ">"
12444
+ },
12445
+ {
12446
+ "kind": "Content",
12447
+ "text": ";"
12448
+ }
12449
+ ],
12450
+ "isStatic": true,
12451
+ "returnTypeTokenRange": {
12452
+ "startIndex": 5,
12453
+ "endIndex": 9
12454
+ },
12455
+ "releaseTag": "Beta",
12456
+ "isProtected": false,
12457
+ "overloadIndex": 1,
12458
+ "parameters": [
12459
+ {
12460
+ "parameterName": "element",
12461
+ "parameterTypeTokenRange": {
12462
+ "startIndex": 1,
12463
+ "endIndex": 2
12464
+ },
12465
+ "isOptional": false
12466
+ },
12467
+ {
12468
+ "parameterName": "override",
12469
+ "parameterTypeTokenRange": {
12470
+ "startIndex": 3,
12471
+ "endIndex": 4
12472
+ },
12473
+ "isOptional": true
12474
+ }
12475
+ ],
12476
+ "isOptional": false,
12477
+ "isAbstract": false,
12478
+ "name": "forCustomElement"
12479
+ },
12269
12480
  {
12270
12481
  "kind": "Method",
12271
12482
  "canonicalReference": "@microsoft/fast-element!HydratableElementController.install:member(1)",
@@ -14926,6 +15137,34 @@
14926
15137
  "startIndex": 1,
14927
15138
  "endIndex": 2
14928
15139
  }
15140
+ },
15141
+ {
15142
+ "kind": "PropertySignature",
15143
+ "canonicalReference": "@microsoft/fast-element!PartialFASTElementDefinition#templateOptions:member",
15144
+ "docComment": "/**\n * Options controlling how the template will be created.\n *\n * @alpha\n */\n",
15145
+ "excerptTokens": [
15146
+ {
15147
+ "kind": "Content",
15148
+ "text": "readonly templateOptions?: "
15149
+ },
15150
+ {
15151
+ "kind": "Reference",
15152
+ "text": "TemplateOptions",
15153
+ "canonicalReference": "@microsoft/fast-element!TemplateOptions:type"
15154
+ },
15155
+ {
15156
+ "kind": "Content",
15157
+ "text": ";"
15158
+ }
15159
+ ],
15160
+ "isReadonly": true,
15161
+ "isOptional": true,
15162
+ "releaseTag": "Alpha",
15163
+ "name": "templateOptions",
15164
+ "propertyTypeTokenRange": {
15165
+ "startIndex": 1,
15166
+ "endIndex": 2
15167
+ }
14929
15168
  }
14930
15169
  ],
14931
15170
  "extendsTokenRanges": []
@@ -20551,6 +20790,32 @@
20551
20790
  ],
20552
20791
  "extendsTokenRanges": []
20553
20792
  },
20793
+ {
20794
+ "kind": "TypeAlias",
20795
+ "canonicalReference": "@microsoft/fast-element!TemplateOptions:type",
20796
+ "docComment": "/**\n * Template options.\n *\n * @alpha\n */\n",
20797
+ "excerptTokens": [
20798
+ {
20799
+ "kind": "Content",
20800
+ "text": "export declare type TemplateOptions = "
20801
+ },
20802
+ {
20803
+ "kind": "Content",
20804
+ "text": "\"defer-and-hydrate\""
20805
+ },
20806
+ {
20807
+ "kind": "Content",
20808
+ "text": ";"
20809
+ }
20810
+ ],
20811
+ "fileUrlPath": "dist/dts/components/fast-definitions.d.ts",
20812
+ "releaseTag": "Alpha",
20813
+ "name": "TemplateOptions",
20814
+ "typeTokenRange": {
20815
+ "startIndex": 1,
20816
+ "endIndex": 2
20817
+ }
20818
+ },
20554
20819
  {
20555
20820
  "kind": "TypeAlias",
20556
20821
  "canonicalReference": "@microsoft/fast-element!TemplateValue:type",
@@ -4510,6 +4510,36 @@ function children(propertyOrOptions) {
4510
4510
  return new ChildrenDirective(propertyOrOptions);
4511
4511
  }
4512
4512
 
4513
+ /******************************************************************************
4514
+ Copyright (c) Microsoft Corporation.
4515
+
4516
+ Permission to use, copy, modify, and/or distribute this software for any
4517
+ purpose with or without fee is hereby granted.
4518
+
4519
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4520
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4521
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4522
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4523
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4524
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4525
+ PERFORMANCE OF THIS SOFTWARE.
4526
+ ***************************************************************************** */
4527
+
4528
+ function __awaiter(thisArg, _arguments, P, generator) {
4529
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4530
+ return new (P || (P = Promise))(function (resolve, reject) {
4531
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
4532
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
4533
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
4534
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
4535
+ });
4536
+ }
4537
+
4538
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
4539
+ var e = new Error(message);
4540
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4541
+ };
4542
+
4513
4543
  const booleanMode = "boolean";
4514
4544
  const reflectMode = "reflect";
4515
4545
  /**
@@ -4732,7 +4762,7 @@ const fastElementRegistry = FAST.getById(KernelServiceId.elementRegistry, () =>
4732
4762
  */
4733
4763
  class FASTElementDefinition {
4734
4764
  constructor(type, nameOrConfig = type.definition) {
4735
- var _a;
4765
+ var _b;
4736
4766
  this.platformDefined = false;
4737
4767
  if (isString(nameOrConfig)) {
4738
4768
  nameOrConfig = { name: nameOrConfig };
@@ -4740,7 +4770,8 @@ class FASTElementDefinition {
4740
4770
  this.type = type;
4741
4771
  this.name = nameOrConfig.name;
4742
4772
  this.template = nameOrConfig.template;
4743
- this.registry = (_a = nameOrConfig.registry) !== null && _a !== void 0 ? _a : customElements;
4773
+ this.templateOptions = nameOrConfig.templateOptions;
4774
+ this.registry = (_b = nameOrConfig.registry) !== null && _b !== void 0 ? _b : customElements;
4744
4775
  const proto = type.prototype;
4745
4776
  const attributes = AttributeDefinition.collect(type, nameOrConfig.attributes);
4746
4777
  const observedAttributes = new Array(attributes.length);
@@ -4772,6 +4803,8 @@ class FASTElementDefinition {
4772
4803
  : Object.assign(Object.assign({}, defaultElementOptions), nameOrConfig.elementOptions);
4773
4804
  this.styles = ElementStyles.normalize(nameOrConfig.styles);
4774
4805
  fastElementRegistry.register(this);
4806
+ Observable.defineProperty(FASTElementDefinition.isRegistered, this.name);
4807
+ FASTElementDefinition.isRegistered[this.name] = this.type;
4775
4808
  }
4776
4809
  /**
4777
4810
  * Indicates if this element has been defined in at least one registry.
@@ -4814,7 +4847,43 @@ class FASTElementDefinition {
4814
4847
  static registerBaseType(type) {
4815
4848
  fastElementBaseTypes.add(type);
4816
4849
  }
4850
+ /**
4851
+ * Creates an instance of FASTElementDefinition asynchronously. This option assumes
4852
+ * that a template and shadowOptions will be provided and completes when those requirements
4853
+ * are met.
4854
+ * @param type - The type this definition is being created for.
4855
+ * @param nameOrDef - The name of the element to define or a config object
4856
+ * that describes the element to define.
4857
+ * @alpha
4858
+ */
4859
+ static composeAsync(type, nameOrDef) {
4860
+ return new Promise(resolve => {
4861
+ if (fastElementBaseTypes.has(type) || fastElementRegistry.getByType(type)) {
4862
+ resolve(new FASTElementDefinition(class extends type {
4863
+ }, nameOrDef));
4864
+ }
4865
+ const definition = new FASTElementDefinition(type, nameOrDef);
4866
+ Promise.all([
4867
+ new Promise(resolve => {
4868
+ Observable.getNotifier(definition).subscribe({
4869
+ handleChange: () => resolve(),
4870
+ }, "template");
4871
+ }),
4872
+ new Promise(resolve => {
4873
+ Observable.getNotifier(definition).subscribe({
4874
+ handleChange: () => resolve(),
4875
+ }, "shadowOptions");
4876
+ }),
4877
+ ]).then(() => {
4878
+ resolve(definition);
4879
+ });
4880
+ });
4881
+ }
4817
4882
  }
4883
+ /**
4884
+ * The definition has been registered to the FAST element registry.
4885
+ */
4886
+ FASTElementDefinition.isRegistered = {};
4818
4887
  /**
4819
4888
  * Gets the element definition associated with the specified type.
4820
4889
  * @param type - The custom element type to retrieve the definition for.
@@ -4825,6 +4894,21 @@ FASTElementDefinition.getByType = fastElementRegistry.getByType;
4825
4894
  * @param instance - The custom element instance to retrieve the definition for.
4826
4895
  */
4827
4896
  FASTElementDefinition.getForInstance = fastElementRegistry.getForInstance;
4897
+ /**
4898
+ * Indicates when a custom elements definition has been registered with the fastElementRegistry.
4899
+ * @param name - The name of the defined custom element.
4900
+ * @alpha
4901
+ */
4902
+ FASTElementDefinition.registerAsync = (name) => __awaiter(void 0, void 0, void 0, function* () {
4903
+ return new Promise(resolve => {
4904
+ if (FASTElementDefinition.isRegistered[name]) {
4905
+ resolve(FASTElementDefinition.isRegistered[name]);
4906
+ }
4907
+ Observable.getNotifier(FASTElementDefinition.isRegistered).subscribe({
4908
+ handleChange: () => resolve(FASTElementDefinition.isRegistered[name]),
4909
+ }, name);
4910
+ });
4911
+ });
4828
4912
  Observable.defineProperty(FASTElementDefinition.prototype, "template");
4829
4913
  Observable.defineProperty(FASTElementDefinition.prototype, "shadowOptions");
4830
4914
 
@@ -5925,6 +6009,16 @@ class HydratableElementController extends ElementController {
5925
6009
  record.target.$fastController.connect();
5926
6010
  }
5927
6011
  }
6012
+ static forCustomElement(element, override) {
6013
+ const definition = FASTElementDefinition.getForInstance(element);
6014
+ if (definition !== undefined &&
6015
+ definition.templateOptions === "defer-and-hydrate" &&
6016
+ !definition.template) {
6017
+ element.setAttribute(deferHydrationAttribute, "");
6018
+ element.setAttribute(needsHydrationAttribute, "");
6019
+ }
6020
+ return super.forCustomElement(element, override);
6021
+ }
5928
6022
  connect() {
5929
6023
  var _a, _b;
5930
6024
  // Initialize needsHydration on first connect
@@ -6024,6 +6118,24 @@ function compose(type, nameOrDef) {
6024
6118
  }
6025
6119
  return FASTElementDefinition.compose(this, type);
6026
6120
  }
6121
+ function defineAsync(type, nameOrDef) {
6122
+ if (isFunction(type)) {
6123
+ return new Promise(resolve => {
6124
+ FASTElementDefinition.composeAsync(type, nameOrDef).then(value => {
6125
+ resolve(value);
6126
+ });
6127
+ }).then(value => {
6128
+ return value.define().type;
6129
+ });
6130
+ }
6131
+ return new Promise(resolve => {
6132
+ FASTElementDefinition.composeAsync(this, type).then(value => {
6133
+ resolve(value);
6134
+ });
6135
+ }).then(value => {
6136
+ return value.define().type;
6137
+ });
6138
+ }
6027
6139
  function define(type, nameOrDef) {
6028
6140
  if (isFunction(type)) {
6029
6141
  return FASTElementDefinition.compose(type, nameOrDef).define().type;
@@ -6057,6 +6169,11 @@ const FASTElement = Object.assign(createFASTElement(HTMLElement), {
6057
6169
  * @public
6058
6170
  */
6059
6171
  compose,
6172
+ /**
6173
+ * Defines metadata for a FASTElement which can be used after it has been resolved to define the element.
6174
+ * @alpha
6175
+ */
6176
+ defineAsync,
6060
6177
  });
6061
6178
  /**
6062
6179
  * Decorator: Defines a platform custom element based on `FASTElement`.