@flowgram.ai/form-core 0.1.0-alpha.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.
@@ -0,0 +1,890 @@
1
+ import React from 'react';
2
+ import { FlowNodeEntity } from '@flowgram.ai/document';
3
+ import { EntityData, PlaygroundContext, PluginContext, EntityDataRegistry } from '@flowgram.ai/core';
4
+ import * as inversify from 'inversify';
5
+ import { ContainerModule } from 'inversify';
6
+ import * as _flowgram_ai_utils from '@flowgram.ai/utils';
7
+ import { Emitter, MaybePromise, Event, DisposableCollection } from '@flowgram.ai/utils';
8
+
9
+ /**
10
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
11
+ * SPDX-License-Identifier: MIT
12
+ */
13
+
14
+ interface ErrorData {
15
+ error: Error | null;
16
+ }
17
+ declare class FlowNodeErrorData extends EntityData {
18
+ static type: string;
19
+ getDefaultData(): ErrorData;
20
+ setError(e: ErrorData['error']): void;
21
+ getError(): Error;
22
+ }
23
+
24
+ /**
25
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
26
+ * SPDX-License-Identifier: MIT
27
+ */
28
+
29
+ interface NodeErrorRenderProps {
30
+ error: Error;
31
+ context: NodeContext;
32
+ }
33
+ type NodeErrorRender = Render<NodeErrorRenderProps>;
34
+
35
+ /**
36
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
37
+ * SPDX-License-Identifier: MIT
38
+ */
39
+
40
+ declare const ErrorContainerModule: ContainerModule;
41
+
42
+ /**
43
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
44
+ * SPDX-License-Identifier: MIT
45
+ */
46
+
47
+ declare function getNodeError(node: FlowNodeEntity): Error;
48
+
49
+ /**
50
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
51
+ * SPDX-License-Identifier: MIT
52
+ */
53
+
54
+ interface NodeContext {
55
+ node: FlowNodeEntity;
56
+ playgroundContext: PlaygroundContext;
57
+ clientContext: PluginContext & Record<string, any>;
58
+ }
59
+ type Render<T = any> = (props: T) => any;
60
+ type NodePluginRender = Render<NodeContext>;
61
+ type NodePlaceholderRender = Render<NodeContext>;
62
+ interface NodeRenderProps {
63
+ node: FlowNodeEntity;
64
+ }
65
+ type NodeRenderHoc = (Component: React.JSXElementConstructor<NodeRenderProps>) => React.JSXElementConstructor<NodeRenderProps>;
66
+
67
+ /**
68
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
69
+ * SPDX-License-Identifier: MIT
70
+ */
71
+
72
+ declare enum MaterialRenderKey {
73
+ CustomNodeError = "Material_CustomNodeError"
74
+ }
75
+ declare class NodeManager {
76
+ readonly materialRenderRegistry: Map<string, Render>;
77
+ readonly pluginRenderRegistry: Map<string, Render>;
78
+ readonly nodeRenderHocs: NodeRenderHoc[];
79
+ protected nodeContributions: NodeContribution[];
80
+ registerMaterialRender(key: string, render: Render): void;
81
+ getMaterialRender(key: string): Render | undefined;
82
+ registerPluginRender(key: string, render: NodePluginRender): void;
83
+ getPluginRender(key: string): NodePluginRender | undefined;
84
+ registerNodeErrorRender(render: Render<NodeErrorRenderProps>): void;
85
+ get nodeRenderHoc(): (...args: any[]) => any;
86
+ registerNodeRenderHoc(hoc: NodeRenderHoc): void;
87
+ get nodeErrorRender(): Render | undefined;
88
+ protected init(): void;
89
+ }
90
+
91
+ /**
92
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
93
+ * SPDX-License-Identifier: MIT
94
+ */
95
+
96
+ declare const NodeContribution: unique symbol;
97
+ interface NodeContribution {
98
+ onRegister?(nodeManager: NodeManager): void;
99
+ }
100
+
101
+ /**
102
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
103
+ * SPDX-License-Identifier: MIT
104
+ */
105
+
106
+ declare const NodeContainerModule: ContainerModule;
107
+
108
+ /**
109
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
110
+ * SPDX-License-Identifier: MIT
111
+ */
112
+ declare const PLUGIN_KEY: {
113
+ FORM: string;
114
+ ERROR: string;
115
+ };
116
+
117
+ /**
118
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
119
+ * SPDX-License-Identifier: MIT
120
+ */
121
+ declare const MATERIAL_KEY: {
122
+ NODE_ERROR_RENDER: string;
123
+ NODE_PLACEHOLDER_RENDER: string;
124
+ };
125
+
126
+ interface INodeEngineContext {
127
+ readonly: boolean;
128
+ }
129
+ /**
130
+ * NodeEngineContext 在 Node Engine 中为全局单例, 它的作用是让Node之间共享数据。
131
+ * context 分为内置context(如 readonly) 和 自定义context(业务可以按需注入)
132
+ */
133
+ declare class NodeEngineContext {
134
+ static DEFAULT_READONLY: boolean;
135
+ static DEFAULT_JSON: {
136
+ readonly: boolean;
137
+ };
138
+ readonly onChangeEmitter: Emitter<NodeEngineContext>;
139
+ readonly onChange: _flowgram_ai_utils.Event<NodeEngineContext>;
140
+ private _readonly;
141
+ private _json;
142
+ get json(): INodeEngineContext;
143
+ get readonly(): boolean;
144
+ set readonly(value: boolean);
145
+ private fireChange;
146
+ private updateJSON;
147
+ }
148
+
149
+ /**
150
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
151
+ * SPDX-License-Identifier: MIT
152
+ */
153
+
154
+ declare class NodeEngine {
155
+ nodeManager: NodeManager;
156
+ context: NodeEngineContext;
157
+ }
158
+
159
+ /**
160
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
161
+ * SPDX-License-Identifier: MIT
162
+ */
163
+
164
+ declare const FormCoreContainerModule: ContainerModule;
165
+
166
+ /**
167
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
168
+ * SPDX-License-Identifier: MIT
169
+ */
170
+ interface FormItemAbility {
171
+ type: string;
172
+ /**
173
+ * 注册到formManager时钩子时调用
174
+ */
175
+ onAbilityRegister?: () => void;
176
+ }
177
+ interface AbilityClass {
178
+ type: string;
179
+ new (): FormItemAbility;
180
+ }
181
+
182
+ /**
183
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
184
+ * SPDX-License-Identifier: MIT
185
+ */
186
+ interface IFormItem<T = any> {
187
+ value: T;
188
+ }
189
+ declare enum FormItemEventName {
190
+ onFormValueChange = "onFormValueChange",
191
+ onFormItemInit = "onFormItemInit"
192
+ }
193
+ type FormModelValid = boolean | null;
194
+ type FeedbackStatus = 'error' | 'warning' | 'pending';
195
+ type FeedbackText = string;
196
+ interface FormItemFeedback {
197
+ feedbackStatus?: FeedbackStatus;
198
+ feedbackText?: FeedbackText;
199
+ }
200
+ interface FormFeedback {
201
+ feedbackStatus?: FeedbackStatus;
202
+ feedbackText?: FeedbackText;
203
+ path: string;
204
+ }
205
+ interface FormItemDomRef {
206
+ current: HTMLElement | null;
207
+ }
208
+
209
+ /**
210
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
211
+ * SPDX-License-Identifier: MIT
212
+ */
213
+
214
+ interface FormItemAbilityMeta<Options = any> {
215
+ type: string;
216
+ options: Options;
217
+ }
218
+ /**
219
+ * @deprecated
220
+ */
221
+ interface FormItemContext {
222
+ /**
223
+ * @deprecated Use context.node instead
224
+ */
225
+ formItemMeta: IFormItemMeta;
226
+ /**
227
+ * @deprecated
228
+ */
229
+ formItem: IFormItem;
230
+ /**
231
+ * @deprecated Use context.node instead
232
+ */
233
+ flowNodeEntity: FlowNodeEntity;
234
+ /**
235
+ * @deprecated Use context.playgroundContext instead
236
+ */
237
+ playgroundContext: PlaygroundContext;
238
+ }
239
+ interface FormItemHookParams extends FormItemContext {
240
+ formItem: IFormItem;
241
+ }
242
+ interface FormItemHooks<T> {
243
+ /**
244
+ * FormItem初始化钩子
245
+ */
246
+ onInit?: (params: FormItemHookParams & T) => void;
247
+ /**
248
+ * FormItem提交时钩子
249
+ */
250
+ onSubmit?: (params: FormItemHookParams & T) => void;
251
+ /**
252
+ * FormItem克隆时钩子
253
+ */
254
+ onClone?: (params: FormItemHookParams & T) => MaybePromise<void>;
255
+ /**
256
+ * 克隆后执行的逻辑
257
+ */
258
+ afterClone?: (params: FormItemHookParams & T) => void;
259
+ /**
260
+ * FormItem全局校验时钩子
261
+ */
262
+ onValidate?: (params: FormItemHookParams & T) => void;
263
+ }
264
+
265
+ /**
266
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
267
+ * SPDX-License-Identifier: MIT
268
+ */
269
+
270
+ type FormDataTypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
271
+ type FormDataType = string | number | boolean | FormDataObject | DataArray | null;
272
+ interface FormDataObject {
273
+ [key: string]: FormDataType;
274
+ }
275
+ type DataArray = Array<FormDataType>;
276
+ declare const FORM_VOID: "form-void";
277
+ interface TreeNode<T> {
278
+ name: string;
279
+ children?: TreeNode<T>[];
280
+ }
281
+ interface IFormItemMeta extends TreeNode<IFormItemMeta> {
282
+ /**
283
+ * 表单项名称
284
+ */
285
+ name: string;
286
+ /**
287
+ * 数据类型
288
+ */
289
+ type: FormDataTypeName | typeof FORM_VOID;
290
+ /**
291
+ * 枚举值
292
+ */
293
+ enum?: FormDataType[];
294
+ /**
295
+ * 数组类型item的数据类型描述
296
+ */
297
+ items?: IFormItemMeta;
298
+ /**
299
+ * 表单项标题
300
+ */
301
+ title?: string;
302
+ /**
303
+ * 表单项描述
304
+ */
305
+ description?: string;
306
+ /**
307
+ * 表单项默认值
308
+ */
309
+ default?: FormDataType;
310
+ /**
311
+ * 是否必填
312
+ */
313
+ required?: boolean;
314
+ /**
315
+ * 扩展能力
316
+ */
317
+ abilities?: FormItemAbilityMeta[];
318
+ /**
319
+ * 子表单项
320
+ */
321
+ children?: IFormItemMeta[];
322
+ }
323
+ interface IFormMeta {
324
+ /**
325
+ * 表单树结构root
326
+ */
327
+ root?: IFormItemMeta;
328
+ /**
329
+ * 表单全局配置
330
+ */
331
+ options?: IFormMetaOptions;
332
+ }
333
+ interface NodeFormContext {
334
+ node: FlowNodeEntity;
335
+ playgroundContext: PlaygroundContext;
336
+ }
337
+ interface IFormMetaOptions {
338
+ formatOnInit?: (value: any, context: NodeFormContext) => any;
339
+ formatOnSubmit?: (value: any, context: NodeFormContext) => any;
340
+ [key: string]: any;
341
+ }
342
+ interface FormMetaGeneratorParams<PlaygroundContext, FormValue = any> {
343
+ node: FlowNodeEntity;
344
+ playgroundContext: PlaygroundContext;
345
+ initialValue?: FormValue;
346
+ }
347
+ type FormMetaGenerator<PlaygroundContext = any, FormValue = any> = (params: FormMetaGeneratorParams<FormValue, FormValue>) => MaybePromise<IFormMeta>;
348
+ type FormMetaOrFormMetaGenerator = FormMetaGenerator | IFormMeta;
349
+
350
+ /**
351
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
352
+ * SPDX-License-Identifier: MIT
353
+ */
354
+
355
+ type FormModelFactory = (entity: FlowNodeEntity) => FormModel;
356
+ declare const FormModelFactory: unique symbol;
357
+ declare const FormModelEntity: unique symbol;
358
+ declare abstract class FormModel {
359
+ readonly onValidate: Event<FormModel>;
360
+ readonly onValidChange: Event<FormModelValid>;
361
+ readonly onFeedbacksChange: Event<FormFeedback[]>;
362
+ readonly onInitialized: Event<FormModel>;
363
+ protected toDispose: DisposableCollection;
364
+ /**
365
+ * @deprecated
366
+ * use `formModel.node` instead in FormModelV2
367
+ */
368
+ abstract get flowNodeEntity(): FlowNodeEntity;
369
+ /**
370
+ * @deprecated
371
+ */
372
+ abstract get formManager(): FormManager;
373
+ abstract get formMeta(): any;
374
+ abstract get initialized(): boolean;
375
+ abstract get valid(): FormModelValid;
376
+ abstract updateFormValues(value: any): void;
377
+ /**
378
+ * @deprecated
379
+ * use `formModel.getFieldIn` instead in FormModelV2 to get the model of a form field
380
+ * do not use this in FormModelV2 since it only return an empty Map.
381
+ */
382
+ abstract get formItemPathMap(): Map<string, IFormItem>;
383
+ /**
384
+ * @deprecated
385
+ */
386
+ abstract clearValid(): void;
387
+ abstract validate(): Promise<boolean>;
388
+ abstract validateWithFeedbacks(): Promise<FormFeedback[]>;
389
+ abstract init(formMetaOrFormMetaGenerator: any, initialValue?: any): MaybePromise<void>;
390
+ abstract toJSON(): any;
391
+ /**
392
+ * @deprecated
393
+ * use `formModel.getField` instead in FormModelV2
394
+ */
395
+ abstract getFormItemByPath(path: string): FormItem | undefined;
396
+ /**
397
+ * @deprecated
398
+ * use `formModel.getFieldValue` instead in FormModelV2 to get the model of a form field by path
399
+ */
400
+ abstract getFormItemValueByPath<T = any>(path: string): any | undefined;
401
+ abstract render(): any;
402
+ abstract dispose(): void;
403
+ }
404
+
405
+ declare abstract class FormItem {
406
+ readonly meta: IFormItemMeta;
407
+ readonly path: string;
408
+ readonly formModel: FormModel;
409
+ readonly onInitEventEmitter: Emitter<FormItem>;
410
+ readonly onInit: _flowgram_ai_utils.Event<FormItem>;
411
+ protected toDispose: DisposableCollection;
412
+ readonly onDispose: _flowgram_ai_utils.Event<void>;
413
+ private _domRef;
414
+ protected constructor(meta: IFormItemMeta, path: string, formModel: FormModel);
415
+ abstract get value(): any;
416
+ abstract set value(value: any);
417
+ abstract validate(): void;
418
+ set domRef(domRef: FormItemDomRef);
419
+ get domRef(): FormItemDomRef;
420
+ dispose(): void;
421
+ }
422
+
423
+ /**
424
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
425
+ * SPDX-License-Identifier: MIT
426
+ */
427
+
428
+ interface FormMetaTraverseParams {
429
+ formItemMeta: IFormItemMeta;
430
+ parentPath?: string;
431
+ handle: (params: {
432
+ formItemMeta: IFormItemMeta;
433
+ path: string;
434
+ }) => any;
435
+ }
436
+ declare class FormMeta implements IFormMeta {
437
+ constructor(root: IFormItemMeta, options: IFormMetaOptions);
438
+ protected _root: IFormItemMeta;
439
+ get root(): IFormItemMeta;
440
+ protected _options: IFormMetaOptions;
441
+ get options(): IFormMetaOptions;
442
+ static traverse({ formItemMeta, parentPath, handle }: FormMetaTraverseParams): void;
443
+ }
444
+
445
+ /**
446
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
447
+ * SPDX-License-Identifier: MIT
448
+ */
449
+ interface Extension {
450
+ key: string;
451
+ }
452
+ declare class FormAbilityExtensionRegistry {
453
+ protected registry: Map<string, Extension>;
454
+ register(extension: Extension): void;
455
+ get<T extends Extension>(key: string): T | undefined;
456
+ get objectMap(): Record<string, Extension>;
457
+ get collection(): Extension[];
458
+ }
459
+
460
+ /**
461
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
462
+ * SPDX-License-Identifier: MIT
463
+ */
464
+
465
+ interface FormItemMaterialContext {
466
+ /**
467
+ * 当前表单项的meta
468
+ */
469
+ meta: IFormItemMeta;
470
+ /**
471
+ * 当前表单项的路径
472
+ */
473
+ path: string;
474
+ /**
475
+ * 节点引擎全局readonly
476
+ */
477
+ readonly: boolean;
478
+ /**
479
+ * 通过路径获取表单项的值
480
+ * @param path 表单项在当前表单中的绝对路径,路径协议遵循glob
481
+ */
482
+ getFormItemValueByPath: <T>(path: string) => T;
483
+ /**
484
+ * 节点表单校验回调函数注册
485
+ */
486
+ onFormValidate: FormModel['onValidate'];
487
+ /**
488
+ * 获取Node模型
489
+ */
490
+ node: FlowNodeEntity;
491
+ /**
492
+ * 获取FormModel原始模型
493
+ */
494
+ form: FormModel;
495
+ /**
496
+ * 业务注入的全局context
497
+ */
498
+ playgroundContext: PlaygroundContext;
499
+ /**
500
+ * 数组场景下当前项的index
501
+ */
502
+ index?: number | undefined;
503
+ }
504
+
505
+ /**
506
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
507
+ * SPDX-License-Identifier: MIT
508
+ */
509
+
510
+ declare class SetterAbility implements FormItemAbility {
511
+ static readonly type = "setter";
512
+ get type(): string;
513
+ }
514
+
515
+ /**
516
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
517
+ * SPDX-License-Identifier: MIT
518
+ */
519
+
520
+ declare class ValidationAbility implements FormItemAbility {
521
+ static readonly type = "validation";
522
+ get type(): string;
523
+ }
524
+
525
+ /**
526
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
527
+ * SPDX-License-Identifier: MIT
528
+ */
529
+
530
+ interface IValidateResult {
531
+ type: 'error' | 'warning';
532
+ message: string;
533
+ }
534
+ type ValidatorFunctionResponse = null | void | undefined | string | boolean | IValidateResult;
535
+ interface ValidationAbilityOptions {
536
+ /**
537
+ * 已注册的validator唯一标识
538
+ */
539
+ key?: string;
540
+ /**
541
+ * 不使用已注册的validator 也支持在options中直接写validator
542
+ */
543
+ validator?: ValidatorFunction;
544
+ }
545
+ interface ValidatorProps<T = any, CustomOptions = any> {
546
+ value: T;
547
+ options: ValidationAbilityOptions & CustomOptions;
548
+ context: FormItemMaterialContext;
549
+ }
550
+ type ValidatorFunction = (props: ValidatorProps) => ValidatorFunctionResponse;
551
+ interface ValidationExtension {
552
+ key: string;
553
+ validator: ValidatorFunction;
554
+ }
555
+
556
+ /**
557
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
558
+ * SPDX-License-Identifier: MIT
559
+ */
560
+
561
+ interface SetterAbilityOptions {
562
+ /**
563
+ * 已注册的setter的唯一标识
564
+ */
565
+ key: string;
566
+ }
567
+ /**
568
+ * Setter context 是 FormItemMaterialContext 的外观
569
+ * 基于外观设计模式设计,屏蔽了FormItemMaterialContext中一些setter不可见的接口
570
+ * readonly: 对于setter 已经放在props 根级别,所以在这里屏蔽,防止干扰
571
+ * getFormItemValueByPath: setter需通过表单联动方式获取其他表单项的值,不推荐是用这个方法,所以屏蔽
572
+ */
573
+ type SetterOrDecoratorContext = Omit<FormItemMaterialContext, 'getFormItemValueByPath' | 'readonly'>;
574
+ interface SetterComponentProps<T = any, CustomOptions = any> extends FormItemFeedback, FormItemContext {
575
+ value: T;
576
+ onChange: (v: T) => void;
577
+ /**
578
+ * 节点引擎全局readonly
579
+ */
580
+ readonly: boolean;
581
+ children?: any;
582
+ options: SetterAbilityOptions & CustomOptions;
583
+ context: SetterOrDecoratorContext;
584
+ }
585
+ interface SetterExtension {
586
+ key: string;
587
+ component: (props: SetterComponentProps) => any;
588
+ validator?: ValidatorFunction;
589
+ }
590
+ type SetterHoc = (Component: React.JSXElementConstructor<SetterComponentProps>) => React.JSXElementConstructor<SetterComponentProps>;
591
+
592
+ /**
593
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
594
+ * SPDX-License-Identifier: MIT
595
+ */
596
+
597
+ declare class DecoratorAbility implements FormItemAbility {
598
+ static readonly type = "decorator";
599
+ get type(): string;
600
+ }
601
+
602
+ /**
603
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
604
+ * SPDX-License-Identifier: MIT
605
+ */
606
+
607
+ interface DecoratorAbilityOptions {
608
+ /**
609
+ * 已注册的decorator的唯一标识
610
+ */
611
+ key: string;
612
+ }
613
+ interface DecoratorComponentProps<CustomOptions = any> extends FormItemFeedback, FormItemContext {
614
+ readonly: boolean;
615
+ children?: any;
616
+ options: DecoratorAbilityOptions & CustomOptions;
617
+ context: SetterOrDecoratorContext;
618
+ }
619
+ interface DecoratorExtension {
620
+ key: string;
621
+ component: (props: DecoratorComponentProps) => any;
622
+ }
623
+
624
+ /**
625
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
626
+ * SPDX-License-Identifier: MIT
627
+ */
628
+
629
+ interface VisibilityAbilityOptions {
630
+ /**
631
+ * 是否隐藏
632
+ */
633
+ hidden: string | boolean;
634
+ /**
635
+ * 隐藏是否要清空表单值, 默认为false
636
+ */
637
+ clearWhenHidden?: boolean;
638
+ }
639
+ declare class VisibilityAbility implements FormItemAbility {
640
+ static readonly type = "visibility";
641
+ get type(): string;
642
+ }
643
+
644
+ /**
645
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
646
+ * SPDX-License-Identifier: MIT
647
+ */
648
+
649
+ declare class EffectAbility implements FormItemAbility {
650
+ static readonly type = "effect";
651
+ get type(): string;
652
+ }
653
+
654
+ /**
655
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
656
+ * SPDX-License-Identifier: MIT
657
+ */
658
+
659
+ interface EffectAbilityOptions {
660
+ /**
661
+ * 已注册的effect 唯一标识
662
+ */
663
+ key?: string;
664
+ /**
665
+ * 触发 effect 的事件
666
+ */
667
+ event?: FormItemEventName;
668
+ /**
669
+ * 如果不使用已经注册的effect, 也支持直接写effect函数
670
+ */
671
+ effect?: EffectFunction;
672
+ }
673
+ interface EffectEvent {
674
+ target: any & {
675
+ value: any;
676
+ };
677
+ currentTarget: any;
678
+ type: FormItemEventName;
679
+ }
680
+ interface EffectProps<CustomOptions = any, Event = EffectEvent> extends FormItemContext {
681
+ event: Event;
682
+ options: EffectAbilityOptions & CustomOptions;
683
+ context: FormItemMaterialContext;
684
+ }
685
+ type EffectFunction = (props: EffectProps) => void;
686
+ interface EffectExtension {
687
+ key: string;
688
+ effect: EffectFunction;
689
+ }
690
+
691
+ /**
692
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
693
+ * SPDX-License-Identifier: MIT
694
+ */
695
+
696
+ declare class DefaultAbility implements FormItemAbility {
697
+ static readonly type = "default";
698
+ get type(): string;
699
+ }
700
+
701
+ /**
702
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
703
+ * SPDX-License-Identifier: MIT
704
+ */
705
+
706
+ interface GetDefaultValueProps extends FormItemContext {
707
+ options: DefaultAbilityOptions;
708
+ context: FormItemMaterialContext;
709
+ }
710
+ interface DefaultAbilityOptions<T = any> {
711
+ getDefaultValue: (params: GetDefaultValueProps) => T;
712
+ }
713
+
714
+ /**
715
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
716
+ * SPDX-License-Identifier: MIT
717
+ */
718
+ declare class FormPathService {
719
+ static readonly ROOT = "/";
720
+ static readonly DIVIDER = "/";
721
+ static readonly RELATIVE_PARENT = "..";
722
+ static readonly RELATIVE_CURRENT = ".";
723
+ static readonly ARRAY = "[]";
724
+ static normalize(path: string): string;
725
+ static join(paths: string[]): string;
726
+ static toArrayPath(path: string): string;
727
+ static parseArrayItemPath(path: string): {
728
+ itemIndex: number;
729
+ arrayPath: string;
730
+ itemMetaPath: string;
731
+ } | null;
732
+ simplify(path: string): string;
733
+ }
734
+
735
+ /**
736
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
737
+ * SPDX-License-Identifier: MIT
738
+ */
739
+
740
+ declare class FormContextMaker {
741
+ readonly nodeEngineContext: NodeEngineContext;
742
+ readonly playgroundContext: PlaygroundContext;
743
+ makeFormItemMaterialContext(formItem: FormItem, options?: {
744
+ getIndex: () => number | undefined;
745
+ }): FormItemMaterialContext;
746
+ }
747
+
748
+ declare class FormManager {
749
+ readonly abilityRegistry: Map<string, FormItemAbility>;
750
+ readonly setterHocs: SetterHoc[];
751
+ readonly extensionRegistryMap: Map<string, FormAbilityExtensionRegistry>;
752
+ readonly pathManager: FormPathService;
753
+ readonly formContextMaker: FormContextMaker;
754
+ readonly playgroundContext: PlaygroundContext;
755
+ protected formContributions: FormContribution[];
756
+ private readonly onFormModelWillInitEmitter;
757
+ readonly onFormModelWillInit: _flowgram_ai_utils.Event<{
758
+ model: FormModel;
759
+ data: any;
760
+ }>;
761
+ get components(): Record<string, any>;
762
+ get decorators(): Record<string, any>;
763
+ registerAbilityExtension(type: string, extension: any): void;
764
+ getAbilityExtension(abilityType: string, extensionKey: string): any;
765
+ registerAbility(Ability: AbilityClass): void;
766
+ registerAbilities(Abilities: AbilityClass[]): void;
767
+ getAbility<ExtendAbility>(type: string): (FormItemAbility & ExtendAbility) | undefined;
768
+ /**
769
+ * @deprecated
770
+ * Setter Hoc and setter are no longer supported in NodeEngineV2
771
+ * @param hoc
772
+ */
773
+ registerSetterHoc(hoc: SetterHoc): void;
774
+ fireFormModelWillInit(model: FormModel, data: any): void;
775
+ dispose(): void;
776
+ protected init(): void;
777
+ }
778
+
779
+ /**
780
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
781
+ * SPDX-License-Identifier: MIT
782
+ */
783
+
784
+ declare const FormContribution: unique symbol;
785
+ interface FormContribution {
786
+ onRegister?(formManager: FormManager): void;
787
+ }
788
+
789
+ interface Options {
790
+ formModelFactory: FormModelFactory;
791
+ }
792
+ interface DetailChangeEvent {
793
+ path: string;
794
+ oldValue: any;
795
+ value: any;
796
+ initialized: boolean;
797
+ }
798
+ interface OnFormValuesChangePayload {
799
+ values: any;
800
+ prevValues: any;
801
+ name: string;
802
+ }
803
+ declare class FlowNodeFormData extends EntityData {
804
+ static type: string;
805
+ readonly formModel: FormModel;
806
+ protected flowNodeEntity: FlowNodeEntity;
807
+ /**
808
+ * @deprecated rehaje 版表单form Values change 事件
809
+ * @protected
810
+ */
811
+ protected onDetailChangeEmitter: Emitter<DetailChangeEvent>;
812
+ /**
813
+ * @deprecated 该方法为旧版引擎(rehaje)表单数据变更事件, 新版节点引擎请使用
814
+ * this.getFormModel<FormModelV2>().onFormValuesChange.
815
+ * @protected
816
+ */
817
+ readonly onDetailChange: _flowgram_ai_utils.Event<DetailChangeEvent>;
818
+ constructor(entity: FlowNodeEntity, opts: Options);
819
+ getFormModel<TFormModel>(): TFormModel;
820
+ getDefaultData(): any;
821
+ createForm(formMetaOrFormMetaGenerator: any, initialValue?: any): void;
822
+ updateFormValues(value: any): void;
823
+ recreateForm(formMetaOrFormMetaGenerator: FormMetaOrFormMetaGenerator, initialValue?: any): void;
824
+ toJSON(): any;
825
+ dispose(): void;
826
+ /**
827
+ * @deprecated rehaje 版表单form Values change 事件触发函数
828
+ * @protected
829
+ */
830
+ fireDetaiChange(detailChangeEvent: DetailChangeEvent): void;
831
+ }
832
+
833
+ /**
834
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
835
+ * SPDX-License-Identifier: MIT
836
+ */
837
+
838
+ declare function isNodeFormReady(node: FlowNodeEntity): boolean;
839
+ declare function getFormModel(node: FlowNodeEntity): FormModel;
840
+
841
+ /**
842
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
843
+ * SPDX-License-Identifier: MIT
844
+ */
845
+ declare function createNodeContainerModules(): inversify.ContainerModule[];
846
+
847
+ /**
848
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
849
+ * SPDX-License-Identifier: MIT
850
+ */
851
+
852
+ declare const NodeRender: React.MemoExoticComponent<({ node }: NodeRenderProps) => React.JSX.Element>;
853
+
854
+ /**
855
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
856
+ * SPDX-License-Identifier: MIT
857
+ */
858
+
859
+ declare function registerNodeErrorRender(nodeManager: NodeManager, render: Render): void;
860
+ declare function registerNodePlaceholderRender(nodeManager: NodeManager, render: NodePlaceholderRender): void;
861
+
862
+ /**
863
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
864
+ * SPDX-License-Identifier: MIT
865
+ */
866
+
867
+ declare function createNodeEntityDatas(): EntityDataRegistry[];
868
+
869
+ /**
870
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
871
+ * SPDX-License-Identifier: MIT
872
+ */
873
+
874
+ declare function useNodeEngineContext(): NodeEngineContext;
875
+
876
+ /**
877
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
878
+ * SPDX-License-Identifier: MIT
879
+ */
880
+
881
+ declare function useFormItem(path: string): IFormItem | undefined;
882
+
883
+ /**
884
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
885
+ * SPDX-License-Identifier: MIT
886
+ */
887
+
888
+ declare const NodeEngineReactContext: React.Context<INodeEngineContext>;
889
+
890
+ export { type AbilityClass, type DataArray, DecoratorAbility, type DecoratorAbilityOptions, type DecoratorComponentProps, type DecoratorExtension, DefaultAbility, type DefaultAbilityOptions, type DetailChangeEvent, EffectAbility, type EffectAbilityOptions, type EffectEvent, type EffectExtension, type EffectFunction, type EffectProps, ErrorContainerModule, type ErrorData, type Extension, FORM_VOID, type FeedbackStatus, type FeedbackText, FlowNodeErrorData, FlowNodeFormData, FormAbilityExtensionRegistry, FormContextMaker, FormContribution, FormCoreContainerModule, type FormDataObject, type FormDataType, type FormDataTypeName, type FormFeedback, FormItem, type FormItemAbility, type FormItemAbilityMeta, type FormItemContext, type FormItemDomRef, FormItemEventName, type FormItemFeedback, type FormItemHookParams, type FormItemHooks, type FormItemMaterialContext, FormManager, FormMeta, type FormMetaGenerator, type FormMetaGeneratorParams, type FormMetaOrFormMetaGenerator, type FormMetaTraverseParams, FormModel, FormModelEntity, FormModelFactory, type FormModelValid, FormPathService, type GetDefaultValueProps, type IFormItem, type IFormItemMeta, type IFormMeta, type IFormMetaOptions, type INodeEngineContext, type IValidateResult, MATERIAL_KEY, MaterialRenderKey, NodeContainerModule, type NodeContext, NodeContribution, NodeEngine, NodeEngineContext, NodeEngineReactContext, type NodeErrorRender, type NodeErrorRenderProps, type NodeFormContext, NodeManager, type NodePlaceholderRender, type NodePluginRender, NodeRender, type NodeRenderHoc, type NodeRenderProps, type OnFormValuesChangePayload, PLUGIN_KEY, type Render, SetterAbility, type SetterAbilityOptions, type SetterComponentProps, type SetterExtension, type SetterHoc, type SetterOrDecoratorContext, type TreeNode, ValidationAbility, type ValidationAbilityOptions, type ValidationExtension, type ValidatorFunction, type ValidatorFunctionResponse, type ValidatorProps, VisibilityAbility, type VisibilityAbilityOptions, createNodeContainerModules, createNodeEntityDatas, getFormModel, getNodeError, isNodeFormReady, registerNodeErrorRender, registerNodePlaceholderRender, useFormItem, useNodeEngineContext };