@rijkshuisstijl-community/web-components-stencil 1.0.0-alpha.3 → 1.0.0-alpha.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/dist/cjs/{index-97a16ac9.js → index-6abd9e3a.js} +123 -26
  2. package/dist/cjs/index-6abd9e3a.js.map +1 -0
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/rhc-icon-arrow-right.cjs.entry.js +1 -1
  5. package/dist/cjs/rhc-icon-calendar.cjs.entry.js +1 -1
  6. package/dist/cjs/rhc-icon-error.cjs.entry.js +1 -1
  7. package/dist/cjs/rhc-icon-info_2.cjs.entry.js +1 -1
  8. package/dist/cjs/rhc-icon-info_2.cjs.entry.js.map +1 -1
  9. package/dist/cjs/rhc-icon-success.cjs.entry.js +1 -1
  10. package/dist/cjs/rhc-icon-warning.cjs.entry.js +1 -1
  11. package/dist/cjs/rhc.cjs.js +2 -2
  12. package/dist/cjs/rhc.cjs.js.map +1 -1
  13. package/dist/collection/collection-manifest.json +2 -2
  14. package/dist/collection/logo.css +4 -0
  15. package/dist/components/rhc-logo.js.map +1 -1
  16. package/dist/esm/{index-c2d82fd1.js → index-a0c70ca0.js} +123 -26
  17. package/dist/esm/index-a0c70ca0.js.map +1 -0
  18. package/dist/esm/loader.js +2 -2
  19. package/dist/esm/rhc-icon-arrow-right.entry.js +1 -1
  20. package/dist/esm/rhc-icon-calendar.entry.js +1 -1
  21. package/dist/esm/rhc-icon-error.entry.js +1 -1
  22. package/dist/esm/rhc-icon-info_2.entry.js +1 -1
  23. package/dist/esm/rhc-icon-info_2.entry.js.map +1 -1
  24. package/dist/esm/rhc-icon-success.entry.js +1 -1
  25. package/dist/esm/rhc-icon-warning.entry.js +1 -1
  26. package/dist/esm/rhc.js +3 -3
  27. package/dist/esm/rhc.js.map +1 -1
  28. package/dist/rhc/{p-bab6df1d.entry.js → p-11cacb44.entry.js} +2 -2
  29. package/dist/rhc/{p-569d82ec.entry.js → p-6ff329f1.entry.js} +2 -2
  30. package/dist/rhc/p-74d5e7fb.js +3 -0
  31. package/dist/rhc/p-74d5e7fb.js.map +1 -0
  32. package/dist/rhc/{p-1849850a.entry.js → p-80f1e438.entry.js} +2 -2
  33. package/dist/rhc/p-80f1e438.entry.js.map +1 -0
  34. package/dist/rhc/{p-4378bb06.entry.js → p-c053a5fc.entry.js} +2 -2
  35. package/dist/rhc/{p-3c963064.entry.js → p-d056e80b.entry.js} +2 -2
  36. package/dist/rhc/{p-1ddc5ba6.entry.js → p-e7742379.entry.js} +2 -2
  37. package/dist/rhc/rhc.esm.js +1 -1
  38. package/dist/rhc/rhc.esm.js.map +1 -1
  39. package/dist/types/stencil-public-runtime.d.ts +24 -3
  40. package/package.json +8 -8
  41. package/dist/cjs/index-97a16ac9.js.map +0 -1
  42. package/dist/esm/index-c2d82fd1.js.map +0 -1
  43. package/dist/rhc/p-1849850a.entry.js.map +0 -1
  44. package/dist/rhc/p-1f328841.js +0 -3
  45. package/dist/rhc/p-1f328841.js.map +0 -1
  46. /package/dist/rhc/{p-bab6df1d.entry.js.map → p-11cacb44.entry.js.map} +0 -0
  47. /package/dist/rhc/{p-569d82ec.entry.js.map → p-6ff329f1.entry.js.map} +0 -0
  48. /package/dist/rhc/{p-4378bb06.entry.js.map → p-c053a5fc.entry.js.map} +0 -0
  49. /package/dist/rhc/{p-3c963064.entry.js.map → p-d056e80b.entry.js.map} +0 -0
  50. /package/dist/rhc/{p-1ddc5ba6.entry.js.map → p-e7742379.entry.js.map} +0 -0
