@taybart/corvid 0.1.27 → 0.1.29
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/index.js +36 -11
- package/dist/ls.js +31 -8
- package/dist/network.d.ts +1 -1
- package/dist/network.js +5 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -549,7 +549,7 @@ class request {
|
|
|
549
549
|
...this.opts.headers,
|
|
550
550
|
...override.headers
|
|
551
551
|
},
|
|
552
|
-
body: JSON.stringify(body)
|
|
552
|
+
body: body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer ? body : JSON.stringify(body)
|
|
553
553
|
}
|
|
554
554
|
};
|
|
555
555
|
}
|
|
@@ -579,8 +579,10 @@ class request {
|
|
|
579
579
|
body
|
|
580
580
|
};
|
|
581
581
|
}
|
|
582
|
-
|
|
583
|
-
|
|
582
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
583
|
+
this.log.debug(`content type: ${ct}`);
|
|
584
|
+
if (ct.includes('application/json')) return await res.json();
|
|
585
|
+
if (ct.startsWith('image/') || 'application/octet-stream' === ct) return await res.blob();
|
|
584
586
|
return await res.text();
|
|
585
587
|
}
|
|
586
588
|
constructor(opts = {}, verbose = false){
|
|
@@ -759,28 +761,51 @@ function set(key, value, broadcast = false) {
|
|
|
759
761
|
}
|
|
760
762
|
const listeners = new Map();
|
|
761
763
|
function listen(key, cb) {
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
+
const customListener = (ev)=>{
|
|
765
|
+
const customEv = ev;
|
|
766
|
+
if (customEv.detail.key === key || '*' === key) {
|
|
764
767
|
if (cb instanceof dom_el) {
|
|
765
|
-
if (
|
|
768
|
+
if (customEv.detail.key === key) cb.content(customEv.detail.value);
|
|
766
769
|
return;
|
|
767
770
|
}
|
|
768
771
|
cb({
|
|
769
|
-
key:
|
|
770
|
-
value:
|
|
772
|
+
key: customEv.detail.key,
|
|
773
|
+
value: customEv.detail.value
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
const storageListener = (ev)=>{
|
|
778
|
+
const storageEv = ev;
|
|
779
|
+
if (storageEv.key === key || '*' === key) {
|
|
780
|
+
let value = storageEv.newValue;
|
|
781
|
+
try {
|
|
782
|
+
value = JSON.parse(value);
|
|
783
|
+
} catch (e) {}
|
|
784
|
+
if (cb instanceof dom_el) {
|
|
785
|
+
if (storageEv.key === key) cb.content(value);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
cb({
|
|
789
|
+
key: storageEv.key,
|
|
790
|
+
value
|
|
771
791
|
});
|
|
772
792
|
}
|
|
773
793
|
};
|
|
774
794
|
if (!listeners.has(key)) listeners.set(key, new Map());
|
|
775
|
-
listeners.get(key).set(cb,
|
|
776
|
-
|
|
795
|
+
listeners.get(key).set(cb, {
|
|
796
|
+
custom: customListener,
|
|
797
|
+
storage: storageListener
|
|
798
|
+
});
|
|
799
|
+
document.addEventListener('@corvid/ls-update', customListener);
|
|
800
|
+
window.addEventListener('storage', storageListener);
|
|
777
801
|
}
|
|
778
802
|
function unlisten(key, cb) {
|
|
779
803
|
const keyListeners = listeners.get(key);
|
|
780
804
|
if (!keyListeners) return;
|
|
781
805
|
const listener = keyListeners.get(cb);
|
|
782
806
|
if (!listener) return;
|
|
783
|
-
document.removeEventListener('@corvid/ls-update', listener);
|
|
807
|
+
document.removeEventListener('@corvid/ls-update', listener.custom);
|
|
808
|
+
window.removeEventListener('storage', listener.storage);
|
|
784
809
|
keyListeners.delete(cb);
|
|
785
810
|
if (0 === keyListeners.size) listeners.delete(key);
|
|
786
811
|
}
|
package/dist/ls.js
CHANGED
|
@@ -298,28 +298,51 @@ function set(key, value, broadcast = false) {
|
|
|
298
298
|
}
|
|
299
299
|
const listeners = new Map();
|
|
300
300
|
function listen(key, cb) {
|
|
301
|
-
const
|
|
302
|
-
|
|
301
|
+
const customListener = (ev)=>{
|
|
302
|
+
const customEv = ev;
|
|
303
|
+
if (customEv.detail.key === key || '*' === key) {
|
|
303
304
|
if (cb instanceof dom_el) {
|
|
304
|
-
if (
|
|
305
|
+
if (customEv.detail.key === key) cb.content(customEv.detail.value);
|
|
305
306
|
return;
|
|
306
307
|
}
|
|
307
308
|
cb({
|
|
308
|
-
key:
|
|
309
|
-
value:
|
|
309
|
+
key: customEv.detail.key,
|
|
310
|
+
value: customEv.detail.value
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const storageListener = (ev)=>{
|
|
315
|
+
const storageEv = ev;
|
|
316
|
+
if (storageEv.key === key || '*' === key) {
|
|
317
|
+
let value = storageEv.newValue;
|
|
318
|
+
try {
|
|
319
|
+
value = JSON.parse(value);
|
|
320
|
+
} catch (e) {}
|
|
321
|
+
if (cb instanceof dom_el) {
|
|
322
|
+
if (storageEv.key === key) cb.content(value);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
cb({
|
|
326
|
+
key: storageEv.key,
|
|
327
|
+
value
|
|
310
328
|
});
|
|
311
329
|
}
|
|
312
330
|
};
|
|
313
331
|
if (!listeners.has(key)) listeners.set(key, new Map());
|
|
314
|
-
listeners.get(key).set(cb,
|
|
315
|
-
|
|
332
|
+
listeners.get(key).set(cb, {
|
|
333
|
+
custom: customListener,
|
|
334
|
+
storage: storageListener
|
|
335
|
+
});
|
|
336
|
+
document.addEventListener('@corvid/ls-update', customListener);
|
|
337
|
+
window.addEventListener('storage', storageListener);
|
|
316
338
|
}
|
|
317
339
|
function unlisten(key, cb) {
|
|
318
340
|
const keyListeners = listeners.get(key);
|
|
319
341
|
if (!keyListeners) return;
|
|
320
342
|
const listener = keyListeners.get(cb);
|
|
321
343
|
if (!listener) return;
|
|
322
|
-
document.removeEventListener('@corvid/ls-update', listener);
|
|
344
|
+
document.removeEventListener('@corvid/ls-update', listener.custom);
|
|
345
|
+
window.removeEventListener('storage', listener.storage);
|
|
323
346
|
keyListeners.delete(cb);
|
|
324
347
|
if (0 === keyListeners.size) listeners.delete(key);
|
|
325
348
|
}
|
package/dist/network.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare class request {
|
|
|
64
64
|
isPrototypeOf(v: Object): boolean;
|
|
65
65
|
propertyIsEnumerable(v: PropertyKey): boolean;
|
|
66
66
|
};
|
|
67
|
-
body: string;
|
|
67
|
+
body: string | ArrayBuffer | FormData | Blob;
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
70
|
do({ path, params: passedParams, override, _recurselevel, }?: {
|
package/dist/network.js
CHANGED
|
@@ -124,7 +124,7 @@ class request {
|
|
|
124
124
|
...this.opts.headers,
|
|
125
125
|
...override.headers
|
|
126
126
|
},
|
|
127
|
-
body: JSON.stringify(body)
|
|
127
|
+
body: body instanceof FormData || body instanceof Blob || body instanceof ArrayBuffer ? body : JSON.stringify(body)
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
}
|
|
@@ -154,8 +154,10 @@ class request {
|
|
|
154
154
|
body
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
158
|
+
this.log.debug(`content type: ${ct}`);
|
|
159
|
+
if (ct.includes('application/json')) return await res.json();
|
|
160
|
+
if (ct.startsWith('image/') || 'application/octet-stream' === ct) return await res.blob();
|
|
159
161
|
return await res.text();
|
|
160
162
|
}
|
|
161
163
|
constructor(opts = {}, verbose = false){
|