@ienlab/react-library 0.7.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`)})}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
+ 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;
@@ -60,11 +60,21 @@ async function y(e, t, n) {
60
60
  t.set(n.path, r);
61
61
  }));
62
62
  }
63
- function b(e, t, n = {}) {
64
- let { cache: r = !0, onError: i } = n;
65
- return u(e, { includeMetadataChanges: !r }, (e) => {
66
- (r || !e.metadata.fromCache) && t(e);
67
- }, 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);
68
78
  }
69
79
  //#endregion
70
80
  //#region src/utils/array.ts
@@ -76,14 +86,14 @@ Array.prototype.mapNotNull = function(e) {
76
86
  };
77
87
  //#endregion
78
88
  //#region src/utils/platform.ts
79
- function x() {
89
+ function C() {
80
90
  if (typeof window > "u") return "pc";
81
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;
82
92
  return n ? "android" : r ? "ios" : "pc";
83
93
  }
84
94
  //#endregion
85
95
  //#region src/utils/zustand.tsx
86
- function S(n) {
96
+ function w(n) {
87
97
  let i = e(null);
88
98
  function a({ children: e, ...t }) {
89
99
  let [a] = r(() => n(t));
@@ -106,12 +116,12 @@ function S(n) {
106
116
  }
107
117
  //#endregion
108
118
  //#region src/constant/firestore.ts
109
- var C = () => ({
119
+ var T = () => ({
110
120
  updateAt: f(),
111
121
  delete: !0
112
- }), w = () => ({
122
+ }), E = () => ({
113
123
  updateAt: f(),
114
124
  delete: !1
115
125
  });
116
126
  //#endregion
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 };
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,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,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC,EAAE,iBAQzD;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,iBAAiB,EACtB,QAAQ,EAAE,CAAC,QAAQ,E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,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.7.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",