@microsoft/fast-element 2.0.0-beta.19 → 2.0.0-beta.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.
@@ -321,6 +321,17 @@ export declare class ChildrenDirective extends NodeObservationDirective<Children
321
321
  */
322
322
  export declare type ChildrenDirectiveOptions<T = any> = ChildListDirectiveOptions<T> | SubtreeDirectiveOptions<T>;
323
323
 
324
+ /**
325
+ * Represents a constructable class with a prototype.
326
+ * @public
327
+ */
328
+ export declare type Class<T, C = {}> = C & Constructable<T> & {
329
+ /**
330
+ * The class's prototype;
331
+ */
332
+ readonly prototype: T;
333
+ };
334
+
324
335
  /**
325
336
  * A function capable of compiling a template from the preprocessed form produced
326
337
  * by the html template function into a result that can instantiate views.
@@ -391,7 +402,7 @@ declare function compose<TType extends Constructable<HTMLElement> = Constructabl
391
402
  declare function compose<TType extends Constructable<HTMLElement> = Constructable<HTMLElement>>(type: TType, nameOrDef?: string | PartialFASTElementDefinition): FASTElementDefinition<TType>;
392
403
 
393
404
  /**
394
- * Allows for the creation of Constructable mixin classes.
405
+ * Represents a type which can be constructed with the new operator.
395
406
  *
396
407
  * @public
397
408
  */
@@ -517,12 +528,6 @@ export declare interface CSSDirectiveDefinition<TType extends Constructable<CSSD
517
528
  readonly type: TType;
518
529
  }
519
530
 
520
- /**
521
- * @deprecated Use css.partial instead.
522
- * @public
523
- */
524
- export declare const cssPartial: (strings: TemplateStringsArray, ...values: (ComposableStyles | CSSDirective)[]) => CSSDirective;
525
-
526
531
  /**
527
532
  * Transforms a template literal string into styles.
528
533
  * @param strings - The string fragments that are interpolated with the values.
@@ -550,24 +555,6 @@ export declare type CSSTemplateTag = ((strings: TemplateStringsArray, ...values:
550
555
  */
551
556
  export declare function customElement(nameOrDef: string | PartialFASTElementDefinition): (type: Constructable<HTMLElement>) => void;
552
557
 
553
- /**
554
- * Injects static HTML without platform protection.
555
- * @param html - The html to injection.
556
- * @returns A DangerousHTMLDirective.
557
- * @public
558
- */
559
- export declare function dangerousHTML<TSource = any, TParent = any>(html: string): CaptureType<TSource, TParent>;
560
-
561
- /**
562
- * A directive capable of injecting static HTML platform runtime protection.
563
- * @public
564
- */
565
- export declare class DangerousHTMLDirective implements HTMLDirective {
566
- private html;
567
- constructor(html: string);
568
- createHTML(): string;
569
- }
570
-
571
558
  /**
572
559
  * Metadata used to configure a custom attribute's behavior through a decorator.
573
560
  * @public
@@ -594,21 +581,6 @@ export declare interface Disposable {
594
581
  * @public
595
582
  */