@@ -49,6 +49,13 @@ const uniqueTime = (key, measureText) => {
49
49
  }
50
50
  };
51
51
  const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
52
+ /**
53
+ * Constant for styles to be globally applied to `slot-fb` elements for pseudo-slot behavior.
54
+ *
55
+ * Two cascading rules must be used instead of a `:not()` selector due to Stencil browser
56
+ * support as of Stencil v4.
57
+ */
58
+ const SLOT_FB_CSS = 'slot-fb{display:contents}slot-fb[hidden]{display:none}';
52
59
  const XLINK_NS = 'http://www.w3.org/1999/xlink';
53
60
  /**
54
61
  * Default style mode id
@@ -127,6 +134,7 @@ const h = (nodeName, vnodeData, ...children) => {
127
134
  };
128
135
  walk(children);
129
136
  if (vnodeData) {
137
+ // normalize class / className attributes
130
138
  {
131
139
  const classData = vnodeData.className || vnodeData.class;
132
140
  if (classData) {
@@ -268,6 +276,10 @@ const addStyle = (styleContainerNode, cmpMeta, mode) => {
268
276
  }
269
277
  styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
270
278
  }
279
+ // Add styles for `slot-fb` elements if we're using slots outside the Shadow DOM
280
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
281
+ styleElm.innerHTML += SLOT_FB_CSS;
282
+ }
271
283
  if (appliedStyles) {
272
284
  appliedStyles.add(scopeId);
273
285
  }
@@ -975,6 +987,10 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
975
987
  */
976
988
  const callRender = (hostRef, instance, elm, isInitialLoad) => {
977
989
  try {
990
+ /**
991
+ * minification optimization: `allRenderFn` is `true` if all components have a `render`
992
+ * method, so we can call the method immediately. If not, check before calling it.
993
+ */
978
994
  instance = instance.render() ;
979
995
  {
980
996
  hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
@@ -1083,6 +1099,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
1083
1099
  * @returns a reference to the same constructor passed in (but now mutated)
1084
1100
  */
1085
1101
  const proxyComponent = (Cstr, cmpMeta, flags) => {
1102
+ var _a;
1086
1103
  if (cmpMeta.$members$) {
1087
1104
  // It's better to have a const than two Object.entries()
1088
1105
  const members = Object.entries(cmpMeta.$members$);
@@ -1107,7 +1124,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1107
1124
  });
1108
1125
  if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1109
1126
  const attrNameToPropName = new Map();
1110
- prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1127
+ prototype.attributeChangedCallback = function (attrName, oldValue, newValue) {
1111
1128
  plt.jmp(() => {
1112
1129
  const propName = attrNameToPropName.get(attrName);
1113
1130
  // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
@@ -1130,12 +1147,12 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1130
1147
  // customElements.define('my-component', MyComponent);
1131
1148
  // </script>
1132
1149
  // ```
1133
- // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
1150
+ // In this case if we do not un-shadow here and use the value of the shadowing property, attributeChangedCallback
1134
1151
  // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1135
1152
  // to the value that was set inline i.e. "some-value" from above example. When
1136
- // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
1153
+ // the connectedCallback attempts to un-shadow it will use "some-value" as the initial value rather than "another-value"
1137
1154
  //
1138
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
1155
+ // The case where the attribute was NOT set inline but was not set programmatically shall be handled/un-shadowed
1139
1156
  // by connectedCallback as this attributeChangedCallback will not fire.
1140
1157
  //
1141
1158
  // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
@@ -1155,23 +1172,62 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
1155
1172
  // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1156
1173
  return;
1157
1174
  }
1175
+ else if (propName == null) {
1176
+ // At this point we should know this is not a "member", so we can treat it like watching an attribute
1177
+ // on a vanilla web component
1178
+ const hostRef = getHostRef(this);
1179
+ const flags = hostRef === null || hostRef === void 0 ? void 0 : hostRef.$flags$;
1180
+ // We only want to trigger the callback(s) if:
1181
+ // 1. The instance is ready
1182
+ // 2. The watchers are ready
1183
+ // 3. The value has changed
1184
+ if (!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) &&
1185
+ flags & 128 /* HOST_FLAGS.isWatchReady */ &&
1186
+ newValue !== oldValue) {
1187
+ const instance = hostRef.$lazyInstance$ ;
1188
+ const entry = cmpMeta.$watchers$[attrName];
1189
+ entry === null || entry === void 0 ? void 0 : entry.forEach((callbackName) => {
1190
+ if (instance[callbackName] != null) {
1191
+ instance[callbackName].call(instance, newValue, oldValue, attrName);
1192
+ }
1193
+ });
1194
+ }
1195
+ return;
1196
+ }
1158
1197
  this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1159
1198
  });
1160
1199
  };
1161
- // create an array of attributes to observe
1162
- // and also create a map of html attribute name to js property name
1163
- Cstr.observedAttributes = members
1164
- .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
1165
- .map(([propName, m]) => {
1166
- const attrName = m[1] || propName;
1167
- attrNameToPropName.set(attrName, propName);
1168
- return attrName;
1169
- });
1200
+ // Create an array of attributes to observe
1201
+ // This list in comprised of all strings used within a `@Watch()` decorator
1202
+ // on a component as well as any Stencil-specific "members" (`@Prop()`s and `@State()`s).
1203
+ // As such, there is no way to guarantee type-safety here that a user hasn't entered
1204
+ // an invalid attribute.
1205
+ Cstr.observedAttributes = Array.from(new Set([
1206
+ ...Object.keys((_a = cmpMeta.$watchers$) !== null && _a !== void 0 ? _a : {}),
1207
+ ...members
1208
+ .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */)
1209
+ .map(([propName, m]) => {
1210
+ const attrName = m[1] || propName;
1211
+ attrNameToPropName.set(attrName, propName);
1212
+ return attrName;
1213
+ }),
1214
+ ]));
1170
1215
  }
