@form-instant/react-input-mapping 1.8.0 → 2.0.2

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 (38) hide show
  1. package/dist/index.js +2 -7
  2. package/dist/index.js.map +23 -0
  3. package/dist/src/InputMapping/class.d.ts +81 -0
  4. package/dist/src/InputMapping/index.d.ts +7 -0
  5. package/dist/src/InputMapping/provider.d.ts +30 -0
  6. package/dist/{InputMapping → src/InputMapping}/types.d.ts +4 -1
  7. package/dist/src/hooks/useInputArray/application/useInputArray.d.ts +17 -0
  8. package/dist/src/hooks/useInputArray/domain/guards/isParsedField.d.ts +7 -0
  9. package/dist/src/hooks/useInputArray/domain/services/cloneFieldWithIndex.d.ts +9 -0
  10. package/dist/src/hooks/useInputArray/index.d.ts +2 -0
  11. package/dist/src/hooks/useInputArray/types/index.d.ts +8 -0
  12. package/dist/src/hooks/useInputMapping.d.ts +14 -0
  13. package/dist/src/hooks/useInputMappingGranular/application/factory/create-granular-hook.d.ts +18 -0
  14. package/dist/src/hooks/useInputMappingGranular/application/hooks/index.d.ts +2 -0
  15. package/dist/src/hooks/useInputMappingGranular/application/hooks/use-input-component.d.ts +12 -0
  16. package/dist/src/hooks/useInputMappingGranular/application/hooks/use-input-mapping-actions.d.ts +16 -0
  17. package/dist/src/hooks/useInputMappingGranular/application/validators/store-validator.d.ts +9 -0
  18. package/dist/src/hooks/useInputMappingGranular/domain/services/index.d.ts +2 -0
  19. package/dist/src/hooks/useInputMappingGranular/domain/services/notification-service.d.ts +23 -0
  20. package/dist/src/hooks/useInputMappingGranular/domain/services/subscription-manager.d.ts +47 -0
  21. package/dist/src/hooks/useInputMappingGranular/domain/types/index.d.ts +11 -0
  22. package/dist/src/hooks/useInputMappingGranular/index.d.ts +13 -0
  23. package/dist/src/hooks/useInputMappingGranular/infrastructure/store/input-mapping-store.d.ts +47 -0
  24. package/package.json +40 -61
  25. package/LICENSE +0 -21
  26. package/dist/InputMapping/class.d.ts +0 -20
  27. package/dist/InputMapping/index.d.ts +0 -6
  28. package/dist/InputMapping/provider.d.ts +0 -15
  29. package/dist/InputMapping/useFormInstantField.d.ts +0 -16
  30. package/dist/InputMapping/useInputMapping.d.ts +0 -14
  31. package/dist/react-input-mapping.cjs.development.js +0 -265
  32. package/dist/react-input-mapping.cjs.development.js.map +0 -1
  33. package/dist/react-input-mapping.cjs.production.min.js +0 -2
  34. package/dist/react-input-mapping.cjs.production.min.js.map +0 -1
  35. package/dist/react-input-mapping.esm.js +0 -258
  36. package/dist/react-input-mapping.esm.js.map +0 -1
  37. /package/dist/{InputMapping → src/InputMapping}/context.d.ts +0 -0
  38. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
+ "type": "module",
3
+ "private": false,
4
+ "license": "MIT",
5
+ "version": "2.0.2",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/src/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/src/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
2
18
  "name": "@form-instant/react-input-mapping",
3
- "version": "1.8.0",
4
19
  "author": {
5
20
  "name": "leomerida15",
6
21
  "email": "dimasmerida15@gmail.com",
@@ -10,72 +25,36 @@
10
25
  "type": "git",
11
26
  "url": "git+https://github.com/leomerida15/form-instant-react-mapping.git"
12
27
  },
