@infineon/design-system-angular 42.3.2 → 42.3.3--canary.2608.42982946104.1.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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { HostListener, Directive, forwardRef, ElementRef, ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core';
2
+ import { HostListener, Directive, forwardRef, ElementRef, inject, PLATFORM_ID, ChangeDetectionStrategy, Component, EventEmitter, Output } from '@angular/core';
3
3
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
4
  import { __decorate } from 'tslib';
5
5
  import { fromEvent } from 'rxjs';
@@ -376,7 +376,48 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.35", ngImpo
376
376
 
377
377
  /* eslint-disable */
378
378
  /* tslint:disable */
379
- const proxyInputs = (Cmp, inputs) => {
379
+ const serverInstances = new WeakSet();
380
+ /**
381
+ * Records a wrapper created during server rendering. Call from the constructor.
382
+ */
383
+ const markServer = (instance) => {
384
+ // what `isPlatformServer()` from `@angular/common` checks
385
+ if (inject(PLATFORM_ID) === 'server') {
386
+ serverInstances.add(instance);
387
+ }
388
+ };
389
+ /**
390
+ * Stencil's own prop name to attribute name conversion (`prop1` -> `prop-1`).
391
+ */
392
+ const toDashCase = (str) => str
393
+ .replace(/([A-Z0-9])/g, (match) => ` ${match[0]}`)
394
+ .trim()
395
+ .split(' ')
396
+ .join('-')
397
+ .toLowerCase();
398
+ /**
399
+ * Angular's server DOM never writes properties to the HTML, so on the server an input becomes an
400
+ * attribute, which Stencil's `renderToString()` reads:
401
+ * - a string or number as itself, and `true` as an empty attribute, so the component's first
402
+ * render in the browser sees them too;
403
+ * - `false`, anything that isn't a primitive, and any value for a prop with no attribute through
404
+ * `ssrProp()`, which gives the server render the exact value and leaves no attribute behind.
405
+ */
406
+ const setServerAttribute = (el, item, val, ssr) => {
407
+ const name = ssr.attributes?.[item] ?? toDashCase(item);
408
+ if (val == null) {
409
+ el.removeAttribute(name);
410
+ }
411
+ else if (ssr.refs?.includes(item) ||
412
+ val === false ||
413
+ (typeof val !== 'string' && typeof val !== 'number' && val !== true)) {
414
+ el.setAttribute(name, ssr.ssrProp(val));
415
+ }
416
+ else {
417
+ el.setAttribute(name, val === true ? '' : String(val));
418
+ }
419
+ };
420
+ const proxyInputs = (Cmp, inputs, ssr) => {
380
421
  const Prototype = Cmp.prototype;
381
422
  inputs.forEach((item) => {
382
423
  Object.defineProperty(Prototype, item, {
@@ -384,6 +425,12 @@ const proxyInputs = (Cmp, inputs) => {
384
425
  return this.el[item];
385
426
  },
386
427
  set(val) {
428
+ if (ssr && serverInstances.has(this)) {
429
+ // kept on the element too, so reading the input back on the server works
430
+ this.el[item] = val;
431
+ setServerAttribute(this.el, item, val, ssr);
432
+ return;
433
+ }
387
434
  this.z.runOutsideAngular(() => (this.el[item] = val));
388
435
  },
389
436
  /**
@@ -417,12 +464,12 @@ const defineCustomElement = (tagName, customElement) => {
417
464
  // tslint:disable-next-line: only-arrow-functions
418
465
  function ProxyCmp(opts) {
419
466
  const decorator = function (cls) {
420
- const { defineCustomElementFn, inputs, methods } = opts;
467
+ const { defineCustomElementFn, inputs, methods, ssr } = opts;
421
468
  if (defineCustomElementFn !== undefined) {
422
469
  defineCustomElementFn();
423
470
  }
424
471
  if (inputs) {
425
- proxyInputs(cls, inputs);
472
+ proxyInputs(cls, inputs, ssr);
426
473
  }
427
474
  if (methods) {
428
475
  proxyMethods(cls, methods);