@flowgram-vue/form-core 0.2.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 +22 -0
- package/dist/index.cjs +0 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +0 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
- package/src/client/NodeRender.vue +76 -0
- package/src/client/create-node-container-modules.ts +12 -0
- package/src/client/create-node-entity-datas.ts +13 -0
- package/src/client/index.ts +11 -0
- package/src/client/node-material-client.ts +18 -0
- package/src/client/node-render.ts +6 -0
- package/src/env.d.ts +10 -0
- package/src/error/client.ts +12 -0
- package/src/error/error-container-module.ts +14 -0
- package/src/error/error-node-contribution.ts +17 -0
- package/src/error/flow-node-error-data.ts +26 -0
- package/src/error/index.ts +9 -0
- package/src/error/renders/ErrorRender.vue +61 -0
- package/src/error/renders/default-error-render.ts +15 -0
- package/src/error/renders/error-render.ts +19 -0
- package/src/error/renders/index.ts +6 -0
- package/src/error/types.ts +13 -0
- package/src/form/FormRender.vue +39 -0
- package/src/form/abilities/decorator-ability/decorator-ability.ts +14 -0
- package/src/form/abilities/decorator-ability/index.ts +7 -0
- package/src/form/abilities/decorator-ability/types.ts +28 -0
- package/src/form/abilities/default-ability/default-ability.ts +14 -0
- package/src/form/abilities/default-ability/index.ts +7 -0
- package/src/form/abilities/default-ability/types.ts +15 -0
- package/src/form/abilities/effect-ability/effect-ability.ts +14 -0
- package/src/form/abilities/effect-ability/index.ts +7 -0
- package/src/form/abilities/effect-ability/types.ts +41 -0
- package/src/form/abilities/index.ts +11 -0
- package/src/form/abilities/setter-ability/index.ts +7 -0
- package/src/form/abilities/setter-ability/setter-ability.ts +14 -0
- package/src/form/abilities/setter-ability/types.ts +52 -0
- package/src/form/abilities/validation-ability/form-validate.types.ts +74 -0
- package/src/form/abilities/validation-ability/index.ts +7 -0
- package/src/form/abilities/validation-ability/types.ts +44 -0
- package/src/form/abilities/validation-ability/validation-ability.ts +14 -0
- package/src/form/abilities/visibility-ability/index.ts +6 -0
- package/src/form/abilities/visibility-ability/visibility-ability.ts +25 -0
- package/src/form/client/index.ts +17 -0
- package/src/form/flow-node-form-data.ts +109 -0
- package/src/form/form-contribution.ts +12 -0
- package/src/form/form-core-container-module.ts +19 -0
- package/src/form/form-node-contribution.ts +16 -0
- package/src/form/form-render.ts +13 -0
- package/src/form/index.ts +13 -0
- package/src/form/models/form-ability-extension-registry.ts +30 -0
- package/src/form/models/form-item-ability.ts +18 -0
- package/src/form/models/form-item-material-context.ts +50 -0
- package/src/form/models/form-item.ts +53 -0
- package/src/form/models/form-meta.ts +62 -0
- package/src/form/models/form-model.ts +84 -0
- package/src/form/models/index.ts +11 -0
- package/src/form/services/form-context-maker.ts +35 -0
- package/src/form/services/form-manager.ts +113 -0
- package/src/form/services/form-path-service.ts +88 -0
- package/src/form/services/index.ts +8 -0
- package/src/form/types/form-ability.types.ts +65 -0
- package/src/form/types/form-meta.types.ts +121 -0
- package/src/form/types/form-model.types.ts +33 -0
- package/src/form/types/index.ts +8 -0
- package/src/index.ts +10 -0
- package/src/node/core-materials.ts +9 -0
- package/src/node/core-plugins.ts +9 -0
- package/src/node/index.ts +13 -0
- package/src/node/node-container-module.ts +16 -0
- package/src/node/node-contribution.ts +12 -0
- package/src/node/node-engine-context.ts +54 -0
- package/src/node/node-engine.ts +16 -0
- package/src/node/node-manager.ts +63 -0
- package/src/node/types.ts +30 -0
- package/src/node-vue/composables/index.ts +7 -0
- package/src/node-vue/composables/use-form-item.ts +28 -0
- package/src/node-vue/composables/use-node-engine-context.ts +25 -0
- package/src/node-vue/context/index.ts +6 -0
- package/src/node-vue/context/node-engine-vue-context.ts +24 -0
- package/src/node-vue/hooks/index.ts +6 -0
- package/src/node-vue/index.ts +7 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { injectable } from 'inversify';
|
|
7
|
+
|
|
8
|
+
import { NodeContribution } from '../node';
|
|
9
|
+
import { NodeManager, PLUGIN_KEY } from '../node';
|
|
10
|
+
import { errorPluginRender } from './renders';
|
|
11
|
+
|
|
12
|
+
@injectable()
|
|
13
|
+
export class ErrorNodeContribution implements NodeContribution {
|
|
14
|
+
onRegister(nodeManager: NodeManager) {
|
|
15
|
+
nodeManager.registerPluginRender(PLUGIN_KEY.ERROR, errorPluginRender);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EntityData } from '@flowgram-vue/core';
|
|
7
|
+
|
|
8
|
+
export interface ErrorData {
|
|
9
|
+
error: Error | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class FlowNodeErrorData extends EntityData {
|
|
13
|
+
static type = 'FlowNodeErrorData';
|
|
14
|
+
|
|
15
|
+
getDefaultData(): ErrorData {
|
|
16
|
+
return { error: null };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setError(e: ErrorData['error']) {
|
|
20
|
+
this.update({ error: e });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getError(): Error {
|
|
24
|
+
return this.data.error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { defineComponent, onBeforeUnmount, type PropType } from 'vue';
|
|
7
|
+
|
|
8
|
+
import { FlowNodeEntity } from '@flowgram-vue/document';
|
|
9
|
+
import { PlaygroundContext, useRefresh, useService, PluginContext } from '@flowgram-vue/core';
|
|
10
|
+
|
|
11
|
+
import { FlowNodeErrorData } from '../flow-node-error-data';
|
|
12
|
+
import { MATERIAL_KEY, NodeManager } from '../../node';
|
|
13
|
+
import { defaultErrorRender } from './default-error-render';
|
|
14
|
+
|
|
15
|
+
export default defineComponent({
|
|
16
|
+
name: 'ErrorRender',
|
|
17
|
+
props: {
|
|
18
|
+
node: { type: Object as PropType<FlowNodeEntity>, required: true },
|
|
19
|
+
playgroundContext: { type: Object as PropType<PlaygroundContext>, required: true },
|
|
20
|
+
clientContext: { type: Object as PropType<PluginContext>, required: true },
|
|
21
|
+
},
|
|
22
|
+
setup(props) {
|
|
23
|
+
const refresh = useRefresh();
|
|
24
|
+
const nodeErrorData = props.node.getData<FlowNodeErrorData>(FlowNodeErrorData);
|
|
25
|
+
const nodeManager = useService<NodeManager>(NodeManager);
|
|
26
|
+
const nodeErrorRender = nodeManager.getMaterialRender(MATERIAL_KEY.NODE_ERROR_RENDER);
|
|
27
|
+
|
|
28
|
+
const disposable = nodeErrorData.onDataChange(() => {
|
|
29
|
+
refresh();
|
|
30
|
+
});
|
|
31
|
+
onBeforeUnmount(() => {
|
|
32
|
+
disposable.dispose();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
const nodeError = nodeErrorData.getError();
|
|
37
|
+
if (!nodeError) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (!nodeErrorRender) {
|
|
41
|
+
return defaultErrorRender({
|
|
42
|
+
error: nodeError,
|
|
43
|
+
context: {
|
|
44
|
+
node: props.node,
|
|
45
|
+
playgroundContext: props.playgroundContext,
|
|
46
|
+
clientContext: props.clientContext,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return nodeErrorRender({
|
|
51
|
+
error: nodeError,
|
|
52
|
+
context: {
|
|
53
|
+
node: props.node,
|
|
54
|
+
playgroundContext: props.playgroundContext,
|
|
55
|
+
clientContext: props.clientContext,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { h } from 'vue';
|
|
7
|
+
|
|
8
|
+
import { NodeErrorRenderProps } from '../types';
|
|
9
|
+
|
|
10
|
+
const ERROR_STYLE = {
|
|
11
|
+
color: '#f54a45',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const defaultErrorRender = ({ error }: NodeErrorRenderProps) =>
|
|
15
|
+
h('div', { style: ERROR_STYLE }, error.message);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { h } from 'vue';
|
|
7
|
+
|
|
8
|
+
import { NodePluginRender } from '../../node';
|
|
9
|
+
import ErrorRender from './ErrorRender.vue';
|
|
10
|
+
|
|
11
|
+
export { default as ErrorRender } from './ErrorRender.vue';
|
|
12
|
+
export { defaultErrorRender } from './default-error-render';
|
|
13
|
+
|
|
14
|
+
export const errorPluginRender: NodePluginRender = (props) =>
|
|
15
|
+
h(ErrorRender, {
|
|
16
|
+
node: props.node,
|
|
17
|
+
playgroundContext: props.playgroundContext,
|
|
18
|
+
clientContext: props.clientContext,
|
|
19
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { NodeContext, Render } from '../node';
|
|
7
|
+
|
|
8
|
+
export interface NodeErrorRenderProps {
|
|
9
|
+
error: Error;
|
|
10
|
+
context: NodeContext;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type NodeErrorRender = Render<NodeErrorRenderProps>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
import { defineComponent, onBeforeUnmount, type PropType } from 'vue';
|
|
7
|
+
|
|
8
|
+
import { useRefresh } from '@flowgram-vue/utils';
|
|
9
|
+
import { FlowNodeEntity } from '@flowgram-vue/document';
|
|
10
|
+
|
|
11
|
+
import { FormModel } from './models';
|
|
12
|
+
import { FlowNodeFormData } from './flow-node-form-data';
|
|
13
|
+
|
|
14
|
+
function getFormModelFromNode(node: FlowNodeEntity) {
|
|
15
|
+
return node.getData(FlowNodeFormData)?.getFormModel<FormModel>();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default defineComponent({
|
|
19
|
+
name: 'FormRender',
|
|
20
|
+
props: {
|
|
21
|
+
node: { type: Object as PropType<FlowNodeEntity>, required: true },
|
|
22
|
+
},
|
|
23
|
+
setup(props) {
|
|
24
|
+
const refresh = useRefresh();
|
|
25
|
+
const formModel = getFormModelFromNode(props.node);
|
|
26
|
+
|
|
27
|
+
if (formModel) {
|
|
28
|
+
const disposable = formModel.onInitialized(() => {
|
|
29
|
+
refresh();
|
|
30
|
+
});
|
|
31
|
+
onBeforeUnmount(() => {
|
|
32
|
+
disposable.dispose();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return () => (formModel?.initialized ? formModel.render() : null);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export class DecoratorAbility implements FormItemAbility {
|
|
9
|
+
static readonly type = 'decorator';
|
|
10
|
+
|
|
11
|
+
get type(): string {
|
|
12
|
+
return DecoratorAbility.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemContext, FormItemFeedback } from '../../types';
|
|
7
|
+
import { SetterOrDecoratorContext } from '../../abilities/setter-ability';
|
|
8
|
+
|
|
9
|
+
export interface DecoratorAbilityOptions {
|
|
10
|
+
/**
|
|
11
|
+
* 已注册的decorator的唯一标识
|
|
12
|
+
*/
|
|
13
|
+
key: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface DecoratorComponentProps<CustomOptions = any>
|
|
17
|
+
extends FormItemFeedback,
|
|
18
|
+
FormItemContext {
|
|
19
|
+
readonly: boolean;
|
|
20
|
+
children?: any;
|
|
21
|
+
options: DecoratorAbilityOptions & CustomOptions;
|
|
22
|
+
context: SetterOrDecoratorContext;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DecoratorExtension {
|
|
26
|
+
key: string;
|
|
27
|
+
component: (props: DecoratorComponentProps) => any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export class DefaultAbility implements FormItemAbility {
|
|
9
|
+
static readonly type = 'default';
|
|
10
|
+
|
|
11
|
+
get type(): string {
|
|
12
|
+
return DefaultAbility.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemContext, FormItemMaterialContext } from '../..';
|
|
7
|
+
|
|
8
|
+
export interface GetDefaultValueProps extends FormItemContext {
|
|
9
|
+
options: DefaultAbilityOptions;
|
|
10
|
+
context: FormItemMaterialContext;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DefaultAbilityOptions<T = any> {
|
|
14
|
+
getDefaultValue: (params: GetDefaultValueProps) => T;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export class EffectAbility implements FormItemAbility {
|
|
9
|
+
static readonly type = 'effect';
|
|
10
|
+
|
|
11
|
+
get type(): string {
|
|
12
|
+
return EffectAbility.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemContext, FormItemEventName } from '../../types';
|
|
7
|
+
import { type FormItemMaterialContext } from '../../models/form-item-material-context';
|
|
8
|
+
|
|
9
|
+
export interface EffectAbilityOptions {
|
|
10
|
+
/**
|
|
11
|
+
* 已注册的effect 唯一标识
|
|
12
|
+
*/
|
|
13
|
+
key?: string;
|
|
14
|
+
/**
|
|
15
|
+
* 触发 effect 的事件
|
|
16
|
+
*/
|
|
17
|
+
event?: FormItemEventName;
|
|
18
|
+
/**
|
|
19
|
+
* 如果不使用已经注册的effect, 也支持直接写effect函数
|
|
20
|
+
*/
|
|
21
|
+
effect?: EffectFunction;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface EffectEvent {
|
|
25
|
+
target: any & { value: any };
|
|
26
|
+
currentTarget: any;
|
|
27
|
+
type: FormItemEventName;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface EffectProps<CustomOptions = any, Event = EffectEvent> extends FormItemContext {
|
|
31
|
+
event: Event;
|
|
32
|
+
options: EffectAbilityOptions & CustomOptions;
|
|
33
|
+
context: FormItemMaterialContext;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type EffectFunction = (props: EffectProps) => void;
|
|
37
|
+
|
|
38
|
+
export interface EffectExtension {
|
|
39
|
+
key: string;
|
|
40
|
+
effect: EffectFunction;
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export * from './setter-ability';
|
|
7
|
+
export * from './decorator-ability';
|
|
8
|
+
export * from './visibility-ability';
|
|
9
|
+
export * from './effect-ability';
|
|
10
|
+
export * from './default-ability';
|
|
11
|
+
export * from './validation-ability';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export class SetterAbility implements FormItemAbility {
|
|
9
|
+
static readonly type = 'setter';
|
|
10
|
+
|
|
11
|
+
get type(): string {
|
|
12
|
+
return SetterAbility.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Component } from 'vue';
|
|
7
|
+
|
|
8
|
+
import { FormItemContext, FormItemFeedback } from '../../types';
|
|
9
|
+
import { type FormItemMaterialContext } from '../../models/form-item-material-context';
|
|
10
|
+
import { ValidatorFunction } from '../../abilities/validation-ability';
|
|
11
|
+
|
|
12
|
+
export interface SetterAbilityOptions {
|
|
13
|
+
/**
|
|
14
|
+
* 已注册的setter的唯一标识
|
|
15
|
+
*/
|
|
16
|
+
key: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Setter context 是 FormItemMaterialContext 的外观
|
|
21
|
+
* 基于外观设计模式设计,屏蔽了FormItemMaterialContext中一些setter不可见的接口
|
|
22
|
+
* readonly: 对于setter 已经放在props 根级别,所以在这里屏蔽,防止干扰
|
|
23
|
+
* getFormItemValueByPath: setter需通过表单联动方式获取其他表单项的值,不推荐是用这个方法,所以屏蔽
|
|
24
|
+
*/
|
|
25
|
+
export type SetterOrDecoratorContext = Omit<
|
|
26
|
+
FormItemMaterialContext,
|
|
27
|
+
'getFormItemValueByPath' | 'readonly'
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export interface SetterComponentProps<T = any, CustomOptions = any>
|
|
31
|
+
extends FormItemFeedback,
|
|
32
|
+
FormItemContext {
|
|
33
|
+
value: T;
|
|
34
|
+
onChange: (v: T) => void;
|
|
35
|
+
/**
|
|
36
|
+
* 节点引擎全局readonly
|
|
37
|
+
*/
|
|
38
|
+
readonly: boolean;
|
|
39
|
+
children?: any;
|
|
40
|
+
options: SetterAbilityOptions & CustomOptions;
|
|
41
|
+
context: SetterOrDecoratorContext;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SetterExtension {
|
|
45
|
+
key: string;
|
|
46
|
+
component: (props: SetterComponentProps) => any;
|
|
47
|
+
validator?: ValidatorFunction;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type SetterHoc = (
|
|
51
|
+
Component: Component<SetterComponentProps>
|
|
52
|
+
) => Component<SetterComponentProps>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// export type ValidatorFormats =
|
|
7
|
+
// | 'url'
|
|
8
|
+
// | 'email'
|
|
9
|
+
// | 'ipv6'
|
|
10
|
+
// | 'ipv4'
|
|
11
|
+
// | 'number'
|
|
12
|
+
// | 'integer'
|
|
13
|
+
// | 'idcard'
|
|
14
|
+
// | 'qq'
|
|
15
|
+
// | 'phone'
|
|
16
|
+
// | 'money'
|
|
17
|
+
// | 'zh'
|
|
18
|
+
// | 'date'
|
|
19
|
+
// | 'zip'
|
|
20
|
+
// | (string & {});
|
|
21
|
+
//
|
|
22
|
+
// export interface IValidatorRules<Context = any> {
|
|
23
|
+
// format?: ValidatorFormats;
|
|
24
|
+
// validator?: ValidatorFunction<Context>;
|
|
25
|
+
// required?: boolean;
|
|
26
|
+
// pattern?: RegExp | string;
|
|
27
|
+
// max?: number;
|
|
28
|
+
// maximum?: number;
|
|
29
|
+
// maxItems?: number;
|
|
30
|
+
// minItems?: number;
|
|
31
|
+
// maxLength?: number;
|
|
32
|
+
// minLength?: number;
|
|
33
|
+
// exclusiveMaximum?: number;
|
|
34
|
+
// exclusiveMinimum?: number;
|
|
35
|
+
// minimum?: number;
|
|
36
|
+
// min?: number;
|
|
37
|
+
// len?: number;
|
|
38
|
+
// whitespace?: boolean;
|
|
39
|
+
// enum?: any[];
|
|
40
|
+
// const?: any;
|
|
41
|
+
// multipleOf?: number;
|
|
42
|
+
// uniqueItems?: boolean;
|
|
43
|
+
// maxProperties?: number;
|
|
44
|
+
// minProperties?: number;
|
|
45
|
+
// message?: string;
|
|
46
|
+
//
|
|
47
|
+
// [key: string]: any;
|
|
48
|
+
// }
|
|
49
|
+
//
|
|
50
|
+
// export interface IValidateResult {
|
|
51
|
+
// type: 'error' | 'warning';
|
|
52
|
+
// message: string;
|
|
53
|
+
// }
|
|
54
|
+
//
|
|
55
|
+
// export const isValidateResult = (obj: any): obj is IValidateResult =>
|
|
56
|
+
// Boolean(obj.type) && Boolean(obj.message);
|
|
57
|
+
//
|
|
58
|
+
// export type ValidatorFunctionResponse =
|
|
59
|
+
// | null
|
|
60
|
+
// | void
|
|
61
|
+
// | undefined
|
|
62
|
+
// | string
|
|
63
|
+
// | boolean
|
|
64
|
+
// | IValidateResult;
|
|
65
|
+
//
|
|
66
|
+
// export type ValidatorFunction<Context = any> = (
|
|
67
|
+
// value: any,
|
|
68
|
+
// ctx: Context,
|
|
69
|
+
// ) => ValidatorFunctionResponse | Promise<ValidatorFunctionResponse>;
|
|
70
|
+
//
|
|
71
|
+
// export type Validator<Context = any> =
|
|
72
|
+
// | ValidatorFormats
|
|
73
|
+
// | ValidatorFunction<Context>
|
|
74
|
+
// | IValidatorRules;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemMaterialContext } from '../../models';
|
|
7
|
+
|
|
8
|
+
// 这里参照了rehaje 的validator function 返回格式
|
|
9
|
+
export interface IValidateResult {
|
|
10
|
+
type: 'error' | 'warning';
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ValidatorFunctionResponse =
|
|
15
|
+
| null
|
|
16
|
+
| void
|
|
17
|
+
| undefined
|
|
18
|
+
| string
|
|
19
|
+
| boolean
|
|
20
|
+
| IValidateResult;
|
|
21
|
+
|
|
22
|
+
export interface ValidationAbilityOptions {
|
|
23
|
+
/**
|
|
24
|
+
* 已注册的validator唯一标识
|
|
25
|
+
*/
|
|
26
|
+
key?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 不使用已注册的validator 也支持在options中直接写validator
|
|
29
|
+
*/
|
|
30
|
+
validator?: ValidatorFunction;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ValidatorProps<T = any, CustomOptions = any> {
|
|
34
|
+
value: T;
|
|
35
|
+
options: ValidationAbilityOptions & CustomOptions;
|
|
36
|
+
context: FormItemMaterialContext;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ValidatorFunction = (props: ValidatorProps) => ValidatorFunctionResponse;
|
|
40
|
+
|
|
41
|
+
export interface ValidationExtension {
|
|
42
|
+
key: string;
|
|
43
|
+
validator: ValidatorFunction;
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export class ValidationAbility implements FormItemAbility {
|
|
9
|
+
static readonly type = 'validation';
|
|
10
|
+
|
|
11
|
+
get type(): string {
|
|
12
|
+
return ValidationAbility.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FormItemAbility } from '../../models/form-item-ability';
|
|
7
|
+
|
|
8
|
+
export interface VisibilityAbilityOptions {
|
|
9
|
+
/**
|
|
10
|
+
* 是否隐藏
|
|
11
|
+
*/
|
|
12
|
+
hidden: string | boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 隐藏是否要清空表单值, 默认为false
|
|
15
|
+
*/
|
|
16
|
+
clearWhenHidden?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class VisibilityAbility implements FormItemAbility {
|
|
20
|
+
static readonly type = 'visibility';
|
|
21
|
+
|
|
22
|
+
get type(): string {
|
|
23
|
+
return VisibilityAbility.type;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { FlowNodeEntity } from '@flowgram-vue/document';
|
|
7
|
+
|
|
8
|
+
import { FlowNodeFormData } from '../flow-node-form-data';
|
|
9
|
+
import { FormModel } from '../models';
|
|
10
|
+
|
|
11
|
+
export function isNodeFormReady(node: FlowNodeEntity) {
|
|
12
|
+
return node.getData<FlowNodeFormData>(FlowNodeFormData).getFormModel<FormModel>().initialized;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getFormModel(node: FlowNodeEntity) {
|
|
16
|
+
return node.getData<FlowNodeFormData>(FlowNodeFormData).formModel;
|
|
17
|
+
}
|