@tduniec/plugin-template-designer 0.1.7

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 (69) hide show
  1. package/README.md +120 -0
  2. package/dist/api/scaffolderActions.esm.js +42 -0
  3. package/dist/api/scaffolderActions.esm.js.map +1 -0
  4. package/dist/components/DesignerFlow/DesignerFlow.esm.js +370 -0
  5. package/dist/components/DesignerFlow/DesignerFlow.esm.js.map +1 -0
  6. package/dist/components/DesignerFlow/flowConfig.esm.js +21 -0
  7. package/dist/components/DesignerFlow/flowConfig.esm.js.map +1 -0
  8. package/dist/components/DesignerFlow/handlers.esm.js +288 -0
  9. package/dist/components/DesignerFlow/handlers.esm.js.map +1 -0
  10. package/dist/components/DesignerFlow/model.esm.js +181 -0
  11. package/dist/components/DesignerFlow/model.esm.js.map +1 -0
  12. package/dist/components/DesignerFlow/nodeLayout.esm.js +138 -0
  13. package/dist/components/DesignerFlow/nodeLayout.esm.js.map +1 -0
  14. package/dist/components/DesignerFlow/parameterTransforms.esm.js +184 -0
  15. package/dist/components/DesignerFlow/parameterTransforms.esm.js.map +1 -0
  16. package/dist/components/Nodes/ActionNode.esm.js +437 -0
  17. package/dist/components/Nodes/ActionNode.esm.js.map +1 -0
  18. package/dist/components/Nodes/OutputNode.esm.js +368 -0
  19. package/dist/components/Nodes/OutputNode.esm.js.map +1 -0
  20. package/dist/components/Nodes/ParameterInputNode.esm.js +310 -0
  21. package/dist/components/Nodes/ParameterInputNode.esm.js.map +1 -0
  22. package/dist/components/Nodes/ParameterTitlesNode.esm.js +251 -0
  23. package/dist/components/Nodes/ParameterTitlesNode.esm.js.map +1 -0
  24. package/dist/components/Nodes/ParametersNode.esm.js +142 -0
  25. package/dist/components/Nodes/ParametersNode.esm.js.map +1 -0
  26. package/dist/components/Nodes/action/schema.esm.js +117 -0
  27. package/dist/components/Nodes/action/schema.esm.js.map +1 -0
  28. package/dist/components/Nodes/action/useActionInputs.esm.js +66 -0
  29. package/dist/components/Nodes/action/useActionInputs.esm.js.map +1 -0
  30. package/dist/components/Nodes/common/AutoWidthPopper.esm.js +22 -0
  31. package/dist/components/Nodes/common/AutoWidthPopper.esm.js.map +1 -0
  32. package/dist/components/Nodes/common/nodeInteraction.esm.js +9 -0
  33. package/dist/components/Nodes/common/nodeInteraction.esm.js.map +1 -0
  34. package/dist/components/Nodes/output/useOutputController.esm.js +191 -0
  35. package/dist/components/Nodes/output/useOutputController.esm.js.map +1 -0
  36. package/dist/components/Nodes/parameters/useParameterSections.esm.js +162 -0
  37. package/dist/components/Nodes/parameters/useParameterSections.esm.js.map +1 -0
  38. package/dist/components/Nodes/types.esm.js +8 -0
  39. package/dist/components/Nodes/types.esm.js.map +1 -0
  40. package/dist/components/TemplateDesigner/TemplateDesigner.esm.js +115 -0
  41. package/dist/components/TemplateDesigner/TemplateDesigner.esm.js.map +1 -0
  42. package/dist/components/TemplateDesigner/components/FieldEditorDialog.esm.js +32 -0
  43. package/dist/components/TemplateDesigner/components/FieldEditorDialog.esm.js.map +1 -0
  44. package/dist/components/TemplateDesigner/components/TemplateLanding.esm.js +102 -0
  45. package/dist/components/TemplateDesigner/components/TemplateLanding.esm.js.map +1 -0
  46. package/dist/components/TemplateDesigner/components/TemplateWorkspace.esm.js +200 -0
  47. package/dist/components/TemplateDesigner/components/TemplateWorkspace.esm.js.map +1 -0
  48. package/dist/components/TemplateDesigner/index.esm.js +2 -0
  49. package/dist/components/TemplateDesigner/index.esm.js.map +1 -0
  50. package/dist/components/TemplateDesigner/useFieldEditor.esm.js +96 -0
  51. package/dist/components/TemplateDesigner/useFieldEditor.esm.js.map +1 -0
  52. package/dist/components/TemplateDesigner/useTemplateState.esm.js +391 -0
  53. package/dist/components/TemplateDesigner/useTemplateState.esm.js.map +1 -0
  54. package/dist/components/TemplateDesigner/utils.esm.js +46 -0
  55. package/dist/components/TemplateDesigner/utils.esm.js.map +1 -0
  56. package/dist/index.d.ts +9 -0
  57. package/dist/index.esm.js +2 -0
  58. package/dist/index.esm.js.map +1 -0
  59. package/dist/plugin.esm.js +19 -0
  60. package/dist/plugin.esm.js.map +1 -0
  61. package/dist/routes.esm.js +8 -0
  62. package/dist/routes.esm.js.map +1 -0
  63. package/dist/utils/createSequentialEdges.esm.js +15 -0
  64. package/dist/utils/createSequentialEdges.esm.js.map +1 -0
  65. package/dist/utils/sampleTemplate.esm.js +40 -0
  66. package/dist/utils/sampleTemplate.esm.js.map +1 -0
  67. package/dist/utils/yamlJsonConversion.esm.js +47 -0
  68. package/dist/utils/yamlJsonConversion.esm.js.map +1 -0
  69. package/package.json +116 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeLayout.esm.js","sources":["../../../src/components/DesignerFlow/nodeLayout.ts"],"sourcesContent":["import type { Node } from \"@xyflow/react\";\nimport type {\n ActionNodeData,\n DesignerNodeType,\n OutputNodeData,\n ParametersNodeData,\n} from \"../Nodes/types\";\nimport { NODE_VERTICAL_SPACING } from \"../Nodes/types\";\n\n// Shared helpers for computing consistent node alignment/spacing in the flow.\n\nconst DEFAULT_NODE_HEIGHT = 320;\nconst MIN_VERTICAL_GAP = 48;\n\nconst parseNumericHeight = (value: unknown): number | null => {\n if (typeof value === \"number\" && Number.isFinite(value) && value > 0) {\n return value;\n }\n if (typeof value === \"string\") {\n const parsed = Number.parseFloat(value);\n if (!Number.isNaN(parsed) && parsed > 0) {\n return parsed;\n }\n }\n return null;\n};\n\nconst estimateParametersNodeHeight = (node: Node): number | null => {\n if (node.type !== \"parametersNode\") {\n return null;\n }\n const data = node.data as ParametersNodeData | undefined;\n if (!data) {\n return null;\n }\n\n const sections = data.sections ?? [];\n const PARAMETER_SHELL_HEIGHT = 300;\n const PARAMETER_CARD_BASE = 220;\n const SECTION_BASE = 180;\n const FIELD_HEIGHT = 86;\n\n if (!sections.length) {\n return PARAMETER_SHELL_HEIGHT + PARAMETER_CARD_BASE + SECTION_BASE;\n }\n\n const sectionsHeight = sections.reduce((total, section) => {\n const fieldCount = section.fields?.length ?? 0;\n return total + SECTION_BASE + Math.max(fieldCount, 1) * FIELD_HEIGHT;\n }, 0);\n\n return PARAMETER_SHELL_HEIGHT + PARAMETER_CARD_BASE + sectionsHeight;\n};\n\nconst estimateActionNodeHeight = (node: Node): number | null => {\n if (node.type !== \"actionNode\") {\n return null;\n }\n const data = node.data as ActionNodeData | undefined;\n if (!data) {\n return null;\n }\n const base =\n NODE_VERTICAL_SPACING.actionNode && NODE_VERTICAL_SPACING.actionNode > 0\n ? NODE_VERTICAL_SPACING.actionNode\n : MIN_VERTICAL_GAP;\n const rowHeight = 84;\n const inputCount = Object.keys(data.step?.input ?? {}).length;\n const displayedRows = Math.max(inputCount, 1);\n const extraRows = Math.max(displayedRows - 1, 0);\n return base + extraRows * rowHeight;\n};\n\nconst BUILTIN_OUTPUT_KEYS = new Set([\"links\", \"text\"]);\n\nconst estimateOutputNodeHeight = (node: Node): number | null => {\n if (node.type !== \"outputNode\") {\n return null;\n }\n const data = node.data as OutputNodeData | undefined;\n if (!data) {\n return null;\n }\n const base = 240;\n const linkHeight = 68;\n const textHeight = 68;\n const customHeight = 56;\n\n const links = Array.isArray(data.output?.links) ? data.output.links : [];\n const textEntries = Array.isArray(data.output?.text) ? data.output.text : [];\n const customEntries =\n data.output && typeof data.output === \"object\"\n ? Object.entries(data.output).filter(\n ([key]) => !BUILTIN_OUTPUT_KEYS.has(key)\n )\n : [];\n\n return (\n base +\n links.length * linkHeight +\n textEntries.length * textHeight +\n customEntries.length * customHeight\n );\n};\n\nconst getEstimatedHeightForNode = (node: Node): number | null => {\n const type = node.type as DesignerNodeType | undefined;\n if (!type) {\n return null;\n }\n\n const estimators: Partial<\n Record<DesignerNodeType, (node: Node) => number | null>\n > = {\n parametersNode: estimateParametersNodeHeight,\n actionNode: estimateActionNodeHeight,\n outputNode: estimateOutputNodeHeight,\n };\n\n const estimated = estimators[type]?.(node);\n if (typeof estimated === \"number\" && estimated > 0) {\n return estimated;\n }\n\n const fallback = NODE_VERTICAL_SPACING[type];\n return typeof fallback === \"number\" && fallback > 0 ? fallback : null;\n};\n\nconst getNodeHeight = (node: Node): number => {\n const measured = parseNumericHeight(node.measured?.height);\n if (measured) {\n return measured;\n }\n const explicitHeight = parseNumericHeight(node.height);\n if (explicitHeight) {\n return explicitHeight;\n }\n const styleHeight = parseNumericHeight(node.style?.height);\n if (styleHeight) {\n return styleHeight;\n }\n const estimatedHeight = getEstimatedHeightForNode(node);\n if (estimatedHeight) {\n return estimatedHeight;\n }\n return DEFAULT_NODE_HEIGHT;\n};\n\nconst getSpacingBufferForNode = (node: Node): number => {\n const type = node.type as DesignerNodeType | undefined;\n if (!type) {\n return MIN_VERTICAL_GAP;\n }\n const buffer = NODE_VERTICAL_SPACING[type] ?? MIN_VERTICAL_GAP;\n return buffer > MIN_VERTICAL_GAP ? buffer : MIN_VERTICAL_GAP;\n};\n\nexport const alignNodes = (\n nodes: Node[],\n fixedXPosition: number,\n verticalSpacing: number\n) => {\n let currentY = 0;\n\n return nodes.map((node) => {\n const alignedNode: Node = {\n ...node,\n position: {\n x: fixedXPosition,\n y: currentY,\n },\n };\n\n const nodeHeight = getNodeHeight(node);\n const spacingBuffer = getSpacingBufferForNode(node);\n const minDistance = nodeHeight + spacingBuffer;\n const distanceToNext = Math.max(minDistance, verticalSpacing);\n currentY += distanceToNext;\n\n return alignedNode;\n });\n};\n"],"names":[],"mappings":";;AAWA,MAAM,mBAAA,GAAsB,GAAA;AAC5B,MAAM,gBAAA,GAAmB,EAAA;AAEzB,MAAM,kBAAA,GAAqB,CAAC,KAAA,KAAkC;AAC5D,EAAA,IAAI,OAAO,UAAU,QAAA,IAAY,MAAA,CAAO,SAAS,KAAK,CAAA,IAAK,QAAQ,CAAA,EAAG;AACpE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,MAAA,GAAS,MAAA,CAAO,UAAA,CAAW,KAAK,CAAA;AACtC,IAAA,I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A,EACT,CAAC,CAAA;AACH;;;;"}
