@maggioli-design-system/magma 1.12.2 → 1.12.3
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/cjs/mds-button_3.cjs.entry.js +59 -36
- package/dist/collection/components/mds-icon/services/icons-set.service.js +38 -16
- package/dist/collection/components/mds-input-date/test/mds-input-date.stories.js +75 -0
- package/dist/components/mds-icon2.js +59 -36
- package/dist/documentation.json +1 -1
- package/dist/esm/mds-button_3.entry.js +59 -36
- package/dist/esm-es5/mds-button_3.entry.js +1 -1
- package/dist/hydrate/index.js +59 -36
- package/dist/hydrate/index.mjs +59 -36
- package/dist/magma-components/magma-components.esm.js +1 -1
- package/dist/magma-components/p-26cd6ec8.system.js +1 -1
- package/dist/magma-components/p-5214b07e.entry.js +1 -0
- package/dist/magma-components/{p-68dde65c.system.entry.js → p-8465aa1a.system.entry.js} +1 -1
- package/dist/stats.json +14 -14
- package/dist/types/components/mds-icon/services/icons-set.service.d.ts +9 -9
- package/dist/types/components/mds-input-date/test/mds-input-date.stories.d.ts +4 -0
- package/package.json +2 -2
- package/dist/magma-components/p-3e72a9f4.entry.js +0 -1
|
@@ -238,37 +238,44 @@ function promisifyRequest(request) {
|
|
|
238
238
|
// @ts-ignore - file size hacks
|
|
239
239
|
request.oncomplete = request.onsuccess = function () {
|
|
240
240
|
return resolve(request.result);
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
};
|
|
242
|
+
// @ts-ignore - file size hacks
|
|
244
243
|
request.onabort = request.onerror = function () {
|
|
245
244
|
return reject(request.error);
|
|
246
245
|
};
|
|
247
246
|
});
|
|
248
247
|
}
|
|
249
|
-
|
|
250
248
|
function createStore(dbName, storeName) {
|
|
251
|
-
var
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
249
|
+
var dbp;
|
|
250
|
+
var getDB = function getDB() {
|
|
251
|
+
if (dbp) return dbp;
|
|
252
|
+
var request = indexedDB.open(dbName);
|
|
253
|
+
request.onupgradeneeded = function () {
|
|
254
|
+
return request.result.createObjectStore(storeName);
|
|
255
|
+
};
|
|
256
|
+
dbp = promisifyRequest(request);
|
|
257
|
+
dbp.then(function (db) {
|
|
258
|
+
// It seems like Safari sometimes likes to just close the connection.
|
|
259
|
+
// It's supposed to fire this event when that happens. Let's hope it does!
|
|
260
|
+
db.onclose = function () {
|
|
261
|
+
return dbp = undefined;
|
|
262
|
+
};
|
|
263
|
+
}, function () {
|
|
264
|
+
dbp = undefined;
|
|
265
|
+
});
|
|
266
|
+
return dbp;
|
|
255
267
|
};
|
|
256
|
-
|
|
257
|
-
var dbp = promisifyRequest(request);
|
|
258
268
|
return function (txMode, callback) {
|
|
259
|
-
return
|
|
269
|
+
return getDB().then(function (db) {
|
|
260
270
|
return callback(db.transaction(storeName, txMode).objectStore(storeName));
|
|
261
271
|
});
|
|
262
272
|
};
|
|
263
273
|
}
|
|
264
|
-
|
|
265
274
|
var defaultGetStoreFunc;
|
|
266
|
-
|
|
267
275
|
function defaultGetStore() {
|
|
268
276
|
if (!defaultGetStoreFunc) {
|
|
269
277
|
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
|
270
278
|
}
|
|
271
|
-
|
|
272
279
|
return defaultGetStoreFunc;
|
|
273
280
|
}
|
|
274
281
|
/**
|
|
@@ -277,8 +284,6 @@ function defaultGetStore() {
|
|
|
277
284
|
* @param key
|
|
278
285
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
279
286
|
*/
|
|
280
|
-
|
|
281
|
-
|
|
282
287
|
function get(key) {
|
|
283
288
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
284
289
|
return customStore('readonly', function (store) {
|
|
@@ -292,8 +297,6 @@ function get(key) {
|
|
|
292
297
|
* @param value
|
|
293
298
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
294
299
|
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
300
|
function set(key, value) {
|
|
298
301
|
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
|
299
302
|
return customStore('readwrite', function (store) {
|
|
@@ -307,8 +310,6 @@ function set(key, value) {
|
|
|
307
310
|
* @param key
|
|
308
311
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
309
312
|
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
313
|
function del(key) {
|
|
313
314
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
314
315
|
return customStore('readwrite', function (store) {
|
|
@@ -410,29 +411,46 @@ class IconsSetController {
|
|
|
410
411
|
return { set: this._iconsSets.get(iconName.split('/')[0]) };
|
|
411
412
|
}
|
|
412
413
|
/**
|
|
413
|
-
*
|
|
414
|
+
* Sets the directory of the svg files. Query and fragment are dropped: the icon name is
|
|
415
|
+
* appended to the path.
|
|
414
416
|
*
|
|
415
|
-
* input path: https://www.abc.com/svg/path
|
|
416
|
-
* svgPath =
|
|
417
|
+
* input path: https://www.abc.com/svg/path/
|
|
418
|
+
* svgPath = https://www.abc.com/svg/path/
|
|
417
419
|
*
|
|
418
|
-
* input path: localhost:9000/svg/path
|
|
419
|
-
* svgPath = localhost:9000/svg/path
|
|
420
|
+
* input path: localhost:9000/svg/path/
|
|
421
|
+
* svgPath = //localhost:9000/svg/path/ (with the protocol of the page)
|
|
420
422
|
*
|
|
421
|
-
* input path: /svg/path
|
|
422
|
-
* svgPath =
|
|
423
|
+
* input path: /svg/path/ or svg/path/
|
|
424
|
+
* svgPath = unchanged, resolved by `fetch` against the document base URL on each request
|
|
423
425
|
*
|
|
424
|
-
* input path:
|
|
426
|
+
* input path: empty or not a URL
|
|
425
427
|
* throw error
|
|
426
|
-
*
|
|
427
428
|
*/
|
|
428
429
|
setSvgPath(svgPath) {
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
430
|
+
const error = Error(`Svg path not recognize ${svgPath}, ensure is a absolute path starting with '/' or a url`);
|
|
431
|
+
if (typeof svgPath !== 'string' || svgPath.trim() === '') {
|
|
432
|
+
throw error;
|
|
433
|
+
}
|
|
434
|
+
const value = svgPath.trim();
|
|
435
|
+
// a host with a port and no scheme (`localhost:9000/svg/`) would be read as the scheme `localhost:`
|
|
436
|
+
const path = /^[\w.-]+:\d+(\/|$)/.test(value) ? `//${value}` : value;
|
|
437
|
+
let url;
|
|
438
|
+
try {
|
|
439
|
+
// the placeholder base only validates a path, which is kept as it is
|
|
440
|
+
url = new URL(path, 'http://localhost/');
|
|
441
|
+
}
|
|
442
|
+
catch (_a) {
|
|
443
|
+
throw error;
|
|
433
444
|
}
|
|
434
445
|
if (typeof window !== 'undefined') {
|
|
435
|
-
|
|
446
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path)) {
|
|
447
|
+
url.search = '';
|
|
448
|
+
url.hash = '';
|
|
449
|
+
this._svgPath = url.href;
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
this._svgPath = path.replace(/[?#].*$/, '');
|
|
453
|
+
}
|
|
436
454
|
window.dispatchEvent(new Event(this._svgPathUpdate));
|
|
437
455
|
}
|
|
438
456
|
}
|
|
@@ -460,9 +478,14 @@ class IconsSetController {
|
|
|
460
478
|
this.setSvgPath((_a = window.sessionStorage.getItem(IconsSetService._svgPathKey)) !== null && _a !== void 0 ? _a : '');
|
|
461
479
|
}
|
|
462
480
|
const src = this._svgPath && !name.startsWith('http') ? this._svgPath.concat(name, '.svg') : name;
|
|
481
|
+
// Memory first: every instance of an icon already loaded skips the IndexedDB round-trip
|
|
482
|
+
if (this.memoryCache[src]) {
|
|
483
|
+
return this.memoryCache[src];
|
|
484
|
+
}
|
|
463
485
|
const lsCache = await this.isCacheAvailable(src);
|
|
464
|
-
if (
|
|
465
|
-
|
|
486
|
+
if (lsCache) {
|
|
487
|
+
this.memoryCache[src] = lsCache;
|
|
488
|
+
return lsCache;
|
|
466
489
|
}
|
|
467
490
|
const response = await fetch(src);
|
|
468
491
|
if (!response.ok) {
|
|
@@ -64,29 +64,46 @@ class IconsSetController {
|
|
|
64
64
|
return { set: this._iconsSets.get(iconName.split('/')[0]) };
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
67
|
+
* Sets the directory of the svg files. Query and fragment are dropped: the icon name is
|
|
68
|
+
* appended to the path.
|
|
68
69
|
*
|
|
69
|
-
* input path: https://www.abc.com/svg/path
|
|
70
|
-
* svgPath =
|
|
70
|
+
* input path: https://www.abc.com/svg/path/
|
|
71
|
+
* svgPath = https://www.abc.com/svg/path/
|
|
71
72
|
*
|
|
72
|
-
* input path: localhost:9000/svg/path
|
|
73
|
-
* svgPath = localhost:9000/svg/path
|
|
73
|
+
* input path: localhost:9000/svg/path/
|
|
74
|
+
* svgPath = //localhost:9000/svg/path/ (with the protocol of the page)
|
|
74
75
|
*
|
|
75
|
-
* input path: /svg/path
|
|
76
|
-
* svgPath =
|
|
76
|
+
* input path: /svg/path/ or svg/path/
|
|
77
|
+
* svgPath = unchanged, resolved by `fetch` against the document base URL on each request
|
|
77
78
|
*
|
|
78
|
-
* input path:
|
|
79
|
+
* input path: empty or not a URL
|
|
79
80
|
* throw error
|
|
80
|
-
*
|
|
81
81
|
*/
|
|
82
82
|
setSvgPath(svgPath) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
const error = Error(`Svg path not recognize ${svgPath}, ensure is a absolute path starting with '/' or a url`);
|
|
84
|
+
if (typeof svgPath !== 'string' || svgPath.trim() === '') {
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
const value = svgPath.trim();
|
|
88
|
+
// a host with a port and no scheme (`localhost:9000/svg/`) would be read as the scheme `localhost:`
|
|
89
|
+
const path = /^[\w.-]+:\d+(\/|$)/.test(value) ? `//${value}` : value;
|
|
90
|
+
let url;
|
|
91
|
+
try {
|
|
92
|
+
// the placeholder base only validates a path, which is kept as it is
|
|
93
|
+
url = new URL(path, 'http://localhost/');
|
|
94
|
+
}
|
|
95
|
+
catch (_a) {
|
|
96
|
+
throw error;
|
|
87
97
|
}
|
|
88
98
|
if (typeof window !== 'undefined') {
|
|
89
|
-
|
|
99
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path)) {
|
|
100
|
+
url.search = '';
|
|
101
|
+
url.hash = '';
|
|
102
|
+
this._svgPath = url.href;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this._svgPath = path.replace(/[?#].*$/, '');
|
|
106
|
+
}
|
|
90
107
|
window.dispatchEvent(new Event(this._svgPathUpdate));
|
|
91
108
|
}
|
|
92
109
|
}
|
|
@@ -114,9 +131,14 @@ class IconsSetController {
|
|
|
114
131
|
this.setSvgPath((_a = window.sessionStorage.getItem(IconsSetService._svgPathKey)) !== null && _a !== void 0 ? _a : '');
|
|
115
132
|
}
|
|
116
133
|
const src = this._svgPath && !name.startsWith('http') ? this._svgPath.concat(name, '.svg') : name;
|
|
134
|
+
// Memory first: every instance of an icon already loaded skips the IndexedDB round-trip
|
|
135
|
+
if (this.memoryCache[src]) {
|
|
136
|
+
return this.memoryCache[src];
|
|
137
|
+
}
|
|
117
138
|
const lsCache = await this.isCacheAvailable(src);
|
|
118
|
-
if (
|
|
119
|
-
|
|
139
|
+
if (lsCache) {
|
|
140
|
+
this.memoryCache[src] = lsCache;
|
|
141
|
+
return lsCache;
|
|
120
142
|
}
|
|
121
143
|
const response = await fetch(src);
|
|
122
144
|
if (!response.ok) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { h } from "@stencil/core";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { expect, waitFor } from "storybook/test";
|
|
2
4
|
export default {
|
|
3
5
|
title: 'Form / Input Date',
|
|
4
6
|
argTypes: {
|
|
@@ -68,3 +70,76 @@ export const Disabled = {
|
|
|
68
70
|
disabled: true,
|
|
69
71
|
},
|
|
70
72
|
};
|
|
73
|
+
// A date field inside a modal with a custom window (mds-banner in slot="window", so the calendar
|
|
74
|
+
// pops out of the window instead of being clipped by the default window). The play opens the
|
|
75
|
+
// modal and the calendar and checks that the calendar takes the field width, capped by
|
|
76
|
+
// the calendar max-width, with seven evenly sized columns, anchored to the end of the field.
|
|
77
|
+
const InsideModalTemplate = () => {
|
|
78
|
+
const [opened, setOpened] = useState(false);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const modalElement = document.querySelector('#date-modal');
|
|
81
|
+
const close = () => setOpened(false);
|
|
82
|
+
modalElement === null || modalElement === void 0 ? void 0 : modalElement.addEventListener('mdsModalClose', close);
|
|
83
|
+
modalElement === null || modalElement === void 0 ? void 0 : modalElement.addEventListener('mdsModalHide', close);
|
|
84
|
+
return () => {
|
|
85
|
+
modalElement === null || modalElement === void 0 ? void 0 : modalElement.removeEventListener('mdsModalClose', close);
|
|
86
|
+
modalElement === null || modalElement === void 0 ? void 0 : modalElement.removeEventListener('mdsModalHide', close);
|
|
87
|
+
};
|
|
88
|
+
}, []);
|
|
89
|
+
return (h("div", null, h("mds-button", { id: "open-modal", onClick: () => setOpened(true) }, "Apri la modale"), h("mds-modal", { id: "date-modal", opened: opened ? true : undefined, position: "center" }, h("mds-banner", { slot: "window", class: "max-w-[480px]" }, h("mds-button", { icon: "mi/baseline/close", variant: "dark", tone: "quiet", style: { position: 'absolute', right: '0.5rem', top: '0.5rem' }, onClick: () => setOpened(false) }), h("mds-input-field", { label: "Preparato da" }, h("mds-input", { value: "Mario Rossi" })), h("mds-input-field", { label: "il" }, h("mds-input-date", { id: "modal-date", value: getDate() })), h("mds-input-field", { label: "Commento" }, h("mds-input", { type: "textarea", placeholder: "Commento" }))))));
|
|
90
|
+
};
|
|
91
|
+
// Waits for the dropdown opening transition to stand still before measuring.
|
|
92
|
+
const waitForSettled = (element) => waitFor(() => {
|
|
93
|
+
const { opacity, transform } = getComputedStyle(element);
|
|
94
|
+
expect(opacity).toBe('1');
|
|
95
|
+
expect(['none', 'matrix(1, 0, 0, 1, 0, 0)']).toContain(transform);
|
|
96
|
+
}, { timeout: 5000 });
|
|
97
|
+
// The play starts on the React render, before the Stencil hydration: wait for the components,
|
|
98
|
+
// then for mdsModalShow (the end of the window's opening transition) before opening the calendar.
|
|
99
|
+
const openModalAndCalendar = async ({ canvasElement, userEvent }) => {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
const modal = canvasElement.querySelector('#date-modal');
|
|
102
|
+
const host = canvasElement.querySelector('#modal-date');
|
|
103
|
+
await Promise.all([modal.componentOnReady(), host.componentOnReady()]);
|
|
104
|
+
const dropdown = (_a = host.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('mds-dropdown');
|
|
105
|
+
await dropdown.componentOnReady();
|
|
106
|
+
let shown = false;
|
|
107
|
+
modal.addEventListener('mdsModalShow', () => {
|
|
108
|
+
shown = true;
|
|
109
|
+
}, { once: true });
|
|
110
|
+
await userEvent.click(canvasElement.querySelector('#open-modal'));
|
|
111
|
+
await waitFor(() => expect(shown).toBe(true), { timeout: 5000 });
|
|
112
|
+
await userEvent.click((_b = host.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#calendar-dropdown'));
|
|
113
|
+
await waitFor(() => expect(dropdown).toHaveAttribute('visible'), { timeout: 5000 });
|
|
114
|
+
await waitForSettled(dropdown);
|
|
115
|
+
return {
|
|
116
|
+
host,
|
|
117
|
+
dropdown,
|
|
118
|
+
calendar: dropdown.querySelector('mds-calendar'),
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
// The calendar takes the field width (100cqw of the input-date host) capped by its own max-width,
|
|
122
|
+
// with seven evenly sized columns; the dropdown ends at the field's right edge (placement
|
|
123
|
+
// bottom-end), pushed past it by at most the dropdown arrow padding.
|
|
124
|
+
const expectCalendarSizedToField = ({ host, dropdown, calendar }) => {
|
|
125
|
+
var _a;
|
|
126
|
+
const { width: fieldWidth, right: fieldRight } = host.getBoundingClientRect();
|
|
127
|
+
const maxWidth = parseFloat(getComputedStyle(calendar).maxWidth);
|
|
128
|
+
const { width } = calendar.getBoundingClientRect();
|
|
129
|
+
expect(maxWidth).toBeGreaterThan(0);
|
|
130
|
+
expect(width).toBeCloseTo(Math.min(fieldWidth, maxWidth), 0);
|
|
131
|
+
const cells = (_a = calendar.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.month-view__cells');
|
|
132
|
+
const tracks = getComputedStyle(cells).gridTemplateColumns.split(' ').map(parseFloat);
|
|
133
|
+
expect(tracks).toHaveLength(7);
|
|
134
|
+
tracks.forEach(track => expect(track).toBeCloseTo(tracks[0], 0));
|
|
135
|
+
// sub-pixel rounding aside, the dropdown never starts before the field's end
|
|
136
|
+
const overshoot = dropdown.getBoundingClientRect().right - fieldRight;
|
|
137
|
+
expect(overshoot).toBeGreaterThanOrEqual(-1);
|
|
138
|
+
expect(overshoot).toBeLessThanOrEqual(dropdown.arrowPadding);
|
|
139
|
+
};
|
|
140
|
+
export const UseCaseInsideModal = {
|
|
141
|
+
render: InsideModalTemplate,
|
|
142
|
+
play: async (context) => {
|
|
143
|
+
expectCalendarSizedToField(await openModalAndCalendar(context));
|
|
144
|
+
},
|
|
145
|
+
};
|
|
@@ -20,37 +20,44 @@ function promisifyRequest(request) {
|
|
|
20
20
|
// @ts-ignore - file size hacks
|
|
21
21
|
request.oncomplete = request.onsuccess = function () {
|
|
22
22
|
return resolve(request.result);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
};
|
|
24
|
+
// @ts-ignore - file size hacks
|
|
26
25
|
request.onabort = request.onerror = function () {
|
|
27
26
|
return reject(request.error);
|
|
28
27
|
};
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
|
|
32
30
|
function createStore(dbName, storeName) {
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
var dbp;
|
|
32
|
+
var getDB = function getDB() {
|
|
33
|
+
if (dbp) return dbp;
|
|
34
|
+
var request = indexedDB.open(dbName);
|
|
35
|
+
request.onupgradeneeded = function () {
|
|
36
|
+
return request.result.createObjectStore(storeName);
|
|
37
|
+
};
|
|
38
|
+
dbp = promisifyRequest(request);
|
|
39
|
+
dbp.then(function (db) {
|
|
40
|
+
// It seems like Safari sometimes likes to just close the connection.
|
|
41
|
+
// It's supposed to fire this event when that happens. Let's hope it does!
|
|
42
|
+
db.onclose = function () {
|
|
43
|
+
return dbp = undefined;
|
|
44
|
+
};
|
|
45
|
+
}, function () {
|
|
46
|
+
dbp = undefined;
|
|
47
|
+
});
|
|
48
|
+
return dbp;
|
|
37
49
|
};
|
|
38
|
-
|
|
39
|
-
var dbp = promisifyRequest(request);
|
|
40
50
|
return function (txMode, callback) {
|
|
41
|
-
return
|
|
51
|
+
return getDB().then(function (db) {
|
|
42
52
|
return callback(db.transaction(storeName, txMode).objectStore(storeName));
|
|
43
53
|
});
|
|
44
54
|
};
|
|
45
55
|
}
|
|
46
|
-
|
|
47
56
|
var defaultGetStoreFunc;
|
|
48
|
-
|
|
49
57
|
function defaultGetStore() {
|
|
50
58
|
if (!defaultGetStoreFunc) {
|
|
51
59
|
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
|
52
60
|
}
|
|
53
|
-
|
|
54
61
|
return defaultGetStoreFunc;
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
@@ -59,8 +66,6 @@ function defaultGetStore() {
|
|
|
59
66
|
* @param key
|
|
60
67
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
61
68
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
69
|
function get(key) {
|
|
65
70
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
66
71
|
return customStore('readonly', function (store) {
|
|
@@ -74,8 +79,6 @@ function get(key) {
|
|
|
74
79
|
* @param value
|
|
75
80
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
76
81
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
82
|
function set(key, value) {
|
|
80
83
|
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
|
81
84
|
return customStore('readwrite', function (store) {
|
|
@@ -89,8 +92,6 @@ function set(key, value) {
|
|
|
89
92
|
* @param key
|
|
90
93
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
91
94
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
95
|
function del(key) {
|
|
95
96
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
96
97
|
return customStore('readwrite', function (store) {
|
|
@@ -192,29 +193,46 @@ class IconsSetController {
|
|
|
192
193
|
return { set: this._iconsSets.get(iconName.split('/')[0]) };
|
|
193
194
|
}
|
|
194
195
|
/**
|
|
195
|
-
*
|
|
196
|
+
* Sets the directory of the svg files. Query and fragment are dropped: the icon name is
|
|
197
|
+
* appended to the path.
|
|
196
198
|
*
|
|
197
|
-
* input path: https://www.abc.com/svg/path
|
|
198
|
-
* svgPath =
|
|
199
|
+
* input path: https://www.abc.com/svg/path/
|
|
200
|
+
* svgPath = https://www.abc.com/svg/path/
|
|
199
201
|
*
|
|
200
|
-
* input path: localhost:9000/svg/path
|
|
201
|
-
* svgPath = localhost:9000/svg/path
|
|
202
|
+
* input path: localhost:9000/svg/path/
|
|
203
|
+
* svgPath = //localhost:9000/svg/path/ (with the protocol of the page)
|
|
202
204
|
*
|
|
203
|
-
* input path: /svg/path
|
|
204
|
-
* svgPath =
|
|
205
|
+
* input path: /svg/path/ or svg/path/
|
|
206
|
+
* svgPath = unchanged, resolved by `fetch` against the document base URL on each request
|
|
205
207
|
*
|
|
206
|
-
* input path:
|
|
208
|
+
* input path: empty or not a URL
|
|
207
209
|
* throw error
|
|
208
|
-
*
|
|
209
210
|
*/
|
|
210
211
|
setSvgPath(svgPath) {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
const error = Error(`Svg path not recognize ${svgPath}, ensure is a absolute path starting with '/' or a url`);
|
|
213
|
+
if (typeof svgPath !== 'string' || svgPath.trim() === '') {
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
const value = svgPath.trim();
|
|
217
|
+
// a host with a port and no scheme (`localhost:9000/svg/`) would be read as the scheme `localhost:`
|
|
218
|
+
const path = /^[\w.-]+:\d+(\/|$)/.test(value) ? `//${value}` : value;
|
|
219
|
+
let url;
|
|
220
|
+
try {
|
|
221
|
+
// the placeholder base only validates a path, which is kept as it is
|
|
222
|
+
url = new URL(path, 'http://localhost/');
|
|
223
|
+
}
|
|
224
|
+
catch (_a) {
|
|
225
|
+
throw error;
|
|
215
226
|
}
|
|
216
227
|
if (typeof window !== 'undefined') {
|
|
217
|
-
|
|
228
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path)) {
|
|
229
|
+
url.search = '';
|
|
230
|
+
url.hash = '';
|
|
231
|
+
this._svgPath = url.href;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this._svgPath = path.replace(/[?#].*$/, '');
|
|
235
|
+
}
|
|
218
236
|
window.dispatchEvent(new Event(this._svgPathUpdate));
|
|
219
237
|
}
|
|
220
238
|
}
|
|
@@ -242,9 +260,14 @@ class IconsSetController {
|
|
|
242
260
|
this.setSvgPath((_a = window.sessionStorage.getItem(IconsSetService._svgPathKey)) !== null && _a !== void 0 ? _a : '');
|
|
243
261
|
}
|
|
244
262
|
const src = this._svgPath && !name.startsWith('http') ? this._svgPath.concat(name, '.svg') : name;
|
|
263
|
+
// Memory first: every instance of an icon already loaded skips the IndexedDB round-trip
|
|
264
|
+
if (this.memoryCache[src]) {
|
|
265
|
+
return this.memoryCache[src];
|
|
266
|
+
}
|
|
245
267
|
const lsCache = await this.isCacheAvailable(src);
|
|
246
|
-
if (
|
|
247
|
-
|
|
268
|
+
if (lsCache) {
|
|
269
|
+
this.memoryCache[src] = lsCache;
|
|
270
|
+
return lsCache;
|
|
248
271
|
}
|
|
249
272
|
const response = await fetch(src);
|
|
250
273
|
if (!response.ok) {
|
package/dist/documentation.json
CHANGED
|
@@ -234,37 +234,44 @@ function promisifyRequest(request) {
|
|
|
234
234
|
// @ts-ignore - file size hacks
|
|
235
235
|
request.oncomplete = request.onsuccess = function () {
|
|
236
236
|
return resolve(request.result);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
};
|
|
238
|
+
// @ts-ignore - file size hacks
|
|
240
239
|
request.onabort = request.onerror = function () {
|
|
241
240
|
return reject(request.error);
|
|
242
241
|
};
|
|
243
242
|
});
|
|
244
243
|
}
|
|
245
|
-
|
|
246
244
|
function createStore(dbName, storeName) {
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
245
|
+
var dbp;
|
|
246
|
+
var getDB = function getDB() {
|
|
247
|
+
if (dbp) return dbp;
|
|
248
|
+
var request = indexedDB.open(dbName);
|
|
249
|
+
request.onupgradeneeded = function () {
|
|
250
|
+
return request.result.createObjectStore(storeName);
|
|
251
|
+
};
|
|
252
|
+
dbp = promisifyRequest(request);
|
|
253
|
+
dbp.then(function (db) {
|
|
254
|
+
// It seems like Safari sometimes likes to just close the connection.
|
|
255
|
+
// It's supposed to fire this event when that happens. Let's hope it does!
|
|
256
|
+
db.onclose = function () {
|
|
257
|
+
return dbp = undefined;
|
|
258
|
+
};
|
|
259
|
+
}, function () {
|
|
260
|
+
dbp = undefined;
|
|
261
|
+
});
|
|
262
|
+
return dbp;
|
|
251
263
|
};
|
|
252
|
-
|
|
253
|
-
var dbp = promisifyRequest(request);
|
|
254
264
|
return function (txMode, callback) {
|
|
255
|
-
return
|
|
265
|
+
return getDB().then(function (db) {
|
|
256
266
|
return callback(db.transaction(storeName, txMode).objectStore(storeName));
|
|
257
267
|
});
|
|
258
268
|
};
|
|
259
269
|
}
|
|
260
|
-
|
|
261
270
|
var defaultGetStoreFunc;
|
|
262
|
-
|
|
263
271
|
function defaultGetStore() {
|
|
264
272
|
if (!defaultGetStoreFunc) {
|
|
265
273
|
defaultGetStoreFunc = createStore('keyval-store', 'keyval');
|
|
266
274
|
}
|
|
267
|
-
|
|
268
275
|
return defaultGetStoreFunc;
|
|
269
276
|
}
|
|
270
277
|
/**
|
|
@@ -273,8 +280,6 @@ function defaultGetStore() {
|
|
|
273
280
|
* @param key
|
|
274
281
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
275
282
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
283
|
function get(key) {
|
|
279
284
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
280
285
|
return customStore('readonly', function (store) {
|
|
@@ -288,8 +293,6 @@ function get(key) {
|
|
|
288
293
|
* @param value
|
|
289
294
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
290
295
|
*/
|
|
291
|
-
|
|
292
|
-
|
|
293
296
|
function set(key, value) {
|
|
294
297
|
var customStore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultGetStore();
|
|
295
298
|
return customStore('readwrite', function (store) {
|
|
@@ -303,8 +306,6 @@ function set(key, value) {
|
|
|
303
306
|
* @param key
|
|
304
307
|
* @param customStore Method to get a custom store. Use with caution (see the docs).
|
|
305
308
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
309
|
function del(key) {
|
|
309
310
|
var customStore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultGetStore();
|
|
310
311
|
return customStore('readwrite', function (store) {
|
|
@@ -406,29 +407,46 @@ class IconsSetController {
|
|
|
406
407
|
return { set: this._iconsSets.get(iconName.split('/')[0]) };
|
|
407
408
|
}
|
|
408
409
|
/**
|
|
409
|
-
*
|
|
410
|
+
* Sets the directory of the svg files. Query and fragment are dropped: the icon name is
|
|
411
|
+
* appended to the path.
|
|
410
412
|
*
|
|
411
|
-
* input path: https://www.abc.com/svg/path
|
|
412
|
-
* svgPath =
|
|
413
|
+
* input path: https://www.abc.com/svg/path/
|
|
414
|
+
* svgPath = https://www.abc.com/svg/path/
|
|
413
415
|
*
|
|
414
|
-
* input path: localhost:9000/svg/path
|
|
415
|
-
* svgPath = localhost:9000/svg/path
|
|
416
|
+
* input path: localhost:9000/svg/path/
|
|
417
|
+
* svgPath = //localhost:9000/svg/path/ (with the protocol of the page)
|
|
416
418
|
*
|
|
417
|
-
* input path: /svg/path
|
|
418
|
-
* svgPath =
|
|
419
|
+
* input path: /svg/path/ or svg/path/
|
|
420
|
+
* svgPath = unchanged, resolved by `fetch` against the document base URL on each request
|
|
419
421
|
*
|
|
420
|
-
* input path:
|
|
422
|
+
* input path: empty or not a URL
|
|
421
423
|
* throw error
|
|
422
|
-
*
|
|
423
424
|
*/
|
|
424
425
|
setSvgPath(svgPath) {
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
426
|
+
const error = Error(`Svg path not recognize ${svgPath}, ensure is a absolute path starting with '/' or a url`);
|
|
427
|
+
if (typeof svgPath !== 'string' || svgPath.trim() === '') {
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
const value = svgPath.trim();
|
|
431
|
+
// a host with a port and no scheme (`localhost:9000/svg/`) would be read as the scheme `localhost:`
|
|
432
|
+
const path = /^[\w.-]+:\d+(\/|$)/.test(value) ? `//${value}` : value;
|
|
433
|
+
let url;
|
|
434
|
+
try {
|
|
435
|
+
// the placeholder base only validates a path, which is kept as it is
|
|
436
|
+
url = new URL(path, 'http://localhost/');
|
|
437
|
+
}
|
|
438
|
+
catch (_a) {
|
|
439
|
+
throw error;
|
|
429
440
|
}
|
|
430
441
|
if (typeof window !== 'undefined') {
|
|
431
|
-
|
|
442
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path)) {
|
|
443
|
+
url.search = '';
|
|
444
|
+
url.hash = '';
|
|
445
|
+
this._svgPath = url.href;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
this._svgPath = path.replace(/[?#].*$/, '');
|
|
449
|
+
}
|
|
432
450
|
window.dispatchEvent(new Event(this._svgPathUpdate));
|
|
433
451
|
}
|
|
434
452
|
}
|
|
@@ -456,9 +474,14 @@ class IconsSetController {
|
|
|
456
474
|
this.setSvgPath((_a = window.sessionStorage.getItem(IconsSetService._svgPathKey)) !== null && _a !== void 0 ? _a : '');
|
|
457
475
|
}
|
|
458
476
|
const src = this._svgPath && !name.startsWith('http') ? this._svgPath.concat(name, '.svg') : name;
|
|
477
|
+
// Memory first: every instance of an icon already loaded skips the IndexedDB round-trip
|
|
478
|
+
if (this.memoryCache[src]) {
|
|
479
|
+
return this.memoryCache[src];
|
|
480
|
+
}
|
|
459
481
|
const lsCache = await this.isCacheAvailable(src);
|
|
460
|
-
if (
|
|
461
|
-
|
|
482
|
+
if (lsCache) {
|
|
483
|
+
this.memoryCache[src] = lsCache;
|
|
484
|
+
return lsCache;
|
|
462
485
|
}
|
|
463
486
|
const response = await fetch(src);
|
|
464
487
|
if (!response.ok) {
|