596
583
  export declare const DOM: Readonly<{
597
- /**
598
- * @deprecated
599
- * Use Updates.enqueue().
600
- */
601
- queueUpdate: (callable: Callable) => void;
602
- /**
603
- * @deprecated
604
- * Use Updates.next()
605
- */
606
- nextUpdate: () => Promise<void>;
607
- /**
608
- * @deprecated
609
- * Use Updates.process()
610
- */
611
- processUpdates: () => void;
612
584
  /**
613
585
  * Gets the dom policy used by the templating system.
614
586
  */
@@ -1325,7 +1297,7 @@ export declare interface HostController<TSource = any> {
1325
1297
  * other template instances, and Directive instances.
1326
1298
  * @public
1327
1299
  */
1328
- export declare function html<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent>[]): ViewTemplate<TSource, TParent>;
1300
+ export declare const html: HTMLTemplateTag;
1329
1301
 
1330
1302
  /**
1331
1303
  * A directive that applies bindings.
@@ -1456,6 +1428,24 @@ export declare interface HTMLTemplateCompilationResult<TSource = any, TParent =
1456
1428
  createView(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
1457
1429
  }
1458
1430
 
1431
+ /**
1432
+ * Transforms a template literal string into a ViewTemplate.
1433
+ * @param strings - The string fragments that are interpolated with the values.
1434
+ * @param values - The values that are interpolated with the string fragments.
1435
+ * @remarks
1436
+ * The html helper supports interpolation of strings, numbers, binding expressions,
1437
+ * other template instances, and Directive instances.
1438
+ * @public
1439
+ */
1440
+ export declare type HTMLTemplateTag = (<TSource = any, TParent = any>(strings: TemplateStringsArray, ...values: TemplateValue<TSource, TParent>[]) => ViewTemplate<TSource, TParent>) & {
1441
+ /**
1442
+ * Transforms a template literal string into partial HTML.
1443
+ * @param html - The HTML string fragment to interpolate.
1444
+ * @public
1445
+ */
1446
+ partial(html: string): InlineTemplateDirective;
1447
+ };
1448
+
1459
1449
  /**
1460
1450
  * The standard View implementation, which also implements ElementView and SyntheticView.
1461
1451
  * @public
@@ -1591,6 +1581,29 @@ export declare class HTMLView<TSource = any, TParent = any> implements ElementVi
1591
1581
  static disposeContiguousBatch(views: SyntheticView[]): void;
1592
1582
  }
1593
1583
 
1584
+ /**
1585
+ * Inlines a template into another template.
1586
+ * @public
1587
+ */
1588
+ export declare class InlineTemplateDirective implements HTMLDirective {
1589
+ private html;
1590
+ private factories;
1591
+ /**
1592
+ * An empty template partial.
1593
+ */
1594
+ static readonly empty: InlineTemplateDirective;
1595
+ /**
1596
+ * Creates an instance of InlineTemplateDirective.
1597
+ * @param template - The template to inline.
1598
+ */
1599
+ constructor(html: string, factories?: Record<string, ViewBehaviorFactory>);
1600
+ /**
1601
+ * Creates HTML to be used within a template.
1602
+ * @param add - Can be used to add behavior factories to a template.
1603
+ */
1604
+ createHTML(add: AddViewBehaviorFactory): string;
1605
+ }
1606
+
1594
1607
  /**
1595
1608
  * Observes array lengths.
1596
1609
  * @public
@@ -1650,8 +1663,6 @@ export declare const Markup: Readonly<{
1650
1663
  comment: (id: string) => string;
1651
1664
  }>;
1652
1665
 
1653
- /* Excluded from this release type: Mutable */
1654
-
1655
1666
  /**
1656
1667
  * Options for configuring node observation behavior.
1657
1668
  * @public
@@ -1783,6 +1794,12 @@ export declare interface Notifier {
1783
1794
  unsubscribe(subscriber: Subscriber, propertyToUnwatch?: any): void;
1784
1795
  }
1785
1796
 
1797
+ /**
1798
+ * A {@link ValueConverter} that converts to and from `boolean` values. `null`, `undefined`, `""`, and `void` values are converted to `null`.
1799
+ * @public
1800
+ */
1801
+ export declare const nullableBooleanConverter: ValueConverter;
1802
+
1786
1803
  /**
1787
1804
  * A {@link ValueConverter} that converts to and from `number` values.
1788
1805
  * @remarks
@@ -2522,6 +2539,10 @@ export declare interface SyntheticViewTemplate<TSource = any, TParent = any> {
2522
2539
  * Creates a SyntheticView instance based on this template definition.
2523
2540
  */
2524
2541
  create(): SyntheticView<TSource, TParent>;
2542
+ /**
2543
+ * Returns a directive that can inline the template.
2544
+ */
2545
+ inline(): CaptureType<TSource, TParent>;
2525
2546
  }
