@mieweb/forms-renderer 0.1.10 → 0.1.11

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 CHANGED
@@ -1,29 +1,25 @@
1
- # 📋 @mieweb/forms-renderer
1
+ # @mieweb/forms-renderer
2
2
 
3
- Read-only questionnaire renderer with dual distribution: React component or Standalone Web Component.
3
+ Questionnaire renderer with three distribution options: React component, standalone Web Component, or Blaze component for Meteor.
4
4
 
5
- ## 📦 Installation
5
+ ## Examples
6
6
 
7
- ```bash
8
- npm install @mieweb/forms-renderer
9
- ```
7
+ - [`example-react.jsx`](./examples/example-react.jsx) - React component
8
+ - [`example-standalone.html`](./examples/example-standalone.html) - Web Component
9
+ - [`blaze-example.html`](./examples/blaze-example.html) - Blaze/Meteor
10
10
 
11
- ## 🚀 Examples
11
+ ## Usage
12
12
 
13
- See the complete working examples in this package:
14
- - [`example-react.jsx`](./examples/example-react.jsx) - ⚛️ React component usage
15
- - [`example-standalone.html`](./examples/example-standalone.html) - 🌐 Web Component usage
13
+ Choose the method that fits your stack:
16
14
 
17
- ## 💻 Usage
15
+ ### 1. React Component (for React apps)
18
16
 
19
- ### ⚛️ React Component (Recommended for React Projects)
20
-
21
- Requires React peer dependencies:
17
+ **Install:**
22
18
  ```bash
23
- npm install react react-dom
19
+ npm install @mieweb/forms-renderer react react-dom
24
20
  ```
25
21
 
26
- #### Basic Usage (Custom Submit Button)
22
+ **Basic Usage:**
27
23
  ```jsx
28
24
  import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
29
25
 
@@ -31,7 +27,7 @@ function MyForm() {
31
27
  const [fields] = React.useState([
32
28
  {
33
29
  id: 'q-name',
34
- fieldType: 'input',
30
+ fieldType: 'text',
35
31
  question: 'What is your full name?',
36
32
  answer: ''
37
33
  }
@@ -41,61 +37,7 @@ function MyForm() {
41
37
 
42
38
  const handleSubmit = (e) => {
43
39
  e.preventDefault();
44
- const fhirResponse = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
45
- console.log('Submitted:', fhirResponse);
46
- // Send to your API, etc.
47
- };
48
-
49
- return (
50
- <form onSubmit={handleSubmit}>
51
- <QuestionnaireRenderer
52
- fields={fields}
53
- onChange={(updated) => console.log('Changed:', updated)}
54
- />
55
- <button type="submit">Submit Questionnaire</button>
56
- </form>
57
- );
58
- }
59
- ```
60
-
61
- #### With Sections and Conditional Logic
62
- From [`example-react.jsx`](./examples/example-react.jsx):
63
- ```jsx
64
- import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
65
-
66
- function App() {
67
- const [fields] = React.useState([
68
- {
69
- id: 'sec-1',
70
- fieldType: 'section',
71
- title: 'Personal Information',
72
- fields: [
73
- {
74
- id: 'q-name',
75
- fieldType: 'input',
76
- question: 'What is your full name?',
77
- answer: ''
78
- },
79
- {
80
- id: 'q-gender',
81
- fieldType: 'radio',
82
- question: 'Biological sex',
83
- options: [
84
- { id: 'gender-male', value: 'Male' },
85
- { id: 'gender-female', value: 'Female' }
86
- ],
87
- selected: null
88
- }
89
- ]
90
- }
91
- ]);
92
-
93
- const currentFields = useFieldsArray();
94
-
95
- const handleSubmit = (e) => {
96
- e.preventDefault();
97
- const fhirResponse = buildQuestionnaireResponse(currentFields, 'demo-1', 'patient-123');
98
- // Handle submission
40
+ const fhir = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
99
41
  };
100
42
 
101
43
  return (
@@ -107,18 +49,19 @@ function App() {
107
49
  }
108
50
  ```
109
51
 
