@sitecore-feaas/clientside 0.0.8 → 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 -435
  7. package/dist/node/{react.js → basic.js} +432 -431
  8. package/dist/node/index.cjs +667 -284
  9. package/dist/node/index.js +667 -288
  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 -379
  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,385 +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: this.getAttribute("hostname") || void 0
1235
- };
1180
+ getComponentName() {
1181
+ return this.tagName.replace("FEAAS-", "").toLowerCase();
1236
1182
  }
1237
- };
1238
- var HTMLFeaasStylesheet = class extends WebComponent {
1239
- constructor() {
1240
- super(...arguments);
1241
- this.connected = false;
1183
+ isReadyToLoad() {
1184
+ return this.payload === void 0 && this.getAttribute("hidden") == null;
1242
1185
  }
1243
- static get observedAttributes() {
1244
- return ["library", "revision", "hostname"];
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
+ }
1194
+ });
1245
1195
  }
1246
- connectedCallback() {
1247
- this.connected = true;
1248
- this.render();
1196
+ load() {
1197
+ return Promise.resolve(null);
1249
1198
  }
1250
- attributeChangedCallback() {
1251
- if (this.connected)
1252
- this.render();
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
+ }
1253
1216
  }
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}`);
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")
1225
+ });
1260
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();
1261
1264
  }
1262
- getProps() {
1263
- return {
1264
- library: this.getAttribute("library") || void 0,
1265
- revision: this.getAttribute("revision") || void 0,
1266
- hostname: this.getAttribute("hostname") || void 0
1267
- };
1268
- }
1269
- };
1270
- var HTMLFeaasPickerLazy = class extends WebComponent {
1271
- constructor() {
1272
- super(...arguments);
1273
- this.src = "https://components.sitecorecloud.io/assets/picker.js";
1274
- this.onClose = () => {
1275
- this.set({
1276
- mode: null
1277
- });
1278
- };
1279
- this.onScriptLoaded = () => {
1280
- this.element = document.createElement("feaas-picker");
1281
- this.element.style.cssText = "border: 0; width: 100%; height: 100%; display: block";
1282
- this.appendChild(this.element);
1283
- this.set(this.getProps());
1284
- };
1265
+ scheduleRender() {
1266
+ cancelAnimationFrame(this.nextRender);
1267
+ this.nextRender = requestAnimationFrame(() => {
1268
+ this.reify();
1269
+ });
1285
1270
  }
1286
- static get observedAttributes() {
1287
- return ["library", "mode", "hidden", "src"];
1271
+ formatURL(src, hostname) {
1272
+ if (typeof src == "string" && src.match(/\/[^\/]/)) {
1273
+ return hostname + src;
1274
+ } else {
1275
+ return src;
1276
+ }
1288
1277
  }
1289
- connectedCallback() {
1290
- this.loader = document.createElement("feaas-loader");
1291
- this.loader.style.cssText = "position: absolute; top: 0; left: 0; right: 0;bottom: 0; ";
1292
- this.appendChild(this.loader);
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);
1293
1281
  }
1294
- load() {
1295
- if (!this.script) {
1296
- this.script = document.createElement("script");
1297
- this.script.type = "module";
1298
- this.script.onload = this.onScriptLoaded;
1299
- this.script.src = this.src;
1300
- this.script.crossOrigin = "anonymous";
1301
- this.appendChild(this.script);
1282
+ static register(tagName) {
1283
+ if (!window.customElements.get(tagName)) {
1284
+ window.customElements.define(tagName, this);
1302
1285
  }
1303
1286
  }
1304
- getProps() {
1305
- return {
1306
- mode: this.getAttribute("mode"),
1307
- context: this.context,
1308
- library: this.getAttribute("library"),
1309
- src: this.getAttribute("src")
1310
- };
1311
- }
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 {
1312
1296
  attributeChangedCallback(name, oldValue, newValue) {
1313
- this.set(this.getProps());
1314
- }
1315
- set(options) {
1316
- Object.assign(this, options);
1317
- const keys = Object.keys(this.getProps());
1318
- for (var key of keys) {
1319
- const value = this[key];
1320
- if (value == null) {
1321
- this.removeAttribute(key);
1322
- } else if (this.getAttribute(key) != String(value)) {
1323
- 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";
1324
1306
  }
1325
1307
  }
1326
- if (this.mode) {
1327
- this.removeAttribute("hidden");
1328
- } else if (this.getAttribute("hidden") == null) {
1329
- 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;
1330
1329
  }
1331
- if (this.mode && !this.hidden) {
1332
- this.load();
1330
+ 50% {
1331
+ stroke-dasharray: 400, 400;
1332
+ stroke-dashoffset: -100;
1333
1333
  }
1334
- if (this.element && this.element.set) {
1335
- this.element.onClose = this.onClose;
1336
- this.element.getToken = this.getToken;
1337
- this.element.set(options);
1334
+ 100% {
1335
+ stroke-dasharray: 400, 400;
1336
+ stroke-dashoffset: -260;
1338
1337
  }
1339
1338
  }
1340
- };
1341
- var HTMLFeaasLoader = class extends WebComponent {
1342
- static get observedAttributes() {
1343
- return ["hidden"];
1339
+
1340
+ @keyframes loader-circular-spinner {
1341
+ 0% {
1342
+ transform: rotate(0deg);
1343
+ }
1344
+
1345
+ 100% {
1346
+ transform: rotate(360deg);
1347
+ }
1344
1348
  }
1345
- connectedCallback() {
1346
- this.style.opacity = "1";
1347
- this.style.transition = "opacity 0.2s 0.6s";
1348
- this.stylesheet = document.createElement("style");
1349
- this.stylesheet.textContent = `
1350
- #loader {
1351
- position: absolute;
1352
- top: 0;
1353
- left: 0;
1354
- right: 0;
1355
- bottom: 0;
1356
- display: flex;
1357
- align-items: center;
1358
- justify-content: center;
1359
- background: #f6f6ff;
1360
- z-index: 1000;
1361
- opacity: 1;
1362
- transition: top 0.3s, background-color 0.7s 0.3s;
1363
- }
1364
- @keyframes loader-disappearance {
1365
- 100% {
1366
- opacity: 0;
1349
+ #loader .spinner {
1350
+ width: 48px;
1351
+ height: 48px;
1367
1352
  }
1368
- }
1369
- @keyframes loader-appearance {
1370
- 0% {
1371
- 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);
1372
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
+ };
1373
1395
  }
