@vunk/form 2.7.1 → 2.9.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.
@@ -14,6 +14,7 @@ var templatesLayout = require('@vunk/form/components/templates-layout');
14
14
  var utilsObject = require('@vunk/core/shared/utils-object');
15
15
  var form = require('@vunk/form/shared/form');
16
16
  var rendererData = require('@vunk/form/components/renderer-data');
17
+ var object = require('@vunk/shared/object');
17
18
  var _pluginVue_exportHelper = require('../_plugin-vue_export-helper.cjs');
18
19
 
19
20
  const props = {
@@ -141,14 +142,19 @@ var _sfc_main = vue.defineComponent({
141
142
  a.push(c);
142
143
  return a;
143
144
  }
144
- if (Reflect.has(c, "templateIf")) {
145
+ if (!c.templateLayout?.allowEmpty && Reflect.has(c, "templateIf")) {
145
146
  const templateIfFunc = form.genTemplateIfFunc(c.templateIf);
146
147
  const flag = templateIfFunc(props2.data);
147
148
  if (!flag) {
148
149
  return a;
149
150
  }
150
151
  }
151
- const colItem = genColItem(c, props2.colSource);
152
+ const colItem = genColItem(c, object.pickObject({
153
+ ...props2.colSource,
154
+ ...c.templateLayout
155
+ }, {
156
+ excludes: ["allowEmpty", "span"]
157
+ }));
152
158
  if (!lastRow || getRowEmptySpan(lastRow) < itemSpan) {
153
159
  a.push(genRowItem(colItem, props2.rowSource));
154
160
  } else {
@@ -10,6 +10,7 @@ import { VkfTemplatesLayout } from '@vunk/form/components/templates-layout';
10
10
  import { pickObject } from '@vunk/core/shared/utils-object';
11
11
  import { genTemplateIfFunc } from '@vunk/form/shared/form';
12
12
  import { VkfRendererData } from '@vunk/form/components/renderer-data';
13
+ import { pickObject as pickObject$1 } from '@vunk/shared/object';
13
14
  import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
14
15
 
15
16
  const props = {
@@ -137,14 +138,19 @@ var _sfc_main = defineComponent({
137
138
  a.push(c);
138
139
  return a;
139
140
  }
140
- if (Reflect.has(c, "templateIf")) {
141
+ if (!c.templateLayout?.allowEmpty && Reflect.has(c, "templateIf")) {
141
142
  const templateIfFunc = genTemplateIfFunc(c.templateIf);
142
143
  const flag = templateIfFunc(props2.data);
143
144
  if (!flag) {
144
145
  return a;
145
146
  }
146
147
  }
147
- const colItem = genColItem(c, props2.colSource);
148
+ const colItem = genColItem(c, pickObject$1({
149
+ ...props2.colSource,
150
+ ...c.templateLayout
151
+ }, {
152
+ excludes: ["allowEmpty", "span"]
153
+ }));
148
154
  if (!lastRow || getRowEmptySpan(lastRow) < itemSpan) {
149
155
  a.push(genRowItem(colItem, props2.rowSource));
150
156
  } else {
@@ -1,12 +1,25 @@
1
1
  import { __VkfTemplatesDefault } from '@vunk/form/components/templates-default';
2
2
  import { __VkfTemplatesLayout } from '@vunk/form/components/templates-layout';
3
- export type FormItem<P extends string = string> = (__VkfTemplatesDefault.Source<P> | __VkfTemplatesLayout.ElRowSource<FormItem<P>> | __VkfTemplatesLayout.ElColSource<FormItem<P>> | __VkfTemplatesLayout.VkfFlexSource<FormItem<P>>) & {
3
+ import { VueComponentPropsType } from '@vunk/shared';
4
+ import { ElCol } from 'element-plus';
5
+ export type LayoutProps = {
4
6
  /**
5
- * 如果开启 props.itemLayout,那么
7
+ * 如果开启 props.layout,那么
6
8
  * span 将生效
7
9
  * 1-24 之间的数字
8
10
  */
9
11
  span?: number;
12
+ /**
13
+ * layout 配置
14
+ */
15
+ templateLayout?: TemplateLayout;
10
16
  };
17
+ export type FormItem<P extends string = string> = (__VkfTemplatesDefault.Source<P> | __VkfTemplatesLayout.ElRowSource<FormItem<P>> | __VkfTemplatesLayout.ElColSource<FormItem<P>> | __VkfTemplatesLayout.VkfFlexSource<FormItem<P>>) & LayoutProps;
11
18
  export type ColItem = __VkfTemplatesLayout.ElColSource<FormItem>;
12
19
  export type RowItem = __VkfTemplatesLayout.ElRowSource<ColItem>;
20
+ export interface TemplateLayout extends VueComponentPropsType<typeof ElCol> {
21
+ /**
22
+ * 允许空渲染
23
+ */
24
+ allowEmpty?: boolean;
25
+ }
@@ -25,6 +25,20 @@ const props = {
25
25
  }
26
26
  };
27
27
 
28
+ const genInputEffectFunc = (inputEffectRaw) => {
29
+ if (!inputEffectRaw) {
30
+ return;
31
+ }
32
+ if (typeof inputEffectRaw === "function") {
33
+ return inputEffectRaw;
34
+ }
35
+ if (typeof inputEffectRaw === "string") {
36
+ const inputEffect = new Function("value", "context", inputEffectRaw);
37
+ return inputEffect;
38
+ }
39
+ return _function.noop;
40
+ };
41
+
28
42
  const VkfFormItemRenderer$1 = vue.defineComponent({
29
43
  name: "VkfFormItemRenderer",
30
44
  props: props,
@@ -65,10 +79,12 @@ const VkfFormItemRenderer$1 = vue.defineComponent({
65
79
  _function.isCallable(c.templateProps) ? c.templateProps(rendererData?.value) : c.templateProps
66
80
  );
67
81
  const informationProps = _function.isCallable(slotData.informationProps) ? slotData.informationProps(rendererData?.value) : slotData.informationProps;
82
+ const inputEffect = genInputEffectFunc(slotData.inputEffect);
68
83
  Reflect.deleteProperty(slotData, "templateType");
69
84
  Reflect.deleteProperty(slotData, "templateIf");
70
85
  Reflect.deleteProperty(slotData, "templateProps");
71
86
  Reflect.deleteProperty(slotData, "informationProps");
87
+ Reflect.deleteProperty(slotData, "inputEffect");
72
88
  const nodeKey = currentK.join(",") + "-" + c.templateType + "-" + (c.prop || "no-prop");
73
89
  const modelValue = vue.computed({
74
90
  get: () => c.prop && getDataValue?.(c.prop),
@@ -77,7 +93,7 @@ const VkfFormItemRenderer$1 = vue.defineComponent({
77
93
  v
78
94
  })
79
95
  });
80
- const nodes = getTemplateInstance(c.templateType)?.slots.default?.({
96
+ const defaultSlotArguments = {
81
97
  // for legacy
82
98
  data: slotData,
83
99
  raw: c,
@@ -85,13 +101,21 @@ const VkfFormItemRenderer$1 = vue.defineComponent({
85
101
  k: currentK,
86
102
  key: nodeKey,
87
103
  value: modelValue.value,
88
- input: (v) => modelValue.value = v,
104
+ input: (v) => {
105
+ modelValue.value = v;
106
+ inputEffect?.(v, {
107
+ ...defaultSlotArguments,
108
+ parentProp: [c.prop].flat(Infinity).slice(0, -1)
109
+ });
110
+ },
89
111
  informationProps,
90
112
  templateIf,
91
113
  Renderer,
92
114
  getDataValue,
93
- emitSetData
94
- });
115
+ emitSetData,
116
+ inputEffect
117
+ };
118
+ const nodes = getTemplateInstance(c.templateType)?.slots.default?.(defaultSlotArguments);
95
119
  nodes && a.push(nodes);
96
120
  } else {
97
121
  validateTemplateType();
@@ -2,7 +2,7 @@ import { defineComponent, computed, h, nextTick, openBlock, createBlock, withCtx
2
2
  import { VkfTemplateInstancesProvider } from '@vunk/form/components/template-instances-provider';
3
3
  import { genTemplateIfFunc } from '@vunk/form/shared/form';
4
4
  import { useTemplateInstancesContext, useRendererData } from '@vunk/form/composables';
5
- import { isCallable } from '@vunk/shared/function';
5
+ import { noop, isCallable } from '@vunk/shared/function';
6
6
  import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
7
7
 
8
8
  const props = {
@@ -21,6 +21,20 @@ const props = {
21
21
  }
22
22
  };
23
23
 
24
+ const genInputEffectFunc = (inputEffectRaw) => {
25
+ if (!inputEffectRaw) {
26
+ return;
27
+ }
28
+ if (typeof inputEffectRaw === "function") {
29
+ return inputEffectRaw;
30
+ }
31
+ if (typeof inputEffectRaw === "string") {
32
+ const inputEffect = new Function("value", "context", inputEffectRaw);
33
+ return inputEffect;
34
+ }
35
+ return noop;
36
+ };
37
+
24
38
  const VkfFormItemRenderer$1 = defineComponent({
25
39
  name: "VkfFormItemRenderer",
26
40
  props: props,
@@ -61,10 +75,12 @@ const VkfFormItemRenderer$1 = defineComponent({
61
75
  isCallable(c.templateProps) ? c.templateProps(rendererData?.value) : c.templateProps
62
76
  );
63
77
  const informationProps = isCallable(slotData.informationProps) ? slotData.informationProps(rendererData?.value) : slotData.informationProps;
78
+ const inputEffect = genInputEffectFunc(slotData.inputEffect);
64
79
  Reflect.deleteProperty(slotData, "templateType");
65
80
  Reflect.deleteProperty(slotData, "templateIf");
66
81
  Reflect.deleteProperty(slotData, "templateProps");
67
82
  Reflect.deleteProperty(slotData, "informationProps");
83
+ Reflect.deleteProperty(slotData, "inputEffect");
68
84
  const nodeKey = currentK.join(",") + "-" + c.templateType + "-" + (c.prop || "no-prop");
69
85
  const modelValue = computed({
70
86
  get: () => c.prop && getDataValue?.(c.prop),
@@ -73,7 +89,7 @@ const VkfFormItemRenderer$1 = defineComponent({
73
89
  v
74
90
  })
75
91
  });
76
- const nodes = getTemplateInstance(c.templateType)?.slots.default?.({
92
+ const defaultSlotArguments = {
77
93
  // for legacy
78
94
  data: slotData,
79
95
  raw: c,
@@ -81,13 +97,21 @@ const VkfFormItemRenderer$1 = defineComponent({
81
97
  k: currentK,
82
98
  key: nodeKey,
83
99
  value: modelValue.value,
84
- input: (v) => modelValue.value = v,
100
+ input: (v) => {
101
+ modelValue.value = v;
102
+ inputEffect?.(v, {
103
+ ...defaultSlotArguments,
104
+ parentProp: [c.prop].flat(Infinity).slice(0, -1)
105
+ });
106
+ },
85
107
  informationProps,
86
108
  templateIf,
87
109
  Renderer,
88
110
  getDataValue,
89
- emitSetData
90
- });
111
+ emitSetData,
112
+ inputEffect
113
+ };
114
+ const nodes = getTemplateInstance(c.templateType)?.slots.default?.(defaultSlotArguments);
91
115
  nodes && a.push(nodes);
92
116
  } else {
93
117
  validateTemplateType();
@@ -0,0 +1,5 @@
1
+ import { BasicSource } from '@vunk/form/shared';
2
+ import { Func } from '@vunk/core';
3
+ export declare const genInputEffectFunc: Func<[
4
+ any
5
+ ], BasicSource['inputEffect']>;
@@ -2,7 +2,9 @@ import { __VkfFormItemRenderer } from '@vunk/form/components/form-item-renderer'
2
2
  import { NormalObject } from '@vunk/shared';
3
3
  import type { VkfFormItemRenderer } from '@vunk/form/components/form-item-renderer';
4
4
  import { MaybeArray, SetDataEvent } from '@vunk/core';
5
+ import { InputEffectContext } from '@vunk/form/shared';
5
6
  type RendererTreeData = __VkfFormItemRenderer.RendererTreeData;
7
+ type InternalField = 'templateType' | 'templateIf' | 'informationProps' | 'templateProps' | 'inputEffect';
6
8
  export interface DefaultSlotArguments {
7
9
  raw: RendererTreeData;
8
10
  /**
@@ -16,7 +18,7 @@ export interface DefaultSlotArguments {
16
18
  /**
17
19
  * 当前表单项的数据,排除渲染占用字段
18
20
  */
19
- props: Omit<RendererTreeData, 'templateType' | 'templateIf' | 'informationProps' | 'templateProps'>;
21
+ props: Omit<RendererTreeData, InternalField>;
20
22
  /**
21
23
  * 提供给 Information 组件的 props
22
24
  */
@@ -37,6 +39,10 @@ export interface DefaultSlotArguments {
37
39
  * 更新表单数据(如果formItem提供prop)
38
40
  */
39
41
  input?: (v: any) => void;
42
+ /**
43
+ * input 执行后的副操作
44
+ */
45
+ inputEffect?: (v: any, e: InputEffectContext) => void;
40
46
  /**
41
47
  * 从表单数据中获取对应的值
42
48
  */
@@ -11,6 +11,10 @@ var _pluginVue_exportHelper = require('../_plugin-vue_export-helper.cjs');
11
11
 
12
12
  const props = {
13
13
  ...formItem._VkfFormItemCtx.props,
14
+ information: {
15
+ type: Boolean,
16
+ default: true
17
+ },
14
18
  modelValue: {
15
19
  type: Array,
16
20
  default: () => []
@@ -39,8 +43,7 @@ var _sfc_main = /* @__PURE__ */ vue.defineComponent({
39
43
  }) {
40
44
  const formItemProps = formItem._VkfFormItemCtx.createBindProps(props2);
41
45
  return () => vue.createVNode(formItem.VkfFormItem, vue.mergeProps({
42
- "class": "vk-information-collection",
43
- "information": true
46
+ "class": "vk-information-collection"
44
47
  }, formItemProps.value), {
45
48
  default: () => [vue.createVNode("div", {
46
49
  "class": "vk-information-collection-value"
@@ -7,6 +7,10 @@ import { _ as _export_sfc } from '../_plugin-vue_export-helper.mjs';
7
7
 
8
8
  const props = {
9
9
  ..._VkfFormItemCtx.props,
10
+ information: {
11
+ type: Boolean,
12
+ default: true
13
+ },
10
14
  modelValue: {
11
15
  type: Array,
12
16
  default: () => []
@@ -35,8 +39,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
35
39
  }) {
36
40
  const formItemProps = _VkfFormItemCtx.createBindProps(props2);
37
41
  return () => createVNode(VkfFormItem, mergeProps({
38
- "class": "vk-information-collection",
39
- "information": true
42
+ "class": "vk-information-collection"
40
43
  }, formItemProps.value), {
41
44
  default: () => [createVNode("div", {
42
45
  "class": "vk-information-collection-value"
@@ -3,6 +3,10 @@ import { NormalObject } from '@vunk/shared';
3
3
  import { PropType } from 'vue';
4
4
  import { TagProps } from 'element-plus';
5
5
  export declare const props: {
6
+ information: {
7
+ type: BooleanConstructor;
8
+ default: boolean;
9
+ };
6
10
  modelValue: {
7
11
  type: {
8
12
  (arrayLength: number): NormalObject[];
@@ -79,10 +83,6 @@ export declare const props: {
79
83
  type: StringConstructor;
80
84
  default: any;
81
85
  };
82
- information: {
83
- type: BooleanConstructor;
84
- default: boolean;
85
- };
86
86
  label: StringConstructor;
87
87
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
88
88
  labelPosition: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "" | "top" | "left" | "right", unknown, "", boolean>;
@@ -1,4 +1,8 @@
1
1
  declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2
+ information: {
3
+ type: BooleanConstructor;
4
+ default: boolean;
5
+ };
2
6
  modelValue: {
3
7
  type: {
4
8
  (arrayLength: number): import("@vunk/shared").NormalObject[];
@@ -75,10 +79,6 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
75
79
  type: StringConstructor;
76
80
  default: any;
77
81
  };
78
- information: {
79
- type: BooleanConstructor;
80
- default: boolean;
81
- };
82
82
  label: StringConstructor;
83
83
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
84
84
  labelPosition: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "" | "top" | "left" | "right", unknown, "", boolean>;
@@ -105,6 +105,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
105
105
  inlineMessage: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, BooleanConstructor], unknown, unknown, "", boolean>;
106
106
  showMessage: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, true, boolean>;
107
107
  }>, () => JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
108
+ information: {
109
+ type: BooleanConstructor;
110
+ default: boolean;
111
+ };
108
112
  modelValue: {
109
113
  type: {
110
114
  (arrayLength: number): import("@vunk/shared").NormalObject[];
@@ -181,10 +185,6 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
181
185
  type: StringConstructor;
182
186
  default: any;
183
187
  };
184
- information: {
185
- type: BooleanConstructor;
186
- default: boolean;
187
- };
188
188
  label: StringConstructor;
189
189
  labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
190
190
  labelPosition: import("element-plus/es/utils").EpPropFinalized<StringConstructor, "" | "top" | "left" | "right", unknown, "", boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/form",
3
- "version": "2.7.1",
3
+ "version": "2.9.0",
4
4
  "description": "",
5
5
  "main": "index.esm.js",
6
6
  "scripts": {
@@ -4,24 +4,31 @@ import { __VkfTemplatesElementPlus } from '@vunk/form/components/templates-eleme
4
4
  import { __VkfTemplatesEsri } from '@vunk/form/components/templates-esri';
5
5
  import { AnyFunc, NormalObject } from '@vunk/core';
6
6
  import { __VkfTemplatesVariant } from '@vunk/form/components/templates-variant';
7
+ import { __VkfFormItemRendererTemplate } from '@vunk/form/components/form-item-renderer-template';
8
+ export interface InputEffectContext extends __VkfFormItemRendererTemplate.DefaultSlotArguments {
9
+ parentProp: Array<string | number>;
10
+ }
7
11
  export interface BasicSource {
8
12
  /**
9
13
  * @description 渲染的组件
10
14
  */
11
15
  templateType?: string;
12
- /**
13
- * @description 渲染时提供给组件的 props
14
- */
15
- templateProps?: NormalObject | AnyFunc;
16
16
  /**
17
17
  * @description 条件渲染
18
18
  */
19
19
  templateIf?: ((data: NormalObject) => boolean) | string | boolean;
20
+ /**
21
+ * @description 渲染时提供给组件的 props
22
+ */
23
+ templateProps?: NormalObject | AnyFunc;
20
24
  /**
21
25
  * @description 当被 Information 渲染时, 提供的 props
22
- *
23
26
  */
24
27
  informationProps?: NormalObject | AnyFunc;
28
+ /**
29
+ * @description 当 input 触发时, 产生的副作用
30
+ */
31
+ inputEffect?: (value: any, context: InputEffectContext) => void;
25
32
  /**
26
33
  * @description dom class
27
34
  */