@dmitryvim/form-builder 0.1.38 → 0.1.39
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/demo.js +17 -0
- package/dist/form-builder.js +28 -13
- package/package.json +1 -1
package/dist/demo.js
CHANGED
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
const EXAMPLE_SCHEMA = {
|
|
6
6
|
version: "0.3",
|
|
7
7
|
title: "Asset Uploader with Slides",
|
|
8
|
+
actions: [
|
|
9
|
+
{
|
|
10
|
+
key: "test-missing",
|
|
11
|
+
label: "Другая потеря"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
key: "save-draft",
|
|
15
|
+
label: "Сохранить черновик"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
8
18
|
elements: [
|
|
9
19
|
{
|
|
10
20
|
type: "file",
|
|
@@ -797,6 +807,13 @@ const EXAMPLE_ACTIONS = [
|
|
|
797
807
|
value: "save_form_draft",
|
|
798
808
|
label: "💾 Save Draft",
|
|
799
809
|
},
|
|
810
|
+
// Action with missing related field (should appear at bottom of form)
|
|
811
|
+
{
|
|
812
|
+
related_field: "non_existent_field",
|
|
813
|
+
key: "test-missing",
|
|
814
|
+
value: "test_missing_field_action",
|
|
815
|
+
label: "🔍 Test Missing Field Action",
|
|
816
|
+
},
|
|
800
817
|
{
|
|
801
818
|
key: "preview",
|
|
802
819
|
value: "preview_infographic",
|
package/dist/form-builder.js
CHANGED
|
@@ -998,14 +998,15 @@ function renderExternalActions() {
|
|
|
998
998
|
|
|
999
999
|
// Group actions by related_field (null for form-level actions)
|
|
1000
1000
|
const actionsByField = new Map();
|
|
1001
|
-
const
|
|
1001
|
+
const trueFormLevelActions = [];
|
|
1002
|
+
const movedFormLevelActions = [];
|
|
1002
1003
|
|
|
1003
1004
|
state.externalActions.forEach((action) => {
|
|
1004
1005
|
if (!action.key || !action.value) return;
|
|
1005
1006
|
|
|
1006
1007
|
if (!action.related_field) {
|
|
1007
|
-
//
|
|
1008
|
-
|
|
1008
|
+
// True form-level action
|
|
1009
|
+
trueFormLevelActions.push(action);
|
|
1009
1010
|
} else {
|
|
1010
1011
|
// Field-level action
|
|
1011
1012
|
if (!actionsByField.has(action.related_field)) {
|
|
@@ -1021,8 +1022,10 @@ function renderExternalActions() {
|
|
|
1021
1022
|
const fieldElement = findFormElementByFieldPath(fieldPath);
|
|
1022
1023
|
if (!fieldElement) {
|
|
1023
1024
|
console.warn(
|
|
1024
|
-
`External action: Could not find form element for field "${fieldPath}"`,
|
|
1025
|
+
`External action: Could not find form element for field "${fieldPath}", treating as form-level actions`,
|
|
1025
1026
|
);
|
|
1027
|
+
// If field is not found, treat these actions as moved form-level actions
|
|
1028
|
+
movedFormLevelActions.push(...actions);
|
|
1026
1029
|
return;
|
|
1027
1030
|
}
|
|
1028
1031
|
|
|
@@ -1087,12 +1090,13 @@ function renderExternalActions() {
|
|
|
1087
1090
|
});
|
|
1088
1091
|
|
|
1089
1092
|
// Render form-level actions at the bottom of the form
|
|
1090
|
-
|
|
1091
|
-
|
|
1093
|
+
const allFormLevelActions = [...trueFormLevelActions, ...movedFormLevelActions];
|
|
1094
|
+
if (allFormLevelActions.length > 0) {
|
|
1095
|
+
renderFormLevelActions(allFormLevelActions, trueFormLevelActions);
|
|
1092
1096
|
}
|
|
1093
1097
|
}
|
|
1094
1098
|
|
|
1095
|
-
function renderFormLevelActions(actions) {
|
|
1099
|
+
function renderFormLevelActions(actions, trueFormLevelActions = []) {
|
|
1096
1100
|
if (!state.formRoot) return;
|
|
1097
1101
|
|
|
1098
1102
|
// Remove any existing form-level actions container
|
|
@@ -1113,11 +1117,14 @@ function renderFormLevelActions(actions) {
|
|
|
1113
1117
|
actionBtn.className =
|
|
1114
1118
|
"bg-white text-gray-700 border border-gray-200 px-4 py-2 text-sm font-medium rounded-lg hover:bg-gray-50 hover:border-gray-300 transition-all duration-200 shadow-sm";
|
|
1115
1119
|
|
|
1120
|
+
// Check if this is a true form-level action (no related_field originally)
|
|
1121
|
+
const isTrueFormLevelAction = trueFormLevelActions.includes(action);
|
|
1122
|
+
|
|
1116
1123
|
// Resolve action label with priority:
|
|
1117
1124
|
// 1. Use explicit label from action if provided
|
|
1118
|
-
// 2. Try to find label from schema element labels using key
|
|
1125
|
+
// 2. Try to find label from schema element labels using key (only for true form-level actions)
|
|
1119
1126
|
// 3. Fall back to using key as label
|
|
1120
|
-
const resolvedLabel = resolveActionLabel(action.key, action.label, null);
|
|
1127
|
+
const resolvedLabel = resolveActionLabel(action.key, action.label, null, isTrueFormLevelAction);
|
|
1121
1128
|
actionBtn.textContent = resolvedLabel;
|
|
1122
1129
|
|
|
1123
1130
|
actionBtn.addEventListener("click", (e) => {
|
|
@@ -1141,8 +1148,8 @@ function renderFormLevelActions(actions) {
|
|
|
1141
1148
|
}
|
|
1142
1149
|
|
|
1143
1150
|
// Helper function to resolve action label
|
|
1144
|
-
function resolveActionLabel(actionKey, externalLabel, schemaElement) {
|
|
1145
|
-
// 1. Try to find label from predefined actions in schema using key (highest priority)
|
|
1151
|
+
function resolveActionLabel(actionKey, externalLabel, schemaElement, isTrueFormLevelAction = false) {
|
|
1152
|
+
// 1. Try to find label from predefined actions in schema element using key (highest priority)
|
|
1146
1153
|
if (schemaElement && schemaElement.actions && Array.isArray(schemaElement.actions)) {
|
|
1147
1154
|
const predefinedAction = schemaElement.actions.find(a => a.key === actionKey);
|
|
1148
1155
|
if (predefinedAction && predefinedAction.label) {
|
|
@@ -1150,12 +1157,20 @@ function resolveActionLabel(actionKey, externalLabel, schemaElement) {
|
|
|
1150
1157
|
}
|
|
1151
1158
|
}
|
|
1152
1159
|
|
|
1153
|
-
// 2.
|
|
1160
|
+
// 2. Try to find label from root-level schema actions (only for true form-level actions)
|
|
1161
|
+
if (isTrueFormLevelAction && state.schema && state.schema.actions && Array.isArray(state.schema.actions)) {
|
|
1162
|
+
const rootAction = state.schema.actions.find(a => a.key === actionKey);
|
|
1163
|
+
if (rootAction && rootAction.label) {
|
|
1164
|
+
return rootAction.label;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// 3. Use explicit label from external action if provided
|
|
1154
1169
|
if (externalLabel) {
|
|
1155
1170
|
return externalLabel;
|
|
1156
1171
|
}
|
|
1157
1172
|
|
|
1158
|
-
//
|
|
1173
|
+
// 4. Fall back to using key as label
|
|
1159
1174
|
return actionKey;
|
|
1160
1175
|
}
|
|
1161
1176
|
|