@sitecore-feaas/clientside 0.0.9 → 0.1.1

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
@@ -1,11 +1,9 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
8
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -33,10 +31,6 @@ var __copyProps = (to, from, except, desc) => {
33
31
  }
34
32
  return to;
35
33
  };
36
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
- mod
39
- ));
40
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
35
  var __async = (__this, __arguments, generator) => {
42
36
  return new Promise((resolve, reject) => {
@@ -59,121 +53,18 @@ var __async = (__this, __arguments, generator) => {
59
53
  });
60
54
  };
61
55
 
62
- // src/react.ts
63
- var react_exports = {};
64
- __export(react_exports, {
65
- Component: () => Component,
66
- HTMLFeaasComponent: () => HTMLFeaasComponent,
67
- HTMLFeaasStylesheet: () => HTMLFeaasStylesheet,
68
- Stylesheet: () => Stylesheet,
69
- autoloadScripts: () => autoloadScripts,
70
- cleanCollectionBit: () => cleanCollectionBit,
71
- default: () => react_default,
72
- fetchComponent: () => fetchComponent,
73
- fetchStylesheet: () => fetchStylesheet,
74
- getComponentURL: () => getComponentURL,
75
- getStylesheetURL: () => getStylesheetURL,
76
- loadScript: () => loadScript,
77
- normalizeCollectionScope: () => normalizeCollectionScope,
78
- observeDOMElement: () => observeDOMElement,
79
- queryScopes: () => queryScopes,
80
- renderComponent: () => renderComponent,
81
- renderComponentElement: () => renderComponentElement,
82
- renderComponentPromise: () => renderComponentPromise,
83
- renderDOMContent: () => renderDOMContent,
84
- renderDOMElement: () => renderDOMElement,
85
- renderStylesheet: () => renderStylesheet,
86
- renderStylesheetPromise: () => renderStylesheetPromise,
87
- setDOMAttribute: () => setDOMAttribute
88
- });
89
- module.exports = __toCommonJS(react_exports);
90
- var import_react = __toESM(require("react"), 1);
91
-
92
- // src/fetch.ts
93
- function fetchAndRevalidate(url, options, validator, callback) {
94
- return __async(this, null, function* () {
95
- const date = new Date();
96
- const initialResponse = yield fetch(url, options);
97
- if (!initialResponse.ok)
98
- throw new Error("Fetch failed");
99
- const responseDate = new Date(initialResponse.headers.get("date"));
100
- var response = initialResponse;
101
- callback(initialResponse, "cached");
102
- if (responseDate < date) {
103
- const freshHeadResponse = yield fetch(url + "?" + Math.random(), __spreadProps(__spreadValues({}, options), {
104
- method: "HEAD",
105
- cache: "no-cache"
106
- }));
107
- if (freshHeadResponse.headers.get("last-modified") != initialResponse.headers.get("last-modified")) {
108
- if (validator(freshHeadResponse) === false) {
109
- throw new Error("Response is stale");
110
- }
111
- response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
112
- cache: "reload"
113
- }));
114
- }
115
- }
116
- if (validator(response) === false) {
117
- throw new Error("Response is not valid");
118
- }
119
- if (initialResponse !== response) {
120
- callback(response, "valid");
121
- }
122
- return response;
123
- });
124
- }
125
-
126
- // src/cloud.ts
127
- function getComponentURL({
128
- hostname = "https://feaascomponentsapidev.blob.core.windows.net",
129
- library,
130
- component,
131
- version,
132
- revision = "published"
133
- }) {
134
- return `${hostname}/components/${library}/${component}/${version}/${revision}.html`;
135
- }
136
- function getStylesheetURL({
137
- hostname = `https://feaascomponentsapidev.blob.core.windows.net`,
138
- library,
139
- revision = "published"
140
- }) {
141
- return `${hostname}/styles/${library}/${revision}.css`;
142
- }
143
- function fetchComponent(props, callback) {
144
- return __async(this, null, function* () {
145
- return fetchAndRevalidate(
146
- getComponentURL(props),
147
- {},
148
- (response) => {
149
- return response.headers.get("x-ms-meta-versionDeletedAt") == null;
150
- },
151
- (response) => {
152
- response.text().then(callback);
153
- }
154
- );
155
- });
156
- }
157
- function fetchStylesheet(props, callback) {
158
- return __async(this, null, function* () {
159
- return fetchAndRevalidate(
160
- getStylesheetURL(props),
161
- {},
162
- (response) => {
163
- return response.headers.get("x-ms-meta-deletedAt") == null;
164
- },
165
- (response) => {
166
- response.text().then(callback);
167
- }
168
- );
169
- });
170
- }
171
-
172
- // src/dom.ts
173
- var dom_exports = {};
174
- __export(dom_exports, {
56
+ // src/basic.ts
57
+ var basic_exports = {};
58
+ __export(basic_exports, {
59
+ FEAASComponent: () => FEAASComponent,
60
+ FEAASComponentsProps: () => FEAASComponentsProps,
61
+ FEAASLoader: () => FEAASLoader,
62
+ FEAASLoaderProps: () => FEAASLoaderProps,
63
+ FEAASStylesheet: () => FEAASStylesheet,
64
+ FEAASStylesheetProps: () => FEAASStylesheetProps,
175
65
  autoloadScripts: () => autoloadScripts,
176
66
  cleanCollectionBit: () => cleanCollectionBit,
67
+ fetchAndRevalidate: () => fetchAndRevalidate,
177
68
  loadScript: () => loadScript,
178
69
  normalizeCollectionScope: () => normalizeCollectionScope,
179
70
  observeDOMElement: () => observeDOMElement,
@@ -187,6 +78,7 @@ __export(dom_exports, {
187
78
  renderStylesheetPromise: () => renderStylesheetPromise,
188
79
  setDOMAttribute: () => setDOMAttribute
189
80
  });
81
+ module.exports = __toCommonJS(basic_exports);
190
82
 
191
83
  // ../node_modules/jsonpath-plus/dist/index-browser-esm.js
192
84
  function _typeof(obj) {
@@ -887,6 +779,88 @@ JSONPath.prototype.vm = {
887
779
  }
888
780
  };
889
781
 
782
+ // src/fetch.ts
783
+ function fetchAndRevalidate(url, options, validator, callback) {
784
+ return __async(this, null, function* () {
785
+ const date = new Date();
786
+ const initialResponse = yield fetch(url, options);
787
+ if (!initialResponse.ok)
788
+ throw new Error("Fetch failed");
789
+ const responseDate = new Date(initialResponse.headers.get("date"));
790
+ var response = initialResponse;
791
+ callback(initialResponse, "cached");
792
+ if (responseDate < date) {
793
+ const freshHeadResponse = yield fetch(url + "?" + Math.random(), __spreadProps(__spreadValues({}, options), {
794
+ method: "HEAD",
795
+ cache: "no-cache"
796
+ }));
797
+ if (freshHeadResponse.headers.get("last-modified") != initialResponse.headers.get("last-modified")) {
798
+ if (validator(freshHeadResponse) === false) {
799
+ throw new Error("Response is stale");
800
+ }
801
+ response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
802
+ cache: "reload"
803
+ }));
804
+ }
805
+ }
806
+ if (validator(response) === false) {
807
+ throw new Error("Response is not valid");
808
+ }
809
+ if (initialResponse !== response) {
810
+ callback(response, "valid");
811
+ }
812
+ return response;
813
+ });
814
+ }
815
+
816
+ // src/cloud.ts
817
+ function getComponentURL({
818
+ cdn = "https://feaascomponentsapidev.blob.core.windows.net",
819
+ hostname,
820
+ library,
821
+ component,
822
+ version,
823
+ revision = "published"
824
+ }) {
825
+ return `${cdn || hostname}/components/${library}/${component}/${version}/${revision}.html`;
826
+ }
827
+ function getStylesheetURL({
828
+ cdn = `https://feaascomponentsapidev.blob.core.windows.net`,
829
+ hostname,
830
+ library,
831
+ revision = "published"
832
+ }) {
833
+ return `${cdn || hostname}/styles/${library}/${revision}.css`;
834
+ }
835
+ function fetchComponent(props, callback) {
836
+ return __async(this, null, function* () {
837
+ return fetchAndRevalidate(
838
+ getComponentURL(props),
839
+ {},
840
+ (response) => {
841
+ return response.headers.get("x-ms-meta-versionDeletedAt") == null;
842
+ },
843
+ (response) => {
844
+ response.text().then(callback);
845
+ }
846
+ );
847
+ });
848
+ }
849
+ function fetchStylesheet(props, callback) {
850
+ return __async(this, null, function* () {
851
+ return fetchAndRevalidate(
852
+ getStylesheetURL(props),
853
+ {},
854
+ (response) => {
855
+ return response.headers.get("x-ms-meta-deletedAt") == null;
856
+ },
857
+ (response) => {
858
+ response.text().then(callback);
859
+ }
860
+ );
861
+ });
862
+ }
863
+
890
864
  // src/dom.ts
891
865
  function renderComponentElement(content, datasources) {
892
866
  const wrapper = document.createElement("div");
@@ -1166,378 +1140,397 @@ function renderComponentPromise(props, root) {
1166
1140
  });
1167
1141
  }
