@evanschleret/formforgeclient 1.1.0 → 1.1.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.1.0",
7
+ "version": "1.1.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -137,12 +137,55 @@ function getResolvedZodSchema() {
137
137
  }
138
138
  return internalForm.zodSchema.value;
139
139
  }
140
+ function resolveSchemaFieldNames(schema) {
141
+ const names = /* @__PURE__ */ new Set();
142
+ if (Array.isArray(schema.fields)) {
143
+ for (const field of schema.fields) {
144
+ if (typeof field.name === "string" && field.name !== "") {
145
+ names.add(field.name);
146
+ }
147
+ }
148
+ }
149
+ if (Array.isArray(schema.pages)) {
150
+ for (const page of schema.pages) {
151
+ if (!Array.isArray(page.fields)) {
152
+ continue;
153
+ }
154
+ for (const field of page.fields) {
155
+ if (typeof field.name === "string" && field.name !== "") {
156
+ names.add(field.name);
157
+ }
158
+ }
159
+ }
160
+ }
161
+ return names;
162
+ }
163
+ function sanitizePayloadWithSchema(value, schema) {
164
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
165
+ return {};
166
+ }
167
+ const allowedFieldNames = resolveSchemaFieldNames(schema);
168
+ const sanitizedPayload = {};
169
+ for (const [key, entryValue] of Object.entries(value)) {
170
+ if (!allowedFieldNames.has(key)) {
171
+ continue;
172
+ }
173
+ sanitizedPayload[key] = entryValue;
174
+ }
175
+ return sanitizedPayload;
176
+ }
140
177
  const formState = computed({
141
178
  get: () => {
142
179
  const value = usesExternalModel.value ? unwrapModelValueProp(props.modelValue) : internalForm.state.value;
143
180
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
144
181
  return {};
145
182
  }
183
+ if (usesExternalModel.value) {
184
+ const schema = getResolvedSchema();
185
+ if (schema !== null) {
186
+ return sanitizePayloadWithSchema(value, schema);
187
+ }
188
+ }
146
189
  return value;
147
190
  },
148
191
  set: (value) => {
@@ -153,6 +196,23 @@ const formState = computed({
153
196
  internalForm.replaceState(value);
154
197
  }
155
198
  });
199
+ watch(
200
+ () => [usesExternalModel.value, getResolvedSchema(), unwrapModelValueProp(props.modelValue)],
201
+ ([externalModel, schema, modelValue]) => {
202
+ if (!externalModel || schema === null) {
203
+ return;
204
+ }
205
+ const sanitizedValue = sanitizePayloadWithSchema(modelValue, schema);
206
+ if (areValuesEqual(modelValue, sanitizedValue)) {
207
+ return;
208
+ }
209
+ emit("update:modelValue", sanitizedValue);
210
+ },
211
+ {
212
+ immediate: true,
213
+ deep: true
214
+ }
215
+ );
156
216
  const displayPages = computed(() => {
157
217
  const schema = getResolvedSchema();
158
218
  if (schema === null) {
@@ -861,6 +921,20 @@ function getFieldMetaUi(field) {
861
921
  component: componentUi
862
922
  };
863
923
  }
924
+ function mergeUiClass(defaultClass, value) {
925
+ if (typeof value !== "string" || value.trim() === "") {
926
+ return defaultClass;
927
+ }
928
+ return `${defaultClass} ${value}`;
929
+ }
930
+ function getResolvedFormFieldUi(field) {
931
+ const metaUi = getFieldMetaUi(field).formField;
932
+ return {
933
+ ...metaUi,
934
+ label: mergeUiClass("text-default", metaUi?.label),
935
+ help: mergeUiClass("text-muted", metaUi?.help)
936
+ };
937
+ }
864
938
  function getFieldValue(field) {
865
939
  return formState.value[field.name];
866
940
  }
@@ -1098,7 +1172,7 @@ async function onSubmit() {
1098
1172
  >
1099
1173
  <h3
1100
1174
  v-if="page.title !== ''"
1101
- class="text-base font-semibold"
1175
+ class="text-base font-semibold text-default"
1102
1176
  >
1103
1177
  {{ page.title }}
1104
1178
  </h3>
@@ -1119,7 +1193,7 @@ async function onSubmit() {
1119
1193
  :label="field.label"
1120
1194
  :help="field.help_text"
1121
1195
  :required="isFieldRequired(field)"
1122
- :ui="getFieldMetaUi(field).formField"
1196
+ :ui="getResolvedFormFieldUi(field)"
1123
1197
  @focusout="() => onFieldBlur(field.name)"
1124
1198
  >
1125
1199
  <UInput
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanschleret/formforgeclient",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Nuxt module and runtime client for FormForge",
5
5
  "license": "MIT",
6
6
  "type": "module",