@microsoft/fast-element 2.0.0-beta.20 → 2.0.0-beta.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.
package/CHANGELOG.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "@microsoft/fast-element",
3
3
  "entries": [
4
+ {
5
+ "date": "Tue, 14 Feb 2023 04:02:35 GMT",
6
+ "tag": "@microsoft/fast-element_v2.0.0-beta.21",
7
+ "version": "2.0.0-beta.21",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "rob@bluespire.com",
12
+ "package": "@microsoft/fast-element",
13
+ "commit": "d38d31d2dd7496b5eb1e7c65b57de9a5e05e8546",
14
+ "comment": "fix: cleanup types, docs, etc. in root source files of fast-element in preparation for release"
15
+ },
16
+ {
17
+ "author": "nicholasrice@users.noreply.github.com",
18
+ "package": "@microsoft/fast-element",
19
+ "commit": "09d57ca18700331d054515c3b3f6fae07528cca0",
20
+ "comment": "Remove un-necessary expression from StyleElementStrategy"
21
+ }
22
+ ]
23
+ }
24
+ },
4
25
  {
5
26
  "date": "Wed, 11 Jan 2023 22:07:47 GMT",
6
27
  "tag": "@microsoft/fast-element_v2.0.0-beta.20",
package/CHANGELOG.md CHANGED
@@ -1,9 +1,18 @@
1
1
  # Change Log - @microsoft/fast-element
2
2
 
3
- This log was last generated on Wed, 11 Jan 2023 22:07:47 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 14 Feb 2023 04:02:35 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 2.0.0-beta.21
8
+
9
+ Tue, 14 Feb 2023 04:02:35 GMT
10
+
11
+ ### Changes
12
+
13
+ - fix: cleanup types, docs, etc. in root source files of fast-element in preparation for release (rob@bluespire.com)
14
+ - Remove un-necessary expression from StyleElementStrategy (nicholasrice@users.noreply.github.com)
15
+
7
16
  ## 2.0.0-beta.20
8
17
 
9
18
  Wed, 11 Jan 2023 22:07:47 GMT
@@ -11,31 +11,31 @@ export declare type Context<T> = {
11
11
  * A constant key that can be used to represent a Context dependency.
12
12
  * The key can be used for context or DI but also doubles as a decorator for
13
13
  * resolving the associated dependency.
14
- * @beta
14
+ * @public
15
15
  */
16
16
  export declare type ContextDecorator<T = any> = Readonly<Context<T>> & PropertyDecorator & ParameterDecorator;
17
17
  /**
18
18
  * A Context object defines an optional initial value for a Context, as well as a name identifier for debugging purposes.
19
19
  * The FASTContext can also be used as a decorator to declare context dependencies or as a key for DI.
20
- * @beta
20
+ * @public
21
21
  */
22
22
  export declare type FASTContext<T> = ContextDecorator<T> & {
23
23
  get(target: EventTarget): T;
24
24
  provide(target: EventTarget, value: T): void;
25
25
  request(target: EventTarget, callback: ContextCallback<T>, multiple?: boolean): void;
26
- handle(target: EventTarget, callback: (event: ContextEvent<FASTContext<T>>) => void): any;
26
+ handle(target: EventTarget, callback: (event: ContextEvent<FASTContext<T>>) => void): void;
27
27
  };
28
28
  /**
29
29
  * A strategy that controls how all Context.request API calls are handled.
30
30
  * @remarks
31
- * By default this is handled via Context.dispatch, which dispatched a ContextEvent.
32
- * @beta
31
+ * By default this is handled via Context.dispatch, which dispatches a ContextEvent.
32
+ * @public
33
33
  */
34
34
  export declare type FASTContextRequestStrategy = <T extends UnknownContext>(target: EventTarget, context: T, callback: ContextCallback<ContextType<T>>, multiple: any) => void;
35
35
  declare const contextEventType = "context-request";
36
36
  /**
37
37
  * Enables using the {@link https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md | W3C Community Context protocol.}
38
- * @beta
38
+ * @public
39
39
  */
40
40
  export declare const Context: Readonly<{
41
41
  /**
@@ -2,10 +2,12 @@ import { DOMAspect, DOMPolicy, DOMSink } from "./dom.js";
2
2
  import { TrustedTypesPolicy } from "./interfaces.js";
3
3
  /**
4
4
  * A specific DOM sink guard for a node aspect.
5
+ * @public
5
6
  */
6
7
  export declare type DOMSinkGuards = Record<string, (tagName: string | null, aspect: DOMAspect, aspectName: string, sink: DOMSink) => DOMSink>;
7
8
  /**
8
9
  * Aspect-specific guards for a DOM Policy.
10
+ * @public
9
11
  */
10
12
  export declare type DOMAspectGuards = {
11
13
  /**
@@ -35,17 +37,26 @@ export declare type DOMAspectGuards = {
35
37
  };
36
38
  /**
37
39
  * Element-specific guards for a DOM Policy.
40
+ * @public
38
41
  */
39
42
  export declare type DOMElementGuards = Record<string, DOMAspectGuards>;
40
43
  /**
41
44
  * Guard configuration for a DOM Policy.
45
+ * @public
42
46
  */
43
47
  export declare type DOMGuards = {
48
+ /**
49
+ * Guards for specific elements.
50
+ */
44
51
  elements: DOMElementGuards;
52
+ /**
53
+ * General aspect guards independent of the element type.
54
+ */
45
55
  aspects: DOMAspectGuards;
46
56
  };
47
57
  /**
48
58
  * Options for creating a DOM Policy.
59
+ * @public
49
60
  */
50
61
  export declare type DOMPolicyOptions = {
51
62
  /**
@@ -57,6 +68,10 @@ export declare type DOMPolicyOptions = {
57
68
  */
58
69
  guards?: Partial<DOMGuards>;
59
70
  };
71
+ /**
72
+ * A helper for creating DOM policies.
73
+ * @public
74
+ */
60
75
  declare const DOMPolicy: Readonly<{
61
76
  /**
62
77
  * Creates a new DOM Policy object.
@@ -53,7 +53,7 @@ export declare type Mutable<T> = {
53
53
  };
54
54
  /**
55
55
  * The FAST global.
56
- * @internal
56
+ * @public
57
57
  */
58
58
  export interface FASTGlobal {
59
59
  /**
@@ -114,6 +114,7 @@ export declare const enum Message {
114
114
  directCallToHTMLTagNotAllowed = 1206,
115
115
  onlySetTemplatePolicyOnce = 1207,
116
116
  cannotSetTemplatePolicyAfterCompilation = 1208,
117
+ blockedByDOMPolicy = 1209,
117
118
  missingElementDefinition = 1401,
118
119
  noRegistrationForContext = 1501,
119
120
  noFactoryForResolver = 1502,
@@ -8,18 +8,18 @@ export declare const Metadata: Readonly<{
8
8
  * @param Type - The type to get the metadata for.
9
9
  * @returns The metadata array or a frozen empty array if no metadata is found.
10
10
  */
11
- getDesignParamTypes: (Type: any) => any;
11
+ getDesignParamTypes: (Type: Constructable) => readonly any[];
12
12
  /**
13
13
  * Gets the "annotation:paramtypes" metadata for the specified type.
14
14
  * @param Type - The type to get the metadata for.
15
15
  * @returns The metadata array or a frozen empty array if no metadata is found.
16
16
  */
17
- getAnnotationParamTypes: (Type: any) => any;
17
+ getAnnotationParamTypes: (Type: Constructable) => readonly any[];
18
18
  /**
19
- *
20
- * @param Type - Gets the "annotation:paramtypes" metadata for the specified type. If none is found,
19
+ * Gets the "annotation:paramtypes" metadata for the specified type. If none is found,
21
20
  * an empty, mutable metadata array is created and added.
22
- * @returns The metadata array.
21
+ * @param Type - The type to get or create the metadata for.
22
+ * @returns A mutable metadata array.
23
23
  */
24
24
  getOrCreateAnnotationParamTypes(Type: Constructable): any[];
25
25
  }>;
@@ -1,20 +1,32 @@
1
- /**
2
- * This module provides
3
- */
4
1
  /**
5
2
  * An implementation of the https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/pending-task.md proposal.
6
- * @beta
3
+ * @public
7
4
  */
8
5
  export interface PendingTask extends Event {
9
- complete: Promise<void>;
6
+ /**
7
+ * A promise that resolves when the pending task is complete.
8
+ */
9
+ readonly complete: Promise<void>;
10
10
  }
11
11
  /**
12
12
  * A concrete implementation of {@link PendingTask}
13
- * @beta
13
+ * @public
14
14
  */
15
15
  export declare class PendingTaskEvent extends Event implements PendingTask {
16
- complete: Promise<void>;
16
+ readonly complete: Promise<void>;
17
+ /**
18
+ * The type of the pending task event.
19
+ */
17
20
  static readonly type = "pending-task";
21
+ /**
22
+ * Creates an instance of PendingTaskEvent.
23
+ * @param complete - A promise that resolves when the pending task is complete.
24
+ */
18
25
  constructor(complete: Promise<void>);
26
+ /**
27
+ * Determines whether a value is a PendingTaskEvent.
28
+ * @param value - The value to check.
29
+ * @returns True if the value is a PendingTaskEvent; false otherwise.
30
+ */
19
31
  static isPendingTask<T extends Event>(value: T | PendingTask): value is PendingTask;
20
32
  }
@@ -2,7 +2,7 @@ import type { FASTGlobal } from "./interfaces.js";
2
2
  import "./polyfills.js";
3
3
  /**
4
4
  * The FAST global.
5
- * @internal
5
+ * @public
6
6
  */
7
7
  export declare const FAST: FASTGlobal;
8
8
  /**
@@ -14,7 +14,7 @@ export declare function composedParent<T extends HTMLElement>(element: T): HTMLE
14
14
  * Determines if the reference element contains the test element in a "composed" DOM tree that
15
15
  * ignores shadow DOM boundaries.
16
16
  *
17
- * Returns true of the test element is a descendent of the reference, or exist in
17
+ * Returns true of the test element is a descendent of the reference, or exists in
18
18
  * a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
19
19
  * @param reference - The element to test for containment against.
20
20
  * @param test - The element being tested for containment.
@@ -23,13 +23,14 @@ export declare function composedParent<T extends HTMLElement>(element: T): HTMLE
23
23
  */
24
24
  export declare function composedContains(reference: HTMLElement, test: HTMLElement): boolean;
25
25
  /**
26
+ * An extension of MutationObserver that supports unobserving nodes.
26
27
  * @internal
27
28
  */
28
29
  export declare class UnobservableMutationObserver extends MutationObserver {
29
30
  private readonly callback;
30
31
  private observedNodes;
31
32
  /**
32
- * An extension of MutationObserver that supports unobserving nodes.
33
+ * Creates an instance of UnobservableMutationObserver.
33
34
  * @param callback - The callback to invoke when observed nodes are changed.
34
35
  */
35
36
  constructor(callback: MutationCallback);
@@ -478,7 +478,6 @@ export class StyleElementStrategy {
478
478
  removeStylesFrom(target) {
479
479
  target = usableStyleTarget(normalizeStyleTarget(target));
480
480
  const styles = target.querySelectorAll(`.${this.styleClass}`);
481
- styles[0].parentNode;
482
481
  for (let i = 0, ii = styles.length; i < ii; ++i) {
483
482
  target.removeChild(styles[i]);
484
483
  }
@@ -5,7 +5,7 @@ const contextEventType = "context-request";
5
5
  let requestStrategy;
6
6
  /**
7
7
  * Enables using the {@link https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md | W3C Community Context protocol.}
8
- * @beta
8
+ * @public
9
9
  */
10
10
  export const Context = Object.freeze({
11
11
  /**
@@ -132,7 +132,7 @@ export const Context = Object.freeze({
132
132
  * initialValue if the context isn't handled.
133
133
  */
134
134
  defineProperty(target, propertyName, context) {
135
- const field = `$di_${propertyName}`;
135
+ const field = Symbol.for(`fast:di:${propertyName}`);
136
136
  Reflect.defineProperty(target, propertyName, {
137
137
  get: function () {
138
138
  var _a;
package/dist/esm/debug.js CHANGED
@@ -17,6 +17,7 @@ const debugMessages = {
17
17
  [1206 /* directCallToHTMLTagNotAllowed */]: "Calling html`` as a normal function invalidates the security guarantees provided by FAST.",
18
18
  [1207 /* onlySetTemplatePolicyOnce */]: "The DOM Policy for an HTML template can only be set once.",
19
19
  [1208 /* cannotSetTemplatePolicyAfterCompilation */]: "The DOM Policy cannot be set after a template is compiled.",
20
+ [1209 /* blockedByDOMPolicy */]: "'${aspectName}' on '${tagName}' is blocked by the current DOMPolicy.",
20
21
  [1401 /* missingElementDefinition */]: "Missing FASTElement definition.",
21
22
  [1501 /* noRegistrationForContext */]: "No registration for Context/Interface '${name}'.",
22
23
  [1502 /* noFactoryForResolver */]: "Dependency injection resolver for '${key}' returned a null factory.",
package/dist/esm/di/di.js CHANGED
@@ -371,16 +371,16 @@ export const DI = Object.freeze({
371
371
  * The respectConnection option is only applicable to elements that descend from FASTElement.
372
372
  */
373
373
  defineProperty(target, propertyName, key, respectConnection = false) {
374
- const diPropertyKey = `$di_${propertyName}`;
374
+ const field = Symbol.for(`fast:di:${propertyName}`);
375
375
  Reflect.defineProperty(target, propertyName, {
376
376
  get: function () {
377
- let value = this[diPropertyKey];
377
+ let value = this[field];
378
378
  if (value === void 0) {
379
379
  const container = this instanceof Node
380
380
  ? DI.findResponsibleContainer(this)
381
381
  : DI.getOrCreateDOMContainer();
382
382
  value = container.get(key);
383
- this[diPropertyKey] = value;
383
+ this[field] = value;
384
384
  if (respectConnection) {
385
385
  const notifier = this.$fastController;
386
386
  if (!notifier) {
@@ -389,9 +389,9 @@ export const DI = Object.freeze({
389
389
  const handleChange = () => {
390
390
  const newContainer = DI.findResponsibleContainer(this);
391
391
  const newValue = newContainer.get(key);
392
- const oldValue = this[diPropertyKey];
392
+ const oldValue = this[field];
393
393
  if (newValue !== oldValue) {
394
- this[diPropertyKey] = value;
394
+ this[field] = value;
395
395
  notifier.notify(propertyName);
396
396
  }
397
397
  };
@@ -1,5 +1,6 @@
1
1
  import { DOMAspect } from "./dom.js";
2
2
  import { isString } from "./interfaces.js";
3
+ import { FAST } from "./platform.js";
3
4
  function safeURL(tagName, aspect, aspectName, sink) {
4
5
  return (target, name, value, ...rest) => {
5
6
  if (isString(value)) {
@@ -9,7 +10,10 @@ function safeURL(tagName, aspect, aspectName, sink) {
9
10
  };
10
11
  }
11
12
  function block(tagName, aspect, aspectName, sink) {
12
- throw new Error(`${aspectName} on ${tagName !== null && tagName !== void 0 ? tagName : "text"} is blocked by the current DOMPolicy.`);
13
+ throw FAST.error(1209 /* Message.blockedByDOMPolicy */, {
14
+ aspectName,
15
+ tagName: tagName !== null && tagName !== void 0 ? tagName : "text",
16
+ });
13
17
  }
14
18
  const defaultDOMElementGuards = {
15
19
  a: {
@@ -303,6 +307,10 @@ function tryGuard(aspectGuards, tagName, aspect, aspectName, sink) {
303
307
  }
304
308
  }
305
309
  }
310
+ /**
311
+ * A helper for creating DOM policies.
312
+ * @public
313
+ */
306
314
  const DOMPolicy = Object.freeze({
307
315
  /**
308
316
  * Creates a new DOM Policy object.
@@ -22,6 +22,7 @@ if (!("metadata" in Reflect)) {
22
22
  return void 0;
23
23
  };
24
24
  }
25
+ const annotationParamTypesKey = "annotation:paramtypes";
25
26
  /**
26
27
  * Provides basic metadata capabilities used by Context and Dependency Injection.
27
28
  */
@@ -31,29 +32,29 @@ export const Metadata = Object.freeze({
31
32
  * @param Type - The type to get the metadata for.
32
33
  * @returns The metadata array or a frozen empty array if no metadata is found.
33
34
  */
34
- getDesignParamTypes: Type => {
35
+ getDesignParamTypes: (Type) => {
35
36
  var _a;
36
- return (_a = Reflect.getOwnMetadata("design:paramtypes", Type)) !== null && _a !== void 0 ? _a : emptyArray;
37
+ return ((_a = Reflect.getOwnMetadata("design:paramtypes", Type)) !== null && _a !== void 0 ? _a : emptyArray);
37
38
  },
38
39
  /**
39
40
  * Gets the "annotation:paramtypes" metadata for the specified type.
40
41
  * @param Type - The type to get the metadata for.
41
42
  * @returns The metadata array or a frozen empty array if no metadata is found.
42
43
  */
43
- getAnnotationParamTypes: Type => {
44
+ getAnnotationParamTypes: (Type) => {
44
45
  var _a;
45
- return (_a = Reflect.getOwnMetadata("annotation:paramtypes", Type)) !== null && _a !== void 0 ? _a : emptyArray;
46
+ return ((_a = Reflect.getOwnMetadata(annotationParamTypesKey, Type)) !== null && _a !== void 0 ? _a : emptyArray);
46
47
  },
47
48
  /**
48
- *
49
- * @param Type - Gets the "annotation:paramtypes" metadata for the specified type. If none is found,
49
+ * Gets the "annotation:paramtypes" metadata for the specified type. If none is found,
50
50
  * an empty, mutable metadata array is created and added.
51
- * @returns The metadata array.
51
+ * @param Type - The type to get or create the metadata for.
52
+ * @returns A mutable metadata array.
52
53
  */
53
54
  getOrCreateAnnotationParamTypes(Type) {
54
55
  let types = this.getAnnotationParamTypes(Type);
55
56
  if (types === emptyArray) {
56
- Reflect.defineMetadata("annotation:paramtypes", (types = []), Type);
57
+ Reflect.defineMetadata(annotationParamTypesKey, (types = []), Type);
57
58
  }
58
59
  return types;
59
60
  },
@@ -1,16 +1,28 @@
1
1
  /**
2
2
  * A concrete implementation of {@link PendingTask}
3
- * @beta
3
+ * @public
4
4
  */
5
5
  export class PendingTaskEvent extends Event {
6
+ /**
7
+ * Creates an instance of PendingTaskEvent.
8
+ * @param complete - A promise that resolves when the pending task is complete.
9
+ */
6
10
  constructor(complete) {
7
11
  super(PendingTaskEvent.type, { bubbles: true, composed: true });
8
12
  this.complete = complete;
9
13
  }
14
+ /**
15
+ * Determines whether a value is a PendingTaskEvent.
16
+ * @param value - The value to check.
17
+ * @returns True if the value is a PendingTaskEvent; false otherwise.
18
+ */
10
19
  static isPendingTask(value) {
11
20
  var _a;
12
21
  return (value.type === PendingTaskEvent.type &&
13
22
  typeof ((_a = value.complete) === null || _a === void 0 ? void 0 : _a.then) === "function");
14
23
  }
15
24
  }
25
+ /**
26
+ * The type of the pending task event.
27
+ */
16
28
  PendingTaskEvent.type = "pending-task";
@@ -10,7 +10,7 @@ if (globalThis.FAST === void 0) {
10
10
  }
11
11
  /**
12
12
  * The FAST global.
13
- * @internal
13
+ * @public
14
14
  */
15
15
  export const FAST = globalThis.FAST;
16
16
  if (FAST.getById === void 0) {
@@ -28,7 +28,7 @@ export function composedParent(element) {
28
28
  * Determines if the reference element contains the test element in a "composed" DOM tree that
29
29
  * ignores shadow DOM boundaries.
30
30
  *
31
- * Returns true of the test element is a descendent of the reference, or exist in
31
+ * Returns true of the test element is a descendent of the reference, or exists in
32
32
  * a shadow DOM that is a logical descendent of the reference. Otherwise returns false.
33
33
  * @param reference - The element to test for containment against.
34
34
  * @param test - The element being tested for containment.
@@ -46,11 +46,12 @@ export function composedContains(reference, test) {
46
46
  return false;
47
47
  }
48
48
  /**
49
+ * An extension of MutationObserver that supports unobserving nodes.
49
50
  * @internal
50
51
  */
51
52
  export class UnobservableMutationObserver extends MutationObserver {
52
53
  /**
53
- * An extension of MutationObserver that supports unobserving nodes.
54
+ * Creates an instance of UnobservableMutationObserver.
54
55
  * @param callback - The callback to invoke when observed nodes are changed.
55
56
  */
56
57
  constructor(callback) {