@sitecore-feaas/clientside 0.0.9 → 0.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.
Files changed (57) hide show
  1. package/README.md +5 -5
  2. package/dist/browser/basic.cjs +67 -0
  3. package/dist/browser/basic.js +67 -0
  4. package/dist/browser/index.cjs +68 -79
  5. package/dist/browser/index.js +68 -79
  6. package/dist/node/{react.cjs → basic.cjs} +436 -443
  7. package/dist/node/{react.js → basic.js} +432 -439
  8. package/dist/node/index.cjs +666 -291
  9. package/dist/node/index.js +666 -295
  10. package/examples/index.html +1 -1
  11. package/package.json +17 -17
  12. package/src/basic.ts +5 -0
  13. package/src/cloud.ts +9 -5
  14. package/src/components/FEAASBase.tsx +265 -0
  15. package/src/components/FEAASComponent.ts +98 -0
  16. package/src/components/FEAASContext.tsx +105 -0
  17. package/src/components/FEAASEditor.tsx +291 -0
  18. package/src/components/FEAASLoader.ts +113 -0
  19. package/src/components/FEAASPicker.tsx +98 -0
  20. package/src/components/FEAASStylesheet.ts +43 -0
  21. package/src/components/index.tsx +7 -0
  22. package/src/index.ts +4 -11
  23. package/test/components.js +11 -0
  24. package/test/components.ts +12 -0
  25. package/test/render.js +688 -0
  26. package/tsconfig.json +11 -6
  27. package/types/basic.d.ts +5 -0
  28. package/types/cloud.d.ts +18 -0
  29. package/types/components/FEAASBase.d.ts +70 -0
  30. package/types/components/FEAASComponent.d.ts +39 -0
  31. package/types/components/FEAASContext.d.ts +43 -0
  32. package/types/components/FEAASEditor.d.ts +70 -0
  33. package/types/components/FEAASLoader.d.ts +20 -0
  34. package/types/components/FEAASPicker.d.ts +61 -0
  35. package/types/components/FEAASStylesheet.d.ts +25 -0
  36. package/types/components/index.d.ts +7 -0
  37. package/types/dom.d.ts +29 -0
  38. package/types/fetch.d.ts +1 -0
  39. package/types/index.d.ts +4 -0
  40. package/types/tsbuildinfo +1 -0
  41. package/dist/browser/index.d.ts +0 -25
  42. package/dist/browser/react.cjs +0 -83
  43. package/dist/browser/react.d.ts +0 -36
  44. package/dist/browser/react.js +0 -83
  45. package/dist/browser/webcomponent-6b45b819.d.ts +0 -120
  46. package/dist/node/index.d.ts +0 -25
  47. package/dist/node/react.d.ts +0 -36
  48. package/dist/node/webcomponent-6b45b819.d.ts +0 -120
  49. package/index.cjs +0 -83
  50. package/index.d.ts +0 -25
  51. package/index.js +0 -83
  52. package/react.cjs +0 -83
  53. package/react.d.ts +0 -36
  54. package/react.js +0 -83
  55. package/src/react.ts +0 -66
  56. package/src/webcomponent.ts +0 -393
  57. package/webcomponent-6b45b819.d.ts +0 -120
