fx-platform-ui 0.0.2 → 0.0.3

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 (45) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/lib/fx-platform-ui.mjs +26210 -6477
  3. package/lib/fx-platform-ui.umd.js +58 -14
  4. package/lib/packages/components/form/index.d.ts +2 -0
  5. package/lib/packages/components/form/src/hook/index.d.ts +9 -0
  6. package/lib/packages/components/form/src/hook/useFormContext.d.ts +3 -0
  7. package/lib/packages/components/form/src/hook/useFormEvents.d.ts +29 -0
  8. package/lib/packages/components/form/src/hook/useFormLabel.d.ts +79 -0
  9. package/lib/packages/components/form/src/hook/useFormMethods.d.ts +13 -0
  10. package/lib/packages/components/form/src/methods.d.ts +7 -0
  11. package/lib/packages/components/form/src/plat-form-emits.d.ts +9 -0
  12. package/lib/packages/components/form/src/types/form.d.ts +70 -0
  13. package/lib/packages/components/form/src/types/index.d.ts +2 -0
  14. package/lib/packages/types/global.d.ts +81 -0
  15. package/lib/packages/types/index.d.ts +27 -0
  16. package/lib/packages/utils/dateUtil.d.ts +7 -0
  17. package/lib/packages/utils/index.d.ts +11 -0
  18. package/lib/packages/utils/is/index.d.ts +22 -0
  19. package/lib/style.css +1 -1
  20. package/package.json +5 -2
  21. package/packages/component.ts +3 -2
  22. package/packages/components/form/index.tsx +10 -0
  23. package/packages/components/form/src/components/form-action.vue +131 -0
  24. package/packages/components/form/src/hook/index.ts +12 -0
  25. package/packages/components/form/src/hook/useForm.tsx +61 -0
  26. package/packages/components/form/src/hook/useFormContext.ts +12 -0
  27. package/packages/components/form/src/hook/useFormEvents.ts +274 -0
  28. package/packages/components/form/src/hook/useFormLabel.ts +42 -0
  29. package/packages/components/form/src/hook/useFormMethods.ts +137 -0
  30. package/packages/components/form/src/hook/useFormState.ts +80 -0
  31. package/packages/components/form/src/index.vue +124 -0
  32. package/packages/components/form/src/methods.ts +49 -0
  33. package/packages/components/form/src/plat-form-emits.ts +13 -0
  34. package/packages/components/form/src/plat-form-item.vue +421 -0
  35. package/packages/components/form/src/plat-form-props.ts +108 -0
  36. package/packages/components/form/src/types/component.ts +167 -0
  37. package/packages/components/form/src/types/form.ts +130 -0
  38. package/packages/components/form/src/types/index.ts +2 -0
  39. package/packages/types/global.d.ts +81 -0
  40. package/packages/types/index.d.ts +27 -0
  41. package/packages/utils/dateUtil.ts +24 -0
  42. package/packages/utils/index.ts +33 -0
  43. package/packages/utils/is/index.ts +104 -0
  44. package/lib/packages/component.d.ts +0 -7
  45. package/packages/utils/className.ts +0 -28