1171
1216
  }
1172
1217
  return Cstr;
1173
1218
  };
1174
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1219
+ /**
1220
+ * Initialize a Stencil component given a reference to its host element, its
1221
+ * runtime bookkeeping data structure, runtime metadata about the component,
1222
+ * and (optionally) an HMR version ID.
1223
+ *
1224
+ * @param elm a host element
1225
+ * @param hostRef the element's runtime bookkeeping object
1226
+ * @param cmpMeta runtime metadata for the Stencil component
1227
+ * @param hmrVersionId an (optional) HMR version ID
1228
+ */
1229
+ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId) => {
1230
+ let Cstr;
1175
1231
  // initializeComponent
1176
1232
  if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1177
1233
  // Let the runtime know that the component has been initialized
@@ -1309,12 +1365,13 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1309
1365
  const customElements = win.customElements;
1310
1366
  const head = doc.head;
1311
1367
  const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1312
- const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1368
+ const dataStyles = /*@__PURE__*/ doc.createElement('style');
1313
1369
  const deferredConnectedCallbacks = [];
1314
1370
  let appLoadFallback;
1315
1371
  let isBootstrapping = true;
1316
1372
  Object.assign(plt, options);
1317
1373
  plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1374
+ let hasSlotRelocation = false;
1318
1375
  lazyBundles.map((lazyBundle) => {
1319
1376
  lazyBundle[1].map((compactMeta) => {
1320
1377
  const cmpMeta = {
@@ -1323,6 +1380,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1323
1380
  $members$: compactMeta[2],
1324
1381
  $listeners$: compactMeta[3],
1325
1382
  };
1383
+ // Check if we are using slots outside the shadow DOM in this component.
1384
+ // We'll use this information later to add styles for `slot-fb` elements
1385
+ if (cmpMeta.$flags$ & 4 /* CMP_FLAGS.hasSlotRelocation */) {
1386
+ hasSlotRelocation = true;
1387
+ }
1326
1388
  {
1327
1389
  cmpMeta.$members$ = compactMeta[2];
1328
1390
  }
@@ -1373,15 +1435,23 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1373
1435
  }
1374
1436
  });
1375
1437
  });