2526
2547
 
2527
2548
  /**
@@ -2530,6 +2551,18 @@ export declare interface SyntheticViewTemplate<TSource = any, TParent = any> {
2530
2551
  */
2531
2552
  export declare type TemplateValue<TSource, TParent = any> = Expression<TSource, any, TParent> | Binding<TSource, any, TParent> | HTMLDirective | CaptureType<TSource, TParent>;
2532
2553
 
2554
+ /**
2555
+ * A policy for use with the standard trustedTypes platform API.
2556
+ * @public
2557
+ */
2558
+ export declare type TrustedTypesPolicy = {
2559
+ /**
2560
+ * Creates trusted HTML.
2561
+ * @param html - The HTML to clear as trustworthy.
2562
+ */
2563
+ createHTML(html: string): string;
2564
+ };
2565
+
2533
2566
  /* Excluded from this release type: TypeDefinition */
2534
2567
 
2535
2568
  /* Excluded from this release type: TypeRegistry */
@@ -2704,6 +2737,10 @@ export declare class ViewTemplate<TSource = any, TParent = any> implements Eleme
2704
2737
  * @param hostBindingTarget - The element that host behaviors will be bound to.
2705
2738
  */
2706
2739
  create(hostBindingTarget?: Element): HTMLView<TSource, TParent>;
2740
+ /**
2741
+ * Returns a directive that can inline the template.
2742
+ */
2743
+ inline(): CaptureType<TSource, TParent>;
2707
2744
  /**
2708
2745
  * Sets the DOMPolicy for this template.
2709
2746
  * @param policy - The policy to associated with this template.
@@ -107,14 +107,17 @@ switch (kernelMode) {
107
107
  break;
108
108
  }
109
109
  /**
110
+ * Determines whether or not an object is a function.
110
111
  * @internal
111
112
  */
112
113
  const isFunction = (object) => typeof object === "function";
113
114
  /**
115
+ * Determines whether or not an object is a string.
114
116
  * @internal
115
117
  */
116
118
  const isString = (object) => typeof object === "string";
117
119
  /**
120
+ * A function which does nothing.
118
121
  * @internal
119
122
  */
120
123
  const noop = () => void 0;
@@ -235,72 +238,6 @@ function createMetadataLocator() {
235
238
  };
236
239
  }
237
240
 
238
- /**
239
- * The default UpdateQueue.
240
- * @public
241
- */
242
- const Updates = FAST.getById(KernelServiceId.updateQueue, () => {
243
- const tasks = [];
244
- const pendingErrors = [];
245
- const rAF = globalThis.requestAnimationFrame;
246
- let updateAsync = true;
247
- function throwFirstError() {
248
- if (pendingErrors.length) {
249
- throw pendingErrors.shift();
250
- }
251
- }
252
- function tryRunTask(task) {
253
- try {
254
- task.call();
255
- }
256
- catch (error) {
257
- if (updateAsync) {
258
- pendingErrors.push(error);
259
- setTimeout(throwFirstError, 0);
260
- }
261
- else {
262
- tasks.length = 0;
263
- throw error;
264
- }
265
- }
266
- }
267
- function process() {
268
- const capacity = 1024;
269
- let index = 0;
270
- while (index < tasks.length) {
271
- tryRunTask(tasks[index]);
272
- index++;
273
- // Prevent leaking memory for long chains of recursive calls to `enqueue`.
274
- // If we call `enqueue` within a task scheduled by `enqueue`, the queue will
275
- // grow, but to avoid an O(n) walk for every task we execute, we don't
276
- // shift tasks off the queue after they have been executed.
277
- // Instead, we periodically shift 1024 tasks off the queue.
278
- if (index > capacity) {
279
- // Manually shift all values starting at the index back to the
280
- // beginning of the queue.
281
- for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
282
- tasks[scan] = tasks[scan + index];
283
- }
284
- tasks.length -= index;
285
- index = 0;
286
- }
287
- }
288
- tasks.length = 0;
289
- }
290
- function enqueue(callable) {
291
- tasks.push(callable);
292
- if (tasks.length < 2) {
293
- updateAsync ? rAF(process) : process();
294
- }
295
- }
296
- return Object.freeze({
297
- enqueue,
298
- next: () => new Promise(enqueue),
299
- process,
300
- setMode: (isAsync) => (updateAsync = isAsync),
301
- });
302
- });
303
-
304
241
  /**
305
242
  * The type of HTML aspect to target.
306
243
  * @public
@@ -353,21 +290,6 @@ const fastPolicy = defaultPolicy;
353
290
  * @public
354
291
  */
