@ienlab/react-library 0.6.0 → 0.8.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`),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
+ 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={}){let{cache:t=!0,includeMetadataChanges:n}=e;return{listenOptions:{includeMetadataChanges:n??!t},cache:t}}function d(e,t){return t!==!1||!e}function f(e,t,n={}){let{listenOptions:i,cache:a}=u(n),{onError:o}=n;return e.type,(0,r.onSnapshot)(e,i,e=>{d(e.metadata.fromCache,a)&&t(e)},o)}Array.prototype.mapNotNull=function(e){return this.flatMap((t,n)=>{let r=e(t,n);return r==null?[]:[r]})};function p(){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 m(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 h=()=>({updateAt:(0,r.serverTimestamp)(),delete:!0}),g=()=>({updateAt:(0,r.serverTimestamp)(),delete:!1});exports.CrossfadeImage=a,exports.SUPPORTED_LOCALES=o,exports.createZustandContext=m,exports.deleteItem=h,exports.fetchItems=c,exports.fetchItemsByOne=l,exports.getPlatformType=p,exports.getSnapshots=f,exports.snapshotToData=s,exports.undeleteItem=g;
@@ -33,14 +33,17 @@ function h({ placeholder: e, src: t, onLoadError: s, ...c }) {
33
33
  }, "placeholder") });
34
34
  }
35
35
  //#endregion
36
+ //#region src/types/localized.ts
37
+ var g = ["ko", "en"];
38
+ //#endregion
36
39
  //#region src/utils/firestore.ts
37
- function g(e) {
40
+ function _(e) {
38
41
  return {
39
42
  ...e.data(),
40
43
  id: e.id
41
44
  };
42
45
  }
43
- async function _(e, t, n, r) {
46
+ async function v(e, t, n, r) {
44
47
  let i = r.filter((e) => !!(e && !n.has(e.path)));
45
48
  for (let r = 0; r < i.length; r += 30) {
46
49
  let a = i.slice(r, r + 30);
@@ -50,18 +53,28 @@ async function _(e, t, n, r) {
50
53
  });
51
54
  }
52
55
  }
53
- async function v(e, t, n) {
56
+ async function y(e, t, n) {
54
57
  let r = n.filter((e) => !!(e && !t.has(e.path)));
55
58
  await Promise.all(r.map(async (n) => {
56
59
  let r = e(await c(n));
57
60
  t.set(n.path, r);
58
61
  }));
59
62
  }
60
- function y(e, t, n = {}) {
61
- let { cache: r = !0, onError: i } = n;
62
- return u(e, { includeMetadataChanges: !r }, (e) => {
63
- (r || !e.metadata.fromCache) && t(e);
64
- }, i);
63
+ function b(e = {}) {
64
+ let { cache: t = !0, includeMetadataChanges: n } = e;
65
+ return {
66
+ listenOptions: { includeMetadataChanges: n ?? !t },
67
+ cache: t
68
+ };
69
+ }
70
+ function x(e, t) {
71
+ return t !== !1 || !e;
72
+ }
73
+ function S(e, t, n = {}) {
74
+ let { listenOptions: r, cache: i } = b(n), { onError: a } = n;
75
+ return e.type, u(e, r, (e) => {
76
+ x(e.metadata.fromCache, i) && t(e);
77
+ }, a);
65
78
  }
66
79
  //#endregion
67
80
  //#region src/utils/array.ts
@@ -73,14 +86,14 @@ Array.prototype.mapNotNull = function(e) {
73
86
  };
74
87
  //#endregion
75
88
  //#region src/utils/platform.ts
76
- function b() {
89
+ function C() {
77
90
  if (typeof window > "u") return "pc";
78
91
  let e = navigator.userAgent, t = navigator.platform, n = /Android/i.test(e), r = /iPhone|iPad|iPod/i.test(e) || t === "MacIntel" && navigator.maxTouchPoints > 1;
79
92
  return n ? "android" : r ? "ios" : "pc";
80
93
  }
81
94
  //#endregion
82
95
  //#region src/utils/zustand.tsx
83
- function x(n) {
96
+ function w(n) {
84
97
  let i = e(null);
85
98
  function a({ children: e, ...t }) {
86
99
  let [a] = r(() => n(t));
@@ -103,12 +116,12 @@ function x(n) {
103
116
  }
104
117
  //#endregion
105
118
  //#region src/constant/firestore.ts
106
- var S = () => ({
119
+ var T = () => ({
107
120
  updateAt: f(),
108
121
  delete: !0
109
- }), C = () => ({
122
+ }), E = () => ({
110
123
  updateAt: f(),
111
124
  delete: !1
112
125
  });
113
126
  //#endregion
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 };
127
+ export { h as CrossfadeImage, g as SUPPORTED_LOCALES, w as createZustandContext, T as deleteItem, v as fetchItems, y as fetchItemsByOne, C as getPlatformType, S as getSnapshots, _ as snapshotToData, E 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,10 +1,13 @@
1
- import { CollectionReference, DocumentData, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, Unsubscribe, FirestoreError } from 'firebase/firestore';
1
+ import { CollectionReference, DocumentData, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, Unsubscribe, FirestoreError, Query, QuerySnapshot } from 'firebase/firestore';
2
2
  import { FirestoreItem } from '../types';
3
3
  export declare function snapshotToData(snapshot: QueryDocumentSnapshot | DocumentSnapshot): DocumentData;
4
4
  export declare function fetchItems<T extends FirestoreItem>(collection: CollectionReference, changeMethod: ((snapshot: QueryDocumentSnapshot | DocumentSnapshot) => T), cache: Map<string, T>, referenceArray: (DocumentReference | undefined | null)[]): Promise<void>;
5
5
  export declare function fetchItemsByOne<T extends FirestoreItem>(changeMethod: ((snapshot: QueryDocumentSnapshot | DocumentSnapshot) => T), cache: Map<string, T>, referenceArray: (DocumentReference | undefined | null)[]): Promise<void>;
6
- export declare function getSnapshots(ref: DocumentReference, callback: (snapshot: DocumentSnapshot) => void, options?: {
6
+ export type SnapshotOptions = {
7
7
  cache?: boolean;
8
+ includeMetadataChanges?: boolean;
8
9
  onError?: (error: FirestoreError) => void;
9
- }): Unsubscribe;
10
+ };
11
+ export declare function getSnapshots<AppModelType, DbModelType extends DocumentData = DocumentData>(ref: DocumentReference<AppModelType, DbModelType>, callback: (snapshot: DocumentSnapshot<AppModelType, DbModelType>) => void, options?: SnapshotOptions): Unsubscribe;
12
+ export declare function getSnapshots<AppModelType, DbModelType extends DocumentData = DocumentData>(query: Query<AppModelType, DbModelType>, callback: (snapshot: QuerySnapshot<AppModelType, DbModelType>) => void, options?: SnapshotOptions): Unsubscribe;
10
13
  //# sourceMappingURL=firestore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"firestore.d.ts","sourceRoot":"","sources":["../../src/utils/firestore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,mBAAmB,EAC3D,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,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,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AAS,GAAG,IAAI,CAAC,EAAE,iBAQzD;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;CAC1C,CAAA;AAsBD,wBAAgB,YAAY,CAC1B,YAAY,EACZ,WAAW,SAAS,YAAY,GAAG,YAAY,EAE/C,GAAG,EAAE,iBAAiB,CAAC,YAAY,EAAE,WAAW,CAAC,EACjD,QAAQ,EAAE,CACR,QAAQ,EAAE,gBAAgB,CAAC,YAAY,EAAE,WAAW,CAAC,KAClD,IAAI,EACT,OAAO,CAAC,EAAE,eAAe,GACxB,WAAW,CAAA;AAEd,wBAAgB,YAAY,CAC1B,YAAY,EACZ,WAAW,SAAS,YAAY,GAAG,YAAY,EAE/C,KAAK,EAAE,KAAK,CAAC,YAAY,EAAE,WAAW,CAAC,EACvC,QAAQ,EAAE,CACR,QAAQ,EAAE,aAAa,CAAC,YAAY,EAAE,WAAW,CAAC,KAC/C,IAAI,EACT,OAAO,CAAC,EAAE,eAAe,GACxB,WAAW,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ienlab/react-library",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "My React component library",
5
5
  "main": "./dist/my-library.cjs.js",
6
6
  "module": "./dist/my-library.es.js",