isomorfeus-preact 10.6.1 → 10.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/lib/preact/version.rb +1 -1
  3. data/node_modules/.package-lock.json +3 -3
  4. data/node_modules/preact/LICENSE +21 -21
  5. data/node_modules/preact/README.md +187 -187
  6. data/node_modules/preact/compat/dist/compat.js +1 -1
  7. data/node_modules/preact/compat/dist/compat.js.map +1 -1
  8. data/node_modules/preact/compat/dist/compat.mjs +1 -1
  9. data/node_modules/preact/compat/dist/compat.module.js +1 -1
  10. data/node_modules/preact/compat/dist/compat.module.js.map +1 -1
  11. data/node_modules/preact/compat/dist/compat.umd.js +1 -1
  12. data/node_modules/preact/compat/dist/compat.umd.js.map +1 -1
  13. data/node_modules/preact/compat/jsx-dev-runtime.js +1 -1
  14. data/node_modules/preact/compat/jsx-dev-runtime.mjs +1 -1
  15. data/node_modules/preact/compat/jsx-runtime.js +1 -1
  16. data/node_modules/preact/compat/jsx-runtime.mjs +1 -1
  17. data/node_modules/preact/compat/package.json +19 -19
  18. data/node_modules/preact/compat/scheduler.js +15 -15
  19. data/node_modules/preact/compat/scheduler.mjs +23 -23
  20. data/node_modules/preact/compat/server.js +15 -15
  21. data/node_modules/preact/compat/server.mjs +4 -4
  22. data/node_modules/preact/compat/src/Children.js +21 -21
  23. data/node_modules/preact/compat/src/PureComponent.js +15 -15
  24. data/node_modules/preact/compat/src/forwardRef.js +51 -51
  25. data/node_modules/preact/compat/src/index.d.ts +141 -141
  26. data/node_modules/preact/compat/src/index.js +187 -187
  27. data/node_modules/preact/compat/src/internal.d.ts +47 -47
  28. data/node_modules/preact/compat/src/memo.js +34 -34
  29. data/node_modules/preact/compat/src/portals.js +80 -80
  30. data/node_modules/preact/compat/src/render.js +230 -226
  31. data/node_modules/preact/compat/src/suspense-list.d.ts +14 -14
  32. data/node_modules/preact/compat/src/suspense-list.js +126 -126
  33. data/node_modules/preact/compat/src/suspense.d.ts +15 -15
  34. data/node_modules/preact/compat/src/suspense.js +270 -270
  35. data/node_modules/preact/compat/src/util.js +28 -28
  36. data/node_modules/preact/compat/test-utils.js +1 -1
  37. data/node_modules/preact/debug/dist/debug.js.map +1 -1
  38. data/node_modules/preact/debug/dist/debug.module.js.map +1 -1
  39. data/node_modules/preact/debug/dist/debug.umd.js.map +1 -1
  40. data/node_modules/preact/debug/package.json +18 -18
  41. data/node_modules/preact/debug/src/check-props.js +54 -54
  42. data/node_modules/preact/debug/src/component-stack.js +146 -146
  43. data/node_modules/preact/debug/src/constants.js +3 -3
  44. data/node_modules/preact/debug/src/debug.js +442 -442
  45. data/node_modules/preact/debug/src/index.js +6 -6
  46. data/node_modules/preact/debug/src/internal.d.ts +82 -82
  47. data/node_modules/preact/debug/src/util.js +11 -11
  48. data/node_modules/preact/devtools/dist/devtools.js +1 -1
  49. data/node_modules/preact/devtools/dist/devtools.js.map +1 -1
  50. data/node_modules/preact/devtools/dist/devtools.mjs +1 -1
  51. data/node_modules/preact/devtools/dist/devtools.module.js +1 -1
  52. data/node_modules/preact/devtools/dist/devtools.module.js.map +1 -1
  53. data/node_modules/preact/devtools/dist/devtools.umd.js +1 -1
  54. data/node_modules/preact/devtools/dist/devtools.umd.js.map +1 -1
  55. data/node_modules/preact/devtools/package.json +16 -16
  56. data/node_modules/preact/devtools/src/devtools.js +10 -10
  57. data/node_modules/preact/devtools/src/index.d.ts +8 -8
  58. data/node_modules/preact/devtools/src/index.js +15 -15
  59. data/node_modules/preact/dist/preact.js +1 -1
  60. data/node_modules/preact/dist/preact.js.map +1 -1
  61. data/node_modules/preact/dist/preact.min.js +1 -1
  62. data/node_modules/preact/dist/preact.min.js.map +1 -1
  63. data/node_modules/preact/dist/preact.mjs +1 -1
  64. data/node_modules/preact/dist/preact.module.js +1 -1
  65. data/node_modules/preact/dist/preact.module.js.map +1 -1
  66. data/node_modules/preact/dist/preact.umd.js +1 -1
  67. data/node_modules/preact/dist/preact.umd.js.map +1 -1
  68. data/node_modules/preact/hooks/dist/hooks.js +1 -1
  69. data/node_modules/preact/hooks/dist/hooks.js.map +1 -1
  70. data/node_modules/preact/hooks/dist/hooks.mjs +1 -1
  71. data/node_modules/preact/hooks/dist/hooks.module.js +1 -1
  72. data/node_modules/preact/hooks/dist/hooks.module.js.map +1 -1
  73. data/node_modules/preact/hooks/dist/hooks.umd.js +1 -1
  74. data/node_modules/preact/hooks/dist/hooks.umd.js.map +1 -1
  75. data/node_modules/preact/hooks/package.json +26 -26
  76. data/node_modules/preact/hooks/src/index.d.ts +139 -139
  77. data/node_modules/preact/hooks/src/index.js +388 -379
  78. data/node_modules/preact/hooks/src/internal.d.ts +75 -75
  79. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +1 -1
  80. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +1 -1
  81. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +1 -1
  82. data/node_modules/preact/jsx-runtime/package.json +19 -19
  83. data/node_modules/preact/jsx-runtime/src/index.d.ts +50 -50
  84. data/node_modules/preact/jsx-runtime/src/index.js +77 -77
  85. data/node_modules/preact/package.json +287 -281
  86. data/node_modules/preact/src/cjs.js +3 -3
  87. data/node_modules/preact/src/clone-element.js +34 -34
  88. data/node_modules/preact/src/component.js +225 -225
  89. data/node_modules/preact/src/constants.js +3 -3
  90. data/node_modules/preact/src/create-context.js +68 -68
  91. data/node_modules/preact/src/create-element.js +98 -98
  92. data/node_modules/preact/src/diff/catch-error.js +38 -38
  93. data/node_modules/preact/src/diff/children.js +335 -335
  94. data/node_modules/preact/src/diff/index.js +516 -516
  95. data/node_modules/preact/src/diff/props.js +158 -158
  96. data/node_modules/preact/src/index.d.ts +310 -310
  97. data/node_modules/preact/src/index.js +13 -13
  98. data/node_modules/preact/src/internal.d.ts +146 -146
  99. data/node_modules/preact/src/jsx.d.ts +1005 -1005
  100. data/node_modules/preact/src/options.js +16 -16
  101. data/node_modules/preact/src/render.js +75 -75
  102. data/node_modules/preact/src/util.js +27 -27
  103. data/node_modules/preact/test-utils/dist/testUtils.js.map +1 -1
  104. data/node_modules/preact/test-utils/dist/testUtils.module.js.map +1 -1
  105. data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +1 -1
  106. data/node_modules/preact/test-utils/package.json +19 -19
  107. data/node_modules/preact/test-utils/src/index.d.ts +3 -3
  108. data/node_modules/preact/test-utils/src/index.js +117 -117
  109. data/package.json +1 -1
  110. metadata +17 -37
  111. data/node_modules/preact/compat/dist/compat.mjs.map +0 -1
  112. data/node_modules/preact/compat/dist/compat.modern.js +0 -2
  113. data/node_modules/preact/compat/dist/compat.modern.js.map +0 -1
  114. data/node_modules/preact/debug/dist/debug.mjs.map +0 -1
  115. data/node_modules/preact/debug/dist/debug.modern.js +0 -2
  116. data/node_modules/preact/debug/dist/debug.modern.js.map +0 -1
  117. data/node_modules/preact/devtools/dist/devtools.mjs.map +0 -1
  118. data/node_modules/preact/devtools/dist/devtools.modern.js +0 -2
  119. data/node_modules/preact/devtools/dist/devtools.modern.js.map +0 -1
  120. data/node_modules/preact/dist/index.d.ts +0 -1295
  121. data/node_modules/preact/dist/preact.mjs.map +0 -1
  122. data/node_modules/preact/hooks/dist/hooks.mjs.map +0 -1
  123. data/node_modules/preact/hooks/dist/hooks.modern.js +0 -2
  124. data/node_modules/preact/hooks/dist/hooks.modern.js.map +0 -1
  125. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs.map +0 -1
  126. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.modern.js +0 -2
  127. data/node_modules/preact/jsx-runtime/dist/jsxRuntime.modern.js.map +0 -1
  128. data/node_modules/preact/test-utils/dist/testUtils.mjs.map +0 -1
  129. data/node_modules/preact/test-utils/dist/testUtils.modern.js +0 -2
  130. data/node_modules/preact/test-utils/dist/testUtils.modern.js.map +0 -1
