instantsearch.js 4.54.1 → 4.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/components/Breadcrumb/Breadcrumb.js +2 -2
- package/cjs/components/Hits/Hits.js +16 -7
- package/cjs/components/InfiniteHits/InfiniteHits.js +13 -2
- package/cjs/components/RangeInput/RangeInput.js +22 -11
- package/cjs/components/RefinementList/RefinementList.js +34 -52
- package/cjs/components/Slider/Rheostat.js +163 -249
- package/cjs/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/cjs/connectors/geo-search/connectGeoSearch.js +1 -1
- package/cjs/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/cjs/connectors/hits/connectHits.js +1 -1
- package/cjs/connectors/infinite-hits/connectInfiniteHits.js +55 -32
- package/cjs/connectors/menu/connectMenu.js +1 -1
- package/cjs/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/cjs/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/cjs/connectors/refinement-list/connectRefinementList.js +1 -1
- package/cjs/connectors/toggle-refinement/connectToggleRefinement.js +14 -4
- package/cjs/helpers/insights.js +3 -4
- package/cjs/lib/InstantSearch.js +20 -6
- package/cjs/lib/insights/listener.js +43 -36
- package/cjs/lib/routers/history.js +55 -1
- package/cjs/lib/stateMappings/simple.js +1 -0
- package/cjs/lib/stateMappings/singleIndex.js +1 -0
- package/cjs/lib/utils/createSendEventForFacet.js +12 -2
- package/cjs/lib/utils/createSendEventForHits.js +34 -11
- package/cjs/lib/utils/render-args.js +3 -2
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createInsightsMiddleware.js +135 -33
- package/cjs/middlewares/createMetadataMiddleware.js +17 -5
- package/cjs/middlewares/createRouterMiddleware.js +5 -1
- package/cjs/widgets/hits/hits.js +1 -2
- package/cjs/widgets/hits-per-page/hits-per-page.js +3 -1
- package/cjs/widgets/index/index.js +8 -8
- package/cjs/widgets/infinite-hits/infinite-hits.js +1 -2
- package/dist/instantsearch.development.d.ts +143 -84
- package/dist/instantsearch.development.js +770 -584
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +143 -84
- package/dist/instantsearch.production.min.d.ts +143 -84
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/components/Breadcrumb/Breadcrumb.d.ts +2 -2
- package/es/components/Breadcrumb/Breadcrumb.js +2 -2
- package/es/components/GeoSearchControls/GeoSearchButton.d.ts +1 -1
- package/es/components/GeoSearchControls/GeoSearchControls.d.ts +3 -3
- package/es/components/GeoSearchControls/GeoSearchToggle.d.ts +1 -1
- package/es/components/Hits/Hits.d.ts +5 -5
- package/es/components/Hits/Hits.js +15 -5
- package/es/components/InfiniteHits/InfiniteHits.d.ts +3 -2
- package/es/components/InfiniteHits/InfiniteHits.js +13 -2
- package/es/components/Pagination/Pagination.d.ts +2 -2
- package/es/components/RangeInput/RangeInput.d.ts +7 -4
- package/es/components/RangeInput/RangeInput.js +22 -11
- package/es/components/RefinementList/RefinementList.d.ts +0 -1
- package/es/components/RefinementList/RefinementList.js +34 -52
- package/es/components/RelevantSort/RelevantSort.d.ts +1 -1
- package/es/components/Selector/Selector.d.ts +2 -2
- package/es/components/Slider/Rheostat.d.ts +23 -17
- package/es/components/Slider/Rheostat.js +163 -249
- package/es/components/Slider/Slider.d.ts +1 -1
- package/es/connectors/autocomplete/connectAutocomplete.js +1 -1
- package/es/connectors/current-refinements/connectCurrentRefinements.d.ts +2 -2
- package/es/connectors/dynamic-widgets/connectDynamicWidgets.d.ts +2 -2
- package/es/connectors/geo-search/connectGeoSearch.d.ts +7 -7
- package/es/connectors/geo-search/connectGeoSearch.js +1 -1
- package/es/connectors/hierarchical-menu/connectHierarchicalMenu.js +1 -1
- package/es/connectors/hits/connectHits.js +1 -1
- package/es/connectors/infinite-hits/connectInfiniteHits.js +56 -33
- package/es/connectors/menu/connectMenu.d.ts +2 -2
- package/es/connectors/menu/connectMenu.js +1 -1
- package/es/connectors/numeric-menu/connectNumericMenu.js +1 -1
- package/es/connectors/pagination/connectPagination.d.ts +1 -1
- package/es/connectors/range/connectRange.d.ts +3 -3
- package/es/connectors/rating-menu/connectRatingMenu.js +7 -3
- package/es/connectors/refinement-list/connectRefinementList.d.ts +3 -3
- package/es/connectors/refinement-list/connectRefinementList.js +1 -1
- package/es/connectors/relevant-sort/connectRelevantSort.d.ts +1 -1
- package/es/connectors/toggle-refinement/connectToggleRefinement.js +13 -3
- package/es/helpers/insights.d.ts +2 -1
- package/es/helpers/insights.js +3 -3
- package/es/lib/InstantSearch.d.ts +24 -14
- package/es/lib/InstantSearch.js +21 -7
- package/es/lib/insights/listener.d.ts +10 -6
- package/es/lib/insights/listener.js +42 -36
- package/es/lib/routers/history.d.ts +3 -2
- package/es/lib/routers/history.js +56 -2
- package/es/lib/stateMappings/simple.js +1 -0
- package/es/lib/stateMappings/singleIndex.js +1 -0
- package/es/lib/utils/createSendEventForFacet.js +12 -2
- package/es/lib/utils/createSendEventForHits.d.ts +8 -0
- package/es/lib/utils/createSendEventForHits.js +33 -11
- package/es/lib/utils/defer.d.ts +2 -2
- package/es/lib/utils/render-args.js +3 -2
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createInsightsMiddleware.d.ts +12 -12
- package/es/middlewares/createInsightsMiddleware.js +136 -34
- package/es/middlewares/createMetadataMiddleware.d.ts +3 -1
- package/es/middlewares/createMetadataMiddleware.js +17 -5
- package/es/middlewares/createRouterMiddleware.js +5 -1
- package/es/types/insights.d.ts +19 -1
- package/es/types/middleware.d.ts +22 -6
- package/es/types/router.d.ts +15 -7
- package/es/types/widget.d.ts +1 -1
- package/es/widgets/dynamic-widgets/dynamic-widgets.d.ts +2 -2
- package/es/widgets/geo-search/createHTMLMarker.d.ts +1 -1
- package/es/widgets/geo-search/geo-search.d.ts +1 -1
- package/es/widgets/hits/hits.js +2 -3
- package/es/widgets/hits-per-page/hits-per-page.js +3 -1
- package/es/widgets/index/index.d.ts +20 -20
- package/es/widgets/index/index.js +8 -8
- package/es/widgets/infinite-hits/infinite-hits.js +2 -3
- package/es/widgets/panel/panel.d.ts +2 -2
- package/es/widgets/range-slider/range-slider.d.ts +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! InstantSearch.js 4.
|
|
1
|
+
/*! InstantSearch.js 4.56.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
@@ -748,10 +748,13 @@
|
|
|
748
748
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
749
749
|
args[_key] = arguments[_key];
|
|
750
750
|
}
|
|
751
|
-
var
|
|
752
|
-
facetValue = args[1],
|
|
751
|
+
var facetValue = args[1],
|
|
753
752
|
_args$ = args[2],
|
|
754
753
|
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
754
|
+
var _args$0$split = args[0].split(':'),
|
|
755
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
756
|
+
eventType = _args$0$split2[0],
|
|
757
|
+
eventModifier = _args$0$split2[1];
|
|
755
758
|
var attribute = typeof attr === 'string' ? attr : attr(facetValue);
|
|
756
759
|
if (args.length === 1 && _typeof(args[0]) === 'object') {
|
|
757
760
|
instantSearchInstance.sendEventToInsights(args[0]);
|
|
@@ -762,6 +765,7 @@
|
|
|
762
765
|
insightsMethod: 'clickedFilters',
|
|
763
766
|
widgetType: widgetType,
|
|
764
767
|
eventType: eventType,
|
|
768
|
+
eventModifier: eventModifier,
|
|
765
769
|
payload: {
|
|
766
770
|
eventName: eventName,
|
|
767
771
|
index: helper.getIndex(),
|
|
@@ -792,7 +796,7 @@
|
|
|
792
796
|
}
|
|
793
797
|
return chunks;
|
|
794
798
|
}
|
|
795
|
-
|
|
799
|
+
function _buildEventPayloadsForHits(_ref) {
|
|
796
800
|
var index = _ref.index,
|
|
797
801
|
widgetType = _ref.widgetType,
|
|
798
802
|
methodName = _ref.methodName,
|
|
@@ -802,7 +806,10 @@
|
|
|
802
806
|
if (args.length === 1 && _typeof(args[0]) === 'object') {
|
|
803
807
|
return [args[0]];
|
|
804
808
|
}
|
|
805
|
-
var
|
|
809
|
+
var _args$0$split = args[0].split(':'),
|
|
810
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
811
|
+
eventType = _args$0$split2[0],
|
|
812
|
+
eventModifier = _args$0$split2[1];
|
|
806
813
|
var hits = args[1];
|
|
807
814
|
var eventName = args[2];
|
|
808
815
|
if (!hits) {
|
|
@@ -845,7 +852,8 @@
|
|
|
845
852
|
index: index,
|
|
846
853
|
objectIDs: objectIDsByChunk[i]
|
|
847
854
|
},
|
|
848
|
-
hits: batch
|
|
855
|
+
hits: batch,
|
|
856
|
+
eventModifier: eventModifier
|
|
849
857
|
};
|
|
850
858
|
});
|
|
851
859
|
} else if (eventType === 'click') {
|
|
@@ -855,13 +863,14 @@
|
|
|
855
863
|
widgetType: widgetType,
|
|
856
864
|
eventType: eventType,
|
|
857
865
|
payload: {
|
|
858
|
-
eventName: eventName,
|
|
866
|
+
eventName: eventName || 'Hit Clicked',
|
|
859
867
|
index: index,
|
|
860
868
|
queryID: queryID,
|
|
861
869
|
objectIDs: objectIDsByChunk[i],
|
|
862
870
|
positions: positionsByChunk[i]
|
|
863
871
|
},
|
|
864
|
-
hits: batch
|
|
872
|
+
hits: batch,
|
|
873
|
+
eventModifier: eventModifier
|
|
865
874
|
};
|
|
866
875
|
});
|
|
867
876
|
} else if (eventType === 'conversion') {
|
|
@@ -871,27 +880,30 @@
|
|
|
871
880
|
widgetType: widgetType,
|
|
872
881
|
eventType: eventType,
|
|
873
882
|
payload: {
|
|
874
|
-
eventName: eventName,
|
|
883
|
+
eventName: eventName || 'Hit Converted',
|
|
875
884
|
index: index,
|
|
876
885
|
queryID: queryID,
|
|
877
886
|
objectIDs: objectIDsByChunk[i]
|
|
878
887
|
},
|
|
879
|
-
hits: batch
|
|
888
|
+
hits: batch,
|
|
889
|
+
eventModifier: eventModifier
|
|
880
890
|
};
|
|
881
891
|
});
|
|
882
892
|
} else {
|
|
883
893
|
throw new Error("eventType(\"".concat(eventType, "\") is not supported.\n If you want to send a custom payload, you can pass one object: ").concat(methodName, "(customPayload);\n "));
|
|
884
894
|
}
|
|
885
|
-
}
|
|
895
|
+
}
|
|
886
896
|
function createSendEventForHits(_ref2) {
|
|
887
897
|
var instantSearchInstance = _ref2.instantSearchInstance,
|
|
888
898
|
index = _ref2.index,
|
|
889
899
|
widgetType = _ref2.widgetType;
|
|
900
|
+
var sentEvents = {};
|
|
901
|
+
var timer = undefined;
|
|
890
902
|
var sendEventForHits = function sendEventForHits() {
|
|
891
903
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
892
904
|
args[_key] = arguments[_key];
|
|
893
905
|
}
|
|
894
|
-
var payloads =
|
|
906
|
+
var payloads = _buildEventPayloadsForHits({
|
|
895
907
|
widgetType: widgetType,
|
|
896
908
|
index: index,
|
|
897
909
|
methodName: 'sendEvent',
|
|
@@ -899,8 +911,16 @@
|
|
|
899
911
|
instantSearchInstance: instantSearchInstance
|
|
900
912
|
});
|
|
901
913
|
payloads.forEach(function (payload) {
|
|
902
|
-
|
|
914
|
+
if (payload.eventType === 'click' && payload.eventModifier === 'internal' && sentEvents[payload.eventType]) {
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
sentEvents[payload.eventType] = true;
|
|
918
|
+
instantSearchInstance.sendEventToInsights(payload);
|
|
903
919
|
});
|
|
920
|
+
clearTimeout(timer);
|
|
921
|
+
timer = setTimeout(function () {
|
|
922
|
+
sentEvents = {};
|
|
923
|
+
}, 0);
|
|
904
924
|
};
|
|
905
925
|
return sendEventForHits;
|
|
906
926
|
}
|
|
@@ -912,7 +932,7 @@
|
|
|
912
932
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
913
933
|
args[_key2] = arguments[_key2];
|
|
914
934
|
}
|
|
915
|
-
var payloads =
|
|
935
|
+
var payloads = _buildEventPayloadsForHits({
|
|
916
936
|
widgetType: widgetType,
|
|
917
937
|
index: index,
|
|
918
938
|
methodName: 'bindEvent',
|
|
@@ -1426,6 +1446,18 @@
|
|
|
1426
1446
|
return isMiddleClick || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
|
1427
1447
|
}
|
|
1428
1448
|
|
|
1449
|
+
/**
|
|
1450
|
+
* Recurse over all child indices
|
|
1451
|
+
*/
|
|
1452
|
+
function walkIndex(indexWidget, callback) {
|
|
1453
|
+
callback(indexWidget);
|
|
1454
|
+
indexWidget.getWidgets().forEach(function (widget) {
|
|
1455
|
+
if (isIndexWidget(widget)) {
|
|
1456
|
+
walkIndex(widget, callback);
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1429
1461
|
function uniq(array) {
|
|
1430
1462
|
return array.filter(function (value, index, self) {
|
|
1431
1463
|
return self.indexOf(value) === index;
|
|
@@ -1595,13 +1627,14 @@
|
|
|
1595
1627
|
}
|
|
1596
1628
|
function createRenderArgs(instantSearchInstance, parent) {
|
|
1597
1629
|
var results = parent.getResults();
|
|
1630
|
+
var helper = parent.getHelper();
|
|
1598
1631
|
return {
|
|
1599
|
-
helper:
|
|
1632
|
+
helper: helper,
|
|
1600
1633
|
parent: parent,
|
|
1601
1634
|
instantSearchInstance: instantSearchInstance,
|
|
1602
1635
|
results: results,
|
|
1603
1636
|
scopedResults: parent.getScopedResults(),
|
|
1604
|
-
state: results._state,
|
|
1637
|
+
state: results ? results._state : helper.state,
|
|
1605
1638
|
renderState: instantSearchInstance.renderState,
|
|
1606
1639
|
templatesConfig: instantSearchInstance.templatesConfig,
|
|
1607
1640
|
createURL: parent.createURL,
|
|
@@ -2384,7 +2417,7 @@
|
|
|
2384
2417
|
}
|
|
2385
2418
|
if (!_refine) {
|
|
2386
2419
|
_refine = function _refine(facetValue) {
|
|
2387
|
-
sendEvent('click', facetValue);
|
|
2420
|
+
sendEvent('click:internal', facetValue);
|
|
2388
2421
|
helper.toggleFacetRefinement(hierarchicalFacetName, facetValue).search();
|
|
2389
2422
|
};
|
|
2390
2423
|
}
|
|
@@ -2490,7 +2523,7 @@
|
|
|
2490
2523
|
renderFn(_objectSpread2(_objectSpread2({}, renderState), {}, {
|
|
2491
2524
|
instantSearchInstance: renderOptions.instantSearchInstance
|
|
2492
2525
|
}), false);
|
|
2493
|
-
renderState.sendEvent('view', renderState.hits);
|
|
2526
|
+
renderState.sendEvent('view:internal', renderState.hits);
|
|
2494
2527
|
},
|
|
2495
2528
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
2496
2529
|
return _objectSpread2(_objectSpread2({}, renderState), {}, {
|
|
@@ -2667,6 +2700,7 @@
|
|
|
2667
2700
|
|
|
2668
2701
|
var n,l,u,t,o,r,f={},e=[],c=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function s(n,l){for(var u in l)n[u]=l[u];return n}function a(n){var l=n.parentNode;l&&l.removeChild(n);}function h(l,u,i){var t,o,r,f={};for(r in u)"key"==r?t=u[r]:"ref"==r?o=u[r]:f[r]=u[r];if(arguments.length>2&&(f.children=arguments.length>3?n.call(arguments,2):i),"function"==typeof l&&null!=l.defaultProps)for(r in l.defaultProps)void 0===f[r]&&(f[r]=l.defaultProps[r]);return v(l,f,t,o,null)}function v(n,i,t,o,r){var f={type:n,props:i,key:t,ref:o,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==r?++u:r};return null==r&&null!=l.vnode&&l.vnode(f),f}function y(){return {current:null}}function p(n){return n.children}function d(n,l){this.props=n,this.context=l;}function _(n,l){if(null==l)return n.__?_(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?_(n):null}function k(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return k(n)}}function b(n){(!n.__d&&(n.__d=!0)&&t.push(n)&&!g.__r++||o!==l.debounceRendering)&&((o=l.debounceRendering)||setTimeout)(g);}function g(){for(var n;g.__r=t.length;)n=t.sort(function(n,l){return n.__v.__b-l.__v.__b}),t=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=s({},t)).__v=t.__v+1,j(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?_(t):o,t.__h),z(u,t),t.__e!=o&&k(t)));});}function w(n,l,u,i,t,o,r,c,s,a){var h,y,d,k,b,g,w,x=i&&i.__k||e,C=x.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v(null,k,null,null,k):Array.isArray(k)?v(p,{children:k},null,null,null):k.__b>0?v(k.type,k.props,k.key,k.ref?k.ref:null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(d=x[h])||d&&k.key==d.key&&k.type===d.type)x[h]=void 0;else for(y=0;y<C;y++){if((d=x[y])&&k.key==d.key&&k.type===d.type){x[y]=void 0;break}d=null;}j(n,k,d=d||f,t,o,r,c,s,a),b=k.__e,(y=k.ref)&&d.ref!=y&&(w||(w=[]),d.ref&&w.push(d.ref,null,k),w.push(y,k.__c||b,k)),null!=b?(null==g&&(g=b),"function"==typeof k.type&&k.__k===d.__k?k.__d=s=m(k,s,n):s=A(n,k,d,x,b,s),"function"==typeof u.type&&(u.__d=s)):s&&d.__e==s&&s.parentNode!=n&&(s=_(d));}for(u.__e=g,h=C;h--;)null!=x[h]&&("function"==typeof u.type&&null!=x[h].__e&&x[h].__e==u.__d&&(u.__d=_(i,h+1)),N(x[h],x[h]));if(w)for(h=0;h<w.length;h++)M(w[h],w[++h],w[++h]);}function m(n,l,u){for(var i,t=n.__k,o=0;t&&o<t.length;o++)(i=t[o])&&(i.__=n,l="function"==typeof i.type?m(i,l,u):A(u,i,i,t,i.__e,l));return l}function A(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else{for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function C(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||H(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||H(n,o,l[o],u[o],i);}function $(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||c.test(l)?u:u+"px";}function H(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else{if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||$(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||$(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?T:I,o):n.removeEventListener(l,o?T:I,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function I(n){this.l[n.type+!1](l.event?l.event(n):n);}function T(n){this.l[n.type+!0](l.event?l.event(n):n);}function j(n,u,i,t,o,r,f,e,c){var a,h,v,y,_,k,b,g,m,x,A,C,$,H=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(c=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=l.__b)&&a(u);try{n:if("function"==typeof H){if(g=u.props,m=(a=H.contextType)&&t[a.__c],x=a?m?m.props.value:a.__:t,i.__c?b=(h=u.__c=i.__c).__=h.__E:("prototype"in H&&H.prototype.render?u.__c=h=new H(g,x):(u.__c=h=new d(g,x),h.constructor=H,h.render=O),m&&m.sub(h),h.props=g,h.state||(h.state={}),h.context=x,h.__n=t,v=h.__d=!0,h.__h=[]),null==h.__s&&(h.__s=h.state),null!=H.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=s({},h.__s)),s(h.__s,H.getDerivedStateFromProps(g,h.__s))),y=h.props,_=h.state,v)null==H.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(null==H.getDerivedStateFromProps&&g!==y&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(g,x),!h.__e&&null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(g,h.__s,x)||u.__v===i.__v){h.props=g,h.state=h.__s,u.__v!==i.__v&&(h.__d=!1),h.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),h.__h.length&&f.push(h);break n}null!=h.componentWillUpdate&&h.componentWillUpdate(g,h.__s,x),null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(y,_,k);});}if(h.context=x,h.props=g,h.__v=u,h.__P=n,A=l.__r,C=0,"prototype"in H&&H.prototype.render)h.state=h.__s,h.__d=!1,A&&A(u),a=h.render(h.props,h.state,h.context);else do{h.__d=!1,A&&A(u),a=h.render(h.props,h.state,h.context),h.state=h.__s;}while(h.__d&&++C<25);h.state=h.__s,null!=h.getChildContext&&(t=s(s({},t),h.getChildContext())),v||null==h.getSnapshotBeforeUpdate||(k=h.getSnapshotBeforeUpdate(y,_)),$=null!=a&&a.type===p&&null==a.key?a.props.children:a,w(n,Array.isArray($)?$:[$],u,i,t,o,r,f,e,c),h.base=u.__e,u.__h=null,h.__h.length&&f.push(h),b&&(h.__E=h.__=null),h.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=L(i.__e,u,i,t,o,r,f,c);(a=l.diffed)&&a(u);}catch(n){u.__v=null,(c||null!=r)&&(u.__e=e,u.__h=!!c,r[r.indexOf(e)]=null),l.__e(n,u,i);}}function z(n,u){l.__c&&l.__c(u,n),n.some(function(u){try{n=u.__h,u.__h=[],n.some(function(n){n.call(u);});}catch(n){l.__e(n,u.__v);}});}function L(l,u,i,t,o,r,e,c){var s,h,v,y=i.props,p=u.props,d=u.type,k=0;if("svg"===d&&(o=!0),null!=r)for(;k<r.length;k++)if((s=r[k])&&"setAttribute"in s==!!d&&(d?s.localName===d:3===s.nodeType)){l=s,r[k]=null;break}if(null==l){if(null===d)return document.createTextNode(p);l=o?document.createElementNS("http://www.w3.org/2000/svg",d):document.createElement(d,p.is&&p),r=null,c=!1;}if(null===d)y===p||c&&l.data===p||(l.data=p);else{if(r=r&&n.call(l.childNodes),h=(y=i.props||f).dangerouslySetInnerHTML,v=p.dangerouslySetInnerHTML,!c){if(null!=r)for(y={},k=0;k<l.attributes.length;k++)y[l.attributes[k].name]=l.attributes[k].value;(v||h)&&(v&&(h&&v.__html==h.__html||v.__html===l.innerHTML)||(l.innerHTML=v&&v.__html||""));}if(C(l,p,y,o,c),v)u.__k=[];else if(k=u.props.children,w(l,Array.isArray(k)?k:[k],u,i,t,o&&"foreignObject"!==d,r,e,r?r[0]:i.__k&&_(i,0),c),null!=r)for(k=r.length;k--;)null!=r[k]&&a(r[k]);c||("value"in p&&void 0!==(k=p.value)&&(k!==l.value||"progress"===d&&!k||"option"===d&&k!==y.value)&&H(l,"value",k,y.value,!1),"checked"in p&&void 0!==(k=p.checked)&&k!==l.checked&&H(l,"checked",k,y.checked,!1));}return l}function M(n,u,i){try{"function"==typeof n?n(u):n.current=u;}catch(n){l.__e(n,i);}}function N(n,u,i){var t,o;if(l.unmount&&l.unmount(n),(t=n.ref)&&(t.current&&t.current!==n.__e||M(t,null,u)),null!=(t=n.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(n){l.__e(n,u);}t.base=t.__P=null,n.__c=void 0;}if(t=n.__k)for(o=0;o<t.length;o++)t[o]&&N(t[o],u,"function"!=typeof n.type);i||null==n.__e||a(n.__e),n.__=n.__e=n.__d=void 0;}function O(n,l,u){return this.constructor(n,u)}function P(u,i,t){var o,r,e;l.__&&l.__(u,i),r=(o="function"==typeof t)?null:t&&t.__k||i.__k,e=[],j(i,u=(!o&&t||i).__k=h(p,null,[u]),r||f,f,void 0!==i.ownerSVGElement,!o&&t?[t]:r?null:i.firstChild?n.call(i.childNodes):null,e,!o&&t?t:r?r.__e:i.firstChild,o),z(e,u);}n=e.slice,l={__e:function(n,l,u,i){for(var t,o,r;l=l.__;)if((t=l.__c)&&!t.__)try{if((o=t.constructor)&&null!=o.getDerivedStateFromError&&(t.setState(o.getDerivedStateFromError(n)),r=t.__d),null!=t.componentDidCatch&&(t.componentDidCatch(n,i||{}),r=t.__d),r)return t.__E=t}catch(l){n=l;}throw n}},u=0,d.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=s({},this.state),"function"==typeof n&&(n=n(s({},u),this.props)),n&&s(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),b(this));},d.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),b(this));},d.prototype.render=p,t=[],g.__r=0,r=0;
|
|
2669
2702
|
|
|
2703
|
+
/** @deprecated use bindEvent instead */
|
|
2670
2704
|
function readDataAttributes(domElement) {
|
|
2671
2705
|
var method = domElement.getAttribute('data-insights-method');
|
|
2672
2706
|
var serializedPayload = domElement.getAttribute('data-insights-payload');
|
|
@@ -2683,9 +2717,8 @@
|
|
|
2683
2717
|
throw new Error('The insights helper was unable to parse `data-insights-payload`.');
|
|
2684
2718
|
}
|
|
2685
2719
|
}
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
}
|
|
2720
|
+
|
|
2721
|
+
/** @deprecated use bindEvent instead */
|
|
2689
2722
|
function writeDataAttributes(_ref) {
|
|
2690
2723
|
var method = _ref.method,
|
|
2691
2724
|
payload = _ref.payload;
|
|
@@ -2712,7 +2745,34 @@
|
|
|
2712
2745
|
});
|
|
2713
2746
|
}
|
|
2714
2747
|
|
|
2715
|
-
var
|
|
2748
|
+
var createInsightsEventHandler = function createInsightsEventHandler(_ref) {
|
|
2749
|
+
var insights = _ref.insights,
|
|
2750
|
+
sendEvent = _ref.sendEvent;
|
|
2751
|
+
return function (event) {
|
|
2752
|
+
// new way, e.g. bindEvent("click", hit, "Hit clicked")
|
|
2753
|
+
var insightsThroughSendEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
2754
|
+
return element.hasAttribute('data-insights-event');
|
|
2755
|
+
});
|
|
2756
|
+
if (insightsThroughSendEvent) {
|
|
2757
|
+
var payload = parseInsightsEvent(insightsThroughSendEvent);
|
|
2758
|
+
payload.forEach(function (single) {
|
|
2759
|
+
return sendEvent(single);
|
|
2760
|
+
});
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
|
|
2764
|
+
var insightsThroughFunction = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
2765
|
+
return element.hasAttribute('data-insights-method') && element.hasAttribute('data-insights-payload');
|
|
2766
|
+
});
|
|
2767
|
+
if (insightsThroughFunction) {
|
|
2768
|
+
var _readDataAttributes = readDataAttributes(insightsThroughFunction),
|
|
2769
|
+
method = _readDataAttributes.method,
|
|
2770
|
+
_payload = _readDataAttributes.payload;
|
|
2771
|
+
insights(method, _payload);
|
|
2772
|
+
}
|
|
2773
|
+
};
|
|
2774
|
+
};
|
|
2775
|
+
function findInsightsTarget(startElement, endElement, validator) {
|
|
2716
2776
|
var element = startElement;
|
|
2717
2777
|
while (element && !validator(element)) {
|
|
2718
2778
|
if (element === endElement) {
|
|
@@ -2721,8 +2781,8 @@
|
|
|
2721
2781
|
element = element.parentElement;
|
|
2722
2782
|
}
|
|
2723
2783
|
return element;
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2784
|
+
}
|
|
2785
|
+
function parseInsightsEvent(element) {
|
|
2726
2786
|
var serializedPayload = element.getAttribute('data-insights-event');
|
|
2727
2787
|
if (typeof serializedPayload !== 'string') {
|
|
2728
2788
|
throw new Error('The insights middleware expects `data-insights-event` to be a base64-encoded JSON string.');
|
|
@@ -2732,40 +2792,7 @@
|
|
|
2732
2792
|
} catch (error) {
|
|
2733
2793
|
throw new Error('The insights middleware was unable to parse `data-insights-event`.');
|
|
2734
2794
|
}
|
|
2735
|
-
}
|
|
2736
|
-
var insightsListener = function insightsListener(BaseComponent) {
|
|
2737
|
-
function WithInsightsListener(props) {
|
|
2738
|
-
var handleClick = function handleClick(event) {
|
|
2739
|
-
if (props.sendEvent) {
|
|
2740
|
-
// new way with insights middleware
|
|
2741
|
-
var targetWithEvent = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
2742
|
-
return element.hasAttribute('data-insights-event');
|
|
2743
|
-
});
|
|
2744
|
-
if (targetWithEvent) {
|
|
2745
|
-
var payload = parseInsightsEvent(targetWithEvent);
|
|
2746
|
-
payload.forEach(function (single) {
|
|
2747
|
-
return props.sendEvent(single);
|
|
2748
|
-
});
|
|
2749
|
-
}
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
// old way, e.g. instantsearch.insights("clickedObjectIDsAfterSearch", { .. })
|
|
2753
|
-
var insightsTarget = findInsightsTarget(event.target, event.currentTarget, function (element) {
|
|
2754
|
-
return hasDataAttributes(element);
|
|
2755
|
-
});
|
|
2756
|
-
if (insightsTarget) {
|
|
2757
|
-
var _readDataAttributes = readDataAttributes(insightsTarget),
|
|
2758
|
-
method = _readDataAttributes.method,
|
|
2759
|
-
_payload = _readDataAttributes.payload;
|
|
2760
|
-
props.insights(method, _payload);
|
|
2761
|
-
}
|
|
2762
|
-
};
|
|
2763
|
-
return h("div", {
|
|
2764
|
-
onClick: handleClick
|
|
2765
|
-
}, h(BaseComponent, props));
|
|
2766
|
-
}
|
|
2767
|
-
return WithInsightsListener;
|
|
2768
|
-
};
|
|
2795
|
+
}
|
|
2769
2796
|
|
|
2770
2797
|
var connectHitsWithInsights = withInsights(connectHits);
|
|
2771
2798
|
|
|
@@ -2897,7 +2924,8 @@
|
|
|
2897
2924
|
};
|
|
2898
2925
|
};
|
|
2899
2926
|
|
|
2900
|
-
var _excluded$2 = ["page"]
|
|
2927
|
+
var _excluded$2 = ["page"],
|
|
2928
|
+
_excluded2 = ["clickAnalytics", "userToken"];
|
|
2901
2929
|
var withUsage$7 = createDocumentationMessageGenerator({
|
|
2902
2930
|
name: 'infinite-hits',
|
|
2903
2931
|
connector: true
|
|
@@ -2908,17 +2936,24 @@
|
|
|
2908
2936
|
rest = _objectWithoutProperties(_ref, _excluded$2);
|
|
2909
2937
|
return rest;
|
|
2910
2938
|
}
|
|
2939
|
+
function normalizeState(state) {
|
|
2940
|
+
var _ref2 = state || {},
|
|
2941
|
+
clickAnalytics = _ref2.clickAnalytics,
|
|
2942
|
+
userToken = _ref2.userToken,
|
|
2943
|
+
rest = _objectWithoutProperties(_ref2, _excluded2);
|
|
2944
|
+
return rest;
|
|
2945
|
+
}
|
|
2911
2946
|
function getInMemoryCache() {
|
|
2912
2947
|
var cachedHits = null;
|
|
2913
2948
|
var cachedState = null;
|
|
2914
2949
|
return {
|
|
2915
|
-
read: function read(
|
|
2916
|
-
var state =
|
|
2950
|
+
read: function read(_ref3) {
|
|
2951
|
+
var state = _ref3.state;
|
|
2917
2952
|
return isEqual(cachedState, getStateWithoutPage(state)) ? cachedHits : null;
|
|
2918
2953
|
},
|
|
2919
|
-
write: function write(
|
|
2920
|
-
var state =
|
|
2921
|
-
hits =
|
|
2954
|
+
write: function write(_ref4) {
|
|
2955
|
+
var state = _ref4.state,
|
|
2956
|
+
hits = _ref4.hits;
|
|
2922
2957
|
cachedState = getStateWithoutPage(state);
|
|
2923
2958
|
cachedHits = hits;
|
|
2924
2959
|
}
|
|
@@ -2938,15 +2973,15 @@
|
|
|
2938
2973
|
// @TODO: this should be a generic, but a Connector can not yet be generic itself
|
|
2939
2974
|
|
|
2940
2975
|
return function (widgetParams) {
|
|
2941
|
-
var
|
|
2942
|
-
|
|
2943
|
-
escapeHTML =
|
|
2944
|
-
|
|
2945
|
-
transformItems =
|
|
2976
|
+
var _ref5 = widgetParams || {},
|
|
2977
|
+
_ref5$escapeHTML = _ref5.escapeHTML,
|
|
2978
|
+
escapeHTML = _ref5$escapeHTML === void 0 ? true : _ref5$escapeHTML,
|
|
2979
|
+
_ref5$transformItems = _ref5.transformItems,
|
|
2980
|
+
transformItems = _ref5$transformItems === void 0 ? function (items) {
|
|
2946
2981
|
return items;
|
|
2947
|
-
} :
|
|
2948
|
-
|
|
2949
|
-
cache =
|
|
2982
|
+
} : _ref5$transformItems,
|
|
2983
|
+
_ref5$cache = _ref5.cache,
|
|
2984
|
+
cache = _ref5$cache === void 0 ? getInMemoryCache() : _ref5$cache;
|
|
2950
2985
|
var showPrevious;
|
|
2951
2986
|
var showMore;
|
|
2952
2987
|
var sendEvent;
|
|
@@ -2977,7 +3012,7 @@
|
|
|
2977
3012
|
// avoid updating the browser URL when the user displays the previous page.
|
|
2978
3013
|
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
2979
3014
|
page: getFirstReceivedPage(helper.state, cache.read({
|
|
2980
|
-
state: helper.state
|
|
3015
|
+
state: normalizeState(helper.state)
|
|
2981
3016
|
}) || {}) - 1
|
|
2982
3017
|
})).searchWithoutTriggeringOnStateChange();
|
|
2983
3018
|
};
|
|
@@ -2985,7 +3020,7 @@
|
|
|
2985
3020
|
var getShowMore = function getShowMore(helper) {
|
|
2986
3021
|
return function () {
|
|
2987
3022
|
helper.setPage(getLastReceivedPage(helper.state, cache.read({
|
|
2988
|
-
state: helper.state
|
|
3023
|
+
state: normalizeState(helper.state)
|
|
2989
3024
|
}) || {}) + 1).search();
|
|
2990
3025
|
};
|
|
2991
3026
|
};
|
|
@@ -3002,19 +3037,19 @@
|
|
|
3002
3037
|
renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
|
|
3003
3038
|
instantSearchInstance: instantSearchInstance
|
|
3004
3039
|
}), false);
|
|
3005
|
-
sendEvent('view', widgetRenderState.currentPageHits);
|
|
3040
|
+
sendEvent('view:internal', widgetRenderState.currentPageHits);
|
|
3006
3041
|
},
|
|
3007
3042
|
getRenderState: function getRenderState(renderState, renderOptions) {
|
|
3008
3043
|
return _objectSpread2(_objectSpread2({}, renderState), {}, {
|
|
3009
3044
|
infiniteHits: this.getWidgetRenderState(renderOptions)
|
|
3010
3045
|
});
|
|
3011
3046
|
},
|
|
3012
|
-
getWidgetRenderState: function getWidgetRenderState(
|
|
3013
|
-
var results =
|
|
3014
|
-
helper =
|
|
3015
|
-
parent =
|
|
3016
|
-
existingState =
|
|
3017
|
-
instantSearchInstance =
|
|
3047
|
+
getWidgetRenderState: function getWidgetRenderState(_ref6) {
|
|
3048
|
+
var results = _ref6.results,
|
|
3049
|
+
helper = _ref6.helper,
|
|
3050
|
+
parent = _ref6.parent,
|
|
3051
|
+
existingState = _ref6.state,
|
|
3052
|
+
instantSearchInstance = _ref6.instantSearchInstance;
|
|
3018
3053
|
var isFirstPage;
|
|
3019
3054
|
var currentPageHits = [];
|
|
3020
3055
|
/**
|
|
@@ -3024,7 +3059,7 @@
|
|
|
3024
3059
|
*/
|
|
3025
3060
|
var state = parent.getPreviousState() || existingState;
|
|
3026
3061
|
var cachedHits = cache.read({
|
|
3027
|
-
state: state
|
|
3062
|
+
state: normalizeState(state)
|
|
3028
3063
|
}) || {};
|
|
3029
3064
|
if (!results) {
|
|
3030
3065
|
showPrevious = getShowPrevious(helper);
|
|
@@ -3041,6 +3076,7 @@
|
|
|
3041
3076
|
});
|
|
3042
3077
|
isFirstPage = state.page === undefined || getFirstReceivedPage(state, cachedHits) === 0;
|
|
3043
3078
|
} else {
|
|
3079
|
+
var _results$disjunctiveF, _results$facets, _results$hierarchical;
|
|
3044
3080
|
var _state$page3 = state.page,
|
|
3045
3081
|
_page = _state$page3 === void 0 ? 0 : _state$page3;
|
|
3046
3082
|
if (escapeHTML && results.hits.length > 0) {
|
|
@@ -3051,10 +3087,24 @@
|
|
|
3051
3087
|
var transformedHits = transformItems(hitsWithAbsolutePositionAndQueryID, {
|
|
3052
3088
|
results: results
|
|
3053
3089
|
});
|
|
3054
|
-
|
|
3090
|
+
|
|
3091
|
+
/*
|
|
3092
|
+
With dynamic widgets, facets are not included in the state before their relevant widgets are mounted. Until then, we need to bail out of writing this incomplete state representation in cache.
|
|
3093
|
+
*/
|
|
3094
|
+
var hasDynamicWidgets = false;
|
|
3095
|
+
walkIndex(instantSearchInstance.mainIndex, function (indexWidget) {
|
|
3096
|
+
if (!hasDynamicWidgets && indexWidget.getWidgets().some(function (_ref7) {
|
|
3097
|
+
var $$type = _ref7.$$type;
|
|
3098
|
+
return $$type === 'ais.dynamicWidgets';
|
|
3099
|
+
})) {
|
|
3100
|
+
hasDynamicWidgets = true;
|
|
3101
|
+
}
|
|
3102
|
+
});
|
|
3103
|
+
var hasNoFacets = !((_results$disjunctiveF = results.disjunctiveFacets) !== null && _results$disjunctiveF !== void 0 && _results$disjunctiveF.length) && !((_results$facets = results.facets) !== null && _results$facets !== void 0 && _results$facets.length) && !((_results$hierarchical = results.hierarchicalFacets) !== null && _results$hierarchical !== void 0 && _results$hierarchical.length);
|
|
3104
|
+
if (cachedHits[_page] === undefined && !results.__isArtificial && instantSearchInstance.status === 'idle' && !(hasDynamicWidgets && hasNoFacets)) {
|
|
3055
3105
|
cachedHits[_page] = transformedHits;
|
|
3056
3106
|
cache.write({
|
|
3057
|
-
state: state,
|
|
3107
|
+
state: normalizeState(state),
|
|
3058
3108
|
hits: cachedHits
|
|
3059
3109
|
});
|
|
3060
3110
|
}
|
|
@@ -3076,8 +3126,8 @@
|
|
|
3076
3126
|
widgetParams: widgetParams
|
|
3077
3127
|
};
|
|
3078
3128
|
},
|
|
3079
|
-
dispose: function dispose(
|
|
3080
|
-
var state =
|
|
3129
|
+
dispose: function dispose(_ref8) {
|
|
3130
|
+
var state = _ref8.state;
|
|
3081
3131
|
unmountFn();
|
|
3082
3132
|
var stateWithoutPage = state.setQueryParameter('page', undefined);
|
|
3083
3133
|
if (!escapeHTML) {
|
|
@@ -3087,8 +3137,8 @@
|
|
|
3087
3137
|
return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, undefined));
|
|
3088
3138
|
}, {}));
|
|
3089
3139
|
},
|
|
3090
|
-
getWidgetUiState: function getWidgetUiState(uiState,
|
|
3091
|
-
var searchParameters =
|
|
3140
|
+
getWidgetUiState: function getWidgetUiState(uiState, _ref9) {
|
|
3141
|
+
var searchParameters = _ref9.searchParameters;
|
|
3092
3142
|
var page = searchParameters.page || 0;
|
|
3093
3143
|
if (!page) {
|
|
3094
3144
|
// return without adding `page` to uiState
|
|
@@ -3101,8 +3151,8 @@
|
|
|
3101
3151
|
page: page + 1
|
|
3102
3152
|
});
|
|
3103
3153
|
},
|
|
3104
|
-
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters,
|
|
3105
|
-
var uiState =
|
|
3154
|
+
getWidgetSearchParameters: function getWidgetSearchParameters(searchParameters, _ref10) {
|
|
3155
|
+
var uiState = _ref10.uiState;
|
|
3106
3156
|
var widgetSearchParameters = searchParameters;
|
|
3107
3157
|
if (escapeHTML) {
|
|
3108
3158
|
widgetSearchParameters = searchParameters.setQueryParameters(TAG_PLACEHOLDER);
|
|
@@ -3227,7 +3277,7 @@
|
|
|
3227
3277
|
var _helper$getHierarchic = helper.getHierarchicalFacetBreadcrumb(attribute),
|
|
3228
3278
|
_helper$getHierarchic2 = _slicedToArray(_helper$getHierarchic, 1),
|
|
3229
3279
|
refinedItem = _helper$getHierarchic2[0];
|
|
3230
|
-
sendEvent('click', facetValue ? facetValue : refinedItem);
|
|
3280
|
+
sendEvent('click:internal', facetValue ? facetValue : refinedItem);
|
|
3231
3281
|
helper.toggleFacetRefinement(attribute, facetValue ? facetValue : refinedItem).search();
|
|
3232
3282
|
};
|
|
3233
3283
|
}
|
|
@@ -3428,7 +3478,7 @@
|
|
|
3428
3478
|
if (!connectorState.refine) {
|
|
3429
3479
|
connectorState.refine = function (facetValue) {
|
|
3430
3480
|
var refinedState = getRefinedState(helper.state, attribute, facetValue);
|
|
3431
|
-
connectorState.sendEvent('click', facetValue);
|
|
3481
|
+
connectorState.sendEvent('click:internal', facetValue);
|
|
3432
3482
|
helper.setState(refinedState).search();
|
|
3433
3483
|
};
|
|
3434
3484
|
}
|
|
@@ -3992,7 +4042,7 @@
|
|
|
3992
4042
|
};
|
|
3993
4043
|
|
|
3994
4044
|
var _excluded$4 = ["name", "escapedValue"],
|
|
3995
|
-
_excluded2 = ["escapedValue", "value"];
|
|
4045
|
+
_excluded2$1 = ["escapedValue", "value"];
|
|
3996
4046
|
var withUsage$c = createDocumentationMessageGenerator({
|
|
3997
4047
|
name: 'refinement-list',
|
|
3998
4048
|
connector: true
|
|
@@ -4101,7 +4151,7 @@
|
|
|
4101
4151
|
var normalizedFacetValues = transformItems(facetValues.map(function (_ref3) {
|
|
4102
4152
|
var escapedValue = _ref3.escapedValue,
|
|
4103
4153
|
value = _ref3.value,
|
|
4104
|
-
item = _objectWithoutProperties(_ref3, _excluded2);
|
|
4154
|
+
item = _objectWithoutProperties(_ref3, _excluded2$1);
|
|
4105
4155
|
return _objectSpread2(_objectSpread2({}, item), {}, {
|
|
4106
4156
|
value: escapedValue,
|
|
4107
4157
|
label: value
|
|
@@ -4156,7 +4206,7 @@
|
|
|
4156
4206
|
widgetType: this.$$type
|
|
4157
4207
|
});
|
|
4158
4208
|
triggerRefine = function triggerRefine(facetValue) {
|
|
4159
|
-
sendEvent('click', facetValue);
|
|
4209
|
+
sendEvent('click:internal', facetValue);
|
|
4160
4210
|
helper.toggleFacetRefinement(attribute, facetValue).search();
|
|
4161
4211
|
};
|
|
4162
4212
|
searchForFacetValues = createSearchForFacetValues(helper, this);
|
|
@@ -4459,10 +4509,13 @@
|
|
|
4459
4509
|
instantSearchInstance.sendEventToInsights(args[0]);
|
|
4460
4510
|
return;
|
|
4461
4511
|
}
|
|
4462
|
-
var
|
|
4463
|
-
facetValue = args[1],
|
|
4512
|
+
var facetValue = args[1],
|
|
4464
4513
|
_args$ = args[2],
|
|
4465
4514
|
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
4515
|
+
var _args$0$split = args[0].split(':'),
|
|
4516
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
4517
|
+
eventType = _args$0$split2[0],
|
|
4518
|
+
eventModifier = _args$0$split2[1];
|
|
4466
4519
|
if (eventType !== 'click') {
|
|
4467
4520
|
return;
|
|
4468
4521
|
}
|
|
@@ -4472,6 +4525,7 @@
|
|
|
4472
4525
|
insightsMethod: 'clickedFilters',
|
|
4473
4526
|
widgetType: $$type$2,
|
|
4474
4527
|
eventType: eventType,
|
|
4528
|
+
eventModifier: eventModifier,
|
|
4475
4529
|
payload: {
|
|
4476
4530
|
eventName: eventName,
|
|
4477
4531
|
index: helper.getIndex(),
|
|
@@ -4547,7 +4601,7 @@
|
|
|
4547
4601
|
return emptyState;
|
|
4548
4602
|
}
|
|
4549
4603
|
var toggleRefinement = function toggleRefinement(helper, facetValue) {
|
|
4550
|
-
sendEvent('click', facetValue);
|
|
4604
|
+
sendEvent('click:internal', facetValue);
|
|
4551
4605
|
helper.setState(getRefinedState(helper.state, facetValue)).search();
|
|
4552
4606
|
};
|
|
4553
4607
|
var connectorState = {
|
|
@@ -4776,10 +4830,13 @@
|
|
|
4776
4830
|
instantSearchInstance.sendEventToInsights(args[0]);
|
|
4777
4831
|
return;
|
|
4778
4832
|
}
|
|
4779
|
-
var
|
|
4780
|
-
isRefined = args[1],
|
|
4833
|
+
var isRefined = args[1],
|
|
4781
4834
|
_args$ = args[2],
|
|
4782
4835
|
eventName = _args$ === void 0 ? 'Filter Applied' : _args$;
|
|
4836
|
+
var _args$0$split = args[0].split(':'),
|
|
4837
|
+
_args$0$split2 = _slicedToArray(_args$0$split, 2),
|
|
4838
|
+
eventType = _args$0$split2[0],
|
|
4839
|
+
eventModifier = _args$0$split2[1];
|
|
4783
4840
|
if (eventType !== 'click' || on === undefined) {
|
|
4784
4841
|
return;
|
|
4785
4842
|
}
|
|
@@ -4791,6 +4848,7 @@
|
|
|
4791
4848
|
insightsMethod: 'clickedFilters',
|
|
4792
4849
|
widgetType: $$type$3,
|
|
4793
4850
|
eventType: eventType,
|
|
4851
|
+
eventModifier: eventModifier,
|
|
4794
4852
|
payload: {
|
|
4795
4853
|
eventName: eventName,
|
|
4796
4854
|
index: helper.getIndex(),
|
|
@@ -4837,7 +4895,7 @@
|
|
|
4837
4895
|
},
|
|
4838
4896
|
isRefined = _ref3.isRefined;
|
|
4839
4897
|
if (!isRefined) {
|
|
4840
|
-
sendEvent('click', isRefined);
|
|
4898
|
+
sendEvent('click:internal', isRefined);
|
|
4841
4899
|
if (hasAnOffValue) {
|
|
4842
4900
|
off.forEach(function (v) {
|
|
4843
4901
|
return helper.removeDisjunctiveFacetRefinement(attribute, v);
|
|
@@ -5298,7 +5356,7 @@
|
|
|
5298
5356
|
widgetState.internalToggleRefineOnMapMove = createInternalToggleRefinementOnMapMove(renderArgs, this.render.bind(this));
|
|
5299
5357
|
widgetState.internalSetMapMoveSinceLastRefine = createInternalSetMapMoveSinceLastRefine(renderArgs, this.render.bind(this));
|
|
5300
5358
|
var widgetRenderState = this.getWidgetRenderState(renderArgs);
|
|
5301
|
-
sendEvent('view', widgetRenderState.items);
|
|
5359
|
+
sendEvent('view:internal', widgetRenderState.items);
|
|
5302
5360
|
renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
|
|
5303
5361
|
instantSearchInstance: instantSearchInstance
|
|
5304
5362
|
}), isFirstRendering);
|
|
@@ -9379,7 +9437,7 @@
|
|
|
9379
9437
|
|
|
9380
9438
|
var requestBuilder_1 = requestBuilder;
|
|
9381
9439
|
|
|
9382
|
-
var version = '3.
|
|
9440
|
+
var version = '3.13.0';
|
|
9383
9441
|
|
|
9384
9442
|
var escapeFacetValue$4 = escapeFacetValue_1.escapeFacetValue;
|
|
9385
9443
|
|
|
@@ -10645,7 +10703,9 @@
|
|
|
10645
10703
|
|
|
10646
10704
|
var derivedQueries = this.derivedHelpers.map(function(derivedHelper) {
|
|
10647
10705
|
var derivedState = derivedHelper.getModifiedState(state);
|
|
10648
|
-
var derivedStateQueries =
|
|
10706
|
+
var derivedStateQueries = derivedState.index
|
|
10707
|
+
? requestBuilder_1._getQueries(derivedState.index, derivedState)
|
|
10708
|
+
: [];
|
|
10649
10709
|
|
|
10650
10710
|
states.push({
|
|
10651
10711
|
state: derivedState,
|
|
@@ -10662,10 +10722,16 @@
|
|
|
10662
10722
|
});
|
|
10663
10723
|
|
|
10664
10724
|
var queries = Array.prototype.concat.apply(mainQueries, derivedQueries);
|
|
10665
|
-
var queryId = this._queryId++;
|
|
10666
10725
|
|
|
10726
|
+
var queryId = this._queryId++;
|
|
10667
10727
|
this._currentNbQueries++;
|
|
10668
10728
|
|
|
10729
|
+
if (!queries.length) {
|
|
10730
|
+
return Promise.resolve({results: []}).then(
|
|
10731
|
+
this._dispatchAlgoliaResponse.bind(this, states, queryId)
|
|
10732
|
+
);
|
|
10733
|
+
}
|
|
10734
|
+
|
|
10669
10735
|
try {
|
|
10670
10736
|
this.client.search(queries)
|
|
10671
10737
|
.then(this._dispatchAlgoliaResponse.bind(this, states, queryId))
|
|
@@ -10710,6 +10776,14 @@
|
|
|
10710
10776
|
var helper = s.helper;
|
|
10711
10777
|
var specificResults = results.splice(0, queriesCount);
|
|
10712
10778
|
|
|
10779
|
+
if (!state.index) {
|
|
10780
|
+
helper.emit('result', {
|
|
10781
|
+
results: null,
|
|
10782
|
+
state: state
|
|
10783
|
+
});
|
|
10784
|
+
return;
|
|
10785
|
+
}
|
|
10786
|
+
|
|
10713
10787
|
var formattedResponse = helper.lastResults = new SearchResults_1(state, specificResults);
|
|
10714
10788
|
|
|
10715
10789
|
helper.emit('result', {
|
|
@@ -11109,7 +11183,7 @@
|
|
|
11109
11183
|
renderState.indices.forEach(function (_ref3) {
|
|
11110
11184
|
var sendEvent = _ref3.sendEvent,
|
|
11111
11185
|
hits = _ref3.hits;
|
|
11112
|
-
sendEvent('view', hits);
|
|
11186
|
+
sendEvent('view:internal', hits);
|
|
11113
11187
|
});
|
|
11114
11188
|
renderFn(_objectSpread2(_objectSpread2({}, renderState), {}, {
|
|
11115
11189
|
instantSearchInstance: instantSearchInstance
|
|
@@ -11899,7 +11973,231 @@
|
|
|
11899
11973
|
};
|
|
11900
11974
|
}
|
|
11901
11975
|
|
|
11902
|
-
|
|
11976
|
+
var ALGOLIA_INSIGHTS_VERSION = '2.6.0';
|
|
11977
|
+
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@".concat(ALGOLIA_INSIGHTS_VERSION, "/dist/search-insights.min.js");
|
|
11978
|
+
function createInsightsMiddleware() {
|
|
11979
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11980
|
+
var _insightsClient = props.insightsClient,
|
|
11981
|
+
insightsInitParams = props.insightsInitParams,
|
|
11982
|
+
onEvent = props.onEvent,
|
|
11983
|
+
_props$$$internal = props.$$internal,
|
|
11984
|
+
$$internal = _props$$$internal === void 0 ? false : _props$$$internal;
|
|
11985
|
+
var potentialInsightsClient = _insightsClient;
|
|
11986
|
+
if (!_insightsClient && _insightsClient !== null) {
|
|
11987
|
+
safelyRunOnBrowser(function (_ref) {
|
|
11988
|
+
var window = _ref.window;
|
|
11989
|
+
var pointer = window.AlgoliaAnalyticsObject || 'aa';
|
|
11990
|
+
if (typeof pointer === 'string') {
|
|
11991
|
+
potentialInsightsClient = window[pointer];
|
|
11992
|
+
}
|
|
11993
|
+
if (!potentialInsightsClient) {
|
|
11994
|
+
window.AlgoliaAnalyticsObject = pointer;
|
|
11995
|
+
if (!window[pointer]) {
|
|
11996
|
+
window[pointer] = function () {
|
|
11997
|
+
if (!window[pointer].queue) {
|
|
11998
|
+
window[pointer].queue = [];
|
|
11999
|
+
}
|
|
12000
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12001
|
+
args[_key] = arguments[_key];
|
|
12002
|
+
}
|
|
12003
|
+
window[pointer].queue.push(args);
|
|
12004
|
+
};
|
|
12005
|
+
window[pointer].version = ALGOLIA_INSIGHTS_VERSION;
|
|
12006
|
+
window[pointer].shouldAddScript = true;
|
|
12007
|
+
}
|
|
12008
|
+
potentialInsightsClient = window[pointer];
|
|
12009
|
+
}
|
|
12010
|
+
});
|
|
12011
|
+
}
|
|
12012
|
+
// if still no insightsClient was found, we use a noop
|
|
12013
|
+
var insightsClient = potentialInsightsClient || noop;
|
|
12014
|
+
return function (_ref2) {
|
|
12015
|
+
var instantSearchInstance = _ref2.instantSearchInstance;
|
|
12016
|
+
// remove existing default insights middleware
|
|
12017
|
+
// user-provided insights middleware takes precedence
|
|
12018
|
+
var existingInsightsMiddlewares = instantSearchInstance.middleware.filter(function (m) {
|
|
12019
|
+
return m.instance.$$type === 'ais.insights' && m.instance.$$internal;
|
|
12020
|
+
}).map(function (m) {
|
|
12021
|
+
return m.creator;
|
|
12022
|
+
});
|
|
12023
|
+
instantSearchInstance.unuse.apply(instantSearchInstance, _toConsumableArray(existingInsightsMiddlewares));
|
|
12024
|
+
var _getAppIdAndApiKey = getAppIdAndApiKey(instantSearchInstance.client),
|
|
12025
|
+
_getAppIdAndApiKey2 = _slicedToArray(_getAppIdAndApiKey, 2),
|
|
12026
|
+
appId = _getAppIdAndApiKey2[0],
|
|
12027
|
+
apiKey = _getAppIdAndApiKey2[1];
|
|
12028
|
+
|
|
12029
|
+
// search-insights.js also throws an error so dev-only clarification is sufficient
|
|
12030
|
+
_warning(Boolean(appId && apiKey), 'could not extract Algolia credentials from searchClient in insights middleware.') ;
|
|
12031
|
+
var queuedUserToken = undefined;
|
|
12032
|
+
var userTokenBeforeInit = undefined;
|
|
12033
|
+
if (Array.isArray(insightsClient.queue)) {
|
|
12034
|
+
// Context: The umd build of search-insights is asynchronously loaded by the snippet.
|
|
12035
|
+
//
|
|
12036
|
+
// When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
|
|
12037
|
+
// ['setUserToken', 'my-user-token'] gets stored in `aa.queue`.
|
|
12038
|
+
// Whenever `search-insights` is finally loaded, it will process the queue.
|
|
12039
|
+
//
|
|
12040
|
+
// But here's the reason why we handle it here:
|
|
12041
|
+
// At this point, even though `search-insights` is not loaded yet,
|
|
12042
|
+
// we still want to read the token from the queue.
|
|
12043
|
+
// Otherwise, the first search call will be fired without the token.
|
|
12044
|
+
var _ref3 = find(insightsClient.queue.slice().reverse(), function (_ref5) {
|
|
12045
|
+
var _ref6 = _slicedToArray(_ref5, 1),
|
|
12046
|
+
method = _ref6[0];
|
|
12047
|
+
return method === 'setUserToken';
|
|
12048
|
+
}) || [];
|
|
12049
|
+
var _ref4 = _slicedToArray(_ref3, 2);
|
|
12050
|
+
queuedUserToken = _ref4[1];
|
|
12051
|
+
}
|
|
12052
|
+
insightsClient('getUserToken', null, function (_error, userToken) {
|
|
12053
|
+
// If user has called `aa('setUserToken', 'my-user-token')` before creating
|
|
12054
|
+
// the `insights` middleware, we store them temporarily and
|
|
12055
|
+
// set it later on.
|
|
12056
|
+
//
|
|
12057
|
+
// Otherwise, the `init` call might override it with anonymous user token.
|
|
12058
|
+
userTokenBeforeInit = userToken;
|
|
12059
|
+
});
|
|
12060
|
+
|
|
12061
|
+
// Only `init` if the `insightsInitParams` option is passed or
|
|
12062
|
+
// if the `insightsClient` version doesn't supports optional `init` calling.
|
|
12063
|
+
if (insightsInitParams || !isModernInsightsClient(insightsClient)) {
|
|
12064
|
+
insightsClient('init', _objectSpread2({
|
|
12065
|
+
appId: appId,
|
|
12066
|
+
apiKey: apiKey,
|
|
12067
|
+
partial: true
|
|
12068
|
+
}, insightsInitParams));
|
|
12069
|
+
}
|
|
12070
|
+
var initialParameters;
|
|
12071
|
+
var helper;
|
|
12072
|
+
return {
|
|
12073
|
+
$$type: 'ais.insights',
|
|
12074
|
+
$$internal: $$internal,
|
|
12075
|
+
onStateChange: function onStateChange() {},
|
|
12076
|
+
subscribe: function subscribe() {
|
|
12077
|
+
if (!insightsClient.shouldAddScript) return;
|
|
12078
|
+
var errorMessage = '[insights middleware]: could not load search-insights.js. Please load it manually following https://alg.li/insights-init';
|
|
12079
|
+
try {
|
|
12080
|
+
var script = document.createElement('script');
|
|
12081
|
+
script.async = true;
|
|
12082
|
+
script.src = ALGOLIA_INSIGHTS_SRC;
|
|
12083
|
+
script.onerror = function () {
|
|
12084
|
+
instantSearchInstance.emit('error', new Error(errorMessage));
|
|
12085
|
+
};
|
|
12086
|
+
document.body.appendChild(script);
|
|
12087
|
+
insightsClient.shouldAddScript = false;
|
|
12088
|
+
} catch (cause) {
|
|
12089
|
+
insightsClient.shouldAddScript = false;
|
|
12090
|
+
instantSearchInstance.emit('error', new Error(errorMessage));
|
|
12091
|
+
}
|
|
12092
|
+
},
|
|
12093
|
+
started: function started() {
|
|
12094
|
+
insightsClient('addAlgoliaAgent', 'insights-middleware');
|
|
12095
|
+
helper = instantSearchInstance.helper;
|
|
12096
|
+
initialParameters = {
|
|
12097
|
+
userToken: helper.state.userToken,
|
|
12098
|
+
clickAnalytics: helper.state.clickAnalytics
|
|
12099
|
+
};
|
|
12100
|
+
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
12101
|
+
clickAnalytics: true
|
|
12102
|
+
}));
|
|
12103
|
+
if (!$$internal) {
|
|
12104
|
+
instantSearchInstance.scheduleSearch();
|
|
12105
|
+
}
|
|
12106
|
+
var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
|
|
12107
|
+
if (!userToken) {
|
|
12108
|
+
return;
|
|
12109
|
+
}
|
|
12110
|
+
var existingToken = helper.state.userToken;
|
|
12111
|
+
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
12112
|
+
userToken: userToken
|
|
12113
|
+
}));
|
|
12114
|
+
if (existingToken && existingToken !== userToken) {
|
|
12115
|
+
instantSearchInstance.scheduleSearch();
|
|
12116
|
+
}
|
|
12117
|
+
};
|
|
12118
|
+
var anonymousUserToken = getInsightsAnonymousUserTokenInternal();
|
|
12119
|
+
if (anonymousUserToken) {
|
|
12120
|
+
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
12121
|
+
// We can set it as userToken.
|
|
12122
|
+
setUserTokenToSearch(anonymousUserToken);
|
|
12123
|
+
}
|
|
12124
|
+
|
|
12125
|
+
// We consider the `userToken` coming from a `init` call to have a higher
|
|
12126
|
+
// importance than the one coming from the queue.
|
|
12127
|
+
if (userTokenBeforeInit) {
|
|
12128
|
+
setUserTokenToSearch(userTokenBeforeInit);
|
|
12129
|
+
insightsClient('setUserToken', userTokenBeforeInit);
|
|
12130
|
+
} else if (queuedUserToken) {
|
|
12131
|
+
setUserTokenToSearch(queuedUserToken);
|
|
12132
|
+
insightsClient('setUserToken', queuedUserToken);
|
|
12133
|
+
}
|
|
12134
|
+
|
|
12135
|
+
// This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
|
|
12136
|
+
insightsClient('onUserTokenChange', setUserTokenToSearch, {
|
|
12137
|
+
immediate: true
|
|
12138
|
+
});
|
|
12139
|
+
var insightsClientWithLocalCredentials = insightsClient;
|
|
12140
|
+
if (isModernInsightsClient(insightsClient)) {
|
|
12141
|
+
insightsClientWithLocalCredentials = function insightsClientWithLocalCredentials(method, payload) {
|
|
12142
|
+
var extraParams = {
|
|
12143
|
+
headers: {
|
|
12144
|
+
'X-Algolia-Application-Id': appId,
|
|
12145
|
+
'X-Algolia-API-Key': apiKey
|
|
12146
|
+
}
|
|
12147
|
+
};
|
|
12148
|
+
|
|
12149
|
+
// @ts-ignore we are calling this only when we know that the client actually is correct
|
|
12150
|
+
return insightsClient(method, payload, extraParams);
|
|
12151
|
+
};
|
|
12152
|
+
}
|
|
12153
|
+
instantSearchInstance.sendEventToInsights = function (event) {
|
|
12154
|
+
if (onEvent) {
|
|
12155
|
+
onEvent(event, insightsClientWithLocalCredentials);
|
|
12156
|
+
} else if (event.insightsMethod) {
|
|
12157
|
+
// Source is used to differentiate events sent by instantsearch from those sent manually.
|
|
12158
|
+
event.payload.algoliaSource = ['instantsearch'];
|
|
12159
|
+
if (event.eventModifier === 'internal') {
|
|
12160
|
+
event.payload.algoliaSource.push('instantsearch-internal');
|
|
12161
|
+
}
|
|
12162
|
+
insightsClientWithLocalCredentials(event.insightsMethod, event.payload);
|
|
12163
|
+
_warning(Boolean(helper.state.userToken), "\nCannot send event to Algolia Insights because `userToken` is not set.\n\nSee documentation: https://www.algolia.com/doc/guides/building-search-ui/going-further/send-insights-events/js/#setting-the-usertoken\n") ;
|
|
12164
|
+
} else {
|
|
12165
|
+
_warning(false, 'Cannot send event to Algolia Insights because `insightsMethod` option is missing.') ;
|
|
12166
|
+
}
|
|
12167
|
+
};
|
|
12168
|
+
},
|
|
12169
|
+
unsubscribe: function unsubscribe() {
|
|
12170
|
+
insightsClient('onUserTokenChange', undefined);
|
|
12171
|
+
instantSearchInstance.sendEventToInsights = noop;
|
|
12172
|
+
if (helper && initialParameters) {
|
|
12173
|
+
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), initialParameters));
|
|
12174
|
+
instantSearchInstance.scheduleSearch();
|
|
12175
|
+
}
|
|
12176
|
+
}
|
|
12177
|
+
};
|
|
12178
|
+
};
|
|
12179
|
+
}
|
|
12180
|
+
|
|
12181
|
+
/**
|
|
12182
|
+
* Determines if a given insights `client` supports the optional call to `init`
|
|
12183
|
+
* and the ability to set credentials via extra parameters when sending events.
|
|
12184
|
+
*/
|
|
12185
|
+
function isModernInsightsClient(client) {
|
|
12186
|
+
var _split$map = (client.version || '').split('.').map(Number),
|
|
12187
|
+
_split$map2 = _slicedToArray(_split$map, 2),
|
|
12188
|
+
major = _split$map2[0],
|
|
12189
|
+
minor = _split$map2[1];
|
|
12190
|
+
|
|
12191
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
12192
|
+
var v3 = major >= 3;
|
|
12193
|
+
var v2_6 = major === 2 && minor >= 6;
|
|
12194
|
+
var v1_10 = major === 1 && minor >= 10;
|
|
12195
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
12196
|
+
|
|
12197
|
+
return v3 || v2_6 || v1_10;
|
|
12198
|
+
}
|
|
12199
|
+
|
|
12200
|
+
function extractWidgetPayload(widgets, instantSearchInstance, payload) {
|
|
11903
12201
|
var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
|
|
11904
12202
|
widgets.forEach(function (widget) {
|
|
11905
12203
|
var widgetParams = {};
|
|
@@ -11921,7 +12219,7 @@
|
|
|
11921
12219
|
params: params
|
|
11922
12220
|
});
|
|
11923
12221
|
if (widget.$$type === 'ais.index') {
|
|
11924
|
-
|
|
12222
|
+
extractWidgetPayload(widget.getWidgets(), instantSearchInstance, payload);
|
|
11925
12223
|
}
|
|
11926
12224
|
});
|
|
11927
12225
|
}
|
|
@@ -11945,8 +12243,11 @@
|
|
|
11945
12243
|
* - connector name
|
|
11946
12244
|
*/
|
|
11947
12245
|
function createMetadataMiddleware() {
|
|
11948
|
-
|
|
11949
|
-
|
|
12246
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
12247
|
+
_ref2$$$internal = _ref2.$$internal,
|
|
12248
|
+
$$internal = _ref2$$$internal === void 0 ? false : _ref2$$$internal;
|
|
12249
|
+
return function (_ref3) {
|
|
12250
|
+
var instantSearchInstance = _ref3.instantSearchInstance;
|
|
11950
12251
|
var payload = {
|
|
11951
12252
|
widgets: []
|
|
11952
12253
|
};
|
|
@@ -11954,13 +12255,22 @@
|
|
|
11954
12255
|
var refNode = document.querySelector('head');
|
|
11955
12256
|
payloadContainer.name = 'instantsearch:widgets';
|
|
11956
12257
|
return {
|
|
12258
|
+
$$type: 'ais.metadata',
|
|
12259
|
+
$$internal: $$internal,
|
|
11957
12260
|
onStateChange: function onStateChange() {},
|
|
11958
12261
|
subscribe: function subscribe() {
|
|
11959
12262
|
// using setTimeout here to delay extraction until widgets have been added in a tick (e.g. Vue)
|
|
11960
12263
|
setTimeout(function () {
|
|
11961
12264
|
var client = instantSearchInstance.client;
|
|
11962
12265
|
payload.ua = client.transporter && client.transporter.userAgent ? client.transporter.userAgent.value : client._ua;
|
|
11963
|
-
|
|
12266
|
+
extractWidgetPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
|
|
12267
|
+
instantSearchInstance.middleware.forEach(function (middleware) {
|
|
12268
|
+
return payload.widgets.push({
|
|
12269
|
+
middleware: true,
|
|
12270
|
+
type: middleware.instance.$$type,
|
|
12271
|
+
internal: middleware.instance.$$internal
|
|
12272
|
+
});
|
|
12273
|
+
});
|
|
11964
12274
|
payloadContainer.content = JSON.stringify(payload);
|
|
11965
12275
|
refNode.appendChild(payloadContainer);
|
|
11966
12276
|
}, 0);
|
|
@@ -12796,6 +13106,48 @@
|
|
|
12796
13106
|
}
|
|
12797
13107
|
};
|
|
12798
13108
|
var BrowserHistory = /*#__PURE__*/function () {
|
|
13109
|
+
/**
|
|
13110
|
+
* Transforms a UI state into a title for the page.
|
|
13111
|
+
*/
|
|
13112
|
+
|
|
13113
|
+
/**
|
|
13114
|
+
* Time in milliseconds before performing a write in the history.
|
|
13115
|
+
* It prevents from adding too many entries in the history and
|
|
13116
|
+
* makes the back button more usable.
|
|
13117
|
+
*
|
|
13118
|
+
* @default 400
|
|
13119
|
+
*/
|
|
13120
|
+
|
|
13121
|
+
/**
|
|
13122
|
+
* Creates a full URL based on the route state.
|
|
13123
|
+
* The storage adaptor maps all syncable keys to the query string of the URL.
|
|
13124
|
+
*/
|
|
13125
|
+
|
|
13126
|
+
/**
|
|
13127
|
+
* Parses the URL into a route state.
|
|
13128
|
+
* It should be symmetrical to `createURL`.
|
|
13129
|
+
*/
|
|
13130
|
+
|
|
13131
|
+
/**
|
|
13132
|
+
* Returns the location to store in the history.
|
|
13133
|
+
* @default () => window.location
|
|
13134
|
+
*/
|
|
13135
|
+
|
|
13136
|
+
/**
|
|
13137
|
+
* Indicates if last action was back/forward in the browser.
|
|
13138
|
+
*/
|
|
13139
|
+
|
|
13140
|
+
/**
|
|
13141
|
+
* Indicates whether the history router is disposed or not.
|
|
13142
|
+
*/
|
|
13143
|
+
|
|
13144
|
+
/**
|
|
13145
|
+
* Indicates the window.history.length before the last call to
|
|
13146
|
+
* window.history.pushState (called in `write`).
|
|
13147
|
+
* It allows to determine if a `pushState` has been triggered elsewhere,
|
|
13148
|
+
* and thus to prevent the `write` method from calling `pushState`.
|
|
13149
|
+
*/
|
|
13150
|
+
|
|
12799
13151
|
/**
|
|
12800
13152
|
* Initializes a new storage provider that syncs the search state to the URL
|
|
12801
13153
|
* using web APIs (`window.location.pushState` and `onpopstate` event).
|
|
@@ -12812,12 +13164,14 @@
|
|
|
12812
13164
|
dispose = _ref.dispose,
|
|
12813
13165
|
push = _ref.push;
|
|
12814
13166
|
_classCallCheck(this, BrowserHistory);
|
|
13167
|
+
_defineProperty(this, "$$type", 'ais.browser');
|
|
12815
13168
|
_defineProperty(this, "windowTitle", void 0);
|
|
12816
13169
|
_defineProperty(this, "writeDelay", void 0);
|
|
12817
13170
|
_defineProperty(this, "_createURL", void 0);
|
|
12818
13171
|
_defineProperty(this, "parseURL", void 0);
|
|
12819
13172
|
_defineProperty(this, "getLocation", void 0);
|
|
12820
13173
|
_defineProperty(this, "writeTimer", void 0);
|
|
13174
|
+
_defineProperty(this, "_onPopState", void 0);
|
|
12821
13175
|
_defineProperty(this, "inPopState", false);
|
|
12822
13176
|
_defineProperty(this, "isDisposed", false);
|
|
12823
13177
|
_defineProperty(this, "latestAcknowledgedHistory", 0);
|
|
@@ -12923,11 +13277,21 @@
|
|
|
12923
13277
|
}, {
|
|
12924
13278
|
key: "createURL",
|
|
12925
13279
|
value: function createURL(routeState) {
|
|
12926
|
-
|
|
13280
|
+
var url = this._createURL({
|
|
12927
13281
|
qsModule: lib$1,
|
|
12928
13282
|
routeState: routeState,
|
|
12929
13283
|
location: this.getLocation()
|
|
12930
13284
|
});
|
|
13285
|
+
{
|
|
13286
|
+
try {
|
|
13287
|
+
// We just want to check if the URL is valid.
|
|
13288
|
+
// eslint-disable-next-line no-new
|
|
13289
|
+
new URL(url);
|
|
13290
|
+
} catch (e) {
|
|
13291
|
+
_warning(false, "The URL returned by the `createURL` function is invalid.\nPlease make sure it returns an absolute URL to avoid issues, e.g: `https://algolia.com/search?query=iphone`.") ;
|
|
13292
|
+
}
|
|
13293
|
+
}
|
|
13294
|
+
return url;
|
|
12931
13295
|
}
|
|
12932
13296
|
|
|
12933
13297
|
/**
|
|
@@ -13064,6 +13428,7 @@
|
|
|
13064
13428
|
// which excludes "configure" as this function does.
|
|
13065
13429
|
function simpleStateMapping() {
|
|
13066
13430
|
return {
|
|
13431
|
+
$$type: 'ais.simple',
|
|
13067
13432
|
stateToRoute: function stateToRoute(uiState) {
|
|
13068
13433
|
return Object.keys(uiState).reduce(function (state, indexId) {
|
|
13069
13434
|
return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty({}, indexId, getIndexStateWithoutConfigure(uiState[indexId])));
|
|
@@ -13083,7 +13448,9 @@
|
|
|
13083
13448
|
var _props$router = props.router,
|
|
13084
13449
|
router = _props$router === void 0 ? historyRouter() : _props$router,
|
|
13085
13450
|
_props$stateMapping = props.stateMapping,
|
|
13086
|
-
stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping
|
|
13451
|
+
stateMapping = _props$stateMapping === void 0 ? simpleStateMapping() : _props$stateMapping,
|
|
13452
|
+
_props$$$internal = props.$$internal,
|
|
13453
|
+
$$internal = _props$$$internal === void 0 ? false : _props$$$internal;
|
|
13087
13454
|
return function (_ref) {
|
|
13088
13455
|
var instantSearchInstance = _ref.instantSearchInstance;
|
|
13089
13456
|
function topLevelCreateURL(nextState) {
|
|
@@ -13100,6 +13467,8 @@
|
|
|
13100
13467
|
var lastRouteState = undefined;
|
|
13101
13468
|
var initialUiState = instantSearchInstance._initialUiState;
|
|
13102
13469
|
return {
|
|
13470
|
+
$$type: "ais.router({router:".concat(router.$$type || '__unknown__', ", stateMapping:").concat(stateMapping.$$type || '__unknown__', "})"),
|
|
13471
|
+
$$internal: $$internal,
|
|
13103
13472
|
onStateChange: function onStateChange(_ref2) {
|
|
13104
13473
|
var uiState = _ref2.uiState;
|
|
13105
13474
|
var routeState = stateMapping.stateToRoute(uiState);
|
|
@@ -13443,7 +13812,7 @@
|
|
|
13443
13812
|
// does not have access to lastResults, which it used to in pre-federated
|
|
13444
13813
|
// search behavior.
|
|
13445
13814
|
helper.lastResults = results;
|
|
13446
|
-
lastValidSearchParameters = results._state;
|
|
13815
|
+
lastValidSearchParameters = results === null || results === void 0 ? void 0 : results._state;
|
|
13447
13816
|
});
|
|
13448
13817
|
|
|
13449
13818
|
// We compute the render state before calling `init` in a separate loop
|
|
@@ -13499,16 +13868,16 @@
|
|
|
13499
13868
|
render: function render(_ref5) {
|
|
13500
13869
|
var _this4 = this;
|
|
13501
13870
|
var instantSearchInstance = _ref5.instantSearchInstance;
|
|
13502
|
-
if (!this.getResults()) {
|
|
13503
|
-
return;
|
|
13504
|
-
}
|
|
13505
|
-
|
|
13506
13871
|
// we can't attach a listener to the error event of search, as the error
|
|
13507
13872
|
// then would no longer be thrown for global handlers.
|
|
13508
|
-
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests()) {
|
|
13873
|
+
if (instantSearchInstance.status === 'error' && !instantSearchInstance.mainHelper.hasPendingRequests() && lastValidSearchParameters) {
|
|
13509
13874
|
helper.setState(lastValidSearchParameters);
|
|
13510
13875
|
}
|
|
13511
|
-
|
|
13876
|
+
|
|
13877
|
+
// We only render index widgets if there are no results.
|
|
13878
|
+
// This makes sure `render` is never called with `results` being `null`.
|
|
13879
|
+
var widgetsToRender = this.getResults() ? localWidgets : localWidgets.filter(isIndexWidget);
|
|
13880
|
+
widgetsToRender.forEach(function (widget) {
|
|
13512
13881
|
if (widget.getRenderState) {
|
|
13513
13882
|
var renderState = widget.getRenderState(instantSearchInstance.renderState[_this4.getIndexId()] || {}, createRenderArgs(instantSearchInstance, _this4));
|
|
13514
13883
|
storeRenderState({
|
|
@@ -13518,7 +13887,7 @@
|
|
|
13518
13887
|
});
|
|
13519
13888
|
}
|
|
13520
13889
|
});
|
|
13521
|
-
|
|
13890
|
+
widgetsToRender.forEach(function (widget) {
|
|
13522
13891
|
// At this point, all the variables used below are set. Both `helper`
|
|
13523
13892
|
// and `derivedHelper` have been created at the `init` step. The attribute
|
|
13524
13893
|
// `lastResults` might be `null` though. It's possible that a stalled render
|
|
@@ -13660,7 +14029,7 @@
|
|
|
13660
14029
|
};
|
|
13661
14030
|
}
|
|
13662
14031
|
|
|
13663
|
-
var version$1 = '4.
|
|
14032
|
+
var version$1 = '4.56.0';
|
|
13664
14033
|
|
|
13665
14034
|
var withUsage$r = createDocumentationMessageGenerator({
|
|
13666
14035
|
name: 'instantsearch'
|
|
@@ -13739,12 +14108,14 @@
|
|
|
13739
14108
|
}));
|
|
13740
14109
|
_this.setMaxListeners(100);
|
|
13741
14110
|
var _options$indexName = options.indexName,
|
|
13742
|
-
indexName = _options$indexName === void 0 ?
|
|
14111
|
+
indexName = _options$indexName === void 0 ? '' : _options$indexName,
|
|
13743
14112
|
numberLocale = options.numberLocale,
|
|
13744
14113
|
_options$initialUiSta = options.initialUiState,
|
|
13745
14114
|
initialUiState = _options$initialUiSta === void 0 ? {} : _options$initialUiSta,
|
|
13746
14115
|
_options$routing = options.routing,
|
|
13747
14116
|
routing = _options$routing === void 0 ? null : _options$routing,
|
|
14117
|
+
_options$insights = options.insights,
|
|
14118
|
+
insights = _options$insights === void 0 ? false : _options$insights,
|
|
13748
14119
|
searchFunction = options.searchFunction,
|
|
13749
14120
|
_options$stalledSearc = options.stalledSearchDelay,
|
|
13750
14121
|
stalledSearchDelay = _options$stalledSearc === void 0 ? 200 : _options$stalledSearc,
|
|
@@ -13754,9 +14125,6 @@
|
|
|
13754
14125
|
insightsClient = _options$insightsClie === void 0 ? null : _options$insightsClie,
|
|
13755
14126
|
_options$onStateChang = options.onStateChange,
|
|
13756
14127
|
onStateChange = _options$onStateChang === void 0 ? null : _options$onStateChang;
|
|
13757
|
-
if (indexName === null) {
|
|
13758
|
-
throw new Error(withUsage$r('The `indexName` option is required.'));
|
|
13759
|
-
}
|
|
13760
14128
|
if (searchClient === null) {
|
|
13761
14129
|
throw new Error(withUsage$r('The `searchClient` option is required.'));
|
|
13762
14130
|
}
|
|
@@ -13800,11 +14168,22 @@
|
|
|
13800
14168
|
}
|
|
13801
14169
|
_this.sendEventToInsights = noop;
|
|
13802
14170
|
if (routing) {
|
|
13803
|
-
var routerOptions = typeof routing === 'boolean' ?
|
|
14171
|
+
var routerOptions = typeof routing === 'boolean' ? {} : routing;
|
|
14172
|
+
routerOptions.$$internal = true;
|
|
13804
14173
|
_this.use(createRouterMiddleware(routerOptions));
|
|
13805
14174
|
}
|
|
14175
|
+
|
|
14176
|
+
// This is the default middleware,
|
|
14177
|
+
// any user-provided middleware will be added later and override this one.
|
|
14178
|
+
if (insights) {
|
|
14179
|
+
var insightsOptions = typeof insights === 'boolean' ? {} : insights;
|
|
14180
|
+
insightsOptions.$$internal = true;
|
|
14181
|
+
_this.use(createInsightsMiddleware(insightsOptions));
|
|
14182
|
+
}
|
|
13806
14183
|
if (isMetadataEnabled()) {
|
|
13807
|
-
_this.use(createMetadataMiddleware(
|
|
14184
|
+
_this.use(createMetadataMiddleware({
|
|
14185
|
+
$$internal: true
|
|
14186
|
+
}));
|
|
13808
14187
|
}
|
|
13809
14188
|
return _this;
|
|
13810
14189
|
}
|
|
@@ -13840,6 +14219,8 @@
|
|
|
13840
14219
|
}
|
|
13841
14220
|
var newMiddlewareList = middleware.map(function (fn) {
|
|
13842
14221
|
var newMiddleware = _objectSpread2({
|
|
14222
|
+
$$type: '__unknown__',
|
|
14223
|
+
$$internal: false,
|
|
13843
14224
|
subscribe: noop,
|
|
13844
14225
|
started: noop,
|
|
13845
14226
|
unsubscribe: noop,
|
|
@@ -13985,6 +14366,7 @@
|
|
|
13985
14366
|
mainHelper.search = function () {
|
|
13986
14367
|
_this3.status = 'loading';
|
|
13987
14368
|
_this3.scheduleRender(false);
|
|
14369
|
+
_warning(Boolean(_this3.indexName) || _this3.mainIndex.getWidgets().some(isIndexWidget), 'No indexName provided, nor an explicit index widget in the widgets tree. This is required to be able to display results.') ;
|
|
13988
14370
|
|
|
13989
14371
|
// This solution allows us to keep the exact same API for the users but
|
|
13990
14372
|
// under the hood, we have a different implementation. It should be
|
|
@@ -14217,6 +14599,7 @@
|
|
|
14217
14599
|
}
|
|
14218
14600
|
function singleIndexStateMapping(indexName) {
|
|
14219
14601
|
return {
|
|
14602
|
+
$$type: 'ais.singleIndex',
|
|
14220
14603
|
stateToRoute: function stateToRoute(uiState) {
|
|
14221
14604
|
return getIndexStateWithoutConfigure$1(uiState[indexName] || {});
|
|
14222
14605
|
},
|
|
@@ -14235,130 +14618,6 @@
|
|
|
14235
14618
|
singleIndex: singleIndexStateMapping
|
|
14236
14619
|
});
|
|
14237
14620
|
|
|
14238
|
-
function createInsightsMiddleware(props) {
|
|
14239
|
-
var _ref = props || {},
|
|
14240
|
-
_insightsClient = _ref.insightsClient,
|
|
14241
|
-
insightsInitParams = _ref.insightsInitParams,
|
|
14242
|
-
onEvent = _ref.onEvent;
|
|
14243
|
-
if (_insightsClient !== null && !_insightsClient) {
|
|
14244
|
-
{
|
|
14245
|
-
throw new Error("The `insightsClient` option is required if you want userToken to be automatically set in search calls. If you don't want this behaviour, set it to `null`.");
|
|
14246
|
-
}
|
|
14247
|
-
}
|
|
14248
|
-
var hasInsightsClient = Boolean(_insightsClient);
|
|
14249
|
-
var insightsClient = _insightsClient === null ? noop : _insightsClient;
|
|
14250
|
-
return function (_ref2) {
|
|
14251
|
-
var instantSearchInstance = _ref2.instantSearchInstance;
|
|
14252
|
-
var _getAppIdAndApiKey = getAppIdAndApiKey(instantSearchInstance.client),
|
|
14253
|
-
_getAppIdAndApiKey2 = _slicedToArray(_getAppIdAndApiKey, 2),
|
|
14254
|
-
appId = _getAppIdAndApiKey2[0],
|
|
14255
|
-
apiKey = _getAppIdAndApiKey2[1];
|
|
14256
|
-
|
|
14257
|
-
// search-insights.js also throws an error so dev-only clarification is sufficient
|
|
14258
|
-
if ( !(appId && apiKey)) {
|
|
14259
|
-
throw new Error('[insights middleware]: could not extract Algolia credentials from searchClient');
|
|
14260
|
-
}
|
|
14261
|
-
var queuedUserToken = undefined;
|
|
14262
|
-
var userTokenBeforeInit = undefined;
|
|
14263
|
-
if (Array.isArray(insightsClient.queue)) {
|
|
14264
|
-
// Context: The umd build of search-insights is asynchronously loaded by the snippet.
|
|
14265
|
-
//
|
|
14266
|
-
// When user calls `aa('setUserToken', 'my-user-token')` before `search-insights` is loaded,
|
|
14267
|
-
// ['setUserToken', 'my-user-token'] gets stored in `aa.queue`.
|
|
14268
|
-
// Whenever `search-insights` is finally loaded, it will process the queue.
|
|
14269
|
-
//
|
|
14270
|
-
// But here's the reason why we handle it here:
|
|
14271
|
-
// At this point, even though `search-insights` is not loaded yet,
|
|
14272
|
-
// we still want to read the token from the queue.
|
|
14273
|
-
// Otherwise, the first search call will be fired without the token.
|
|
14274
|
-
var _ref3 = find(insightsClient.queue.slice().reverse(), function (_ref5) {
|
|
14275
|
-
var _ref6 = _slicedToArray(_ref5, 1),
|
|
14276
|
-
method = _ref6[0];
|
|
14277
|
-
return method === 'setUserToken';
|
|
14278
|
-
}) || [];
|
|
14279
|
-
var _ref4 = _slicedToArray(_ref3, 2);
|
|
14280
|
-
queuedUserToken = _ref4[1];
|
|
14281
|
-
}
|
|
14282
|
-
insightsClient('getUserToken', null, function (_error, userToken) {
|
|
14283
|
-
// If user has called `aa('setUserToken', 'my-user-token')` before creating
|
|
14284
|
-
// the `insights` middleware, we store them temporarily and
|
|
14285
|
-
// set it later on.
|
|
14286
|
-
//
|
|
14287
|
-
// Otherwise, the `init` call might override it with anonymous user token.
|
|
14288
|
-
userTokenBeforeInit = userToken;
|
|
14289
|
-
});
|
|
14290
|
-
insightsClient('init', _objectSpread2({
|
|
14291
|
-
appId: appId,
|
|
14292
|
-
apiKey: apiKey
|
|
14293
|
-
}, insightsInitParams));
|
|
14294
|
-
var initialParameters;
|
|
14295
|
-
var helper;
|
|
14296
|
-
return {
|
|
14297
|
-
onStateChange: function onStateChange() {},
|
|
14298
|
-
subscribe: function subscribe() {},
|
|
14299
|
-
started: function started() {
|
|
14300
|
-
insightsClient('addAlgoliaAgent', 'insights-middleware');
|
|
14301
|
-
helper = instantSearchInstance.helper;
|
|
14302
|
-
initialParameters = {
|
|
14303
|
-
userToken: helper.state.userToken,
|
|
14304
|
-
clickAnalytics: helper.state.clickAnalytics
|
|
14305
|
-
};
|
|
14306
|
-
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
14307
|
-
clickAnalytics: true
|
|
14308
|
-
}));
|
|
14309
|
-
instantSearchInstance.scheduleSearch();
|
|
14310
|
-
var setUserTokenToSearch = function setUserTokenToSearch(userToken) {
|
|
14311
|
-
helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread2(_objectSpread2({}, helper.state), {}, {
|
|
14312
|
-
userToken: userToken
|
|
14313
|
-
}));
|
|
14314
|
-
instantSearchInstance.scheduleSearch();
|
|
14315
|
-
};
|
|
14316
|
-
var anonymousUserToken = getInsightsAnonymousUserTokenInternal();
|
|
14317
|
-
if (hasInsightsClient && anonymousUserToken) {
|
|
14318
|
-
// When `aa('init', { ... })` is called, it creates an anonymous user token in cookie.
|
|
14319
|
-
// We can set it as userToken.
|
|
14320
|
-
setUserTokenToSearch(anonymousUserToken);
|
|
14321
|
-
}
|
|
14322
|
-
|
|
14323
|
-
// We consider the `userToken` coming from a `init` call to have a higher
|
|
14324
|
-
// importance than the one coming from the queue.
|
|
14325
|
-
if (userTokenBeforeInit) {
|
|
14326
|
-
insightsClient('setUserToken', userTokenBeforeInit);
|
|
14327
|
-
} else if (queuedUserToken) {
|
|
14328
|
-
insightsClient('setUserToken', queuedUserToken);
|
|
14329
|
-
}
|
|
14330
|
-
|
|
14331
|
-
// This updates userToken which is set explicitly by `aa('setUserToken', userToken)`
|
|
14332
|
-
insightsClient('onUserTokenChange', setUserTokenToSearch, {
|
|
14333
|
-
immediate: true
|
|
14334
|
-
});
|
|
14335
|
-
instantSearchInstance.sendEventToInsights = function (event) {
|
|
14336
|
-
if (onEvent) {
|
|
14337
|
-
onEvent(event, _insightsClient);
|
|
14338
|
-
} else if (event.insightsMethod) {
|
|
14339
|
-
var hasUserToken = Boolean(helper.state.userToken);
|
|
14340
|
-
if (hasUserToken) {
|
|
14341
|
-
insightsClient(event.insightsMethod, event.payload);
|
|
14342
|
-
} else {
|
|
14343
|
-
_warning(false, "\nCannot send event to Algolia Insights because `userToken` is not set.\n\nSee documentation: https://www.algolia.com/doc/guides/building-search-ui/going-further/send-insights-events/js/#setting-the-usertoken\n") ;
|
|
14344
|
-
}
|
|
14345
|
-
} else {
|
|
14346
|
-
_warning(false, 'Cannot send event to Algolia Insights because `insightsMethod` option is missing.') ;
|
|
14347
|
-
}
|
|
14348
|
-
};
|
|
14349
|
-
},
|
|
14350
|
-
unsubscribe: function unsubscribe() {
|
|
14351
|
-
insightsClient('onUserTokenChange', undefined);
|
|
14352
|
-
instantSearchInstance.sendEventToInsights = noop;
|
|
14353
|
-
if (helper && initialParameters) {
|
|
14354
|
-
helper.setState(_objectSpread2(_objectSpread2({}, helper.state), initialParameters));
|
|
14355
|
-
instantSearchInstance.scheduleSearch();
|
|
14356
|
-
}
|
|
14357
|
-
}
|
|
14358
|
-
};
|
|
14359
|
-
};
|
|
14360
|
-
}
|
|
14361
|
-
|
|
14362
14621
|
|
|
14363
14622
|
|
|
14364
14623
|
var middlewares = /*#__PURE__*/Object.freeze({
|
|
@@ -15375,7 +15634,7 @@
|
|
|
15375
15634
|
}
|
|
15376
15635
|
|
|
15377
15636
|
var _excluded$d = ["hit", "attribute", "cssClasses"],
|
|
15378
|
-
_excluded2$
|
|
15637
|
+
_excluded2$2 = ["isHighlighted"];
|
|
15379
15638
|
function ReverseHighlight$1(_ref) {
|
|
15380
15639
|
var hit = _ref.hit,
|
|
15381
15640
|
attribute = _ref.attribute,
|
|
@@ -15388,7 +15647,7 @@
|
|
|
15388
15647
|
var value = _ref2.value;
|
|
15389
15648
|
return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
|
|
15390
15649
|
var isHighlighted = _ref3.isHighlighted,
|
|
15391
|
-
rest = _objectWithoutProperties(_ref3, _excluded2$
|
|
15650
|
+
rest = _objectWithoutProperties(_ref3, _excluded2$2);
|
|
15392
15651
|
return _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
15393
15652
|
isHighlighted: !isHighlighted
|
|
15394
15653
|
});
|
|
@@ -15416,7 +15675,7 @@
|
|
|
15416
15675
|
}
|
|
15417
15676
|
|
|
15418
15677
|
var _excluded$f = ["hit", "attribute", "cssClasses"],
|
|
15419
|
-
_excluded2$
|
|
15678
|
+
_excluded2$3 = ["isHighlighted"];
|
|
15420
15679
|
function ReverseSnippet$1(_ref) {
|
|
15421
15680
|
var hit = _ref.hit,
|
|
15422
15681
|
attribute = _ref.attribute,
|
|
@@ -15429,7 +15688,7 @@
|
|
|
15429
15688
|
var value = _ref2.value;
|
|
15430
15689
|
return getHighlightedParts(unescape$1(value || '')).map(function (_ref3) {
|
|
15431
15690
|
var isHighlighted = _ref3.isHighlighted,
|
|
15432
|
-
rest = _objectWithoutProperties(_ref3, _excluded2$
|
|
15691
|
+
rest = _objectWithoutProperties(_ref3, _excluded2$3);
|
|
15433
15692
|
return _objectSpread2(_objectSpread2({}, rest), {}, {
|
|
15434
15693
|
isHighlighted: !isHighlighted
|
|
15435
15694
|
});
|
|
@@ -15970,10 +16229,10 @@
|
|
|
15970
16229
|
rootTagName: "a",
|
|
15971
16230
|
rootProps: {
|
|
15972
16231
|
className: cssClasses.link,
|
|
15973
|
-
href: createURL(
|
|
16232
|
+
href: createURL(null),
|
|
15974
16233
|
onClick: function onClick(event) {
|
|
15975
16234
|
event.preventDefault();
|
|
15976
|
-
refine(
|
|
16235
|
+
refine(null);
|
|
15977
16236
|
}
|
|
15978
16237
|
}
|
|
15979
16238
|
}))), items.map(function (item, idx) {
|
|
@@ -16719,7 +16978,7 @@
|
|
|
16719
16978
|
};
|
|
16720
16979
|
|
|
16721
16980
|
var _excluded$j = ["initialZoom", "initialPosition", "templates", "cssClasses", "builtInMarker", "customHTMLMarker", "enableRefine", "enableClearMapRefinement", "enableRefineControl", "container", "googleReference"],
|
|
16722
|
-
_excluded2$
|
|
16981
|
+
_excluded2$4 = ["item"],
|
|
16723
16982
|
_excluded3 = ["item"];
|
|
16724
16983
|
var withUsage$y = createDocumentationMessageGenerator({
|
|
16725
16984
|
name: 'geo-search'
|
|
@@ -16821,7 +17080,7 @@
|
|
|
16821
17080
|
var customHTMLMarker = isCustomHTMLMarker && _objectSpread2(_objectSpread2({}, defaultCustomHTMLMarker), userCustomHTMLMarker);
|
|
16822
17081
|
var createBuiltInMarker = function createBuiltInMarker(_ref2) {
|
|
16823
17082
|
var item = _ref2.item,
|
|
16824
|
-
rest = _objectWithoutProperties(_ref2, _excluded2$
|
|
17083
|
+
rest = _objectWithoutProperties(_ref2, _excluded2$4);
|
|
16825
17084
|
return new googleReference.maps.Marker(_objectSpread2(_objectSpread2(_objectSpread2({}, builtInMarker.createOptions(item)), rest), {}, {
|
|
16826
17085
|
// @ts-expect-error @types/googlemaps doesn't document this
|
|
16827
17086
|
__id: item.objectID,
|
|
@@ -17100,49 +17359,36 @@
|
|
|
17100
17359
|
var RefinementList$1 = /*#__PURE__*/function (_Component) {
|
|
17101
17360
|
_inherits(RefinementList, _Component);
|
|
17102
17361
|
var _super = _createSuper(RefinementList);
|
|
17103
|
-
function RefinementList(
|
|
17362
|
+
function RefinementList() {
|
|
17104
17363
|
var _this;
|
|
17105
17364
|
_classCallCheck(this, RefinementList);
|
|
17106
|
-
|
|
17107
|
-
|
|
17108
|
-
_this.handleItemClick = _this.handleItemClick.bind(_assertThisInitialized(_this));
|
|
17109
|
-
return _this;
|
|
17110
|
-
}
|
|
17111
|
-
_createClass(RefinementList, [{
|
|
17112
|
-
key: "shouldComponentUpdate",
|
|
17113
|
-
value: function shouldComponentUpdate(nextProps) {
|
|
17114
|
-
var areFacetValuesDifferent = !isEqual(this.props.facetValues, nextProps.facetValues);
|
|
17115
|
-
return areFacetValuesDifferent;
|
|
17116
|
-
}
|
|
17117
|
-
}, {
|
|
17118
|
-
key: "refine",
|
|
17119
|
-
value: function refine(facetValueToRefine) {
|
|
17120
|
-
this.props.toggleRefinement(facetValueToRefine);
|
|
17365
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
17366
|
+
args[_key] = arguments[_key];
|
|
17121
17367
|
}
|
|
17122
|
-
|
|
17123
|
-
|
|
17124
|
-
|
|
17368
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
17369
|
+
_defineProperty(_assertThisInitialized(_this), "searchBox", y());
|
|
17370
|
+
_defineProperty(_assertThisInitialized(_this), "_generateFacetItem", function (facetValue) {
|
|
17125
17371
|
var subItems;
|
|
17126
17372
|
if (isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) {
|
|
17127
|
-
var _this$props$cssClasse =
|
|
17373
|
+
var _this$props$cssClasse = _this.props.cssClasses,
|
|
17128
17374
|
root = _this$props$cssClasse.root,
|
|
17129
17375
|
cssClasses = _objectWithoutProperties(_this$props$cssClasse, _excluded$k);
|
|
17130
|
-
subItems = h(RefinementList, _extends({},
|
|
17376
|
+
subItems = h(RefinementList, _extends({}, _this.props, {
|
|
17131
17377
|
// We want to keep `root` required for external usage but not for the
|
|
17132
17378
|
// sub items.
|
|
17133
17379
|
cssClasses: cssClasses,
|
|
17134
|
-
depth:
|
|
17380
|
+
depth: _this.props.depth + 1,
|
|
17135
17381
|
facetValues: facetValue.data,
|
|
17136
17382
|
showMore: false,
|
|
17137
|
-
className:
|
|
17383
|
+
className: _this.props.cssClasses.childList
|
|
17138
17384
|
}));
|
|
17139
17385
|
}
|
|
17140
|
-
var url =
|
|
17386
|
+
var url = _this.props.createURL(facetValue.value);
|
|
17141
17387
|
var templateData = _objectSpread2(_objectSpread2({}, facetValue), {}, {
|
|
17142
17388
|
url: url,
|
|
17143
|
-
attribute:
|
|
17144
|
-
cssClasses:
|
|
17145
|
-
isFromSearch:
|
|
17389
|
+
attribute: _this.props.attribute,
|
|
17390
|
+
cssClasses: _this.props.cssClasses,
|
|
17391
|
+
isFromSearch: _this.props.isFromSearch
|
|
17146
17392
|
});
|
|
17147
17393
|
var key = facetValue.value;
|
|
17148
17394
|
if (facetValue.isRefined !== undefined) {
|
|
@@ -17151,38 +17397,20 @@
|
|
|
17151
17397
|
if (facetValue.count !== undefined) {
|
|
17152
17398
|
key += "/".concat(facetValue.count);
|
|
17153
17399
|
}
|
|
17154
|
-
var refinementListItemClassName = cx(
|
|
17400
|
+
var refinementListItemClassName = cx(_this.props.cssClasses.item, facetValue.isRefined && _this.props.cssClasses.selectedItem, !facetValue.count && _this.props.cssClasses.disabledItem, Boolean(isHierarchicalMenuItem(facetValue) && Array.isArray(facetValue.data) && facetValue.data.length > 0) && _this.props.cssClasses.parentItem);
|
|
17155
17401
|
return h(RefinementListItem, {
|
|
17156
17402
|
templateKey: "item",
|
|
17157
17403
|
key: key,
|
|
17158
17404
|
facetValueToRefine: facetValue.value,
|
|
17159
|
-
handleClick:
|
|
17405
|
+
handleClick: _this.handleItemClick,
|
|
17160
17406
|
isRefined: facetValue.isRefined,
|
|
17161
17407
|
className: refinementListItemClassName,
|
|
17162
17408
|
subItems: subItems,
|
|
17163
17409
|
templateData: templateData,
|
|
17164
|
-
templateProps:
|
|
17410
|
+
templateProps: _this.props.templateProps
|
|
17165
17411
|
});
|
|
17166
|
-
}
|
|
17167
|
-
|
|
17168
|
-
// Click events on DOM tree like LABEL > INPUT will result in two click events
|
|
17169
|
-
// instead of one.
|
|
17170
|
-
// No matter the framework, see https://www.google.com/search?q=click+label+twice
|
|
17171
|
-
//
|
|
17172
|
-
// Thus making it hard to distinguish activation from deactivation because both click events
|
|
17173
|
-
// are very close. Debounce is a solution but hacky.
|
|
17174
|
-
//
|
|
17175
|
-
// So the code here checks if the click was done on or in a LABEL. If this LABEL
|
|
17176
|
-
// has a checkbox inside, we ignore the first click event because we will get another one.
|
|
17177
|
-
//
|
|
17178
|
-
// We also check if the click was done inside a link and then e.preventDefault() because we already
|
|
17179
|
-
// handle the url
|
|
17180
|
-
//
|
|
17181
|
-
// Finally, we always stop propagation of the event to avoid multiple levels RefinementLists to fail: click
|
|
17182
|
-
// on child would click on parent also
|
|
17183
|
-
}, {
|
|
17184
|
-
key: "handleItemClick",
|
|
17185
|
-
value: function handleItemClick(_ref) {
|
|
17412
|
+
});
|
|
17413
|
+
_defineProperty(_assertThisInitialized(_this), "handleItemClick", function (_ref) {
|
|
17186
17414
|
var facetValueToRefine = _ref.facetValueToRefine,
|
|
17187
17415
|
isRefined = _ref.isRefined,
|
|
17188
17416
|
originalEvent = _ref.originalEvent;
|
|
@@ -17199,7 +17427,7 @@
|
|
|
17199
17427
|
return;
|
|
17200
17428
|
}
|
|
17201
17429
|
if (originalEvent.target.tagName === 'INPUT') {
|
|
17202
|
-
|
|
17430
|
+
_this.refine(facetValueToRefine);
|
|
17203
17431
|
return;
|
|
17204
17432
|
}
|
|
17205
17433
|
var parent = originalEvent.target;
|
|
@@ -17213,7 +17441,20 @@
|
|
|
17213
17441
|
parent = parent.parentNode;
|
|
17214
17442
|
}
|
|
17215
17443
|
originalEvent.stopPropagation();
|
|
17216
|
-
|
|
17444
|
+
_this.refine(facetValueToRefine);
|
|
17445
|
+
});
|
|
17446
|
+
return _this;
|
|
17447
|
+
}
|
|
17448
|
+
_createClass(RefinementList, [{
|
|
17449
|
+
key: "shouldComponentUpdate",
|
|
17450
|
+
value: function shouldComponentUpdate(nextProps) {
|
|
17451
|
+
var areFacetValuesDifferent = !isEqual(this.props.facetValues, nextProps.facetValues);
|
|
17452
|
+
return areFacetValuesDifferent;
|
|
17453
|
+
}
|
|
17454
|
+
}, {
|
|
17455
|
+
key: "refine",
|
|
17456
|
+
value: function refine(facetValueToRefine) {
|
|
17457
|
+
this.props.toggleRefinement(facetValueToRefine);
|
|
17217
17458
|
}
|
|
17218
17459
|
}, {
|
|
17219
17460
|
key: "componentWillReceiveProps",
|
|
@@ -17494,18 +17735,24 @@
|
|
|
17494
17735
|
});
|
|
17495
17736
|
};
|
|
17496
17737
|
|
|
17497
|
-
|
|
17738
|
+
function Hits(_ref) {
|
|
17498
17739
|
var results = _ref.results,
|
|
17499
17740
|
hits = _ref.hits,
|
|
17741
|
+
insights = _ref.insights,
|
|
17500
17742
|
bindEvent = _ref.bindEvent,
|
|
17501
17743
|
sendEvent = _ref.sendEvent,
|
|
17502
17744
|
cssClasses = _ref.cssClasses,
|
|
17503
17745
|
templateProps = _ref.templateProps;
|
|
17746
|
+
var handleInsightsClick = createInsightsEventHandler({
|
|
17747
|
+
insights: insights,
|
|
17748
|
+
sendEvent: sendEvent
|
|
17749
|
+
});
|
|
17504
17750
|
if (results.hits.length === 0) {
|
|
17505
17751
|
return h(Template, _extends({}, templateProps, {
|
|
17506
17752
|
templateKey: "empty",
|
|
17507
17753
|
rootProps: {
|
|
17508
|
-
className: cx(cssClasses.root, cssClasses.emptyRoot)
|
|
17754
|
+
className: cx(cssClasses.root, cssClasses.emptyRoot),
|
|
17755
|
+
onClick: handleInsightsClick
|
|
17509
17756
|
},
|
|
17510
17757
|
data: results
|
|
17511
17758
|
}));
|
|
@@ -17519,7 +17766,11 @@
|
|
|
17519
17766
|
templateKey: "item",
|
|
17520
17767
|
rootTagName: "li",
|
|
17521
17768
|
rootProps: {
|
|
17522
|
-
className: cssClasses.item
|
|
17769
|
+
className: cssClasses.item,
|
|
17770
|
+
onClick: function onClick(event) {
|
|
17771
|
+
handleInsightsClick(event);
|
|
17772
|
+
sendEvent('click:internal', hit, 'Hit Clicked');
|
|
17773
|
+
}
|
|
17523
17774
|
},
|
|
17524
17775
|
key: hit.objectID,
|
|
17525
17776
|
data: _objectSpread2(_objectSpread2({}, hit), {}, {
|
|
@@ -17532,7 +17783,7 @@
|
|
|
17532
17783
|
sendEvent: sendEvent
|
|
17533
17784
|
}));
|
|
17534
17785
|
})));
|
|
17535
|
-
}
|
|
17786
|
+
}
|
|
17536
17787
|
|
|
17537
17788
|
var defaultTemplates$5 = {
|
|
17538
17789
|
empty: function empty() {
|
|
@@ -17547,7 +17798,6 @@
|
|
|
17547
17798
|
name: 'hits'
|
|
17548
17799
|
});
|
|
17549
17800
|
var suit$b = component('Hits');
|
|
17550
|
-
var HitsWithInsightsListener = insightsListener(Hits);
|
|
17551
17801
|
var renderer$6 = function renderer(_ref) {
|
|
17552
17802
|
var renderState = _ref.renderState,
|
|
17553
17803
|
cssClasses = _ref.cssClasses,
|
|
@@ -17568,7 +17818,7 @@
|
|
|
17568
17818
|
});
|
|
17569
17819
|
return;
|
|
17570
17820
|
}
|
|
17571
|
-
P(h(
|
|
17821
|
+
P(h(Hits, {
|
|
17572
17822
|
cssClasses: cssClasses,
|
|
17573
17823
|
hits: receivedHits,
|
|
17574
17824
|
results: results,
|
|
@@ -17662,7 +17912,9 @@
|
|
|
17662
17912
|
}, h(Selector, {
|
|
17663
17913
|
cssClasses: cssClasses,
|
|
17664
17914
|
currentValue: currentValue,
|
|
17665
|
-
options: items
|
|
17915
|
+
options: items
|
|
17916
|
+
// @ts-expect-error: the refine function expects a number, but setValue will call it with a string. We don't want to change the type of the refine function because it's part of the connector API.
|
|
17917
|
+
,
|
|
17666
17918
|
setValue: refine
|
|
17667
17919
|
})), containerNode);
|
|
17668
17920
|
};
|
|
@@ -17705,6 +17957,7 @@
|
|
|
17705
17957
|
var InfiniteHits = function InfiniteHits(_ref) {
|
|
17706
17958
|
var results = _ref.results,
|
|
17707
17959
|
hits = _ref.hits,
|
|
17960
|
+
insights = _ref.insights,
|
|
17708
17961
|
bindEvent = _ref.bindEvent,
|
|
17709
17962
|
sendEvent = _ref.sendEvent,
|
|
17710
17963
|
hasShowPrevious = _ref.hasShowPrevious,
|
|
@@ -17714,11 +17967,16 @@
|
|
|
17714
17967
|
isLastPage = _ref.isLastPage,
|
|
17715
17968
|
cssClasses = _ref.cssClasses,
|
|
17716
17969
|
templateProps = _ref.templateProps;
|
|
17970
|
+
var handleInsightsClick = createInsightsEventHandler({
|
|
17971
|
+
insights: insights,
|
|
17972
|
+
sendEvent: sendEvent
|
|
17973
|
+
});
|
|
17717
17974
|
if (results.hits.length === 0) {
|
|
17718
17975
|
return h(Template, _extends({}, templateProps, {
|
|
17719
17976
|
templateKey: "empty",
|
|
17720
17977
|
rootProps: {
|
|
17721
|
-
className: cx(cssClasses.root, cssClasses.emptyRoot)
|
|
17978
|
+
className: cx(cssClasses.root, cssClasses.emptyRoot),
|
|
17979
|
+
onClick: handleInsightsClick
|
|
17722
17980
|
},
|
|
17723
17981
|
data: results
|
|
17724
17982
|
}));
|
|
@@ -17740,7 +17998,11 @@
|
|
|
17740
17998
|
templateKey: "item",
|
|
17741
17999
|
rootTagName: "li",
|
|
17742
18000
|
rootProps: {
|
|
17743
|
-
className: cssClasses.item
|
|
18001
|
+
className: cssClasses.item,
|
|
18002
|
+
onClick: function onClick(event) {
|
|
18003
|
+
handleInsightsClick(event);
|
|
18004
|
+
sendEvent('click:internal', hit, 'Hit Clicked');
|
|
18005
|
+
}
|
|
17744
18006
|
},
|
|
17745
18007
|
key: hit.objectID,
|
|
17746
18008
|
data: _objectSpread2(_objectSpread2({}, hit), {}, {
|
|
@@ -17782,7 +18044,6 @@
|
|
|
17782
18044
|
name: 'infinite-hits'
|
|
17783
18045
|
});
|
|
17784
18046
|
var suit$d = component('InfiniteHits');
|
|
17785
|
-
var InfiniteHitsWithInsightsListener = insightsListener(InfiniteHits);
|
|
17786
18047
|
var renderer$8 = function renderer(_ref) {
|
|
17787
18048
|
var containerNode = _ref.containerNode,
|
|
17788
18049
|
cssClasses = _ref.cssClasses,
|
|
@@ -17808,7 +18069,7 @@
|
|
|
17808
18069
|
});
|
|
17809
18070
|
return;
|
|
17810
18071
|
}
|
|
17811
|
-
P(h(
|
|
18072
|
+
P(h(InfiniteHits, {
|
|
17812
18073
|
cssClasses: cssClasses,
|
|
17813
18074
|
hits: hits,
|
|
17814
18075
|
results: results,
|
|
@@ -18741,7 +19002,7 @@
|
|
|
18741
19002
|
};
|
|
18742
19003
|
|
|
18743
19004
|
var _excluded$l = ["placesReference", "defaultPosition"],
|
|
18744
|
-
_excluded2$
|
|
19005
|
+
_excluded2$5 = ["places"];
|
|
18745
19006
|
/* Places.js is an optional dependency, no error should be reported if the package is missing */
|
|
18746
19007
|
/** @ts-ignore */
|
|
18747
19008
|
|
|
@@ -18797,7 +19058,7 @@
|
|
|
18797
19058
|
var hasPositionSet = position !== defaultPosition.join(',');
|
|
18798
19059
|
if (!hasPositionSet && !state.query) {
|
|
18799
19060
|
var places = uiState.places,
|
|
18800
|
-
uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$
|
|
19061
|
+
uiStateWithoutPlaces = _objectWithoutProperties(uiState, _excluded2$5);
|
|
18801
19062
|
return uiStateWithoutPlaces;
|
|
18802
19063
|
}
|
|
18803
19064
|
return _objectSpread2(_objectSpread2({}, uiState), {}, {
|
|
@@ -19012,10 +19273,17 @@
|
|
|
19012
19273
|
});
|
|
19013
19274
|
};
|
|
19014
19275
|
|
|
19276
|
+
// Strips leading `0` from a positive number value
|
|
19277
|
+
function stripLeadingZeroFromInput(value) {
|
|
19278
|
+
return value.replace(/^(0+)\d/, function (part) {
|
|
19279
|
+
return Number(part).toString();
|
|
19280
|
+
});
|
|
19281
|
+
}
|
|
19015
19282
|
var RangeInput = /*#__PURE__*/function (_Component) {
|
|
19016
19283
|
_inherits(RangeInput, _Component);
|
|
19017
19284
|
var _super = _createSuper(RangeInput);
|
|
19018
19285
|
function RangeInput() {
|
|
19286
|
+
var _this$props$values$mi, _this$props$values$ma;
|
|
19019
19287
|
var _this;
|
|
19020
19288
|
_classCallCheck(this, RangeInput);
|
|
19021
19289
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -19023,36 +19291,40 @@
|
|
|
19023
19291
|
}
|
|
19024
19292
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
19025
19293
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
19026
|
-
min: _this.props.values.min,
|
|
19027
|
-
max: _this.props.values.max
|
|
19294
|
+
min: (_this$props$values$mi = _this.props.values.min) === null || _this$props$values$mi === void 0 ? void 0 : _this$props$values$mi.toString(),
|
|
19295
|
+
max: (_this$props$values$ma = _this.props.values.max) === null || _this$props$values$ma === void 0 ? void 0 : _this$props$values$ma.toString()
|
|
19028
19296
|
});
|
|
19029
19297
|
_defineProperty(_assertThisInitialized(_this), "onInput", function (key) {
|
|
19030
19298
|
return function (event) {
|
|
19031
19299
|
var _ref = event.currentTarget,
|
|
19032
19300
|
value = _ref.value;
|
|
19033
|
-
_this.setState(_defineProperty({}, key,
|
|
19301
|
+
_this.setState(_defineProperty({}, key, value));
|
|
19034
19302
|
};
|
|
19035
19303
|
});
|
|
19036
19304
|
_defineProperty(_assertThisInitialized(_this), "onSubmit", function (event) {
|
|
19037
19305
|
event.preventDefault();
|
|
19038
|
-
_this
|
|
19306
|
+
var _this$state = _this.state,
|
|
19307
|
+
min = _this$state.min,
|
|
19308
|
+
max = _this$state.max;
|
|
19309
|
+
_this.props.refine([min ? Number(min) : undefined, max ? Number(max) : undefined]);
|
|
19039
19310
|
});
|
|
19040
19311
|
return _this;
|
|
19041
19312
|
}
|
|
19042
19313
|
_createClass(RangeInput, [{
|
|
19043
19314
|
key: "componentWillReceiveProps",
|
|
19044
19315
|
value: function componentWillReceiveProps(nextProps) {
|
|
19316
|
+
var _nextProps$values$min, _nextProps$values$max;
|
|
19045
19317
|
this.setState({
|
|
19046
|
-
min: nextProps.values.min,
|
|
19047
|
-
max: nextProps.values.max
|
|
19318
|
+
min: (_nextProps$values$min = nextProps.values.min) === null || _nextProps$values$min === void 0 ? void 0 : _nextProps$values$min.toString(),
|
|
19319
|
+
max: (_nextProps$values$max = nextProps.values.max) === null || _nextProps$values$max === void 0 ? void 0 : _nextProps$values$max.toString()
|
|
19048
19320
|
});
|
|
19049
19321
|
}
|
|
19050
19322
|
}, {
|
|
19051
19323
|
key: "render",
|
|
19052
19324
|
value: function render() {
|
|
19053
|
-
var _this$
|
|
19054
|
-
minValue = _this$
|
|
19055
|
-
maxValue = _this$
|
|
19325
|
+
var _this$state2 = this.state,
|
|
19326
|
+
minValue = _this$state2.min,
|
|
19327
|
+
maxValue = _this$state2.max;
|
|
19056
19328
|
var _this$props = this.props,
|
|
19057
19329
|
min = _this$props.min,
|
|
19058
19330
|
max = _this$props.max,
|
|
@@ -19075,7 +19347,7 @@
|
|
|
19075
19347
|
min: min,
|
|
19076
19348
|
max: max,
|
|
19077
19349
|
step: step,
|
|
19078
|
-
value: minValue !== null && minValue !== void 0 ? minValue : '',
|
|
19350
|
+
value: stripLeadingZeroFromInput(minValue !== null && minValue !== void 0 ? minValue : ''),
|
|
19079
19351
|
onInput: this.onInput('min'),
|
|
19080
19352
|
placeholder: min === null || min === void 0 ? void 0 : min.toString(),
|
|
19081
19353
|
disabled: isDisabled
|
|
@@ -19093,7 +19365,7 @@
|
|
|
19093
19365
|
min: min,
|
|
19094
19366
|
max: max,
|
|
19095
19367
|
step: step,
|
|
19096
|
-
value: maxValue !== null && maxValue !== void 0 ? maxValue : '',
|
|
19368
|
+
value: stripLeadingZeroFromInput(maxValue !== null && maxValue !== void 0 ? maxValue : ''),
|
|
19097
19369
|
onInput: this.onInput('max'),
|
|
19098
19370
|
placeholder: max === null || max === void 0 ? void 0 : max.toString(),
|
|
19099
19371
|
disabled: isDisabled
|
|
@@ -19296,10 +19568,16 @@
|
|
|
19296
19568
|
var Rheostat = /*#__PURE__*/function (_Component) {
|
|
19297
19569
|
_inherits(Rheostat, _Component);
|
|
19298
19570
|
var _super = _createSuper(Rheostat);
|
|
19299
|
-
function Rheostat(
|
|
19571
|
+
function Rheostat() {
|
|
19300
19572
|
var _this;
|
|
19301
19573
|
_classCallCheck(this, Rheostat);
|
|
19302
|
-
|
|
19574
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
19575
|
+
args[_key] = arguments[_key];
|
|
19576
|
+
}
|
|
19577
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
19578
|
+
_defineProperty(_assertThisInitialized(_this), "x", [0, 0].map(function (y) {
|
|
19579
|
+
return y;
|
|
19580
|
+
}));
|
|
19303
19581
|
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
19304
19582
|
className: getClassName(_this.props),
|
|
19305
19583
|
// non-null thanks to defaultProps
|
|
@@ -19314,44 +19592,14 @@
|
|
|
19314
19592
|
values: _this.props.values
|
|
19315
19593
|
});
|
|
19316
19594
|
_defineProperty(_assertThisInitialized(_this), "rheostat", y());
|
|
19317
|
-
|
|
19318
|
-
|
|
19319
|
-
_this.getProgressStyle = _this.getProgressStyle.bind(_assertThisInitialized(_this));
|
|
19320
|
-
_this.getMinValue = _this.getMinValue.bind(_assertThisInitialized(_this));
|
|
19321
|
-
_this.getMaxValue = _this.getMaxValue.bind(_assertThisInitialized(_this));
|
|
19322
|
-
_this.getHandleDimensions = _this.getHandleDimensions.bind(_assertThisInitialized(_this));
|
|
19323
|
-
_this.getClosestSnapPoint = _this.getClosestSnapPoint.bind(_assertThisInitialized(_this));
|
|
19324
|
-
_this.getSnapPosition = _this.getSnapPosition.bind(_assertThisInitialized(_this));
|
|
19325
|
-
_this.getNextPositionForKey = _this.getNextPositionForKey.bind(_assertThisInitialized(_this));
|
|
19326
|
-
_this.getNextState = _this.getNextState.bind(_assertThisInitialized(_this));
|
|
19327
|
-
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
|
|
19328
|
-
_this.getClosestHandle = _this.getClosestHandle.bind(_assertThisInitialized(_this));
|
|
19329
|
-
_this.setStartSlide = _this.setStartSlide.bind(_assertThisInitialized(_this));
|
|
19330
|
-
_this.startMouseSlide = _this.startMouseSlide.bind(_assertThisInitialized(_this));
|
|
19331
|
-
_this.startTouchSlide = _this.startTouchSlide.bind(_assertThisInitialized(_this));
|
|
19332
|
-
_this.handleMouseSlide = _this.handleMouseSlide.bind(_assertThisInitialized(_this));
|
|
19333
|
-
_this.handleTouchSlide = _this.handleTouchSlide.bind(_assertThisInitialized(_this));
|
|
19334
|
-
_this.handleSlide = _this.handleSlide.bind(_assertThisInitialized(_this));
|
|
19335
|
-
_this.endSlide = _this.endSlide.bind(_assertThisInitialized(_this));
|
|
19336
|
-
_this.handleKeydown = _this.handleKeydown.bind(_assertThisInitialized(_this));
|
|
19337
|
-
_this.validatePosition = _this.validatePosition.bind(_assertThisInitialized(_this));
|
|
19338
|
-
_this.validateValues = _this.validateValues.bind(_assertThisInitialized(_this));
|
|
19339
|
-
_this.canMove = _this.canMove.bind(_assertThisInitialized(_this));
|
|
19340
|
-
_this.fireChangeEvent = _this.fireChangeEvent.bind(_assertThisInitialized(_this));
|
|
19341
|
-
_this.slideTo = _this.slideTo.bind(_assertThisInitialized(_this));
|
|
19342
|
-
_this.updateNewValues = _this.updateNewValues.bind(_assertThisInitialized(_this));
|
|
19343
|
-
return _this;
|
|
19344
|
-
}
|
|
19345
|
-
_createClass(Rheostat, [{
|
|
19346
|
-
key: "componentWillReceiveProps",
|
|
19347
|
-
value: function componentWillReceiveProps(nextProps) {
|
|
19348
|
-
var _this$props = this.props,
|
|
19595
|
+
_defineProperty(_assertThisInitialized(_this), "componentWillReceiveProps", function (nextProps) {
|
|
19596
|
+
var _this$props = _this.props,
|
|
19349
19597
|
className = _this$props.className,
|
|
19350
19598
|
disabled = _this$props.disabled,
|
|
19351
19599
|
min = _this$props.min,
|
|
19352
19600
|
max = _this$props.max,
|
|
19353
19601
|
orientation = _this$props.orientation;
|
|
19354
|
-
var _this$state =
|
|
19602
|
+
var _this$state = _this.state,
|
|
19355
19603
|
values = _this$state.values,
|
|
19356
19604
|
slidingIndex = _this$state.slidingIndex;
|
|
19357
19605
|
var minMaxChanged = nextProps.min !== min || nextProps.max !== max;
|
|
@@ -19361,33 +19609,29 @@
|
|
|
19361
19609
|
var orientationChanged = nextProps.className !== className || nextProps.orientation !== orientation;
|
|
19362
19610
|
var willBeDisabled = nextProps.disabled && !disabled;
|
|
19363
19611
|
if (orientationChanged) {
|
|
19364
|
-
|
|
19612
|
+
_this.setState({
|
|
19365
19613
|
className: getClassName(nextProps)
|
|
19366
19614
|
});
|
|
19367
19615
|
}
|
|
19368
|
-
if (minMaxChanged || valuesChanged)
|
|
19616
|
+
if (minMaxChanged || valuesChanged) _this.updateNewValues(nextProps);
|
|
19369
19617
|
if (willBeDisabled && slidingIndex !== null) {
|
|
19370
|
-
|
|
19618
|
+
_this.endSlide();
|
|
19371
19619
|
}
|
|
19372
|
-
}
|
|
19373
|
-
|
|
19374
|
-
|
|
19375
|
-
value: function getPublicState() {
|
|
19376
|
-
var _this$props2 = this.props,
|
|
19620
|
+
});
|
|
19621
|
+
_defineProperty(_assertThisInitialized(_this), "getPublicState", function () {
|
|
19622
|
+
var _this$props2 = _this.props,
|
|
19377
19623
|
min = _this$props2.min,
|
|
19378
19624
|
max = _this$props2.max;
|
|
19379
|
-
var values =
|
|
19625
|
+
var values = _this.state.values;
|
|
19380
19626
|
return {
|
|
19381
19627
|
max: max,
|
|
19382
19628
|
min: min,
|
|
19383
19629
|
values: values
|
|
19384
19630
|
};
|
|
19385
|
-
}
|
|
19386
|
-
|
|
19387
|
-
key: "getSliderBoundingBox",
|
|
19388
|
-
value: function getSliderBoundingBox() {
|
|
19631
|
+
});
|
|
19632
|
+
_defineProperty(_assertThisInitialized(_this), "getSliderBoundingBox", function () {
|
|
19389
19633
|
// only gets called after render, so it will always be defined
|
|
19390
|
-
var node =
|
|
19634
|
+
var node = _this.rheostat.current;
|
|
19391
19635
|
var rect = node.getBoundingClientRect();
|
|
19392
19636
|
return {
|
|
19393
19637
|
height: rect.height || node.clientHeight,
|
|
@@ -19395,14 +19639,12 @@
|
|
|
19395
19639
|
top: rect.top,
|
|
19396
19640
|
width: rect.width || node.clientWidth
|
|
19397
19641
|
};
|
|
19398
|
-
}
|
|
19399
|
-
|
|
19400
|
-
|
|
19401
|
-
value: function getProgressStyle(idx) {
|
|
19402
|
-
var handlePos = this.state.handlePos;
|
|
19642
|
+
});
|
|
19643
|
+
_defineProperty(_assertThisInitialized(_this), "getProgressStyle", function (idx) {
|
|
19644
|
+
var handlePos = _this.state.handlePos;
|
|
19403
19645
|
var value = handlePos[idx];
|
|
19404
19646
|
if (idx === 0) {
|
|
19405
|
-
return
|
|
19647
|
+
return _this.props.orientation === 'vertical' ? {
|
|
19406
19648
|
height: "".concat(value, "%"),
|
|
19407
19649
|
top: 0
|
|
19408
19650
|
} : {
|
|
@@ -19412,63 +19654,51 @@
|
|
|
19412
19654
|
}
|
|
19413
19655
|
var prevValue = handlePos[idx - 1];
|
|
19414
19656
|
var diffValue = value - prevValue;
|
|
19415
|
-
return
|
|
19657
|
+
return _this.props.orientation === 'vertical' ? {
|
|
19416
19658
|
height: "".concat(diffValue, "%"),
|
|
19417
19659
|
top: "".concat(prevValue, "%")
|
|
19418
19660
|
} : {
|
|
19419
19661
|
left: "".concat(prevValue, "%"),
|
|
19420
19662
|
width: "".concat(diffValue, "%")
|
|
19421
19663
|
};
|
|
19422
|
-
}
|
|
19423
|
-
|
|
19424
|
-
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
|
|
19430
|
-
value: function getMaxValue(idx) {
|
|
19431
|
-
return this.state.values[idx + 1] ? Math.min(this.props.max, this.state.values[idx + 1]) : this.props.max;
|
|
19432
|
-
}
|
|
19433
|
-
}, {
|
|
19434
|
-
key: "getHandleDimensions",
|
|
19435
|
-
value: function getHandleDimensions(ev, sliderBox) {
|
|
19664
|
+
});
|
|
19665
|
+
_defineProperty(_assertThisInitialized(_this), "getMinValue", function (idx) {
|
|
19666
|
+
return _this.state.values[idx - 1] ? Math.max(_this.props.min, _this.state.values[idx - 1]) : _this.props.min;
|
|
19667
|
+
});
|
|
19668
|
+
_defineProperty(_assertThisInitialized(_this), "getMaxValue", function (idx) {
|
|
19669
|
+
return _this.state.values[idx + 1] ? Math.min(_this.props.max, _this.state.values[idx + 1]) : _this.props.max;
|
|
19670
|
+
});
|
|
19671
|
+
_defineProperty(_assertThisInitialized(_this), "getHandleDimensions", function (ev, sliderBox) {
|
|
19436
19672
|
var handleNode = ev.currentTarget || null;
|
|
19437
19673
|
if (!handleNode) return 0;
|
|
19438
|
-
return
|
|
19439
|
-
}
|
|
19440
|
-
|
|
19441
|
-
key: "getClosestSnapPoint",
|
|
19442
|
-
value: function getClosestSnapPoint(value) {
|
|
19674
|
+
return _this.props.orientation === 'vertical' ? handleNode.clientHeight / sliderBox.height * PERCENT_FULL / 2 : handleNode.clientWidth / sliderBox.width * PERCENT_FULL / 2;
|
|
19675
|
+
});
|
|
19676
|
+
_defineProperty(_assertThisInitialized(_this), "getClosestSnapPoint", function (value) {
|
|
19443
19677
|
// non-null thanks to defaultProps
|
|
19444
|
-
if (!
|
|
19445
|
-
return
|
|
19678
|
+
if (!_this.props.snapPoints.length) return value;
|
|
19679
|
+
return _this.props.snapPoints.reduce(function (snapTo, snap) {
|
|
19446
19680
|
return Math.abs(snapTo - value) < Math.abs(snap - value) ? snapTo : snap;
|
|
19447
19681
|
});
|
|
19448
|
-
}
|
|
19449
|
-
|
|
19450
|
-
|
|
19451
|
-
|
|
19452
|
-
if (!this.props.snap) return positionPercent;
|
|
19453
|
-
var _ref = this.props,
|
|
19682
|
+
});
|
|
19683
|
+
_defineProperty(_assertThisInitialized(_this), "getSnapPosition", function (positionPercent) {
|
|
19684
|
+
if (!_this.props.snap) return positionPercent;
|
|
19685
|
+
var _ref = _this.props,
|
|
19454
19686
|
max = _ref.max,
|
|
19455
19687
|
min = _ref.min;
|
|
19456
19688
|
var value = getValue$1(positionPercent, min, max);
|
|
19457
|
-
var snapValue =
|
|
19689
|
+
var snapValue = _this.getClosestSnapPoint(value);
|
|
19458
19690
|
return getPosition(snapValue, min, max);
|
|
19459
|
-
}
|
|
19460
|
-
|
|
19461
|
-
key: "getNextPositionForKey",
|
|
19462
|
-
value: function getNextPositionForKey(idx, keyCode) {
|
|
19691
|
+
});
|
|
19692
|
+
_defineProperty(_assertThisInitialized(_this), "getNextPositionForKey", function (idx, keyCode) {
|
|
19463
19693
|
var _stepMultiplier;
|
|
19464
|
-
var _this$state2 =
|
|
19694
|
+
var _this$state2 = _this.state,
|
|
19465
19695
|
handlePos = _this$state2.handlePos,
|
|
19466
19696
|
values = _this$state2.values;
|
|
19467
|
-
var _ref2 =
|
|
19697
|
+
var _ref2 = _this.props,
|
|
19468
19698
|
max = _ref2.max,
|
|
19469
19699
|
min = _ref2.min,
|
|
19470
19700
|
snapPoints = _ref2.snapPoints;
|
|
19471
|
-
var shouldSnap =
|
|
19701
|
+
var shouldSnap = _this.props.snap;
|
|
19472
19702
|
var proposedValue = values[idx];
|
|
19473
19703
|
var proposedPercentage = handlePos[idx];
|
|
19474
19704
|
var originalPercentage = proposedPercentage;
|
|
@@ -19480,7 +19710,7 @@
|
|
|
19480
19710
|
}
|
|
19481
19711
|
var currentIndex = null;
|
|
19482
19712
|
if (shouldSnap) {
|
|
19483
|
-
currentIndex = snapPoints.indexOf(
|
|
19713
|
+
currentIndex = snapPoints.indexOf(_this.getClosestSnapPoint(values[idx]));
|
|
19484
19714
|
}
|
|
19485
19715
|
var stepMultiplier = (_stepMultiplier = {}, _defineProperty(_stepMultiplier, KEYS.LEFT, function (v) {
|
|
19486
19716
|
return v * -1;
|
|
@@ -19522,15 +19752,13 @@
|
|
|
19522
19752
|
return null;
|
|
19523
19753
|
}
|
|
19524
19754
|
return shouldSnap ? getPosition(proposedValue, min, max) : proposedPercentage;
|
|
19525
|
-
}
|
|
19526
|
-
|
|
19527
|
-
|
|
19528
|
-
|
|
19529
|
-
var handlePos = this.state.handlePos;
|
|
19530
|
-
var _ref3 = this.props,
|
|
19755
|
+
});
|
|
19756
|
+
_defineProperty(_assertThisInitialized(_this), "getNextState", function (idx, proposedPosition) {
|
|
19757
|
+
var handlePos = _this.state.handlePos;
|
|
19758
|
+
var _ref3 = _this.props,
|
|
19531
19759
|
max = _ref3.max,
|
|
19532
19760
|
min = _ref3.min;
|
|
19533
|
-
var actualPosition =
|
|
19761
|
+
var actualPosition = _this.validatePosition(idx, proposedPosition);
|
|
19534
19762
|
var nextHandlePos = handlePos.map(function (pos, index) {
|
|
19535
19763
|
return index === idx ? actualPosition : pos;
|
|
19536
19764
|
});
|
|
@@ -19540,23 +19768,19 @@
|
|
|
19540
19768
|
return getValue$1(pos, min, max);
|
|
19541
19769
|
})
|
|
19542
19770
|
};
|
|
19543
|
-
}
|
|
19544
|
-
|
|
19545
|
-
|
|
19546
|
-
value: function getClosestHandle(positionPercent) {
|
|
19547
|
-
var handlePos = this.state.handlePos;
|
|
19771
|
+
});
|
|
19772
|
+
_defineProperty(_assertThisInitialized(_this), "getClosestHandle", function (positionPercent) {
|
|
19773
|
+
var handlePos = _this.state.handlePos;
|
|
19548
19774
|
return handlePos.reduce(function (closestIdx, _node, idx) {
|
|
19549
19775
|
var challenger = Math.abs(handlePos[idx] - positionPercent);
|
|
19550
19776
|
var current = Math.abs(handlePos[closestIdx] - positionPercent);
|
|
19551
19777
|
return challenger < current ? idx : closestIdx;
|
|
19552
19778
|
}, 0);
|
|
19553
|
-
}
|
|
19554
|
-
|
|
19555
|
-
|
|
19556
|
-
|
|
19557
|
-
|
|
19558
|
-
this.setState({
|
|
19559
|
-
handleDimensions: this.getHandleDimensions(ev, sliderBox),
|
|
19779
|
+
});
|
|
19780
|
+
_defineProperty(_assertThisInitialized(_this), "setStartSlide", function (ev, x, y) {
|
|
19781
|
+
var sliderBox = _this.getSliderBoundingBox();
|
|
19782
|
+
_this.setState({
|
|
19783
|
+
handleDimensions: _this.getHandleDimensions(ev, sliderBox),
|
|
19560
19784
|
mousePos: {
|
|
19561
19785
|
x: x,
|
|
19562
19786
|
y: y
|
|
@@ -19564,144 +19788,118 @@
|
|
|
19564
19788
|
sliderBox: sliderBox,
|
|
19565
19789
|
slidingIndex: getHandleFor(ev)
|
|
19566
19790
|
});
|
|
19567
|
-
}
|
|
19568
|
-
|
|
19569
|
-
|
|
19570
|
-
|
|
19571
|
-
|
|
19572
|
-
document.addEventListener('mousemove', this.handleMouseSlide, false);
|
|
19573
|
-
document.addEventListener('mouseup', this.endSlide, false);
|
|
19791
|
+
});
|
|
19792
|
+
_defineProperty(_assertThisInitialized(_this), "startMouseSlide", function (ev) {
|
|
19793
|
+
_this.setStartSlide(ev, ev.clientX, ev.clientY);
|
|
19794
|
+
document.addEventListener('mousemove', _this.handleMouseSlide, false);
|
|
19795
|
+
document.addEventListener('mouseup', _this.endSlide, false);
|
|
19574
19796
|
killEvent(ev);
|
|
19575
|
-
}
|
|
19576
|
-
|
|
19577
|
-
key: "startTouchSlide",
|
|
19578
|
-
value: function startTouchSlide(ev) {
|
|
19797
|
+
});
|
|
19798
|
+
_defineProperty(_assertThisInitialized(_this), "startTouchSlide", function (ev) {
|
|
19579
19799
|
if (ev.changedTouches.length > 1) return;
|
|
19580
19800
|
var touch = ev.changedTouches[0];
|
|
19581
|
-
|
|
19582
|
-
document.addEventListener('touchmove',
|
|
19583
|
-
document.addEventListener('touchend',
|
|
19584
|
-
if (
|
|
19801
|
+
_this.setStartSlide(ev, touch.clientX, touch.clientY);
|
|
19802
|
+
document.addEventListener('touchmove', _this.handleTouchSlide, false);
|
|
19803
|
+
document.addEventListener('touchend', _this.endSlide, false);
|
|
19804
|
+
if (_this.props.onSliderDragStart) _this.props.onSliderDragStart();
|
|
19585
19805
|
killEvent(ev);
|
|
19586
|
-
}
|
|
19587
|
-
|
|
19588
|
-
|
|
19589
|
-
|
|
19590
|
-
if (this.state.slidingIndex === null) return;
|
|
19591
|
-
this.handleSlide(ev.clientX, ev.clientY);
|
|
19806
|
+
});
|
|
19807
|
+
_defineProperty(_assertThisInitialized(_this), "handleMouseSlide", function (ev) {
|
|
19808
|
+
if (_this.state.slidingIndex === null) return;
|
|
19809
|
+
_this.handleSlide(ev.clientX, ev.clientY);
|
|
19592
19810
|
killEvent(ev);
|
|
19593
|
-
}
|
|
19594
|
-
|
|
19595
|
-
|
|
19596
|
-
value: function handleTouchSlide(ev) {
|
|
19597
|
-
if (this.state.slidingIndex === null) return;
|
|
19811
|
+
});
|
|
19812
|
+
_defineProperty(_assertThisInitialized(_this), "handleTouchSlide", function (ev) {
|
|
19813
|
+
if (_this.state.slidingIndex === null) return;
|
|
19598
19814
|
if (ev.changedTouches.length > 1) {
|
|
19599
|
-
|
|
19815
|
+
_this.endSlide();
|
|
19600
19816
|
return;
|
|
19601
19817
|
}
|
|
19602
19818
|
var touch = ev.changedTouches[0];
|
|
19603
|
-
|
|
19819
|
+
_this.handleSlide(touch.clientX, touch.clientY);
|
|
19604
19820
|
killEvent(ev);
|
|
19605
|
-
}
|
|
19606
|
-
|
|
19607
|
-
|
|
19608
|
-
value: function handleSlide(x, y) {
|
|
19609
|
-
var _this$state3 = this.state,
|
|
19821
|
+
});
|
|
19822
|
+
_defineProperty(_assertThisInitialized(_this), "handleSlide", function (x, y) {
|
|
19823
|
+
var _this$state3 = _this.state,
|
|
19610
19824
|
idx = _this$state3.slidingIndex,
|
|
19611
19825
|
sliderBox = _this$state3.sliderBox;
|
|
19612
|
-
var positionPercent =
|
|
19613
|
-
|
|
19614
|
-
if (
|
|
19826
|
+
var positionPercent = _this.props.orientation === 'vertical' ? (y - sliderBox.top) / sliderBox.height * PERCENT_FULL : (x - sliderBox.left) / sliderBox.width * PERCENT_FULL;
|
|
19827
|
+
_this.slideTo(idx, positionPercent);
|
|
19828
|
+
if (_this.canMove(idx, positionPercent)) {
|
|
19615
19829
|
// update mouse positions
|
|
19616
|
-
|
|
19830
|
+
_this.setState({
|
|
19617
19831
|
mousePos: {
|
|
19618
19832
|
x: x,
|
|
19619
19833
|
y: y
|
|
19620
19834
|
}
|
|
19621
19835
|
});
|
|
19622
|
-
if (
|
|
19836
|
+
if (_this.props.onSliderDragMove) _this.props.onSliderDragMove();
|
|
19623
19837
|
}
|
|
19624
|
-
}
|
|
19625
|
-
|
|
19626
|
-
|
|
19627
|
-
|
|
19628
|
-
var _this2 = this;
|
|
19629
|
-
var idx = this.state.slidingIndex;
|
|
19630
|
-
this.setState({
|
|
19838
|
+
});
|
|
19839
|
+
_defineProperty(_assertThisInitialized(_this), "endSlide", function () {
|
|
19840
|
+
var idx = _this.state.slidingIndex;
|
|
19841
|
+
_this.setState({
|
|
19631
19842
|
slidingIndex: null
|
|
19632
19843
|
});
|
|
19633
|
-
document.removeEventListener('mouseup',
|
|
19634
|
-
document.removeEventListener('touchend',
|
|
19635
|
-
document.removeEventListener('touchmove',
|
|
19636
|
-
document.removeEventListener('mousemove',
|
|
19637
|
-
if (
|
|
19638
|
-
if (
|
|
19639
|
-
var positionPercent =
|
|
19640
|
-
|
|
19641
|
-
return
|
|
19844
|
+
document.removeEventListener('mouseup', _this.endSlide, false);
|
|
19845
|
+
document.removeEventListener('touchend', _this.endSlide, false);
|
|
19846
|
+
document.removeEventListener('touchmove', _this.handleTouchSlide, false);
|
|
19847
|
+
document.removeEventListener('mousemove', _this.handleMouseSlide, false);
|
|
19848
|
+
if (_this.props.onSliderDragEnd) _this.props.onSliderDragEnd();
|
|
19849
|
+
if (_this.props.snap) {
|
|
19850
|
+
var positionPercent = _this.getSnapPosition(_this.state.handlePos[idx]);
|
|
19851
|
+
_this.slideTo(idx, positionPercent, function () {
|
|
19852
|
+
return _this.fireChangeEvent();
|
|
19642
19853
|
});
|
|
19643
19854
|
} else {
|
|
19644
|
-
|
|
19855
|
+
_this.fireChangeEvent();
|
|
19645
19856
|
}
|
|
19646
|
-
}
|
|
19647
|
-
|
|
19648
|
-
key: "handleClick",
|
|
19649
|
-
value: function handleClick(ev) {
|
|
19650
|
-
var _this3 = this;
|
|
19857
|
+
});
|
|
19858
|
+
_defineProperty(_assertThisInitialized(_this), "handleClick", function (ev) {
|
|
19651
19859
|
if (ev.target.getAttribute('data-handle-key')) {
|
|
19652
19860
|
return;
|
|
19653
19861
|
}
|
|
19654
19862
|
|
|
19655
19863
|
// Calculate the position of the slider on the page so we can determine
|
|
19656
19864
|
// the position where you click in relativity.
|
|
19657
|
-
var sliderBox =
|
|
19658
|
-
var positionDecimal =
|
|
19865
|
+
var sliderBox = _this.getSliderBoundingBox();
|
|
19866
|
+
var positionDecimal = _this.props.orientation === 'vertical' ? (ev.clientY - sliderBox.top) / sliderBox.height : (ev.clientX - sliderBox.left) / sliderBox.width;
|
|
19659
19867
|
var positionPercent = positionDecimal * PERCENT_FULL;
|
|
19660
|
-
var handleId =
|
|
19661
|
-
var validPositionPercent =
|
|
19868
|
+
var handleId = _this.getClosestHandle(positionPercent);
|
|
19869
|
+
var validPositionPercent = _this.getSnapPosition(positionPercent);
|
|
19662
19870
|
|
|
19663
19871
|
// Move the handle there
|
|
19664
|
-
|
|
19665
|
-
return
|
|
19872
|
+
_this.slideTo(handleId, validPositionPercent, function () {
|
|
19873
|
+
return _this.fireChangeEvent();
|
|
19666
19874
|
});
|
|
19667
|
-
if (
|
|
19668
|
-
}
|
|
19669
|
-
|
|
19670
|
-
key: "handleKeydown",
|
|
19671
|
-
value: function handleKeydown(ev) {
|
|
19672
|
-
var _this4 = this;
|
|
19875
|
+
if (_this.props.onClick) _this.props.onClick();
|
|
19876
|
+
});
|
|
19877
|
+
_defineProperty(_assertThisInitialized(_this), "handleKeydown", function (ev) {
|
|
19673
19878
|
var idx = getHandleFor(ev);
|
|
19674
19879
|
if (ev.keyCode === KEYS.ESC) {
|
|
19675
19880
|
ev.currentTarget.blur();
|
|
19676
19881
|
return;
|
|
19677
19882
|
}
|
|
19678
|
-
var proposedPercentage =
|
|
19883
|
+
var proposedPercentage = _this.getNextPositionForKey(idx, ev.keyCode);
|
|
19679
19884
|
if (proposedPercentage === null) return;
|
|
19680
|
-
if (
|
|
19681
|
-
|
|
19682
|
-
return
|
|
19885
|
+
if (_this.canMove(idx, proposedPercentage)) {
|
|
19886
|
+
_this.slideTo(idx, proposedPercentage, function () {
|
|
19887
|
+
return _this.fireChangeEvent();
|
|
19683
19888
|
});
|
|
19684
|
-
if (
|
|
19889
|
+
if (_this.props.onKeyPress) _this.props.onKeyPress();
|
|
19685
19890
|
}
|
|
19686
19891
|
killEvent(ev);
|
|
19687
|
-
}
|
|
19688
|
-
|
|
19689
|
-
|
|
19690
|
-
// does not collide with other handles too much.
|
|
19691
|
-
}, {
|
|
19692
|
-
key: "validatePosition",
|
|
19693
|
-
value: function validatePosition(idx, proposedPosition) {
|
|
19694
|
-
var _this$state4 = this.state,
|
|
19892
|
+
});
|
|
19893
|
+
_defineProperty(_assertThisInitialized(_this), "validatePosition", function (idx, proposedPosition) {
|
|
19894
|
+
var _this$state4 = _this.state,
|
|
19695
19895
|
handlePos = _this$state4.handlePos,
|
|
19696
19896
|
handleDimensions = _this$state4.handleDimensions;
|
|
19697
19897
|
return Math.max(Math.min(proposedPosition, handlePos[idx + 1] !== undefined ? handlePos[idx + 1] - handleDimensions : PERCENT_FULL // 100% is the highest value
|
|
19698
19898
|
), handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : PERCENT_EMPTY // 0% is the lowest value
|
|
19699
19899
|
);
|
|
19700
|
-
}
|
|
19701
|
-
|
|
19702
|
-
|
|
19703
|
-
value: function validateValues(proposedValues, props) {
|
|
19704
|
-
var _ref4 = props || this.props,
|
|
19900
|
+
});
|
|
19901
|
+
_defineProperty(_assertThisInitialized(_this), "validateValues", function (proposedValues, props) {
|
|
19902
|
+
var _ref4 = props || _this.props,
|
|
19705
19903
|
max = _ref4.max,
|
|
19706
19904
|
min = _ref4.min;
|
|
19707
19905
|
return proposedValues.map(function (value, idx, values) {
|
|
@@ -19711,11 +19909,9 @@
|
|
|
19711
19909
|
}
|
|
19712
19910
|
return realValue;
|
|
19713
19911
|
});
|
|
19714
|
-
}
|
|
19715
|
-
|
|
19716
|
-
|
|
19717
|
-
value: function canMove(idx, proposedPosition) {
|
|
19718
|
-
var _this$state5 = this.state,
|
|
19912
|
+
});
|
|
19913
|
+
_defineProperty(_assertThisInitialized(_this), "canMove", function (idx, proposedPosition) {
|
|
19914
|
+
var _this$state5 = _this.state,
|
|
19719
19915
|
handlePos = _this$state5.handlePos,
|
|
19720
19916
|
handleDimensions = _this$state5.handleDimensions;
|
|
19721
19917
|
if (proposedPosition < PERCENT_EMPTY) return false;
|
|
@@ -19725,29 +19921,21 @@
|
|
|
19725
19921
|
var prevHandlePosition = handlePos[idx - 1] !== undefined ? handlePos[idx - 1] + handleDimensions : -Infinity;
|
|
19726
19922
|
if (proposedPosition < prevHandlePosition) return false;
|
|
19727
19923
|
return true;
|
|
19728
|
-
}
|
|
19729
|
-
|
|
19730
|
-
|
|
19731
|
-
|
|
19732
|
-
|
|
19733
|
-
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
var _this5 = this;
|
|
19739
|
-
var nextState = this.getNextState(idx, proposedPosition);
|
|
19740
|
-
this.setState(nextState, function () {
|
|
19741
|
-
var onValuesUpdated = _this5.props.onValuesUpdated;
|
|
19742
|
-
if (onValuesUpdated) onValuesUpdated(_this5.getPublicState());
|
|
19924
|
+
});
|
|
19925
|
+
_defineProperty(_assertThisInitialized(_this), "fireChangeEvent", function () {
|
|
19926
|
+
var onChange = _this.props.onChange;
|
|
19927
|
+
if (onChange) onChange(_this.getPublicState());
|
|
19928
|
+
});
|
|
19929
|
+
_defineProperty(_assertThisInitialized(_this), "slideTo", function (idx, proposedPosition, onAfterSet) {
|
|
19930
|
+
var nextState = _this.getNextState(idx, proposedPosition);
|
|
19931
|
+
_this.setState(nextState, function () {
|
|
19932
|
+
var onValuesUpdated = _this.props.onValuesUpdated;
|
|
19933
|
+
if (onValuesUpdated) onValuesUpdated(_this.getPublicState());
|
|
19743
19934
|
if (onAfterSet) onAfterSet();
|
|
19744
19935
|
});
|
|
19745
|
-
}
|
|
19746
|
-
|
|
19747
|
-
|
|
19748
|
-
value: function updateNewValues(nextProps) {
|
|
19749
|
-
var _this6 = this;
|
|
19750
|
-
var slidingIndex = this.state.slidingIndex;
|
|
19936
|
+
});
|
|
19937
|
+
_defineProperty(_assertThisInitialized(_this), "updateNewValues", function (nextProps) {
|
|
19938
|
+
var slidingIndex = _this.state.slidingIndex;
|
|
19751
19939
|
|
|
19752
19940
|
// Don't update while the slider is sliding
|
|
19753
19941
|
if (slidingIndex !== null) {
|
|
@@ -19756,21 +19944,18 @@
|
|
|
19756
19944
|
var max = nextProps.max,
|
|
19757
19945
|
min = nextProps.min,
|
|
19758
19946
|
values = nextProps.values;
|
|
19759
|
-
var nextValues =
|
|
19760
|
-
|
|
19947
|
+
var nextValues = _this.validateValues(values, nextProps);
|
|
19948
|
+
_this.setState({
|
|
19761
19949
|
handlePos: nextValues.map(function (value) {
|
|
19762
19950
|
return getPosition(value, min, max);
|
|
19763
19951
|
}),
|
|
19764
19952
|
values: nextValues
|
|
19765
19953
|
}, function () {
|
|
19766
|
-
return
|
|
19954
|
+
return _this.fireChangeEvent();
|
|
19767
19955
|
});
|
|
19768
|
-
}
|
|
19769
|
-
|
|
19770
|
-
|
|
19771
|
-
value: function render() {
|
|
19772
|
-
var _this7 = this;
|
|
19773
|
-
var _ref5 = this.props,
|
|
19956
|
+
});
|
|
19957
|
+
_defineProperty(_assertThisInitialized(_this), "render", function () {
|
|
19958
|
+
var _ref5 = _this.props,
|
|
19774
19959
|
children = _ref5.children,
|
|
19775
19960
|
disabled = _ref5.disabled,
|
|
19776
19961
|
Handle = _ref5.handle,
|
|
@@ -19780,14 +19965,14 @@
|
|
|
19780
19965
|
PitComponent = _ref5.pitComponent,
|
|
19781
19966
|
pitPoints = _ref5.pitPoints,
|
|
19782
19967
|
ProgressBar = _ref5.progressBar; // all required thanks to defaultProps
|
|
19783
|
-
var _this$state6 =
|
|
19968
|
+
var _this$state6 = _this.state,
|
|
19784
19969
|
className = _this$state6.className,
|
|
19785
19970
|
handlePos = _this$state6.handlePos,
|
|
19786
19971
|
values = _this$state6.values;
|
|
19787
19972
|
return h("div", {
|
|
19788
19973
|
className: className,
|
|
19789
|
-
ref:
|
|
19790
|
-
onClick: disabled ? undefined :
|
|
19974
|
+
ref: _this.rheostat,
|
|
19975
|
+
onClick: disabled ? undefined : _this.handleClick,
|
|
19791
19976
|
style: {
|
|
19792
19977
|
position: 'relative'
|
|
19793
19978
|
}
|
|
@@ -19800,17 +19985,17 @@
|
|
|
19800
19985
|
position: 'absolute'
|
|
19801
19986
|
};
|
|
19802
19987
|
return h(Handle, {
|
|
19803
|
-
"aria-valuemax":
|
|
19804
|
-
"aria-valuemin":
|
|
19988
|
+
"aria-valuemax": _this.getMaxValue(idx),
|
|
19989
|
+
"aria-valuemin": _this.getMinValue(idx),
|
|
19805
19990
|
"aria-valuenow": values[idx],
|
|
19806
19991
|
"aria-disabled": disabled,
|
|
19807
19992
|
"data-handle-key": idx,
|
|
19808
19993
|
className: "rheostat-handle",
|
|
19809
19994
|
key: "handle-".concat(idx),
|
|
19810
19995
|
onClick: killEvent,
|
|
19811
|
-
onKeyDown: disabled ? undefined :
|
|
19812
|
-
onMouseDown: disabled ? undefined :
|
|
19813
|
-
onTouchStart: disabled ? undefined :
|
|
19996
|
+
onKeyDown: disabled ? undefined : _this.handleKeydown,
|
|
19997
|
+
onMouseDown: disabled ? undefined : _this.startMouseSlide,
|
|
19998
|
+
onTouchStart: disabled ? undefined : _this.startTouchSlide,
|
|
19814
19999
|
role: "slider",
|
|
19815
20000
|
style: handleStyle,
|
|
19816
20001
|
tabIndex: 0
|
|
@@ -19822,7 +20007,7 @@
|
|
|
19822
20007
|
return h(ProgressBar, {
|
|
19823
20008
|
className: "rheostat-progress",
|
|
19824
20009
|
key: "progress-bar-".concat(idx),
|
|
19825
|
-
style:
|
|
20010
|
+
style: _this.getProgressStyle(idx)
|
|
19826
20011
|
});
|
|
19827
20012
|
}), PitComponent && pitPoints.map(function (n) {
|
|
19828
20013
|
var pos = getPosition(n, min, max);
|
|
@@ -19838,9 +20023,10 @@
|
|
|
19838
20023
|
style: pitStyle
|
|
19839
20024
|
}, n);
|
|
19840
20025
|
}), children);
|
|
19841
|
-
}
|
|
19842
|
-
|
|
19843
|
-
|
|
20026
|
+
});
|
|
20027
|
+
return _this;
|
|
20028
|
+
}
|
|
20029
|
+
return _createClass(Rheostat);
|
|
19844
20030
|
}(d);
|
|
19845
20031
|
_defineProperty(Rheostat, "defaultProps", {
|
|
19846
20032
|
className: '',
|