react-antd-xform 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/_virtual/_commonjsHelpers.js +8 -0
- package/dist/_virtual/index.js +4 -0
- package/dist/_virtual/index2.js +4 -0
- package/dist/_virtual/jsx-runtime.js +4 -0
- package/dist/_virtual/react-jsx-runtime.development.js +4 -0
- package/dist/_virtual/react-jsx-runtime.production.min.js +4 -0
- package/dist/_virtual/use-sync-external-store-shim.development.js +4 -0
- package/dist/_virtual/use-sync-external-store-shim.production.js +4 -0
- package/dist/form/array-helper.d.ts +12 -0
- package/dist/form/array-helper.js +115 -0
- package/dist/form/common-utils.d.ts +12 -0
- package/dist/form/common-utils.js +90 -0
- package/dist/form/context/formEnvContext.d.ts +6 -0
- package/dist/form/context/formEnvContext.js +23 -0
- package/dist/form/context/modelContext.d.ts +4 -0
- package/dist/form/context/modelContext.js +11 -0
- package/dist/form/enum.d.ts +9 -0
- package/dist/form/enum.js +15 -0
- package/dist/form/form-item.d.ts +15 -0
- package/dist/form/form-item.js +286 -0
- package/dist/form/index.d.ts +22 -0
- package/dist/form/index.js +73 -0
- package/dist/form/layout.d.ts +4 -0
- package/dist/form/layout.js +180 -0
- package/dist/form/model-utils.d.ts +23 -0
- package/dist/form/model-utils.js +171 -0
- package/dist/form/model.d.ts +103 -0
- package/dist/form/model.js +504 -0
- package/dist/form/type.d.ts +289 -0
- package/dist/form-ui/common-utils.d.ts +9 -0
- package/dist/form-ui/common-utils.js +17 -0
- package/dist/form-ui/default-button.d.ts +3 -0
- package/dist/form-ui/default-button.js +39 -0
- package/dist/form-ui/default-component.d.ts +2 -0
- package/dist/form-ui/default-component.js +63 -0
- package/dist/form-ui/type.d.ts +2 -0
- package/dist/helpers/AsyncValue.d.ts +38 -0
- package/dist/helpers/AsyncValue.js +154 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +20 -0
- package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +63 -0
- package/dist/node_modules/.pnpm/get-own-enumerable-keys@1.0.0/node_modules/get-own-enumerable-keys/index.js +10 -0
- package/dist/node_modules/.pnpm/invariant@2.2.4/node_modules/invariant/browser.js +32 -0
- package/dist/node_modules/.pnpm/is-obj@3.0.0/node_modules/is-obj/index.js +7 -0
- package/dist/node_modules/.pnpm/is-regexp@3.1.0/node_modules/is-regexp/index.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Hash.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_ListCache.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Map.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_MapCache.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_Symbol.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_apply.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayMap.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayPush.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assignValue.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_assocIndexOf.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseAssignValue.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseFlatten.js +25 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGet.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseGetTag.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseHasIn.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsArguments.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseIsNative.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePick.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePickBy.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSet.js +33 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSetToString.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseToString.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_castPath.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_coreJsData.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_defineProperty.js +14 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_flatRest.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js +6 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getMapData.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getNative.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getRawTag.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_getValue.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasPath.js +27 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashClear.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashDelete.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashGet.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashHas.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hashSet.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isFlattenable.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isIndex.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKey.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isKeyable.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_isMasked.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheClear.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheDelete.js +22 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheGet.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheHas.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_listCacheSet.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheClear.js +16 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheDelete.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheGet.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheHas.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_mapCacheSet.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_memoizeCapped.js +17 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_nativeCreate.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_objectToString.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_overRest.js +23 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_root.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_setToString.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_shortOut.js +21 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_stringToPath.js +18 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toKey.js +13 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_toSource.js +19 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/constant.js +9 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/eq.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/flatten.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/hasIn.js +10 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/identity.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArguments.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isArray.js +5 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isFunction.js +15 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isLength.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObject.js +8 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isObjectLike.js +7 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/isSymbol.js +11 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/memoize.js +24 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/pick.js +12 -0
- package/dist/node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/toString.js +9 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/ObserverComponent.js +5 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/index.js +18 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/observer.js +84 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/useObserver.js +72 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/UniversalFinalizationRegistry.js +96 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/assertEnvironment.js +8 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/observerBatching.js +17 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/observerFinalizationRegistry.js +9 -0
- package/dist/node_modules/.pnpm/mobx-react-lite@4.1.0_mobx@6.13.7_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/mobx-react-lite/es/utils/printDebugValue.js +7 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.development.js +890 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react-jsx-runtime.production.min.js +33 -0
- package/dist/node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js +12 -0
- package/dist/node_modules/.pnpm/stringify-object@5.0.0/node_modules/stringify-object/index.js +94 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +77 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +62 -0
- package/dist/node_modules/.pnpm/use-sync-external-store@1.5.0_react@18.3.1/node_modules/use-sync-external-store/shim/index.js +12 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 knowledge is limitless
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
2
|
+
function getDefaultExportFromCjs(x) {
|
|
3
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
commonjsGlobal,
|
|
7
|
+
getDefaultExportFromCjs
|
|
8
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormModel } from './model';
|
|
2
|
+
import { FormArrayLayoutInput } from './type';
|
|
3
|
+
export declare const arrayHelpers: {
|
|
4
|
+
append: (arrayModel: FormModel<unknown[]>, itemFactory?: any) => void;
|
|
5
|
+
delete: (arrayModel: FormModel<unknown[]>, itemIndex: number) => void;
|
|
6
|
+
moveUp: (arrayModel: FormModel<unknown[]>, itemIndex: number) => void;
|
|
7
|
+
moveDown: (arrayModel: FormModel<unknown[]>, itemIndex: number) => void;
|
|
8
|
+
clear: (arrayModel: FormModel<unknown[]>) => void;
|
|
9
|
+
move: (arrayModel: FormModel<unknown[]>, fromIndex: number, toIndex: number) => void;
|
|
10
|
+
renderArrayItem(arrayModel: FormModel<unknown[]>, itemIndex: number, itemContent: FormArrayLayoutInput["itemContent"]): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
getKey(arrayModel: FormModel<unknown[]>, itemIndex: number): string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
|
|
2
|
+
import { action } from "mobx";
|
|
3
|
+
import invariant from "../node_modules/.pnpm/invariant@2.2.4/node_modules/invariant/browser.js";
|
|
4
|
+
import { Form } from "./index.js";
|
|
5
|
+
import { composeValue } from "./common-utils.js";
|
|
6
|
+
function invariantArrayShapeIsAutoOrArray(arrayModel) {
|
|
7
|
+
invariant(
|
|
8
|
+
arrayModel._valueShape === "auto" || arrayModel._valueShape === "array",
|
|
9
|
+
'arrayModel._valueShape should be "auto" or "array"'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function updateSubModelsNames(arrayModel) {
|
|
13
|
+
arrayModel._subModels.forEach((mod, index) => {
|
|
14
|
+
mod.name = String(index);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function reorderInPlace(list, fromIndex, toIndex) {
|
|
18
|
+
if (list == null) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const [movingItem] = list.splice(fromIndex, 1);
|
|
22
|
+
list.splice(toIndex, 0, movingItem);
|
|
23
|
+
}
|
|
24
|
+
function swapInPlace(values, a, b) {
|
|
25
|
+
if (values == null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const temp = values[a];
|
|
29
|
+
values[a] = values[b];
|
|
30
|
+
values[b] = temp;
|
|
31
|
+
}
|
|
32
|
+
const arrayHelpers = {
|
|
33
|
+
append: action((arrayModel, itemFactory) => {
|
|
34
|
+
if (arrayModel.values == null) {
|
|
35
|
+
arrayModel.values = [];
|
|
36
|
+
}
|
|
37
|
+
const value = composeValue(
|
|
38
|
+
typeof itemFactory === "function" ? itemFactory(arrayModel) : itemFactory,
|
|
39
|
+
{}
|
|
40
|
+
);
|
|
41
|
+
arrayModel.values.push(value);
|
|
42
|
+
}),
|
|
43
|
+
delete: action((arrayModel, itemIndex) => {
|
|
44
|
+
invariantArrayShapeIsAutoOrArray(arrayModel);
|
|
45
|
+
if (Array.isArray(arrayModel.values)) {
|
|
46
|
+
arrayModel.values.splice(itemIndex, 1);
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(arrayModel._subModels)) {
|
|
49
|
+
const [subModel] = arrayModel._subModels.splice(itemIndex, 1);
|
|
50
|
+
subModel._markDeleted();
|
|
51
|
+
updateSubModelsNames(arrayModel);
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
moveUp: action((arrayModel, itemIndex) => {
|
|
55
|
+
invariantArrayShapeIsAutoOrArray(arrayModel);
|
|
56
|
+
if (itemIndex === 0) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(arrayModel.values)) {
|
|
60
|
+
swapInPlace(arrayModel.values, itemIndex, itemIndex - 1);
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(arrayModel._subModels)) {
|
|
63
|
+
swapInPlace(arrayModel._subModels, itemIndex, itemIndex - 1);
|
|
64
|
+
updateSubModelsNames(arrayModel);
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
moveDown: action((arrayModel, itemIndex) => {
|
|
68
|
+
invariantArrayShapeIsAutoOrArray(arrayModel);
|
|
69
|
+
if (Array.isArray(arrayModel.values)) {
|
|
70
|
+
if (itemIndex === arrayModel.values.length - 1) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
swapInPlace(arrayModel.values, itemIndex, itemIndex + 1);
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(arrayModel._subModels)) {
|
|
76
|
+
swapInPlace(arrayModel._subModels, itemIndex, itemIndex + 1);
|
|
77
|
+
updateSubModelsNames(arrayModel);
|
|
78
|
+
}
|
|
79
|
+
}),
|
|
80
|
+
clear: action((arrayModel) => {
|
|
81
|
+
invariantArrayShapeIsAutoOrArray(arrayModel);
|
|
82
|
+
if (arrayModel.values == null || arrayModel.values.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
arrayModel.values = [];
|
|
86
|
+
if (Array.isArray(arrayModel)) {
|
|
87
|
+
arrayModel._subModels.forEach((subModel) => {
|
|
88
|
+
subModel._markDeleted();
|
|
89
|
+
});
|
|
90
|
+
arrayModel._subModels.length = 0;
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
move: action(
|
|
94
|
+
(arrayModel, fromIndex, toIndex) => {
|
|
95
|
+
invariantArrayShapeIsAutoOrArray(arrayModel);
|
|
96
|
+
if (Array.isArray(arrayModel.values)) {
|
|
97
|
+
reorderInPlace(arrayModel.values, fromIndex, toIndex);
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(arrayModel._subModels)) {
|
|
100
|
+
reorderInPlace(arrayModel._subModels, fromIndex, toIndex);
|
|
101
|
+
updateSubModelsNames(arrayModel);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
renderArrayItem(arrayModel, itemIndex, itemContent) {
|
|
106
|
+
const itemModel = arrayModel.getSubModel(itemIndex);
|
|
107
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(Form.ModelProvider, { value: itemModel, children: itemContent(itemIndex, itemModel) }, itemModel.id);
|
|
108
|
+
},
|
|
109
|
+
getKey(arrayModel, itemIndex) {
|
|
110
|
+
return arrayModel.getSubModel(itemIndex).id;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
arrayHelpers
|
|
115
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function keyToValueShape(key: string): "array" | "object";
|
|
2
|
+
export declare function splitToPath(name: number | string): string[];
|
|
3
|
+
/** 合并两个值,如果第一个不为 undefined,则使用第一个值,否则使用第二个值 */
|
|
4
|
+
export declare function composeValue<T>(first: T, second: T): T;
|
|
5
|
+
/** lodash.get(...) for mobx observables */
|
|
6
|
+
export declare function observableGetIn(obj: any, key: string | string[], defaultValue?: any): any;
|
|
7
|
+
/** lodash.set(...) for mobx observables */
|
|
8
|
+
export declare function observableSetIn(obj: unknown, key: string | string[], value: unknown): void;
|
|
9
|
+
export declare function useHtmlIdPrefix(htmlIdPrefixProp?: string): string;
|
|
10
|
+
export declare function asCSSLength(len: number | string): string;
|
|
11
|
+
export declare function isFalsyOrEmptyArray(value: any): boolean;
|
|
12
|
+
export declare const range: (n: number) => number[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import * as mobx from "mobx";
|
|
3
|
+
function isNumericKey(key) {
|
|
4
|
+
return String(Number.parseInt(key)) === key;
|
|
5
|
+
}
|
|
6
|
+
function keyToValueShape(key) {
|
|
7
|
+
return isNumericKey(key) ? "array" : "object";
|
|
8
|
+
}
|
|
9
|
+
function splitToPath(name) {
|
|
10
|
+
return String(name).split(".");
|
|
11
|
+
}
|
|
12
|
+
function composeValue(first, second) {
|
|
13
|
+
if (first !== void 0) {
|
|
14
|
+
return first;
|
|
15
|
+
}
|
|
16
|
+
return second;
|
|
17
|
+
}
|
|
18
|
+
function observableGetIn(obj, key, defaultValue) {
|
|
19
|
+
const path = Array.isArray(key) ? key : splitToPath(key);
|
|
20
|
+
let target = obj;
|
|
21
|
+
for (let i = 0; i < path.length; i += 1) {
|
|
22
|
+
if (!mobx.isObservable(target)) {
|
|
23
|
+
return defaultValue;
|
|
24
|
+
}
|
|
25
|
+
target = mobx.get(target, path[i]);
|
|
26
|
+
}
|
|
27
|
+
if (target === void 0) {
|
|
28
|
+
return defaultValue;
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
function observableSetIn(obj, key, value) {
|
|
33
|
+
const path = Array.isArray(key) ? key : splitToPath(key);
|
|
34
|
+
const lastPartIndex = path.length - 1;
|
|
35
|
+
let target = obj;
|
|
36
|
+
for (let i = 0; i < lastPartIndex; i += 1) {
|
|
37
|
+
const part = path[i];
|
|
38
|
+
if (mobx.get(target, part) == null) {
|
|
39
|
+
if (isNumericKey(path[i + 1])) {
|
|
40
|
+
mobx.set(target, part, []);
|
|
41
|
+
} else {
|
|
42
|
+
mobx.set(target, part, {});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
target = mobx.get(target, part);
|
|
46
|
+
if (!mobx.isObservable(target)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (mobx.isObservable(target)) {
|
|
51
|
+
mobx.set(target, path[lastPartIndex], value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function generateRandomId(len) {
|
|
55
|
+
const byteToHex = (byte) => ("0" + byte.toString(16)).slice(-2);
|
|
56
|
+
const arr = new Uint8Array(len / 2);
|
|
57
|
+
window.crypto.getRandomValues(arr);
|
|
58
|
+
return Array.from(arr, byteToHex).join("");
|
|
59
|
+
}
|
|
60
|
+
function useHtmlIdPrefix(htmlIdPrefixProp) {
|
|
61
|
+
const [autoGeneratedPrefix] = useState(() => `xform_${generateRandomId(6)}.`);
|
|
62
|
+
if (htmlIdPrefixProp !== void 0) {
|
|
63
|
+
return htmlIdPrefixProp;
|
|
64
|
+
}
|
|
65
|
+
return autoGeneratedPrefix;
|
|
66
|
+
}
|
|
67
|
+
function asCSSLength(len) {
|
|
68
|
+
return typeof len === "number" ? `${len}px` : len;
|
|
69
|
+
}
|
|
70
|
+
function isFalsyOrEmptyArray(value) {
|
|
71
|
+
return !value || Array.isArray(value) && value.length === 0;
|
|
72
|
+
}
|
|
73
|
+
const range = (n) => {
|
|
74
|
+
const result = [];
|
|
75
|
+
for (let i = 0; i < n; i++) {
|
|
76
|
+
result.push(i);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
asCSSLength,
|
|
82
|
+
composeValue,
|
|
83
|
+
isFalsyOrEmptyArray,
|
|
84
|
+
keyToValueShape,
|
|
85
|
+
observableGetIn,
|
|
86
|
+
observableSetIn,
|
|
87
|
+
range,
|
|
88
|
+
splitToPath,
|
|
89
|
+
useHtmlIdPrefix
|
|
90
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { FormEnvContextType } from '../type';
|
|
3
|
+
export declare const useFormEnv: () => FormEnvContextType;
|
|
4
|
+
export declare function FormEnvProvider({ children, ...override }: FormEnvContextType & {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.3.1/node_modules/react/jsx-runtime.js";
|
|
2
|
+
import { useContext, createContext } from "react";
|
|
3
|
+
const FormEnvContext = createContext({
|
|
4
|
+
isPreview: false,
|
|
5
|
+
validateOnMount: false,
|
|
6
|
+
validateOnBlur: true,
|
|
7
|
+
validateOnChange: true,
|
|
8
|
+
writeDefaultValueToModel: false,
|
|
9
|
+
autoUnmount: false
|
|
10
|
+
});
|
|
11
|
+
FormEnvContext.displayName = "FormEnvContext";
|
|
12
|
+
const useFormEnv = () => useContext(FormEnvContext);
|
|
13
|
+
function FormEnvProvider({
|
|
14
|
+
children,
|
|
15
|
+
...override
|
|
16
|
+
}) {
|
|
17
|
+
const parent = useFormEnv();
|
|
18
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(FormEnvContext.Provider, { value: { ...parent, ...override }, children });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
FormEnvProvider,
|
|
22
|
+
useFormEnv
|
|
23
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const ModelContext = createContext(null);
|
|
3
|
+
function useModel() {
|
|
4
|
+
return useContext(ModelContext);
|
|
5
|
+
}
|
|
6
|
+
ModelContext.displayName = "ModelContext";
|
|
7
|
+
const ModelProvider = ModelContext.Provider;
|
|
8
|
+
export {
|
|
9
|
+
ModelProvider,
|
|
10
|
+
useModel
|
|
11
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var ModelType = /* @__PURE__ */ ((ModelType2) => {
|
|
2
|
+
ModelType2["rootModel"] = "rootModel";
|
|
3
|
+
ModelType2["subModel"] = "subModel";
|
|
4
|
+
return ModelType2;
|
|
5
|
+
})(ModelType || {});
|
|
6
|
+
var FieldType = /* @__PURE__ */ ((FieldType2) => {
|
|
7
|
+
FieldType2["normal"] = "normal";
|
|
8
|
+
FieldType2["tuple"] = "tuple";
|
|
9
|
+
FieldType2["readonly"] = "readonly";
|
|
10
|
+
return FieldType2;
|
|
11
|
+
})(FieldType || {});
|
|
12
|
+
export {
|
|
13
|
+
FieldType,
|
|
14
|
+
ModelType
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FormItemCreationOptions, FormItemProps, FormItemViewProps } from './type';
|
|
2
|
+
export declare function FormItemView({ htmlId, label, help, tip, asterisk, error, children, className, style, labelWidth, controlWidth, rightNode, labelStyle, controlStyle, }: FormItemViewProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function createFormItem(inputOptions: FormItemCreationOptions): {
|
|
4
|
+
({ defaultValue: defaultValueProp, isEmpty, renderPreview, componentProps: componentPropsProp, name, field: fieldProp, ...props }: Omit<FormItemProps, "component">): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
displayName: string;
|
|
6
|
+
} & {
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const AnonymousFormItem: {
|
|
10
|
+
({ defaultValue: defaultValueProp, isEmpty, renderPreview, componentProps: componentPropsProp, name, field: fieldProp, ...props }: Omit<FormItemProps, "component">): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
} & {
|
|
13
|
+
displayName: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function FormItem({ use, component, ...props }: FormItemProps): import("react/jsx-runtime").JSX.Element;
|