@@ -0,0 +1,130 @@
1
+ import type { ColEx, ComponentMapType, ComponentProps } from './component'
2
+ import type { Component, VNode } from 'vue'
3
+ import type { RuleObject } from 'ant-design-vue/lib/form/interface'
4
+ import type { FormItemProps } from 'ant-design-vue/es/form/FormItem'
5
+ import type { PlatFormType } from '../hook'
6
+
7
+ export type Rule = RuleObject & {
8
+ trigger?: 'blur' | 'change' | ['change', 'blur']
9
+ }
10
+
11
+ export interface RenderCallbackParams<T = string> {
12
+ schema: FormSchema<T>
13
+ formModel: Recordable<T>
14
+ field: string
15
+ values: any
16
+ // /** 动态表单实例 */
17
+ // @ts-ignore
18
+ formInstance: PlatFormType
19
+ // /** 动态表格实例 */
20
+ // tableInstance?: TableActionType;
21
+ // /** 作用域插槽数据 */
22
+ slotData?: Recordable
23
+ }
24
+
25
+ /** 自定义VNode渲染器 */
26
+ export type CustomRenderFn<T = any> = (
27
+ renderCallbackParams: RenderCallbackParams<T>
28
+ ) => VNode | VNode[] | string
29
+
30
+ export interface HelpComponentProps {
31
+ maxWidth: string
32
+ // Whether to display the serial number
33
+ showIndex: boolean
34
+ // Text list
35
+ text: any
36
+ // colour
37
+ color: string
38
+ // font size
39
+ fontSize: string
40
+ icon: string
41
+ absolute: boolean
42
+ // Positioning
43
+ position: any
44
+ }
45
+
46
+ /** 表单项 */
47
+ export interface FormSchema<T = string> {
48
+ /** 字段名 */
49
+ field: any
50
+ // Event name triggered by internal value change, default change
51
+ changeEvent?: string
52
+ // Variable name bound to v-model Default value
53
+ valueField?: string
54
+ // Label name
55
+ label?: string
56
+ // Auxiliary text
57
+ subLabel?: string
58
+ // Help text on the right side of the text
59
+ helpMessage?:
60
+ | string
61
+ | string[]
62
+ | ((renderCallbackParams: RenderCallbackParams<T>) => string | string[])
63
+ // BaseHelp component props
64
+ helpComponentProps?: Partial<HelpComponentProps>
65
+ // Label width, if it is passed, the labelCol and WrapperCol configured by itemProps will be invalid
66
+ labelWidth?: string | number
67
+ // Disable the adjustment of labelWidth with global settings of formModel, and manually set labelCol and wrapperCol by yourself
68
+ disabledLabelWidth?: boolean
69
+ /** 表单项对应的组件,eg: Input */
70
+ component?: ComponentMapType | ((opt: RenderCallbackParams<T>) => Component)
71
+ /** 表单组件属性 */
72
+ componentProps?:
73
+ | ComponentProps
74
+ | {
75
+ (opt: RenderCallbackParams<T>): ComponentProps
76
+ requestResult: ComponentProps['requestResult']
77
+ }
78
+ /** 表单组件slots,例如 a-input 的 suffix slot 可以写成:{ suffix: () => VNode } */
79
+ componentSlots?: any
80
+ // Required
81
+ required?:
82
+ | boolean
83
+ | ((renderCallbackParams: RenderCallbackParams<T>) => boolean)
84
+
85
+ suffix?:
86
+ | string
87
+ | number
88
+ | ((values: RenderCallbackParams<T>) => string | number)
89
+
90
+ // Validation rules
91
+ rules?: Rule[]
92
+ // Check whether the information is added to the label
93
+ rulesMessageJoinLabel?: boolean
94
+ /** 组件加载状态 */
95
+ loading?: boolean
96
+
97
+ // Reference formModelItem
98
+ formItemProps?: Partial<FormItemProps>
99
+
100
+ // col configuration outside formModelItem
101
+ colProps?: Partial<ColEx>
102
+
103
+ // 默认值
104
+ defaultValue?: any
105
+ isAdvanced?: boolean
106
+
107
+ // Matching details components
108
+ span?: number
109
+ /** 作用同v-show */
110
+ vShow?: boolean | ((renderCallbackParams: RenderCallbackParams<T>) => boolean)
111
+ /** 作用同v-if */
112
+ vIf?: boolean | ((renderCallbackParams: RenderCallbackParams<T>) => boolean)
113
+
114
+ // 渲染col内容需要外层包装form-item
115
+ renderColContent?: (
116
+ renderCallbackParams: RenderCallbackParams
117
+ ) => VNode | VNode[] | string
118
+
119
+ // Custom slot, in from-item
120
+ slot?: string
121
+
122
+ // 自定义槽,类似renderColContent
123
+ colSlot?: string
124
+
125
+ dynamicDisabled?:
126
+ | boolean
127
+ | ((renderCallbackParams: RenderCallbackParams<T>) => boolean)
128
+
129
+ dynamicRules?: (renderCallbackParams: RenderCallbackParams<T>) => Rule[]
130
+ }
@@ -0,0 +1,2 @@
1
+ export * from './form'
2
+ export * from './component'
@@ -0,0 +1,81 @@
1
+ import packageJSON from '../../package.json'
2
+ import type {
3
+ ComponentRenderProxy,
4
+ VNode,
5
+ VNodeChild,
6
+ SetupContext,
7
+ EmitsOptions,
8
+ PropType as VuePropType
9
+ } from 'vue'
10
+
11
+ declare global {
12
+ const __APP_INFO__: {
13
+ pkg: typeof packageJSON
14
+ lastBuildTime: string
15
+ }
16
+ // declare interface Window {
17
+ // // Global vue app instance
18
+ // __APP__: App<Element>;
19
+ // }
20
+
21
+ // vue
22
+ declare type PropType<T> = VuePropType<T>
23
+ declare type VueNode = VNodeChild | JSX.Element
24
+
25
+ export type Writable<T> = {
26
+ -readonly [P in keyof T]: T[P]
27
+ }
28
+ type RemoveIndex<T> = {
29
+ [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]
30
+ }
31
+ declare type Nullable<T> = T | null
32
+ declare type NonNullable<T> = T extends null | undefined ? never : T
33
+ declare type Recordable<T = any> = Record<string, T>
34
+ declare type ReadonlyRecordable<T = any> = {
35
+ readonly [key: string]: T
36
+ }
37
+ declare type Indexable<T = any> = {
38
+ [key: string]: T
39
+ }
40
+ declare type DeepPartial<T> = {
41
+ [P in keyof T]?: DeepPartial<T[P]>
42
+ }
43
+
44
+ declare type TimeoutHandle = ReturnType<typeof setTimeout>
45
+ declare type IntervalHandle = ReturnType<typeof setInterval>
46
+
47
+ declare interface ChangeEvent extends Event {
48
+ target: HTMLInputElement
49
+ }
50
+
51
+ declare interface WheelEvent {
52
+ path?: EventTarget[]
53
+ }
54
+ declare function parseInt(s: string | number, radix?: number): number
55
+
56
+ declare function parseFloat(string: string | number): number
57
+
58
+ declare type EmitFn<E = EmitsOptions> = SetupContext<E>['emit']
59
+
60
+ namespace JSX {
61
+ // tslint:disable no-empty-interface
62
+ type Element = VNode
63
+ // tslint:disable no-empty-interface
64
+ type ElementClass = ComponentRenderProxy
65
+ interface ElementAttributesProperty {
66
+ $props: any
67
+ }
68
+ interface IntrinsicElements {
69
+ [elem: string]: any
70
+ }
71
+ interface IntrinsicAttributes {
72
+ [elem: string]: any
73
+ }
74
+ }
75
+ }
76
+
77
+ declare module 'vue' {
78
+ export type JSXComponent<Props = any> =
79
+ | { new (): ComponentPublicInstance<Props> }
80
+ | FunctionalComponent<Props>
81
+ }
@@ -0,0 +1,27 @@
1
+ declare interface Fn<T = any, R = T> {
2
+ (...arg: T[]): R
3
+ }
4
+
5
+ declare interface PromiseFn<T = any, R = T> {
6
+ (...arg: T[]): Promise<R>
7
+ }
8
+
9
+ declare type RefType<T> = T | null
10
+
11
+ declare type LabelValueOptions = {
12
+ label: string
13
+ value: any
14
+ [key: string]: string | number | boolean
15
+ }[]
16
+
17
+ declare type EmitType = (event: string, ...args: any[]) => void
18
+
19
+ declare type TargetContext = '_self' | '_blank'
20
+
21
+ declare interface ComponentElRef<T extends HTMLElement = HTMLDivElement> {
22
+ $el: T
23
+ }
24
+
25
+ declare type ComponentRef<T extends HTMLElement = HTMLDivElement> = ComponentElRef<T> | null
26
+
27
+ declare type ElRef<T extends HTMLElement = HTMLDivElement> = Nullable<T>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Independent time operation tool to facilitate subsequent switch to dayjs
3
+ */
4
+ import dayjs from 'dayjs'
5
+ import 'dayjs/locale/zh-cn'
6
+
7
+ const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
8
+ const DATE_FORMAT = 'YYYY-MM-DD'
9
+
10
+ export function formatToDateTime(
11
+ date: dayjs.Dayjs | undefined = undefined,
12
+ format = DATE_TIME_FORMAT
13
+ ): string {
14
+ return dayjs(date).format(format)
15
+ }
16
+
17
+ export function formatToDate(
18
+ date: dayjs.Dayjs | undefined = undefined,
19
+ format = DATE_FORMAT
20
+ ): string {
21
+ return dayjs(date).format(format)
22
+ }
23
+
24
+ export const dateUtil = dayjs
@@ -0,0 +1,33 @@
1
+ import { type App } from 'vue'
2
+ import { isObject } from './is'
3
+
4
+ /**
5
+ *
6
+ * byte to size
7
+ * formatBytes(1024); // 1 KB
8
+ * formatBytes('1024'); // 1 KB
9
+ * formatBytes(1234); // 1.21 KB
10
+ * formatBytes(1234, 3); // 1.205 KB
11
+ * @param {number} bytes file size
12
+ */
13
+ export function formatSizeUnits(bytes, decimals = 2) {
14
+ if (bytes === 0) return '0 Bytes'
15
+
16
+ const k = 1024
17
+ const dm = decimals < 0 ? 0 : decimals
18
+ const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
19
+
20
+ const i = Math.floor(Math.log(bytes) / Math.log(k))
21
+
22
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
23
+ }
24
+
25
+ export function deepMerge<T = any>(src: any = {}, target: any = {}): T {
26
+ let key: string
27
+ for (key in target) {
28
+ src[key] = isObject(src[key])
29
+ ? deepMerge(src[key], target[key])
30
+ : (src[key] = target[key])
31
+ }
32
+ return src
33
+ }
@@ -0,0 +1,104 @@
1
+ const toString = Object.prototype.toString
2
+
3
+ export function is(val: unknown, type: string) {
4
+ return toString.call(val) === `[object ${type}]`
5
+ }
6
+
7
+ export function isDef<T = unknown>(val?: T): val is T {
8
+ return typeof val !== 'undefined'
9
+ }
10
+
11
+ export function isUnDef<T = unknown>(val?: T): val is T {
12
+ return !isDef(val)
13
+ }
14
+
15
+ export function isObject(val: any): val is Record<any, any> {
16
+ return val !== null && is(val, 'Object')
17
+ }
18
+
19
+ export function isEmpty<T = unknown>(val: T): val is T {
20
+ if (isArray(val) || isString(val)) {
21
+ return val.length === 0
22
+ }
23
+
24
+ if (val instanceof Map || val instanceof Set) {
25
+ return val.size === 0
26
+ }
27
+
28
+ if (isObject(val)) {
29
+ return Object.keys(val).length === 0
30
+ }
31
+
32
+ return false
33
+ }
34
+
35
+ export function isDate(val: unknown): val is Date {
36
+ return is(val, 'Date')
37
+ }
38
+
39
+ export function isNull(val: unknown): val is null {
40
+ return val === null
41
+ }
42
+
43
+ export function isNullAndUnDef(val: unknown): val is null | undefined {
44
+ return isUnDef(val) && isNull(val)
45
+ }
46
+
47
+ export function isNullOrUnDef(val: unknown): val is null | undefined {
48
+ return isUnDef(val) || isNull(val)
49
+ }
50
+
51
+ export function isNumber(val: unknown): val is number {
52
+ return is(val, 'Number')
53
+ }
54
+
55
+ export function isPromise<T = any>(val: unknown): val is Promise<T> {
56
+ return (
57
+ is(val, 'Promise') &&
58
+ isObject(val) &&
59
+ isFunction(val.then) &&
60
+ isFunction(val.catch)
61
+ )
62
+ }
63
+
64
+ export function isString(val: unknown): val is string {
65
+ return is(val, 'String')
66
+ }
67
+
68
+ export function isFunction(val: unknown): val is Function {
69
+ return typeof val === 'function'
70
+ }
71
+
72
+ export function isBoolean(val: unknown): val is boolean {
73
+ return is(val, 'Boolean')
74
+ }
75
+
76
+ export function isRegExp(val: unknown): val is RegExp {
77
+ return is(val, 'RegExp')
78
+ }
79
+
80
+ export function isArray(val: any): val is Array<any> {
81
+ return val && Array.isArray(val)
82
+ }
83
+
84
+ export function isWindow(val: any): val is Window {
85
+ return typeof window !== 'undefined' && is(val, 'Window')
86
+ }
87
+
88
+ export function isElement(val: unknown): val is Element {
89
+ return isObject(val) && !!val.tagName
90
+ }
91
+
92
+ export function isMap(val: unknown): val is Map<any, any> {
93
+ return is(val, 'Map')
94
+ }
95
+
96
+ export const isServer = typeof window === 'undefined'
97
+
98
+ export const isClient = !isServer
99
+
100
+ export function isUrl(path: string): boolean {
101
+ const reg =
102
+ /(((^https?:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)$/
103
+ return reg.test(path)
104
+ }
@@ -1,7 +0,0 @@
1
- /**
2
- * 导出所有组件
3
- */
4
- import PlCard from './components/card';
5
- declare const _default: import("vue").DefineComponent<unknown, object, {}, import("vue").ComputedOptions, import("vue").MethodOptions, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<unknown>, {}>[];
6
- export default _default;
7
- export { PlCard };
@@ -1,28 +0,0 @@
1
- import { isArray, isString, isObject } from './util'
2
-
3
- function className(...args: any[]) {
4
- const classes = []
5
- for (let i = 0; i < args.length; i++) {
6
- const value = args[i]
7
- if (!value) continue
8
- if (isString(value)) {
9
- classes.push(value)
10
- } else if (isArray(value)) {
11
- for (let i = 0; i < value.length; i++) {
12
- const inner: any = className(value[i])
13
- if (inner) {
14
- classes.push(inner)
15
- }
16
- }
17
- } else if (isObject(value)) {
18
- for (const name in value) {
19
- if (value[name]) {
20
- classes.push(name)
21
- }
22
- }
23
- }
24
- }
25
- return classes.join(' ')
26
- }
27
-
28
- export default className