355
292
  const DOM = Object.freeze({
356
- /**
357
- * @deprecated
358
- * Use Updates.enqueue().
359
- */
360
- queueUpdate: Updates.enqueue,
361
- /**
362
- * @deprecated
363
- * Use Updates.next()
364
- */
365
- nextUpdate: Updates.next,
366
- /**
367
- * @deprecated
368
- * Use Updates.process()
369
- */
370
- processUpdates: Updates.process,
371
293
  /**
372
294
  * Gets the dom policy used by the templating system.
373
295
  */
@@ -751,6 +673,72 @@ const DOMPolicy = Object.freeze({
751
673
  },
752
674
  });
753
675
 
676
+ /**
677
+ * The default UpdateQueue.
678
+ * @public
679
+ */
680
+ const Updates = FAST.getById(KernelServiceId.updateQueue, () => {
681
+ const tasks = [];
682
+ const pendingErrors = [];
683
+ const rAF = globalThis.requestAnimationFrame;
684
+ let updateAsync = true;
685
+ function throwFirstError() {
686
+ if (pendingErrors.length) {
687
+ throw pendingErrors.shift();
688
+ }
689
+ }
690
+ function tryRunTask(task) {
691
+ try {
692
+ task.call();
693
+ }
694
+ catch (error) {
695
+ if (updateAsync) {
696
+ pendingErrors.push(error);
697
+ setTimeout(throwFirstError, 0);
698
+ }
699
+ else {
700
+ tasks.length = 0;
701
+ throw error;
702
+ }
703
+ }
704
+ }
705
+ function process() {
706
+ const capacity = 1024;
707
+ let index = 0;
708
+ while (index < tasks.length) {
709
+ tryRunTask(tasks[index]);
710
+ index++;
711
+ // Prevent leaking memory for long chains of recursive calls to `enqueue`.
712
+ // If we call `enqueue` within a task scheduled by `enqueue`, the queue will
713
+ // grow, but to avoid an O(n) walk for every task we execute, we don't
714
+ // shift tasks off the queue after they have been executed.
715
+ // Instead, we periodically shift 1024 tasks off the queue.
716
+ if (index > capacity) {
717
+ // Manually shift all values starting at the index back to the
718
+ // beginning of the queue.
719
+ for (let scan = 0, newLength = tasks.length - index; scan < newLength; scan++) {
720
+ tasks[scan] = tasks[scan + index];
721
+ }
722
+ tasks.length -= index;
723
+ index = 0;
724
+ }
725
+ }
726
+ tasks.length = 0;
727
+ }
728
+ function enqueue(callable) {
729
+ tasks.push(callable);
730
+ if (tasks.length < 2) {
731
+ updateAsync ? rAF(process) : process();
732
+ }
733
+ }
734
+ return Object.freeze({
735
+ enqueue,
736
+ next: () => new Promise(enqueue),
737
+ process,
738
+ setMode: (isAsync) => (updateAsync = isAsync),
739
+ });
740
+ });
741
+
754
742
  /**
755
743
  * An implementation of {@link Notifier} that efficiently keeps track of
756
744
  * subscribers interested in a specific change notification on an
@@ -2031,11 +2019,6 @@ css.partial = (strings, ...values) => {
2031
2019
  const { styles, behaviors } = collectStyles(strings, values);
2032
2020
  return new CSSPartial(styles, behaviors);
2033
2021
  };
2034
- /**
2035
- * @deprecated Use css.partial instead.
2036
- * @public
2037
- */
2038
- const cssPartial = css.partial;
2039
2022
 
2040
2023
  const marker = `fast-${Math.random().toString(36).substring(2, 8)}`;
2041
2024
  const interpolationStart = `${marker}{`;
@@ -3018,6 +3001,37 @@ const Compiler = {
3018
3001
  const lastAttributeNameRegex =
3019
3002
  /* eslint-disable-next-line no-control-regex */
3020
3003
  /([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;
3004
+ const noFactories = Object.create(null);
3005
+ /**
3006
+ * Inlines a template into another template.
3007
+ * @public
3008
+ */
3009
+ class InlineTemplateDirective {
3010
+ /**
3011
+ * Creates an instance of InlineTemplateDirective.
3012
+ * @param template - The template to inline.
3013
+ */
3014
+ constructor(html, factories = noFactories) {
3015
+ this.html = html;
3016
+ this.factories = factories;
3017
+ }
3018
+ /**
3019
+ * Creates HTML to be used within a template.
3020
+ * @param add - Can be used to add behavior factories to a template.
3021
+ */
3022
+ createHTML(add) {
3023
+ const factories = this.factories;
3024
+ for (const key in factories) {
3025
+ add(factories[key]);
3026
+ }
3027
+ return this.html;
3028
+ }
3029
+ }
3030
+ /**
3031
+ * An empty template partial.
3032
+ */
3033
+ InlineTemplateDirective.empty = new InlineTemplateDirective("");
3034
+ HTMLDirective.define(InlineTemplateDirective);
3021
3035
  function createHTML(value, prevString, add, definition = HTMLDirective.getForInstance(value)) {
3022
3036
  if (definition.aspected) {
3023
3037
  const match = lastAttributeNameRegex.exec(prevString);
@@ -3059,6 +3073,12 @@ class ViewTemplate {
3059
3073
  }
3060
3074
  return this.result.createView(hostBindingTarget);
3061
3075
  }
3076
+ /**
3077
+ * Returns a directive that can inline the template.
3078
+ */
3079
+ inline() {
3080
+ return new InlineTemplateDirective(isString(this.html) ? this.html : this.html.innerHTML, this.factories);
3081
+ }
3062
3082
  /**
3063
3083
  * Sets the DOMPolicy for this template.
3064
3084
  * @param policy - The policy to associated with this template.
@@ -3141,12 +3161,15 @@ class ViewTemplate {
3141
3161
  * other template instances, and Directive instances.
3142
3162
  * @public
3143
3163
  */
3144
- function html(strings, ...values) {
3164
+ const html = ((strings, ...values) => {
3145
3165
  if (Array.isArray(strings) && Array.isArray(strings.raw)) {
3146
3166
  return ViewTemplate.create(strings, values);
3147
3167
  }
3148
3168
  throw FAST.error(1206 /* Message.directCallToHTMLTagNotAllowed */);
3149
- }
3169
+ });
3170
+ html.partial = (html) => {
3171
+ return new InlineTemplateDirective(html);
3172
+ };
3150
3173
 
3151
3174
  /**
3152
3175
  * The runtime behavior for template references.
@@ -3642,29 +3665,6 @@ function children(propertyOrOptions) {
3642
3665
  return new ChildrenDirective(propertyOrOptions);
3643
3666
  }
3644
3667
 
3645
- /**
3646
- * A directive capable of injecting static HTML platform runtime protection.
3647
- * @public
3648
- */
3649
- class DangerousHTMLDirective {
3650
- constructor(html) {
3651
- this.html = html;
3652
- }
3653
- createHTML() {
3654
- return this.html;
3655
- }
3656
- }
3657
- HTMLDirective.define(DangerousHTMLDirective);
3658
- /**
3659
- * Injects static HTML without platform protection.
3660
- * @param html - The html to injection.
3661
- * @returns A DangerousHTMLDirective.
3662
- * @public
3663
- */
3664
- function dangerousHTML(html) {
3665
- return new DangerousHTMLDirective(html);
3666
- }
3667
-
3668
3668
  const booleanMode = "boolean";
3669
3669
  const reflectMode = "reflect";
3670
3670
  /**
@@ -3697,6 +3697,20 @@ const booleanConverter = {
3697
3697
  : true;
3698
3698
  },
3699
3699
  };
3700
+ /**
3701
+ * A {@link ValueConverter} that converts to and from `boolean` values. `null`, `undefined`, `""`, and `void` values are converted to `null`.
3702
+ * @public
3703
+ */
3704
+ const nullableBooleanConverter = {
3705
+ toView(value) {
3706
+ return typeof value === "boolean" ? value.toString() : "";
3707
+ },
3708
+ fromView(value) {
3709
+ return [null, undefined, void 0].includes(value)
3710
+ ? null
3711
+ : booleanConverter.fromView(value);
3712
+ },
3713
+ };
3700
3714
  function toNumber(value) {
3701
3715
  if (value === null || value === undefined) {
3702
3716
  return null;
@@ -4527,4 +4541,4 @@ function customElement(nameOrDef) {
4527
4541
 
4528
4542
  DOM.setPolicy(DOMPolicy.create());
4529
4543
 
4530
- export { ArrayObserver, AttributeConfiguration, AttributeDefinition, Binding, CSSDirective, ChildrenDirective, Compiler, DOM, DOMAspect, DangerousHTMLDirective, ElementController, ElementStyles, ExecutionContext, FAST, FASTElement, FASTElementDefinition, HTMLBindingDirective, HTMLDirective, HTMLView, Markup, NodeObservationDirective, Observable, Parser, PropertyChangeNotifier, RefDirective, RepeatBehavior, RepeatDirective, SlottedDirective, SourceLifetime, Splice, SpliceStrategy, SpliceStrategySupport, StatelessAttachedAttributeDirective, SubscriberSet, Updates, ViewTemplate, attr, bind, booleanConverter, children, createMetadataLocator, createTypeRegistry, css, cssDirective, cssPartial, customElement, dangerousHTML, elements, emptyArray, html, htmlDirective, lengthOf, listener, normalizeBinding, nullableNumberConverter, observable, oneTime, ref, repeat, slotted, volatile, when };
4544
+ export { ArrayObserver, AttributeConfiguration, AttributeDefinition, Binding, CSSDirective, ChildrenDirective, Compiler, DOM, DOMAspect, ElementController, ElementStyles, ExecutionContext, FAST, FASTElement, FASTElementDefinition, HTMLBindingDirective, HTMLDirective, HTMLView, InlineTemplateDirective, Markup, NodeObservationDirective, Observable, Parser, PropertyChangeNotifier, RefDirective, RepeatBehavior, RepeatDirective, SlottedDirective, SourceLifetime, Splice, SpliceStrategy, SpliceStrategySupport, StatelessAttachedAttributeDirective, SubscriberSet, Updates, ViewTemplate, attr, bind, booleanConverter, children, createMetadataLocator, createTypeRegistry, css, cssDirective, customElement, elements, emptyArray, html, htmlDirective, lengthOf, listener, normalizeBinding, nullableBooleanConverter, nullableNumberConverter, observable, oneTime, ref, repeat, slotted, volatile, when };