@mieweb/forms-editor 0.1.3 → 0.1.6
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 +66 -81
- package/dist/index.js +388 -390
- package/dist/index.js.map +1 -1
- package/package.json +38 -38
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# @mieweb/forms-editor
|
|
1
|
+
# @mieweb/forms-editor `v0.1.4`
|
|
2
2
|
|
|
3
|
-
Embeddable questionnaire editor component with
|
|
3
|
+
Embeddable questionnaire editor component with FHIR export and conditional logic support.
|
|
4
4
|
|
|
5
5
|
## 📦 Installation
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ Embeddable questionnaire editor component with drag-and-drop, FHIR export, and c
|
|
|
8
8
|
npm install @mieweb/forms-editor
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
### Peer Dependencies
|
|
11
|
+
### Peer Dependencies (Required)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
You must install React 18+ in your project:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install react react-dom
|
|
@@ -26,55 +26,62 @@ The following are installed automatically:
|
|
|
26
26
|
|
|
27
27
|
## 🚀 Quick Start
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### Basic Usage
|
|
30
30
|
|
|
31
31
|
```jsx
|
|
32
32
|
import { QuestionnaireEditor } from '@mieweb/forms-editor';
|
|
33
|
+
import { createRoot } from 'react-dom/client';
|
|
34
|
+
import './index.css';
|
|
33
35
|
|
|
34
36
|
function App() {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const [fields, setFields] = React.useState([
|
|
38
|
+
{ id: 'section-1', fieldType: 'section', title: 'Section 1', fields: [] },
|
|
39
|
+
{ id: 'name', fieldType: 'input', question: 'Your Name', required: true },
|
|
40
|
+
{ id: 'gender', fieldType: 'radio', question: 'Gender', options: [{ value: 'Male' }, { value: 'Female' }], selected: null },
|
|
41
|
+
]);
|
|
38
42
|
|
|
39
43
|
return (
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
<div className="w-full h-dvh bg-slate-100">
|
|
45
|
+
<div className="absolute inset-0 overflow-auto">
|
|
46
|
+
<QuestionnaireEditor
|
|
47
|
+
initialFields={fields}
|
|
48
|
+
onChange={setFields}
|
|
49
|
+
/>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
43
52
|
);
|
|
44
53
|
}
|
|
54
|
+
|
|
55
|
+
createRoot(document.getElementById('root')).render(<App />);
|
|
45
56
|
```
|
|
46
57
|
|
|
47
|
-
###
|
|
58
|
+
### With State Persistence
|
|
48
59
|
|
|
49
60
|
```jsx
|
|
50
|
-
import { QuestionnaireEditor } from '@mieweb/forms-editor';
|
|
51
|
-
|
|
52
|
-
const initialFields = [
|
|
53
|
-
{
|
|
54
|
-
id: '1',
|
|
55
|
-
fieldType: 'input',
|
|
56
|
-
question: 'What is your name?',
|
|
57
|
-
answer: ''
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: '2',
|
|
61
|
-
fieldType: 'radio',
|
|
62
|
-
question: 'Select your role',
|
|
63
|
-
options: ['Developer', 'Designer', 'Manager'],
|
|
64
|
-
selected: null
|
|
65
|
-
}
|
|
66
|
-
];
|
|
67
|
-
|
|
68
61
|
function App() {
|
|
62
|
+
const [fields, setFields] = React.useState(() => {
|
|
63
|
+
const saved = localStorage.getItem('questionnaire');
|
|
64
|
+
return saved ? JSON.parse(saved) : [];
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const handleChange = (newFields) => {
|
|
68
|
+
setFields(newFields);
|
|
69
|
+
localStorage.setItem('questionnaire', JSON.stringify(newFields));
|
|
70
|
+
};
|
|
71
|
+
|
|
69
72
|
return (
|
|
70
|
-
<
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
<div className="absolute inset-0 overflow-auto">
|
|
74
|
+
<QuestionnaireEditor
|
|
75
|
+
initialFields={fields}
|
|
76
|
+
onChange={handleChange}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
74
79
|
);
|
|
75
80
|
}
|
|
76
81
|
```
|
|
77
82
|
|
|
83
|
+
---
|
|
84
|
+
|
|
78
85
|
## 📖 Props
|
|
79
86
|
|
|
80
87
|
### `QuestionnaireEditor`
|
|
@@ -147,59 +154,34 @@ Toggle preview mode to see how the form looks to end users:
|
|
|
147
154
|
### Custom Styling
|
|
148
155
|
|
|
149
156
|
```jsx
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.my-custom-editor {
|
|
158
|
-
--primary-color: #3b82f6;
|
|
159
|
-
--border-radius: 0.5rem;
|
|
160
|
-
}
|
|
157
|
+
<div className="absolute inset-0 overflow-auto">
|
|
158
|
+
<QuestionnaireEditor
|
|
159
|
+
className="custom-editor"
|
|
160
|
+
initialFields={fields}
|
|
161
|
+
onChange={setFields}
|
|
162
|
+
/>
|
|
163
|
+
</div>
|
|
161
164
|
```
|
|
162
165
|
|
|
163
|
-
###
|
|
166
|
+
### Start in Preview Mode
|
|
164
167
|
|
|
165
168
|
```jsx
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const [savedFields, setSavedFields] = useState([]);
|
|
172
|
-
|
|
173
|
-
const handleChange = (fields) => {
|
|
174
|
-
setSavedFields(fields);
|
|
175
|
-
localStorage.setItem('questionnaire', JSON.stringify(fields));
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
return (
|
|
179
|
-
<QuestionnaireEditor
|
|
180
|
-
initialFields={savedFields}
|
|
181
|
-
onChange={handleChange}
|
|
182
|
-
/>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
169
|
+
<QuestionnaireEditor
|
|
170
|
+
initialFields={fields}
|
|
171
|
+
onChange={setFields}
|
|
172
|
+
startInPreview={true}
|
|
173
|
+
/>
|
|
185
174
|
```
|
|
186
175
|
|
|
187
|
-
###
|
|
176
|
+
### Hide Header or Mobile Toolbar
|
|
188
177
|
|
|
189
178
|
```jsx
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return (
|
|
197
|
-
<div>
|
|
198
|
-
<p>{fieldCount} fields | Mode: {isPreview ? 'Preview' : 'Edit'}</p>
|
|
199
|
-
<QuestionnaireEditor />
|
|
200
|
-
</div>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
179
|
+
<QuestionnaireEditor
|
|
180
|
+
initialFields={fields}
|
|
181
|
+
onChange={setFields}
|
|
182
|
+
showHeader={false}
|
|
183
|
+
showMobileToolbar={false}
|
|
184
|
+
/>
|
|
203
185
|
```
|
|
204
186
|
|
|
205
187
|
## 🔧 Field Structure
|
|
@@ -228,8 +210,11 @@ Each field follows this structure:
|
|
|
228
210
|
|
|
229
211
|
## 📦 Bundle Size
|
|
230
212
|
|
|
231
|
-
- **
|
|
232
|
-
- **
|
|
213
|
+
- **ESM format** with tree-shaking support
|
|
214
|
+
- **TypeScript definitions** included
|
|
215
|
+
- **CSS automatically injected** - no manual imports needed
|
|
216
|
+
- Dependencies: `@mieweb/forms-engine`, `framer-motion`, `js-yaml`
|
|
217
|
+
- Peer dependencies: React 18+
|
|
233
218
|
|
|
234
219
|
## 🎨 Theming
|
|
235
220
|
|