mirror of
https://github.com/oneclickvirt/oneclickvirt.github.io.git
synced 2026-05-30 06:39:31 +08:00
Update
This commit is contained in:
21
node_modules/preact/hooks/LICENSE
generated
vendored
Normal file
21
node_modules/preact/hooks/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Jason Miller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
2
node_modules/preact/hooks/dist/hooks.js
generated
vendored
Normal file
2
node_modules/preact/hooks/dist/hooks.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var n,t,r,u=require("preact"),o=0,i=[],c=u.options.__b,e=u.options.__r,f=u.options.diffed,a=u.options.__c,v=u.options.unmount;function p(n,r){u.options.__h&&u.options.__h(t,n,o||r),o=0;var i=t.__H||(t.__H={__:[],__h:[]});return n>=i.__.length&&i.__.push({}),i.__[n]}function s(n){return o=1,l(A,n)}function l(r,u,o){var i=p(n++,2);return i.t=r,i.__c||(i.__=[o?o(u):A(void 0,u),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}))}],i.__c=t),i.__}function x(r,o){var i=p(n++,4);!u.options.__s&&q(i.__H,o)&&(i.__=r,i.__H=o,t.__h.push(i))}function m(t,r){var u=p(n++,7);return q(u.__H,r)&&(u.__=t(),u.__H=r,u.__h=t),u.__}function y(){for(var n;n=i.shift();)if(n.__P)try{n.__H.__h.forEach(h),n.__H.__h.forEach(_),n.__H.__h=[]}catch(t){n.__H.__h=[],u.options.__e(t,n.__v)}}u.options.__b=function(n){t=null,c&&c(n)},u.options.__r=function(r){e&&e(r),n=0;var u=(t=r.__c).__H;u&&(u.__h.forEach(h),u.__h.forEach(_),u.__h=[])},u.options.diffed=function(n){f&&f(n);var o=n.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===u.options.requestAnimationFrame||((r=u.options.requestAnimationFrame)||function(n){var t,r=function(){clearTimeout(u),d&&cancelAnimationFrame(t),setTimeout(n)},u=setTimeout(r,100);d&&(t=requestAnimationFrame(r))})(y)),t=null},u.options.__c=function(n,t){t.some(function(n){try{n.__h.forEach(h),n.__h=n.__h.filter(function(n){return!n.__||_(n)})}catch(r){t.some(function(n){n.__h&&(n.__h=[])}),t=[],u.options.__e(r,n.__v)}}),a&&a(n,t)},u.options.unmount=function(n){v&&v(n);var t,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{h(n)}catch(n){t=n}}),t&&u.options.__e(t,r.__v))};var d="function"==typeof requestAnimationFrame;function h(n){var r=t,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),t=r}function _(n){var r=t;n.__c=n.__(),t=r}function q(n,t){return!n||n.length!==t.length||t.some(function(t,r){return t!==n[r]})}function A(n,t){return"function"==typeof t?t(n):t}exports.useState=s,exports.useReducer=l,exports.useEffect=function(r,o){var i=p(n++,3);!u.options.__s&&q(i.__H,o)&&(i.__=r,i.__H=o,t.__H.__h.push(i))},exports.useLayoutEffect=x,exports.useRef=function(n){return o=5,m(function(){return{current:n}},[])},exports.useImperativeHandle=function(n,t,r){o=6,x(function(){return"function"==typeof n?(n(t()),function(){return n(null)}):n?(n.current=t(),function(){return n.current=null}):void 0},null==r?r:r.concat(n))},exports.useMemo=m,exports.useCallback=function(n,t){return o=8,m(function(){return n},t)},exports.useContext=function(r){var u=t.context[r.__c],o=p(n++,9);return o.c=r,u?(null==o.__&&(o.__=!0,u.sub(t)),u.props.value):r.__},exports.useDebugValue=function(n,t){u.options.useDebugValue&&u.options.useDebugValue(t?t(n):n)},exports.useErrorBoundary=function(r){var u=p(n++,10),o=s();return u.__=r,t.componentDidCatch||(t.componentDidCatch=function(n){u.__&&u.__(n),o[1](n)}),[o[0],function(){o[1](void 0)}]};
|
||||
//# sourceMappingURL=hooks.js.map
|
||||
1
node_modules/preact/hooks/dist/hooks.js.map
generated
vendored
Normal file
1
node_modules/preact/hooks/dist/hooks.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/preact/hooks/dist/hooks.mjs
generated
vendored
Normal file
2
node_modules/preact/hooks/dist/hooks.mjs
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import{options as n}from"preact";var t,u,r,o=0,i=[],c=n.__b,f=n.__r,e=n.diffed,a=n.__c,v=n.unmount;function l(t,r){n.__h&&n.__h(u,t,o||r),o=0;var i=u.__H||(u.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({}),i.__[t]}function m(n){return o=1,p(w,n)}function p(n,r,o){var i=l(t++,2);return i.t=n,i.__c||(i.__=[o?o(r):w(void 0,r),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}))}],i.__c=u),i.__}function y(r,o){var i=l(t++,3);!n.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__H.__h.push(i))}function d(r,o){var i=l(t++,4);!n.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__h.push(i))}function h(n){return o=5,_(function(){return{current:n}},[])}function s(n,t,u){o=6,d(function(){return"function"==typeof n?(n(t()),function(){return n(null)}):n?(n.current=t(),function(){return n.current=null}):void 0},null==u?u:u.concat(n))}function _(n,u){var r=l(t++,7);return k(r.__H,u)&&(r.__=n(),r.__H=u,r.__h=n),r.__}function A(n,t){return o=8,_(function(){return n},t)}function F(n){var r=u.context[n.__c],o=l(t++,9);return o.c=n,r?(null==o.__&&(o.__=!0,r.sub(u)),r.props.value):n.__}function T(t,u){n.useDebugValue&&n.useDebugValue(u?u(t):t)}function q(n){var r=l(t++,10),o=m();return r.__=n,u.componentDidCatch||(u.componentDidCatch=function(n){r.__&&r.__(n),o[1](n)}),[o[0],function(){o[1](void 0)}]}function x(){for(var t;t=i.shift();)if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j),t.__H.__h=[]}catch(u){t.__H.__h=[],n.__e(u,t.__v)}}n.__b=function(n){u=null,c&&c(n)},n.__r=function(n){f&&f(n),t=0;var r=(u=n.__c).__H;r&&(r.__h.forEach(g),r.__h.forEach(j),r.__h=[])},n.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===n.requestAnimationFrame||((r=n.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b&&cancelAnimationFrame(t),setTimeout(n)},r=setTimeout(u,100);b&&(t=requestAnimationFrame(u))})(x)),u=null},n.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g),t.__h=t.__h.filter(function(n){return!n.__||j(n)})}catch(r){u.some(function(n){n.__h&&(n.__h=[])}),u=[],n.__e(r,t.__v)}}),a&&a(t,u)},n.unmount=function(t){v&&v(t);var u,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{g(n)}catch(n){u=n}}),u&&n.__e(u,r.__v))};var b="function"==typeof requestAnimationFrame;function g(n){var t=u,r=n.__c;"function"==typeof r&&(n.__c=void 0,r()),u=t}function j(n){var t=u;n.__c=n.__(),u=t}function k(n,t){return!n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function w(n,t){return"function"==typeof t?t(n):t}export{m as useState,p as useReducer,y as useEffect,d as useLayoutEffect,h as useRef,s as useImperativeHandle,_ as useMemo,A as useCallback,F as useContext,T as useDebugValue,q as useErrorBoundary};
|
||||
//# sourceMappingURL=hooks.module.js.map
|
||||
2
node_modules/preact/hooks/dist/hooks.module.js
generated
vendored
Normal file
2
node_modules/preact/hooks/dist/hooks.module.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import{options as n}from"preact";var t,u,r,o=0,i=[],c=n.__b,f=n.__r,e=n.diffed,a=n.__c,v=n.unmount;function l(t,r){n.__h&&n.__h(u,t,o||r),o=0;var i=u.__H||(u.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({}),i.__[t]}function m(n){return o=1,p(w,n)}function p(n,r,o){var i=l(t++,2);return i.t=n,i.__c||(i.__=[o?o(r):w(void 0,r),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}))}],i.__c=u),i.__}function y(r,o){var i=l(t++,3);!n.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__H.__h.push(i))}function d(r,o){var i=l(t++,4);!n.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__h.push(i))}function h(n){return o=5,_(function(){return{current:n}},[])}function s(n,t,u){o=6,d(function(){return"function"==typeof n?(n(t()),function(){return n(null)}):n?(n.current=t(),function(){return n.current=null}):void 0},null==u?u:u.concat(n))}function _(n,u){var r=l(t++,7);return k(r.__H,u)&&(r.__=n(),r.__H=u,r.__h=n),r.__}function A(n,t){return o=8,_(function(){return n},t)}function F(n){var r=u.context[n.__c],o=l(t++,9);return o.c=n,r?(null==o.__&&(o.__=!0,r.sub(u)),r.props.value):n.__}function T(t,u){n.useDebugValue&&n.useDebugValue(u?u(t):t)}function q(n){var r=l(t++,10),o=m();return r.__=n,u.componentDidCatch||(u.componentDidCatch=function(n){r.__&&r.__(n),o[1](n)}),[o[0],function(){o[1](void 0)}]}function x(){for(var t;t=i.shift();)if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j),t.__H.__h=[]}catch(u){t.__H.__h=[],n.__e(u,t.__v)}}n.__b=function(n){u=null,c&&c(n)},n.__r=function(n){f&&f(n),t=0;var r=(u=n.__c).__H;r&&(r.__h.forEach(g),r.__h.forEach(j),r.__h=[])},n.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===n.requestAnimationFrame||((r=n.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b&&cancelAnimationFrame(t),setTimeout(n)},r=setTimeout(u,100);b&&(t=requestAnimationFrame(u))})(x)),u=null},n.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g),t.__h=t.__h.filter(function(n){return!n.__||j(n)})}catch(r){u.some(function(n){n.__h&&(n.__h=[])}),u=[],n.__e(r,t.__v)}}),a&&a(t,u)},n.unmount=function(t){v&&v(t);var u,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{g(n)}catch(n){u=n}}),u&&n.__e(u,r.__v))};var b="function"==typeof requestAnimationFrame;function g(n){var t=u,r=n.__c;"function"==typeof r&&(n.__c=void 0,r()),u=t}function j(n){var t=u;n.__c=n.__(),u=t}function k(n,t){return!n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function w(n,t){return"function"==typeof t?t(n):t}export{m as useState,p as useReducer,y as useEffect,d as useLayoutEffect,h as useRef,s as useImperativeHandle,_ as useMemo,A as useCallback,F as useContext,T as useDebugValue,q as useErrorBoundary};
|
||||
//# sourceMappingURL=hooks.module.js.map
|
||||
1
node_modules/preact/hooks/dist/hooks.module.js.map
generated
vendored
Normal file
1
node_modules/preact/hooks/dist/hooks.module.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/preact/hooks/dist/hooks.umd.js
generated
vendored
Normal file
2
node_modules/preact/hooks/dist/hooks.umd.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],t):t(n.preactHooks={},n.preact)}(this,function(n,t){var u,r,o,i=0,c=[],f=t.options.__b,e=t.options.__r,a=t.options.diffed,v=t.options.__c,l=t.options.unmount;function p(n,u){t.options.__h&&t.options.__h(r,n,i||u),i=0;var o=r.__H||(r.__H={__:[],__h:[]});return n>=o.__.length&&o.__.push({}),o.__[n]}function d(n){return i=1,m(F,n)}function m(n,t,o){var i=p(u++,2);return i.t=n,i.__c||(i.__=[o?o(t):F(void 0,t),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}))}],i.__c=r),i.__}function y(n,o){var i=p(u++,4);!t.options.__s&&A(i.__H,o)&&(i.__=n,i.__H=o,r.__h.push(i))}function s(n,t){var r=p(u++,7);return A(r.__H,t)&&(r.__=n(),r.__H=t,r.__h=n),r.__}function h(){for(var n;n=c.shift();)if(n.__P)try{n.__H.__h.forEach(q),n.__H.__h.forEach(x),n.__H.__h=[]}catch(u){n.__H.__h=[],t.options.__e(u,n.__v)}}t.options.__b=function(n){r=null,f&&f(n)},t.options.__r=function(n){e&&e(n),u=0;var t=(r=n.__c).__H;t&&(t.__h.forEach(q),t.__h.forEach(x),t.__h=[])},t.options.diffed=function(n){a&&a(n);var u=n.__c;u&&u.__H&&u.__H.__h.length&&(1!==c.push(u)&&o===t.options.requestAnimationFrame||((o=t.options.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),_&&cancelAnimationFrame(t),setTimeout(n)},r=setTimeout(u,100);_&&(t=requestAnimationFrame(u))})(h)),r=null},t.options.__c=function(n,u){u.some(function(n){try{n.__h.forEach(q),n.__h=n.__h.filter(function(n){return!n.__||x(n)})}catch(r){u.some(function(n){n.__h&&(n.__h=[])}),u=[],t.options.__e(r,n.__v)}}),v&&v(n,u)},t.options.unmount=function(n){l&&l(n);var u,r=n.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{q(n)}catch(n){u=n}}),u&&t.options.__e(u,r.__v))};var _="function"==typeof requestAnimationFrame;function q(n){var t=r,u=n.__c;"function"==typeof u&&(n.__c=void 0,u()),r=t}function x(n){var t=r;n.__c=n.__(),r=t}function A(n,t){return!n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function F(n,t){return"function"==typeof t?t(n):t}n.useState=d,n.useReducer=m,n.useEffect=function(n,o){var i=p(u++,3);!t.options.__s&&A(i.__H,o)&&(i.__=n,i.__H=o,r.__H.__h.push(i))},n.useLayoutEffect=y,n.useRef=function(n){return i=5,s(function(){return{current:n}},[])},n.useImperativeHandle=function(n,t,u){i=6,y(function(){return"function"==typeof n?(n(t()),function(){return n(null)}):n?(n.current=t(),function(){return n.current=null}):void 0},null==u?u:u.concat(n))},n.useMemo=s,n.useCallback=function(n,t){return i=8,s(function(){return n},t)},n.useContext=function(n){var t=r.context[n.__c],o=p(u++,9);return o.c=n,t?(null==o.__&&(o.__=!0,t.sub(r)),t.props.value):n.__},n.useDebugValue=function(n,u){t.options.useDebugValue&&t.options.useDebugValue(u?u(n):n)},n.useErrorBoundary=function(n){var t=p(u++,10),o=d();return t.__=n,r.componentDidCatch||(r.componentDidCatch=function(n){t.__&&t.__(n),o[1](n)}),[o[0],function(){o[1](void 0)}]}});
|
||||
//# sourceMappingURL=hooks.umd.js.map
|
||||
1
node_modules/preact/hooks/dist/hooks.umd.js.map
generated
vendored
Normal file
1
node_modules/preact/hooks/dist/hooks.umd.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
26
node_modules/preact/hooks/package.json
generated
vendored
Normal file
26
node_modules/preact/hooks/package.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "preact-hooks",
|
||||
"amdName": "preactHooks",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Hook addon for Preact",
|
||||
"main": "dist/hooks.js",
|
||||
"module": "dist/hooks.module.js",
|
||||
"umd:main": "dist/hooks.umd.js",
|
||||
"source": "src/index.js",
|
||||
"license": "MIT",
|
||||
"types": "src/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "microbundle build --raw",
|
||||
"dev": "microbundle watch --raw --format cjs",
|
||||
"test": "npm-run-all build --parallel test:karma",
|
||||
"test:karma": "karma start test/karma.conf.js --single-run",
|
||||
"test:karma:watch": "karma start test/karma.conf.js --no-single-run"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"preact": "^10.0.0"
|
||||
},
|
||||
"mangle": {
|
||||
"regex": "^_"
|
||||
}
|
||||
}
|
||||
139
node_modules/preact/hooks/src/index.d.ts
generated
vendored
Normal file
139
node_modules/preact/hooks/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
import { PreactContext, Ref as PreactRef } from '../..';
|
||||
|
||||
type Inputs = ReadonlyArray<unknown>;
|
||||
|
||||
export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
|
||||
/**
|
||||
* Returns a stateful value, and a function to update it.
|
||||
* @param initialState The initial value (or a function that returns the initial value)
|
||||
*/
|
||||
export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
|
||||
|
||||
export function useState<S = undefined>(): [
|
||||
S | undefined,
|
||||
StateUpdater<S | undefined>
|
||||
];
|
||||
|
||||
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
||||
/**
|
||||
* An alternative to `useState`.
|
||||
*
|
||||
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
||||
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
||||
* updates because you can pass `dispatch` down instead of callbacks.
|
||||
* @param reducer Given the current state and an action, returns the new state
|
||||
* @param initialState The initial value to store as state
|
||||
*/
|
||||
export function useReducer<S, A>(
|
||||
reducer: Reducer<S, A>,
|
||||
initialState: S
|
||||
): [S, (action: A) => void];
|
||||
|
||||
/**
|
||||
* An alternative to `useState`.
|
||||
*
|
||||
* `useReducer` is usually preferable to `useState` when you have complex state logic that involves
|
||||
* multiple sub-values. It also lets you optimize performance for components that trigger deep
|
||||
* updates because you can pass `dispatch` down instead of callbacks.
|
||||
* @param reducer Given the current state and an action, returns the new state
|
||||
* @param initialArg The initial argument to pass to the `init` function
|
||||
* @param init A function that, given the `initialArg`, returns the initial value to store as state
|
||||
*/
|
||||
export function useReducer<S, A, I>(
|
||||
reducer: Reducer<S, A>,
|
||||
initialArg: I,
|
||||
init: (arg: I) => S
|
||||
): [S, (action: A) => void];
|
||||
|
||||
/** @deprecated Use the `Ref` type instead. */
|
||||
type PropRef<T> = MutableRef<T>;
|
||||
interface Ref<T> {
|
||||
readonly current: T | null;
|
||||
}
|
||||
|
||||
interface MutableRef<T> {
|
||||
current: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
|
||||
* (`initialValue`). The returned object will persist for the full lifetime of the component.
|
||||
*
|
||||
* Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
|
||||
* value around similar to how you’d use instance fields in classes.
|
||||
*
|
||||
* @param initialValue the initial value to store in the ref object
|
||||
*/
|
||||
export function useRef<T>(initialValue: T): MutableRef<T>;
|
||||
export function useRef<T>(initialValue: T | null): Ref<T>;
|
||||
export function useRef<T = undefined>(): MutableRef<T | undefined>;
|
||||
|
||||
type EffectCallback = () => void | (() => void);
|
||||
/**
|
||||
* Accepts a function that contains imperative, possibly effectful code.
|
||||
* The effects run after browser paint, without blocking it.
|
||||
*
|
||||
* @param effect Imperative function that can return a cleanup function
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
|
||||
|
||||
type CreateHandle = () => object;
|
||||
|
||||
/**
|
||||
* @param ref The ref that will be mutated
|
||||
* @param create The function that will be executed to get the value that will be attached to
|
||||
* ref.current
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useImperativeHandle<T, R extends T>(
|
||||
ref: PreactRef<T>,
|
||||
create: () => R,
|
||||
inputs?: Inputs
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Accepts a function that contains imperative, possibly effectful code.
|
||||
* Use this to read layout from the DOM and synchronously re-render.
|
||||
* Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
|
||||
* Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
|
||||
*
|
||||
* @param effect Imperative function that can return a cleanup function
|
||||
* @param inputs If present, effect will only activate if the values in the list change (using ===).
|
||||
*/
|
||||
export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
|
||||
|
||||
/**
|
||||
* Returns a memoized version of the callback that only changes if one of the `inputs`
|
||||
* has changed (using ===).
|
||||
*/
|
||||
export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
|
||||
|
||||
/**
|
||||
* Pass a factory function and an array of inputs.
|
||||
* useMemo will only recompute the memoized value when one of the inputs has changed.
|
||||
* This optimization helps to avoid expensive calculations on every render.
|
||||
* If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
|
||||
*/
|
||||
// for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
|
||||
export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
|
||||
|
||||
/**
|
||||
* Returns the current context value, as given by the nearest context provider for the given context.
|
||||
* When the provider updates, this Hook will trigger a rerender with the latest context value.
|
||||
*
|
||||
* @param context The context you want to use
|
||||
*/
|
||||
export function useContext<T>(context: PreactContext<T>): T;
|
||||
|
||||
/**
|
||||
* Customize the displayed value in the devtools panel.
|
||||
*
|
||||
* @param value Custom hook name or object that is passed to formatter
|
||||
* @param formatter Formatter to modify value before sending it to the devtools
|
||||
*/
|
||||
export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
|
||||
|
||||
export function useErrorBoundary(
|
||||
callback?: (error: any) => Promise<void> | void
|
||||
): [any, () => void];
|
||||
391
node_modules/preact/hooks/src/index.js
generated
vendored
Normal file
391
node_modules/preact/hooks/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,391 @@
|
||||
import { options } from 'preact';
|
||||
|
||||
/** @type {number} */
|
||||
let currentIndex;
|
||||
|
||||
/** @type {import('./internal').Component} */
|
||||
let currentComponent;
|
||||
|
||||
/** @type {number} */
|
||||
let currentHook = 0;
|
||||
|
||||
/** @type {Array<import('./internal').Component>} */
|
||||
let afterPaintEffects = [];
|
||||
|
||||
let oldBeforeDiff = options._diff;
|
||||
let oldBeforeRender = options._render;
|
||||
let oldAfterDiff = options.diffed;
|
||||
let oldCommit = options._commit;
|
||||
let oldBeforeUnmount = options.unmount;
|
||||
|
||||
const RAF_TIMEOUT = 100;
|
||||
let prevRaf;
|
||||
|
||||
options._diff = vnode => {
|
||||
currentComponent = null;
|
||||
if (oldBeforeDiff) oldBeforeDiff(vnode);
|
||||
};
|
||||
|
||||
options._render = vnode => {
|
||||
if (oldBeforeRender) oldBeforeRender(vnode);
|
||||
|
||||
currentComponent = vnode._component;
|
||||
currentIndex = 0;
|
||||
|
||||
const hooks = currentComponent.__hooks;
|
||||
if (hooks) {
|
||||
hooks._pendingEffects.forEach(invokeCleanup);
|
||||
hooks._pendingEffects.forEach(invokeEffect);
|
||||
hooks._pendingEffects = [];
|
||||
}
|
||||
};
|
||||
|
||||
options.diffed = vnode => {
|
||||
if (oldAfterDiff) oldAfterDiff(vnode);
|
||||
|
||||
const c = vnode._component;
|
||||
if (c && c.__hooks && c.__hooks._pendingEffects.length) {
|
||||
afterPaint(afterPaintEffects.push(c));
|
||||
}
|
||||
currentComponent = null;
|
||||
};
|
||||
|
||||
options._commit = (vnode, commitQueue) => {
|
||||
commitQueue.some(component => {
|
||||
try {
|
||||
component._renderCallbacks.forEach(invokeCleanup);
|
||||
component._renderCallbacks = component._renderCallbacks.filter(cb =>
|
||||
cb._value ? invokeEffect(cb) : true
|
||||
);
|
||||
} catch (e) {
|
||||
commitQueue.some(c => {
|
||||
if (c._renderCallbacks) c._renderCallbacks = [];
|
||||
});
|
||||
commitQueue = [];
|
||||
options._catchError(e, component._vnode);
|
||||
}
|
||||
});
|
||||
|
||||
if (oldCommit) oldCommit(vnode, commitQueue);
|
||||
};
|
||||
|
||||
options.unmount = vnode => {
|
||||
if (oldBeforeUnmount) oldBeforeUnmount(vnode);
|
||||
|
||||
const c = vnode._component;
|
||||
if (c && c.__hooks) {
|
||||
let hasErrored;
|
||||
c.__hooks._list.forEach(s => {
|
||||
try {
|
||||
invokeCleanup(s);
|
||||
} catch (e) {
|
||||
hasErrored = e;
|
||||
}
|
||||
});
|
||||
if (hasErrored) options._catchError(hasErrored, c._vnode);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a hook's state from the currentComponent
|
||||
* @param {number} index The index of the hook to get
|
||||
* @param {number} type The index of the hook to get
|
||||
* @returns {any}
|
||||
*/
|
||||
function getHookState(index, type) {
|
||||
if (options._hook) {
|
||||
options._hook(currentComponent, index, currentHook || type);
|
||||
}
|
||||
currentHook = 0;
|
||||
|
||||
// Largely inspired by:
|
||||
// * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs
|
||||
// * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs
|
||||
// Other implementations to look at:
|
||||
// * https://codesandbox.io/s/mnox05qp8
|
||||
const hooks =
|
||||
currentComponent.__hooks ||
|
||||
(currentComponent.__hooks = {
|
||||
_list: [],
|
||||
_pendingEffects: []
|
||||
});
|
||||
|
||||
if (index >= hooks._list.length) {
|
||||
hooks._list.push({});
|
||||
}
|
||||
return hooks._list[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./index').StateUpdater<any>} [initialState]
|
||||
*/
|
||||
export function useState(initialState) {
|
||||
currentHook = 1;
|
||||
return useReducer(invokeOrReturn, initialState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./index').Reducer<any, any>} reducer
|
||||
* @param {import('./index').StateUpdater<any>} initialState
|
||||
* @param {(initialState: any) => void} [init]
|
||||
* @returns {[ any, (state: any) => void ]}
|
||||
*/
|
||||
export function useReducer(reducer, initialState, init) {
|
||||
/** @type {import('./internal').ReducerHookState} */
|
||||
const hookState = getHookState(currentIndex++, 2);
|
||||
hookState._reducer = reducer;
|
||||
if (!hookState._component) {
|
||||
hookState._value = [
|
||||
!init ? invokeOrReturn(undefined, initialState) : init(initialState),
|
||||
|
||||
action => {
|
||||
const nextValue = hookState._reducer(hookState._value[0], action);
|
||||
if (hookState._value[0] !== nextValue) {
|
||||
hookState._value = [nextValue, hookState._value[1]];
|
||||
hookState._component.setState({});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
hookState._component = currentComponent;
|
||||
}
|
||||
|
||||
return hookState._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./internal').Effect} callback
|
||||
* @param {any[]} args
|
||||
*/
|
||||
export function useEffect(callback, args) {
|
||||
/** @type {import('./internal').EffectHookState} */
|
||||
const state = getHookState(currentIndex++, 3);
|
||||
if (!options._skipEffects && argsChanged(state._args, args)) {
|
||||
state._value = callback;
|
||||
state._args = args;
|
||||
|
||||
currentComponent.__hooks._pendingEffects.push(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./internal').Effect} callback
|
||||
* @param {any[]} args
|
||||
*/
|
||||
export function useLayoutEffect(callback, args) {
|
||||
/** @type {import('./internal').EffectHookState} */
|
||||
const state = getHookState(currentIndex++, 4);
|
||||
if (!options._skipEffects && argsChanged(state._args, args)) {
|
||||
state._value = callback;
|
||||
state._args = args;
|
||||
|
||||
currentComponent._renderCallbacks.push(state);
|
||||
}
|
||||
}
|
||||
|
||||
export function useRef(initialValue) {
|
||||
currentHook = 5;
|
||||
return useMemo(() => ({ current: initialValue }), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} ref
|
||||
* @param {() => object} createHandle
|
||||
* @param {any[]} args
|
||||
*/
|
||||
export function useImperativeHandle(ref, createHandle, args) {
|
||||
currentHook = 6;
|
||||
useLayoutEffect(
|
||||
() => {
|
||||
if (typeof ref == 'function') {
|
||||
ref(createHandle());
|
||||
return () => ref(null);
|
||||
} else if (ref) {
|
||||
ref.current = createHandle();
|
||||
return () => ref.current = null;
|
||||
}
|
||||
},
|
||||
args == null ? args : args.concat(ref)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {() => any} factory
|
||||
* @param {any[]} args
|
||||
*/
|
||||
export function useMemo(factory, args) {
|
||||
/** @type {import('./internal').MemoHookState} */
|
||||
const state = getHookState(currentIndex++, 7);
|
||||
if (argsChanged(state._args, args)) {
|
||||
state._value = factory();
|
||||
state._args = args;
|
||||
state._factory = factory;
|
||||
}
|
||||
|
||||
return state._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {() => void} callback
|
||||
* @param {any[]} args
|
||||
*/
|
||||
export function useCallback(callback, args) {
|
||||
currentHook = 8;
|
||||
return useMemo(() => callback, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./internal').PreactContext} context
|
||||
*/
|
||||
export function useContext(context) {
|
||||
const provider = currentComponent.context[context._id];
|
||||
// We could skip this call here, but than we'd not call
|
||||
// `options._hook`. We need to do that in order to make
|
||||
// the devtools aware of this hook.
|
||||
/** @type {import('./internal').ContextHookState} */
|
||||
const state = getHookState(currentIndex++, 9);
|
||||
// The devtools needs access to the context object to
|
||||
// be able to pull of the default value when no provider
|
||||
// is present in the tree.
|
||||
state._context = context;
|
||||
if (!provider) return context._defaultValue;
|
||||
// This is probably not safe to convert to "!"
|
||||
if (state._value == null) {
|
||||
state._value = true;
|
||||
provider.sub(currentComponent);
|
||||
}
|
||||
return provider.props.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a custom label for a custom hook for the devtools panel
|
||||
* @type {<T>(value: T, cb?: (value: T) => string | number) => void}
|
||||
*/
|
||||
export function useDebugValue(value, formatter) {
|
||||
if (options.useDebugValue) {
|
||||
options.useDebugValue(formatter ? formatter(value) : value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(error: any) => void} cb
|
||||
*/
|
||||
export function useErrorBoundary(cb) {
|
||||
/** @type {import('./internal').ErrorBoundaryHookState} */
|
||||
const state = getHookState(currentIndex++, 10);
|
||||
const errState = useState();
|
||||
state._value = cb;
|
||||
if (!currentComponent.componentDidCatch) {
|
||||
currentComponent.componentDidCatch = err => {
|
||||
if (state._value) state._value(err);
|
||||
errState[1](err);
|
||||
};
|
||||
}
|
||||
return [
|
||||
errState[0],
|
||||
() => {
|
||||
errState[1](undefined);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* After paint effects consumer.
|
||||
*/
|
||||
function flushAfterPaintEffects() {
|
||||
let component;
|
||||
while ((component = afterPaintEffects.shift())) {
|
||||
if (!component._parentDom) continue;
|
||||
try {
|
||||
component.__hooks._pendingEffects.forEach(invokeCleanup);
|
||||
component.__hooks._pendingEffects.forEach(invokeEffect);
|
||||
component.__hooks._pendingEffects = [];
|
||||
} catch (e) {
|
||||
component.__hooks._pendingEffects = [];
|
||||
options._catchError(e, component._vnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let HAS_RAF = typeof requestAnimationFrame == 'function';
|
||||
|
||||
/**
|
||||
* Schedule a callback to be invoked after the browser has a chance to paint a new frame.
|
||||
* Do this by combining requestAnimationFrame (rAF) + setTimeout to invoke a callback after
|
||||
* the next browser frame.
|
||||
*
|
||||
* Also, schedule a timeout in parallel to the the rAF to ensure the callback is invoked
|
||||
* even if RAF doesn't fire (for example if the browser tab is not visible)
|
||||
*
|
||||
* @param {() => void} callback
|
||||
*/
|
||||
function afterNextFrame(callback) {
|
||||
const done = () => {
|
||||
clearTimeout(timeout);
|
||||
if (HAS_RAF) cancelAnimationFrame(raf);
|
||||
setTimeout(callback);
|
||||
};
|
||||
const timeout = setTimeout(done, RAF_TIMEOUT);
|
||||
|
||||
let raf;
|
||||
if (HAS_RAF) {
|
||||
raf = requestAnimationFrame(done);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: if someone used options.debounceRendering = requestAnimationFrame,
|
||||
// then effects will ALWAYS run on the NEXT frame instead of the current one, incurring a ~16ms delay.
|
||||
// Perhaps this is not such a big deal.
|
||||
/**
|
||||
* Schedule afterPaintEffects flush after the browser paints
|
||||
* @param {number} newQueueLength
|
||||
*/
|
||||
function afterPaint(newQueueLength) {
|
||||
if (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {
|
||||
prevRaf = options.requestAnimationFrame;
|
||||
(prevRaf || afterNextFrame)(flushAfterPaintEffects);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('./internal').EffectHookState} hook
|
||||
*/
|
||||
function invokeCleanup(hook) {
|
||||
// A hook cleanup can introduce a call to render which creates a new root, this will call options.vnode
|
||||
// and move the currentComponent away.
|
||||
const comp = currentComponent;
|
||||
let cleanup = hook._cleanup;
|
||||
if (typeof cleanup == 'function') {
|
||||
hook._cleanup = undefined;
|
||||
cleanup();
|
||||
}
|
||||
currentComponent = comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a Hook's effect
|
||||
* @param {import('./internal').EffectHookState} hook
|
||||
*/
|
||||
function invokeEffect(hook) {
|
||||
// A hook call can introduce a call to render which creates a new root, this will call options.vnode
|
||||
// and move the currentComponent away.
|
||||
const comp = currentComponent;
|
||||
hook._cleanup = hook._value();
|
||||
currentComponent = comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any[]} oldArgs
|
||||
* @param {any[]} newArgs
|
||||
*/
|
||||
function argsChanged(oldArgs, newArgs) {
|
||||
return (
|
||||
!oldArgs ||
|
||||
oldArgs.length !== newArgs.length ||
|
||||
newArgs.some((arg, index) => arg !== oldArgs[index])
|
||||
);
|
||||
}
|
||||
|
||||
function invokeOrReturn(arg, f) {
|
||||
return typeof f == 'function' ? f(arg) : f;
|
||||
}
|
||||
75
node_modules/preact/hooks/src/internal.d.ts
generated
vendored
Normal file
75
node_modules/preact/hooks/src/internal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
Component as PreactComponent,
|
||||
PreactContext
|
||||
} from '../../src/internal';
|
||||
import { Reducer } from '.';
|
||||
|
||||
export { PreactContext };
|
||||
|
||||
/**
|
||||
* The type of arguments passed to a Hook function. While this type is not
|
||||
* strictly necessary, they are given a type name to make it easier to read
|
||||
* the following types and trace the flow of data.
|
||||
*/
|
||||
export type HookArgs = any;
|
||||
|
||||
/**
|
||||
* The return type of a Hook function. While this type is not
|
||||
* strictly necessary, they are given a type name to make it easier to read
|
||||
* the following types and trace the flow of data.
|
||||
*/
|
||||
export type HookReturnValue = any;
|
||||
|
||||
/** The public function a user invokes to use a Hook */
|
||||
export type Hook = (...args: HookArgs[]) => HookReturnValue;
|
||||
|
||||
// Hook tracking
|
||||
|
||||
export interface ComponentHooks {
|
||||
/** The list of hooks a component uses */
|
||||
_list: HookState[];
|
||||
/** List of Effects to be invoked after the next frame is rendered */
|
||||
_pendingEffects: EffectHookState[];
|
||||
}
|
||||
|
||||
export interface Component extends PreactComponent<any, any> {
|
||||
__hooks?: ComponentHooks;
|
||||
}
|
||||
|
||||
export type HookState =
|
||||
| EffectHookState
|
||||
| MemoHookState
|
||||
| ReducerHookState
|
||||
| ContextHookState
|
||||
| ErrorBoundaryHookState;
|
||||
|
||||
export type Effect = () => void | Cleanup;
|
||||
export type Cleanup = () => void;
|
||||
|
||||
export interface EffectHookState {
|
||||
_value?: Effect;
|
||||
_args?: any[];
|
||||
_cleanup?: Cleanup | void;
|
||||
}
|
||||
|
||||
export interface MemoHookState {
|
||||
_value?: any;
|
||||
_args?: any[];
|
||||
_factory?: () => any;
|
||||
}
|
||||
|
||||
export interface ReducerHookState {
|
||||
_value?: any;
|
||||
_component?: Component;
|
||||
_reducer?: Reducer<any, any>;
|
||||
}
|
||||
|
||||
export interface ContextHookState {
|
||||
/** Whether this hooks as subscribed to updates yet */
|
||||
_value?: boolean;
|
||||
_context?: PreactContext;
|
||||
}
|
||||
|
||||
export interface ErrorBoundaryHookState {
|
||||
_value?: (error: any) => void;
|
||||
}
|
||||
Reference in New Issue
Block a user