@mindful-web/marko-web-search 1.0.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/.eslintignore +1 -0
- package/LICENSE +21 -0
- package/browser/.eslintrc.js +1 -0
- package/browser/index.js +9 -0
- package/browser/sort-select.vue +37 -0
- package/browser/toggle-filter-button.vue +69 -0
- package/browser/toggle-filters-button.vue +87 -0
- package/components/build-href.marko +14 -0
- package/components/build-href.marko.js +46 -0
- package/components/filters/content-types.marko +12 -0
- package/components/filters/content-types.marko.js +40 -0
- package/components/filters/filter-block.marko +66 -0
- package/components/filters/filter-block.marko.js +151 -0
- package/components/filters/filter-container.marko +29 -0
- package/components/filters/filter-container.marko.js +85 -0
- package/components/filters/load-website-sections.js +69 -0
- package/components/filters/marko.json +36 -0
- package/components/filters/selected/index.marko +51 -0
- package/components/filters/selected/index.marko.js +113 -0
- package/components/filters/selected/item.marko +27 -0
- package/components/filters/selected/item.marko.js +101 -0
- package/components/filters/selected/marko.json +8 -0
- package/components/filters/website-sections-by-alias.marko +46 -0
- package/components/filters/website-sections-by-alias.marko.js +139 -0
- package/components/filters/website-sections.marko +42 -0
- package/components/filters/website-sections.marko.js +123 -0
- package/components/form/index.marko +23 -0
- package/components/form/index.marko.js +79 -0
- package/components/form/input.marko +8 -0
- package/components/form/input.marko.js +30 -0
- package/components/form/marko.json +10 -0
- package/components/links/link.marko +14 -0
- package/components/links/link.marko.js +47 -0
- package/components/links/marko.json +17 -0
- package/components/links/next-page.marko +25 -0
- package/components/links/next-page.marko.js +59 -0
- package/components/links/previous-page.marko +25 -0
- package/components/links/previous-page.marko.js +59 -0
- package/components/links/reset-filter.marko +24 -0
- package/components/links/reset-filter.marko.js +55 -0
- package/components/links/set-filter-value.marko +45 -0
- package/components/links/set-filter-value.marko.js +86 -0
- package/components/marko.json +25 -0
- package/components/pagination-controls.marko +42 -0
- package/components/pagination-controls.marko.js +108 -0
- package/components/query-child-sections.marko +24 -0
- package/components/query-child-sections.marko.js +60 -0
- package/components/query.marko +30 -0
- package/components/query.marko.js +67 -0
- package/components/sort-by/index.marko +25 -0
- package/components/sort-by/index.marko.js +72 -0
- package/components/sort-by/marko.json +5 -0
- package/config/index.js +84 -0
- package/config/param.js +69 -0
- package/config/query-params.js +101 -0
- package/index.js +113 -0
- package/loaders/search.js +108 -0
- package/marko.json +6 -0
- package/middleware.js +9 -0
- package/package.json +32 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Compiled using marko@4.20.2 - DO NOT EDIT
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-search$1.0.0/components/links/set-filter-value.marko",
|
|
6
|
+
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
7
|
+
module_defaultValue = require("@mindful-web/marko-core/utils/default-value"),
|
|
8
|
+
defaultValue = module_defaultValue.default || module_defaultValue,
|
|
9
|
+
marko_dynamicTag = require("marko/dist/runtime/helpers/dynamic-tag"),
|
|
10
|
+
marko_web_search_link_template = require("./link.marko"),
|
|
11
|
+
marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
|
|
12
|
+
marko_web_search_link_tag = marko_loadTag(marko_web_search_link_template);
|
|
13
|
+
|
|
14
|
+
function render(input, out, __component, component, state) {
|
|
15
|
+
var data = input;
|
|
16
|
+
|
|
17
|
+
const { isArray } = Array;
|
|
18
|
+
|
|
19
|
+
const { $markoWebSearch: search } = out.global;
|
|
20
|
+
|
|
21
|
+
const { name } = input;
|
|
22
|
+
|
|
23
|
+
const { value } = input;
|
|
24
|
+
|
|
25
|
+
const v = search.isArrayParam(name) && !isArray(value) ? [value] : value;
|
|
26
|
+
|
|
27
|
+
const resetPage = defaultValue(input.resetPage, true);
|
|
28
|
+
|
|
29
|
+
const queryValues = {
|
|
30
|
+
[name]: v,
|
|
31
|
+
...(resetPage && { page: 1 }),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const resetValues = {
|
|
35
|
+
...queryValues,
|
|
36
|
+
[name]: null,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const isSelected = search.isInputValueSelectedFor(name, v);
|
|
40
|
+
|
|
41
|
+
if (isSelected) {
|
|
42
|
+
marko_web_search_link_tag({
|
|
43
|
+
path: input.path,
|
|
44
|
+
queryValues: resetValues,
|
|
45
|
+
class: input.resetClass,
|
|
46
|
+
target: input.target,
|
|
47
|
+
rel: input.rel,
|
|
48
|
+
attrs: input.attrs,
|
|
49
|
+
renderBody: function(out) {
|
|
50
|
+
marko_dynamicTag(out, input.renderBody, function() {
|
|
51
|
+
return {
|
|
52
|
+
"is-selected": false
|
|
53
|
+
};
|
|
54
|
+
}, null, null, null, __component, "1");
|
|
55
|
+
}
|
|
56
|
+
}, out, __component, "0");
|
|
57
|
+
} else {
|
|
58
|
+
marko_web_search_link_tag({
|
|
59
|
+
path: input.path,
|
|
60
|
+
queryValues: queryValues,
|
|
61
|
+
class: input.class,
|
|
62
|
+
target: input.target,
|
|
63
|
+
rel: input.rel,
|
|
64
|
+
attrs: input.attrs,
|
|
65
|
+
renderBody: function(out) {
|
|
66
|
+
marko_dynamicTag(out, input.renderBody, function() {
|
|
67
|
+
return {
|
|
68
|
+
"is-selected": false
|
|
69
|
+
};
|
|
70
|
+
}, null, null, null, __component, "3");
|
|
71
|
+
}
|
|
72
|
+
}, out, __component, "2");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
marko_template._ = marko_renderer(render, {
|
|
77
|
+
d_: true,
|
|
78
|
+
e_: marko_componentType
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
marko_template.meta = {
|
|
82
|
+
id: "/@mindful-web/marko-web-search$1.0.0/components/links/set-filter-value.marko",
|
|
83
|
+
tags: [
|
|
84
|
+
"./link.marko"
|
|
85
|
+
]
|
|
86
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"taglib-imports": [
|
|
3
|
+
"./filters/marko.json",
|
|
4
|
+
"./form/marko.json",
|
|
5
|
+
"./links/marko.json",
|
|
6
|
+
"./sort-by/marko.json"
|
|
7
|
+
],
|
|
8
|
+
"<marko-web-search-build-href>": {
|
|
9
|
+
"template": "./build-href.marko",
|
|
10
|
+
"@path": "string",
|
|
11
|
+
"@query-values": "object"
|
|
12
|
+
},
|
|
13
|
+
"<marko-web-search-query>": {
|
|
14
|
+
"template": "./query.marko"
|
|
15
|
+
},
|
|
16
|
+
"<marko-web-search-pagination-controls>": {
|
|
17
|
+
"template": "./pagination-controls.marko",
|
|
18
|
+
"<block>": {},
|
|
19
|
+
"<link>": {},
|
|
20
|
+
"@total-count": "number"
|
|
21
|
+
},
|
|
22
|
+
"<marko-web-search-query-child-sections>": {
|
|
23
|
+
"template": "./query-child-sections.marko"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import defaultValue from "@mindful-web/marko-core/utils/default-value";
|
|
2
|
+
import { get } from "@mindful-web/object-path";
|
|
3
|
+
import { isFunction } from '@mindful-web/utils';
|
|
4
|
+
|
|
5
|
+
$ const { $markoWebSearch: search, i18n } = out.global;
|
|
6
|
+
$ const totalCount = defaultValue(input.totalCount, 0);
|
|
7
|
+
$ const linkClasses = get(input.link, "class");
|
|
8
|
+
|
|
9
|
+
$ const blockName = "marko-web-search-pagination-controls";
|
|
10
|
+
|
|
11
|
+
<if(totalCount)>
|
|
12
|
+
<marko-web-block ...input.block name=blockName>
|
|
13
|
+
<marko-web-search-previous-page-link
|
|
14
|
+
...input.link
|
|
15
|
+
class=`${linkClasses} ${blockName}__prev`
|
|
16
|
+
/>
|
|
17
|
+
|
|
18
|
+
<marko-web-element block-name=blockName name="pages">
|
|
19
|
+
$ const currentPage = search.getCurrentPage();
|
|
20
|
+
$ const totalPages = search.getTotalPages(totalCount);
|
|
21
|
+
<if(input.renderBody)>
|
|
22
|
+
<!-- custom rendering -->
|
|
23
|
+
<${input.renderBody} current-page=currentPage total-pages=totalPages />
|
|
24
|
+
</if>
|
|
25
|
+
<else>
|
|
26
|
+
<!-- default rendering -->
|
|
27
|
+
<if(isFunction(i18n))>
|
|
28
|
+
${i18n("Page")} ${currentPage} ${i18n("of")} ${totalPages}
|
|
29
|
+
</if>
|
|
30
|
+
<else>
|
|
31
|
+
Page ${currentPage} of ${totalPages}
|
|
32
|
+
</else>
|
|
33
|
+
</else>
|
|
34
|
+
</marko-web-element>
|
|
35
|
+
|
|
36
|
+
<marko-web-search-next-page-link
|
|
37
|
+
...input.link
|
|
38
|
+
class=`${linkClasses} ${blockName}__next`
|
|
39
|
+
total-count=totalCount
|
|
40
|
+
/>
|
|
41
|
+
</marko-web-block>
|
|
42
|
+
</if>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Compiled using marko@4.20.2 - DO NOT EDIT
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-search$1.0.0/components/pagination-controls.marko",
|
|
6
|
+
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
7
|
+
module_defaultValue = require("@mindful-web/marko-core/utils/default-value"),
|
|
8
|
+
defaultValue = module_defaultValue.default || module_defaultValue,
|
|
9
|
+
module_objectPath_module = require("@mindful-web/object-path"),
|
|
10
|
+
objectPath_module = module_objectPath_module.default || module_objectPath_module,
|
|
11
|
+
get = module_objectPath_module.get,
|
|
12
|
+
module_utils_module = require("@mindful-web/utils"),
|
|
13
|
+
utils_module = module_utils_module.default || module_utils_module,
|
|
14
|
+
isFunction = module_utils_module.isFunction,
|
|
15
|
+
marko_assign = require("marko/dist/runtime/helpers/assign"),
|
|
16
|
+
marko_web_search_previous_page_link_template = require("./links/previous-page.marko"),
|
|
17
|
+
marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
|
|
18
|
+
marko_web_search_previous_page_link_tag = marko_loadTag(marko_web_search_previous_page_link_template),
|
|
19
|
+
marko_dynamicTag = require("marko/dist/runtime/helpers/dynamic-tag"),
|
|
20
|
+
helpers_escape_xml = require("marko/dist/runtime/html/helpers/escape-xml"),
|
|
21
|
+
marko_escapeXml = helpers_escape_xml.x,
|
|
22
|
+
marko_web_element_template = require("@mindful-web/marko-web/components/element/index.marko"),
|
|
23
|
+
marko_web_element_tag = marko_loadTag(marko_web_element_template),
|
|
24
|
+
marko_web_search_next_page_link_template = require("./links/next-page.marko"),
|
|
25
|
+
marko_web_search_next_page_link_tag = marko_loadTag(marko_web_search_next_page_link_template),
|
|
26
|
+
marko_web_block_template = require("@mindful-web/marko-web/components/element/block.marko"),
|
|
27
|
+
marko_web_block_tag = marko_loadTag(marko_web_block_template);
|
|
28
|
+
|
|
29
|
+
function render(input, out, __component, component, state) {
|
|
30
|
+
var data = input;
|
|
31
|
+
|
|
32
|
+
const { $markoWebSearch: search, i18n } = out.global;
|
|
33
|
+
|
|
34
|
+
const totalCount = defaultValue(input.totalCount, 0);
|
|
35
|
+
|
|
36
|
+
const linkClasses = get(input.link, "class");
|
|
37
|
+
|
|
38
|
+
const blockName = "marko-web-search-pagination-controls";
|
|
39
|
+
|
|
40
|
+
if (totalCount) {
|
|
41
|
+
marko_web_block_tag(marko_assign({
|
|
42
|
+
name: "block",
|
|
43
|
+
tag: "div"
|
|
44
|
+
}, input.block, {
|
|
45
|
+
name: blockName,
|
|
46
|
+
renderBody: function(out) {
|
|
47
|
+
marko_web_search_previous_page_link_tag(marko_assign({}, input.link, {
|
|
48
|
+
class: ((linkClasses + " ") + blockName) + "__prev"
|
|
49
|
+
}), out, __component, "1");
|
|
50
|
+
|
|
51
|
+
marko_web_element_tag({
|
|
52
|
+
name: "pages",
|
|
53
|
+
tag: "div",
|
|
54
|
+
blockName: blockName,
|
|
55
|
+
renderBody: function(out) {
|
|
56
|
+
const currentPage = search.getCurrentPage();
|
|
57
|
+
|
|
58
|
+
const totalPages = search.getTotalPages(totalCount);
|
|
59
|
+
|
|
60
|
+
if (input.renderBody) {
|
|
61
|
+
marko_dynamicTag(out, input.renderBody, function() {
|
|
62
|
+
return {
|
|
63
|
+
"current-page": currentPage,
|
|
64
|
+
"total-pages": totalPages
|
|
65
|
+
};
|
|
66
|
+
}, null, null, null, __component, "3");
|
|
67
|
+
} else {
|
|
68
|
+
if (isFunction(i18n)) {
|
|
69
|
+
out.w(marko_escapeXml(i18n("Page")) +
|
|
70
|
+
" " +
|
|
71
|
+
marko_escapeXml(currentPage) +
|
|
72
|
+
" " +
|
|
73
|
+
marko_escapeXml(i18n("of")) +
|
|
74
|
+
" " +
|
|
75
|
+
marko_escapeXml(totalPages));
|
|
76
|
+
} else {
|
|
77
|
+
out.w("Page " +
|
|
78
|
+
marko_escapeXml(currentPage) +
|
|
79
|
+
" of " +
|
|
80
|
+
marko_escapeXml(totalPages));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}, out, __component, "2");
|
|
85
|
+
|
|
86
|
+
marko_web_search_next_page_link_tag(marko_assign({}, input.link, {
|
|
87
|
+
class: ((linkClasses + " ") + blockName) + "__next",
|
|
88
|
+
totalCount: totalCount
|
|
89
|
+
}), out, __component, "4");
|
|
90
|
+
}
|
|
91
|
+
}), out, __component, "0");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
marko_template._ = marko_renderer(render, {
|
|
96
|
+
d_: true,
|
|
97
|
+
e_: marko_componentType
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
marko_template.meta = {
|
|
101
|
+
id: "/@mindful-web/marko-web-search$1.0.0/components/pagination-controls.marko",
|
|
102
|
+
tags: [
|
|
103
|
+
"./links/previous-page.marko",
|
|
104
|
+
"@mindful-web/marko-web/components/element/index.marko",
|
|
105
|
+
"./links/next-page.marko",
|
|
106
|
+
"@mindful-web/marko-web/components/element/block.marko"
|
|
107
|
+
]
|
|
108
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import gql from "graphql-tag";
|
|
2
|
+
import { getAsArray } from "@mindful-web/object-path";
|
|
3
|
+
|
|
4
|
+
$ const queryFragment = gql`
|
|
5
|
+
fragment MarkoWebSearchChildSectionsFragment on WebsiteSection {
|
|
6
|
+
id
|
|
7
|
+
children(input: { pagination: { limit: 100 }, sort: { field: name, order: asc } }) {
|
|
8
|
+
edges {
|
|
9
|
+
node {
|
|
10
|
+
id
|
|
11
|
+
name
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
<marko-web-query-website-sections|{ nodes }|
|
|
19
|
+
include-ids=input.parentId
|
|
20
|
+
query-fragment=queryFragment
|
|
21
|
+
>
|
|
22
|
+
$ const edges = getAsArray(nodes[0], "children.edges");
|
|
23
|
+
<${input.renderBody} nodes=edges.map(edge => edge.node) />
|
|
24
|
+
</marko-web-query-website-sections>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Compiled using marko@4.20.2 - DO NOT EDIT
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-search$1.0.0/components/query-child-sections.marko",
|
|
6
|
+
marko_component = require("./query-child-sections.marko"),
|
|
7
|
+
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
8
|
+
module_gql = require("graphql-tag"),
|
|
9
|
+
gql = module_gql.default || module_gql,
|
|
10
|
+
module_objectPath_module = require("@mindful-web/object-path"),
|
|
11
|
+
objectPath_module = module_objectPath_module.default || module_objectPath_module,
|
|
12
|
+
getAsArray = module_objectPath_module.getAsArray,
|
|
13
|
+
marko_dynamicTag = require("marko/dist/runtime/helpers/dynamic-tag"),
|
|
14
|
+
marko_web_query_website_sections_template = require("@mindful-web/marko-core/components/queries/website-sections.marko"),
|
|
15
|
+
marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
|
|
16
|
+
marko_web_query_website_sections_tag = marko_loadTag(marko_web_query_website_sections_template);
|
|
17
|
+
|
|
18
|
+
function render(input, out, __component, component, state) {
|
|
19
|
+
var data = input;
|
|
20
|
+
|
|
21
|
+
const queryFragment = gql`
|
|
22
|
+
fragment MarkoWebSearchChildSectionsFragment on WebsiteSection {
|
|
23
|
+
id
|
|
24
|
+
children(input: { pagination: { limit: 100 }, sort: { field: name, order: asc } }) {
|
|
25
|
+
edges {
|
|
26
|
+
node {
|
|
27
|
+
id
|
|
28
|
+
name
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
marko_web_query_website_sections_tag({
|
|
36
|
+
includeIds: input.parentId,
|
|
37
|
+
queryFragment: queryFragment,
|
|
38
|
+
renderBody: function(out, { nodes }) {
|
|
39
|
+
const edges = getAsArray(nodes[0], "children.edges");
|
|
40
|
+
|
|
41
|
+
marko_dynamicTag(out, input.renderBody, function() {
|
|
42
|
+
return {
|
|
43
|
+
nodes: edges.map(edge => edge.node)
|
|
44
|
+
};
|
|
45
|
+
}, null, null, null, __component, "1");
|
|
46
|
+
}
|
|
47
|
+
}, out, __component, "0");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
marko_template._ = marko_renderer(render, {
|
|
51
|
+
e_: marko_componentType
|
|
52
|
+
}, marko_component);
|
|
53
|
+
|
|
54
|
+
marko_template.meta = {
|
|
55
|
+
id: "/@mindful-web/marko-web-search$1.0.0/components/query-child-sections.marko",
|
|
56
|
+
component: "./query-child-sections.marko",
|
|
57
|
+
tags: [
|
|
58
|
+
"@mindful-web/marko-core/components/queries/website-sections.marko"
|
|
59
|
+
]
|
|
60
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import loader from "../loaders/search";
|
|
2
|
+
|
|
3
|
+
$ const {
|
|
4
|
+
apollo: apolloMindfulWebCMS,
|
|
5
|
+
$baseBrowse: apolloBaseBrowse,
|
|
6
|
+
config,
|
|
7
|
+
site
|
|
8
|
+
} = out.global;
|
|
9
|
+
$ const { assignedToWebsiteSectionIds } = input;
|
|
10
|
+
|
|
11
|
+
$ const params = {
|
|
12
|
+
limit: input.limit,
|
|
13
|
+
skip: input.skip,
|
|
14
|
+
searchQuery: input.searchQuery,
|
|
15
|
+
sortField: input.sortField,
|
|
16
|
+
sortOrder: input.sortOrder,
|
|
17
|
+
contentTypes: input.contentTypes,
|
|
18
|
+
countryCodes: input.countryCodes,
|
|
19
|
+
...(assignedToWebsiteSectionIds && assignedToWebsiteSectionIds.length
|
|
20
|
+
? { assignedToWebsiteSectionIds }
|
|
21
|
+
: { assignedToWebsiteSiteIds: [config.website("id")] }
|
|
22
|
+
),
|
|
23
|
+
queryFragment: input.queryFragment,
|
|
24
|
+
opSuffix: input.opSuffix,
|
|
25
|
+
searchType: site.get('search.type'),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
<marko-web-resolve|{ resolved }| promise=loader({ apolloMindfulWebCMS, apolloBaseBrowse }, params)>
|
|
29
|
+
<${input.renderBody} ...resolved />
|
|
30
|
+
</marko-web-resolve>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Compiled using marko@4.20.2 - DO NOT EDIT
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-search$1.0.0/components/query.marko",
|
|
6
|
+
marko_component = require("./query.marko"),
|
|
7
|
+
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
8
|
+
module_loader = require("../loaders/search"),
|
|
9
|
+
loader = module_loader.default || module_loader,
|
|
10
|
+
marko_dynamicTag = require("marko/dist/runtime/helpers/dynamic-tag"),
|
|
11
|
+
marko_web_resolve_template = require("@mindful-web/marko-core/components/resolve.marko"),
|
|
12
|
+
marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
|
|
13
|
+
marko_web_resolve_tag = marko_loadTag(marko_web_resolve_template);
|
|
14
|
+
|
|
15
|
+
function render(input, out, __component, component, state) {
|
|
16
|
+
var data = input;
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
apollo: apolloMindfulWebCMS,
|
|
20
|
+
$baseBrowse: apolloBaseBrowse,
|
|
21
|
+
config,
|
|
22
|
+
site
|
|
23
|
+
} = out.global;
|
|
24
|
+
|
|
25
|
+
const { assignedToWebsiteSectionIds } = input;
|
|
26
|
+
|
|
27
|
+
const params = {
|
|
28
|
+
limit: input.limit,
|
|
29
|
+
skip: input.skip,
|
|
30
|
+
searchQuery: input.searchQuery,
|
|
31
|
+
sortField: input.sortField,
|
|
32
|
+
sortOrder: input.sortOrder,
|
|
33
|
+
contentTypes: input.contentTypes,
|
|
34
|
+
countryCodes: input.countryCodes,
|
|
35
|
+
...(assignedToWebsiteSectionIds && assignedToWebsiteSectionIds.length
|
|
36
|
+
? { assignedToWebsiteSectionIds }
|
|
37
|
+
: { assignedToWebsiteSiteIds: [config.website("id")] }
|
|
38
|
+
),
|
|
39
|
+
queryFragment: input.queryFragment,
|
|
40
|
+
opSuffix: input.opSuffix,
|
|
41
|
+
searchType: site.get('search.type'),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
marko_web_resolve_tag({
|
|
45
|
+
promise: loader({
|
|
46
|
+
apolloMindfulWebCMS: apolloMindfulWebCMS,
|
|
47
|
+
apolloBaseBrowse: apolloBaseBrowse
|
|
48
|
+
}, params),
|
|
49
|
+
renderBody: function(out, { resolved }) {
|
|
50
|
+
marko_dynamicTag(out, input.renderBody, function() {
|
|
51
|
+
return resolved;
|
|
52
|
+
}, null, null, null, __component, "1");
|
|
53
|
+
}
|
|
54
|
+
}, out, __component, "0");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
marko_template._ = marko_renderer(render, {
|
|
58
|
+
e_: marko_componentType
|
|
59
|
+
}, marko_component);
|
|
60
|
+
|
|
61
|
+
marko_template.meta = {
|
|
62
|
+
id: "/@mindful-web/marko-web-search$1.0.0/components/query.marko",
|
|
63
|
+
component: "./query.marko",
|
|
64
|
+
tags: [
|
|
65
|
+
"@mindful-web/marko-core/components/resolve.marko"
|
|
66
|
+
]
|
|
67
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { get, getAsArray, getAsObject } from "@mindful-web/object-path";
|
|
2
|
+
import { dasherize } from "@mindful-web/inflector";
|
|
3
|
+
import { isFunction } from '@mindful-web/utils';
|
|
4
|
+
|
|
5
|
+
$ const { $markoWebSearch: search, i18n } = out.global;
|
|
6
|
+
|
|
7
|
+
$ const blockName = "marko-web-search-sort-by";
|
|
8
|
+
$ const options = isFunction(i18n) ? [
|
|
9
|
+
{ id: 'PUBLISHED', label: `${i18n("Sort")}: ${i18n("Published")}` },
|
|
10
|
+
{ id: 'SCORE', label: `${i18n("Sort")}: ${i18n("Relevancy")}` },
|
|
11
|
+
] : [
|
|
12
|
+
{ id: 'PUBLISHED', label: "Sort: Published" },
|
|
13
|
+
{ id: 'SCORE', label: "Sort: Relevancy" },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
<marko-web-block name=blockName modifiers=input.modifiers>
|
|
17
|
+
$ const { searchQuery, sortField } = search.input;
|
|
18
|
+
$ const selectedId = sortField;
|
|
19
|
+
<if(searchQuery)>
|
|
20
|
+
<marko-web-browser-component
|
|
21
|
+
name="MarkoWebSearchSortSelect"
|
|
22
|
+
props={ options, selectedId }
|
|
23
|
+
/>
|
|
24
|
+
</if>
|
|
25
|
+
</marko-web-block>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Compiled using marko@4.20.2 - DO NOT EDIT
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var marko_template = module.exports = require("marko/dist/html").t(__filename),
|
|
5
|
+
marko_componentType = "/@mindful-web/marko-web-search$1.0.0/components/sort-by/index.marko",
|
|
6
|
+
marko_renderer = require("marko/dist/runtime/components/renderer"),
|
|
7
|
+
module_objectPath_module = require("@mindful-web/object-path"),
|
|
8
|
+
objectPath_module = module_objectPath_module.default || module_objectPath_module,
|
|
9
|
+
get = module_objectPath_module.get,
|
|
10
|
+
getAsArray = module_objectPath_module.getAsArray,
|
|
11
|
+
getAsObject = module_objectPath_module.getAsObject,
|
|
12
|
+
module_inflector_module = require("@mindful-web/inflector"),
|
|
13
|
+
inflector_module = module_inflector_module.default || module_inflector_module,
|
|
14
|
+
dasherize = module_inflector_module.dasherize,
|
|
15
|
+
module_utils_module = require("@mindful-web/utils"),
|
|
16
|
+
utils_module = module_utils_module.default || module_utils_module,
|
|
17
|
+
isFunction = module_utils_module.isFunction,
|
|
18
|
+
marko_web_browser_component_template = require("@mindful-web/marko-web/components/browser-component.marko"),
|
|
19
|
+
marko_loadTag = require("marko/dist/runtime/helpers/load-tag"),
|
|
20
|
+
marko_web_browser_component_tag = marko_loadTag(marko_web_browser_component_template),
|
|
21
|
+
marko_web_block_template = require("@mindful-web/marko-web/components/element/block.marko"),
|
|
22
|
+
marko_web_block_tag = marko_loadTag(marko_web_block_template);
|
|
23
|
+
|
|
24
|
+
function render(input, out, __component, component, state) {
|
|
25
|
+
var data = input;
|
|
26
|
+
|
|
27
|
+
const { $markoWebSearch: search, i18n } = out.global;
|
|
28
|
+
|
|
29
|
+
const blockName = "marko-web-search-sort-by";
|
|
30
|
+
|
|
31
|
+
const options = isFunction(i18n) ? [
|
|
32
|
+
{ id: 'PUBLISHED', label: `${i18n("Sort")}: ${i18n("Published")}` },
|
|
33
|
+
{ id: 'SCORE', label: `${i18n("Sort")}: ${i18n("Relevancy")}` },
|
|
34
|
+
] : [
|
|
35
|
+
{ id: 'PUBLISHED', label: "Sort: Published" },
|
|
36
|
+
{ id: 'SCORE', label: "Sort: Relevancy" },
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
marko_web_block_tag({
|
|
40
|
+
name: blockName,
|
|
41
|
+
tag: "div",
|
|
42
|
+
modifiers: input.modifiers,
|
|
43
|
+
renderBody: function(out) {
|
|
44
|
+
const { searchQuery, sortField } = search.input;
|
|
45
|
+
|
|
46
|
+
const selectedId = sortField;
|
|
47
|
+
|
|
48
|
+
if (searchQuery) {
|
|
49
|
+
marko_web_browser_component_tag({
|
|
50
|
+
name: "MarkoWebSearchSortSelect",
|
|
51
|
+
props: {
|
|
52
|
+
options: options,
|
|
53
|
+
selectedId: selectedId
|
|
54
|
+
}
|
|
55
|
+
}, out, __component, "1");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, out, __component, "0");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
marko_template._ = marko_renderer(render, {
|
|
62
|
+
d_: true,
|
|
63
|
+
e_: marko_componentType
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
marko_template.meta = {
|
|
67
|
+
id: "/@mindful-web/marko-web-search$1.0.0/components/sort-by/index.marko",
|
|
68
|
+
tags: [
|
|
69
|
+
"@mindful-web/marko-web/components/browser-component.marko",
|
|
70
|
+
"@mindful-web/marko-web/components/element/block.marko"
|
|
71
|
+
]
|
|
72
|
+
};
|
package/config/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const Joi = require('@parameter1/joi');
|
|
2
|
+
const { validate } = require('@parameter1/joi/utils');
|
|
3
|
+
const { getDefaultContentTypes } = require('@mindful-web/utils');
|
|
4
|
+
const { titleize, underscore } = require('@mindful-web/inflector');
|
|
5
|
+
const MarkoWebSearchQueryParamConfig = require('./query-params');
|
|
6
|
+
|
|
7
|
+
const defaultContentTypes = getDefaultContentTypes();
|
|
8
|
+
|
|
9
|
+
class MarkoWebSearchConfig {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {object} params
|
|
13
|
+
*
|
|
14
|
+
* @param {object} [params.resultsPerPage=10] The results per page setting.
|
|
15
|
+
* @param {number} [params.resultsPerPage.min=1]
|
|
16
|
+
* @param {number} [params.resultsPerPage.max=100]
|
|
17
|
+
* @param {number} [params.resultsPerPage.default=20]
|
|
18
|
+
*
|
|
19
|
+
* @param {string[]} [params.contentTypes] The allowed content type filters. Defaults to all.
|
|
20
|
+
* Should be provided as an array of classified content
|
|
21
|
+
* type strings, e.g. ['Article', 'MediaGallery'] etc.
|
|
22
|
+
*
|
|
23
|
+
* @param {object[]} [params.assignedToWebsiteSectionIds] The allowed website section filters.
|
|
24
|
+
* Defaults to none. Should be an array of
|
|
25
|
+
* section IDs, e.g. [123, 321]
|
|
26
|
+
*
|
|
27
|
+
* @param {string} [params.rootAlias] The root alias for the search page defaults to 'search'
|
|
28
|
+
*/
|
|
29
|
+
constructor(params = {}) {
|
|
30
|
+
const {
|
|
31
|
+
resultsPerPage,
|
|
32
|
+
contentTypes,
|
|
33
|
+
assignedToWebsiteSectionIds,
|
|
34
|
+
defaultSortField,
|
|
35
|
+
rootAlias,
|
|
36
|
+
} = validate(Joi.object({
|
|
37
|
+
resultsPerPage: Joi.object({
|
|
38
|
+
min: Joi.number().integer().default(1),
|
|
39
|
+
max: Joi.number().integer().default(100),
|
|
40
|
+
default: Joi.number().integer().default(20),
|
|
41
|
+
}).default(),
|
|
42
|
+
|
|
43
|
+
contentTypes: Joi.array().items(Joi.alternatives().try(
|
|
44
|
+
Joi.string().trim().allow(...defaultContentTypes),
|
|
45
|
+
Joi.object({
|
|
46
|
+
type: Joi.string().trim().allow(...defaultContentTypes),
|
|
47
|
+
label: Joi.string().trim(),
|
|
48
|
+
}),
|
|
49
|
+
)).default(defaultContentTypes),
|
|
50
|
+
|
|
51
|
+
assignedToWebsiteSectionIds: Joi.array().items(
|
|
52
|
+
Joi.number().integer().min(1).required(),
|
|
53
|
+
).default([]),
|
|
54
|
+
|
|
55
|
+
defaultSortField: Joi.string().allow('NAME', 'PUBLISHED', 'SCORE').default('PUBLISHED'),
|
|
56
|
+
|
|
57
|
+
rootAlias: Joi.string().default('search'),
|
|
58
|
+
}).default(), params);
|
|
59
|
+
|
|
60
|
+
this.contentTypeObjects = contentTypes.sort().map((type) => (type.label ? ({
|
|
61
|
+
id: underscore(type.type).toUpperCase(),
|
|
62
|
+
label: type.label,
|
|
63
|
+
}) : ({
|
|
64
|
+
id: underscore(type).toUpperCase(),
|
|
65
|
+
label: titleize(type),
|
|
66
|
+
})));
|
|
67
|
+
|
|
68
|
+
this.contentTypeObjectMap = this.contentTypeObjects.reduce((map, type) => {
|
|
69
|
+
map.set(type.id, type);
|
|
70
|
+
return map;
|
|
71
|
+
}, new Map());
|
|
72
|
+
|
|
73
|
+
this.assignedToWebsiteSectionIds = assignedToWebsiteSectionIds;
|
|
74
|
+
|
|
75
|
+
this.queryParams = new MarkoWebSearchQueryParamConfig({
|
|
76
|
+
resultsPerPage,
|
|
77
|
+
contentTypeIds: this.contentTypeObjects.map(({ id }) => id),
|
|
78
|
+
defaultSortField,
|
|
79
|
+
});
|
|
80
|
+
this.rootAlias = rootAlias;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = MarkoWebSearchConfig;
|