@silver-formily/vue 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { isVoidField as r } from "@formily/core";
|
|
2
|
-
import { toJS as
|
|
2
|
+
import { toJS as F } from "@formily/reactive";
|
|
3
3
|
import { useObserver as w } from "@formily/reactive-vue";
|
|
4
|
-
import { FormPath as
|
|
5
|
-
import { defineComponent as D, inject as E, ref as H, shallowRef as
|
|
6
|
-
import { useField as
|
|
7
|
-
import { SchemaOptionsSymbol as
|
|
8
|
-
import { useForm as
|
|
9
|
-
import { useAttach as
|
|
10
|
-
import { mergeSlots as
|
|
11
|
-
const
|
|
4
|
+
import { FormPath as P } from "@formily/shared";
|
|
5
|
+
import { defineComponent as D, inject as E, ref as H, shallowRef as j, watch as x, provide as z, h } from "vue";
|
|
6
|
+
import { useField as B } from "../hooks/useField.mjs";
|
|
7
|
+
import { SchemaOptionsSymbol as J, FieldSymbol as N } from "../shared/context.mjs";
|
|
8
|
+
import { useForm as U } from "../hooks/useForm.mjs";
|
|
9
|
+
import { useAttach as $ } from "../hooks/useAttach.mjs";
|
|
10
|
+
import { mergeSlots as k, wrapFragment as A, extractAttrsAndEvents as T, createVNodeProps as R } from "../utils/reactiveFieldHelpers.mjs";
|
|
11
|
+
const oe = D({
|
|
12
12
|
name: "ReactiveField",
|
|
13
13
|
props: {
|
|
14
14
|
fieldType: {
|
|
@@ -21,53 +21,55 @@ const _ = D({
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
setup(n, { slots: u }) {
|
|
24
|
-
const
|
|
24
|
+
const S = U(), V = B(), C = E(J, H());
|
|
25
25
|
w();
|
|
26
|
-
const y = () =>
|
|
26
|
+
const y = () => S?.value?.[`create${n.fieldType}`]?.({
|
|
27
27
|
...n.fieldProps,
|
|
28
|
-
basePath: n.fieldProps?.basePath ??
|
|
29
|
-
}), a =
|
|
30
|
-
return
|
|
28
|
+
basePath: n.fieldProps?.basePath ?? V.value?.address
|
|
29
|
+
}), a = j(y());
|
|
30
|
+
return x(
|
|
31
31
|
() => n.fieldProps,
|
|
32
32
|
() => a.value = y()
|
|
33
|
-
),
|
|
33
|
+
), $(a), z(N, a), () => {
|
|
34
34
|
const e = a.value, v = C.value;
|
|
35
35
|
if (!e)
|
|
36
36
|
return u.default?.();
|
|
37
37
|
if (e.display !== "visible")
|
|
38
38
|
return null;
|
|
39
|
-
const b =
|
|
39
|
+
const b = k(e, u, e.content);
|
|
40
40
|
return ((s) => {
|
|
41
|
-
const
|
|
41
|
+
const d = s.filter((f) => f != null);
|
|
42
42
|
if (!e.decoratorType)
|
|
43
|
-
return A(
|
|
44
|
-
const
|
|
45
|
-
return
|
|
46
|
-
default: () =>
|
|
43
|
+
return A(d);
|
|
44
|
+
const c = P.getIn(v?.components, e.decoratorType) ?? e.decoratorType, i = Array.isArray(e.decorator) ? e.decorator[1] : void 0, l = F(i) || {}, { attrs: p, events: t } = T(l), m = R(p, t);
|
|
45
|
+
return h(c, m, {
|
|
46
|
+
default: () => d
|
|
47
47
|
});
|
|
48
48
|
})([(() => {
|
|
49
49
|
if (!e.componentType)
|
|
50
50
|
return A(b?.default?.());
|
|
51
|
-
const s =
|
|
51
|
+
const s = P.getIn(v?.components, e.componentType) ?? e.componentType, d = Array.isArray(e.component) ? e.component[1] : void 0, c = F(d) || {}, i = r(e) ? void 0 : e.value, l = {
|
|
52
52
|
disabled: r(e) ? void 0 : e.pattern === "disabled" || e.pattern === "readPretty",
|
|
53
53
|
readOnly: r(e) ? void 0 : e.pattern === "readOnly",
|
|
54
|
-
...
|
|
55
|
-
|
|
56
|
-
}, { attrs:
|
|
57
|
-
|
|
58
|
-
r(e) || e.onInput(...t), p?.(...t);
|
|
59
|
-
}, o.focus = (...t) => {
|
|
60
|
-
r(e) || e.onFocus(...t), m?.(...t);
|
|
61
|
-
}, o.blur = (...t) => {
|
|
62
|
-
r(e) || e.onBlur(...t), f?.(...t);
|
|
54
|
+
...c,
|
|
55
|
+
modelValue: i
|
|
56
|
+
}, { attrs: p, events: t } = T(l), m = t["update:modelValue"], f = t.focus, O = t.blur, g = (...o) => {
|
|
57
|
+
r(e) || e.onInput(...o);
|
|
63
58
|
};
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
t["update:modelValue"] = (...o) => {
|
|
60
|
+
g(...o), m?.(...o);
|
|
61
|
+
}, t.focus = (...o) => {
|
|
62
|
+
r(e) || e.onFocus(...o), f?.(...o);
|
|
63
|
+
}, t.blur = (...o) => {
|
|
64
|
+
r(e) || e.onBlur(...o), O?.(...o);
|
|
65
|
+
};
|
|
66
|
+
const I = R(p, t);
|
|
67
|
+
return h(s, I, b);
|
|
66
68
|
})()]);
|
|
67
69
|
};
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
export {
|
|
71
|
-
|
|
73
|
+
oe as default
|
|
72
74
|
};
|
|
73
75
|
//# sourceMappingURL=ReactiveField.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactiveField.mjs","sources":["../../src/components/ReactiveField.ts"],"sourcesContent":["import type { GeneralField } from '@formily/core'\nimport type { Ref, VNode } from 'vue'\nimport type { IReactiveFieldProps } from '../types'\nimport { isVoidField } from '@formily/core'\nimport { toJS } from '@formily/reactive'\nimport { useObserver } from '@formily/reactive-vue'\nimport { FormPath } from '@formily/shared'\nimport { defineComponent, h, inject, provide, ref, shallowRef, watch } from 'vue'\nimport { useField, useForm } from '../hooks'\nimport { useAttach } from '../hooks/useAttach'\n\nimport { FieldSymbol, SchemaOptionsSymbol } from '../shared'\nimport { createVNodeProps, extractAttrsAndEvents, mergeSlots, wrapFragment } from '../utils/reactiveFieldHelpers'\n\ntype ComponentEventArgs = unknown[]\ntype ComponentEventHandler = (...args: ComponentEventArgs) => unknown\n\nexport default defineComponent({\n name: 'ReactiveField',\n props: {\n fieldType: {\n type: String,\n default: 'Field',\n },\n fieldProps: {\n type: Object,\n default: () => ({}),\n },\n },\n setup(props: IReactiveFieldProps, { slots }) {\n const formRef = useForm()\n const parentRef = useField()\n const optionsRef = inject(SchemaOptionsSymbol, ref())\n\n useObserver()\n\n const createField = () =>\n formRef?.value?.[`create${props.fieldType}`]?.({\n ...props.fieldProps,\n basePath: props.fieldProps?.basePath ?? parentRef.value?.address,\n })\n\n const fieldRef = shallowRef(createField()) as Ref<GeneralField>\n\n watch(\n () => props.fieldProps,\n () => (fieldRef.value = createField()),\n )\n\n useAttach(fieldRef)\n provide(FieldSymbol, fieldRef)\n\n return () => {\n const field = fieldRef.value\n const options = optionsRef.value\n\n if (!field) {\n return slots.default?.()\n }\n\n if (field.display !== 'visible') {\n return null\n }\n\n const mergedSlots = mergeSlots(field, slots, field.content)\n\n const renderDecorator = (childNodes: Array<VNode | null | undefined>) => {\n const normalizedChildren = childNodes.filter(child => child != null) as VNode[]\n if (!field.decoratorType) {\n return wrapFragment(normalizedChildren)\n }\n\n const finalComponent\n = FormPath.getIn(options?.components, field.decoratorType as string) ?? field.decoratorType\n const decoratorEntry = Array.isArray(field.decorator) ? field.decorator[1] : undefined\n const decoratorAttrs = toJS(decoratorEntry) || {}\n const { attrs, events } = extractAttrsAndEvents(decoratorAttrs)\n const decoratorProps = createVNodeProps(attrs, events)\n\n return h(finalComponent, decoratorProps, {\n default: () => normalizedChildren,\n })\n }\n\n const renderComponent = (): VNode | null => {\n if (!field.componentType) {\n return wrapFragment(mergedSlots?.default?.())\n }\n\n const component\n = FormPath.getIn(options?.components, field.componentType as string) ?? field.componentType\n\n const componentEntry = Array.isArray(field.component) ? field.component[1] : undefined\n const originData = toJS(componentEntry) || {}\n const composedAttrs = {\n disabled: !isVoidField(field)\n ? field.pattern === 'disabled' || field.pattern === 'readPretty'\n : undefined,\n readOnly: !isVoidField(field) ? field.pattern === 'readOnly' : undefined,\n ...originData,\n
|
|
1
|
+
{"version":3,"file":"ReactiveField.mjs","sources":["../../src/components/ReactiveField.ts"],"sourcesContent":["import type { GeneralField } from '@formily/core'\nimport type { Ref, VNode } from 'vue'\nimport type { IReactiveFieldProps } from '../types'\nimport { isVoidField } from '@formily/core'\nimport { toJS } from '@formily/reactive'\nimport { useObserver } from '@formily/reactive-vue'\nimport { FormPath } from '@formily/shared'\nimport { defineComponent, h, inject, provide, ref, shallowRef, watch } from 'vue'\nimport { useField, useForm } from '../hooks'\nimport { useAttach } from '../hooks/useAttach'\n\nimport { FieldSymbol, SchemaOptionsSymbol } from '../shared'\nimport { createVNodeProps, extractAttrsAndEvents, mergeSlots, wrapFragment } from '../utils/reactiveFieldHelpers'\n\ntype ComponentEventArgs = unknown[]\ntype ComponentEventHandler = (...args: ComponentEventArgs) => unknown\n\nexport default defineComponent({\n name: 'ReactiveField',\n props: {\n fieldType: {\n type: String,\n default: 'Field',\n },\n fieldProps: {\n type: Object,\n default: () => ({}),\n },\n },\n setup(props: IReactiveFieldProps, { slots }) {\n const formRef = useForm()\n const parentRef = useField()\n const optionsRef = inject(SchemaOptionsSymbol, ref())\n\n useObserver()\n\n const createField = () =>\n formRef?.value?.[`create${props.fieldType}`]?.({\n ...props.fieldProps,\n basePath: props.fieldProps?.basePath ?? parentRef.value?.address,\n })\n\n const fieldRef = shallowRef(createField()) as Ref<GeneralField>\n\n watch(\n () => props.fieldProps,\n () => (fieldRef.value = createField()),\n )\n\n useAttach(fieldRef)\n provide(FieldSymbol, fieldRef)\n\n return () => {\n const field = fieldRef.value\n const options = optionsRef.value\n\n if (!field) {\n return slots.default?.()\n }\n\n if (field.display !== 'visible') {\n return null\n }\n\n const mergedSlots = mergeSlots(field, slots, field.content)\n\n const renderDecorator = (childNodes: Array<VNode | null | undefined>) => {\n const normalizedChildren = childNodes.filter(child => child != null) as VNode[]\n if (!field.decoratorType) {\n return wrapFragment(normalizedChildren)\n }\n\n const finalComponent\n = FormPath.getIn(options?.components, field.decoratorType as string) ?? field.decoratorType\n const decoratorEntry = Array.isArray(field.decorator) ? field.decorator[1] : undefined\n const decoratorAttrs = toJS(decoratorEntry) || {}\n const { attrs, events } = extractAttrsAndEvents(decoratorAttrs)\n const decoratorProps = createVNodeProps(attrs, events)\n\n return h(finalComponent, decoratorProps, {\n default: () => normalizedChildren,\n })\n }\n\n const renderComponent = (): VNode | null => {\n if (!field.componentType) {\n return wrapFragment(mergedSlots?.default?.())\n }\n\n const component\n = FormPath.getIn(options?.components, field.componentType as string) ?? field.componentType\n\n const componentEntry = Array.isArray(field.component) ? field.component[1] : undefined\n const originData = toJS(componentEntry) || {}\n const fieldValue = !isVoidField(field) ? field.value : undefined\n const composedAttrs = {\n disabled: !isVoidField(field)\n ? field.pattern === 'disabled' || field.pattern === 'readPretty'\n : undefined,\n readOnly: !isVoidField(field) ? field.pattern === 'readOnly' : undefined,\n ...originData,\n modelValue: fieldValue,\n }\n const { attrs, events } = extractAttrsAndEvents(composedAttrs)\n const modelUpdateHandler: ComponentEventHandler | undefined = events['update:modelValue']\n const focusHandler: ComponentEventHandler | undefined = events.focus\n const blurHandler: ComponentEventHandler | undefined = events.blur\n\n const emitInput = (...args: ComponentEventArgs) => {\n if (!isVoidField(field)) {\n field.onInput(...(args as Parameters<typeof field.onInput>))\n }\n }\n\n events['update:modelValue'] = (...args: ComponentEventArgs) => {\n emitInput(...args)\n modelUpdateHandler?.(...args)\n }\n events.focus = (...args: ComponentEventArgs) => {\n if (!isVoidField(field)) {\n field.onFocus(...(args as Parameters<typeof field.onFocus>))\n }\n focusHandler?.(...args)\n }\n events.blur = (...args: ComponentEventArgs) => {\n if (!isVoidField(field)) {\n field.onBlur(...(args as Parameters<typeof field.onBlur>))\n }\n blurHandler?.(...args)\n }\n\n const componentProps = createVNodeProps(attrs, events)\n return h(component, componentProps, mergedSlots)\n }\n\n return renderDecorator([renderComponent()])\n }\n },\n})\n"],"names":["ReactiveField","defineComponent","props","slots","formRef","useForm","parentRef","useField","optionsRef","inject","SchemaOptionsSymbol","ref","useObserver","createField","fieldRef","shallowRef","watch","useAttach","provide","FieldSymbol","field","options","mergedSlots","mergeSlots","childNodes","normalizedChildren","child","wrapFragment","finalComponent","FormPath","decoratorEntry","decoratorAttrs","toJS","attrs","events","extractAttrsAndEvents","decoratorProps","createVNodeProps","component","componentEntry","originData","fieldValue","isVoidField","composedAttrs","modelUpdateHandler","focusHandler","blurHandler","emitInput","args","componentProps"],"mappings":";;;;;;;;;;AAiBA,MAAAA,KAAeC,EAAgB;AAAA,EAC7B,MAAM;AAAA,EACN,OAAO;AAAA,IACL,WAAW;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,IAAA;AAAA,IAEX,YAAY;AAAA,MACV,MAAM;AAAA,MACN,SAAS,OAAO,CAAA;AAAA,IAAC;AAAA,EACnB;AAAA,EAEF,MAAMC,GAA4B,EAAE,OAAAC,KAAS;AAC3C,UAAMC,IAAUC,EAAA,GACVC,IAAYC,EAAA,GACZC,IAAaC,EAAOC,GAAqBC,EAAA,CAAK;AAEpD,IAAAC,EAAA;AAEA,UAAMC,IAAc,MAClBT,GAAS,QAAQ,SAASF,EAAM,SAAS,EAAE,IAAI;AAAA,MAC7C,GAAGA,EAAM;AAAA,MACT,UAAUA,EAAM,YAAY,YAAYI,EAAU,OAAO;AAAA,IAAA,CAC1D,GAEGQ,IAAWC,EAAWF,GAAa;AAEzC,WAAAG;AAAA,MACE,MAAMd,EAAM;AAAA,MACZ,MAAOY,EAAS,QAAQD,EAAA;AAAA,IAAY,GAGtCI,EAAUH,CAAQ,GAClBI,EAAQC,GAAaL,CAAQ,GAEtB,MAAM;AACX,YAAMM,IAAQN,EAAS,OACjBO,IAAUb,EAAW;AAE3B,UAAI,CAACY;AACH,eAAOjB,EAAM,UAAA;AAGf,UAAIiB,EAAM,YAAY;AACpB,eAAO;AAGT,YAAME,IAAcC,EAAWH,GAAOjB,GAAOiB,EAAM,OAAO;AAuE1D,cArEwB,CAACI,MAAgD;AACvE,cAAMC,IAAqBD,EAAW,OAAO,CAAAE,MAASA,KAAS,IAAI;AACnE,YAAI,CAACN,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