|
1 /******/ var __webpack_modules__ = ({ |
|
2 |
|
3 /***/ 622: |
|
4 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
|
5 |
|
6 /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
|
7 /* harmony export */ Ob: () => (/* binding */ J), |
|
8 /* harmony export */ Qv: () => (/* binding */ G), |
|
9 /* harmony export */ XX: () => (/* binding */ E), |
|
10 /* harmony export */ fF: () => (/* binding */ l), |
|
11 /* harmony export */ h: () => (/* binding */ _), |
|
12 /* harmony export */ q6: () => (/* binding */ K), |
|
13 /* harmony export */ uA: () => (/* binding */ x), |
|
14 /* harmony export */ zO: () => (/* binding */ u) |
|
15 /* harmony export */ }); |
|
16 /* unused harmony exports Fragment, createElement, createRef, toChildArray */ |
|
17 var n,l,t,u,i,r,o,e,f,c,s,a,h,p={},v=[],y=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,d=Array.isArray;function w(n,l){for(var t in l)n[t]=l[t];return n}function g(n){n&&n.parentNode&&n.parentNode.removeChild(n)}function _(l,t,u){var i,r,o,e={};for(o in t)"key"==o?i=t[o]:"ref"==o?r=t[o]:e[o]=t[o];if(arguments.length>2&&(e.children=arguments.length>3?n.call(arguments,2):u),"function"==typeof l&&null!=l.defaultProps)for(o in l.defaultProps)void 0===e[o]&&(e[o]=l.defaultProps[o]);return m(l,e,i,r,null)}function m(n,u,i,r,o){var e={type:n,props:u,key:i,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:null==o?++t:o,__i:-1,__u:0};return null==o&&null!=l.vnode&&l.vnode(e),e}function b(){return{current:null}}function k(n){return n.children}function x(n,l){this.props=n,this.context=l}function S(n,l){if(null==l)return n.__?S(n.__,n.__i+1):null;for(var t;l<n.__k.length;l++)if(null!=(t=n.__k[l])&&null!=t.__e)return t.__e;return"function"==typeof n.type?S(n):null}function C(n){var l,t;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(t=n.__k[l])&&null!=t.__e){n.__e=n.__c.base=t.__e;break}return C(n)}}function M(n){(!n.__d&&(n.__d=!0)&&i.push(n)&&!$.__r++||r!==l.debounceRendering)&&((r=l.debounceRendering)||o)($)}function $(){for(var n,t,u,r,o,f,c,s=1;i.length;)i.length>s&&i.sort(e),n=i.shift(),s=i.length,n.__d&&(u=void 0,o=(r=(t=n).__v).__e,f=[],c=[],t.__P&&((u=w({},r)).__v=r.__v+1,l.vnode&&l.vnode(u),O(t.__P,u,r,t.__n,t.__P.namespaceURI,32&r.__u?[o]:null,f,null==o?S(r):o,!!(32&r.__u),c),u.__v=r.__v,u.__.__k[u.__i]=u,z(f,u,c),u.__e!=o&&C(u)));$.__r=0}function I(n,l,t,u,i,r,o,e,f,c,s){var a,h,y,d,w,g,_=u&&u.__k||v,m=l.length;for(f=P(t,l,_,f,m),a=0;a<m;a++)null!=(y=t.__k[a])&&(h=-1===y.__i?p:_[y.__i]||p,y.__i=a,g=O(n,y,h,i,r,o,e,f,c,s),d=y.__e,y.ref&&h.ref!=y.ref&&(h.ref&&q(h.ref,null,y),s.push(y.ref,y.__c||d,y)),null==w&&null!=d&&(w=d),4&y.__u||h.__k===y.__k?f=A(y,f,n):"function"==typeof y.type&&void 0!==g?f=g:d&&(f=d.nextSibling),y.__u&=-7);return t.__e=w,f}function P(n,l,t,u,i){var r,o,e,f,c,s=t.length,a=s,h=0;for(n.__k=new Array(i),r=0;r<i;r++)null!=(o=l[r])&&"boolean"!=typeof o&&"function"!=typeof o?(f=r+h,(o=n.__k[r]="string"==typeof o||"number"==typeof o||"bigint"==typeof o||o.constructor==String?m(null,o,null,null,null):d(o)?m(k,{children:o},null,null,null):void 0===o.constructor&&o.__b>0?m(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):o).__=n,o.__b=n.__b+1,e=null,-1!==(c=o.__i=L(o,t,f,a))&&(a--,(e=t[c])&&(e.__u|=2)),null==e||null===e.__v?(-1==c&&(i>s?h--:i<s&&h++),"function"!=typeof o.type&&(o.__u|=4)):c!=f&&(c==f-1?h--:c==f+1?h++:(c>f?h--:h++,o.__u|=4))):n.__k[r]=null;if(a)for(r=0;r<s;r++)null!=(e=t[r])&&0==(2&e.__u)&&(e.__e==u&&(u=S(e)),B(e,e));return u}function A(n,l,t){var u,i;if("function"==typeof n.type){for(u=n.__k,i=0;u&&i<u.length;i++)u[i]&&(u[i].__=n,l=A(u[i],l,t));return l}n.__e!=l&&(l&&n.type&&!t.contains(l)&&(l=S(n)),t.insertBefore(n.__e,l||null),l=n.__e);do{l=l&&l.nextSibling}while(null!=l&&8==l.nodeType);return l}function H(n,l){return l=l||[],null==n||"boolean"==typeof n||(d(n)?n.some(function(n){H(n,l)}):l.push(n)),l}function L(n,l,t,u){var i,r,o=n.key,e=n.type,f=l[t];if(null===f&&null==n.key||f&&o==f.key&&e===f.type&&0==(2&f.__u))return t;if(u>(null!=f&&0==(2&f.__u)?1:0))for(i=t-1,r=t+1;i>=0||r<l.length;){if(i>=0){if((f=l[i])&&0==(2&f.__u)&&o==f.key&&e===f.type)return i;i--}if(r<l.length){if((f=l[r])&&0==(2&f.__u)&&o==f.key&&e===f.type)return r;r++}}return-1}function T(n,l,t){"-"==l[0]?n.setProperty(l,null==t?"":t):n[l]=null==t?"":"number"!=typeof t||y.test(l)?t:t+"px"}function j(n,l,t,u,i){var r;n:if("style"==l)if("string"==typeof t)n.style.cssText=t;else{if("string"==typeof u&&(n.style.cssText=u=""),u)for(l in u)t&&l in t||T(n.style,l,"");if(t)for(l in t)u&&t[l]===u[l]||T(n.style,l,t[l])}else if("o"==l[0]&&"n"==l[1])r=l!=(l=l.replace(f,"$1")),l=l.toLowerCase()in n||"onFocusOut"==l||"onFocusIn"==l?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+r]=t,t?u?t.t=u.t:(t.t=c,n.addEventListener(l,r?a:s,r)):n.removeEventListener(l,r?a:s,r);else{if("http://www.w3.org/2000/svg"==i)l=l.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if("width"!=l&&"height"!=l&&"href"!=l&&"list"!=l&&"form"!=l&&"tabIndex"!=l&&"download"!=l&&"rowSpan"!=l&&"colSpan"!=l&&"role"!=l&&"popover"!=l&&l in n)try{n[l]=null==t?"":t;break n}catch(n){}"function"==typeof t||(null==t||!1===t&&"-"!=l[4]?n.removeAttribute(l):n.setAttribute(l,"popover"==l&&1==t?"":t))}}function F(n){return function(t){if(this.l){var u=this.l[t.type+n];if(null==t.u)t.u=c++;else if(t.u<u.t)return;return u(l.event?l.event(t):t)}}}function O(n,t,u,i,r,o,e,f,c,s){var a,h,p,v,y,_,m,b,S,C,M,$,P,A,H,L,T,j=t.type;if(void 0!==t.constructor)return null;128&u.__u&&(c=!!(32&u.__u),o=[f=t.__e=u.__e]),(a=l.__b)&&a(t);n:if("function"==typeof j)try{if(b=t.props,S="prototype"in j&&j.prototype.render,C=(a=j.contextType)&&i[a.__c],M=a?C?C.props.value:a.__:i,u.__c?m=(h=t.__c=u.__c).__=h.__E:(S?t.__c=h=new j(b,M):(t.__c=h=new x(b,M),h.constructor=j,h.render=D),C&&C.sub(h),h.props=b,h.state||(h.state={}),h.context=M,h.__n=i,p=h.__d=!0,h.__h=[],h._sb=[]),S&&null==h.__s&&(h.__s=h.state),S&&null!=j.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=w({},h.__s)),w(h.__s,j.getDerivedStateFromProps(b,h.__s))),v=h.props,y=h.state,h.__v=t,p)S&&null==j.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),S&&null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(S&&null==j.getDerivedStateFromProps&&b!==v&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(b,M),!h.__e&&(null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(b,h.__s,M)||t.__v==u.__v)){for(t.__v!=u.__v&&(h.props=b,h.state=h.__s,h.__d=!1),t.__e=u.__e,t.__k=u.__k,t.__k.some(function(n){n&&(n.__=t)}),$=0;$<h._sb.length;$++)h.__h.push(h._sb[$]);h._sb=[],h.__h.length&&e.push(h);break n}null!=h.componentWillUpdate&&h.componentWillUpdate(b,h.__s,M),S&&null!=h.componentDidUpdate&&h.__h.push(function(){h.componentDidUpdate(v,y,_)})}if(h.context=M,h.props=b,h.__P=n,h.__e=!1,P=l.__r,A=0,S){for(h.state=h.__s,h.__d=!1,P&&P(t),a=h.render(h.props,h.state,h.context),H=0;H<h._sb.length;H++)h.__h.push(h._sb[H]);h._sb=[]}else do{h.__d=!1,P&&P(t),a=h.render(h.props,h.state,h.context),h.state=h.__s}while(h.__d&&++A<25);h.state=h.__s,null!=h.getChildContext&&(i=w(w({},i),h.getChildContext())),S&&!p&&null!=h.getSnapshotBeforeUpdate&&(_=h.getSnapshotBeforeUpdate(v,y)),L=a,null!=a&&a.type===k&&null==a.key&&(L=N(a.props.children)),f=I(n,d(L)?L:[L],t,u,i,r,o,e,f,c,s),h.base=t.__e,t.__u&=-161,h.__h.length&&e.push(h),m&&(h.__E=h.__=null)}catch(n){if(t.__v=null,c||null!=o)if(n.then){for(t.__u|=c?160:128;f&&8==f.nodeType&&f.nextSibling;)f=f.nextSibling;o[o.indexOf(f)]=null,t.__e=f}else for(T=o.length;T--;)g(o[T]);else t.__e=u.__e,t.__k=u.__k;l.__e(n,t,u)}else null==o&&t.__v==u.__v?(t.__k=u.__k,t.__e=u.__e):f=t.__e=V(u.__e,t,u,i,r,o,e,c,s);return(a=l.diffed)&&a(t),128&t.__u?void 0:f}function z(n,t,u){for(var i=0;i<u.length;i++)q(u[i],u[++i],u[++i]);l.__c&&l.__c(t,n),n.some(function(t){try{n=t.__h,t.__h=[],n.some(function(n){n.call(t)})}catch(n){l.__e(n,t.__v)}})}function N(n){return"object"!=typeof n||null==n?n:d(n)?n.map(N):w({},n)}function V(t,u,i,r,o,e,f,c,s){var a,h,v,y,w,_,m,b=i.props,k=u.props,x=u.type;if("svg"==x?o="http://www.w3.org/2000/svg":"math"==x?o="http://www.w3.org/1998/Math/MathML":o||(o="http://www.w3.org/1999/xhtml"),null!=e)for(a=0;a<e.length;a++)if((w=e[a])&&"setAttribute"in w==!!x&&(x?w.localName==x:3==w.nodeType)){t=w,e[a]=null;break}if(null==t){if(null==x)return document.createTextNode(k);t=document.createElementNS(o,x,k.is&&k),c&&(l.__m&&l.__m(u,e),c=!1),e=null}if(null===x)b===k||c&&t.data===k||(t.data=k);else{if(e=e&&n.call(t.childNodes),b=i.props||p,!c&&null!=e)for(b={},a=0;a<t.attributes.length;a++)b[(w=t.attributes[a]).name]=w.value;for(a in b)if(w=b[a],"children"==a);else if("dangerouslySetInnerHTML"==a)v=w;else if(!(a in k)){if("value"==a&&"defaultValue"in k||"checked"==a&&"defaultChecked"in k)continue;j(t,a,null,w,o)}for(a in k)w=k[a],"children"==a?y=w:"dangerouslySetInnerHTML"==a?h=w:"value"==a?_=w:"checked"==a?m=w:c&&"function"!=typeof w||b[a]===w||j(t,a,w,b[a],o);if(h)c||v&&(h.__html===v.__html||h.__html===t.innerHTML)||(t.innerHTML=h.__html),u.__k=[];else if(v&&(t.innerHTML=""),I("template"===u.type?t.content:t,d(y)?y:[y],u,i,r,"foreignObject"==x?"http://www.w3.org/1999/xhtml":o,e,f,e?e[0]:i.__k&&S(i,0),c,s),null!=e)for(a=e.length;a--;)g(e[a]);c||(a="value","progress"==x&&null==_?t.removeAttribute("value"):void 0!==_&&(_!==t[a]||"progress"==x&&!_||"option"==x&&_!==b[a])&&j(t,a,_,b[a],o),a="checked",void 0!==m&&m!==t[a]&&j(t,a,m,b[a],o))}return t}function q(n,t,u){try{if("function"==typeof n){var i="function"==typeof n.__u;i&&n.__u(),i&&null==t||(n.__u=n(t))}else n.current=t}catch(n){l.__e(n,u)}}function B(n,t,u){var i,r;if(l.unmount&&l.unmount(n),(i=n.ref)&&(i.current&&i.current!==n.__e||q(i,null,t)),null!=(i=n.__c)){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(n){l.__e(n,t)}i.base=i.__P=null}if(i=n.__k)for(r=0;r<i.length;r++)i[r]&&B(i[r],t,u||"function"!=typeof n.type);u||g(n.__e),n.__c=n.__=n.__e=void 0}function D(n,l,t){return this.constructor(n,t)}function E(t,u,i){var r,o,e,f;u==document&&(u=document.documentElement),l.__&&l.__(t,u),o=(r="function"==typeof i)?null:i&&i.__k||u.__k,e=[],f=[],O(u,t=(!r&&i||u).__k=_(k,null,[t]),o||p,p,u.namespaceURI,!r&&i?[i]:o?null:u.firstChild?n.call(u.childNodes):null,e,!r&&i?i:o?o.__e:u.firstChild,r,f),z(e,t,f)}function G(n,l){E(n,l,G)}function J(l,t,u){var i,r,o,e,f=w({},l.props);for(o in l.type&&l.type.defaultProps&&(e=l.type.defaultProps),t)"key"==o?i=t[o]:"ref"==o?r=t[o]:f[o]=void 0===t[o]&&void 0!==e?e[o]:t[o];return arguments.length>2&&(f.children=arguments.length>3?n.call(arguments,2):u),m(l.type,f,i||l.key,r||l.ref,null)}function K(n){function l(n){var t,u;return this.getChildContext||(t=new Set,(u={})[l.__c]=this,this.getChildContext=function(){return u},this.componentWillUnmount=function(){t=null},this.shouldComponentUpdate=function(n){this.props.value!==n.value&&t.forEach(function(n){n.__e=!0,M(n)})},this.sub=function(n){t.add(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){t&&t.delete(n),l&&l.call(n)}}),n.children}return l.__c="__cC"+h++,l.__=n,l.Provider=l.__l=(l.Consumer=function(n,l){return n.children(l)}).contextType=l,l}n=v.slice,l={__e:function(n,l,t,u){for(var i,r,o;l=l.__;)if((i=l.__c)&&!i.__)try{if((r=i.constructor)&&null!=r.getDerivedStateFromError&&(i.setState(r.getDerivedStateFromError(n)),o=i.__d),null!=i.componentDidCatch&&(i.componentDidCatch(n,u||{}),o=i.__d),o)return i.__E=i}catch(l){n=l}throw n}},t=0,u=function(n){return null!=n&&null==n.constructor},x.prototype.setState=function(n,l){var t;t=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=w({},this.state),"function"==typeof n&&(n=n(w({},t),this.props)),n&&w(t,n),null!=n&&this.__v&&(l&&this._sb.push(l),M(this))},x.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),M(this))},x.prototype.render=k,i=[],o="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,e=function(n,l){return n.__v.__b-l.__v.__b},$.__r=0,f=/(PointerCapture)$|Capture$/i,c=0,s=F(!1),a=F(!0),h=0; |
|
18 |
|
19 |
|
20 /***/ }) |
|
21 |
|
22 /******/ }); |
|
23 /************************************************************************/ |
|
24 /******/ // The module cache |
|
25 /******/ var __webpack_module_cache__ = {}; |
|
26 /******/ |
|
27 /******/ // The require function |
|
28 /******/ function __webpack_require__(moduleId) { |
|
29 /******/ // Check if module is in cache |
|
30 /******/ var cachedModule = __webpack_module_cache__[moduleId]; |
|
31 /******/ if (cachedModule !== undefined) { |
|
32 /******/ return cachedModule.exports; |
|
33 /******/ } |
|
34 /******/ // Create a new module (and put it into the cache) |
|
35 /******/ var module = __webpack_module_cache__[moduleId] = { |
|
36 /******/ // no module.id needed |
|
37 /******/ // no module.loaded needed |
|
38 /******/ exports: {} |
|
39 /******/ }; |
|
40 /******/ |
|
41 /******/ // Execute the module function |
|
42 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
|
43 /******/ |
|
44 /******/ // Return the exports of the module |
|
45 /******/ return module.exports; |
|
46 /******/ } |
|
47 /******/ |
|
48 /************************************************************************/ |
|
49 /******/ /* webpack/runtime/define property getters */ |
|
50 /******/ (() => { |
|
51 /******/ // define getter functions for harmony exports |
|
52 /******/ __webpack_require__.d = (exports, definition) => { |
|
53 /******/ for(var key in definition) { |
|
54 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
55 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
56 /******/ } |
|
57 /******/ } |
|
58 /******/ }; |
|
59 /******/ })(); |
|
60 /******/ |
|
61 /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
62 /******/ (() => { |
|
63 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
|
64 /******/ })(); |
|
65 /******/ |
|
66 /************************************************************************/ |
|
67 var __webpack_exports__ = {}; |
|
68 |
|
69 // EXPORTS |
|
70 __webpack_require__.d(__webpack_exports__, { |
|
71 zj: () => (/* reexport */ getConfig), |
|
72 SD: () => (/* reexport */ getContext), |
|
73 V6: () => (/* reexport */ getElement), |
|
74 $K: () => (/* reexport */ getServerContext), |
|
75 vT: () => (/* reexport */ getServerState), |
|
76 jb: () => (/* binding */ privateApis), |
|
77 yT: () => (/* reexport */ splitTask), |
|
78 M_: () => (/* reexport */ store), |
|
79 hb: () => (/* reexport */ useCallback), |
|
80 vJ: () => (/* reexport */ useEffect), |
|
81 ip: () => (/* reexport */ useInit), |
|
82 Nf: () => (/* reexport */ useLayoutEffect), |
|
83 Kr: () => (/* reexport */ useMemo), |
|
84 li: () => (/* reexport */ A), |
|
85 J0: () => (/* reexport */ d), |
|
86 FH: () => (/* reexport */ useWatch), |
|
87 v4: () => (/* reexport */ withScope), |
|
88 mh: () => (/* reexport */ withSyncEvent) |
|
89 }); |
|
90 |
|
91 // EXTERNAL MODULE: ./node_modules/preact/dist/preact.module.js |
|
92 var preact_module = __webpack_require__(622); |
|
93 ;// ./node_modules/preact/hooks/dist/hooks.module.js |
|
94 var hooks_module_t,r,hooks_module_u,i,hooks_module_o=0,hooks_module_f=[],hooks_module_c=preact_module/* options */.fF,e=hooks_module_c.__b,a=hooks_module_c.__r,v=hooks_module_c.diffed,l=hooks_module_c.__c,m=hooks_module_c.unmount,s=hooks_module_c.__;function p(n,t){hooks_module_c.__h&&hooks_module_c.__h(r,n,hooks_module_o||t),hooks_module_o=0;var u=r.__H||(r.__H={__:[],__h:[]});return n>=u.__.length&&u.__.push({}),u.__[n]}function d(n){return hooks_module_o=1,h(D,n)}function h(n,u,i){var o=p(hooks_module_t++,2);if(o.t=n,!o.__c&&(o.__=[i?i(u):D(void 0,u),function(n){var t=o.__N?o.__N[0]:o.__[0],r=o.t(t,n);t!==r&&(o.__N=[r,o.__[1]],o.__c.setState({}))}],o.__c=r,!r.__f)){var f=function(n,t,r){if(!o.__c.__H)return!0;var u=o.__c.__H.__.filter(function(n){return!!n.__c});if(u.every(function(n){return!n.__N}))return!c||c.call(this,n,t,r);var i=o.__c.props!==n;return u.forEach(function(n){if(n.__N){var t=n.__[0];n.__=n.__N,n.__N=void 0,t!==n.__[0]&&(i=!0)}}),c&&c.call(this,n,t,r)||i};r.__f=!0;var c=r.shouldComponentUpdate,e=r.componentWillUpdate;r.componentWillUpdate=function(n,t,r){if(this.__e){var u=c;c=void 0,f(n,t,r),c=u}e&&e.call(this,n,t,r)},r.shouldComponentUpdate=f}return o.__N||o.__}function y(n,u){var i=p(hooks_module_t++,3);!hooks_module_c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__H.__h.push(i))}function _(n,u){var i=p(hooks_module_t++,4);!hooks_module_c.__s&&C(i.__H,u)&&(i.__=n,i.u=u,r.__h.push(i))}function A(n){return hooks_module_o=5,T(function(){return{current:n}},[])}function F(n,t,r){hooks_module_o=6,_(function(){if("function"==typeof n){var r=n(t());return function(){n(null),r&&"function"==typeof r&&r()}}if(n)return n.current=t(),function(){return n.current=null}},null==r?r:r.concat(n))}function T(n,r){var u=p(hooks_module_t++,7);return C(u.__H,r)&&(u.__=n(),u.__H=r,u.__h=n),u.__}function q(n,t){return hooks_module_o=8,T(function(){return n},t)}function x(n){var u=r.context[n.__c],i=p(hooks_module_t++,9);return i.c=n,u?(null==i.__&&(i.__=!0,u.sub(r)),u.props.value):n.__}function P(n,t){hooks_module_c.useDebugValue&&hooks_module_c.useDebugValue(t?t(n):n)}function b(n){var u=p(hooks_module_t++,10),i=d();return u.__=n,r.componentDidCatch||(r.componentDidCatch=function(n,t){u.__&&u.__(n,t),i[1](n)}),[i[0],function(){i[1](void 0)}]}function g(){var n=p(hooks_module_t++,11);if(!n.__){for(var u=r.__v;null!==u&&!u.__m&&null!==u.__;)u=u.__;var i=u.__m||(u.__m=[0,0]);n.__="P"+i[0]+"-"+i[1]++}return n.__}function j(){for(var n;n=hooks_module_f.shift();)if(n.__P&&n.__H)try{n.__H.__h.forEach(z),n.__H.__h.forEach(B),n.__H.__h=[]}catch(t){n.__H.__h=[],hooks_module_c.__e(t,n.__v)}}hooks_module_c.__b=function(n){r=null,e&&e(n)},hooks_module_c.__=function(n,t){n&&t.__k&&t.__k.__m&&(n.__m=t.__k.__m),s&&s(n,t)},hooks_module_c.__r=function(n){a&&a(n),hooks_module_t=0;var i=(r=n.__c).__H;i&&(hooks_module_u===r?(i.__h=[],r.__h=[],i.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(i.__h.forEach(z),i.__h.forEach(B),i.__h=[],hooks_module_t=0)),hooks_module_u=r},hooks_module_c.diffed=function(n){v&&v(n);var t=n.__c;t&&t.__H&&(t.__H.__h.length&&(1!==hooks_module_f.push(t)&&i===hooks_module_c.requestAnimationFrame||((i=hooks_module_c.requestAnimationFrame)||w)(j)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),hooks_module_u=r=null},hooks_module_c.__c=function(n,t){t.some(function(n){try{n.__h.forEach(z),n.__h=n.__h.filter(function(n){return!n.__||B(n)})}catch(r){t.some(function(n){n.__h&&(n.__h=[])}),t=[],hooks_module_c.__e(r,n.__v)}}),l&&l(n,t)},hooks_module_c.unmount=function(n){m&&m(n);var t,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{z(n)}catch(n){t=n}}),r.__H=void 0,t&&hooks_module_c.__e(t,r.__v))};var k="function"==typeof requestAnimationFrame;function w(n){var t,r=function(){clearTimeout(u),k&&cancelAnimationFrame(t),setTimeout(n)},u=setTimeout(r,100);k&&(t=requestAnimationFrame(r))}function z(n){var t=r,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),r=t}function B(n){var t=r;n.__c=n.__(),r=t}function C(n,t){return!n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function D(n,t){return"function"==typeof t?t(n):t} |
|
95 |
|
96 ;// ./node_modules/@preact/signals-core/dist/signals-core.module.js |
|
97 var signals_core_module_i=Symbol.for("preact-signals");function signals_core_module_t(){if(!(signals_core_module_s>1)){var i,t=!1;while(void 0!==signals_core_module_h){var r=signals_core_module_h;signals_core_module_h=void 0;signals_core_module_f++;while(void 0!==r){var o=r.o;r.o=void 0;r.f&=-3;if(!(8&r.f)&&signals_core_module_c(r))try{r.c()}catch(r){if(!t){i=r;t=!0}}r=o}}signals_core_module_f=0;signals_core_module_s--;if(t)throw i}else signals_core_module_s--}function signals_core_module_r(i){if(signals_core_module_s>0)return i();signals_core_module_s++;try{return i()}finally{signals_core_module_t()}}var signals_core_module_o=void 0;function n(i){var t=signals_core_module_o;signals_core_module_o=void 0;try{return i()}finally{signals_core_module_o=t}}var signals_core_module_h=void 0,signals_core_module_s=0,signals_core_module_f=0,signals_core_module_v=0;function signals_core_module_e(i){if(void 0!==signals_core_module_o){var t=i.n;if(void 0===t||t.t!==signals_core_module_o){t={i:0,S:i,p:signals_core_module_o.s,n:void 0,t:signals_core_module_o,e:void 0,x:void 0,r:t};if(void 0!==signals_core_module_o.s)signals_core_module_o.s.n=t;signals_core_module_o.s=t;i.n=t;if(32&signals_core_module_o.f)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.n){t.n.p=t.p;if(void 0!==t.p)t.p.n=t.n;t.p=signals_core_module_o.s;t.n=void 0;signals_core_module_o.s.n=t;signals_core_module_o.s=t}return t}}}function signals_core_module_u(i){this.v=i;this.i=0;this.n=void 0;this.t=void 0}signals_core_module_u.prototype.brand=signals_core_module_i;signals_core_module_u.prototype.h=function(){return!0};signals_core_module_u.prototype.S=function(i){if(this.t!==i&&void 0===i.e){i.x=this.t;if(void 0!==this.t)this.t.e=i;this.t=i}};signals_core_module_u.prototype.U=function(i){if(void 0!==this.t){var t=i.e,r=i.x;if(void 0!==t){t.x=r;i.e=void 0}if(void 0!==r){r.e=t;i.x=void 0}if(i===this.t)this.t=r}};signals_core_module_u.prototype.subscribe=function(i){var t=this;return E(function(){var r=t.value,n=signals_core_module_o;signals_core_module_o=void 0;try{i(r)}finally{signals_core_module_o=n}})};signals_core_module_u.prototype.valueOf=function(){return this.value};signals_core_module_u.prototype.toString=function(){return this.value+""};signals_core_module_u.prototype.toJSON=function(){return this.value};signals_core_module_u.prototype.peek=function(){var i=signals_core_module_o;signals_core_module_o=void 0;try{return this.value}finally{signals_core_module_o=i}};Object.defineProperty(signals_core_module_u.prototype,"value",{get:function(){var i=signals_core_module_e(this);if(void 0!==i)i.i=this.i;return this.v},set:function(i){if(i!==this.v){if(signals_core_module_f>100)throw new Error("Cycle detected");this.v=i;this.i++;signals_core_module_v++;signals_core_module_s++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{signals_core_module_t()}}}});function signals_core_module_d(i){return new signals_core_module_u(i)}function signals_core_module_c(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function signals_core_module_a(i){for(var t=i.s;void 0!==t;t=t.n){var r=t.S.n;if(void 0!==r)t.r=r;t.S.n=t;t.i=-1;if(void 0===t.n){i.s=t;break}}}function signals_core_module_l(i){var t=i.s,r=void 0;while(void 0!==t){var o=t.p;if(-1===t.i){t.S.U(t);if(void 0!==o)o.n=t.n;if(void 0!==t.n)t.n.p=o}else r=t;t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=o}i.s=r}function signals_core_module_y(i){signals_core_module_u.call(this,void 0);this.x=i;this.s=void 0;this.g=signals_core_module_v-1;this.f=4}(signals_core_module_y.prototype=new signals_core_module_u).h=function(){this.f&=-3;if(1&this.f)return!1;if(32==(36&this.f))return!0;this.f&=-5;if(this.g===signals_core_module_v)return!0;this.g=signals_core_module_v;this.f|=1;if(this.i>0&&!signals_core_module_c(this)){this.f&=-2;return!0}var i=signals_core_module_o;try{signals_core_module_a(this);signals_core_module_o=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}signals_core_module_o=i;signals_core_module_l(this);this.f&=-2;return!0};signals_core_module_y.prototype.S=function(i){if(void 0===this.t){this.f|=36;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}signals_core_module_u.prototype.S.call(this,i)};signals_core_module_y.prototype.U=function(i){if(void 0!==this.t){signals_core_module_u.prototype.U.call(this,i);if(void 0===this.t){this.f&=-33;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}}};signals_core_module_y.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};Object.defineProperty(signals_core_module_y.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var i=signals_core_module_e(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function signals_core_module_w(i){return new signals_core_module_y(i)}function signals_core_module_(i){var r=i.u;i.u=void 0;if("function"==typeof r){signals_core_module_s++;var n=signals_core_module_o;signals_core_module_o=void 0;try{r()}catch(t){i.f&=-2;i.f|=8;signals_core_module_g(i);throw t}finally{signals_core_module_o=n;signals_core_module_t()}}}function signals_core_module_g(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;signals_core_module_(i)}function signals_core_module_p(i){if(signals_core_module_o!==this)throw new Error("Out-of-order effect");signals_core_module_l(this);signals_core_module_o=i;this.f&=-2;if(8&this.f)signals_core_module_g(this);signals_core_module_t()}function signals_core_module_b(i){this.x=i;this.u=void 0;this.s=void 0;this.o=void 0;this.f=32}signals_core_module_b.prototype.c=function(){var i=this.S();try{if(8&this.f)return;if(void 0===this.x)return;var t=this.x();if("function"==typeof t)this.u=t}finally{i()}};signals_core_module_b.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1;this.f&=-9;signals_core_module_(this);signals_core_module_a(this);signals_core_module_s++;var i=signals_core_module_o;signals_core_module_o=this;return signals_core_module_p.bind(this,i)};signals_core_module_b.prototype.N=function(){if(!(2&this.f)){this.f|=2;this.o=signals_core_module_h;signals_core_module_h=this}};signals_core_module_b.prototype.d=function(){this.f|=8;if(!(1&this.f))signals_core_module_g(this)};function E(i){var t=new signals_core_module_b(i);try{t.c()}catch(i){t.d();throw i}return t.d.bind(t)} |
|
98 ;// ./node_modules/@preact/signals/dist/signals.module.js |
|
99 var signals_module_v,signals_module_s;function signals_module_l(i,n){preact_module/* options */.fF[i]=n.bind(null,preact_module/* options */.fF[i]||function(){})}function signals_module_d(i){if(signals_module_s)signals_module_s();signals_module_s=i&&i.S()}function signals_module_h(i){var r=this,f=i.data,o=useSignal(f);o.value=f;var e=T(function(){var i=r.__v;while(i=i.__)if(i.__c){i.__c.__$f|=4;break}r.__$u.c=function(){var i,t=r.__$u.S(),f=e.value;t();if((0,preact_module/* isValidElement */.zO)(f)||3!==(null==(i=r.base)?void 0:i.nodeType)){r.__$f|=1;r.setState({})}else r.base.data=f};return signals_core_module_w(function(){var i=o.value.value;return 0===i?0:!0===i?"":i||""})},[]);return e.value}signals_module_h.displayName="_st";Object.defineProperties(signals_core_module_u.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:signals_module_h},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});signals_module_l("__b",function(i,r){if("string"==typeof r.type){var n,t=r.props;for(var f in t)if("children"!==f){var o=t[f];if(o instanceof signals_core_module_u){if(!n)r.__np=n={};n[f]=o;t[f]=o.peek()}}}i(r)});signals_module_l("__r",function(i,r){signals_module_d();var n,t=r.__c;if(t){t.__$f&=-2;if(void 0===(n=t.__$u))t.__$u=n=function(i){var r;E(function(){r=this});r.c=function(){t.__$f|=1;t.setState({})};return r}()}signals_module_v=t;signals_module_d(n);i(r)});signals_module_l("__e",function(i,r,n,t){signals_module_d();signals_module_v=void 0;i(r,n,t)});signals_module_l("diffed",function(i,r){signals_module_d();signals_module_v=void 0;var n;if("string"==typeof r.type&&(n=r.__e)){var t=r.__np,f=r.props;if(t){var o=n.U;if(o)for(var e in o){var u=o[e];if(void 0!==u&&!(e in t)){u.d();o[e]=void 0}}else n.U=o={};for(var a in t){var c=o[a],s=t[a];if(void 0===c){c=signals_module_p(n,a,s,f);o[a]=c}else c.o(s,f)}}}i(r)});function signals_module_p(i,r,n,t){var f=r in i&&void 0===i.ownerSVGElement,o=signals_core_module_d(n);return{o:function(i,r){o.value=i;t=r},d:E(function(){var n=o.value.value;if(t[r]!==n){t[r]=n;if(f)i[r]=n;else if(n)i.setAttribute(r,n);else i.removeAttribute(r)}})}}signals_module_l("unmount",function(i,r){if("string"==typeof r.type){var n=r.__e;if(n){var t=n.U;if(t){n.U=void 0;for(var f in t){var o=t[f];if(o)o.d()}}}}else{var e=r.__c;if(e){var u=e.__$u;if(u){e.__$u=void 0;u.d()}}}i(r)});signals_module_l("__h",function(i,r,n,t){if(t<3||9===t)r.__$f|=2;i(r,n,t)});preact_module/* Component */.uA.prototype.shouldComponentUpdate=function(i,r){var n=this.__$u,t=n&&void 0!==n.s;for(var f in r)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){if(!(t||2&this.__$f||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(t||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var o in i)if("__source"!==o&&i[o]!==this.props[o])return!0;for(var e in this.props)if(!(e in i))return!0;return!1};function useSignal(i){return T(function(){return signals_core_module_d(i)},[])}function useComputed(i){var r=f(i);r.current=i;signals_module_v.__$f|=4;return t(function(){return u(function(){return r.current()})},[])}function useSignalEffect(i){var r=f(i);r.current=i;o(function(){return c(function(){return r.current()})},[])} |
|
100 ;// ./node_modules/@wordpress/interactivity/build-module/namespaces.js |
|
101 const namespaceStack = []; |
|
102 const getNamespace = () => namespaceStack.slice(-1)[0]; |
|
103 const setNamespace = namespace => { |
|
104 namespaceStack.push(namespace); |
|
105 }; |
|
106 const resetNamespace = () => { |
|
107 namespaceStack.pop(); |
|
108 }; |
|
109 |
|
110 ;// ./node_modules/@wordpress/interactivity/build-module/scopes.js |
|
111 /** |
|
112 * External dependencies |
|
113 */ |
|
114 |
|
115 /** |
|
116 * Internal dependencies |
|
117 */ |
|
118 |
|
119 // Store stacks for the current scope and the default namespaces and export APIs |
|
120 // to interact with them. |
|
121 const scopeStack = []; |
|
122 const getScope = () => scopeStack.slice(-1)[0]; |
|
123 const setScope = scope => { |
|
124 scopeStack.push(scope); |
|
125 }; |
|
126 const resetScope = () => { |
|
127 scopeStack.pop(); |
|
128 }; |
|
129 |
|
130 // Wrap the element props to prevent modifications. |
|
131 const immutableMap = new WeakMap(); |
|
132 const immutableError = () => { |
|
133 throw new Error('Please use `data-wp-bind` to modify the attributes of an element.'); |
|
134 }; |
|
135 const immutableHandlers = { |
|
136 get(target, key, receiver) { |
|
137 const value = Reflect.get(target, key, receiver); |
|
138 return !!value && typeof value === 'object' ? deepImmutable(value) : value; |
|
139 }, |
|
140 set: immutableError, |
|
141 deleteProperty: immutableError |
|
142 }; |
|
143 const deepImmutable = target => { |
|
144 if (!immutableMap.has(target)) { |
|
145 immutableMap.set(target, new Proxy(target, immutableHandlers)); |
|
146 } |
|
147 return immutableMap.get(target); |
|
148 }; |
|
149 |
|
150 /** |
|
151 * Retrieves the context inherited by the element evaluating a function from the |
|
152 * store. The returned value depends on the element and the namespace where the |
|
153 * function calling `getContext()` exists. |
|
154 * |
|
155 * @param namespace Store namespace. By default, the namespace where the calling |
|
156 * function exists is used. |
|
157 * @return The context content. |
|
158 */ |
|
159 const getContext = namespace => { |
|
160 const scope = getScope(); |
|
161 if (true) { |
|
162 if (!scope) { |
|
163 throw Error('Cannot call `getContext()` when there is no scope. If you are using an async function, please consider using a generator instead. If you are using some sort of async callbacks, like `setTimeout`, please wrap the callback with `withScope(callback)`.'); |
|
164 } |
|
165 } |
|
166 return scope.context[namespace || getNamespace()]; |
|
167 }; |
|
168 |
|
169 /** |
|
170 * Retrieves a representation of the element where a function from the store |
|
171 * is being evaluated. Such representation is read-only, and contains a |
|
172 * reference to the DOM element, its props and a local reactive state. |
|
173 * |
|
174 * @return Element representation. |
|
175 */ |
|
176 const getElement = () => { |
|
177 const scope = getScope(); |
|
178 if (true) { |
|
179 if (!scope) { |
|
180 throw Error('Cannot call `getElement()` when there is no scope. If you are using an async function, please consider using a generator instead. If you are using some sort of async callbacks, like `setTimeout`, please wrap the callback with `withScope(callback)`.'); |
|
181 } |
|
182 } |
|
183 const { |
|
184 ref, |
|
185 attributes |
|
186 } = scope; |
|
187 return Object.freeze({ |
|
188 ref: ref.current, |
|
189 attributes: deepImmutable(attributes) |
|
190 }); |
|
191 }; |
|
192 |
|
193 /** |
|
194 * Retrieves the part of the inherited context defined and updated from the |
|
195 * server. |
|
196 * |
|
197 * The object returned is read-only, and includes the context defined in PHP |
|
198 * with `wp_interactivity_data_wp_context()`, including the corresponding |
|
199 * inherited properties. When `actions.navigate()` is called, this object is |
|
200 * updated to reflect the changes in the new visited page, without affecting the |
|
201 * context returned by `getContext()`. Directives can subscribe to those changes |
|
202 * to update the context if needed. |
|
203 * |
|
204 * @example |
|
205 * ```js |
|
206 * store('...', { |
|
207 * callbacks: { |
|
208 * updateServerContext() { |
|
209 * const context = getContext(); |
|
210 * const serverContext = getServerContext(); |
|
211 * // Override some property with the new value that came from the server. |
|
212 * context.overridableProp = serverContext.overridableProp; |
|
213 * }, |
|
214 * }, |
|
215 * }); |
|
216 * ``` |
|
217 * |
|
218 * @param namespace Store namespace. By default, the namespace where the calling |
|
219 * function exists is used. |
|
220 * @return The server context content. |
|
221 */ |
|
222 const getServerContext = namespace => { |
|
223 const scope = getScope(); |
|
224 if (true) { |
|
225 if (!scope) { |
|
226 throw Error('Cannot call `getServerContext()` when there is no scope. If you are using an async function, please consider using a generator instead. If you are using some sort of async callbacks, like `setTimeout`, please wrap the callback with `withScope(callback)`.'); |
|
227 } |
|
228 } |
|
229 return scope.serverContext[namespace || getNamespace()]; |
|
230 }; |
|
231 |
|
232 ;// ./node_modules/@wordpress/interactivity/build-module/utils.js |
|
233 /** |
|
234 * External dependencies |
|
235 */ |
|
236 |
|
237 |
|
238 |
|
239 /** |
|
240 * Internal dependencies |
|
241 */ |
|
242 |
|
243 |
|
244 /** |
|
245 * Executes a callback function after the next frame is rendered. |
|
246 * |
|
247 * @param callback The callback function to be executed. |
|
248 * @return A promise that resolves after the callback function is executed. |
|
249 */ |
|
250 const afterNextFrame = callback => { |
|
251 return new Promise(resolve => { |
|
252 const done = () => { |
|
253 clearTimeout(timeout); |
|
254 window.cancelAnimationFrame(raf); |
|
255 setTimeout(() => { |
|
256 callback(); |
|
257 resolve(); |
|
258 }); |
|
259 }; |
|
260 const timeout = setTimeout(done, 100); |
|
261 const raf = window.requestAnimationFrame(done); |
|
262 }); |
|
263 }; |
|
264 |
|
265 /** |
|
266 * Returns a promise that resolves after yielding to main. |
|
267 * |
|
268 * @return Promise<void> |
|
269 */ |
|
270 const splitTask = typeof window.scheduler?.yield === 'function' ? window.scheduler.yield.bind(window.scheduler) : () => { |
|
271 return new Promise(resolve => { |
|
272 setTimeout(resolve, 0); |
|
273 }); |
|
274 }; |
|
275 |
|
276 /** |
|
277 * Creates a Flusher object that can be used to flush computed values and notify listeners. |
|
278 * |
|
279 * Using the mangled properties: |
|
280 * this.c: this._callback |
|
281 * this.x: this._compute |
|
282 * https://github.com/preactjs/signals/blob/main/mangle.json |
|
283 * |
|
284 * @param compute The function that computes the value to be flushed. |
|
285 * @param notify The function that notifies listeners when the value is flushed. |
|
286 * @return The Flusher object with `flush` and `dispose` properties. |
|
287 */ |
|
288 function createFlusher(compute, notify) { |
|
289 let flush = () => undefined; |
|
290 const dispose = E(function () { |
|
291 flush = this.c.bind(this); |
|
292 this.x = compute; |
|
293 this.c = notify; |
|
294 return compute(); |
|
295 }); |
|
296 return { |
|
297 flush, |
|
298 dispose |
|
299 }; |
|
300 } |
|
301 |
|
302 /** |
|
303 * Custom hook that executes a callback function whenever a signal is triggered. |
|
304 * Version of `useSignalEffect` with a `useEffect`-like execution. This hook |
|
305 * implementation comes from this PR, but we added short-cirtuiting to avoid |
|
306 * infinite loops: https://github.com/preactjs/signals/pull/290 |
|
307 * |
|
308 * @param callback The callback function to be executed. |
|
309 */ |
|
310 function utils_useSignalEffect(callback) { |
|
311 y(() => { |
|
312 let eff = null; |
|
313 let isExecuting = false; |
|
314 const notify = async () => { |
|
315 if (eff && !isExecuting) { |
|
316 isExecuting = true; |
|
317 await afterNextFrame(eff.flush); |
|
318 isExecuting = false; |
|
319 } |
|
320 }; |
|
321 eff = createFlusher(callback, notify); |
|
322 return eff.dispose; |
|
323 }, []); |
|
324 } |
|
325 |
|
326 /** |
|
327 * Returns the passed function wrapped with the current scope so it is |
|
328 * accessible whenever the function runs. This is primarily to make the scope |
|
329 * available inside hook callbacks. |
|
330 * |
|
331 * Asynchronous functions should use generators that yield promises instead of awaiting them. |
|
332 * See the documentation for details: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-interactivity/packages-interactivity-api-reference/#the-store |
|
333 * |
|
334 * @param func The passed function. |
|
335 * @return The wrapped function. |
|
336 */ |
|
337 |
|
338 function withScope(func) { |
|
339 const scope = getScope(); |
|
340 const ns = getNamespace(); |
|
341 let wrapped; |
|
342 if (func?.constructor?.name === 'GeneratorFunction') { |
|
343 wrapped = async (...args) => { |
|
344 const gen = func(...args); |
|
345 let value; |
|
346 let it; |
|
347 while (true) { |
|
348 setNamespace(ns); |
|
349 setScope(scope); |
|
350 try { |
|
351 it = gen.next(value); |
|
352 } finally { |
|
353 resetScope(); |
|
354 resetNamespace(); |
|
355 } |
|
356 try { |
|
357 value = await it.value; |
|
358 } catch (e) { |
|
359 setNamespace(ns); |
|
360 setScope(scope); |
|
361 gen.throw(e); |
|
362 } finally { |
|
363 resetScope(); |
|
364 resetNamespace(); |
|
365 } |
|
366 if (it.done) { |
|
367 break; |
|
368 } |
|
369 } |
|
370 return value; |
|
371 }; |
|
372 } else { |
|
373 wrapped = (...args) => { |
|
374 setNamespace(ns); |
|
375 setScope(scope); |
|
376 try { |
|
377 return func(...args); |
|
378 } finally { |
|
379 resetNamespace(); |
|
380 resetScope(); |
|
381 } |
|
382 }; |
|
383 } |
|
384 |
|
385 // If function was annotated via `withSyncEvent()`, maintain the annotation. |
|
386 const syncAware = func; |
|
387 if (syncAware.sync) { |
|
388 const syncAwareWrapped = wrapped; |
|
389 syncAwareWrapped.sync = true; |
|
390 return syncAwareWrapped; |
|
391 } |
|
392 return wrapped; |
|
393 } |
|
394 |
|
395 /** |
|
396 * Accepts a function that contains imperative code which runs whenever any of |
|
397 * the accessed _reactive_ properties (e.g., values from the global state or the |
|
398 * context) is modified. |
|
399 * |
|
400 * This hook makes the element's scope available so functions like |
|
401 * `getElement()` and `getContext()` can be used inside the passed callback. |
|
402 * |
|
403 * @param callback The hook callback. |
|
404 */ |
|
405 function useWatch(callback) { |
|
406 utils_useSignalEffect(withScope(callback)); |
|
407 } |
|
408 |
|
409 /** |
|
410 * Accepts a function that contains imperative code which runs only after the |
|
411 * element's first render, mainly useful for initialization logic. |
|
412 * |
|
413 * This hook makes the element's scope available so functions like |
|
414 * `getElement()` and `getContext()` can be used inside the passed callback. |
|
415 * |
|
416 * @param callback The hook callback. |
|
417 */ |
|
418 function useInit(callback) { |
|
419 y(withScope(callback), []); |
|
420 } |
|
421 |
|
422 /** |
|
423 * Accepts a function that contains imperative, possibly effectful code. The |
|
424 * effects run after browser paint, without blocking it. |
|
425 * |
|
426 * This hook is equivalent to Preact's `useEffect` and makes the element's scope |
|
427 * available so functions like `getElement()` and `getContext()` can be used |
|
428 * inside the passed callback. |
|
429 * |
|
430 * @param callback Imperative function that can return a cleanup |
|
431 * function. |
|
432 * @param inputs If present, effect will only activate if the |
|
433 * values in the list change (using `===`). |
|
434 */ |
|
435 function useEffect(callback, inputs) { |
|
436 y(withScope(callback), inputs); |
|
437 } |
|
438 |
|
439 /** |
|
440 * Accepts a function that contains imperative, possibly effectful code. Use |
|
441 * this to read layout from the DOM and synchronously re-render. |
|
442 * |
|
443 * This hook is equivalent to Preact's `useLayoutEffect` and makes the element's |
|
444 * scope available so functions like `getElement()` and `getContext()` can be |
|
445 * used inside the passed callback. |
|
446 * |
|
447 * @param callback Imperative function that can return a cleanup |
|
448 * function. |
|
449 * @param inputs If present, effect will only activate if the |
|
450 * values in the list change (using `===`). |
|
451 */ |
|
452 function useLayoutEffect(callback, inputs) { |
|
453 _(withScope(callback), inputs); |
|
454 } |
|
455 |
|
456 /** |
|
457 * Returns a memoized version of the callback that only changes if one of the |
|
458 * inputs has changed (using `===`). |
|
459 * |
|
460 * This hook is equivalent to Preact's `useCallback` and makes the element's |
|
461 * scope available so functions like `getElement()` and `getContext()` can be |
|
462 * used inside the passed callback. |
|
463 * |
|
464 * @param callback Callback function. |
|
465 * @param inputs If present, the callback will only be updated if the |
|
466 * values in the list change (using `===`). |
|
467 * |
|
468 * @return The callback function. |
|
469 */ |
|
470 function useCallback(callback, inputs) { |
|
471 return q(withScope(callback), inputs); |
|
472 } |
|
473 |
|
474 /** |
|
475 * Pass a factory function and an array of inputs. `useMemo` will only recompute |
|
476 * the memoized value when one of the inputs has changed. |
|
477 * |
|
478 * This hook is equivalent to Preact's `useMemo` and makes the element's scope |
|
479 * available so functions like `getElement()` and `getContext()` can be used |
|
480 * inside the passed factory function. |
|
481 * |
|
482 * @param factory Factory function that returns that value for memoization. |
|
483 * @param inputs If present, the factory will only be run to recompute if |
|
484 * the values in the list change (using `===`). |
|
485 * |
|
486 * @return The memoized value. |
|
487 */ |
|
488 function useMemo(factory, inputs) { |
|
489 return T(withScope(factory), inputs); |
|
490 } |
|
491 |
|
492 /** |
|
493 * Creates a root fragment by replacing a node or an array of nodes in a parent element. |
|
494 * For wrapperless hydration. |
|
495 * See https://gist.github.com/developit/f4c67a2ede71dc2fab7f357f39cff28c |
|
496 * |
|
497 * @param parent The parent element where the nodes will be replaced. |
|
498 * @param replaceNode The node or array of nodes to replace in the parent element. |
|
499 * @return The created root fragment. |
|
500 */ |
|
501 const createRootFragment = (parent, replaceNode) => { |
|
502 replaceNode = [].concat(replaceNode); |
|
503 const sibling = replaceNode[replaceNode.length - 1].nextSibling; |
|
504 function insert(child, root) { |
|
505 parent.insertBefore(child, root || sibling); |
|
506 } |
|
507 return parent.__k = { |
|
508 nodeType: 1, |
|
509 parentNode: parent, |
|
510 firstChild: replaceNode[0], |
|
511 childNodes: replaceNode, |
|
512 insertBefore: insert, |
|
513 appendChild: insert, |
|
514 removeChild(c) { |
|
515 parent.removeChild(c); |
|
516 } |
|
517 }; |
|
518 }; |
|
519 |
|
520 /** |
|
521 * Transforms a kebab-case string to camelCase. |
|
522 * |
|
523 * @param str The kebab-case string to transform to camelCase. |
|
524 * @return The transformed camelCase string. |
|
525 */ |
|
526 function kebabToCamelCase(str) { |
|
527 return str.replace(/^-+|-+$/g, '').toLowerCase().replace(/-([a-z])/g, function (_match, group1) { |
|
528 return group1.toUpperCase(); |
|
529 }); |
|
530 } |
|
531 const logged = new Set(); |
|
532 |
|
533 /** |
|
534 * Shows a warning with `message` if environment is not `production`. |
|
535 * |
|
536 * Based on the `@wordpress/warning` package. |
|
537 * |
|
538 * @param message Message to show in the warning. |
|
539 */ |
|
540 const warn = message => { |
|
541 if (true) { |
|
542 if (logged.has(message)) { |
|
543 return; |
|
544 } |
|
545 |
|
546 // eslint-disable-next-line no-console |
|
547 console.warn(message); |
|
548 |
|
549 // Throwing an error and catching it immediately to improve debugging |
|
550 // A consumer can use 'pause on caught exceptions' |
|
551 try { |
|
552 throw Error(message); |
|
553 } catch (e) { |
|
554 // Do nothing. |
|
555 } |
|
556 logged.add(message); |
|
557 } |
|
558 }; |
|
559 |
|
560 /** |
|
561 * Checks if the passed `candidate` is a plain object with just the `Object` |
|
562 * prototype. |
|
563 * |
|
564 * @param candidate The item to check. |
|
565 * @return Whether `candidate` is a plain object. |
|
566 */ |
|
567 const isPlainObject = candidate => Boolean(candidate && typeof candidate === 'object' && candidate.constructor === Object); |
|
568 |
|
569 /** |
|
570 * Indicates that the passed `callback` requires synchronous access to the event object. |
|
571 * |
|
572 * @param callback The event callback. |
|
573 * @return Altered event callback. |
|
574 */ |
|
575 function withSyncEvent(callback) { |
|
576 const syncAware = callback; |
|
577 syncAware.sync = true; |
|
578 return syncAware; |
|
579 } |
|
580 |
|
581 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/registry.js |
|
582 /** |
|
583 * Proxies for each object. |
|
584 */ |
|
585 const objToProxy = new WeakMap(); |
|
586 const proxyToObj = new WeakMap(); |
|
587 |
|
588 /** |
|
589 * Namespaces for each created proxy. |
|
590 */ |
|
591 const proxyToNs = new WeakMap(); |
|
592 |
|
593 /** |
|
594 * Object types that can be proxied. |
|
595 */ |
|
596 const supported = new Set([Object, Array]); |
|
597 |
|
598 /** |
|
599 * Returns a proxy to the passed object with the given handlers, assigning the |
|
600 * specified namespace to it. If a proxy for the passed object was created |
|
601 * before, that proxy is returned. |
|
602 * |
|
603 * @param namespace The namespace that will be associated to this proxy. |
|
604 * @param obj The object to proxify. |
|
605 * @param handlers Handlers that the proxy will use. |
|
606 * |
|
607 * @throws Error if the object cannot be proxified. Use {@link shouldProxy} to |
|
608 * check if a proxy can be created for a specific object. |
|
609 * |
|
610 * @return The created proxy. |
|
611 */ |
|
612 const createProxy = (namespace, obj, handlers) => { |
|
613 if (!shouldProxy(obj)) { |
|
614 throw Error('This object cannot be proxified.'); |
|
615 } |
|
616 if (!objToProxy.has(obj)) { |
|
617 const proxy = new Proxy(obj, handlers); |
|
618 objToProxy.set(obj, proxy); |
|
619 proxyToObj.set(proxy, obj); |
|
620 proxyToNs.set(proxy, namespace); |
|
621 } |
|
622 return objToProxy.get(obj); |
|
623 }; |
|
624 |
|
625 /** |
|
626 * Returns the proxy for the given object. If there is no associated proxy, the |
|
627 * function returns `undefined`. |
|
628 * |
|
629 * @param obj Object from which to know the proxy. |
|
630 * @return Associated proxy or `undefined`. |
|
631 */ |
|
632 const getProxyFromObject = obj => objToProxy.get(obj); |
|
633 |
|
634 /** |
|
635 * Gets the namespace associated with the given proxy. |
|
636 * |
|
637 * Proxies have a namespace assigned upon creation. See {@link createProxy}. |
|
638 * |
|
639 * @param proxy Proxy. |
|
640 * @return Namespace. |
|
641 */ |
|
642 const getNamespaceFromProxy = proxy => proxyToNs.get(proxy); |
|
643 |
|
644 /** |
|
645 * Checks if a given object can be proxied. |
|
646 * |
|
647 * @param candidate Object to know whether it can be proxied. |
|
648 * @return True if the passed instance can be proxied. |
|
649 */ |
|
650 const shouldProxy = candidate => { |
|
651 if (typeof candidate !== 'object' || candidate === null) { |
|
652 return false; |
|
653 } |
|
654 return !proxyToNs.has(candidate) && supported.has(candidate.constructor); |
|
655 }; |
|
656 |
|
657 /** |
|
658 * Returns the target object for the passed proxy. If the passed object is not a registered proxy, the |
|
659 * function returns `undefined`. |
|
660 * |
|
661 * @param proxy Proxy from which to know the target. |
|
662 * @return The target object or `undefined`. |
|
663 */ |
|
664 const getObjectFromProxy = proxy => proxyToObj.get(proxy); |
|
665 |
|
666 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/signals.js |
|
667 /** |
|
668 * External dependencies |
|
669 */ |
|
670 |
|
671 |
|
672 /** |
|
673 * Internal dependencies |
|
674 */ |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 /** |
|
681 * Identifier for property computeds not associated to any scope. |
|
682 */ |
|
683 const NO_SCOPE = {}; |
|
684 |
|
685 /** |
|
686 * Structure that manages reactivity for a property in a state object. It uses |
|
687 * signals to keep track of property value or getter modifications. |
|
688 */ |
|
689 class PropSignal { |
|
690 /** |
|
691 * Proxy that holds the property this PropSignal is associated with. |
|
692 */ |
|
693 |
|
694 /** |
|
695 * Relation of computeds by scope. These computeds are read-only signals |
|
696 * that depend on whether the property is a value or a getter and, |
|
697 * therefore, can return different values depending on the scope in which |
|
698 * the getter is accessed. |
|
699 */ |
|
700 |
|
701 /** |
|
702 * Signal with the value assigned to the related property. |
|
703 */ |
|
704 |
|
705 /** |
|
706 * Signal with the getter assigned to the related property. |
|
707 */ |
|
708 |
|
709 /** |
|
710 * Structure that manages reactivity for a property in a state object, using |
|
711 * signals to keep track of property value or getter modifications. |
|
712 * |
|
713 * @param owner Proxy that holds the property this instance is associated |
|
714 * with. |
|
715 */ |
|
716 constructor(owner) { |
|
717 this.owner = owner; |
|
718 this.computedsByScope = new WeakMap(); |
|
719 } |
|
720 |
|
721 /** |
|
722 * Changes the internal value. If a getter was set before, it is set to |
|
723 * `undefined`. |
|
724 * |
|
725 * @param value New value. |
|
726 */ |
|
727 setValue(value) { |
|
728 this.update({ |
|
729 value |
|
730 }); |
|
731 } |
|
732 |
|
733 /** |
|
734 * Changes the internal getter. If a value was set before, it is set to |
|
735 * `undefined`. |
|
736 * |
|
737 * @param getter New getter. |
|
738 */ |
|
739 setGetter(getter) { |
|
740 this.update({ |
|
741 get: getter |
|
742 }); |
|
743 } |
|
744 |
|
745 /** |
|
746 * Returns the computed that holds the result of evaluating the prop in the |
|
747 * current scope. |
|
748 * |
|
749 * These computeds are read-only signals that depend on whether the property |
|
750 * is a value or a getter and, therefore, can return different values |
|
751 * depending on the scope in which the getter is accessed. |
|
752 * |
|
753 * @return Computed that depends on the scope. |
|
754 */ |
|
755 getComputed() { |
|
756 const scope = getScope() || NO_SCOPE; |
|
757 if (!this.valueSignal && !this.getterSignal) { |
|
758 this.update({}); |
|
759 } |
|
760 if (!this.computedsByScope.has(scope)) { |
|
761 const callback = () => { |
|
762 const getter = this.getterSignal?.value; |
|
763 return getter ? getter.call(this.owner) : this.valueSignal?.value; |
|
764 }; |
|
765 setNamespace(getNamespaceFromProxy(this.owner)); |
|
766 this.computedsByScope.set(scope, signals_core_module_w(withScope(callback))); |
|
767 resetNamespace(); |
|
768 } |
|
769 return this.computedsByScope.get(scope); |
|
770 } |
|
771 |
|
772 /** |
|
773 * Update the internal signals for the value and the getter of the |
|
774 * corresponding prop. |
|
775 * |
|
776 * @param param0 |
|
777 * @param param0.get New getter. |
|
778 * @param param0.value New value. |
|
779 */ |
|
780 update({ |
|
781 get, |
|
782 value |
|
783 }) { |
|
784 if (!this.valueSignal) { |
|
785 this.valueSignal = signals_core_module_d(value); |
|
786 this.getterSignal = signals_core_module_d(get); |
|
787 } else if (value !== this.valueSignal.peek() || get !== this.getterSignal.peek()) { |
|
788 signals_core_module_r(() => { |
|
789 this.valueSignal.value = value; |
|
790 this.getterSignal.value = get; |
|
791 }); |
|
792 } |
|
793 } |
|
794 } |
|
795 |
|
796 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/state.js |
|
797 /** |
|
798 * External dependencies |
|
799 */ |
|
800 |
|
801 |
|
802 /** |
|
803 * Internal dependencies |
|
804 */ |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 /** |
|
811 * Set of built-in symbols. |
|
812 */ |
|
813 const wellKnownSymbols = new Set(Object.getOwnPropertyNames(Symbol).map(key => Symbol[key]).filter(value => typeof value === 'symbol')); |
|
814 |
|
815 /** |
|
816 * Relates each proxy with a map of {@link PropSignal} instances, representing |
|
817 * the proxy's accessed properties. |
|
818 */ |
|
819 const proxyToProps = new WeakMap(); |
|
820 |
|
821 /** |
|
822 * Checks whether a {@link PropSignal | `PropSignal`} instance exists for the |
|
823 * given property in the passed proxy. |
|
824 * |
|
825 * @param proxy Proxy of a state object or array. |
|
826 * @param key The property key. |
|
827 * @return `true` when it exists; false otherwise. |
|
828 */ |
|
829 const hasPropSignal = (proxy, key) => proxyToProps.has(proxy) && proxyToProps.get(proxy).has(key); |
|
830 const readOnlyProxies = new WeakSet(); |
|
831 |
|
832 /** |
|
833 * Returns the {@link PropSignal | `PropSignal`} instance associated with the |
|
834 * specified prop in the passed proxy. |
|
835 * |
|
836 * The `PropSignal` instance is generated if it doesn't exist yet, using the |
|
837 * `initial` parameter to initialize the internal signals. |
|
838 * |
|
839 * @param proxy Proxy of a state object or array. |
|
840 * @param key The property key. |
|
841 * @param initial Initial data for the `PropSignal` instance. |
|
842 * @return The `PropSignal` instance. |
|
843 */ |
|
844 const getPropSignal = (proxy, key, initial) => { |
|
845 if (!proxyToProps.has(proxy)) { |
|
846 proxyToProps.set(proxy, new Map()); |
|
847 } |
|
848 key = typeof key === 'number' ? `${key}` : key; |
|
849 const props = proxyToProps.get(proxy); |
|
850 if (!props.has(key)) { |
|
851 const ns = getNamespaceFromProxy(proxy); |
|
852 const prop = new PropSignal(proxy); |
|
853 props.set(key, prop); |
|
854 if (initial) { |
|
855 const { |
|
856 get, |
|
857 value |
|
858 } = initial; |
|
859 if (get) { |
|
860 prop.setGetter(get); |
|
861 } else { |
|
862 const readOnly = readOnlyProxies.has(proxy); |
|
863 prop.setValue(shouldProxy(value) ? proxifyState(ns, value, { |
|
864 readOnly |
|
865 }) : value); |
|
866 } |
|
867 } |
|
868 } |
|
869 return props.get(key); |
|
870 }; |
|
871 |
|
872 /** |
|
873 * Relates each proxied object (i.e., the original object) with a signal that |
|
874 * tracks changes in the number of properties. |
|
875 */ |
|
876 const objToIterable = new WeakMap(); |
|
877 |
|
878 /** |
|
879 * When this flag is `true`, it avoids any signal subscription, overriding state |
|
880 * props' "reactive" behavior. |
|
881 */ |
|
882 let peeking = false; |
|
883 |
|
884 /** |
|
885 * Handlers for reactive objects and arrays in the state. |
|
886 */ |
|
887 const stateHandlers = { |
|
888 get(target, key, receiver) { |
|
889 /* |
|
890 * The property should not be reactive for the following cases: |
|
891 * 1. While using the `peek` function to read the property. |
|
892 * 2. The property exists but comes from the Object or Array prototypes. |
|
893 * 3. The property key is a known symbol. |
|
894 */ |
|
895 if (peeking || !target.hasOwnProperty(key) && key in target || typeof key === 'symbol' && wellKnownSymbols.has(key)) { |
|
896 return Reflect.get(target, key, receiver); |
|
897 } |
|
898 |
|
899 // At this point, the property should be reactive. |
|
900 const desc = Object.getOwnPropertyDescriptor(target, key); |
|
901 const prop = getPropSignal(receiver, key, desc); |
|
902 const result = prop.getComputed().value; |
|
903 |
|
904 /* |
|
905 * Check if the property is a synchronous function. If it is, set the |
|
906 * default namespace. Synchronous functions always run in the proper scope, |
|
907 * which is set by the Directives component. |
|
908 */ |
|
909 if (typeof result === 'function') { |
|
910 const ns = getNamespaceFromProxy(receiver); |
|
911 return (...args) => { |
|
912 setNamespace(ns); |
|
913 try { |
|
914 return result.call(receiver, ...args); |
|
915 } finally { |
|
916 resetNamespace(); |
|
917 } |
|
918 }; |
|
919 } |
|
920 return result; |
|
921 }, |
|
922 set(target, key, value, receiver) { |
|
923 if (readOnlyProxies.has(receiver)) { |
|
924 return false; |
|
925 } |
|
926 setNamespace(getNamespaceFromProxy(receiver)); |
|
927 try { |
|
928 return Reflect.set(target, key, value, receiver); |
|
929 } finally { |
|
930 resetNamespace(); |
|
931 } |
|
932 }, |
|
933 defineProperty(target, key, desc) { |
|
934 if (readOnlyProxies.has(getProxyFromObject(target))) { |
|
935 return false; |
|
936 } |
|
937 const isNew = !(key in target); |
|
938 const result = Reflect.defineProperty(target, key, desc); |
|
939 if (result) { |
|
940 const receiver = getProxyFromObject(target); |
|
941 const prop = getPropSignal(receiver, key); |
|
942 const { |
|
943 get, |
|
944 value |
|
945 } = desc; |
|
946 if (get) { |
|
947 prop.setGetter(get); |
|
948 } else { |
|
949 const ns = getNamespaceFromProxy(receiver); |
|
950 prop.setValue(shouldProxy(value) ? proxifyState(ns, value) : value); |
|
951 } |
|
952 if (isNew && objToIterable.has(target)) { |
|
953 objToIterable.get(target).value++; |
|
954 } |
|
955 |
|
956 /* |
|
957 * Modify the `length` property value only if the related |
|
958 * `PropSignal` exists, which means that there are subscriptions to |
|
959 * this property. |
|
960 */ |
|
961 if (Array.isArray(target) && proxyToProps.get(receiver)?.has('length')) { |
|
962 const length = getPropSignal(receiver, 'length'); |
|
963 length.setValue(target.length); |
|
964 } |
|
965 } |
|
966 return result; |
|
967 }, |
|
968 deleteProperty(target, key) { |
|
969 if (readOnlyProxies.has(getProxyFromObject(target))) { |
|
970 return false; |
|
971 } |
|
972 const result = Reflect.deleteProperty(target, key); |
|
973 if (result) { |
|
974 const prop = getPropSignal(getProxyFromObject(target), key); |
|
975 prop.setValue(undefined); |
|
976 if (objToIterable.has(target)) { |
|
977 objToIterable.get(target).value++; |
|
978 } |
|
979 } |
|
980 return result; |
|
981 }, |
|
982 ownKeys(target) { |
|
983 if (!objToIterable.has(target)) { |
|
984 objToIterable.set(target, signals_core_module_d(0)); |
|
985 } |
|
986 /* |
|
987 *This subscribes to the signal while preventing the minifier from |
|
988 * deleting this line in production. |
|
989 */ |
|
990 objToIterable._ = objToIterable.get(target).value; |
|
991 return Reflect.ownKeys(target); |
|
992 } |
|
993 }; |
|
994 |
|
995 /** |
|
996 * Returns the proxy associated with the given state object, creating it if it |
|
997 * does not exist. |
|
998 * |
|
999 * @param namespace The namespace that will be associated to this proxy. |
|
1000 * @param obj The object to proxify. |
|
1001 * @param options Options. |
|
1002 * @param options.readOnly Read-only. |
|
1003 * |
|
1004 * @throws Error if the object cannot be proxified. Use {@link shouldProxy} to |
|
1005 * check if a proxy can be created for a specific object. |
|
1006 * |
|
1007 * @return The associated proxy. |
|
1008 */ |
|
1009 const proxifyState = (namespace, obj, options) => { |
|
1010 const proxy = createProxy(namespace, obj, stateHandlers); |
|
1011 if (options?.readOnly) { |
|
1012 readOnlyProxies.add(proxy); |
|
1013 } |
|
1014 return proxy; |
|
1015 }; |
|
1016 |
|
1017 /** |
|
1018 * Reads the value of the specified property without subscribing to it. |
|
1019 * |
|
1020 * @param obj The object to read the property from. |
|
1021 * @param key The property key. |
|
1022 * @return The property value. |
|
1023 */ |
|
1024 const peek = (obj, key) => { |
|
1025 peeking = true; |
|
1026 try { |
|
1027 return obj[key]; |
|
1028 } finally { |
|
1029 peeking = false; |
|
1030 } |
|
1031 }; |
|
1032 |
|
1033 /** |
|
1034 * Internal recursive implementation for {@link deepMerge | `deepMerge`}. |
|
1035 * |
|
1036 * @param target The target object. |
|
1037 * @param source The source object containing new values and props. |
|
1038 * @param override Whether existing props should be overwritten or not (`true` |
|
1039 * by default). |
|
1040 */ |
|
1041 const deepMergeRecursive = (target, source, override = true) => { |
|
1042 // If target is not a plain object and the source is, we don't need to merge |
|
1043 // them because the source will be used as the new value of the target. |
|
1044 if (!(isPlainObject(target) && isPlainObject(source))) { |
|
1045 return; |
|
1046 } |
|
1047 let hasNewKeys = false; |
|
1048 for (const key in source) { |
|
1049 const isNew = !(key in target); |
|
1050 hasNewKeys = hasNewKeys || isNew; |
|
1051 const desc = Object.getOwnPropertyDescriptor(source, key); |
|
1052 const proxy = getProxyFromObject(target); |
|
1053 const propSignal = !!proxy && hasPropSignal(proxy, key) && getPropSignal(proxy, key); |
|
1054 |
|
1055 // Handle getters and setters |
|
1056 if (typeof desc.get === 'function' || typeof desc.set === 'function') { |
|
1057 if (override || isNew) { |
|
1058 // Because we are setting a getter or setter, we need to use |
|
1059 // Object.defineProperty to define the property on the target object. |
|
1060 Object.defineProperty(target, key, { |
|
1061 ...desc, |
|
1062 configurable: true, |
|
1063 enumerable: true |
|
1064 }); |
|
1065 // Update the getter in the property signal if it exists |
|
1066 if (desc.get && propSignal) { |
|
1067 propSignal.setGetter(desc.get); |
|
1068 } |
|
1069 } |
|
1070 |
|
1071 // Handle nested objects |
|
1072 } else if (isPlainObject(source[key])) { |
|
1073 const targetValue = Object.getOwnPropertyDescriptor(target, key)?.value; |
|
1074 if (isNew || override && !isPlainObject(targetValue)) { |
|
1075 // Create a new object if the property is new or needs to be overridden |
|
1076 target[key] = {}; |
|
1077 if (propSignal) { |
|
1078 // Create a new proxified state for the nested object |
|
1079 const ns = getNamespaceFromProxy(proxy); |
|
1080 propSignal.setValue(proxifyState(ns, target[key])); |
|
1081 } |
|
1082 deepMergeRecursive(target[key], source[key], override); |
|
1083 } |
|
1084 // Both target and source are plain objects, merge them recursively |
|
1085 else if (isPlainObject(targetValue)) { |
|
1086 deepMergeRecursive(target[key], source[key], override); |
|
1087 } |
|
1088 |
|
1089 // Handle primitive values and non-plain objects |
|
1090 } else if (override || isNew) { |
|
1091 Object.defineProperty(target, key, desc); |
|
1092 if (propSignal) { |
|
1093 const { |
|
1094 value |
|
1095 } = desc; |
|
1096 const ns = getNamespaceFromProxy(proxy); |
|
1097 // Proxify the value if necessary before setting it in the signal |
|
1098 propSignal.setValue(shouldProxy(value) ? proxifyState(ns, value) : value); |
|
1099 } |
|
1100 } |
|
1101 } |
|
1102 if (hasNewKeys && objToIterable.has(target)) { |
|
1103 objToIterable.get(target).value++; |
|
1104 } |
|
1105 }; |
|
1106 |
|
1107 /** |
|
1108 * Recursively update prop values inside the passed `target` and nested plain |
|
1109 * objects, using the values present in `source`. References to plain objects |
|
1110 * are kept, only updating props containing primitives or arrays. Arrays are |
|
1111 * replaced instead of merged or concatenated. |
|
1112 * |
|
1113 * If the `override` parameter is set to `false`, then all values in `target` |
|
1114 * are preserved, and only new properties from `source` are added. |
|
1115 * |
|
1116 * @param target The target object. |
|
1117 * @param source The source object containing new values and props. |
|
1118 * @param override Whether existing props should be overwritten or not (`true` |
|
1119 * by default). |
|
1120 */ |
|
1121 const deepMerge = (target, source, override = true) => signals_core_module_r(() => deepMergeRecursive(getObjectFromProxy(target) || target, source, override)); |
|
1122 |
|
1123 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/store.js |
|
1124 /** |
|
1125 * Internal dependencies |
|
1126 */ |
|
1127 |
|
1128 /** |
|
1129 * External dependencies |
|
1130 */ |
|
1131 |
|
1132 |
|
1133 |
|
1134 /** |
|
1135 * Identifies the store proxies handling the root objects of each store. |
|
1136 */ |
|
1137 const storeRoots = new WeakSet(); |
|
1138 |
|
1139 /** |
|
1140 * Handlers for store proxies. |
|
1141 */ |
|
1142 const storeHandlers = { |
|
1143 get: (target, key, receiver) => { |
|
1144 const result = Reflect.get(target, key); |
|
1145 const ns = getNamespaceFromProxy(receiver); |
|
1146 |
|
1147 /* |
|
1148 * Check if the proxy is the store root and no key with that name exist. In |
|
1149 * that case, return an empty object for the requested key. |
|
1150 */ |
|
1151 if (typeof result === 'undefined' && storeRoots.has(receiver)) { |
|
1152 const obj = {}; |
|
1153 Reflect.set(target, key, obj); |
|
1154 return proxifyStore(ns, obj, false); |
|
1155 } |
|
1156 |
|
1157 /* |
|
1158 * Check if the property is a function. If it is, add the store |
|
1159 * namespace to the stack and wrap the function with the current scope. |
|
1160 * The `withScope` util handles both synchronous functions and generator |
|
1161 * functions. |
|
1162 */ |
|
1163 if (typeof result === 'function') { |
|
1164 setNamespace(ns); |
|
1165 const scoped = withScope(result); |
|
1166 resetNamespace(); |
|
1167 return scoped; |
|
1168 } |
|
1169 |
|
1170 // Check if the property is an object. If it is, proxyify it. |
|
1171 if (isPlainObject(result) && shouldProxy(result)) { |
|
1172 return proxifyStore(ns, result, false); |
|
1173 } |
|
1174 return result; |
|
1175 } |
|
1176 }; |
|
1177 |
|
1178 /** |
|
1179 * Returns the proxy associated with the given store object, creating it if it |
|
1180 * does not exist. |
|
1181 * |
|
1182 * @param namespace The namespace that will be associated to this proxy. |
|
1183 * @param obj The object to proxify. |
|
1184 * |
|
1185 * @param isRoot Whether the passed object is the store root object. |
|
1186 * @throws Error if the object cannot be proxified. Use {@link shouldProxy} to |
|
1187 * check if a proxy can be created for a specific object. |
|
1188 * |
|
1189 * @return The associated proxy. |
|
1190 */ |
|
1191 const proxifyStore = (namespace, obj, isRoot = true) => { |
|
1192 const proxy = createProxy(namespace, obj, storeHandlers); |
|
1193 if (proxy && isRoot) { |
|
1194 storeRoots.add(proxy); |
|
1195 } |
|
1196 return proxy; |
|
1197 }; |
|
1198 |
|
1199 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/context.js |
|
1200 const contextObjectToProxy = new WeakMap(); |
|
1201 const contextObjectToFallback = new WeakMap(); |
|
1202 const contextProxies = new WeakSet(); |
|
1203 const descriptor = Reflect.getOwnPropertyDescriptor; |
|
1204 |
|
1205 // TODO: Use the proxy registry to avoid multiple proxies on the same object. |
|
1206 const contextHandlers = { |
|
1207 get: (target, key) => { |
|
1208 const fallback = contextObjectToFallback.get(target); |
|
1209 // Always subscribe to prop changes in the current context. |
|
1210 const currentProp = target[key]; |
|
1211 |
|
1212 /* |
|
1213 * Return the value from `target` if it exists, or from `fallback` |
|
1214 * otherwise. This way, in the case the property doesn't exist either in |
|
1215 * `target` or `fallback`, it also subscribes to changes in the parent |
|
1216 * context. |
|
1217 */ |
|
1218 return key in target ? currentProp : fallback[key]; |
|
1219 }, |
|
1220 set: (target, key, value) => { |
|
1221 const fallback = contextObjectToFallback.get(target); |
|
1222 |
|
1223 // If the property exists in the current context, modify it. Otherwise, |
|
1224 // add it to the current context. |
|
1225 const obj = key in target || !(key in fallback) ? target : fallback; |
|
1226 obj[key] = value; |
|
1227 return true; |
|
1228 }, |
|
1229 ownKeys: target => [...new Set([...Object.keys(contextObjectToFallback.get(target)), ...Object.keys(target)])], |
|
1230 getOwnPropertyDescriptor: (target, key) => descriptor(target, key) || descriptor(contextObjectToFallback.get(target), key), |
|
1231 has: (target, key) => Reflect.has(target, key) || Reflect.has(contextObjectToFallback.get(target), key) |
|
1232 }; |
|
1233 |
|
1234 /** |
|
1235 * Wrap a context object with a proxy to reproduce the context stack. The proxy |
|
1236 * uses the passed `inherited` context as a fallback to look up for properties |
|
1237 * that don't exist in the given context. Also, updated properties are modified |
|
1238 * where they are defined, or added to the main context when they don't exist. |
|
1239 * |
|
1240 * @param current Current context. |
|
1241 * @param inherited Inherited context, used as fallback. |
|
1242 * |
|
1243 * @return The wrapped context object. |
|
1244 */ |
|
1245 const proxifyContext = (current, inherited = {}) => { |
|
1246 if (contextProxies.has(current)) { |
|
1247 throw Error('This object cannot be proxified.'); |
|
1248 } |
|
1249 // Update the fallback object reference when it changes. |
|
1250 contextObjectToFallback.set(current, inherited); |
|
1251 if (!contextObjectToProxy.has(current)) { |
|
1252 const proxy = new Proxy(current, contextHandlers); |
|
1253 contextObjectToProxy.set(current, proxy); |
|
1254 contextProxies.add(proxy); |
|
1255 } |
|
1256 return contextObjectToProxy.get(current); |
|
1257 }; |
|
1258 |
|
1259 ;// ./node_modules/@wordpress/interactivity/build-module/proxies/index.js |
|
1260 /** |
|
1261 * Internal dependencies |
|
1262 */ |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 ;// ./node_modules/@wordpress/interactivity/build-module/store.js |
|
1268 /** |
|
1269 * Internal dependencies |
|
1270 */ |
|
1271 |
|
1272 /** |
|
1273 * External dependencies |
|
1274 */ |
|
1275 |
|
1276 |
|
1277 const stores = new Map(); |
|
1278 const rawStores = new Map(); |
|
1279 const storeLocks = new Map(); |
|
1280 const storeConfigs = new Map(); |
|
1281 const serverStates = new Map(); |
|
1282 |
|
1283 /** |
|
1284 * Get the defined config for the store with the passed namespace. |
|
1285 * |
|
1286 * @param namespace Store's namespace from which to retrieve the config. |
|
1287 * @return Defined config for the given namespace. |
|
1288 */ |
|
1289 const getConfig = namespace => storeConfigs.get(namespace || getNamespace()) || {}; |
|
1290 |
|
1291 /** |
|
1292 * Get the part of the state defined and updated from the server. |
|
1293 * |
|
1294 * The object returned is read-only, and includes the state defined in PHP with |
|
1295 * `wp_interactivity_state()`. When using `actions.navigate()`, this object is |
|
1296 * updated to reflect the changes in its properties, without affecting the state |
|
1297 * returned by `store()`. Directives can subscribe to those changes to update |
|
1298 * the state if needed. |
|
1299 * |
|
1300 * @example |
|
1301 * ```js |
|
1302 * const { state } = store('myStore', { |
|
1303 * callbacks: { |
|
1304 * updateServerState() { |
|
1305 * const serverState = getServerState(); |
|
1306 * // Override some property with the new value that came from the server. |
|
1307 * state.overridableProp = serverState.overridableProp; |
|
1308 * }, |
|
1309 * }, |
|
1310 * }); |
|
1311 * ``` |
|
1312 * |
|
1313 * @param namespace Store's namespace from which to retrieve the server state. |
|
1314 * @return The server state for the given namespace. |
|
1315 */ |
|
1316 const getServerState = namespace => { |
|
1317 const ns = namespace || getNamespace(); |
|
1318 if (!serverStates.has(ns)) { |
|
1319 serverStates.set(ns, proxifyState(ns, {}, { |
|
1320 readOnly: true |
|
1321 })); |
|
1322 } |
|
1323 return serverStates.get(ns); |
|
1324 }; |
|
1325 const universalUnlock = 'I acknowledge that using a private store means my plugin will inevitably break on the next store release.'; |
|
1326 |
|
1327 /** |
|
1328 * Extends the Interactivity API global store adding the passed properties to |
|
1329 * the given namespace. It also returns stable references to the namespace |
|
1330 * content. |
|
1331 * |
|
1332 * These props typically consist of `state`, which is the reactive part of the |
|
1333 * store ― which means that any directive referencing a state property will be |
|
1334 * re-rendered anytime it changes ― and function properties like `actions` and |
|
1335 * `callbacks`, mostly used for event handlers. These props can then be |
|
1336 * referenced by any directive to make the HTML interactive. |
|
1337 * |
|
1338 * @example |
|
1339 * ```js |
|
1340 * const { state } = store( 'counter', { |
|
1341 * state: { |
|
1342 * value: 0, |
|
1343 * get double() { return state.value * 2; }, |
|
1344 * }, |
|
1345 * actions: { |
|
1346 * increment() { |
|
1347 * state.value += 1; |
|
1348 * }, |
|
1349 * }, |
|
1350 * } ); |
|
1351 * ``` |
|
1352 * |
|
1353 * The code from the example above allows blocks to subscribe and interact with |
|
1354 * the store by using directives in the HTML, e.g.: |
|
1355 * |
|
1356 * ```html |
|
1357 * <div data-wp-interactive="counter"> |
|
1358 * <button |
|
1359 * data-wp-text="state.double" |
|
1360 * data-wp-on--click="actions.increment" |
|
1361 * > |
|
1362 * 0 |
|
1363 * </button> |
|
1364 * </div> |
|
1365 * ``` |
|
1366 * @param namespace The store namespace to interact with. |
|
1367 * @param storePart Properties to add to the store namespace. |
|
1368 * @param options Options for the given namespace. |
|
1369 * |
|
1370 * @return A reference to the namespace content. |
|
1371 */ |
|
1372 |
|
1373 // Overload for when the types are inferred. |
|
1374 |
|
1375 // Overload for when types are passed via generics and they contain state. |
|
1376 |
|
1377 // Overload for when types are passed via generics and they don't contain state. |
|
1378 |
|
1379 // Overload for when types are divided into multiple parts. |
|
1380 |
|
1381 function store(namespace, { |
|
1382 state = {}, |
|
1383 ...block |
|
1384 } = {}, { |
|
1385 lock = false |
|
1386 } = {}) { |
|
1387 if (!stores.has(namespace)) { |
|
1388 // Lock the store if the passed lock is different from the universal |
|
1389 // unlock. Once the lock is set (either false, true, or a given string), |
|
1390 // it cannot change. |
|
1391 if (lock !== universalUnlock) { |
|
1392 storeLocks.set(namespace, lock); |
|
1393 } |
|
1394 const rawStore = { |
|
1395 state: proxifyState(namespace, isPlainObject(state) ? state : {}), |
|
1396 ...block |
|
1397 }; |
|
1398 const proxifiedStore = proxifyStore(namespace, rawStore); |
|
1399 rawStores.set(namespace, rawStore); |
|
1400 stores.set(namespace, proxifiedStore); |
|
1401 } else { |
|
1402 // Lock the store if it wasn't locked yet and the passed lock is |
|
1403 // different from the universal unlock. If no lock is given, the store |
|
1404 // will be public and won't accept any lock from now on. |
|
1405 if (lock !== universalUnlock && !storeLocks.has(namespace)) { |
|
1406 storeLocks.set(namespace, lock); |
|
1407 } else { |
|
1408 const storeLock = storeLocks.get(namespace); |
|
1409 const isLockValid = lock === universalUnlock || lock !== true && lock === storeLock; |
|
1410 if (!isLockValid) { |
|
1411 if (!storeLock) { |
|
1412 throw Error('Cannot lock a public store'); |
|
1413 } else { |
|
1414 throw Error('Cannot unlock a private store with an invalid lock code'); |
|
1415 } |
|
1416 } |
|
1417 } |
|
1418 const target = rawStores.get(namespace); |
|
1419 deepMerge(target, block); |
|
1420 deepMerge(target.state, state); |
|
1421 } |
|
1422 return stores.get(namespace); |
|
1423 } |
|
1424 const parseServerData = (dom = document) => { |
|
1425 var _dom$getElementById; |
|
1426 const jsonDataScriptTag = // Preferred Script Module data passing form |
|
1427 (_dom$getElementById = dom.getElementById('wp-script-module-data-@wordpress/interactivity')) !== null && _dom$getElementById !== void 0 ? _dom$getElementById : |
|
1428 // Legacy form |
|
1429 dom.getElementById('wp-interactivity-data'); |
|
1430 if (jsonDataScriptTag?.textContent) { |
|
1431 try { |
|
1432 return JSON.parse(jsonDataScriptTag.textContent); |
|
1433 } catch {} |
|
1434 } |
|
1435 return {}; |
|
1436 }; |
|
1437 const populateServerData = data => { |
|
1438 if (isPlainObject(data?.state)) { |
|
1439 Object.entries(data.state).forEach(([namespace, state]) => { |
|
1440 const st = store(namespace, {}, { |
|
1441 lock: universalUnlock |
|
1442 }); |
|
1443 deepMerge(st.state, state, false); |
|
1444 deepMerge(getServerState(namespace), state); |
|
1445 }); |
|
1446 } |
|
1447 if (isPlainObject(data?.config)) { |
|
1448 Object.entries(data.config).forEach(([namespace, config]) => { |
|
1449 storeConfigs.set(namespace, config); |
|
1450 }); |
|
1451 } |
|
1452 }; |
|
1453 |
|
1454 // Parse and populate the initial state and config. |
|
1455 const data = parseServerData(); |
|
1456 populateServerData(data); |
|
1457 |
|
1458 ;// ./node_modules/@wordpress/interactivity/build-module/hooks.js |
|
1459 // eslint-disable-next-line eslint-comments/disable-enable-pair |
|
1460 /* eslint-disable react-hooks/exhaustive-deps */ |
|
1461 |
|
1462 /** |
|
1463 * External dependencies |
|
1464 */ |
|
1465 |
|
1466 |
|
1467 /** |
|
1468 * Internal dependencies |
|
1469 */ |
|
1470 |
|
1471 |
|
1472 |
|
1473 function isNonDefaultDirectiveSuffix(entry) { |
|
1474 return entry.suffix !== null; |
|
1475 } |
|
1476 function isDefaultDirectiveSuffix(entry) { |
|
1477 return entry.suffix === null; |
|
1478 } |
|
1479 // Main context. |
|
1480 const context = (0,preact_module/* createContext */.q6)({ |
|
1481 client: {}, |
|
1482 server: {} |
|
1483 }); |
|
1484 |
|
1485 // WordPress Directives. |
|
1486 const directiveCallbacks = {}; |
|
1487 const directivePriorities = {}; |
|
1488 |
|
1489 /** |
|
1490 * Register a new directive type in the Interactivity API runtime. |
|
1491 * |
|
1492 * @example |
|
1493 * ```js |
|
1494 * directive( |
|
1495 * 'alert', // Name without the `data-wp-` prefix. |
|
1496 * ( { directives: { alert }, element, evaluate } ) => { |
|
1497 * const defaultEntry = alert.find( isDefaultDirectiveSuffix ); |
|
1498 * element.props.onclick = () => { alert( evaluate( defaultEntry ) ); } |
|
1499 * } |
|
1500 * ) |
|
1501 * ``` |
|
1502 * |
|
1503 * The previous code registers a custom directive type for displaying an alert |
|
1504 * message whenever an element using it is clicked. The message text is obtained |
|
1505 * from the store under the inherited namespace, using `evaluate`. |
|
1506 * |
|
1507 * When the HTML is processed by the Interactivity API, any element containing |
|
1508 * the `data-wp-alert` directive will have the `onclick` event handler, e.g., |
|
1509 * |
|
1510 * ```html |
|
1511 * <div data-wp-interactive="messages"> |
|
1512 * <button data-wp-alert="state.alert">Click me!</button> |
|
1513 * </div> |
|
1514 * ``` |
|
1515 * Note that, in the previous example, the directive callback gets the path |
|
1516 * value (`state.alert`) from the directive entry with suffix `null`. A |
|
1517 * custom suffix can also be specified by appending `--` to the directive |
|
1518 * attribute, followed by the suffix, like in the following HTML snippet: |
|
1519 * |
|
1520 * ```html |
|
1521 * <div data-wp-interactive="myblock"> |
|
1522 * <button |
|
1523 * data-wp-color--text="state.text" |
|
1524 * data-wp-color--background="state.background" |
|
1525 * >Click me!</button> |
|
1526 * </div> |
|
1527 * ``` |
|
1528 * |
|
1529 * This could be an hypothetical implementation of the custom directive used in |
|
1530 * the snippet above. |
|
1531 * |
|
1532 * @example |
|
1533 * ```js |
|
1534 * directive( |
|
1535 * 'color', // Name without prefix and suffix. |
|
1536 * ( { directives: { color: colors }, ref, evaluate } ) => |
|
1537 * colors.forEach( ( color ) => { |
|
1538 * if ( color.suffix = 'text' ) { |
|
1539 * ref.style.setProperty( |
|
1540 * 'color', |
|
1541 * evaluate( color.text ) |
|
1542 * ); |
|
1543 * } |
|
1544 * if ( color.suffix = 'background' ) { |
|
1545 * ref.style.setProperty( |
|
1546 * 'background-color', |
|
1547 * evaluate( color.background ) |
|
1548 * ); |
|
1549 * } |
|
1550 * } ); |
|
1551 * } |
|
1552 * ) |
|
1553 * ``` |
|
1554 * |
|
1555 * @param name Directive name, without the `data-wp-` prefix. |
|
1556 * @param callback Function that runs the directive logic. |
|
1557 * @param options Options object. |
|
1558 * @param options.priority Option to control the directive execution order. The |
|
1559 * lesser, the highest priority. Default is `10`. |
|
1560 */ |
|
1561 const directive = (name, callback, { |
|
1562 priority = 10 |
|
1563 } = {}) => { |
|
1564 directiveCallbacks[name] = callback; |
|
1565 directivePriorities[name] = priority; |
|
1566 }; |
|
1567 |
|
1568 // Resolve the path to some property of the store object. |
|
1569 const resolve = (path, namespace) => { |
|
1570 if (!namespace) { |
|
1571 warn(`Namespace missing for "${path}". The value for that path won't be resolved.`); |
|
1572 return; |
|
1573 } |
|
1574 let resolvedStore = stores.get(namespace); |
|
1575 if (typeof resolvedStore === 'undefined') { |
|
1576 resolvedStore = store(namespace, {}, { |
|
1577 lock: universalUnlock |
|
1578 }); |
|
1579 } |
|
1580 const current = { |
|
1581 ...resolvedStore, |
|
1582 context: getScope().context[namespace] |
|
1583 }; |
|
1584 try { |
|
1585 // TODO: Support lazy/dynamically initialized stores |
|
1586 return path.split('.').reduce((acc, key) => acc[key], current); |
|
1587 } catch (e) {} |
|
1588 }; |
|
1589 |
|
1590 // Generate the evaluate function. |
|
1591 const getEvaluate = ({ |
|
1592 scope |
|
1593 }) => |
|
1594 // TODO: When removing the temporarily remaining `value( ...args )` call below, remove the `...args` parameter too. |
|
1595 (entry, ...args) => { |
|
1596 let { |
|
1597 value: path, |
|
1598 namespace |
|
1599 } = entry; |
|
1600 if (typeof path !== 'string') { |
|
1601 throw new Error('The `value` prop should be a string path'); |
|
1602 } |
|
1603 // If path starts with !, remove it and save a flag. |
|
1604 const hasNegationOperator = path[0] === '!' && !!(path = path.slice(1)); |
|
1605 setScope(scope); |
|
1606 const value = resolve(path, namespace); |
|
1607 // Functions are returned without invoking them. |
|
1608 if (typeof value === 'function') { |
|
1609 // Except if they have a negation operator present, for backward compatibility. |
|
1610 // This pattern is strongly discouraged and deprecated, and it will be removed in a near future release. |
|
1611 // TODO: Remove this condition to effectively ignore negation operator when provided with a function. |
|
1612 if (hasNegationOperator) { |
|
1613 warn('Using a function with a negation operator is deprecated and will stop working in WordPress 6.9. Please use derived state instead.'); |
|
1614 const functionResult = !value(...args); |
|
1615 resetScope(); |
|
1616 return functionResult; |
|
1617 } |
|
1618 // Reset scope before return and wrap the function so it will still run within the correct scope. |
|
1619 resetScope(); |
|
1620 return (...functionArgs) => { |
|
1621 setScope(scope); |
|
1622 const functionResult = value(...functionArgs); |
|
1623 resetScope(); |
|
1624 return functionResult; |
|
1625 }; |
|
1626 } |
|
1627 const result = value; |
|
1628 resetScope(); |
|
1629 return hasNegationOperator ? !result : result; |
|
1630 }; |
|
1631 |
|
1632 // Separate directives by priority. The resulting array contains objects |
|
1633 // of directives grouped by same priority, and sorted in ascending order. |
|
1634 const getPriorityLevels = directives => { |
|
1635 const byPriority = Object.keys(directives).reduce((obj, name) => { |
|
1636 if (directiveCallbacks[name]) { |
|
1637 const priority = directivePriorities[name]; |
|
1638 (obj[priority] = obj[priority] || []).push(name); |
|
1639 } |
|
1640 return obj; |
|
1641 }, {}); |
|
1642 return Object.entries(byPriority).sort(([p1], [p2]) => parseInt(p1) - parseInt(p2)).map(([, arr]) => arr); |
|
1643 }; |
|
1644 |
|
1645 // Component that wraps each priority level of directives of an element. |
|
1646 const Directives = ({ |
|
1647 directives, |
|
1648 priorityLevels: [currentPriorityLevel, ...nextPriorityLevels], |
|
1649 element, |
|
1650 originalProps, |
|
1651 previousScope |
|
1652 }) => { |
|
1653 // Initialize the scope of this element. These scopes are different per each |
|
1654 // level because each level has a different context, but they share the same |
|
1655 // element ref, state and props. |
|
1656 const scope = A({}).current; |
|
1657 scope.evaluate = q(getEvaluate({ |
|
1658 scope |
|
1659 }), []); |
|
1660 const { |
|
1661 client, |
|
1662 server |
|
1663 } = x(context); |
|
1664 scope.context = client; |
|
1665 scope.serverContext = server; |
|
1666 /* eslint-disable react-hooks/rules-of-hooks */ |
|
1667 scope.ref = previousScope?.ref || A(null); |
|
1668 /* eslint-enable react-hooks/rules-of-hooks */ |
|
1669 |
|
1670 // Create a fresh copy of the vnode element and add the props to the scope, |
|
1671 // named as attributes (HTML Attributes). |
|
1672 element = (0,preact_module/* cloneElement */.Ob)(element, { |
|
1673 ref: scope.ref |
|
1674 }); |
|
1675 scope.attributes = element.props; |
|
1676 |
|
1677 // Recursively render the wrapper for the next priority level. |
|
1678 const children = nextPriorityLevels.length > 0 ? (0,preact_module.h)(Directives, { |
|
1679 directives, |
|
1680 priorityLevels: nextPriorityLevels, |
|
1681 element, |
|
1682 originalProps, |
|
1683 previousScope: scope |
|
1684 }) : element; |
|
1685 const props = { |
|
1686 ...originalProps, |
|
1687 children |
|
1688 }; |
|
1689 const directiveArgs = { |
|
1690 directives, |
|
1691 props, |
|
1692 element, |
|
1693 context, |
|
1694 evaluate: scope.evaluate |
|
1695 }; |
|
1696 setScope(scope); |
|
1697 for (const directiveName of currentPriorityLevel) { |
|
1698 const wrapper = directiveCallbacks[directiveName]?.(directiveArgs); |
|
1699 if (wrapper !== undefined) { |
|
1700 props.children = wrapper; |
|
1701 } |
|
1702 } |
|
1703 resetScope(); |
|
1704 return props.children; |
|
1705 }; |
|
1706 |
|
1707 // Preact Options Hook called each time a vnode is created. |
|
1708 const old = preact_module/* options */.fF.vnode; |
|
1709 preact_module/* options */.fF.vnode = vnode => { |
|
1710 if (vnode.props.__directives) { |
|
1711 const props = vnode.props; |
|
1712 const directives = props.__directives; |
|
1713 if (directives.key) { |
|
1714 vnode.key = directives.key.find(isDefaultDirectiveSuffix).value; |
|
1715 } |
|
1716 delete props.__directives; |
|
1717 const priorityLevels = getPriorityLevels(directives); |
|
1718 if (priorityLevels.length > 0) { |
|
1719 vnode.props = { |
|
1720 directives, |
|
1721 priorityLevels, |
|
1722 originalProps: props, |
|
1723 type: vnode.type, |
|
1724 element: (0,preact_module.h)(vnode.type, props), |
|
1725 top: true |
|
1726 }; |
|
1727 vnode.type = Directives; |
|
1728 } |
|
1729 } |
|
1730 if (old) { |
|
1731 old(vnode); |
|
1732 } |
|
1733 }; |
|
1734 |
|
1735 ;// ./node_modules/@wordpress/interactivity/build-module/directives.js |
|
1736 // eslint-disable-next-line eslint-comments/disable-enable-pair |
|
1737 /* eslint-disable react-hooks/exhaustive-deps */ |
|
1738 |
|
1739 /** |
|
1740 * External dependencies |
|
1741 */ |
|
1742 |
|
1743 |
|
1744 |
|
1745 /** |
|
1746 * Internal dependencies |
|
1747 */ |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 /** |
|
1754 * Recursively clone the passed object. |
|
1755 * |
|
1756 * @param source Source object. |
|
1757 * @return Cloned object. |
|
1758 */ |
|
1759 function deepClone(source) { |
|
1760 if (isPlainObject(source)) { |
|
1761 return Object.fromEntries(Object.entries(source).map(([key, value]) => [key, deepClone(value)])); |
|
1762 } |
|
1763 if (Array.isArray(source)) { |
|
1764 return source.map(i => deepClone(i)); |
|
1765 } |
|
1766 return source; |
|
1767 } |
|
1768 |
|
1769 /** |
|
1770 * Wraps event object to warn about access of synchronous properties and methods. |
|
1771 * |
|
1772 * For all store actions attached to an event listener the event object is proxied via this function, unless the action |
|
1773 * uses the `withSyncEvent()` utility to indicate that it requires synchronous access to the event object. |
|
1774 * |
|
1775 * At the moment, the proxied event only emits warnings when synchronous properties or methods are being accessed. In |
|
1776 * the future this will be changed and result in an error. The current temporary behavior allows implementers to update |
|
1777 * their relevant actions to use `withSyncEvent()`. |
|
1778 * |
|
1779 * For additional context, see https://github.com/WordPress/gutenberg/issues/64944. |
|
1780 * |
|
1781 * @param event Event object. |
|
1782 * @return Proxied event object. |
|
1783 */ |
|
1784 function wrapEventAsync(event) { |
|
1785 const handler = { |
|
1786 get(target, prop, receiver) { |
|
1787 const value = target[prop]; |
|
1788 switch (prop) { |
|
1789 case 'currentTarget': |
|
1790 warn(`Accessing the synchronous event.${prop} property in a store action without wrapping it in withSyncEvent() is deprecated and will stop working in WordPress 6.9. Please wrap the store action in withSyncEvent().`); |
|
1791 break; |
|
1792 case 'preventDefault': |
|
1793 case 'stopImmediatePropagation': |
|
1794 case 'stopPropagation': |
|
1795 warn(`Using the synchronous event.${prop}() function in a store action without wrapping it in withSyncEvent() is deprecated and will stop working in WordPress 6.9. Please wrap the store action in withSyncEvent().`); |
|
1796 break; |
|
1797 } |
|
1798 if (value instanceof Function) { |
|
1799 return function (...args) { |
|
1800 return value.apply(this === receiver ? target : this, args); |
|
1801 }; |
|
1802 } |
|
1803 return value; |
|
1804 } |
|
1805 }; |
|
1806 return new Proxy(event, handler); |
|
1807 } |
|
1808 const newRule = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g; |
|
1809 const ruleClean = /\/\*[^]*?\*\/| +/g; |
|
1810 const ruleNewline = /\n+/g; |
|
1811 const empty = ' '; |
|
1812 |
|
1813 /** |
|
1814 * Convert a css style string into a object. |
|
1815 * |
|
1816 * Made by Cristian Bote (@cristianbote) for Goober. |
|
1817 * https://unpkg.com/browse/goober@2.1.13/src/core/astish.js |
|
1818 * |
|
1819 * @param val CSS string. |
|
1820 * @return CSS object. |
|
1821 */ |
|
1822 const cssStringToObject = val => { |
|
1823 const tree = [{}]; |
|
1824 let block, left; |
|
1825 while (block = newRule.exec(val.replace(ruleClean, ''))) { |
|
1826 if (block[4]) { |
|
1827 tree.shift(); |
|
1828 } else if (block[3]) { |
|
1829 left = block[3].replace(ruleNewline, empty).trim(); |
|
1830 tree.unshift(tree[0][left] = tree[0][left] || {}); |
|
1831 } else { |
|
1832 tree[0][block[1]] = block[2].replace(ruleNewline, empty).trim(); |
|
1833 } |
|
1834 } |
|
1835 return tree[0]; |
|
1836 }; |
|
1837 |
|
1838 /** |
|
1839 * Creates a directive that adds an event listener to the global window or |
|
1840 * document object. |
|
1841 * |
|
1842 * @param type 'window' or 'document' |
|
1843 */ |
|
1844 const getGlobalEventDirective = type => { |
|
1845 return ({ |
|
1846 directives, |
|
1847 evaluate |
|
1848 }) => { |
|
1849 directives[`on-${type}`].filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
1850 const eventName = entry.suffix.split('--', 1)[0]; |
|
1851 useInit(() => { |
|
1852 const cb = event => { |
|
1853 const result = evaluate(entry); |
|
1854 if (typeof result === 'function') { |
|
1855 if (!result?.sync) { |
|
1856 event = wrapEventAsync(event); |
|
1857 } |
|
1858 result(event); |
|
1859 } |
|
1860 }; |
|
1861 const globalVar = type === 'window' ? window : document; |
|
1862 globalVar.addEventListener(eventName, cb); |
|
1863 return () => globalVar.removeEventListener(eventName, cb); |
|
1864 }); |
|
1865 }); |
|
1866 }; |
|
1867 }; |
|
1868 |
|
1869 /** |
|
1870 * Creates a directive that adds an async event listener to the global window or |
|
1871 * document object. |
|
1872 * |
|
1873 * @param type 'window' or 'document' |
|
1874 */ |
|
1875 const getGlobalAsyncEventDirective = type => { |
|
1876 return ({ |
|
1877 directives, |
|
1878 evaluate |
|
1879 }) => { |
|
1880 directives[`on-async-${type}`].filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
1881 const eventName = entry.suffix.split('--', 1)[0]; |
|
1882 useInit(() => { |
|
1883 const cb = async event => { |
|
1884 await splitTask(); |
|
1885 const result = evaluate(entry); |
|
1886 if (typeof result === 'function') { |
|
1887 result(event); |
|
1888 } |
|
1889 }; |
|
1890 const globalVar = type === 'window' ? window : document; |
|
1891 globalVar.addEventListener(eventName, cb, { |
|
1892 passive: true |
|
1893 }); |
|
1894 return () => globalVar.removeEventListener(eventName, cb); |
|
1895 }); |
|
1896 }); |
|
1897 }; |
|
1898 }; |
|
1899 /* harmony default export */ const directives = (() => { |
|
1900 // data-wp-context |
|
1901 directive('context', ({ |
|
1902 directives: { |
|
1903 context |
|
1904 }, |
|
1905 props: { |
|
1906 children |
|
1907 }, |
|
1908 context: inheritedContext |
|
1909 }) => { |
|
1910 const { |
|
1911 Provider |
|
1912 } = inheritedContext; |
|
1913 const defaultEntry = context.find(isDefaultDirectiveSuffix); |
|
1914 const { |
|
1915 client: inheritedClient, |
|
1916 server: inheritedServer |
|
1917 } = x(inheritedContext); |
|
1918 const ns = defaultEntry.namespace; |
|
1919 const client = A(proxifyState(ns, {})); |
|
1920 const server = A(proxifyState(ns, {}, { |
|
1921 readOnly: true |
|
1922 })); |
|
1923 |
|
1924 // No change should be made if `defaultEntry` does not exist. |
|
1925 const contextStack = T(() => { |
|
1926 const result = { |
|
1927 client: { |
|
1928 ...inheritedClient |
|
1929 }, |
|
1930 server: { |
|
1931 ...inheritedServer |
|
1932 } |
|
1933 }; |
|
1934 if (defaultEntry) { |
|
1935 const { |
|
1936 namespace, |
|
1937 value |
|
1938 } = defaultEntry; |
|
1939 // Check that the value is a JSON object. Send a console warning if not. |
|
1940 if (!isPlainObject(value)) { |
|
1941 warn(`The value of data-wp-context in "${namespace}" store must be a valid stringified JSON object.`); |
|
1942 } |
|
1943 deepMerge(client.current, deepClone(value), false); |
|
1944 deepMerge(server.current, deepClone(value)); |
|
1945 result.client[namespace] = proxifyContext(client.current, inheritedClient[namespace]); |
|
1946 result.server[namespace] = proxifyContext(server.current, inheritedServer[namespace]); |
|
1947 } |
|
1948 return result; |
|
1949 }, [defaultEntry, inheritedClient, inheritedServer]); |
|
1950 return (0,preact_module.h)(Provider, { |
|
1951 value: contextStack |
|
1952 }, children); |
|
1953 }, { |
|
1954 priority: 5 |
|
1955 }); |
|
1956 |
|
1957 // data-wp-watch--[name] |
|
1958 directive('watch', ({ |
|
1959 directives: { |
|
1960 watch |
|
1961 }, |
|
1962 evaluate |
|
1963 }) => { |
|
1964 watch.forEach(entry => { |
|
1965 useWatch(() => { |
|
1966 let start; |
|
1967 if (false) {} |
|
1968 let result = evaluate(entry); |
|
1969 if (typeof result === 'function') { |
|
1970 result = result(); |
|
1971 } |
|
1972 if (false) {} |
|
1973 return result; |
|
1974 }); |
|
1975 }); |
|
1976 }); |
|
1977 |
|
1978 // data-wp-init--[name] |
|
1979 directive('init', ({ |
|
1980 directives: { |
|
1981 init |
|
1982 }, |
|
1983 evaluate |
|
1984 }) => { |
|
1985 init.forEach(entry => { |
|
1986 // TODO: Replace with useEffect to prevent unneeded scopes. |
|
1987 useInit(() => { |
|
1988 let start; |
|
1989 if (false) {} |
|
1990 let result = evaluate(entry); |
|
1991 if (typeof result === 'function') { |
|
1992 result = result(); |
|
1993 } |
|
1994 if (false) {} |
|
1995 return result; |
|
1996 }); |
|
1997 }); |
|
1998 }); |
|
1999 |
|
2000 // data-wp-on--[event] |
|
2001 directive('on', ({ |
|
2002 directives: { |
|
2003 on |
|
2004 }, |
|
2005 element, |
|
2006 evaluate |
|
2007 }) => { |
|
2008 const events = new Map(); |
|
2009 on.filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
2010 const event = entry.suffix.split('--')[0]; |
|
2011 if (!events.has(event)) { |
|
2012 events.set(event, new Set()); |
|
2013 } |
|
2014 events.get(event).add(entry); |
|
2015 }); |
|
2016 events.forEach((entries, eventType) => { |
|
2017 const existingHandler = element.props[`on${eventType}`]; |
|
2018 element.props[`on${eventType}`] = event => { |
|
2019 entries.forEach(entry => { |
|
2020 if (existingHandler) { |
|
2021 existingHandler(event); |
|
2022 } |
|
2023 let start; |
|
2024 if (false) {} |
|
2025 const result = evaluate(entry); |
|
2026 if (typeof result === 'function') { |
|
2027 if (!result?.sync) { |
|
2028 event = wrapEventAsync(event); |
|
2029 } |
|
2030 result(event); |
|
2031 } |
|
2032 if (false) {} |
|
2033 }); |
|
2034 }; |
|
2035 }); |
|
2036 }); |
|
2037 |
|
2038 // data-wp-on-async--[event] |
|
2039 directive('on-async', ({ |
|
2040 directives: { |
|
2041 'on-async': onAsync |
|
2042 }, |
|
2043 element, |
|
2044 evaluate |
|
2045 }) => { |
|
2046 const events = new Map(); |
|
2047 onAsync.filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
2048 const event = entry.suffix.split('--')[0]; |
|
2049 if (!events.has(event)) { |
|
2050 events.set(event, new Set()); |
|
2051 } |
|
2052 events.get(event).add(entry); |
|
2053 }); |
|
2054 events.forEach((entries, eventType) => { |
|
2055 const existingHandler = element.props[`on${eventType}`]; |
|
2056 element.props[`on${eventType}`] = event => { |
|
2057 if (existingHandler) { |
|
2058 existingHandler(event); |
|
2059 } |
|
2060 entries.forEach(async entry => { |
|
2061 await splitTask(); |
|
2062 const result = evaluate(entry); |
|
2063 if (typeof result === 'function') { |
|
2064 result(event); |
|
2065 } |
|
2066 }); |
|
2067 }; |
|
2068 }); |
|
2069 }); |
|
2070 |
|
2071 // data-wp-on-window--[event] |
|
2072 directive('on-window', getGlobalEventDirective('window')); |
|
2073 // data-wp-on-document--[event] |
|
2074 directive('on-document', getGlobalEventDirective('document')); |
|
2075 |
|
2076 // data-wp-on-async-window--[event] |
|
2077 directive('on-async-window', getGlobalAsyncEventDirective('window')); |
|
2078 // data-wp-on-async-document--[event] |
|
2079 directive('on-async-document', getGlobalAsyncEventDirective('document')); |
|
2080 |
|
2081 // data-wp-class--[classname] |
|
2082 directive('class', ({ |
|
2083 directives: { |
|
2084 class: classNames |
|
2085 }, |
|
2086 element, |
|
2087 evaluate |
|
2088 }) => { |
|
2089 classNames.filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
2090 const className = entry.suffix; |
|
2091 let result = evaluate(entry); |
|
2092 if (typeof result === 'function') { |
|
2093 result = result(); |
|
2094 } |
|
2095 const currentClass = element.props.class || ''; |
|
2096 const classFinder = new RegExp(`(^|\\s)${className}(\\s|$)`, 'g'); |
|
2097 if (!result) { |
|
2098 element.props.class = currentClass.replace(classFinder, ' ').trim(); |
|
2099 } else if (!classFinder.test(currentClass)) { |
|
2100 element.props.class = currentClass ? `${currentClass} ${className}` : className; |
|
2101 } |
|
2102 useInit(() => { |
|
2103 /* |
|
2104 * This seems necessary because Preact doesn't change the class |
|
2105 * names on the hydration, so we have to do it manually. It doesn't |
|
2106 * need deps because it only needs to do it the first time. |
|
2107 */ |
|
2108 if (!result) { |
|
2109 element.ref.current.classList.remove(className); |
|
2110 } else { |
|
2111 element.ref.current.classList.add(className); |
|
2112 } |
|
2113 }); |
|
2114 }); |
|
2115 }); |
|
2116 |
|
2117 // data-wp-style--[style-prop] |
|
2118 directive('style', ({ |
|
2119 directives: { |
|
2120 style |
|
2121 }, |
|
2122 element, |
|
2123 evaluate |
|
2124 }) => { |
|
2125 style.filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
2126 const styleProp = entry.suffix; |
|
2127 let result = evaluate(entry); |
|
2128 if (typeof result === 'function') { |
|
2129 result = result(); |
|
2130 } |
|
2131 element.props.style = element.props.style || {}; |
|
2132 if (typeof element.props.style === 'string') { |
|
2133 element.props.style = cssStringToObject(element.props.style); |
|
2134 } |
|
2135 if (!result) { |
|
2136 delete element.props.style[styleProp]; |
|
2137 } else { |
|
2138 element.props.style[styleProp] = result; |
|
2139 } |
|
2140 useInit(() => { |
|
2141 /* |
|
2142 * This seems necessary because Preact doesn't change the styles on |
|
2143 * the hydration, so we have to do it manually. It doesn't need deps |
|
2144 * because it only needs to do it the first time. |
|
2145 */ |
|
2146 if (!result) { |
|
2147 element.ref.current.style.removeProperty(styleProp); |
|
2148 } else { |
|
2149 element.ref.current.style[styleProp] = result; |
|
2150 } |
|
2151 }); |
|
2152 }); |
|
2153 }); |
|
2154 |
|
2155 // data-wp-bind--[attribute] |
|
2156 directive('bind', ({ |
|
2157 directives: { |
|
2158 bind |
|
2159 }, |
|
2160 element, |
|
2161 evaluate |
|
2162 }) => { |
|
2163 bind.filter(isNonDefaultDirectiveSuffix).forEach(entry => { |
|
2164 const attribute = entry.suffix; |
|
2165 let result = evaluate(entry); |
|
2166 if (typeof result === 'function') { |
|
2167 result = result(); |
|
2168 } |
|
2169 element.props[attribute] = result; |
|
2170 |
|
2171 /* |
|
2172 * This is necessary because Preact doesn't change the attributes on the |
|
2173 * hydration, so we have to do it manually. It only needs to do it the |
|
2174 * first time. After that, Preact will handle the changes. |
|
2175 */ |
|
2176 useInit(() => { |
|
2177 const el = element.ref.current; |
|
2178 |
|
2179 /* |
|
2180 * We set the value directly to the corresponding HTMLElement instance |
|
2181 * property excluding the following special cases. We follow Preact's |
|
2182 * logic: https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L110-L129 |
|
2183 */ |
|
2184 if (attribute === 'style') { |
|
2185 if (typeof result === 'string') { |
|
2186 el.style.cssText = result; |
|
2187 } |
|
2188 return; |
|
2189 } else if (attribute !== 'width' && attribute !== 'height' && attribute !== 'href' && attribute !== 'list' && attribute !== 'form' && |
|
2190 /* |
|
2191 * The value for `tabindex` follows the parsing rules for an |
|
2192 * integer. If that fails, or if the attribute isn't present, then |
|
2193 * the browsers should "follow platform conventions to determine if |
|
2194 * the element should be considered as a focusable area", |
|
2195 * practically meaning that most elements get a default of `-1` (not |
|
2196 * focusable), but several also get a default of `0` (focusable in |
|
2197 * order after all elements with a positive `tabindex` value). |
|
2198 * |
|
2199 * @see https://html.spec.whatwg.org/#tabindex-value |
|
2200 */ |
|
2201 attribute !== 'tabIndex' && attribute !== 'download' && attribute !== 'rowSpan' && attribute !== 'colSpan' && attribute !== 'role' && attribute in el) { |
|
2202 try { |
|
2203 el[attribute] = result === null || result === undefined ? '' : result; |
|
2204 return; |
|
2205 } catch (err) {} |
|
2206 } |
|
2207 /* |
|
2208 * aria- and data- attributes have no boolean representation. |
|
2209 * A `false` value is different from the attribute not being |
|
2210 * present, so we can't remove it. |
|
2211 * We follow Preact's logic: https://github.com/preactjs/preact/blob/ea49f7a0f9d1ff2c98c0bdd66aa0cbc583055246/src/diff/props.js#L131C24-L136 |
|
2212 */ |
|
2213 if (result !== null && result !== undefined && (result !== false || attribute[4] === '-')) { |
|
2214 el.setAttribute(attribute, result); |
|
2215 } else { |
|
2216 el.removeAttribute(attribute); |
|
2217 } |
|
2218 }); |
|
2219 }); |
|
2220 }); |
|
2221 |
|
2222 // data-wp-ignore |
|
2223 directive('ignore', ({ |
|
2224 element: { |
|
2225 type: Type, |
|
2226 props: { |
|
2227 innerHTML, |
|
2228 ...rest |
|
2229 } |
|
2230 } |
|
2231 }) => { |
|
2232 // Preserve the initial inner HTML. |
|
2233 const cached = T(() => innerHTML, []); |
|
2234 return (0,preact_module.h)(Type, { |
|
2235 dangerouslySetInnerHTML: { |
|
2236 __html: cached |
|
2237 }, |
|
2238 ...rest |
|
2239 }); |
|
2240 }); |
|
2241 |
|
2242 // data-wp-text |
|
2243 directive('text', ({ |
|
2244 directives: { |
|
2245 text |
|
2246 }, |
|
2247 element, |
|
2248 evaluate |
|
2249 }) => { |
|
2250 const entry = text.find(isDefaultDirectiveSuffix); |
|
2251 if (!entry) { |
|
2252 element.props.children = null; |
|
2253 return; |
|
2254 } |
|
2255 try { |
|
2256 let result = evaluate(entry); |
|
2257 if (typeof result === 'function') { |
|
2258 result = result(); |
|
2259 } |
|
2260 element.props.children = typeof result === 'object' ? null : result.toString(); |
|
2261 } catch (e) { |
|
2262 element.props.children = null; |
|
2263 } |
|
2264 }); |
|
2265 |
|
2266 // data-wp-run |
|
2267 directive('run', ({ |
|
2268 directives: { |
|
2269 run |
|
2270 }, |
|
2271 evaluate |
|
2272 }) => { |
|
2273 run.forEach(entry => { |
|
2274 let result = evaluate(entry); |
|
2275 if (typeof result === 'function') { |
|
2276 result = result(); |
|
2277 } |
|
2278 return result; |
|
2279 }); |
|
2280 }); |
|
2281 |
|
2282 // data-wp-each--[item] |
|
2283 directive('each', ({ |
|
2284 directives: { |
|
2285 each, |
|
2286 'each-key': eachKey |
|
2287 }, |
|
2288 context: inheritedContext, |
|
2289 element, |
|
2290 evaluate |
|
2291 }) => { |
|
2292 if (element.type !== 'template') { |
|
2293 return; |
|
2294 } |
|
2295 const { |
|
2296 Provider |
|
2297 } = inheritedContext; |
|
2298 const inheritedValue = x(inheritedContext); |
|
2299 const [entry] = each; |
|
2300 const { |
|
2301 namespace |
|
2302 } = entry; |
|
2303 let iterable = evaluate(entry); |
|
2304 if (typeof iterable === 'function') { |
|
2305 iterable = iterable(); |
|
2306 } |
|
2307 if (typeof iterable?.[Symbol.iterator] !== 'function') { |
|
2308 return; |
|
2309 } |
|
2310 const itemProp = isNonDefaultDirectiveSuffix(entry) ? kebabToCamelCase(entry.suffix) : 'item'; |
|
2311 const result = []; |
|
2312 for (const item of iterable) { |
|
2313 const itemContext = proxifyContext(proxifyState(namespace, {}), inheritedValue.client[namespace]); |
|
2314 const mergedContext = { |
|
2315 client: { |
|
2316 ...inheritedValue.client, |
|
2317 [namespace]: itemContext |
|
2318 }, |
|
2319 server: { |
|
2320 ...inheritedValue.server |
|
2321 } |
|
2322 }; |
|
2323 |
|
2324 // Set the item after proxifying the context. |
|
2325 mergedContext.client[namespace][itemProp] = item; |
|
2326 const scope = { |
|
2327 ...getScope(), |
|
2328 context: mergedContext.client, |
|
2329 serverContext: mergedContext.server |
|
2330 }; |
|
2331 const key = eachKey ? getEvaluate({ |
|
2332 scope |
|
2333 })(eachKey[0]) : item; |
|
2334 result.push((0,preact_module.h)(Provider, { |
|
2335 value: mergedContext, |
|
2336 key |
|
2337 }, element.props.content)); |
|
2338 } |
|
2339 return result; |
|
2340 }, { |
|
2341 priority: 20 |
|
2342 }); |
|
2343 directive('each-child', () => null, { |
|
2344 priority: 1 |
|
2345 }); |
|
2346 }); |
|
2347 |
|
2348 ;// ./node_modules/@wordpress/interactivity/build-module/constants.js |
|
2349 const directivePrefix = 'wp'; |
|
2350 |
|
2351 ;// ./node_modules/@wordpress/interactivity/build-module/vdom.js |
|
2352 /** |
|
2353 * External dependencies |
|
2354 */ |
|
2355 |
|
2356 /** |
|
2357 * Internal dependencies |
|
2358 */ |
|
2359 |
|
2360 |
|
2361 const ignoreAttr = `data-${directivePrefix}-ignore`; |
|
2362 const islandAttr = `data-${directivePrefix}-interactive`; |
|
2363 const fullPrefix = `data-${directivePrefix}-`; |
|
2364 const namespaces = []; |
|
2365 const currentNamespace = () => { |
|
2366 var _namespaces; |
|
2367 return (_namespaces = namespaces[namespaces.length - 1]) !== null && _namespaces !== void 0 ? _namespaces : null; |
|
2368 }; |
|
2369 const isObject = item => Boolean(item && typeof item === 'object' && item.constructor === Object); |
|
2370 |
|
2371 // Regular expression for directive parsing. |
|
2372 const directiveParser = new RegExp(`^data-${directivePrefix}-` + |
|
2373 // ${p} must be a prefix string, like 'wp'. |
|
2374 // Match alphanumeric characters including hyphen-separated |
|
2375 // segments. It excludes underscore intentionally to prevent confusion. |
|
2376 // E.g., "custom-directive". |
|
2377 '([a-z0-9]+(?:-[a-z0-9]+)*)' + |
|
2378 // (Optional) Match '--' followed by any alphanumeric characters. It |
|
2379 // excludes underscore intentionally to prevent confusion, but it can |
|
2380 // contain multiple hyphens. E.g., "--custom-prefix--with-more-info". |
|
2381 '(?:--([a-z0-9_-]+))?$', 'i' // Case insensitive. |
|
2382 ); |
|
2383 |
|
2384 // Regular expression for reference parsing. It can contain a namespace before |
|
2385 // the reference, separated by `::`, like `some-namespace::state.somePath`. |
|
2386 // Namespaces can contain any alphanumeric characters, hyphens, underscores or |
|
2387 // forward slashes. References don't have any restrictions. |
|
2388 const nsPathRegExp = /^([\w_\/-]+)::(.+)$/; |
|
2389 const hydratedIslands = new WeakSet(); |
|
2390 |
|
2391 /** |
|
2392 * Recursive function that transforms a DOM tree into vDOM. |
|
2393 * |
|
2394 * @param root The root element or node to start traversing on. |
|
2395 * @return The resulting vDOM tree. |
|
2396 */ |
|
2397 function toVdom(root) { |
|
2398 const treeWalker = document.createTreeWalker(root, 205 // TEXT + CDATA_SECTION + COMMENT + PROCESSING_INSTRUCTION + ELEMENT |
|
2399 ); |
|
2400 function walk(node) { |
|
2401 const { |
|
2402 nodeType |
|
2403 } = node; |
|
2404 |
|
2405 // TEXT_NODE (3) |
|
2406 if (nodeType === 3) { |
|
2407 return [node.data]; |
|
2408 } |
|
2409 |
|
2410 // CDATA_SECTION_NODE (4) |
|
2411 if (nodeType === 4) { |
|
2412 var _nodeValue; |
|
2413 const next = treeWalker.nextSibling(); |
|
2414 node.replaceWith(new window.Text((_nodeValue = node.nodeValue) !== null && _nodeValue !== void 0 ? _nodeValue : '')); |
|
2415 return [node.nodeValue, next]; |
|
2416 } |
|
2417 |
|
2418 // COMMENT_NODE (8) || PROCESSING_INSTRUCTION_NODE (7) |
|
2419 if (nodeType === 8 || nodeType === 7) { |
|
2420 const next = treeWalker.nextSibling(); |
|
2421 node.remove(); |
|
2422 return [null, next]; |
|
2423 } |
|
2424 const elementNode = node; |
|
2425 const { |
|
2426 attributes |
|
2427 } = elementNode; |
|
2428 const localName = elementNode.localName; |
|
2429 const props = {}; |
|
2430 const children = []; |
|
2431 const directives = []; |
|
2432 let ignore = false; |
|
2433 let island = false; |
|
2434 for (let i = 0; i < attributes.length; i++) { |
|
2435 const attributeName = attributes[i].name; |
|
2436 const attributeValue = attributes[i].value; |
|
2437 if (attributeName[fullPrefix.length] && attributeName.slice(0, fullPrefix.length) === fullPrefix) { |
|
2438 if (attributeName === ignoreAttr) { |
|
2439 ignore = true; |
|
2440 } else { |
|
2441 var _regexResult$, _regexResult$2; |
|
2442 const regexResult = nsPathRegExp.exec(attributeValue); |
|
2443 const namespace = (_regexResult$ = regexResult?.[1]) !== null && _regexResult$ !== void 0 ? _regexResult$ : null; |
|
2444 let value = (_regexResult$2 = regexResult?.[2]) !== null && _regexResult$2 !== void 0 ? _regexResult$2 : attributeValue; |
|
2445 try { |
|
2446 const parsedValue = JSON.parse(value); |
|
2447 value = isObject(parsedValue) ? parsedValue : value; |
|
2448 } catch {} |
|
2449 if (attributeName === islandAttr) { |
|
2450 island = true; |
|
2451 const islandNamespace = |
|
2452 // eslint-disable-next-line no-nested-ternary |
|
2453 typeof value === 'string' ? value : typeof value?.namespace === 'string' ? value.namespace : null; |
|
2454 namespaces.push(islandNamespace); |
|
2455 } else { |
|
2456 directives.push([attributeName, namespace, value]); |
|
2457 } |
|
2458 } |
|
2459 } else if (attributeName === 'ref') { |
|
2460 continue; |
|
2461 } |
|
2462 props[attributeName] = attributeValue; |
|
2463 } |
|
2464 if (ignore && !island) { |
|
2465 return [(0,preact_module.h)(localName, { |
|
2466 ...props, |
|
2467 innerHTML: elementNode.innerHTML, |
|
2468 __directives: { |
|
2469 ignore: true |
|
2470 } |
|
2471 })]; |
|
2472 } |
|
2473 if (island) { |
|
2474 hydratedIslands.add(elementNode); |
|
2475 } |
|
2476 if (directives.length) { |
|
2477 props.__directives = directives.reduce((obj, [name, ns, value]) => { |
|
2478 const directiveMatch = directiveParser.exec(name); |
|
2479 if (directiveMatch === null) { |
|
2480 warn(`Found malformed directive name: ${name}.`); |
|
2481 return obj; |
|
2482 } |
|
2483 const prefix = directiveMatch[1] || ''; |
|
2484 const suffix = directiveMatch[2] || null; |
|
2485 obj[prefix] = obj[prefix] || []; |
|
2486 obj[prefix].push({ |
|
2487 namespace: ns !== null && ns !== void 0 ? ns : currentNamespace(), |
|
2488 value: value, |
|
2489 suffix |
|
2490 }); |
|
2491 return obj; |
|
2492 }, {}); |
|
2493 } |
|
2494 if (localName === 'template') { |
|
2495 props.content = [...elementNode.content.childNodes].map(childNode => toVdom(childNode)); |
|
2496 } else { |
|
2497 let child = treeWalker.firstChild(); |
|
2498 if (child) { |
|
2499 while (child) { |
|
2500 const [vnode, nextChild] = walk(child); |
|
2501 if (vnode) { |
|
2502 children.push(vnode); |
|
2503 } |
|
2504 child = nextChild || treeWalker.nextSibling(); |
|
2505 } |
|
2506 treeWalker.parentNode(); |
|
2507 } |
|
2508 } |
|
2509 |
|
2510 // Restore previous namespace. |
|
2511 if (island) { |
|
2512 namespaces.pop(); |
|
2513 } |
|
2514 return [(0,preact_module.h)(localName, props, children)]; |
|
2515 } |
|
2516 return walk(treeWalker.currentNode); |
|
2517 } |
|
2518 |
|
2519 ;// ./node_modules/@wordpress/interactivity/build-module/init.js |
|
2520 /** |
|
2521 * External dependencies |
|
2522 */ |
|
2523 |
|
2524 /** |
|
2525 * Internal dependencies |
|
2526 */ |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 // Keep the same root fragment for each interactive region node. |
|
2532 const regionRootFragments = new WeakMap(); |
|
2533 const getRegionRootFragment = region => { |
|
2534 if (!region.parentElement) { |
|
2535 throw Error('The passed region should be an element with a parent.'); |
|
2536 } |
|
2537 if (!regionRootFragments.has(region)) { |
|
2538 regionRootFragments.set(region, createRootFragment(region.parentElement, region)); |
|
2539 } |
|
2540 return regionRootFragments.get(region); |
|
2541 }; |
|
2542 |
|
2543 // Initial vDOM regions associated with its DOM element. |
|
2544 const initialVdom = new WeakMap(); |
|
2545 |
|
2546 // Initialize the router with the initial DOM. |
|
2547 const init = async () => { |
|
2548 const nodes = document.querySelectorAll(`[data-${directivePrefix}-interactive]`); |
|
2549 |
|
2550 /* |
|
2551 * This `await` with setTimeout is required to apparently ensure that the interactive blocks have their stores |
|
2552 * fully initialized prior to hydrating the blocks. If this is not present, then an error occurs, for example: |
|
2553 * > view.js:46 Uncaught (in promise) ReferenceError: Cannot access 'state' before initialization |
|
2554 * This occurs when splitTask() is implemented with scheduler.yield() as opposed to setTimeout(), as with the former |
|
2555 * split tasks are added to the front of the task queue whereas with the latter they are added to the end of the queue. |
|
2556 */ |
|
2557 await new Promise(resolve => { |
|
2558 setTimeout(resolve, 0); |
|
2559 }); |
|
2560 for (const node of nodes) { |
|
2561 if (!hydratedIslands.has(node)) { |
|
2562 await splitTask(); |
|
2563 const fragment = getRegionRootFragment(node); |
|
2564 const vdom = toVdom(node); |
|
2565 initialVdom.set(node, vdom); |
|
2566 await splitTask(); |
|
2567 (0,preact_module/* hydrate */.Qv)(vdom, fragment); |
|
2568 } |
|
2569 } |
|
2570 }; |
|
2571 |
|
2572 ;// ./node_modules/@wordpress/interactivity/build-module/index.js |
|
2573 /** |
|
2574 * External dependencies |
|
2575 */ |
|
2576 |
|
2577 |
|
2578 |
|
2579 /** |
|
2580 * Internal dependencies |
|
2581 */ |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 |
|
2594 const requiredConsent = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'; |
|
2595 const privateApis = lock => { |
|
2596 if (lock === requiredConsent) { |
|
2597 return { |
|
2598 directivePrefix: directivePrefix, |
|
2599 getRegionRootFragment: getRegionRootFragment, |
|
2600 initialVdom: initialVdom, |
|
2601 toVdom: toVdom, |
|
2602 directive: directive, |
|
2603 getNamespace: getNamespace, |
|
2604 h: preact_module.h, |
|
2605 cloneElement: preact_module/* cloneElement */.Ob, |
|
2606 render: preact_module/* render */.XX, |
|
2607 proxifyState: proxifyState, |
|
2608 parseServerData: parseServerData, |
|
2609 populateServerData: populateServerData, |
|
2610 batch: signals_core_module_r |
|
2611 }; |
|
2612 } |
|
2613 throw new Error('Forbidden access.'); |
|
2614 }; |
|
2615 directives(); |
|
2616 init(); |
|
2617 |
|
2618 var __webpack_exports__getConfig = __webpack_exports__.zj; |
|
2619 var __webpack_exports__getContext = __webpack_exports__.SD; |
|
2620 var __webpack_exports__getElement = __webpack_exports__.V6; |
|
2621 var __webpack_exports__getServerContext = __webpack_exports__.$K; |
|
2622 var __webpack_exports__getServerState = __webpack_exports__.vT; |
|
2623 var __webpack_exports__privateApis = __webpack_exports__.jb; |
|
2624 var __webpack_exports__splitTask = __webpack_exports__.yT; |
|
2625 var __webpack_exports__store = __webpack_exports__.M_; |
|
2626 var __webpack_exports__useCallback = __webpack_exports__.hb; |
|
2627 var __webpack_exports__useEffect = __webpack_exports__.vJ; |
|
2628 var __webpack_exports__useInit = __webpack_exports__.ip; |
|
2629 var __webpack_exports__useLayoutEffect = __webpack_exports__.Nf; |
|
2630 var __webpack_exports__useMemo = __webpack_exports__.Kr; |
|
2631 var __webpack_exports__useRef = __webpack_exports__.li; |
|
2632 var __webpack_exports__useState = __webpack_exports__.J0; |
|
2633 var __webpack_exports__useWatch = __webpack_exports__.FH; |
|
2634 var __webpack_exports__withScope = __webpack_exports__.v4; |
|
2635 var __webpack_exports__withSyncEvent = __webpack_exports__.mh; |
|
2636 export { __webpack_exports__getConfig as getConfig, __webpack_exports__getContext as getContext, __webpack_exports__getElement as getElement, __webpack_exports__getServerContext as getServerContext, __webpack_exports__getServerState as getServerState, __webpack_exports__privateApis as privateApis, __webpack_exports__splitTask as splitTask, __webpack_exports__store as store, __webpack_exports__useCallback as useCallback, __webpack_exports__useEffect as useEffect, __webpack_exports__useInit as useInit, __webpack_exports__useLayoutEffect as useLayoutEffect, __webpack_exports__useMemo as useMemo, __webpack_exports__useRef as useRef, __webpack_exports__useState as useState, __webpack_exports__useWatch as useWatch, __webpack_exports__withScope as withScope, __webpack_exports__withSyncEvent as withSyncEvent }; |