@searchcraft/javascript-sdk 0.7.0 → 0.7.2
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/README.md +7 -1
- package/dist/cjs/{index-d4b4a45e.js → index-a81df4f0.js} +29 -113
- package/dist/{components/p-6cafd48d.js.map → cjs/index-a81df4f0.js.map} +1 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/searchcraft-base-search-result.cjs.entry.js +91 -44
- package/dist/cjs/searchcraft-base-search-result.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-base-search-results.cjs.entry.js +74 -50
- package/dist/cjs/searchcraft-base-search-results.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-button_3.cjs.entry.js +37 -36
- package/dist/cjs/searchcraft-button_3.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-facet-list_3.cjs.entry.js +141 -119
- package/dist/cjs/searchcraft-facet-list_3.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-filter-panel.cjs.entry.js +11 -14
- package/dist/cjs/searchcraft-filter-panel.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-input-form_2.cjs.entry.js +127 -92
- package/dist/cjs/searchcraft-input-form_2.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-javascript-sdk.cjs.js +2 -2
- package/dist/cjs/searchcraft-popover-button.cjs.entry.js +3 -7
- package/dist/cjs/searchcraft-popover-button.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-popover-form.cjs.entry.js +81 -75
- package/dist/cjs/searchcraft-popover-form.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-popover-list-item.cjs.entry.js +29 -6
- package/dist/cjs/searchcraft-popover-list-item.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-results-info.cjs.entry.js +9 -13
- package/dist/cjs/searchcraft-results-info.cjs.entry.js.map +1 -1
- package/dist/cjs/searchcraft-theme.cjs.entry.js +38 -0
- package/dist/cjs/searchcraft-theme.cjs.entry.js.map +1 -0
- package/dist/cjs/{store-abe47006.js → store-f6ba3dfb.js} +26 -10
- package/dist/cjs/{store-abe47006.js.map → store-f6ba3dfb.js.map} +1 -1
- package/dist/collection/collection-manifest.json +1 -0
- package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.js +102 -62
- package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.js.map +1 -1
- package/dist/collection/components/searchcraft-base-search-results/searchcraft-base-search-results.js +77 -61
- package/dist/collection/components/searchcraft-base-search-results/searchcraft-base-search-results.js.map +1 -1
- package/dist/collection/components/searchcraft-button/searchcraft-button.js +26 -30
- package/dist/collection/components/searchcraft-button/searchcraft-button.js.map +1 -1
- package/dist/collection/components/searchcraft-error-message/searchcraft-error-message.js +6 -12
- package/dist/collection/components/searchcraft-error-message/searchcraft-error-message.js.map +1 -1
- package/dist/collection/components/searchcraft-facet-list/searchcraft-facet-list.js +59 -51
- package/dist/collection/components/searchcraft-facet-list/searchcraft-facet-list.js.map +1 -1
- package/dist/collection/components/searchcraft-filter-panel/searchcraft-filter-panel.js +9 -20
- package/dist/collection/components/searchcraft-filter-panel/searchcraft-filter-panel.js.map +1 -1
- package/dist/collection/components/searchcraft-input-form/searchcraft-input-form.js +109 -87
- package/dist/collection/components/searchcraft-input-form/searchcraft-input-form.js.map +1 -1
- package/dist/collection/components/searchcraft-input-label/searchcraft-input-label.js +10 -20
- package/dist/collection/components/searchcraft-input-label/searchcraft-input-label.js.map +1 -1
- package/dist/collection/components/searchcraft-popover-button/searchcraft-popover-button.js +1 -11
- package/dist/collection/components/searchcraft-popover-button/searchcraft-popover-button.js.map +1 -1
- package/dist/collection/components/searchcraft-popover-form/searchcraft-popover-form.js +81 -82
- package/dist/collection/components/searchcraft-popover-form/searchcraft-popover-form.js.map +1 -1
- package/dist/collection/components/searchcraft-popover-list-item/searchcraft-popover-list-item.js +35 -17
- package/dist/collection/components/searchcraft-popover-list-item/searchcraft-popover-list-item.js.map +1 -1
- package/dist/collection/components/searchcraft-popover-list-view/searchcraft-popover-list-view.js +17 -19
- package/dist/collection/components/searchcraft-popover-list-view/searchcraft-popover-list-view.js.map +1 -1
- package/dist/collection/components/searchcraft-results-info/searchcraft-results-info.js +7 -19
- package/dist/collection/components/searchcraft-results-info/searchcraft-results-info.js.map +1 -1
- package/dist/collection/components/searchcraft-slider/searchcraft-slider.js +57 -65
- package/dist/collection/components/searchcraft-slider/searchcraft-slider.js.map +1 -1
- package/dist/collection/components/searchcraft-theme/searchcraft-theme.js +37 -0
- package/dist/collection/components/searchcraft-theme/searchcraft-theme.js.map +1 -0
- package/dist/collection/components/searchcraft-toggle-button/searchcraft-toggle-button.js +23 -26
- package/dist/collection/components/searchcraft-toggle-button/searchcraft-toggle-button.js.map +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/provider/store.js +25 -9
- package/dist/collection/provider/store.js.map +1 -1
- package/dist/collection/utils/facets.js +5 -3
- package/dist/collection/utils/facets.js.map +1 -1
- package/dist/components/index.js +4 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/p-0ef4ab33.js +66 -0
- package/dist/components/p-0ef4ab33.js.map +1 -0
- package/dist/components/p-1234974c.js +72 -0
- package/dist/components/p-1234974c.js.map +1 -0
- package/dist/components/p-4b92ae26.js +109 -0
- package/dist/components/p-4b92ae26.js.map +1 -0
- package/dist/components/{p-e1cf5f9d.js → p-506cdac1.js} +18 -14
- package/dist/components/p-506cdac1.js.map +1 -0
- package/dist/components/p-521fe971.js +60 -0
- package/dist/components/p-521fe971.js.map +1 -0
- package/dist/components/{p-6cafd48d.js → p-5365011f.js} +30 -123
- package/dist/components/p-5365011f.js.map +1 -0
- package/dist/components/p-54998882.js +285 -0
- package/dist/components/p-54998882.js.map +1 -0
- package/dist/{esm/store-712f0586.js → components/p-936e2ed4.js} +26 -10
- package/dist/components/{p-01dc5b3b.js.map → p-936e2ed4.js.map} +1 -1
- package/dist/components/p-960ddc89.js +284 -0
- package/dist/components/p-960ddc89.js.map +1 -0
- package/dist/components/p-a75ef832.js +34 -0
- package/dist/components/p-a75ef832.js.map +1 -0
- package/dist/components/p-b4a8fcbe.js +144 -0
- package/dist/components/p-b4a8fcbe.js.map +1 -0
- package/dist/components/p-ca881e5c.js +37 -0
- package/dist/components/p-ca881e5c.js.map +1 -0
- package/dist/components/searchcraft-base-search-result.js +1 -1
- package/dist/components/searchcraft-base-search-results.js +76 -52
- package/dist/components/searchcraft-base-search-results.js.map +1 -1
- package/dist/components/searchcraft-button.js +1 -1
- package/dist/components/searchcraft-error-message.js +1 -1
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +14 -17
- package/dist/components/searchcraft-filter-panel.js.map +1 -1
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-input-label.js +1 -1
- package/dist/components/searchcraft-popover-button.js +3 -7
- package/dist/components/searchcraft-popover-button.js.map +1 -1
- package/dist/components/searchcraft-popover-form.js +87 -81
- package/dist/components/searchcraft-popover-form.js.map +1 -1
- package/dist/components/searchcraft-popover-list-item.js +1 -1
- package/dist/components/searchcraft-popover-list-view.js +1 -1
- package/dist/components/searchcraft-results-info.js +9 -13
- package/dist/components/searchcraft-results-info.js.map +1 -1
- package/dist/components/searchcraft-slider.js +1 -1
- package/dist/components/searchcraft-theme.d.ts +11 -0
- package/dist/components/searchcraft-theme.js +51 -0
- package/dist/components/searchcraft-theme.js.map +1 -0
- package/dist/components/searchcraft-toggle-button.js +1 -1
- package/dist/esm/{index-56b713de.js → index-3608c57d.js} +29 -113
- package/dist/esm/index-3608c57d.js.map +1 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/loader.js +3 -3
- package/dist/esm/searchcraft-base-search-result.entry.js +91 -44
- package/dist/esm/searchcraft-base-search-result.entry.js.map +1 -1
- package/dist/esm/searchcraft-base-search-results.entry.js +74 -50
- package/dist/esm/searchcraft-base-search-results.entry.js.map +1 -1
- package/dist/esm/searchcraft-button_3.entry.js +37 -36
- package/dist/esm/searchcraft-button_3.entry.js.map +1 -1
- package/dist/esm/searchcraft-facet-list_3.entry.js +141 -119
- package/dist/esm/searchcraft-facet-list_3.entry.js.map +1 -1
- package/dist/esm/searchcraft-filter-panel.entry.js +11 -14
- package/dist/esm/searchcraft-filter-panel.entry.js.map +1 -1
- package/dist/esm/searchcraft-input-form_2.entry.js +127 -92
- package/dist/esm/searchcraft-input-form_2.entry.js.map +1 -1
- package/dist/esm/searchcraft-javascript-sdk.js +3 -3
- package/dist/esm/searchcraft-popover-button.entry.js +3 -7
- package/dist/esm/searchcraft-popover-button.entry.js.map +1 -1
- package/dist/esm/searchcraft-popover-form.entry.js +81 -75
- package/dist/esm/searchcraft-popover-form.entry.js.map +1 -1
- package/dist/esm/searchcraft-popover-list-item.entry.js +29 -6
- package/dist/esm/searchcraft-popover-list-item.entry.js.map +1 -1
- package/dist/esm/searchcraft-results-info.entry.js +9 -13
- package/dist/esm/searchcraft-results-info.entry.js.map +1 -1
- package/dist/esm/searchcraft-theme.entry.js +34 -0
- package/dist/esm/searchcraft-theme.entry.js.map +1 -0
- package/dist/{components/p-01dc5b3b.js → esm/store-aa071d9c.js} +26 -10
- package/dist/esm/{store-712f0586.js.map → store-aa071d9c.js.map} +1 -1
- package/dist/searchcraft-javascript-sdk/index.esm.js +1 -1
- package/dist/searchcraft-javascript-sdk/p-109ab0e0.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-109ab0e0.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-26f5263d.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-26f5263d.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-2ff7eb35.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-2ff7eb35.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-36f0532e.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-36f0532e.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-41b6bc5d.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-41b6bc5d.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-57eddb07.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-57eddb07.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-5d6fbee0.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-5d6fbee0.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-64c5a1d2.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-64c5a1d2.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-7e13c128.js +3 -0
- package/dist/searchcraft-javascript-sdk/p-7e13c128.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/{p-01dc5b3b.js → p-936e2ed4.js} +2 -2
- package/dist/searchcraft-javascript-sdk/{p-01dc5b3b.js.map → p-936e2ed4.js.map} +1 -1
- package/dist/searchcraft-javascript-sdk/p-c7df8be6.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-c7df8be6.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-eb6058e8.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-eb6058e8.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/p-faaa4394.entry.js +2 -0
- package/dist/searchcraft-javascript-sdk/p-faaa4394.entry.js.map +1 -0
- package/dist/searchcraft-javascript-sdk/searchcraft-javascript-sdk.esm.js +1 -1
- package/dist/searchcraft-javascript-sdk/searchcraft-javascript-sdk.esm.js.map +1 -1
- package/dist/types/components/searchcraft-base-search-result/searchcraft-base-search-result.d.ts +1 -0
- package/dist/types/components/searchcraft-base-search-results/searchcraft-base-search-results.d.ts +2 -1
- package/dist/types/components/searchcraft-button/searchcraft-button.d.ts +1 -0
- package/dist/types/components/searchcraft-error-message/searchcraft-error-message.d.ts +1 -0
- package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +2 -1
- package/dist/types/components/searchcraft-filter-panel/searchcraft-filter-panel.d.ts +1 -0
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +7 -10
- package/dist/types/components/searchcraft-input-label/searchcraft-input-label.d.ts +2 -1
- package/dist/types/components/searchcraft-popover-button/searchcraft-popover-button.d.ts +1 -0
- package/dist/types/components/searchcraft-popover-form/searchcraft-popover-form.d.ts +2 -1
- package/dist/types/components/searchcraft-popover-list-item/searchcraft-popover-list-item.d.ts +2 -0
- package/dist/types/components/searchcraft-popover-list-view/searchcraft-popover-list-view.d.ts +1 -0
- package/dist/types/components/searchcraft-results-info/searchcraft-results-info.d.ts +1 -0
- package/dist/types/components/searchcraft-slider/searchcraft-slider.d.ts +2 -1
- package/dist/types/components/searchcraft-theme/searchcraft-theme.d.ts +15 -0
- package/dist/types/components/searchcraft-toggle-button/searchcraft-toggle-button.d.ts +2 -1
- package/dist/types/components.d.ts +53 -4
- package/dist/types/index.d.ts +2 -1
- package/dist/types/provider/store.d.ts +1 -0
- package/dist/types/types/_shared.types.d.ts +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/raw.d.ts +4 -0
- package/dist/types/types/searchcraft-base-search-results.types.d.ts +1 -0
- package/dist/types/types/searchcraft-filter-panel.types.d.ts +1 -0
- package/dist/types/types/searchcraft-popover-form.types.d.ts +1 -0
- package/dist/types/utils/facets.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/styles.d.ts +1 -0
- package/dist/types/utils/units.d.ts +1 -0
- package/package.json +5 -4
- package/dist/cjs/index-d4b4a45e.js.map +0 -1
- package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.module.css +0 -227
- package/dist/collection/components/searchcraft-base-search-results/searchcraft-base-search-results.module.css +0 -179
- package/dist/collection/components/searchcraft-button/searchcraft-button.module.css +0 -174
- package/dist/collection/components/searchcraft-error-message/searchcraft-error-message.module.css +0 -158
- package/dist/collection/components/searchcraft-facet-list/searchcraft-facet-list.module.css +0 -266
- package/dist/collection/components/searchcraft-filter-panel/searchcraft-filter-panel.module.css +0 -168
- package/dist/collection/components/searchcraft-input-form/searchcraft-input-form.module.css +0 -293
- package/dist/collection/components/searchcraft-input-label/searchcraft-input-label.module.css +0 -159
- package/dist/collection/components/searchcraft-popover-button/searchcraft-popover-button.module.css +0 -0
- package/dist/collection/components/searchcraft-popover-form/searchcraft-popover-form.module.css +0 -322
- package/dist/collection/components/searchcraft-popover-list-item/searchcraft-popover-list-item.module.css +0 -209
- package/dist/collection/components/searchcraft-popover-list-view/searchcraft-popover-list-view.module.css +0 -0
- package/dist/collection/components/searchcraft-results-info/searchcraft-results-info.module.css +0 -169
- package/dist/collection/components/searchcraft-slider/searchcraft-slider.module.css +0 -231
- package/dist/collection/components/searchcraft-toggle-button/searchcraft-toggle-button.module.css +0 -207
- package/dist/components/p-1ae87308.js +0 -43
- package/dist/components/p-1ae87308.js.map +0 -1
- package/dist/components/p-649654b5.js +0 -268
- package/dist/components/p-649654b5.js.map +0 -1
- package/dist/components/p-662cb490.js +0 -67
- package/dist/components/p-662cb490.js.map +0 -1
- package/dist/components/p-87d1611b.js +0 -97
- package/dist/components/p-87d1611b.js.map +0 -1
- package/dist/components/p-c273e43d.js +0 -40
- package/dist/components/p-c273e43d.js.map +0 -1
- package/dist/components/p-cc9f8c61.js +0 -109
- package/dist/components/p-cc9f8c61.js.map +0 -1
- package/dist/components/p-cf096782.js +0 -56
- package/dist/components/p-cf096782.js.map +0 -1
- package/dist/components/p-da5b92ef.js +0 -253
- package/dist/components/p-da5b92ef.js.map +0 -1
- package/dist/components/p-e1cf5f9d.js.map +0 -1
- package/dist/components/p-f5a06210.js +0 -34
- package/dist/components/p-f5a06210.js.map +0 -1
- package/dist/esm/index-56b713de.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-117fcdd3.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-117fcdd3.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-129e6f2c.js +0 -3
- package/dist/searchcraft-javascript-sdk/p-129e6f2c.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-27cb401c.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-27cb401c.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-4df4a29e.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-4df4a29e.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-54248dd8.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-54248dd8.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-69430dbf.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-69430dbf.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-a460755d.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-a460755d.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-bc2c4259.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-bc2c4259.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-caecdcda.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-caecdcda.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-f8129731.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-f8129731.entry.js.map +0 -1
- package/dist/searchcraft-javascript-sdk/p-f839b682.entry.js +0 -2
- package/dist/searchcraft-javascript-sdk/p-f839b682.entry.js.map +0 -1
|
@@ -32,64 +32,40 @@ import { useSearchcraftStore } from "../../provider/store";
|
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
export class SearchcraftPopoverForm {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
// Document-scoped -> Popover-scoped keyboard event boundary
|
|
71
|
-
if (!this.hostElement.contains(document.activeElement)) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// Popover-scoped actions
|
|
75
|
-
switch (event.key) {
|
|
76
|
-
case 'ArrowDown':
|
|
77
|
-
case 'ArrowUp':
|
|
78
|
-
event.preventDefault();
|
|
79
|
-
this.focusOnNextListItem(event.key);
|
|
80
|
-
break;
|
|
81
|
-
case 'Escape':
|
|
82
|
-
useSearchcraftStore.getState().setPopoverVisibility(false);
|
|
83
|
-
break;
|
|
84
|
-
default:
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
this.handleInputInit = () => {
|
|
89
|
-
const input = this.hostElement.querySelector('.searchcraft-input');
|
|
90
|
-
input === null || input === void 0 ? void 0 : input.focus();
|
|
91
|
-
};
|
|
92
|
-
}
|
|
35
|
+
/**
|
|
36
|
+
* The Searchcraft config object.
|
|
37
|
+
*/
|
|
38
|
+
config;
|
|
39
|
+
/**
|
|
40
|
+
* The type of popover form to render.
|
|
41
|
+
*
|
|
42
|
+
* - `inline` - Renders inline with the rest of the content on the page. The search results pop over the page content.
|
|
43
|
+
* - `fullscreen` - Renders in fullscreen view. Used together with the `searchcraft-popover-button` component.
|
|
44
|
+
* - `modal` - Renders in a modal view. Used together with the `searchcraft-popover-button` component.
|
|
45
|
+
*/
|
|
46
|
+
type = 'inline';
|
|
47
|
+
/**
|
|
48
|
+
* Formats the content rendered for each result.
|
|
49
|
+
*/
|
|
50
|
+
popoverResultMappings;
|
|
51
|
+
/**
|
|
52
|
+
* The hotkey that activates the popover.
|
|
53
|
+
*/
|
|
54
|
+
hotkey = 'k';
|
|
55
|
+
/**
|
|
56
|
+
* The hotkey modifier that activates the popover. Used together with the `hotkey` prop.
|
|
57
|
+
*/
|
|
58
|
+
hotkeyModifier = 'meta';
|
|
59
|
+
isPopoverVisibleInState = false;
|
|
60
|
+
unsubscribe;
|
|
61
|
+
searchResults;
|
|
62
|
+
searchTerm;
|
|
63
|
+
isFocused = false;
|
|
64
|
+
breakpointSm = 576;
|
|
65
|
+
breakpointMd = 768;
|
|
66
|
+
breakpointLg = 992;
|
|
67
|
+
modalElement;
|
|
68
|
+
hostElement;
|
|
93
69
|
componentDidLoad() {
|
|
94
70
|
// Loads the breakpoint values into state
|
|
95
71
|
const computedStyle = getComputedStyle(document.documentElement);
|
|
@@ -107,16 +83,20 @@ export class SearchcraftPopoverForm {
|
|
|
107
83
|
if (this.isPopoverVisibleInState !== state.isPopoverVisible) {
|
|
108
84
|
this.handlePopoverVisibilityChange(state.isPopoverVisible);
|
|
109
85
|
}
|
|
110
|
-
this.searchResults =
|
|
86
|
+
this.searchResults = { ...state.searchResults };
|
|
111
87
|
this.searchTerm = state.query;
|
|
112
88
|
});
|
|
113
89
|
}
|
|
114
90
|
disconnectedCallback() {
|
|
115
|
-
|
|
116
|
-
(_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
91
|
+
this.unsubscribe?.();
|
|
117
92
|
document.removeEventListener('click', this.handleDocumentClick);
|
|
118
93
|
document.removeEventListener('keydown', this.handleDocumentKeyDown);
|
|
119
94
|
}
|
|
95
|
+
handleDocumentClick = (event) => {
|
|
96
|
+
if (!this.hostElement.contains(event.target)) {
|
|
97
|
+
this.isFocused = false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
120
100
|
/**
|
|
121
101
|
* Handles when popover visibility is changed in state
|
|
122
102
|
*/
|
|
@@ -124,6 +104,36 @@ export class SearchcraftPopoverForm {
|
|
|
124
104
|
this.isPopoverVisibleInState = isVisible;
|
|
125
105
|
document.body.style.overflow = isVisible ? 'hidden' : 'auto';
|
|
126
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Actions to perform when various keys are pressed within the popover form.
|
|
109
|
+
*/
|
|
110
|
+
handleDocumentKeyDown = (event) => {
|
|
111
|
+
// Document-scoped actions
|
|
112
|
+
if (event.key === this.hotkey) {
|
|
113
|
+
this.handleHotkeyPressed(event);
|
|
114
|
+
}
|
|
115
|
+
// Document-scoped -> Popover-scoped keyboard event boundary
|
|
116
|
+
if (!this.hostElement.contains(document.activeElement)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// Popover-scoped actions
|
|
120
|
+
switch (event.key) {
|
|
121
|
+
case 'ArrowDown':
|
|
122
|
+
case 'ArrowUp':
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
this.focusOnNextListItem(event.key);
|
|
125
|
+
break;
|
|
126
|
+
case 'Escape':
|
|
127
|
+
useSearchcraftStore.getState().setPopoverVisibility(false);
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
handleInputInit = () => {
|
|
134
|
+
const input = this.hostElement.querySelector('.searchcraft-input');
|
|
135
|
+
input?.focus();
|
|
136
|
+
};
|
|
127
137
|
/**
|
|
128
138
|
* When popover is `inline` and the viewport is at the smallest breakpoint,
|
|
129
139
|
* focusing on the input will open a modal version of the popover form.
|
|
@@ -131,6 +141,7 @@ export class SearchcraftPopoverForm {
|
|
|
131
141
|
handleInputFocus() {
|
|
132
142
|
this.isFocused = true;
|
|
133
143
|
if (this.type === 'inline' &&
|
|
144
|
+
window.visualViewport &&
|
|
134
145
|
window.visualViewport.width < this.breakpointSm) {
|
|
135
146
|
useSearchcraftStore.getState().setPopoverVisibility(true);
|
|
136
147
|
// Appends a popover form of type=`modal` to the body
|
|
@@ -157,7 +168,7 @@ export class SearchcraftPopoverForm {
|
|
|
157
168
|
event.preventDefault();
|
|
158
169
|
if (this.type === 'inline' && !this.isPopoverVisibleInState) {
|
|
159
170
|
const hostElementInput = this.hostElement.querySelector('.searchcraft-input');
|
|
160
|
-
hostElementInput
|
|
171
|
+
hostElementInput?.focus();
|
|
161
172
|
}
|
|
162
173
|
else {
|
|
163
174
|
useSearchcraftStore
|
|
@@ -176,15 +187,14 @@ export class SearchcraftPopoverForm {
|
|
|
176
187
|
* @param direction
|
|
177
188
|
*/
|
|
178
189
|
focusOnNextListItem(direction) {
|
|
179
|
-
var _a, _b;
|
|
180
190
|
const listItems = Array.from(document.querySelectorAll('a.searchcraft-popover-list-item')).filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);
|
|
181
191
|
const currentIndex = listItems.indexOf(document.activeElement);
|
|
182
192
|
if (direction === 'ArrowDown') {
|
|
183
|
-
|
|
193
|
+
listItems[(currentIndex + 1) % listItems.length]?.focus();
|
|
184
194
|
}
|
|
185
195
|
else if (direction === 'ArrowUp') {
|
|
186
196
|
if (currentIndex >= 1) {
|
|
187
|
-
|
|
197
|
+
listItems[currentIndex - 1]?.focus();
|
|
188
198
|
}
|
|
189
199
|
else {
|
|
190
200
|
const input = document.querySelector('.searchcraft-input');
|
|
@@ -199,9 +209,9 @@ export class SearchcraftPopoverForm {
|
|
|
199
209
|
}
|
|
200
210
|
}
|
|
201
211
|
get hasResultsToShow() {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
(
|
|
212
|
+
return (this.searchTerm &&
|
|
213
|
+
this.searchTerm?.trim()?.length > 0 &&
|
|
214
|
+
(this.searchResults?.data?.hits?.length || 0) > 0);
|
|
205
215
|
}
|
|
206
216
|
renderInlinePopover(documents) {
|
|
207
217
|
const isListViewVisible = this.hasResultsToShow && this.isFocused;
|
|
@@ -224,8 +234,7 @@ export class SearchcraftPopoverForm {
|
|
|
224
234
|
}
|
|
225
235
|
}
|
|
226
236
|
render() {
|
|
227
|
-
|
|
228
|
-
const documents = (_c = (_b = (_a = this.searchResults) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.map((data, _index) => {
|
|
237
|
+
const documents = this.searchResults?.data?.hits?.map((data, _index) => {
|
|
229
238
|
const { doc: result } = data;
|
|
230
239
|
return result;
|
|
231
240
|
});
|
|
@@ -239,16 +248,6 @@ export class SearchcraftPopoverForm {
|
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
250
|
static get is() { return "searchcraft-popover-form"; }
|
|
242
|
-
static get originalStyleUrls() {
|
|
243
|
-
return {
|
|
244
|
-
"$": ["searchcraft-popover-form.module.scss"]
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
static get styleUrls() {
|
|
248
|
-
return {
|
|
249
|
-
"$": ["searchcraft-popover-form.module.css"]
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
251
|
static get properties() {
|
|
253
252
|
return {
|
|
254
253
|
"config": {
|
|
@@ -256,7 +255,7 @@ export class SearchcraftPopoverForm {
|
|
|
256
255
|
"mutable": false,
|
|
257
256
|
"complexType": {
|
|
258
257
|
"original": "SearchcraftConfig | undefined",
|
|
259
|
-
"resolved": "SearchcraftConfig",
|
|
258
|
+
"resolved": "SearchcraftConfig | undefined",
|
|
260
259
|
"references": {
|
|
261
260
|
"SearchcraftConfig": {
|
|
262
261
|
"location": "import",
|
|
@@ -299,7 +298,7 @@ export class SearchcraftPopoverForm {
|
|
|
299
298
|
"mutable": false,
|
|
300
299
|
"complexType": {
|
|
301
300
|
"original": "PopoverResultMappings | undefined",
|
|
302
|
-
"resolved": "{ title?: SearchResultMapping; subtitle?: SearchResultMapping; imageSource?: SearchResultMapping; imageAlt?: SearchResultMapping; href?: SearchResultMapping; }",
|
|
301
|
+
"resolved": "undefined | { title?: SearchResultMapping | undefined; subtitle?: SearchResultMapping | undefined; imageSource?: SearchResultMapping | undefined; imageAlt?: SearchResultMapping | undefined; href?: SearchResultMapping | undefined; }",
|
|
303
302
|
"references": {
|
|
304
303
|
"PopoverResultMappings": {
|
|
305
304
|
"location": "import",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchcraft-popover-form.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-form/searchcraft-popover-form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAMH,MAAM,OAAO,sBAAsB;IALnC;QAUE;;;;;;WAMG;QACK,SAAI,GAAsC,QAAQ,CAAC;QAK3D;;WAEG;QACK,WAAM,GAAG,GAAG,CAAC;QACrB;;WAEG;QACK,mBAAc,GAAuC,MAAM,CAAC;QAE3D,4BAAuB,GAAG,KAAK,CAAC;QAIhC,cAAS,GAAG,KAAK,CAAC;QAClB,iBAAY,GAAG,GAAG,CAAC;QACnB,iBAAY,GAAG,GAAG,CAAC;QACnB,iBAAY,GAAG,GAAG,CAAC;QA2C5B,wBAAmB,GAAG,CAAC,KAAiB,EAAE,EAAE;YAC1C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAc,CAAC,EAAE,CAAC;gBACrD,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;QAUF;;WAEG;QACH,0BAAqB,GAAG,CAAC,KAAoB,EAAE,EAAE;YAC/C,0BAA0B;YAC1B,IAAI,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC9B,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAClC,CAAC;YAED,4DAA4D;YAC5D,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,EA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G,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YACnD,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QAEL,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAC7C,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;YAC5C,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Prop, State, h } from '@stencil/core';\nimport classNames from 'classnames';\nimport type { SearchcraftConfig, SearchcraftResponse } from '@searchcraft/core';\n\nimport { useSearchcraftStore } from '@provider/store';\nimport type { PopoverResultMappings } from 'types';\n\n/**\n * This web component is designed to display search results in a popover container that dynamically appears when the user interacts with a search input field.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-form type=\"fullscreen\" />\n * ```\n *\n * ```js\n * // index.js\n * const popoverForm = document.querySelector('searchcraft-popover-form');\n *\n * popoverForm.config = {\n * index: [index_name_from_vektron],\n * readKey: 'read_key_from_vektron',\n * endpointUrl: 'enpoint_url_from_vektron',\n * };\n *\n * popoverForm.popoverResultMappings = {\n * containerHref: {\n * fieldNames: [\n * {\n * fieldName: 'canonical_link',\n * dataType: 'text',\n * },\n * ],\n * };\n * ```\n */\n@Component({\n tag: 'searchcraft-popover-form',\n styleUrl: 'searchcraft-popover-form.module.scss',\n shadow: false,\n})\nexport class SearchcraftPopoverForm {\n /**\n * The Searchcraft config object.\n */\n @Prop() config: SearchcraftConfig | undefined;\n /**\n * The type of popover form to render.\n *\n * - `inline` - Renders inline with the rest of the content on the page. The search results pop over the page content.\n * - `fullscreen` - Renders in fullscreen view. Used together with the `searchcraft-popover-button` component.\n * - `modal` - Renders in a modal view. Used together with the `searchcraft-popover-button` component.\n */\n @Prop() type: 'inline' | 'fullscreen' | 'modal' = 'inline';\n /**\n * Formats the content rendered for each result.\n */\n @Prop() popoverResultMappings: PopoverResultMappings | undefined;\n /**\n * The hotkey that activates the popover.\n */\n @Prop() hotkey = 'k';\n /**\n * The hotkey modifier that activates the popover. Used together with the `hotkey` prop.\n */\n @Prop() hotkeyModifier: 'ctrl' | 'meta' | 'alt' | 'option' = 'meta';\n\n @State() isPopoverVisibleInState = false;\n @State() unsubscribe: (() => void) | undefined;\n @State() searchResults: SearchcraftResponse | undefined;\n @State() searchTerm: string | undefined;\n @State() isFocused = false;\n @State() breakpointSm = 576;\n @State() breakpointMd = 768;\n @State() breakpointLg = 992;\n\n @State() modalElement;\n\n @Element() hostElement!: HTMLElement;\n\n componentDidLoad() {\n // Loads the breakpoint values into state\n const computedStyle = getComputedStyle(document.documentElement);\n this.breakpointSm = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-sm').trim(),\n );\n this.breakpointMd = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-md').trim(),\n );\n this.breakpointLg = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-lg').trim(),\n );\n // Set popover visiblity in state\n this.isPopoverVisibleInState =\n useSearchcraftStore.getState().isPopoverVisible;\n\n // Add event listeners\n document.addEventListener('click', this.handleDocumentClick);\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n\n // Subscribe to state events\n this.unsubscribe = useSearchcraftStore.subscribe((state) => {\n if (this.isPopoverVisibleInState !== state.isPopoverVisible) {\n this.handlePopoverVisibilityChange(state.isPopoverVisible);\n }\n\n this.searchResults = { ...state.searchResults };\n this.searchTerm = state.query;\n });\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n document.removeEventListener('click', this.handleDocumentClick);\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n }\n\n handleDocumentClick = (event: MouseEvent) => {\n if (!this.hostElement.contains(event.target as Node)) {\n this.isFocused = false;\n }\n };\n\n /**\n * Handles when popover visibility is changed in state\n */\n handlePopoverVisibilityChange(isVisible: boolean) {\n this.isPopoverVisibleInState = isVisible;\n document.body.style.overflow = isVisible ? 'hidden' : 'auto';\n }\n\n /**\n * Actions to perform when various keys are pressed within the popover form.\n */\n handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Document-scoped actions\n if (event.key === this.hotkey) {\n this.handleHotkeyPressed(event);\n }\n\n // Document-scoped -> Popover-scoped keyboard event boundary\n if (!this.hostElement.contains(document.activeElement)) {\n return;\n }\n\n // Popover-scoped actions\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n this.focusOnNextListItem(event.key);\n break;\n case 'Escape':\n useSearchcraftStore.getState().setPopoverVisibility(false);\n break;\n default:\n return;\n }\n };\n\n handleInputInit = () => {\n const input = this.hostElement.querySelector('.searchcraft-input') as\n | HTMLInputElement\n | undefined;\n input?.focus();\n };\n\n /**\n * When popover is `inline` and the viewport is at the smallest breakpoint,\n * focusing on the input will open a modal version of the popover form.\n */\n handleInputFocus() {\n this.isFocused = true;\n\n if (\n this.type === 'inline' &&\n window.visualViewport.width < this.breakpointSm\n ) {\n useSearchcraftStore.getState().setPopoverVisibility(true);\n\n // Appends a popover form of type=`modal` to the body\n if (!this.modalElement) {\n this.modalElement = document.createElement('searchcraft-popover-form');\n this.modalElement.config = this.config;\n this.modalElement.popoverResultMappings = this.popoverResultMappings;\n this.modalElement.setAttribute('type', 'fullscreen');\n document.body.appendChild(this.modalElement);\n }\n }\n }\n\n handleModalBackdropClick(_event: MouseEvent) {\n useSearchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * When a hotkey is pressed, tests if the modifiers also match.\n * If modifiers match, toggles visibility of the popover modal.\n */\n handleHotkeyPressed(event: KeyboardEvent) {\n if (\n (event.ctrlKey && this.hotkeyModifier === 'ctrl') ||\n (event.altKey && this.hotkeyModifier === 'alt') ||\n (event.metaKey && this.hotkeyModifier === 'meta')\n ) {\n event.preventDefault();\n if (this.type === 'inline' && !this.isPopoverVisibleInState) {\n const hostElementInput = this.hostElement.querySelector(\n '.searchcraft-input',\n ) as HTMLInputElement | undefined;\n hostElementInput?.focus();\n } else {\n useSearchcraftStore\n .getState()\n .setPopoverVisibility(!this.isPopoverVisibleInState);\n }\n }\n }\n\n handleCancelButtonClick() {\n useSearchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * Moves focus to the next/previous list item in the list view. If you are at the top\n * of the list view, it moves focus back to the input.\n *\n * @param direction\n */\n focusOnNextListItem(direction: 'ArrowDown' | 'ArrowUp') {\n const listItems = Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n 'a.searchcraft-popover-list-item',\n ),\n ).filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);\n\n const currentIndex = listItems.indexOf(\n document.activeElement as HTMLAnchorElement,\n );\n\n if (direction === 'ArrowDown') {\n listItems[(currentIndex + 1) % listItems.length]?.focus();\n } else if (direction === 'ArrowUp') {\n if (currentIndex >= 1) {\n listItems[currentIndex - 1]?.focus();\n } else {\n const input = document.querySelector('.searchcraft-input') as\n | HTMLInputElement\n | undefined;\n\n if (input) {\n input.focus();\n requestAnimationFrame(() => {\n input.selectionEnd = input.value.length;\n input.selectionStart = input.value.length;\n });\n }\n }\n }\n }\n\n get hasResultsToShow() {\n return (\n this.searchTerm?.trim()?.length > 0 &&\n this.searchResults?.data?.hits?.length > 0\n );\n }\n\n renderInlinePopover(documents: Record<string, unknown>[]) {\n const isListViewVisible = this.hasResultsToShow && this.isFocused;\n\n const popoverFormClassNames = classNames(\n 'searchcraft-popover-form searchcraft-popover-form-inline',\n {\n 'searchcraft-popover-form-active': isListViewVisible,\n },\n );\n\n return (\n <div class={popoverFormClassNames}>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n />\n {isListViewVisible && (\n <div class='searchcraft-popover-inline-wrapper-outer'>\n <div class='searchcraft-popover-inline-wrapper-inner'>\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n </div>\n </div>\n )}\n </div>\n );\n }\n\n renderModalPopover(documents: Record<string, unknown>[]) {\n if (this.isPopoverVisibleInState) {\n const popoverFormClassNames = classNames('searchcraft-popover-form', {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n });\n\n return (\n <div class='searchcraft-popover-form-modal'>\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: <explanation> */}\n <div\n class='searchcraft-popover-form-modal-backdrop'\n onClick={this.handleModalBackdropClick}\n />\n <div class='searchcraft-popover-form-modal-inner'>\n <div class={popoverFormClassNames}>\n <div class='searchcraft-popover-form-input-wrapper'>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n )}\n </div>\n </div>\n </div>\n );\n }\n }\n\n renderFullscreenPopover(documents: Record<string, unknown>[]) {\n if (this.isPopoverVisibleInState) {\n return (\n <div class='searchcraft-popover-form-fullscreen'>\n <div class='searchcraft-popover-form'>\n <div class='searchcraft-popover-form-input-wrapper'>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n )}\n </div>\n </div>\n );\n }\n }\n\n render() {\n const documents: Record<string, unknown>[] =\n this.searchResults?.data?.hits?.map((data, _index) => {\n const { doc: result } = data;\n return result;\n });\n\n switch (this.type) {\n case 'inline':\n return this.renderInlinePopover(documents);\n case 'modal':\n return this.renderModalPopover(documents);\n case 'fullscreen':\n return this.renderFullscreenPopover(documents);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"searchcraft-popover-form.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-form/searchcraft-popover-form.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAKH,MAAM,OAAO,sBAAsB;IACjC;;OAEG;IACK,MAAM,CAAgC;IAC9C;;;;;;OAMG;IACK,IAAI,GAAsC,QAAQ,CAAC;IAC3D;;OAEG;IACK,qBAAqB,CAAoC;IACjE;;OAEG;IACK,MAAM,GAAG,GAAG,CAAC;IACrB;;OAEG;IACK,cAAc,GAAuC,MAAM,CAAC;IAE3D,uBAAuB,GAAG,KAAK,CAAC;IAChC,WAAW,CAA2B;IACtC,aAAa,CAAkC;IAC/C,UAAU,CAAqB;IAC/B,SAAS,GAAG,KAAK,CAAC;IAClB,YAAY,GAAG,GAAG,CAAC;IACnB,YAAY,GAAG,GAAG,CAAC;IACnB,YAAY,GAAG,GAAG,CAAC;IAEnB,YAAY,CAAC;IAEX,WAAW,CAAe;IAErC,gBAAgB;QACd,yCAAyC;QACzC,MAAM,aAAa,GAAG,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC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,wCAAwC,EAC9C,OAAO,EAAE,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,aAGzC,CACL;oBACL,IAAI,CAAC,gBAAgB,IAAI,CACxB,qCACE,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,SAAS,EAAE,SAAS,GACpB,CACH,CACG,CACF,CACP,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM;QACJ,MAAM,SAAS,GACb,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YACnD,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC,CAA8B,CAAC;QAElC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAC7C,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;YAC5C,KAAK,YAAY;gBACf,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Prop, State, h } from '@stencil/core';\nimport classNames from 'classnames';\nimport type { SearchcraftConfig, SearchcraftResponse } from '@searchcraft/core';\n\nimport { useSearchcraftStore } from '@provider/store';\nimport type { PopoverResultMappings } from 'types';\n\n/**\n * This web component is designed to display search results in a popover container that dynamically appears when the user interacts with a search input field.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-form type=\"fullscreen\" />\n * ```\n *\n * ```js\n * // index.js\n * const popoverForm = document.querySelector('searchcraft-popover-form');\n *\n * popoverForm.config = {\n * index: [index_name_from_vektron],\n * readKey: 'read_key_from_vektron',\n * endpointUrl: 'enpoint_url_from_vektron',\n * };\n *\n * popoverForm.popoverResultMappings = {\n * containerHref: {\n * fieldNames: [\n * {\n * fieldName: 'canonical_link',\n * dataType: 'text',\n * },\n * ],\n * };\n * ```\n */\n@Component({\n tag: 'searchcraft-popover-form',\n shadow: false,\n})\nexport class SearchcraftPopoverForm {\n /**\n * The Searchcraft config object.\n */\n @Prop() config: SearchcraftConfig | undefined;\n /**\n * The type of popover form to render.\n *\n * - `inline` - Renders inline with the rest of the content on the page. The search results pop over the page content.\n * - `fullscreen` - Renders in fullscreen view. Used together with the `searchcraft-popover-button` component.\n * - `modal` - Renders in a modal view. Used together with the `searchcraft-popover-button` component.\n */\n @Prop() type: 'inline' | 'fullscreen' | 'modal' = 'inline';\n /**\n * Formats the content rendered for each result.\n */\n @Prop() popoverResultMappings: PopoverResultMappings | undefined;\n /**\n * The hotkey that activates the popover.\n */\n @Prop() hotkey = 'k';\n /**\n * The hotkey modifier that activates the popover. Used together with the `hotkey` prop.\n */\n @Prop() hotkeyModifier: 'ctrl' | 'meta' | 'alt' | 'option' = 'meta';\n\n @State() isPopoverVisibleInState = false;\n @State() unsubscribe: (() => void) | undefined;\n @State() searchResults: SearchcraftResponse | undefined;\n @State() searchTerm: string | undefined;\n @State() isFocused = false;\n @State() breakpointSm = 576;\n @State() breakpointMd = 768;\n @State() breakpointLg = 992;\n\n @State() modalElement;\n\n @Element() hostElement!: HTMLElement;\n\n componentDidLoad() {\n // Loads the breakpoint values into state\n const computedStyle = getComputedStyle(document.documentElement);\n this.breakpointSm = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-sm').trim(),\n );\n this.breakpointMd = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-md').trim(),\n );\n this.breakpointLg = Number.parseFloat(\n computedStyle.getPropertyValue('--sc-breakpoint-lg').trim(),\n );\n // Set popover visiblity in state\n this.isPopoverVisibleInState =\n useSearchcraftStore.getState().isPopoverVisible;\n\n // Add event listeners\n document.addEventListener('click', this.handleDocumentClick);\n document.addEventListener('keydown', this.handleDocumentKeyDown);\n\n // Subscribe to state events\n this.unsubscribe = useSearchcraftStore.subscribe((state) => {\n if (this.isPopoverVisibleInState !== state.isPopoverVisible) {\n this.handlePopoverVisibilityChange(state.isPopoverVisible);\n }\n\n this.searchResults = { ...state.searchResults } as SearchcraftResponse;\n this.searchTerm = state.query;\n });\n }\n\n disconnectedCallback() {\n this.unsubscribe?.();\n document.removeEventListener('click', this.handleDocumentClick);\n document.removeEventListener('keydown', this.handleDocumentKeyDown);\n }\n\n handleDocumentClick = (event: MouseEvent) => {\n if (!this.hostElement.contains(event.target as Node)) {\n this.isFocused = false;\n }\n };\n\n /**\n * Handles when popover visibility is changed in state\n */\n handlePopoverVisibilityChange(isVisible: boolean) {\n this.isPopoverVisibleInState = isVisible;\n document.body.style.overflow = isVisible ? 'hidden' : 'auto';\n }\n\n /**\n * Actions to perform when various keys are pressed within the popover form.\n */\n handleDocumentKeyDown = (event: KeyboardEvent) => {\n // Document-scoped actions\n if (event.key === this.hotkey) {\n this.handleHotkeyPressed(event);\n }\n\n // Document-scoped -> Popover-scoped keyboard event boundary\n if (!this.hostElement.contains(document.activeElement)) {\n return;\n }\n\n // Popover-scoped actions\n switch (event.key) {\n case 'ArrowDown':\n case 'ArrowUp':\n event.preventDefault();\n this.focusOnNextListItem(event.key);\n break;\n case 'Escape':\n useSearchcraftStore.getState().setPopoverVisibility(false);\n break;\n default:\n return;\n }\n };\n\n handleInputInit = () => {\n const input = this.hostElement.querySelector('.searchcraft-input') as\n | HTMLInputElement\n | undefined;\n input?.focus();\n };\n\n /**\n * When popover is `inline` and the viewport is at the smallest breakpoint,\n * focusing on the input will open a modal version of the popover form.\n */\n handleInputFocus() {\n this.isFocused = true;\n\n if (\n this.type === 'inline' &&\n window.visualViewport &&\n window.visualViewport.width < this.breakpointSm\n ) {\n useSearchcraftStore.getState().setPopoverVisibility(true);\n\n // Appends a popover form of type=`modal` to the body\n if (!this.modalElement) {\n this.modalElement = document.createElement('searchcraft-popover-form');\n this.modalElement.config = this.config;\n this.modalElement.popoverResultMappings = this.popoverResultMappings;\n this.modalElement.setAttribute('type', 'fullscreen');\n document.body.appendChild(this.modalElement);\n }\n }\n }\n\n handleModalBackdropClick(_event: MouseEvent) {\n useSearchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * When a hotkey is pressed, tests if the modifiers also match.\n * If modifiers match, toggles visibility of the popover modal.\n */\n handleHotkeyPressed(event: KeyboardEvent) {\n if (\n (event.ctrlKey && this.hotkeyModifier === 'ctrl') ||\n (event.altKey && this.hotkeyModifier === 'alt') ||\n (event.metaKey && this.hotkeyModifier === 'meta')\n ) {\n event.preventDefault();\n if (this.type === 'inline' && !this.isPopoverVisibleInState) {\n const hostElementInput = this.hostElement.querySelector(\n '.searchcraft-input',\n ) as HTMLInputElement | undefined;\n hostElementInput?.focus();\n } else {\n useSearchcraftStore\n .getState()\n .setPopoverVisibility(!this.isPopoverVisibleInState);\n }\n }\n }\n\n handleCancelButtonClick() {\n useSearchcraftStore.getState().setPopoverVisibility(false);\n }\n\n /**\n * Moves focus to the next/previous list item in the list view. If you are at the top\n * of the list view, it moves focus back to the input.\n *\n * @param direction\n */\n focusOnNextListItem(direction: 'ArrowDown' | 'ArrowUp') {\n const listItems = Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n 'a.searchcraft-popover-list-item',\n ),\n ).filter((el) => !el.hasAttribute('disabled') && el.offsetParent !== null);\n\n const currentIndex = listItems.indexOf(\n document.activeElement as HTMLAnchorElement,\n );\n\n if (direction === 'ArrowDown') {\n listItems[(currentIndex + 1) % listItems.length]?.focus();\n } else if (direction === 'ArrowUp') {\n if (currentIndex >= 1) {\n listItems[currentIndex - 1]?.focus();\n } else {\n const input = document.querySelector('.searchcraft-input') as\n | HTMLInputElement\n | undefined;\n\n if (input) {\n input.focus();\n requestAnimationFrame(() => {\n input.selectionEnd = input.value.length;\n input.selectionStart = input.value.length;\n });\n }\n }\n }\n }\n\n get hasResultsToShow() {\n return (\n this.searchTerm &&\n this.searchTerm?.trim()?.length > 0 &&\n (this.searchResults?.data?.hits?.length || 0) > 0\n );\n }\n\n renderInlinePopover(documents: Record<string, unknown>[]) {\n const isListViewVisible = this.hasResultsToShow && this.isFocused;\n\n const popoverFormClassNames = classNames(\n 'searchcraft-popover-form searchcraft-popover-form-inline',\n {\n 'searchcraft-popover-form-active': isListViewVisible,\n },\n );\n\n return (\n <div class={popoverFormClassNames}>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n />\n {isListViewVisible && (\n <div class='searchcraft-popover-inline-wrapper-outer'>\n <div class='searchcraft-popover-inline-wrapper-inner'>\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n </div>\n </div>\n )}\n </div>\n );\n }\n\n renderModalPopover(documents: Record<string, unknown>[]) {\n if (this.isPopoverVisibleInState) {\n const popoverFormClassNames = classNames('searchcraft-popover-form', {\n 'searchcraft-popover-form-active': this.hasResultsToShow,\n });\n\n return (\n <div class='searchcraft-popover-form-modal'>\n {/* biome-ignore lint/a11y/useKeyWithClickEvents: <explanation> */}\n <div\n class='searchcraft-popover-form-modal-backdrop'\n onClick={this.handleModalBackdropClick}\n />\n <div class='searchcraft-popover-form-modal-inner'>\n <div class={popoverFormClassNames}>\n <div class='searchcraft-popover-form-input-wrapper'>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n )}\n </div>\n </div>\n </div>\n );\n }\n }\n\n renderFullscreenPopover(documents: Record<string, unknown>[]) {\n if (this.isPopoverVisibleInState) {\n return (\n <div class='searchcraft-popover-form-fullscreen'>\n <div class='searchcraft-popover-form'>\n <div class='searchcraft-popover-form-input-wrapper'>\n <searchcraft-input-form\n config={this.config}\n onInputFocus={this.handleInputFocus.bind(this)}\n onInputInit={this.handleInputInit.bind(this)}\n />\n <button\n type='button'\n class='searchcraft-popover-form-cancel-button'\n onClick={this.handleCancelButtonClick.bind(this)}\n >\n Cancel\n </button>\n </div>\n {this.hasResultsToShow && (\n <searchcraft-popover-list-view\n popoverResultMappings={this.popoverResultMappings}\n documents={documents}\n />\n )}\n </div>\n </div>\n );\n }\n }\n\n render() {\n const documents: Record<string, unknown>[] =\n this.searchResults?.data?.hits?.map((data, _index) => {\n const { doc: result } = data;\n return result;\n }) as Record<string, unknown>[];\n\n switch (this.type) {\n case 'inline':\n return this.renderInlinePopover(documents);\n case 'modal':\n return this.renderModalPopover(documents);\n case 'fullscreen':\n return this.renderFullscreenPopover(documents);\n }\n }\n}\n"]}
|
package/dist/collection/components/searchcraft-popover-list-item/searchcraft-popover-list-item.js
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
|
+
import { useSearchcraftStore } from "../../provider/store";
|
|
1
2
|
import { h } from "@stencil/core";
|
|
2
3
|
/**
|
|
3
4
|
* A single list item rendered in a searchcraft-popover-list-view.
|
|
4
5
|
*/
|
|
5
6
|
export class SearchcraftPopoverListItem {
|
|
7
|
+
/** The result title */
|
|
8
|
+
titleContent;
|
|
9
|
+
/** The result subtitle */
|
|
10
|
+
subtitleContent;
|
|
11
|
+
/** The source of the image. If not included, no item will be rendered. */
|
|
12
|
+
imageSrc;
|
|
13
|
+
/** The image alt tag. */
|
|
14
|
+
imageAlt;
|
|
15
|
+
/** The link href */
|
|
16
|
+
href;
|
|
17
|
+
/** The document position relative to the search results (For Measure) */
|
|
18
|
+
documentPosition = 0;
|
|
6
19
|
componentDidLoad() { }
|
|
7
20
|
connectedCallback() { }
|
|
8
21
|
disconnectedCallback() { }
|
|
9
22
|
handleButtonClick() { }
|
|
23
|
+
handleLinkClick = () => {
|
|
24
|
+
const state = useSearchcraftStore.getState();
|
|
25
|
+
const searchcraft = state.getSearchcraftInstance();
|
|
26
|
+
if (searchcraft) {
|
|
27
|
+
const document_position = this.documentPosition;
|
|
28
|
+
const search_term = state.query;
|
|
29
|
+
const number_of_documents = state.searchResults?.data?.hits?.length || 0;
|
|
30
|
+
searchcraft.sendMeasureEvent('document_clicked', {
|
|
31
|
+
document_position,
|
|
32
|
+
number_of_documents,
|
|
33
|
+
search_term,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
10
37
|
render() {
|
|
11
|
-
return (h("a", { key: '
|
|
38
|
+
return (h("a", { key: 'b20aae2fc421323774a5129dde7d53d4ae3283fb', class: 'searchcraft-popover-list-item', href: this.href, onClick: this.handleLinkClick.bind(this) }, this.imageSrc && (h("div", { key: '79541d12ea3adafff2e141cb8946aa3feaea51df', class: 'searchcraft-popover-list-item-image-wrapper' }, h("img", { key: '3e6368a0f544a58ee0af9d1c15d0c909c6231842', alt: this.imageAlt, src: this.imageSrc, class: 'searchcraft-popover-list-item-image' }))), h("div", { key: '87e7a9dcc8b868af259b4456e9962af9d8dee498', class: 'searchcraft-popover-list-item-info-wrapper' }, h("p", { key: 'e5b63b4c2752573d0ee0ef52c2903b593a8b94a0', class: 'searchcraft-popover-list-item-title' }, this.titleContent), h("p", { key: 'c506d5d7e569ec20885eb65cdc6476dfb8895a13', class: 'searchcraft-popover-list-item-subtitle' }, this.subtitleContent))));
|
|
12
39
|
}
|
|
13
40
|
static get is() { return "searchcraft-popover-list-item"; }
|
|
14
|
-
static get originalStyleUrls() {
|
|
15
|
-
return {
|
|
16
|
-
"$": ["searchcraft-popover-list-item.module.scss"]
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
static get styleUrls() {
|
|
20
|
-
return {
|
|
21
|
-
"$": ["searchcraft-popover-list-item.module.css"]
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
41
|
static get properties() {
|
|
25
42
|
return {
|
|
26
43
|
"titleContent": {
|
|
@@ -28,7 +45,7 @@ export class SearchcraftPopoverListItem {
|
|
|
28
45
|
"mutable": false,
|
|
29
46
|
"complexType": {
|
|
30
47
|
"original": "string | undefined",
|
|
31
|
-
"resolved": "string",
|
|
48
|
+
"resolved": "string | undefined",
|
|
32
49
|
"references": {}
|
|
33
50
|
},
|
|
34
51
|
"required": false,
|
|
@@ -47,7 +64,7 @@ export class SearchcraftPopoverListItem {
|
|
|
47
64
|
"mutable": false,
|
|
48
65
|
"complexType": {
|
|
49
66
|
"original": "string | undefined",
|
|
50
|
-
"resolved": "string",
|
|
67
|
+
"resolved": "string | undefined",
|
|
51
68
|
"references": {}
|
|
52
69
|
},
|
|
53
70
|
"required": false,
|
|
@@ -66,7 +83,7 @@ export class SearchcraftPopoverListItem {
|
|
|
66
83
|
"mutable": false,
|
|
67
84
|
"complexType": {
|
|
68
85
|
"original": "string | undefined",
|
|
69
|
-
"resolved": "string",
|
|
86
|
+
"resolved": "string | undefined",
|
|
70
87
|
"references": {}
|
|
71
88
|
},
|
|
72
89
|
"required": false,
|
|
@@ -85,7 +102,7 @@ export class SearchcraftPopoverListItem {
|
|
|
85
102
|
"mutable": false,
|
|
86
103
|
"complexType": {
|
|
87
104
|
"original": "string | undefined",
|
|
88
|
-
"resolved": "string",
|
|
105
|
+
"resolved": "string | undefined",
|
|
89
106
|
"references": {}
|
|
90
107
|
},
|
|
91
108
|
"required": false,
|
|
@@ -104,7 +121,7 @@ export class SearchcraftPopoverListItem {
|
|
|
104
121
|
"mutable": false,
|
|
105
122
|
"complexType": {
|
|
106
123
|
"original": "string | undefined",
|
|
107
|
-
"resolved": "string",
|
|
124
|
+
"resolved": "string | undefined",
|
|
108
125
|
"references": {}
|
|
109
126
|
},
|
|
110
127
|
"required": false,
|
|
@@ -135,7 +152,8 @@ export class SearchcraftPopoverListItem {
|
|
|
135
152
|
"getter": false,
|
|
136
153
|
"setter": false,
|
|
137
154
|
"attribute": "document-position",
|
|
138
|
-
"reflect": false
|
|
155
|
+
"reflect": false,
|
|
156
|
+
"defaultValue": "0"
|
|
139
157
|
}
|
|
140
158
|
};
|
|
141
159
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchcraft-popover-list-item.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-list-item/searchcraft-popover-list-item.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;
|
|
1
|
+
{"version":3,"file":"searchcraft-popover-list-item.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-list-item/searchcraft-popover-list-item.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEnD;;GAEG;AAKH,MAAM,OAAO,0BAA0B;IACrC,uBAAuB;IACf,YAAY,CAAqB;IACzC,0BAA0B;IAClB,eAAe,CAAqB;IAC5C,0EAA0E;IAClE,QAAQ,CAAqB;IACrC,yBAAyB;IACjB,QAAQ,CAAqB;IACrC,oBAAoB;IACZ,IAAI,CAAqB;IACjC,yEAAyE;IACjE,gBAAgB,GAAG,CAAC,CAAC;IAE7B,gBAAgB,KAAI,CAAC;IAErB,iBAAiB,KAAI,CAAC;IAEtB,oBAAoB,KAAI,CAAC;IAEzB,iBAAiB,KAAI,CAAC;IAEtB,eAAe,GAAG,GAAG,EAAE;QACrB,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,EAAE,CAAC;QAC7C,MAAM,WAAW,GAAG,KAAK,CAAC,sBAAsB,EAAE,CAAC;QAEnD,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,CAAC;YAChD,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC;YAChC,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;YAEzE,WAAW,CAAC,gBAAgB,CAAC,kBAAkB,EAAE;gBAC/C,iBAAiB;gBACjB,mBAAmB;gBACnB,WAAW;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;IAEF,MAAM;QACJ,OAAO,CACL,0DACE,KAAK,EAAC,+BAA+B,EACrC,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,OAAO,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;YAEvC,IAAI,CAAC,QAAQ,IAAI,CAChB,4DAAK,KAAK,EAAC,6CAA6C;gBACtD,4DACE,GAAG,EAAE,IAAI,CAAC,QAAQ,EAClB,GAAG,EAAE,IAAI,CAAC,QAAQ,EAClB,KAAK,EAAC,qCAAqC,GAC3C,CACE,CACP;YACD,4DAAK,KAAK,EAAC,4CAA4C;gBACrD,0DAAG,KAAK,EAAC,qCAAqC,IAAE,IAAI,CAAC,YAAY,CAAK;gBACtE,0DAAG,KAAK,EAAC,wCAAwC,IAC9C,IAAI,CAAC,eAAe,CACnB,CACA,CACJ,CACL,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { useSearchcraftStore } from '@provider/store';\nimport { Component, h, Prop } from '@stencil/core';\n\n/**\n * A single list item rendered in a searchcraft-popover-list-view.\n */\n@Component({\n tag: 'searchcraft-popover-list-item',\n shadow: false,\n})\nexport class SearchcraftPopoverListItem {\n /** The result title */\n @Prop() titleContent: string | undefined;\n /** The result subtitle */\n @Prop() subtitleContent: string | undefined;\n /** The source of the image. If not included, no item will be rendered. */\n @Prop() imageSrc: string | undefined;\n /** The image alt tag. */\n @Prop() imageAlt: string | undefined;\n /** The link href */\n @Prop() href: string | undefined;\n /** The document position relative to the search results (For Measure) */\n @Prop() documentPosition = 0;\n\n componentDidLoad() {}\n\n connectedCallback() {}\n\n disconnectedCallback() {}\n\n handleButtonClick() {}\n\n handleLinkClick = () => {\n const state = useSearchcraftStore.getState();\n const searchcraft = state.getSearchcraftInstance();\n\n if (searchcraft) {\n const document_position = this.documentPosition;\n const search_term = state.query;\n const number_of_documents = state.searchResults?.data?.hits?.length || 0;\n\n searchcraft.sendMeasureEvent('document_clicked', {\n document_position,\n number_of_documents,\n search_term,\n });\n }\n };\n\n render() {\n return (\n <a\n class='searchcraft-popover-list-item'\n href={this.href}\n onClick={this.handleLinkClick.bind(this)}\n >\n {this.imageSrc && (\n <div class='searchcraft-popover-list-item-image-wrapper'>\n <img\n alt={this.imageAlt}\n src={this.imageSrc}\n class='searchcraft-popover-list-item-image'\n />\n </div>\n )}\n <div class='searchcraft-popover-list-item-info-wrapper'>\n <p class='searchcraft-popover-list-item-title'>{this.titleContent}</p>\n <p class='searchcraft-popover-list-item-subtitle'>\n {this.subtitleContent}\n </p>\n </div>\n </a>\n );\n }\n}\n"]}
|
package/dist/collection/components/searchcraft-popover-list-view/searchcraft-popover-list-view.js
CHANGED
|
@@ -11,32 +11,30 @@ import { getDocumentValueFromSearchResultMapping } from "../../utils/index";
|
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
13
|
export class SearchcraftPopoverListView {
|
|
14
|
+
/**
|
|
15
|
+
* The mappings that define how the data in the documents are mapped to the
|
|
16
|
+
* list-view-item elements.
|
|
17
|
+
*/
|
|
18
|
+
popoverResultMappings;
|
|
19
|
+
/**
|
|
20
|
+
* The documents to render in the list view.
|
|
21
|
+
*/
|
|
22
|
+
documents;
|
|
14
23
|
renderDocument(document, index) {
|
|
15
24
|
/**
|
|
16
25
|
* Index field values -> Result container props mappings.
|
|
17
26
|
*/
|
|
18
|
-
const titleContent = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings
|
|
19
|
-
const subtitleContent = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings
|
|
20
|
-
const href = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings
|
|
21
|
-
const imageSource = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings
|
|
22
|
-
const imageAlt = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings
|
|
27
|
+
const titleContent = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings?.title);
|
|
28
|
+
const subtitleContent = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings?.subtitle);
|
|
29
|
+
const href = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings?.href);
|
|
30
|
+
const imageSource = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings?.imageSource);
|
|
31
|
+
const imageAlt = getDocumentValueFromSearchResultMapping(document, this.popoverResultMappings?.imageAlt);
|
|
23
32
|
return (h("searchcraft-popover-list-item", { key: `${document.document_id}-${index}`, "title-content": titleContent, "subtitle-content": subtitleContent, "image-src": imageSource, "image-alt": imageAlt, href: href, "document-position": index }));
|
|
24
33
|
}
|
|
25
34
|
render() {
|
|
26
|
-
|
|
27
|
-
return (h("div", { key: '6e9017370d7079412d6d31fb439be599d689c9c2', class: 'searchcraft-popover-list-view' }, (_a = this.documents) === null || _a === void 0 ? void 0 : _a.map((document, index) => this.renderDocument(document, index))));
|
|
35
|
+
return (h("div", { key: '2eee5552a2bf24bd0c75a224d4de6da8526df316', class: 'searchcraft-popover-list-view' }, this.documents?.map((document, index) => this.renderDocument(document, index))));
|
|
28
36
|
}
|
|
29
37
|
static get is() { return "searchcraft-popover-list-view"; }
|
|
30
|
-
static get originalStyleUrls() {
|
|
31
|
-
return {
|
|
32
|
-
"$": ["searchcraft-popover-list-view.module.scss"]
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
static get styleUrls() {
|
|
36
|
-
return {
|
|
37
|
-
"$": ["searchcraft-popover-list-view.module.css"]
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
38
|
static get properties() {
|
|
41
39
|
return {
|
|
42
40
|
"popoverResultMappings": {
|
|
@@ -44,7 +42,7 @@ export class SearchcraftPopoverListView {
|
|
|
44
42
|
"mutable": false,
|
|
45
43
|
"complexType": {
|
|
46
44
|
"original": "PopoverResultMappings | undefined",
|
|
47
|
-
"resolved": "{ title?: SearchResultMapping; subtitle?: SearchResultMapping; imageSource?: SearchResultMapping; imageAlt?: SearchResultMapping; href?: SearchResultMapping; }",
|
|
45
|
+
"resolved": "undefined | { title?: SearchResultMapping | undefined; subtitle?: SearchResultMapping | undefined; imageSource?: SearchResultMapping | undefined; imageAlt?: SearchResultMapping | undefined; href?: SearchResultMapping | undefined; }",
|
|
48
46
|
"references": {
|
|
49
47
|
"PopoverResultMappings": {
|
|
50
48
|
"location": "import",
|
|
@@ -67,7 +65,7 @@ export class SearchcraftPopoverListView {
|
|
|
67
65
|
"mutable": false,
|
|
68
66
|
"complexType": {
|
|
69
67
|
"original": "Record<string, unknown>[] | undefined",
|
|
70
|
-
"resolved": "Record<string, unknown>[]",
|
|
68
|
+
"resolved": "Record<string, unknown>[] | undefined",
|
|
71
69
|
"references": {
|
|
72
70
|
"Record": {
|
|
73
71
|
"location": "global",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchcraft-popover-list-view.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-list-view/searchcraft-popover-list-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,uCAAuC,EAAE,MAAM,QAAQ,CAAC;AAGjE;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"searchcraft-popover-list-view.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-popover-list-view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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, h, Prop } from '@stencil/core';\n\nimport { getDocumentValueFromSearchResultMapping } from '@utils';\nimport type { PopoverResultMappings } from 'types';\n\n/**\n * This web component is designed to display a list of results within a popover interface.\n * It is consumed within the `searchcraft-popover-form` component.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-popover-list-view />\n * ```\n */\n@Component({\n tag: 'searchcraft-popover-list-view',\n shadow: false,\n})\nexport class SearchcraftPopoverListView {\n /**\n * The mappings that define how the data in the documents are mapped to the\n * list-view-item elements.\n */\n @Prop() popoverResultMappings: PopoverResultMappings | undefined;\n /**\n * The documents to render in the list view.\n */\n @Prop() documents: Record<string, unknown>[] | undefined;\n\n renderDocument(document: Record<string, unknown>, index: number) {\n /**\n * Index field values -> Result container props mappings.\n */\n const titleContent = getDocumentValueFromSearchResultMapping(\n document,\n this.popoverResultMappings?.title,\n );\n const subtitleContent = getDocumentValueFromSearchResultMapping(\n document,\n this.popoverResultMappings?.subtitle,\n );\n const href = getDocumentValueFromSearchResultMapping(\n document,\n this.popoverResultMappings?.href,\n );\n const imageSource = getDocumentValueFromSearchResultMapping(\n document,\n this.popoverResultMappings?.imageSource,\n );\n const imageAlt = getDocumentValueFromSearchResultMapping(\n document,\n this.popoverResultMappings?.imageAlt,\n );\n\n return (\n <searchcraft-popover-list-item\n key={`${document.document_id}-${index}`}\n title-content={titleContent}\n subtitle-content={subtitleContent}\n image-src={imageSource}\n image-alt={imageAlt}\n href={href}\n document-position={index}\n />\n );\n }\n\n render() {\n return (\n <div class='searchcraft-popover-list-view'>\n {this.documents?.map((document, index) =>\n this.renderDocument(document, index),\n )}\n </div>\n );\n }\n}\n"]}
|
|
@@ -12,18 +12,16 @@ import { formatNumberWithCommas } from "../../utils/index";
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export class SearchcraftResultsInfo {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
isRequesting = false;
|
|
16
|
+
resultsCount = 0;
|
|
17
|
+
responseTime = '';
|
|
18
|
+
query = '';
|
|
19
|
+
unsubscribe = () => { };
|
|
21
20
|
connectedCallback() {
|
|
22
21
|
this.unsubscribe = useSearchcraftStore.subscribe((state) => {
|
|
23
|
-
var _a, _b, _c, _d;
|
|
24
22
|
this.isRequesting = state.isRequesting;
|
|
25
|
-
this.resultsCount =
|
|
26
|
-
this.responseTime = ((
|
|
23
|
+
this.resultsCount = state.searchResults?.data?.count || 0;
|
|
24
|
+
this.responseTime = ((state.searchResults?.data?.time_taken || 0) * 1000).toFixed(2);
|
|
27
25
|
this.query = state.query || '';
|
|
28
26
|
});
|
|
29
27
|
}
|
|
@@ -40,16 +38,6 @@ export class SearchcraftResultsInfo {
|
|
|
40
38
|
return (h("div", { class: 'searchcraft-results-info-container' }, h("p", { class: 'searchcraft-results-info-content' }, formattedResults, " results found in ", this.responseTime, "ms")));
|
|
41
39
|
}
|
|
42
40
|
static get is() { return "searchcraft-results-info"; }
|
|
43
|
-
static get originalStyleUrls() {
|
|
44
|
-
return {
|
|
45
|
-
"$": ["searchcraft-results-info.module.scss"]
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
static get styleUrls() {
|
|
49
|
-
return {
|
|
50
|
-
"$": ["searchcraft-results-info.module.css"]
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
41
|
static get states() {
|
|
54
42
|
return {
|
|
55
43
|
"isRequesting": {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchcraft-results-info.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-results-info/searchcraft-results-info.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAEhD;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"searchcraft-results-info.js","sourceRoot":"","sources":["../../../../src/components/searchcraft-results-info/searchcraft-results-info.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAEhD;;;;;;;;;GASG;AAKH,MAAM,OAAO,sBAAsB;IACxB,YAAY,GAAG,KAAK,CAAC;IACrB,YAAY,GAAG,CAAC,CAAC;IACjB,YAAY,GAAG,EAAE,CAAC;IAClB,KAAK,GAAG,EAAE,CAAC;IAEpB,WAAW,GAAe,GAAG,EAAE,GAAE,CAAC,CAAC;IAEnC,iBAAiB;QACf,IAAI,CAAC,WAAW,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACzD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;YACvC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,CAAC;YAC1D,IAAI,CAAC,YAAY,GAAG,CAClB,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,UAAU,IAAI,CAAC,CAAC,GAAG,IAAI,CACpD,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;QAClB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACnE,OAAO,CACL,WAAK,KAAK,EAAC,oCAAoC;YAC7C,SAAG,KAAK,EAAC,kCAAkC;gBACxC,gBAAgB;;gBAAoB,IAAI,CAAC,YAAY;qBACpD,CACA,CACP,CAAC;IACJ,CAAC;;;;;;;;CACF","sourcesContent":["import { Component, h, State } from '@stencil/core';\n\nimport { useSearchcraftStore } from '@provider/store';\n\nimport { formatNumberWithCommas } from '@utils';\n\n/**\n * This web component is designed to display the number of results returned from a search query.\n * It provides users with real-time feedback on the scale of the results, such as the total number of items found.\n *\n * ## Usage\n * ```html\n * <!-- index.html -->\n * <searchcraft-results-info />\n * ```\n */\n@Component({\n tag: 'searchcraft-results-info',\n shadow: false,\n})\nexport class SearchcraftResultsInfo {\n @State() isRequesting = false;\n @State() resultsCount = 0;\n @State() responseTime = '';\n @State() query = '';\n\n unsubscribe: () => void = () => {};\n\n connectedCallback() {\n this.unsubscribe = useSearchcraftStore.subscribe((state) => {\n this.isRequesting = state.isRequesting;\n this.resultsCount = state.searchResults?.data?.count || 0;\n this.responseTime = (\n (state.searchResults?.data?.time_taken || 0) * 1000\n ).toFixed(2);\n this.query = state.query || '';\n });\n }\n\n disconnectedCallback() {\n if (this.unsubscribe) {\n this.unsubscribe();\n }\n }\n\n render() {\n if (!this.query || this.resultsCount === 0) {\n return null;\n }\n const formattedResults = formatNumberWithCommas(this.resultsCount);\n return (\n <div class='searchcraft-results-info-container'>\n <p class='searchcraft-results-info-content'>\n {formattedResults} results found in {this.responseTime}ms\n </p>\n </div>\n );\n }\n}\n"]}
|