@voplus/morpho-document 1.0.0-dev205 → 1.0.0-dev207

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,2 +1,3 @@
1
1
  export * from "./useOnNewDocument";
2
2
  export * from "./useOnDeleteDocument";
3
+ export * from "./useAutoUpdateListData";
@@ -1,3 +1,4 @@
1
1
  export * from "./useOnNewDocument";
2
2
  export * from "./useOnDeleteDocument";
3
+ export * from "./useAutoUpdateListData";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/data/DocumentStore/hooks/document-events/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/data/DocumentStore/hooks/document-events/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { IDocument } from "../../../interfaces";
2
+ import { ListDataContextState } from "@voplus/morpho-ui/es/data";
3
+ /** React hook to call action when a new document has been created. */
4
+ export declare const useAutoUpdateListData: (list: ListDataContextState<any>, shouldUpdate: (d: IDocument, event: string) => boolean) => void;
@@ -0,0 +1,13 @@
1
+ import { useOnDeleteDocument, useOnNewDocument } from "./";
2
+ /** React hook to call action when a new document has been created. */
3
+ export const useAutoUpdateListData = (list, shouldUpdate) => {
4
+ useOnNewDocument((s, d) => {
5
+ if (shouldUpdate(d, "new"))
6
+ list.union([d]);
7
+ });
8
+ useOnDeleteDocument((s, d) => {
9
+ if (shouldUpdate(d, "new"))
10
+ list.remove(d.id);
11
+ });
12
+ };
13
+ //# sourceMappingURL=useAutoUpdateListData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutoUpdateListData.js","sourceRoot":"","sources":["../../../../../src/data/DocumentStore/hooks/document-events/useAutoUpdateListData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AAK3D,sEAAsE;AACtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACpC,IAA+B,EAC/B,YAAsD,EACrD,EAAE;IACH,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACzB,IAAI,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5B,IAAI,YAAY,CAAC,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -8,6 +8,6 @@ export const useDocumentListEffect = (effect, options) => {
8
8
  const deps = options ? options : {};
9
9
  const store = useDocumentStore();
10
10
  // Call useDocumentListLoaderEffect and ensure won't load twice for same loading options.
11
- return useDocumentListLoaderEffect(effect, () => store.loadList(options), [deps]);
11
+ return useDocumentListLoaderEffect(null, effect, () => store.loadList(options), [deps]);
12
12
  };
13
13
  //# sourceMappingURL=useDocumentListEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDocumentListEffect.js","sourceRoot":"","sources":["../../../../src/data/DocumentStore/hooks/useDocumentListEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACpC,MAA0C,EAC1C,OAAiC,EAChC,EAAE;IACH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAE,EAA8B,CAAC;IACjE,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;IAEjC,yFAAyF;IACzF,OAAO,2BAA2B,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACnF,CAAC,CAAC"}
1
+ {"version":3,"file":"useDocumentListEffect.js","sourceRoot":"","sources":["../../../../src/data/DocumentStore/hooks/useDocumentListEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAG7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACpC,MAA0C,EAC1C,OAAiC,EAChC,EAAE;IACH,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAE,EAA8B,CAAC;IACjE,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAC;IAEjC,yFAAyF;IACzF,OAAO,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC"}
@@ -1,7 +1,9 @@
1
1
  import { IDocument } from "../../interfaces";
2
+ import { ListDataContextState } from "@voplus/morpho-ui/es/data";
2
3
  /** React hook to retrieve a list of documents from a loader
4
+ * @param list - List state used to update loading and hasMore states.
3
5
  * @param effect - Effect callback to be ran after successful retrieved the list. Loading will be ignored if effect is null.
4
6
  * @param {Promise<T[]>} loader - a function return promise of list of documents.
5
7
  * @param deps - a list of dependencies
6
8
  */
7
- export declare function useDocumentListLoaderEffect<T extends IDocument>(effect: (list: T[]) => void | null, loader: () => Promise<T[]>, deps?: any[]): void;
9
+ export declare function useDocumentListLoaderEffect<T extends IDocument>(list: ListDataContextState<T> | null, effect: (list: T[]) => void | null, loader: () => Promise<T[]>, deps?: any[]): void;
@@ -1,28 +1,27 @@
1
1
  import { useCountedMapListEffect } from "@voplus/morpho-data";
2
2
  import { useDocumentStore } from "../DocumentStore";
3
- import { useListDataContext } from "@voplus/morpho-ui/es/data";
4
3
  /** React hook to retrieve a list of documents from a loader
4
+ * @param list - List state used to update loading and hasMore states.
5
5
  * @param effect - Effect callback to be ran after successful retrieved the list. Loading will be ignored if effect is null.
6
6
  * @param {Promise<T[]>} loader - a function return promise of list of documents.
7
7
  * @param deps - a list of dependencies
8
8
  */
9
- export function useDocumentListLoaderEffect(effect, loader, deps) {
9
+ export function useDocumentListLoaderEffect(list, effect, loader, deps) {
10
10
  const documents = useDocumentStore();
11
- const listData = useListDataContext();
12
11
  useCountedMapListEffect(innerEffect, documents.items, loader, deps, {
13
12
  preload: () => {
14
- if (listData)
15
- listData.loading = true;
13
+ if (list)
14
+ list.loading = true;
16
15
  },
17
16
  postload: () => {
18
- if (listData)
19
- listData.loading = false;
17
+ if (list)
18
+ list.loading = false;
20
19
  }
21
20
  });
22
- function innerEffect(list) {
23
- if (listData && list.length === 0)
24
- listData.hasMore = false;
25
- effect(list);
21
+ function innerEffect(result) {
22
+ if (list && result.length < list.filters.paging.PageSize)
23
+ list.hasMore = false;
24
+ effect(result);
26
25
  }
27
26
  }
28
27
  //# sourceMappingURL=useDocumentListLoaderEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDocumentListLoaderEffect.js","sourceRoot":"","sources":["../../../../src/data/DocumentStore/hooks/useDocumentListLoaderEffect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;GAIG;AACH,MAAM,UAAU,2BAA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,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAChC,CAAC;KACD,CAAC,CAAC;IAEH,SAAS,WAAW,CAAC,MAAW;QAC/B,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;YAAE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QAC/E,MAAM,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voplus/morpho-document",
3
- "version": "1.0.0-dev205",
3
+ "version": "1.0.0-dev207",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://voplus.visualstudio.com/morpho-document/_git/morpho-document"
@@ -58,7 +58,7 @@
58
58
  "@voplus/morpho-data": "^1.0.0-dev095",
59
59
  "@voplus/morpho-org": "^1.0.0-dev032-antd4",
60
60
  "@voplus/morpho-text": "^1.0.0-dev016",
61
- "@voplus/morpho-ui": "^1.0.0-listview006",
61
+ "@voplus/morpho-ui": "^1.0.0-dev104",
62
62
  "draft-js": "^0.11.5",
63
63
  "mobx": "^5.15.4",
64
64
  "mobx-react-lite": "^1.5.2",