vue-instantsearch 4.13.8 → 4.14.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.
Files changed (83) hide show
  1. package/package.json +8 -6
  2. package/src/components/Highlight.vue +1 -2
  3. package/src/components/Highlighter.js +69 -0
  4. package/src/components/Hits.js +113 -0
  5. package/src/components/Snippet.vue +1 -2
  6. package/src/components/__tests__/Hits.js +1 -1
  7. package/src/util/pragma.js +22 -0
  8. package/src/{components/Highlighter.vue → util/vue-compat/Highlighter/Highlighter-vue2.vue} +6 -9
  9. package/src/util/vue-compat/Highlighter/index-vue2.js +1 -0
  10. package/src/util/vue-compat/Highlighter/index-vue3.js +1 -0
  11. package/src/util/vue-compat/Highlighter/index.js +1 -0
  12. package/src/util/vue-compat/index-vue2.js +26 -1
  13. package/src/util/vue-compat/index-vue3.js +7 -0
  14. package/src/widgets.js +1 -1
  15. package/vue2/cjs/index.js +1 -1
  16. package/vue2/cjs/index.js.map +1 -1
  17. package/vue2/es/package.json.js +1 -1
  18. package/vue2/es/src/components/Highlight.vue_rollup-plugin-vue=script.js +1 -1
  19. package/vue2/es/src/components/Hits.js +2 -0
  20. package/vue2/es/src/components/Hits.js.map +1 -0
  21. package/vue2/es/src/components/Snippet.vue_rollup-plugin-vue=script.js +1 -1
  22. package/vue2/es/src/instantsearch.js +1 -1
  23. package/vue2/es/src/util/vue-compat/Highlighter/Highlighter-vue2.vue.js +2 -0
  24. package/vue2/es/src/util/vue-compat/Highlighter/Highlighter-vue2.vue.js.map +1 -0
  25. package/vue2/es/src/util/vue-compat/Highlighter/Highlighter-vue2.vue_rollup-plugin-vue=script.js +2 -0
  26. package/vue2/es/src/util/vue-compat/Highlighter/Highlighter-vue2.vue_rollup-plugin-vue=script.js.map +1 -0
  27. package/vue2/es/src/util/vue-compat/index-vue2.js +1 -1
  28. package/vue2/es/src/util/vue-compat/index-vue2.js.map +1 -1
  29. package/vue2/es/src/widgets.js +1 -1
  30. package/vue2/umd/index.js +1 -1
  31. package/vue2/umd/index.js.map +1 -1
  32. package/vue3/cjs/index.js +1 -1
  33. package/vue3/cjs/index.js.map +1 -1
  34. package/vue3/es/package.json.js +1 -1
  35. package/vue3/es/src/components/Highlight.vue.js +1 -1
  36. package/vue3/es/src/components/Highlight.vue_vue&type=script&lang.js +1 -1
  37. package/vue3/es/src/components/Highlight.vue_vue&type=script&lang.js.map +1 -1
  38. package/vue3/es/src/components/{Highlight.vue_vue&type=template&id=1d5c1fda&lang.js → Highlight.vue_vue&type=template&id=214ecb36&lang.js} +1 -1
  39. package/vue3/es/src/components/Highlight.vue_vue&type=template&id=214ecb36&lang.js.map +1 -0
  40. package/vue3/es/src/components/Highlighter.js +2 -0
  41. package/vue3/es/src/components/Highlighter.js.map +1 -0
  42. package/vue3/es/src/components/Hits.js +2 -0
  43. package/vue3/es/src/components/Hits.js.map +1 -0
  44. package/vue3/es/src/components/Snippet.vue.js +1 -1
  45. package/vue3/es/src/components/Snippet.vue_vue&type=script&lang.js +1 -1
  46. package/vue3/es/src/components/Snippet.vue_vue&type=script&lang.js.map +1 -1
  47. package/vue3/es/src/components/{Snippet.vue_vue&type=template&id=1e214b4c&lang.js → Snippet.vue_vue&type=template&id=edc35952&lang.js} +1 -1
  48. package/vue3/es/src/components/Snippet.vue_vue&type=template&id=edc35952&lang.js.map +1 -0
  49. package/vue3/es/src/instantsearch.js +1 -1
  50. package/vue3/es/src/util/pragma.js +2 -0
  51. package/vue3/es/src/util/pragma.js.map +1 -0
  52. package/vue3/es/src/util/vue-compat/index-vue3.js +1 -1
  53. package/vue3/es/src/util/vue-compat/index-vue3.js.map +1 -1
  54. package/vue3/es/src/widgets.js +1 -1
  55. package/vue3/umd/index.js +1 -1
  56. package/vue3/umd/index.js.map +1 -1
  57. package/src/components/Hits.vue +0 -72
  58. package/vue2/es/src/components/Highlighter.vue.js +0 -2
  59. package/vue2/es/src/components/Highlighter.vue.js.map +0 -1
  60. package/vue2/es/src/components/Highlighter.vue_rollup-plugin-vue=script.js +0 -2
  61. package/vue2/es/src/components/Highlighter.vue_rollup-plugin-vue=script.js.map +0 -1
  62. package/vue2/es/src/components/Hits.vue.js +0 -2
  63. package/vue2/es/src/components/Hits.vue.js.map +0 -1
  64. package/vue2/es/src/components/Hits.vue_rollup-plugin-vue=script.js +0 -2
  65. package/vue2/es/src/components/Hits.vue_rollup-plugin-vue=script.js.map +0 -1
  66. package/vue3/es/src/components/Highlight.vue_vue&type=template&id=1d5c1fda&lang.js.map +0 -1
  67. package/vue3/es/src/components/Highlighter.vue.js +0 -2
  68. package/vue3/es/src/components/Highlighter.vue.js.map +0 -1
  69. package/vue3/es/src/components/Highlighter.vue_vue&type=script&lang.js +0 -2
  70. package/vue3/es/src/components/Highlighter.vue_vue&type=script&lang.js.map +0 -1
  71. package/vue3/es/src/components/Highlighter.vue_vue&type=template&id=f822f802&lang.js +0 -2
  72. package/vue3/es/src/components/Highlighter.vue_vue&type=template&id=f822f802&lang.js.map +0 -1
  73. package/vue3/es/src/components/Hits.vue.js +0 -2
  74. package/vue3/es/src/components/Hits.vue.js.map +0 -1
  75. package/vue3/es/src/components/Hits.vue_vue&type=script&lang.js +0 -2
  76. package/vue3/es/src/components/Hits.vue_vue&type=script&lang.js.map +0 -1
  77. package/vue3/es/src/components/Hits.vue_vue&type=template&id=026646d2&lang.js +0 -2
  78. package/vue3/es/src/components/Hits.vue_vue&type=template&id=026646d2&lang.js.map +0 -1
  79. package/vue3/es/src/components/Snippet.vue_vue&type=template&id=1e214b4c&lang.js.map +0 -1
  80. package/vue3/es/src/util/parseAlgoliaHit.js +0 -2
  81. package/vue3/es/src/util/parseAlgoliaHit.js.map +0 -1
  82. package/vue3/es/src/util/unescape.js +0 -2
  83. package/vue3/es/src/util/unescape.js.map +0 -1
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "autocomplete"
17
17
  ],