110
- #### With SurveyJS Schema and Hidden Unsupported Fields
52
+ **With SurveyJS Schema:**
111
53
  ```jsx
112
54
  import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
113
55
 
114
56
  function SurveyForm() {
115
- const [surveySchema, setSurveySchema] = React.useState(null);
116
-
117
- React.useEffect(() => {
118
- fetch('/surveyjs-schema.json')
119
- .then(r => r.json())
120
- .then(setSurveySchema);
121
- }, []);
57
+ const surveySchema = {
58
+ pages: [{
59
+ elements: [
60
+ { type: 'text', name: 'firstName', title: 'First Name' },
61
+ { type: 'text', name: 'lastName', title: 'Last Name' }
62
+ ]
63
+ }]
64
+ };
122
65
 
123
66
  return (
124
67
  <QuestionnaireRenderer
@@ -130,127 +73,158 @@ function SurveyForm() {
130
73
  }
131
74
  ```
132
75
 
133
- ### 🌐 Standalone Web Component (Framework-Agnostic)
76
+ ---
134
77
 
135
- Zero dependencies - works with any framework or vanilla JS.
78
+ ### 2. Standalone Web Component (framework-agnostic)
79
+
80
+ **Install:**
81
+ ```bash
82
+ npm install @mieweb/forms-renderer
83
+ ```
84
+ No peer dependencies required - bundles React internally.
136
85
 
137
- From [`example-standalone.html`](./examples/example-standalone.html):
86
+ **Usage:**
138
87
  ```html
139
- <script type="module">
140
- import './package/dist/standalone.js';
141
-
142
- const renderer = document.querySelector('questionnaire-renderer');
143
- renderer.fields = [
144
- {
145
- id: 'sec-1',
146
- fieldType: 'section',
147
- title: 'Patient Information',
148
- fields: [
149
- {
150
- id: 'q-name',
151
- fieldType: 'input',
152
- question: 'Full Name',
153
- answer: ''
154
- },
155
- {
156
- id: 'q-gender',
157
- fieldType: 'radio',
158
- question: 'Biological sex',
159
- options: [
160
- { id: 'gender-male', value: 'Male' },
161
- { id: 'gender-female', value: 'Female' }
162
- ],
163
- selected: null
164
- }
165
- ]
166
- }
167
- ];
168
-
169
- // Handle form submission
170
- const form = document.getElementById('myForm');
171
- form.addEventListener('submit', (e) => {
172
- e.preventDefault();
173
- const fhirResponse = renderer.getQuestionnaireResponse('q-1', 'patient-123');
174
- console.log('Form submitted:', fhirResponse);
175
- });
176
- </script>
177
-
178
- <form id="myForm">
179
- <questionnaire-renderer full-height></questionnaire-renderer>
180
- <button type="submit">Submit</button>
181
- </form>
88
+ <!DOCTYPE html>
89
+ <html>
90
+ <head>
91
+ <script type="module">
92
+ import '@mieweb/forms-renderer/standalone';
93
+ </script>
94
+ </head>
95
+ <body>
96
+ <form id="myForm">
97
+ <questionnaire-renderer></questionnaire-renderer>
98
+ <button type="submit">Submit</button>
99
+ </form>
100
+
101
+ <script>
102
+ const renderer = document.querySelector('questionnaire-renderer');
103
+
104
+ // Set schema type for SurveyJS schemas
105
+ renderer.schemaType = 'surveyjs';
106
+
107
+ // Hide unsupported field types
108
+ renderer.hideUnsupportedFields = true;
109
+
110
+ renderer.fields = [
111
+ {
112
+ id: 'q-name',
113
+ fieldType: 'text',
114
+ question: 'Full Name',
115
+ answer: ''
116
+ }
117
+ ];
118
+
119
+ document.getElementById('myForm').addEventListener('submit', (e) => {
120
+ e.preventDefault();
121
+ const fhir = renderer.getQuestionnaireResponse('q-1', 'patient-123');
122
+ console.log(fhir);
123
+ });
124
+ </script>
125
+ </body>
126
+ </html>
182
127
  ```