1374
- @keyframes loader-circular-track {
1375
- 0% {
1376
- stroke-dasharray: 1, 400;
1377
- stroke-dashoffset: 0;
1396
+ var FEAASStylesheet = class extends FEAASBase {
1397
+ getProps() {
1398
+ return FEAASStylesheetProps(this);
1378
1399
  }
1379
- 50% {
1380
- stroke-dasharray: 400, 400;
1381
- stroke-dashoffset: -100;
1400
+ isReadyToLoad() {
1401
+ return this.props.library != null && this.props.revision != null && this.props.cdn != null;
1382
1402
  }
1383
- 100% {
1384
- stroke-dasharray: 400, 400;
1385
- stroke-dashoffset: -260;
1403
+ load() {
1404
+ return __async(this, null, function* () {
1405
+ fetchStylesheet(this.props, this.onLoad);
1406
+ });
1386
1407
  }
1387
- }
1388
-
1389
- @keyframes loader-circular-spinner {
1390
- 0% {
1391
- 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;
1392
1414
  }
1415
+ };
1416
+ FEAASStylesheet.register("feaas-stylesheet");
1393
1417
 
1394
- 100% {
1395
- 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
+ }
1396
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
+ };
1397
1438
  }
1398
- #loader .spinner {
1399
- animation: loader-disappearance 0.6s both;
1400
- width: 48px;
1401
- height: 48px;
1402
- }
1403
- #loader .spinner {
1404
- animation: loader-appearance 0.6s both;
1405
- }
1406
- `;
1407
- this.root = this.attachShadow({ mode: "open" });
1408
- this.loader = document.createElement("div");
1409
- this.loader.id = "loader";
1410
- this.loader.innerHTML = `
1411
- <div class="spinner">
1412
- <svg
1413
- viewBox="0 0 100 100"
1414
- style="
1415
- animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1416
- display: block;
1417
- width: 48px;
1418
- height: 48px;
1419
- "
1420
- >
1421
- <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1422
- <circle
1423
- fill="transparent"
1424
- stroke="#5548D9"
1425
- cx="50"
1426
- cy="50"
1427
- r="42"
1428
- stroke-width="10px"
1429
- stroke-linecap="round"
1430
- style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1431
- ></circle>
1432
- </svg>
1433
- </div>`;
1434
- this.shadowRoot.appendChild(this.stylesheet);
1435
- this.shadowRoot.appendChild(this.loader);
1439
+ var FEAASComponent = class extends FEAASBase {
1440
+ setData(data) {
1441
+ this.set({ data });
1436
1442
  }
1437
- };
1438
- if (typeof window != "undefined" && !window.customElements.get("feaas-stylesheet")) {
1439
- window.customElements.define("feaas-stylesheet", HTMLFeaasStylesheet);
1440
- window.customElements.define("feaas-component", HTMLFeaasComponent);
1441
- window.customElements.define("feaas-picker-lazy", HTMLFeaasPickerLazy);
1442
- window.customElements.define("feaas-loader", HTMLFeaasLoader);
1443
- }
1444
-
1445
- // src/react.ts
1446
- function Component(props) {
1447
- const [template, setTemplate] = React.useState("template" in props ? props.template : null);
1448
- const data = props.data;
1449
- const ref = React.useRef(null);
1450
- React.useEffect(
1451
- () => {
1452
- if (template == null && !("template" in props)) {
1453
- fetchComponent(props, setTemplate).catch(() => {
1454
- console.error(
1455
- `FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.version}/${props.revision}`
1456
- );
1457
- });
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;
1458
1460
  }
1459
- },
1460
- "template" in props ? [props.template, null, null, null] : [props.library, props.component, props.version, props.revision, props.hostname]
1461
- );
1462
- React.useEffect(() => {
1463
- if (ref.current && template) {
1464
- ref.current.innerHTML = template;
1465
- }
1466
- }, [ref, template]);
1467
- React.useEffect(() => {
1468
- if (template && ref.current) {
1469
- renderDOMElement(ref.current, data || {}, props);
1470
1461
  }
1471
- }, [ref, template, data]);
1472
- return React.createElement("div", { ref, className: "-feaas" });
1473
- }
1474
- function Stylesheet(props) {
1475
- const ref = React.useRef(null);
1476
- const [css, setCss] = React.useState("");
1477
- React.useEffect(() => {
1478
- fetchStylesheet(props, setCss).catch((e) => {
1479
- 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
+ }
1480
1479
  });
1481
- }, [props.hostname, props.library]);
1482
- return React.createElement(
1483
- "style",
1484
- { ref, rel: "stylesheet", className: "-stylesheet", "data-library-id": props.library },
1485
- [css]
1486
- );
1487
- }
1488
- var react_default = __spreadProps(__spreadValues(__spreadValues({}, dom_exports), webcomponent_exports), {
1489
- Stylesheet,
1490
- Component
1491
- });
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");
1492
1495
  export {
1493
- Component,
1494
- HTMLFeaasComponent,
1495
- HTMLFeaasStylesheet,
1496
- Stylesheet,
1496
+ FEAASComponent,
1497
+ FEAASComponentsProps,
1498
+ FEAASLoader,
1499
+ FEAASLoaderProps,
1500
+ FEAASStylesheet,
1501
+ FEAASStylesheetProps,
1497
1502
  autoloadScripts,
1498
1503
  cleanCollectionBit,
1499
- react_default as default,
1500
- fetchComponent,
1501
- fetchStylesheet,
1502
- getComponentURL,
1503
- getStylesheetURL,
1504
+ fetchAndRevalidate,
1504
1505
  loadScript,
1505
1506
  normalizeCollectionScope,
1506
1507
  observeDOMElement,