@ienlab/react-library 0.4.3 → 0.4.4
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/my-library.cjs.js +1 -0
- package/dist/my-library.es.js +55 -70
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`react`),t=require(`motion/react`),n=require(`react/jsx-runtime`),r=require(`firebase/firestore`);function i({placeholder:r,src:i,onLoadError:a,...o}){let[s,c]=(0,e.useState)(()=>{if(typeof window>`u`||!i)return!1;let e=new Image;return e.src=i,e.complete&&e.naturalWidth>0}),[l,u]=(0,e.useState)(i);return l!==i&&(u(i),c(!1)),(0,e.useEffect)(()=>{if(!i)return;let e=new Image;return e.src=i,e.onload=()=>c(!0),e.onerror=e=>{a?a(e):console.error(`CrossfadeImage: Failed to load image`,i)},e.complete&&e.naturalWidth>0&&e.onload(new Event(`load`)),()=>{e.onload=null,e.onerror=null}},[i,a]),(0,n.jsx)(t.AnimatePresence,{children:s&&i?(0,n.jsx)(t.motion.img,{src:i,...o,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},style:{...o.style}},`loaded-image`):(0,n.jsx)(t.motion.div,{initial:{opacity:1},transition:{duration:.3},style:{...o.style},children:r??(0,n.jsx)(`div`,{className:`w-full h-full bg-sidebar`})},`placeholder`)})}function a(e){return{...e.data(),id:e.id}}async function o(e,t,n,i,a){let o=a.filter(e=>!!(e&&!i.has(e.path)));for(let a=0;a<o.length;a+=30){let s=o.slice(a,a+30);(await(0,r.getDocs)((0,r.query)((0,r.collection)(e,t),(0,r.where)((0,r.documentId)(),`in`,s.map(e=>e.id))))).forEach(e=>{let t=n(e);i.set(e.ref.path,t)})}}async function s(e,t,n){let i=n.filter(e=>!!(e&&!t.has(e.path)));await Promise.all(i.map(async n=>{let i=e(await(0,r.getDoc)(n));t.set(n.path,i)}))}function c(e,t,n={}){let{cache:i=!0,onError:a}=n;return(0,r.onSnapshot)(e,{includeMetadataChanges:!i},e=>{(i||!e.metadata.fromCache)&&t(e)},a)}Array.prototype.mapNotNull=function(e){return this.flatMap((t,n)=>{let r=e(t,n);return r==null?[]:[r]})};var l=()=>({updateAt:(0,r.serverTimestamp)(),delete:!0}),u=()=>({updateAt:(0,r.serverTimestamp)(),delete:!1});exports.CrossfadeImage=i,exports.deleteItem=l,exports.fetchItems=o,exports.fetchItemsByOne=s,exports.getSnapshots=c,exports.snapshotToData=a,exports.undeleteItem=u;
|
package/dist/my-library.es.js
CHANGED
|
@@ -1,98 +1,83 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { AnimatePresence, motion } from "motion/react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import { collection, documentId, getDoc, getDocs, onSnapshot, query, serverTimestamp, where } from "firebase/firestore";
|
|
1
|
+
import { useEffect as e, useState as t } from "react";
|
|
2
|
+
import { AnimatePresence as n, motion as r } from "motion/react";
|
|
3
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
4
|
+
import { collection as a, documentId as o, getDoc as s, getDocs as c, onSnapshot as l, query as u, serverTimestamp as d, where as f } from "firebase/firestore";
|
|
5
5
|
//#region src/components/image.tsx
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
if (typeof window
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!src) return;
|
|
20
|
-
const img = new Image();
|
|
21
|
-
img.src = src;
|
|
22
|
-
img.onload = () => setIsLoaded(true);
|
|
23
|
-
img.onerror = (e) => {
|
|
24
|
-
if (onLoadError) onLoadError(e);
|
|
25
|
-
else console.error("CrossfadeImage: Failed to load image", src);
|
|
6
|
+
function p({ placeholder: a, src: o, onLoadError: s, ...c }) {
|
|
7
|
+
let [l, u] = t(() => {
|
|
8
|
+
if (typeof window > "u" || !o) return !1;
|
|
9
|
+
let e = new Image();
|
|
10
|
+
return e.src = o, e.complete && e.naturalWidth > 0;
|
|
11
|
+
}), [d, f] = t(o);
|
|
12
|
+
return d !== o && (f(o), u(!1)), e(() => {
|
|
13
|
+
if (!o) return;
|
|
14
|
+
let e = new Image();
|
|
15
|
+
return e.src = o, e.onload = () => u(!0), e.onerror = (e) => {
|
|
16
|
+
s ? s(e) : console.error("CrossfadeImage: Failed to load image", o);
|
|
17
|
+
}, e.complete && e.naturalWidth > 0 && e.onload(new Event("load")), () => {
|
|
18
|
+
e.onload = null, e.onerror = null;
|
|
26
19
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
img.onerror = null;
|
|
31
|
-
};
|
|
32
|
-
}, [src, onLoadError]);
|
|
33
|
-
return /* @__PURE__ */ jsx(AnimatePresence, { children: isLoaded && src ? /* @__PURE__ */ jsx(motion.img, {
|
|
34
|
-
src,
|
|
35
|
-
...imgProps,
|
|
20
|
+
}, [o, s]), /* @__PURE__ */ i(n, { children: l && o ? /* @__PURE__ */ i(r.img, {
|
|
21
|
+
src: o,
|
|
22
|
+
...c,
|
|
36
23
|
initial: { opacity: 0 },
|
|
37
24
|
animate: { opacity: 1 },
|
|
38
25
|
exit: { opacity: 0 },
|
|
39
|
-
style: { ...
|
|
40
|
-
}, "loaded-image") : /* @__PURE__ */
|
|
26
|
+
style: { ...c.style }
|
|
27
|
+
}, "loaded-image") : /* @__PURE__ */ i(r.div, {
|
|
41
28
|
initial: { opacity: 1 },
|
|
42
29
|
transition: { duration: .3 },
|
|
43
|
-
style: { ...
|
|
44
|
-
children:
|
|
30
|
+
style: { ...c.style },
|
|
31
|
+
children: a ?? /* @__PURE__ */ i("div", { className: "w-full h-full bg-sidebar" })
|
|
45
32
|
}, "placeholder") });
|
|
46
33
|
}
|
|
47
34
|
//#endregion
|
|
48
35
|
//#region src/utils/firestore.ts
|
|
49
|
-
function
|
|
36
|
+
function m(e) {
|
|
50
37
|
return {
|
|
51
|
-
...
|
|
52
|
-
id:
|
|
38
|
+
...e.data(),
|
|
39
|
+
id: e.id
|
|
53
40
|
};
|
|
54
41
|
}
|
|
55
|
-
async function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
cache.set(snapshot.ref.path, item);
|
|
42
|
+
async function h(e, t, n, r, i) {
|
|
43
|
+
let s = i.filter((e) => !!(e && !r.has(e.path)));
|
|
44
|
+
for (let i = 0; i < s.length; i += 30) {
|
|
45
|
+
let l = s.slice(i, i + 30);
|
|
46
|
+
(await c(u(a(e, t), f(o(), "in", l.map((e) => e.id))))).forEach((e) => {
|
|
47
|
+
let t = n(e);
|
|
48
|
+
r.set(e.ref.path, t);
|
|
63
49
|
});
|
|
64
50
|
}
|
|
65
51
|
}
|
|
66
|
-
async function
|
|
67
|
-
|
|
68
|
-
await Promise.all(
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
async function g(e, t, n) {
|
|
53
|
+
let r = n.filter((e) => !!(e && !t.has(e.path)));
|
|
54
|
+
await Promise.all(r.map(async (n) => {
|
|
55
|
+
let r = e(await s(n));
|
|
56
|
+
t.set(n.path, r);
|
|
71
57
|
}));
|
|
72
58
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
},
|
|
59
|
+
function _(e, t, n = {}) {
|
|
60
|
+
let { cache: r = !0, onError: i } = n;
|
|
61
|
+
return l(e, { includeMetadataChanges: !r }, (e) => {
|
|
62
|
+
(r || !e.metadata.fromCache) && t(e);
|
|
63
|
+
}, i);
|
|
78
64
|
}
|
|
79
65
|
//#endregion
|
|
80
66
|
//#region src/utils/array.ts
|
|
81
|
-
Array.prototype.mapNotNull = function(
|
|
82
|
-
return this.flatMap((
|
|
83
|
-
|
|
84
|
-
return
|
|
67
|
+
Array.prototype.mapNotNull = function(e) {
|
|
68
|
+
return this.flatMap((t, n) => {
|
|
69
|
+
let r = e(t, n);
|
|
70
|
+
return r == null ? [] : [r];
|
|
85
71
|
});
|
|
86
72
|
};
|
|
87
73
|
//#endregion
|
|
88
74
|
//#region src/constant/firestore.ts
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"delete": false
|
|
75
|
+
var v = () => ({
|
|
76
|
+
updateAt: d(),
|
|
77
|
+
delete: !0
|
|
78
|
+
}), y = () => ({
|
|
79
|
+
updateAt: d(),
|
|
80
|
+
delete: !1
|
|
96
81
|
});
|
|
97
82
|
//#endregion
|
|
98
|
-
export { CrossfadeImage, deleteItem, fetchItems, fetchItemsByOne, getSnapshots, snapshotToData, undeleteItem };
|
|
83
|
+
export { p as CrossfadeImage, v as deleteItem, h as fetchItems, g as fetchItemsByOne, _ as getSnapshots, m as snapshotToData, y as undeleteItem };
|