@recode-js/next-toolkit 0.0.1

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 (266) hide show
  1. package/README.md +27 -0
  2. package/dist/NextToolkitProvider.d.ts +8 -0
  3. package/dist/NextToolkitProvider.d.ts.map +1 -0
  4. package/dist/NextToolkitProvider.js +12 -0
  5. package/dist/NextToolkitProvider.js.map +1 -0
  6. package/dist/_virtual/_commonjsHelpers.js +6 -0
  7. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  8. package/dist/_virtual/browser.js +4 -0
  9. package/dist/_virtual/browser.js.map +1 -0
  10. package/dist/_virtual/index.js +4 -0
  11. package/dist/_virtual/index.js.map +1 -0
  12. package/dist/_virtual/index2.js +4 -0
  13. package/dist/_virtual/index2.js.map +1 -0
  14. package/dist/_virtual/index3.js +4 -0
  15. package/dist/_virtual/index3.js.map +1 -0
  16. package/dist/_virtual/node.js +4 -0
  17. package/dist/_virtual/node.js.map +1 -0
  18. package/dist/_virtual/use-sync-external-store-with-selector.development.js +4 -0
  19. package/dist/_virtual/use-sync-external-store-with-selector.development.js.map +1 -0
  20. package/dist/_virtual/use-sync-external-store-with-selector.production.js +4 -0
  21. package/dist/_virtual/use-sync-external-store-with-selector.production.js.map +1 -0
  22. package/dist/_virtual/with-selector.js +4 -0
  23. package/dist/_virtual/with-selector.js.map +1 -0
  24. package/dist/axios/api.d.ts +16 -0
  25. package/dist/axios/api.d.ts.map +1 -0
  26. package/dist/axios/api.js +11 -0
  27. package/dist/axios/api.js.map +1 -0
  28. package/dist/components/auth/Form.d.ts +10 -0
  29. package/dist/components/auth/Form.d.ts.map +1 -0
  30. package/dist/components/auth/Form.js +49 -0
  31. package/dist/components/auth/Form.js.map +1 -0
  32. package/dist/components/auth/auth.d.ts +8 -0
  33. package/dist/components/auth/auth.d.ts.map +1 -0
  34. package/dist/components/auth/auth.js +18 -0
  35. package/dist/components/auth/auth.js.map +1 -0
  36. package/dist/components/auth/formActions.d.ts +17 -0
  37. package/dist/components/auth/formActions.d.ts.map +1 -0
  38. package/dist/components/auth/formActions.js +58 -0
  39. package/dist/components/auth/formActions.js.map +1 -0
  40. package/dist/components/auth/login/LoginPage.d.ts +7 -0
  41. package/dist/components/auth/login/LoginPage.d.ts.map +1 -0
  42. package/dist/components/auth/login/LoginPage.js +18 -0
  43. package/dist/components/auth/login/LoginPage.js.map +1 -0
  44. package/dist/components/auth/login/login.d.ts +1 -0
  45. package/dist/components/auth/login/login.d.ts.map +1 -0
  46. package/dist/components/auth/register/RegisterPage.d.ts +7 -0
  47. package/dist/components/auth/register/RegisterPage.d.ts.map +1 -0
  48. package/dist/components/auth/register/RegisterPage.js +18 -0
  49. package/dist/components/auth/register/RegisterPage.js.map +1 -0
  50. package/dist/components/auth/register/register.d.ts +1 -0
  51. package/dist/components/auth/register/register.d.ts.map +1 -0
  52. package/dist/components/auth/styles/form.module.css.js +4 -0
  53. package/dist/components/auth/styles/form.module.css.js.map +1 -0
  54. package/dist/components/common/Button.d.ts +25 -0
  55. package/dist/components/common/Button.d.ts.map +1 -0
  56. package/dist/components/common/Button.js +25 -0
  57. package/dist/components/common/Button.js.map +1 -0
  58. package/dist/components/common/styles/button.module.css.js +4 -0
  59. package/dist/components/common/styles/button.module.css.js.map +1 -0
  60. package/dist/components/navigation/NavigatorProvider.d.ts +10 -0
  61. package/dist/components/navigation/NavigatorProvider.d.ts.map +1 -0
  62. package/dist/components/navigation/NavigatorProvider.js +15 -0
  63. package/dist/components/navigation/NavigatorProvider.js.map +1 -0
  64. package/dist/components/navigation/bottom-tab/BottomTab.d.ts +12 -0
  65. package/dist/components/navigation/bottom-tab/BottomTab.d.ts.map +1 -0
  66. package/dist/components/navigation/bottom-tab/BottomTab.js +45 -0
  67. package/dist/components/navigation/bottom-tab/BottomTab.js.map +1 -0
  68. package/dist/components/navigation/bottom-tab/bottom-tab.module.css.js +4 -0
  69. package/dist/components/navigation/bottom-tab/bottom-tab.module.css.js.map +1 -0
  70. package/dist/components/navigation/drawer/Drawer.d.ts +21 -0
  71. package/dist/components/navigation/drawer/Drawer.d.ts.map +1 -0
  72. package/dist/components/navigation/drawer/Drawer.js +91 -0
  73. package/dist/components/navigation/drawer/Drawer.js.map +1 -0
  74. package/dist/components/navigation/drawer/drawer.module.css.js +4 -0
  75. package/dist/components/navigation/drawer/drawer.module.css.js.map +1 -0
  76. package/dist/components/navigation/header/Header.d.ts +7 -0
  77. package/dist/components/navigation/header/Header.d.ts.map +1 -0
  78. package/dist/components/navigation/header/Header.js +32 -0
  79. package/dist/components/navigation/header/Header.js.map +1 -0
  80. package/dist/components/navigation/header/header.module.css.js +4 -0
  81. package/dist/components/navigation/header/header.module.css.js.map +1 -0
  82. package/dist/components/navigation/navigatior-provider.module.css.js +4 -0
  83. package/dist/components/navigation/navigatior-provider.module.css.js.map +1 -0
  84. package/dist/components/toast/Toast.d.ts +9 -0
  85. package/dist/components/toast/Toast.d.ts.map +1 -0
  86. package/dist/components/toast/Toast.js +92 -0
  87. package/dist/components/toast/Toast.js.map +1 -0
  88. package/dist/components/toast/ToastExamples.d.ts +2 -0
  89. package/dist/components/toast/ToastExamples.d.ts.map +1 -0
  90. package/dist/components/toast/ToastExamples.js +74 -0
  91. package/dist/components/toast/ToastExamples.js.map +1 -0
  92. package/dist/components/toast/toast.module.css.js +4 -0
  93. package/dist/components/toast/toast.module.css.js.map +1 -0
  94. package/dist/index.d.ts +11 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +9 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.js +969 -0
  99. package/dist/node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.js.map +1 -0
  100. package/dist/node_modules/axios/index.js +26 -0
  101. package/dist/node_modules/axios/index.js.map +1 -0
  102. package/dist/node_modules/axios/lib/adapters/adapters.js +129 -0
  103. package/dist/node_modules/axios/lib/adapters/adapters.js.map +1 -0
  104. package/dist/node_modules/axios/lib/adapters/fetch.js +289 -0
  105. package/dist/node_modules/axios/lib/adapters/fetch.js.map +1 -0
  106. package/dist/node_modules/axios/lib/adapters/http.js +895 -0
  107. package/dist/node_modules/axios/lib/adapters/http.js.map +1 -0
  108. package/dist/node_modules/axios/lib/adapters/xhr.js +203 -0
  109. package/dist/node_modules/axios/lib/adapters/xhr.js.map +1 -0
  110. package/dist/node_modules/axios/lib/axios.js +88 -0
  111. package/dist/node_modules/axios/lib/axios.js.map +1 -0
  112. package/dist/node_modules/axios/lib/cancel/CancelToken.js +135 -0
  113. package/dist/node_modules/axios/lib/cancel/CancelToken.js.map +1 -0
  114. package/dist/node_modules/axios/lib/cancel/CanceledError.js +25 -0
  115. package/dist/node_modules/axios/lib/cancel/CanceledError.js.map +1 -0
  116. package/dist/node_modules/axios/lib/cancel/isCancel.js +7 -0
  117. package/dist/node_modules/axios/lib/cancel/isCancel.js.map +1 -0
  118. package/dist/node_modules/axios/lib/core/Axios.js +238 -0
  119. package/dist/node_modules/axios/lib/core/Axios.js.map +1 -0
  120. package/dist/node_modules/axios/lib/core/AxiosError.js +110 -0
  121. package/dist/node_modules/axios/lib/core/AxiosError.js.map +1 -0
  122. package/dist/node_modules/axios/lib/core/AxiosHeaders.js +314 -0
  123. package/dist/node_modules/axios/lib/core/AxiosHeaders.js.map +1 -0
  124. package/dist/node_modules/axios/lib/core/InterceptorManager.js +71 -0
  125. package/dist/node_modules/axios/lib/core/InterceptorManager.js.map +1 -0
  126. package/dist/node_modules/axios/lib/core/buildFullPath.js +24 -0
  127. package/dist/node_modules/axios/lib/core/buildFullPath.js.map +1 -0
  128. package/dist/node_modules/axios/lib/core/dispatchRequest.js +83 -0
  129. package/dist/node_modules/axios/lib/core/dispatchRequest.js.map +1 -0
  130. package/dist/node_modules/axios/lib/core/mergeConfig.js +108 -0
  131. package/dist/node_modules/axios/lib/core/mergeConfig.js.map +1 -0
  132. package/dist/node_modules/axios/lib/core/settle.js +29 -0
  133. package/dist/node_modules/axios/lib/core/settle.js.map +1 -0
  134. package/dist/node_modules/axios/lib/core/transformData.js +30 -0
  135. package/dist/node_modules/axios/lib/core/transformData.js.map +1 -0
  136. package/dist/node_modules/axios/lib/defaults/index.js +161 -0
  137. package/dist/node_modules/axios/lib/defaults/index.js.map +1 -0
  138. package/dist/node_modules/axios/lib/defaults/transitional.js +9 -0
  139. package/dist/node_modules/axios/lib/defaults/transitional.js.map +1 -0
  140. package/dist/node_modules/axios/lib/env/data.js +4 -0
  141. package/dist/node_modules/axios/lib/env/data.js.map +1 -0
  142. package/dist/node_modules/axios/lib/helpers/AxiosTransformStream.js +143 -0
  143. package/dist/node_modules/axios/lib/helpers/AxiosTransformStream.js.map +1 -0
  144. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +58 -0
  145. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js.map +1 -0
  146. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +78 -0
  147. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js.map +1 -0
  148. package/dist/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  149. package/dist/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js.map +1 -0
  150. package/dist/node_modules/axios/lib/helpers/bind.js +16 -0
  151. package/dist/node_modules/axios/lib/helpers/bind.js.map +1 -0
  152. package/dist/node_modules/axios/lib/helpers/buildURL.js +69 -0
  153. package/dist/node_modules/axios/lib/helpers/buildURL.js.map +1 -0
  154. package/dist/node_modules/axios/lib/helpers/callbackify.js +17 -0
  155. package/dist/node_modules/axios/lib/helpers/callbackify.js.map +1 -0
  156. package/dist/node_modules/axios/lib/helpers/combineURLs.js +17 -0
  157. package/dist/node_modules/axios/lib/helpers/combineURLs.js.map +1 -0
  158. package/dist/node_modules/axios/lib/helpers/composeSignals.js +49 -0
  159. package/dist/node_modules/axios/lib/helpers/composeSignals.js.map +1 -0
  160. package/dist/node_modules/axios/lib/helpers/cookies.js +55 -0
  161. package/dist/node_modules/axios/lib/helpers/cookies.js.map +1 -0
  162. package/dist/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +76 -0
  163. package/dist/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js.map +1 -0
  164. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +95 -0
  165. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js.map +1 -0
  166. package/dist/node_modules/axios/lib/helpers/formDataToStream.js +113 -0
  167. package/dist/node_modules/axios/lib/helpers/formDataToStream.js.map +1 -0
  168. package/dist/node_modules/axios/lib/helpers/fromDataURI.js +55 -0
  169. package/dist/node_modules/axios/lib/helpers/fromDataURI.js.map +1 -0
  170. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +17 -0
  171. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js.map +1 -0
  172. package/dist/node_modules/axios/lib/helpers/isAxiosError.js +16 -0
  173. package/dist/node_modules/axios/lib/helpers/isAxiosError.js.map +1 -0
  174. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +17 -0
  175. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js.map +1 -0
  176. package/dist/node_modules/axios/lib/helpers/parseHeaders.js +57 -0
  177. package/dist/node_modules/axios/lib/helpers/parseHeaders.js.map +1 -0
  178. package/dist/node_modules/axios/lib/helpers/parseProtocol.js +8 -0
  179. package/dist/node_modules/axios/lib/helpers/parseProtocol.js.map +1 -0
  180. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +47 -0
  181. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js.map +1 -0
  182. package/dist/node_modules/axios/lib/helpers/readBlob.js +16 -0
  183. package/dist/node_modules/axios/lib/helpers/readBlob.js.map +1 -0
  184. package/dist/node_modules/axios/lib/helpers/resolveConfig.js +63 -0
  185. package/dist/node_modules/axios/lib/helpers/resolveConfig.js.map +1 -0
  186. package/dist/node_modules/axios/lib/helpers/speedometer.js +55 -0
  187. package/dist/node_modules/axios/lib/helpers/speedometer.js.map +1 -0
  188. package/dist/node_modules/axios/lib/helpers/spread.js +30 -0
  189. package/dist/node_modules/axios/lib/helpers/spread.js.map +1 -0
  190. package/dist/node_modules/axios/lib/helpers/throttle.js +45 -0
  191. package/dist/node_modules/axios/lib/helpers/throttle.js.map +1 -0
  192. package/dist/node_modules/axios/lib/helpers/toFormData.js +222 -0
  193. package/dist/node_modules/axios/lib/helpers/toFormData.js.map +1 -0
  194. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +21 -0
  195. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js.map +1 -0
  196. package/dist/node_modules/axios/lib/helpers/trackStream.js +89 -0
  197. package/dist/node_modules/axios/lib/helpers/trackStream.js.map +1 -0
  198. package/dist/node_modules/axios/lib/helpers/validator.js +101 -0
  199. package/dist/node_modules/axios/lib/helpers/validator.js.map +1 -0
  200. package/dist/node_modules/axios/lib/platform/common/utils.js +46 -0
  201. package/dist/node_modules/axios/lib/platform/common/utils.js.map +1 -0
  202. package/dist/node_modules/axios/lib/platform/index.js +10 -0
  203. package/dist/node_modules/axios/lib/platform/index.js.map +1 -0
  204. package/dist/node_modules/axios/lib/platform/node/classes/FormData.js +3 -0
  205. package/dist/node_modules/axios/lib/platform/node/classes/FormData.js.map +1 -0
  206. package/dist/node_modules/axios/lib/platform/node/classes/URLSearchParams.js +7 -0
  207. package/dist/node_modules/axios/lib/platform/node/classes/URLSearchParams.js.map +1 -0
  208. package/dist/node_modules/axios/lib/platform/node/index.js +41 -0
  209. package/dist/node_modules/axios/lib/platform/node/index.js.map +1 -0
  210. package/dist/node_modules/axios/lib/utils.js +784 -0
  211. package/dist/node_modules/axios/lib/utils.js.map +1 -0
  212. package/dist/node_modules/debug/src/browser.js +287 -0
  213. package/dist/node_modules/debug/src/browser.js.map +1 -0
  214. package/dist/node_modules/debug/src/common.js +304 -0
  215. package/dist/node_modules/debug/src/common.js.map +1 -0
  216. package/dist/node_modules/debug/src/index.js +24 -0
  217. package/dist/node_modules/debug/src/index.js.map +1 -0
  218. package/dist/node_modules/debug/src/node.js +280 -0
  219. package/dist/node_modules/debug/src/node.js.map +1 -0
  220. package/dist/node_modules/follow-redirects/debug.js +20 -0
  221. package/dist/node_modules/follow-redirects/debug.js.map +1 -0
  222. package/dist/node_modules/follow-redirects/index.js +701 -0
  223. package/dist/node_modules/follow-redirects/index.js.map +1 -0
  224. package/dist/node_modules/immer/dist/immer.js +860 -0
  225. package/dist/node_modules/immer/dist/immer.js.map +1 -0
  226. package/dist/node_modules/proxy-from-env/index.js +112 -0
  227. package/dist/node_modules/proxy-from-env/index.js.map +1 -0
  228. package/dist/node_modules/react-redux/dist/react-redux.js +348 -0
  229. package/dist/node_modules/react-redux/dist/react-redux.js.map +1 -0
  230. package/dist/node_modules/redux/dist/redux.js +362 -0
  231. package/dist/node_modules/redux/dist/redux.js.map +1 -0
  232. package/dist/node_modules/redux-thunk/dist/redux-thunk.js +15 -0
  233. package/dist/node_modules/redux-thunk/dist/redux-thunk.js.map +1 -0
  234. package/dist/node_modules/reselect/dist/reselect.js +322 -0
  235. package/dist/node_modules/reselect/dist/reselect.js.map +1 -0
  236. package/dist/node_modules/server-only/index.js +5 -0
  237. package/dist/node_modules/server-only/index.js.map +1 -0
  238. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +108 -0
  239. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js.map +1 -0
  240. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +96 -0
  241. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js.map +1 -0
  242. package/dist/node_modules/use-sync-external-store/with-selector.js +14 -0
  243. package/dist/node_modules/use-sync-external-store/with-selector.js.map +1 -0
  244. package/dist/store/StoreProvider.d.ts +7 -0
  245. package/dist/store/StoreProvider.d.ts.map +1 -0
  246. package/dist/store/StoreProvider.js +11 -0
  247. package/dist/store/StoreProvider.js.map +1 -0
  248. package/dist/store/features/drawer/drawer.slice.d.ts +12 -0
  249. package/dist/store/features/drawer/drawer.slice.d.ts.map +1 -0
  250. package/dist/store/features/drawer/drawer.slice.js +26 -0
  251. package/dist/store/features/drawer/drawer.slice.js.map +1 -0
  252. package/dist/store/features/toast/toastSlice.d.ts +16 -0
  253. package/dist/store/features/toast/toastSlice.d.ts.map +1 -0
  254. package/dist/store/features/toast/toastSlice.js +26 -0
  255. package/dist/store/features/toast/toastSlice.js.map +1 -0
  256. package/dist/store/hooks.d.ts +10 -0
  257. package/dist/store/hooks.d.ts.map +1 -0
  258. package/dist/store/hooks.js +8 -0
  259. package/dist/store/hooks.js.map +1 -0
  260. package/dist/store/store.d.ts +16 -0
  261. package/dist/store/store.d.ts.map +1 -0
  262. package/dist/store/store.js +13 -0
  263. package/dist/store/store.js.map +1 -0
  264. package/dist/styles.css +2 -0
  265. package/dist/styles.css.map +1 -0
  266. package/package.json +57 -0
