@dialob/composer-material 0.0.12 → 0.0.14
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 +180 -0
- package/dist-lib/index.d.ts +2 -0
- package/dist-lib/index.js +27949 -18496
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -101,4 +101,184 @@ pnpm run preview
|
|
|
101
101
|
|
|
102
102
|
Starts preview server for built application from `/dist` (No hot-reload!). Run `pnpm build` first to build the package
|
|
103
103
|
|
|
104
|
+
### Item type configuration
|
|
105
|
+
|
|
106
|
+
For exmaple: `src/defaults/itemTypes.js`
|
|
107
|
+
|
|
108
|
+
Item type configuration corresponds to "Add new" item creation menu structure and also defines available item types including their configuration
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
DEFAULT_ITEMTYPE_CONFIG: ItemTypeConfig = {
|
|
112
|
+
categories: [
|
|
113
|
+
{
|
|
114
|
+
title: 'Structure',
|
|
115
|
+
type: 'structure',
|
|
116
|
+
items: [
|
|
117
|
+
{
|
|
118
|
+
title: 'Group',
|
|
119
|
+
optionEditors: [
|
|
120
|
+
{name: 'Additional option', editor: PropEditors.InputProp}
|
|
121
|
+
],
|
|
122
|
+
propEditors: {
|
|
123
|
+
columns: {
|
|
124
|
+
component: PropEditors.InputProp,
|
|
125
|
+
props: {
|
|
126
|
+
type: 'number',
|
|
127
|
+
min: 1,
|
|
128
|
+
max: 20
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
config: {
|
|
133
|
+
type: 'group',
|
|
134
|
+
props: {
|
|
135
|
+
columns: 1
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: 'Multi-choice',
|
|
141
|
+
convertible: ['list'],
|
|
142
|
+
propEditors: {
|
|
143
|
+
display: {
|
|
144
|
+
component: PropEditors.ChoiceProp,
|
|
145
|
+
props: {
|
|
146
|
+
options: [
|
|
147
|
+
{key: 'dropdown', label: 'Dropdown'},
|
|
148
|
+
{key: 'button', label: 'Button'},
|
|
149
|
+
{key: 'checkbox', label: 'Checkbox'}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
config: {
|
|
155
|
+
type: 'multichoice',
|
|
156
|
+
props: {
|
|
157
|
+
display: 'dropdown',
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
// ....
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
// ....
|
|
167
|
+
]
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
See: `src/defaults/type.ts` for TypeScript types
|
|
172
|
+
|
|
173
|
+
* `categories` defines top-level categories, category object contains following attributes:
|
|
174
|
+
* `Title` Label used in UI
|
|
175
|
+
* `type` Category type, allowed values: `structure`, `input`, `output` - These are used to limit certain categories of items to be added into form depending on conditions
|
|
176
|
+
* `items` Array of item configurations within this category. Item objects contain following attributes
|
|
177
|
+
* `title` Label used in UI
|
|
178
|
+
* `convertible` (Optional) Array of item type identifiers into which this item can be converted. Entries are first matched by `view` attribute, if not found then by `type`. If omitted, item can't be converted to other types.
|
|
179
|
+
* `optionEditors` (Optional) Array of additional pages for item options dialog. Array of objects: `{name: 'Title of page', editor: OptionEditorComponent}` (see below)
|
|
180
|
+
* `propEditors` (Optional) if custom property editors are configured for item. If prop editor is not defined, it will be fallen back to plain text. Editor configuration is set of objects having prop name as a key:
|
|
181
|
+
* `component` : React component to use for editing the prop
|
|
182
|
+
* `props` : (Optional) Additional properties for the editing component. (see below)
|
|
183
|
+
* `config` : Snippet of Dialob form item configuration (See Dialob Form API). Any predefined structure is supported. only mandatory attribute is `type`. Item's default ID will be based on `view` attribute falling back to `type`
|
|
184
|
+
|
|
185
|
+
**Note!** `props` Are item specific properties that are available at filling time
|
|
186
|
+
|
|
187
|
+
#### Prop editor configrurations
|
|
188
|
+
|
|
189
|
+
Built in editors:
|
|
190
|
+
|
|
191
|
+
* `PropEditors.InputProp` - Plain input component, supports HTML `<input>` attributes as props for defining input type etc.
|
|
192
|
+
|
|
193
|
+
* `PropEditors.ChoiceProp` - Dropdown selection list, `options` prop having an array of `{key: '', label: ''},` entries, where `key` is value stored in prop and `label` is text displayed in UI.
|
|
194
|
+
|
|
195
|
+
* `PropEditors.BoolProp` - Boolean switch.
|
|
196
|
+
|
|
197
|
+
* `PropEditors.MultiChoiceProp` - Dropdown selection list, allows multiple selections (Array of string value). `options` prop as in `ChoiceProp`, `allowAdditions` true/false -- Allow adding arbitrary strings to list.
|
|
198
|
+
|
|
199
|
+
Custom editing component template
|
|
200
|
+
```typescript
|
|
201
|
+
const CustomProp = ({ onChange, value, name, item, ...props }) => {
|
|
202
|
+
// onChange(value) - callback function for setting the prop's value
|
|
203
|
+
// value - current value of the prop
|
|
204
|
+
// name - prop name
|
|
205
|
+
// item - item data for current item. (Immutable.Map)
|
|
206
|
+
// props - additional editor component props passed on from configuration
|
|
207
|
+
|
|
208
|
+
// Return react component here that renders UI for prop editor
|
|
209
|
+
return (<Input onChange={(e) => onChange(e.target.value)} value={value || ''} {...props} />);
|
|
210
|
+
};
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
### Item editor configuration
|
|
215
|
+
|
|
216
|
+
For example: `src/defaults/itemConfig.js`
|
|
217
|
+
|
|
218
|
+
Item editor configuration defines which kind of item editing components are used in which conditions.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
export const DEFAULT_ITEM_CONFIG: ItemConfig = {
|
|
222
|
+
defaultIcon: Circle,
|
|
223
|
+
items: [
|
|
224
|
+
{
|
|
225
|
+
matcher: item => item.type === 'group',
|
|
226
|
+
component: Group,
|
|
227
|
+
props: {
|
|
228
|
+
icon: CropSquare,
|
|
229
|
+
placeholder: 'placeholders.group',
|
|
230
|
+
treeCollapsible: true,
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
...
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Where:
|
|
239
|
+
|
|
240
|
+
- **mathcer** Function that receives item data and returns true if this configuration is applied to the item
|
|
241
|
+
- **component** React component used for rendering the item in the form editor
|
|
242
|
+
- **props** Additional properties passed to the component
|
|
243
|
+
- **icon** MUI Icon component used for representing the item in tree view
|
|
244
|
+
- **placeholder** Placeholder text identifier shown when item has no title
|
|
245
|
+
- **treeCollapsible** (Group items only) true/false - Allow collapsing/expanding the group in tree view
|
|
246
|
+
|
|
247
|
+
### Valueset property configuration
|
|
248
|
+
|
|
249
|
+
This is for controlling additional metadata properties for value set entries that are stored with form data, but *not communicated to filling side*.
|
|
250
|
+
|
|
251
|
+
For example: `src/defaults/valueSetProps.js`
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
export const DEFAULT_VALUESET_PROPS: ValueSetProp[] = [
|
|
255
|
+
{
|
|
256
|
+
title: 'Custom attribute',
|
|
257
|
+
name: 'attr',
|
|
258
|
+
editor: Box,
|
|
259
|
+
}
|
|
260
|
+
];
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
* `title` Title shown in table column header
|
|
264
|
+
* `attr` attribute name
|
|
265
|
+
* `editor` React component for editing the value
|
|
266
|
+
|
|
267
|
+
Valueset entry metadata prop editor React component template
|
|
268
|
+
```javascript
|
|
269
|
+
const CustomValueSetProp = ({ onChange, value }) => {
|
|
270
|
+
// onChange(value) - callback function for setting the prop's value
|
|
271
|
+
// value - current value of the prop
|
|
272
|
+
|
|
273
|
+
// Return react component here that renders UI for prop editor
|
|
274
|
+
};
|
|
275
|
+
```
|
|
104
276
|
---
|
|
277
|
+
|
|
278
|
+
### Customixing Markdown components
|
|
279
|
+
|
|
280
|
+
You can customize how markdown is rendered by passing custom components to the `Markdown` component from `react-markdown`.
|
|
281
|
+
|
|
282
|
+
List of available components can be found in [`src/defaults/markdown.tsx`](https://github.com/dialob/dialob-parent/blob/dev/frontend/dialob-composer-material/src/defaults/markdown.tsx). See also [`src/components/editors/LocalizedStringEditor.tsx`](https://github.com/dialob/dialob-parent/blob/dev/frontend/dialob-composer-material/src/components/editors/LocalizedStringEditor.tsx) for an example of how to use custom components. To support table rendering, you also need to include the `remark-gfm` plugin.
|
|
283
|
+
|
|
284
|
+
The same components can be used on the filling side as well, so that the markdown looks the same when editing and when filling the form.
|
package/dist-lib/index.d.ts
CHANGED
|
@@ -653,6 +653,8 @@ export declare const useEditor: () => {
|
|
|
653
653
|
setActiveList: (listId?: string) => void;
|
|
654
654
|
setActiveVariableTab: (tab?: VariableTabType) => void;
|
|
655
655
|
setConfirmationActiveItem: (item?: DialobItem) => void;
|
|
656
|
+
toggleItemCollapsed: (itemId: string) => void;
|
|
657
|
+
setMarkdownHelpDialogOpen: (open: boolean) => void;
|
|
656
658
|
};
|
|
657
659
|
|
|
658
660
|
declare const useErrorColor: (error: EditorError | undefined) => string | undefined;
|