18
18
  "license": "MIT",
19
- "version": "4.13.8",
19
+ "version": "4.14.0",
20
20
  "files": [
21
21
  "vue2",
22
22
  "vue3",
@@ -32,10 +32,12 @@
32
32
  "storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006 -c .storybook",
33
33
  "storybook:build": "NODE_OPTIONS=--openssl-legacy-provider build-storybook -c .storybook -o ../../website/stories/vue",
34
34
  "test:exports": "node ./test/module/vue2/is-es-module.mjs && node ./test/module/vue2/is-cjs-module.cjs",
35
- "test:exports:vue3": "node ./test/module/vue3/is-es-module.mjs && node ./test/module/vue3/is-cjs-module.cjs"
35
+ "test:exports:vue3": "node ./test/module/vue3/is-es-module.mjs && node ./test/module/vue3/is-cjs-module.cjs",
36
+ "watch:es": "yarn --silent build --watch"
36
37
  },
37
38
  "dependencies": {
38
- "instantsearch.js": "4.65.0",
39
+ "instantsearch-ui-components": "0.4.0",
40
+ "instantsearch.js": "4.66.0",
39
41
  "mitt": "^2.1.0"
40
42
  },
41
43
  "peerDependencies": {
@@ -59,8 +61,8 @@
59
61
  "@vue/server-renderer": "3.2.47",
60
62
  "@vue/test-utils": "1.3.0",
61
63
  "@vue/test-utils2": "npm:@vue/test-utils@2.0.0-rc.11",
62
- "algoliasearch": "4.14.3",
63
- "algoliasearch-helper": "3.16.2",
64
+ "algoliasearch": "4.22.1",
65
+ "algoliasearch-helper": "3.16.3",
64
66
  "instantsearch.css": "8.1.0",
65
67
  "rollup": "1.32.1",
66
68
  "rollup-plugin-babel": "4.4.0",
@@ -87,5 +89,5 @@
87
89
  "vuex": "3.5.1",
88
90
  "vuex4": "npm:vuex@4.0.0"
89
91
  },