@@ -0,0 +1,860 @@
1
+ // src/utils/env.ts
2
+ var NOTHING = Symbol.for("immer-nothing");
3
+ var DRAFTABLE = Symbol.for("immer-draftable");
4
+ var DRAFT_STATE = Symbol.for("immer-state");
5
+
6
+ // src/utils/errors.ts
7
+ var errors = process.env.NODE_ENV !== "production" ? [
8
+ // All error codes, starting by 0:
9
+ function(plugin) {
10
+ return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
11
+ },
12
+ function(thing) {
13
+ return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
14
+ },
15
+ "This object has been frozen and should not be mutated",
16
+ function(data) {
17
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
18
+ },
19
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
20
+ "Immer forbids circular references",
21
+ "The first or second argument to `produce` must be a function",
22
+ "The third argument to `produce` must be a function or undefined",
23
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
24
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
25
+ function(thing) {
26
+ return `'current' expects a draft, got: ${thing}`;
27
+ },
28
+ "Object.defineProperty() cannot be used on an Immer draft",
29
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
30
+ "Immer only supports deleting array indices",
31
+ "Immer only supports setting array indices and the 'length' property",
32
+ function(thing) {
33
+ return `'original' expects a draft, got: ${thing}`;
34
+ }
35
+ // Note: if more errors are added, the errorOffset in Patches.ts should be increased
36
+ // See Patches.ts for additional errors
37
+ ] : [];
38
+ function die(error, ...args) {
39
+ if (process.env.NODE_ENV !== "production") {
40
+ const e = errors[error];
41
+ const msg = isFunction(e) ? e.apply(null, args) : e;
42
+ throw new Error(`[Immer] ${msg}`);
43
+ }
44
+ throw new Error(
45
+ `[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
46
+ );
47
+ }
48
+
49
+ // src/utils/common.ts
50
+ var O = Object;
51
+ var getPrototypeOf = O.getPrototypeOf;
52
+ var CONSTRUCTOR = "constructor";
53
+ var PROTOTYPE = "prototype";
54
+ var CONFIGURABLE = "configurable";
55
+ var ENUMERABLE = "enumerable";
56
+ var WRITABLE = "writable";
57
+ var VALUE = "value";
58
+ var isDraft = (value) => !!value && !!value[DRAFT_STATE];
59
+ function isDraftable(value) {
60
+ if (!value)
61
+ return false;
62
+ return isPlainObject(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);
63
+ }
64
+ var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();
65
+ var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
66
+ function isPlainObject(value) {
67
+ if (!value || !isObjectish(value))
68
+ return false;
69
+ const proto = getPrototypeOf(value);
70
+ if (proto === null || proto === O[PROTOTYPE])
71
+ return true;
72
+ const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];
73
+ if (Ctor === Object)
74
+ return true;
75
+ if (!isFunction(Ctor))
76
+ return false;
77
+ let ctorString = cachedCtorStrings.get(Ctor);
78
+ if (ctorString === void 0) {
79
+ ctorString = Function.toString.call(Ctor);
80
+ cachedCtorStrings.set(Ctor, ctorString);
81
+ }
82
+ return ctorString === objectCtorString;
83
+ }
84
+ function each(obj, iter, strict = true) {
85
+ if (getArchtype(obj) === 0 /* Object */) {
86
+ const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);
87
+ keys.forEach((key) => {
88
+ iter(key, obj[key], obj);
89
+ });
90
+ } else {
91
+ obj.forEach((entry, index) => iter(index, entry, obj));
92
+ }
93
+ }
94
+ function getArchtype(thing) {
95
+ const state = thing[DRAFT_STATE];
96
+ return state ? state.type_ : isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
97
+ }
98
+ var has = (thing, prop, type = getArchtype(thing)) => type === 2 /* Map */ ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);
99
+ var get = (thing, prop, type = getArchtype(thing)) => (
100
+ // @ts-ignore
101
+ type === 2 /* Map */ ? thing.get(prop) : thing[prop]
102
+ );
103
+ var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {
104
+ if (type === 2 /* Map */)
105
+ thing.set(propOrOldValue, value);
106
+ else if (type === 3 /* Set */) {
107
+ thing.add(value);
108
+ } else
109
+ thing[propOrOldValue] = value;
110
+ };
111
+ function is(x, y) {
112
+ if (x === y) {
113
+ return x !== 0 || 1 / x === 1 / y;
114
+ } else {
115
+ return x !== x && y !== y;
116
+ }
117
+ }
118
+ var isArray = Array.isArray;
119
+ var isMap = (target) => target instanceof Map;
120
+ var isSet = (target) => target instanceof Set;
121
+ var isObjectish = (target) => typeof target === "object";
122
+ var isFunction = (target) => typeof target === "function";
123
+ var isBoolean = (target) => typeof target === "boolean";
124
+ function isArrayIndex(value) {
125
+ const n = +value;
126
+ return Number.isInteger(n) && String(n) === value;
127
+ }
128
+ var latest = (state) => state.copy_ || state.base_;
129
+ var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
130
+ function shallowCopy(base, strict) {
131
+ if (isMap(base)) {
132
+ return new Map(base);
133
+ }
134
+ if (isSet(base)) {
135
+ return new Set(base);
136
+ }
137
+ if (isArray(base))
138
+ return Array[PROTOTYPE].slice.call(base);
139
+ const isPlain = isPlainObject(base);
140
+ if (strict === true || strict === "class_only" && !isPlain) {
141
+ const descriptors = O.getOwnPropertyDescriptors(base);
142
+ delete descriptors[DRAFT_STATE];
143
+ let keys = Reflect.ownKeys(descriptors);
144
+ for (let i = 0; i < keys.length; i++) {
145
+ const key = keys[i];
146
+ const desc = descriptors[key];
147
+ if (desc[WRITABLE] === false) {
148
+ desc[WRITABLE] = true;
149
+ desc[CONFIGURABLE] = true;
150
+ }
151
+ if (desc.get || desc.set)
152
+ descriptors[key] = {
153
+ [CONFIGURABLE]: true,
154
+ [WRITABLE]: true,
155
+ // could live with !!desc.set as well here...
156
+ [ENUMERABLE]: desc[ENUMERABLE],
157
+ [VALUE]: base[key]
158
+ };
159
+ }
160
+ return O.create(getPrototypeOf(base), descriptors);
161
+ } else {
162
+ const proto = getPrototypeOf(base);
163
+ if (proto !== null && isPlain) {
164
+ return { ...base };
165
+ }
166
+ const obj = O.create(proto);
167
+ return O.assign(obj, base);
168
+ }
169
+ }
170
+ function freeze(obj, deep = false) {
171
+ if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
172
+ return obj;
173
+ if (getArchtype(obj) > 1) {
174
+ O.defineProperties(obj, {
175
+ set: dontMutateMethodOverride,
176
+ add: dontMutateMethodOverride,
177
+ clear: dontMutateMethodOverride,
178
+ delete: dontMutateMethodOverride
179
+ });
180
+ }
181
+ O.freeze(obj);
182
+ if (deep)
183
+ each(
184
+ obj,
185
+ (_key, value) => {
186
+ freeze(value, true);
187
+ },
188
+ false
189
+ );
190
+ return obj;
191
+ }
192
+ function dontMutateFrozenCollections() {
193
+ die(2);
194
+ }
195
+ var dontMutateMethodOverride = {
196
+ [VALUE]: dontMutateFrozenCollections
197
+ };
198
+ function isFrozen(obj) {
199
+ if (obj === null || !isObjectish(obj))
200
+ return true;
201
+ return O.isFrozen(obj);
202
+ }
203
+
204
+ // src/utils/plugins.ts
205
+ var PluginMapSet = "MapSet";
206
+ var PluginPatches = "Patches";
207
+ var PluginArrayMethods = "ArrayMethods";
208
+ var plugins = {};
209
+ function getPlugin(pluginKey) {
210
+ const plugin = plugins[pluginKey];
211
+ if (!plugin) {
212
+ die(0, pluginKey);
213
+ }
214
+ return plugin;
215
+ }
216
+ var isPluginLoaded = (pluginKey) => !!plugins[pluginKey];
217
+
218
+ // src/core/scope.ts
219
+ var currentScope;
220
+ var getCurrentScope = () => currentScope;
221
+ var createScope = (parent_, immer_) => ({
222
+ drafts_: [],
223
+ parent_,
224
+ immer_,
225
+ // Whenever the modified draft contains a draft from another scope, we
226
+ // need to prevent auto-freezing so the unowned draft can be finalized.
227
+ canAutoFreeze_: true,
228
+ unfinalizedDrafts_: 0,
229
+ handledSet_: /* @__PURE__ */ new Set(),
230
+ processedForPatches_: /* @__PURE__ */ new Set(),
231
+ mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
232
+ arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
233
+ });
234
+ function usePatchesInScope(scope, patchListener) {
235
+ if (patchListener) {
236
+ scope.patchPlugin_ = getPlugin(PluginPatches);
237
+ scope.patches_ = [];
238
+ scope.inversePatches_ = [];
239
+ scope.patchListener_ = patchListener;
240
+ }
241
+ }
242
+ function revokeScope(scope) {
243
+ leaveScope(scope);
244
+ scope.drafts_.forEach(revokeDraft);
245
+ scope.drafts_ = null;
246
+ }
247
+ function leaveScope(scope) {
248
+ if (scope === currentScope) {
249
+ currentScope = scope.parent_;
250
+ }
251
+ }
252
+ var enterScope = (immer2) => currentScope = createScope(currentScope, immer2);
253
+ function revokeDraft(draft) {
254
+ const state = draft[DRAFT_STATE];
255
+ if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */)
256
+ state.revoke_();
257
+ else
258
+ state.revoked_ = true;
259
+ }
260
+
261
+ // src/core/finalize.ts
262
+ function processResult(result, scope) {
263
+ scope.unfinalizedDrafts_ = scope.drafts_.length;
264
+ const baseDraft = scope.drafts_[0];
265
+ const isReplaced = result !== void 0 && result !== baseDraft;
266
+ if (isReplaced) {
267
+ if (baseDraft[DRAFT_STATE].modified_) {
268
+ revokeScope(scope);
269
+ die(4);
270
+ }
271
+ if (isDraftable(result)) {
272
+ result = finalize(scope, result);
273
+ }
274
+ const { patchPlugin_ } = scope;
275
+ if (patchPlugin_) {
276
+ patchPlugin_.generateReplacementPatches_(
277
+ baseDraft[DRAFT_STATE].base_,
278
+ result,
279
+ scope
280
+ );
281
+ }
282
+ } else {
283
+ result = finalize(scope, baseDraft);
284
+ }
285
+ maybeFreeze(scope, result, true);
286
+ revokeScope(scope);
287
+ if (scope.patches_) {
288
+ scope.patchListener_(scope.patches_, scope.inversePatches_);
289
+ }
290
+ return result !== NOTHING ? result : void 0;
291
+ }
292
+ function finalize(rootScope, value) {
293
+ if (isFrozen(value))
294
+ return value;
295
+ const state = value[DRAFT_STATE];
296
+ if (!state) {
297
+ const finalValue = handleValue(value, rootScope.handledSet_, rootScope);
298
+ return finalValue;
299
+ }
300
+ if (!isSameScope(state, rootScope)) {
301
+ return value;
302
+ }
303
+ if (!state.modified_) {
304
+ return state.base_;
305
+ }
306
+ if (!state.finalized_) {
307
+ const { callbacks_ } = state;
308
+ if (callbacks_) {
309
+ while (callbacks_.length > 0) {
310
+ const callback = callbacks_.pop();
311
+ callback(rootScope);
312
+ }
313
+ }
314
+ generatePatchesAndFinalize(state, rootScope);
315
+ }
316
+ return state.copy_;
317
+ }
318
+ function maybeFreeze(scope, value, deep = false) {
319
+ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
320
+ freeze(value, deep);
321
+ }
322
+ }
323
+ function markStateFinalized(state) {
324
+ state.finalized_ = true;
325
+ state.scope_.unfinalizedDrafts_--;
326
+ }
327
+ var isSameScope = (state, rootScope) => state.scope_ === rootScope;
328
+ var EMPTY_LOCATIONS_RESULT = [];
329
+ function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {
330
+ const parentCopy = latest(parent);
331
+ const parentType = parent.type_;
332
+ if (originalKey !== void 0) {
333
+ const currentValue = get(parentCopy, originalKey, parentType);
334
+ if (currentValue === draftValue) {
335
+ set(parentCopy, originalKey, finalizedValue, parentType);
336
+ return;
337
+ }
338
+ }
339
+ if (!parent.draftLocations_) {
340
+ const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();
341
+ each(parentCopy, (key, value) => {
342
+ if (isDraft(value)) {
343
+ const keys = draftLocations.get(value) || [];
344
+ keys.push(key);
345
+ draftLocations.set(value, keys);
346
+ }
347
+ });
348
+ }
349
+ const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;
350
+ for (const location of locations) {
351
+ set(parentCopy, location, finalizedValue, parentType);
352
+ }
353
+ }
354
+ function registerChildFinalizationCallback(parent, child, key) {
355
+ parent.callbacks_.push(function childCleanup(rootScope) {
356
+ const state = child;
357
+ if (!state || !isSameScope(state, rootScope)) {
358
+ return;
359
+ }
360
+ rootScope.mapSetPlugin_?.fixSetContents(state);
361
+ const finalizedValue = getFinalValue(state);
362
+ updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);
363
+ generatePatchesAndFinalize(state, rootScope);
364
+ });
365
+ }
366
+ function generatePatchesAndFinalize(state, rootScope) {
367
+ const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || state.type_ === 1 /* Array */ && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);
368
+ if (shouldFinalize) {
369
+ const { patchPlugin_ } = rootScope;
370
+ if (patchPlugin_) {
371
+ const basePath = patchPlugin_.getPath(state);
372
+ if (basePath) {
373
+ patchPlugin_.generatePatches_(state, basePath, rootScope);
374
+ }
375
+ }
376
+ markStateFinalized(state);
377
+ }
378
+ }
379
+ function handleCrossReference(target, key, value) {
380
+ const { scope_ } = target;
381
+ if (isDraft(value)) {
382
+ const state = value[DRAFT_STATE];
383
+ if (isSameScope(state, scope_)) {
384
+ state.callbacks_.push(function crossReferenceCleanup() {
385
+ prepareCopy(target);
386
+ const finalizedValue = getFinalValue(state);
387
+ updateDraftInParent(target, value, finalizedValue, key);
388
+ });
389
+ }
390
+ } else if (isDraftable(value)) {
391
+ target.callbacks_.push(function nestedDraftCleanup() {
392
+ const targetCopy = latest(target);
393
+ if (target.type_ === 3 /* Set */) {
394
+ if (targetCopy.has(value)) {
395
+ handleValue(value, scope_.handledSet_, scope_);
396
+ }
397
+ } else {
398
+ if (get(targetCopy, key, target.type_) === value) {
399
+ if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
400
+ handleValue(
401
+ get(target.copy_, key, target.type_),
402
+ scope_.handledSet_,
403
+ scope_
404
+ );
405
+ }
406
+ }
407
+ }
408
+ });
409
+ }
410
+ }
411
+ function handleValue(target, handledSet, rootScope) {
412
+ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
413
+ return target;
414
+ }
415
+ if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {
416
+ return target;
417
+ }
418
+ handledSet.add(target);
419
+ each(target, (key, value) => {
420
+ if (isDraft(value)) {
421
+ const state = value[DRAFT_STATE];
422
+ if (isSameScope(state, rootScope)) {
423
+ const updatedValue = getFinalValue(state);
424
+ set(target, key, updatedValue, target.type_);
425
+ markStateFinalized(state);
426
+ }
427
+ } else if (isDraftable(value)) {
428
+ handleValue(value, handledSet, rootScope);
429
+ }
430
+ });
431
+ return target;
432
+ }
433
+
434
+ // src/core/proxy.ts
435
+ function createProxyProxy(base, parent) {
436
+ const baseIsArray = isArray(base);
437
+ const state = {
438
+ type_: baseIsArray ? 1 /* Array */ : 0 /* Object */,
439
+ // Track which produce call this is associated with.
440
+ scope_: parent ? parent.scope_ : getCurrentScope(),
441
+ // True for both shallow and deep changes.
442
+ modified_: false,
443
+ // Used during finalization.
444
+ finalized_: false,
445
+ // Track which properties have been assigned (true) or deleted (false).
446
+ // actually instantiated in `prepareCopy()`
447
+ assigned_: void 0,
448
+ // The parent draft state.
449
+ parent_: parent,
450
+ // The base state.
451
+ base_: base,
452
+ // The base proxy.
453
+ draft_: null,
454
+ // set below
455
+ // The base copy with any updated values.
456
+ copy_: null,
457
+ // Called by the `produce` function.
458
+ revoke_: null,
459
+ isManual_: false,
460
+ // `callbacks` actually gets assigned in `createProxy`
461
+ callbacks_: void 0
462
+ };
463
+ let target = state;
464
+ let traps = objectTraps;
465
+ if (baseIsArray) {
466
+ target = [state];
467
+ traps = arrayTraps;
468
+ }
469
+ const { revoke, proxy } = Proxy.revocable(target, traps);
470
+ state.draft_ = proxy;
471
+ state.revoke_ = revoke;
472
+ return [proxy, state];
473
+ }
474
+ var objectTraps = {
475
+ get(state, prop) {
476
+ if (prop === DRAFT_STATE)
477
+ return state;
478
+ let arrayPlugin = state.scope_.arrayMethodsPlugin_;
479
+ const isArrayWithStringProp = state.type_ === 1 /* Array */ && typeof prop === "string";
480
+ if (isArrayWithStringProp) {
481
+ if (arrayPlugin?.isArrayOperationMethod(prop)) {
482
+ return arrayPlugin.createMethodInterceptor(state, prop);
483
+ }
484
+ }
485
+ const source = latest(state);
486
+ if (!has(source, prop, state.type_)) {
487
+ return readPropFromProto(state, source, prop);
488
+ }
489
+ const value = source[prop];
490
+ if (state.finalized_ || !isDraftable(value)) {
491
+ return value;
492
+ }
493
+ if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(
494
+ state.operationMethod
495
+ ) && isArrayIndex(prop)) {
496
+ return value;
497
+ }
498
+ if (value === peek(state.base_, prop)) {
499
+ prepareCopy(state);
500
+ const childKey = state.type_ === 1 /* Array */ ? +prop : prop;
501
+ const childDraft = createProxy(state.scope_, value, state, childKey);
502
+ return state.copy_[childKey] = childDraft;
503
+ }
504
+ return value;
505
+ },
506
+ has(state, prop) {
507
+ return prop in latest(state);
508
+ },
509
+ ownKeys(state) {
510
+ return Reflect.ownKeys(latest(state));
511
+ },
512
+ set(state, prop, value) {
513
+ const desc = getDescriptorFromProto(latest(state), prop);
514
+ if (desc?.set) {
515
+ desc.set.call(state.draft_, value);
516
+ return true;
517
+ }
518
+ if (!state.modified_) {
519
+ const current2 = peek(latest(state), prop);
520
+ const currentState = current2?.[DRAFT_STATE];
521
+ if (currentState && currentState.base_ === value) {
522
+ state.copy_[prop] = value;
523
+ state.assigned_.set(prop, false);
524
+ return true;
525
+ }
526
+ if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))
527
+ return true;
528
+ prepareCopy(state);
529
+ markChanged(state);
530
+ }
531
+ if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
532
+ (value !== void 0 || prop in state.copy_) || // special case: NaN
533
+ Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
534
+ return true;
535
+ state.copy_[prop] = value;
536
+ state.assigned_.set(prop, true);
537
+ handleCrossReference(state, prop, value);
538
+ return true;
539
+ },
540
+ deleteProperty(state, prop) {
541
+ prepareCopy(state);
542
+ if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
543
+ state.assigned_.set(prop, false);
544
+ markChanged(state);
545
+ } else {
546
+ state.assigned_.delete(prop);
547
+ }
548
+ if (state.copy_) {
549
+ delete state.copy_[prop];
550
+ }
551
+ return true;
552
+ },
553
+ // Note: We never coerce `desc.value` into an Immer draft, because we can't make
554
+ // the same guarantee in ES5 mode.
555
+ getOwnPropertyDescriptor(state, prop) {
556
+ const owner = latest(state);
557
+ const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
558
+ if (!desc)
559
+ return desc;
560
+ return {
561
+ [WRITABLE]: true,
562
+ [CONFIGURABLE]: state.type_ !== 1 /* Array */ || prop !== "length",
563
+ [ENUMERABLE]: desc[ENUMERABLE],
564
+ [VALUE]: owner[prop]
565
+ };
566
+ },
567
+ defineProperty() {
568
+ die(11);
569
+ },
570
+ getPrototypeOf(state) {
571
+ return getPrototypeOf(state.base_);
572
+ },
573
+ setPrototypeOf() {
574
+ die(12);
575
+ }
576
+ };
577
+ var arrayTraps = {};
578
+ for (let key in objectTraps) {
579
+ let fn = objectTraps[key];
580
+ arrayTraps[key] = function() {
581
+ const args = arguments;
582
+ args[0] = args[0][0];
583
+ return fn.apply(this, args);
584
+ };
585
+ }
586
+ arrayTraps.deleteProperty = function(state, prop) {
587
+ if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
588
+ die(13);
589
+ return arrayTraps.set.call(this, state, prop, void 0);
590
+ };
591
+ arrayTraps.set = function(state, prop, value) {
592
+ if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
593
+ die(14);
594
+ return objectTraps.set.call(this, state[0], prop, value, state[0]);
595
+ };
596
+ function peek(draft, prop) {
597
+ const state = draft[DRAFT_STATE];
598
+ const source = state ? latest(state) : draft;
599
+ return source[prop];
600
+ }
601
+ function readPropFromProto(state, source, prop) {
602
+ const desc = getDescriptorFromProto(source, prop);
603
+ return desc ? VALUE in desc ? desc[VALUE] : (
604
+ // This is a very special case, if the prop is a getter defined by the
605
+ // prototype, we should invoke it with the draft as context!
606
+ desc.get?.call(state.draft_)
607
+ ) : void 0;
608
+ }
609
+ function getDescriptorFromProto(source, prop) {
610
+ if (!(prop in source))
611
+ return void 0;
612
+ let proto = getPrototypeOf(source);
613
+ while (proto) {
614
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
615
+ if (desc)
616
+ return desc;
617
+ proto = getPrototypeOf(proto);
618
+ }
619
+ return void 0;
620
+ }
621
+ function markChanged(state) {
622
+ if (!state.modified_) {
623
+ state.modified_ = true;
624
+ if (state.parent_) {
625
+ markChanged(state.parent_);
626
+ }
627
+ }
628
+ }
629
+ function prepareCopy(state) {
630
+ if (!state.copy_) {
631
+ state.assigned_ = /* @__PURE__ */ new Map();
632
+ state.copy_ = shallowCopy(
633
+ state.base_,
634
+ state.scope_.immer_.useStrictShallowCopy_
635
+ );
636
+ }
637
+ }
638
+
639
+ // src/core/immerClass.ts
640
+ var Immer2 = class {
641
+ constructor(config) {
642
+ this.autoFreeze_ = true;
643
+ this.useStrictShallowCopy_ = false;
644
+ this.useStrictIteration_ = false;
645
+ /**
646
+ * The `produce` function takes a value and a "recipe function" (whose
647
+ * return value often depends on the base state). The recipe function is
648
+ * free to mutate its first argument however it wants. All mutations are
649
+ * only ever applied to a __copy__ of the base state.
650
+ *
651
+ * Pass only a function to create a "curried producer" which relieves you
652
+ * from passing the recipe function every time.
653
+ *
654
+ * Only plain objects and arrays are made mutable. All other objects are
655
+ * considered uncopyable.
656
+ *
657
+ * Note: This function is __bound__ to its `Immer` instance.
658
+ *
659
+ * @param {any} base - the initial state
660
+ * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
661
+ * @param {Function} patchListener - optional function that will be called with all the patches produced here
662
+ * @returns {any} a new state, or the initial state if nothing was modified
663
+ */
664
+ this.produce = (base, recipe, patchListener) => {
665
+ if (isFunction(base) && !isFunction(recipe)) {
666
+ const defaultBase = recipe;
667
+ recipe = base;
668
+ const self = this;
669
+ return function curriedProduce(base2 = defaultBase, ...args) {
670
+ return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
671
+ };
672
+ }
673
+ if (!isFunction(recipe))
674
+ die(6);
675
+ if (patchListener !== void 0 && !isFunction(patchListener))
676
+ die(7);
677
+ let result;
678
+ if (isDraftable(base)) {
679
+ const scope = enterScope(this);
680
+ const proxy = createProxy(scope, base, void 0);
681
+ let hasError = true;
682
+ try {
683
+ result = recipe(proxy);
684
+ hasError = false;
685
+ } finally {
686
+ if (hasError)
687
+ revokeScope(scope);
688
+ else
689
+ leaveScope(scope);
690
+ }
691
+ usePatchesInScope(scope, patchListener);
692
+ return processResult(result, scope);
693
+ } else if (!base || !isObjectish(base)) {
694
+ result = recipe(base);
695
+ if (result === void 0)
696
+ result = base;
697
+ if (result === NOTHING)
698
+ result = void 0;
699
+ if (this.autoFreeze_)
700
+ freeze(result, true);
701
+ if (patchListener) {
702
+ const p = [];
703
+ const ip = [];
704
+ getPlugin(PluginPatches).generateReplacementPatches_(base, result, {
705
+ patches_: p,
706
+ inversePatches_: ip
707
+ });
708
+ patchListener(p, ip);
709
+ }
710
+ return result;
711
+ } else
712
+ die(1, base);
713
+ };
714
+ this.produceWithPatches = (base, recipe) => {
715
+ if (isFunction(base)) {
716
+ return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
717
+ }
718
+ let patches, inversePatches;
719
+ const result = this.produce(base, recipe, (p, ip) => {
720
+ patches = p;
721
+ inversePatches = ip;
722
+ });
723
+ return [result, patches, inversePatches];
724
+ };
725
+ if (isBoolean(config?.autoFreeze))
726
+ this.setAutoFreeze(config.autoFreeze);
727
+ if (isBoolean(config?.useStrictShallowCopy))
728
+ this.setUseStrictShallowCopy(config.useStrictShallowCopy);
729
+ if (isBoolean(config?.useStrictIteration))
730
+ this.setUseStrictIteration(config.useStrictIteration);
731
+ }
732
+ createDraft(base) {
733
+ if (!isDraftable(base))
734
+ die(8);
735
+ if (isDraft(base))
736
+ base = current(base);
737
+ const scope = enterScope(this);
738
+ const proxy = createProxy(scope, base, void 0);
739
+ proxy[DRAFT_STATE].isManual_ = true;
740
+ leaveScope(scope);
741
+ return proxy;
742
+ }
743
+ finishDraft(draft, patchListener) {
744
+ const state = draft && draft[DRAFT_STATE];
745
+ if (!state || !state.isManual_)
746
+ die(9);
747
+ const { scope_: scope } = state;
748
+ usePatchesInScope(scope, patchListener);
749
+ return processResult(void 0, scope);
750
+ }
751
+ /**
752
+ * Pass true to automatically freeze all copies created by Immer.
753
+ *
754
+ * By default, auto-freezing is enabled.
755
+ */
756
+ setAutoFreeze(value) {
757
+ this.autoFreeze_ = value;
758
+ }
759
+ /**
760
+ * Pass true to enable strict shallow copy.
761
+ *
762
+ * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
763
+ */
764
+ setUseStrictShallowCopy(value) {
765
+ this.useStrictShallowCopy_ = value;
766
+ }
767
+ /**
768
+ * Pass false to use faster iteration that skips non-enumerable properties
769
+ * but still handles symbols for compatibility.
770
+ *
771
+ * By default, strict iteration is enabled (includes all own properties).
772
+ */
773
+ setUseStrictIteration(value) {
774
+ this.useStrictIteration_ = value;
775
+ }
776
+ shouldUseStrictIteration() {
777
+ return this.useStrictIteration_;
778
+ }
779
+ applyPatches(base, patches) {
780
+ let i;
781
+ for (i = patches.length - 1; i >= 0; i--) {
782
+ const patch = patches[i];
783
+ if (patch.path.length === 0 && patch.op === "replace") {
784
+ base = patch.value;
785
+ break;
786
+ }
787
+ }
788
+ if (i > -1) {
789
+ patches = patches.slice(i + 1);
790
+ }
791
+ const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;
792
+ if (isDraft(base)) {
793
+ return applyPatchesImpl(base, patches);
794
+ }
795
+ return this.produce(
796
+ base,
797
+ (draft) => applyPatchesImpl(draft, patches)
798
+ );
799
+ }
800
+ };
801
+ function createProxy(rootScope, value, parent, key) {
802
+ const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);
803
+ const scope = parent?.scope_ ?? getCurrentScope();
804
+ scope.drafts_.push(draft);
805
+ state.callbacks_ = parent?.callbacks_ ?? [];
806
+ state.key_ = key;
807
+ if (parent && key !== void 0) {
808
+ registerChildFinalizationCallback(parent, state, key);
809
+ } else {
810
+ state.callbacks_.push(function rootDraftCleanup(rootScope2) {
811
+ rootScope2.mapSetPlugin_?.fixSetContents(state);
812
+ const { patchPlugin_ } = rootScope2;
813
+ if (state.modified_ && patchPlugin_) {
814
+ patchPlugin_.generatePatches_(state, [], rootScope2);
815
+ }
816
+ });
817
+ }
818
+ return draft;
819
+ }
820
+
821
+ // src/core/current.ts
822
+ function current(value) {
823
+ if (!isDraft(value))
824
+ die(10, value);
825
+ return currentImpl(value);
826
+ }
827
+ function currentImpl(value) {
828
+ if (!isDraftable(value) || isFrozen(value))
829
+ return value;
830
+ const state = value[DRAFT_STATE];
831
+ let copy;
832
+ let strict = true;
833
+ if (state) {
834
+ if (!state.modified_)
835
+ return state.base_;
836
+ state.finalized_ = true;
837
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
838
+ strict = state.scope_.immer_.shouldUseStrictIteration();
839
+ } else {
840
+ copy = shallowCopy(value, true);
841
+ }
842
+ each(
843
+ copy,
844
+ (key, childValue) => {
845
+ set(copy, key, currentImpl(childValue));
846
+ },
847
+ strict
848
+ );
849
+ if (state) {
850
+ state.finalized_ = false;
851
+ }
852
+ return copy;
853
+ }
854
+
855
+ // src/immer.ts
856
+ var immer = new Immer2();
857
+ var produce = immer.produce;
858
+
859
+ export { Immer2 as Immer, current, freeze, DRAFTABLE as immerable, isDraft, isDraftable, NOTHING as nothing, produce };
860
+ //# sourceMappingURL=immer.js.map