@ienlab/react-library 0.5.1 → 0.6.0

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.
@@ -1 +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){let a=i.filter(e=>!!(e&&!n.has(e.path)));for(let i=0;i<a.length;i+=30){let o=a.slice(i,i+30);(await(0,r.getDocs)((0,r.query)(e,(0,r.where)((0,r.documentId)(),`in`,o.map(e=>e.id))))).forEach(e=>{let r=t(e);n.set(e.ref.path,r)})}}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]})};function l(){if(typeof window>`u`)return`pc`;let e=navigator.userAgent,t=navigator.platform,n=/Android/i.test(e),r=/iPhone|iPad|iPod/i.test(e)||t===`MacIntel`&&navigator.maxTouchPoints>1;return n?`android`:r?`ios`:`pc`}var u=()=>({updateAt:(0,r.serverTimestamp)(),delete:!0}),d=()=>({updateAt:(0,r.serverTimestamp)(),delete:!1});exports.CrossfadeImage=i,exports.deleteItem=u,exports.fetchItems=o,exports.fetchItemsByOne=s,exports.getPlatformType=l,exports.getSnapshots=c,exports.snapshotToData=a,exports.undeleteItem=d;
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`),i=require(`zustand/react`);function a({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 o(e){return{...e.data(),id:e.id}}async function s(e,t,n,i){let a=i.filter(e=>!!(e&&!n.has(e.path)));for(let i=0;i<a.length;i+=30){let o=a.slice(i,i+30);(await(0,r.getDocs)((0,r.query)(e,(0,r.where)((0,r.documentId)(),`in`,o.map(e=>e.id))))).forEach(e=>{let r=t(e);n.set(e.ref.path,r)})}}async function c(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 l(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]})};function u(){if(typeof window>`u`)return`pc`;let e=navigator.userAgent,t=navigator.platform,n=/Android/i.test(e),r=/iPhone|iPad|iPod/i.test(e)||t===`MacIntel`&&navigator.maxTouchPoints>1;return n?`android`:r?`ios`:`pc`}function d(t){let r=(0,e.createContext)(null);function a({children:i,...a}){let[o]=(0,e.useState)(()=>t(a));return(0,n.jsx)(r.Provider,{value:o,children:i})}function o(t){let n=(0,e.useContext)(r);if(!n)throw Error(`Provider가 필요합니다.`);return(0,i.useStore)(n,t)}let s=new Map;return{Provider:a,useStore:o,use:new Proxy({},{get:(e,t)=>(s.has(t)||s.set(t,()=>o(e=>e[t])),s.get(t))})}}var f=()=>({updateAt:(0,r.serverTimestamp)(),delete:!0}),p=()=>({updateAt:(0,r.serverTimestamp)(),delete:!1});exports.CrossfadeImage=a,exports.createZustandContext=d,exports.deleteItem=f,exports.fetchItems=s,exports.fetchItemsByOne=c,exports.getPlatformType=u,exports.getSnapshots=l,exports.snapshotToData=o,exports.undeleteItem=p;
@@ -1,64 +1,65 @@
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 { documentId as a, getDoc as o, getDocs as s, onSnapshot as c, query as l, serverTimestamp as u, where as d } from "firebase/firestore";
1
+ import { createContext as e, useContext as t, useEffect as n, useState as r } from "react";
2
+ import { AnimatePresence as i, motion as a } from "motion/react";
3
+ import { jsx as o } from "react/jsx-runtime";
4
+ import { documentId as s, getDoc as c, getDocs as l, onSnapshot as u, query as d, serverTimestamp as f, where as p } from "firebase/firestore";
5
+ import { useStore as m } from "zustand/react";
5
6
  //#region src/components/image.tsx
6
- function f({ placeholder: a, src: o, onLoadError: s, ...c }) {
7
- let [l, u] = t(() => {
8
- if (typeof window > "u" || !o) return !1;
7
+ function h({ placeholder: e, src: t, onLoadError: s, ...c }) {
8
+ let [l, u] = r(() => {
9
+ if (typeof window > "u" || !t) return !1;
9
10
  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;
11
+ return e.src = t, e.complete && e.naturalWidth > 0;
12
+ }), [d, f] = r(t);
13
+ return d !== t && (f(t), u(!1)), n(() => {
14
+ if (!t) return;
14
15
  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);
16
+ return e.src = t, e.onload = () => u(!0), e.onerror = (e) => {
17
+ s ? s(e) : console.error("CrossfadeImage: Failed to load image", t);
17
18
  }, e.complete && e.naturalWidth > 0 && e.onload(new Event("load")), () => {
18
19
  e.onload = null, e.onerror = null;
19
20
  };
20
- }, [o, s]), /* @__PURE__ */ i(n, { children: l && o ? /* @__PURE__ */ i(r.img, {
21
- src: o,
21
+ }, [t, s]), /* @__PURE__ */ o(i, { children: l && t ? /* @__PURE__ */ o(a.img, {
22
+ src: t,
22
23
  ...c,
23
24
  initial: { opacity: 0 },
24
25
  animate: { opacity: 1 },
25
26
  exit: { opacity: 0 },
26
27
  style: { ...c.style }
27
- }, "loaded-image") : /* @__PURE__ */ i(r.div, {
28
+ }, "loaded-image") : /* @__PURE__ */ o(a.div, {
28
29
  initial: { opacity: 1 },
29
30
  transition: { duration: .3 },
30
31
  style: { ...c.style },
31
- children: a ?? /* @__PURE__ */ i("div", { className: "w-full h-full bg-sidebar" })
32
+ children: e ?? /* @__PURE__ */ o("div", { className: "w-full h-full bg-sidebar" })
32
33
  }, "placeholder") });
33
34
  }
34
35
  //#endregion
35
36
  //#region src/utils/firestore.ts
36
- function p(e) {
37
+ function g(e) {
37
38
  return {
38
39
  ...e.data(),
39
40
  id: e.id
40
41
  };
41
42
  }
42
- async function m(e, t, n, r) {
43
+ async function _(e, t, n, r) {
43
44
  let i = r.filter((e) => !!(e && !n.has(e.path)));
44
45
  for (let r = 0; r < i.length; r += 30) {
45
- let o = i.slice(r, r + 30);
46
- (await s(l(e, d(a(), "in", o.map((e) => e.id))))).forEach((e) => {
46
+ let a = i.slice(r, r + 30);
47
+ (await l(d(e, p(s(), "in", a.map((e) => e.id))))).forEach((e) => {
47
48
  let r = t(e);
48
49
  n.set(e.ref.path, r);
49
50
  });
50
51
  }
51
52
  }
52
- async function h(e, t, n) {
53
+ async function v(e, t, n) {
53
54
  let r = n.filter((e) => !!(e && !t.has(e.path)));
54
55
  await Promise.all(r.map(async (n) => {
55
- let r = e(await o(n));
56
+ let r = e(await c(n));
56
57
  t.set(n.path, r);
57
58
  }));
58
59
  }
59
- function g(e, t, n = {}) {
60
+ function y(e, t, n = {}) {
60
61
  let { cache: r = !0, onError: i } = n;
61
- return c(e, { includeMetadataChanges: !r }, (e) => {
62
+ return u(e, { includeMetadataChanges: !r }, (e) => {
62
63
  (r || !e.metadata.fromCache) && t(e);
63
64
  }, i);
64
65
  }
@@ -72,19 +73,42 @@ Array.prototype.mapNotNull = function(e) {
72
73
  };
73
74
  //#endregion
74
75
  //#region src/utils/platform.ts
75
- function _() {
76
+ function b() {
76
77
  if (typeof window > "u") return "pc";
77
78
  let e = navigator.userAgent, t = navigator.platform, n = /Android/i.test(e), r = /iPhone|iPad|iPod/i.test(e) || t === "MacIntel" && navigator.maxTouchPoints > 1;
78
79
  return n ? "android" : r ? "ios" : "pc";
79
80
  }
80
81
  //#endregion
82
+ //#region src/utils/zustand.tsx
83
+ function x(n) {
84
+ let i = e(null);
85
+ function a({ children: e, ...t }) {
86
+ let [a] = r(() => n(t));
87
+ return /* @__PURE__ */ o(i.Provider, {
88
+ value: a,
89
+ children: e
90
+ });
91
+ }
92
+ function s(e) {
93
+ let n = t(i);
94
+ if (!n) throw Error("Provider가 필요합니다.");
95
+ return m(n, e);
96
+ }
97
+ let c = /* @__PURE__ */ new Map();
98
+ return {
99
+ Provider: a,
100
+ useStore: s,
101
+ use: new Proxy({}, { get: (e, t) => (c.has(t) || c.set(t, () => s((e) => e[t])), c.get(t)) })
102
+ };
103
+ }
104
+ //#endregion
81
105
  //#region src/constant/firestore.ts
82
- var v = () => ({
83
- updateAt: u(),
106
+ var S = () => ({
107
+ updateAt: f(),
84
108
  delete: !0
85
- }), y = () => ({
86
- updateAt: u(),
109
+ }), C = () => ({
110
+ updateAt: f(),
87
111
  delete: !1
88
112
  });
89
113
  //#endregion
90
- export { f as CrossfadeImage, v as deleteItem, m as fetchItems, h as fetchItemsByOne, _ as getPlatformType, g as getSnapshots, p as snapshotToData, y as undeleteItem };
114
+ export { h as CrossfadeImage, x as createZustandContext, S as deleteItem, _ as fetchItems, v as fetchItemsByOne, b as getPlatformType, y as getSnapshots, g as snapshotToData, C as undeleteItem };
@@ -1 +1 @@
1
- {"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../src/utils/firestore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,mBAAmB,EACtD,KAAK,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EACnG,KAAK,WAAW,EAEhB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,UAAU,CAAA;AAE3C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,gBAAgB,GAAG,YAAY,CAK/F;AAED,wBAAsB,UAAU,CAAC,CAAC,SAAS,aAAa,EACtD,UAAU,EAAE,mBAAmB,EAC/B,YA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AqB,GAAG,gBAAgB,KAAK,CAAC,CAAC,EACzE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EACrB,cAAc,EAAE,CAAC,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,iBAgBzD;AAED,wBAAsB,eAAe,CAAC,CAAC,SAAS,aAAa,EAC3D,YAAY,EAAE,CAAC,CAAC,QAAQ,EAAE,qBAAqB,GAAG,gBAAgB,KAAK,CAAC,CAAC,EACzE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EACrB,cAAc,EAAE,CAAC,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,iBAQzD;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,iBAAiB,EACtB,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,IAAI,EAC9C,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;CAAO,GAC3E,WAAW,CAYb"}
@@ -1,4 +1,5 @@
1
1
  export * from './firestore';
2
2
  export * from './array';
3
3
  export * from './platform';
4
+ export * from './zustand';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA;AACvB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { StoreApi } from 'zustand/vanilla';
2
+ import { PropsWithChildren } from 'react';
3
+ type AutoSelectors<TState extends object> = {
4
+ [K in keyof TState]: () => TState[K];
5
+ };
6
+ export declare function createZustandContext<TState extends object, TProps extends object>(createLocalStore: (props: TProps) => StoreApi<TState>): {
7
+ Provider: ({ children, ...props }: PropsWithChildren<TProps>) => import("react/jsx-runtime").JSX.Element;
8
+ useStore: <T>(selector: (state: TState) => T) => T;
9
+ use: AutoSelectors<TState>;
10
+ };
11
+ export {};
12
+ //# sourceMappingURL=zustand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zustand.d.ts","sourceRoot":"","sources":["../../src/utils/zustand.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAiB,KAAK,iBAAiB,EAAwB,MAAM,OAAO,CAAA;AAGnF,KAAK,aAAa,CAAC,MAAM,SAAS,MAAM,IAAI;KACzC,CAAC,IAAI,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC;CACrC,CAAA;AAED,wBAAgB,oBAAoB,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,SAAS,MAAM,EAC/E,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC;uCAIX,iBAAiB,CAAC,MAAM,CAAC;eAU5C,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC;;EAyBzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ienlab/react-library",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "My React component library",
5
5
  "main": "./dist/my-library.cjs.js",
6
6
  "module": "./dist/my-library.es.js",