@@ -17,10 +17,6 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __export = (target, all) => {
21
- for (var name in all)
22
- __defProp(target, name, { get: all[name], enumerable: true });
23
- };
24
20
  var __async = (__this, __arguments, generator) => {
25
21
  return new Promise((resolve, reject) => {
26
22
  var fulfilled = (value) => {
@@ -42,108 +38,6 @@ var __async = (__this, __arguments, generator) => {
42
38
  });
43
39
  };
44
40
 
45
- // src/react.ts
46
- import React from "react";
47
-
48
- // src/fetch.ts
49
- function fetchAndRevalidate(url, options, validator, callback) {
50
- return __async(this, null, function* () {
51
- const date = new Date();
52
- const initialResponse = yield fetch(url, options);
53
- if (!initialResponse.ok)
54
- throw new Error("Fetch failed");
55
- const responseDate = new Date(initialResponse.headers.get("date"));
56
- var response = initialResponse;
57
- callback(initialResponse, "cached");
58
- if (responseDate < date) {
59
- const freshHeadResponse = yield fetch(url + "?" + Math.random(), __spreadProps(__spreadValues({}, options), {
60
- method: "HEAD",
61
- cache: "no-cache"
62
- }));
63
- if (freshHeadResponse.headers.get("last-modified") != initialResponse.headers.get("last-modified")) {
64
- if (validator(freshHeadResponse) === false) {
65
- throw new Error("Response is stale");
66
- }
67
- response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
68
- cache: "reload"
69
- }));
70
- }
71
- }
72
- if (validator(response) === false) {
73
- throw new Error("Response is not valid");
74
- }
75
- if (initialResponse !== response) {
76
- callback(response, "valid");
77
- }
78
- return response;
79
- });
80
- }
81
-
82
- // src/cloud.ts
83
- function getComponentURL({
84
- hostname = "https://feaascomponentsapidev.blob.core.windows.net",
85
- library,
86
- component,
87
- version,
88
- revision = "published"
89
- }) {
90
- return `${hostname}/components/${library}/${component}/${version}/${revision}.html`;
91
- }
92
- function getStylesheetURL({
93
- hostname = `https://feaascomponentsapidev.blob.core.windows.net`,
94
- library,
95
- revision = "published"
96
- }) {
97
- return `${hostname}/styles/${library}/${revision}.css`;
98
- }
99
- function fetchComponent(props, callback) {
100
- return __async(this, null, function* () {
101
- return fetchAndRevalidate(
102
- getComponentURL(props),
103
- {},
104
- (response) => {
105
- return response.headers.get("x-ms-meta-versionDeletedAt") == null;
106
- },
107
- (response) => {
108
- response.text().then(callback);
109
- }
110
- );
111
- });
112
- }
113
- function fetchStylesheet(props, callback) {
114
- return __async(this, null, function* () {
115
- return fetchAndRevalidate(
116
- getStylesheetURL(props),
117
- {},
118
- (response) => {
119
- return response.headers.get("x-ms-meta-deletedAt") == null;
120
- },
121
- (response) => {
122
- response.text().then(callback);
123
- }
124
- );
125
- });
126
- }
127
-
128
- // src/dom.ts
129
- var dom_exports = {};
130
- __export(dom_exports, {
131
- autoloadScripts: () => autoloadScripts,
132
- cleanCollectionBit: () => cleanCollectionBit,
133
- loadScript: () => loadScript,
134
- normalizeCollectionScope: () => normalizeCollectionScope,
135
- observeDOMElement: () => observeDOMElement,
136
- queryScopes: () => queryScopes,
137
- renderComponent: () => renderComponent,
138
- renderComponentElement: () => renderComponentElement,
139
- renderComponentPromise: () => renderComponentPromise,
140
- renderDOMContent: () => renderDOMContent,
141
- renderDOMElement: () => renderDOMElement,
142
- renderStylesheet: () => renderStylesheet,
143
- renderStylesheetPromise: () => renderStylesheetPromise,
144
- setDOMAttribute: () => setDOMAttribute
145
- });
146
-
147
41
  // ../node_modules/jsonpath-plus/dist/index-browser-esm.js
148
42
  function _typeof(obj) {
149
43
  "@babel/helpers - typeof";
@@ -843,6 +737,88 @@ JSONPath.prototype.vm = {
843
737
  }
844
738
  };
845
739
 
740
+ // src/fetch.ts
741
+ function fetchAndRevalidate(url, options, validator, callback) {
742
+ return __async(this, null, function* () {
743
+ const date = new Date();
744
+ const initialResponse = yield fetch(url, options);
745
+ if (!initialResponse.ok)
746
+ throw new Error("Fetch failed");
747
+ const responseDate = new Date(initialResponse.headers.get("date"));
748
+ var response = initialResponse;
749
+ callback(initialResponse, "cached");
750
+ if (responseDate < date) {
751
+ const freshHeadResponse = yield fetch(url + "?" + Math.random(), __spreadProps(__spreadValues({}, options), {
752
+ method: "HEAD",
753
+ cache: "no-cache"
754
+ }));
755
+ if (freshHeadResponse.headers.get("last-modified") != initialResponse.headers.get("last-modified")) {
756
+ if (validator(freshHeadResponse) === false) {
757
+ throw new Error("Response is stale");
758
+ }
759
+ response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
760
+ cache: "reload"
761
+ }));
762
+ }
763
+ }
764
+ if (validator(response) === false) {
765
+ throw new Error("Response is not valid");
766
+ }
767
+ if (initialResponse !== response) {
768
+ callback(response, "valid");
769
+ }
770
+ return response;
771
+ });
772
+ }
773
+
774
+ // src/cloud.ts
775
+ function getComponentURL({
776
+ cdn = "https://feaascomponentsapidev.blob.core.windows.net",
777
+ hostname,
778
+ library,
779
+ component,
780
+ version,
781
+ revision = "published"
782
+ }) {
783
+ return `${cdn || hostname}/components/${library}/${component}/${version}/${revision}.html`;
784
+ }
785
+ function getStylesheetURL({
786
+ cdn = `https://feaascomponentsapidev.blob.core.windows.net`,
787
+ hostname,
788
+ library,
789
+ revision = "published"
790
+ }) {
791
+ return `${cdn || hostname}/styles/${library}/${revision}.css`;
792
+ }
793
+ function fetchComponent(props, callback) {
794
+ return __async(this, null, function* () {
795
+ return fetchAndRevalidate(
796
+ getComponentURL(props),
797
+ {},
798
+ (response) => {
799
+ return response.headers.get("x-ms-meta-versionDeletedAt") == null;
800
+ },
801
+ (response) => {
802
+ response.text().then(callback);
803
+ }
804
+ );
805
+ });
806
+ }
807
+ function fetchStylesheet(props, callback) {
808
+ return __async(this, null, function* () {
809
+ return fetchAndRevalidate(
810
+ getStylesheetURL(props),
811
+ {},
812
+ (response) => {
813
+ return response.headers.get("x-ms-meta-deletedAt") == null;
814
+ },
815
+ (response) => {
816
+ response.text().then(callback);
817
+ }
818
+ );
819
+ });
820
+ }
821
+
846
822
  // src/dom.ts