@@ -0,0 +1,184 @@
1
+ const asString = (value) => typeof value === "string" ? value : void 0;
2
+ const asStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string") ? value : void 0;
3
+ const asSchemaRecord = (value) => {
4
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
5
+ return void 0;
6
+ }
7
+ return value;
8
+ };
9
+ const cloneSchema = (schema) => {
10
+ if (!schema) {
11
+ return void 0;
12
+ }
13
+ return JSON.parse(JSON.stringify(schema));
14
+ };
15
+ const buildDefaultSchema = (fieldName) => ({
16
+ title: fieldName || "Field",
17
+ type: "string"
18
+ });
19
+ const buildFieldsForSection = (sectionId, sectionTitle, properties, requiredList) => {
20
+ if (!properties) {
21
+ return [];
22
+ }
23
+ return Object.entries(properties).map(([fieldName, schema], fieldIndex) => {
24
+ const isRequired = Array.isArray(requiredList) && requiredList.includes(fieldName);
25
+ const safeSchema = cloneSchema(schema) ?? buildDefaultSchema(fieldName);
26
+ return {
27
+ id: `${sectionId}-field-${fieldIndex}`,
28
+ fieldName,
29
+ sectionId,
30
+ sectionTitle,
31
+ required: Boolean(isRequired),
32
+ schema: safeSchema
33
+ };
34
+ });
35
+ };
36
+ const sanitizeField = (field, fallbackSectionId, index) => {
37
+ const fieldId = field.id ?? `${fallbackSectionId}-field-${index}`;
38
+ return {
39
+ ...field,
40
+ id: fieldId,
41
+ sectionId: field.sectionId ?? fallbackSectionId,
42
+ schema: cloneSchema(field.schema) ?? buildDefaultSchema(field.fieldName)
43
+ };
44
+ };
45
+ const rebuildSectionMeta = (section, index) => {
46
+ const fallbackId = section.id ?? `section-${index}`;
47
+ const sanitizedFields = (section.fields ?? []).map(
48
+ (field, fieldIndex) => sanitizeField(field, fallbackId, fieldIndex)
49
+ );
50
+ const properties = sanitizedFields.reduce((acc, field) => {
51
+ if (!field.fieldName) {
52
+ return acc;
53
+ }
54
+ acc[field.fieldName] = cloneSchema(field.schema) ?? buildDefaultSchema(field.fieldName);
55
+ return acc;
56
+ }, {});
57
+ const required = sanitizedFields.filter((field) => field.required && field.fieldName).map((field) => field.fieldName);
58
+ const propagatedFields = sanitizedFields.map((field) => ({
59
+ ...field,
60
+ sectionTitle: section.title ?? field.sectionTitle
61
+ }));
62
+ return {
63
+ ...section,
64
+ id: fallbackId,
65
+ fields: propagatedFields,
66
+ properties,
67
+ required
68
+ };
69
+ };
70
+ const sanitizeSections = (sections) => (sections ?? []).map((section, index) => rebuildSectionMeta(section, index));
71
+ const sectionsToParametersValue = (sections) => {
72
+ const sanitizedSections = sanitizeSections(sections);
73
+ if (!sanitizedSections.length) {
74
+ return void 0;
75
+ }
76
+ const templates = sanitizedSections.map((section) => {
77
+ const properties = section.properties ?? {};
78
+ if (!Object.keys(properties).length) {
79
+ return null;
80
+ }
81
+ const template = {
82
+ title: section.title,
83
+ description: section.description,
84
+ required: section.required && section.required.length ? [...section.required] : void 0,
85
+ properties: JSON.parse(JSON.stringify(properties))
86
+ };
87
+ return template;
88
+ }).filter((entry) => entry !== null);
89
+ if (!templates.length) {
90
+ return void 0;
91
+ }
92
+ return templates.length === 1 ? [templates[0]] : templates;
93
+ };
94
+ const normalizeParametersToSections = (parameters) => {
95
+ if (parameters === void 0 || parameters === null) {
96
+ return [];
97
+ }
98
+ const entries = Array.isArray(parameters) ? parameters : [parameters];
99
+ const sections = [];
100
+ entries.forEach((entry, index) => {
101
+ if (!entry || typeof entry !== "object") {
102
+ return;
103
+ }
104
+ const record = entry;
105
+ const steps = Array.isArray(record.steps) ? record.steps : [];
106
+ if (steps.length > 0) {
107
+ steps.forEach((step, stepIndex) => {
108
+ if (!step || typeof step !== "object") {
109
+ return;
110
+ }
111
+ const schema2 = step.schema;
112
+ if (!schema2 || typeof schema2 !== "object") {
113
+ return;
114
+ }
115
+ const sectionSchema = schema2;
116
+ const stepRecord = step;
117
+ const sectionTitle = asString(stepRecord.title) ?? asString(sectionSchema.title) ?? `Step ${stepIndex + 1}`;
118
+ const sectionDescription = asString(stepRecord.description) ?? asString(sectionSchema.description);
119
+ const sectionProperties2 = asSchemaRecord(sectionSchema.properties) ?? {};
120
+ const required = asStringArray(sectionSchema.required) ?? [];
121
+ const sectionId2 = `section-${index}-step-${stepIndex}`;
122
+ sections.push({
123
+ id: sectionId2,
124
+ title: sectionTitle,
125
+ description: sectionDescription,
126
+ properties: sectionProperties2,
127
+ required,
128
+ fields: buildFieldsForSection(
129
+ sectionId2,
130
+ sectionTitle,
131
+ sectionProperties2,
132
+ required
133
+ )
134
+ });
135
+ });
136
+ return;
137
+ }
138
+ const schema = record;
139
+ const schemaTitle = asString(schema.title);
140
+ const schemaDescription = asString(schema.description);
141
+ const sectionProperties = asSchemaRecord(schema.properties);
142
+ if (sectionProperties && Object.keys(sectionProperties).length > 0) {
143
+ const required = asStringArray(schema.required) ?? [];
144
+ const sectionId2 = `section-${index}`;
145
+ sections.push({
146
+ id: sectionId2,
147
+ title: schemaTitle ?? `Section ${index + 1}`,
148
+ description: schemaDescription,
149
+ properties: sectionProperties,
150
+ required,
151
+ fields: buildFieldsForSection(
152
+ sectionId2,
153
+ schemaTitle,
154
+ sectionProperties,
155
+ required
156
+ )
157
+ });
158
+ return;
159
+ }
160
+ const parameterSchema = entry;
161
+ const fallbackKey = schemaTitle ?? `field-${index + 1}`;
162
+ const sectionId = `section-${index}`;
163
+ const fallbackProperties = {
164
+ [fallbackKey]: parameterSchema
165
+ };
166
+ sections.push({
167
+ id: sectionId,
168
+ title: schemaTitle ?? `Section ${index + 1}`,
169
+ description: schemaDescription,
170
+ properties: fallbackProperties,
171
+ required: [],
172
+ fields: buildFieldsForSection(
173
+ sectionId,
174
+ schemaTitle,
175
+ fallbackProperties,
176
+ []
177
+ )
178
+ });
179
+ });
180
+ return sections;
181
+ };
182
+
183
+ export { normalizeParametersToSections, sanitizeSections, sectionsToParametersValue };
184
+ //# sourceMappingURL=parameterTransforms.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameterTransforms.esm.js","sources":["../../../src/components/DesignerFlow/parameterTransforms.ts"],"sourcesContent":["import type {\n TemplateParameterSchema,\n TemplateParametersV1beta3,\n} from \"@backstage/plugin-scaffolder-common\";\nimport type {\n ParameterFieldDisplay,\n ParameterSectionDisplay,\n TemplateParametersValue,\n} from \"../Nodes/types\";\n\ntype ParameterPropertySchema = Record<string, unknown>;\n\nconst asString = (value: unknown): string | undefined =>\n typeof value === \"string\" ? value : undefined;\n\nconst asStringArray = (value: unknown): string[] | undefined =>\n Array.isArray(value) && value.every((item) => typeof item === \"string\")\n ? (value as string[])\n : undefined;\n\nconst asSchemaRecord = (\n value: unknown\n): Record<string, ParameterPropertySchema> | undefined => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, ParameterPropertySchema>;\n};\n\nconst cloneSchema = (\n schema?: ParameterPropertySchema\n): ParameterPropertySchema | undefined => {\n if (!schema) {\n return undefined;\n }\n return JSON.parse(JSON.stringify(schema)) as ParameterPropertySchema;\n};\n\nconst buildDefaultSchema = (fieldName: string): ParameterPropertySchema => ({\n title: fieldName || \"Field\",\n type: \"string\",\n});\n\nconst buildFieldsForSection = (\n sectionId: string,\n sectionTitle: string | undefined,\n properties?: Record<string, ParameterPropertySchema>,\n requiredList?: string[]\n): ParameterFieldDisplay[] => {\n if (!properties) {\n return [];\n }\n\n return Object.entries(properties).map(([fieldName, schema], fieldIndex) => {\n const isRequired =\n Array.isArray(requiredList) && requiredList.includes(fieldName);\n const safeSchema = cloneSchema(schema) ?? buildDefaultSchema(fieldName);\n return {\n id: `${sectionId}-field-${fieldIndex}`,\n fieldName,\n sectionId,\n sectionTitle,\n required: Boolean(isRequired),\n schema: safeSchema,\n };\n });\n};\n\nconst sanitizeField = (\n field: ParameterFieldDisplay,\n fallbackSectionId: string,\n index: number\n): ParameterFieldDisplay => {\n const fieldId = field.id ?? `${fallbackSectionId}-field-${index}`;\n return {\n ...field,\n id: fieldId,\n sectionId: field.sectionId ?? fallbackSectionId,\n schema: cloneSchema(field.schema) ?? buildDefaultSchema(field.fieldName),\n };\n};\n\nconst rebuildSectionMeta = (\n section: ParameterSectionDisplay,\n index: number\n): ParameterSectionDisplay => {\n const fallbackId = section.id ?? `section-${index}`;\n const sanitizedFields = (section.fields ?? []).map((field, fieldIndex) =>\n sanitizeField(field, fallbackId, fieldIndex)\n );\n\n const properties = sanitizedFields.reduce<\n Record<string, ParameterPropertySchema>\n >((acc, field) => {\n if (!field.fieldName) {\n return acc;\n }\n acc[field.fieldName] =\n cloneSchema(field.schema) ?? buildDefaultSchema(field.fieldName);\n return acc;\n }, {});\n\n const required = sanitizedFields\n .filter((field) => field.required && field.fieldName)\n .map((field) => field.fieldName);\n\n const propagatedFields = sanitizedFields.map((field) => ({\n ...field,\n sectionTitle: section.title ?? field.sectionTitle,\n }));\n\n return {\n ...section,\n id: fallbackId,\n fields: propagatedFields,\n properties,\n required,\n };\n};\n\nexport const sanitizeSections = (\n sections: ParameterSectionDisplay[] | undefined\n): ParameterSectionDisplay[] =>\n (sections ?? []).map((section, index) => rebuildSectionMeta(section, index));\n\nexport const sectionsToParametersValue = (\n sections: ParameterSectionDisplay[]\n): TemplateParametersValue => {\n const sanitizedSections = sanitizeSections(sections);\n if (!sanitizedSections.length) {\n return undefined;\n }\n\n const templates = sanitizedSections\n .map((section) => {\n const properties = section.properties ?? {};\n if (!Object.keys(properties).length) {\n return null;\n }\n const template: TemplateParametersV1beta3 = {\n title: section.title,\n description: section.description,\n required:\n section.required && section.required.length\n ? [...section.required]\n : undefined,\n properties: JSON.parse(JSON.stringify(properties)),\n };\n return template;\n })\n .filter((entry): entry is TemplateParametersV1beta3 => entry !== null);\n\n if (!templates.length) {\n return undefined;\n }\n\n return templates.length === 1 ? [templates[0]] : templates;\n};\n\nexport const normalizeParametersToSections = (\n parameters: TemplateParametersValue\n): ParameterSectionDisplay[] => {\n if (parameters === undefined || parameters === null) {\n return [];\n }\n\n const entries = Array.isArray(parameters) ? parameters : [parameters];\n const sections: ParameterSectionDisplay[] = [];\n\n entries.forEach((entry, index) => {\n if (!entry || typeof entry !== \"object\") {\n return;\n }\n\n const record = entry as Record<string, any>;\n const steps = Array.isArray(record.steps) ? record.steps : [];\n if (steps.length > 0) {\n steps.forEach((step, stepIndex) => {\n if (!step || typeof step !== \"object\") {\n return;\n }\n const schema = (step as Record<string, any>).schema;\n if (!schema || typeof schema !== \"object\") {\n return;\n }\n const sectionSchema = schema as TemplateParametersV1beta3;\n const stepRecord = step as Record<string, any>;\n const sectionTitle =\n asString(stepRecord.title) ??\n asString(sectionSchema.title) ??\n `Step ${stepIndex + 1}`;\n const sectionDescription =\n asString(stepRecord.description) ??\n asString(sectionSchema.description);\n const sectionProperties =\n asSchemaRecord(sectionSchema.properties) ?? {};\n const required = asStringArray(sectionSchema.required) ?? [];\n const sectionId = `section-${index}-step-${stepIndex}`;\n sections.push({\n id: sectionId,\n title: sectionTitle,\n description: sectionDescription,\n properties: sectionProperties,\n required,\n fields: buildFieldsForSection(\n sectionId,\n sectionTitle,\n sectionProperties,\n required\n ),\n });\n });\n return;\n }\n\n const schema = record as TemplateParametersV1beta3;\n const schemaTitle = asString(schema.title);\n const schemaDescription = asString(schema.description);\n const sectionProperties = asSchemaRecord(schema.properties);\n\n if (sectionProperties && Object.keys(sectionProperties).length > 0) {\n const required = asStringArray(schema.required) ?? [];\n const sectionId = `section-${index}`;\n sections.push({\n id: sectionId,\n title: schemaTitle ?? `Section ${index + 1}`,\n description: schemaDescription,\n properties: sectionProperties,\n required,\n fields: buildFieldsForSection(\n sectionId,\n schemaTitle,\n sectionProperties,\n required\n ),\n });\n return;\n }\n\n const parameterSchema = entry as TemplateParameterSchema;\n const fallbackKey = schemaTitle ?? `field-${index + 1}`;\n const sectionId = `section-${index}`;\n const fallbackProperties: Record<string, ParameterPropertySchema> = {\n [fallbackKey]: parameterSchema as ParameterPropertySchema,\n };\n\n sections.push({\n id: sectionId,\n title: schemaTitle ?? `Section ${index + 1}`,\n description: schemaDescription,\n properties: fallbackProperties,\n required: [],\n fields: buildFieldsForSection(\n sectionId,\n schemaTitle,\n fallbackProperties,\n []\n ),\n });\n });\n\n return sections;\n};\n"],"names":["schema","sectionProperties","sectionId"],"mappings":"AAYA,MAAM,WAAW,CAAC,KAAA,KAChB,OAAO,KAAA,KAAU,WAAW,KAAA,GAAQ,MAAA;AAEtC,MAAM,aAAA,GAAgB,CAAC,KAAA,KACrB,KAAA,CAAM,QAAQ,KAAK,CAAA,IAAK,KAAA,CAAM,KAAA,CAAM,CAAC,IAAA,KAAS,OAAO,IAAA,KAAS,QAAQ,IACjE,KAAA,GACD,MAAA;AAEN,MAAM,cAAA,GAAiB,CACrB,KAAA,KACwD;AACxD,EAAA,IAAI,CAAC,SAAS,OAAO,KAAA,KAAU,YAAY,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AAC/D,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA;AACT,CAAA;AAEA,MAAM,WAAA,GAAc,CAClB,MAAA,KACwC;AACxC,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,MAAM,CAAC,CAAA;AAC1C,CAAA;AAEA,MAAM,kBAAA,GAAqB,CAAC,SAAA,MAAgD;AAAA,EAC1E,OAAO,SAAA,IAAa,OAAA;AAAA,EACpB,IAAA,EAAM;AACR,CAAA,CAAA;AAEA,MAAM,qBAAA,GAAwB,CAC5B,SAAA,EACA,YAAA,EACA,YACA,YAAA,KAC4B;AAC5B,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,SAAA,EAAW,MAAM,CAAA,EAAG,UAAA,KAAe;AACzE,IAAA,MAAM,aACJ,KAAA,CAAM,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AA,MACJ,KAAA,EAAO,WAAA,IAAe,CAAA,QAAA,EAAW,KAAA,GAAQ,CAAC,CAAA,CAAA;AAAA,MAC1C,WAAA,EAAa,iBAAA;AAAA,MACb,UAAA,EAAY,kBAAA;AAAA,MACZ,UAAU,EAAC;AAAA,MACX,MAAA,EAAQ,qBAAA;AAAA,QACN,SAAA;AAAA,QACA,WAAA;AAAA,QACA,kBAAA;AAAA,QACA;AAAC;AACH,KACD,CAAA;AAAA,EACH,CAAC,CAAA;AAED,EAAA,OAAO,QAAA;AACT;;;;"}
@@ -0,0 +1,437 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { useState } from 'react';
3
+ import { NodeToolbar, Position, Handle } from '@xyflow/react';
4
+ import { useTheme, styled } from '@material-ui/core/styles';
5
+ import { Typography, TextField, Button, Divider, Box, Chip, IconButton } from '@material-ui/core';
6
+ import DeleteOutlineIcon from '@material-ui/icons/DeleteOutline';
7
+ import AddIcon from '@material-ui/icons/Add';
8
+ import Autocomplete from '@material-ui/lab/Autocomplete';
9
+ import { normalizeSchemaType, buildTypeLabel, extractEnumOptions, stringifyValueForDisplay, coerceValueForType } from './action/schema.esm.js';
10
+ import { useActionInputs } from './action/useActionInputs.esm.js';
11
+ import { createStopNodeInteraction } from './common/nodeInteraction.esm.js';
12
+ import { AutoWidthPopper } from './common/AutoWidthPopper.esm.js';
13
+
14
+ const Card = styled(Box)(({ theme }) => ({
15
+ background: theme.palette.background.paper,
16
+ border: `1px solid ${theme.palette.divider}`,
17
+ borderRadius: 12,
18
+ width: 760,
19
+ // card width
20
+ padding: theme.spacing(1.5),
21
+ boxShadow: theme.shadows[2],
22
+ color: theme.palette.text.primary
23
+ }));
24
+ const Header = styled(Box)(({ theme }) => ({
25
+ display: "grid",
26
+ gridTemplateColumns: "1fr",
27
+ gap: theme.spacing(1),
28
+ marginBottom: theme.spacing(1)
29
+ }));
30
+ const Grid = styled(Box)(({ theme }) => ({
31
+ display: "grid",
32
+ gridTemplateColumns: "88px 1fr",
33
+ gap: theme.spacing(1),
34
+ alignItems: "center"
35
+ }));
36
+ const KvRow = styled(Box)(({ theme }) => ({
37
+ display: "grid",
38
+ gridTemplateColumns: "200px 140px 1fr auto",
39
+ gap: theme.spacing(1),
40
+ alignItems: "center"
41
+ }));
42
+ const DEFAULT_ACTION_OPTIONS = [
43
+ "fetch:template"
44
+ // TODO to be fixed later to not uses default actions
45
+ ];
46
+ const ActionNode = ({ data }) => {
47
+ const { rfId, step } = data;
48
+ const [newKey, setNewKey] = useState("");
49
+ const [newVal, setNewVal] = useState("");
50
+ const stepOutputReferences = data.stepOutputReferences ?? [];
51
+ const theme = useTheme();
52
+ const actionOptions = (data.scaffolderActionIds?.length ?? 0) > 0 ? data.scaffolderActionIds ?? [] : DEFAULT_ACTION_OPTIONS;
53
+ const handleTop = (field) => (e) => data.onUpdateField?.(rfId, field, e.target.value);
54
+ const actionId = typeof step?.action === "string" ? step.action : "";
55
+ const {
56
+ actionInputSchema,
57
+ inputEntries,
58
+ usedInputKeys,
59
+ availableInputOptions,
60
+ trimmedNewKey,
61
+ selectedNewKeyOption,
62
+ newKeyNormalizedType,
63
+ newKeyTypeLabel,
64
+ newKeyEnumOptions
65
+ } = useActionInputs({ data, step, actionId, newKey });
66
+ const isAddDisabled = !trimmedNewKey || usedInputKeys.has(trimmedNewKey);
67
+ const newValueOptions = Array.from(
68
+ /* @__PURE__ */ new Set([
69
+ ...newKeyNormalizedType === "boolean" ? ["true", "false"] : [],
70
+ ...newKeyEnumOptions,
71
+ ...stepOutputReferences
72
+ ])
73
+ );
74
+ const addPair = () => {
75
+ const k = trimmedNewKey;
76
+ if (!k || usedInputKeys.has(k)) return;
77
+ const schema = selectedNewKeyOption?.schema ?? actionInputSchema?.[k];
78
+ const normalizedType = normalizeSchemaType(schema);
79
+ const parsedValue = coerceValueForType(newVal, normalizedType);
80
+ data.onUpdateInput?.(rfId, k, parsedValue);
81
+ setNewKey("");
82
+ setNewVal("");
83
+ };
84
+ const stopAll = createStopNodeInteraction();
85
+ return /* @__PURE__ */ jsxs(Card, { children: [
86
+ /* @__PURE__ */ jsxs(Header, { title: step?.name || "Unnamed Step", children: [
87
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", noWrap: true, children: step?.name || "Unnamed Step" }),
88
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Action" }),
89
+ /* @__PURE__ */ jsx(
90
+ Autocomplete,
91
+ {
92
+ size: "small",
93
+ options: actionOptions,
94
+ PopperComponent: AutoWidthPopper,
95
+ freeSolo: true,
96
+ value: typeof step?.action === "string" ? step.action : "",
97
+ inputValue: typeof step?.action === "string" ? step.action : "",
98
+ onChange: (_, newValue) => data.onUpdateField?.(rfId, "action", newValue ?? ""),
99
+ onInputChange: (_, newInputValue) => data.onUpdateField?.(rfId, "action", newInputValue ?? ""),
100
+ onPointerDown: stopAll.onPointerDown,
101
+ onKeyDown: stopAll.onKeyDown,
102
+ className: stopAll.className,
103
+ fullWidth: true,
104
+ renderInput: (params) => /* @__PURE__ */ jsx(
105
+ TextField,
106
+ {
107
+ ...params,
108
+ size: "small",
109
+ placeholder: "e.g. fetch:template",
110
+ fullWidth: true,
111
+ inputProps: {
112
+ ...params.inputProps,
113
+ ...stopAll.inputProps
114
+ }
115
+ }
116
+ )
117
+ }
118
+ )
119
+ ] }),
120
+ /* @__PURE__ */ jsx(NodeToolbar, { position: Position.Bottom, children: /* @__PURE__ */ jsx(
121
+ Button,
122
+ {
123
+ variant: "outlined",
124
+ size: "small",
125
+ startIcon: /* @__PURE__ */ jsx(AddIcon, { fontSize: "small" }),
126
+ onClick: () => data.onAddNode?.({
127
+ afterRfId: rfId,
128
+ type: "actionNode"
129
+ }),
130
+ onPointerDown: (e) => e.stopPropagation(),
131
+ className: "nodrag nowheel",
132
+ children: "Add Action"
133
+ }
134
+ ) }),
135
+ /* @__PURE__ */ jsx(Divider, {}),
136
+ /* @__PURE__ */ jsx(Box, { sx: { mb: 1 }, children: /* @__PURE__ */ jsxs(Grid, { children: [
137
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "ID" }),
138
+ /* @__PURE__ */ jsx(
139
+ TextField,
140
+ {
141
+ size: "small",
142
+ placeholder: "string id",
143
+ value: String(step?.id ?? ""),
144
+ onChange: handleTop("id"),
145
+ fullWidth: true,
146
+ ...stopAll
147
+ }
148
+ ),
149
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Name" }),
150
+ /* @__PURE__ */ jsx(
151
+ TextField,
152
+ {
153
+ size: "small",
154
+ placeholder: "Step name",
155
+ value: String(step?.name ?? ""),
156
+ onChange: handleTop("name"),
157
+ fullWidth: true,
158
+ ...stopAll
159
+ }
160
+ )
161
+ ] }) }),
162
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Inputs" }),
163
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", mt: 0.5 }, children: [
164
+ inputEntries.length === 0 && /* @__PURE__ */ jsx(
165
+ Box,
166
+ {
167
+ sx: {
168
+ fontSize: 12,
169
+ color: theme.palette.text.secondary,
170
+ border: `1px dashed ${theme.palette.divider}`,
171
+ borderRadius: 1,
172
+ p: 1,
173
+ textAlign: "center"
174
+ },
175
+ children: "No inputs yet"
176
+ }
177
+ ),
178
+ /* @__PURE__ */ jsxs(
179
+ KvRow,
180
+ {
181
+ sx: {
182
+ mt: inputEntries.length === 0 ? 1.5 : 0.5,
183
+ color: theme.palette.text.secondary
184
+ },
185
+ children: [
186
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Key" }),
187
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Type" }),
188
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "textSecondary", children: "Value" }),
189
+ /* @__PURE__ */ jsx(Box, {})
190
+ ]
191
+ }
192
+ ),
193
+ inputEntries.map(([k, v]) => {
194
+ const schema = actionInputSchema?.[k];
195
+ const normalizedType = normalizeSchemaType(schema);
196
+ const typeLabel = buildTypeLabel(schema) || "String";
197
+ const enumOptions = extractEnumOptions(schema);
198
+ const baseOptions = normalizedType === "boolean" ? ["true", "false"] : [];
199
+ const options = Array.from(
200
+ /* @__PURE__ */ new Set([...baseOptions, ...enumOptions, ...stepOutputReferences])
201
+ );
202
+ const displayValue = stringifyValueForDisplay(v, normalizedType);
203
+ const handleStringChange = (nextValue) => {
204
+ const parsed = coerceValueForType(nextValue, normalizedType);
205
+ data.onUpdateInput?.(rfId, k, parsed);
206
+ };
207
+ return /* @__PURE__ */ jsxs(KvRow, { children: [
208
+ /* @__PURE__ */ jsx(
209
+ Typography,
210
+ {
211
+ variant: "caption",
212
+ noWrap: true,
213
+ title: k,
214
+ color: "textSecondary",
215
+ children: k
216
+ }
217
+ ),
218
+ /* @__PURE__ */ jsx(Box, { display: "flex", children: /* @__PURE__ */ jsx(Chip, { size: "small", variant: "outlined", label: typeLabel }) }),
219
+ (normalizedType === "array" || normalizedType === "object") && /* @__PURE__ */ jsx(
220
+ TextField,
221
+ {
222
+ size: "small",
223
+ value: displayValue,
224
+ onChange: (event) => handleStringChange(event.target.value),
225
+ placeholder: "JSON value",
226
+ fullWidth: true,
227
+ multiline: true,
228
+ minRows: 2,
229
+ inputProps: {
230
+ ...stopAll.inputProps
231
+ },
232
+ onPointerDown: stopAll.onPointerDown,
233
+ onKeyDown: stopAll.onKeyDown,
234
+ className: stopAll.className
235
+ }
236
+ ),
237
+ (normalizedType === "number" || normalizedType === "integer") && /* @__PURE__ */ jsx(
238
+ TextField,
239
+ {
240
+ size: "small",
241
+ value: displayValue,
242
+ onChange: (event) => handleStringChange(event.target.value),
243
+ placeholder: "Number",
244
+ fullWidth: true,
245
+ inputProps: {
246
+ ...stopAll.inputProps,
247
+ inputMode: "decimal"
248
+ },
249
+ onPointerDown: stopAll.onPointerDown,
250
+ onKeyDown: stopAll.onKeyDown,
251
+ className: stopAll.className
252
+ }
253
+ ),
254
+ normalizedType !== "array" && normalizedType !== "object" && normalizedType !== "number" && normalizedType !== "integer" && /* @__PURE__ */ jsx(
255
+ Autocomplete,
256
+ {
257
+ size: "small",
258
+ freeSolo: true,
259
+ options,
260
+ PopperComponent: AutoWidthPopper,
261
+ value: displayValue,
262
+ inputValue: displayValue,
263
+ fullWidth: true,
264
+ onChange: (_, value) => handleStringChange(value ?? ""),
265
+ onInputChange: (_, value, reason) => {
266
+ if (reason === "reset") {
267
+ return;
268
+ }
269
+ handleStringChange(value ?? "");
270
+ },
271
+ onPointerDown: stopAll.onPointerDown,
272
+ onKeyDown: stopAll.onKeyDown,
273
+ className: stopAll.className,
274
+ renderInput: (params) => /* @__PURE__ */ jsx(
275
+ TextField,
276
+ {
277
+ ...params,
278
+ size: "small",
279
+ placeholder: "value",
280
+ inputProps: {
281
+ ...params.inputProps,
282
+ ...stopAll.inputProps
283
+ }
284
+ }
285
+ )
286
+ }
287
+ ),
288
+ /* @__PURE__ */ jsx(
289
+ IconButton,
290
+ {
291
+ size: "small",
292
+ onClick: () => data.onRemoveInputKey?.(rfId, k),
293
+ onPointerDown: (e) => e.stopPropagation(),
294
+ "aria-label": `Remove ${k}`,
295
+ className: "nodrag nowheel",
296
+ children: /* @__PURE__ */ jsx(DeleteOutlineIcon, { fontSize: "small" })
297
+ }
298
+ )
299
+ ] }, k);
300
+ }),
301
+ /* @__PURE__ */ jsxs(KvRow, { children: [
302
+ /* @__PURE__ */ jsx(
303
+ Autocomplete,
304
+ {
305
+ size: "small",
306
+ freeSolo: true,
307
+ options: availableInputOptions,
308
+ PopperComponent: AutoWidthPopper,
309
+ value: selectedNewKeyOption,
310
+ inputValue: newKey,
311
+ onChange: (_, value) => {
312
+ if (!value) {
313
+ setNewKey("");
314
+ return;
315
+ }
316
+ if (typeof value === "string") {
317
+ setNewKey(value);
318
+ return;
319
+ }
320
+ setNewKey(value.key);
321
+ },
322
+ onInputChange: (_, value, reason) => {
323
+ if (reason === "reset") {
324
+ return;
325
+ }
326
+ setNewKey(value ?? "");
327
+ },
328
+ onPointerDown: stopAll.onPointerDown,
329
+ onKeyDown: stopAll.onKeyDown,
330
+ className: stopAll.className,
331
+ getOptionSelected: (option, value) => option.key === value?.key,
332
+ getOptionLabel: (option) => typeof option === "string" ? option : option.label,
333
+ renderInput: (params) => /* @__PURE__ */ jsx(
334
+ TextField,
335
+ {
336
+ ...params,
337
+ size: "small",
338
+ placeholder: "new key",
339
+ inputProps: {
340
+ ...params.inputProps,
341
+ ...stopAll.inputProps
342
+ }
343
+ }
344
+ )
345
+ }
346
+ ),
347
+ /* @__PURE__ */ jsx(Box, { display: "flex", children: /* @__PURE__ */ jsx(Chip, { size: "small", variant: "outlined", label: newKeyTypeLabel }) }),
348
+ (newKeyNormalizedType === "array" || newKeyNormalizedType === "object") && /* @__PURE__ */ jsx(
349
+ TextField,
350
+ {
351
+ size: "small",
352
+ value: newVal,
353
+ onChange: (event) => setNewVal(event.target.value),
354
+ placeholder: "JSON value",
355
+ fullWidth: true,
356
+ multiline: true,
357
+ minRows: 2,
358
+ inputProps: {
359
+ ...stopAll.inputProps
360
+ },
361
+ onPointerDown: stopAll.onPointerDown,
362
+ onKeyDown: stopAll.onKeyDown,
363
+ className: stopAll.className
364
+ }
365
+ ),
366
+ (newKeyNormalizedType === "number" || newKeyNormalizedType === "integer") && /* @__PURE__ */ jsx(
367
+ TextField,
368
+ {
369
+ size: "small",
370
+ value: newVal,
371
+ onChange: (event) => setNewVal(event.target.value),
372
+ placeholder: "Number",
373
+ fullWidth: true,
374
+ inputProps: {
375
+ ...stopAll.inputProps,
376
+ inputMode: "decimal"
377
+ },
378
+ onPointerDown: stopAll.onPointerDown,
379
+ onKeyDown: stopAll.onKeyDown,
380
+ className: stopAll.className
381
+ }
382
+ ),
383
+ newKeyNormalizedType !== "array" && newKeyNormalizedType !== "object" && newKeyNormalizedType !== "number" && newKeyNormalizedType !== "integer" && /* @__PURE__ */ jsx(
384
+ Autocomplete,
385
+ {
386
+ size: "small",
387
+ freeSolo: true,
388
+ options: newValueOptions,
389
+ PopperComponent: AutoWidthPopper,
390
+ value: newVal,
391
+ inputValue: newVal,
392
+ fullWidth: true,
393
+ onChange: (_, value) => setNewVal(value ?? ""),
394
+ onInputChange: (_, value, reason) => {
395
+ if (reason === "reset") {
396
+ return;
397
+ }
398
+ setNewVal(value ?? "");
399
+ },
400
+ onPointerDown: stopAll.onPointerDown,
401
+ onKeyDown: stopAll.onKeyDown,
402
+ className: stopAll.className,
403
+ renderInput: (params) => /* @__PURE__ */ jsx(
404
+ TextField,
405
+ {
406
+ ...params,
407
+ size: "small",
408
+ placeholder: "new value",
409
+ inputProps: {
410
+ ...params.inputProps,
411
+ ...stopAll.inputProps
412
+ }
413
+ }
414
+ )
415
+ }
416
+ ),
417
+ /* @__PURE__ */ jsx(
418
+ Button,
419
+ {
420
+ size: "small",
421
+ variant: "contained",
422
+ onClick: addPair,
423
+ onPointerDown: (e) => e.stopPropagation(),
424
+ disabled: isAddDisabled,
425
+ className: "nodrag nowheel",
426
+ children: "Add"
427
+ }
428
+ )
429
+ ] })
430
+ ] }),
431
+ /* @__PURE__ */ jsx(Handle, { type: "target", position: Position.Top }),
432
+ /* @__PURE__ */ jsx(Handle, { type: "source", position: Position.Bottom })
433
+ ] });
434
+ };
435
+
436
+ export { ActionNode };
437
+ //# sourceMappingURL=ActionNode.esm.js.map