@dmitryvim/form-builder 0.2.26 → 0.2.28
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/README.md +60 -4
- package/dist/browser/formbuilder.min.js +534 -184
- package/dist/browser/formbuilder.v0.2.28.min.js +956 -0
- package/dist/cjs/index.cjs +2002 -1005
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1976 -992
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +534 -184
- package/dist/types/components/file/constraints.d.ts +62 -0
- package/dist/types/components/file/dom.d.ts +44 -0
- package/dist/types/components/file/library.d.ts +49 -0
- package/dist/types/components/file/preview.d.ts +69 -0
- package/dist/types/components/file/render-edit.d.ts +18 -0
- package/dist/types/components/file/render-readonly.d.ts +23 -0
- package/dist/types/components/file/styles.d.ts +1 -0
- package/dist/types/components/file/upload.d.ts +25 -0
- package/dist/types/components/file/validate.d.ts +13 -0
- package/dist/types/components/file.d.ts +5 -27
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/config.d.ts +37 -0
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/schema.d.ts +13 -6
- package/package.json +1 -1
- package/dist/browser/formbuilder.v0.2.26.min.js +0 -606
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ This package ships with complete TypeScript definitions. Ensure your `tsconfig.j
|
|
|
54
54
|
## Core Features
|
|
55
55
|
|
|
56
56
|
- **🎯 Schema-driven forms**: JSON Schema v0.3 → Interactive forms with live preview
|
|
57
|
-
- **📁 Advanced file handling**: Images, videos, documents with drag-and-drop and
|
|
57
|
+
- **📁 Advanced file handling**: Images, videos, documents with drag-and-drop, tile preview, and per-file upload progress
|
|
58
58
|
- **✅ Real-time validation**: Client-side validation with visual feedback and error display
|
|
59
59
|
- **🌍 Internationalization**: Built-in English/Russian support with extensible translation system
|
|
60
60
|
- **🎨 Rich field types**: Text, textarea, number, select, file, files, and nested groups
|
|
@@ -301,8 +301,8 @@ See [Integration Guide](docs/integration.md) for detailed setup instructions.
|
|
|
301
301
|
- **Colour**: Colour picker with hex values (single or palette)
|
|
302
302
|
- **Slider**: Range slider with linear/exponential scales (v0.2.7+)
|
|
303
303
|
- **Table**: 2D editable grid with cell merging, keyboard navigation, readonly mode
|
|
304
|
-
- **File**: Single file upload with preview and type restrictions
|
|
305
|
-
- **Files**: Multiple file upload with grid
|
|
304
|
+
- **File**: Single file upload with compact dropzone, tile preview, and type restrictions
|
|
305
|
+
- **Files**: Multiple file upload with 80px tile grid, per-file upload progress, and drag-and-drop
|
|
306
306
|
- **Container**: Nested containers with repeatable array support
|
|
307
307
|
|
|
308
308
|
### File Handling
|
|
@@ -341,6 +341,19 @@ const form = createFormBuilder({
|
|
|
341
341
|
getDownloadUrl?: (resourceId: string) => string | null, // Optional: URL for downloading full file
|
|
342
342
|
actionHandler?: (value: any, key: string, field: any) => void,
|
|
343
343
|
|
|
344
|
+
// v0.2.28: Host-owned file library picker (optional)
|
|
345
|
+
// When configured, adds an equal-prominence "From library" trigger alongside upload.
|
|
346
|
+
// resolve([]) = silent cancel; reject/throw = error shown in the field.
|
|
347
|
+
// PickedResource is exported from the package root.
|
|
348
|
+
pickExistingFiles?: (context: {
|
|
349
|
+
fieldPath: string; // bracket-notation path, e.g. "slides[2].image"
|
|
350
|
+
mode: 'single' | 'multiple';
|
|
351
|
+
accept?: { extensions?: string[]; mime?: string[] };
|
|
352
|
+
maxSizeMB?: number; // Infinity if no limit
|
|
353
|
+
remainingSlots?: number; // multi mode only
|
|
354
|
+
selectedResourceIds?: string[];
|
|
355
|
+
}) => Promise<PickedResource[]>,
|
|
356
|
+
|
|
344
357
|
// v0.2.0: onChange events
|
|
345
358
|
onChange?: (formData: FormResult) => void,
|
|
346
359
|
onFieldChange?: (fieldPath: string, value: any, formData: FormResult) => void,
|
|
@@ -510,6 +523,49 @@ When a user clicks the download button in readonly mode, the form builder uses t
|
|
|
510
523
|
|
|
511
524
|
`getThumbnail` must be async (return `Promise`). TypeScript enforces this at compile-time. If you provide a synchronous handler, the error will occur at first file usage (not at form instantiation). This is intentional - we avoid validation calls that would trigger unnecessary API requests. Follow the **FAIL FAST** principle: errors surface naturally at usage.
|
|
512
525
|
|
|
526
|
+
### File Library Picker (v0.2.28+)
|
|
527
|
+
|
|
528
|
+
Let users pick from already-uploaded files without re-uploading. Configure the optional `pickExistingFiles` handler to open your own media library modal.
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
import { createFormBuilder, PickedResource } from "@dmitryvim/form-builder";
|
|
532
|
+
|
|
533
|
+
const form = createFormBuilder({
|
|
534
|
+
uploadFile: async (file) => "resource-id",
|
|
535
|
+
|
|
536
|
+
pickExistingFiles: async (ctx) => {
|
|
537
|
+
// ctx.fieldPath — bracket-notation path, e.g. "images[0].cover"
|
|
538
|
+
// ctx.mode — "single" | "multiple"
|
|
539
|
+
// ctx.accept — { extensions?, mime? }
|
|
540
|
+
// ctx.remainingSlots — multi mode: how many more files fit
|
|
541
|
+
// ctx.selectedResourceIds — IDs already in this field (for UI deselection)
|
|
542
|
+
|
|
543
|
+
const chosen = await openYourLibraryModal(ctx);
|
|
544
|
+
// resolve([]) to cancel silently
|
|
545
|
+
return chosen; // PickedResource[]
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
**`PickedResource` interface:**
|
|
551
|
+
|
|
552
|
+
```typescript
|
|
553
|
+
interface PickedResource {
|
|
554
|
+
resourceId: string;
|
|
555
|
+
name: string;
|
|
556
|
+
type: string; // MIME type
|
|
557
|
+
size: number; // bytes
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
**UI behavior:**
|
|
562
|
+
|
|
563
|
+
- Without `pickExistingFiles`: no UI change (identical to v0.2.27).
|
|
564
|
+
- With `pickExistingFiles`: empty state shows two equal cards (upload + library). Multi-file fields show two add-tiles ("+"/upload and library icon). Both are hidden when `maxCount` is reached.
|
|
565
|
+
- Single-file with a file already selected: no library trigger (existing tile occupies slot).
|
|
566
|
+
|
|
567
|
+
**Validation:** The library re-validates resolved items using the same rules as upload (`accept.extensions`, `maxSize`, `maxCount`, dedupe). Host-side filtering in your picker UI is advisory.
|
|
568
|
+
|
|
513
569
|
### Conditional Field Visibility
|
|
514
570
|
|
|
515
571
|
Show or hide fields based on form data values using the `enableIf` property:
|
|
@@ -788,7 +844,7 @@ Features a 3-column interface:
|
|
|
788
844
|
- **GitHub**: [picazru/form-builder](https://github.com/picazru/form-builder)
|
|
789
845
|
- **NPM Package**: [@dmitryvim/form-builder](https://www.npmjs.com/package/@dmitryvim/form-builder)
|
|
790
846
|
- **CDN**: [picaz-form-builder.website.yandexcloud.net](https://picaz-form-builder.website.yandexcloud.net/)
|
|
791
|
-
- **Version**: 0.2.
|
|
847
|
+
- **Version**: 0.2.28
|
|
792
848
|
- **License**: MIT - see [LICENSE](LICENSE) file
|
|
793
849
|
|
|
794
850
|
Built with ❤️ for the web development community.
|