@dmitryvim/form-builder 0.2.27 → 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 +57 -1
- package/dist/browser/formbuilder.min.js +207 -125
- package/dist/browser/formbuilder.v0.2.28.min.js +956 -0
- package/dist/cjs/index.cjs +542 -133
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +528 -122
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +207 -125
- package/dist/types/components/file/constraints.d.ts +39 -3
- package/dist/types/components/file/library.d.ts +49 -0
- package/dist/types/components/file/render-edit.d.ts +12 -9
- package/dist/types/components/file/upload.d.ts +15 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/config.d.ts +33 -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.27.min.js +0 -874
package/README.md
CHANGED
|
@@ -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.
|