@pronto-tools-and-more/files 8.21.0 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,10 +76,127 @@ const updateCssError = (errorColor, css) => {
76
76
  document.body.append(error);
77
77
  };
78
78
 
79
+ let loading;
80
+
81
+ const removeLoading = () => {
82
+ if (!loading) {
83
+ return;
84
+ }
85
+ loading.remove();
86
+ loading = undefined;
87
+ };
88
+
89
+ const updateViewsLoading = () => {
90
+ removeLoading();
91
+ loading = document.createElement("div");
92
+ loading.className = "pronto-views-loading";
93
+ const loadingColor = "lime";
94
+ loading.style.position = "fixed";
95
+ loading.style.top = "0";
96
+ loading.style.right = "0";
97
+ loading.style.width = "20px";
98
+ loading.style.height = "20px";
99
+ loading.style.background = `radial-gradient(${loadingColor}, transparent)`;
100
+ loading.style.zIndex = "11111111";
101
+ loading.style.display = "flex";
102
+ document.body.append(loading);
103
+ };
104
+
105
+ let frame;
106
+
107
+ const waitForIdle = (window) => {
108
+ return new Promise((resolve) => {
109
+ window.requestIdleCallback(resolve);
110
+ });
111
+ };
112
+
113
+ const waitForFrameReallyToLoad = async (currentFrame) => {
114
+ const maxWait = 10000;
115
+ const end = performance.now() + maxWait;
116
+ while (performance.now() < end) {
117
+ const { contentWindow } = currentFrame;
118
+ await waitForIdle(contentWindow);
119
+ contentWindow.document.documentElement.scrollTop =
120
+ document.documentElement.scrollTop;
121
+ const hasRoot =
122
+ contentWindow.document.body.querySelector("storefront-root");
123
+ const hasPurple = contentWindow.purple;
124
+ const hasView =
125
+ contentWindow.document.body.querySelector("storefront-view");
126
+ const hasCustomCss = contentWindow.document.body.querySelector(
127
+ 'link[href="assets/custom.css"]'
128
+ );
129
+ const hasDeviceType =
130
+ contentWindow.document.body.dataset.storefrontDevice_type;
131
+ if (hasRoot && hasPurple && hasView && hasCustomCss && hasDeviceType) {
132
+ await waitForIdle(contentWindow);
133
+ await waitForIdle(contentWindow);
134
+ await waitForIdle(contentWindow);
135
+ return true;
136
+ }
137
+ }
138
+ return false;
139
+ };
140
+
141
+ const handleFrameLoad = async (event) => {
142
+ if (event.target !== frame) {
143
+ return;
144
+ }
145
+
146
+ const hasLoaded = await waitForFrameReallyToLoad(frame);
147
+ if (!hasLoaded) {
148
+ console.info("[pronto] iframe did not load");
149
+ // TODO hard reload?
150
+ return;
151
+ }
152
+ const toRemove = [];
153
+ for (const node of document.body.childNodes) {
154
+ if (node !== frame && node.nodeName !== "LINK") {
155
+ toRemove.push(node);
156
+ }
157
+ }
158
+ for (const node of toRemove) {
159
+ node.remove();
160
+ }
161
+ const toAdd = [];
162
+ for (const node of frame.contentWindow.document.body.childNodes) {
163
+ if (node.nodeName !== "LINK") {
164
+ toAdd.push(node);
165
+ }
166
+ }
167
+ document.body.prepend(...toAdd);
168
+ // frame.remove();
169
+ frame = undefined;
170
+ };
171
+
172
+ const updateViews = () => {
173
+ updateViewsLoading();
174
+ if (frame) {
175
+ frame.remove();
176
+ frame = undefined;
177
+ }
178
+ const currentFrame = document.createElement("iframe");
179
+ frame = currentFrame;
180
+ currentFrame.addEventListener("load", handleFrameLoad);
181
+ currentFrame.src = location.href;
182
+ const width = window.innerWidth;
183
+ const height = window.innerHeight;
184
+ currentFrame.style.background = "blue";
185
+ currentFrame.style.display = "block";
186
+ currentFrame.style.visibility = "hidden";
187
+ currentFrame.width = `${width}`;
188
+ currentFrame.height = `${height}`;
189
+ currentFrame.style.position = "fixed";
190
+ currentFrame.style.bottom = "0";
191
+ currentFrame.style.right = "0";
192
+ document.body.append(currentFrame);
193
+ };
194
+
79
195
  const commandMap = {
80
196
  reload,
81
197
  updateCss,
82
198
  updateCssError,
199
+ updateViews,
83
200
  };
84
201
 
85
202
  const getCommand = (method) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/files",
3
- "version": "8.21.0",
3
+ "version": "9.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {},
@@ -1 +0,0 @@
1
- [{"id":"default","logo":false,"scrollBehavior":"none","content":{"content":[{"name":"template-main-app-bar","type":"view"},{"name":"template-app-bar-menus","type":"view"},{"dataSource":{"type":"menu","filter":{"name":{"value":"burger-menu"}}},"type":"menu","class":"menu-side","id":"menu-side","actions":[{"content":{"mode":"once","type":"action-executor"},"name":"close"}],"template":"SLIDE_IN_LEFT"}],"type":"section","class":"header-section"}},{"id":"article","logo":false,"scrollBehavior":"none","content":{"content":[{"name":"template-article-app-bar","type":"view"},{"content":[{"content":[{"dataSource":{"type":"menu","filter":{"name":{"value":"menu-ressorts"}},"contextKey":"menu-ressorts"},"type":"menu","class":"$functions.handleAppBarMenu($global.menu_ressorts[0].items, $context.ressort)","template":"STATIC","id":"menu-ressorts"}],"type":"section","class":"main-menu"}],"type":"section","id":"app-bar-menus","sticky":true}],"type":"section","class":"header-section"}},{"id":"back","logo":false,"scrollBehavior":"none","content":{"content":[{"name":"template-main-app-bar","type":"view"},{"dataSource":{"type":"menu","filter":{"name":{"value":"menu-burger-web"}}},"type":"menu","class":"menu-side","id":"menu-side","actions":[{"content":{"mode":"once","type":"action-executor"},"name":"close"}]}],"type":"section","class":"header-section"},"leftButton":"back"},{"id":"default-with-menus","logo":false,"scrollBehavior":"none","content":{"content":[{"name":"template-main-app-bar","type":"view"},{"name":"init-view","type":"view"},{"dataSource":{"type":"menu","filter":{"name":{"value":"menu-burger-web"}}},"type":"menu","class":"menu-side","id":"menu-side","actions":[{"content":{"mode":"once","type":"action-executor"},"name":"close"}]}],"type":"section","class":"header-section"},"leftButton":"menu"},{"id":"close","logo":false,"scrollBehavior":"none","content":{"type":"toolbar","actions":[{"iconUrl":"","type":"close"}]}},{"id":"foobar","logo":false,"scrollBehavior":"none","content":{"content":[{"name":"template-main-app-bar","type":"view"},{"name":"template-app-bar-menus","type":"view"}],"type":"section","class":"header-section"}}]