@dr.pogodin/react-utils 1.23.9 → 1.23.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +3 -2
  2. package/build/development/client/getInj.js.map +1 -1
  3. package/build/development/client/index.js.map +1 -1
  4. package/build/development/client/init.js.map +1 -1
  5. package/build/development/index.js.map +1 -1
  6. package/build/development/server/Cache.js.map +1 -1
  7. package/build/development/server/index.js.map +1 -1
  8. package/build/development/server/renderer.js.map +1 -1
  9. package/build/development/server/server.js.map +1 -1
  10. package/build/development/shared/components/Button/index.js.map +1 -1
  11. package/build/development/shared/components/Checkbox/index.js.map +1 -1
  12. package/build/development/shared/components/CodeSplit/index.js.map +1 -1
  13. package/build/development/shared/components/Dropdown/index.js.map +1 -1
  14. package/build/development/shared/components/GenericLink/index.js.map +1 -1
  15. package/build/development/shared/components/Input/index.js.map +1 -1
  16. package/build/development/shared/components/Link.js.map +1 -1
  17. package/build/development/shared/components/MetaTags.js.map +1 -1
  18. package/build/development/shared/components/Modal/index.js.map +1 -1
  19. package/build/development/shared/components/NavLink.js.map +1 -1
  20. package/build/development/shared/components/PageLayout/index.js.map +1 -1
  21. package/build/development/shared/components/ScalableRect/index.js.map +1 -1
  22. package/build/development/shared/components/Throbber/index.js.map +1 -1
  23. package/build/development/shared/components/WithTooltip/Tooltip.js.map +1 -1
  24. package/build/development/shared/components/WithTooltip/index.js.map +1 -1
  25. package/build/development/shared/components/YouTubeVideo/index.js.map +1 -1
  26. package/build/development/shared/utils/config.js.map +1 -1
  27. package/build/development/shared/utils/index.js.map +1 -1
  28. package/build/development/shared/utils/isomorphy/index.js.map +1 -1
  29. package/build/development/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  30. package/build/development/shared/utils/jest/index.js.map +1 -1
  31. package/build/development/shared/utils/splitComponent.js.map +1 -1
  32. package/build/development/shared/utils/time.js.map +1 -1
  33. package/build/development/web.bundle.js +49 -191
  34. package/build/production/client/getInj.js.map +1 -1
  35. package/build/production/client/index.js.map +1 -1
  36. package/build/production/client/init.js.map +1 -1
  37. package/build/production/index.js.map +1 -1
  38. package/build/production/server/Cache.js.map +1 -1
  39. package/build/production/server/index.js +1 -1
  40. package/build/production/server/index.js.map +1 -1
  41. package/build/production/server/renderer.js.map +1 -1
  42. package/build/production/server/server.js.map +1 -1
  43. package/build/production/shared/components/Button/index.js.map +1 -1
  44. package/build/production/shared/components/Checkbox/index.js.map +1 -1
  45. package/build/production/shared/components/CodeSplit/index.js.map +1 -1
  46. package/build/production/shared/components/Dropdown/index.js.map +1 -1
  47. package/build/production/shared/components/GenericLink/index.js.map +1 -1
  48. package/build/production/shared/components/Input/index.js.map +1 -1
  49. package/build/production/shared/components/Link.js.map +1 -1
  50. package/build/production/shared/components/MetaTags.js.map +1 -1
  51. package/build/production/shared/components/Modal/index.js.map +1 -1
  52. package/build/production/shared/components/NavLink.js.map +1 -1
  53. package/build/production/shared/components/PageLayout/index.js.map +1 -1
  54. package/build/production/shared/components/ScalableRect/index.js.map +1 -1
  55. package/build/production/shared/components/Throbber/index.js.map +1 -1
  56. package/build/production/shared/components/WithTooltip/Tooltip.js.map +1 -1
  57. package/build/production/shared/components/WithTooltip/index.js.map +1 -1
  58. package/build/production/shared/components/YouTubeVideo/index.js.map +1 -1
  59. package/build/production/shared/utils/config.js.map +1 -1
  60. package/build/production/shared/utils/index.js.map +1 -1
  61. package/build/production/shared/utils/isomorphy/index.js.map +1 -1
  62. package/build/production/shared/utils/jest/E2eSsrEnv.js +1 -1
  63. package/build/production/shared/utils/jest/E2eSsrEnv.js.map +1 -1
  64. package/build/production/shared/utils/jest/index.js.map +1 -1
  65. package/build/production/shared/utils/splitComponent.js.map +1 -1
  66. package/build/production/shared/utils/time.js.map +1 -1
  67. package/build/production/web.bundle.js +1 -1
  68. package/build/production/web.bundle.js.map +1 -1
  69. package/config/webpack/lib-base.js +2 -0
  70. package/package.json +31 -31
