@flowgram.ai/form-materials 0.3.1 → 0.3.2
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/bin/materials.ts +1 -0
- package/dist/esm/index.js +271 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +81 -5
- package/dist/index.d.ts +81 -5
- package/dist/index.js +304 -49
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/config.json +11 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/config.json +11 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/constant-input/config.json +1 -1
- package/src/components/display-outputs/index.tsx +7 -1
- package/src/components/display-schema-tree/config.json +1 -1
- package/src/components/index.ts +2 -0
- package/src/components/variable-selector/index.tsx +1 -1
- package/src/effects/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/config.json +5 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/index.ts +1 -0
- package/src/form-plugins/infer-assign-plugin/config.json +7 -0
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/index.ts +1 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +1 -1
- package/src/plugins/json-schema-preset/type-definition/array.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +2 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/config.json +7 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
AssignRow: () => AssignRow,
|
|
34
|
+
AssignRows: () => AssignRows,
|
|
33
35
|
BatchOutputs: () => BatchOutputs,
|
|
34
36
|
BatchVariableSelector: () => BatchVariableSelector,
|
|
35
37
|
CodeEditor: () => CodeEditor,
|
|
@@ -55,6 +57,7 @@ __export(src_exports, {
|
|
|
55
57
|
autoRenameRefEffect: () => autoRenameRefEffect,
|
|
56
58
|
createBatchOutputsFormPlugin: () => createBatchOutputsFormPlugin,
|
|
57
59
|
createDisableDeclarationPlugin: () => createDisableDeclarationPlugin,
|
|
60
|
+
createInferAssignPlugin: () => createInferAssignPlugin,
|
|
58
61
|
createInferInputsPlugin: () => createInferInputsPlugin,
|
|
59
62
|
createTypePresetPlugin: () => createTypePresetPlugin,
|
|
60
63
|
formatLegacyRefOnInit: () => formatLegacyRefOnInit,
|
|
@@ -70,7 +73,9 @@ __export(src_exports, {
|
|
|
70
73
|
provideJsonSchemaOutputs: () => provideJsonSchemaOutputs,
|
|
71
74
|
syncVariableTitle: () => syncVariableTitle,
|
|
72
75
|
useTypeManager: () => useTypeManager,
|
|
73
|
-
useVariableTree: () => useVariableTree
|
|
76
|
+
useVariableTree: () => useVariableTree,
|
|
77
|
+
validateFlowValue: () => validateFlowValue,
|
|
78
|
+
validateWhenVariableSync: () => validateWhenVariableSync
|
|
74
79
|
});
|
|
75
80
|
module.exports = __toCommonJS(src_exports);
|
|
76
81
|
|
|
@@ -800,7 +805,7 @@ var VariableSelector = ({
|
|
|
800
805
|
showClear: false,
|
|
801
806
|
arrowIcon: /* @__PURE__ */ import_react12.default.createElement(import_semi_icons.IconChevronDownStroked, { size: "small" }),
|
|
802
807
|
triggerRender,
|
|
803
|
-
placeholder: config?.placeholder ?? "Select Variable
|
|
808
|
+
placeholder: config?.placeholder ?? "Select Variable"
|
|
804
809
|
}
|
|
805
810
|
));
|
|
806
811
|
};
|
|
@@ -3146,7 +3151,16 @@ function DisplayOutputs({ value, showIconInTree, displayFromScope }) {
|
|
|
3146
3151
|
return acm;
|
|
3147
3152
|
}, {}) : value?.properties || {};
|
|
3148
3153
|
const childEntries = Object.entries(properties || {});
|
|
3149
|
-
return /* @__PURE__ */ import_react54.default.createElement(DisplayOutputsWrapper, null, childEntries.map(([key, schema]) => /* @__PURE__ */ import_react54.default.createElement(
|
|
3154
|
+
return /* @__PURE__ */ import_react54.default.createElement(DisplayOutputsWrapper, null, childEntries.map(([key, schema]) => /* @__PURE__ */ import_react54.default.createElement(
|
|
3155
|
+
DisplaySchemaTag,
|
|
3156
|
+
{
|
|
3157
|
+
key,
|
|
3158
|
+
title: key,
|
|
3159
|
+
value: schema,
|
|
3160
|
+
showIconInTree,
|
|
3161
|
+
warning: !schema
|
|
3162
|
+
}
|
|
3163
|
+
)));
|
|
3150
3164
|
}
|
|
3151
3165
|
|
|
3152
3166
|
// src/components/display-flow-value/index.tsx
|
|
@@ -3207,30 +3221,151 @@ function DisplayInputsValues({ value, showIconInTree }) {
|
|
|
3207
3221
|
return /* @__PURE__ */ import_react56.default.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => /* @__PURE__ */ import_react56.default.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree })));
|
|
3208
3222
|
}
|
|
3209
3223
|
|
|
3210
|
-
// src/
|
|
3224
|
+
// src/components/assign-rows/index.tsx
|
|
3225
|
+
var import_react59 = __toESM(require("react"));
|
|
3211
3226
|
var import_editor15 = require("@flowgram.ai/editor");
|
|
3212
|
-
var
|
|
3227
|
+
var import_semi_ui28 = require("@douyinfe/semi-ui");
|
|
3228
|
+
var import_semi_icons12 = require("@douyinfe/semi-icons");
|
|
3229
|
+
|
|
3230
|
+
// src/components/assign-row/index.tsx
|
|
3231
|
+
var import_react58 = __toESM(require("react"));
|
|
3232
|
+
var import_semi_ui27 = require("@douyinfe/semi-ui");
|
|
3233
|
+
var import_semi_icons11 = require("@douyinfe/semi-icons");
|
|
3234
|
+
|
|
3235
|
+
// src/components/assign-row/components/blur-input.tsx
|
|
3236
|
+
var import_react57 = __toESM(require("react"));
|
|
3237
|
+
var import_input3 = __toESM(require("@douyinfe/semi-ui/lib/es/input"));
|
|
3238
|
+
function BlurInput3(props) {
|
|
3239
|
+
const [value, setValue] = (0, import_react57.useState)("");
|
|
3240
|
+
(0, import_react57.useEffect)(() => {
|
|
3241
|
+
setValue(props.value);
|
|
3242
|
+
}, [props.value]);
|
|
3243
|
+
return /* @__PURE__ */ import_react57.default.createElement(
|
|
3244
|
+
import_input3.default,
|
|
3245
|
+
{
|
|
3246
|
+
...props,
|
|
3247
|
+
value,
|
|
3248
|
+
onChange: (value2) => {
|
|
3249
|
+
setValue(value2);
|
|
3250
|
+
},
|
|
3251
|
+
onBlur: (e) => props.onChange?.(value, e)
|
|
3252
|
+
}
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
// src/components/assign-row/index.tsx
|
|
3257
|
+
function AssignRow(props) {
|
|
3258
|
+
const {
|
|
3259
|
+
value = {
|
|
3260
|
+
operator: "assign"
|
|
3261
|
+
},
|
|
3262
|
+
onChange,
|
|
3263
|
+
onDelete,
|
|
3264
|
+
readonly
|
|
3265
|
+
} = props;
|
|
3266
|
+
return /* @__PURE__ */ import_react58.default.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5 } }, /* @__PURE__ */ import_react58.default.createElement("div", { style: { width: 150, minWidth: 150, maxWidth: 150 } }, value?.operator === "assign" ? /* @__PURE__ */ import_react58.default.createElement(
|
|
3267
|
+
VariableSelector,
|
|
3268
|
+
{
|
|
3269
|
+
style: { width: "100%", height: 26 },
|
|
3270
|
+
value: value?.left?.content,
|
|
3271
|
+
config: { placeholder: "Select Left" },
|
|
3272
|
+
onChange: (v) => onChange?.({
|
|
3273
|
+
...value,
|
|
3274
|
+
left: { type: "ref", content: v }
|
|
3275
|
+
})
|
|
3276
|
+
}
|
|
3277
|
+
) : /* @__PURE__ */ import_react58.default.createElement(
|
|
3278
|
+
BlurInput3,
|
|
3279
|
+
{
|
|
3280
|
+
style: { height: 26 },
|
|
3281
|
+
size: "small",
|
|
3282
|
+
placeholder: "Input Name",
|
|
3283
|
+
value: value?.left,
|
|
3284
|
+
onChange: (v) => onChange?.({
|
|
3285
|
+
...value,
|
|
3286
|
+
left: v
|
|
3287
|
+
})
|
|
3288
|
+
}
|
|
3289
|
+
)), /* @__PURE__ */ import_react58.default.createElement("div", { style: { flexGrow: 1 } }, /* @__PURE__ */ import_react58.default.createElement(
|
|
3290
|
+
DynamicValueInput,
|
|
3291
|
+
{
|
|
3292
|
+
readonly,
|
|
3293
|
+
value: value?.right,
|
|
3294
|
+
onChange: (v) => onChange?.({
|
|
3295
|
+
...value,
|
|
3296
|
+
right: v
|
|
3297
|
+
})
|
|
3298
|
+
}
|
|
3299
|
+
)), onDelete && /* @__PURE__ */ import_react58.default.createElement("div", null, /* @__PURE__ */ import_react58.default.createElement(
|
|
3300
|
+
import_semi_ui27.IconButton,
|
|
3301
|
+
{
|
|
3302
|
+
size: "small",
|
|
3303
|
+
theme: "borderless",
|
|
3304
|
+
icon: /* @__PURE__ */ import_react58.default.createElement(import_semi_icons11.IconMinus, null),
|
|
3305
|
+
onClick: () => onDelete?.()
|
|
3306
|
+
}
|
|
3307
|
+
)));
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
// src/components/assign-rows/index.tsx
|
|
3311
|
+
function AssignRows(props) {
|
|
3312
|
+
const { name, readonly } = props;
|
|
3313
|
+
return /* @__PURE__ */ import_react59.default.createElement(import_editor15.FieldArray, { name }, ({ field }) => /* @__PURE__ */ import_react59.default.createElement(import_react59.default.Fragment, null, field.map((childField, index) => /* @__PURE__ */ import_react59.default.createElement(
|
|
3314
|
+
AssignRow,
|
|
3315
|
+
{
|
|
3316
|
+
key: childField.key,
|
|
3317
|
+
readonly,
|
|
3318
|
+
value: childField.value,
|
|
3319
|
+
onChange: (value) => {
|
|
3320
|
+
childField.onChange(value);
|
|
3321
|
+
},
|
|
3322
|
+
onDelete: () => field.remove(index)
|
|
3323
|
+
}
|
|
3324
|
+
)), /* @__PURE__ */ import_react59.default.createElement("div", { style: { display: "flex", gap: 5 } }, /* @__PURE__ */ import_react59.default.createElement(
|
|
3325
|
+
import_semi_ui28.Button,
|
|
3326
|
+
{
|
|
3327
|
+
size: "small",
|
|
3328
|
+
theme: "borderless",
|
|
3329
|
+
icon: /* @__PURE__ */ import_react59.default.createElement(import_semi_icons12.IconPlus, null),
|
|
3330
|
+
onClick: () => field.append({ operator: "assign" })
|
|
3331
|
+
},
|
|
3332
|
+
"Assign"
|
|
3333
|
+
), /* @__PURE__ */ import_react59.default.createElement(
|
|
3334
|
+
import_semi_ui28.Button,
|
|
3335
|
+
{
|
|
3336
|
+
size: "small",
|
|
3337
|
+
theme: "borderless",
|
|
3338
|
+
icon: /* @__PURE__ */ import_react59.default.createElement(import_semi_icons12.IconPlus, null),
|
|
3339
|
+
onClick: () => field.append({ operator: "declare" })
|
|
3340
|
+
},
|
|
3341
|
+
"Declaration"
|
|
3342
|
+
))));
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3345
|
+
// src/effects/provide-batch-input/index.ts
|
|
3346
|
+
var import_editor16 = require("@flowgram.ai/editor");
|
|
3347
|
+
var provideBatchInputEffect = (0, import_editor16.createEffectFromVariableProvider)({
|
|
3213
3348
|
private: true,
|
|
3214
3349
|
parse: (value, ctx) => [
|
|
3215
|
-
|
|
3350
|
+
import_editor16.ASTFactory.createVariableDeclaration({
|
|
3216
3351
|
key: `${ctx.node.id}_locals`,
|
|
3217
3352
|
meta: {
|
|
3218
|
-
title: (0,
|
|
3353
|
+
title: (0, import_editor16.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
3219
3354
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
3220
3355
|
},
|
|
3221
|
-
type:
|
|
3356
|
+
type: import_editor16.ASTFactory.createObject({
|
|
3222
3357
|
properties: [
|
|
3223
|
-
|
|
3358
|
+
import_editor16.ASTFactory.createProperty({
|
|
3224
3359
|
key: "item",
|
|
3225
|
-
initializer:
|
|
3226
|
-
enumerateFor:
|
|
3360
|
+
initializer: import_editor16.ASTFactory.createEnumerateExpression({
|
|
3361
|
+
enumerateFor: import_editor16.ASTFactory.createKeyPathExpression({
|
|
3227
3362
|
keyPath: value.content || []
|
|
3228
3363
|
})
|
|
3229
3364
|
})
|
|
3230
3365
|
}),
|
|
3231
|
-
|
|
3366
|
+
import_editor16.ASTFactory.createProperty({
|
|
3232
3367
|
key: "index",
|
|
3233
|
-
type:
|
|
3368
|
+
type: import_editor16.ASTFactory.createNumber()
|
|
3234
3369
|
})
|
|
3235
3370
|
]
|
|
3236
3371
|
})
|
|
@@ -3240,13 +3375,13 @@ var provideBatchInputEffect = (0, import_editor15.createEffectFromVariableProvid
|
|
|
3240
3375
|
|
|
3241
3376
|
// src/effects/auto-rename-ref/index.ts
|
|
3242
3377
|
var import_lodash6 = require("lodash");
|
|
3243
|
-
var
|
|
3378
|
+
var import_editor17 = require("@flowgram.ai/editor");
|
|
3244
3379
|
var autoRenameRefEffect = [
|
|
3245
3380
|
{
|
|
3246
|
-
event:
|
|
3381
|
+
event: import_editor17.DataEvent.onValueInit,
|
|
3247
3382
|
effect: (params) => {
|
|
3248
3383
|
const { context, form, name } = params;
|
|
3249
|
-
const renameService = context.node.getService(
|
|
3384
|
+
const renameService = context.node.getService(import_editor17.VariableFieldKeyRenameService);
|
|
3250
3385
|
const disposable = renameService.onRename(({ before, after }) => {
|
|
3251
3386
|
const beforeKeyPath = [
|
|
3252
3387
|
...before.parentFields.map((_field) => _field.key).reverse(),
|
|
@@ -3331,13 +3466,13 @@ function traverseRef(name, value, cb) {
|
|
|
3331
3466
|
|
|
3332
3467
|
// src/effects/provide-json-schema-outputs/index.ts
|
|
3333
3468
|
var import_json_schema9 = require("@flowgram.ai/json-schema");
|
|
3334
|
-
var
|
|
3335
|
-
var provideJsonSchemaOutputs = (0,
|
|
3469
|
+
var import_editor18 = require("@flowgram.ai/editor");
|
|
3470
|
+
var provideJsonSchemaOutputs = (0, import_editor18.createEffectFromVariableProvider)({
|
|
3336
3471
|
parse: (value, ctx) => [
|
|
3337
|
-
|
|
3472
|
+
import_editor18.ASTFactory.createVariableDeclaration({
|
|
3338
3473
|
key: `${ctx.node.id}`,
|
|
3339
3474
|
meta: {
|
|
3340
|
-
title: (0,
|
|
3475
|
+
title: (0, import_editor18.getNodeForm)(ctx.node)?.getValueIn("title") || ctx.node.id,
|
|
3341
3476
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
3342
3477
|
},
|
|
3343
3478
|
type: import_json_schema9.JsonSchemaUtils.schemaToAST(value)
|
|
@@ -3346,12 +3481,12 @@ var provideJsonSchemaOutputs = (0, import_editor17.createEffectFromVariableProvi
|
|
|
3346
3481
|
});
|
|
3347
3482
|
|
|
3348
3483
|
// src/effects/sync-variable-title/index.ts
|
|
3349
|
-
var
|
|
3484
|
+
var import_editor19 = require("@flowgram.ai/editor");
|
|
3350
3485
|
var syncVariableTitle = [
|
|
3351
3486
|
{
|
|
3352
|
-
event:
|
|
3487
|
+
event: import_editor19.DataEvent.onValueChange,
|
|
3353
3488
|
effect: ({ value, context }) => {
|
|
3354
|
-
context.node.getData(
|
|
3489
|
+
context.node.getData(import_editor19.FlowNodeVariableData).allScopes.forEach((_scope) => {
|
|
3355
3490
|
_scope.output.variables.forEach((_var) => {
|
|
3356
3491
|
_var.updateMeta({
|
|
3357
3492
|
..._var.meta || {},
|
|
@@ -3364,10 +3499,30 @@ var syncVariableTitle = [
|
|
|
3364
3499
|
}
|
|
3365
3500
|
];
|
|
3366
3501
|
|
|
3367
|
-
// src/
|
|
3502
|
+
// src/effects/validate-when-variable-sync/index.ts
|
|
3368
3503
|
var import_lodash7 = require("lodash");
|
|
3504
|
+
var import_editor20 = require("@flowgram.ai/editor");
|
|
3505
|
+
var validateWhenVariableSync = ({
|
|
3506
|
+
scope
|
|
3507
|
+
} = {}) => [
|
|
3508
|
+
{
|
|
3509
|
+
event: import_editor20.DataEvent.onValueInit,
|
|
3510
|
+
effect: ({ context, form }) => {
|
|
3511
|
+
const nodeScope = scope === "private" ? (0, import_editor20.getNodePrivateScope)(context.node) : (0, import_editor20.getNodeScope)(context.node);
|
|
3512
|
+
const disposable = nodeScope.available.onListOrAnyVarChange(() => {
|
|
3513
|
+
if (!(0, import_lodash7.isEmpty)(form.state.errors)) {
|
|
3514
|
+
form.validate();
|
|
3515
|
+
}
|
|
3516
|
+
});
|
|
3517
|
+
return () => disposable.dispose();
|
|
3518
|
+
}
|
|
3519
|
+
}
|
|
3520
|
+
];
|
|
3521
|
+
|
|
3522
|
+
// src/shared/format-legacy-refs/index.ts
|
|
3523
|
+
var import_lodash8 = require("lodash");
|
|
3369
3524
|
function formatLegacyRefOnSubmit(value) {
|
|
3370
|
-
if ((0,
|
|
3525
|
+
if ((0, import_lodash8.isObject)(value)) {
|
|
3371
3526
|
if (isLegacyFlowRefValueSchema(value)) {
|
|
3372
3527
|
return formatLegacyRefToNewRef(value);
|
|
3373
3528
|
}
|
|
@@ -3384,7 +3539,7 @@ function formatLegacyRefOnSubmit(value) {
|
|
|
3384
3539
|
return value;
|
|
3385
3540
|
}
|
|
3386
3541
|
function formatLegacyRefOnInit(value) {
|
|
3387
|
-
if ((0,
|
|
3542
|
+
if ((0, import_lodash8.isObject)(value)) {
|
|
3388
3543
|
if (isNewFlowRefValueSchema(value)) {
|
|
3389
3544
|
return formatNewRefToLegacyRef(value);
|
|
3390
3545
|
}
|
|
@@ -3401,10 +3556,10 @@ function formatLegacyRefOnInit(value) {
|
|
|
3401
3556
|
return value;
|
|
3402
3557
|
}
|
|
3403
3558
|
function isLegacyFlowRefValueSchema(value) {
|
|
3404
|
-
return (0,
|
|
3559
|
+
return (0, import_lodash8.isObject)(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
|
|
3405
3560
|
}
|
|
3406
3561
|
function isNewFlowRefValueSchema(value) {
|
|
3407
|
-
return (0,
|
|
3562
|
+
return (0, import_lodash8.isObject)(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
|
|
3408
3563
|
}
|
|
3409
3564
|
function formatLegacyRefToNewRef(value) {
|
|
3410
3565
|
const keyPath = value.content.split(".");
|
|
@@ -3427,21 +3582,21 @@ function formatNewRefToLegacyRef(value) {
|
|
|
3427
3582
|
}
|
|
3428
3583
|
|
|
3429
3584
|
// src/form-plugins/batch-outputs-plugin/index.ts
|
|
3430
|
-
var
|
|
3431
|
-
var provideBatchOutputsEffect = (0,
|
|
3585
|
+
var import_editor21 = require("@flowgram.ai/editor");
|
|
3586
|
+
var provideBatchOutputsEffect = (0, import_editor21.createEffectFromVariableProvider)({
|
|
3432
3587
|
parse: (value, ctx) => [
|
|
3433
|
-
|
|
3588
|
+
import_editor21.ASTFactory.createVariableDeclaration({
|
|
3434
3589
|
key: `${ctx.node.id}`,
|
|
3435
3590
|
meta: {
|
|
3436
|
-
title: (0,
|
|
3591
|
+
title: (0, import_editor21.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
3437
3592
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
3438
3593
|
},
|
|
3439
|
-
type:
|
|
3594
|
+
type: import_editor21.ASTFactory.createObject({
|
|
3440
3595
|
properties: Object.entries(value).map(
|
|
3441
|
-
([_key, value2]) =>
|
|
3596
|
+
([_key, value2]) => import_editor21.ASTFactory.createProperty({
|
|
3442
3597
|
key: _key,
|
|
3443
|
-
initializer:
|
|
3444
|
-
wrapFor:
|
|
3598
|
+
initializer: import_editor21.ASTFactory.createWrapArrayExpression({
|
|
3599
|
+
wrapFor: import_editor21.ASTFactory.createKeyPathExpression({
|
|
3445
3600
|
keyPath: value2?.content || []
|
|
3446
3601
|
})
|
|
3447
3602
|
})
|
|
@@ -3451,7 +3606,7 @@ var provideBatchOutputsEffect = (0, import_editor19.createEffectFromVariableProv
|
|
|
3451
3606
|
})
|
|
3452
3607
|
]
|
|
3453
3608
|
});
|
|
3454
|
-
var createBatchOutputsFormPlugin = (0,
|
|
3609
|
+
var createBatchOutputsFormPlugin = (0, import_editor21.defineFormPluginCreator)({
|
|
3455
3610
|
name: "batch-outputs-plugin",
|
|
3456
3611
|
onSetupFormMeta({ mergeEffect }, { outputKey }) {
|
|
3457
3612
|
mergeEffect({
|
|
@@ -3459,7 +3614,7 @@ var createBatchOutputsFormPlugin = (0, import_editor19.defineFormPluginCreator)(
|
|
|
3459
3614
|
});
|
|
3460
3615
|
},
|
|
3461
3616
|
onInit(ctx, { outputKey }) {
|
|
3462
|
-
const chainTransformService = ctx.node.getService(
|
|
3617
|
+
const chainTransformService = ctx.node.getService(import_editor21.ScopeChainTransformService);
|
|
3463
3618
|
const batchNodeType = ctx.node.flowNodeType;
|
|
3464
3619
|
const transformerId = `${batchNodeType}-outputs`;
|
|
3465
3620
|
if (chainTransformService.hasTransformer(transformerId)) {
|
|
@@ -3469,21 +3624,21 @@ var createBatchOutputsFormPlugin = (0, import_editor19.defineFormPluginCreator)(
|
|
|
3469
3624
|
transformCovers: (covers, ctx2) => {
|
|
3470
3625
|
const node = ctx2.scope.meta?.node;
|
|
3471
3626
|
if (node?.parent?.flowNodeType === batchNodeType) {
|
|
3472
|
-
return [...covers, (0,
|
|
3627
|
+
return [...covers, (0, import_editor21.getNodeScope)(node.parent)];
|
|
3473
3628
|
}
|
|
3474
3629
|
return covers;
|
|
3475
3630
|
},
|
|
3476
3631
|
transformDeps(scopes, ctx2) {
|
|
3477
3632
|
const scopeMeta = ctx2.scope.meta;
|
|
3478
|
-
if (scopeMeta?.type ===
|
|
3633
|
+
if (scopeMeta?.type === import_editor21.FlowNodeScopeType.private) {
|
|
3479
3634
|
return scopes;
|
|
3480
3635
|
}
|
|
3481
3636
|
const node = scopeMeta?.node;
|
|
3482
3637
|
if (node?.flowNodeType === batchNodeType) {
|
|
3483
3638
|
const childBlocks = node.blocks;
|
|
3484
3639
|
return [
|
|
3485
|
-
(0,
|
|
3486
|
-
...childBlocks.map((_childBlock) => (0,
|
|
3640
|
+
(0, import_editor21.getNodePrivateScope)(node),
|
|
3641
|
+
...childBlocks.map((_childBlock) => (0, import_editor21.getNodeScope)(_childBlock))
|
|
3487
3642
|
];
|
|
3488
3643
|
}
|
|
3489
3644
|
return scopes;
|
|
@@ -3493,21 +3648,21 @@ var createBatchOutputsFormPlugin = (0, import_editor19.defineFormPluginCreator)(
|
|
|
3493
3648
|
});
|
|
3494
3649
|
|
|
3495
3650
|
// src/form-plugins/infer-inputs-plugin/index.ts
|
|
3496
|
-
var
|
|
3651
|
+
var import_lodash9 = require("lodash");
|
|
3497
3652
|
var import_json_schema10 = require("@flowgram.ai/json-schema");
|
|
3498
|
-
var
|
|
3499
|
-
var createInferInputsPlugin = (0,
|
|
3653
|
+
var import_editor22 = require("@flowgram.ai/editor");
|
|
3654
|
+
var createInferInputsPlugin = (0, import_editor22.defineFormPluginCreator)({
|
|
3500
3655
|
onSetupFormMeta({ addFormatOnSubmit }, { sourceKey, targetKey, scope }) {
|
|
3501
3656
|
if (!sourceKey || !targetKey) {
|
|
3502
3657
|
return;
|
|
3503
3658
|
}
|
|
3504
3659
|
addFormatOnSubmit((formData, ctx) => {
|
|
3505
|
-
(0,
|
|
3660
|
+
(0, import_lodash9.set)(
|
|
3506
3661
|
formData,
|
|
3507
3662
|
targetKey,
|
|
3508
3663
|
infer(
|
|
3509
|
-
(0,
|
|
3510
|
-
scope === "private" ? (0,
|
|
3664
|
+
(0, import_lodash9.get)(formData, sourceKey),
|
|
3665
|
+
scope === "private" ? (0, import_editor22.getNodePrivateScope)(ctx.node) : (0, import_editor22.getNodeScope)(ctx.node)
|
|
3511
3666
|
)
|
|
3512
3667
|
);
|
|
3513
3668
|
return formData;
|
|
@@ -3567,8 +3722,105 @@ var infer = (values, scope) => {
|
|
|
3567
3722
|
};
|
|
3568
3723
|
}
|
|
3569
3724
|
};
|
|
3725
|
+
|
|
3726
|
+
// src/form-plugins/infer-assign-plugin/index.ts
|
|
3727
|
+
var import_lodash10 = require("lodash");
|
|
3728
|
+
var import_json_schema11 = require("@flowgram.ai/json-schema");
|
|
3729
|
+
var import_editor23 = require("@flowgram.ai/editor");
|
|
3730
|
+
var createInferAssignPlugin = (0, import_editor23.defineFormPluginCreator)({
|
|
3731
|
+
onSetupFormMeta({ addFormatOnSubmit, mergeEffect }, { assignKey, outputKey }) {
|
|
3732
|
+
if (!assignKey || !outputKey) {
|
|
3733
|
+
return;
|
|
3734
|
+
}
|
|
3735
|
+
mergeEffect({
|
|
3736
|
+
[assignKey]: (0, import_editor23.createEffectFromVariableProvider)({
|
|
3737
|
+
parse: (value, ctx) => {
|
|
3738
|
+
const declareRows = (0, import_lodash10.uniqBy)(
|
|
3739
|
+
value.filter((_v) => _v.operator === "declare" && _v.left && _v.right),
|
|
3740
|
+
"left"
|
|
3741
|
+
);
|
|
3742
|
+
return [
|
|
3743
|
+
import_editor23.ASTFactory.createVariableDeclaration({
|
|
3744
|
+
key: `${ctx.node.id}`,
|
|
3745
|
+
meta: {
|
|
3746
|
+
title: (0, import_editor23.getNodeForm)(ctx.node)?.getValueIn("title"),
|
|
3747
|
+
icon: ctx.node.getNodeRegistry().info?.icon
|
|
3748
|
+
},
|
|
3749
|
+
type: import_editor23.ASTFactory.createObject({
|
|
3750
|
+
properties: declareRows.map(
|
|
3751
|
+
(_v) => import_editor23.ASTFactory.createProperty({
|
|
3752
|
+
key: _v.left,
|
|
3753
|
+
type: _v.right?.type === "constant" ? import_json_schema11.JsonSchemaUtils.schemaToAST(_v.right?.schema || {}) : void 0,
|
|
3754
|
+
initializer: _v.right?.type === "ref" ? import_editor23.ASTFactory.createKeyPathExpression({
|
|
3755
|
+
keyPath: _v.right?.content || []
|
|
3756
|
+
}) : {}
|
|
3757
|
+
})
|
|
3758
|
+
)
|
|
3759
|
+
})
|
|
3760
|
+
})
|
|
3761
|
+
];
|
|
3762
|
+
}
|
|
3763
|
+
})
|
|
3764
|
+
});
|
|
3765
|
+
addFormatOnSubmit((formData, ctx) => {
|
|
3766
|
+
(0, import_lodash10.set)(
|
|
3767
|
+
formData,
|
|
3768
|
+
outputKey,
|
|
3769
|
+
import_json_schema11.JsonSchemaUtils.astToSchema((0, import_editor23.getNodeScope)(ctx.node).output.variables?.[0]?.type)
|
|
3770
|
+
);
|
|
3771
|
+
return formData;
|
|
3772
|
+
});
|
|
3773
|
+
}
|
|
3774
|
+
});
|
|
3775
|
+
|
|
3776
|
+
// src/validate/validate-flow-value/index.tsx
|
|
3777
|
+
var import_lodash11 = require("lodash");
|
|
3778
|
+
var import_editor24 = require("@flowgram.ai/editor");
|
|
3779
|
+
function validateFlowValue(value, ctx) {
|
|
3780
|
+
const { node, required, errorMessages } = ctx;
|
|
3781
|
+
const {
|
|
3782
|
+
required: requiredMessage = "Field is required",
|
|
3783
|
+
unknownVariable: unknownVariableMessage = "Unknown Variable"
|
|
3784
|
+
} = errorMessages || {};
|
|
3785
|
+
if (required && ((0, import_lodash11.isNil)(value) || (0, import_lodash11.isNil)(value?.content) || value?.content === "")) {
|
|
3786
|
+
return {
|
|
3787
|
+
level: import_editor24.FeedbackLevel.Error,
|
|
3788
|
+
message: requiredMessage
|
|
3789
|
+
};
|
|
3790
|
+
}
|
|
3791
|
+
if (value?.type === "ref") {
|
|
3792
|
+
const variable = (0, import_editor24.getNodeScope)(node).available.getByKeyPath(value?.content || []);
|
|
3793
|
+
if (!variable) {
|
|
3794
|
+
return {
|
|
3795
|
+
level: import_editor24.FeedbackLevel.Error,
|
|
3796
|
+
message: unknownVariableMessage
|
|
3797
|
+
};
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
if (value?.type === "template") {
|
|
3801
|
+
const allRefs = getTemplateKeyPaths2(value);
|
|
3802
|
+
for (const ref of allRefs) {
|
|
3803
|
+
const variable = (0, import_editor24.getNodeScope)(node).available.getByKeyPath(ref);
|
|
3804
|
+
if (!variable) {
|
|
3805
|
+
return {
|
|
3806
|
+
level: import_editor24.FeedbackLevel.Error,
|
|
3807
|
+
message: unknownVariableMessage
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
}
|
|
3812
|
+
return void 0;
|
|
3813
|
+
}
|
|
3814
|
+
function getTemplateKeyPaths2(value) {
|
|
3815
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
3816
|
+
return (0, import_lodash11.uniq)(value.content?.match(keyPathReg) || []).map(
|
|
3817
|
+
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
3818
|
+
);
|
|
3819
|
+
}
|
|
3570
3820
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3571
3821
|
0 && (module.exports = {
|
|
3822
|
+
AssignRow,
|
|
3823
|
+
AssignRows,
|
|
3572
3824
|
BatchOutputs,
|
|
3573
3825
|
BatchVariableSelector,
|
|
3574
3826
|
CodeEditor,
|
|
@@ -3594,6 +3846,7 @@ var infer = (values, scope) => {
|
|
|
3594
3846
|
autoRenameRefEffect,
|
|
3595
3847
|
createBatchOutputsFormPlugin,
|
|
3596
3848
|
createDisableDeclarationPlugin,
|
|
3849
|
+
createInferAssignPlugin,
|
|
3597
3850
|
createInferInputsPlugin,
|
|
3598
3851
|
createTypePresetPlugin,
|
|
3599
3852
|
formatLegacyRefOnInit,
|
|
@@ -3609,6 +3862,8 @@ var infer = (values, scope) => {
|
|
|
3609
3862
|
provideJsonSchemaOutputs,
|
|
3610
3863
|
syncVariableTitle,
|
|
3611
3864
|
useTypeManager,
|
|
3612
|
-
useVariableTree
|
|
3865
|
+
useVariableTree,
|
|
3866
|
+
validateFlowValue,
|
|
3867
|
+
validateWhenVariableSync
|
|
3613
3868
|
});
|
|
3614
3869
|
//# sourceMappingURL=index.js.map
|