@silver-formily/element-plus 2.3.0 → 2.4.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 -21
- package/README.en-US.md +32 -32
- package/README.md +32 -32
- package/esm/__builtins__/configs/index.mjs.map +1 -1
- package/esm/__builtins__/index.mjs +12 -11
- package/esm/__builtins__/shared/index.mjs +11 -10
- package/esm/__builtins__/shared/loading.mjs.map +1 -1
- package/esm/__builtins__/shared/simple-version-compare.mjs.map +1 -1
- package/esm/__builtins__/shared/transform-component.mjs.map +1 -1
- package/esm/__builtins__/shared/use-enter-submit.mjs.map +1 -1
- package/esm/__builtins__/shared/utils.d.ts +1 -0
- package/esm/__builtins__/shared/utils.mjs +23 -17
- package/esm/__builtins__/shared/utils.mjs.map +1 -1
- package/esm/array-base/index.mjs +56 -52
- package/esm/array-base/index.mjs.map +1 -1
- package/esm/array-base/symbols.mjs.map +1 -1
- package/esm/array-base/utils.d.ts +0 -1
- package/esm/array-base/utils.mjs +45 -46
- package/esm/array-base/utils.mjs.map +1 -1
- package/esm/array-cards/index.mjs +36 -33
- package/esm/array-cards/index.mjs.map +1 -1
- package/esm/array-collapse/index.mjs +39 -37
- package/esm/array-collapse/index.mjs.map +1 -1
- package/esm/array-collapse/utils.mjs +9 -2
- package/esm/array-collapse/utils.mjs.map +1 -1
- package/esm/array-items/index.mjs +38 -34
- package/esm/array-items/index.mjs.map +1 -1
- package/esm/array-list-tabs/index.mjs +38 -36
- package/esm/array-list-tabs/index.mjs.map +1 -1
- package/esm/array-list-tabs/utils.mjs +12 -5
- package/esm/array-list-tabs/utils.mjs.map +1 -1
- package/esm/array-table/index.mjs +63 -60
- package/esm/array-table/index.mjs.map +1 -1
- package/esm/array-table/utils.mjs +18 -11
- package/esm/array-table/utils.mjs.map +1 -1
- package/esm/array-tabs/index.mjs +28 -25
- package/esm/array-tabs/index.mjs.map +1 -1
- package/esm/autocomplete/index.mjs +24 -18
- package/esm/autocomplete/index.mjs.map +1 -1
- package/esm/cascader/index.mjs +22 -18
- package/esm/cascader/index.mjs.map +1 -1
- package/esm/checkbox/index.mjs +20 -16
- package/esm/checkbox/index.mjs.map +1 -1
- package/esm/color-picker/index.mjs +9 -6
- package/esm/color-picker/index.mjs.map +1 -1
- package/esm/color-picker-panel/index.mjs +9 -6
- package/esm/color-picker-panel/index.mjs.map +1 -1
- package/esm/date-picker/index.mjs +14 -11
- package/esm/date-picker/index.mjs.map +1 -1
- package/esm/date-picker/utils.mjs.map +1 -1
- package/esm/date-picker-panel/index.mjs +14 -11
- package/esm/date-picker-panel/index.mjs.map +1 -1
- package/esm/editable/editable.d.ts +2 -0
- package/esm/editable/index.d.ts +1 -0
- package/esm/editable/index.mjs +71 -66
- package/esm/editable/index.mjs.map +1 -1
- package/esm/form/form.mjs +6 -6
- package/esm/form/form.mjs.map +1 -1
- package/esm/form-button-group/form-button-group.d.ts +9 -0
- package/esm/form-button-group/index.d.ts +15 -0
- package/esm/form-button-group/index.mjs +47 -28
- package/esm/form-button-group/index.mjs.map +1 -1
- package/esm/form-button-group/utils.mjs +9 -2
- package/esm/form-button-group/utils.mjs.map +1 -1
- package/esm/form-collapse/index.mjs +21 -18
- package/esm/form-collapse/index.mjs.map +1 -1
- package/esm/form-collapse/utils.mjs.map +1 -1
- package/esm/form-dialog/index.mjs +22 -22
- package/esm/form-dialog/index.mjs.map +1 -1
- package/esm/form-drawer/index.mjs +21 -21
- package/esm/form-drawer/index.mjs.map +1 -1
- package/esm/form-grid/hooks.mjs.map +1 -1
- package/esm/form-grid/index.mjs +26 -22
- package/esm/form-grid/index.mjs.map +1 -1
- package/esm/form-item/index.d.ts +1 -0
- package/esm/form-item/index.mjs +102 -99
- package/esm/form-item/index.mjs.map +1 -1
- package/esm/form-item/types.d.ts +4 -0
- package/esm/form-item/utils.mjs.map +1 -1
- package/esm/form-layout/form-layout.mjs +14 -10
- package/esm/form-layout/form-layout.mjs.map +1 -1
- package/esm/form-layout/utils.mjs +23 -23
- package/esm/form-layout/utils.mjs.map +1 -1
- package/esm/form-step/index.mjs +30 -27
- package/esm/form-step/index.mjs.map +1 -1
- package/esm/form-step/utils.mjs.map +1 -1
- package/esm/form-tab/hooks.mjs.map +1 -1
- package/esm/form-tab/index.mjs +24 -22
- package/esm/form-tab/index.mjs.map +1 -1
- package/esm/form-tab/utils.mjs.map +1 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.mjs +82 -78
- package/esm/index.mjs.map +1 -1
- package/esm/input/index.mjs +30 -26
- package/esm/input/index.mjs.map +1 -1
- package/esm/input-number/index.mjs +11 -8
- package/esm/input-number/index.mjs.map +1 -1
- package/esm/input-tag/index.mjs +20 -16
- package/esm/input-tag/index.mjs.map +1 -1
- package/esm/mention/index.mjs +24 -20
- package/esm/mention/index.mjs.map +1 -1
- package/esm/pagination/components/jumper.mjs.map +1 -1
- package/esm/pagination/components/next.mjs.map +1 -1
- package/esm/pagination/components/pager.mjs.map +1 -1
- package/esm/pagination/components/prev.mjs.map +1 -1
- package/esm/pagination/components/total.mjs.map +1 -1
- package/esm/pagination/pagination.mjs.map +1 -1
- package/esm/password/index.mjs.map +1 -1
- package/esm/preview-text/index.mjs +57 -53
- package/esm/preview-text/index.mjs.map +1 -1
- package/esm/preview-text/utils.mjs.map +1 -1
- package/esm/query-form/default-components.d.ts +5 -0
- package/esm/query-form/default-components.mjs +47 -0
- package/esm/query-form/default-components.mjs.map +1 -0
- package/esm/query-form/hooks.d.ts +25 -0
- package/esm/query-form/hooks.mjs +29 -0
- package/esm/query-form/hooks.mjs.map +1 -0
- package/esm/query-form/index.d.ts +117 -0
- package/esm/query-form/index.mjs +337 -0
- package/esm/query-form/index.mjs.map +1 -0
- package/esm/query-form/query-form-light.d.ts +27 -0
- package/esm/query-form/query-form.d.ts +52 -0
- package/esm/query-form/types.d.ts +44 -0
- package/esm/query-form/types.mjs +2 -0
- package/esm/query-form/types.mjs.map +1 -0
- package/esm/query-form-item/index.d.ts +151 -0
- package/esm/query-form-item/index.mjs +188 -0
- package/esm/query-form-item/index.mjs.map +1 -0
- package/esm/query-form-item/query-form-item.d.ts +96 -0
- package/esm/query-form-item/types.d.ts +46 -0
- package/esm/query-form-item/types.mjs +2 -0
- package/esm/query-form-item/types.mjs.map +1 -0
- package/esm/radio/index.mjs +29 -25
- package/esm/radio/index.mjs.map +1 -1
- package/esm/rate/index.mjs +13 -10
- package/esm/rate/index.mjs.map +1 -1
- package/esm/reset/index.mjs.map +1 -1
- package/esm/segmented/index.mjs +16 -12
- package/esm/segmented/index.mjs.map +1 -1
- package/esm/select/index.mjs +26 -22
- package/esm/select/index.mjs.map +1 -1
- package/esm/select-table/index.mjs +36 -33
- package/esm/select-table/index.mjs.map +1 -1
- package/esm/shared/overlay-elements.mjs +14 -11
- package/esm/shared/overlay-elements.mjs.map +1 -1
- package/esm/slider/index.mjs +13 -10
- package/esm/slider/index.mjs.map +1 -1
- package/esm/styles/form-button-group/index.css +1 -1
- package/esm/styles/form-item/index.css +1 -1
- package/esm/styles/query-form/index.css +1 -0
- package/esm/styles/query-form-item/index.css +1 -0
- package/esm/submit/index.mjs.map +1 -1
- package/esm/switch/index.mjs.map +1 -1
- package/esm/time-picker/index.mjs +9 -6
- package/esm/time-picker/index.mjs.map +1 -1
- package/esm/time-select/index.mjs +9 -6
- package/esm/time-select/index.mjs.map +1 -1
- package/esm/transfer/index.mjs.map +1 -1
- package/esm/tree/index.mjs +33 -29
- package/esm/tree/index.mjs.map +1 -1
- package/esm/tree/utils.mjs.map +1 -1
- package/esm/tree-select/index.mjs +18 -14
- package/esm/tree-select/index.mjs.map +1 -1
- package/esm/upload/index.mjs +10 -7
- package/esm/upload/index.mjs.map +1 -1
- package/esm/vendor/lodash.mjs +751 -663
- package/esm/vendor/lodash.mjs.map +1 -1
- package/esm/vendor/sizes.mjs.map +1 -1
- package/package.json +115 -115
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { connect as e, mapProps as t } from "@silver-formily/vue";
|
|
2
2
|
import { ElTimeSelect as m } from "element-plus";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
3
|
+
import "@formily/reactive";
|
|
4
|
+
import "@vueuse/core";
|
|
5
|
+
import "vue";
|
|
6
|
+
import { mapReadPretty as o } from "../__builtins__/shared/transform-component.mjs";
|
|
7
|
+
import { PreviewText as r } from "../preview-text/index.mjs";
|
|
8
|
+
const s = e(
|
|
6
9
|
m,
|
|
7
10
|
t({ disabled: "disabled", editable: "editable" }),
|
|
8
|
-
r
|
|
11
|
+
o(r.Input)
|
|
9
12
|
);
|
|
10
13
|
export {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
s as TimeSelect,
|
|
15
|
+
s as default
|
|
13
16
|
};
|
|
14
17
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/time-select/index.ts"],"sourcesContent":["import { connect, mapProps } from '@silver-formily/vue'\r\nimport { ElTimeSelect } from 'element-plus'\r\nimport { mapReadPretty } from '../__builtins__'\r\nimport { PreviewText } from '../preview-text'\r\n\r\nexport const TimeSelect = connect<typeof ElTimeSelect>(\n ElTimeSelect,\n mapProps({ disabled: 'disabled', editable: 'editable' }),\r\n mapReadPretty(PreviewText.Input),\r\n)\r\n\r\nexport default TimeSelect\r\n"],"names":["TimeSelect","connect","ElTimeSelect","mapProps","mapReadPretty","PreviewText"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/time-select/index.ts"],"sourcesContent":["import { connect, mapProps } from '@silver-formily/vue'\r\nimport { ElTimeSelect } from 'element-plus'\r\nimport { mapReadPretty } from '../__builtins__'\r\nimport { PreviewText } from '../preview-text'\r\n\r\nexport const TimeSelect = connect<typeof ElTimeSelect>(\n ElTimeSelect,\n mapProps({ disabled: 'disabled', editable: 'editable' }),\r\n mapReadPretty(PreviewText.Input),\r\n)\r\n\r\nexport default TimeSelect\r\n"],"names":["TimeSelect","connect","ElTimeSelect","mapProps","mapReadPretty","PreviewText"],"mappings":";;;;;;;AAKO,MAAMA,IAAaC;AAAA,EACxBC;AAAA,EACAC,EAAS,EAAE,UAAU,YAAY,UAAU,YAAY;AAAA,EACvDC,EAAcC,EAAY,KAAK;AACjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/transfer/index.ts"],"sourcesContent":["import { connect, mapProps } from '@silver-formily/vue'\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/transfer/index.ts"],"sourcesContent":["import { connect, mapProps } from '@silver-formily/vue'\nimport { ElTransfer } from 'element-plus'\n\nexport type TransferProps = typeof ElTransfer\n\nexport const Transfer = connect<typeof ElTransfer>(\n ElTransfer,\n mapProps({ dataSource: 'data' }),\n)\n\nexport default Transfer\n"],"names":["Transfer","connect","ElTransfer","mapProps"],"mappings":";;AAKO,MAAMA,IAAWC;AAAA,EACtBC;AAAA,EACAC,EAAS,EAAE,YAAY,OAAA,CAAQ;AACjC;"}
|
package/esm/tree/index.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { useField as _, connect as A, mapProps as D } from "@silver-formily/vue";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
2
|
+
import { ElScrollbar as H, ElTree as P, vLoading as R } from "element-plus";
|
|
3
|
+
import "@formily/reactive";
|
|
4
|
+
import "@vueuse/core";
|
|
5
|
+
import { defineComponent as w, useSlots as F, ref as h, computed as y, watch as v, nextTick as k, createBlock as g, openBlock as C, unref as a, withCtx as T, withDirectives as B, mergeProps as E, createSlots as L, renderList as j, renderSlot as z, normalizeProps as I, guardReactiveProps as N } from "vue";
|
|
6
|
+
import { mapReadPretty as O } from "../__builtins__/shared/transform-component.mjs";
|
|
7
|
+
import { PreviewText as $ } from "../preview-text/index.mjs";
|
|
8
|
+
import { isFn as q } from "@formily/shared";
|
|
9
|
+
import "@formily/core";
|
|
10
|
+
import "@silver-formily/reactive-vue";
|
|
11
|
+
import { useCleanAttrs as G } from "../__builtins__/shared/utils.mjs";
|
|
12
|
+
import { addDisabledToNodes as J, flattenTree as M, getInputKeys as Q, getOutputData as U } from "./utils.mjs";
|
|
13
|
+
const W = /* @__PURE__ */ w({
|
|
10
14
|
name: "Tree",
|
|
11
15
|
inheritAttrs: !1,
|
|
12
16
|
__name: "tree",
|
|
@@ -28,13 +32,13 @@ const W = /* @__PURE__ */ P({
|
|
|
28
32
|
},
|
|
29
33
|
emits: ["update:modelValue"],
|
|
30
34
|
setup(K, { emit: V }) {
|
|
31
|
-
const e = K,
|
|
32
|
-
async function
|
|
35
|
+
const e = K, i = V, b = F(), { props: l } = G(), o = h(), d = h([]), n = y(() => J(e.data ?? [], l.value.disabled, e.props)), p = y(() => M(n.value ?? [], [], e.props.children));
|
|
36
|
+
async function c() {
|
|
33
37
|
await k();
|
|
34
38
|
const t = o.value.getCheckedKeys(), f = o.value.getHalfCheckedKeys() || [];
|
|
35
39
|
d.value = t;
|
|
36
|
-
const { value: m, nodes: r } =
|
|
37
|
-
flatData:
|
|
40
|
+
const { value: m, nodes: r } = U(t, f, {
|
|
41
|
+
flatData: p.value,
|
|
38
42
|
nodeKey: e.nodeKey,
|
|
39
43
|
propsConfig: e.props,
|
|
40
44
|
data: e.data ?? [],
|
|
@@ -42,13 +46,13 @@ const W = /* @__PURE__ */ P({
|
|
|
42
46
|
includeHalfChecked: e.includeHalfChecked,
|
|
43
47
|
checkStrictly: l.value.checkStrictly
|
|
44
48
|
});
|
|
45
|
-
e.optionAsValue ?
|
|
49
|
+
e.optionAsValue ? q(e.optionFormatter) ? i("update:modelValue", r.map((s, x, S) => e.optionFormatter(s, x, S))) : i("update:modelValue", r) : i("update:modelValue", m);
|
|
46
50
|
}
|
|
47
51
|
v(() => e.modelValue, (t) => {
|
|
48
|
-
t !== void 0 && (d.value =
|
|
52
|
+
t !== void 0 && (d.value = Q(t, {
|
|
49
53
|
optionAsValue: e.optionAsValue,
|
|
50
54
|
nodeKey: e.nodeKey,
|
|
51
|
-
flatData:
|
|
55
|
+
flatData: p.value,
|
|
52
56
|
propsConfig: e.props,
|
|
53
57
|
data: e.data ?? [],
|
|
54
58
|
valueType: e.valueType,
|
|
@@ -57,17 +61,17 @@ const W = /* @__PURE__ */ P({
|
|
|
57
61
|
o.value && o.value.setCheckedKeys(d.value);
|
|
58
62
|
}));
|
|
59
63
|
}, { immediate: !0 }), v(() => [e.valueType, e.optionAsValue, e.includeHalfChecked], () => {
|
|
60
|
-
|
|
64
|
+
c();
|
|
61
65
|
}, { immediate: !1 });
|
|
62
|
-
const
|
|
63
|
-
return
|
|
66
|
+
const u = _();
|
|
67
|
+
return u.value?.inject({
|
|
64
68
|
getTreeRef: () => o
|
|
65
|
-
}), (t, f) => (C(), g(a(
|
|
69
|
+
}), (t, f) => (C(), g(a(H), {
|
|
66
70
|
height: e.height,
|
|
67
71
|
"max-height": e.maxHeight
|
|
68
72
|
}, {
|
|
69
73
|
default: T(() => [
|
|
70
|
-
|
|
74
|
+
B((C(), g(a(P), E({
|
|
71
75
|
ref_key: "treeRef",
|
|
72
76
|
ref: o,
|
|
73
77
|
data: n.value,
|
|
@@ -75,27 +79,27 @@ const W = /* @__PURE__ */ P({
|
|
|
75
79
|
"node-key": e.nodeKey,
|
|
76
80
|
"default-checked-keys": d.value,
|
|
77
81
|
"show-checkbox": !0
|
|
78
|
-
}, a(l), { onCheck:
|
|
79
|
-
|
|
82
|
+
}, a(l), { onCheck: c }), L({ _: 2 }, [
|
|
83
|
+
j(a(b), (m, r) => ({
|
|
80
84
|
name: r,
|
|
81
|
-
fn: T((
|
|
82
|
-
|
|
85
|
+
fn: T((s) => [
|
|
86
|
+
z(t.$slots, r, I(N({ field: a(u), ...s })))
|
|
83
87
|
])
|
|
84
88
|
}))
|
|
85
89
|
]), 1040, ["data", "props", "node-key", "default-checked-keys"])), [
|
|
86
|
-
[a(
|
|
90
|
+
[a(R), a(l).loading]
|
|
87
91
|
])
|
|
88
92
|
]),
|
|
89
93
|
_: 3
|
|
90
94
|
}, 8, ["height", "max-height"]));
|
|
91
95
|
}
|
|
92
|
-
}),
|
|
96
|
+
}), ne = A(
|
|
93
97
|
W,
|
|
94
98
|
D({ dataSource: "data", loading: "loading", disabled: !0 }),
|
|
95
|
-
|
|
99
|
+
O($.Tree)
|
|
96
100
|
);
|
|
97
101
|
export {
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
ne as Tree,
|
|
103
|
+
ne as default
|
|
100
104
|
};
|
|
101
105
|
//# sourceMappingURL=index.mjs.map
|
package/esm/tree/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/tree/tree.vue","../../src/tree/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/tree/tree.vue","../../src/tree/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { Field } from '@formily/core'\nimport type { TreeValueTypeProps } from './types'\nimport { isFn } from '@formily/shared'\nimport { useField } from '@silver-formily/vue'\nimport { ElScrollbar, ElTree, vLoading } from 'element-plus'\nimport { computed, nextTick, ref, useSlots, watch } from 'vue'\nimport { useCleanAttrs } from '../__builtins__'\nimport { addDisabledToNodes, flattenTree, getInputKeys, getOutputData } from './utils'\n\ndefineOptions({\n name: 'Tree',\n inheritAttrs: false,\n})\n\nconst props = withDefaults(defineProps<TreeValueTypeProps>(), {\n valueType: 'all',\n optionAsValue: false,\n includeHalfChecked: false,\n props: {\n children: 'children',\n label: 'label',\n disabled: 'disabled',\n },\n})\n\nconst emit = defineEmits<{\n 'update:modelValue': [value: any]\n}>()\n\nconst slots = useSlots()\n\nconst { props: attrs } = useCleanAttrs()\nconst treeRef = ref<InstanceType<typeof ElTree>>()\nconst checkedKeys = ref<any[]>([])\n\nconst processedData = computed(() => {\n return addDisabledToNodes(props.data ?? [], attrs.value.disabled, props.props)\n})\n\nconst flatData = computed(() => flattenTree(processedData.value ?? [], [], props.props.children))\n\nasync function handleCheck() {\n await nextTick()\n const keys = treeRef.value.getCheckedKeys()\n const halfCheckedKeys = treeRef.value.getHalfCheckedKeys() || []\n checkedKeys.value = keys\n\n const { value, nodes } = getOutputData(keys, halfCheckedKeys, {\n flatData: flatData.value,\n nodeKey: props.nodeKey,\n propsConfig: props.props,\n data: props.data ?? [],\n valueType: props.valueType,\n includeHalfChecked: props.includeHalfChecked,\n checkStrictly: attrs.value.checkStrictly,\n })\n\n if (props.optionAsValue) {\n isFn(props.optionFormatter)\n ? emit('update:modelValue', nodes.map((element, index, array) => {\n return props.optionFormatter(element, index, array)\n }))\n : emit('update:modelValue', nodes)\n }\n else {\n emit('update:modelValue', value)\n }\n}\n\nwatch(() => props.modelValue, (newValue) => {\n if (newValue !== undefined) {\n checkedKeys.value = getInputKeys(newValue, {\n optionAsValue: props.optionAsValue,\n nodeKey: props.nodeKey,\n flatData: flatData.value,\n propsConfig: props.props,\n data: props.data ?? [],\n valueType: props.valueType,\n checkStrictly: attrs.value.checkStrictly,\n })\n nextTick(() => {\n if (treeRef.value) {\n treeRef.value.setCheckedKeys(checkedKeys.value)\n }\n })\n }\n}, { immediate: true })\n\nwatch(() => [props.valueType, props.optionAsValue, props.includeHalfChecked], () => {\n handleCheck()\n}, { immediate: false })\n\nconst fieldRef = useField<Field>()\nfieldRef.value?.inject({\n getTreeRef: () => {\n return treeRef\n },\n})\n</script>\n\n<template>\n <ElScrollbar :height=\"props.height\" :max-height=\"props.maxHeight\">\n <ElTree\n ref=\"treeRef\"\n v-loading=\"attrs.loading\"\n :data=\"processedData\"\n :props=\"props.props\"\n :node-key=\"props.nodeKey\"\n :default-checked-keys=\"checkedKeys\"\n :show-checkbox=\"true\"\n v-bind=\"attrs\"\n @check=\"handleCheck\"\n >\n <template v-for=\"(_, name) of slots\" #[name]=\"slotData\">\n <slot :name=\"name\" v-bind=\"{ field: fieldRef, ...slotData }\" />\n </template>\n </ElTree>\n </ElScrollbar>\n</template>\n","import { connect, mapProps } from '@silver-formily/vue'\nimport { mapReadPretty } from '../__builtins__'\nimport { PreviewText } from '../preview-text'\nimport InnerTree from './tree.vue'\n\nconst Tree = connect<typeof InnerTree>(\n InnerTree,\n mapProps({ dataSource: 'data', loading: 'loading', disabled: true }),\n mapReadPretty(PreviewText.Tree),\n)\n\nexport { Tree }\n\nexport default Tree\n"],"names":["props","__props","emit","__emit","slots","useSlots","attrs","useCleanAttrs","treeRef","ref","checkedKeys","processedData","computed","addDisabledToNodes","flatData","flattenTree","handleCheck","nextTick","keys","halfCheckedKeys","value","nodes","getOutputData","isFn","element","index","array","watch","newValue","getInputKeys","fieldRef","useField","_createBlock","_unref","ElScrollbar","_withDirectives","_openBlock","_mergeProps","_createSlots","_","name","_withCtx","slotData","_renderSlot","_ctx","_normalizeProps","_guardReactiveProps","vLoading","Tree","connect","InnerTree","mapProps","mapReadPretty","PreviewText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,UAAMA,IAAQC,GAWRC,IAAOC,GAIPC,IAAQC,EAAA,GAER,EAAE,OAAOC,EAAA,IAAUC,EAAA,GACnBC,IAAUC,EAAA,GACVC,IAAcD,EAAW,EAAE,GAE3BE,IAAgBC,EAAS,MACtBC,EAAmBb,EAAM,QAAQ,CAAA,GAAIM,EAAM,MAAM,UAAUN,EAAM,KAAK,CAC9E,GAEKc,IAAWF,EAAS,MAAMG,EAAYJ,EAAc,SAAS,CAAA,GAAI,IAAIX,EAAM,MAAM,QAAQ,CAAC;AAEhG,mBAAegB,IAAc;AAC3B,YAAMC,EAAA;AACN,YAAMC,IAAOV,EAAQ,MAAM,eAAA,GACrBW,IAAkBX,EAAQ,MAAM,mBAAA,KAAwB,CAAA;AAC9D,MAAAE,EAAY,QAAQQ;AAEpB,YAAM,EAAE,OAAAE,GAAO,OAAAC,EAAA,IAAUC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AAA,MAAS,cAAYA,EAAM;AAAA,IAAA;iBACrD,MAcS;AAAA,QAdTmC,GAAAC,EAAA,GAAAJ,EAcSC,MAdTI,EAcS;AAAA,mBAbH;AAAA,UAAJ,KAAI7B;AAAA,UAEH,MAAMG,EAAA;AAAA,UACN,OAAOX,EAAM;AAAA,UACb,YAAUA,EAAM;AAAA,UAChB,wBAAsBU,EAAA;AAAA,UACtB,iBAAe;AAAA,QAAA,GACRuB,EAAA3B,CAAA,GAAK,EACZ,SAAOU,GAAW,GAAAsB,EAAA,EAAA,GAAA,KAAA;AAAA,YAEWL,EAAA7B,CAAA,GAAK,CAAjBmC,GAAGC;;YACnB,IAAAC,EAAA,CAD4CC,MAAQ;AAAA,cACpDC,EAA+DC,EAAA,QAAlDJ,GAAIK,EAAAC,EAAA,EAAA,OAAmBb,EAAAH,CAAA,MAAaY,EAAA,CAAQ,CAAA,CAAA;AAAA,YAAA;;;UAVhD,CAAAT,EAAAc,CAAA,GAAAd,EAAA3B,CAAA,EAAM,OAAO;AAAA,QAAA;;;;;ICpGxB0C,KAAOC;AAAA,EACXC;AAAAA,EACAC,EAAS,EAAE,YAAY,QAAQ,SAAS,WAAW,UAAU,IAAM;AAAA,EACnEC,EAAcC,EAAY,IAAI;AAChC;"}
|
package/esm/tree/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/tree/utils.ts"],"sourcesContent":["import type { TreeNodeData } from 'element-plus'\r\n\r\nexport function flattenTree(nodes: TreeNodeData[], result: TreeNodeData[] = [], childrenKey = 'children'): TreeNodeData[] {\r\n for (const node of nodes) {\r\n result.push(node)\r\n if (node[childrenKey] && node[childrenKey].length > 0) {\r\n flattenTree(node[childrenKey], result, childrenKey)\r\n }\r\n }\r\n return result\r\n}\r\n\r\nexport function addDisabledToNodes(nodes: TreeNodeData[], disabled: boolean, propsConfig: any): TreeNodeData[] {\r\n if (!disabled) {\r\n return nodes\r\n }\r\n\r\n return nodes.map((node) => {\r\n const newNode = { ...node }\r\n newNode[propsConfig.disabled!] = true\r\n\r\n if (node[propsConfig.children!] && node[propsConfig.children!].length > 0) {\r\n newNode[propsConfig.children!] = addDisabledToNodes(node[propsConfig.children!], disabled, propsConfig)\r\n }\r\n\r\n return newNode\r\n })\r\n}\r\n\r\nexport function traverseTree(\r\n nodes: TreeNodeData[],\r\n callback: (node: TreeNodeData) => void,\r\n options: {\r\n leafOnly?: boolean\r\n childrenKey?: string\r\n } = {},\r\n) {\r\n const { leafOnly = false, childrenKey = 'children' } = options\r\n\r\n for (const node of nodes) {\r\n const children = node[childrenKey] || []\r\n const isLeaf = children.length === 0\r\n\r\n if (!leafOnly || isLeaf) {\r\n callback(node)\r\n }\r\n if (children.length > 0) {\r\n traverseTree(children, callback, options)\r\n }\r\n }\r\n}\r\n\r\nexport function getChildrenKeys(node: TreeNodeData, nodeKey: string, propsConfig: any): any[] {\r\n const children = node[propsConfig.children!] || []\r\n if (children.length === 0)\r\n return []\r\n\r\n const keys: any[] = []\r\n traverseTree(children, (child) => {\r\n keys.push(child[nodeKey])\r\n }, { childrenKey: propsConfig.children })\r\n\r\n return keys\r\n}\r\n\r\nexport function extractKeysFromPath(pathNodes: TreeNodeData[], nodeKey: string, propsConfig: any): any[] {\r\n const keys: any[] = []\r\n traverseTree(pathNodes, (node) => {\r\n keys.push(node[nodeKey])\r\n }, { leafOnly: true, childrenKey: propsConfig.children })\r\n\r\n return keys\r\n}\r\n\r\nexport function getSelectedPath(nodes: TreeNodeData[], selectedKeys: any[], nodeKey: string, propsConfig: any): TreeNodeData[] {\r\n const result: TreeNodeData[] = []\r\n\r\n for (const node of nodes) {\r\n const children = node[propsConfig.children!] || []\r\n const hasSelectedChild = children.length > 0\r\n ? getSelectedPath(children, selectedKeys, nodeKey, propsConfig).length > 0\r\n : false\r\n\r\n if (selectedKeys.includes(node[nodeKey]) || hasSelectedChild) {\r\n const newNode = { ...node }\r\n if (hasSelectedChild && children.length > 0) {\r\n newNode[propsConfig.children!] = getSelectedPath(children, selectedKeys, nodeKey, propsConfig)\r\n }\r\n result.push(newNode)\r\n }\r\n }\r\n\r\n return result\r\n}\r\n\r\n/**\r\n * 查找节点的所有父节点路径\r\n */\r\nexport function findParents(nodes: TreeNodeData[], targetKey: any, nodeKey: string, propsConfig: any, parents: any[] = []): any[] {\r\n for (const node of nodes) {\r\n const currentPath = [...parents, node[nodeKey]]\r\n\r\n if (node[nodeKey] === targetKey) {\r\n return currentPath\r\n }\r\n\r\n const children = node[propsConfig.children!] || []\r\n if (children.length > 0) {\r\n const found = findParents(children, targetKey, nodeKey, propsConfig, currentPath)\r\n if (found.length > 0) {\r\n return found\r\n }\r\n }\r\n }\r\n /* istanbul ignore next -- @preserve */\r\n return []\r\n}\r\n\r\n/**\r\n * 过滤叶子节点\r\n */\r\nexport function filterLeafNodes(keys: any[], flatData: TreeNodeData[], nodeKey: string, propsConfig: any): any[] {\r\n return keys.filter((key) => {\r\n const node = flatData.find(n => n[nodeKey] === key)\r\n if (!node)\r\n return false\r\n const children = node[propsConfig.children!] || []\r\n return children.length === 0\r\n })\r\n}\r\n\r\n/**\r\n * 获取输出数据\r\n */\r\nexport function getOutputData(\r\n keys: any[],\r\n halfCheckedKeys: any[] = [],\r\n options: {\r\n flatData: TreeNodeData[]\r\n nodeKey: string\r\n propsConfig: any\r\n data: TreeNodeData[]\r\n valueType: string\r\n includeHalfChecked: boolean\r\n checkStrictly: boolean\r\n },\r\n) {\r\n const { flatData, nodeKey, propsConfig, data, valueType, includeHalfChecked, checkStrictly } = options\r\n\r\n const selectedNodes = flatData.filter(node =>\r\n keys.includes(node[nodeKey]),\r\n )\r\n\r\n let outputKeys = [...keys]\r\n let outputNodes = [...selectedNodes]\r\n\r\n if (checkStrictly) {\r\n return {\r\n value: outputKeys,\r\n nodes: outputNodes,\r\n }\r\n }\r\n\r\n switch (valueType) {\r\n case 'parent': {\r\n const allChildKeys: any[] = []\r\n for (const node of selectedNodes) {\r\n allChildKeys.push(...getChildrenKeys(node, nodeKey, propsConfig))\r\n }\r\n outputKeys = keys.filter(key => !allChildKeys.includes(key))\r\n outputNodes = selectedNodes.filter(node =>\r\n outputKeys.includes(node[nodeKey]),\r\n )\r\n break\r\n }\r\n\r\n case 'child': {\r\n for (const node of selectedNodes) {\r\n const childKeys = getChildrenKeys(node, nodeKey, propsConfig)\r\n const hasSelectedChild = childKeys.some(key => keys.includes(key))\r\n if (hasSelectedChild) {\r\n outputKeys = outputKeys.filter(key => key !== node[nodeKey])\r\n outputNodes = outputNodes.filter(n =>\r\n n[nodeKey] !== node[nodeKey],\r\n )\r\n }\r\n }\r\n break\r\n }\r\n\r\n case 'path': {\r\n const selectedPath = getSelectedPath(data, keys, nodeKey, propsConfig)\r\n return {\r\n value: selectedPath,\r\n nodes: selectedPath,\r\n }\r\n }\r\n\r\n default: { // 'all'\r\n if (includeHalfChecked && halfCheckedKeys.length > 0) {\r\n const halfCheckedNodes = flatData.filter(node =>\r\n halfCheckedKeys.includes(node[nodeKey]),\r\n )\r\n outputKeys = [...outputKeys, ...halfCheckedKeys]\r\n outputNodes = [...outputNodes, ...halfCheckedNodes]\r\n }\r\n break\r\n }\r\n }\r\n\r\n return {\r\n value: outputKeys,\r\n nodes: outputNodes,\r\n }\r\n}\r\n\r\n/**\r\n * 根据valueType将输入值转换为checkedKeys\r\n */\r\nexport function getInputKeys(\r\n inputValue: any,\r\n options: {\r\n optionAsValue: boolean\r\n nodeKey: string\r\n flatData: TreeNodeData[]\r\n propsConfig: any\r\n data: TreeNodeData[]\r\n valueType: string\r\n checkStrictly: boolean\r\n },\r\n): any[] {\r\n const { optionAsValue, nodeKey, flatData, propsConfig, data, valueType, checkStrictly } = options\r\n\r\n /* istanbul ignore if -- @preserve */\r\n if (!inputValue || !Array.isArray(inputValue))\r\n return []\r\n\r\n const valueArray = optionAsValue ? inputValue.map((item: any) => item[nodeKey]) : inputValue\r\n\r\n if (checkStrictly) {\r\n return valueArray\r\n }\r\n\r\n switch (valueType) {\r\n case 'parent': {\r\n const allKeys = [...valueArray]\r\n\r\n for (const key of valueArray) {\r\n const node = flatData.find(n => n[nodeKey] === key)\r\n if (node) {\r\n const childKeys = getChildrenKeys(node, nodeKey, propsConfig)\r\n allKeys.push(...childKeys)\r\n }\r\n }\r\n return filterLeafNodes(allKeys, flatData, nodeKey, propsConfig)\r\n }\r\n\r\n case 'child': {\r\n const allKeys = [...valueArray]\r\n for (const key of valueArray) {\r\n const parentPath = findParents(data, key, nodeKey, propsConfig)\r\n allKeys.push(...parentPath)\r\n }\r\n return filterLeafNodes(allKeys, flatData, nodeKey, propsConfig)\r\n }\r\n\r\n case 'path': {\r\n return extractKeysFromPath(valueArray, nodeKey, propsConfig)\r\n }\r\n\r\n default: { // 'all'\r\n return filterLeafNodes(valueArray, flatData, nodeKey, propsConfig)\r\n }\r\n }\r\n}\r\n"],"names":["flattenTree","nodes","result","childrenKey","node","addDisabledToNodes","disabled","propsConfig","newNode","traverseTree","callback","options","leafOnly","children","isLeaf","getChildrenKeys","nodeKey","keys","child","extractKeysFromPath","pathNodes","getSelectedPath","selectedKeys","hasSelectedChild","findParents","targetKey","parents","currentPath","found","filterLeafNodes","flatData","key","n","getOutputData","halfCheckedKeys","data","valueType","includeHalfChecked","checkStrictly","selectedNodes","outputKeys","outputNodes","allChildKeys","selectedPath","halfCheckedNodes","getInputKeys","inputValue","optionAsValue","valueArray","item","allKeys","childKeys","parentPath"],"mappings":"AAEO,SAASA,EAAYC,GAAuBC,IAAyB,CAAA,GAAIC,IAAc,YAA4B;AACxH,aAAWC,KAAQH;AACjB,IAAAC,EAAO,KAAKE,CAAI,GACZA,EAAKD,CAAW,KAAKC,EAAKD,CAAW,EAAE,SAAS,KAClDH,EAAYI,EAAKD,CAAW,GAAGD,GAAQC,CAAW;AAGtD,SAAOD;AACT;AAEO,SAASG,EAAmBJ,GAAuBK,GAAmBC,GAAkC;AAC7G,SAAKD,IAIEL,EAAM,IAAI,CAACG,MAAS;AACzB,UAAM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ST,CAAW;AAAA,IAChE;AAAA,IAEA,KAAK;AACH,aAAOY,EAAoB6B,GAAYhC,GAAST,CAAW;AAAA,IAG7D;AACE,aAAOsB,EAAgBmB,GAAYlB,GAAUd,GAAST,CAAW;AAAA,EACnE;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/tree/utils.ts"],"sourcesContent":["import type { TreeNodeData } from 'element-plus'\n\nexport function flattenTree(nodes: TreeNodeData[], result: TreeNodeData[] = [], childrenKey = 'children'): TreeNodeData[] {\n for (const node of nodes) {\n result.push(node)\n if (node[childrenKey] && node[childrenKey].length > 0) {\n flattenTree(node[childrenKey], result, childrenKey)\n }\n }\n return result\n}\n\nexport function addDisabledToNodes(nodes: TreeNodeData[], disabled: boolean, propsConfig: any): TreeNodeData[] {\n if (!disabled) {\n return nodes\n }\n\n return nodes.map((node) => {\n const newNode = { ...node }\n newNode[propsConfig.disabled!] = true\n\n if (node[propsConfig.children!] && node[propsConfig.children!].length > 0) {\n newNode[propsConfig.children!] = addDisabledToNodes(node[propsConfig.children!], disabled, propsConfig)\n }\n\n return newNode\n })\n}\n\nexport function traverseTree(\n nodes: TreeNodeData[],\n callback: (node: TreeNodeData) => void,\n options: {\n leafOnly?: boolean\n childrenKey?: string\n } = {},\n) {\n const { leafOnly = false, childrenKey = 'children' } = options\n\n for (const node of nodes) {\n const children = node[childrenKey] || []\n const isLeaf = children.length === 0\n\n if (!leafOnly || isLeaf) {\n callback(node)\n }\n if (children.length > 0) {\n traverseTree(children, callback, options)\n }\n }\n}\n\nexport function getChildrenKeys(node: TreeNodeData, nodeKey: string, propsConfig: any): any[] {\n const children = node[propsConfig.children!] || []\n if (children.length === 0)\n return []\n\n const keys: any[] = []\n traverseTree(children, (child) => {\n keys.push(child[nodeKey])\n }, { childrenKey: propsConfig.children })\n\n return keys\n}\n\nexport function extractKeysFromPath(pathNodes: TreeNodeData[], nodeKey: string, propsConfig: any): any[] {\n const keys: any[] = []\n traverseTree(pathNodes, (node) => {\n keys.push(node[nodeKey])\n }, { leafOnly: true, childrenKey: propsConfig.children })\n\n return keys\n}\n\nexport function getSelectedPath(nodes: TreeNodeData[], selectedKeys: any[], nodeKey: string, propsConfig: any): TreeNodeData[] {\n const result: TreeNodeData[] = []\n\n for (const node of nodes) {\n const children = node[propsConfig.children!] || []\n const hasSelectedChild = children.length > 0\n ? getSelectedPath(children, selectedKeys, nodeKey, propsConfig).length > 0\n : false\n\n if (selectedKeys.includes(node[nodeKey]) || hasSelectedChild) {\n const newNode = { ...node }\n if (hasSelectedChild && children.length > 0) {\n newNode[propsConfig.children!] = getSelectedPath(children, selectedKeys, nodeKey, propsConfig)\n }\n result.push(newNode)\n }\n }\n\n return result\n}\n\n/**\n * 查找节点的所有父节点路径\n */\nexport function findParents(nodes: TreeNodeData[], targetKey: any, nodeKey: string, propsConfig: any, parents: any[] = []): any[] {\n for (const node of nodes) {\n const currentPath = [...parents, node[nodeKey]]\n\n if (node[nodeKey] === targetKey) {\n return currentPath\n }\n\n const children = node[propsConfig.children!] || []\n if (children.length > 0) {\n const found = findParents(children, targetKey, nodeKey, propsConfig, currentPath)\n if (found.length > 0) {\n return found\n }\n }\n }\n /* istanbul ignore next -- @preserve */\n return []\n}\n\n/**\n * 过滤叶子节点\n */\nexport function filterLeafNodes(keys: any[], flatData: TreeNodeData[], nodeKey: string, propsConfig: any): any[] {\n return keys.filter((key) => {\n const node = flatData.find(n => n[nodeKey] === key)\n if (!node)\n return false\n const children = node[propsConfig.children!] || []\n return children.length === 0\n })\n}\n\n/**\n * 获取输出数据\n */\nexport function getOutputData(\n keys: any[],\n halfCheckedKeys: any[] = [],\n options: {\n flatData: TreeNodeData[]\n nodeKey: string\n propsConfig: any\n data: TreeNodeData[]\n valueType: string\n includeHalfChecked: boolean\n checkStrictly: boolean\n },\n) {\n const { flatData, nodeKey, propsConfig, data, valueType, includeHalfChecked, checkStrictly } = options\n\n const selectedNodes = flatData.filter(node =>\n keys.includes(node[nodeKey]),\n )\n\n let outputKeys = [...keys]\n let outputNodes = [...selectedNodes]\n\n if (checkStrictly) {\n return {\n value: outputKeys,\n nodes: outputNodes,\n }\n }\n\n switch (valueType) {\n case 'parent': {\n const allChildKeys: any[] = []\n for (const node of selectedNodes) {\n allChildKeys.push(...getChildrenKeys(node, nodeKey, propsConfig))\n }\n outputKeys = keys.filter(key => !allChildKeys.includes(key))\n outputNodes = selectedNodes.filter(node =>\n outputKeys.includes(node[nodeKey]),\n )\n break\n }\n\n case 'child': {\n for (const node of selectedNodes) {\n const childKeys = getChildrenKeys(node, nodeKey, propsConfig)\n const hasSelectedChild = childKeys.some(key => keys.includes(key))\n if (hasSelectedChild) {\n outputKeys = outputKeys.filter(key => key !== node[nodeKey])\n outputNodes = outputNodes.filter(n =>\n n[nodeKey] !== node[nodeKey],\n )\n }\n }\n break\n }\n\n case 'path': {\n const selectedPath = getSelectedPath(data, keys, nodeKey, propsConfig)\n return {\n value: selectedPath,\n nodes: selectedPath,\n }\n }\n\n default: { // 'all'\n if (includeHalfChecked && halfCheckedKeys.length > 0) {\n const halfCheckedNodes = flatData.filter(node =>\n halfCheckedKeys.includes(node[nodeKey]),\n )\n outputKeys = [...outputKeys, ...halfCheckedKeys]\n outputNodes = [...outputNodes, ...halfCheckedNodes]\n }\n break\n }\n }\n\n return {\n value: outputKeys,\n nodes: outputNodes,\n }\n}\n\n/**\n * 根据valueType将输入值转换为checkedKeys\n */\nexport function getInputKeys(\n inputValue: any,\n options: {\n optionAsValue: boolean\n nodeKey: string\n flatData: TreeNodeData[]\n propsConfig: any\n data: TreeNodeData[]\n valueType: string\n checkStrictly: boolean\n },\n): any[] {\n const { optionAsValue, nodeKey, flatData, propsConfig, data, valueType, checkStrictly } = options\n\n /* istanbul ignore if -- @preserve */\n if (!inputValue || !Array.isArray(inputValue))\n return []\n\n const valueArray = optionAsValue ? inputValue.map((item: any) => item[nodeKey]) : inputValue\n\n if (checkStrictly) {\n return valueArray\n }\n\n switch (valueType) {\n case 'parent': {\n const allKeys = [...valueArray]\n\n for (const key of valueArray) {\n const node = flatData.find(n => n[nodeKey] === key)\n if (node) {\n const childKeys = getChildrenKeys(node, nodeKey, propsConfig)\n allKeys.push(...childKeys)\n }\n }\n return filterLeafNodes(allKeys, flatData, nodeKey, propsConfig)\n }\n\n case 'child': {\n const allKeys = [...valueArray]\n for (const key of valueArray) {\n const parentPath = findParents(data, key, nodeKey, propsConfig)\n allKeys.push(...parentPath)\n }\n return filterLeafNodes(allKeys, flatData, nodeKey, propsConfig)\n }\n\n case 'path': {\n return extractKeysFromPath(valueArray, nodeKey, propsConfig)\n }\n\n default: { // 'all'\n return filterLeafNodes(valueArray, flatData, nodeKey, propsConfig)\n }\n }\n}\n"],"names":["flattenTree","nodes","result","childrenKey","node","addDisabledToNodes","disabled","propsConfig","newNode","traverseTree","callback","options","leafOnly","children","isLeaf","getChildrenKeys","nodeKey","keys","child","extractKeysFromPath","pathNodes","getSelectedPath","selectedKeys","hasSelectedChild","findParents","targetKey","parents","currentPath","found","filterLeafNodes","flatData","key","n","getOutputData","halfCheckedKeys","data","valueType","includeHalfChecked","checkStrictly","selectedNodes","outputKeys","outputNodes","allChildKeys","selectedPath","halfCheckedNodes","getInputKeys","inputValue","optionAsValue","valueArray","item","allKeys","childKeys","parentPath"],"mappings":"AAEO,SAASA,EAAYC,GAAuBC,IAAyB,CAAA,GAAIC,IAAc,YAA4B;AACxH,aAAWC,KAAQH;AACjB,IAAAC,EAAO,KAAKE,CAAI,GACZA,EAAKD,CAAW,KAAKC,EAAKD,CAAW,EAAE,SAAS,KAClDH,EAAYI,EAAKD,CAAW,GAAGD,GAAQC,CAAW;AAGtD,SAAOD;AACT;AAEO,SAASG,EAAmBJ,GAAuBK,GAAmBC,GAAkC;AAC7G,SAAKD,IAIEL,EAAM,IAAI,CAACG,MAAS;AACzB,UAAMI,IAAU,EAAE,GAAGJ,EAAA;AACrB,WAAAI,EAAQD,EAAY,QAAS,IAAI,IAE7BH,EAAKG,EAAY,QAAS,K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E,aAAOsB,EAAgBmB,GAAYlB,GAAUd,GAAST,CAAW;AAAA,EACnE;AAEJ;"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { useField as c, connect as i, mapProps as
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { mapReadPretty as
|
|
7
|
-
|
|
1
|
+
import { useField as c, connect as i, mapProps as p } from "@silver-formily/vue";
|
|
2
|
+
import { ElTreeSelect as m } from "element-plus";
|
|
3
|
+
import "@formily/reactive";
|
|
4
|
+
import "@vueuse/core";
|
|
5
|
+
import { defineComponent as f, useSlots as d, ref as u, createBlock as S, openBlock as _, unref as e, mergeProps as g, createSlots as P, renderList as R, withCtx as T, renderSlot as v, normalizeProps as y, guardReactiveProps as h } from "vue";
|
|
6
|
+
import { mapReadPretty as k } from "../__builtins__/shared/transform-component.mjs";
|
|
7
|
+
import { PreviewText as x } from "../preview-text/index.mjs";
|
|
8
|
+
import "@formily/core";
|
|
9
|
+
import "@silver-formily/reactive-vue";
|
|
10
|
+
import { useCleanAttrs as C } from "../__builtins__/shared/utils.mjs";
|
|
11
|
+
const w = /* @__PURE__ */ f({
|
|
8
12
|
name: "FSelectTree",
|
|
9
13
|
inheritAttrs: !1,
|
|
10
14
|
__name: "tree-select",
|
|
11
15
|
setup(A) {
|
|
12
|
-
const n = d(), { props: l } =
|
|
16
|
+
const n = d(), { props: l } = C(), r = u(), t = c();
|
|
13
17
|
return t.value?.inject({
|
|
14
18
|
getTreeSelectRef: () => r
|
|
15
|
-
}), (s, B) => (_(), S(e(
|
|
19
|
+
}), (s, B) => (_(), S(e(m), g({
|
|
16
20
|
ref_key: "treeSelectRef",
|
|
17
21
|
ref: r,
|
|
18
22
|
loading: e(t).value?.loading
|
|
@@ -25,13 +29,13 @@ const w = /* @__PURE__ */ m({
|
|
|
25
29
|
}))
|
|
26
30
|
]), 1040, ["loading"]));
|
|
27
31
|
}
|
|
28
|
-
}),
|
|
32
|
+
}), H = i(
|
|
29
33
|
w,
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
p({ readOnly: "readonly", dataSource: "data" }),
|
|
35
|
+
k(x.Select)
|
|
32
36
|
);
|
|
33
37
|
export {
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
H as TreeSelect,
|
|
39
|
+
H as default
|
|
36
40
|
};
|
|
37
41
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/tree-select/tree-select.vue","../../src/tree-select/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/tree-select/tree-select.vue","../../src/tree-select/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { Field } from '@formily/core'\nimport { useField } from '@silver-formily/vue'\nimport { ElTreeSelect } from 'element-plus'\nimport { ref, useSlots } from 'vue'\nimport { useCleanAttrs } from '../__builtins__'\n\ndefineOptions({\n name: 'FSelectTree',\n inheritAttrs: false,\n})\n\nconst slots = useSlots()\n\nconst { props: attrs } = useCleanAttrs()\n\nconst treeSelectRef = ref()\n\nconst fieldRef = useField<Field>()\n\nfieldRef.value?.inject({\n getTreeSelectRef: () => {\n return treeSelectRef\n },\n})\n</script>\n\n<template>\n <ElTreeSelect\n ref=\"treeSelectRef\"\n :loading=\"fieldRef.value?.loading\"\n v-bind=\"attrs\"\n >\n <template v-for=\"(_, name) of slots\" #[name]=\"slotData\">\n <slot :name=\"name\" v-bind=\"{ field: fieldRef, ...slotData }\" />\n </template>\n </ElTreeSelect>\n</template>\n","import { connect, mapProps } from '@silver-formily/vue'\r\nimport { mapReadPretty } from '../__builtins__'\r\nimport { PreviewText } from '../preview-text'\r\nimport FTreeSelect from './tree-select.vue'\r\n\r\nexport const TreeSelect = connect<typeof FTreeSelect>(\n FTreeSelect,\n mapProps({ readOnly: 'readonly', dataSource: 'data' }),\r\n mapReadPretty(PreviewText.Select),\r\n)\r\n\r\nexport default TreeSelect\r\n"],"names":["slots","useSlots","attrs","useCleanAttrs","treeSelectRef","ref","fieldRef","useField","_openBlock","_createBlock","_unref","_mergeProps","_createSlots","_","name","_withCtx","slotData","_renderSlot","_ctx","_normalizeProps","_guardReactiveProps","TreeSelect","connect","FTreeSelect","mapProps","mapReadPretty","PreviewText"],"mappings":";;;;;;;;;;;;;;;AAYA,UAAMA,IAAQC,EAAA,GAER,EAAE,OAAOC,EAAA,IAAUC,EAAA,GAEnBC,IAAgBC,EAAA,GAEhBC,IAAWC,EAAA;AAEjB,WAAAD,EAAS,OAAO,OAAO;AAAA,MACrB,kBAAkB,MACTF;AAAA,IACT,CACD,cAICI,KAAAC,EAQeC,MARfC,EAQe;AAAA,eAPT;AAAA,MAAJ,KAAIP;AAAA,MACH,SAASM,EAAAJ,CAAA,EAAS,OAAO;AAAA,IAAA,GAClBI,EAAAR,CAAA,CAAK,GAAAU,EAAA,EAAA,GAAA,KAAA;AAAA,QAEiBF,EAAAV,CAAA,GAAK,CAAjBa,GAAGC;;QACnB,IAAAC,EAAA,CAD4CC,MAAQ;AAAA,UACpDC,EAA+DC,EAAA,QAAlDJ,GAAIK,EAAAC,EAAA,EAAA,OAAmBV,EAAAJ,CAAA,MAAaU,EAAA,CAAQ,CAAA,CAAA;AAAA,QAAA;;;;IC7BlDK,IAAaC;AAAA,EACxBC;AAAAA,EACAC,EAAS,EAAE,UAAU,YAAY,YAAY,QAAQ;AAAA,EACrDC,EAAcC,EAAY,MAAM;AAClC;"}
|
package/esm/upload/index.mjs
CHANGED
|
@@ -4,8 +4,11 @@ import { UploadFilled as H, Plus as J, Upload as K } from "@element-plus/icons-v
|
|
|
4
4
|
import { reaction as M } from "@formily/reactive";
|
|
5
5
|
import { isFn as c } from "@formily/shared";
|
|
6
6
|
import { ElUpload as Q, ElIcon as W, ElButton as X, ElImageViewer as Y, genFileId as Z } from "element-plus";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import "@vueuse/core";
|
|
8
|
+
import "@formily/core";
|
|
9
|
+
import "@silver-formily/reactive-vue";
|
|
10
|
+
import { hasSlotContent as ee } from "../__builtins__/shared/utils.mjs";
|
|
11
|
+
import { o as te } from "../vendor/lodash.mjs";
|
|
9
12
|
const oe = { class: "el-upload__text" }, re = { style: { "margin-left": "6px" } }, ne = /* @__PURE__ */ O({
|
|
10
13
|
name: "FUpload",
|
|
11
14
|
inheritAttrs: !1,
|
|
@@ -34,7 +37,7 @@ const oe = { class: "el-upload__text" }, re = { style: { "margin-left": "6px" }
|
|
|
34
37
|
},
|
|
35
38
|
emits: ["update:modelValue"],
|
|
36
39
|
setup(u, { emit: S }) {
|
|
37
|
-
const i = u, V = S, d = f(), o = z(), R = w(() =>
|
|
40
|
+
const i = u, V = S, d = f(), o = z(), R = w(() => te(o, [
|
|
38
41
|
"onChange",
|
|
39
42
|
"onRemove",
|
|
40
43
|
"onExceed",
|
|
@@ -100,7 +103,7 @@ const oe = { class: "el-upload__text" }, re = { style: { "margin-left": "6px" }
|
|
|
100
103
|
onPreview: B
|
|
101
104
|
}), G({
|
|
102
105
|
default: s(() => [
|
|
103
|
-
r(
|
|
106
|
+
r(ee)(e.$slots?.default) ? m(e.$slots, "default", { key: 0 }) : (a(), v(y, { key: 1 }, [
|
|
104
107
|
r(o).drag ? (a(), v(y, { key: 0 }, [
|
|
105
108
|
p(r(W), { style: { "font-size": "60px", margin: "40px 0 16px" } }, {
|
|
106
109
|
default: s(() => [
|
|
@@ -162,12 +165,12 @@ const oe = { class: "el-upload__text" }, re = { style: { "margin-left": "6px" }
|
|
|
162
165
|
}), null, 16, ["url-list", "initial-index"])) : q("", !0)
|
|
163
166
|
], 64));
|
|
164
167
|
}
|
|
165
|
-
}),
|
|
168
|
+
}), ve = N(
|
|
166
169
|
ne,
|
|
167
170
|
j({ readOnly: "readonly", dataSource: "fileList" })
|
|
168
171
|
);
|
|
169
172
|
export {
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
ve as Upload,
|
|
174
|
+
ve as default
|
|
172
175
|
};
|
|
173
176
|
//# sourceMappingURL=index.mjs.map
|
package/esm/upload/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/upload/upload.vue","../../src/upload/index.ts"],"sourcesContent":["<script lang=\"ts\" setup>\r\nimport type { Field } from '@formily/core'\r\nimport type { ImageViewerInstance, ImageViewerProps, UploadFile, UploadInstance, UploadProps, UploadRawFile } from 'element-plus'\r\nimport type { PropType } from 'vue'\r\nimport {\r\n Plus as PlusIcon,\r\n UploadFilled as UploadFilledIcon,\r\n Upload as UploadIcon,\r\n} from '@element-plus/icons-vue'\r\nimport { reaction } from '@formily/reactive'\r\nimport { isFn } from '@formily/shared'\r\nimport { useField } from '@silver-formily/vue'\r\nimport { ElButton, ElIcon, ElImageViewer, ElUpload, genFileId } from 'element-plus'\r\nimport { omit } from 'lodash-es'\r\nimport { computed, onBeforeUnmount, ref, useAttrs } from 'vue'\r\nimport { hasSlotContent } from '../__builtins__'\r\n\r\ndefineOptions({\r\n name: 'FUpload',\r\n inheritAttrs: false,\r\n})\r\n\r\nconst props = defineProps({\r\n textContent: {\r\n type: String,\r\n default: '',\r\n },\r\n errorAdaptor: {\r\n type: Function as PropType<(error?: Error) => string>,\r\n default: (error?: Error) => error?.message,\r\n },\r\n formatValue: {\r\n type: Function as PropType<(fileList?: UploadFile[]) => any>,\r\n default: item => item,\r\n },\r\n fileList: {\r\n type: Array as PropType<UploadFile[]>,\r\n default: () => [],\r\n },\r\n imageViewerProps: {\r\n type: Object as PropType<ImageViewerProps>,\r\n default: () => ({ teleported: true, showProgress: true }),\r\n },\r\n})\r\n\r\nconst emit = defineEmits(['update:modelValue'])\r\n\r\nconst uploadRef = ref<UploadInstance>()\r\nconst attrs = useAttrs() as UploadProps\r\nconst innerAttrs = computed(() => {\r\n return omit(attrs, [\r\n 'onChange',\r\n 'onRemove',\r\n 'onExceed',\r\n 'onError',\r\n 'onPreview',\r\n 'fileList',\r\n 'onUpdate:fileList',\r\n ])\r\n})\r\nconst fieldRef = useField<Field>()\r\nfieldRef.value?.inject({\r\n getElUploadRef: () => {\r\n return uploadRef\r\n },\r\n})\r\n\r\nconst imgPreviewRef = ref<ImageViewerInstance>()\r\nconst activeImageIndex = ref(0)\r\nconst isShowImgViewer = ref(false)\r\nconst imgPreviewList = computed(() => {\r\n return props.fileList.map(item => item.url)\r\n})\r\n\r\nfunction setFeedBack(error?: Error) {\r\n const message = props.errorAdaptor(error)\r\n fieldRef.value?.setFeedback({\r\n type: 'error',\r\n code: 'UploadError',\r\n messages: message ? [message] : [],\r\n })\r\n}\r\n\r\nfunction handleChange(file: UploadFile, fileList: UploadFile[]) {\r\n fieldRef.value?.setDataSource([...fileList])\r\n setFeedBack()\r\n}\r\n\r\nfunction handleRemove(file: UploadFile, fileList: UploadFile[]) {\r\n if (isFn(attrs.onRemove)) {\r\n attrs.onRemove(file, fileList)\r\n }\r\n fieldRef.value.setDataSource([...fileList])\r\n setFeedBack()\r\n}\r\n\r\nfunction handleExceed(files: File[], uploadFIles) {\r\n if (isFn(attrs.onExceed)) {\r\n attrs.onExceed(files, uploadFIles)\r\n }\r\n if (attrs.limit !== 1)\r\n return\r\n uploadRef.value!.clearFiles()\r\n const file = files[0] as UploadRawFile\r\n file.uid = genFileId()\r\n uploadRef.value!.handleStart(file)\r\n if (attrs.autoUpload ?? true) {\r\n uploadRef.value!.submit()\r\n }\r\n}\r\n\r\nfunction handleError(error: Error, file: UploadFile, fileList: UploadFile[]) {\r\n if (isFn(attrs.onError)) {\r\n (attrs.onError)(error, file, fileList)\r\n }\r\n}\r\n\r\nfunction onPreviewClick(uploadFile: UploadFile) {\r\n if (isFn(attrs.onPreview)) {\r\n (attrs.onPreview)(uploadFile)\r\n return\r\n }\r\n if (!uploadFile.url && !attrs.accept?.includes('image'))\r\n return\r\n const clickIndex = props.fileList.findIndex((element: UploadFile) => element.uid === uploadFile.uid)\r\n activeImageIndex.value = clickIndex\r\n isShowImgViewer.value = true\r\n}\r\n\r\nconst dispose = reaction(() => {\r\n return fieldRef.value?.dataSource ?? []\r\n}, () => {\r\n const emitValue = props.formatValue(fieldRef.value.dataSource as UploadFile[])\r\n emit('update:modelValue', emitValue)\r\n})\r\nonBeforeUnmount(() => {\r\n dispose()\r\n})\r\n</script>\r\n\r\n<template>\r\n <ElUpload\r\n ref=\"uploadRef\"\r\n v-bind=\"innerAttrs\"\r\n :file-list=\"$props.fileList\"\r\n @change=\"handleChange\"\r\n @remove=\"handleRemove\"\r\n @exceed=\"handleExceed\"\r\n @error=\"handleError\"\r\n @preview=\"onPreviewClick\"\r\n >\r\n <slot v-if=\"hasSlotContent($slots?.default)\" />\r\n <template v-else>\r\n <template v-if=\"attrs.drag\">\r\n <ElIcon style=\"font-size: 60px; margin: 40px 0 16px;\">\r\n <UploadFilledIcon color=\"gray\" />\r\n </ElIcon>\r\n <div class=\"el-upload__text\">\r\n {{ props.textContent }}\r\n </div>\r\n </template>\r\n <template v-else-if=\"attrs.listType === 'picture-card'\">\r\n <PlusIcon style=\"width: 28px; height: 28px; color: gray\" />\r\n </template>\r\n <template v-else>\r\n <ElButton>\r\n <UploadIcon width=\"16px\" height=\"16px\" />\r\n <span style=\"margin-left: 6px\">\r\n {{ props.textContent }}\r\n </span>\r\n </ElButton>\r\n </template>\r\n </template>\r\n <template v-if=\"$slots.file\" #file=\"{ file, index }\">\r\n <slot name=\"file\" :file=\"file\" :index=\"index\" />\r\n </template>\r\n <template v-if=\"$slots.tip\" #tip>\r\n <slot name=\"tip\" />\r\n </template>\r\n <template v-if=\"$slots.trigger\" #trigger>\r\n <slot name=\"trigger\" />\r\n </template>\r\n </ElUpload>\r\n <ElImageViewer\r\n v-if=\"isShowImgViewer\"\r\n ref=\"imgPreviewRef\"\r\n :url-list=\"imgPreviewList\"\r\n :initial-index=\"activeImageIndex\"\r\n v-bind=\"props.imageViewerProps\"\r\n @close=\"isShowImgViewer = false\"\r\n />\r\n</template>\r\n","import { connect, mapProps } from '@silver-formily/vue'\r\nimport FUpload from './upload.vue'\r\n\r\nexport const Upload = connect<typeof FUpload>(\n FUpload,\n mapProps({ readOnly: 'readonly', dataSource: 'fileList' }),\r\n)\r\n\r\nexport default Upload\r\n"],"names":["props","__props","emit","__emit","uploadRef","ref","attrs","useAttrs","innerAttrs","computed","omit","fieldRef","useField","imgPreviewRef","activeImageIndex","isShowImgViewer","imgPreviewList","item","setFeedBack","error","message","handleChange","file","fileList","handleRemove","isFn","handleExceed","files","uploadFIles","genFileId","handleError","onPreviewClick","uploadFile","clickIndex","element","dispose","reaction","emitValue","onBeforeUnmount","_createVNode","_unref","_mergeProps","$props","hasSlotContent","$slots","_renderSlot","_ctx","_createElementBlock","_Fragment","ElIcon","UploadFilledIcon","_createElementVNode","_hoisted_1","_toDisplayString","_createBlock","PlusIcon","ElButton","UploadIcon","_hoisted_2","index","_openBlock","Upload","connect","FUpload","mapProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,UAAMA,IAAQC,GAuBRC,IAAOC,GAEPC,IAAYC,EAAA,GACZC,IAAQC,EAAA,GACRC,IAAaC,EAAS,MACnBC,GAAKJ,GAAO;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD,CACF,GACKK,IAAWC,EAAA;AACjB,IAAAD,EAAS,OAAO,OAAO;AAAA,MACrB,gBAAgB,MACPP;AAAA,IACT,CACD;AAED,UAAMS,IAAgBR,EAAA,GAChBS,IAAmBT,EAAI,CAAC,GACxBU,IAAkBV,EAAI,EAAK,GAC3BW,IAAiBP,EAAS,MACvBT,EAAM,SAAS,IAAI,CAAAiB,MAAQA,EAAK,GAAG,CAC3C;AAED,aAASC,EAAYC,GAAe;AAClC,YAAMC,IAAUpB,EAAM,aAAamB,CAAK;AACxC,MAAAR,EAAS,OAAO,YAAY;AAAA,QAC1B,MAAM;AAAA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A,gBAAA;gBAChCN,EAEO,QAFPO,IAEOL,EADFrD,EAAM,WAAW,GAAA,CAAA;AAAA,cAAA;;;;;;;QAKZ4C,EAAAA,OAAO;gBAAO;AAAA,gBAC5B,CAAgD,EADZ,MAAAtB,GAAM,OAAAqC,QAAK;AAAA,YAC/Cd,EAAgDC,EAAA,QAAA,QAAA;AAAA,cAA7B,MAAAxB;AAAA,cAAa,OAAAqC;AAAA,YAAA;;;;QAElBf,EAAAA,OAAO;gBAAM;AAAA,gBAC3B,MAAmB;AAAA,YAAnBC,EAAmBC,EAAA,QAAA,KAAA;AAAA,UAAA;;;QAELF,EAAAA,OAAO;gBAAU;AAAA,gBAC/B,MAAuB;AAAA,YAAvBC,EAAuBC,EAAA,QAAA,SAAA;AAAA,UAAA;;;;MAInB/B,EAAA,SADR6C,EAAA,GAAAN,EAOEd,MAPFC,EAOE;AAAA;iBALI;AAAA,QAAJ,KAAI5B;AAAA,QACH,YAAUG,EAAA;AAAA,QACV,iBAAeF,EAAA;AAAA,MAAA,GACRd,EAAM,kBAAgB;AAAA,QAC7B,gCAAOe,EAAA,QAAe;AAAA,MAAA;;;IC1Ld8C,KAASC;AAAA,EACpBC;AAAAA,EACAC,EAAS,EAAE,UAAU,YAAY,YAAY,YAAY;AAC3D;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/upload/upload.vue","../../src/upload/index.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { Field } from '@formily/core'\nimport type { ImageViewerInstance, ImageViewerProps, UploadFile, UploadInstance, UploadProps, UploadRawFile } from 'element-plus'\nimport type { PropType } from 'vue'\nimport {\n Plus as PlusIcon,\n UploadFilled as UploadFilledIcon,\n Upload as UploadIcon,\n} from '@element-plus/icons-vue'\nimport { reaction } from '@formily/reactive'\nimport { isFn } from '@formily/shared'\nimport { useField } from '@silver-formily/vue'\nimport { ElButton, ElIcon, ElImageViewer, ElUpload, genFileId } from 'element-plus'\nimport { omit } from 'lodash-es'\nimport { computed, onBeforeUnmount, ref, useAttrs } from 'vue'\nimport { hasSlotContent } from '../__builtins__'\n\ndefineOptions({\n name: 'FUpload',\n inheritAttrs: false,\n})\n\nconst props = defineProps({\n textContent: {\n type: String,\n default: '',\n },\n errorAdaptor: {\n type: Function as PropType<(error?: Error) => string>,\n default: (error?: Error) => error?.message,\n },\n formatValue: {\n type: Function as PropType<(fileList?: UploadFile[]) => any>,\n default: item => item,\n },\n fileList: {\n type: Array as PropType<UploadFile[]>,\n default: () => [],\n },\n imageViewerProps: {\n type: Object as PropType<ImageViewerProps>,\n default: () => ({ teleported: true, showProgress: true }),\n },\n})\n\nconst emit = defineEmits(['update:modelValue'])\n\nconst uploadRef = ref<UploadInstance>()\nconst attrs = useAttrs() as UploadProps\nconst innerAttrs = computed(() => {\n return omit(attrs, [\n 'onChange',\n 'onRemove',\n 'onExceed',\n 'onError',\n 'onPreview',\n 'fileList',\n 'onUpdate:fileList',\n ])\n})\nconst fieldRef = useField<Field>()\nfieldRef.value?.inject({\n getElUploadRef: () => {\n return uploadRef\n },\n})\n\nconst imgPreviewRef = ref<ImageViewerInstance>()\nconst activeImageIndex = ref(0)\nconst isShowImgViewer = ref(false)\nconst imgPreviewList = computed(() => {\n return props.fileList.map(item => item.url)\n})\n\nfunction setFeedBack(error?: Error) {\n const message = props.errorAdaptor(error)\n fieldRef.value?.setFeedback({\n type: 'error',\n code: 'UploadError',\n messages: message ? [message] : [],\n })\n}\n\nfunction handleChange(file: UploadFile, fileList: UploadFile[]) {\n fieldRef.value?.setDataSource([...fileList])\n setFeedBack()\n}\n\nfunction handleRemove(file: UploadFile, fileList: UploadFile[]) {\n if (isFn(attrs.onRemove)) {\n attrs.onRemove(file, fileList)\n }\n fieldRef.value.setDataSource([...fileList])\n setFeedBack()\n}\n\nfunction handleExceed(files: File[], uploadFIles) {\n if (isFn(attrs.onExceed)) {\n attrs.onExceed(files, uploadFIles)\n }\n if (attrs.limit !== 1)\n return\n uploadRef.value!.clearFiles()\n const file = files[0] as UploadRawFile\n file.uid = genFileId()\n uploadRef.value!.handleStart(file)\n if (attrs.autoUpload ?? true) {\n uploadRef.value!.submit()\n }\n}\n\nfunction handleError(error: Error, file: UploadFile, fileList: UploadFile[]) {\n if (isFn(attrs.onError)) {\n (attrs.onError)(error, file, fileList)\n }\n}\n\nfunction onPreviewClick(uploadFile: UploadFile) {\n if (isFn(attrs.onPreview)) {\n (attrs.onPreview)(uploadFile)\n return\n }\n if (!uploadFile.url && !attrs.accept?.includes('image'))\n return\n const clickIndex = props.fileList.findIndex((element: UploadFile) => element.uid === uploadFile.uid)\n activeImageIndex.value = clickIndex\n isShowImgViewer.value = true\n}\n\nconst dispose = reaction(() => {\n return fieldRef.value?.dataSource ?? []\n}, () => {\n const emitValue = props.formatValue(fieldRef.value.dataSource as UploadFile[])\n emit('update:modelValue', emitValue)\n})\nonBeforeUnmount(() => {\n dispose()\n})\n</script>\n\n<template>\n <ElUpload\n ref=\"uploadRef\"\n v-bind=\"innerAttrs\"\n :file-list=\"$props.fileList\"\n @change=\"handleChange\"\n @remove=\"handleRemove\"\n @exceed=\"handleExceed\"\n @error=\"handleError\"\n @preview=\"onPreviewClick\"\n >\n <slot v-if=\"hasSlotContent($slots?.default)\" />\n <template v-else>\n <template v-if=\"attrs.drag\">\n <ElIcon style=\"font-size: 60px; margin: 40px 0 16px;\">\n <UploadFilledIcon color=\"gray\" />\n </ElIcon>\n <div class=\"el-upload__text\">\n {{ props.textContent }}\n </div>\n </template>\n <template v-else-if=\"attrs.listType === 'picture-card'\">\n <PlusIcon style=\"width: 28px; height: 28px; color: gray\" />\n </template>\n <template v-else>\n <ElButton>\n <UploadIcon width=\"16px\" height=\"16px\" />\n <span style=\"margin-left: 6px\">\n {{ props.textContent }}\n </span>\n </ElButton>\n </template>\n </template>\n <template v-if=\"$slots.file\" #file=\"{ file, index }\">\n <slot name=\"file\" :file=\"file\" :index=\"index\" />\n </template>\n <template v-if=\"$slots.tip\" #tip>\n <slot name=\"tip\" />\n </template>\n <template v-if=\"$slots.trigger\" #trigger>\n <slot name=\"trigger\" />\n </template>\n </ElUpload>\n <ElImageViewer\n v-if=\"isShowImgViewer\"\n ref=\"imgPreviewRef\"\n :url-list=\"imgPreviewList\"\n :initial-index=\"activeImageIndex\"\n v-bind=\"props.imageViewerProps\"\n @close=\"isShowImgViewer = false\"\n />\n</template>\n","import { connect, mapProps } from '@silver-formily/vue'\r\nimport FUpload from './upload.vue'\r\n\r\nexport const Upload = connect<typeof FUpload>(\n FUpload,\n mapProps({ readOnly: 'readonly', dataSource: 'fileList' }),\r\n)\r\n\r\nexport default Upload\r\n"],"names":["props","__props","emit","__emit","uploadRef","ref","attrs","useAttrs","innerAttrs","computed","omit","fieldRef","useField","imgPreviewRef","activeImageIndex","isShowImgViewer","imgPreviewList","item","setFeedBack","error","message","handleChange","file","fileList","handleRemove","isFn","handleExceed","files","uploadFIles","genFileId","handleError","onPreviewClick","uploadFile","clickIndex","element","dispose","reaction","emitValue","onBeforeUnmount","_createVNode","_unref","_mergeProps","$props","hasSlotContent","$slots","_renderSlot","_ctx","_createElementBlock","_Fragment","ElIcon","UploadFilledIcon","_createElementVNode","_hoisted_1","_toDisplayString","_createBlock","PlusIcon","ElButton","UploadIcon","_hoisted_2","index","_openBlock","Upload","connect","FUpload","mapProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,UAAMA,IAAQC,GAuBRC,IAAOC,GAEPC,IAAYC,EAAA,GACZC,IAAQC,EAAA,GACRC,IAAaC,EAAS,MACnBC,GAAKJ,GAAO;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD,CACF,GACKK,IAAWC,EAAA;AACjB,IAAAD,EAAS,OAAO,OAAO;AAAA,MACrB,gBAAgB,MACPP;AAAA,IACT,CACD;AAED,UAAMS,IAAgBR,EAAA,GAChBS,IAAmBT,EAAI,CAAC,GACxBU,IAAkB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