1438
+ // Add styles for `slot-fb` elements if any of our components are using slots outside the Shadow DOM
1439
+ if (hasSlotRelocation) {
1440
+ dataStyles.innerHTML += SLOT_FB_CSS;
1441
+ }
1442
+ // Add hydration styles
1376
1443
  {
1377
- visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1378
- visibilityStyle.setAttribute('data-styles', '');
1444
+ dataStyles.innerHTML += cmpTags + HYDRATED_CSS;
1445
+ }
1446
+ // If we have styles, add them to the DOM
1447
+ if (dataStyles.innerHTML.length) {
1448
+ dataStyles.setAttribute('data-styles', '');
1449
+ head.insertBefore(dataStyles, metaCharset ? metaCharset.nextSibling : head.firstChild);
1379
1450
  // Apply CSP nonce to the style tag if it exists
1380
1451
  const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
1381
1452
  if (nonce != null) {
1382
- visibilityStyle.setAttribute('nonce', nonce);
1453
+ dataStyles.setAttribute('nonce', nonce);
1383
1454
  }
1384
- head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1385
1455
  }
1386
1456
  // Process deferred connectedCallbacks now all components have been registered
1387
1457
  isBootstrapping = false;
@@ -1403,22 +1473,49 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1403
1473
  * @returns void
1404
1474
  */
1405
1475
  const setNonce = (nonce) => (plt.$nonce$ = nonce);
1476
+ /**
1477
+ * A WeakMap mapping runtime component references to their corresponding host reference
1478
+ * instances.
1479
+ */
1406
1480
  const hostRefs = /*@__PURE__*/ new WeakMap();
1481
+ /**
1482
+ * Given a {@link d.RuntimeRef} retrieve the corresponding {@link d.HostRef}
1483
+ *
1484
+ * @param ref the runtime ref of interest
1485
+ * @returns the Host reference (if found) or undefined
1486
+ */
1407
1487
  const getHostRef = (ref) => hostRefs.get(ref);
1488
+ /**
1489
+ * Register a lazy instance with the {@link hostRefs} object so it's
1490
+ * corresponding {@link d.HostRef} can be retrieved later.
1491
+ *
1492
+ * @param lazyInstance the lazy instance of interest
1493
+ * @param hostRef that instances `HostRef` object
1494
+ * @returns a reference to the host ref WeakMap
1495
+ */
1408
1496
  const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1409
- const registerHost = (elm, cmpMeta) => {
1497
+ /**
1498
+ * Register a host element for a Stencil component, setting up various metadata
1499
+ * and callbacks based on {@link BUILD} flags as well as the component's runtime
1500
+ * metadata.
1501
+ *
1502
+ * @param hostElement the host element to register
1503
+ * @param cmpMeta runtime metadata for that component
1504
+ * @returns a reference to the host ref WeakMap
1505
+ */
1506
+ const registerHost = (hostElement, cmpMeta) => {
1410
1507
  const hostRef = {
1411
1508
  $flags$: 0,
1412
- $hostElement$: elm,
1509
+ $hostElement$: hostElement,
1413
1510
  $cmpMeta$: cmpMeta,
1414
1511
  $instanceValues$: new Map(),
1415
1512
  };
1416
1513
  {
1417
1514
  hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1418
- elm['s-p'] = [];
1419
- elm['s-rc'] = [];
1515
+ hostElement['s-p'] = [];
1516
+ hostElement['s-rc'] = [];
1420
1517
  }
1421
- return hostRefs.set(elm, hostRef);
1518
+ return hostRefs.set(hostElement, hostRef);
1422
1519
  };
1423
1520
  const isMemberInElement = (elm, memberName) => memberName in elm;
1424
1521
  const consoleError = (e, el) => (0, console.error)(e, el);
@@ -1539,7 +1636,7 @@ const flush = () => {
1539
1636
  }
1540
1637
  }
1541
1638
  };
1542
- const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1639
+ const nextTick = (cb) => promiseResolve().then(cb);
1543
1640
  const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1544
1641
 
1545
1642
  exports.bootstrapLazy = bootstrapLazy;
@@ -1548,4 +1645,4 @@ exports.promiseResolve = promiseResolve;
1548
1645
  exports.registerInstance = registerInstance;
1549
1646
  exports.setNonce = setNonce;
1550
1647
 
1551
- //# sourceMappingURL=index-97a16ac9.js.map
1648
+ //# sourceMappingURL=index-6abd9e3a.js.map