@tmagic/form 1.4.8 → 1.4.10

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.
Files changed (63) hide show
  1. package/dist/style.css +4 -0
  2. package/dist/tmagic-form.js +13 -12
  3. package/dist/tmagic-form.umd.cjs +13 -12
  4. package/package.json +5 -5
  5. package/src/Form.vue +201 -0
  6. package/src/FormBox.vue +120 -0
  7. package/src/FormDialog.vue +173 -0
  8. package/src/FormDrawer.vue +159 -0
  9. package/src/containers/Col.vue +52 -0
  10. package/src/containers/Container.vue +408 -0
  11. package/src/containers/Fieldset.vue +124 -0
  12. package/src/containers/GroupList.vue +139 -0
  13. package/src/containers/GroupListItem.vue +135 -0
  14. package/src/containers/Panel.vue +99 -0
  15. package/src/containers/Row.vue +54 -0
  16. package/src/containers/Step.vue +82 -0
  17. package/src/containers/Table.vue +648 -0
  18. package/src/containers/Tabs.vue +226 -0
  19. package/src/fields/Cascader.vue +131 -0
  20. package/src/fields/Checkbox.vue +58 -0
  21. package/src/fields/CheckboxGroup.vue +44 -0
  22. package/src/fields/ColorPicker.vue +30 -0
  23. package/src/fields/Date.vue +38 -0
  24. package/src/fields/DateTime.vue +47 -0
  25. package/src/fields/Daterange.vue +99 -0
  26. package/src/fields/Display.vue +21 -0
  27. package/src/fields/DynamicField.vue +90 -0
  28. package/src/fields/Hidden.vue +16 -0
  29. package/src/fields/Link.vue +86 -0
  30. package/src/fields/Number.vue +49 -0
  31. package/src/fields/NumberRange.vue +50 -0
  32. package/src/fields/RadioGroup.vue +28 -0
  33. package/src/fields/Select.vue +449 -0
  34. package/src/fields/Switch.vue +59 -0
  35. package/src/fields/Text.vue +170 -0
  36. package/src/fields/Textarea.vue +46 -0
  37. package/src/fields/Time.vue +34 -0
  38. package/src/fields/Timerange.vue +76 -0
  39. package/src/index.ts +139 -0
  40. package/src/schema.ts +758 -0
  41. package/src/shims-vue.d.ts +6 -0
  42. package/src/theme/container.scss +5 -0
  43. package/src/theme/date-time.scss +7 -0
  44. package/src/theme/fieldset.scss +28 -0
  45. package/src/theme/form-box.scss +13 -0
  46. package/src/theme/form-dialog.scss +13 -0
  47. package/src/theme/form-drawer.scss +11 -0
  48. package/src/theme/form.scss +43 -0
  49. package/src/theme/group-list.scss +23 -0
  50. package/src/theme/index.scss +15 -0
  51. package/src/theme/link.scss +3 -0
  52. package/src/theme/number-range.scss +8 -0
  53. package/src/theme/panel.scss +24 -0
  54. package/src/theme/select.scss +3 -0
  55. package/src/theme/table.scss +70 -0
  56. package/src/theme/tabs.scss +27 -0
  57. package/src/theme/text.scss +6 -0
  58. package/src/utils/config.ts +27 -0
  59. package/src/utils/containerProps.ts +50 -0
  60. package/src/utils/form.ts +273 -0
  61. package/src/utils/useAddField.ts +40 -0
  62. package/types/schema.d.ts +7 -5
  63. package/types/utils/form.d.ts +2 -2
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { ComponentInternalInstance, getCurrentInstance, inject, watch } from 'vue';
20
+
21
+ import { FormState } from '../schema';
22
+
23
+ export const useAddField = (prop?: string) => {
24
+ if (!prop) return;
25
+ const mForm = inject<FormState | null>('mForm');
26
+ const instance = getCurrentInstance() as ComponentInternalInstance;
27
+ watch(
28
+ () => instance?.proxy,
29
+ (vm) => {
30
+ if (vm) {
31
+ mForm?.setField(prop, vm);
32
+ } else {
33
+ mForm?.deleteField(prop);
34
+ }
35
+ },
36
+ {
37
+ immediate: true,
38
+ },
39
+ );
40
+ };
package/types/schema.d.ts CHANGED
@@ -130,6 +130,7 @@ export type FilterFunction<T = boolean> = (mForm: FormState | undefined, data: {
130
130
  formValue: Record<any, any>;
131
131
  prop: string;
132
132
  config: any;
133
+ index?: number;
133
134
  }) => T;
134
135
  type OnChangeHandler = (mForm: FormState | undefined, value: any, data: {
135
136
  model: Record<any, any>;
@@ -346,16 +347,17 @@ export interface RadioGroupConfig extends FormItem {
346
347
  export interface ColorPickConfig extends FormItem {
347
348
  type: 'colorPicker';
348
349
  }
350
+ export interface CheckboxGroupOption {
351
+ value: any;
352
+ text: string;
353
+ disabled?: boolean;
354
+ }
349
355
  /**
350
356
  * 多选框组
351
357
  */
352
358
  export interface CheckboxGroupConfig extends FormItem {
353
359
  type: 'checkbox-group';
354
- options: {
355
- value: any;
356
- text: string;
357
- disabled?: boolean;
358
- }[] | Function;
360
+ options: CheckboxGroupOption[] | FilterFunction<CheckboxGroupOption[]>;
359
361
  }
360
362
  /**
361
363
  * 下拉选择器
@@ -1,6 +1,6 @@
1
- import { FormConfig, FormState, FormValue, Rule, TabPaneConfig } from '../schema';
1
+ import { FilterFunction, FormConfig, FormState, FormValue, Rule, TabPaneConfig } from '../schema';
2
2
  export declare const createValues: (mForm: FormState | undefined, config?: FormConfig | TabPaneConfig[], initValue?: FormValue, value?: FormValue) => FormValue;
3
- export declare const filterFunction: <T = any>(mForm: FormState | undefined, config: T, props: any) => any;
3
+ export declare const filterFunction: <T = any>(mForm: FormState | undefined, config: T | FilterFunction<T> | undefined, props: any) => T | undefined;
4
4
  export declare const display: (mForm: FormState | undefined, config: any, props: any) => any;
5
5
  export declare const getRules: (mForm: FormState | undefined, rules: Rule | Rule[] | undefined, props: any) => Rule[];
6
6
  export declare const initValue: (mForm: FormState | undefined, { initValues, config }: {