@usereactify/search 6.0.0 → 6.1.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [6.1.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v6.0.0...release-v6.1.0) (2023-09-13)
6
+
7
+
8
+ ### Features
9
+
10
+ * move results/resultStats data out of context and into custom events ([734bddb](https://bitbucket.org/usereactify/reactify-search-ui/commit/734bddb9baf778ef6620f00c5c177e1201642328))
11
+
5
12
  ## [6.0.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.32.0...release-v6.0.0) (2023-09-12)
6
13
 
7
14
 
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "6.0.0",
4
+ "version": "6.1.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { ReactivesearchResultProps } from "../types";
3
2
  /** This hook must never be used to render results */
4
3
  export declare const useResults: () => {
@@ -7,7 +6,7 @@ export declare const useResults: () => {
7
6
  /** All of the current results */
8
7
  results: ReactivesearchResultProps["data"];
9
8
  /** Function for setting the current results */
10
- setResults: React.Dispatch<React.SetStateAction<ReactivesearchResultProps["data"]>>;
9
+ setResults: (value: ReactivesearchResultProps["data"]) => void;
11
10
  /** All of the current result stats */
12
11
  resultStats?: {
13
12
  time: number;
@@ -19,5 +18,5 @@ export declare const useResults: () => {
19
18
  displayedResults: number;
20
19
  } | undefined;
21
20
  /** Function for setting the current result stats */
22
- setResultStats: React.Dispatch<React.SetStateAction<ReactivesearchResultProps["resultStats"] | undefined>>;
21
+ setResultStats: (value: ReactivesearchResultProps["resultStats"]) => void;
23
22
  };
@@ -5,24 +5,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useResults = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
- const hooks_1 = require("../hooks");
9
8
  const utility_1 = require("../utility");
10
9
  /** This hook must never be used to render results */
11
10
  const useResults = () => {
12
- var _a;
13
- const { results } = (0, hooks_1.useReactifySearchContext)();
11
+ const [results, setResults] = react_1.default.useState([]);
12
+ const [resultStats, setResultStats] = react_1.default.useState();
14
13
  const loading = react_1.default.useMemo(() => {
15
- var _a;
16
- return typeof ((_a = results.resultStats) === null || _a === void 0 ? void 0 : _a.numberOfResults) === "undefined";
17
- }, [(_a = results.resultStats) === null || _a === void 0 ? void 0 : _a.numberOfResults]);
18
- utility_1.debug.hook("useResults", "results", results.results);
19
- utility_1.debug.hook("useResults", "resultStats", results.resultStats);
14
+ return typeof (resultStats === null || resultStats === void 0 ? void 0 : resultStats.numberOfResults) === "undefined";
15
+ }, [resultStats === null || resultStats === void 0 ? void 0 : resultStats.numberOfResults]);
16
+ react_1.default.useEffect(() => {
17
+ const handler = (event) => {
18
+ setResults(event.detail);
19
+ };
20
+ window.addEventListener(`@usereactify/search:results:update`, handler);
21
+ return () => window.removeEventListener(`@usereactify/search:results:update`, handler);
22
+ }, []);
23
+ react_1.default.useEffect(() => {
24
+ const handler = (event) => {
25
+ setResultStats(event.detail);
26
+ };
27
+ window.addEventListener(`@usereactify/search:resultStats:update`, handler);
28
+ return () => window.removeEventListener(`@usereactify/search:resultStats:update`, handler);
29
+ }, []);
30
+ const handleSetResults = (value) => {
31
+ const event = new CustomEvent(`@usereactify/search:results:update`, {
32
+ detail: value
33
+ });
34
+ window.dispatchEvent(event);
35
+ };
36
+ const handleSetResultStats = (value) => {
37
+ const event = new CustomEvent(`@usereactify/search:resultStats:update`, {
38
+ detail: value
39
+ });
40
+ window.dispatchEvent(event);
41
+ };
42
+ utility_1.debug.hook("useResults", "results", results);
43
+ utility_1.debug.hook("useResults", "resultStats", resultStats);
20
44
  return {
21
45
  loading: loading,
22
- results: results.results,
23
- setResults: results.setResults,
24
- resultStats: results.resultStats,
25
- setResultStats: results.setResultStats,
46
+ results: results,
47
+ setResults: handleSetResults,
48
+ resultStats: resultStats,
49
+ setResultStats: handleSetResultStats,
26
50
  };
27
51
  };
28
52
  exports.useResults = useResults;
@@ -1 +1 @@
1
- {"version":3,"file":"useResults.js","sourceRoot":"","sources":["../../../src/hooks/useResults.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAoD;AACpD,wCAAmC;AAEnC,qDAAqD;AAC9C,MAAM,UAAU,GAAG,GAexB,EAAE;;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QACjC,OAAO,OAAO,CAAA,MAAA,OAAO,CAAC,WAAW,0CAAE,eAAe,CAAA,KAAK,WAAW,CAAC;IACrE,CAAC,EAAE,CAAC,MAAA,OAAO,CAAC,WAAW,0CAAE,eAAe,CAAC,CAAC,CAAC;IAE3C,eAAK,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACrD,eAAK,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAE7D,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,UAAU,cAgCrB","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\n\n/** This hook must never be used to render results */\nexport const useResults = (): {\n /** Equals true until first load has completed */\n loading: boolean;\n /** All of the current results */\n results: ReactivesearchResultProps[\"data\"];\n /** Function for setting the current results */\n setResults: React.Dispatch<\n React.SetStateAction<ReactivesearchResultProps[\"data\"]>\n >;\n /** All of the current result stats */\n resultStats?: ReactivesearchResultProps[\"resultStats\"];\n /** Function for setting the current result stats */\n setResultStats: React.Dispatch<\n React.SetStateAction<ReactivesearchResultProps[\"resultStats\"] | undefined>\n >;\n} => {\n const { results } = useReactifySearchContext();\n\n const loading = React.useMemo(() => {\n return typeof results.resultStats?.numberOfResults === \"undefined\";\n }, [results.resultStats?.numberOfResults]);\n\n debug.hook(\"useResults\", \"results\", results.results);\n debug.hook(\"useResults\", \"resultStats\", results.resultStats);\n\n return {\n loading: loading,\n results: results.results,\n setResults: results.setResults,\n resultStats: results.resultStats,\n setResultStats: results.setResultStats,\n };\n};\n"]}
1
+ {"version":3,"file":"useResults.js","sourceRoot":"","sources":["../../../src/hooks/useResults.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,wCAAmC;AAEnC,qDAAqD;AAC9C,MAAM,UAAU,GAAG,GAWxB,EAAE;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,eAAK,CAAC,QAAQ,CAE1C,EAAE,CAAC,CAAC;IACN,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GACjC,eAAK,CAAC,QAAQ,EAA4C,CAAC;IAE7D,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjC,OAAO,OAAO,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAA,KAAK,WAAW,CAAC;IAC7D,CAAC,EAAE,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,CAAC,CAAC,CAAC;IAEnC,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MA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L,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,gBAAgB;QAC5B,WAAW,EAAE,WAAW;QACxB,cAAc,EAAE,oBAAoB;KACrC,CAAC;AACJ,CAAC,CAAC;AAlFW,QAAA,UAAU,cAkFrB","sourcesContent":["import React from \"react\";\n\nimport { ReactivesearchResultProps } from \"../types\";\nimport { debug } from \"../utility\";\n\n/** This hook must never be used to render results */\nexport const useResults = (): {\n /** Equals true until first load has completed */\n loading: boolean;\n /** All of the current results */\n results: ReactivesearchResultProps[\"data\"];\n /** Function for setting the current results */\n setResults: (value: ReactivesearchResultProps[\"data\"]) => void;\n /** All of the current result stats */\n resultStats?: ReactivesearchResultProps[\"resultStats\"];\n /** Function for setting the current result stats */\n setResultStats: (value: ReactivesearchResultProps[\"resultStats\"]) => void;\n} => {\n const [results, setResults] = React.useState<\n ReactivesearchResultProps[\"data\"]\n >([]);\n const [resultStats, setResultStats] =\n React.useState<ReactivesearchResultProps[\"resultStats\"]>();\n\n const loading = React.useMemo(() => {\n return typeof resultStats?.numberOfResults === \"undefined\";\n }, [resultStats?.numberOfResults]);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<typeof results>\n ) => {\n setResults(event.detail);\n };\n window.addEventListener(\n `@usereactify/search:results:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:results:update`,\n handler as EventListener\n );\n }, []);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<typeof resultStats>\n ) => {\n setResultStats(event.detail);\n };\n window.addEventListener(\n `@usereactify/search:resultStats:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:resultStats:update`,\n handler as EventListener\n );\n }, []);\n\n const handleSetResults = (value: typeof results) => {\n const event = new CustomEvent<typeof results>(`@usereactify/search:results:update`, {\n detail: value\n });\n window.dispatchEvent(event);\n }\n\n const handleSetResultStats = (value: typeof resultStats) => {\n const event = new CustomEvent<typeof resultStats>(`@usereactify/search:resultStats:update`, {\n detail: value\n });\n window.dispatchEvent(event);\n }\n\n debug.hook(\"useResults\", \"results\", results);\n debug.hook(\"useResults\", \"resultStats\", resultStats);\n\n return {\n loading: loading,\n results: results,\n setResults: handleSetResults,\n resultStats: resultStats,\n setResultStats: handleSetResultStats,\n };\n};\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@usereactify/search",
3
3
  "description": "React UI library for Reactify Search",
4
- "version": "6.0.0",
4
+ "version": "6.1.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",