@dmitryvim/form-builder 0.1.19 β†’ 0.1.20

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.
@@ -87,54 +87,36 @@ function validateSchema(schema) {
87
87
 
88
88
  // Form rendering
89
89
  function renderForm(schema, prefill) {
90
- console.log('πŸ”§ FormBuilder.renderForm called with:', { schema, prefill });
91
- console.log('πŸ”§ Arguments length:', arguments.length);
92
- console.log('πŸ”§ Argument 0 (schema):', typeof schema, schema?.title);
93
- console.log('πŸ”§ Argument 1 (prefill):', typeof prefill, prefill);
94
- console.log('πŸ”§ Prefill keys:', Object.keys(prefill || {}));
95
- console.log('πŸ”§ Schema element keys:', schema.elements?.map(e => e.key));
96
90
 
97
91
  const errors = validateSchema(schema);
98
92
  if (errors.length > 0) {
99
93
  console.error('Schema validation errors:', errors);
100
94
  return;
101
95
  }
102
- console.log('βœ… Schema validation passed');
103
96
 
104
97
  state.schema = schema;
105
98
  if (!state.formRoot) {
106
99
  console.error('No form root element set. Call setFormRoot() first.');
107
100
  return;
108
101
  }
109
- console.log('βœ… FormRoot is set:', state.formRoot);
110
102
 
111
103
  clear(state.formRoot);
112
104
 
113
105
  const formEl = document.createElement('div');
114
106
  formEl.className = 'space-y-6';
115
107
 
116
- console.log(`πŸ”§ Processing ${schema.elements.length} schema elements`);
117
108
  schema.elements.forEach((element, index) => {
118
- console.log(`πŸ”§ Rendering element ${index}:`, element);
119
109
  const block = renderElement(element, {
120
110
  path: '',
121
111
  prefill: prefill || {}
122
112
  });
123
- console.log(`βœ… Element ${index} rendered:`, block);
124
113
  formEl.appendChild(block);
125
114
  });
126
115
 
127
116
  state.formRoot.appendChild(formEl);
128
- console.log(`βœ… Form rendered with ${schema.elements.length} elements`);
129
117
  }
130
118
 
131
119
  function renderElement(element, ctx) {
132
- console.log(`πŸ”§ renderElement called for '${element.key}':`, {
133
- elementKey: element.key,
134
- prefillKeys: Object.keys(ctx.prefill || {}),
135
- prefillValue: ctx.prefill?.[element.key],
136
- ctx
137
- });
138
120
 
139
121
  const wrapper = document.createElement('div');
140
122
  wrapper.className = 'mb-6';
@@ -200,21 +182,17 @@ function renderElement(element, ctx) {
200
182
 
201
183
  case 'file':
202
184
  // TODO: Extract to renderFileElement() function
203
- console.log(`πŸ”§ Rendering file element '${element.key}':`, { readonly: state.config.readonly, prefill: ctx.prefill[element.key], element });
204
185
  if (state.config.readonly) {
205
186
  // Readonly mode: use common preview function
206
187
  const initial = ctx.prefill[element.key] || element.default;
207
- console.log(`πŸ”§ File initial value:`, initial);
208
188
  if (initial) {
209
189
  const filePreview = renderFilePreviewReadonly(initial);
210
190
  wrapper.appendChild(filePreview);
211
- console.log(`βœ… File preview rendered for '${element.key}'`);
212
191
  } else {
213
192
  const emptyState = document.createElement('div');
214
193
  emptyState.className = 'aspect-video bg-gray-100 rounded-lg flex items-center justify-center text-gray-500';
215
194
  emptyState.innerHTML = '<div class="text-center">НСт Ρ„Π°ΠΉΠ»Π°</div>';
216
195
  wrapper.appendChild(emptyState);
217
- console.log(`❌ No file data for '${element.key}' - showing empty state`);
218
196
  }
219
197
  } else {
220
198
  // Edit mode: normal file input
@@ -236,6 +214,24 @@ function renderElement(element, ctx) {
236
214
 
237
215
  const initial = ctx.prefill[element.key] || element.default;
238
216
  if (initial) {
217
+ // Add prefill data to resourceIndex so renderFilePreview can use it
218
+ if (!state.resourceIndex.has(initial)) {
219
+ // Extract filename from URL/path
220
+ const filename = initial.split('/').pop() || 'file';
221
+ // Determine file type from extension
222
+ const extension = filename.split('.').pop()?.toLowerCase();
223
+ const fileType = extension && ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(extension)
224
+ ? `image/${extension === 'jpg' ? 'jpeg' : extension}`
225
+ : 'application/octet-stream';
226
+
227
+ state.resourceIndex.set(initial, {
228
+ name: filename,
229
+ type: fileType,
230
+ size: 0,
231
+ file: null // No local file for prefill data
232
+ });
233
+ console.log(`πŸ”§ Added prefill file '${element.key}' to resourceIndex:`, initial);
234
+ }
239
235
  renderFilePreview(fileContainer, initial, initial, '', false).catch(console.error);
240
236
  } else {
241
237
  fileContainer.innerHTML = `
@@ -325,6 +321,29 @@ function renderElement(element, ctx) {
325
321
 
326
322
  const initialFiles = ctx.prefill[element.key] || [];
327
323
 
324
+ // Add prefill files to resourceIndex so renderResourcePills can use them
325
+ if (initialFiles.length > 0) {
326
+ initialFiles.forEach(resourceId => {
327
+ if (!state.resourceIndex.has(resourceId)) {
328
+ // Extract filename from URL/path
329
+ const filename = resourceId.split('/').pop() || 'file';
330
+ // Determine file type from extension
331
+ const extension = filename.split('.').pop()?.toLowerCase();
332
+ const fileType = extension && ['jpg', 'jpeg', 'png', 'gif', 'webp'].includes(extension)
333
+ ? `image/${extension === 'jpg' ? 'jpeg' : extension}`
334
+ : 'application/octet-stream';
335
+
336
+ state.resourceIndex.set(resourceId, {
337
+ name: filename,
338
+ type: fileType,
339
+ size: 0,
340
+ file: null // No local file for prefill data
341
+ });
342
+ console.log(`πŸ”§ Added prefill file to resourceIndex:`, resourceId);
343
+ }
344
+ });
345
+ }
346
+
328
347
  function updateFilesList() {
329
348
  renderResourcePills(list, initialFiles, (ridToRemove) => {
330
349
  const index = initialFiles.indexOf(ridToRemove);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.19",
6
+ "version": "0.1.20",
7
7
  "description": "A reusable JSON schema form builder library",
8
8
  "main": "dist/form-builder.js",
9
9
  "files": [