@fluid-topics/ft-search-context 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ft-search-context.d.ts +4 -1
- package/build/ft-search-context.js +16 -0
- package/build/ft-search-context.light.js +3 -3
- package/build/ft-search-context.min.js +21 -17
- package/build/store/FtSearchStateManager.d.ts +5 -1
- package/build/store/FtSearchStateManager.js +30 -9
- package/package.json +5 -5
|
@@ -2,7 +2,7 @@ import { PropertyValues } from "lit";
|
|
|
2
2
|
import { ElementDefinitionsMap, FtLitElementRedux } from "@fluid-topics/ft-wc-utils";
|
|
3
3
|
import { FtSearchContextProperties } from "./ft-search-context.properties";
|
|
4
4
|
import { FtSearchComponentInterface, FtSearchResultsChangeEventDetail } from "./registration";
|
|
5
|
-
import { FtSearchFilter, FtSearchRequest, FtSearchResultsPageInfo, FtSearchSortCriterion, FtSpellcheck } from "@fluid-topics/public-api";
|
|
5
|
+
import { FtSearchFilter, FtSearchRequest, FtSearchResultsPageInfo, FtSearchScope, FtSearchSortCriterion, FtSpellcheck } from "@fluid-topics/public-api";
|
|
6
6
|
export declare class LoadErrorEvent extends CustomEvent<Error> {
|
|
7
7
|
constructor(e: Error);
|
|
8
8
|
}
|
|
@@ -19,6 +19,8 @@ export declare class FtSearchContext extends FtLitElementRedux implements FtSear
|
|
|
19
19
|
contentLocale?: string;
|
|
20
20
|
pageSize: number;
|
|
21
21
|
searchInDocumentTitlesOnly: boolean;
|
|
22
|
+
scope?: FtSearchScope;
|
|
23
|
+
ignoreEmptyQuery: boolean;
|
|
22
24
|
filters: FtSearchFilter[];
|
|
23
25
|
sort: FtSearchSortCriterion[];
|
|
24
26
|
private request?;
|
|
@@ -36,4 +38,5 @@ export declare class FtSearchContext extends FtLitElementRedux implements FtSear
|
|
|
36
38
|
register(component: FtSearchComponentInterface): void;
|
|
37
39
|
private handleLoadError;
|
|
38
40
|
reloadSavedSearches(): void;
|
|
41
|
+
clear(): void;
|
|
39
42
|
}
|
|
@@ -40,6 +40,7 @@ class FtSearchContext extends FtLitElementRedux {
|
|
|
40
40
|
this.query = "";
|
|
41
41
|
this.pageSize = 20;
|
|
42
42
|
this.searchInDocumentTitlesOnly = false;
|
|
43
|
+
this.ignoreEmptyQuery = false;
|
|
43
44
|
this.filters = [];
|
|
44
45
|
this.sort = [];
|
|
45
46
|
this.addStore(ftAppInfoStore);
|
|
@@ -72,6 +73,12 @@ class FtSearchContext extends FtLitElementRedux {
|
|
|
72
73
|
if (props.has("searchInDocumentTitlesOnly") && this.searchInDocumentTitlesOnly !== undefined) {
|
|
73
74
|
this.stateManager.setSearchInDocumentTitlesOnly(this.searchInDocumentTitlesOnly);
|
|
74
75
|
}
|
|
76
|
+
if (props.has("scope") && this.scope !== undefined) {
|
|
77
|
+
this.stateManager.setScope(this.scope);
|
|
78
|
+
}
|
|
79
|
+
if (props.has("ignoreEmptyQuery") && this.ignoreEmptyQuery !== undefined) {
|
|
80
|
+
this.stateManager.setIgnoreEmptyQuery(this.ignoreEmptyQuery);
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
83
|
connectedCallback() {
|
|
77
84
|
super.connectedCallback();
|
|
@@ -105,6 +112,9 @@ class FtSearchContext extends FtLitElementRedux {
|
|
|
105
112
|
reloadSavedSearches() {
|
|
106
113
|
userAssetsActions.clearMySearches();
|
|
107
114
|
}
|
|
115
|
+
clear() {
|
|
116
|
+
this.stateManager.clear();
|
|
117
|
+
}
|
|
108
118
|
}
|
|
109
119
|
FtSearchContext.elementDefinitions = {};
|
|
110
120
|
FtSearchContext.styles = styles;
|
|
@@ -120,6 +130,12 @@ __decorate([
|
|
|
120
130
|
__decorate([
|
|
121
131
|
property({ type: Boolean })
|
|
122
132
|
], FtSearchContext.prototype, "searchInDocumentTitlesOnly", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
property()
|
|
135
|
+
], FtSearchContext.prototype, "scope", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
property({ type: Boolean })
|
|
138
|
+
], FtSearchContext.prototype, "ignoreEmptyQuery", void 0);
|
|
123
139
|
__decorate([
|
|
124
140
|
jsonProperty([])
|
|
125
141
|
], FtSearchContext.prototype, "filters", void 0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
!function(t,s,i,e){const n=i.css`
|
|
2
|
-
`,r={setRequest:(t,s)=>{t.request=s.payload},setRequestQuery:(t,s)=>{t.request.query=s.payload},setRequestContentLocale:(t,s)=>{t.request.contentLocale=s.payload},setPageSize:(t,s)=>{t.request.paging.perPage=s.payload},setPageNumber:(t,s)=>{t.request.paging.page=s.payload},setRequestSort:(t,s)=>{t.request.sort=s.payload},setRequestFilters:(t,s)=>{t.request.filters=s.payload},setRequestFacets:(t,s)=>{t.request.facets=s.payload},setRequestVirtualField:(t,s)=>{t.request.virtualField=s.payload},setRequestScope:(t,s)=>{t.request.scope=s.payload},setResults:(t,s)=>{t.results=s.payload},setFacets:(t,s)=>{t.facets=s.payload},setSpellcheck:(t,s)=>{t.spellcheck=s.payload},setLocales:(t,s)=>{t.locales=s.payload},setPaging:(t,s)=>{t.paging=s.payload},setLiveQuery:(t,s)=>{t.liveQuery=s.payload},setSuggestResults:(t,s)=>{t.suggestResults=s.payload}};var o,a,h,c,u,l,f,d,v,w,y,E,S,b;!function(t){!function(s){var i={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(i.arrayBuffer)var e=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&e.indexOf(Object.prototype.toString.call(t))>-1};function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var s={next:function(){var s=t.shift();return{done:void 0===s,value:s}}};return i.iterable&&(s[Symbol.iterator]=function(){return s}),s}function h(t){this.map={},t instanceof h?t.forEach((function(t,s){this.append(s,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(s){this.append(s,t[s])}),this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise((function(s,i){t.onload=function(){s(t.result)},t.onerror=function(){i(t.error)}}))}function l(t){var s=new FileReader,i=u(s);return s.readAsArrayBuffer(t),i}function f(t){if(t.slice)return t.slice(0);var s=new Uint8Array(t.byteLength);return s.set(new Uint8Array(t)),s.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(t){var s;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i.arrayBuffer&&i.blob&&((s=t)&&DataView.prototype.isPrototypeOf(s))?(this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=f(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,s,i,e=c(this);if(e)return e;if(this._bodyBlob)return t=this._bodyBlob,s=new FileReader,i=u(s),s.readAsText(t),i;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var s=new Uint8Array(t),i=new Array(s.length),e=0;e<s.length;e++)i[e]=String.fromCharCode(s[e]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,s){t=r(t),s=o(s);var i=this.map[t];this.map[t]=i?i+", "+s:s},h.prototype.delete=function(t){delete this.map[r(t)]},h.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},h.prototype.set=function(t,s){this.map[r(t)]=o(s)},h.prototype.forEach=function(t,s){for(var i in this.map)this.map.hasOwnProperty(i)&&t.call(s,this.map[i],i,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(s,i){t.push(i)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(s){t.push(s)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(s,i){t.push([i,s])})),a(t)},i.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,s){var i,e,n=(s=s||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,s.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=s.credentials||this.credentials||"same-origin",!s.headers&&this.headers||(this.headers=new h(s.headers)),this.method=(i=s.method||this.method||"GET",e=i.toUpperCase(),v.indexOf(e)>-1?e:i),this.mode=s.mode||this.mode||null,this.signal=s.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function y(t){var s=new FormData;return t.trim().split("&").forEach((function(t){if(t){var i=t.split("="),e=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");s.append(decodeURIComponent(e),decodeURIComponent(n))}})),s}function E(t,s){s||(s={}),this.type="default",this.status=void 0===s.status?200:s.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in s?s.statusText:"OK",this.headers=new h(s.headers),this.url=s.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},d.call(w.prototype),d.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var S=[301,302,303,307,308];E.redirect=function(t,s){if(-1===S.indexOf(s))throw new RangeError("Invalid status code");return new E(null,{status:s,headers:{location:t}})},s.DOMException=t.DOMException;try{new s.DOMException}catch(t){s.DOMException=function(t,s){this.message=t,this.name=s;var i=Error(t);this.stack=i.stack},s.DOMException.prototype=Object.create(Error.prototype),s.DOMException.prototype.constructor=s.DOMException}function b(t,e){return new Promise((function(n,r){var o=new w(t,e);if(o.signal&&o.signal.aborted)return r(new s.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,s,i={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",s=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var i=t.split(":"),e=i.shift().trim();if(e){var n=i.join(":").trim();s.append(e,n)}})),s)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var e="response"in a?a.response:a.responseText;n(new E(e,i))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.onabort=function(){r(new s.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&i.blob&&(a.responseType="blob"),o.headers.forEach((function(t,s){a.setRequestHeader(s,t)})),o.signal&&(o.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",c)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}b.polyfill=!0,t.fetch||(t.fetch=b,t.Headers=h,t.Request=w,t.Response=E),s.Headers=h,s.Request=w,s.Response=E,s.fetch=b,Object.defineProperty(s,"t",{value:!0})}({})}("undefined"!=typeof self?self:void 0),function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(o||(o={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(a||(a={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(h||(h={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(c||(c={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(u||(u={})),function(t){t.ASC="ASC",t.DESC="DESC"}(l||(l={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(f||(f={})),function(t){t.EVERYWHERE="EVERYWHERE",t.TITLE_ONLY="TITLE_ONLY",t.NONE="NONE"}(d||(d={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK",t.SHARED_BOOK="SHARED_BOOK"}(v||(v={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(w||(w={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(y||(y={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(E||(E={})),function(t){t.DEFAULT="DEFAULT",t.DOCUMENTS="DOCUMENTS"}(S||(S={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}(b||(b={})),b.PERSONAL_BOOK_SHARE_USER,b.PERSONAL_BOOK_USER,b.HTML_EXPORT_USER,b.PERSONAL_BOOK_USER,b.PDF_EXPORT_USER,b.PERSONAL_BOOK_USER,b.KHUB_ADMIN,b.CONTENT_PUBLISHER,b.ADMIN,b.KHUB_ADMIN,b.USERS_ADMIN,b.PORTAL_ADMIN,b.DEVELOPER,b.BETA_USER,b.DEBUG_USER;const p=i.css`
|
|
2
|
+
`,r={setRequest:(t,s)=>{t.request=s.payload},setRequestQuery:(t,s)=>{t.request.query=s.payload},setRequestContentLocale:(t,s)=>{t.request.contentLocale=s.payload},setPageSize:(t,s)=>{t.request.paging.perPage=s.payload},setPageNumber:(t,s)=>{t.request.paging.page=s.payload},setRequestSort:(t,s)=>{t.request.sort=s.payload},setRequestFilters:(t,s)=>{t.request.filters=s.payload},setRequestFacets:(t,s)=>{t.request.facets=s.payload},setRequestVirtualField:(t,s)=>{t.request.virtualField=s.payload},setRequestScope:(t,s)=>{t.request.scope=s.payload},setResults:(t,s)=>{t.results=s.payload},setFacets:(t,s)=>{t.facets=s.payload},setSpellcheck:(t,s)=>{t.spellcheck=s.payload},setLocales:(t,s)=>{t.locales=s.payload},setPaging:(t,s)=>{t.paging=s.payload},setLiveQuery:(t,s)=>{t.liveQuery=s.payload},setSuggestResults:(t,s)=>{t.suggestResults=s.payload}};var o,a,h,c,u,l,d,f,v,w,y,E,S,p;!function(t){!function(s){var i={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(i.arrayBuffer)var e=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&e.indexOf(Object.prototype.toString.call(t))>-1};function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var s={next:function(){var s=t.shift();return{done:void 0===s,value:s}}};return i.iterable&&(s[Symbol.iterator]=function(){return s}),s}function h(t){this.map={},t instanceof h?t.forEach((function(t,s){this.append(s,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(s){this.append(s,t[s])}),this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function u(t){return new Promise((function(s,i){t.onload=function(){s(t.result)},t.onerror=function(){i(t.error)}}))}function l(t){var s=new FileReader,i=u(s);return s.readAsArrayBuffer(t),i}function d(t){if(t.slice)return t.slice(0);var s=new Uint8Array(t.byteLength);return s.set(new Uint8Array(t)),s.buffer}function f(){return this.bodyUsed=!1,this._initBody=function(t){var s;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:i.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:i.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():i.arrayBuffer&&i.blob&&((s=t)&&DataView.prototype.isPrototypeOf(s))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):i.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},i.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,s,i,e=c(this);if(e)return e;if(this._bodyBlob)return t=this._bodyBlob,s=new FileReader,i=u(s),s.readAsText(t),i;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var s=new Uint8Array(t),i=new Array(s.length),e=0;e<s.length;e++)i[e]=String.fromCharCode(s[e]);return i.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},i.formData&&(this.formData=function(){return this.text().then(y)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,s){t=r(t),s=o(s);var i=this.map[t];this.map[t]=i?i+", "+s:s},h.prototype.delete=function(t){delete this.map[r(t)]},h.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},h.prototype.set=function(t,s){this.map[r(t)]=o(s)},h.prototype.forEach=function(t,s){for(var i in this.map)this.map.hasOwnProperty(i)&&t.call(s,this.map[i],i,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(s,i){t.push(i)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(s){t.push(s)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(s,i){t.push([i,s])})),a(t)},i.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function w(t,s){var i,e,n=(s=s||{}).body;if(t instanceof w){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,s.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=s.credentials||this.credentials||"same-origin",!s.headers&&this.headers||(this.headers=new h(s.headers)),this.method=(i=s.method||this.method||"GET",e=i.toUpperCase(),v.indexOf(e)>-1?e:i),this.mode=s.mode||this.mode||null,this.signal=s.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function y(t){var s=new FormData;return t.trim().split("&").forEach((function(t){if(t){var i=t.split("="),e=i.shift().replace(/\+/g," "),n=i.join("=").replace(/\+/g," ");s.append(decodeURIComponent(e),decodeURIComponent(n))}})),s}function E(t,s){s||(s={}),this.type="default",this.status=void 0===s.status?200:s.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in s?s.statusText:"OK",this.headers=new h(s.headers),this.url=s.url||"",this._initBody(t)}w.prototype.clone=function(){return new w(this,{body:this._bodyInit})},f.call(w.prototype),f.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var S=[301,302,303,307,308];E.redirect=function(t,s){if(-1===S.indexOf(s))throw new RangeError("Invalid status code");return new E(null,{status:s,headers:{location:t}})},s.DOMException=t.DOMException;try{new s.DOMException}catch(t){s.DOMException=function(t,s){this.message=t,this.name=s;var i=Error(t);this.stack=i.stack},s.DOMException.prototype=Object.create(Error.prototype),s.DOMException.prototype.constructor=s.DOMException}function p(t,e){return new Promise((function(n,r){var o=new w(t,e);if(o.signal&&o.signal.aborted)return r(new s.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var t,s,i={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",s=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var i=t.split(":"),e=i.shift().trim();if(e){var n=i.join(":").trim();s.append(e,n)}})),s)};i.url="responseURL"in a?a.responseURL:i.headers.get("X-Request-URL");var e="response"in a?a.response:a.responseText;n(new E(e,i))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.onabort=function(){r(new s.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&i.blob&&(a.responseType="blob"),o.headers.forEach((function(t,s){a.setRequestHeader(s,t)})),o.signal&&(o.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",c)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}p.polyfill=!0,t.fetch||(t.fetch=p,t.Headers=h,t.Request=w,t.Response=E),s.Headers=h,s.Request=w,s.Response=E,s.fetch=p,Object.defineProperty(s,"t",{value:!0})}({})}("undefined"!=typeof self?self:void 0),function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(o||(o={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(a||(a={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(h||(h={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(c||(c={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(u||(u={})),function(t){t.ASC="ASC",t.DESC="DESC"}(l||(l={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(d||(d={})),function(t){t.EVERYWHERE="EVERYWHERE",t.TITLE_ONLY="TITLE_ONLY",t.NONE="NONE"}(f||(f={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK",t.SHARED_BOOK="SHARED_BOOK"}(v||(v={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(w||(w={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(y||(y={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(E||(E={})),function(t){t.DEFAULT="DEFAULT",t.DOCUMENTS="DOCUMENTS"}(S||(S={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}(p||(p={})),p.PERSONAL_BOOK_SHARE_USER,p.PERSONAL_BOOK_USER,p.HTML_EXPORT_USER,p.PERSONAL_BOOK_USER,p.PDF_EXPORT_USER,p.PERSONAL_BOOK_USER,p.KHUB_ADMIN,p.CONTENT_PUBLISHER,p.ADMIN,p.KHUB_ADMIN,p.USERS_ADMIN,p.PORTAL_ADMIN,p.DEVELOPER,p.BETA_USER,p.DEBUG_USER;const b=i.css`
|
|
3
3
|
`,m=s.FtReduxStore.get({name:"ft-app-info",reducers:{setBaseUrl:(t,s)=>{t.baseUrl=s.payload},setApiIntegrationIdentifier:(t,s)=>{t.apiIntegrationIdentifier=s.payload},setUiLocale:(t,s)=>{t.uiLocale=s.payload},setAvailableUiLocales:(t,s)=>{t.availableUiLocales=s.payload},setEditorMode:(t,s)=>{t.editorMode=s.payload},setNoCustom:(t,s)=>{t.noCustom=s.payload},setNoCustomComponent:(t,s)=>{t.noCustomComponent=s.payload},setSession:(t,s)=>{t.session=s.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class A{static build(t){const{baseUrl:s,apiIntegrationIdentifier:i}=m.getState(),e=null!=t?t:i;if(s&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(s,e,!0)}static get(t){var s;return null!=t?A.build(t):null!==(s=A.API)&&void 0!==s?s:A.API=A.build()}static await(t){return new Promise((s=>{let i=A.get(t);if(i)s(i);else{const e=m.subscribe((()=>{i=A.get(t),i&&(e(),s(i))}))}}))}}var g;const R=Symbol("clearAfterUnitTest");class T{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={},this.currentUiLocale="",this[g]=()=>{this.defaultMessages={},this.cache=new s.CacheRegistry,this.listeners={}},this.currentUiLocale=m.getState().uiLocale,m.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=m.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const s=t.name.toLowerCase();this.cache.setFinal(s,t),this.notify(s)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,i){var e;if(t=t.toLowerCase(),Object.keys(i).length>0){const n={...null!==(e=this.defaultMessages[t])&&void 0!==e?e:{},...i};s.deepEqual(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,i,...e){var n,r,o;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(r=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==r?r:{};return new s.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},a).resolve(i,...e)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,s){var i;return t=t.toLowerCase(),this.listeners[t]=null!==(i=this.listeners[t])&&void 0!==i?i:new Set,this.listeners[t].add(s),()=>{var i;return null===(i=this.listeners[t])||void 0===i?void 0:i.delete(s)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>s.delay(0).then((()=>t())).catch((()=>null)))))}}g=R,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new T((async(t,s)=>(await A.await()).getFluidTopicsMessageContext(t,s)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new T((async(t,s)=>(await A.await()).getCustomMessageContext(t,s))));const O=window.FluidTopicsI18nService;var U=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class C extends s.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.availableUiLocales=[],this.editorMode=!1,this.noCustom=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>A.get(),this.cache=new s.CacheRegistry,this.cleanSessionDebouncer=new s.Debouncer}render(){return i.html`
|
|
4
4
|
<slot></slot>
|
|
5
|
-
`}update(t){super.update(t),t.has("baseUrl")&&m.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&m.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&m.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&m.actions.setNoCustom(this.noCustom),t.has("editorMode")&&m.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&m.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&m.actions.setSession(this.session),t.has("availableUiLocales")&&m.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>O.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const s=await t.getCurrentSession();return s.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),s.idleTimeoutInMillis),s}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}C.elementDefinitions={},C.styles=p,U([e.property()],C.prototype,"baseUrl",void 0),U([e.property()],C.prototype,"apiIntegrationIdentifier",void 0),U([e.property()],C.prototype,"uiLocale",void 0),U([s.jsonProperty([])],C.prototype,"availableUiLocales",void 0),U([e.property({type:Boolean})],C.prototype,"editorMode",void 0),U([e.property({type:Boolean})],C.prototype,"noCustom",void 0),U([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],C.prototype,"noCustomComponent",void 0),U([e.property({type:Boolean})],C.prototype,"withManualResources",void 0),U([s.jsonProperty([])],C.prototype,"messageContexts",void 0),U([s.jsonProperty(void 0)],C.prototype,"session",void 0),U([e.property({type:Object})],C.prototype,"apiProvider",void 0);class L{async listMySearches(){var t;return(null===(t=m.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await A.await()).listMySearches(m.getState().session.profile.userId):[]}}const I=new s.CacheRegistry;class P{async listMyBookmarks(){return I.get("bookmarks",(async()=>(await A.await()).listMyBookmarks(m.getState().session.profile.userId)))}clearCache(){I.clear("bookmarks")}}const D=s.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const N=new class{constructor(){this.currentSession=m.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new P,m.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=m.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){D.actions.savedSearches(void 0)}clearMyBookmarks(){D.actions.bookmarks(void 0)}async reloadMySearches(){const t=new L,s=await t.listMySearches();D.actions.savedSearches(s)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;D.actions.bookmarks(s)}}};s.customElement("ft-app-context")(C);class _{static async build(){return new _(await A.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const B=t=>t.request.virtualField===d.TITLE_ONLY&&t.request.scope===S.DOCUMENTS;class M extends Event{constructor(){super(M.eventName)}}M.eventName="search-context-clear-all-filters";class F{static build(t){return new F((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:r}))(t.trim()||"context"),_.build)}constructor(t,i){this.store=t,this.serviceProvider=i,this.searchDebouncer=new s.Debouncer(100),this.suggestDebouncer=new s.Debouncer(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await s.delay(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let s=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(s){const e=t=>s.some((s=>s.lang==t));e(t)||(t=e(i)?i:s[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const s=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(s),this.store.actions.setPageNumber(1),s.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(d.TITLE_ONLY),this.store.actions.setRequestScope(S.DOCUMENTS)):(this.store.actions.setRequestVirtualField(d.EVERYWHERE),this.store.actions.setRequestScope(S.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return B(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new M)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,s){let i=this.facetIds.filter((s=>s!=t));s&&i.push(s),this.facetIds=i,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let s=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(s)}setFilter(t,s){let i=this.store.getState().request.filters,e={key:t,values:s,negative:!1},n=[...i.filter((s=>s.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,i;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel(),this.cancelableSearch=s.cancelable(this.service.launchSearch(this.store.getState().request));const e=await this.cancelableSearch;if(e.paging.currentPage<=1)this.store.actions.setResults(e.results),this.store.actions.setFacets(e.facets),this.store.actions.setSpellcheck(e.spellcheck);else{let t=(null!==(i=this.store.getState().results)&&void 0!==i?i:[]).concat(e.results);this.store.actions.setResults(t)}this.store.actions.setPaging(e.paging)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{const i=this.store.getState(),e=i.request,n={input:i.liveQuery,filters:e.filters,sort:e.sort,contentLocale:e.contentLocale,scope:e.scope};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=s.cancelable(this.service.launchSuggest(n));let r=await this.cancelableSuggest;this.store.actions.setSuggestResults(r.suggestions)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}}var x=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class k extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const j=Symbol("registerInterval");class q extends(function(t){var s;class i extends t{constructor(){super(...arguments),this[s]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[j]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[j]):this.dispatchEvent(new k)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=j,x([e.state()],i.prototype,"stateManager",void 0),i}(s.FtLitElementRedux)){}var H=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class G extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class K extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class z extends CustomEvent{constructor(t,s,i){super("ft-search-results-change",{detail:{request:t,paging:s,spellcheck:i}})}}class Q extends s.FtLitElementRedux{get stateManager(){return null==this._stateManager&&(this._stateManager=F.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.filters=[],this.sort=[],this.addStore(m)}render(){return i.html`
|
|
5
|
+
`}update(t){super.update(t),t.has("baseUrl")&&m.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&m.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&m.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&m.actions.setNoCustom(this.noCustom),t.has("editorMode")&&m.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&m.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&m.actions.setSession(this.session),t.has("availableUiLocales")&&m.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>O.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const s=await t.getCurrentSession();return s.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),s.idleTimeoutInMillis),s}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}C.elementDefinitions={},C.styles=b,U([e.property()],C.prototype,"baseUrl",void 0),U([e.property()],C.prototype,"apiIntegrationIdentifier",void 0),U([e.property()],C.prototype,"uiLocale",void 0),U([s.jsonProperty([])],C.prototype,"availableUiLocales",void 0),U([e.property({type:Boolean})],C.prototype,"editorMode",void 0),U([e.property({type:Boolean})],C.prototype,"noCustom",void 0),U([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],C.prototype,"noCustomComponent",void 0),U([e.property({type:Boolean})],C.prototype,"withManualResources",void 0),U([s.jsonProperty([])],C.prototype,"messageContexts",void 0),U([s.jsonProperty(void 0)],C.prototype,"session",void 0),U([e.property({type:Object})],C.prototype,"apiProvider",void 0);class L{async listMySearches(){var t;return(null===(t=m.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await A.await()).listMySearches(m.getState().session.profile.userId):[]}}const I=new s.CacheRegistry;class P{async listMyBookmarks(){return I.get("bookmarks",(async()=>(await A.await()).listMyBookmarks(m.getState().session.profile.userId)))}clearCache(){I.clear("bookmarks")}}const D=s.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const N=new class{constructor(){this.currentSession=m.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new P,m.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:i}=m.getState();s.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==i?void 0:i.profile)||(this.currentSession=i,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){D.actions.savedSearches(void 0)}clearMyBookmarks(){D.actions.bookmarks(void 0)}async reloadMySearches(){const t=new L,s=await t.listMySearches();D.actions.savedSearches(s)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const s=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;D.actions.bookmarks(s)}}};s.customElement("ft-app-context")(C);class _{static async build(){return new _(await A.await())}constructor(t){this.api=t,this.cache=new s.CacheRegistry,this.cache.registerFinal("available-locales",(()=>this.api.getAvailableSearchLocales()))}async launchSearch(t){return this.api.search(t)}async launchSuggest(t){return this.api.getSuggestions(t)}async getAvailableSearchLocales(){return this.cache.get("available-locales")}}const B=t=>t.request.virtualField===f.TITLE_ONLY&&t.request.scope===S.DOCUMENTS;class M extends Event{constructor(){super(M.eventName)}}M.eventName="search-context-clear-all-filters";class F{static build(t){return new F((t=>s.FtReduxStore.get({name:"ft-search-"+t,initialState:{request:{query:"",filters:[],facets:[],sort:[],paging:{page:1,perPage:20}},liveQuery:""},reducers:r}))(t.trim()||"context"),_.build)}constructor(t,i){this.store=t,this.serviceProvider=i,this.ignoreEmptyQuery=!1,this.searchDebouncer=new s.Debouncer(100),this.suggestDebouncer=new s.Debouncer(300)}async initService(){return this.service=await this.serviceProvider(),this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales),this.launchSearch()}async awaitService(){for(;null==this.service;)await s.delay(5);return this.service}setQuery(t){this.store.actions.setRequestQuery(t),this.store.actions.setLiveQuery(t),this.store.actions.setPageNumber(1),this.launchSearch()}setContentLocale(t){let s=this.store.getState().locales,i=this.store.getState().request.contentLocale;if(t!=i){if(s){const e=t=>s.some((s=>s.lang==t));e(t)||(t=e(i)?i:s[0].lang)}this.store.actions.setRequestContentLocale(t),this.store.actions.setPageNumber(1),this.store.actions.setRequestFilters([]),this.launchSearch()}return t}setPageSize(t){this.store.actions.setPageSize(t),this.launchSearch()}setPageNumber(t){this.store.actions.setPageNumber(t),this.launchSearch()}setSort(t){this.store.actions.setRequestSort(t),this.store.actions.setPageNumber(1),this.launchSearch()}setFilters(t){const s=t.filter((t=>t.values.length>0));this.store.actions.setRequestFilters(s),this.store.actions.setPageNumber(1),s.forEach((t=>{this.facetIds.includes(t.key)||(this.facetIds=[...this.facetIds,t.key])})),this.launchSearch()}setSearchInDocumentTitlesOnly(t){t?(this.store.actions.setRequestVirtualField(f.TITLE_ONLY),this.store.actions.setRequestScope(S.DOCUMENTS)):(this.store.actions.setRequestVirtualField(f.EVERYWHERE),this.store.actions.setRequestScope(S.DEFAULT)),this.launchSearch()}get searchInDocumentTitlesOnly(){return B(this.store.getState())}clearAllFilters(){this.setFilters([]),this.store.eventBus.dispatchEvent(new M)}addFacet(t){this.facetIds=[...this.facetIds,t],this.launchSearch()}replaceFacet(t,s){let i=this.facetIds.filter((s=>s!=t));s&&i.push(s),this.facetIds=i,this.launchSearch()}get facetIds(){return this.store.getState().request.facets.map((t=>t.id))}set facetIds(t){let s=[...new Set(t)].map((t=>({id:t})));this.store.actions.setRequestFacets(s)}setFilter(t,s){let i=this.store.getState().request.filters,e={key:t,values:s,negative:!1},n=[...i.filter((s=>s.key!==t)),e];this.setFilters(n)}setLiveQuery(t){this.store.actions.setLiveQuery(t),this.launchSuggest()}setRequest(t){this.store.actions.setRequest(t),this.store.actions.setLiveQuery(t.query),this.store.actions.setPageNumber(1),this.launchSearch()}setScope(t){this.store.actions.setRequestScope(t),this.launchSearch()}setIgnoreEmptyQuery(t){this.ignoreEmptyQuery=t,this.launchSearch()}async launchSearch(){return await this.awaitService(),this.searchDebouncer.run((()=>this.fetchSearchData()))}async launchSuggest(){await this.awaitService(),this.suggestDebouncer.run((()=>this.fetchSuggestData()))}async fetchSearchData(){var t,i;try{null===(t=this.cancelableSearch)||void 0===t||t.cancel();let e=this.store.getState().request;if(this.store.actions.setPaging(void 0),this.ignoreEmptyQuery&&0==e.query.length)this.store.actions.setResults(void 0),this.store.actions.setFacets(void 0),this.store.actions.setSpellcheck(void 0);else{this.cancelableSearch=s.cancelable(this.service.launchSearch(e));const t=await this.cancelableSearch;if(t.paging.currentPage<=1)this.store.actions.setResults(t.results),this.store.actions.setFacets(t.facets),this.store.actions.setSpellcheck(t.spellcheck);else{let s=(null!==(i=this.store.getState().results)&&void 0!==i?i:[]).concat(t.results);this.store.actions.setResults(s)}this.store.actions.setPaging(t.paging)}}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}async fetchSuggestData(){var t;try{const i=this.store.getState(),e=i.request,n={input:i.liveQuery,filters:e.filters,sort:e.sort,contentLocale:e.contentLocale,scope:e.scope};null===(t=this.cancelableSuggest)||void 0===t||t.cancel(),this.cancelableSuggest=s.cancelable(this.service.launchSuggest(n));let r=await this.cancelableSuggest;this.store.actions.setSuggestResults(r.suggestions)}catch(t){t instanceof s.CanceledPromiseError||!this.errorHandler||this.errorHandler(t)}}clear(){this.store.clear()}}var x=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class k extends Event{constructor(){super("register-ft-search-component",{bubbles:!0,composed:!0})}}const j=Symbol("registerInterval");class q extends(function(t){var s;class i extends t{constructor(){super(...arguments),this[s]=0}setSearchStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"search")}clearStateManager(){this.stateManager&&(this.removeStore(this.stateManager.store),this.stateManager=void 0)}connectedCallback(){super.connectedCallback(),this[j]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[j]):this.dispatchEvent(new k)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return s=j,x([e.state()],i.prototype,"stateManager",void 0),i}(s.FtLitElementRedux)){}var H=function(t,s,i,e){for(var n,r=arguments.length,o=r<3?s:null===e?e=Object.getOwnPropertyDescriptor(s,i):e,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(s,i,o):n(s,i))||o);return r>3&&o&&Object.defineProperty(s,i,o),o};class G extends CustomEvent{constructor(t){super("ft-search-load-error",{detail:t})}}class K extends CustomEvent{constructor(t){super("ft-search-request-change",{detail:t})}}class Q extends CustomEvent{constructor(t,s,i){super("ft-search-results-change",{detail:{request:t,paging:s,spellcheck:i}})}}class z extends s.FtLitElementRedux{get stateManager(){return null==this._stateManager&&(this._stateManager=F.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"search")),this._stateManager}constructor(){super(),this.query="",this.pageSize=20,this.searchInDocumentTitlesOnly=!1,this.ignoreEmptyQuery=!1,this.filters=[],this.sort=[],this.addStore(m)}render(){return i.html`
|
|
6
6
|
<slot @register-ft-search-component=${this.registerComponent}></slot>
|
|
7
|
-
`}update(t){super.update(t),t.has("query")&&void 0!==this.query&&this.stateManager.setQuery(this.query),t.has("contentLocale")&&void 0!==this.contentLocale&&this.stateManager.setContentLocale(this.contentLocale),t.has("session")&&this.session&&this.stateManager.initService(),t.has("filters")&&void 0!==this.filters&&this.stateManager.setFilters(this.filters),t.has("sort")&&void 0!==this.sort&&this.stateManager.setSort(this.sort),t.has("pageSize")&&void 0!==this.pageSize&&this.stateManager.setPageSize(this.pageSize),t.has("searchInDocumentTitlesOnly")&&void 0!==this.searchInDocumentTitlesOnly&&this.stateManager.setSearchInDocumentTitlesOnly(this.searchInDocumentTitlesOnly)}connectedCallback(){super.connectedCallback(),this.stateManager.setQuery(this.query),this.stateManager.setContentLocale(this.contentLocale),this.stateManager.setFilters(this.filters),this.stateManager.setPageSize(this.pageSize),this.stateManager.setSort(this.sort)}contentAvailableCallback(t){super.contentAvailableCallback(t),t.has("request")&&this.request&&this.dispatchEvent(new K(this.request)),t.has("paging")&&void 0!==this.paging&&this.dispatchEvent(new
|
|
7
|
+
`}update(t){super.update(t),t.has("query")&&void 0!==this.query&&this.stateManager.setQuery(this.query),t.has("contentLocale")&&void 0!==this.contentLocale&&this.stateManager.setContentLocale(this.contentLocale),t.has("session")&&this.session&&this.stateManager.initService(),t.has("filters")&&void 0!==this.filters&&this.stateManager.setFilters(this.filters),t.has("sort")&&void 0!==this.sort&&this.stateManager.setSort(this.sort),t.has("pageSize")&&void 0!==this.pageSize&&this.stateManager.setPageSize(this.pageSize),t.has("searchInDocumentTitlesOnly")&&void 0!==this.searchInDocumentTitlesOnly&&this.stateManager.setSearchInDocumentTitlesOnly(this.searchInDocumentTitlesOnly),t.has("scope")&&void 0!==this.scope&&this.stateManager.setScope(this.scope),t.has("ignoreEmptyQuery")&&void 0!==this.ignoreEmptyQuery&&this.stateManager.setIgnoreEmptyQuery(this.ignoreEmptyQuery)}connectedCallback(){super.connectedCallback(),this.stateManager.setQuery(this.query),this.stateManager.setContentLocale(this.contentLocale),this.stateManager.setFilters(this.filters),this.stateManager.setPageSize(this.pageSize),this.stateManager.setSort(this.sort)}contentAvailableCallback(t){super.contentAvailableCallback(t),t.has("request")&&this.request&&this.dispatchEvent(new K(this.request)),t.has("paging")&&void 0!==this.paging&&this.dispatchEvent(new Q(this.request,this.paging,this.autocorrect))}registerComponent(t){t.stopPropagation();const s=t.composedPath()[0];this.register(s)}register(t){t.setSearchStateManager(this.stateManager)}handleLoadError(t){this.dispatchEvent(new G(t))}reloadSavedSearches(){N.clearMySearches()}clear(){this.stateManager.clear()}}z.elementDefinitions={},z.styles=n,H([e.property()],z.prototype,"query",void 0),H([e.property()],z.prototype,"contentLocale",void 0),H([e.property({type:Number})],z.prototype,"pageSize",void 0),H([e.property({type:Boolean})],z.prototype,"searchInDocumentTitlesOnly",void 0),H([e.property()],z.prototype,"scope",void 0),H([e.property({type:Boolean})],z.prototype,"ignoreEmptyQuery",void 0),H([s.jsonProperty([])],z.prototype,"filters",void 0),H([s.jsonProperty([])],z.prototype,"sort",void 0),H([s.redux({store:"search"})],z.prototype,"request",void 0),H([s.redux({store:"search"})],z.prototype,"paging",void 0),H([s.redux({store:"search",selector:t=>t.spellcheck})],z.prototype,"autocorrect",void 0),H([s.redux({store:m.name})],z.prototype,"session",void 0),s.customElement("ft-search-context")(z),t.ClearAllFiltersEvent=M,t.FtSearchContext=z,t.FtSearchContextCssVariables={},t.FtSearchStateManager=F,t.LoadErrorEvent=G,t.SearchRequestChangeEvent=K,t.SearchResultsChangeEvent=Q,t.searchInDocumentTitlesOnlySelector=B,t.styles=n}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
|