@usereactify/search 5.5.0 → 5.6.0-beta.1

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,36 @@
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
+ ## [5.6.0-beta.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.6.0-beta.0...beta-v5.6.0-beta.1) (2022-10-10)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * skip sort option logic for instant search ([4ef922f](https://bitbucket.org/usereactify/reactify-search-ui/commit/4ef922ffe553c51ee90cd5ae6de2f5292bbf6734))
11
+
12
+ ## [5.6.0-beta.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.2.2-beta.0...beta-v5.6.0-beta.0) (2022-10-10)
13
+
14
+
15
+ ### Features
16
+
17
+ * add scrollPosition prop to Results to trigger load more ([c2dc2a4](https://bitbucket.org/usereactify/reactify-search-ui/commit/c2dc2a44c853f52691f11ffc8459e64e6ea439ed))
18
+ * add scrollTarget prop and infinite scroll pagination rendered ([11f4d02](https://bitbucket.org/usereactify/reactify-search-ui/commit/11f4d02b43058e65a1d1ffa5f96a311f102ef6cf))
19
+ * align queries and sensors for both search and instant search modes ([481c9c6](https://bitbucket.org/usereactify/reactify-search-ui/commit/481c9c62a0c6f3088dd2b0bc2f0fcbb94cbebf9a))
20
+ * switch from npm to pnpm ([1166f9a](https://bitbucket.org/usereactify/reactify-search-ui/commit/1166f9ae5eab18e4519c3b5be7c9fd5526e6c35e))
21
+ * upgrade to react 18 ([f059591](https://bitbucket.org/usereactify/reactify-search-ui/commit/f059591a752fa4cf3a3bfd3709c1053224e1fcdf))
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * add debounce and tracking to search term sensor ([7563319](https://bitbucket.org/usereactify/reactify-search-ui/commit/75633197026554b1835ab1f683edc5cc8fcb35c7))
27
+ * add lib options to tsconfig ([11da357](https://bitbucket.org/usereactify/reactify-search-ui/commit/11da3571dce6bf8039863fd49bf403c68b8f168d))
28
+ * correctly apply weights for phrase-prefix ([88dbac1](https://bitbucket.org/usereactify/reactify-search-ui/commit/88dbac1c902691f6fba99e4a1b2dfab883f00dd7))
29
+ * minor clean up for react 18 ([c8a4775](https://bitbucket.org/usereactify/reactify-search-ui/commit/c8a477585acb01960a69734688fe6eac6ae6b672))
30
+ * switch from usePaginationLoadMore to usePaginationLoadable ([1337749](https://bitbucket.org/usereactify/reactify-search-ui/commit/1337749b0806d82a5026600387edd91886f3f4c5))
31
+ * track zeroResults event when the result data changes rather than the search term ([c10bb44](https://bitbucket.org/usereactify/reactify-search-ui/commit/c10bb4427b77e1cb6581ca35f43b56fd7e715670))
32
+ * use pnpm during cicd build process ([fb7c399](https://bitbucket.org/usereactify/reactify-search-ui/commit/fb7c39922afe269af4d93bf59da16874fe671ec7))
33
+ * weight search matches higher when field starts with term ([db1d430](https://bitbucket.org/usereactify/reactify-search-ui/commit/db1d43024dc97fb2547c7656b109d34becee6e45))
34
+
5
35
  ## [5.5.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.4.0...release-v5.5.0) (2022-10-06)
6
36
 
7
37
 
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": "5.5.0",
4
+ "version": "5.6.0-beta.1",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",
@@ -62,7 +62,7 @@ const SensorSearchTerm = () => {
62
62
  const query = {
63
63
  bool: {
64
64
  should: [
65
- ...(options.mode === "search" && value
65
+ ...(value
66
66
  ? [
67
67
  {
68
68
  nested: {
@@ -1 +1 @@
1
- {"version":3,"file":"SensorSearchTerm.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSearchTerm.tsx"],"names":[],"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AM,EAAE,kBAAkB;4CAC1B,IAAI,EAAE,eAAe;4CACrB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;gCAC9B,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,iBAAiB;4CACzB,IAAI,EAAE,cAAc;4CACpB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;yBAC5D;wBACD,oBAAoB,EAAE,GAAG;qBAC1B;iBACF,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,CAAC,GACD,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AA3JW,QAAA,gBAAgB,oBA2J3B","sourcesContent":["import React from \"react\";\nimport { useDebounceFn } from \"ahooks\";\nimport DataSearch from \"@appbaseio/reactivesearch/lib/components/search/DataSearch\";\n\nimport { useAnalytics, useReactifySearchContext, useSearch } from \"../../hooks\";\n\nexport const SensorSearchTerm: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { track } = useAnalytics();\n const { searchTerm } = useSearch();\n const [searchTermDebounced, setSearchTermDebounced] =\n React.useState<string>(\"\");\n\n // ignore search fields only set for instant search\n const searchFields = React.useMemo(() => {\n if (options.mode === \"search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"search_page\"].includes(field.searchType)\n );\n }\n\n if (options.mode === \"instant-search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"instant_search\"].includes(field.searchType)\n );\n }\n\n return [];\n }, [config.fields]);\n\n const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } =\n useDebounceFn(\n (value: string) => {\n setSearchTermDebounced(value);\n\n if (!value || (value && value.length < 3)) {\n return;\n }\n\n track({\n eventName: \"search\",\n payload: {\n searchTerm: value,\n },\n });\n },\n {\n wait: 300,\n }\n );\n\n React.useEffect(() => {\n runDebouncedTriggerQuery(searchTerm);\n }, [searchTerm]);\n\n if (searchFields.length === 0) {\n return null;\n }\n\n return (\n <>\n <DataSearch\n fuzziness={1}\n queryFormat=\"and\"\n autosuggest={false}\n value={searchTermDebounced}\n componentId=\"SensorSearchTerm\"\n style={{ display: \"none\" }}\n dataField={searchFields.map((field) => field.field)}\n fieldWeights={searchFields.map((field) => field.importance)}\n customQuery={(value, props) => {\n const { dataField, fieldWeights } = props;\n\n const fieldsCrossFields = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrase = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrasePrefix = dataField\n .map(\n (field: string, index: number) =>\n `${field}^${fieldWeights[index]}`\n )\n .filter((field: string) => !field.includes(\".\"));\n\n const fieldsSpanFirst: any = dataField.map((field: string) => ({\n span_first: {\n match: {\n span_term: { [`${field}`]: value },\n },\n end: 1,\n },\n }));\n\n const query = {\n bool: {\n should: [\n ...(options.mode === \"search\" && value\n ? [\n {\n nested: {\n path: \"curations\",\n query: {\n term: {\n \"curations.searchTerm.keyword\":\n value.toLowerCase(),\n },\n },\n },\n },\n ]\n : []),\n ...(fieldsPhrase.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrase,\n type: \"phrase\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsPhrasePrefix.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrasePrefix,\n type: \"phrase_prefix\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsCrossFields.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsCrossFields,\n type: \"cross_fields\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsSpanFirst.length > 0 ? [...fieldsSpanFirst] : []),\n ],\n minimum_should_match: \"1\",\n },\n };\n return { query };\n }}\n />\n </>\n );\n};\n"]}
1
+ {"version":3,"file":"SensorSearchTerm.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSearchTerm.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAuC;AACvC,4GAAoF;AAEpF,uCAAgF;AAEzE,MAAM,gBAAgB,GAAa,GAAG,EAAE;IAC7C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IACjC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IACnC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GACjD,eAAK,CAAC,QAAQ,CAAS,EAAE,CAAC,CAAC;IAE7B,mDAAmD;IACnD,MAAM,YAAY,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACtC,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACpC,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAC5D,CAAC;SACH;QAED,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;YACrC,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACpC,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAC/D,CAAC;SACH;QAED,OAAO,EAAE,CAAC;IACZ,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAEpB,MAAM,EAAE,GA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iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC;gCAC/B,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,kBAAkB;4CAC1B,IAAI,EAAE,eAAe;4CACrB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC;gCAC9B,CAAC,CAAC;oCACE;wCACE,WAAW,EAAE;4CACX,KAAK,EAAE,KAAK;4CACZ,MAAM,EAAE,iBAAiB;4CACzB,IAAI,EAAE,cAAc;4CACpB,QAAQ,EAAE,KAAK;yCAChB;qCACF;iCACF;gCACH,CAAC,CAAC,EAAE,CAAC;4BACP,GAAG,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;yBAC5D;wBACD,oBAAoB,EAAE,GAAG;qBAC1B;iBACF,CAAC;gBACF,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,CAAC,GACD,CACD,CACJ,CAAC;AACJ,CAAC,CAAC;AA3JW,QAAA,gBAAgB,oBA2J3B","sourcesContent":["import React from \"react\";\nimport { useDebounceFn } from \"ahooks\";\nimport DataSearch from \"@appbaseio/reactivesearch/lib/components/search/DataSearch\";\n\nimport { useAnalytics, useReactifySearchContext, useSearch } from \"../../hooks\";\n\nexport const SensorSearchTerm: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { track } = useAnalytics();\n const { searchTerm } = useSearch();\n const [searchTermDebounced, setSearchTermDebounced] =\n React.useState<string>(\"\");\n\n // ignore search fields only set for instant search\n const searchFields = React.useMemo(() => {\n if (options.mode === \"search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"search_page\"].includes(field.searchType)\n );\n }\n\n if (options.mode === \"instant-search\") {\n return config.fields.filter((field) =>\n [\"always_search\", \"instant_search\"].includes(field.searchType)\n );\n }\n\n return [];\n }, [config.fields]);\n\n const { run: runDebouncedTriggerQuery, cancel: cancelDebouncedTriggerQuery } =\n useDebounceFn(\n (value: string) => {\n setSearchTermDebounced(value);\n\n if (!value || (value && value.length < 3)) {\n return;\n }\n\n track({\n eventName: \"search\",\n payload: {\n searchTerm: value,\n },\n });\n },\n {\n wait: 300,\n }\n );\n\n React.useEffect(() => {\n runDebouncedTriggerQuery(searchTerm);\n }, [searchTerm]);\n\n if (searchFields.length === 0) {\n return null;\n }\n\n return (\n <>\n <DataSearch\n fuzziness={1}\n queryFormat=\"and\"\n autosuggest={false}\n value={searchTermDebounced}\n componentId=\"SensorSearchTerm\"\n style={{ display: \"none\" }}\n dataField={searchFields.map((field) => field.field)}\n fieldWeights={searchFields.map((field) => field.importance)}\n customQuery={(value, props) => {\n const { dataField, fieldWeights } = props;\n\n const fieldsCrossFields = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrase = dataField.map(\n (field: string, index: number) => `${field}^${fieldWeights[index]}`\n );\n\n const fieldsPhrasePrefix = dataField\n .map(\n (field: string, index: number) =>\n `${field}^${fieldWeights[index]}`\n )\n .filter((field: string) => !field.includes(\".\"));\n\n const fieldsSpanFirst: any = dataField.map((field: string) => ({\n span_first: {\n match: {\n span_term: { [`${field}`]: value },\n },\n end: 1,\n },\n }));\n\n const query = {\n bool: {\n should: [\n ...(value\n ? [\n {\n nested: {\n path: \"curations\",\n query: {\n term: {\n \"curations.searchTerm.keyword\":\n value.toLowerCase(),\n },\n },\n },\n },\n ]\n : []),\n ...(fieldsPhrase.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrase,\n type: \"phrase\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsPhrasePrefix.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsPhrasePrefix,\n type: \"phrase_prefix\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsCrossFields.length > 0\n ? [\n {\n multi_match: {\n query: value,\n fields: fieldsCrossFields,\n type: \"cross_fields\",\n operator: \"and\",\n },\n },\n ]\n : []),\n ...(fieldsSpanFirst.length > 0 ? [...fieldsSpanFirst] : []),\n ],\n minimum_should_match: \"1\",\n },\n };\n return { query };\n }}\n />\n </>\n );\n};\n"]}
@@ -15,6 +15,7 @@ const SensorSort = () => {
15
15
  const { sort, query } = react_1.default.useMemo(() => {
16
16
  return {
17
17
  sort: buildSort({
18
+ mode: options.mode,
18
19
  globalCuration,
19
20
  curation,
20
21
  sortOption,
@@ -35,17 +36,19 @@ const SensorSort = () => {
35
36
  exports.SensorSort = SensorSort;
36
37
  const buildSort = (args) => {
37
38
  var _a;
38
- const { curation, sortOption, collectionHandle, globalCuration } = args;
39
- // return default sort option if unset
40
- if (!sortOption) {
41
- return collectionHandle
42
- ? mapCollectionPositionSortClause(collectionHandle)
43
- : ["_score"];
44
- }
45
- // curation positions are only applied for the default `collections.position` or `_score` sort
46
- // if the sort is something else, apply a normal sort which applies what the user has requested
47
- if (!["_score", "collections.position"].includes(sortOption.field)) {
48
- return [{ [sortOption.field]: sortOption.direction }];
39
+ const { mode, curation, sortOption, collectionHandle, globalCuration } = args;
40
+ if (mode !== "instant-search") {
41
+ // return default sort option if unset
42
+ if (!sortOption) {
43
+ return collectionHandle
44
+ ? mapCollectionPositionSortClause(collectionHandle)
45
+ : ["_score"];
46
+ }
47
+ // curation positions are only applied for the default `collections.position` or `_score` sort
48
+ // if the sort is something else, apply a normal sort which applies what the user has requested
49
+ if (!["_score", "collections.position"].includes(sortOption.field)) {
50
+ return [{ [sortOption.field]: sortOption.direction }];
51
+ }
49
52
  }
50
53
  // no matching curation, return default sort clause
51
54
  if (!curation) {
@@ -58,7 +61,7 @@ const buildSort = (args) => {
58
61
  if (globalCuration && collectionHandle) {
59
62
  sorts.push(...mapCollectionPositionSortClause(collectionHandle));
60
63
  }
61
- if (!globalCuration && curation.collectionHandle || curation.searchTerm) {
64
+ if ((!globalCuration && curation.collectionHandle) || curation.searchTerm) {
62
65
  sorts.push({
63
66
  "curations.position": {
64
67
  unmapped_type: "long",
@@ -1 +1 @@
1
- {"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAA+E;AAExE,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;IACnC,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE,CAAC;IAEnC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,eAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACzC,OAAO;YACL,IAAI,EAAE,SAAS,CAAC;gBACd,cAAc;gBACd,QAAQ;gBACR,UAAU;gBACV,gBAAgB,EACd,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS;aACvE,CAAC;YACF,KAAK,EAAE,UAAU,CAAC;gBAChB,UAAU;gBACV,QAAQ;gBACR,cAAc;aACf,CAAC;SACH,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnC,OAAO,CACL,8BAAC,2BAAiB,IAChB,WAAW,EAAC,YAAY,EACxB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YAClB,IAAI;YACJ,KAAK;SACN,CAAC,GACF,CACH,CAAC;AACJ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AAC,IAAI;gDAC5B,CAAC,CAAC,kBAAkB;gDACpB,CAAC,CAAC,YACN,UAAU,CAAC,EACT,YAAY,KAAK,QAAQ,CAAC,IAAI;gDAC5B,CAAC,CAAC,QAAQ,CAAC,gBAAgB;gDAC3B,CAAC,CAAC,MAAA,QAAQ,CAAC,UAAU,0CAAE,WAAW,EAAE;yCACzC;qCACF;oCACD;wCACE,IAAI,EAAE;4CACJ,kBAAkB,EAAE,IAAI;yCACzB;qCACF;iCACF;6BACF;yBACF;qBACF;iBACF;gBACD,kEAAkE;gBAClE,GAAG,CAAC,UAAU;oBACd,CAAC,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;oBAC5D,CAAC,CAAC;wBACE;4BACE,IAAI,EAAE;gCACJ,IAAI,EAAE,SAAS;6BAChB;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport { useReactifySearchContext, useSortBy, useCuration } from \"../../hooks\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n const globalCuration = curation?.id === \"global\";\n\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n globalCuration,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n globalCuration,\n }),\n };\n }, [config, sortOption, curation]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n globalCuration?: boolean;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { curation, sortOption, collectionHandle, globalCuration } = args;\n\n // return default sort option if unset\n if (!sortOption) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n\n // no matching curation, return default sort clause\n if (!curation) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n const sorts = [];\n\n // show pins first\n if (globalCuration && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\n if (!globalCuration && curation.collectionHandle || curation.searchTerm) {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n },\n },\n });\n }\n\n if (0 < curation.boosting.groupings.length) {\n const groupings = curation.boosting.groupings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost grouping`, grouping);\n }\n }\n }\n\n if (0 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n\n // finally, for collections, if no other sorting is defined, sort by index order to provide\n // a consistent order\n if (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n globalCuration?: boolean;\n}): Record<string, any> | undefined => {\n const { curation, sortOption, globalCuration } = args;\n\n if (!curation || globalCuration) {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
1
+ {"version":3,"file":"SensorSort.js","sourceRoot":"","sources":["../../../../src/components/Sensor/SensorSort.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AAGjG,uCAKqB;AAGd,MAAM,UAAU,GAAa,GAAG,EAAE;IACvC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IACvD,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAA,mBAAW,GAAE,CAAC;IACnC,MAAM,cAAc,GAAG,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,MAAK,QAAQ,CAAC;IAEjD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,iBAAS,GAAE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AI,EAAE,SAAS;6BAChB;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\n\nimport { ConfigCuration, ConfigSort } from \"../../types\";\nimport {\n useReactifySearchContext,\n useSortBy,\n useCuration,\n ReactifySearchMode,\n} from \"../../hooks\";\nimport { optionsToId } from \"react-intersection-observer/observe\";\n\nexport const SensorSort: React.FC = () => {\n const { options, config } = useReactifySearchContext();\n const { curation } = useCuration();\n const globalCuration = curation?.id === \"global\";\n\n const { sortOption } = useSortBy();\n\n const { sort, query } = React.useMemo(() => {\n return {\n sort: buildSort({\n mode: options.mode,\n globalCuration,\n curation,\n sortOption,\n collectionHandle:\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n }),\n query: buildQuery({\n sortOption,\n curation,\n globalCuration,\n }),\n };\n }, [config, sortOption, curation]);\n\n return (\n <ReactiveComponent\n componentId=\"SensorSort\"\n customQuery={() => ({\n sort,\n query,\n })}\n />\n );\n};\n\nconst buildSort = (args: {\n mode: ReactifySearchMode;\n globalCuration: boolean;\n curation?: ConfigCuration;\n sortOption?: ConfigSort;\n collectionHandle?: string;\n}): any[] => {\n const { mode, curation, sortOption, collectionHandle, globalCuration } = args;\n\n if (mode !== \"instant-search\") {\n // return default sort option if unset\n if (!sortOption) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n // curation positions are only applied for the default `collections.position` or `_score` sort\n // if the sort is something else, apply a normal sort which applies what the user has requested\n if (![\"_score\", \"collections.position\"].includes(sortOption.field)) {\n return [{ [sortOption.field]: sortOption.direction }];\n }\n }\n\n // no matching curation, return default sort clause\n if (!curation) {\n return collectionHandle\n ? mapCollectionPositionSortClause(collectionHandle)\n : [\"_score\"];\n }\n\n const sorts = [];\n\n // show pins first\n if (globalCuration && collectionHandle) {\n sorts.push(...mapCollectionPositionSortClause(collectionHandle));\n }\n if ((!globalCuration && curation.collectionHandle) || curation.searchTerm) {\n sorts.push({\n \"curations.position\": {\n unmapped_type: \"long\",\n order: \"asc\",\n nested: {\n path: \"curations\",\n filter: {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n },\n },\n });\n }\n\n if (0 < curation.boosting.groupings.length) {\n const groupings = curation.boosting.groupings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const grouping of groupings) {\n try {\n const query = JSON.parse(grouping.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost grouping`, grouping);\n }\n }\n }\n\n if (0 < curation.boosting.sortings.length) {\n const sortings = curation.boosting.sortings.sort((a, b) =>\n a.position > b.position ? 1 : -1\n );\n\n for (const sorting of sortings) {\n try {\n const query = JSON.parse(sorting.query);\n if (query) sorts.push(query);\n } catch {\n console.error(`query could not be parsed for boost sorting`, sorting);\n }\n }\n }\n\n // finally, for collections, if no other sorting is defined, sort by index order to provide\n // a consistent order\n if (\"collection\" === curation.type && sorts.length === 0) {\n sorts.push(\"_doc\");\n }\n\n // finally, for search, sort by score\n if (\"search\" === curation.type) {\n sorts.push(\"_score\");\n }\n\n return sorts;\n};\n\n/**\n * Return a sort clause which sorts by position within the given collection.\n */\nfunction mapCollectionPositionSortClause(collectionHandle: string) {\n return [\n {\n \"collections.position\": {\n order: \"asc\",\n nested: {\n path: \"collections\",\n filter: {\n term: {\n \"collections.handle.keyword\": collectionHandle,\n },\n },\n },\n },\n },\n ];\n}\n\nconst buildQuery = (args: {\n sortOption?: ConfigSort;\n curation?: ConfigCuration;\n globalCuration?: boolean;\n}): Record<string, any> | undefined => {\n const { curation, sortOption, globalCuration } = args;\n\n if (!curation || globalCuration) {\n return undefined;\n }\n\n return {\n bool: {\n must_not: [\n {\n nested: {\n path: \"curations\",\n query: {\n bool: {\n must: [\n {\n term: {\n [`curations.${\n \"collection\" === curation.type\n ? \"collectionHandle\"\n : \"searchTerm\"\n }.keyword`]:\n \"collection\" === curation.type\n ? curation.collectionHandle\n : curation.searchTerm?.toLowerCase(),\n },\n },\n {\n term: {\n \"curations.hidden\": true,\n },\n },\n ],\n },\n },\n },\n },\n // hide callout when not sorting by _score or collections.position\n ...(sortOption &&\n ![\"_score\", \"collections.position\"].includes(sortOption.field)\n ? [\n {\n term: {\n type: \"callout\",\n },\n },\n ]\n : []),\n ],\n },\n };\n};\n"]}
@@ -7,13 +7,18 @@ exports.Sensors = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const hooks_1 = require("../../hooks");
9
9
  const SensorSort_1 = require("./SensorSort");
10
- const SensorSortScore_1 = require("./SensorSortScore");
11
10
  const SensorPublished_1 = require("./SensorPublished");
12
11
  const SensorCollection_1 = require("./SensorCollection");
13
12
  const SensorSearchTerm_1 = require("./SensorSearchTerm");
14
13
  const SensorInventoryAvailable_1 = require("./SensorInventoryAvailable");
15
14
  const Sensors = () => {
16
15
  const { options } = (0, hooks_1.useReactifySearchContext)();
16
+ if (options.mode === "instant-search") {
17
+ return (react_1.default.createElement(react_1.default.Fragment, null,
18
+ react_1.default.createElement(SensorSort_1.SensorSort, null),
19
+ react_1.default.createElement(SensorPublished_1.SensorPublished, null),
20
+ react_1.default.createElement(SensorSearchTerm_1.SensorSearchTerm, null)));
21
+ }
17
22
  if (options.mode === "search") {
18
23
  return (react_1.default.createElement(react_1.default.Fragment, null,
19
24
  react_1.default.createElement(SensorSort_1.SensorSort, null),
@@ -28,12 +33,6 @@ const Sensors = () => {
28
33
  react_1.default.createElement(SensorCollection_1.SensorCollection, null),
29
34
  react_1.default.createElement(SensorInventoryAvailable_1.SensorInventoryAvailable, null)));
30
35
  }
31
- if (options.mode === "instant-search") {
32
- return (react_1.default.createElement(react_1.default.Fragment, null,
33
- react_1.default.createElement(SensorSortScore_1.SensorSortScore, null),
34
- react_1.default.createElement(SensorPublished_1.SensorPublished, null),
35
- react_1.default.createElement(SensorSearchTerm_1.SensorSearchTerm, null)));
36
- }
37
36
  return null;
38
37
  };
39
38
  exports.Sensors = Sensors;
@@ -1 +1 @@
1
- {"version":3,"file":"Sensors.js","sourceRoot":"","sources":["../../../../src/components/Sensor/Sensors.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAuD;AAEvD,6CAA0C;AAC1C,uDAAoD;AACpD,uDAAoD;AACpD,yDAAsD;AACtD,yDAAsD;AACtD,yEAAsE;AAM/D,MAAM,OAAO,GAA2B,GAAG,EAAE;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7B,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG,CAC3B,CACJ,CAAC;KACH;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE;QACjC,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG,CAC3B,CACJ,CAAC;KACH;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;QACrC,OAAO,CACL;YACE,8BAAC,iCAAe,OAAG;YACnB,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG,CACnB,CACJ,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AApCW,QAAA,OAAO,WAoClB","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nimport { SensorSort } from \"./SensorSort\";\nimport { SensorSortScore } from \"./SensorSortScore\";\nimport { SensorPublished } from \"./SensorPublished\";\nimport { SensorCollection } from \"./SensorCollection\";\nimport { SensorSearchTerm } from \"./SensorSearchTerm\";\nimport { SensorInventoryAvailable } from \"./SensorInventoryAvailable\";\n\nexport type SensorsProps = {\n /** This component does not support any props */\n};\n\nexport const Sensors: React.FC<SensorsProps> = () => {\n const { options } = useReactifySearchContext();\n\n if (options.mode === \"search\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorSearchTerm />\n <SensorInventoryAvailable />\n </>\n );\n }\n\n if (options.mode === \"collection\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorCollection />\n <SensorInventoryAvailable />\n </>\n );\n }\n\n if (options.mode === \"instant-search\") {\n return (\n <>\n <SensorSortScore />\n <SensorPublished />\n <SensorSearchTerm />\n </>\n );\n }\n\n return null;\n};\n"]}
1
+ {"version":3,"file":"Sensors.js","sourceRoot":"","sources":["../../../../src/components/Sensor/Sensors.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,uCAAuD;AAEvD,6CAA0C;AAC1C,uDAAoD;AACpD,yDAAsD;AACtD,yDAAsD;AACtD,yEAAsE;AAM/D,MAAM,OAAO,GAA2B,GAAG,EAAE;IAClD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAE/C,IAAI,OAAO,CAAC,IAAI,KAAK,gBAAgB,EAAE;QACrC,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG,CACnB,CACJ,CAAC;KACH;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7B,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG,CAC3B,CACJ,CAAC;KACH;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,YAAY,EAAE;QACjC,OAAO,CACL;YACE,8BAAC,uBAAU,OAAG;YACd,8BAAC,iCAAe,OAAG;YACnB,8BAAC,mCAAgB,OAAG;YACpB,8BAAC,mDAAwB,OAAG,CAC3B,CACJ,CAAC;KACH;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AApCW,QAAA,OAAO,WAoClB","sourcesContent":["import React from \"react\";\n\nimport { useReactifySearchContext } from \"../../hooks\";\n\nimport { SensorSort } from \"./SensorSort\";\nimport { SensorPublished } from \"./SensorPublished\";\nimport { SensorCollection } from \"./SensorCollection\";\nimport { SensorSearchTerm } from \"./SensorSearchTerm\";\nimport { SensorInventoryAvailable } from \"./SensorInventoryAvailable\";\n\nexport type SensorsProps = {\n /** This component does not support any props */\n};\n\nexport const Sensors: React.FC<SensorsProps> = () => {\n const { options } = useReactifySearchContext();\n\n if (options.mode === \"instant-search\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorSearchTerm />\n </>\n );\n }\n\n if (options.mode === \"search\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorSearchTerm />\n <SensorInventoryAvailable />\n </>\n );\n }\n\n if (options.mode === \"collection\") {\n return (\n <>\n <SensorSort />\n <SensorPublished />\n <SensorCollection />\n <SensorInventoryAvailable />\n </>\n );\n }\n\n return null;\n};\n"]}
@@ -20,6 +20,10 @@ const useCuration = () => {
20
20
  var _a, _b;
21
21
  const normalisedSearchTerm = (_a = curation.searchTerm) === null || _a === void 0 ? void 0 : _a.toLowerCase().trim();
22
22
  const normalisedCollectionHandle = (_b = curation.collectionHandle) === null || _b === void 0 ? void 0 : _b.toLowerCase().trim();
23
+ if ("instant-search" === options.mode) {
24
+ return ("search" === curation.type &&
25
+ normalisedHandleOrSearchTerm === normalisedSearchTerm);
26
+ }
23
27
  if ("search" === options.mode) {
24
28
  return ("search" === curation.type &&
25
29
  normalisedHandleOrSearchTerm === normalisedSearchTerm);
@@ -1 +1 @@
1
- {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/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nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find(\n (curation) => curation.id === \"global\" && curation.type === options.mode\n );\n\n const curation = config.curations.find((curation) => {\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules || !globalCuration) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
1
+ {"version":3,"file":"useCuration.js","sourceRoot":"","sources":["../../../src/hooks/useCuration.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAA+D;AAC/D,wCAAmC;AA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W,QAAA,WAAW,eAwFtB","sourcesContent":["import React from \"react\";\n\nimport { ConfigCuration } from \"../types\";\nimport { useReactifySearchContext, useSearch } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useCuration = (): {\n curation?: ConfigCuration;\n} => {\n const { options, config } = useReactifySearchContext();\n const { searchTerm } = useSearch();\n\n const curation = React.useMemo(() => {\n const handleOrSearchTerm =\n options.mode === \"collection\" ? options.collectionHandle : searchTerm;\n\n const normalisedHandleOrSearchTerm = handleOrSearchTerm\n .toLowerCase()\n .trim();\n\n const globalCuration = config.curations.find(\n (curation) => curation.id === \"global\" && curation.type === options.mode\n );\n\n const curation = config.curations.find((curation) => {\n const normalisedSearchTerm = curation.searchTerm?.toLowerCase().trim();\n const normalisedCollectionHandle = curation.collectionHandle\n ?.toLowerCase()\n .trim();\n\n if (\"instant-search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"search\" === options.mode) {\n return (\n \"search\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedSearchTerm\n );\n }\n\n if (\"collection\" === options.mode) {\n return (\n \"collection\" === curation.type &&\n normalisedHandleOrSearchTerm === normalisedCollectionHandle\n );\n }\n\n return false;\n });\n\n const addGlobalBoosting = (curation: ConfigCuration) => {\n const curationIsCollection = curation.type === \"collection\";\n if (!curationIsCollection) {\n return curation;\n }\n\n const curationHasRules =\n !!curation.boosting.groupings.length ||\n !!curation.boosting.sortings.length;\n\n if (curationHasRules || !globalCuration) {\n return curation;\n }\n\n const curationWithGlobalBoosting = {\n ...curation,\n boosting: globalCuration.boosting,\n } as ConfigCuration;\n\n return curationWithGlobalBoosting;\n };\n\n return curation\n ? addGlobalBoosting(curation)\n : globalCuration\n ? globalCuration\n : undefined;\n }, [\n config,\n options.mode === \"collection\" ? options.collectionHandle : undefined,\n searchTerm,\n ]);\n\n React.useEffect(() => {\n debug.log(\"useCuration\", \"curation\", curation);\n }, [curation]);\n\n return {\n curation: curation,\n };\n};\n"]}
@@ -1,9 +1,10 @@
1
1
  import React from "react";
2
2
  import { Config } from "../types";
3
+ export declare type ReactifySearchMode = "search" | "collection" | "instant-search";
3
4
  export declare const ReactifySearchContext: React.Context<{
4
5
  config: Config;
5
6
  options: {
6
- mode: "search" | "collection" | "instant-search";
7
+ mode: ReactifySearchMode;
7
8
  index: string;
8
9
  shopifyPermanentDomain: string;
9
10
  filtersHandle?: string | undefined;
@@ -39,7 +40,7 @@ export declare const ReactifySearchContext: React.Context<{
39
40
  export declare const useReactifySearchContext: () => {
40
41
  config: Config;
41
42
  options: {
42
- mode: "search" | "collection" | "instant-search";
43
+ mode: ReactifySearchMode;
43
44
  index: string;
44
45
  shopifyPermanentDomain: string;
45
46
  filtersHandle?: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"useReactifySearchContext.js","sourceRoot":"","sources":["../../../src/hooks/useReactifySearchContext.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAIb,QAAA,qBAAqB,GAAG,eAAK,CAAC,aAAa,CA4CtD,SAAS,CAAC,CAAC;AAEN,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAC3C,eAAK,CAAC,UAAU,CAAC,6BAAqB,CAAE,CAAC;AAD9B,QAAA,wBAAwB,4BACM","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types\";\n\nexport const ReactifySearchContext = React.createContext<\n | {\n config: Config;\n options: {\n mode: \"search\" | \"collection\" | \"instant-search\";\n index: string;\n shopifyPermanentDomain: string;\n filtersHandle?: string;\n credentials: {\n username: string;\n password: string;\n endpoint: string;\n };\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n theme: Record<string, unknown>;\n additionalComponentIds?: Array<string>;\n includeFields?: Array<string>;\n excludeFields?: Array<string>;\n } & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n );\n search: {\n searchTerm: string;\n setSearchTerm: React.Dispatch<React.SetStateAction<string>>;\n showInstantSearchResults: boolean;\n setShowInstantSearchResults: React.Dispatch<\n React.SetStateAction<boolean>\n >;\n };\n sortby: {\n sortOption: string;\n setSortOption: React.Dispatch<React.SetStateAction<string>>;\n };\n }\n | undefined\n>(undefined);\n\nexport const useReactifySearchContext = () =>\n React.useContext(ReactifySearchContext)!;\n"]}
1
+ {"version":3,"file":"useReactifySearchContext.js","sourceRoot":"","sources":["../../../src/hooks/useReactifySearchContext.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAMb,QAAA,qBAAqB,GAAG,eAAK,CAAC,aAAa,CA4CtD,SAAS,CAAC,CAAC;AAEN,MAAM,wBAAwB,GAAG,GAAG,EAAE,CAC3C,eAAK,CAAC,UAAU,CAAC,6BAAqB,CAAE,CAAC;AAD9B,QAAA,wBAAwB,4BACM","sourcesContent":["import React from \"react\";\n\nimport { Config } from \"../types\";\n\nexport type ReactifySearchMode = \"search\" | \"collection\" | \"instant-search\";\n\nexport const ReactifySearchContext = React.createContext<\n | {\n config: Config;\n options: {\n mode: ReactifySearchMode;\n index: string;\n shopifyPermanentDomain: string;\n filtersHandle?: string;\n credentials: {\n username: string;\n password: string;\n endpoint: string;\n };\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n theme: Record<string, unknown>;\n additionalComponentIds?: Array<string>;\n includeFields?: Array<string>;\n excludeFields?: Array<string>;\n } & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n );\n search: {\n searchTerm: string;\n setSearchTerm: React.Dispatch<React.SetStateAction<string>>;\n showInstantSearchResults: boolean;\n setShowInstantSearchResults: React.Dispatch<\n React.SetStateAction<boolean>\n >;\n };\n sortby: {\n sortOption: string;\n setSortOption: React.Dispatch<React.SetStateAction<string>>;\n };\n }\n | undefined\n>(undefined);\n\nexport const useReactifySearchContext = () =>\n React.useContext(ReactifySearchContext)!;\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": "5.5.0",
4
+ "version": "5.6.0-beta.1",
5
5
  "license": "MIT",
6
6
  "main": "dist/src/index.js",
7
7
  "types": "dist/src/index.d.ts",