90
- "gitHead": "084aff3d29e15cea8125076c46fb753c83d4dcad"
92
+ "gitHead": "358f849cba15cbbb415da05feb582b47358aa239"
91
93
  }
@@ -12,8 +12,7 @@
12
12
 
13
13
  <script>
14
14
  import { createSuitMixin } from '../mixins/suit';
15
-
16
- import AisHighlighter from './Highlighter.vue';
15
+ import AisHighlighter from '../util/vue-compat/Highlighter';
17
16
 
18
17
  export default {
19
18
  name: 'AisHighlight',
@@ -0,0 +1,69 @@
1
+ import { createHighlightComponent } from 'instantsearch-ui-components';
2
+ import {
3
+ getHighlightedParts,
4
+ getPropertyByPath,
5
+ unescape,
6
+ } from 'instantsearch.js/es/lib/utils';
7
+
8
+ import { createElement, Fragment } from '../util/pragma';
9
+
10
+ const Highlight = createHighlightComponent({ createElement, Fragment });
11
+
12
+ export default {
13
+ name: 'AisHighlighter',
14
+ props: {
15
+ hit: {
16
+ type: Object,
17
+ required: true,
18
+ },
19
+ attribute: {
20
+ type: String,
21
+ required: true,
22
+ },
23
+ highlightedTagName: {
24
+ type: String,
25
+ default: 'mark',
26
+ },
27
+ suit: {
28
+ type: Function,
29
+ required: true,
30
+ },
31
+ highlightProperty: {
32
+ type: String,
33
+ required: true,
34
+ },
35
+ preTag: {
36
+ type: String,
37
+ required: true,
38
+ },
39
+ postTag: {
40
+ type: String,
41
+ required: true,
42
+ },
43
+ },
44
+ render() {
45
+ const property =
46
+ getPropertyByPath(this.hit[this.highlightProperty], this.attribute) || [];
47
+ const properties = Array.isArray(property) ? property : [property];
48
+
49
+ const parts = properties.map((singleValue) =>
50
+ getHighlightedParts(unescape(singleValue.value || '')).map(
51
+ ({ value, isHighlighted }) => ({
52
+ // We have to do this because Vue gets rid of TextNodes with a single white space
53
+ value: value === ' ' ? ' ' : value,
54
+ isHighlighted,
55
+ })
56
+ )
57
+ );
58
+
59
+ return createElement(Highlight, {
60
+ classNames: {
61
+ root: this.suit(),
62
+ highlighted: this.suit('highlighted'),
63
+ },
64
+ highlightedTagName: this.highlightedTagName,
65
+ nonHighlightedTagName: Fragment,
66
+ parts,
67
+ });
68
+ },
69
+ };
@@ -0,0 +1,113 @@
1
+ import { createHitsComponent } from 'instantsearch-ui-components';
2
+ import { connectHitsWithInsights } from 'instantsearch.js/es/connectors';
3
+
4
+ import { createSuitMixin } from '../mixins/suit';
5
+ import { createWidgetMixin } from '../mixins/widget';
6
+ import { getScopedSlot, renderCompat } from '../util/vue-compat';
7
+
8
+ export default {
9
+ name: 'AisHits',
10
+ mixins: [
11
+ createWidgetMixin(
12
+ {
13
+ connector: connectHitsWithInsights,
14
+ },
15
+ {
16
+ $$widgetType: 'ais.hits',
17
+ }
18
+ ),
19
+ createSuitMixin({ name: 'Hits' }),
20
+ ],
21
+ props: {
22
+ escapeHTML: {
23
+ type: Boolean,
24
+ default: true,
25
+ },
26
+ transformItems: {
27
+ type: Function,
28
+ default: undefined,
29
+ },
30
+ },
31
+ computed: {
32
+ items() {
33
+ return this.state.hits;
34
+ },
35
+ widgetParams() {
36
+ return {
37
+ escapeHTML: this.escapeHTML,
38
+ transformItems: this.transformItems,
39
+ };
40
+ },
41
+ },
42
+ render: renderCompat(function (h) {
43
+ if (!this.state) {
44
+ return null;
45
+ }
46
+
47
+ const defaultSlot = getScopedSlot(this, 'default');
48
+ const itemSlot = getScopedSlot(this, 'item');
49
+
50
+ const itemComponent = ({
51
+ hit,
52
+ index,
53
+ onClick,
54
+ onAuxClick,
55
+ // We don't want to pass the Preact key as a prop
56
+ key: _key,
57
+ ...rootProps
58
+ }) => {
59
+ return h(
60
+ 'li',
61
+ {
62
+ key: hit.objectID,
63
+ attrs: rootProps,
64
+ on: {
65
+ click: onClick,
66
+ auxclick: onAuxClick,
67
+ },
68
+ },
69
+ [
70
+ (itemSlot &&
71
+ itemSlot({
72
+ item: hit,
73
+ index,
74
+ insights: this.state.insights,
75
+ sendEvent: this.state.sendEvent,
76
+ })) ||
77
+ `objectID: ${hit.objectID}, index: ${index}`,
78
+ ]
79
+ );
80
+ };
81
+
82
+ // We only want to render the default slot
83
+ // if no other slots are defined
84
+ if (!itemSlot && defaultSlot) {
85
+ return h(
86
+ 'div',
87
+ {
88
+ attrs: {
89
+ class: this.suit(),
90
+ },
91
+ },
92
+ [
93
+ defaultSlot({
94
+ items: this.state.hits,
95
+ insights: this.state.insights,
96
+ sendEvent: this.state.sendEvent,
97
+ }),
98
+ ]
99
+ );
100
+ }
101
+
102
+ return h(createHitsComponent({ createElement: h }), {
103
+ hits: this.state.hits,
104
+ itemComponent,
105
+ sendEvent: this.state.sendEvent,
106
+ classNames: this.classNames && {
107
+ root: this.classNames['ais-Hits'],
108
+ list: this.classNames['ais-Hits-list'],
109
+ item: this.classNames['ais-Hits-item'],
110
+ },
111
+ });
112
+ }),
113
+ };
@@ -12,8 +12,7 @@
12
12
 
13
13
  <script>
14
14
  import { createSuitMixin } from '../mixins/suit';
15
-
16
- import AisHighlighter from './Highlighter.vue';
15
+ import AisHighlighter from '../util/vue-compat/Highlighter';
17
16
 
18
17
  export default {
19
18
  name: 'AisSnippet',
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { mount } from '../../../test/utils';
6
6
  import { __setState } from '../../mixins/widget';
7
- import Hits from '../Hits.vue';
7
+ import Hits from '../Hits';
8
8
  import '../../../test/utils/sortedHtmlSerializer';
9
9
 
10
10
  jest.mock('../../mixins/widget');
@@ -0,0 +1,22 @@
1
+ import { h, Fragment } from 'vue';
2
+
3
+ export const createElement = (tag, props, children) => {
4
+ if (!children) {
5
+ return h(tag, props);
6
+ }
7
+
8
+ if (tag === Fragment) {
9
+ return h(tag, Array.isArray(children) ? children : [children]);
10
+ }
11
+
12
+ // It does work to just pass a string but outputs a warning about performance issues
13
+ const newChildren =
14
+ typeof children === 'string' ? { default: () => children } : children;
15
+ // Passing a `children` prop to a DOM element outputs a warning
16
+ const newProps =
17
+ typeof tag === 'string' ? props : Object.assign(props, { children });
18
+
19
+ return h(tag, newProps, newChildren);
20
+ };
21
+
22
+ export { Fragment };
@@ -11,16 +11,13 @@
11
11
  </template>
12
12
 
13
13
  <script>
14
- import { parseAlgoliaHit } from '../util/parseAlgoliaHit';
15
- import { getDefaultSlot, renderCompat, isVue3 } from '../util/vue-compat';
14
+ import { parseAlgoliaHit } from '../../parseAlgoliaHit';
16
15
 
17
- const TextNode = isVue3
18
- ? (props, context) => context.slots.default()
19
- : {
20
- render: renderCompat(function () {
21
- return getDefaultSlot(this);
22
- }),
23
- };
16
+ const TextNode = {
17
+ render() {
18
+ return this.$slots.default;
19
+ },
20
+ };
24
21
 
25
22
  export default {
26
23
  name: 'AisHighlighter',
@@ -0,0 +1 @@
1
+ export { default } from './Highlighter-vue2.vue';
@@ -0,0 +1 @@
1
+ export { default } from '../../../components/Highlighter';
@@ -0,0 +1 @@
1
+ export { default } from './index-vue2';
@@ -7,9 +7,30 @@ const version = Vue.version;
7
7
 
8
8
  export { Vue, Vue2, isVue2, isVue3, version };
9
9
 
10
+ const augmentCreateElement =
11
+ (createElement) =>
12
+ (tag, propsWithClassName = {}, children) => {
13
+ const { className, ...props } = propsWithClassName;
14
+
15
+ if (typeof tag === 'function') {
16
+ return tag(
17
+ Object.assign(props, {
18
+ class: className || props.class,
19
+ children,
20
+ })
21
+ );
22
+ }
23
+
24
+ return createElement(
25
+ tag,
26
+ Object.assign(props, { class: className || props.class }),
27
+ [children]
28
+ );
29
+ };
30
+
10
31
  export function renderCompat(fn) {
11
32
  return function (createElement) {
12
- return fn.call(this, createElement);
33
+ return fn.call(this, augmentCreateElement(createElement));
13
34
  };
14
35
  }
15
36
 
@@ -17,6 +38,10 @@ export function getDefaultSlot(component) {
17
38
  return component.$slots.default;
18
39
  }
19
40
 
41
+ export function getScopedSlot(component, name) {
42
+ return (component.$scopedSlots || {})[name];
43
+ }
44
+
20
45
  // Vue3-only APIs
21
46
  export const computed = undefined;
22
47
  export const createApp = undefined;
@@ -30,6 +30,9 @@ export function renderCompat(fn) {
30
30
  delete flatProps.props;
31
31
  delete flatProps.scopedSlots;
32
32
  onPropKeys.forEach((key) => delete flatProps.on[key]);
33
+ if (flatProps.on && Object.keys(flatProps.on).length === 0) {
34
+ delete flatProps.on;
35
+ }
33
36
 
34
37
  return Vue.h(
35
38
  tag,
@@ -59,3 +62,7 @@ export function getDefaultSlot(component) {
59
62
  // Vue 3 with @vue/compat
60
63
  return $slots.default;
61
64
  }
65
+
66
+ export function getScopedSlot(component, name) {
67
+ return (component.$slots || component.slots || {})[name];
68
+ }
package/src/widgets.js CHANGED
@@ -6,7 +6,7 @@ export { default as AisExperimentalConfigureRelatedItems } from './components/Co
6
6
  export { default as AisCurrentRefinements } from './components/CurrentRefinements.vue';
7
7
  export { default as AisHierarchicalMenu } from './components/HierarchicalMenu.vue';
8
8
  export { default as AisHighlight } from './components/Highlight.vue';
9
- export { default as AisHits } from './components/Hits.vue';
9
+ export { default as AisHits } from './components/Hits';
10
10
  export { default as AisHitsPerPage } from './components/HitsPerPage.vue';
11
11
  export { default as AisIndex } from './components/Index';
12
12
  export { default as AisInstantSearch } from './components/InstantSearch';