@jsenv/plugin-toolbar 0.1.13 → 0.1.15
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.
- package/dist/html/toolbar.html +5 -4
- package/dist/jsenv_plugin_toolbar.js +30 -7
- package/package.json +3 -3
- package/src/client/core/animation_actions.js +5 -5
- package/src/client/core/animation_effects.js +6 -6
- package/src/client/core/animation_signals.js +4 -4
- package/src/client/core/changes_actions.js +5 -5
- package/src/client/core/changes_signals.js +2 -2
- package/src/client/core/execution_actions.js +16 -16
- package/src/client/core/execution_effects.js +10 -10
- package/src/client/core/execution_signals.js +6 -6
- package/src/client/core/notification_actions.js +31 -31
- package/src/client/core/notification_context.js +2 -1
- package/src/client/core/notification_effects.js +6 -6
- package/src/client/core/notification_signals.js +5 -5
- package/src/client/core/parent_window_actions.js +18 -18
- package/src/client/core/parent_window_context.js +5 -5
- package/src/client/core/parent_window_effects.js +9 -9
- package/src/client/core/parent_window_signals.js +17 -17
- package/src/client/core/server_actions.js +5 -5
- package/src/client/core/server_effects.js +6 -6
- package/src/client/core/server_signals.js +7 -7
- package/src/client/core/settings_actions.js +5 -5
- package/src/client/core/settings_signals.js +2 -2
- package/src/client/core/theme_actions.js +5 -5
- package/src/client/core/theme_effects.js +5 -5
- package/src/client/core/theme_signals.js +4 -4
- package/src/client/core/toolbar_logger.js +8 -8
- package/src/client/core/toolbar_open_actions.js +5 -5
- package/src/client/core/toolbar_open_effects.js +4 -4
- package/src/client/core/toolbar_open_signals.js +4 -4
- package/src/client/core/toolbar_state_context.js +1 -1
- package/src/client/core/toolbar_state_effects.js +7 -7
- package/src/client/core/toolbar_state_signals.js +11 -11
- package/src/client/core/tooltip_actions.js +5 -5
- package/src/client/toolbar_core.js +8 -8
- package/src/client/toolbar_injector.js +97 -97
- package/src/client/ui/changes_indicator/changes_indicator.js +33 -33
- package/src/client/ui/document_execution_indicator/document_execution_indicator.js +28 -28
- package/src/client/ui/document_index_link/document_index_link.js +3 -3
- package/src/client/ui/server_indicator/server_indicator.js +30 -30
- package/src/client/ui/toolbar_close_button/toolbar_close_button.js +6 -6
- package/src/client/ui/toolbar_menu_overflow/toolbar_menu_overflow.js +50 -50
- package/src/client/ui/toolbar_opening/toolbar_opening.js +35 -35
- package/src/client/ui/toolbar_overlay/toolbar_overlay.js +36 -36
- package/src/client/ui/toolbar_settings/toolbar_animation_setting.js +13 -13
- package/src/client/ui/toolbar_settings/toolbar_autoreload_setting.js +19 -19
- package/src/client/ui/toolbar_settings/toolbar_notification_setting.js +47 -47
- package/src/client/ui/toolbar_settings/toolbar_settings.js +29 -29
- package/src/client/ui/toolbar_settings/toolbar_theme_setting.js +8 -8
- package/src/client/ui/toolbar_ui.js +19 -19
- package/src/client/ui/util/animation.js +116 -116
- package/src/client/ui/util/dom.js +29 -29
- package/src/client/ui/util/fetch_using_xhr.js +184 -184
- package/src/client/ui/util/fetching.js +6 -6
- package/src/client/ui/util/iframe_to_parent_href.js +6 -6
- package/src/client/ui/util/responsive.js +48 -48
- package/src/client/ui/util/util.js +13 -13
- package/src/client/ui/variant.js +27 -27
- package/src/jsenv_plugin_toolbar.js +55 -30
|
@@ -8,161 +8,161 @@ export const fetchUsingXHR = async (
|
|
|
8
8
|
body = null,
|
|
9
9
|
} = {},
|
|
10
10
|
) => {
|
|
11
|
-
const headersPromise = createPromiseAndHooks()
|
|
12
|
-
const bodyPromise = createPromiseAndHooks()
|
|
11
|
+
const headersPromise = createPromiseAndHooks();
|
|
12
|
+
const bodyPromise = createPromiseAndHooks();
|
|
13
13
|
|
|
14
|
-
const xhr = new XMLHttpRequest()
|
|
14
|
+
const xhr = new XMLHttpRequest();
|
|
15
15
|
|
|
16
16
|
const failure = (error) => {
|
|
17
17
|
// if it was already resolved, we must reject the body promise
|
|
18
18
|
if (headersPromise.settled) {
|
|
19
|
-
bodyPromise.reject(error)
|
|
19
|
+
bodyPromise.reject(error);
|
|
20
20
|
} else {
|
|
21
|
-
headersPromise.reject(error)
|
|
21
|
+
headersPromise.reject(error);
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
|
|
25
25
|
const cleanup = () => {
|
|
26
|
-
xhr.ontimeout = null
|
|
27
|
-
xhr.onerror = null
|
|
28
|
-
xhr.onload = null
|
|
29
|
-
xhr.onreadystatechange = null
|
|
30
|
-
}
|
|
26
|
+
xhr.ontimeout = null;
|
|
27
|
+
xhr.onerror = null;
|
|
28
|
+
xhr.onload = null;
|
|
29
|
+
xhr.onreadystatechange = null;
|
|
30
|
+
};
|
|
31
31
|
|
|
32
32
|
xhr.ontimeout = () => {
|
|
33
|
-
cleanup()
|
|
34
|
-
failure(new Error(`xhr request timeout on ${url}.`))
|
|
35
|
-
}
|
|
33
|
+
cleanup();
|
|
34
|
+
failure(new Error(`xhr request timeout on ${url}.`));
|
|
35
|
+
};
|
|
36
36
|
|
|
37
37
|
xhr.onerror = (error) => {
|
|
38
|
-
cleanup()
|
|
38
|
+
cleanup();
|
|
39
39
|
// unfortunately with have no clue why it fails
|
|
40
40
|
// might be cors for instance
|
|
41
|
-
failure(createRequestError(error, { url }))
|
|
42
|
-
}
|
|
41
|
+
failure(createRequestError(error, { url }));
|
|
42
|
+
};
|
|
43
43
|
|
|
44
44
|
xhr.onload = () => {
|
|
45
|
-
cleanup()
|
|
46
|
-
bodyPromise.resolve()
|
|
47
|
-
}
|
|
45
|
+
cleanup();
|
|
46
|
+
bodyPromise.resolve();
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
signal.addEventListener("abort", () => {
|
|
50
|
-
xhr.abort()
|
|
51
|
-
const abortError = new Error("aborted")
|
|
52
|
-
abortError.name = "AbortError"
|
|
53
|
-
failure(abortError)
|
|
54
|
-
})
|
|
50
|
+
xhr.abort();
|
|
51
|
+
const abortError = new Error("aborted");
|
|
52
|
+
abortError.name = "AbortError";
|
|
53
|
+
failure(abortError);
|
|
54
|
+
});
|
|
55
55
|
|
|
56
56
|
xhr.onreadystatechange = () => {
|
|
57
57
|
// https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/readyState
|
|
58
|
-
const { readyState } = xhr
|
|
58
|
+
const { readyState } = xhr;
|
|
59
59
|
|
|
60
60
|
if (readyState === 2) {
|
|
61
|
-
headersPromise.resolve()
|
|
61
|
+
headersPromise.resolve();
|
|
62
62
|
} else if (readyState === 4) {
|
|
63
|
-
cleanup()
|
|
64
|
-
bodyPromise.resolve()
|
|
63
|
+
cleanup();
|
|
64
|
+
bodyPromise.resolve();
|
|
65
65
|
}
|
|
66
|
-
}
|
|
66
|
+
};
|
|
67
67
|
|
|
68
|
-
xhr.open(method, url, true)
|
|
68
|
+
xhr.open(method, url, true);
|
|
69
69
|
Object.keys(headers).forEach((key) => {
|
|
70
|
-
xhr.setRequestHeader(key, headers[key])
|
|
71
|
-
})
|
|
72
|
-
xhr.withCredentials = computeWithCredentials({ credentials, url })
|
|
70
|
+
xhr.setRequestHeader(key, headers[key]);
|
|
71
|
+
});
|
|
72
|
+
xhr.withCredentials = computeWithCredentials({ credentials, url });
|
|
73
73
|
if ("responseType" in xhr && hasBlob) {
|
|
74
|
-
xhr.responseType = "blob"
|
|
74
|
+
xhr.responseType = "blob";
|
|
75
75
|
}
|
|
76
|
-
xhr.send(body)
|
|
76
|
+
xhr.send(body);
|
|
77
77
|
|
|
78
|
-
await headersPromise
|
|
78
|
+
await headersPromise;
|
|
79
79
|
|
|
80
80
|
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL
|
|
81
81
|
const responseUrl =
|
|
82
|
-
"responseURL" in xhr ? xhr.responseURL : headers["x-request-url"]
|
|
83
|
-
let responseStatus = xhr.status
|
|
84
|
-
const responseStatusText = xhr.statusText
|
|
85
|
-
const responseHeaders = getHeadersFromXHR(xhr)
|
|
82
|
+
"responseURL" in xhr ? xhr.responseURL : headers["x-request-url"];
|
|
83
|
+
let responseStatus = xhr.status;
|
|
84
|
+
const responseStatusText = xhr.statusText;
|
|
85
|
+
const responseHeaders = getHeadersFromXHR(xhr);
|
|
86
86
|
|
|
87
87
|
const readBody = async () => {
|
|
88
|
-
await bodyPromise
|
|
88
|
+
await bodyPromise;
|
|
89
89
|
|
|
90
|
-
const { status } = xhr
|
|
90
|
+
const { status } = xhr;
|
|
91
91
|
// in Chrome on file:/// URLs, status is 0
|
|
92
92
|
if (status === 0) {
|
|
93
|
-
responseStatus = 200
|
|
93
|
+
responseStatus = 200;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
const body = "response" in xhr ? xhr.response : xhr.responseText
|
|
96
|
+
const body = "response" in xhr ? xhr.response : xhr.responseText;
|
|
97
97
|
|
|
98
98
|
return {
|
|
99
99
|
responseBody: body,
|
|
100
100
|
responseBodyType: detectBodyType(body),
|
|
101
|
-
}
|
|
102
|
-
}
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
103
|
|
|
104
104
|
const text = async () => {
|
|
105
|
-
const { responseBody, responseBodyType } = await readBody()
|
|
105
|
+
const { responseBody, responseBodyType } = await readBody();
|
|
106
106
|
|
|
107
107
|
if (responseBodyType === "blob") {
|
|
108
|
-
return blobToText(responseBody)
|
|
108
|
+
return blobToText(responseBody);
|
|
109
109
|
}
|
|
110
110
|
if (responseBodyType === "formData") {
|
|
111
|
-
throw new Error("could not read FormData body as text")
|
|
111
|
+
throw new Error("could not read FormData body as text");
|
|
112
112
|
}
|
|
113
113
|
if (responseBodyType === "dataView") {
|
|
114
|
-
return arrayBufferToText(responseBody.buffer)
|
|
114
|
+
return arrayBufferToText(responseBody.buffer);
|
|
115
115
|
}
|
|
116
116
|
if (responseBodyType === "arrayBuffer") {
|
|
117
|
-
return arrayBufferToText(responseBody)
|
|
117
|
+
return arrayBufferToText(responseBody);
|
|
118
118
|
}
|
|
119
|
-
return String(responseBody)
|
|
120
|
-
}
|
|
119
|
+
return String(responseBody);
|
|
120
|
+
};
|
|
121
121
|
|
|
122
122
|
const json = async () => {
|
|
123
|
-
const responseText = await text()
|
|
124
|
-
return JSON.parse(responseText)
|
|
125
|
-
}
|
|
123
|
+
const responseText = await text();
|
|
124
|
+
return JSON.parse(responseText);
|
|
125
|
+
};
|
|
126
126
|
|
|
127
127
|
const blob = async () => {
|
|
128
128
|
if (!hasBlob) {
|
|
129
|
-
throw new Error(`blob not supported`)
|
|
129
|
+
throw new Error(`blob not supported`);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
const { responseBody, responseBodyType } = await readBody()
|
|
132
|
+
const { responseBody, responseBodyType } = await readBody();
|
|
133
133
|
|
|
134
134
|
if (responseBodyType === "blob") {
|
|
135
|
-
return responseBody
|
|
135
|
+
return responseBody;
|
|
136
136
|
}
|
|
137
137
|
if (responseBodyType === "dataView") {
|
|
138
|
-
return new Blob([cloneBuffer(responseBody.buffer)])
|
|
138
|
+
return new Blob([cloneBuffer(responseBody.buffer)]);
|
|
139
139
|
}
|
|
140
140
|
if (responseBodyType === "arrayBuffer") {
|
|
141
|
-
return new Blob([cloneBuffer(responseBody)])
|
|
141
|
+
return new Blob([cloneBuffer(responseBody)]);
|
|
142
142
|
}
|
|
143
143
|
if (responseBodyType === "formData") {
|
|
144
|
-
throw new Error("could not read FormData body as blob")
|
|
144
|
+
throw new Error("could not read FormData body as blob");
|
|
145
145
|
}
|
|
146
|
-
return new Blob([String(responseBody)])
|
|
147
|
-
}
|
|
146
|
+
return new Blob([String(responseBody)]);
|
|
147
|
+
};
|
|
148
148
|
|
|
149
149
|
const arrayBuffer = async () => {
|
|
150
|
-
const { responseBody, responseBodyType } = await readBody()
|
|
150
|
+
const { responseBody, responseBodyType } = await readBody();
|
|
151
151
|
|
|
152
152
|
if (responseBodyType === "arrayBuffer") {
|
|
153
|
-
return cloneBuffer(responseBody)
|
|
153
|
+
return cloneBuffer(responseBody);
|
|
154
154
|
}
|
|
155
|
-
const responseBlob = await blob()
|
|
156
|
-
return blobToArrayBuffer(responseBlob)
|
|
157
|
-
}
|
|
155
|
+
const responseBlob = await blob();
|
|
156
|
+
return blobToArrayBuffer(responseBlob);
|
|
157
|
+
};
|
|
158
158
|
|
|
159
159
|
const formData = async () => {
|
|
160
160
|
if (!hasFormData) {
|
|
161
|
-
throw new Error(`formData not supported`)
|
|
161
|
+
throw new Error(`formData not supported`);
|
|
162
162
|
}
|
|
163
|
-
const responseText = await text()
|
|
164
|
-
return textToFormData(responseText)
|
|
165
|
-
}
|
|
163
|
+
const responseText = await text();
|
|
164
|
+
return textToFormData(responseText);
|
|
165
|
+
};
|
|
166
166
|
|
|
167
167
|
return {
|
|
168
168
|
url: responseUrl,
|
|
@@ -174,146 +174,146 @@ export const fetchUsingXHR = async (
|
|
|
174
174
|
blob,
|
|
175
175
|
arrayBuffer,
|
|
176
176
|
formData,
|
|
177
|
-
}
|
|
178
|
-
}
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
179
|
|
|
180
180
|
const canUseBlob = () => {
|
|
181
|
-
if (typeof window.FileReader !== "function") return false
|
|
181
|
+
if (typeof window.FileReader !== "function") return false;
|
|
182
182
|
|
|
183
|
-
if (typeof window.Blob !== "function") return false
|
|
183
|
+
if (typeof window.Blob !== "function") return false;
|
|
184
184
|
|
|
185
185
|
try {
|
|
186
186
|
// eslint-disable-next-line no-new
|
|
187
|
-
new Blob()
|
|
188
|
-
return true
|
|
187
|
+
new Blob();
|
|
188
|
+
return true;
|
|
189
189
|
} catch (e) {
|
|
190
|
-
return false
|
|
190
|
+
return false;
|
|
191
191
|
}
|
|
192
|
-
}
|
|
192
|
+
};
|
|
193
193
|
|
|
194
|
-
const hasBlob = canUseBlob()
|
|
194
|
+
const hasBlob = canUseBlob();
|
|
195
195
|
|
|
196
|
-
const hasFormData = typeof window.FormData === "function"
|
|
196
|
+
const hasFormData = typeof window.FormData === "function";
|
|
197
197
|
|
|
198
|
-
const hasArrayBuffer = typeof window.ArrayBuffer === "function"
|
|
198
|
+
const hasArrayBuffer = typeof window.ArrayBuffer === "function";
|
|
199
199
|
|
|
200
|
-
const hasSearchParams = typeof window.URLSearchParams === "function"
|
|
200
|
+
const hasSearchParams = typeof window.URLSearchParams === "function";
|
|
201
201
|
|
|
202
202
|
const createRequestError = (error, { url }) => {
|
|
203
203
|
return new Error(
|
|
204
204
|
`error during xhr request on ${url}.
|
|
205
205
|
--- error stack ---
|
|
206
206
|
${error.stack}`,
|
|
207
|
-
)
|
|
208
|
-
}
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
209
|
|
|
210
210
|
const createPromiseAndHooks = () => {
|
|
211
|
-
let resolve
|
|
212
|
-
let reject
|
|
211
|
+
let resolve;
|
|
212
|
+
let reject;
|
|
213
213
|
const promise = new Promise((res, rej) => {
|
|
214
214
|
resolve = (value) => {
|
|
215
|
-
promise.settled = true
|
|
216
|
-
res(value)
|
|
217
|
-
}
|
|
215
|
+
promise.settled = true;
|
|
216
|
+
res(value);
|
|
217
|
+
};
|
|
218
218
|
reject = (value) => {
|
|
219
|
-
promise.settled = true
|
|
220
|
-
rej(value)
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
promise.resolve = resolve
|
|
224
|
-
promise.reject = reject
|
|
225
|
-
return promise
|
|
226
|
-
}
|
|
219
|
+
promise.settled = true;
|
|
220
|
+
rej(value);
|
|
221
|
+
};
|
|
222
|
+
});
|
|
223
|
+
promise.resolve = resolve;
|
|
224
|
+
promise.reject = reject;
|
|
225
|
+
return promise;
|
|
226
|
+
};
|
|
227
227
|
|
|
228
228
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
|
|
229
229
|
const computeWithCredentials = ({ credentials, url }) => {
|
|
230
230
|
if (credentials === "same-origin") {
|
|
231
|
-
return originSameAsGlobalOrigin(url)
|
|
231
|
+
return originSameAsGlobalOrigin(url);
|
|
232
232
|
}
|
|
233
|
-
return credentials === "include"
|
|
234
|
-
}
|
|
233
|
+
return credentials === "include";
|
|
234
|
+
};
|
|
235
235
|
|
|
236
236
|
const originSameAsGlobalOrigin = (url) => {
|
|
237
237
|
// if we cannot read globalOrigin from window.location.origin, let's consider it's ok
|
|
238
|
-
if (typeof window !== "object") return true
|
|
239
|
-
if (typeof window.location !== "object") return true
|
|
240
|
-
const globalOrigin = window.location.origin
|
|
241
|
-
if (globalOrigin === "null") return true
|
|
242
|
-
return hrefToOrigin(url) === globalOrigin
|
|
243
|
-
}
|
|
238
|
+
if (typeof window !== "object") return true;
|
|
239
|
+
if (typeof window.location !== "object") return true;
|
|
240
|
+
const globalOrigin = window.location.origin;
|
|
241
|
+
if (globalOrigin === "null") return true;
|
|
242
|
+
return hrefToOrigin(url) === globalOrigin;
|
|
243
|
+
};
|
|
244
244
|
|
|
245
245
|
const detectBodyType = (body) => {
|
|
246
246
|
if (!body) {
|
|
247
|
-
return ""
|
|
247
|
+
return "";
|
|
248
248
|
}
|
|
249
249
|
if (typeof body === "string") {
|
|
250
|
-
return "text"
|
|
250
|
+
return "text";
|
|
251
251
|
}
|
|
252
252
|
if (hasBlob && Blob.prototype.isPrototypeOf(body)) {
|
|
253
|
-
return "blob"
|
|
253
|
+
return "blob";
|
|
254
254
|
}
|
|
255
255
|
if (hasFormData && FormData.prototype.isPrototypeOf(body)) {
|
|
256
|
-
return "formData"
|
|
256
|
+
return "formData";
|
|
257
257
|
}
|
|
258
258
|
if (hasArrayBuffer) {
|
|
259
259
|
if (hasBlob && isDataView(body)) {
|
|
260
|
-
return `dataView
|
|
260
|
+
return `dataView`;
|
|
261
261
|
}
|
|
262
262
|
if (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body)) {
|
|
263
|
-
return `arrayBuffer
|
|
263
|
+
return `arrayBuffer`;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
if (hasSearchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
267
|
-
return "searchParams"
|
|
267
|
+
return "searchParams";
|
|
268
268
|
}
|
|
269
|
-
return ""
|
|
270
|
-
}
|
|
269
|
+
return "";
|
|
270
|
+
};
|
|
271
271
|
|
|
272
272
|
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
273
273
|
const getHeadersFromXHR = (xhr) => {
|
|
274
|
-
const headerMap = {}
|
|
274
|
+
const headerMap = {};
|
|
275
275
|
|
|
276
|
-
const headersString = xhr.getAllResponseHeaders()
|
|
277
|
-
if (headersString === "") return headerMap
|
|
276
|
+
const headersString = xhr.getAllResponseHeaders();
|
|
277
|
+
if (headersString === "") return headerMap;
|
|
278
278
|
|
|
279
|
-
const lines = headersString.trim().split(/[\r\n]+/)
|
|
279
|
+
const lines = headersString.trim().split(/[\r\n]+/);
|
|
280
280
|
lines.forEach((line) => {
|
|
281
|
-
const parts = line.split(": ")
|
|
282
|
-
const name = parts.shift()
|
|
283
|
-
const value = parts.join(": ")
|
|
284
|
-
headerMap[name.toLowerCase()] = value
|
|
285
|
-
})
|
|
281
|
+
const parts = line.split(": ");
|
|
282
|
+
const name = parts.shift();
|
|
283
|
+
const value = parts.join(": ");
|
|
284
|
+
headerMap[name.toLowerCase()] = value;
|
|
285
|
+
});
|
|
286
286
|
|
|
287
|
-
return headerMap
|
|
288
|
-
}
|
|
287
|
+
return headerMap;
|
|
288
|
+
};
|
|
289
289
|
|
|
290
290
|
const hrefToOrigin = (href) => {
|
|
291
|
-
const scheme = hrefToScheme(href)
|
|
291
|
+
const scheme = hrefToScheme(href);
|
|
292
292
|
|
|
293
293
|
if (scheme === "file") {
|
|
294
|
-
return "file://"
|
|
294
|
+
return "file://";
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
if (scheme === "http" || scheme === "https") {
|
|
298
|
-
const secondProtocolSlashIndex = scheme.length + "://".length
|
|
299
|
-
const pathnameSlashIndex = href.indexOf("/", secondProtocolSlashIndex)
|
|
298
|
+
const secondProtocolSlashIndex = scheme.length + "://".length;
|
|
299
|
+
const pathnameSlashIndex = href.indexOf("/", secondProtocolSlashIndex);
|
|
300
300
|
|
|
301
|
-
if (pathnameSlashIndex === -1) return href
|
|
302
|
-
return href.slice(0, pathnameSlashIndex)
|
|
301
|
+
if (pathnameSlashIndex === -1) return href;
|
|
302
|
+
return href.slice(0, pathnameSlashIndex);
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
return href.slice(0, scheme.length + 1)
|
|
306
|
-
}
|
|
305
|
+
return href.slice(0, scheme.length + 1);
|
|
306
|
+
};
|
|
307
307
|
|
|
308
308
|
const hrefToScheme = (href) => {
|
|
309
|
-
const colonIndex = href.indexOf(":")
|
|
310
|
-
if (colonIndex === -1) return ""
|
|
311
|
-
return href.slice(0, colonIndex)
|
|
312
|
-
}
|
|
309
|
+
const colonIndex = href.indexOf(":");
|
|
310
|
+
if (colonIndex === -1) return "";
|
|
311
|
+
return href.slice(0, colonIndex);
|
|
312
|
+
};
|
|
313
313
|
|
|
314
314
|
const isDataView = (obj) => {
|
|
315
|
-
return obj && DataView.prototype.isPrototypeOf(obj)
|
|
316
|
-
}
|
|
315
|
+
return obj && DataView.prototype.isPrototypeOf(obj);
|
|
316
|
+
};
|
|
317
317
|
|
|
318
318
|
const isArrayBufferView =
|
|
319
319
|
ArrayBuffer.isView ||
|
|
@@ -328,73 +328,73 @@ const isArrayBufferView =
|
|
|
328
328
|
"[object Uint32Array]",
|
|
329
329
|
"[object Float32Array]",
|
|
330
330
|
"[object Float64Array]",
|
|
331
|
-
]
|
|
331
|
+
];
|
|
332
332
|
|
|
333
333
|
return (value) => {
|
|
334
334
|
return (
|
|
335
335
|
value && viewClasses.includes(Object.prototype.toString.call(value))
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
})()
|
|
336
|
+
);
|
|
337
|
+
};
|
|
338
|
+
})();
|
|
339
339
|
|
|
340
340
|
const textToFormData = (text) => {
|
|
341
|
-
const form = new FormData()
|
|
341
|
+
const form = new FormData();
|
|
342
342
|
text
|
|
343
343
|
.trim()
|
|
344
344
|
.split("&")
|
|
345
345
|
.forEach(function (bytes) {
|
|
346
346
|
if (bytes) {
|
|
347
|
-
const split = bytes.split("=")
|
|
348
|
-
const name = split.shift().replace(/\+/g, " ")
|
|
349
|
-
const value = split.join("=").replace(/\+/g, " ")
|
|
350
|
-
form.append(decodeURIComponent(name), decodeURIComponent(value))
|
|
347
|
+
const split = bytes.split("=");
|
|
348
|
+
const name = split.shift().replace(/\+/g, " ");
|
|
349
|
+
const value = split.join("=").replace(/\+/g, " ");
|
|
350
|
+
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
|
351
351
|
}
|
|
352
|
-
})
|
|
353
|
-
return form
|
|
354
|
-
}
|
|
352
|
+
});
|
|
353
|
+
return form;
|
|
354
|
+
};
|
|
355
355
|
|
|
356
356
|
const blobToArrayBuffer = async (blob) => {
|
|
357
|
-
const reader = new FileReader()
|
|
358
|
-
const promise = fileReaderReady(reader)
|
|
359
|
-
reader.readAsArrayBuffer(blob)
|
|
360
|
-
return promise
|
|
361
|
-
}
|
|
357
|
+
const reader = new FileReader();
|
|
358
|
+
const promise = fileReaderReady(reader);
|
|
359
|
+
reader.readAsArrayBuffer(blob);
|
|
360
|
+
return promise;
|
|
361
|
+
};
|
|
362
362
|
|
|
363
363
|
const blobToText = (blob) => {
|
|
364
|
-
const reader = new FileReader()
|
|
365
|
-
const promise = fileReaderReady(reader)
|
|
366
|
-
reader.readAsText(blob)
|
|
367
|
-
return promise
|
|
368
|
-
}
|
|
364
|
+
const reader = new FileReader();
|
|
365
|
+
const promise = fileReaderReady(reader);
|
|
366
|
+
reader.readAsText(blob);
|
|
367
|
+
return promise;
|
|
368
|
+
};
|
|
369
369
|
|
|
370
370
|
const arrayBufferToText = (arrayBuffer) => {
|
|
371
|
-
const view = new Uint8Array(arrayBuffer)
|
|
372
|
-
const chars = new Array(view.length)
|
|
373
|
-
let i = 0
|
|
371
|
+
const view = new Uint8Array(arrayBuffer);
|
|
372
|
+
const chars = new Array(view.length);
|
|
373
|
+
let i = 0;
|
|
374
374
|
while (i < view.length) {
|
|
375
|
-
chars[i] = String.fromCharCode(view[i])
|
|
375
|
+
chars[i] = String.fromCharCode(view[i]);
|
|
376
376
|
|
|
377
|
-
i
|
|
377
|
+
i++;
|
|
378
378
|
}
|
|
379
|
-
return chars.join("")
|
|
380
|
-
}
|
|
379
|
+
return chars.join("");
|
|
380
|
+
};
|
|
381
381
|
|
|
382
382
|
const fileReaderReady = (reader) => {
|
|
383
383
|
return new Promise(function (resolve, reject) {
|
|
384
384
|
reader.onload = function () {
|
|
385
|
-
resolve(reader.result)
|
|
386
|
-
}
|
|
385
|
+
resolve(reader.result);
|
|
386
|
+
};
|
|
387
387
|
reader.onerror = function () {
|
|
388
|
-
reject(reader.error)
|
|
389
|
-
}
|
|
390
|
-
})
|
|
391
|
-
}
|
|
388
|
+
reject(reader.error);
|
|
389
|
+
};
|
|
390
|
+
});
|
|
391
|
+
};
|
|
392
392
|
|
|
393
393
|
const cloneBuffer = (buffer) => {
|
|
394
394
|
if (buffer.slice) {
|
|
395
|
-
return buffer.slice(0)
|
|
395
|
+
return buffer.slice(0);
|
|
396
396
|
}
|
|
397
|
-
const view = new Uint8Array(buffer.byteLength)
|
|
398
|
-
view.set(new Uint8Array(buffer))
|
|
399
|
-
return view.buffer
|
|
400
|
-
}
|
|
397
|
+
const view = new Uint8Array(buffer.byteLength);
|
|
398
|
+
view.set(new Uint8Array(buffer));
|
|
399
|
+
return view.buffer;
|
|
400
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { memoize } from "@jsenv/utils/src/memoize/memoize.js"
|
|
1
|
+
import { memoize } from "@jsenv/utils/src/memoize/memoize.js";
|
|
2
2
|
|
|
3
3
|
const fetchPolyfill = async (...args) => {
|
|
4
|
-
const { fetchUsingXHR } = await loadPolyfill()
|
|
5
|
-
return fetchUsingXHR(...args)
|
|
6
|
-
}
|
|
4
|
+
const { fetchUsingXHR } = await loadPolyfill();
|
|
5
|
+
return fetchUsingXHR(...args);
|
|
6
|
+
};
|
|
7
7
|
|
|
8
|
-
const loadPolyfill = memoize(() => import("./fetch_using_xhr.js"))
|
|
8
|
+
const loadPolyfill = memoize(() => import("./fetch_using_xhr.js"));
|
|
9
9
|
|
|
10
10
|
export const fetchUrl =
|
|
11
11
|
typeof window.fetch === "function" &&
|
|
12
12
|
typeof window.AbortController === "function"
|
|
13
13
|
? window.fetch
|
|
14
|
-
: fetchPolyfill
|
|
14
|
+
: fetchPolyfill;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const setLinkHrefForParentWindow = (a, href) => {
|
|
2
|
-
a.href = href
|
|
2
|
+
a.href = href;
|
|
3
3
|
a.onclick = (e) => {
|
|
4
4
|
if (e.ctrlKey || e.metaKey) {
|
|
5
|
-
return
|
|
5
|
+
return;
|
|
6
6
|
}
|
|
7
|
-
e.preventDefault()
|
|
8
|
-
window.parent.location.href = href
|
|
9
|
-
}
|
|
10
|
-
}
|
|
7
|
+
e.preventDefault();
|
|
8
|
+
window.parent.location.href = href;
|
|
9
|
+
};
|
|
10
|
+
};
|