@pixpilot/formily-shadcn 0.48.0 → 0.49.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.
- package/dist/components/IconPicker.d.cts +3 -3
- package/dist/components/IconToggle.d.cts +2 -2
- package/dist/components/array-base/components/Addition.cjs +10 -0
- package/dist/components/array-base/components/Addition.js +10 -0
- package/dist/components/array-base/types.d.cts +10 -1
- package/dist/components/array-base/types.d.ts +10 -1
- package/dist/components/array-common/create-active-item-manager.cjs +10 -1
- package/dist/components/array-common/create-active-item-manager.js +10 -1
- package/dist/components/array-common/use-array-editor.cjs +19 -3
- package/dist/components/array-common/use-array-editor.js +19 -3
- package/dist/components/array-common/use-array-item-draft-form.cjs +6 -3
- package/dist/components/array-common/use-array-item-draft-form.js +6 -3
- package/dist/components/array-common/use-array-item-edit-state.cjs +66 -0
- package/dist/components/array-common/use-array-item-edit-state.js +63 -0
- package/dist/components/array-dialog/EditDialog.cjs +8 -36
- package/dist/components/array-dialog/EditDialog.js +9 -37
- package/dist/components/array-popover/ArrayPopover.cjs +1 -1
- package/dist/components/array-popover/ArrayPopover.js +1 -1
- package/dist/components/array-popover/Popover.cjs +11 -41
- package/dist/components/array-popover/Popover.js +12 -42
- package/dist/components/file-upload/FileUpload.d.cts +8 -8
- package/dist/components/file-upload/FileUploadInline.d.cts +8 -8
- package/dist/components/form-item/ConnectedFormItem.d.cts +4 -4
- package/dist/components/number/NumberInput.d.cts +3 -3
- package/dist/components/schema-field/schema-field-basics.d.cts +23 -23
- package/dist/components/schema-field/schema-field-basics.d.ts +277 -277
- package/dist/components/schema-field/schema-field-extended.d.cts +607 -607
- package/dist/components/schema-field/schema-field-extended.d.ts +607 -607
- package/dist/components/schema-field/schema-field.d.cts +89 -89
- package/dist/components/schema-field/schema-field.d.ts +387 -387
- package/dist/components/slider/Slider.d.cts +2 -2
- package/dist/components/slider/Slider.d.ts +3 -3
- package/dist/components/slider/SliderInput.d.cts +2 -2
- package/dist/components/slider/SliderInput.d.ts +3 -3
- package/dist/components/slider/SliderSelect.d.cts +2 -2
- package/dist/components/slider/SliderSelect.d.ts +3 -3
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react4 from "react";
|
|
2
2
|
import { IconPickerProps, IconProviderProps } from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/IconPicker.d.ts
|
|
@@ -8,8 +8,8 @@ import { IconPickerProps, IconProviderProps } from "@pixpilot/shadcn-ui";
|
|
|
8
8
|
* Automatically connects to Formily field state
|
|
9
9
|
* Supports both static and async icon providers
|
|
10
10
|
*/
|
|
11
|
-
declare const IconPicker:
|
|
11
|
+
declare const IconPicker: react4.ForwardRefExoticComponent<Partial<Omit<IconPickerProps, "providers"> & {
|
|
12
12
|
providers?: IconProviderProps[];
|
|
13
|
-
}> &
|
|
13
|
+
}> & react4.RefAttributes<unknown>>;
|
|
14
14
|
//#endregion
|
|
15
15
|
export { IconPicker };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react6 from "react";
|
|
2
2
|
import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
|
|
3
3
|
|
|
4
4
|
//#region src/components/IconToggle.d.ts
|
|
@@ -6,6 +6,6 @@ import * as _pixpilot_shadcn_ui0 from "@pixpilot/shadcn-ui";
|
|
|
6
6
|
* Formily-connected IconToggle component
|
|
7
7
|
* Toggle button with customizable icons for boolean values
|
|
8
8
|
*/
|
|
9
|
-
declare const IconToggle:
|
|
9
|
+
declare const IconToggle: react6.ForwardRefExoticComponent<Omit<Partial<Omit<_pixpilot_shadcn_ui0.IconToggleProps, "ref"> & react6.RefAttributes<HTMLButtonElement>>, "ref"> & react6.RefAttributes<unknown>>;
|
|
10
10
|
//#endregion
|
|
11
11
|
export { IconToggle };
|
|
@@ -42,6 +42,16 @@ function ArrayAddition({ ref,...props }) {
|
|
|
42
42
|
if (e.defaultPrevented) return;
|
|
43
43
|
}
|
|
44
44
|
const defaultValue = require_get_default_value.getDefaultValue(props.defaultValue, array.schema);
|
|
45
|
+
if (!(array.props?.autoSave === true)) {
|
|
46
|
+
const method = props.method ?? "push";
|
|
47
|
+
const insertionIndex = method === "unshift" ? 0 : currentLength;
|
|
48
|
+
array.props?.onAdd?.(insertionIndex, {
|
|
49
|
+
mode: "draft-only",
|
|
50
|
+
method,
|
|
51
|
+
initialDraftValue: defaultValue
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
45
55
|
if (props.method === "unshift") {
|
|
46
56
|
array.field?.unshift?.(defaultValue).catch(console.error);
|
|
47
57
|
array.props?.onAdd?.(0);
|
|
@@ -36,6 +36,16 @@ function ArrayAddition({ ref,...props }) {
|
|
|
36
36
|
if (e.defaultPrevented) return;
|
|
37
37
|
}
|
|
38
38
|
const defaultValue = getDefaultValue(props.defaultValue, array.schema);
|
|
39
|
+
if (!(array.props?.autoSave === true)) {
|
|
40
|
+
const method = props.method ?? "push";
|
|
41
|
+
const insertionIndex = method === "unshift" ? 0 : currentLength;
|
|
42
|
+
array.props?.onAdd?.(insertionIndex, {
|
|
43
|
+
mode: "draft-only",
|
|
44
|
+
method,
|
|
45
|
+
initialDraftValue: defaultValue
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
39
49
|
if (props.method === "unshift") {
|
|
40
50
|
array.field?.unshift?.(defaultValue).catch(console.error);
|
|
41
51
|
array.props?.onAdd?.(0);
|
|
@@ -53,7 +53,16 @@ interface ArrayBaseMixins extends ArrayBaseComponents {
|
|
|
53
53
|
}
|
|
54
54
|
interface IArrayBaseProps {
|
|
55
55
|
disabled?: boolean;
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* When true, array editors (dialog/popover) commit changes live.
|
|
58
|
+
* When false/undefined, changes should only commit on Save.
|
|
59
|
+
*/
|
|
60
|
+
autoSave?: boolean;
|
|
61
|
+
onAdd?: (index: number, options?: {
|
|
62
|
+
method?: 'push' | 'unshift';
|
|
63
|
+
initialDraftValue?: unknown;
|
|
64
|
+
mode?: 'inserted' | 'draft-only';
|
|
65
|
+
}) => void;
|
|
57
66
|
onRemove?: (index: number) => void;
|
|
58
67
|
onMoveDown?: (index: number) => void;
|
|
59
68
|
onMoveUp?: (index: number) => void;
|
|
@@ -53,7 +53,16 @@ interface ArrayBaseMixins extends ArrayBaseComponents {
|
|
|
53
53
|
}
|
|
54
54
|
interface IArrayBaseProps {
|
|
55
55
|
disabled?: boolean;
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* When true, array editors (dialog/popover) commit changes live.
|
|
58
|
+
* When false/undefined, changes should only commit on Save.
|
|
59
|
+
*/
|
|
60
|
+
autoSave?: boolean;
|
|
61
|
+
onAdd?: (index: number, options?: {
|
|
62
|
+
method?: 'push' | 'unshift';
|
|
63
|
+
initialDraftValue?: unknown;
|
|
64
|
+
mode?: 'inserted' | 'draft-only';
|
|
65
|
+
}) => void;
|
|
57
66
|
onRemove?: (index: number) => void;
|
|
58
67
|
onMoveDown?: (index: number) => void;
|
|
59
68
|
onMoveUp?: (index: number) => void;
|
|
@@ -7,9 +7,15 @@ function createActiveItemManager() {
|
|
|
7
7
|
const panelState = (0, __formily_reactive.model)({
|
|
8
8
|
activeItem: void 0,
|
|
9
9
|
isNew: false,
|
|
10
|
-
|
|
10
|
+
newItemMode: void 0,
|
|
11
|
+
newItemMethod: void 0,
|
|
12
|
+
draftInitialValue: void 0,
|
|
13
|
+
setActiveItem(key, isNew, options) {
|
|
11
14
|
panelState.activeItem = key;
|
|
12
15
|
panelState.isNew = isNew;
|
|
16
|
+
panelState.newItemMode = isNew ? options?.newItemMode : void 0;
|
|
17
|
+
panelState.newItemMethod = isNew ? options?.newItemMethod : void 0;
|
|
18
|
+
panelState.draftInitialValue = isNew && options?.newItemMode === "draft-only" ? options?.draftInitialValue : void 0;
|
|
13
19
|
},
|
|
14
20
|
hasActiveItem(key) {
|
|
15
21
|
return panelState.activeItem === key;
|
|
@@ -17,6 +23,9 @@ function createActiveItemManager() {
|
|
|
17
23
|
removeActiveItem(key) {
|
|
18
24
|
if (panelState.activeItem === key) panelState.activeItem = void 0;
|
|
19
25
|
panelState.isNew = false;
|
|
26
|
+
panelState.newItemMode = void 0;
|
|
27
|
+
panelState.newItemMethod = void 0;
|
|
28
|
+
panelState.draftInitialValue = void 0;
|
|
20
29
|
},
|
|
21
30
|
isNewItem(index) {
|
|
22
31
|
return panelState.isNew && panelState.activeItem === index;
|
|
@@ -5,9 +5,15 @@ function createActiveItemManager() {
|
|
|
5
5
|
const panelState = model({
|
|
6
6
|
activeItem: void 0,
|
|
7
7
|
isNew: false,
|
|
8
|
-
|
|
8
|
+
newItemMode: void 0,
|
|
9
|
+
newItemMethod: void 0,
|
|
10
|
+
draftInitialValue: void 0,
|
|
11
|
+
setActiveItem(key, isNew, options) {
|
|
9
12
|
panelState.activeItem = key;
|
|
10
13
|
panelState.isNew = isNew;
|
|
14
|
+
panelState.newItemMode = isNew ? options?.newItemMode : void 0;
|
|
15
|
+
panelState.newItemMethod = isNew ? options?.newItemMethod : void 0;
|
|
16
|
+
panelState.draftInitialValue = isNew && options?.newItemMode === "draft-only" ? options?.draftInitialValue : void 0;
|
|
11
17
|
},
|
|
12
18
|
hasActiveItem(key) {
|
|
13
19
|
return panelState.activeItem === key;
|
|
@@ -15,6 +21,9 @@ function createActiveItemManager() {
|
|
|
15
21
|
removeActiveItem(key) {
|
|
16
22
|
if (panelState.activeItem === key) panelState.activeItem = void 0;
|
|
17
23
|
panelState.isNew = false;
|
|
24
|
+
panelState.newItemMode = void 0;
|
|
25
|
+
panelState.newItemMethod = void 0;
|
|
26
|
+
panelState.draftInitialValue = void 0;
|
|
18
27
|
},
|
|
19
28
|
isNewItem(index) {
|
|
20
29
|
return panelState.isNew && panelState.activeItem === index;
|
|
@@ -32,11 +32,27 @@ function useArrayEditor(props) {
|
|
|
32
32
|
activeItemManager.setActiveItem(index, false);
|
|
33
33
|
onEdit?.(index);
|
|
34
34
|
};
|
|
35
|
-
const handleAdd = (index) => {
|
|
36
|
-
|
|
35
|
+
const handleAdd = (index, options) => {
|
|
36
|
+
const isAutoSave = autoSave === true;
|
|
37
|
+
if (options?.mode === "draft-only" || !isAutoSave) {
|
|
38
|
+
activeItemManager.setActiveItem(-1, true, {
|
|
39
|
+
newItemMode: "draft-only",
|
|
40
|
+
newItemMethod: options?.method,
|
|
41
|
+
draftInitialValue: options?.initialDraftValue
|
|
42
|
+
});
|
|
43
|
+
onAdd?.(index);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
activeItemManager.setActiveItem(index, true, { newItemMode: "inserted" });
|
|
37
47
|
onAdd?.(index);
|
|
38
48
|
};
|
|
39
49
|
const handleSaveClick = (itemIndex, nextValue) => {
|
|
50
|
+
if (activeItemManager.isNew && activeItemManager.newItemMode === "draft-only") {
|
|
51
|
+
if ((activeItemManager.newItemMethod ?? "push") === "unshift") field.unshift?.(nextValue).catch(console.error);
|
|
52
|
+
else field.push?.(nextValue).catch(console.error);
|
|
53
|
+
activeItemManager.removeActiveItem(itemIndex);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
40
56
|
setArrayItemValue(field, itemIndex, nextValue);
|
|
41
57
|
activeItemManager.removeActiveItem(itemIndex);
|
|
42
58
|
};
|
|
@@ -44,7 +60,7 @@ function useArrayEditor(props) {
|
|
|
44
60
|
setArrayItemValue(field, itemIndex, nextValue);
|
|
45
61
|
};
|
|
46
62
|
const handleCancelClick = (itemIndex) => {
|
|
47
|
-
if (!autoSave && activeItemManager.isNewItem(itemIndex)) field.remove?.(itemIndex).catch(console.error);
|
|
63
|
+
if (!autoSave && activeItemManager.isNewItem(itemIndex) && activeItemManager.newItemMode !== "draft-only") field.remove?.(itemIndex).catch(console.error);
|
|
48
64
|
activeItemManager.removeActiveItem(itemIndex);
|
|
49
65
|
};
|
|
50
66
|
return {
|
|
@@ -29,11 +29,27 @@ function useArrayEditor(props) {
|
|
|
29
29
|
activeItemManager.setActiveItem(index, false);
|
|
30
30
|
onEdit?.(index);
|
|
31
31
|
};
|
|
32
|
-
const handleAdd = (index) => {
|
|
33
|
-
|
|
32
|
+
const handleAdd = (index, options) => {
|
|
33
|
+
const isAutoSave = autoSave === true;
|
|
34
|
+
if (options?.mode === "draft-only" || !isAutoSave) {
|
|
35
|
+
activeItemManager.setActiveItem(-1, true, {
|
|
36
|
+
newItemMode: "draft-only",
|
|
37
|
+
newItemMethod: options?.method,
|
|
38
|
+
draftInitialValue: options?.initialDraftValue
|
|
39
|
+
});
|
|
40
|
+
onAdd?.(index);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
activeItemManager.setActiveItem(index, true, { newItemMode: "inserted" });
|
|
34
44
|
onAdd?.(index);
|
|
35
45
|
};
|
|
36
46
|
const handleSaveClick = (itemIndex, nextValue) => {
|
|
47
|
+
if (activeItemManager.isNew && activeItemManager.newItemMode === "draft-only") {
|
|
48
|
+
if ((activeItemManager.newItemMethod ?? "push") === "unshift") field.unshift?.(nextValue).catch(console.error);
|
|
49
|
+
else field.push?.(nextValue).catch(console.error);
|
|
50
|
+
activeItemManager.removeActiveItem(itemIndex);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
37
53
|
setArrayItemValue(field, itemIndex, nextValue);
|
|
38
54
|
activeItemManager.removeActiveItem(itemIndex);
|
|
39
55
|
};
|
|
@@ -41,7 +57,7 @@ function useArrayEditor(props) {
|
|
|
41
57
|
setArrayItemValue(field, itemIndex, nextValue);
|
|
42
58
|
};
|
|
43
59
|
const handleCancelClick = (itemIndex) => {
|
|
44
|
-
if (!autoSave && activeItemManager.isNewItem(itemIndex)) field.remove?.(itemIndex).catch(console.error);
|
|
60
|
+
if (!autoSave && activeItemManager.isNewItem(itemIndex) && activeItemManager.newItemMode !== "draft-only") field.remove?.(itemIndex).catch(console.error);
|
|
45
61
|
activeItemManager.removeActiveItem(itemIndex);
|
|
46
62
|
};
|
|
47
63
|
return {
|
|
@@ -5,14 +5,16 @@ let __formily_core = require("@formily/core");
|
|
|
5
5
|
__formily_core = require_rolldown_runtime.__toESM(__formily_core);
|
|
6
6
|
|
|
7
7
|
//#region src/components/array-common/use-array-item-draft-form.ts
|
|
8
|
-
function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange }) {
|
|
8
|
+
function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange, initialDraftValue }) {
|
|
9
9
|
const onDraftChangeRef = react.default.useRef(onDraftChange);
|
|
10
10
|
react.default.useEffect(() => {
|
|
11
11
|
onDraftChangeRef.current = onDraftChange;
|
|
12
12
|
}, [onDraftChange]);
|
|
13
13
|
return react.default.useMemo(() => {
|
|
14
14
|
const arrayValue = arrayField.value;
|
|
15
|
-
const
|
|
15
|
+
const hasArray = Array.isArray(arrayValue);
|
|
16
|
+
const arrayLength = hasArray ? arrayValue.length : 0;
|
|
17
|
+
const currentItemValue = index != null && hasArray && index >= 0 && index < arrayLength ? arrayValue[index] : initialDraftValue;
|
|
16
18
|
let didSkipInitial = false;
|
|
17
19
|
return (0, __formily_core.createForm)({
|
|
18
20
|
values: { draft: currentItemValue },
|
|
@@ -31,7 +33,8 @@ function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange }) {
|
|
|
31
33
|
arrayField.value,
|
|
32
34
|
index,
|
|
33
35
|
autoSave,
|
|
34
|
-
onDraftChange
|
|
36
|
+
onDraftChange,
|
|
37
|
+
initialDraftValue
|
|
35
38
|
]);
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -2,14 +2,16 @@ import React from "react";
|
|
|
2
2
|
import { createForm, onFormValuesChange } from "@formily/core";
|
|
3
3
|
|
|
4
4
|
//#region src/components/array-common/use-array-item-draft-form.ts
|
|
5
|
-
function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange }) {
|
|
5
|
+
function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange, initialDraftValue }) {
|
|
6
6
|
const onDraftChangeRef = React.useRef(onDraftChange);
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
onDraftChangeRef.current = onDraftChange;
|
|
9
9
|
}, [onDraftChange]);
|
|
10
10
|
return React.useMemo(() => {
|
|
11
11
|
const arrayValue = arrayField.value;
|
|
12
|
-
const
|
|
12
|
+
const hasArray = Array.isArray(arrayValue);
|
|
13
|
+
const arrayLength = hasArray ? arrayValue.length : 0;
|
|
14
|
+
const currentItemValue = index != null && hasArray && index >= 0 && index < arrayLength ? arrayValue[index] : initialDraftValue;
|
|
13
15
|
let didSkipInitial = false;
|
|
14
16
|
return createForm({
|
|
15
17
|
values: { draft: currentItemValue },
|
|
@@ -28,7 +30,8 @@ function useArrayItemDraftForm({ arrayField, index, autoSave, onDraftChange }) {
|
|
|
28
30
|
arrayField.value,
|
|
29
31
|
index,
|
|
30
32
|
autoSave,
|
|
31
|
-
onDraftChange
|
|
33
|
+
onDraftChange,
|
|
34
|
+
initialDraftValue
|
|
32
35
|
]);
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_use_array_item_draft_form = require('./use-array-item-draft-form.cjs');
|
|
3
|
+
const require_use_array_item_edit_labels = require('./use-array-item-edit-labels.cjs');
|
|
4
|
+
const require_use_edit_handlers = require('./use-edit-handlers.cjs');
|
|
5
|
+
const require_use_shake_animation = require('./use-shake-animation.cjs');
|
|
6
|
+
let __formily_react = require("@formily/react");
|
|
7
|
+
__formily_react = require_rolldown_runtime.__toESM(__formily_react);
|
|
8
|
+
let react = require("react");
|
|
9
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
10
|
+
|
|
11
|
+
//#region src/components/array-common/use-array-item-edit-state.ts
|
|
12
|
+
function useArrayItemEditState({ schema, activeItemManager, onSave, onCancel, onAutoSave, autoSave }) {
|
|
13
|
+
const arrayField = (0, __formily_react.useField)();
|
|
14
|
+
const activeIndex = activeItemManager.activeItem;
|
|
15
|
+
const isNewItem = activeItemManager.isNew;
|
|
16
|
+
const open = activeIndex !== void 0;
|
|
17
|
+
const normalizedAutoSave = autoSave === true || autoSave === "true";
|
|
18
|
+
const handleDraftChange = react.default.useCallback((nextValue) => {
|
|
19
|
+
if (!normalizedAutoSave) return;
|
|
20
|
+
if (activeIndex === void 0) return;
|
|
21
|
+
onAutoSave?.(activeIndex, nextValue);
|
|
22
|
+
}, [
|
|
23
|
+
activeIndex,
|
|
24
|
+
normalizedAutoSave,
|
|
25
|
+
onAutoSave
|
|
26
|
+
]);
|
|
27
|
+
const draftForm = require_use_array_item_draft_form.useArrayItemDraftForm({
|
|
28
|
+
arrayField,
|
|
29
|
+
index: activeIndex,
|
|
30
|
+
autoSave: normalizedAutoSave,
|
|
31
|
+
onDraftChange: normalizedAutoSave ? handleDraftChange : void 0,
|
|
32
|
+
initialDraftValue: activeItemManager.draftInitialValue
|
|
33
|
+
});
|
|
34
|
+
const isDirty = !normalizedAutoSave && draftForm.modified;
|
|
35
|
+
const { shouldShake, triggerShake } = require_use_shake_animation.useShakeAnimation();
|
|
36
|
+
const { handleSave, handleCancel } = require_use_edit_handlers.useEditHandlers({
|
|
37
|
+
itemIndex: activeIndex,
|
|
38
|
+
draftForm,
|
|
39
|
+
onSave,
|
|
40
|
+
onCancel
|
|
41
|
+
});
|
|
42
|
+
const { title, description } = require_use_array_item_edit_labels.useArrayItemEditLabels({
|
|
43
|
+
schema,
|
|
44
|
+
isNew: isNewItem,
|
|
45
|
+
autoSave: normalizedAutoSave,
|
|
46
|
+
itemIndex: activeIndex
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
arrayField,
|
|
50
|
+
activeIndex,
|
|
51
|
+
isNewItem,
|
|
52
|
+
open,
|
|
53
|
+
normalizedAutoSave,
|
|
54
|
+
draftForm,
|
|
55
|
+
isDirty,
|
|
56
|
+
title,
|
|
57
|
+
description,
|
|
58
|
+
shouldShake,
|
|
59
|
+
triggerShake,
|
|
60
|
+
handleSave,
|
|
61
|
+
handleCancel
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.useArrayItemEditState = useArrayItemEditState;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useArrayItemDraftForm } from "./use-array-item-draft-form.js";
|
|
2
|
+
import { useArrayItemEditLabels } from "./use-array-item-edit-labels.js";
|
|
3
|
+
import { useEditHandlers } from "./use-edit-handlers.js";
|
|
4
|
+
import { useShakeAnimation } from "./use-shake-animation.js";
|
|
5
|
+
import { useField } from "@formily/react";
|
|
6
|
+
import React from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/components/array-common/use-array-item-edit-state.ts
|
|
9
|
+
function useArrayItemEditState({ schema, activeItemManager, onSave, onCancel, onAutoSave, autoSave }) {
|
|
10
|
+
const arrayField = useField();
|
|
11
|
+
const activeIndex = activeItemManager.activeItem;
|
|
12
|
+
const isNewItem = activeItemManager.isNew;
|
|
13
|
+
const open = activeIndex !== void 0;
|
|
14
|
+
const normalizedAutoSave = autoSave === true || autoSave === "true";
|
|
15
|
+
const handleDraftChange = React.useCallback((nextValue) => {
|
|
16
|
+
if (!normalizedAutoSave) return;
|
|
17
|
+
if (activeIndex === void 0) return;
|
|
18
|
+
onAutoSave?.(activeIndex, nextValue);
|
|
19
|
+
}, [
|
|
20
|
+
activeIndex,
|
|
21
|
+
normalizedAutoSave,
|
|
22
|
+
onAutoSave
|
|
23
|
+
]);
|
|
24
|
+
const draftForm = useArrayItemDraftForm({
|
|
25
|
+
arrayField,
|
|
26
|
+
index: activeIndex,
|
|
27
|
+
autoSave: normalizedAutoSave,
|
|
28
|
+
onDraftChange: normalizedAutoSave ? handleDraftChange : void 0,
|
|
29
|
+
initialDraftValue: activeItemManager.draftInitialValue
|
|
30
|
+
});
|
|
31
|
+
const isDirty = !normalizedAutoSave && draftForm.modified;
|
|
32
|
+
const { shouldShake, triggerShake } = useShakeAnimation();
|
|
33
|
+
const { handleSave, handleCancel } = useEditHandlers({
|
|
34
|
+
itemIndex: activeIndex,
|
|
35
|
+
draftForm,
|
|
36
|
+
onSave,
|
|
37
|
+
onCancel
|
|
38
|
+
});
|
|
39
|
+
const { title, description } = useArrayItemEditLabels({
|
|
40
|
+
schema,
|
|
41
|
+
isNew: isNewItem,
|
|
42
|
+
autoSave: normalizedAutoSave,
|
|
43
|
+
itemIndex: activeIndex
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
arrayField,
|
|
47
|
+
activeIndex,
|
|
48
|
+
isNewItem,
|
|
49
|
+
open,
|
|
50
|
+
normalizedAutoSave,
|
|
51
|
+
draftForm,
|
|
52
|
+
isDirty,
|
|
53
|
+
title,
|
|
54
|
+
description,
|
|
55
|
+
shouldShake,
|
|
56
|
+
triggerShake,
|
|
57
|
+
handleSave,
|
|
58
|
+
handleCancel
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { useArrayItemEditState };
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_ArrayItemDraftFields = require('../array-common/ArrayItemDraftFields.cjs');
|
|
3
3
|
const require_ShakeStyles = require('../array-common/ShakeStyles.cjs');
|
|
4
|
-
const
|
|
5
|
-
const require_use_array_item_edit_labels = require('../array-common/use-array-item-edit-labels.cjs');
|
|
6
|
-
const require_use_edit_handlers = require('../array-common/use-edit-handlers.cjs');
|
|
7
|
-
const require_use_shake_animation = require('../array-common/use-shake-animation.cjs');
|
|
4
|
+
const require_use_array_item_edit_state = require('../array-common/use-array-item-edit-state.cjs');
|
|
8
5
|
let __formily_react = require("@formily/react");
|
|
9
6
|
__formily_react = require_rolldown_runtime.__toESM(__formily_react);
|
|
10
7
|
let react = require("react");
|
|
@@ -21,38 +18,13 @@ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
|
21
18
|
* RecursionField inherits component registry from parent SchemaField context (preserved through Radix Portal)
|
|
22
19
|
*/
|
|
23
20
|
const EditDialog = (0, __formily_react.observer)(({ schema, onSave, onAutoSave, onCancel, activeItemManager, autoSave, className,...rest }) => {
|
|
24
|
-
const
|
|
25
|
-
const itemIndex = activeItemManager.activeItem;
|
|
26
|
-
const { isNew } = activeItemManager;
|
|
27
|
-
const open = itemIndex !== void 0;
|
|
28
|
-
const handleDraftChange = react.default.useCallback((nextValue) => {
|
|
29
|
-
if (!autoSave) return;
|
|
30
|
-
if (itemIndex === void 0) return;
|
|
31
|
-
onAutoSave?.(itemIndex, nextValue);
|
|
32
|
-
}, [
|
|
33
|
-
itemIndex,
|
|
34
|
-
autoSave,
|
|
35
|
-
onAutoSave
|
|
36
|
-
]);
|
|
37
|
-
const draftForm = require_use_array_item_draft_form.useArrayItemDraftForm({
|
|
38
|
-
arrayField,
|
|
39
|
-
index: itemIndex,
|
|
40
|
-
autoSave,
|
|
41
|
-
onDraftChange: autoSave ? handleDraftChange : void 0
|
|
42
|
-
});
|
|
43
|
-
const isDirty = !autoSave && draftForm.modified;
|
|
44
|
-
const { shouldShake, triggerShake } = require_use_shake_animation.useShakeAnimation();
|
|
45
|
-
const { handleSave, handleCancel } = require_use_edit_handlers.useEditHandlers({
|
|
46
|
-
itemIndex,
|
|
47
|
-
draftForm,
|
|
48
|
-
onSave,
|
|
49
|
-
onCancel
|
|
50
|
-
});
|
|
51
|
-
const { title, description } = require_use_array_item_edit_labels.useArrayItemEditLabels({
|
|
21
|
+
const { activeIndex: itemIndex, open, normalizedAutoSave, draftForm, isDirty, title, description, shouldShake, triggerShake, handleSave, handleCancel } = require_use_array_item_edit_state.useArrayItemEditState({
|
|
52
22
|
schema,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
activeItemManager,
|
|
24
|
+
onSave,
|
|
25
|
+
onCancel,
|
|
26
|
+
onAutoSave,
|
|
27
|
+
autoSave
|
|
56
28
|
});
|
|
57
29
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.Dialog, {
|
|
58
30
|
open,
|
|
@@ -76,7 +48,7 @@ const EditDialog = (0, __formily_react.observer)(({ schema, onSave, onAutoSave,
|
|
|
76
48
|
form: draftForm,
|
|
77
49
|
className: (0, __pixpilot_shadcn_ui.cn)("grid gap-4 py-4")
|
|
78
50
|
}),
|
|
79
|
-
!
|
|
51
|
+
!normalizedAutoSave && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn_ui.DialogFooter, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn_ui.Button, {
|
|
80
52
|
type: "button",
|
|
81
53
|
variant: "outline",
|
|
82
54
|
onClick: handleCancel,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { ArrayItemDraftFields } from "../array-common/ArrayItemDraftFields.js";
|
|
2
2
|
import { ShakeStyles } from "../array-common/ShakeStyles.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useEditHandlers } from "../array-common/use-edit-handlers.js";
|
|
6
|
-
import { useShakeAnimation } from "../array-common/use-shake-animation.js";
|
|
7
|
-
import { observer, useField } from "@formily/react";
|
|
3
|
+
import { useArrayItemEditState } from "../array-common/use-array-item-edit-state.js";
|
|
4
|
+
import { observer } from "@formily/react";
|
|
8
5
|
import React from "react";
|
|
9
6
|
import { Button, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, cn } from "@pixpilot/shadcn-ui";
|
|
10
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -16,38 +13,13 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
16
13
|
* RecursionField inherits component registry from parent SchemaField context (preserved through Radix Portal)
|
|
17
14
|
*/
|
|
18
15
|
const EditDialog = observer(({ schema, onSave, onAutoSave, onCancel, activeItemManager, autoSave, className,...rest }) => {
|
|
19
|
-
const
|
|
20
|
-
const itemIndex = activeItemManager.activeItem;
|
|
21
|
-
const { isNew } = activeItemManager;
|
|
22
|
-
const open = itemIndex !== void 0;
|
|
23
|
-
const handleDraftChange = React.useCallback((nextValue) => {
|
|
24
|
-
if (!autoSave) return;
|
|
25
|
-
if (itemIndex === void 0) return;
|
|
26
|
-
onAutoSave?.(itemIndex, nextValue);
|
|
27
|
-
}, [
|
|
28
|
-
itemIndex,
|
|
29
|
-
autoSave,
|
|
30
|
-
onAutoSave
|
|
31
|
-
]);
|
|
32
|
-
const draftForm = useArrayItemDraftForm({
|
|
33
|
-
arrayField,
|
|
34
|
-
index: itemIndex,
|
|
35
|
-
autoSave,
|
|
36
|
-
onDraftChange: autoSave ? handleDraftChange : void 0
|
|
37
|
-
});
|
|
38
|
-
const isDirty = !autoSave && draftForm.modified;
|
|
39
|
-
const { shouldShake, triggerShake } = useShakeAnimation();
|
|
40
|
-
const { handleSave, handleCancel } = useEditHandlers({
|
|
41
|
-
itemIndex,
|
|
42
|
-
draftForm,
|
|
43
|
-
onSave,
|
|
44
|
-
onCancel
|
|
45
|
-
});
|
|
46
|
-
const { title, description } = useArrayItemEditLabels({
|
|
16
|
+
const { activeIndex: itemIndex, open, normalizedAutoSave, draftForm, isDirty, title, description, shouldShake, triggerShake, handleSave, handleCancel } = useArrayItemEditState({
|
|
47
17
|
schema,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
activeItemManager,
|
|
19
|
+
onSave,
|
|
20
|
+
onCancel,
|
|
21
|
+
onAutoSave,
|
|
22
|
+
autoSave
|
|
51
23
|
});
|
|
52
24
|
return /* @__PURE__ */ jsx(Dialog, {
|
|
53
25
|
open,
|
|
@@ -71,7 +43,7 @@ const EditDialog = observer(({ schema, onSave, onAutoSave, onCancel, activeItemM
|
|
|
71
43
|
form: draftForm,
|
|
72
44
|
className: cn("grid gap-4 py-4")
|
|
73
45
|
}),
|
|
74
|
-
!
|
|
46
|
+
!normalizedAutoSave && /* @__PURE__ */ jsxs(DialogFooter, { children: [/* @__PURE__ */ jsx(Button, {
|
|
75
47
|
type: "button",
|
|
76
48
|
variant: "outline",
|
|
77
49
|
onClick: handleCancel,
|
|
@@ -19,7 +19,7 @@ __pixpilot_shadcn = require_rolldown_runtime.__toESM(__pixpilot_shadcn);
|
|
|
19
19
|
//#region src/components/array-popover/ArrayPopover.tsx
|
|
20
20
|
const ArrayPopoverBase = (0, __formily_react.observer)((props) => {
|
|
21
21
|
const { onAdd, onRemove, onMoveDown, onMoveUp, onEdit, autoSave: autoSaveProp, className, children, transformActions, popoverProps,...rest } = props;
|
|
22
|
-
const autoSave = autoSaveProp
|
|
22
|
+
const autoSave = autoSaveProp === true;
|
|
23
23
|
const { activeItemManager, handleAdd, isNewItem, handleEdit, handleSaveClick, handleLiveChange, handleCancelClick } = require_use_array_editor.useArrayEditor({
|
|
24
24
|
onAdd,
|
|
25
25
|
onEdit,
|
|
@@ -14,7 +14,7 @@ import { cn } from "@pixpilot/shadcn";
|
|
|
14
14
|
//#region src/components/array-popover/ArrayPopover.tsx
|
|
15
15
|
const ArrayPopoverBase = observer((props) => {
|
|
16
16
|
const { onAdd, onRemove, onMoveDown, onMoveUp, onEdit, autoSave: autoSaveProp, className, children, transformActions, popoverProps,...rest } = props;
|
|
17
|
-
const autoSave = autoSaveProp
|
|
17
|
+
const autoSave = autoSaveProp === true;
|
|
18
18
|
const { activeItemManager, handleAdd, isNewItem, handleEdit, handleSaveClick, handleLiveChange, handleCancelClick } = useArrayEditor({
|
|
19
19
|
onAdd,
|
|
20
20
|
onEdit,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_ArrayItemDraftFields = require('../array-common/ArrayItemDraftFields.cjs');
|
|
3
3
|
const require_ShakeStyles = require('../array-common/ShakeStyles.cjs');
|
|
4
|
-
const
|
|
5
|
-
const require_use_array_item_edit_labels = require('../array-common/use-array-item-edit-labels.cjs');
|
|
6
|
-
const require_use_edit_handlers = require('../array-common/use-edit-handlers.cjs');
|
|
7
|
-
const require_use_shake_animation = require('../array-common/use-shake-animation.cjs');
|
|
4
|
+
const require_use_array_item_edit_state = require('../array-common/use-array-item-edit-state.cjs');
|
|
8
5
|
let __formily_react = require("@formily/react");
|
|
9
6
|
__formily_react = require_rolldown_runtime.__toESM(__formily_react);
|
|
10
7
|
let react = require("react");
|
|
@@ -18,33 +15,13 @@ react_dom = require_rolldown_runtime.__toESM(react_dom);
|
|
|
18
15
|
|
|
19
16
|
//#region src/components/array-popover/Popover.tsx
|
|
20
17
|
const ArrayItemsEditPopover = (0, __formily_react.observer)(({ schema, onSave, onAutoSave, onCancel, children, activeItemManager, autoSave, modal = true,...rest }) => {
|
|
21
|
-
const arrayField
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const open = activeIndex !== void 0;
|
|
25
|
-
const normalizedAutoSave = autoSave !== false && autoSave !== "false";
|
|
26
|
-
const handleDraftChange = react.default.useCallback((nextValue) => {
|
|
27
|
-
if (!normalizedAutoSave) return;
|
|
28
|
-
if (activeIndex === void 0) return;
|
|
29
|
-
onAutoSave?.(activeIndex, nextValue);
|
|
30
|
-
}, [
|
|
31
|
-
activeIndex,
|
|
32
|
-
normalizedAutoSave,
|
|
33
|
-
onAutoSave
|
|
34
|
-
]);
|
|
35
|
-
const draftForm = require_use_array_item_draft_form.useArrayItemDraftForm({
|
|
36
|
-
arrayField,
|
|
37
|
-
index: activeIndex,
|
|
38
|
-
autoSave: normalizedAutoSave,
|
|
39
|
-
onDraftChange: normalizedAutoSave ? handleDraftChange : void 0
|
|
40
|
-
});
|
|
41
|
-
const isDirty = !normalizedAutoSave && draftForm.modified;
|
|
42
|
-
const { shouldShake, triggerShake } = require_use_shake_animation.useShakeAnimation();
|
|
43
|
-
const { handleSave, handleCancel } = require_use_edit_handlers.useEditHandlers({
|
|
44
|
-
itemIndex: activeIndex,
|
|
45
|
-
draftForm,
|
|
18
|
+
const { arrayField, activeIndex, isNewItem, open, normalizedAutoSave, draftForm, isDirty, title, description, shouldShake, triggerShake, handleSave, handleCancel } = require_use_array_item_edit_state.useArrayItemEditState({
|
|
19
|
+
schema,
|
|
20
|
+
activeItemManager,
|
|
46
21
|
onSave,
|
|
47
|
-
onCancel
|
|
22
|
+
onCancel,
|
|
23
|
+
onAutoSave,
|
|
24
|
+
autoSave
|
|
48
25
|
});
|
|
49
26
|
const handleDiscard = react.default.useCallback(() => {
|
|
50
27
|
if (activeIndex === void 0) return;
|
|
@@ -75,19 +52,12 @@ const ArrayItemsEditPopover = (0, __formily_react.observer)(({ schema, onSave, o
|
|
|
75
52
|
isDirty,
|
|
76
53
|
triggerShake
|
|
77
54
|
]);
|
|
78
|
-
const handleOpenChange = react.default.useCallback((isOpen) => {
|
|
79
|
-
if (isOpen) return;
|
|
80
|
-
validateAndClose();
|
|
81
|
-
}, [validateAndClose]);
|
|
82
|
-
const { title, description } = require_use_array_item_edit_labels.useArrayItemEditLabels({
|
|
83
|
-
schema,
|
|
84
|
-
isNew: isNewItem,
|
|
85
|
-
autoSave: normalizedAutoSave,
|
|
86
|
-
itemIndex: activeIndex
|
|
87
|
-
});
|
|
88
55
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Popover, {
|
|
89
56
|
open,
|
|
90
|
-
onOpenChange:
|
|
57
|
+
onOpenChange: react.default.useCallback((isOpen) => {
|
|
58
|
+
if (isOpen) return;
|
|
59
|
+
validateAndClose();
|
|
60
|
+
}, [validateAndClose]),
|
|
91
61
|
modal,
|
|
92
62
|
children: [
|
|
93
63
|
children !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.PopoverTrigger, {
|