847
823
  function renderComponentElement(content, datasources) {
848
824
  const wrapper = document.createElement("div");
@@ -1122,393 +1098,410 @@ function renderComponentPromise(props, root) {
1122
1098
  });
1123
1099
  }
1124
1100
 
1125
- // src/webcomponent.ts
1126
- var webcomponent_exports = {};
1127
- __export(webcomponent_exports, {
1128
- HTMLFeaasComponent: () => HTMLFeaasComponent,
1129
- HTMLFeaasStylesheet: () => HTMLFeaasStylesheet
1130
- });
1131
- var WebComponent = typeof HTMLElement == "undefined" ? class {
1132
- } : HTMLElement;
1133
- var HTMLFeaasComponent = class extends WebComponent {
1101
+ // src/components/FEAASBase.tsx
1102
+ var FEAASBase = class extends HTMLElement {
1134
1103
  constructor() {
1135
1104
  super(...arguments);
1136
- this.connected = false;
1137
- this.template = null;
1138
- this.data = void 0;
1139
- this.isFetching = false;
1140
- }
1141
- static get observedAttributes() {
1142
- return ["data", "library", "component", "version", "revision", "hostname", "template"];
1105
+ this.connected = null;
1106
+ this.refs = {};
1107
+ this.descendants = [];
1108
+ this.onLoad = (payload) => {
1109
+ if (payload == null)
1110
+ return;
1111
+ this.payload = payload;
1112
+ this.render();
1113
+ };
1143
1114
  }
1144
- connectedCallback() {
1145
- this.connected = true;
1146
- this.render();
1115
+ getProps(context) {
1116
+ return {};
1147
1117
  }
1148
- disconnectedCallback() {
1118
+ getRoot() {
1119
+ return this;
1149
1120
  }
1150
1121
  attributeChangedCallback(name, oldValue, newValue) {
1151
- if (!this.connected)
1152
- return;
1153
- if (name == "template") {
1154
- this.template = newValue;
1155
- } else if (name != "date") {
1156
- this.template = null;
1157
- }
1158
- if (name == "data" && this.children.length > 0) {
1159
- this.update();
1160
- } else {
1161
- cancelAnimationFrame(this.rendering);
1162
- this.rendering = requestAnimationFrame(() => {
1163
- this.render();
1164
- });
1165
- }
1122
+ this.set();
1166
1123
  }
1167
- update() {
1168
- renderDOMElement(this, this.getProps().data);
1169
- }
1170
- setData(data) {
1171
- this.data = data;
1172
- if (this.children.length > 0) {
1173
- this.update();
1174
- } else {
1175
- this.render();
1176
- }
1124
+ connectedCallback() {
1125
+ console.log("FEAAS: Connected", this);
1126
+ this.connected = new Event("feaasConnected", { bubbles: true, composed: true });
1127
+ this.dispatchEvent(this.connected);
1128
+ this.addEventListener("feaasConnected", this);
1129
+ this.addEventListener("feaasDisconnected", this);
1130
+ this.set();
1177
1131
  }
1178
- getOriginal() {
1179
- const scope = this.getAttribute("data-path-scope");
1180
- if (!scope)
1181
- return;
1182
- for (var current = this; current = current.previousElementSibling; ) {
1183
- if (current.getAttribute("data-path-scope") == scope) {
1184
- var last = current;
1185
- } else {
1132
+ disconnectedCallback() {
1133
+ console.log("FEAAS: Disconnected", this);
1134
+ this.removeEventListener("feaasConnected", this);
1135
+ this.removeEventListener("feaasDisconnected", this);
1136
+ this.dispatchEvent(new Event("feaasDisconnected", { bubbles: true, composed: true }));
1137
+ this.connected = null;
1138
+ }
1139
+ handleEvent(event) {
1140
+ switch (event.type) {
1141
+ case "feaasConnected":
1142
+ this.adoptedCallback(event);
1143
+ break;
1144
+ case "feaasDisconnected":
1145
+ this.orphanCallback(event);
1186
1146
  break;
1187
- }
1188
- }
1189
- return last;
1190
- }
1191
- getData() {
1192
- var _a;
1193
- if (this.data) {
1194
- return this.data;
1195
- }
1196
- if (this.getAttribute("data")) {
1197
- const dataValue = this.getAttribute("data");
1198
- return typeof dataValue == "string" ? JSON.parse(dataValue) : {};
1199
1147
  }
1200
- return ((_a = this.getOriginal()) == null ? void 0 : _a.getData()) || {};
1201
- return {};
1202
1148
  }
1203
- render() {
1204
- if (this.getOriginal()) {
1149
+ orphanCallback(event) {
1150
+ const target = event.composedPath()[0];
1151
+ const index = this.descendants.indexOf(target);
1152
+ if (index == -1)
1205
1153
  return;
1154
+ console.log("FEAAS: Orphaning", this, target);
1155
+ this.descendants.splice(index, -1);
1156
+ this.refs[target.getComponentName()] = null;
1157
+ if (target.refs.parent == this)
1158
+ target.refs.parent = null;
1159
+ if (target.refs.top == this) {
1160
+ target.refs.top = target.refs.parent;
1206
1161
  }
1207
- const newProps = this.getProps();
1208
- if (this.template == null) {
1209
- if (!this.isFetching) {
1210
- if (newProps.component != null && newProps.version != null) {
1211
- this.isFetching = true;
1212
- fetchComponent(newProps, (template) => {
1213
- this.template = template;
1214
- this.isFetching = false;
1215
- renderDOMContent(this, this.template, newProps.data);
1216
- }).catch(() => {
1217
- console.error(
1218
- `FEAAS: Could not fetch component: ${newProps.component}/${newProps.version}/${newProps.revision}`
1219
- );
1220
- });
1162
+ }
1163
+ adoptedCallback(event) {
1164
+ var _a, _b;
1165
+ const target = event.composedPath()[0];
1166
+ this.descendants.push(target);
1167
+ console.log("FEAAS: Adopting", this, target);
1168
+ this.refs[target.getComponentName()] = target;
1169
+ target.refs.top = this;
1170
+ (_a = target.refs).parent || (_a.parent = this);
1171
+ if (target.renderReact) {
1172
+ for (var p = target.refs.parent; p; p = p.refs.parent) {
1173
+ if (p.renderReact) {
1174
+ (_b = target.refs).parentReact || (_b.parentReact = p);
1175
+ target.refs.topReact = p;
1221
1176
  }
1222
1177
  }
1223
- } else {
1224
- renderDOMContent(this, this.template, newProps.data);
1225
1178
  }
1226
1179
  }
1227
- getProps() {
1228
- return {
1229
- data: this.getData(),
1230
- library: this.getAttribute("library") || void 0,
1231
- component: this.getAttribute("component") || void 0,
1232
- version: this.getAttribute("version") || void 0,
1233
- revision: this.getAttribute("revision") || void 0,
1234
- hostname: patchHostname(this.getAttribute("hostname") || void 0)
1235
- };
1236
- }
1237
- };
1238
- var HTMLFeaasStylesheet = class extends WebComponent {
1239
- constructor() {
1240
- super(...arguments);
1241
- this.connected = false;
1242
- }
1243
- static get observedAttributes() {
1244
- return ["library", "revision", "hostname"];
1180
+ getComponentName() {
1181
+ return this.tagName.replace("FEAAS-", "").toLowerCase();
1245
1182
  }
1246
- connectedCallback() {
1247
- this.connected = true;
1248
- this.render();
1183
+ isReadyToLoad() {
1184
+ return this.payload === void 0 && this.getAttribute("hidden") == null;
1249
1185
  }
1250
- attributeChangedCallback() {
1251
- if (this.connected)
1252
- this.render();
1253
- }
1254
- render() {
1255
- const props = this.getProps();
1256
- fetchStylesheet(props, (cssText) => {
1257
- this.innerHTML = "<style>" + cssText + "</style>";
1258
- }).catch((e) => {
1259
- console.error(`FEAAS: Could not fetch stylesheet for library ${props.library}`);
1186
+ reify() {
1187
+ return __async(this, null, function* () {
1188
+ if (this.payload !== void 0) {
1189
+ this.render();
1190
+ } else if (this.isReadyToLoad()) {
1191
+ this.payload = null;
1192
+ this.load().then(this.onLoad);
1193
+ }
1260
1194
  });
1261
1195
  }
1262
- getProps() {
1263
- return {
1264
- library: this.getAttribute("library") || void 0,
1265
- revision: this.getAttribute("revision") || void 0,
1266
- hostname: patchHostname(this.getAttribute("hostname") || void 0)
1267
- };
1196
+ load() {
1197
+ return Promise.resolve(null);
1268
1198
  }
1269
- };
1270
- function patchHostname(url) {
1271
- if (typeof url == "string" && (location.hostname.includes("pages-staging") || location.hostname.includes("staging-staging"))) {
1272
- return url.replace("components.sitecorecloud.io", "components-staging.sitecore-staging.cloud").replace("feaascompontsapiprod", "feaascomponentsstaging");
1273
- } else {
1274
- return url;
1199
+ render(nested = false) {
1200
+ var _a, _b, _c;
1201
+ console.log("FEAAS: React", this.tagName, this.payload);
1202
+ if (this.payload == null)
1203
+ return;
1204
+ const { React, ReactDOM } = this.payload || {};
1205
+ if (!React)
1206
+ throw new Error(`${this.tagName}: React is not present in payload`);
1207
+ if (!ReactDOM)
1208
+ throw new Error(`${this.tagName}: ReactDOM is not present in payload`);
1209
+ if (!this.refs.topReact && !this.forceUpdateReact) {
1210
+ ReactDOM.render(React.createElement(this.getReactWrapper()), this.getReactRoot());
1211
+ } else if (this.forceUpdateReact) {
1212
+ (_a = this.forceUpdateReact) == null ? void 0 : _a.call(this);
1213
+ } else {
1214
+ (_c = (_b = this.refs.topReact).forceUpdateReact) == null ? void 0 : _c.call(_b);
1215
+ }
1275
1216
  }
1276
- }
1277
- var HTMLFeaasPickerLazy = class extends WebComponent {
1278
- constructor() {
1279
- super(...arguments);
1280
- this.src = "https://components.sitecorecloud.io/assets/picker.js";
1281
- this.onClose = () => {
1282
- this.set({
1283
- mode: null
1217
+ invokeReactRendering() {
1218
+ const { React, ReactDOM } = this.payload || {};
1219
+ const children = this.descendants.filter((r) => {
1220
+ return r.refs.parentReact == this && r.payload;
1221
+ }).map((child, index) => {
1222
+ return React.createElement(this.getReactWrapper(child), {
1223
+ key: this.tagName + "-" + index,
1224
+ slot: child.getAttribute("slot")
1284
1225
  });
1285
- };
1286
- this.onScriptLoaded = () => {
1287
- this.element = document.createElement("feaas-picker");
1288
- this.element.style.cssText = "border: 0; width: 100%; height: 100%; display: block";
1289
- this.appendChild(this.element);
1290
- this.set(this.getProps());
1291
- };
1292
- }
1293
- static get observedAttributes() {
1294
- return ["library", "mode", "hidden", "src"];
1226
+ });
1227
+ return this.renderReact(__spreadProps(__spreadValues({}, this.props), { children }), this.payload);
1228
+ }
1229
+ getReactWrapper(target = this, displayName = target.tagName) {
1230
+ const Wrapper = target.reactWrapper || (target.reactWrapper = (props) => {
1231
+ if (target.renderReact) {
1232
+ const { React, ReactDOM } = target.payload || {};
1233
+ const [value, forceUpdateReact] = React.useReducer((r) => r + 1, 0);
1234
+ target.forceUpdateReact = forceUpdateReact;
1235
+ return ReactDOM.createPortal(<>{target.invokeReactRendering()}</>, target.getReactRoot());
1236
+ } else {
1237
+ return target.render();
1238
+ }
1239
+ });
1240
+ Object.assign(Wrapper, {
1241
+ displayName
1242
+ });
1243
+ return Wrapper;
1244
+ }
1245
+ getUID() {
1246
+ return this.uid || (this.uid = String(Math.random()));
1247
+ }
1248
+ getReactRoot() {
1249
+ return this.getRoot();
1250
+ }
1251
+ set(overrides) {
1252
+ this.overrides = __spreadValues(__spreadValues({}, this.overrides), overrides);
1253
+ this.props = __spreadValues(__spreadValues({}, this.getProps()), this.overrides);
1254
+ for (var property in this.props) {
1255
+ const value = this.props[property];
1256
+ if (this.props[property] == null) {
1257
+ this.removeAttribute(property);
1258
+ } else if (typeof value == "string" || typeof value == "number") {
1259
+ if (this.getAttribute(property) != String(value))
1260
+ this.setAttribute(property, String(value));
1261
+ }
1262
+ }
1263
+ this.scheduleRender();
1295
1264
  }
1296
- connectedCallback() {
1297
- this.loader = document.createElement("feaas-loader");
1298
- this.loader.style.cssText = "position: absolute; top: 0; left: 0; right: 0;bottom: 0; ";
1299
- this.appendChild(this.loader);
1265
+ scheduleRender() {
1266
+ cancelAnimationFrame(this.nextRender);
1267
+ this.nextRender = requestAnimationFrame(() => {
1268
+ this.reify();
1269
+ });
1300
1270
  }
1301
- load() {
1302
- if (!this.script) {
1303
- this.script = document.createElement("script");
1304
- this.script.type = "module";
1305
- this.script.onload = this.onScriptLoaded;
1306
- this.script.src = patchHostname(this.src);
1307
- this.script.crossOrigin = "anonymous";
1308
- this.appendChild(this.script);
1271
+ formatURL(src, hostname) {
1272
+ if (typeof src == "string" && src.match(/\/[^\/]/)) {
1273
+ return hostname + src;
1274
+ } else {
1275
+ return src;
1309
1276
  }
1310
1277
  }
1311
- getProps() {
1312
- return {
1313
- mode: this.getAttribute("mode"),
1314
- context: this.context,
1315
- library: this.getAttribute("library"),
1316
- src: this.getAttribute("src")
1317
- };
1278
+ getContextAttribute(name, element = this) {
1279
+ var _a, _b;
1280
+ return (_b = (_a = element.closest(`[${name}]`)) == null ? void 0 : _a.getAttribute(name)) != null ? _b : this.getAttribute(name);
1281
+ }
1282
+ static register(tagName) {
1283
+ if (!window.customElements.get(tagName)) {
1284
+ window.customElements.define(tagName, this);
1285
+ }
1318
1286
  }
1287
+ };
1288
+
1289
+ // src/components/FEAASLoader.ts
1290
+ function FEAASLoaderProps(element = this) {
1291
+ return {
1292
+ hidden: (element == null ? void 0 : element.getAttribute("hidden")) != null
1293
+ };
1294
+ }
1295
+ var FEAASLoader = class extends FEAASBase {
1319
1296
  attributeChangedCallback(name, oldValue, newValue) {
1320
- this.set(this.getProps());
1321
- }
1322
- set(options) {
1323
- Object.assign(this, options);
1324
- const keys = Object.keys(this.getProps());
1325
- for (var key of keys) {
1326
- const value = this[key];
1327
- if (value == null) {
1328
- this.removeAttribute(key);
1329
- } else if (this.getAttribute(key) != String(value)) {
1330
- this.setAttribute(key, String(value));
1297
+ if (name == "hidden") {
1298
+ this.style.setProperty("display", "block", "important");
1299
+ this.style.setProperty("transition", "opacity 0.3s", "important");
1300
+ if (newValue) {
1301
+ this.style.setProperty("opacity", "0", "important");
1302
+ this.style.pointerEvents = "none";
1303
+ } else {
1304
+ this.style.setProperty("opacity", "1", "important");
1305
+ this.style.pointerEvents = "all";
1331
1306
  }
1332
1307
  }
1333
- if (this.mode) {
1334
- this.removeAttribute("hidden");
1335
- } else if (this.getAttribute("hidden") == null) {
1336
- this.setAttribute("hidden", "hidden");
1308
+ }
1309
+ connectedCallback() {
1310
+ this.attributeChangedCallback("hidden", this.getAttribute("hidden"), this.getAttribute("hidden"));
1311
+ this.stylesheet = document.createElement("style");
1312
+ this.stylesheet.textContent = `
1313
+ #loader {
1314
+ position: absolute;
1315
+ top: 0;
1316
+ left: 0;
1317
+ right: 0;
1318
+ bottom: 0;
1319
+ display: flex;
1320
+ align-items: center;
1321
+ justify-content: center;
1322
+ background: #f6f6ff;
1323
+ z-index: 1000;
1324
+ }
1325
+ @keyframes loader-circular-track {
1326
+ 0% {
1327
+ stroke-dasharray: 1, 400;
1328
+ stroke-dashoffset: 0;
1337
1329
  }
1338
- if (this.mode && !this.hidden) {
1339
- this.load();
1330
+ 50% {
1331
+ stroke-dasharray: 400, 400;
1332
+ stroke-dashoffset: -100;
1340
1333
  }
1341
- if (this.element && this.element.set) {
1342
- this.element.onClose = this.onClose;
1343
- this.element.getToken = this.getToken;
1344
- this.element.set(options);
1334
+ 100% {
1335
+ stroke-dasharray: 400, 400;
1336
+ stroke-dashoffset: -260;
1345
1337
  }
1346
1338
  }
1347
- };
1348
- var HTMLFeaasLoader = class extends WebComponent {
1349
- static get observedAttributes() {
1350
- return ["hidden"];
1339
+
1340
+ @keyframes loader-circular-spinner {
1341
+ 0% {
1342
+ transform: rotate(0deg);
1343
+ }
1344
+
1345
+ 100% {
1346
+ transform: rotate(360deg);
1347
+ }
1351
1348
  }
1352
- connectedCallback() {
1353
- this.style.opacity = "1";
1354
- this.style.transition = "opacity 0.1s 0.2s";
1355
- this.stylesheet = document.createElement("style");
1356
- this.stylesheet.textContent = `
1357
- #loader {
1358
- position: absolute;
1359
- top: 0;
1360
- left: 0;
1361
- right: 0;
1362
- bottom: 0;
1363
- display: flex;
1364
- align-items: center;
1365
- justify-content: center;
1366
- background: #f6f6ff;
1367
- z-index: 1000;
1368
- opacity: 1;
1369
- transition: top 0.3s, background-color 0.7s 0.3s;
1370
- }
1371
- @keyframes loader-disappearance {
1372
- 100% {
1373
- opacity: 0;
1349
+ #loader .spinner {
1350
+ width: 48px;
1351
+ height: 48px;
1374
1352
  }
1375
- }
1376
- @keyframes loader-appearance {
1377
- 0% {
1378
- opacity: 0;
1353
+ `;
1354
+ this.loader = document.createElement("div");
1355
+ this.loader.id = "loader";
1356
+ this.loader.innerHTML = `
1357
+ <div class="spinner">
1358
+ <svg
1359
+ viewBox="0 0 100 100"
1360
+ style="
1361
+ animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1362
+ display: block;
1363
+ width: 48px;
1364
+ height: 48px;
1365
+ "
1366
+ >
1367
+ <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1368
+ <circle
1369
+ fill="transparent"
1370
+ stroke="#5548D9"
1371
+ cx="50"
1372
+ cy="50"
1373
+ r="42"
1374
+ stroke-width="10px"
1375
+ stroke-linecap="round"
1376
+ style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1377
+ ></circle>
1378
+ </svg>
1379
+ </div>`;
1380
+ this.getRoot().appendChild(this.stylesheet);
1381
+ this.getRoot().appendChild(this.loader);
1379
1382
  }
1383
+ };
1384
+ FEAASLoader.observedAttributes = ["hidden"];
1385
+ FEAASLoader.register("feaas-loader");
1386
+
1387
+ // src/components/FEAASStylesheet.ts
1388
+ function FEAASStylesheetProps(element = this) {
1389
+ var _a;
1390
+ return {
1391
+ library: element == null ? void 0 : element.getContextAttribute("library"),
1392
+ revision: (_a = element == null ? void 0 : element.getAttribute("revision")) != null ? _a : "published",
1393
+ cdn: element == null ? void 0 : element.getContextAttribute("cdn")
1394
+ };
1380
1395
  }
1381
- @keyframes loader-circular-track {
1382
- 0% {
1383
- stroke-dasharray: 1, 400;
1384
- stroke-dashoffset: 0;
1396
+ var FEAASStylesheet = class extends FEAASBase {
1397
+ getProps() {
1398
+ return FEAASStylesheetProps(this);
1385
1399
  }
1386
- 50% {
1387
- stroke-dasharray: 400, 400;
1388
- stroke-dashoffset: -100;
1400
+ isReadyToLoad() {
1401
+ return this.props.library != null && this.props.revision != null && this.props.cdn != null;
1389
1402
  }
1390
- 100% {
1391
- stroke-dasharray: 400, 400;
1392
- stroke-dashoffset: -260;
1403
+ load() {
1404
+ return __async(this, null, function* () {
1405
+ fetchStylesheet(this.props, this.onLoad);
1406
+ });
1393
1407
  }
1394
- }
1395
-
1396
- @keyframes loader-circular-spinner {
1397
- 0% {
1398
- transform: rotate(0deg);
1408
+ render() {
1409
+ if (!this.stylesheet) {
1410
+ this.stylesheet = document.createElement("style");
1411
+ this.appendChild(this.stylesheet);
1412
+ }
1413
+ this.stylesheet.textContent = this.payload;
1399
1414
  }
1415
+ };
1416
+ FEAASStylesheet.register("feaas-stylesheet");
1400
1417
 
1401
- 100% {
1402
- transform: rotate(360deg);
1418
+ // src/components/FEAASComponent.ts
1419
+ function FEAASComponentsProps(element = this) {
1420
+ let data;
1421
+ const dataValue = element.getAttribute("data");
1422
+ if (dataValue != null) {
1423
+ try {
1424
+ data = typeof dataValue == "string" ? JSON.parse(dataValue) : {};
1425
+ } catch (e) {
1426
+ }
1403
1427
  }
1428
+ return {
1429
+ data: data != null ? data : {},
1430
+ library: element.getAttribute("library"),
1431
+ component: element.getAttribute("component"),
1432
+ version: element.getAttribute("version"),
1433
+ revision: element.getAttribute("revision"),
1434
+ hostname: element.getAttribute("hostname"),
1435
+ cdn: element.getContextAttribute("cdn"),
1436
+ template: element.getAttribute("template")
1437
+ };
1404
1438
  }
1405
- #loader .spinner {
1406
- animation: loader-disappearance 0.6s both;
1407
- width: 48px;
1408
- height: 48px;
1409
- }
1410
- #loader .spinner {
1411
- animation: loader-appearance 0.6s both;
1412
- }
1413
- `;
1414
- this.root = this.attachShadow({ mode: "open" });
1415
- this.loader = document.createElement("div");
1416
- this.loader.id = "loader";
1417
- this.loader.innerHTML = `
1418
- <div class="spinner">
1419
- <svg
1420
- viewBox="0 0 100 100"
1421
- style="
1422
- animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1423
- display: block;
1424
- width: 48px;
1425
- height: 48px;
1426
- "
1427
- >
1428
- <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1429
- <circle
1430
- fill="transparent"
1431
- stroke="#5548D9"
1432
- cx="50"
1433
- cy="50"
1434
- r="42"
1435
- stroke-width="10px"
1436
- stroke-linecap="round"
1437
- style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1438
- ></circle>
1439
- </svg>
1440
- </div>`;
1441
- this.shadowRoot.appendChild(this.stylesheet);
1442
- this.shadowRoot.appendChild(this.loader);
1439
+ var FEAASComponent = class extends FEAASBase {
1440
+ setData(data) {
1441
+ this.set({ data });
1443
1442
  }
1444
- };
1445
- if (typeof window != "undefined" && !window.customElements.get("feaas-stylesheet")) {
1446
- window.customElements.define("feaas-stylesheet", HTMLFeaasStylesheet);
1447
- window.customElements.define("feaas-component", HTMLFeaasComponent);
1448
- window.customElements.define("feaas-picker-lazy", HTMLFeaasPickerLazy);
1449
- if (!window.customElements.get("feaas-loader"))
1450
- window.customElements.define("feaas-loader", HTMLFeaasLoader);
1451
- }
1452
-
1453
- // src/react.ts
1454
- function Component(props) {
1455
- const [template, setTemplate] = React.useState("template" in props ? props.template : null);
1456
- const data = props.data;
1457
- const ref = React.useRef(null);
1458
- React.useEffect(
1459
- () => {
1460
- if (template == null && !("template" in props)) {
1461
- fetchComponent(props, setTemplate).catch(() => {
1462
- console.error(
1463
- `FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.version}/${props.revision}`
1464
- );
1465
- });
1443
+ getProps() {
1444
+ return FEAASComponentsProps(this);
1445
+ }
1446
+ attributeChangedCallback(name, oldValue, newValue) {
1447
+ this.payload = void 0;
1448
+ this.needsRefresh = true;
1449
+ super.attributeChangedCallback(name, oldValue, newValue);
1450
+ }
1451
+ getOriginal() {
1452
+ const scope = this.getAttribute("data-path-scope");
1453
+ if (!scope)
1454
+ return;
1455
+ for (var current = this; current = current.previousElementSibling; ) {
1456
+ if (current.getAttribute("data-path-scope") == scope) {
1457
+ var last = current;
1458
+ } else {
1459
+ break;
1466
1460
  }
1467
- },
1468
- "template" in props ? [props.template, null, null, null] : [props.library, props.component, props.version, props.revision, props.hostname]
1469
- );
1470
- React.useEffect(() => {
1471
- if (ref.current && template) {
1472
- ref.current.innerHTML = template;
1473
- }
1474
- }, [ref, template]);
1475
- React.useEffect(() => {
1476
- if (template && ref.current) {
1477
- renderDOMElement(ref.current, data || {}, props);
1478
1461
  }
1479
- }, [ref, template, data]);
1480
- return React.createElement("div", { ref, className: "-feaas" });
1481
- }
1482
- function Stylesheet(props) {
1483
- const ref = React.useRef(null);
1484
- const [css, setCss] = React.useState("");
1485
- React.useEffect(() => {
1486
- fetchStylesheet(props, setCss).catch((e) => {
1487
- console.error(`FEAAS: Could not fetch stylesheet for library ${props.library}`);
1462
+ return last;
1463
+ }
1464
+ isReadyToLoad() {
1465
+ return super.isReadyToLoad() && this.props.library != null && this.props.component != null && this.props.version != null;
1466
+ }
1467
+ load() {
1468
+ return __async(this, null, function* () {
1469
+ if (this.getOriginal()) {
1470
+ return;
1471
+ }
1472
+ try {
1473
+ fetchComponent(this.props, this.onLoad);
1474
+ } catch (e) {
1475
+ console.error(
1476
+ `FEAAS: Could not fetch component: ${this.props.component}/${this.props.version}/${this.props.revision}`
1477
+ );
1478
+ }
1488
1479
  });
1489
- }, [props.hostname, props.library]);
1490
- return React.createElement(
1491
- "style",
1492
- { ref, rel: "stylesheet", className: "-stylesheet", "data-library-id": props.library },
1493
- [css]
1494
- );
1495
- }
1496
- var react_default = __spreadProps(__spreadValues(__spreadValues({}, dom_exports), webcomponent_exports), {
1497
- Stylesheet,
1498
- Component
1499
- });
1480
+ }
1481
+ render() {
1482
+ if (Array.from(this.children).filter((c) => c.tagName != "BR").length > 0 && !this.needsRefresh) {
1483
+ renderDOMElement(this, this.props.data);
1484
+ } else {
1485
+ this.needsRefresh = true;
1486
+ if (this.getOriginal()) {
1487
+ return;
1488
+ }
1489
+ renderDOMContent(this, this.payload, this.props.data);
1490
+ }
1491
+ }
1492
+ };
1493
+ FEAASComponent.observedAttributes = ["library", "component", "version", "revision", "hostname", "cdn", "template", "data"];
1494
+ FEAASComponent.register("feaas-component");
1500
1495
  export {
1501
- Component,
1502
- HTMLFeaasComponent,
1503
- HTMLFeaasStylesheet,
1504
- Stylesheet,
1496
+ FEAASComponent,
1497
+ FEAASComponentsProps,
1498
+ FEAASLoader,
1499
+ FEAASLoaderProps,
1500
+ FEAASStylesheet,
1501
+ FEAASStylesheetProps,
1505
1502
  autoloadScripts,
1506
1503
  cleanCollectionBit,
1507
- react_default as default,
1508
- fetchComponent,
1509
- fetchStylesheet,
1510
- getComponentURL,
1511
- getStylesheetURL,
1504
+ fetchAndRevalidate,
1512
1505
  loadScript,
1513
1506
  normalizeCollectionScope,
1514
1507
  observeDOMElement,