183
128
 
184
- ## ⚙️ API Reference
129
+ ---
185
130
 
186
- ### `<QuestionnaireRenderer>` Component
187
- React component for rendering questionnaires (no built-in submit button).
131
+ ### 3. Blaze Component (for Meteor apps)
188
132
 
189
- **Props:**
190
- - `fields` *(array)* - Questionnaire definition array
191
- - `schemaType` *(string)* - Schema format: `'inhouse'` (default) or `'surveyjs'`
192
- - `onChange` *(function)* - Callback when answers change: `(updatedFields) => void`
193
- - `className` *(string)* - Additional CSS classes
194
- - `fullHeight` *(boolean)* - Full viewport height mode
195
- - `hideUnsupportedFields` *(boolean)* - Hide unsupported field types instead of showing placeholders. Useful when importing schemas from external sources like SurveyJS that may contain field types not yet supported by this renderer.
133
+ **Install:**
134
+ ```bash
135
+ meteor npm install @mieweb/forms-renderer
136
+ ```
196
137
 
197
- **Example with hideUnsupportedFields:**
198
- ```jsx
199
- <QuestionnaireRenderer
200
- fields={surveyJsSchema}
201
- schemaType="surveyjs"
202
- hideUnsupportedFields={true}
203
- />
138
+ **Usage:**
139
+ ```javascript
140
+ // In your Meteor client code
141
+ import '@mieweb/forms-renderer/blaze';
142
+
143
+ // If the above doesn't work in your Meteor version, try:
144
+ // import '@mieweb/forms-renderer/dist/blaze.js';
145
+ ```
146
+
147
+ **In your Blaze template:**
148
+ ```handlebars
149
+ {{> questionnaireRenderer
150
+ fields=myFields
151
+ schemaType="surveyjs"
152
+ hideUnsupportedFields=true
153
+ onChange=handleChange}}
154
+ ```
155
+
156
+ **Helper example:**
157
+ ```javascript
158
+ Template.myTemplate.helpers({
159
+ myFields() {
160
+ return [
161
+ { id: 'q1', fieldType: 'text', question: 'Name?', answer: '' }
162
+ ];
163
+ },
164
+ handleChange() {
165
+ return (updatedFields) => {
166
+ console.log('Fields changed:', updatedFields);
167
+ };
168
+ }
169
+ });
204
170
  ```
205
171
 
206
- ### Helper Functions
172
+ ---
173
+
174
+ ## API Reference
207
175
 
208
- #### `buildQuestionnaireResponse(fields, questionnaireId, subjectId)`
209
- Build FHIR QuestionnaireResponse from fields. Use with `useFieldsArray()`.
176
+ ### React Component Props
210
177
 
211
- **Parameters:**
212
- - `fields` *(array)* - Current form fields (from `useFieldsArray()`)
213
- - `questionnaireId` *(string)* - FHIR Questionnaire ID
214
- - `subjectId` *(string, optional)* - Patient/subject ID
178
+ - `fields` - Questionnaire definition array
179
+ - `schemaType` - `'inhouse'` (default) or `'surveyjs'`
180
+ - `onChange` - Callback when answers change
181
+ - `className` - Additional CSS classes
182
+ - `fullHeight` - Full viewport height mode
183
+ - `hideUnsupportedFields` - Hide unsupported field types
215
184
 
216
- **Returns:** FHIR QuestionnaireResponse object
185
+ ### React Helpers
186
+
187
+ **`buildQuestionnaireResponse(fields, questionnaireId, subjectId)`**
188
+
189
+ Returns FHIR QuestionnaireResponse. Use with `useFieldsArray()` to get current form state:
217
190
 
218
- **Example:**
219
191
  ```jsx
