@docsearch/core 4.5.2 → 4.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/umd/index.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! @docsearch/core 4.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/core 4.5.3 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DocSearchCore={},e.React)}(this,function(e,t){"use strict";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function r(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function i(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a,i,u=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,0===t);else for(;!(c=(r=a.call(n)).done)&&(u.push(r.value),u.length!==t);c=!0);}catch(e){l=!0,o=e}finally{try{if(!c&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(l)throw o}}return u}}(e,t)||function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var u={"Ctrl/Cmd+K":!0,"/":!0,"Ctrl/Cmd+I":!0};function c(e){return a(a({},u),e)}function l(e){var n=e.isOpen,r=e.isAskAiActive,o=e.onAskAiToggle,a=e.onClose,i=e.onOpen,c=e.keyboardShortcuts,l=void 0===c?u:c;t.useEffect(function(){function e(e){var t;if(n&&"Escape"===e.code&&r)o(!1);else{var u=l["Ctrl/Cmd+K"]&&"k"===(null===(t=e.key)||void 0===t?void 0:t.toLowerCase())&&(e.metaKey||e.ctrlKey),c=l["/"]&&"/"===e.key;("Escape"===e.code&&n||u||!function(e){var t=e.composedPath()[0],n=t.tagName;return t.isContentEditable||"INPUT"===n||"SELECT"===n||"TEXTAREA"===n}(e)&&c&&!n)&&(e.preventDefault(),n?a():document.body.classList.contains("DocSearch--active")||i())}}return window.addEventListener("keydown",e),function(){window.removeEventListener("keydown",e)}},[n,r,l,i,a,o])}var s=function(e){var n=e.theme;t.useEffect(function(){if(n){var e=document.documentElement.dataset.theme;if(n!==e)return document.documentElement.dataset.theme=n,function(){void 0===e?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e}}},[n])},d=["children","theme","onReady","onOpen","onClose","onSidepanelOpen","onSidepanelClose"],f=t.createContext(void 0);f.displayName="DocSearchContext";var p=t.forwardRef(function(e,n){var r=e.children,o=e.theme,a=e.onReady,u=e.onOpen,p=e.onClose,m=e.onSidepanelOpen,y=e.onSidepanelClose,v=function(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(-1!==t.indexOf(r))continue;n[r]=e[r]}return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],-1===t.indexOf(n)&&{}.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,d),h=i(t.useState("ready"),2),b=h[0],S=h[1],O=i(t.useState(v.initialQuery||""),2),w=O[0],g=O[1],k=t.useRef(null),A=c(v.keyboardShortcuts),E=i(t.useState(),2),C=E[0],j=E[1],D=i(t.useState(function(){return new Set}),2),P=D[0],T=D[1],R=function(){var e=i(t.useState(!1),2),n=e[0],r=e[1];return t.useEffect(function(){var e=function(){var e=window.matchMedia("(max-width: 768px)");r(e.matches)};return e(),window.addEventListener("resize",e),function(){window.removeEventListener("resize",e)}},[]),n}(),x=t.useRef("ready"),I=["modal-search","modal-askai"].includes(b),L="modal-askai"===b,M=!R&&P.has("sidepanel"),K="sidepanel"===b;t.useEffect(function(){null==a||a()},[a]),t.useEffect(function(){var e=x.current,t=b;"modal-search"!==t&&"modal-askai"!==t||"modal-search"===e||"modal-askai"===e||null==u||u(),"ready"!==t||"modal-search"!==e&&"modal-askai"!==e||null==p||p(),"sidepanel"===t&&"sidepanel"!==e&&(null==m||m()),"sidepanel"!==t&&"sidepanel"===e&&(null==y||y()),x.current=t},[b,u,p,m,y]);var N=t.useCallback(function(){S("modal-search")},[]),Q=t.useCallback(function(){var e,t;S("ready"),null===(e=k.current)||void 0===e||e.focus(),g(null!==(t=v.initialQuery)&&void 0!==t?t:"")},[S,v.initialQuery]),U=t.useCallback(function(e,t){if(!R&&e&&M)return j(t),void S("sidepanel");S(e?"modal-askai":"modal-search")},[S,R,M]),B=t.useCallback(function(e){P.has("sidepanel")&&(j(e),S("sidepanel"))},[S,P]),H=t.useCallback(function(e){S("modal-search"),g(e.key)},[S,g]),z=t.useCallback(function(e){P.has(e)||T(function(t){var n=new Set(t);return n.add(e),n})},[P]);t.useImperativeHandle(n,function(){return{open:N,close:Q,openAskAi:function(e){return U(!0,e)},openSidepanel:B,get isReady(){return!0},get isOpen(){return I},get isSidepanelOpen(){return K},get isSidepanelSupported(){return M}}},[N,Q,U,B,I,K,M]),s({theme:o}),l({isOpen:I,onOpen:N,onClose:Q,onAskAiToggle:U,onInput:H,isAskAiActive:L,searchButtonRef:k,keyboardShortcuts:A});var _=t.useMemo(function(){return{docsearchState:b,setDocsearchState:S,searchButtonRef:k,initialQuery:w,keyboardShortcuts:A,openModal:N,closeModal:Q,isAskAiActive:L,isModalActive:I,onAskAiToggle:U,initialAskAiMessage:C,registerView:z,isHybridModeSupported:M}},[b,k,w,A,N,Q,L,I,U,C,z,M]);return t.createElement(f.Provider,{value:_},r)});p.displayName="DocSearch",e.DEFAULT_KEYBOARD_SHORTCUTS=u,e.DocSearch=p,e.useDocSearch=function(){var e=t.useContext(f);if(void 0===e)throw new Error("`useDocSearch` must be used within the `DocSearch` provider");return e},e.useDocSearchKeyboardEvents=l,e.useKeyboardShortcuts=c,e.useTheme=s});
3
3
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- /*! @docsearch/core 4.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/core 4.5.3 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DocSearchCore={},e.React)}(this,function(e,t){"use strict";var o={"Ctrl/Cmd+K":!0,"/":!0,"Ctrl/Cmd+I":!0};e.useDocSearchKeyboardEvents=function(e){var n=e.isOpen,i=e.isAskAiActive,r=e.onAskAiToggle,c=e.onClose,s=e.onOpen,a=e.keyboardShortcuts,d=void 0===a?o:a;t.useEffect(function(){function e(e){var t;if(n&&"Escape"===e.code&&i)r(!1);else{var o=d["Ctrl/Cmd+K"]&&"k"===(null===(t=e.key)||void 0===t?void 0:t.toLowerCase())&&(e.metaKey||e.ctrlKey),a=d["/"]&&"/"===e.key;("Escape"===e.code&&n||o||!function(e){var t=e.composedPath()[0],o=t.tagName;return t.isContentEditable||"INPUT"===o||"SELECT"===o||"TEXTAREA"===o}(e)&&a&&!n)&&(e.preventDefault(),n?c():document.body.classList.contains("DocSearch--active")||s())}}return window.addEventListener("keydown",e),function(){window.removeEventListener("keydown",e)}},[n,i,d,s,c,r])}});
3
3
  //# sourceMappingURL=useDocSearchKeyboardEvents.js.map
@@ -1,3 +1,3 @@
1
- /*! @docsearch/core 4.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/core 4.5.3 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DocSearchCore={})}(this,function(e){"use strict";function t(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(Object(o),!0).forEach(function(r){t(e,r,o[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):r(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}var o={"Ctrl/Cmd+K":!0,"/":!0,"Ctrl/Cmd+I":!0};e.DEFAULT_KEYBOARD_SHORTCUTS=o,e.useKeyboardShortcuts=function(e){return n(n({},o),e)}});
3
3
  //# sourceMappingURL=useKeyboardShortcuts.js.map
@@ -1,3 +1,3 @@
1
- /*! @docsearch/core 4.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/core 4.5.3 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DocSearchCore={},e.React)}(this,function(e,t){"use strict";e.useTheme=function(e){var n=e.theme;t.useEffect(function(){if(n){var e=document.documentElement.dataset.theme;if(n!==e)return document.documentElement.dataset.theme=n,function(){void 0===e?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e}}},[n])}});
3
3
  //# sourceMappingURL=useTheme.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docsearch/core",
3
3
  "description": "Core package logic for DocSearch",
4
- "version": "4.5.2",
4
+ "version": "4.5.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docsearch.algolia.com",
7
7
  "repository": {