@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
@@ -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,370 +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
- }
1164
+ this.set();
1210
1165
  }
1211
- update() {
1212
- renderDOMElement(this, this.getProps().data);
1213
- }
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: this.getAttribute("hostname") || void 0
1279
- };
1222
+ getComponentName() {
1223
+ return this.tagName.replace("FEAAS-", "").toLowerCase();
1280
1224
  }
1281
- };
1282
- var HTMLFeaasStylesheet = class extends WebComponent {
1283
- constructor() {
1284
- super(...arguments);
1285
- this.connected = false;
1225
+ isReadyToLoad() {
1226
+ return this.payload === void 0 && this.getAttribute("hidden") == null;
1286
1227
  }
1287
- static get observedAttributes() {
1288
- return ["library", "revision", "hostname"];
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
+ }
1236
+ });
1289
1237
  }
1290
- connectedCallback() {
1291
- this.connected = true;
1292
- this.render();
1238
+ load() {
1239
+ return Promise.resolve(null);
1293
1240
  }
1294
- attributeChangedCallback() {
1295
- if (this.connected)
1296
- this.render();
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
+ }
1297
1258
  }
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}`);
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")
1267
+ });
1304
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(<>{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();
1305
1306
  }
1306
- getProps() {
1307
- return {
1308
- library: this.getAttribute("library") || void 0,
1309
- revision: this.getAttribute("revision") || void 0,
1310
- hostname: this.getAttribute("hostname") || void 0
1311
- };
1312
- }
1313
- };
1314
- var HTMLFeaasPickerLazy = class extends WebComponent {
1315
- constructor() {
1316
- super(...arguments);
1317
- this.src = "https://components.sitecorecloud.io/assets/picker.js";
1318
- this.onClose = () => {
1319
- this.set({
1320
- mode: null
1321
- });
1322
- };
1323
- this.onScriptLoaded = () => {
1324
- this.element = document.createElement("feaas-picker");
1325
- this.element.style.cssText = "border: 0; width: 100%; height: 100%; display: block";
1326
- this.appendChild(this.element);
1327
- this.set(this.getProps());
1328
- };
1307
+ scheduleRender() {
1308
+ cancelAnimationFrame(this.nextRender);
1309
+ this.nextRender = requestAnimationFrame(() => {
1310
+ this.reify();
1311
+ });
1329
1312
  }
1330
- static get observedAttributes() {
1331
- return ["library", "mode", "hidden", "src"];
1313
+ formatURL(src, hostname) {
1314
+ if (typeof src == "string" && src.match(/\/[^\/]/)) {
1315
+ return hostname + src;
1316
+ } else {
1317
+ return src;
1318
+ }
1332
1319
  }
1333
- connectedCallback() {
1334
- this.loader = document.createElement("feaas-loader");
1335
- this.loader.style.cssText = "position: absolute; top: 0; left: 0; right: 0;bottom: 0; ";
1336
- this.appendChild(this.loader);
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);
1337
1323
  }
1338
- load() {
1339
- if (!this.script) {
1340
- this.script = document.createElement("script");
1341
- this.script.type = "module";
1342
- this.script.onload = this.onScriptLoaded;
1343
- this.script.src = this.src;
1344
- this.script.crossOrigin = "anonymous";
1345
- this.appendChild(this.script);
1324
+ static register(tagName) {
1325
+ if (!window.customElements.get(tagName)) {
1326
+ window.customElements.define(tagName, this);
1346
1327
  }
1347
1328
  }
1348
- getProps() {
1349
- return {
1350
- mode: this.getAttribute("mode"),
1351
- context: this.context,
1352
- library: this.getAttribute("library"),
1353
- src: this.getAttribute("src")
1354
- };
1355
- }
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 {
1356
1338
  attributeChangedCallback(name, oldValue, newValue) {
1357
- this.set(this.getProps());
1358
- }
1359
- set(options) {
1360
- Object.assign(this, options);
1361
- const keys = Object.keys(this.getProps());
1362
- for (var key of keys) {
1363
- const value = this[key];
1364
- if (value == null) {
1365
- this.removeAttribute(key);
1366
- } else if (this.getAttribute(key) != String(value)) {
1367
- 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";
1368
1348
  }
1369
1349
  }
1370
- if (this.mode) {
1371
- this.removeAttribute("hidden");
1372
- } else if (this.getAttribute("hidden") == null) {
1373
- 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;
1374
1371
  }
1375
- if (this.mode && !this.hidden) {
1376
- this.load();
1372
+ 50% {
1373
+ stroke-dasharray: 400, 400;
1374
+ stroke-dashoffset: -100;
1377
1375
  }
1378
- if (this.element && this.element.set) {
1379
- this.element.onClose = this.onClose;
1380
- this.element.getToken = this.getToken;
1381
- this.element.set(options);
1376
+ 100% {
1377
+ stroke-dasharray: 400, 400;
1378
+ stroke-dashoffset: -260;
1382
1379
  }
1383
1380
  }
1384
- };
1385
- var HTMLFeaasLoader = class extends WebComponent {
1386
- static get observedAttributes() {
1387
- return ["hidden"];
1381
+
1382
+ @keyframes loader-circular-spinner {
1383
+ 0% {
1384
+ transform: rotate(0deg);
1385
+ }
1386
+
1387
+ 100% {
1388
+ transform: rotate(360deg);
1389
+ }
1388
1390
  }
1389
- connectedCallback() {
1390
- this.style.opacity = "1";
1391
- this.style.transition = "opacity 0.2s 0.6s";
1392
- this.stylesheet = document.createElement("style");
1393
- this.stylesheet.textContent = `
1394
- #loader {
1395
- position: absolute;
1396
- top: 0;
1397
- left: 0;
1398
- right: 0;
1399
- bottom: 0;
1400
- display: flex;
1401
- align-items: center;
1402
- justify-content: center;
1403
- background: #f6f6ff;
1404
- z-index: 1000;
1405
- opacity: 1;
1406
- transition: top 0.3s, background-color 0.7s 0.3s;
1407
- }
1408
- @keyframes loader-disappearance {
1409
- 100% {
1410
- opacity: 0;
1391
+ #loader .spinner {
1392
+ width: 48px;
1393
+ height: 48px;
1411
1394
  }
1412
- }
1413
- @keyframes loader-appearance {
1414
- 0% {
1415
- 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);
1416
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
+ };
1417
1437
  }
