@flowgram.ai/form-materials 0.2.0 → 0.2.1
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/dist/esm/index.js +133 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +80 -34
- package/dist/index.d.ts +80 -34
- package/dist/index.js +146 -32
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/batch-variable-selector/index.tsx +3 -2
- package/src/components/constant-input/config.json +1 -1
- package/src/components/constant-input/types.ts +3 -3
- package/src/components/dynamic-value-input/index.tsx +2 -2
- package/src/components/json-schema-editor/config.json +1 -1
- package/src/components/json-schema-editor/hooks.tsx +2 -2
- package/src/components/json-schema-editor/index.tsx +3 -3
- package/src/components/json-schema-editor/types.ts +3 -3
- package/src/components/type-selector/config.json +1 -1
- package/src/components/type-selector/constants.tsx +2 -2
- package/src/components/type-selector/index.tsx +6 -6
- package/src/components/variable-selector/config.json +1 -1
- package/src/components/variable-selector/index.tsx +3 -3
- package/src/components/variable-selector/use-variable-tree.tsx +11 -5
- package/src/typings/index.ts +1 -0
- package/src/typings/json-schema/config.json +5 -0
- package/src/typings/json-schema/index.ts +31 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/json-schema/config.json +5 -0
- package/src/utils/json-schema/index.ts +154 -0
- package/src/components/type-selector/types.ts +0 -5
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
|
|
|
4
4
|
|
|
5
5
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
6
6
|
import React2, { useCallback } from "react";
|
|
7
|
-
import { useScopeAvailable, ASTMatch } from "@flowgram.ai/editor";
|
|
7
|
+
import { useScopeAvailable, ASTMatch as ASTMatch2 } from "@flowgram.ai/editor";
|
|
8
8
|
import { Icon as Icon2 } from "@douyinfe/semi-ui";
|
|
9
9
|
|
|
10
10
|
// src/components/type-selector/constants.tsx
|
|
@@ -396,6 +396,118 @@ var options = [
|
|
|
396
396
|
}
|
|
397
397
|
];
|
|
398
398
|
|
|
399
|
+
// src/utils/json-schema/index.ts
|
|
400
|
+
import { get } from "lodash";
|
|
401
|
+
import { ASTFactory, ASTKind, ASTMatch } from "@flowgram.ai/editor";
|
|
402
|
+
var JsonSchemaUtils;
|
|
403
|
+
((JsonSchemaUtils2) => {
|
|
404
|
+
function schemaToAST(jsonSchema) {
|
|
405
|
+
const { type, extra } = jsonSchema || {};
|
|
406
|
+
const { weak = false } = extra || {};
|
|
407
|
+
if (!type) {
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
410
|
+
switch (type) {
|
|
411
|
+
case "object":
|
|
412
|
+
if (weak) {
|
|
413
|
+
return { kind: ASTKind.Object, weak: true };
|
|
414
|
+
}
|
|
415
|
+
return ASTFactory.createObject({
|
|
416
|
+
properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => (get(a?.[1], "extra.index") || 0) - (get(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
|
|
417
|
+
key,
|
|
418
|
+
type: schemaToAST(_property),
|
|
419
|
+
meta: { description: _property.description }
|
|
420
|
+
}))
|
|
421
|
+
});
|
|
422
|
+
case "array":
|
|
423
|
+
if (weak) {
|
|
424
|
+
return { kind: ASTKind.Array, weak: true };
|
|
425
|
+
}
|
|
426
|
+
return ASTFactory.createArray({
|
|
427
|
+
items: schemaToAST(jsonSchema.items)
|
|
428
|
+
});
|
|
429
|
+
case "map":
|
|
430
|
+
if (weak) {
|
|
431
|
+
return { kind: ASTKind.Map, weak: true };
|
|
432
|
+
}
|
|
433
|
+
return ASTFactory.createMap({
|
|
434
|
+
valueType: schemaToAST(jsonSchema.additionalProperties)
|
|
435
|
+
});
|
|
436
|
+
case "string":
|
|
437
|
+
return ASTFactory.createString();
|
|
438
|
+
case "number":
|
|
439
|
+
return ASTFactory.createNumber();
|
|
440
|
+
case "boolean":
|
|
441
|
+
return ASTFactory.createBoolean();
|
|
442
|
+
case "integer":
|
|
443
|
+
return ASTFactory.createInteger();
|
|
444
|
+
default:
|
|
445
|
+
return ASTFactory.createCustomType({ typeName: type });
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
JsonSchemaUtils2.schemaToAST = schemaToAST;
|
|
449
|
+
function astToSchema(typeAST) {
|
|
450
|
+
if (ASTMatch.isString(typeAST)) {
|
|
451
|
+
return {
|
|
452
|
+
type: "string"
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
if (ASTMatch.isBoolean(typeAST)) {
|
|
456
|
+
return {
|
|
457
|
+
type: "boolean"
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
if (ASTMatch.isNumber(typeAST)) {
|
|
461
|
+
return {
|
|
462
|
+
type: "number"
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
if (ASTMatch.isInteger(typeAST)) {
|
|
466
|
+
return {
|
|
467
|
+
type: "integer"
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (ASTMatch.isObject(typeAST)) {
|
|
471
|
+
return {
|
|
472
|
+
type: "object",
|
|
473
|
+
properties: Object.fromEntries(
|
|
474
|
+
Object.entries(typeAST.properties).map(([key, value]) => [key, astToSchema(value)])
|
|
475
|
+
)
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
if (ASTMatch.isArray(typeAST)) {
|
|
479
|
+
return {
|
|
480
|
+
type: "array",
|
|
481
|
+
items: astToSchema(typeAST.items)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
if (ASTMatch.isMap(typeAST)) {
|
|
485
|
+
return {
|
|
486
|
+
type: "map",
|
|
487
|
+
items: astToSchema(typeAST.valueType)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
if (ASTMatch.isCustomType(typeAST)) {
|
|
491
|
+
return {
|
|
492
|
+
type: typeAST.typeName
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
JsonSchemaUtils2.astToSchema = astToSchema;
|
|
498
|
+
function isASTMatchSchema(typeAST, schema) {
|
|
499
|
+
if (Array.isArray(schema)) {
|
|
500
|
+
return typeAST.isTypeEqual(
|
|
501
|
+
ASTFactory.createUnion({
|
|
502
|
+
types: schema.map((_schema) => schemaToAST(_schema)).filter(Boolean)
|
|
503
|
+
})
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
return typeAST.isTypeEqual(schemaToAST(schema));
|
|
507
|
+
}
|
|
508
|
+
JsonSchemaUtils2.isASTMatchSchema = isASTMatchSchema;
|
|
509
|
+
})(JsonSchemaUtils || (JsonSchemaUtils = {}));
|
|
510
|
+
|
|
399
511
|
// src/components/variable-selector/use-variable-tree.tsx
|
|
400
512
|
function useVariableTree(params) {
|
|
401
513
|
const { includeSchema, excludeSchema } = params;
|
|
@@ -408,7 +520,7 @@ function useVariableTree(params) {
|
|
|
408
520
|
return variable.meta.icon;
|
|
409
521
|
}
|
|
410
522
|
const _type = variable.type;
|
|
411
|
-
if (
|
|
523
|
+
if (ASTMatch2.isArray(_type)) {
|
|
412
524
|
return /* @__PURE__ */ React2.createElement(
|
|
413
525
|
Icon2,
|
|
414
526
|
{
|
|
@@ -417,7 +529,7 @@ function useVariableTree(params) {
|
|
|
417
529
|
}
|
|
418
530
|
);
|
|
419
531
|
}
|
|
420
|
-
if (
|
|
532
|
+
if (ASTMatch2.isCustomType(_type)) {
|
|
421
533
|
return /* @__PURE__ */ React2.createElement(Icon2, { size: "small", svg: VariableTypeIcons[_type.typeName.toLowerCase()] });
|
|
422
534
|
}
|
|
423
535
|
return /* @__PURE__ */ React2.createElement(Icon2, { size: "small", svg: VariableTypeIcons[variable.type?.kind.toLowerCase()] });
|
|
@@ -428,7 +540,7 @@ function useVariableTree(params) {
|
|
|
428
540
|
return null;
|
|
429
541
|
}
|
|
430
542
|
let children;
|
|
431
|
-
if (
|
|
543
|
+
if (ASTMatch2.isObject(type)) {
|
|
432
544
|
children = (type.properties || []).map((_property) => renderVariable(_property, [...parentFields, variable])).filter(Boolean);
|
|
433
545
|
if (!children?.length) {
|
|
434
546
|
return null;
|
|
@@ -436,8 +548,8 @@ function useVariableTree(params) {
|
|
|
436
548
|
}
|
|
437
549
|
const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
|
|
438
550
|
const key = keyPath.join(".");
|
|
439
|
-
const isSchemaInclude = includeSchema ?
|
|
440
|
-
const isSchemaExclude = excludeSchema ?
|
|
551
|
+
const isSchemaInclude = includeSchema ? JsonSchemaUtils.isASTMatchSchema(type, includeSchema) : true;
|
|
552
|
+
const isSchemaExclude = excludeSchema ? JsonSchemaUtils.isASTMatchSchema(type, excludeSchema) : false;
|
|
441
553
|
const isSchemaMatch = isSchemaInclude && !isSchemaExclude;
|
|
442
554
|
if (!isSchemaMatch && !children?.length) {
|
|
443
555
|
return null;
|
|
@@ -1132,32 +1244,32 @@ function DynamicValueInput({
|
|
|
1132
1244
|
|
|
1133
1245
|
// src/effects/provide-batch-input/index.ts
|
|
1134
1246
|
import {
|
|
1135
|
-
ASTFactory,
|
|
1247
|
+
ASTFactory as ASTFactory2,
|
|
1136
1248
|
createEffectFromVariableProvider,
|
|
1137
1249
|
getNodeForm
|
|
1138
1250
|
} from "@flowgram.ai/editor";
|
|
1139
1251
|
var provideBatchInputEffect = createEffectFromVariableProvider({
|
|
1140
1252
|
private: true,
|
|
1141
1253
|
parse: (value, ctx) => [
|
|
1142
|
-
|
|
1254
|
+
ASTFactory2.createVariableDeclaration({
|
|
1143
1255
|
key: `${ctx.node.id}_locals`,
|
|
1144
1256
|
meta: {
|
|
1145
1257
|
title: getNodeForm(ctx.node)?.getValueIn("title"),
|
|
1146
1258
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1147
1259
|
},
|
|
1148
|
-
type:
|
|
1260
|
+
type: ASTFactory2.createObject({
|
|
1149
1261
|
properties: [
|
|
1150
|
-
|
|
1262
|
+
ASTFactory2.createProperty({
|
|
1151
1263
|
key: "item",
|
|
1152
|
-
initializer:
|
|
1153
|
-
enumerateFor:
|
|
1264
|
+
initializer: ASTFactory2.createEnumerateExpression({
|
|
1265
|
+
enumerateFor: ASTFactory2.createKeyPathExpression({
|
|
1154
1266
|
keyPath: value.content || []
|
|
1155
1267
|
})
|
|
1156
1268
|
})
|
|
1157
1269
|
}),
|
|
1158
|
-
|
|
1270
|
+
ASTFactory2.createProperty({
|
|
1159
1271
|
key: "index",
|
|
1160
|
-
type:
|
|
1272
|
+
type: ASTFactory2.createNumber()
|
|
1161
1273
|
})
|
|
1162
1274
|
]
|
|
1163
1275
|
})
|
|
@@ -1167,25 +1279,25 @@ var provideBatchInputEffect = createEffectFromVariableProvider({
|
|
|
1167
1279
|
|
|
1168
1280
|
// src/effects/provide-batch-outputs/index.ts
|
|
1169
1281
|
import {
|
|
1170
|
-
ASTFactory as
|
|
1282
|
+
ASTFactory as ASTFactory3,
|
|
1171
1283
|
createEffectFromVariableProvider as createEffectFromVariableProvider2,
|
|
1172
1284
|
getNodeForm as getNodeForm2
|
|
1173
1285
|
} from "@flowgram.ai/editor";
|
|
1174
1286
|
var provideBatchOutputsEffect = createEffectFromVariableProvider2({
|
|
1175
1287
|
private: true,
|
|
1176
1288
|
parse: (value, ctx) => [
|
|
1177
|
-
|
|
1289
|
+
ASTFactory3.createVariableDeclaration({
|
|
1178
1290
|
key: `${ctx.node.id}`,
|
|
1179
1291
|
meta: {
|
|
1180
1292
|
title: getNodeForm2(ctx.node)?.getValueIn("title"),
|
|
1181
1293
|
icon: ctx.node.getNodeRegistry().info?.icon
|
|
1182
1294
|
},
|
|
1183
|
-
type:
|
|
1295
|
+
type: ASTFactory3.createObject({
|
|
1184
1296
|
properties: Object.entries(value).map(
|
|
1185
|
-
([_key, value2]) =>
|
|
1297
|
+
([_key, value2]) => ASTFactory3.createProperty({
|
|
1186
1298
|
key: _key,
|
|
1187
|
-
initializer:
|
|
1188
|
-
wrapFor:
|
|
1299
|
+
initializer: ASTFactory3.createWrapArrayExpression({
|
|
1300
|
+
wrapFor: ASTFactory3.createKeyPathExpression({
|
|
1189
1301
|
keyPath: value2.content || []
|
|
1190
1302
|
})
|
|
1191
1303
|
})
|
|
@@ -1263,6 +1375,7 @@ export {
|
|
|
1263
1375
|
ConstantInput,
|
|
1264
1376
|
DynamicValueInput,
|
|
1265
1377
|
JsonSchemaEditor,
|
|
1378
|
+
JsonSchemaUtils,
|
|
1266
1379
|
TypeSelector,
|
|
1267
1380
|
VariableSelector,
|
|
1268
1381
|
VariableTypeIcons,
|