@@ -1 +1 @@
1
- {"version":3,"file":"time.js","names":["_cookie","_interopRequireDefault","require","_dayjs","_lodash","_react","_jsUtils","_reactGlobalState","useCurrent","autorefresh","globalStatePath","precision","dayjs","SEC_MS","now","setter","useGlobalState","Date","useEffect","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","getSsrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","Cookie","serialize","path","assign","DAY_MS","HOUR_MS","MIN_MS","YEAR_MS","timer","_default","exports","default"],"sources":["../../../../src/shared/utils/time.js"],"sourcesContent":["/* global document */\n\nimport Cookie from 'cookie';\nimport dayjs from 'dayjs';\nimport { assign } from 'lodash';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { getSsrContext, useGlobalState } from '@dr.pogodin/react-global-state';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n * @param {object} [options] Optional settings.\n * @param {string} [options.globalStatePath=\"currentTime\"] Global state path\n * to keep the current time value.\n * @param {number} [options.precision= 5 * time.SEC_MS] Current time precision.\n * The hook won't update the current time stored in the global state unless it\n * is different from Date.now() result by this number (in milliseconds).\n * Default to 5 seconds.\n * @param {boolean} [options.autorefresh=false] Set `true` to automatically\n * refresh time stored in the global state with the given `precision` (and\n * thus automatically re-rendering components dependent on this hook, or\n * the global state with the period equal to the `precision`.\n * @return {number} Unix timestamp in milliseconds.\n */\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * dayjs.SEC_MS,\n} = {}) {\n const [now, setter] = useGlobalState(globalStatePath, Date.now);\n useEffect(() => {\n let timerId;\n const update = () => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return () => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n *\n * @param {object} [options] Optional settings.\n * @param {string} [options.cookieName=\"timezoneOffset\"] Optional. The name of\n * cookie to use to store the timezone offset. Defaults \"timezoneOffset\". Set\n * to a falsy value to forbid using cookies altogether (in that case the hook\n * will always return zero value at the server-side, and in the first render\n * at the client-side).\n * @param {string} [options.timezoneOffset=\"timezoneOffset\"] Optional.\n * The global state path to store the offset. Defaults \"timezoneOffset\".\n * @return {number} Timezone offset.\n */\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}) {\n const ssrContext = getSsrContext(false);\n const [offset, setOffset] = useGlobalState(globalStatePath, () => {\n const value = cookieName && ssrContext?.req?.cookies?.[cookieName];\n return value ? parseInt(value, 10) : 0;\n });\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = Cookie.serialize(cookieName, value, { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nassign(dayjs, {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n});\n\nexport default dayjs;\n"],"mappings":";;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,I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E;EACN,MAAMmB,UAAU,GAAG,IAAAC,+BAAa,EAAC,KAAK,CAAC;EACvC,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAG,IAAAhB,gCAAc,EAACN,eAAe,EAAE,MAAM;IAChE,MAAMuB,KAAK,GAAGL,UAAU,IAAIC,UAAU,EAAEK,GAAG,EAAEC,OAAO,GAAGP,UAAU,CAAC;IAClE,OAAOK,KAAK,GAAGG,QAAQ,CAACH,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC;EACxC,CAAC,CAAC;EACF,IAAAf,gBAAS,EAAC,MAAM;IACd,MAAMmB,IAAI,GAAG,IAAIpB,IAAI,EAAE;IACvB,MAAMgB,KAAK,GAAGI,IAAI,CAACC,iBAAiB,EAAE;IACtCN,SAAS,CAACC,KAAK,CAAC;IAChB,IAAIL,UAAU,EAAE;MACdW,QAAQ,CAACC,MAAM,GAAGC,eAAM,CAACC,SAAS,CAACd,UAAU,EAAEK,KAAK,EAAE;QAAEU,IAAI,EAAE;MAAI,CAAC,CAAC;IACtE;EACF,CAAC,EAAE,CAACf,UAAU,EAAEI,SAAS,CAAC,CAAC;EAC3B,OAAOD,MAAM;AACf;AAEA,IAAAa,cAAM,EAAChC,cAAK,EAAE;EACZiC,MAAM,EAANA,eAAM;EACNC,OAAO,EAAPA,gBAAO;EACPC,MAAM,EAANA,eAAM;EACNlC,MAAM,EAANA,eAAM;EACNmC,OAAO,EAAPA,gBAAO;EACPlC,GAAG,EAAEG,IAAI,CAACH,GAAG;EACbmC,KAAK,EAALA,cAAK;EACLzC,UAAU;EACVmB;AACF,CAAC,CAAC;AAAC,IAAAuB,QAAA,GAEYtC,cAAK;AAAAuC,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"file":"time.js","names":["_cookie","_interopRequireDefault","require","_dayjs","_lodash","_react","_jsUtils","_reactGlobalState","useCurrent","autorefresh","globalStatePath","precision","dayjs","SEC_MS","now","setter","useGlobalState","Date","useEffect","timerId","update","old","neu","Math","abs","setTimeout","clearTimeout","useTimezoneOffset","cookieName","ssrContext","getSsrContext","offset","setOffset","value","req","cookies","parseInt","date","getTimezoneOffset","document","cookie","Cookie","serialize","path","assign","DAY_MS","HOUR_MS","MIN_MS","YEAR_MS","timer","_default","exports","default"],"sources":["../../../../src/shared/utils/time.js"],"sourcesContent":["/* global document */\n\nimport Cookie from 'cookie';\nimport dayjs from 'dayjs';\nimport { assign } from 'lodash';\nimport { useEffect } from 'react';\n\nimport {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n timer,\n} from '@dr.pogodin/js-utils';\n\nimport { getSsrContext, useGlobalState } from '@dr.pogodin/react-global-state';\n\n/**\n * This react hook wraps Date.now() function in a SSR friendly way,\n * ensuring that all calls to useCurrent() within the same render return\n * exactly the same time (which is retrieved from Date.now() first, and\n * then stored in the global state to be reused in all other calls), which\n * is also passed and used in the first client side render, and then updated\n * with a finite precision to avoid infinite re-rendering loops.\n * @param {object} [options] Optional settings.\n * @param {string} [options.globalStatePath=\"currentTime\"] Global state path\n * to keep the current time value.\n * @param {number} [options.precision= 5 * time.SEC_MS] Current time precision.\n * The hook won't update the current time stored in the global state unless it\n * is different from Date.now() result by this number (in milliseconds).\n * Default to 5 seconds.\n * @param {boolean} [options.autorefresh=false] Set `true` to automatically\n * refresh time stored in the global state with the given `precision` (and\n * thus automatically re-rendering components dependent on this hook, or\n * the global state with the period equal to the `precision`.\n * @return {number} Unix timestamp in milliseconds.\n */\nexport function useCurrent({\n autorefresh = false,\n globalStatePath = 'currentTime',\n precision = 5 * dayjs.SEC_MS,\n} = {}) {\n const [now, setter] = useGlobalState(globalStatePath, Date.now);\n useEffect(() => {\n let timerId;\n const update = () => {\n setter((old) => {\n const neu = Date.now();\n return Math.abs(neu - old) > precision ? neu : old;\n });\n if (autorefresh) timerId = setTimeout(update, precision);\n };\n update();\n return () => {\n if (timerId) clearTimeout(timerId);\n };\n }, [autorefresh, precision, setter]);\n return now;\n}\n\n/**\n * Wraps the standard Date.getTimezoneOffset() method in a SSR-friendly way.\n * This hook retrieves the offset value at the client side and uses a cookie\n * to pass it to the server in subsequent requests from that user. At the server\n * side the value from cookie is used in renders and passed back to the client\n * via the global state. Prior to the value being known (in the very first\n * request from the user, when the cookie is still missing), zero value is used\n * as the default value.\n *\n * @param {object} [options] Optional settings.\n * @param {string} [options.cookieName=\"timezoneOffset\"] Optional. The name of\n * cookie to use to store the timezone offset. Defaults \"timezoneOffset\". Set\n * to a falsy value to forbid using cookies altogether (in that case the hook\n * will always return zero value at the server-side, and in the first render\n * at the client-side).\n * @param {string} [options.timezoneOffset=\"timezoneOffset\"] Optional.\n * The global state path to store the offset. Defaults \"timezoneOffset\".\n * @return {number} Timezone offset.\n */\nexport function useTimezoneOffset({\n cookieName = 'timezoneOffset',\n globalStatePath = 'timezoneOffset',\n} = {}) {\n const ssrContext = getSsrContext(false);\n const [offset, setOffset] = useGlobalState(globalStatePath, () => {\n const value = cookieName && ssrContext?.req?.cookies?.[cookieName];\n return value ? parseInt(value, 10) : 0;\n });\n useEffect(() => {\n const date = new Date();\n const value = date.getTimezoneOffset();\n setOffset(value);\n if (cookieName) {\n document.cookie = Cookie.serialize(cookieName, value, { path: '/' });\n }\n }, [cookieName, setOffset]);\n return offset;\n}\n\nassign(dayjs, {\n DAY_MS,\n HOUR_MS,\n MIN_MS,\n SEC_MS,\n YEAR_MS,\n now: Date.now,\n timer,\n useCurrent,\n useTimezoneOffset,\n});\n\nexport default dayjs;\n"],"mappings":";;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,QAAA,GAAAJ,OAAA;AASA,IAAAK,iBAAA,GAAAL,OAAA;AAhBA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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