@@ -1,2 +1,2 @@
1
- !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,o,r,i=0,c=[],f=t.options.__b,e=t.options.__r,a=t.options.diffed,v=t.options.__c,p=t.options.unmount;function l(n,u){t.options.__h&&t.options.__h(o,n,i||u),i=0;var r=o.__H||(o.__H={__:[],__h:[]});return n>=r.__.length&&r.__.push({}),r.__[n]}function m(n){return i=1,y(F,n)}function y(n,t,r){var i=l(u++,2);return i.t=n,i.__c||(i.__=[r?r(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=o),i.__}function d(n,r){var i=l(u++,4);!t.options.__s&&A(i.__H,r)&&(i.__=n,i.__H=r,o.__h.push(i))}function s(n,t){var o=l(u++,7);return A(o.__H,t)&&(o.__=n(),o.__H=t,o.__h=n),o.__}function h(){c.forEach(function(n){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)}}),c=[]}t.options.__b=function(n){o=null,f&&f(n)},t.options.__r=function(n){e&&e(n),u=0;var t=(o=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)&&r===t.options.requestAnimationFrame||((r=t.options.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(o),_&&cancelAnimationFrame(t),setTimeout(n)},o=setTimeout(u,100);_&&(t=requestAnimationFrame(u))})(h)),o=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(o){u.some(function(n){n.__h&&(n.__h=[])}),u=[],t.options.__e(o,n.__v)}}),v&&v(n,u)},t.options.unmount=function(n){p&&p(n);var u=n.__c;if(u&&u.__H)try{u.__H.__.forEach(q)}catch(n){t.options.__e(n,u.__v)}};var _="function"==typeof requestAnimationFrame;function q(n){var t=o;"function"==typeof n.__c&&n.__c(),o=t}function x(n){var t=o;n.__c=n.__(),o=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=m,n.useReducer=y,n.useEffect=function(n,r){var i=l(u++,3);!t.options.__s&&A(i.__H,r)&&(i.__=n,i.__H=r,o.__H.__h.push(i))},n.useLayoutEffect=d,n.useRef=function(n){return i=5,s(function(){return{current:n}},[])},n.useImperativeHandle=function(n,t,u){i=6,d(function(){"function"==typeof n?n(t()):n&&(n.current=t())},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=o.context[n.__c],r=l(u++,9);return r.c=n,t?(null==r.__&&(r.__=!0,t.sub(o)),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=l(u++,10),r=m();return t.__=n,o.componentDidCatch||(o.componentDidCatch=function(n){t.__&&t.__(n),r[1](n)}),[r[0],function(){r[1](void 0)}]}});
1
+ !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,p=t.options.unmount;function l(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 m(n){return i=1,y(F,n)}function y(n,t,o){var i=l(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 d(n,o){var i=l(u++,4);!t.options.__s&&A(i.__H,o)&&(i.__=n,i.__H=o,r.__h.push(i))}function s(n,t){var r=l(u++,7);return A(r.__H,t)&&(r.__=n(),r.__H=t,r.__h=n),r.__}function h(){var n;for(c.sort(function(n,t){return n.__v.__b-t.__v.__b});n=c.pop();)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){p&&p(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=m,n.useReducer=y,n.useEffect=function(n,o){var i=l(u++,3);!t.options.__s&&A(i.__H,o)&&(i.__=n,i.__H=o,r.__H.__h.push(i))},n.useLayoutEffect=d,n.useRef=function(n){return i=5,s(function(){return{current:n}},[])},n.useImperativeHandle=function(n,t,u){i=6,d(function(){"function"==typeof n?n(t()):n&&(n.current=t())},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=l(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=l(u++,10),o=m();return t.__=n,r.componentDidCatch||(r.componentDidCatch=function(n){t.__&&t.__(n),o[1](n)}),[o[0],function(){o[1](void 0)}]}});
2
2
  //# sourceMappingURL=hooks.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.umd.js","sources":["../src/index.js"],"sourcesContent":["import { options } from 'preact';\n\n/** @type {number} */\nlet currentIndex;\n\n/** @type {import('./internal').Component} */\nlet currentComponent;\n\n/** @type {number} */\nlet currentHook = 0;\n\n/** @type {Array<import('./internal').Component>} */\nlet afterPaintEffects = [];\n\nlet oldBeforeDiff = options._diff;\nlet oldBeforeRender = options._render;\nlet oldAfterDiff = options.diffed;\nlet oldCommit = options._commit;\nlet oldBeforeUnmount = options.unmount;\n\nconst RAF_TIMEOUT = 100;\nlet prevRaf;\n\noptions._diff = vnode => {\n\tcurrentComponent = null;\n\tif (oldBeforeDiff) oldBeforeDiff(vnode);\n};\n\noptions._render = vnode => {\n\tif (oldBeforeRender) oldBeforeRender(vnode);\n\n\tcurrentComponent = vnode._component;\n\tcurrentIndex = 0;\n\n\tconst hooks = currentComponent.__hooks;\n\tif (hooks) {\n\t\thooks._pendingEffects.forEach(invokeCleanup);\n\t\thooks._pendingEffects.forEach(invokeEffect);\n\t\thooks._pendingEffects = [];\n\t}\n};\n\noptions.diffed = vnode => {\n\tif (oldAfterDiff) oldAfterDiff(vnode);\n\n\tconst c = vnode._component;\n\tif (c && c.__hooks && c.__hooks._pendingEffects.length) {\n\t\tafterPaint(afterPaintEffects.push(c));\n\t}\n\tcurrentComponent = null;\n};\n\noptions._commit = (vnode, commitQueue) => {\n\tcommitQueue.some(component => {\n\t\ttry {\n\t\t\tcomponent._renderCallbacks.forEach(invokeCleanup);\n\t\t\tcomponent._renderCallbacks = component._renderCallbacks.filter(cb =>\n\t\t\t\tcb._value ? invokeEffect(cb) : true\n\t\t\t);\n\t\t} catch (e) {\n\t\t\tcommitQueue.some(c => {\n\t\t\t\tif (c._renderCallbacks) c._renderCallbacks = [];\n\t\t\t});\n\t\t\tcommitQueue = [];\n\t\t\toptions._catchError(e, component._vnode);\n\t\t}\n\t});\n\n\tif (oldCommit) oldCommit(vnode, commitQueue);\n};\n\noptions.unmount = vnode => {\n\tif (oldBeforeUnmount) oldBeforeUnmount(vnode);\n\n\tconst c = vnode._component;\n\tif (c && c.__hooks) {\n\t\ttry {\n\t\t\tc.__hooks._list.forEach(invokeCleanup);\n\t\t} catch (e) {\n\t\t\toptions._catchError(e, c._vnode);\n\t\t}\n\t}\n};\n\n/**\n * Get a hook's state from the currentComponent\n * @param {number} index The index of the hook to get\n * @param {number} type The index of the hook to get\n * @returns {any}\n */\nfunction getHookState(index, type) {\n\tif (options._hook) {\n\t\toptions._hook(currentComponent, index, currentHook || type);\n\t}\n\tcurrentHook = 0;\n\n\t// Largely inspired by:\n\t// * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs\n\t// * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs\n\t// Other implementations to look at:\n\t// * https://codesandbox.io/s/mnox05qp8\n\tconst hooks =\n\t\tcurrentComponent.__hooks ||\n\t\t(currentComponent.__hooks = {\n\t\t\t_list: [],\n\t\t\t_pendingEffects: []\n\t\t});\n\n\tif (index >= hooks._list.length) {\n\t\thooks._list.push({});\n\t}\n\treturn hooks._list[index];\n}\n\n/**\n * @param {import('./index').StateUpdater<any>} [initialState]\n */\nexport function useState(initialState) {\n\tcurrentHook = 1;\n\treturn useReducer(invokeOrReturn, initialState);\n}\n\n/**\n * @param {import('./index').Reducer<any, any>} reducer\n * @param {import('./index').StateUpdater<any>} initialState\n * @param {(initialState: any) => void} [init]\n * @returns {[ any, (state: any) => void ]}\n */\nexport function useReducer(reducer, initialState, init) {\n\t/** @type {import('./internal').ReducerHookState} */\n\tconst hookState = getHookState(currentIndex++, 2);\n\thookState._reducer = reducer;\n\tif (!hookState._component) {\n\t\thookState._value = [\n\t\t\t!init ? invokeOrReturn(undefined, initialState) : init(initialState),\n\n\t\t\taction => {\n\t\t\t\tconst nextValue = hookState._reducer(hookState._value[0], action);\n\t\t\t\tif (hookState._value[0] !== nextValue) {\n\t\t\t\t\thookState._value = [nextValue, hookState._value[1]];\n\t\t\t\t\thookState._component.setState({});\n\t\t\t\t}\n\t\t\t}\n\t\t];\n\n\t\thookState._component = currentComponent;\n\t}\n\n\treturn hookState._value;\n}\n\n/**\n * @param {import('./internal').Effect} callback\n * @param {any[]} args\n */\nexport function useEffect(callback, args) {\n\t/** @type {import('./internal').EffectHookState} */\n\tconst state = getHookState(currentIndex++, 3);\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\n\t\tstate._value = callback;\n\t\tstate._args = args;\n\n\t\tcurrentComponent.__hooks._pendingEffects.push(state);\n\t}\n}\n\n/**\n * @param {import('./internal').Effect} callback\n * @param {any[]} args\n */\nexport function useLayoutEffect(callback, args) {\n\t/** @type {import('./internal').EffectHookState} */\n\tconst state = getHookState(currentIndex++, 4);\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\n\t\tstate._value = callback;\n\t\tstate._args = args;\n\n\t\tcurrentComponent._renderCallbacks.push(state);\n\t}\n}\n\nexport function useRef(initialValue) {\n\tcurrentHook = 5;\n\treturn useMemo(() => ({ current: initialValue }), []);\n}\n\n/**\n * @param {object} ref\n * @param {() => object} createHandle\n * @param {any[]} args\n */\nexport function useImperativeHandle(ref, createHandle, args) {\n\tcurrentHook = 6;\n\tuseLayoutEffect(\n\t\t() => {\n\t\t\tif (typeof ref == 'function') ref(createHandle());\n\t\t\telse if (ref) ref.current = createHandle();\n\t\t},\n\t\targs == null ? args : args.concat(ref)\n\t);\n}\n\n/**\n * @param {() => any} factory\n * @param {any[]} args\n */\nexport function useMemo(factory, args) {\n\t/** @type {import('./internal').MemoHookState} */\n\tconst state = getHookState(currentIndex++, 7);\n\tif (argsChanged(state._args, args)) {\n\t\tstate._value = factory();\n\t\tstate._args = args;\n\t\tstate._factory = factory;\n\t}\n\n\treturn state._value;\n}\n\n/**\n * @param {() => void} callback\n * @param {any[]} args\n */\nexport function useCallback(callback, args) {\n\tcurrentHook = 8;\n\treturn useMemo(() => callback, args);\n}\n\n/**\n * @param {import('./internal').PreactContext} context\n */\nexport function useContext(context) {\n\tconst provider = currentComponent.context[context._id];\n\t// We could skip this call here, but than we'd not call\n\t// `options._hook`. We need to do that in order to make\n\t// the devtools aware of this hook.\n\t/** @type {import('./internal').ContextHookState} */\n\tconst state = getHookState(currentIndex++, 9);\n\t// The devtools needs access to the context object to\n\t// be able to pull of the default value when no provider\n\t// is present in the tree.\n\tstate._context = context;\n\tif (!provider) return context._defaultValue;\n\t// This is probably not safe to convert to \"!\"\n\tif (state._value == null) {\n\t\tstate._value = true;\n\t\tprovider.sub(currentComponent);\n\t}\n\treturn provider.props.value;\n}\n\n/**\n * Display a custom label for a custom hook for the devtools panel\n * @type {<T>(value: T, cb?: (value: T) => string | number) => void}\n */\nexport function useDebugValue(value, formatter) {\n\tif (options.useDebugValue) {\n\t\toptions.useDebugValue(formatter ? formatter(value) : value);\n\t}\n}\n\n/**\n * @param {(error: any) => void} cb\n */\nexport function useErrorBoundary(cb) {\n\t/** @type {import('./internal').ErrorBoundaryHookState} */\n\tconst state = getHookState(currentIndex++, 10);\n\tconst errState = useState();\n\tstate._value = cb;\n\tif (!currentComponent.componentDidCatch) {\n\t\tcurrentComponent.componentDidCatch = err => {\n\t\t\tif (state._value) state._value(err);\n\t\t\terrState[1](err);\n\t\t};\n\t}\n\treturn [\n\t\terrState[0],\n\t\t() => {\n\t\t\terrState[1](undefined);\n\t\t}\n\t];\n}\n\n/**\n * After paint effects consumer.\n */\nfunction flushAfterPaintEffects() {\n\tafterPaintEffects.forEach(component => {\n\t\tif (component._parentDom) {\n\t\t\ttry {\n\t\t\t\tcomponent.__hooks._pendingEffects.forEach(invokeCleanup);\n\t\t\t\tcomponent.__hooks._pendingEffects.forEach(invokeEffect);\n\t\t\t\tcomponent.__hooks._pendingEffects = [];\n\t\t\t} catch (e) {\n\t\t\t\tcomponent.__hooks._pendingEffects = [];\n\t\t\t\toptions._catchError(e, component._vnode);\n\t\t\t}\n\t\t}\n\t});\n\tafterPaintEffects = [];\n}\n\nlet HAS_RAF = typeof requestAnimationFrame == 'function';\n\n/**\n * Schedule a callback to be invoked after the browser has a chance to paint a new frame.\n * Do this by combining requestAnimationFrame (rAF) + setTimeout to invoke a callback after\n * the next browser frame.\n *\n * Also, schedule a timeout in parallel to the the rAF to ensure the callback is invoked\n * even if RAF doesn't fire (for example if the browser tab is not visible)\n *\n * @param {() => void} callback\n */\nfunction afterNextFrame(callback) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tif (HAS_RAF) cancelAnimationFrame(raf);\n\t\tsetTimeout(callback);\n\t};\n\tconst timeout = setTimeout(done, RAF_TIMEOUT);\n\n\tlet raf;\n\tif (HAS_RAF) {\n\t\traf = requestAnimationFrame(done);\n\t}\n}\n\n// Note: if someone used options.debounceRendering = requestAnimationFrame,\n// then effects will ALWAYS run on the NEXT frame instead of the current one, incurring a ~16ms delay.\n// Perhaps this is not such a big deal.\n/**\n * Schedule afterPaintEffects flush after the browser paints\n * @param {number} newQueueLength\n */\nfunction afterPaint(newQueueLength) {\n\tif (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {\n\t\tprevRaf = options.requestAnimationFrame;\n\t\t(prevRaf || afterNextFrame)(flushAfterPaintEffects);\n\t}\n}\n\n/**\n * @param {import('./internal').EffectHookState} hook\n */\nfunction invokeCleanup(hook) {\n\t// A hook cleanup can introduce a call to render which creates a new root, this will call options.vnode\n\t// and move the currentComponent away.\n\tconst comp = currentComponent;\n\tif (typeof hook._cleanup == 'function') hook._cleanup();\n\tcurrentComponent = comp;\n}\n\n/**\n * Invoke a Hook's effect\n * @param {import('./internal').EffectHookState} hook\n */\nfunction invokeEffect(hook) {\n\t// A hook call can introduce a call to render which creates a new root, this will call options.vnode\n\t// and move the currentComponent away.\n\tconst comp = currentComponent;\n\thook._cleanup = hook._value();\n\tcurrentComponent = comp;\n}\n\n/**\n * @param {any[]} oldArgs\n * @param {any[]} newArgs\n */\nfunction argsChanged(oldArgs, newArgs) {\n\treturn (\n\t\t!oldArgs ||\n\t\toldArgs.length !== newArgs.length ||\n\t\tnewArgs.some((arg, index) => arg !== oldArgs[index])\n\t);\n}\n\nfunction invokeOrReturn(arg, f) {\n\treturn typeof f == 'function' ? f(arg) : f;\n}\n"],"names":["currentIndex","currentComponent","prevRaf","currentHook","afterPaintEffects","oldBeforeDiff","options","oldBeforeRender","oldAfterDiff","diffed","oldCommit","oldBeforeUnmount","unmount","getHookState","index","type","hooks","length","push","useState","initialState","useReducer","invokeOrReturn","reducer","init","hookState","_reducer","undefined","action","nextValue","setState","useLayoutEffect","callback","args","state","argsChanged","useMemo","factory","flushAfterPaintEffects","forEach","component","invokeCleanup","invokeEffect","e","vnode","c","requestAnimationFrame","raf","done","clearTimeout","timeout","HAS_RAF","cancelAnimationFrame","setTimeout","commitQueue","some","filter","cb","hook","comp","oldArgs","newArgs","arg","f","initialValue","current","ref","createHandle","concat","context","provider","sub","props","value","formatter","useDebugValue","errState","componentDidCatch","err"],"mappings":"uNAGA,IAAIA,EAGAC,EAeAC,EAZAC,EAAc,EAGdC,EAAoB,GAEpBC,EAAgBC,cAChBC,EAAkBD,cAClBE,EAAeF,UAAQG,OACvBC,EAAYJ,cACZK,EAAmBL,UAAQM,QAwE/B,SAASC,EAAaC,EAAOC,GACxBT,eACHA,cAAcL,EAAkBa,EAAOX,GAAeY,GAEvDZ,EAAc,MAORa,EACLf,QACCA,MAA2B,IACpB,OACU,YAGfa,GAASE,KAAYC,QACxBD,K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,EAAc,EACd4B,EACC,WACmB,mBAAPmC,EAAmBA,EAAIC,KACzBD,IAAKA,EAAID,QAAUE,MAErB,MAARlC,EAAeA,EAAOA,EAAKmC,OAAOF,+BAwB7B,SAAqBlC,EAAUC,UACrC9B,EAAc,EACPiC,EAAQ,kBAAMJ,GAAUC,iBAMzB,SAAoBoC,OACpBC,EAAWrE,EAAiBoE,QAAQA,OAKpCnC,EAAQrB,EAAab,IAAgB,UAI3CkC,IAAiBmC,EACZC,GAEe,MAAhBpC,OACHA,MAAe,EACfoC,EAASC,IAAItE,IAEPqE,EAASE,MAAMC,OANAJ,sBAahB,SAAuBI,EAAOC,GAChCpE,UAAQqE,eACXrE,UAAQqE,cAAcD,EAAYA,EAAUD,GAASA,uBAOhD,SAA0BhB,OAE1BvB,EAAQrB,EAAab,IAAgB,IACrC4E,EAAWzD,WACjBe,KAAeuB,EACVxD,EAAiB4E,oBACrB5E,EAAiB4E,kBAAoB,SAAAC,GAChC5C,MAAcA,KAAa4C,GAC/BF,EAAS,GAAGE,KAGP,CACNF,EAAS,GACT,WACCA,EAAS,QAAGjD"}
1
+ {"version":3,"file":"hooks.umd.js","sources":["../src/index.js"],"sourcesContent":["import { options } from 'preact';\r\n\r\n/** @type {number} */\r\nlet currentIndex;\r\n\r\n/** @type {import('./internal').Component} */\r\nlet currentComponent;\r\n\r\n/** @type {number} */\r\nlet currentHook = 0;\r\n\r\n/** @type {Array<import('./internal').Component>} */\r\nlet afterPaintEffects = [];\r\n\r\nlet oldBeforeDiff = options._diff;\r\nlet oldBeforeRender = options._render;\r\nlet oldAfterDiff = options.diffed;\r\nlet oldCommit = options._commit;\r\nlet oldBeforeUnmount = options.unmount;\r\n\r\nconst RAF_TIMEOUT = 100;\r\nlet prevRaf;\r\n\r\noptions._diff = vnode => {\r\n\tcurrentComponent = null;\r\n\tif (oldBeforeDiff) oldBeforeDiff(vnode);\r\n};\r\n\r\noptions._render = vnode => {\r\n\tif (oldBeforeRender) oldBeforeRender(vnode);\r\n\r\n\tcurrentComponent = vnode._component;\r\n\tcurrentIndex = 0;\r\n\r\n\tconst hooks = currentComponent.__hooks;\r\n\tif (hooks) {\r\n\t\thooks._pendingEffects.forEach(invokeCleanup);\r\n\t\thooks._pendingEffects.forEach(invokeEffect);\r\n\t\thooks._pendingEffects = [];\r\n\t}\r\n};\r\n\r\noptions.diffed = vnode => {\r\n\tif (oldAfterDiff) oldAfterDiff(vnode);\r\n\r\n\tconst c = vnode._component;\r\n\tif (c && c.__hooks && c.__hooks._pendingEffects.length) {\r\n\t\tafterPaint(afterPaintEffects.push(c));\r\n\t}\r\n\tcurrentComponent = null;\r\n};\r\n\r\noptions._commit = (vnode, commitQueue) => {\r\n\tcommitQueue.some(component => {\r\n\t\ttry {\r\n\t\t\tcomponent._renderCallbacks.forEach(invokeCleanup);\r\n\t\t\tcomponent._renderCallbacks = component._renderCallbacks.filter(cb =>\r\n\t\t\t\tcb._value ? invokeEffect(cb) : true\r\n\t\t\t);\r\n\t\t} catch (e) {\r\n\t\t\tcommitQueue.some(c => {\r\n\t\t\t\tif (c._renderCallbacks) c._renderCallbacks = [];\r\n\t\t\t});\r\n\t\t\tcommitQueue = [];\r\n\t\t\toptions._catchError(e, component._vnode);\r\n\t\t}\r\n\t});\r\n\r\n\tif (oldCommit) oldCommit(vnode, commitQueue);\r\n};\r\n\r\noptions.unmount = vnode => {\r\n\tif (oldBeforeUnmount) oldBeforeUnmount(vnode);\r\n\r\n\tconst c = vnode._component;\r\n\tif (c && c.__hooks) {\r\n\t\tlet hasErrored;\r\n\t\tc.__hooks._list.forEach(s => {\r\n\t\t\ttry {\r\n\t\t\t\tinvokeCleanup(s);\r\n\t\t\t} catch (e) {\r\n\t\t\t\thasErrored = e;\r\n\t\t\t}\r\n\t\t});\r\n\t\tif (hasErrored) options._catchError(hasErrored, c._vnode);\r\n\t}\r\n};\r\n\r\n/**\r\n * Get a hook's state from the currentComponent\r\n * @param {number} index The index of the hook to get\r\n * @param {number} type The index of the hook to get\r\n * @returns {any}\r\n */\r\nfunction getHookState(index, type) {\r\n\tif (options._hook) {\r\n\t\toptions._hook(currentComponent, index, currentHook || type);\r\n\t}\r\n\tcurrentHook = 0;\r\n\r\n\t// Largely inspired by:\r\n\t// * https://github.com/michael-klein/funcy.js/blob/f6be73468e6ec46b0ff5aa3cc4c9baf72a29025a/src/hooks/core_hooks.mjs\r\n\t// * https://github.com/michael-klein/funcy.js/blob/650beaa58c43c33a74820a3c98b3c7079cf2e333/src/renderer.mjs\r\n\t// Other implementations to look at:\r\n\t// * https://codesandbox.io/s/mnox05qp8\r\n\tconst hooks =\r\n\t\tcurrentComponent.__hooks ||\r\n\t\t(currentComponent.__hooks = {\r\n\t\t\t_list: [],\r\n\t\t\t_pendingEffects: []\r\n\t\t});\r\n\r\n\tif (index >= hooks._list.length) {\r\n\t\thooks._list.push({});\r\n\t}\r\n\treturn hooks._list[index];\r\n}\r\n\r\n/**\r\n * @param {import('./index').StateUpdater<any>} [initialState]\r\n */\r\nexport function useState(initialState) {\r\n\tcurrentHook = 1;\r\n\treturn useReducer(invokeOrReturn, initialState);\r\n}\r\n\r\n/**\r\n * @param {import('./index').Reducer<any, any>} reducer\r\n * @param {import('./index').StateUpdater<any>} initialState\r\n * @param {(initialState: any) => void} [init]\r\n * @returns {[ any, (state: any) => void ]}\r\n */\r\nexport function useReducer(reducer, initialState, init) {\r\n\t/** @type {import('./internal').ReducerHookState} */\r\n\tconst hookState = getHookState(currentIndex++, 2);\r\n\thookState._reducer = reducer;\r\n\tif (!hookState._component) {\r\n\t\thookState._value = [\r\n\t\t\t!init ? invokeOrReturn(undefined, initialState) : init(initialState),\r\n\r\n\t\t\taction => {\r\n\t\t\t\tconst nextValue = hookState._reducer(hookState._value[0], action);\r\n\t\t\t\tif (hookState._value[0] !== nextValue) {\r\n\t\t\t\t\thookState._value = [nextValue, hookState._value[1]];\r\n\t\t\t\t\thookState._component.setState({});\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t];\r\n\r\n\t\thookState._component = currentComponent;\r\n\t}\r\n\r\n\treturn hookState._value;\r\n}\r\n\r\n/**\r\n * @param {import('./internal').Effect} callback\r\n * @param {any[]} args\r\n */\r\nexport function useEffect(callback, args) {\r\n\t/** @type {import('./internal').EffectHookState} */\r\n\tconst state = getHookState(currentIndex++, 3);\r\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\r\n\t\tstate._value = callback;\r\n\t\tstate._args = args;\r\n\r\n\t\tcurrentComponent.__hooks._pendingEffects.push(state);\r\n\t}\r\n}\r\n\r\n/**\r\n * @param {import('./internal').Effect} callback\r\n * @param {any[]} args\r\n */\r\nexport function useLayoutEffect(callback, args) {\r\n\t/** @type {import('./internal').EffectHookState} */\r\n\tconst state = getHookState(currentIndex++, 4);\r\n\tif (!options._skipEffects && argsChanged(state._args, args)) {\r\n\t\tstate._value = callback;\r\n\t\tstate._args = args;\r\n\r\n\t\tcurrentComponent._renderCallbacks.push(state);\r\n\t}\r\n}\r\n\r\nexport function useRef(initialValue) {\r\n\tcurrentHook = 5;\r\n\treturn useMemo(() => ({ current: initialValue }), []);\r\n}\r\n\r\n/**\r\n * @param {object} ref\r\n * @param {() => object} createHandle\r\n * @param {any[]} args\r\n */\r\nexport function useImperativeHandle(ref, createHandle, args) {\r\n\tcurrentHook = 6;\r\n\tuseLayoutEffect(\r\n\t\t() => {\r\n\t\t\tif (typeof ref == 'function') ref(createHandle());\r\n\t\t\telse if (ref) ref.current = createHandle();\r\n\t\t},\r\n\t\targs == null ? args : args.concat(ref)\r\n\t);\r\n}\r\n\r\n/**\r\n * @param {() => any} factory\r\n * @param {any[]} args\r\n */\r\nexport function useMemo(factory, args) {\r\n\t/** @type {import('./internal').MemoHookState} */\r\n\tconst state = getHookState(currentIndex++, 7);\r\n\tif (argsChanged(state._args, args)) {\r\n\t\tstate._value = factory();\r\n\t\tstate._args = args;\r\n\t\tstate._factory = factory;\r\n\t}\r\n\r\n\treturn state._value;\r\n}\r\n\r\n/**\r\n * @param {() => void} callback\r\n * @param {any[]} args\r\n */\r\nexport function useCallback(callback, args) {\r\n\tcurrentHook = 8;\r\n\treturn useMemo(() => callback, args);\r\n}\r\n\r\n/**\r\n * @param {import('./internal').PreactContext} context\r\n */\r\nexport function useContext(context) {\r\n\tconst provider = currentComponent.context[context._id];\r\n\t// We could skip this call here, but than we'd not call\r\n\t// `options._hook`. We need to do that in order to make\r\n\t// the devtools aware of this hook.\r\n\t/** @type {import('./internal').ContextHookState} */\r\n\tconst state = getHookState(currentIndex++, 9);\r\n\t// The devtools needs access to the context object to\r\n\t// be able to pull of the default value when no provider\r\n\t// is present in the tree.\r\n\tstate._context = context;\r\n\tif (!provider) return context._defaultValue;\r\n\t// This is probably not safe to convert to \"!\"\r\n\tif (state._value == null) {\r\n\t\tstate._value = true;\r\n\t\tprovider.sub(currentComponent);\r\n\t}\r\n\treturn provider.props.value;\r\n}\r\n\r\n/**\r\n * Display a custom label for a custom hook for the devtools panel\r\n * @type {<T>(value: T, cb?: (value: T) => string | number) => void}\r\n */\r\nexport function useDebugValue(value, formatter) {\r\n\tif (options.useDebugValue) {\r\n\t\toptions.useDebugValue(formatter ? formatter(value) : value);\r\n\t}\r\n}\r\n\r\n/**\r\n * @param {(error: any) => void} cb\r\n */\r\nexport function useErrorBoundary(cb) {\r\n\t/** @type {import('./internal').ErrorBoundaryHookState} */\r\n\tconst state = getHookState(currentIndex++, 10);\r\n\tconst errState = useState();\r\n\tstate._value = cb;\r\n\tif (!currentComponent.componentDidCatch) {\r\n\t\tcurrentComponent.componentDidCatch = err => {\r\n\t\t\tif (state._value) state._value(err);\r\n\t\t\terrState[1](err);\r\n\t\t};\r\n\t}\r\n\treturn [\r\n\t\terrState[0],\r\n\t\t() => {\r\n\t\t\terrState[1](undefined);\r\n\t\t}\r\n\t];\r\n}\r\n\r\n/**\r\n * After paint effects consumer.\r\n */\r\nfunction flushAfterPaintEffects() {\r\n\tlet component;\r\n\t// sort the queue by depth (outermost to innermost)\r\n\tafterPaintEffects.sort((a, b) => a._vnode._depth - b._vnode._depth);\r\n\twhile (component = afterPaintEffects.pop()) {\r\n\t\tif (!component._parentDom) continue;\r\n\t\ttry {\r\n\t\t\tcomponent.__hooks._pendingEffects.forEach(invokeCleanup);\r\n\t\t\tcomponent.__hooks._pendingEffects.forEach(invokeEffect);\r\n\t\t\tcomponent.__hooks._pendingEffects = [];\r\n\t\t} catch (e) {\r\n\t\t\tcomponent.__hooks._pendingEffects = [];\r\n\t\t\toptions._catchError(e, component._vnode);\r\n\t\t}\r\n\t}\r\n}\r\n\r\nlet HAS_RAF = typeof requestAnimationFrame == 'function';\r\n\r\n/**\r\n * Schedule a callback to be invoked after the browser has a chance to paint a new frame.\r\n * Do this by combining requestAnimationFrame (rAF) + setTimeout to invoke a callback after\r\n * the next browser frame.\r\n *\r\n * Also, schedule a timeout in parallel to the the rAF to ensure the callback is invoked\r\n * even if RAF doesn't fire (for example if the browser tab is not visible)\r\n *\r\n * @param {() => void} callback\r\n */\r\nfunction afterNextFrame(callback) {\r\n\tconst done = () => {\r\n\t\tclearTimeout(timeout);\r\n\t\tif (HAS_RAF) cancelAnimationFrame(raf);\r\n\t\tsetTimeout(callback);\r\n\t};\r\n\tconst timeout = setTimeout(done, RAF_TIMEOUT);\r\n\r\n\tlet raf;\r\n\tif (HAS_RAF) {\r\n\t\traf = requestAnimationFrame(done);\r\n\t}\r\n}\r\n\r\n// Note: if someone used options.debounceRendering = requestAnimationFrame,\r\n// then effects will ALWAYS run on the NEXT frame instead of the current one, incurring a ~16ms delay.\r\n// Perhaps this is not such a big deal.\r\n/**\r\n * Schedule afterPaintEffects flush after the browser paints\r\n * @param {number} newQueueLength\r\n */\r\nfunction afterPaint(newQueueLength) {\r\n\tif (newQueueLength === 1 || prevRaf !== options.requestAnimationFrame) {\r\n\t\tprevRaf = options.requestAnimationFrame;\r\n\t\t(prevRaf || afterNextFrame)(flushAfterPaintEffects);\r\n\t}\r\n}\r\n\r\n/**\r\n * @param {import('./internal').EffectHookState} hook\r\n */\r\nfunction invokeCleanup(hook) {\r\n\t// A hook cleanup can introduce a call to render which creates a new root, this will call options.vnode\r\n\t// and move the currentComponent away.\r\n\tconst comp = currentComponent;\r\n\tlet cleanup = hook._cleanup;\r\n\tif (typeof cleanup == 'function') {\r\n\t\thook._cleanup = undefined;\r\n\t\tcleanup();\r\n\t}\r\n\tcurrentComponent = comp;\r\n}\r\n\r\n/**\r\n * Invoke a Hook's effect\r\n * @param {import('./internal').EffectHookState} hook\r\n */\r\nfunction invokeEffect(hook) {\r\n\t// A hook call can introduce a call to render which creates a new root, this will call options.vnode\r\n\t// and move the currentComponent away.\r\n\tconst comp = currentComponent;\r\n\thook._cleanup = hook._value();\r\n\tcurrentComponent = comp;\r\n}\r\n\r\n/**\r\n * @param {any[]} oldArgs\r\n * @param {any[]} newArgs\r\n */\r\nfunction argsChanged(oldArgs, newArgs) {\r\n\treturn (\r\n\t\t!oldArgs ||\r\n\t\toldArgs.length !== newArgs.length ||\r\n\t\tnewArgs.some((arg, index) => arg !== oldArgs[index])\r\n\t);\r\n}\r\n\r\nfunction invokeOrReturn(arg, f) {\r\n\treturn typeof f == 'function' ? f(arg) : f;\r\n}\r\n"],"names":["currentIndex","currentComponent","prevRaf","currentHook","afterPaintEffects","oldBeforeDiff","options","oldBeforeRender","oldAfterDiff","diffed","oldCommit","oldBeforeUnmount","unmount","getHookState","index","type","hooks","length","push","useState","initialState","useReducer","invokeOrReturn","reducer","init","hookState","_reducer","undefined","action","nextValue","setState","useLayoutEffect","callback","args","state","argsChanged","useMemo","factory","flushAfterPaintEffects","component","sort","a","b","pop","forEach","invokeCleanup","invokeEffect","e","vnode","c","requestAnimationFrame","raf","done","clearTimeout","timeout","HAS_RAF","cancelAnimationFrame","setTimeout","commitQueue","some","filter","cb","hasErrored","s","hook","comp","cleanup","oldArgs","newArgs","arg","f","initialValue","current","ref","createHandle","concat","context","provider","sub","props","value","formatter","useDebugValue","errState","componentDidCatch","err"],"mappings":"uNAGA,IAAIA,EAGA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,SAAWmD,EAAQnD,QAC3BmD,EAAQT,KAAK,SAACU,EAAKvD,UAAUuD,IAAQF,EAAQrD,KAI/C,SAASQ,EAAe+C,EAAKC,SACT,mBAALA,EAAkBA,EAAED,GAAOC,0CAnOnC,SAAmBtC,EAAUC,OAE7BC,EAAQrB,EAAab,IAAgB,IACtCM,eAAwB6B,EAAYD,MAAaD,KACrDC,KAAeF,EACfE,MAAcD,EAEdhC,UAAyCiB,KAAKgB,kCAmBzC,SAAgBqC,UACtBpE,EAAc,EACPiC,EAAQ,iBAAO,CAAEoC,QAASD,IAAiB,2BAQ5C,SAA6BE,EAAKC,EAAczC,GACtD9B,EAAc,EACd4B,EACC,WACmB,mBAAP0C,EAAmBA,EAAIC,KACzBD,IAAKA,EAAID,QAAUE,MAErB,MAARzC,EAAeA,EAAOA,EAAK0C,OAAOF,+BAwB7B,SAAqBzC,EAAUC,UACrC9B,EAAc,EACPiC,EAAQ,kBAAMJ,GAAUC,iBAMzB,SAAoB2C,OACpBC,EAAW5E,EAAiB2E,QAAQA,OAKpC1C,EAAQrB,EAAab,IAAgB,UAI3CkC,IAAiB0C,EACZC,GAEe,MAAhB3C,OACHA,MAAe,EACf2C,EAASC,IAAI7E,IAEP4E,EAASE,MAAMC,OANAJ,sBAahB,SAAuBI,EAAOC,GAChC3E,UAAQ4E,eACX5E,UAAQ4E,cAAcD,EAAYA,EAAUD,GAASA,uBAOhD,SAA0BnB,OAE1B3B,EAAQrB,EAAab,IAAgB,IACrCmF,EAAWhE,WACjBe,KAAe2B,EACV5D,EAAiBmF,oBACrBnF,EAAiBmF,kBAAoB,SAAAC,GAChCnD,MAAcA,KAAamD,GAC/BF,EAAS,GAAGE,KAGP,CACNF,EAAS,GACT,WACCA,EAAS,QAAGxD"}
@@ -1,26 +1,26 @@
1
- {
2
- "name": "preact-hooks",
3
- "amdName": "preactHooks",
4
- "version": "0.1.0",
5
- "private": true,
6
- "description": "Hook addon for Preact",
7
- "main": "dist/hooks.js",
8
- "module": "dist/hooks.module.js",
9
- "umd:main": "dist/hooks.umd.js",
10
- "source": "src/index.js",
11
- "license": "MIT",
12
- "types": "src/index.d.ts",
13
- "scripts": {
14
- "build": "microbundle build --raw",
15
- "dev": "microbundle watch --raw --format cjs",
16
- "test": "npm-run-all build --parallel test:karma",
17
- "test:karma": "karma start test/karma.conf.js --single-run",
18
- "test:karma:watch": "karma start test/karma.conf.js --no-single-run"
19
- },
20
- "peerDependencies": {
21
- "preact": "^10.0.0"
22
- },
23
- "mangle": {
24
- "regex": "^_"
25
- }
26
- }
1
+ {
2
+ "name": "preact-hooks",
3
+ "amdName": "preactHooks",
4
+ "version": "0.1.0",
5
+ "private": true,
6
+ "description": "Hook addon for Preact",
7
+ "main": "dist/hooks.js",
8
+ "module": "dist/hooks.module.js",
9
+ "umd:main": "dist/hooks.umd.js",
10
+ "source": "src/index.js",
11
+ "license": "MIT",
12
+ "types": "src/index.d.ts",
13
+ "scripts": {
14
+ "build": "microbundle build --raw",
15
+ "dev": "microbundle watch --raw --format cjs",
16
+ "test": "npm-run-all build --parallel test:karma",
17
+ "test:karma": "karma start test/karma.conf.js --single-run",
18
+ "test:karma:watch": "karma start test/karma.conf.js --no-single-run"
19
+ },
20
+ "peerDependencies": {
21
+ "preact": "^10.0.0"
22
+ },
23
+ "mangle": {
24
+ "regex": "^_"
25
+ }
26
+ }
@@ -1,139 +1,139 @@
1
- import { PreactContext, Ref as PreactRef } from '../..';
2
-
3
- type Inputs = ReadonlyArray<unknown>;
4
-
5
- export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
6
- /**
7
- * Returns a stateful value, and a function to update it.
8
- * @param initialState The initial value (or a function that returns the initial value)
9
- */
10
- export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
11
-
12
- export function useState<S = undefined>(): [
13
- S | undefined,
14
- StateUpdater<S | undefined>
15
- ];
16
-
17
- export type Reducer<S, A> = (prevState: S, action: A) => S;
18
- /**
19
- * An alternative to `useState`.
20
- *
21
- * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
22
- * multiple sub-values. It also lets you optimize performance for components that trigger deep
23
- * updates because you can pass `dispatch` down instead of callbacks.
24
- * @param reducer Given the current state and an action, returns the new state
25
- * @param initialState The initial value to store as state
26
- */
27
- export function useReducer<S, A>(
28
- reducer: Reducer<S, A>,
29
- initialState: S
30
- ): [S, (action: A) => void];
31
-
32
- /**
33
- * An alternative to `useState`.
34
- *
35
- * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
36
- * multiple sub-values. It also lets you optimize performance for components that trigger deep
37
- * updates because you can pass `dispatch` down instead of callbacks.
38
- * @param reducer Given the current state and an action, returns the new state
39
- * @param initialArg The initial argument to pass to the `init` function
40
- * @param init A function that, given the `initialArg`, returns the initial value to store as state
41
- */
42
- export function useReducer<S, A, I>(
43
- reducer: Reducer<S, A>,
44
- initialArg: I,
45
- init: (arg: I) => S
46
- ): [S, (action: A) => void];
47
-
48
- /** @deprecated Use the `Ref` type instead. */
49
- type PropRef<T> = MutableRef<T>;
50
- interface Ref<T> {
51
- readonly current: T | null;
52
- }
53
-
54
- interface MutableRef<T> {
55
- current: T;
56
- }
57
-
58
- /**
59
- * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
60
- * (`initialValue`). The returned object will persist for the full lifetime of the component.
61
- *
62
- * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
63
- * value around similar to how you’d use instance fields in classes.
64
- *
65
- * @param initialValue the initial value to store in the ref object
66
- */
67
- export function useRef<T>(initialValue: T): MutableRef<T>;
68
- export function useRef<T>(initialValue: T | null): Ref<T>;
69
- export function useRef<T = undefined>(): MutableRef<T | undefined>;
70
-
71
- type EffectCallback = () => void | (() => void);
72
- /**
73
- * Accepts a function that contains imperative, possibly effectful code.
74
- * The effects run after browser paint, without blocking it.
75
- *
76
- * @param effect Imperative function that can return a cleanup function
77
- * @param inputs If present, effect will only activate if the values in the list change (using ===).
78
- */
79
- export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
80
-
81
- type CreateHandle = () => object;
82
-
83
- /**
84
- * @param ref The ref that will be mutated
85
- * @param create The function that will be executed to get the value that will be attached to
86
- * ref.current
87
- * @param inputs If present, effect will only activate if the values in the list change (using ===).
88
- */
89
- export function useImperativeHandle<T, R extends T>(
90
- ref: PreactRef<T>,
91
- create: () => R,
92
- inputs?: Inputs
93
- ): void;
94
-
95
- /**
96
- * Accepts a function that contains imperative, possibly effectful code.
97
- * Use this to read layout from the DOM and synchronously re-render.
98
- * Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
99
- * Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
100
- *
101
- * @param effect Imperative function that can return a cleanup function
102
- * @param inputs If present, effect will only activate if the values in the list change (using ===).
103
- */
104
- export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
105
-
106
- /**
107
- * Returns a memoized version of the callback that only changes if one of the `inputs`
108
- * has changed (using ===).
109
- */
110
- export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
111
-
112
- /**
113
- * Pass a factory function and an array of inputs.
114
- * useMemo will only recompute the memoized value when one of the inputs has changed.
115
- * This optimization helps to avoid expensive calculations on every render.
116
- * If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
117
- */
118
- // for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
119
- export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
120
-
121
- /**
122
- * Returns the current context value, as given by the nearest context provider for the given context.
123
- * When the provider updates, this Hook will trigger a rerender with the latest context value.
124
- *
125
- * @param context The context you want to use
126
- */
127
- export function useContext<T>(context: PreactContext<T>): T;
128
-
129
- /**
130
- * Customize the displayed value in the devtools panel.
131
- *
132
- * @param value Custom hook name or object that is passed to formatter
133
- * @param formatter Formatter to modify value before sending it to the devtools
134
- */
135
- export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
136
-
137
- export function useErrorBoundary(
138
- callback?: (error: any) => Promise<void> | void
139
- ): [any, () => void];
1
+ import { PreactContext, Ref as PreactRef } from '../..';
2
+
3
+ type Inputs = ReadonlyArray<unknown>;
4
+
5
+ export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
6
+ /**
7
+ * Returns a stateful value, and a function to update it.
8
+ * @param initialState The initial value (or a function that returns the initial value)
9
+ */
10
+ export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
11
+
12
+ export function useState<S = undefined>(): [
13
+ S | undefined,
14
+ StateUpdater<S | undefined>
15
+ ];
16
+
17
+ export type Reducer<S, A> = (prevState: S, action: A) => S;
18
+ /**
19
+ * An alternative to `useState`.
20
+ *
21
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
22
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
23
+ * updates because you can pass `dispatch` down instead of callbacks.
24
+ * @param reducer Given the current state and an action, returns the new state
25
+ * @param initialState The initial value to store as state
26
+ */
27
+ export function useReducer<S, A>(
28
+ reducer: Reducer<S, A>,
29
+ initialState: S
30
+ ): [S, (action: A) => void];
31
+
32
+ /**
33
+ * An alternative to `useState`.
34
+ *
35
+ * `useReducer` is usually preferable to `useState` when you have complex state logic that involves
36
+ * multiple sub-values. It also lets you optimize performance for components that trigger deep
37
+ * updates because you can pass `dispatch` down instead of callbacks.
38
+ * @param reducer Given the current state and an action, returns the new state
39
+ * @param initialArg The initial argument to pass to the `init` function
40
+ * @param init A function that, given the `initialArg`, returns the initial value to store as state
41
+ */
42
+ export function useReducer<S, A, I>(
43
+ reducer: Reducer<S, A>,
44
+ initialArg: I,
45
+ init: (arg: I) => S
46
+ ): [S, (action: A) => void];
47
+
48
+ /** @deprecated Use the `Ref` type instead. */
49
+ type PropRef<T> = MutableRef<T>;
50
+ interface Ref<T> {
51
+ readonly current: T | null;
52
+ }
53
+
54
+ interface MutableRef<T> {
55
+ current: T;
56
+ }
57
+
58
+ /**
59
+ * `useRef` returns a mutable ref object whose `.current` property is initialized to the passed argument
60
+ * (`initialValue`). The returned object will persist for the full lifetime of the component.
61
+ *
62
+ * Note that `useRef()` is useful for more than the `ref` attribute. It’s handy for keeping any mutable
63
+ * value around similar to how you’d use instance fields in classes.
64
+ *
65
+ * @param initialValue the initial value to store in the ref object
66
+ */
67
+ export function useRef<T>(initialValue: T): MutableRef<T>;
68
+ export function useRef<T>(initialValue: T | null): Ref<T>;
69
+ export function useRef<T = undefined>(): MutableRef<T | undefined>;
70
+
71
+ type EffectCallback = () => void | (() => void);
72
+ /**
73
+ * Accepts a function that contains imperative, possibly effectful code.
74
+ * The effects run after browser paint, without blocking it.
75
+ *
76
+ * @param effect Imperative function that can return a cleanup function
77
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
78
+ */
79
+ export function useEffect(effect: EffectCallback, inputs?: Inputs): void;
80
+
81
+ type CreateHandle = () => object;
82
+
83
+ /**
84
+ * @param ref The ref that will be mutated
85
+ * @param create The function that will be executed to get the value that will be attached to
86
+ * ref.current
87
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
88
+ */
89
+ export function useImperativeHandle<T, R extends T>(
90
+ ref: PreactRef<T>,
91
+ create: () => R,
92
+ inputs?: Inputs
93
+ ): void;
94
+
95
+ /**
96
+ * Accepts a function that contains imperative, possibly effectful code.
97
+ * Use this to read layout from the DOM and synchronously re-render.
98
+ * Updates scheduled inside `useLayoutEffect` will be flushed synchronously, after all DOM mutations but before the browser has a chance to paint.
99
+ * Prefer the standard `useEffect` hook when possible to avoid blocking visual updates.
100
+ *
101
+ * @param effect Imperative function that can return a cleanup function
102
+ * @param inputs If present, effect will only activate if the values in the list change (using ===).
103
+ */
104
+ export function useLayoutEffect(effect: EffectCallback, inputs?: Inputs): void;
105
+
106
+ /**
107
+ * Returns a memoized version of the callback that only changes if one of the `inputs`
108
+ * has changed (using ===).
109
+ */
110
+ export function useCallback<T extends Function>(callback: T, inputs: Inputs): T;
111
+
112
+ /**
113
+ * Pass a factory function and an array of inputs.
114
+ * useMemo will only recompute the memoized value when one of the inputs has changed.
115
+ * This optimization helps to avoid expensive calculations on every render.
116
+ * If no array is provided, a new value will be computed whenever a new function instance is passed as the first argument.
117
+ */
118
+ // for `inputs`, allow undefined, but don't make it optional as that is very likely a mistake
119
+ export function useMemo<T>(factory: () => T, inputs: Inputs | undefined): T;
120
+
121
+ /**
122
+ * Returns the current context value, as given by the nearest context provider for the given context.
123
+ * When the provider updates, this Hook will trigger a rerender with the latest context value.
124
+ *
125
+ * @param context The context you want to use
126
+ */
127
+ export function useContext<T>(context: PreactContext<T>): T;
128
+
129
+ /**
130
+ * Customize the displayed value in the devtools panel.
131
+ *
132
+ * @param value Custom hook name or object that is passed to formatter
133
+ * @param formatter Formatter to modify value before sending it to the devtools
134
+ */
135
+ export function useDebugValue<T>(value: T, formatter?: (value: T) => any): void;
136
+
137
+ export function useErrorBoundary(
138
+ callback?: (error: any) => Promise<void> | void
139
+ ): [any, () => void];