1418
- @keyframes loader-circular-track {
1419
- 0% {
1420
- stroke-dasharray: 1, 400;
1421
- stroke-dashoffset: 0;
1438
+ var FEAASStylesheet = class extends FEAASBase {
1439
+ getProps() {
1440
+ return FEAASStylesheetProps(this);
1422
1441
  }
1423
- 50% {
1424
- stroke-dasharray: 400, 400;
1425
- stroke-dashoffset: -100;
1442
+ isReadyToLoad() {
1443
+ return this.props.library != null && this.props.revision != null && this.props.cdn != null;
1426
1444
  }
1427
- 100% {
1428
- stroke-dasharray: 400, 400;
1429
- stroke-dashoffset: -260;
1445
+ load() {
1446
+ return __async(this, null, function* () {
1447
+ fetchStylesheet(this.props, this.onLoad);
1448
+ });
1430
1449
  }
1431
- }
1432
-
1433
- @keyframes loader-circular-spinner {
1434
- 0% {
1435
- 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;
1436
1456
  }
1457
+ };
1458
+ FEAASStylesheet.register("feaas-stylesheet");
1437
1459
 
1438
- 100% {
1439
- 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
+ }
1440
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
+ };
1441
1480
  }
1442
- #loader .spinner {
1443
- animation: loader-disappearance 0.6s both;
1444
- width: 48px;
1445
- height: 48px;
1446
- }
1447
- #loader .spinner {
1448
- animation: loader-appearance 0.6s both;
1449
- }
1450
- `;
1451
- this.root = this.attachShadow({ mode: "open" });
1452
- this.loader = document.createElement("div");
1453
- this.loader.id = "loader";
1454
- this.loader.innerHTML = `
1455
- <div class="spinner">
1456
- <svg
1457
- viewBox="0 0 100 100"
1458
- style="
1459
- animation: 2s linear 0s infinite normal none running loader-circular-spinner;
1460
- display: block;
1461
- width: 48px;
1462
- height: 48px;
1463
- "
1464
- >
1465
- <circle fill="transparent" cx="50" cy="50" r="42" stroke="rgba(0,0,0,0.1)" stroke-width="10px"></circle>
1466
- <circle
1467
- fill="transparent"
1468
- stroke="#5548D9"
1469
- cx="50"
1470
- cy="50"
1471
- r="42"
1472
- stroke-width="10px"
1473
- stroke-linecap="round"
1474
- style="animation: 1.5s linear 0s infinite normal none running loader-circular-track"
1475
- ></circle>
1476
- </svg>
1477
- </div>`;
1478
- this.shadowRoot.appendChild(this.stylesheet);
1479
- this.shadowRoot.appendChild(this.loader);
1481
+ var FEAASComponent = class extends FEAASBase {
1482
+ setData(data) {
1483
+ this.set({ data });
1480
1484
  }
1481
- };
1482
- if (typeof window != "undefined" && !window.customElements.get("feaas-stylesheet")) {
1483
- window.customElements.define("feaas-stylesheet", HTMLFeaasStylesheet);
1484
- window.customElements.define("feaas-component", HTMLFeaasComponent);
1485
- window.customElements.define("feaas-picker-lazy", HTMLFeaasPickerLazy);
1486
- window.customElements.define("feaas-loader", HTMLFeaasLoader);
1487
- }
1488
-
1489
- // src/react.ts
1490
- function Component(props) {
1491
- const [template, setTemplate] = import_react.default.useState("template" in props ? props.template : null);
1492
- const data = props.data;
1493
- const ref = import_react.default.useRef(null);
1494
- import_react.default.useEffect(
1495
- () => {
1496
- if (template == null && !("template" in props)) {
1497
- fetchComponent(props, setTemplate).catch(() => {
1498
- console.error(
1499
- `FEAAS: Could not fetch component: ${props.library}/${props.component}/${props.version}/${props.revision}`
1500
- );
1501
- });
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;
1502
1502
  }
1503
- },
1504
- "template" in props ? [props.template, null, null, null] : [props.library, props.component, props.version, props.revision, props.hostname]
1505
- );
1506
- import_react.default.useEffect(() => {
1507
- if (ref.current && template) {
1508
- ref.current.innerHTML = template;
1509
- }
1510
- }, [ref, template]);
1511
- import_react.default.useEffect(() => {
1512
- if (template && ref.current) {
1513
- renderDOMElement(ref.current, data || {}, props);
1514
1503
  }
1515
- }, [ref, template, data]);
1516
- return import_react.default.createElement("div", { ref, className: "-feaas" });
1517
- }
1518
- function Stylesheet(props) {
1519
- const ref = import_react.default.useRef(null);
1520
- const [css, setCss] = import_react.default.useState("");
1521
- import_react.default.useEffect(() => {
1522
- fetchStylesheet(props, setCss).catch((e) => {
1523
- 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
+ }
1524
1521
  });
1525
- }, [props.hostname, props.library]);
1526
- return import_react.default.createElement(
1527
- "style",
1528
- { ref, rel: "stylesheet", className: "-stylesheet", "data-library-id": props.library },
1529
- [css]
1530
- );
1531
- }
1532
- var react_default = __spreadProps(__spreadValues(__spreadValues({}, dom_exports), webcomponent_exports), {
1533
- Stylesheet,
1534
- Component
1535
- });
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");