13
- "main": "dist/index.js",
14
- "module": "dist/react-input-mapping.esm.js",
15
- "devDependencies": {
16
- "@size-limit/preset-small-lib": "^11.1.4",
17
- "@tsconfig/recommended": "^1.0.7",
18
- "@tsconfig/vite-react": "^3.0.2",
19
- "@types/bun": "^1.1.8",
20
- "@types/minimatch": "^5.1.2",
21
- "@types/react": "^18.3.12",
22
- "dts-cli": "^2.0.5",
23
- "eslint-plugin-prettier": "^5.2.1",
24
- "husky": "^9.1.5",
25
- "nodemon": "^3.1.4",
26
- "prettier": "^3.3.3",
27
- "size-limit": "^11.1.4",
28
- "tslib": "^2.7.0",
29
- "typescript": "^5.5.4"
28
+ "scripts": {
29
+ "dev": "bun run bunpack.watch.ts",
30
+ "build": "bun run bunpack.build.ts",
31
+ "type:check": "bun x tsc --noEmit",
32
+ "build:types": "bun x tsc --project tsconfig.build.json",
33
+ "lint": "bun -b eslint --config ../../eslint.config.mjs src --ext .ts,.tsx",
34
+ "lint:fix": "bun -b eslint --config ../../eslint.config.mjs src --ext .ts,.tsx --fix",
35
+ "start": "bun run bunpack.watch.ts",
36
+ "watch": "bun run bunpack.watch.ts --build",
37
+ "docs": "bun run docs-serve.ts",
38
+ "docs:dev": "bun run docs.watch.ts"
39
+ },
40
+ "dependencies": {
41
+ "i": "^0.3.7"
30
42
  },
31
43
  "peerDependencies": {
32
- "react": ">=16"
44
+ "react": "^19.2.4"
45
+ },
46
+ "devDependencies": {
47
+ "@types/react": "^19.2.10"
33
48
  },
34
49
  "engines": {
35
- "node": ">=12"
50
+ "node": ">=22",
51
+ "bun": ">=1.3.0"
36
52
  },
37
- "files": [
38
- "dist"
39
- ],
40
53
  "homepage": "https://leomerida15.github.io/form-instant-react-mapping",
41
- "husky": {
42
- "hooks": {
43
- "pre-commit": "dts lint"
44
- }
45
- },
46
- "jest": {
47
- "testEnvironment": "jsdom"
48
- },
49
54
  "keywords": [
50
55
  "@form-instant",
51
56
  "react",
52
- "mapping"
53
- ],
54
- "license": "MIT",
55
- "scripts": {
56
- "analyze": "size-limit --why",
57
- "build": "dts build",
58
- "lint": "dts lint",
59
- "prepare": "dts build",
60
- "size": "size-limit",
61
- "start": "dts watch",
62
- "test": "dts test --passWithNoTests",
63
- "Up": "npm publish --access public",
64
- "Up:rc": "npm publish --access public --tag rc",
65
- "doc:build": "bun nodemon --config docs/nodemon.json"
66
- },
67
- "size-limit": [
68
- {
69
- "path": "dist/react-input-mapping.cjs.production.min.js",
70
- "limit": "10 KB"
71
- },
72
- {
73
- "path": "dist/react-input-mapping.esm.js",
74
- "limit": "10 KB"
75
- }
76
- ],
77
- "typings": "dist/index.d.ts",
78
- "dependencies": {
79
- "minimatch": "^10.0.3"
80
- }
81
- }
57
+ "mapping",
58
+ "form"
59
+ ]
60
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 leomerida15
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,20 +0,0 @@
1
- import { FC } from 'react';
2
- import { INPUT_COMPONENTS_KEYS, ParsedField } from './types';
3
- type InputComponentMap<Ob extends Record<string, any>> = {
4
- [K in keyof Ob]?: FC<ParsedField<Ob[K]>>;
5
- } & {
6
- [K in INPUT_COMPONENTS_KEYS]?: FC<any>;
7
- };
8
- export declare class InputMapping<Ob extends Record<string, any>> extends Map<keyof Ob | INPUT_COMPONENTS_KEYS, FC<any>> {
9
- private zodAdacter;
10
- private appendObj;
11
- constructor(obj?: Partial<InputComponentMap<Ob>>);
12
- exists(k: string): INPUT_COMPONENTS_KEYS | keyof Ob;
13
- get<Ky extends keyof Ob | INPUT_COMPONENTS_KEYS>(k: Ky): FC<any> | undefined;
14
- set<K extends keyof Ob>(k: K, v: FC<Ob[K]>): this;
15
- set<K extends INPUT_COMPONENTS_KEYS>(k: K, v: FC<any>): this;
16
- extends<Ext extends Record<string, FC<any>>>(cb: (mapping: InputMapping<Ob & {
17
- [K in keyof Ext]: any;
18
- }>) => Ext): InputMapping<Ob & { [K in keyof Ext]: any; }>;
19
- }
20
- export {};
@@ -1,6 +0,0 @@
1
- export * from './class';
2
- export * from './context';
3
- export * from './provider';
4
- export * from './types';
5
- export * from './useFormInstantField';
6
- export * from './useInputMapping';
@@ -1,15 +0,0 @@
1
- import { Context, FC, ReactNode } from 'react';
2
- import { InputMapping } from './class';
3
- import { ObBase, ParsedField } from './types';
4
- type FCC = React.FC<{
5
- children: ReactNode;
6
- }>;
7
- interface createFormInstantContainerReturn<Ob extends Record<ObBase, any>> {
8
- useInputMapping: Context<InputMapping<Ob>>;
9
- FormInstantInputsProvider: FCC;
10
- }
11
- export declare const createFormInstantContainer: <Ob extends Record<any, any>>(inputMapping: InputMapping<Ob>) => createFormInstantContainerReturn<Ob>;
12
- export declare const ElementMapping: FC<{
13
- formProps: ParsedField<any, string>;
14
- }>;
15
- export {};
@@ -1,16 +0,0 @@
1
- import { ParsedField } from './types';
2
- export declare const useFormInstantField: <P extends ParsedField<unknown, string>>({ fieldConfig, name, ...prop }: P) => {
3
- fiends: ParsedField<unknown, string>[];
4
- append: () => void;
5
- remove: (index: number) => void;
6
- setFiends: import("react").Dispatch<import("react").SetStateAction<ParsedField<unknown, string>[]>>;
7
- fieldConfig: {
8
- type?: string;
9
- min?: number;
10
- max?: number;
11
- } | undefined;
12
- name: {
13
- current: string;
14
- history: string;
15
- };
16
- } & Omit<P, "fieldConfig" | "name">;
@@ -1,14 +0,0 @@
1
- import { InputMapping } from './class';
2
- export declare function createInputMappingHook<Ob extends Record<string, any>>(InputMappingContext: React.Context<InputMapping<Ob> | null>): () => {
3
- set: (key: keyof Ob | string, value: React.FC<any>) => InputMapping<Ob>;
4
- clear: () => void;
5
- delete: (key: keyof Ob | string) => boolean;
6
- forEach(callbackfn: (value: import("react").FC<any>, key: import("./types").INPUT_COMPONENTS_KEYS | keyof Ob, map: Map<import("./types").INPUT_COMPONENTS_KEYS | keyof Ob, import("react").FC<any>>) => void, thisArg?: any): void;
7
- has(key: import("./types").INPUT_COMPONENTS_KEYS | keyof Ob): boolean;
8
- size: number;
9
- entries(): MapIterator<[import("./types").INPUT_COMPONENTS_KEYS | keyof Ob, import("react").FC<any>]>;
10
- keys(): MapIterator<import("./types").INPUT_COMPONENTS_KEYS | keyof Ob>;
11
- values(): MapIterator<import("react").FC<any>>;
12
- [Symbol.iterator](): MapIterator<[import("./types").INPUT_COMPONENTS_KEYS | keyof Ob, import("react").FC<any>]>;
13
- [Symbol.toStringTag]: string;
14
- };
@@ -1,265 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('react');
4
-
5
- function _arrayLikeToArray(r, a) {
6
- (null == a || a > r.length) && (a = r.length);
7
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
- return n;
9
- }
10
- function _assertThisInitialized(e) {
11
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
12
- return e;
13
- }
14
- function _construct(t, e, r) {
15
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
16
- var o = [null];
17
- o.push.apply(o, e);
18
- var p = new (t.bind.apply(t, o))();
19
- return r && _setPrototypeOf(p, r.prototype), p;
20
- }
21
- function _createForOfIteratorHelperLoose(r, e) {
22
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
23
- if (t) return (t = t.call(r)).next.bind(t);
24
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
25
- t && (r = t);
26
- var o = 0;
27
- return function () {
28
- return o >= r.length ? {
29
- done: !0
30
- } : {
31
- done: !1,
32
- value: r[o++]
33
- };
34
- };
35
- }
36
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
37
- }
38
- function _extends() {
39
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
40
- for (var e = 1; e < arguments.length; e++) {
41
- var t = arguments[e];
42
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
43
- }
44
- return n;
45
- }, _extends.apply(null, arguments);
46
- }
47
- function _getPrototypeOf(t) {
48
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
49
- return t.__proto__ || Object.getPrototypeOf(t);
50
- }, _getPrototypeOf(t);
51
- }
52
- function _inheritsLoose(t, o) {
53
- t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
54
- }
55
- function _isNativeFunction(t) {
56
- try {
57
- return -1 !== Function.toString.call(t).indexOf("[native code]");
58
- } catch (n) {
59
- return "function" == typeof t;
60
- }
61
- }
62
- function _isNativeReflectConstruct() {
63
- try {
64
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
65
- } catch (t) {}
66
- return (_isNativeReflectConstruct = function () {
67
- return !!t;
68
- })();
69
- }
70
- function _objectWithoutPropertiesLoose(r, e) {
71
- if (null == r) return {};
72
- var t = {};
73
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
74
- if (-1 !== e.indexOf(n)) continue;
75
- t[n] = r[n];
76
- }
77
- return t;
78
- }
79
- function _setPrototypeOf(t, e) {
80
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
81
- return t.__proto__ = e, t;
82
- }, _setPrototypeOf(t, e);
83
- }
84
- function _unsupportedIterableToArray(r, a) {
85
- if (r) {
86
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
87
- var t = {}.toString.call(r).slice(8, -1);
88
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
89
- }
90
- }
91
- function _wrapNativeSuper(t) {
92
- var r = "function" == typeof Map ? new Map() : void 0;
93
- return _wrapNativeSuper = function (t) {
94
- if (null === t || !_isNativeFunction(t)) return t;
95
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
96
- if (void 0 !== r) {
97
- if (r.has(t)) return r.get(t);
98
- r.set(t, Wrapper);
99
- }
100
- function Wrapper() {
101
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
102
- }
103
- return Wrapper.prototype = Object.create(t.prototype, {
104
- constructor: {
105
- value: Wrapper,
106
- enumerable: !1,
107
- writable: !0,
108
- configurable: !0
109
- }
110
- }), _setPrototypeOf(Wrapper, t);
111
- }, _wrapNativeSuper(t);
112
- }
113
-
114
- var InputMapping = /*#__PURE__*/function (_Map) {
115
- function InputMapping(obj) {
116
- var _this;
117
- _this = _Map.call(this) || this;
118
- if (!obj) return _assertThisInitialized(_this);
119
- _this.appendObj(obj);
120
- return _this;
121
- }
122
- _inheritsLoose(InputMapping, _Map);
123
- var _proto = InputMapping.prototype;
124
- _proto.zodAdacter = function zodAdacter() {
125
- return Object.entries({
126
- ZodBoolean: 'checkbox',
127
- ZodDate: 'date',
128
- ZodEnum: 'select',
129
- ZodNativeEnum: 'select',
130
- ZodNumber: 'number',
131
- string: 'text'
132
- });
133
- };
134
- _proto.appendObj = function appendObj(obj) {
135
- var keys = Object.keys(obj);
136
- for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
137
- var key = _keys[_i];
138
- var value = obj[key];
139
- if (value && key in {}) {
140
- this.set(key, value);
141
- } else if (value) {
142
- this.set(key, value);
143
- }
144
- }
145
- for (var _iterator = _createForOfIteratorHelperLoose(this.zodAdacter()), _step; !(_step = _iterator()).done;) {
146
- var _step$value = _step.value,
147
- k = _step$value[0],
148
- v = _step$value[1];
149
- var existingValue = this.get(v);
150
- if (existingValue) {
151
- this.set(k, existingValue);
152
- }
153
- }
154
- };
155
- _proto.exists = function exists(k) {
156
- var isHas = _Map.prototype.has.call(this, k);
157
- if (!isHas) return 'fallback';
158
- return k;
159
- };
160
- _proto.get = function get(k) {
161
- return _Map.prototype.get.call(this, k);
162
- };
163
- _proto.set = function set(k, v) {
164
- if (!_Map.prototype.has.call(this, k)) _Map.prototype.set.call(this, k, v);
165
- return this;
166
- };
167
- _proto["extends"] = function _extends$1(cb) {
168
- var obj = Object.fromEntries(_Map.prototype.entries.call(this));
169
- var extendObj = cb(this);
170
- return new InputMapping(_extends({}, obj, extendObj));
171
- };
172
- return InputMapping;
173
- }(/*#__PURE__*/_wrapNativeSuper(Map));
174
-
175
- var InputMappingContext = /*#__PURE__*/react.createContext(null);
176
-
177
- var createFormInstantContainer = function createFormInstantContainer(inputMapping) {
178
- var FormInstantInputsProvider = function FormInstantInputsProvider(props) {
179
- return react.createElement(InputMappingContext.Provider, {
180
- value: inputMapping,
181
- children: props.children
182
- });
183
- };
184
- var useInputMapping = function useInputMapping() {
185
- return react.useContext(InputMappingContext);
186
- };
187
- return {
188
- FormInstantInputsProvider: FormInstantInputsProvider,
189
- useInputMapping: useInputMapping
190
- };
191
- };
192
- var ElementMapping = function ElementMapping(_ref) {
193
- var formProps = _ref.formProps;
194
- var InputMapping = react.useContext(InputMappingContext);
195
- var type = formProps.fieldType;
196
- var Element = InputMapping.get(type);
197
- if (!Element) return null;
198
- return react.createElement(Element, formProps);
199
- };
200
-
201
- var _excluded = ["fieldConfig", "name"];
202
- var useFormInstantField = function useFormInstantField(_ref) {
203
- var fieldConfig = _ref.fieldConfig,
204
- name = _ref.name,
205
- prop = _objectWithoutPropertiesLoose(_ref, _excluded);
206
- var _useState = react.useState(Object.values(prop.schema || {})),
207
- fiends = _useState[0],
208
- setFiends = _useState[1];
209
- var append = react.useCallback(function () {
210
- if (![fieldConfig == null ? void 0 : fieldConfig.max].includes(fiends.length)) setFiends(function (pre) {
211
- return [].concat(pre, [pre[0]]);
212
- });
213
- }, [fiends, fieldConfig == null ? void 0 : fieldConfig.max]);
214
- var remove = react.useCallback(function (index) {
215
- if (![fieldConfig == null ? void 0 : fieldConfig.min].includes(fiends.length)) setFiends(function (pre) {
216
- return pre.filter(function (_, i) {
217
- return i !== index;
218
- });
219
- });
220
- }, [fiends, fieldConfig == null ? void 0 : fieldConfig.min]);
221
- return _extends({
222
- fiends: fiends,
223
- append: append,
224
- remove: remove,
225
- setFiends: setFiends,
226
- fieldConfig: fieldConfig,
227
- name: name
228
- }, prop);
229
- };
230
-
231
- function createInputMappingHook(InputMappingContext) {
232
- return function useInputMapping() {
233
- var initialState = react.useContext(InputMappingContext);
234
- if (!initialState) throw new Error('InputMappingContext not found');
235
- var mapRef = react.useRef(initialState);
236
- var _useReducer = react.useReducer(function (x) {
237
- return x + 1;
238
- }, 0),
239
- reRender = _useReducer[1];
240
- return _extends({}, mapRef.current, {
241
- set: function set(key, value) {
242
- var result = mapRef.current.set(key, value);
243
- reRender();
244
- return result;
245
- },
246
- clear: function clear() {
247
- mapRef.current.clear();
248
- reRender();
249
- },
250
- "delete": function _delete(key) {
251
- var result = mapRef.current["delete"](key);
252
- reRender();
253
- return result;
254
- }
255
- });
256
- };
257
- }
258
-
259
- exports.ElementMapping = ElementMapping;
260
- exports.InputMapping = InputMapping;
261
- exports.InputMappingContext = InputMappingContext;
262
- exports.createFormInstantContainer = createFormInstantContainer;
263
- exports.createInputMappingHook = createInputMappingHook;
264
- exports.useFormInstantField = useFormInstantField;
265
- //# sourceMappingURL=react-input-mapping.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-input-mapping.cjs.development.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/provider.tsx","../src/InputMapping/useFormInstantField.tsx","../src/InputMapping/useInputMapping.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\n\n// Nuevo tipo auxiliar para mapear cada clave a su componente correspondiente\n// Ahora el value depende de la key: si es de Ob, es FC<Ob[K]>; si es de INPUT_COMPONENTS_KEYS, es FC<any>\ntype InputComponentMap<Ob extends Record<string, any>> = {\n [K in keyof Ob]?: FC<ParsedField<Ob[K]>>;\n} & {\n [K in INPUT_COMPONENTS_KEYS]?: FC<any>;\n};\n\nexport class InputMapping<Ob extends Record<string, any>> extends Map<\n keyof Ob | INPUT_COMPONENTS_KEYS,\n FC<any>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<InputComponentMap<Ob>>) {\n const keys = Object.keys(obj) as Array<keyof typeof obj>;\n\n for (const key of keys) {\n const value = obj[key];\n if (value && (key as string) in ({} as Ob)) {\n this.set(key as keyof Ob, value as FC<Ob[keyof Ob]>);\n } else if (value) {\n this.set(key as INPUT_COMPONENTS_KEYS, value as FC<any>);\n }\n }\n\n for (const [k, v] of this.zodAdacter()) {\n const existingValue = this.get(v as INPUT_COMPONENTS_KEYS);\n if (existingValue) {\n this.set(k as INPUT_COMPONENTS_KEYS, existingValue);\n }\n }\n }\n\n constructor(obj?: Partial<InputComponentMap<Ob>>) {\n super();\n if (!obj) return;\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as keyof Ob | INPUT_COMPONENTS_KEYS);\n if (!isHas) return 'fallback';\n return k as keyof Ob | INPUT_COMPONENTS_KEYS;\n }\n\n get<Ky extends keyof Ob | INPUT_COMPONENTS_KEYS>(k: Ky) {\n return super.get(k);\n }\n\n set<K extends keyof Ob>(k: K, v: FC<Ob[K]>): this;\n set<K extends INPUT_COMPONENTS_KEYS>(k: K, v: FC<any>): this;\n set(k: keyof Ob | INPUT_COMPONENTS_KEYS, v: FC<any>): this {\n if (!super.has(k)) super.set(k, v);\n return this;\n }\n\n extends<Ext extends Record<string, FC<any>>>(\n cb: (mapping: InputMapping<Ob & { [K in keyof Ext]: any }>) => Ext,\n ) {\n const obj = Object.fromEntries(super.entries()) as Partial<\n InputComponentMap<Ob & { [K in keyof Ext]: any }>\n >;\n const extendObj = cb(this as InputMapping<Ob & { [K in keyof Ext]: any }>);\n return new InputMapping<Ob & { [K in keyof Ext]: any }>({\n ...obj,\n ...extendObj,\n });\n }\n}\n","import { createContext } from 'react';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping<any> | null>(null) as React.Context<\n InputMapping<any>\n>;\n","import { Context, createElement, FC, ReactNode, useContext } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { ObBase, ParsedField } from './types';\n\ntype FCC = React.FC<{ children: ReactNode }>;\n\ninterface createFormInstantContainerReturn<Ob extends Record<ObBase, any>> {\n useInputMapping: Context<InputMapping<Ob>>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <Ob extends Record<any, any>>(\n inputMapping: InputMapping<Ob>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping,\n children: props.children,\n });\n\n const useInputMapping = () => useContext(InputMappingContext);\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as unknown as createFormInstantContainerReturn<Ob>;\n};\n\nexport const ElementMapping: FC<{ formProps: ParsedField<any, string> }> = ({ formProps }) => {\n const InputMapping = useContext(InputMappingContext);\n\n const type = formProps.fieldType;\n\n const Element = InputMapping.get(type);\n\n if (!Element) return null;\n\n return createElement(Element, formProps);\n};\n","import { useCallback, useState } from 'react';\nimport { ParsedField } from './types';\n\nexport const useFormInstantField = <P extends ParsedField<unknown, string>>({\n fieldConfig,\n name,\n ...prop\n}: P) => {\n const [fiends, setFiends] = useState(Object.values((prop.schema as P['schema']) || {}));\n\n const append = useCallback(() => {\n if (![fieldConfig?.max].includes(fiends.length)) setFiends((pre) => [...pre, pre[0]]);\n }, [fiends, fieldConfig?.max]);\n\n const remove = useCallback(\n (index: number) => {\n if (![fieldConfig?.min].includes(fiends.length))\n setFiends((pre) => pre.filter((_, i) => i !== index));\n },\n [fiends, fieldConfig?.min],\n );\n\n return { fiends, append, remove, setFiends, fieldConfig, name, ...prop };\n};\n","import { useReducer, useRef, useContext } from 'react';\nimport { InputMapping } from './class';\n\nexport function createInputMappingHook<Ob extends Record<string, any>>(\n InputMappingContext: React.Context<InputMapping<Ob> | null>,\n) {\n return function useInputMapping() {\n const initialState = useContext(InputMappingContext);\n if (!initialState) throw new Error('InputMappingContext not found');\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n return {\n ...mapRef.current,\n set: (key: keyof Ob | string, value: React.FC<any>) => {\n const result = mapRef.current.set(key, value);\n reRender();\n return result;\n },\n clear: () => {\n mapRef.current.clear();\n reRender();\n },\n delete: (key: keyof Ob | string) => {\n const result = mapRef.current.delete(key);\n reRender();\n return result;\n },\n };\n };\n}\n"],"names":["InputMapping","_Map","obj","_this","call","_assertThisInitialized","appendObj","_inheritsLoose","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","keys","_i","_keys","length","key","value","set","_iterator","_createForOfIteratorHelperLoose","_step","done","_step$value","k","v","existingValue","get","exists","isHas","has","extends","cb","fromEntries","extendObj","_extends2","_wrapNativeSuper","Map","InputMappingContext","createContext","createFormInstantContainer","inputMapping","FormInstantInputsProvider","props","createElement","Provider","children","useInputMapping","useContext","ElementMapping","_ref","formProps","type","fieldType","Element","useFormInstantField","fieldConfig","name","prop","_objectWithoutPropertiesLoose","_excluded","_useState","useState","values","schema","fiends","setFiends","append","useCallback","max","includes","pre","concat","remove","index","min","filter","_","i","_extends","createInputMappingHook","initialState","Error","mapRef","useRef","_useReducer","useReducer","x","reRender","current","result","clear","delete"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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2C,YAAY,EAAE,MAAM,IAAIC,KAAK,CAAC,+BAA+B,CAAC,CAAA;AACnE,IAAA,IAAMC,MAAM,GAAGC,YAAM,CAACH,YAAY,CAAC,CAAA;AACnC,IAAA,IAAAI,WAAA,GAAqBC,gBAAU,CAAC,UAACC,CAAC,EAAA;QAAA,OAAKA,CAAC,GAAG,CAAC,CAAA;AAAA,OAAA,EAAE,CAAC,CAAC;AAAvCC,MAAAA,QAAQ,GAAAH,WAAA,CAAA,CAAA,CAAA,CAAA;AAEjB,IAAA,OAAAN,QAAA,CAAA,EAAA,EACOI,MAAM,CAACM,OAAO,EAAA;AACjBvE,MAAAA,GAAG,EAAE,SAALA,GAAGA,CAAGF,GAAsB,EAAEC,KAAoB,EAAI;QAClD,IAAMyE,MAAM,GAAGP,MAAM,CAACM,OAAO,CAACvE,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC,CAAA;AAC7CuE,QAAAA,QAAQ,EAAE,CAAA;AACV,QAAA,OAAOE,MAAM,CAAA;OAChB;AACDC,MAAAA,KAAK,EAAE,SAAPA,KAAKA,GAAO;AACRR,QAAAA,MAAM,CAACM,OAAO,CAACE,KAAK,EAAE,CAAA;AACtBH,QAAAA,QAAQ,EAAE,CAAA;OACb;AACD,MAAA,QAAA,EAAQ,SAARI,OAAMA,CAAG5E,GAAsB,EAAI;QAC/B,IAAM0E,MAAM,GAAGP,MAAM,CAACM,OAAO,CAAO,QAAA,CAAA,CAACzE,GAAG,CAAC,CAAA;AACzCwE,QAAAA,QAAQ,EAAE,CAAA;AACV,QAAA,OAAOE,MAAM,CAAA;AACjB,OAAA;AAAC,KAAA,CAAA,CAAA;GAER,CAAA;AACL;;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";var t=require("react");function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(null,arguments)}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(o=function(){return!!t})()}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function i(t){var e="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return function(t,e,n){if(o())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var i=new(t.bind.apply(t,r));return n&&u(i,n.prototype),i}(t,arguments,r(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,t)},i(t)}var a=function(t){function r(e){var n;return n=t.call(this)||this,e?(n.appendObj(e),n):function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n)}var o,i;i=t,(o=r).prototype=Object.create(i.prototype),o.prototype.constructor=o,u(o,i);var a=r.prototype;return a.zodAdacter=function(){return Object.entries({ZodBoolean:"checkbox",ZodDate:"date",ZodEnum:"select",ZodNativeEnum:"select",ZodNumber:"number",string:"text"})},a.appendObj=function(t){for(var n=0,r=Object.keys(t);n<r.length;n++){var o=r[n],u=t[o];(u&&o in{}||u)&&this.set(o,u)}for(var i,a=function(t){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,n){if(t){if("string"==typeof t)return e(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(t,n):void 0}}(t))){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(this.zodAdacter());!(i=a()).done;){var c=i.value,l=c[0],f=this.get(c[1]);f&&this.set(l,f)}},a.exists=function(e){return t.prototype.has.call(this,e)?e:"fallback"},a.get=function(e){return t.prototype.get.call(this,e)},a.set=function(e,n){return t.prototype.has.call(this,e)||t.prototype.set.call(this,e,n),this},a.extends=function(e){return new r(n({},Object.fromEntries(t.prototype.entries.call(this)),e(this)))},r}(i(Map)),c=t.createContext(null),l=["fieldConfig","name"];exports.ElementMapping=function(e){var n=e.formProps,r=t.useContext(c).get(n.fieldType);return r?t.createElement(r,n):null},exports.InputMapping=a,exports.InputMappingContext=c,exports.createFormInstantContainer=function(e){return{FormInstantInputsProvider:function(n){return t.createElement(c.Provider,{value:e,children:n.children})},useInputMapping:function(){return t.useContext(c)}}},exports.createInputMappingHook=function(e){return function(){var r=t.useContext(e);if(!r)throw new Error("InputMappingContext not found");var o=t.useRef(r),u=t.useReducer(function(t){return t+1},0)[1];return n({},o.current,{set:function(t,e){var n=o.current.set(t,e);return u(),n},clear:function(){o.current.clear(),u()},delete:function(t){var e=o.current.delete(t);return u(),e}})}},exports.useFormInstantField=function(e){var r=e.fieldConfig,o=e.name,u=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==e.indexOf(r))continue;n[r]=t[r]}return n}(e,l),i=t.useState(Object.values(u.schema||{})),a=i[0],c=i[1],f=t.useCallback(function(){[null==r?void 0:r.max].includes(a.length)||c(function(t){return[].concat(t,[t[0]])})},[a,null==r?void 0:r.max]),s=t.useCallback(function(t){[null==r?void 0:r.min].includes(a.length)||c(function(e){return e.filter(function(e,n){return n!==t})})},[a,null==r?void 0:r.min]);return n({fiends:a,append:f,remove:s,setFiends:c,fieldConfig:r,name:o},u)};
2
- //# sourceMappingURL=react-input-mapping.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-input-mapping.cjs.production.min.js","sources":["../src/InputMapping/class.ts","../src/InputMapping/context.tsx","../src/InputMapping/provider.tsx","../src/InputMapping/useInputMapping.tsx","../src/InputMapping/useFormInstantField.tsx"],"sourcesContent":["import { FC } from 'react';\nimport { INPUT_COMPONENTS_KEYS, ParsedField } from './types';\n\n// Nuevo tipo auxiliar para mapear cada clave a su componente correspondiente\n// Ahora el value depende de la key: si es de Ob, es FC<Ob[K]>; si es de INPUT_COMPONENTS_KEYS, es FC<any>\ntype InputComponentMap<Ob extends Record<string, any>> = {\n [K in keyof Ob]?: FC<ParsedField<Ob[K]>>;\n} & {\n [K in INPUT_COMPONENTS_KEYS]?: FC<any>;\n};\n\nexport class InputMapping<Ob extends Record<string, any>> extends Map<\n keyof Ob | INPUT_COMPONENTS_KEYS,\n FC<any>\n> {\n private zodAdacter() {\n return Object.entries({\n ZodBoolean: 'checkbox',\n ZodDate: 'date',\n ZodEnum: 'select',\n ZodNativeEnum: 'select',\n ZodNumber: 'number',\n string: 'text',\n });\n }\n\n private appendObj(obj: Partial<InputComponentMap<Ob>>) {\n const keys = Object.keys(obj) as Array<keyof typeof obj>;\n\n for (const key of keys) {\n const value = obj[key];\n if (value && (key as string) in ({} as Ob)) {\n this.set(key as keyof Ob, value as FC<Ob[keyof Ob]>);\n } else if (value) {\n this.set(key as INPUT_COMPONENTS_KEYS, value as FC<any>);\n }\n }\n\n for (const [k, v] of this.zodAdacter()) {\n const existingValue = this.get(v as INPUT_COMPONENTS_KEYS);\n if (existingValue) {\n this.set(k as INPUT_COMPONENTS_KEYS, existingValue);\n }\n }\n }\n\n constructor(obj?: Partial<InputComponentMap<Ob>>) {\n super();\n if (!obj) return;\n this.appendObj(obj);\n }\n\n exists(k: string) {\n const isHas = super.has(k as keyof Ob | INPUT_COMPONENTS_KEYS);\n if (!isHas) return 'fallback';\n return k as keyof Ob | INPUT_COMPONENTS_KEYS;\n }\n\n get<Ky extends keyof Ob | INPUT_COMPONENTS_KEYS>(k: Ky) {\n return super.get(k);\n }\n\n set<K extends keyof Ob>(k: K, v: FC<Ob[K]>): this;\n set<K extends INPUT_COMPONENTS_KEYS>(k: K, v: FC<any>): this;\n set(k: keyof Ob | INPUT_COMPONENTS_KEYS, v: FC<any>): this {\n if (!super.has(k)) super.set(k, v);\n return this;\n }\n\n extends<Ext extends Record<string, FC<any>>>(\n cb: (mapping: InputMapping<Ob & { [K in keyof Ext]: any }>) => Ext,\n ) {\n const obj = Object.fromEntries(super.entries()) as Partial<\n InputComponentMap<Ob & { [K in keyof Ext]: any }>\n >;\n const extendObj = cb(this as InputMapping<Ob & { [K in keyof Ext]: any }>);\n return new InputMapping<Ob & { [K in keyof Ext]: any }>({\n ...obj,\n ...extendObj,\n });\n }\n}\n","import { createContext } from 'react';\nimport { InputMapping } from './class';\n\nexport const InputMappingContext = createContext<InputMapping<any> | null>(null) as React.Context<\n InputMapping<any>\n>;\n","import { Context, createElement, FC, ReactNode, useContext } from 'react';\nimport { InputMapping } from './class';\nimport { InputMappingContext } from './context';\nimport { ObBase, ParsedField } from './types';\n\ntype FCC = React.FC<{ children: ReactNode }>;\n\ninterface createFormInstantContainerReturn<Ob extends Record<ObBase, any>> {\n useInputMapping: Context<InputMapping<Ob>>;\n FormInstantInputsProvider: FCC;\n}\n\nexport const createFormInstantContainer = <Ob extends Record<any, any>>(\n inputMapping: InputMapping<Ob>,\n) => {\n const FormInstantInputsProvider: FCC = (props) =>\n createElement(InputMappingContext.Provider, {\n value: inputMapping,\n children: props.children,\n });\n\n const useInputMapping = () => useContext(InputMappingContext);\n\n return {\n FormInstantInputsProvider,\n useInputMapping,\n } as unknown as createFormInstantContainerReturn<Ob>;\n};\n\nexport const ElementMapping: FC<{ formProps: ParsedField<any, string> }> = ({ formProps }) => {\n const InputMapping = useContext(InputMappingContext);\n\n const type = formProps.fieldType;\n\n const Element = InputMapping.get(type);\n\n if (!Element) return null;\n\n return createElement(Element, formProps);\n};\n","import { useReducer, useRef, useContext } from 'react';\nimport { InputMapping } from './class';\n\nexport function createInputMappingHook<Ob extends Record<string, any>>(\n InputMappingContext: React.Context<InputMapping<Ob> | null>,\n) {\n return function useInputMapping() {\n const initialState = useContext(InputMappingContext);\n if (!initialState) throw new Error('InputMappingContext not found');\n const mapRef = useRef(initialState);\n const [, reRender] = useReducer((x) => x + 1, 0);\n\n return {\n ...mapRef.current,\n set: (key: keyof Ob | string, value: React.FC<any>) => {\n const result = mapRef.current.set(key, value);\n reRender();\n return result;\n },\n clear: () => {\n mapRef.current.clear();\n reRender();\n },\n delete: (key: keyof Ob | string) => {\n const result = mapRef.current.delete(key);\n reRender();\n return result;\n },\n };\n };\n}\n","import { useCallback, useState } from 'react';\nimport { ParsedField } from './types';\n\nexport const useFormInstantField = <P extends ParsedField<unknown, string>>({\n fieldConfig,\n name,\n ...prop\n}: P) => {\n const [fiends, setFiends] = useState(Object.values((prop.schema as P['schema']) || {}));\n\n const append = useCallback(() => {\n if (![fieldConfig?.max].includes(fiends.length)) setFiends((pre) => [...pre, pre[0]]);\n }, [fiends, fieldConfig?.max]);\n\n const remove = useCallback(\n (index: number) => {\n if (![fieldConfig?.min].includes(fiends.length))\n setFiends((pre) => pre.filter((_, i) => i !== index));\n },\n [fiends, fieldConfig?.min],\n );\n\n return { fiends, append, remove, setFiends, fieldConfig, name, ...prop };\n};\n"],"names":["InputMapping","_Map","obj","_this","call","this","appendObj","_assertThisInitialized","_proto","prototype","zodAdacter","Object","entries","ZodBoolean","ZodDate","ZodEnum","ZodNativeEnum","ZodNumber","string","_i","_keys","keys","length","key","value","set","_step","_iterator","_createForOfIteratorHelperLoose","done","_step$value","k","existingValue","get","exists","has","v","cb","_extends2","fromEntries","_wrapNativeSuper","Map","InputMappingContext","createContext","_ref","formProps","Element","useContext","fieldType","createElement","inputMapping","FormInstantInputsProvider","props","Provider","children","useInputMapping","initialState","Error","mapRef","useRef","reRender","useReducer","x","_extends","current","result","clear","delete","fieldConfig","name","prop","_objectWithoutPropertiesLoose","_excluded","_useState","useState","values","schema","fiends","setFiends","append","useCallback","max","includes","pre","concat","remove","index","min","filter","_","i"],"mappings":"07CAWaA,IAAAA,WAA6CC,GAmCtD,SAAAD,EAAYE,GAAoC,IAAAC,EAE5C,OADAA,EAAAF,EAAAG,YAAOC,KACFH,GACLC,EAAKG,UAAUJ,GAAKC,4HADVI,CAAAJ,EAEd,WAACF,KAAAD,yEAAA,IAAAQ,EAAAR,EAAAS,UA8BA,OA9BAD,EAnCOE,WAAA,WACJ,OAAOC,OAAOC,QAAQ,CAClBC,WAAY,WACZC,QAAS,OACTC,QAAS,SACTC,cAAe,SACfC,UAAW,SACXC,OAAQ,UAEfV,EAEOF,UAAA,SAAUJ,GAGd,IAFA,IAEAiB,EAAA,EAAAC,EAFaT,OAAOU,KAAKnB,GAEHiB,EAAAC,EAAAE,OAAAH,IAAE,CAAnB,IAAMI,EAAGH,EAAAD,GACJK,EAAQtB,EAAIqB,IACdC,GAAUD,IAAmB,IAEtBC,IADPnB,KAAKoB,IAAIF,EAAiBC,EAIlC,CAEA,IAAA,IAAsCE,EAAtCC,2pBAAAC,CAAqBvB,KAAKK,gBAAYgB,EAAAC,KAAAE,MAAE,CAAA,IAAAC,EAAAJ,EAAAF,MAA5BO,EAACD,EAAA,GACHE,EAAgB3B,KAAK4B,IADfH,EAAA,IAERE,GACA3B,KAAKoB,IAAIM,EAA4BC,EAE7C,GACHxB,EAQD0B,OAAA,SAAOH,GAEH,OADW9B,EAAAQ,UAAS0B,IAAG/B,KAAC2B,KAAAA,GAEjBA,EADY,YAEtBvB,EAEDyB,IAAA,SAAiDF,GAC7C,OAAA9B,EAAAQ,UAAawB,IAAG7B,UAAC2B,IACpBvB,EAIDiB,IAAA,SAAIM,EAAqCK,GAErC,O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