@dmitryvim/form-builder 0.1.1

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +175 -0
  3. package/dist/index.html +1279 -0
  4. package/package.json +34 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Picaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # Form Builder
2
+
3
+ JSON Schema → Dynamic Forms → Structured Output
4
+
5
+ ## Live Demo
6
+
7
+ Try it now: **[https://picazru.github.io/form-builder/dist/index.html](https://picazru.github.io/form-builder/dist/index.html)**
8
+
9
+ ## Quick Start
10
+
11
+ ### Embed in Your Website
12
+
13
+ ```html
14
+ <!-- Full page embed -->
15
+ <iframe src="https://picazru.github.io/form-builder/dist/index.html"
16
+ width="100%" height="600px"
17
+ frameborder="0"
18
+ style="border-radius: 8px;"></iframe>
19
+
20
+ <!-- With custom schema via URL parameter -->
21
+ <iframe src="https://picazru.github.io/form-builder/dist/index.html?schema=eyJ2ZXJzaW9uIjoiMC4zIi..."
22
+ width="100%" height="600px"></iframe>
23
+ ```
24
+
25
+ ### Install via npm
26
+
27
+ ```bash
28
+ npm install @picazru/form-builder
29
+ ```
30
+
31
+ ## Integration
32
+
33
+ ### Basic Schema
34
+
35
+ ```json
36
+ {
37
+ "version": "0.3",
38
+ "title": "Contact Form",
39
+ "elements": [
40
+ {
41
+ "type": "text",
42
+ "key": "name",
43
+ "label": "Full Name",
44
+ "required": true
45
+ },
46
+ {
47
+ "type": "file",
48
+ "key": "avatar",
49
+ "label": "Profile Picture",
50
+ "accept": {
51
+ "extensions": ["jpg", "png"]
52
+ }
53
+ }
54
+ ]
55
+ }
56
+ ```
57
+
58
+ ### Configure File Handlers
59
+
60
+ When embedding the form builder, configure file upload handlers on your page:
61
+
62
+ ```html
63
+ <!DOCTYPE html>
64
+ <html>
65
+ <head>
66
+ <title>My App with Form Builder</title>
67
+ </head>
68
+ <body>
69
+ <!-- Embed the form builder -->
70
+ <iframe id="formBuilder"
71
+ src="https://picazru.github.io/form-builder/dist/index.html"
72
+ width="100%" height="600px"></iframe>
73
+
74
+ <script>
75
+ // Configure file upload handlers
76
+ window.addEventListener('message', (event) => {
77
+ if (event.origin !== 'https://picazru.github.io') return;
78
+
79
+ if (event.data.type === 'formBuilderReady') {
80
+ // Send configuration to the iframe
81
+ const iframe = document.getElementById('formBuilder');
82
+ iframe.contentWindow.postMessage({
83
+ type: 'configure',
84
+ config: {
85
+ uploadHandler: async (file) => {
86
+ // Your S3 upload logic
87
+ const formData = new FormData();
88
+ formData.append('file', file);
89
+
90
+ const response = await fetch('/api/upload', {
91
+ method: 'POST',
92
+ body: formData
93
+ });
94
+
95
+ const result = await response.json();
96
+ return result.fileUrl;
97
+ }
98
+ }
99
+ }, 'https://picazru.github.io');
100
+ }
101
+ });
102
+ </script>
103
+ </body>
104
+ </html>
105
+ ```
106
+
107
+ ### Direct Page Integration
108
+
109
+ If you want to integrate directly on your page (not iframe):
110
+
111
+ ```html
112
+ <script>
113
+ window.addEventListener('formBuilderReady', (event) => {
114
+ const config = event.detail;
115
+
116
+ // Upload files to S3
117
+ config.setUploadHandler(async (file) => {
118
+ const formData = new FormData();
119
+ formData.append('file', file);
120
+
121
+ const response = await fetch('/api/upload', {
122
+ method: 'POST',
123
+ body: formData
124
+ });
125
+
126
+ const result = await response.json();
127
+ return result.fileUrl; // Return S3 URL or resource ID
128
+ });
129
+
130
+ // Download files
131
+ config.setDownloadHandler(async (resourceId) => {
132
+ window.open(`/api/download/${resourceId}`, '_blank');
133
+ });
134
+
135
+ // Generate thumbnails
136
+ config.setThumbnailHandler(async (resourceId) => {
137
+ return `/api/thumbnail/${resourceId}`;
138
+ });
139
+ });
140
+ </script>
141
+ ```
142
+
143
+ ### Field Types
144
+
145
+ - **text** - Single line text with validation
146
+ - **textarea** - Multi-line text
147
+ - **number** - Numeric input with min/max
148
+ - **select** - Dropdown with options
149
+ - **file** - Single file upload with preview
150
+ - **files** - Multiple file uploads
151
+ - **group** - Nested objects with repeat support
152
+
153
+ ### Form Output
154
+
155
+ ```json
156
+ {
157
+ "name": "John Doe",
158
+ "avatar": "https://bucket.s3.amazonaws.com/files/avatar.jpg"
159
+ }
160
+ ```
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ git clone https://github.com/picazru/form-builder.git
166
+ cd form-builder
167
+ npm install
168
+ npm run dev # Start development server
169
+ npm test # Run tests
170
+ npm run build # Build for production
171
+ ```
172
+
173
+ ## License
174
+
175
+ MIT - see [LICENSE](LICENSE) file.