@searchcraft/javascript-sdk 0.12.0 → 0.12.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/dist/components/index.d.ts +13 -0
- package/dist/components/index.js +136 -17
- package/dist/components/index.js.map +1 -1
- package/dist/components/{p-b7e99386.js → p-870f81fd.js} +38 -6
- package/dist/components/p-870f81fd.js.map +1 -0
- package/dist/components/{p-0c495408.js → p-c8566920.js} +74 -33
- package/dist/components/p-c8566920.js.map +1 -0
- package/dist/components/searchcraft-facet-list.js +1 -1
- package/dist/components/searchcraft-filter-panel.js +2 -2
- package/dist/components/searchcraft-filter-panel.js.map +1 -1
- package/dist/components/searchcraft-input-form.js +1 -1
- package/dist/components/searchcraft-pagination.js +8 -2
- package/dist/components/searchcraft-pagination.js.map +1 -1
- package/dist/components/searchcraft-popover-form.js +1 -1
- package/dist/components/searchcraft-results-info.js +9 -1
- package/dist/components/searchcraft-results-info.js.map +1 -1
- package/dist/components/searchcraft-search-results-per-page.js +8 -2
- package/dist/components/searchcraft-search-results-per-page.js.map +1 -1
- package/dist/hydrate/index.js +192 -100
- package/dist/hydrate/index.mjs +192 -100
- package/dist/types/classes/SearchcraftCore.d.ts +1 -1
- package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +1 -1
- package/dist/types/components/searchcraft-filter-panel/searchcraft-filter-panel.d.ts +1 -1
- package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +5 -0
- package/dist/types/components/searchcraft-pagination/searchcraft-pagination.d.ts +1 -0
- package/dist/types/components/searchcraft-results-info/searchcraft-results-info.d.ts +1 -0
- package/dist/types/components/searchcraft-search-results-per-page/searchcraft-search-results-per-page.d.ts +1 -0
- package/dist/types/components.d.ts +8 -0
- package/dist/types/store/SearchcraftStore.types.d.ts +6 -1
- package/package.json +4 -3
- package/dist/components/p-0c495408.js.map +0 -1
- package/dist/components/p-b7e99386.js.map +0 -1
package/dist/hydrate/index.mjs
CHANGED
|
@@ -2555,6 +2555,65 @@ class SearchcraftErrorMessage {
|
|
|
2555
2555
|
}; }
|
|
2556
2556
|
}
|
|
2557
2557
|
|
|
2558
|
+
/**
|
|
2559
|
+
* This is the default instance id for searchcraft core instances.
|
|
2560
|
+
* When no id is specified in a component's props, use this one.
|
|
2561
|
+
*/
|
|
2562
|
+
const DEFAULT_CORE_INSTANCE_ID = 'searchcraft';
|
|
2563
|
+
/**
|
|
2564
|
+
* CoreInstanceRegistry
|
|
2565
|
+
*
|
|
2566
|
+
* This class is responsible for managing all of the instances of SearchcraftCore on a page.
|
|
2567
|
+
* It provides a means for consuming components to use the instance of SearchcraftCore that
|
|
2568
|
+
* they need to use when that instance of core gets added to the Registry.
|
|
2569
|
+
*/
|
|
2570
|
+
class CoreInstanceRegistry {
|
|
2571
|
+
coreInstances = {};
|
|
2572
|
+
subscriptions = {};
|
|
2573
|
+
/**
|
|
2574
|
+
* Adds a SearchcraftCore instance to the Registry.
|
|
2575
|
+
*
|
|
2576
|
+
* When the instance is added, iterates through the onAvailable callbacks
|
|
2577
|
+
* that have been subscribed via useCoreInstance.
|
|
2578
|
+
*
|
|
2579
|
+
* @param coreInstance The SearchcraftCore instance to add to the registry
|
|
2580
|
+
* @param searchcraftId The unique identifier for this SearchcraftCore instance.
|
|
2581
|
+
*/
|
|
2582
|
+
addCoreInstance(coreInstance, searchcraftId) {
|
|
2583
|
+
const id = searchcraftId || DEFAULT_CORE_INSTANCE_ID;
|
|
2584
|
+
this.coreInstances[id] = coreInstance;
|
|
2585
|
+
for (const callback of this.subscriptions[id] || []) {
|
|
2586
|
+
callback(coreInstance);
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
/**
|
|
2590
|
+
* Use the specified instance of SearchcraftCore. When the instance becomes available,
|
|
2591
|
+
* the onAvailable callback will be called.
|
|
2592
|
+
*
|
|
2593
|
+
* @param searchcraftId The SearchcraftCore instance to use.
|
|
2594
|
+
* @param onAvailable The callback that gets called when the core instance becomes available.
|
|
2595
|
+
*/
|
|
2596
|
+
useCoreInstance(searchcraftId, onAvailable) {
|
|
2597
|
+
const id = searchcraftId || DEFAULT_CORE_INSTANCE_ID;
|
|
2598
|
+
// If the core instance already is available, call the onAvailable callback immediately.
|
|
2599
|
+
if (this.coreInstances[id]) {
|
|
2600
|
+
onAvailable(this.coreInstances[id]);
|
|
2601
|
+
return () => { };
|
|
2602
|
+
}
|
|
2603
|
+
// Add the callback to the collection of callbacks for this searchcraft instance.
|
|
2604
|
+
if (!this.subscriptions[id]) {
|
|
2605
|
+
this.subscriptions[id] = [];
|
|
2606
|
+
}
|
|
2607
|
+
this.subscriptions[id].push(onAvailable);
|
|
2608
|
+
return () => {
|
|
2609
|
+
if (this.subscriptions[id]) {
|
|
2610
|
+
this.subscriptions[id] = this.subscriptions[id].filter((cb) => cb !== onAvailable);
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
const registry = new CoreInstanceRegistry();
|
|
2616
|
+
|
|
2558
2617
|
/**
|
|
2559
2618
|
* Helper function for getting a Node (FacetWithChildrenObject)
|
|
2560
2619
|
* at a given path. Traverses the node tree to get the node.
|
|
@@ -4215,65 +4274,6 @@ const html = (strings, ...values) => {
|
|
|
4215
4274
|
return result || '';
|
|
4216
4275
|
};
|
|
4217
4276
|
|
|
4218
|
-
/**
|
|
4219
|
-
* This is the default instance id for searchcraft core instances.
|
|
4220
|
-
* When no id is specified in a component's props, use this one.
|
|
4221
|
-
*/
|
|
4222
|
-
const DEFAULT_CORE_INSTANCE_ID = 'searchcraft';
|
|
4223
|
-
/**
|
|
4224
|
-
* CoreInstanceRegistry
|
|
4225
|
-
*
|
|
4226
|
-
* This class is responsible for managing all of the instances of SearchcraftCore on a page.
|
|
4227
|
-
* It provides a means for consuming components to use the instance of SearchcraftCore that
|
|
4228
|
-
* they need to use when that instance of core gets added to the Registry.
|
|
4229
|
-
*/
|
|
4230
|
-
class CoreInstanceRegistry {
|
|
4231
|
-
coreInstances = {};
|
|
4232
|
-
subscriptions = {};
|
|
4233
|
-
/**
|
|
4234
|
-
* Adds a SearchcraftCore instance to the Registry.
|
|
4235
|
-
*
|
|
4236
|
-
* When the instance is added, iterates through the onAvailable callbacks
|
|
4237
|
-
* that have been subscribed via useCoreInstance.
|
|
4238
|
-
*
|
|
4239
|
-
* @param coreInstance The SearchcraftCore instance to add to the registry
|
|
4240
|
-
* @param searchcraftId The unique identifier for this SearchcraftCore instance.
|
|
4241
|
-
*/
|
|
4242
|
-
addCoreInstance(coreInstance, searchcraftId) {
|
|
4243
|
-
const id = searchcraftId || DEFAULT_CORE_INSTANCE_ID;
|
|
4244
|
-
this.coreInstances[id] = coreInstance;
|
|
4245
|
-
for (const callback of this.subscriptions[id] || []) {
|
|
4246
|
-
callback(coreInstance);
|
|
4247
|
-
}
|
|
4248
|
-
}
|
|
4249
|
-
/**
|
|
4250
|
-
* Use the specified instance of SearchcraftCore. When the instance becomes available,
|
|
4251
|
-
* the onAvailable callback will be called.
|
|
4252
|
-
*
|
|
4253
|
-
* @param searchcraftId The SearchcraftCore instance to use.
|
|
4254
|
-
* @param onAvailable The callback that gets called when the core instance becomes available.
|
|
4255
|
-
*/
|
|
4256
|
-
useCoreInstance(searchcraftId, onAvailable) {
|
|
4257
|
-
const id = searchcraftId || DEFAULT_CORE_INSTANCE_ID;
|
|
4258
|
-
// If the core instance already is available, call the onAvailable callback immediately.
|
|
4259
|
-
if (this.coreInstances[id]) {
|
|
4260
|
-
onAvailable(this.coreInstances[id]);
|
|
4261
|
-
return () => { };
|
|
4262
|
-
}
|
|
4263
|
-
// Add the callback to the collection of callbacks for this searchcraft instance.
|
|
4264
|
-
if (!this.subscriptions[id]) {
|
|
4265
|
-
this.subscriptions[id] = [];
|
|
4266
|
-
}
|
|
4267
|
-
this.subscriptions[id].push(onAvailable);
|
|
4268
|
-
return () => {
|
|
4269
|
-
if (this.subscriptions[id]) {
|
|
4270
|
-
this.subscriptions[id] = this.subscriptions[id].filter((cb) => cb !== onAvailable);
|
|
4271
|
-
}
|
|
4272
|
-
};
|
|
4273
|
-
}
|
|
4274
|
-
}
|
|
4275
|
-
const registry = new CoreInstanceRegistry();
|
|
4276
|
-
|
|
4277
4277
|
/**
|
|
4278
4278
|
* This web component is designed to display facets in a search interface, allowing users to refine their search results by applying filters based on various attributes.
|
|
4279
4279
|
* It is consumed within the `searchcraft-filter-panel`.
|
|
@@ -4436,45 +4436,86 @@ class SearchcraftFacetList {
|
|
|
4436
4436
|
handleStateUpdate(_state) {
|
|
4437
4437
|
const state = { ..._state };
|
|
4438
4438
|
// Determine what action to take based on the current State
|
|
4439
|
-
if (
|
|
4439
|
+
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
4440
|
+
const isInitialQuery = typeof state.searchClientRequestProperties === 'string' &&
|
|
4441
|
+
state.searchTerm.trim() === '';
|
|
4442
|
+
if (state.searchTerm.trim() === '' && !isInitialQuery) {
|
|
4440
4443
|
this.handleIncomingSearchResponse(state, 'SEARCH_TERM_EMPTY');
|
|
4441
4444
|
this.lastSearchTerm = '';
|
|
4442
4445
|
}
|
|
4443
4446
|
else if (this.lastTimeTaken !== state.searchResponseTimeTaken &&
|
|
4444
|
-
state.searchClientRequestProperties
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
if (this.
|
|
4450
|
-
|
|
4447
|
+
state.searchClientRequestProperties) {
|
|
4448
|
+
// Handle both object and string requestProperties (string is used for initialQuery)
|
|
4449
|
+
if (typeof state.searchClientRequestProperties === 'object') {
|
|
4450
|
+
const requestProperties = state.searchClientRequestProperties;
|
|
4451
|
+
let actionType = 'UNKNOWN';
|
|
4452
|
+
if (this.lastSearchTerm !== requestProperties.searchTerm) {
|
|
4453
|
+
if (this.areAnyFacetPathsSelected) {
|
|
4454
|
+
actionType = 'NEW_SEARCH_TERM_WHILE_FACETS_ACTIVE';
|
|
4455
|
+
}
|
|
4456
|
+
else {
|
|
4457
|
+
actionType = 'NEW_SEARCH_TERM';
|
|
4458
|
+
}
|
|
4451
4459
|
}
|
|
4452
|
-
else
|
|
4453
|
-
|
|
4460
|
+
else if (this.lastRangeValues !==
|
|
4461
|
+
JSON.stringify(requestProperties.rangeValueForIndexFields)) {
|
|
4462
|
+
actionType = 'RANGE_VALUE_UPDATE';
|
|
4454
4463
|
}
|
|
4464
|
+
else if (this.lastFacetValues !==
|
|
4465
|
+
JSON.stringify(requestProperties.facetPathsForIndexFields)) {
|
|
4466
|
+
actionType = 'FACET_UPDATE';
|
|
4467
|
+
}
|
|
4468
|
+
else if (this.lastSortType !== requestProperties.order_by) {
|
|
4469
|
+
actionType = 'SORT_ORDER_UPDATE';
|
|
4470
|
+
}
|
|
4471
|
+
else if (this.lastSearchMode !== requestProperties.mode) {
|
|
4472
|
+
actionType = 'EXACT_MATCH_UPDATE';
|
|
4473
|
+
}
|
|
4474
|
+
this.lastRangeValues = JSON.stringify(requestProperties.rangeValueForIndexFields);
|
|
4475
|
+
this.lastFacetValues = JSON.stringify(requestProperties.facetPathsForIndexFields);
|
|
4476
|
+
this.lastSortType = requestProperties.order_by;
|
|
4477
|
+
this.lastSearchMode = requestProperties.mode;
|
|
4478
|
+
this.lastSearchTerm = requestProperties.searchTerm;
|
|
4479
|
+
this.lastTimeTaken = state.searchResponseTimeTaken;
|
|
4480
|
+
// Handle the incoming response, using the action we have determined.
|
|
4481
|
+
this.handleIncomingSearchResponse(state, actionType);
|
|
4455
4482
|
}
|
|
4456
|
-
else if (
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
JSON.
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4483
|
+
else if (typeof state.searchClientRequestProperties === 'string') {
|
|
4484
|
+
// Handle initialQuery case where requestProperties is a string
|
|
4485
|
+
// For initialQuery, searchTerm will be empty but we still want to show facets
|
|
4486
|
+
let actionType = 'NEW_SEARCH_TERM';
|
|
4487
|
+
// Parse the request to get facet and range filters from the query array
|
|
4488
|
+
const requestObj = JSON.parse(state.searchClientRequestProperties);
|
|
4489
|
+
const queryArray = Array.isArray(requestObj.query)
|
|
4490
|
+
? requestObj.query
|
|
4491
|
+
: [requestObj.query];
|
|
4492
|
+
// Extract filter queries (those with occur: 'must')
|
|
4493
|
+
const filterQueries = queryArray.filter((q) => q.occur === 'must');
|
|
4494
|
+
const currentFilters = JSON.stringify(filterQueries);
|
|
4495
|
+
// Determine the action type based on what changed
|
|
4496
|
+
if (this.lastFacetValues !== undefined && this.lastFacetValues !== currentFilters) {
|
|
4497
|
+
// Filters have changed (not initial load)
|
|
4498
|
+
actionType = 'FACET_UPDATE';
|
|
4499
|
+
}
|
|
4500
|
+
else if (state.searchTerm.trim() === '' && this.lastSearchTerm === '') {
|
|
4501
|
+
// Initial load or no changes with empty search term
|
|
4502
|
+
actionType = 'NEW_SEARCH_TERM';
|
|
4503
|
+
}
|
|
4504
|
+
else if (this.lastSearchTerm !== state.searchTerm) {
|
|
4505
|
+
// User has typed a new search term after initialQuery
|
|
4506
|
+
if (this.areAnyFacetPathsSelected) {
|
|
4507
|
+
actionType = 'NEW_SEARCH_TERM_WHILE_FACETS_ACTIVE';
|
|
4508
|
+
}
|
|
4509
|
+
else {
|
|
4510
|
+
actionType = 'NEW_SEARCH_TERM';
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
this.lastFacetValues = currentFilters;
|
|
4514
|
+
this.lastSearchTerm = state.searchTerm;
|
|
4515
|
+
this.lastTimeTaken = state.searchResponseTimeTaken;
|
|
4516
|
+
// Handle the incoming response, using the action we have determined.
|
|
4517
|
+
this.handleIncomingSearchResponse(state, actionType);
|
|
4469
4518
|
}
|
|
4470
|
-
this.lastRangeValues = JSON.stringify(requestProperties.rangeValueForIndexFields);
|
|
4471
|
-
this.lastFacetValues = JSON.stringify(requestProperties.facetPathsForIndexFields);
|
|
4472
|
-
this.lastSortType = requestProperties.order_by;
|
|
4473
|
-
this.lastSearchMode = requestProperties.mode;
|
|
4474
|
-
this.lastSearchTerm = requestProperties.searchTerm;
|
|
4475
|
-
this.lastTimeTaken = state.searchResponseTimeTaken;
|
|
4476
|
-
// Handle the incoming response, using the action we have determined.
|
|
4477
|
-
this.handleIncomingSearchResponse(state, actionType);
|
|
4478
4519
|
}
|
|
4479
4520
|
}
|
|
4480
4521
|
onCoreAvailable(core) {
|
|
@@ -4714,7 +4755,7 @@ class SearchcraftFilterPanel {
|
|
|
4714
4755
|
* Iterate through `items` and render them based on `type`
|
|
4715
4756
|
*/
|
|
4716
4757
|
render() {
|
|
4717
|
-
return (hAsync("div", { key: '
|
|
4758
|
+
return (hAsync("div", { key: 'ee8974e38b296a1ba27111bc2a4244d8915f5839', class: 'searchcraft-filter-panel' }, this.items.map((filterItem) => {
|
|
4718
4759
|
switch (filterItem.type) {
|
|
4719
4760
|
case 'dateRange': {
|
|
4720
4761
|
const item = filterItem;
|
|
@@ -4833,6 +4874,10 @@ class SearchcraftInputForm {
|
|
|
4833
4874
|
* 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
4834
4875
|
*/
|
|
4835
4876
|
placeholderBehavior;
|
|
4877
|
+
/**
|
|
4878
|
+
* The value to display in the input field.
|
|
4879
|
+
*/
|
|
4880
|
+
value;
|
|
4836
4881
|
/**
|
|
4837
4882
|
* When the input becomes focused.
|
|
4838
4883
|
*/
|
|
@@ -4853,18 +4898,41 @@ class SearchcraftInputForm {
|
|
|
4853
4898
|
cleanupCore;
|
|
4854
4899
|
init() {
|
|
4855
4900
|
if (this.core) {
|
|
4901
|
+
// Initialize inputValue from prop if provided
|
|
4902
|
+
if (this.value !== undefined && this.value.trim().length > 0) {
|
|
4903
|
+
this.inputValue = this.value;
|
|
4904
|
+
this.core.store.getState().setSearchTerm(this.value);
|
|
4905
|
+
// Trigger search if autoSearch is enabled
|
|
4906
|
+
if (this.autoSearch) {
|
|
4907
|
+
this.core.store.getState().search();
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4856
4910
|
this.inputInit?.emit();
|
|
4857
4911
|
}
|
|
4858
4912
|
}
|
|
4859
4913
|
onCoreChange() {
|
|
4860
4914
|
this.init();
|
|
4861
4915
|
}
|
|
4916
|
+
onValueChange(newValue) {
|
|
4917
|
+
if (newValue !== undefined && newValue !== this.inputValue) {
|
|
4918
|
+
this.inputValue = newValue;
|
|
4919
|
+
this.core?.store.getState().setSearchTerm(newValue);
|
|
4920
|
+
// Trigger search if autoSearch is enabled and value is not empty
|
|
4921
|
+
if (this.autoSearch && newValue.trim().length > 0) {
|
|
4922
|
+
this.core?.store.getState().search();
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
}
|
|
4862
4926
|
onCoreAvailable(core) {
|
|
4863
4927
|
this.core = core;
|
|
4864
4928
|
this.init();
|
|
4865
4929
|
this.unsubscribe = core.store.subscribe((state) => {
|
|
4866
4930
|
this.searchTerm = state.searchTerm;
|
|
4867
|
-
|
|
4931
|
+
// Only update inputValue from store if value prop is not set
|
|
4932
|
+
// OR if the store was cleared (empty string)
|
|
4933
|
+
if (this.value === undefined || state.searchTerm === '') {
|
|
4934
|
+
this.inputValue = state.searchTerm;
|
|
4935
|
+
}
|
|
4868
4936
|
});
|
|
4869
4937
|
}
|
|
4870
4938
|
connectedCallback() {
|
|
@@ -4893,6 +4961,8 @@ class SearchcraftInputForm {
|
|
|
4893
4961
|
}
|
|
4894
4962
|
};
|
|
4895
4963
|
handleClearInput = () => {
|
|
4964
|
+
// Clear the input value even if controlled by prop
|
|
4965
|
+
this.inputValue = '';
|
|
4896
4966
|
this.core?.store.getState().resetSearchValues();
|
|
4897
4967
|
this.error = false;
|
|
4898
4968
|
};
|
|
@@ -4911,14 +4981,15 @@ class SearchcraftInputForm {
|
|
|
4911
4981
|
const inputGridStyles = {
|
|
4912
4982
|
gap: shouldHaveVerticalGap ? '4px 8px' : '0px 8px',
|
|
4913
4983
|
};
|
|
4914
|
-
return (hAsync("form", { key: '
|
|
4984
|
+
return (hAsync("form", { key: 'd214ace44e9209154d215e803de088aefa58a285', class: 'searchcraft-input-form', onSubmit: this.handleFormSubmit }, hAsync("div", { key: '5699f5dca28caf5e9584401f1883d2e08d26e3ec', class: inputGridClassNames, style: inputGridStyles }, hAsync("div", { key: 'ef792a946414a680e9c99c145246d00b9b8f2ffb', class: 'searchcraft-input-form-button' }, hAsync("searchcraft-button", { key: 'ba5a8cb98889bb486781af4915a21c94a0b1498a', onButtonClick: this.handleFormSubmit, label: this.buttonLabel })), this.inputLabel && (hAsync("div", { key: 'a9e770ef967f7ab1c6ddf8f87f23cea509894536', class: 'searchcraft-input-form-label' }, hAsync("searchcraft-input-label", { key: '93b29e630e71a3c7724921aa9586aab76e592f4f', label: this.inputLabel }))), this.error && (hAsync("div", { key: '641ef4f468d527c24a1635d49dcbbba03030686f', class: 'searchcraft-input-form-error-message' }, hAsync("searchcraft-error-message", { key: '2d839d17b702fe1b41d7e49aacfc52fb53315766' }, "Something went wrong."))), hAsync("div", { key: 'af0c73478de21447c992bd0037ba007d54f53a86', class: 'searchcraft-input-form-input-wrapper' }, hAsync("input", { key: '3de1be1aa71c143b58cd6080d422410bd400e4e5', autoComplete: 'off', class: classNames('searchcraft-input-form-input', {
|
|
4915
4985
|
'searchcraft-placeholder-hide-on-focus': this.placeholderBehavior === 'hide-on-focus',
|
|
4916
4986
|
}), onFocus: () => this.inputFocus?.emit(), onBlur: () => this.inputBlur?.emit(), onInput: (event) => {
|
|
4917
4987
|
this.handleInput(event);
|
|
4918
|
-
}, placeholder: this.placeholderValue, type: 'text', value: this.inputValue }), hAsync("div", { key: '
|
|
4988
|
+
}, placeholder: this.placeholderValue, type: 'text', value: this.inputValue }), hAsync("div", { key: 'fe9043c046e3b1b91129299f0860919ba8a8416b', class: 'searchcraft-input-form-input-icon' }, hAsync("svg", { key: '31ae1553cd214d5e2f97c9e3699862dff51a0916', class: 'searchcraft-input-form-input-search-icon', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'searchcraft-title' }, hAsync("title", { key: '9db677da65283ff15b0d4e79b5d9daf89637b33f' }, "Search icon"), hAsync("path", { key: '2a002eae6ed3725a432e7c3e4649c0bd2ffff7a0', d: 'M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))), isShowingClearButton && (hAsync("button", { key: 'b7e92b22c3234eb31d85b0aa98d7c682b2fc0021', type: 'button', class: 'searchcraft-input-form-clear-button', onClick: this.handleClearInput }, hAsync("svg", { key: 'bfbeb742f197da0cac6dd5df2627db9df5349207', class: 'searchcraft-input-form-clear-icon', viewBox: '0 0 22 22', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'icon-title' }, hAsync("title", { key: 'c62b9d237b3762609fed72e0520322fb5eabe979' }, "Clear icon"), hAsync("path", { key: '198a13760ce8b076ef8e791dec933b210ff3017a', d: 'M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))))))));
|
|
4919
4989
|
}
|
|
4920
4990
|
static get watchers() { return {
|
|
4921
|
-
"core": ["onCoreChange"]
|
|
4991
|
+
"core": ["onCoreChange"],
|
|
4992
|
+
"value": ["onValueChange"]
|
|
4922
4993
|
}; }
|
|
4923
4994
|
static get cmpMeta() { return {
|
|
4924
4995
|
"$flags$": 0,
|
|
@@ -4931,6 +5002,7 @@ class SearchcraftInputForm {
|
|
|
4931
5002
|
"inputLabel": [1, "input-label"],
|
|
4932
5003
|
"placeholderValue": [1, "placeholder-value"],
|
|
4933
5004
|
"placeholderBehavior": [1, "placeholder-behavior"],
|
|
5005
|
+
"value": [1],
|
|
4934
5006
|
"inputValue": [32],
|
|
4935
5007
|
"searchTerm": [32],
|
|
4936
5008
|
"error": [32]
|
|
@@ -5042,6 +5114,7 @@ class SearchcraftPagination {
|
|
|
5042
5114
|
searchResultsPerPage;
|
|
5043
5115
|
searchResultsPage;
|
|
5044
5116
|
searchResultsCount;
|
|
5117
|
+
searchClientRequestProperties;
|
|
5045
5118
|
// local vars
|
|
5046
5119
|
searchResultsPagesCount = 1;
|
|
5047
5120
|
searchResultsRangeMin = 1;
|
|
@@ -5057,6 +5130,7 @@ class SearchcraftPagination {
|
|
|
5057
5130
|
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
5058
5131
|
this.searchResultsPage = state.searchResultsPage;
|
|
5059
5132
|
this.searchResultsCount = state.searchResultsCount;
|
|
5133
|
+
this.searchClientRequestProperties = state.searchClientRequestProperties;
|
|
5060
5134
|
// local vars
|
|
5061
5135
|
this.searchResultsPagesCount = Math.ceil(this.searchResultsCount / this.searchResultsPerPage);
|
|
5062
5136
|
this.searchResultsRangeMin =
|
|
@@ -5116,8 +5190,11 @@ class SearchcraftPagination {
|
|
|
5116
5190
|
return (hAsync("li", null, hAsync("span", { class: 'searchcraft-pagination-item searchcraft-pagination-item-active' }, this.searchResultsPage)));
|
|
5117
5191
|
}
|
|
5118
5192
|
render() {
|
|
5119
|
-
//
|
|
5120
|
-
|
|
5193
|
+
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
5194
|
+
const isInitialQuery = typeof this.searchClientRequestProperties === 'string' &&
|
|
5195
|
+
this.searchTerm.trim() === '';
|
|
5196
|
+
// early return if there isn't a searchTerm (unless it's initialQuery) or there is 1 or fewer pages of results
|
|
5197
|
+
if ((!this.searchTerm && !isInitialQuery) || this.searchResultsPagesCount <= 1) {
|
|
5121
5198
|
return;
|
|
5122
5199
|
}
|
|
5123
5200
|
return (hAsync("div", { class: 'searchcraft-pagination' }, hAsync("div", { class: 'searchcraft-pagination-control' }, hAsync("searchcraft-button", { disabled: this.searchResultsPage === 1, hierarchy: 'tertiary', onButtonClick: () => this.handleGoToPage(Math.max(1, this.searchResultsPage - 1)), label: 'Previous', iconPosition: 'left', icon: hAsync("svg", { class: 'searchcraft-button-icon', width: '20', height: '20', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' }, hAsync("title", null, "Previous page icon"), hAsync("path", { d: 'M12.5 15L7.5 10L12.5 5', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' })), iconOnly: true })), hAsync("ul", { class: 'searchcraft-pagination-list' }, this.renderOddPaginationItem(1), this.renderEvenPaginationItem(2), this.renderMiddlePaginationItem(), this.renderEvenPaginationItem(this.searchResultsPagesCount > 4
|
|
@@ -5135,6 +5212,7 @@ class SearchcraftPagination {
|
|
|
5135
5212
|
"searchResultsPerPage": [32],
|
|
5136
5213
|
"searchResultsPage": [32],
|
|
5137
5214
|
"searchResultsCount": [32],
|
|
5215
|
+
"searchClientRequestProperties": [32],
|
|
5138
5216
|
"searchResultsPagesCount": [32],
|
|
5139
5217
|
"searchResultsRangeMin": [32],
|
|
5140
5218
|
"searchResultsRangeMax": [32],
|
|
@@ -6158,6 +6236,7 @@ class SearchcraftResultsInfo {
|
|
|
6158
6236
|
searchResultsPage;
|
|
6159
6237
|
searchResultsPerPage;
|
|
6160
6238
|
searchResultsCount;
|
|
6239
|
+
searchClientRequestProperties;
|
|
6161
6240
|
// local vars
|
|
6162
6241
|
count = 0;
|
|
6163
6242
|
range = [0, 0];
|
|
@@ -6171,6 +6250,7 @@ class SearchcraftResultsInfo {
|
|
|
6171
6250
|
this.searchResultsPage = state.searchResultsPage;
|
|
6172
6251
|
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
6173
6252
|
this.searchResultsCount = state.searchResultsCount;
|
|
6253
|
+
this.searchClientRequestProperties = state.searchClientRequestProperties;
|
|
6174
6254
|
// local vars
|
|
6175
6255
|
this.count = this.searchResultsCount;
|
|
6176
6256
|
this.range[0] =
|
|
@@ -6193,7 +6273,12 @@ class SearchcraftResultsInfo {
|
|
|
6193
6273
|
this.cleanupCore?.();
|
|
6194
6274
|
}
|
|
6195
6275
|
render() {
|
|
6196
|
-
if
|
|
6276
|
+
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
6277
|
+
const isInitialQuery = typeof this.searchClientRequestProperties === 'string' &&
|
|
6278
|
+
this.searchTerm.trim() === '';
|
|
6279
|
+
// Only hide if there's no search term AND no initialQuery AND no results
|
|
6280
|
+
if ((!this.searchTerm && !isInitialQuery) ||
|
|
6281
|
+
this.searchResultsCount === 0) {
|
|
6197
6282
|
return null;
|
|
6198
6283
|
}
|
|
6199
6284
|
return (hAsync("p", { class: 'searchcraft-results-info' }, typeof this.template !== 'undefined'
|
|
@@ -6214,6 +6299,7 @@ class SearchcraftResultsInfo {
|
|
|
6214
6299
|
"searchResultsPage": [32],
|
|
6215
6300
|
"searchResultsPerPage": [32],
|
|
6216
6301
|
"searchResultsCount": [32],
|
|
6302
|
+
"searchClientRequestProperties": [32],
|
|
6217
6303
|
"count": [32],
|
|
6218
6304
|
"range": [32],
|
|
6219
6305
|
"responseTime": [32]
|
|
@@ -6588,6 +6674,7 @@ class SearchcraftSearchResultsPerPage {
|
|
|
6588
6674
|
searchResultsPerPage;
|
|
6589
6675
|
searchResultsCount;
|
|
6590
6676
|
searchResultsPagesCount;
|
|
6677
|
+
searchClientRequestProperties;
|
|
6591
6678
|
// local vars
|
|
6592
6679
|
initialSearchResultsPerPage;
|
|
6593
6680
|
// store functions
|
|
@@ -6602,6 +6689,7 @@ class SearchcraftSearchResultsPerPage {
|
|
|
6602
6689
|
this.searchResultsPerPage = state.searchResultsPerPage;
|
|
6603
6690
|
this.searchResultsPage = state.searchResultsPage;
|
|
6604
6691
|
this.searchResultsCount = state.searchResultsCount;
|
|
6692
|
+
this.searchClientRequestProperties = state.searchClientRequestProperties;
|
|
6605
6693
|
// local vars
|
|
6606
6694
|
this.searchResultsPagesCount = Math.ceil(this.searchResultsCount / this.searchResultsPerPage);
|
|
6607
6695
|
// store functions
|
|
@@ -6619,8 +6707,11 @@ class SearchcraftSearchResultsPerPage {
|
|
|
6619
6707
|
this.cleanupCore?.();
|
|
6620
6708
|
}
|
|
6621
6709
|
render() {
|
|
6622
|
-
//
|
|
6623
|
-
|
|
6710
|
+
// Check if this is an initialQuery case (string requestProperties with empty searchTerm)
|
|
6711
|
+
const isInitialQuery = typeof this.searchClientRequestProperties === 'string' &&
|
|
6712
|
+
this.searchTerm.trim() === '';
|
|
6713
|
+
// early return if there isn't a searchTerm (unless it's initialQuery) or there is 1 or fewer pages of results
|
|
6714
|
+
if ((!this.searchTerm && !isInitialQuery) || this.searchResultsPagesCount <= 1) {
|
|
6624
6715
|
return;
|
|
6625
6716
|
}
|
|
6626
6717
|
return (hAsync("div", { class: 'searchcraft-search-results-per-page' }, hAsync("div", { class: 'searchcraft-search-results-per-page-select' }, hAsync("label", { class: 'searchcraft-search-results-per-page-select-label', htmlFor: 'searchcraft-search-results-per-page-select-input' }, "Results Per Page"), hAsync("div", { class: 'searchcraft-search-results-per-page-select-input' }, hAsync("searchcraft-select", { inputId: 'searchcraft-search-results-per-page-select-input', name: 'results-per-page', options: [...Array(5)].map((_, index) => {
|
|
@@ -6646,6 +6737,7 @@ class SearchcraftSearchResultsPerPage {
|
|
|
6646
6737
|
"searchResultsPerPage": [32],
|
|
6647
6738
|
"searchResultsCount": [32],
|
|
6648
6739
|
"searchResultsPagesCount": [32],
|
|
6740
|
+
"searchClientRequestProperties": [32],
|
|
6649
6741
|
"initialSearchResultsPerPage": [32],
|
|
6650
6742
|
"setSearchResultsPerPage": [32],
|
|
6651
6743
|
"setSearchResultsPage": [32]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AdClient, MeasureClient, SearchClient } from "../clients/index";
|
|
2
|
-
import type { AdClientResponseItem, SearchcraftConfig, SearchcraftSDKInfo,
|
|
2
|
+
import type { AdClientResponseItem, SearchClientRequestProperties, SearchcraftConfig, SearchcraftSDKInfo, SubscriptionEventCallback, SubscriptionEventMap, SubscriptionEventName, UnsubscribeFunction } from "../types/index";
|
|
3
3
|
import { type SearchcraftStore } from "../store/index";
|
|
4
4
|
/**
|
|
5
5
|
* Javascript Class providing the functionality to interact with the Searchcraft BE
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type EventEmitter } from '../../stencil-public-runtime';
|
|
2
2
|
import type { FacetWithChildrenObject } from "../../types/index";
|
|
3
|
-
import type { SearchcraftState } from "../../store/index";
|
|
4
3
|
import type { SearchcraftCore } from "../../classes/index";
|
|
4
|
+
import type { SearchcraftState } from "../../store/index";
|
|
5
5
|
type HandlerActionType = 'SEARCH_TERM_EMPTY' | 'NEW_SEARCH_TERM' | 'NEW_SEARCH_TERM_WHILE_FACETS_ACTIVE' | 'RANGE_VALUE_UPDATE' | 'EXACT_MATCH_UPDATE' | 'SORT_ORDER_UPDATE' | 'FACET_UPDATE' | 'UNKNOWN';
|
|
6
6
|
/**
|
|
7
7
|
* This web component is designed to display facets in a search interface, allowing users to refine their search results by applying filters based on various attributes.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SearchcraftCore } from "../../classes/index";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DateRangeFilterItem, FilterItem } from "../../types/index";
|
|
3
3
|
/**
|
|
4
4
|
* This web component represents a series of filters that allows users to refine and control their search queries by applying various filter criteria.
|
|
5
5
|
*
|
|
@@ -60,6 +60,10 @@ export declare class SearchcraftInputForm {
|
|
|
60
60
|
* 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
|
|
61
61
|
*/
|
|
62
62
|
placeholderBehavior?: 'hide-on-focus' | 'hide-on-text-entered';
|
|
63
|
+
/**
|
|
64
|
+
* The value to display in the input field.
|
|
65
|
+
*/
|
|
66
|
+
value?: string;
|
|
63
67
|
/**
|
|
64
68
|
* When the input becomes focused.
|
|
65
69
|
*/
|
|
@@ -80,6 +84,7 @@ export declare class SearchcraftInputForm {
|
|
|
80
84
|
private cleanupCore?;
|
|
81
85
|
init(): void;
|
|
82
86
|
onCoreChange(): void;
|
|
87
|
+
onValueChange(newValue: string | undefined): void;
|
|
83
88
|
onCoreAvailable(core: SearchcraftCore): void;
|
|
84
89
|
connectedCallback(): void;
|
|
85
90
|
disconnectedCallback(): void;
|
|
@@ -36,6 +36,7 @@ export declare class SearchcraftPagination {
|
|
|
36
36
|
searchResultsPerPage: any;
|
|
37
37
|
searchResultsPage: any;
|
|
38
38
|
searchResultsCount: any;
|
|
39
|
+
searchClientRequestProperties: any;
|
|
39
40
|
searchResultsPagesCount: number;
|
|
40
41
|
searchResultsRangeMin: number;
|
|
41
42
|
searchResultsRangeMax: number;
|
|
@@ -43,6 +43,7 @@ export declare class SearchcraftSearchResultsPerPage {
|
|
|
43
43
|
searchResultsPerPage: any;
|
|
44
44
|
searchResultsCount: any;
|
|
45
45
|
searchResultsPagesCount: any;
|
|
46
|
+
searchClientRequestProperties: any;
|
|
46
47
|
initialSearchResultsPerPage: any;
|
|
47
48
|
setSearchResultsPerPage: (perPage: number) => void;
|
|
48
49
|
setSearchResultsPage: (page: number) => void;
|
|
@@ -178,6 +178,10 @@ export namespace Components {
|
|
|
178
178
|
* The id of the Searchcraft instance that this component should use.
|
|
179
179
|
*/
|
|
180
180
|
"searchcraftId"?: string;
|
|
181
|
+
/**
|
|
182
|
+
* The value to display in the input field.
|
|
183
|
+
*/
|
|
184
|
+
"value"?: string;
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
187
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -1437,6 +1441,10 @@ declare namespace LocalJSX {
|
|
|
1437
1441
|
* The id of the Searchcraft instance that this component should use.
|
|
1438
1442
|
*/
|
|
1439
1443
|
"searchcraftId"?: string;
|
|
1444
|
+
/**
|
|
1445
|
+
* The value to display in the input field.
|
|
1446
|
+
*/
|
|
1447
|
+
"value"?: string;
|
|
1440
1448
|
}
|
|
1441
1449
|
/**
|
|
1442
1450
|
* This web component serves as the input label for the searchcraft-input-form component.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { AdClientResponseItem, FacetPathsForIndexField, FacetPrime, RangeValueForIndexField, SearchClientRequest, SearchClientRequestProperties, SearchClientResponseItem } from "../types/index";
|
|
1
2
|
import type { StoreApi } from 'zustand';
|
|
2
|
-
import type { FacetPathsForIndexField, FacetPrime, RangeValueForIndexField, SearchClientResponseItem, AdClientResponseItem, SearchClientRequestProperties, SearchClientRequest } from "../types/index";
|
|
3
3
|
import type { SearchcraftCore } from "../classes/index";
|
|
4
4
|
import type { SummaryClient } from "../clients/SummaryClient";
|
|
5
5
|
/**
|
|
@@ -44,6 +44,11 @@ export interface SearchcraftStateValues {
|
|
|
44
44
|
searchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
45
45
|
searchClientResponseItems: SearchClientResponseItem[];
|
|
46
46
|
cachedSearchClientResponseItems: SearchClientResponseItem[];
|
|
47
|
+
cachedSearchResponseFacetPrime: FacetPrime | undefined | null;
|
|
48
|
+
cachedSupplementalFacetPrime: FacetPrime | undefined | null;
|
|
49
|
+
cachedSearchResponseTimeTaken: number | undefined;
|
|
50
|
+
cachedSearchResultsCount: number | undefined;
|
|
51
|
+
cachedSearchClientRequestProperties: SearchClientRequestProperties | string | undefined | null;
|
|
47
52
|
searchResponseTimeTaken: number | undefined;
|
|
48
53
|
searchResponseFacetPrime: FacetPrime | undefined | null;
|
|
49
54
|
supplementalFacetPrime: FacetPrime | undefined | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchcraft/javascript-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.1",
|
|
5
5
|
"description": "Searchcraft Javascript SDK",
|
|
6
6
|
"author": "Searchcraft Inc.",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "https://
|
|
28
|
+
"url": "https://github.com/searchcraft-inc/searchcraft-javascript-sdks"
|
|
29
29
|
},
|
|
30
|
+
"homepage": "https://github.com/searchcraft-inc/searchcraft-javascript-sdks#readme",
|
|
30
31
|
"files": [
|
|
31
32
|
"dist/"
|
|
32
33
|
],
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"nanoid": "^5.0.9",
|
|
55
56
|
"zustand": "^5.0.1"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "585c42c689029256b94d34ae6f0a900240c3dfbe"
|
|
58
59
|
}
|