@proximus/lavender 1.0.0-alpha.10 → 1.0.0-alpha.12

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.
@@ -174,6 +174,11 @@ class WithFlexAttributes extends HTMLElement {
174
174
  }
175
175
  }
176
176
  class PxElement extends WithFlexAttributes {
177
+ constructor(semanticTokensStylesheet, ...adoptedStylesheets) {
178
+ super(semanticTokensStylesheet, ...adoptedStylesheets);
179
+ this.replayAttributes = false;
180
+ this.nativeName = Object.getPrototypeOf(this).constructor.nativeName;
181
+ }
177
182
  static get observedAttributes() {
178
183
  return [
179
184
  ...super.observedAttributes,
@@ -181,6 +186,12 @@ class PxElement extends WithFlexAttributes {
181
186
  ];
182
187
  }
183
188
  attributeChangedCallback(name, oldValue, newValue) {
189
+ if (!this.shadowRoot) {
190
+ console.warn(
191
+ "shadowRoot not available yet, replaying attributes once connected"
192
+ );
193
+ this.replayAttributes = true;
194
+ }
184
195
  super.attributeChangedCallback(name, oldValue, newValue);
185
196
  if (newValue === null) {
186
197
  this.$el.toggleAttribute(name);
@@ -188,14 +199,18 @@ class PxElement extends WithFlexAttributes {
188
199
  this.$el.setAttribute(name, newValue);
189
200
  }
190
201
  }
191
- constructor(semanticTokensStylesheet, ...adoptedStylesheets) {
192
- super(semanticTokensStylesheet, ...adoptedStylesheets);
193
- this.nativeName = Object.getPrototypeOf(this).constructor.nativeName;
194
- }
195
202
  connectedCallback() {
196
- replayAttributes(this, PxElement.observedAttributes, (name, value) => {
197
- this.attributeChangedCallback(name, null, value);
198
- });
203
+ if (this.replayAttributes) {
204
+ replayAttributes(
205
+ this,
206
+ Object.getPrototypeOf(this).constructor.observedAttributes,
207
+ (name, value) => {
208
+ if (this.getAttribute(name) !== null) {
209
+ this.attributeChangedCallback(name, null, value);
210
+ }
211
+ }
212
+ );
213
+ }
199
214
  for (const name of getSupportedAttributeNames(this.nativeName)) {
200
215
  if (name === "constructor") {
201
216
  continue;
@@ -1358,6 +1373,7 @@ const _Container = class _Container extends PxElement {
1358
1373
  }
1359
1374
  connectedCallback() {
1360
1375
  var _a, _b;
1376
+ super.connectedCallback();
1361
1377
  const anchorSlot = this.querySelector("[slot]");
1362
1378
  if (anchorSlot) {
1363
1379
  if (anchorValues.includes(anchorSlot.getAttribute("slot"))) {
@@ -1394,10 +1410,20 @@ const _Container = class _Container extends PxElement {
1394
1410
  this.updateAttribute(attrName, oldValue, newValue, borderValues);
1395
1411
  break;
1396
1412
  case "borderradius":
1397
- this.updateAttribute(attrName, oldValue, newValue, borderRadiusValues);
1413
+ this.updateAttribute(
1414
+ attrName,
1415
+ oldValue,
1416
+ newValue,
1417
+ borderRadiusValues
1418
+ );
1398
1419
  break;
1399
1420
  case "noborderradius":
1400
- this.updateAttribute(attrName, oldValue, newValue, noBorderRadiusValues);
1421
+ this.updateAttribute(
1422
+ attrName,
1423
+ oldValue,
1424
+ newValue,
1425
+ noBorderRadiusValues
1426
+ );
1401
1427
  break;
1402
1428
  case "bgcolor":
1403
1429
  this.updateAttribute(attrName, oldValue, newValue, bgColorValues);
@@ -1443,7 +1469,9 @@ const _Container = class _Container extends PxElement {
1443
1469
  if (this.checkName(gradientValues, newValue)) {
1444
1470
  this.$el.style.background = `linear-gradient(var(--px-color-bg-gradient-${newValue}))`;
1445
1471
  } else {
1446
- console.error(`${newValue} is not an allowed gradient value for ${this.$el}`);
1472
+ console.error(
1473
+ `${newValue} is not an allowed gradient value for ${this.$el}`
1474
+ );
1447
1475
  }
1448
1476
  }
1449
1477
  updateAttribute(attrName, oldValue, newValue, attrValues) {
@@ -1454,7 +1482,9 @@ const _Container = class _Container extends PxElement {
1454
1482
  this.$el.classList.toggle(`${attrName}-${newValue}`);
1455
1483
  }
1456
1484
  if (!this.checkName(attrValues, newValue)) {
1457
- console.error(`${newValue} is not an allowed ${attrName} value for ${this.$el}`);
1485
+ console.error(
1486
+ `${newValue} is not an allowed ${attrName} value for ${this.$el}`
1487
+ );
1458
1488
  }
1459
1489
  }
1460
1490
  checkName(values, value) {