220
192
  import { buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
221
193
 
222
- function MyForm() {
223
- const currentFields = useFieldsArray();
224
-
225
- const handleSubmit = (e) => {
226
- e.preventDefault();
227
- const fhirResponse = buildQuestionnaireResponse(currentFields, 'q-1', 'patient-123');
228
- // Send to API, save to database, etc.
229
- };
230
-
231
- return <form onSubmit={handleSubmit}>...</form>;
232
- }
194
+ const currentFields = useFieldsArray();
195
+ const fhir = buildQuestionnaireResponse(currentFields, 'q-1', 'patient-123');
233
196
  ```
234
197
 
235
- ### 🌐 Web Component
236
- - `full-height` - Full viewport height (attribute)
237
- - `fields` - Questionnaire definition (property)
238
- - `onChange` - Change callback (property)
239
- - `getQuestionnaireResponse(questionnaireId, subjectId)` - Get FHIR response (method)
198
+ ### Web Component API
199
+
200
+ - `renderer.fields` - Set/get questionnaire definition (property)
201
+ - `renderer.onChange` - Set change callback (property)
202
+ - `renderer.schemaType` - Set to `'surveyjs'` for SurveyJS schemas (property)
203
+ - `renderer.hideUnsupportedFields` - Boolean to hide unsupported types (property)
204
+ - `renderer.getQuestionnaireResponse(id, subjectId)` - Get FHIR response (method)
240
205
 
241
- ## 🔧 Field Types
206
+ ### Blaze Component Data Context
242
207
 
243
- - `input` - 📝 Text input field
244
- - `radio` - 🔘 Single selection radio buttons
245
- - `check` - ☑️ Multiple selection checkboxes
246
- - `selection` - 📋 Dropdown selection
247
- - `section` - 📂 Container for grouping fields
208
+ - `fields` - Questionnaire definition array
209
+ - `schemaType` - `'inhouse'` or `'surveyjs'`
210
+ - `onChange` - Change callback function
211
+ - `hideUnsupportedFields` - Boolean to hide unsupported types
212
+ - `fullHeight` - Boolean for full height mode
248
213
 
249
- ## 🔀 Conditional Logic (enableWhen)
214
+ ## Field Types
250
215
 
251
- Fields can be shown/hidden based on other field values. Both examples include conditional logic:
216
+ - `text` - Single-line text input
217
+ - `longtext` - Multi-line text area
218
+ - `multitext` - Multiple labeled text inputs
219
+ - `boolean` - Yes/No button selection
220
+ - `radio` - Single selection
221
+ - `check` - Multiple selection
222
+ - `dropdown` - Dropdown selection
223
+ - `section` - Container for grouping
252
224
 
253
- From [`example-react.jsx`](./examples/example-react.jsx):
225
+ ## Conditional Logic
226
+
227
+ Show/hide fields based on other answers:
254
228
  ```javascript
255
229
  {
256
230
  id: 'sec-pregnancy',
@@ -265,7 +239,7 @@ From [`example-react.jsx`](./examples/example-react.jsx):
265
239
  fields: [
266
240
  {
267
241
  id: 'q-weeks',
268
- fieldType: 'input',
242
+ fieldType: 'text',
269
243
  question: 'Weeks gestation (if known)',
270
244
  answer: '',
271
245
  enableWhen: {
@@ -279,9 +253,9 @@ From [`example-react.jsx`](./examples/example-react.jsx):
279
253
  }
280
254
  ```
281
255
 
282
- ## 🏥 FHIR Output
256
+ ## FHIR Output
283
257
 
284
- The `onSubmit` callback receives a FHIR QuestionnaireResponse:
258
+ FHIR QuestionnaireResponse format:
285
259
 
286
260
  ```javascript
287
261
  {
@@ -297,14 +271,4 @@ The `onSubmit` callback receives a FHIR QuestionnaireResponse:
297
271
  }
298
272
  ]
299
273
  }
300
- ```
301
-
302
- ## 📊 Bundle Sizes
303
-
304
- - **⚛️ React version**: ~24 KB (requires peer deps)
305
- - **🌐 Standalone version**: ~819 KB (zero dependencies)
306
-
307
- ## 📚 Documentation
308
-
309
- - [⚛️ React Component Example](./examples/example-react.jsx)
310
- - [🌐 Web Component Example](./examples/example-standalone.html)
274
+ ```