@ienlab/react-library 0.5.1 → 0.7.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`)})}var o=[`ko`,`en`];function s(e){return{...e.data(),id:e.id}}async function c(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 l(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 u(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 d(){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 f(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 p=()=>({updateAt:(0,r.serverTimestamp)(),delete:!0}),m=()=>({updateAt:(0,r.serverTimestamp)(),delete:!1});exports.CrossfadeImage=a,exports.SUPPORTED_LOCALES=o,exports.createZustandContext=f,exports.deleteItem=p,exports.fetchItems=c,exports.fetchItemsByOne=l,exports.getPlatformType=d,exports.getSnapshots=u,exports.snapshotToData=s,exports.undeleteItem=m;
@@ -1,64 +1,68 @@
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
36
+ //#region src/types/localized.ts
37
+ var g = ["ko", "en"];
38
+ //#endregion
35
39
  //#region src/utils/firestore.ts
36
- function p(e) {
40
+ function _(e) {
37
41
  return {
38
42
  ...e.data(),
39
43
  id: e.id
40
44
  };
41
45
  }
42
- async function m(e, t, n, r) {
46
+ async function v(e, t, n, r) {
43
47
  let i = r.filter((e) => !!(e && !n.has(e.path)));
44
48
  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) => {
49
+ let a = i.slice(r, r + 30);
50
+ (await l(d(e, p(s(), "in", a.map((e) => e.id))))).forEach((e) => {
47
51
  let r = t(e);
48
52
  n.set(e.ref.path, r);
49
53
  });
50
54
  }
51
55
  }
52
- async function h(e, t, n) {
56
+ async function y(e, t, n) {
53
57
  let r = n.filter((e) => !!(e && !t.has(e.path)));
54
58
  await Promise.all(r.map(async (n) => {
55
- let r = e(await o(n));
59
+ let r = e(await c(n));
56
60
  t.set(n.path, r);
57
61
  }));
58
62
  }
59
- function g(e, t, n = {}) {
63
+ function b(e, t, n = {}) {
60
64
  let { cache: r = !0, onError: i } = n;
61
- return c(e, { includeMetadataChanges: !r }, (e) => {
65
+ return u(e, { includeMetadataChanges: !r }, (e) => {
62
66
  (r || !e.metadata.fromCache) && t(e);
63
67
  }, i);
64
68
  }
@@ -72,19 +76,42 @@ Array.prototype.mapNotNull = function(e) {
72
76
  };
73
77
  //#endregion
74
78
  //#region src/utils/platform.ts
75
- function _() {
79
+ function x() {
76
80
  if (typeof window > "u") return "pc";
77
81
  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
82
  return n ? "android" : r ? "ios" : "pc";
79
83
  }
80
84
  //#endregion
85
+ //#region src/utils/zustand.tsx
86
+ function S(n) {
87
+ let i = e(null);
88
+ function a({ children: e, ...t }) {
89
+ let [a] = r(() => n(t));
90
+ return /* @__PURE__ */ o(i.Provider, {
91
+ value: a,
92
+ children: e
93
+ });
94
+ }
95
+ function s(e) {
96
+ let n = t(i);
97
+ if (!n) throw Error("Provider가 필요합니다.");
98
+ return m(n, e);
99
+ }
100
+ let c = /* @__PURE__ */ new Map();
101
+ return {
102
+ Provider: a,
103
+ useStore: s,
104
+ use: new Proxy({}, { get: (e, t) => (c.has(t) || c.set(t, () => s((e) => e[t])), c.get(t)) })
105
+ };
106
+ }
107
+ //#endregion
81
108
  //#region src/constant/firestore.ts
82
- var v = () => ({
83
- updateAt: u(),
109
+ var C = () => ({
110
+ updateAt: f(),
84
111
  delete: !0
85
- }), y = () => ({
86
- updateAt: u(),
112
+ }), w = () => ({
113
+ updateAt: f(),
87
114
  delete: !1
88
115
  });
89
116
  //#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 };
117
+ export { h as CrossfadeImage, g as SUPPORTED_LOCALES, S as createZustandContext, C as deleteItem, v as fetchItems, y as fetchItemsByOne, x as getPlatformType, b as getSnapshots, _ as snapshotToData, w as undeleteItem };
@@ -1,3 +1,4 @@
1
1
  export * from './firestore';
2
2
  export * from './shadcn';
3
+ export * from './localized';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA"}
@@ -0,0 +1,4 @@
1
+ export declare const SUPPORTED_LOCALES: readonly ["ko", "en"];
2
+ export type Locale = (typeof SUPPORTED_LOCALES)[number];
3
+ export type Localized<T, TLocale extends string = Locale> = Record<TLocale, T>;
4
+ //# sourceMappingURL=localized.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localized.d.ts","sourceRoot":"","sources":["../../src/types/localized.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,uBAAwB,CAAA;AACtD,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AACvD,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,OAAO,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA"}
@@ -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,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,iBAgBzD;AAED,wBAAsB,eAAe,CAAC,CAAC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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.7.0",
4
4
  "description": "My React component library",
5
5
  "main": "./dist/my-library.cjs.js",
6
6
  "module": "./dist/my-library.es.js",