1168
1142
 
1169
- // src/webcomponent.ts
1170
- var webcomponent_exports = {};
1171
- __export(webcomponent_exports, {
1172
- HTMLFeaasComponent: () => HTMLFeaasComponent,
1173
- HTMLFeaasStylesheet: () => HTMLFeaasStylesheet
1174
- });
1175
- var WebComponent = typeof HTMLElement == "undefined" ? class {
1176
- } : HTMLElement;
1177
- var HTMLFeaasComponent = class extends WebComponent {
1143
+ // src/components/FEAASBase.tsx
1144
+ var FEAASBase = class extends HTMLElement {
1178
1145
  constructor() {
1179
1146
  super(...arguments);
1180
- this.connected = false;
1181
- this.template = null;
1182
- this.data = void 0;
1183
- this.isFetching = false;
1184
- }
1185
- static get observedAttributes() {
1186
- return ["data", "library", "component", "version", "revision", "hostname", "template"];
1147
+ this.connected = null;
1148
+ this.refs = {};
1149
+ this.descendants = [];
1150
+ this.onLoad = (payload) => {
1151
+ if (payload == null)
1152
+ return;
1153
+ this.payload = payload;
1154
+ this.render();
1155
+ };
1187
1156
  }
1188
- connectedCallback() {
1189
- this.connected = true;
1190
- this.render();
1157
+ getProps(context) {
1158
+ return {};
1191
1159
  }
1192
- disconnectedCallback() {
1160
+ getRoot() {
1161
+ return this;
1193
1162
  }
1194
1163
  attributeChangedCallback(name, oldValue, newValue) {
1195
- if (!this.connected)
1196
- return;
1197
- if (name == "template") {
1198
- this.template = newValue;
1199
- } else if (name != "date") {
1200
- this.template = null;
1201
- }
1202
- if (name == "data" && this.children.length > 0) {
1203
- this.update();
1204
- } else {
1205
- cancelAnimationFrame(this.rendering);
1206
- this.rendering = requestAnimationFrame(() => {
1207
- this.render();
1208
- });
1209
- }
1210
- }
1211
- update() {
1212
- renderDOMElement(this, this.getProps().data);
1164
+ this.set();
1213
1165
  }
1214
- setData(data) {
1215
- this.data = data;
1216
- if (this.children.length > 0) {
1217
- this.update();
1218
- } else {
1219
- this.render();
1220
- }
1166
+ connectedCallback() {
1167
+ console.log("FEAAS: Connected", this);
1168
+ this.connected = new Event("feaasConnected", { bubbles: true, composed: true });
1169
+ this.dispatchEvent(this.connected);
1170
+ this.addEventListener("feaasConnected", this);
1171
+ this.addEventListener("feaasDisconnected", this);
1172
+ this.set();
1221
1173
  }
1222
- getOriginal() {
1223
- const scope = this.getAttribute("data-path-scope");
1224
- if (!scope)
1225
- return;
1226
- for (var current = this; current = current.previousElementSibling; ) {
1227
- if (current.getAttribute("data-path-scope") == scope) {
1228
- var last = current;
1229
- } else {
1174
+ disconnectedCallback() {
1175
+ console.log("FEAAS: Disconnected", this);
1176
+ this.removeEventListener("feaasConnected", this);
1177
+ this.removeEventListener("feaasDisconnected", this);
1178
+ this.dispatchEvent(new Event("feaasDisconnected", { bubbles: true, composed: true }));
1179
+ this.connected = null;
1180
+ }
1181
+ handleEvent(event) {
1182
+ switch (event.type) {
1183
+ case "feaasConnected":
1184
+ this.adoptedCallback(event);
1185
+ break;
1186
+ case "feaasDisconnected":
1187
+ this.orphanCallback(event);
1230
1188
  break;
1231
- }
1232
- }
1233
- return last;
1234
- }
1235
- getData() {
1236
- var _a;
1237
- if (this.data) {
1238
- return this.data;
1239
- }
1240
- if (this.getAttribute("data")) {
1241
- const dataValue = this.getAttribute("data");
1242
- return typeof dataValue == "string" ? JSON.parse(dataValue) : {};
1243
1189
  }
1244
- return ((_a = this.getOriginal()) == null ? void 0 : _a.getData()) || {};
1245
- return {};
1246
1190
  }
1247
- render() {
1248
- if (this.getOriginal()) {
1191
+ orphanCallback(event) {
1192
+ const target = event.composedPath()[0];
1193
+ const index = this.descendants.indexOf(target);
1194
+ if (index == -1)
1249
1195
  return;
1196
+ console.log("FEAAS: Orphaning", this, target);
1197
+ this.descendants.splice(index, -1);
1198
+ this.refs[target.getComponentName()] = null;
1199
+ if (target.refs.parent == this)
1200
+ target.refs.parent = null;
1201
+ if (target.refs.top == this) {
1202
+ target.refs.top = target.refs.parent;
1250
1203
  }
1251
- const newProps = this.getProps();
1252
- if (this.template == null) {
1253
- if (!this.isFetching) {
1254
- if (newProps.component != null && newProps.version != null) {
1255
- this.isFetching = true;
1256
- fetchComponent(newProps, (template) => {
1257
- this.template = template;
1258
- this.isFetching = false;
1259
- renderDOMContent(this, this.template, newProps.data);
1260
- }).catch(() => {
1261
- console.error(
1262
- `FEAAS: Could not fetch component: ${newProps.component}/${newProps.version}/${newProps.revision}`
1263
- );
1264
- });
1204
+ }
1205
+ adoptedCallback(event) {
1206
+ var _a, _b;
1207
+ const target = event.composedPath()[0];
1208
+ this.descendants.push(target);
1209
+ console.log("FEAAS: Adopting", this, target);
1210
+ this.refs[target.getComponentName()] = target;
1211
+ target.refs.top = this;
1212
+ (_a = target.refs).parent || (_a.parent = this);
1213
+ if (target.renderReact) {
1214
+ for (var p = target.refs.parent; p; p = p.refs.parent) {
1215
+ if (p.renderReact) {
1216
+ (_b = target.refs).parentReact || (_b.parentReact = p);
1217
+ target.refs.topReact = p;
1265
1218
  }
1266
1219
  }
1267
- } else {
1268
- renderDOMContent(this, this.template, newProps.data);
1269
1220
  }
1270
1221
  }
1271
- getProps() {
1272
- return {
1273
- data: this.getData(),
1274
- library: this.getAttribute("library") || void 0,
1275
- component: this.getAttribute("component") || void 0,
1276
- version: this.getAttribute("version") || void 0,
1277
- revision: this.getAttribute("revision") || void 0,
1278
- hostname: patchHostname(this.getAttribute("hostname") || void 0)
1279
- };
1280
- }
1281
- };
1282
- var HTMLFeaasStylesheet = class extends WebComponent {
1283
- constructor() {
1284
- super(...arguments);
1285
- this.connected = false;
1222
+ getComponentName() {
1223
+ return this.tagName.replace("FEAAS-", "").toLowerCase();
1286
1224
  }
1287
- static get observedAttributes() {
1288
- return ["library", "revision", "hostname"];
1225
+ isReadyToLoad() {
1226
+ return this.payload === void 0 && this.getAttribute("hidden") == null;
1289
1227
  }
1290
- connectedCallback() {
1291
- this.connected = true;
1292
- this.render();
1293
- }
1294
- attributeChangedCallback() {
1295
- if (this.connected)
1296
- this.render();
1297
- }
1298
- render() {
1299
- const props = this.getProps();
1300
- fetchStylesheet(props, (cssText) => {
1301
- this.innerHTML = "<style>" + cssText + "</style>";
1302
- }).catch((e) => {
1303
- console.error(`FEAAS: Could not fetch stylesheet for library ${props.library}`);
1228
+ reify() {
1229
+ return __async(this, null, function* () {
1230
+ if (this.payload !== void 0) {
1231
+ this.render();
1232
+ } else if (this.isReadyToLoad()) {
1233
+ this.payload = null;
1234
+ this.load().then(this.onLoad);
1235
+ }
1304
1236
  });
1305
1237
  }
1306
- getProps() {
1307
- return {
1308
- library: this.getAttribute("library") || void 0,
1309
- revision: this.getAttribute("revision") || void 0,
1310
- hostname: patchHostname(this.getAttribute("hostname") || void 0)
1311
- };
1238
+ load() {
1239
+ return Promise.resolve(null);
1312
1240
  }
1313
- };
1314
- function patchHostname(url) {
1315
- if (typeof url == "string" && (location.hostname.includes("pages-staging") || location.hostname.includes("staging-staging"))) {
1316
- return url.replace("components.sitecorecloud.io", "components-staging.sitecore-staging.cloud").replace("feaascompontsapiprod", "feaascomponentsstaging");
1317
- } else {
1318
- return url;
1241
+ render(nested = false) {
1242
+ var _a, _b, _c;
1243
+ console.log("FEAAS: React", this.tagName, this.payload);
1244
+ if (this.payload == null)
1245
+ return;
1246
+ const { React, ReactDOM } = this.payload || {};
1247
+ if (!React)
1248
+ throw new Error(`${this.tagName}: React is not present in payload`);
1249
+ if (!ReactDOM)
1250
+ throw new Error(`${this.tagName}: ReactDOM is not present in payload`);
1251
+ if (!this.refs.topReact && !this.forceUpdateReact) {
1252
+ ReactDOM.render(React.createElement(this.getReactWrapper()), this.getReactRoot());
1253
+ } else if (this.forceUpdateReact) {
1254
+ (_a = this.forceUpdateReact) == null ? void 0 : _a.call(this);
1255
+ } else {
1256
+ (_c = (_b = this.refs.topReact).forceUpdateReact) == null ? void 0 : _c.call(_b);
1257
+ }
1319
1258
  }
1320
- }
1321
- var HTMLFeaasPickerLazy = class extends WebComponent {
1322
- constructor() {
1323
- super(...arguments);
1324
- this.src = "https://components.sitecorecloud.io/assets/picker.js";
1325
- this.onClose = () => {
1326
- this.set({
1327
- mode: null
1259
+ invokeReactRendering() {
1260
+ const { React, ReactDOM } = this.payload || {};
1261
+ const children = this.descendants.filter((r) => {
1262
+ return r.refs.parentReact == this && r.payload;
1263
+ }).map((child, index) => {
1264
+ return React.createElement(this.getReactWrapper(child), {
1265
+ key: this.tagName + "-" + index,
1266
+ slot: child.getAttribute("slot")
1328
1267
  });
1329
- };
1330
- this.onScriptLoaded = () => {
1331
- this.element = document.createElement("feaas-picker");
1332
- this.element.style.cssText = "border: 0; width: 100%; height: 100%; display: block";
1333
- this.appendChild(this.element);
1334
- this.set(this.getProps());
1335
- };
1336
- }
1337
- static get observedAttributes() {
1338
- return ["library", "mode", "hidden", "src"];
1268
+ });
1269
+ return this.renderReact(__spreadProps(__spreadValues({}, this.props), { children }), this.payload);
1270
+ }
1271
+ getReactWrapper(target = this, displayName = target.tagName) {
1272
+ const Wrapper = target.reactWrapper || (target.reactWrapper = (props) => {
1273
+ if (target.renderReact) {
1274
+ const { React, ReactDOM } = target.payload || {};
1275
+ const [value, forceUpdateReact] = React.useReducer((r) => r + 1, 0);
1276
+ target.forceUpdateReact = forceUpdateReact;
1277
+ return ReactDOM.createPortal(React.Fragment({ children: target.invokeReactRendering() }), target.getReactRoot());
1278
+ } else {
1279
+ return target.render();
1280
+ }
1281
+ });
1282
+ Object.assign(Wrapper, {
1283
+ displayName
1284
+ });
1285
+ return Wrapper;
1286
+ }
1287
+ getUID() {
1288
+ return this.uid || (this.uid = String(Math.random()));
1289
+ }
1290
+ getReactRoot() {
1291
+ return this.getRoot();
1292
+ }
1293
+ set(overrides) {
1294
+ this.overrides = __spreadValues(__spreadValues({}, this.overrides), overrides);
1295
+ this.props = __spreadValues(__spreadValues({}, this.getProps()), this.overrides);
1296
+ for (var property in this.props) {
1297
+ const value = this.props[property];
1298
+ if (this.props[property] == null) {
1299
+ this.removeAttribute(property);
1300
+ } else if (typeof value == "string" || typeof value == "number") {
1301
+ if (this.getAttribute(property) != String(value))
1302
+ this.setAttribute(property, String(value));
1303
+ }
1304
+ }
1305
+ this.scheduleRender();
1339
1306
  }
1340
- connectedCallback() {
1341
- this.loader = document.createElement("feaas-loader");
1342
- this.loader.style.cssText = "position: absolute; top: 0; left: 0; right: 0;bottom: 0; ";
1343
- this.appendChild(this.loader);
1307
+ scheduleRender() {
1308
+ cancelAnimationFrame(this.nextRender);
1309
+ this.nextRender = requestAnimationFrame(() => {
1310
+ this.reify();
1311
+ });
1344
1312
  }
1345
- load() {
1346
- if (!this.script) {
1347
- this.script = document.createElement("script");
1348
- this.script.type = "module";
1349
- this.script.onload = this.onScriptLoaded;
1350
- this.script.src = patchHostname(this.src);
1351
- this.script.crossOrigin = "anonymous";
1352
- this.appendChild(this.script);
1313
+ formatURL(src, hostname) {
1314
+ if (typeof src == "string" && src.match(/\/[^\/]/)) {
1315
+ return hostname + src;
1316
+ } else {
1317
+ return src;
1353
1318
  }
1354
1319
  }
1355
- getProps() {
1356
- return {
1357
- mode: this.getAttribute("mode"),
1358
- context: this.context,
1359
- library: this.getAttribute("library"),
1360
- src: this.getAttribute("src")
1361
- };
1320
+ getContextAttribute(name, element = this) {
1321
+ var _a, _b;
1322
+ return (_b = (_a = element.closest(`[${name}]`)) == null ? void 0 : _a.getAttribute(name)) != null ? _b : this.getAttribute(name);
1362
1323
  }
1324
+ static register(tagName) {
1325
+ if (!window.customElements.get(tagName)) {
1326
+ window.customElements.define(tagName, this);
1327
+ }
1328
+ }
1329
+ };
1330
+
1331
+ // src/components/FEAASLoader.ts
1332
+ function FEAASLoaderProps(element = this) {
1333
+ return {
1334
+ hidden: (element == null ? void 0 : element.getAttribute("hidden")) != null
1335
+ };
1336
+ }
1337
+ var FEAASLoader = class extends FEAASBase {
1363
1338
  attributeChangedCallback(name, oldValue, newValue) {
1364
- this.set(this.getProps());
1365
- }
1366
- set(options) {
1367
- Object.assign(this, options);
1368
- const keys = Object.keys(this.getProps());
1369
- for (var key of keys) {
1370
- const value = this[key];
1371
- if (value == null) {
1372
- this.removeAttribute(key);
1373
- } else if (this.getAttribute(key) != String(value)) {
1374
- this.setAttribute(key, String(value));
1339
+ if (name == "hidden") {
1340
+ this.style.setProperty("display", "block", "important");
1341
+ this.style.setProperty("transition", "opacity 0.3s", "important");
1342
+ if (newValue) {
1343
+ this.style.setProperty("opacity", "0", "important");
1344
+ this.style.pointerEvents = "none";
1345
+ } else {
1346
+ this.style.setProperty("opacity", "1", "important");
1347
+ this.style.pointerEvents = "all";
1375
1348
  }
1376
1349
  }
1377
- if (this.mode) {
1378
- this.removeAttribute("hidden");
1379
- } else if (this.getAttribute("hidden") == null) {
1380
- this.setAttribute("hidden", "hidden");
1350
+ }
1351
+ connectedCallback() {
1352
+ this.attributeChangedCallback("hidden", this.getAttribute("hidden"), this.getAttribute("hidden"));
1353
+ this.stylesheet = document.createElement("style");
1354
+ this.stylesheet.textContent = `
1355
+ #loader {
1356
+ position: absolute;
1357
+ top: 0;
1358
+ left: 0;
1359
+ right: 0;
1360
+ bottom: 0;
1361
+ display: flex;
1362
+ align-items: center;
1363
+ justify-content: center;
1364
+ background: #f6f6ff;
1365
+ z-index: 1000;
1366
+ }
1367
+ @keyframes loader-circular-track {
1368
+ 0% {
1369
+ stroke-dasharray: 1, 400;
1370
+ stroke-dashoffset: 0;
1381
1371
  }
1382
- if (this.mode && !this.hidden) {
1383
- this.load();
1372
+ 50% {
1373
+ stroke-dasharray: 400, 400;
1374
+ stroke-dashoffset: -100;
1384
1375
  }
1385
- if (this.element && this.element.set) {
1386
- this.element.onClose = this.onClose;
1387
- this.element.getToken = this.getToken;
1388
- this.element.set(options);
1376
+ 100% {
1377
+ stroke-dasharray: 400, 400;
1378
+ stroke-dashoffset: -260;
1389
1379
  }
1390
1380
  }
1391
- };
1392
- var HTMLFeaasLoader = class extends WebComponent {
1393
- static get observedAttributes() {
1394
- return ["hidden"];
1381
+
1382
+ @keyframes loader-circular-spinner {
1383
+ 0% {
1384
+ transform: rotate(0deg);
1385
+ }
1386
+
1387
+ 100% {
1388
+ transform: rotate(360deg);
1389
+ }
1395
1390
  }
1396
- connectedCallback() {
1397
- this.style.opacity = "1";
1398
- this.style.transition = "opacity 0.1s 0.2s";
1399
- this.stylesheet = document.createElement("style");
1400
- this.stylesheet.textContent = `
1401
- #loader {
1402
- position: absolute;
1403
- top: 0;
1404
- left: 0;
1405
- right: 0;
1406
- bottom: 0;
1407
- display: flex;
1408
- align-items: center;
1409
- justify-content: center;
1410
- background: #f6f6ff;
1411
- z-index: 1000;
1412
- opacity: 1;
1413
- transition: top 0.3s, background-color 0.7s 0.3s;
1414
- }
1415
- @keyframes loader-disappearance {
1416
- 100% {
1417
- opacity: 0;
1391
+ #loader .spinner {
1392
+ width: 48px;
1393
+ height: 48px;
1418
1394
  }
1419
- }
1420
- @keyframes loader-appearance {
1421
- 0% {
1422
- opacity: 0;
1395
+ `;
1396
+ this.loader = document.createElement("div");
1397
+ this.loader.id = "loader";
1398
+ this.loader.innerHTML = `
1399
+ <div class="spinner">
1400
+ <svg
1401
+ viewBox="0 0 100 100"
1402
+ style="
1403
+ animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1404
+ display: block;
1405
+ width: 48px;
1406
+ height: 48px;
1407
+ "
1408
+ >
1409
+ <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1410
+ <circle
1411
+ fill="transparent"
1412
+ stroke="#5548D9"
1413
+ cx="50"
1414
+ cy="50"
1415
+ r="42"
1416
+ stroke-width="10px"
1417
+ stroke-linecap="round"
1418
+ style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1419
+ ></circle>
1420
+ </svg>
1421
+ </div>`;
1422
+ this.getRoot().appendChild(this.stylesheet);
1423
+ this.getRoot().appendChild(this.loader);
1423
1424
  }
1425
+ };
1426
+ FEAASLoader.observedAttributes = ["hidden"];
1427
+ FEAASLoader.register("feaas-loader");
1428
+
1429
+ // src/components/FEAASStylesheet.ts
1430
+ function FEAASStylesheetProps(element = this) {
1431
+ var _a;
1432
+ return {
1433
+ library: element == null ? void 0 : element.getContextAttribute("library"),
1434
+ revision: (_a = element == null ? void 0 : element.getAttribute("revision")) != null ? _a : "published",
1435
+ cdn: element == null ? void 0 : element.getContextAttribute("cdn")
1436
+ };
1424
1437
  }
1425
- @keyframes loader-circular-track {
1426
- 0% {
1427
- stroke-dasharray: 1, 400;
1428
- stroke-dashoffset: 0;
1438
+ var FEAASStylesheet = class extends FEAASBase {
1439
+ getProps() {
1440
+ return FEAASStylesheetProps(this);
1429
1441
  }
1430
- 50% {
1431
- stroke-dasharray: 400, 400;
1432
- stroke-dashoffset: -100;
1442
+ isReadyToLoad() {
1443
+ return this.props.library != null && this.props.revision != null && this.props.cdn != null;
1433
1444
  }
1434
- 100% {
1435
- stroke-dasharray: 400, 400;
1436
- stroke-dashoffset: -260;
1445
+ load() {
1446
+ return __async(this, null, function* () {
1447
+ fetchStylesheet(this.props, this.onLoad);
1448
+ });
1437
1449
  }
1438
- }
1439
-
1440
- @keyframes loader-circular-spinner {
1441
- 0% {
1442
- transform: rotate(0deg);
1450
+ render() {
1451
+ if (!this.stylesheet) {
1452
+ this.stylesheet = document.createElement("style");
1453
+ this.appendChild(this.stylesheet);
1454
+ }
1455
+ this.stylesheet.textContent = this.payload;
1443
1456
  }
1457
+ };
1458
+ FEAASStylesheet.register("feaas-stylesheet");
1444
1459
 
1445
- 100% {
1446
- transform: rotate(360deg);
1460
+ // src/components/FEAASComponent.ts
1461
+ function FEAASComponentsProps(element = this) {
1462
+ let data;
1463
+ const dataValue = element.getAttribute("data");
1464
+ if (dataValue != null) {
1465
+ try {
1466
+ data = typeof dataValue == "string" ? JSON.parse(dataValue) : {};
1467
+ } catch (e) {
1468
+ }
1447
1469
  }
1470
+ return {
1471
+ data: data != null ? data : {},
1472
+ library: element.getAttribute("library"),
1473
+ component: element.getAttribute("component"),
1474
+ version: element.getAttribute("version"),
1475
+ revision: element.getAttribute("revision"),
1476
+ hostname: element.getAttribute("hostname"),
1477
+ cdn: element.getContextAttribute("cdn"),
1478
+ template: element.getAttribute("template")
1479
+ };
1448
1480
  }
1449
- #loader .spinner {
1450
- animation: loader-disappearance 0.6s both;
1451
- width: 48px;
1452
- height: 48px;
1453
- }
1454
- #loader .spinner {
1455
- animation: loader-appearance 0.6s both;
1456
- }
1457
- `;
1458
- this.root = this.attachShadow({ mode: "open" });
1459
- this.loader = document.createElement("div");
1460
- this.loader.id = "loader";
1461
- this.loader.innerHTML = `
1462
- <div class="spinner">
1463
- <svg
1464
- viewBox="0 0 100 100"
1465
- style="
1466
- animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1467
- display: block;
1468
- width: 48px;
1469
- height: 48px;
1470
- "
1471
- >
1472
- <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1473
- <circle
1474
- fill="transparent"
1475
- stroke="#5548D9"
1476
- cx="50"
1477
- cy="50"
1478
- r="42"
1479
- stroke-width="10px"
1480
- stroke-linecap="round"
1481
- style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1482
- ></circle>
1483
- </svg>
1484
- </div>`;
1485
- this.shadowRoot.appendChild(this.stylesheet);
1486
- this.shadowRoot.appendChild(this.loader);
1481
+ var FEAASComponent = class extends FEAASBase {
1482
+ setData(data) {
1483
+ this.set({ data });
1487
1484
  }
1488
- };
1489
- if (typeof window != "undefined" && !window.customElements.get("feaas-stylesheet")) {
1490
- window.customElements.define("feaas-stylesheet", HTMLFeaasStylesheet);
1491
- window.customElements.define("feaas-component", HTMLFeaasComponent);
1492
- window.customElements.define("feaas-picker-lazy", HTMLFeaasPickerLazy);
1493
- if (!window.customElements.get("feaas-loader"))
1494
- window.customElements.define("feaas-loader", HTMLFeaasLoader);
1495
- }
1496
-
1497
- // src/react.ts
1498
- function Component(props) {
1499
- const [template, setTemplate] = import_react.default.useState("template" in props ? props.template : null);
1500
- const data = props.data;
1501
- const ref = import_react.default.useRef(null);
1502
- import_react.default.useEffect(
1503
- () => {
1504
- if (template == null && !("template" in props)) {
1505
- fetchComponent(props, setTemplate).catch(() => {
1506
- console.error(
1507
- `FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.version}/${props.revision}`
1508
- );
1509
- });
1485
+ getProps() {
1486
+ return FEAASComponentsProps(this);
1487
+ }
1488
+ attributeChangedCallback(name, oldValue, newValue) {
1489
+ this.payload = void 0;
1490
+ this.needsRefresh = true;
1491
+ super.attributeChangedCallback(name, oldValue, newValue);
1492
+ }
1493
+ getOriginal() {
1494
+ const scope = this.getAttribute("data-path-scope");
1495
+ if (!scope)
1496
+ return;
1497
+ for (var current = this; current = current.previousElementSibling; ) {
1498
+ if (current.getAttribute("data-path-scope") == scope) {
1499
+ var last = current;
1500
+ } else {
1501
+ break;
1510
1502
  }
1511
- },
1512
- "template" in props ? [props.template, null, null, null] : [props.library, props.component, props.version, props.revision, props.hostname]
1513
- );
1514
- import_react.default.useEffect(() => {
1515
- if (ref.current && template) {
1516
- ref.current.innerHTML = template;
1517
- }
1518
- }, [ref, template]);
1519
- import_react.default.useEffect(() => {
1520
- if (template && ref.current) {
1521
- renderDOMElement(ref.current, data || {}, props);
1522
1503
  }
1523
- }, [ref, template, data]);
1524
- return import_react.default.createElement("div", { ref, className: "-feaas" });
1525
- }
1526
- function Stylesheet(props) {
1527
- const ref = import_react.default.useRef(null);
1528
- const [css, setCss] = import_react.default.useState("");
1529
- import_react.default.useEffect(() => {
1530
- fetchStylesheet(props, setCss).catch((e) => {
1531
- console.error(`FEAAS: Could not fetch stylesheet for library ${props.library}`);
1504
+ return last;
1505
+ }
1506
+ isReadyToLoad() {
1507
+ return super.isReadyToLoad() && this.props.library != null && this.props.component != null && this.props.version != null;
1508
+ }
1509
+ load() {
1510
+ return __async(this, null, function* () {
1511
+ if (this.getOriginal()) {
1512
+ return;
1513
+ }
1514
+ try {
1515
+ fetchComponent(this.props, this.onLoad);
1516
+ } catch (e) {
1517
+ console.error(
1518
+ `FEAAS: Could not fetch component: ${this.props.component}/${this.props.version}/${this.props.revision}`
1519
+ );
1520
+ }
1532
1521
  });
1533
- }, [props.hostname, props.library]);
1534
- return import_react.default.createElement(
1535
- "style",
1536
- { ref, rel: "stylesheet", className: "-stylesheet", "data-library-id": props.library },
1537
- [css]
1538
- );
1539
- }
1540
- var react_default = __spreadProps(__spreadValues(__spreadValues({}, dom_exports), webcomponent_exports), {
1541
- Stylesheet,
1542
- Component
1543
- });
1522
+ }
1523
+ render() {
1524
+ if (Array.from(this.children).filter((c) => c.tagName != "BR").length > 0 && !this.needsRefresh) {
1525
+ renderDOMElement(this, this.props.data);
1526
+ } else {
1527
+ this.needsRefresh = true;
1528
+ if (this.getOriginal()) {
1529
+ return;
1530
+ }
1531
+ renderDOMContent(this, this.payload, this.props.data);
1532
+ }
1533
+ }
1534
+ };
1535
+ FEAASComponent.observedAttributes = ["library", "component", "version", "revision", "hostname", "cdn", "template", "data"];
1536
+ FEAASComponent.register("feaas-component");