swoop-common 2.2.83 → 2.2.88
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 +225 -225
- package/dist/rendering/prebuild/generated/import_generated.d.ts +1 -0
- package/dist/rendering/prebuild/generated/import_generated.js +1 -0
- package/dist/rendering/renderers/testComponent/TestCompForm.d.ts +1 -0
- package/dist/rendering/renderers/testComponent/TestCompForm.js +38 -0
- package/dist/rendering/type_registration/register.js +12 -11
- package/package.json +68 -66
package/README.md
CHANGED
|
@@ -1,225 +1,225 @@
|
|
|
1
|
-
.# Swoop Library
|
|
2
|
-
|
|
3
|
-
This library is used for rendering **Swoop itinerary templates**.
|
|
4
|
-
It provides tools for defining **custom field types**, registering **custom components**,
|
|
5
|
-
rendering templates from a **MasterSchema**, and includes SDKs for all related services.
|
|
6
|
-
It supports both input mode (for creating templates) and presentation mode (for rendering them for end users).
|
|
7
|
-
The schema system is stage-aware, enabling precise control over what data is editable or displayed at which stage.
|
|
8
|
-
|
|
9
|
-
> Note: This package is intended for internal use only.
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
# Swoop Library
|
|
14
|
-
|
|
15
|
-
## Initialization
|
|
16
|
-
|
|
17
|
-
Before using the Swoop Library, you must initialize it with service URLs:
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
import { init } from "swoop-common";
|
|
21
|
-
|
|
22
|
-
init({
|
|
23
|
-
coreServiceUrl: "https://your.core.service",
|
|
24
|
-
swoopServiceForwardUrl: "https://your.forward.service",
|
|
25
|
-
});
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Service Interfaces
|
|
29
|
-
|
|
30
|
-
The library provides three primary service interfaces to interact with backend systems:
|
|
31
|
-
|
|
32
|
-
- **SwoopService** — Interfaces with the Swoop API.
|
|
33
|
-
- **CoreService** — For core service.
|
|
34
|
-
|
|
35
|
-
These interfaces offer convenient methods to work seamlessly with the underlying services required by the itinerary system.
|
|
36
|
-
|
|
37
|
-
## StyledFormView
|
|
38
|
-
|
|
39
|
-
The `StyledFormView` component is the entry point for rendering a full itinerary template. It handles schema parsing and renderer injection based on mode and form stage.
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
import { StyledFormView } from "your-form-library";
|
|
43
|
-
|
|
44
|
-
<StyledFormView
|
|
45
|
-
initialData={/* object */}
|
|
46
|
-
schema={/* MasterSchema */}
|
|
47
|
-
onChange={(val) => console.log(val)}
|
|
48
|
-
pool="FORM"
|
|
49
|
-
readonly={false}
|
|
50
|
-
stage="Inst"
|
|
51
|
-
/>;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Props
|
|
55
|
-
|
|
56
|
-
| Name | Type | Description |
|
|
57
|
-
| ----------- | -------------------- | ------------------------------------------------------------------ |
|
|
58
|
-
| initialData | `any` | Initial values for the template. Should not be updated frequently. |
|
|
59
|
-
| schema | `MasterSchema` | Template definition object. |
|
|
60
|
-
| onChange | `(val: any) => void` | Callback with updated data. |
|
|
61
|
-
| pool | `ComponentPool` | `"FORM"` or `"PRESENTATION"` depending on context. |
|
|
62
|
-
| readonly | `boolean` | Disables inputs if true (only relevant in FORM pool). |
|
|
63
|
-
| stage | `Stage` | Controls which data segment is being rendered. |
|
|
64
|
-
|
|
65
|
-
### Stages
|
|
66
|
-
|
|
67
|
-
The template system is divided into stages:
|
|
68
|
-
|
|
69
|
-
- **Stage.Comp** – Data stored on the root component, often static (e.g. metadata, titles). Does not include any dynamic or time-based fields.
|
|
70
|
-
- **Stage.Inst** – Instance-specific data (e.g. timings, localized notes). This is the most common stage for editable fields.
|
|
71
|
-
- **Stage.User** – Data unique to individual users (e.g. room number).
|
|
72
|
-
|
|
73
|
-
Each stage builds on the one before it. For example, `Stage.User` includes everything from `Stage.Comp` and `Stage.Inst`. Fields are editable based on the current stage. If a value is defined in two stages, the lower stage will take priority.
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## Custom Components
|
|
78
|
-
|
|
79
|
-
Custom components define how individual fields render. These can behave like typical form inputs or be used for display-only formatting in the `PRESENTATION` pool.
|
|
80
|
-
|
|
81
|
-
### Example
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
const FormExample: React.FC<Props> = ({
|
|
85
|
-
text,
|
|
86
|
-
onChange,
|
|
87
|
-
getError,
|
|
88
|
-
label,
|
|
89
|
-
enabled,
|
|
90
|
-
}) => {
|
|
91
|
-
const [val, setVal] = useState(text);
|
|
92
|
-
const error = getError ? getError("example")?.message : undefined;
|
|
93
|
-
const onChangeDebounced = useMemo(() => debounce(onChange, 300), [onChange]);
|
|
94
|
-
|
|
95
|
-
const update = (value: string) => {
|
|
96
|
-
setVal(value);
|
|
97
|
-
onChangeDebounced(value);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<Paper
|
|
102
|
-
sx={{
|
|
103
|
-
display: "flex",
|
|
104
|
-
flexDirection: "column",
|
|
105
|
-
gap: 1,
|
|
106
|
-
p: 2,
|
|
107
|
-
background: "#CBC3E3",
|
|
108
|
-
mb: 1,
|
|
109
|
-
}}
|
|
110
|
-
>
|
|
111
|
-
{!enabled && "THIS IS DISABLED"}
|
|
112
|
-
<Typography variant="h6">{label}</Typography>
|
|
113
|
-
<TextField
|
|
114
|
-
label="Example label"
|
|
115
|
-
value={val}
|
|
116
|
-
onChange={(e) => update(e.target.value)}
|
|
117
|
-
error={!!error}
|
|
118
|
-
helperText={error}
|
|
119
|
-
disabled={!enabled}
|
|
120
|
-
/>
|
|
121
|
-
</Paper>
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const FormRendererExample: React.FC<ControlProps> = ({
|
|
126
|
-
data,
|
|
127
|
-
handleChange,
|
|
128
|
-
path,
|
|
129
|
-
label,
|
|
130
|
-
enabled,
|
|
131
|
-
}) => {
|
|
132
|
-
const getError = useLocalErrors(path);
|
|
133
|
-
return (
|
|
134
|
-
<FormExample
|
|
135
|
-
text={data as string}
|
|
136
|
-
onChange={(val) => handleChange(path, val)}
|
|
137
|
-
getError={getError}
|
|
138
|
-
label={label}
|
|
139
|
-
enabled={enabled}
|
|
140
|
-
/>
|
|
141
|
-
);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
registerComponent("example", FormRendererExample, ComponentPool.FORM);
|
|
145
|
-
registerComponent("example", FormRendererExample, ComponentPool.PRESENTATION);
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
> Important: You **cannot register two components with the same name within the same pool**. You _can_ register the same component name across different pools (e.g., `"example"` in both `"FORM"` and `"PRESENTATION"`).
|
|
149
|
-
|
|
150
|
-
### Presentation Pool
|
|
151
|
-
|
|
152
|
-
The `PRESENTATION` pool is more than just read-only. It is designed for **customer-facing output**, rendering fields in a clean, non-form-like layout for readability and professionalism.
|
|
153
|
-
|
|
154
|
-
---
|
|
155
|
-
|
|
156
|
-
## Custom Types
|
|
157
|
-
|
|
158
|
-
Custom field types define what kinds of fields can be used when **building a template**. These appear in the template builder UI as selectable field types and control how data is validated and configured.
|
|
159
|
-
|
|
160
|
-
### Syntax
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
registerType(
|
|
164
|
-
"typeId", // Unique type string
|
|
165
|
-
"Display Name", // Name shown in template builder
|
|
166
|
-
schema, // JSON Schema defining the data structure
|
|
167
|
-
optionsSchema, // JSON Schema defining configuration data structure
|
|
168
|
-
requiredOptions // boolean: must the options be filled?
|
|
169
|
-
);
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Example
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
registerType(
|
|
176
|
-
"enum",
|
|
177
|
-
"Dropdown",
|
|
178
|
-
{ type: "array" },
|
|
179
|
-
{
|
|
180
|
-
type: "object",
|
|
181
|
-
title: "Dropdown Options",
|
|
182
|
-
properties: {
|
|
183
|
-
enumValues: {
|
|
184
|
-
title: "Dropdown Values",
|
|
185
|
-
type: "array",
|
|
186
|
-
items: { type: "string" },
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
true
|
|
191
|
-
);
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
This type defines a dropdown field where the values are defined via the `enumValues` property in the template configuration.
|
|
195
|
-
|
|
196
|
-
### Custom Option Editors
|
|
197
|
-
|
|
198
|
-
If you want to render a **custom options block** (i.e., how the field type's options are displayed in the template editor), you must do the following:
|
|
199
|
-
|
|
200
|
-
1. In the top-level `optionsSchema` of the type, define `"x-type": "yourTypeName"`
|
|
201
|
-
2. Create and register a custom component with the name `"yourTypeName"` in the `"FORM"` pool.
|
|
202
|
-
|
|
203
|
-
This component will then be used to render the configuration UI for that field type.
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
## File Locations
|
|
208
|
-
|
|
209
|
-
- **Custom components** must be placed in `src/renderers`. They may be nested within subfolders. All files inside `renderers/` will be automatically imported in the correct order.
|
|
210
|
-
- **Custom types** must be added to `src/default_registration/fields_base.tsx`.
|
|
211
|
-
|
|
212
|
-
No manual import wiring is required beyond placing the file in the correct folder.
|
|
213
|
-
|
|
214
|
-
---
|
|
215
|
-
|
|
216
|
-
## Publishing to NPM
|
|
217
|
-
|
|
218
|
-
To publish a new version of the package:
|
|
219
|
-
|
|
220
|
-
```bash
|
|
221
|
-
npm run build # Compile the package
|
|
222
|
-
npm version patch # Bump the patch version (or use minor/major as needed)
|
|
223
|
-
npm adduser # Log in to NPM (if not already)
|
|
224
|
-
npm publish # Publish the package
|
|
225
|
-
```
|
|
1
|
+
.# Swoop Library
|
|
2
|
+
|
|
3
|
+
This library is used for rendering **Swoop itinerary templates**.
|
|
4
|
+
It provides tools for defining **custom field types**, registering **custom components**,
|
|
5
|
+
rendering templates from a **MasterSchema**, and includes SDKs for all related services.
|
|
6
|
+
It supports both input mode (for creating templates) and presentation mode (for rendering them for end users).
|
|
7
|
+
The schema system is stage-aware, enabling precise control over what data is editable or displayed at which stage.
|
|
8
|
+
|
|
9
|
+
> Note: This package is intended for internal use only.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Swoop Library
|
|
14
|
+
|
|
15
|
+
## Initialization
|
|
16
|
+
|
|
17
|
+
Before using the Swoop Library, you must initialize it with service URLs:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { init } from "swoop-common";
|
|
21
|
+
|
|
22
|
+
init({
|
|
23
|
+
coreServiceUrl: "https://your.core.service",
|
|
24
|
+
swoopServiceForwardUrl: "https://your.forward.service",
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Service Interfaces
|
|
29
|
+
|
|
30
|
+
The library provides three primary service interfaces to interact with backend systems:
|
|
31
|
+
|
|
32
|
+
- **SwoopService** — Interfaces with the Swoop API.
|
|
33
|
+
- **CoreService** — For core service.
|
|
34
|
+
|
|
35
|
+
These interfaces offer convenient methods to work seamlessly with the underlying services required by the itinerary system.
|
|
36
|
+
|
|
37
|
+
## StyledFormView
|
|
38
|
+
|
|
39
|
+
The `StyledFormView` component is the entry point for rendering a full itinerary template. It handles schema parsing and renderer injection based on mode and form stage.
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { StyledFormView } from "your-form-library";
|
|
43
|
+
|
|
44
|
+
<StyledFormView
|
|
45
|
+
initialData={/* object */}
|
|
46
|
+
schema={/* MasterSchema */}
|
|
47
|
+
onChange={(val) => console.log(val)}
|
|
48
|
+
pool="FORM"
|
|
49
|
+
readonly={false}
|
|
50
|
+
stage="Inst"
|
|
51
|
+
/>;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Props
|
|
55
|
+
|
|
56
|
+
| Name | Type | Description |
|
|
57
|
+
| ----------- | -------------------- | ------------------------------------------------------------------ |
|
|
58
|
+
| initialData | `any` | Initial values for the template. Should not be updated frequently. |
|
|
59
|
+
| schema | `MasterSchema` | Template definition object. |
|
|
60
|
+
| onChange | `(val: any) => void` | Callback with updated data. |
|
|
61
|
+
| pool | `ComponentPool` | `"FORM"` or `"PRESENTATION"` depending on context. |
|
|
62
|
+
| readonly | `boolean` | Disables inputs if true (only relevant in FORM pool). |
|
|
63
|
+
| stage | `Stage` | Controls which data segment is being rendered. |
|
|
64
|
+
|
|
65
|
+
### Stages
|
|
66
|
+
|
|
67
|
+
The template system is divided into stages:
|
|
68
|
+
|
|
69
|
+
- **Stage.Comp** – Data stored on the root component, often static (e.g. metadata, titles). Does not include any dynamic or time-based fields.
|
|
70
|
+
- **Stage.Inst** – Instance-specific data (e.g. timings, localized notes). This is the most common stage for editable fields.
|
|
71
|
+
- **Stage.User** – Data unique to individual users (e.g. room number).
|
|
72
|
+
|
|
73
|
+
Each stage builds on the one before it. For example, `Stage.User` includes everything from `Stage.Comp` and `Stage.Inst`. Fields are editable based on the current stage. If a value is defined in two stages, the lower stage will take priority.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Custom Components
|
|
78
|
+
|
|
79
|
+
Custom components define how individual fields render. These can behave like typical form inputs or be used for display-only formatting in the `PRESENTATION` pool.
|
|
80
|
+
|
|
81
|
+
### Example
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
const FormExample: React.FC<Props> = ({
|
|
85
|
+
text,
|
|
86
|
+
onChange,
|
|
87
|
+
getError,
|
|
88
|
+
label,
|
|
89
|
+
enabled,
|
|
90
|
+
}) => {
|
|
91
|
+
const [val, setVal] = useState(text);
|
|
92
|
+
const error = getError ? getError("example")?.message : undefined;
|
|
93
|
+
const onChangeDebounced = useMemo(() => debounce(onChange, 300), [onChange]);
|
|
94
|
+
|
|
95
|
+
const update = (value: string) => {
|
|
96
|
+
setVal(value);
|
|
97
|
+
onChangeDebounced(value);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<Paper
|
|
102
|
+
sx={{
|
|
103
|
+
display: "flex",
|
|
104
|
+
flexDirection: "column",
|
|
105
|
+
gap: 1,
|
|
106
|
+
p: 2,
|
|
107
|
+
background: "#CBC3E3",
|
|
108
|
+
mb: 1,
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
{!enabled && "THIS IS DISABLED"}
|
|
112
|
+
<Typography variant="h6">{label}</Typography>
|
|
113
|
+
<TextField
|
|
114
|
+
label="Example label"
|
|
115
|
+
value={val}
|
|
116
|
+
onChange={(e) => update(e.target.value)}
|
|
117
|
+
error={!!error}
|
|
118
|
+
helperText={error}
|
|
119
|
+
disabled={!enabled}
|
|
120
|
+
/>
|
|
121
|
+
</Paper>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const FormRendererExample: React.FC<ControlProps> = ({
|
|
126
|
+
data,
|
|
127
|
+
handleChange,
|
|
128
|
+
path,
|
|
129
|
+
label,
|
|
130
|
+
enabled,
|
|
131
|
+
}) => {
|
|
132
|
+
const getError = useLocalErrors(path);
|
|
133
|
+
return (
|
|
134
|
+
<FormExample
|
|
135
|
+
text={data as string}
|
|
136
|
+
onChange={(val) => handleChange(path, val)}
|
|
137
|
+
getError={getError}
|
|
138
|
+
label={label}
|
|
139
|
+
enabled={enabled}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
registerComponent("example", FormRendererExample, ComponentPool.FORM);
|
|
145
|
+
registerComponent("example", FormRendererExample, ComponentPool.PRESENTATION);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> Important: You **cannot register two components with the same name within the same pool**. You _can_ register the same component name across different pools (e.g., `"example"` in both `"FORM"` and `"PRESENTATION"`).
|
|
149
|
+
|
|
150
|
+
### Presentation Pool
|
|
151
|
+
|
|
152
|
+
The `PRESENTATION` pool is more than just read-only. It is designed for **customer-facing output**, rendering fields in a clean, non-form-like layout for readability and professionalism.
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Custom Types
|
|
157
|
+
|
|
158
|
+
Custom field types define what kinds of fields can be used when **building a template**. These appear in the template builder UI as selectable field types and control how data is validated and configured.
|
|
159
|
+
|
|
160
|
+
### Syntax
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
registerType(
|
|
164
|
+
"typeId", // Unique type string
|
|
165
|
+
"Display Name", // Name shown in template builder
|
|
166
|
+
schema, // JSON Schema defining the data structure
|
|
167
|
+
optionsSchema, // JSON Schema defining configuration data structure
|
|
168
|
+
requiredOptions // boolean: must the options be filled?
|
|
169
|
+
);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Example
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
registerType(
|
|
176
|
+
"enum",
|
|
177
|
+
"Dropdown",
|
|
178
|
+
{ type: "array" },
|
|
179
|
+
{
|
|
180
|
+
type: "object",
|
|
181
|
+
title: "Dropdown Options",
|
|
182
|
+
properties: {
|
|
183
|
+
enumValues: {
|
|
184
|
+
title: "Dropdown Values",
|
|
185
|
+
type: "array",
|
|
186
|
+
items: { type: "string" },
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
true
|
|
191
|
+
);
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
This type defines a dropdown field where the values are defined via the `enumValues` property in the template configuration.
|
|
195
|
+
|
|
196
|
+
### Custom Option Editors
|
|
197
|
+
|
|
198
|
+
If you want to render a **custom options block** (i.e., how the field type's options are displayed in the template editor), you must do the following:
|
|
199
|
+
|
|
200
|
+
1. In the top-level `optionsSchema` of the type, define `"x-type": "yourTypeName"`
|
|
201
|
+
2. Create and register a custom component with the name `"yourTypeName"` in the `"FORM"` pool.
|
|
202
|
+
|
|
203
|
+
This component will then be used to render the configuration UI for that field type.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## File Locations
|
|
208
|
+
|
|
209
|
+
- **Custom components** must be placed in `src/renderers`. They may be nested within subfolders. All files inside `renderers/` will be automatically imported in the correct order.
|
|
210
|
+
- **Custom types** must be added to `src/default_registration/fields_base.tsx`.
|
|
211
|
+
|
|
212
|
+
No manual import wiring is required beyond placing the file in the correct folder.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
## Publishing to NPM
|
|
217
|
+
|
|
218
|
+
To publish a new version of the package:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
npm run build # Compile the package
|
|
222
|
+
npm version patch # Bump the patch version (or use minor/major as needed)
|
|
223
|
+
npm adduser # Log in to NPM (if not already)
|
|
224
|
+
npm publish # Publish the package
|
|
225
|
+
```
|
|
@@ -8,6 +8,7 @@ import "../../renderers/Image/ImagePresentation";
|
|
|
8
8
|
import "../../renderers/StagedText";
|
|
9
9
|
import "../../renderers/Subset";
|
|
10
10
|
import "../../renderers/TemplatePicker";
|
|
11
|
+
import "../../renderers/testComponent/TestCompForm";
|
|
11
12
|
import "../../renderers/textfield/MultilineForm";
|
|
12
13
|
import "../../renderers/textfield/MultilinePresentation";
|
|
13
14
|
import "../../schema/formBuilders/formBuilderJsonSchema";
|
|
@@ -10,6 +10,7 @@ import "../../renderers/Image/ImagePresentation";
|
|
|
10
10
|
import "../../renderers/StagedText";
|
|
11
11
|
import "../../renderers/Subset";
|
|
12
12
|
import "../../renderers/TemplatePicker";
|
|
13
|
+
import "../../renderers/testComponent/TestCompForm";
|
|
13
14
|
import "../../renderers/textfield/MultilineForm";
|
|
14
15
|
import "../../renderers/textfield/MultilinePresentation";
|
|
15
16
|
// Build template from schema last
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { useMemo, useState } from "react";
|
|
2
|
+
import { debounce, FormControl, InputLabel, MenuItem, Select, } from "@mui/material";
|
|
3
|
+
import Editor from "react-simple-wysiwyg";
|
|
4
|
+
import { useLocalErrors } from "../../hooks/errors";
|
|
5
|
+
import { ComponentPool } from "../../registry/types";
|
|
6
|
+
import { registerComponent } from "../../registry/components";
|
|
7
|
+
const TestCompForm = ({ textValues, onChange, getError, label, enabled, }) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const [values, setValues] = useState(textValues);
|
|
10
|
+
const [key, setKey] = useState(null);
|
|
11
|
+
const error = getError ? (_a = getError("testComp")) === null || _a === void 0 ? void 0 : _a.message : undefined;
|
|
12
|
+
const onChangeDebounced = useMemo(() => debounce(onChange, 300), [onChange]);
|
|
13
|
+
// Update text field value when key selection changes
|
|
14
|
+
const html = key ? ((_b = values[key]) !== null && _b !== void 0 ? _b : "") : "";
|
|
15
|
+
const handleSelectChange = (selectedKey) => {
|
|
16
|
+
setKey(selectedKey);
|
|
17
|
+
};
|
|
18
|
+
const update = (event) => {
|
|
19
|
+
const newValue = event.target.value;
|
|
20
|
+
setValues((prev) => {
|
|
21
|
+
const updated = Object.assign(Object.assign({}, prev), { [key]: newValue });
|
|
22
|
+
onChangeDebounced(updated);
|
|
23
|
+
return updated;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return (React.createElement(FormControl, { className: "p-4 my-2" },
|
|
27
|
+
React.createElement(InputLabel, { id: "note-type-label" }, "Select note type"),
|
|
28
|
+
React.createElement(Select, { fullWidth: true, value: key, onChange: (e) => handleSelectChange(e.target.value), disabled: !enabled, label: "note-type-label" },
|
|
29
|
+
React.createElement(MenuItem, { value: "option1" }, "Option 1"),
|
|
30
|
+
React.createElement(MenuItem, { value: "option2" }, "Option 2"),
|
|
31
|
+
React.createElement(MenuItem, { value: "option3" }, "Option 3")),
|
|
32
|
+
React.createElement(Editor, { className: "border border-red-500 rounded p-2 mt-2", value: html, onChange: (event) => update(event), disabled: !enabled || !key })));
|
|
33
|
+
};
|
|
34
|
+
const FormRendererExample = ({ data, handleChange, path, label, enabled, }) => {
|
|
35
|
+
const getError = useLocalErrors(path);
|
|
36
|
+
return (React.createElement(TestCompForm, { textValues: data, onChange: (addr) => handleChange(path, addr), getError: getError, label: label, enabled: enabled }));
|
|
37
|
+
};
|
|
38
|
+
registerComponent("testComp", FormRendererExample, ComponentPool.FORM);
|
|
@@ -37,8 +37,8 @@ registerType("enum", "Dropdown", { type: "string" }, {
|
|
|
37
37
|
title: "Dropdown Values",
|
|
38
38
|
type: "array",
|
|
39
39
|
items: { type: "string" },
|
|
40
|
-
}
|
|
41
|
-
}
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
42
|
}, true);
|
|
43
43
|
registerType("array", "List", { type: "array" }, {
|
|
44
44
|
type: "object",
|
|
@@ -62,7 +62,7 @@ registerType("stagedEnum", "Staged Dropdown", {
|
|
|
62
62
|
title: "Dropdown Values",
|
|
63
63
|
type: "array",
|
|
64
64
|
items: { type: "string" },
|
|
65
|
-
}
|
|
65
|
+
},
|
|
66
66
|
},
|
|
67
67
|
}, true);
|
|
68
68
|
registerType("object", "Group", { type: "object" }, {
|
|
@@ -106,31 +106,32 @@ registerType("address", "Address", {
|
|
|
106
106
|
properties: {
|
|
107
107
|
line1: {
|
|
108
108
|
type: "string",
|
|
109
|
-
title: "Address Line 1"
|
|
109
|
+
title: "Address Line 1",
|
|
110
110
|
},
|
|
111
111
|
line2: {
|
|
112
112
|
type: "string",
|
|
113
|
-
title: "Address Line 2"
|
|
113
|
+
title: "Address Line 2",
|
|
114
114
|
},
|
|
115
115
|
city: {
|
|
116
116
|
type: "string",
|
|
117
|
-
title: "City"
|
|
117
|
+
title: "City",
|
|
118
118
|
},
|
|
119
119
|
county: {
|
|
120
120
|
type: "string",
|
|
121
|
-
title: "County"
|
|
121
|
+
title: "County",
|
|
122
122
|
},
|
|
123
123
|
postcode: {
|
|
124
124
|
type: "string",
|
|
125
125
|
title: "Postcode",
|
|
126
|
-
pattern: "^[A-Z]{1,2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}$"
|
|
126
|
+
pattern: "^[A-Z]{1,2}[0-9][0-9A-Z]? ?[0-9][A-Z]{2}$",
|
|
127
127
|
},
|
|
128
128
|
number: {
|
|
129
129
|
type: "number",
|
|
130
|
-
title: "Number"
|
|
131
|
-
}
|
|
130
|
+
title: "Number",
|
|
131
|
+
},
|
|
132
132
|
},
|
|
133
|
-
required: ["line1", "city", "postcode"]
|
|
133
|
+
required: ["line1", "city", "postcode"],
|
|
134
134
|
}, {}, false);
|
|
135
135
|
registerType("image", "Image", { type: "string" }, {}, false);
|
|
136
136
|
registerType("multiline", "Multiline", { type: "string" }, {}, false);
|
|
137
|
+
registerType("testComp", "Test Component", { type: "object" }, {}, false);
|
package/package.json
CHANGED
|
@@ -1,66 +1,68 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "swoop-common",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"main": "dist/api/index.js",
|
|
5
|
-
"types": "dist/api/index.d.ts",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/api/index.js",
|
|
9
|
-
"require": "./dist/api/index.js",
|
|
10
|
-
"types": "./dist/api/index.d.ts"
|
|
11
|
-
},
|
|
12
|
-
"./rendering": {
|
|
13
|
-
"import": "./dist/rendering/index.js",
|
|
14
|
-
"require": "./dist/rendering/index.js",
|
|
15
|
-
"types": "./dist/rendering/index.d.ts"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"./rendering": {
|
|
19
|
-
"import": "./dist/rendering/index.js",
|
|
20
|
-
"require": "./dist/rendering/index.js",
|
|
21
|
-
"types": "./dist/rendering/index.d.ts"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
],
|
|
26
|
-
"scripts": {
|
|
27
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
28
|
-
"build": "rimraf ./dist && tsc",
|
|
29
|
-
"build-imports": "tsx ./src/rendering/prebuild/import.ts",
|
|
30
|
-
"generate-swoop-specs": "tsx ./src/api/specsgen.ts",
|
|
31
|
-
"build-core-sdk": "npx openapi-typescript-codegen --input ./openapi/core_service.yaml --output ./src/api/generated/core --client fetch",
|
|
32
|
-
"build-swoop-sdk": "npm run generate-swoop-specs && npx openapi-typescript-codegen --input ./openapi/swoop_service.yaml --output ./src/api/generated/swoop --client fetch --postfixModels Swoop --request ./src/api/templates/request.ts",
|
|
33
|
-
"prebuild": "npm run build-imports && npm run build-sdk",
|
|
34
|
-
"build-sdk-exports": "tsx ./src/api/gen.ts",
|
|
35
|
-
"build-sdk": "npm run build-core-sdk && npm run build-swoop-sdk && npm run build-sdk-exports"
|
|
36
|
-
},
|
|
37
|
-
"author": "",
|
|
38
|
-
"license": "ISC",
|
|
39
|
-
"description": "",
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@apidevtools/swagger-parser": "^12.0.0",
|
|
42
|
-
"@emotion/react": "^11.14.0",
|
|
43
|
-
"@emotion/styled": "^11.14.1",
|
|
44
|
-
"@jsonforms/core": "^3.5.1",
|
|
45
|
-
"@jsonforms/material-renderers": "^3.5.1",
|
|
46
|
-
"@jsonforms/react": "^3.5.1",
|
|
47
|
-
"ajv": "^8.17.1",
|
|
48
|
-
"js-yaml": "^4.1.1",
|
|
49
|
-
"lodash.merge": "^4.6.2",
|
|
50
|
-
"openapi-ts": "^0.3.4",
|
|
51
|
-
"react": "^19.0.0",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@types/
|
|
61
|
-
"@types/
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"typescript": "^
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "swoop-common",
|
|
3
|
+
"version": "2.2.88",
|
|
4
|
+
"main": "dist/api/index.js",
|
|
5
|
+
"types": "dist/api/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/api/index.js",
|
|
9
|
+
"require": "./dist/api/index.js",
|
|
10
|
+
"types": "./dist/api/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./rendering": {
|
|
13
|
+
"import": "./dist/rendering/index.js",
|
|
14
|
+
"require": "./dist/rendering/index.js",
|
|
15
|
+
"types": "./dist/rendering/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./rendering": {
|
|
19
|
+
"import": "./dist/rendering/index.js",
|
|
20
|
+
"require": "./dist/rendering/index.js",
|
|
21
|
+
"types": "./dist/rendering/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
28
|
+
"build": "rimraf ./dist && tsc",
|
|
29
|
+
"build-imports": "tsx ./src/rendering/prebuild/import.ts",
|
|
30
|
+
"generate-swoop-specs": "tsx ./src/api/specsgen.ts",
|
|
31
|
+
"build-core-sdk": "npx openapi-typescript-codegen --input ./openapi/core_service.yaml --output ./src/api/generated/core --client fetch",
|
|
32
|
+
"build-swoop-sdk": "npm run generate-swoop-specs && npx openapi-typescript-codegen --input ./openapi/swoop_service.yaml --output ./src/api/generated/swoop --client fetch --postfixModels Swoop --request ./src/api/templates/request.ts",
|
|
33
|
+
"prebuild": "npm run build-imports && npm run build-sdk",
|
|
34
|
+
"build-sdk-exports": "tsx ./src/api/gen.ts",
|
|
35
|
+
"build-sdk": "npm run build-core-sdk && npm run build-swoop-sdk && npm run build-sdk-exports"
|
|
36
|
+
},
|
|
37
|
+
"author": "",
|
|
38
|
+
"license": "ISC",
|
|
39
|
+
"description": "",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@apidevtools/swagger-parser": "^12.0.0",
|
|
42
|
+
"@emotion/react": "^11.14.0",
|
|
43
|
+
"@emotion/styled": "^11.14.1",
|
|
44
|
+
"@jsonforms/core": "^3.5.1",
|
|
45
|
+
"@jsonforms/material-renderers": "^3.5.1",
|
|
46
|
+
"@jsonforms/react": "^3.5.1",
|
|
47
|
+
"ajv": "^8.17.1",
|
|
48
|
+
"js-yaml": "^4.1.1",
|
|
49
|
+
"lodash.merge": "^4.6.2",
|
|
50
|
+
"openapi-ts": "^0.3.4",
|
|
51
|
+
"react": "^19.0.0",
|
|
52
|
+
"react-simple-wysiwyg": "^3.4.1",
|
|
53
|
+
"rimraf": "^6.0.1",
|
|
54
|
+
"swoop-common": "^2.1.55",
|
|
55
|
+
"tailwindcss": "^4.1.18"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@apidevtools/swagger-cli": "^4.0.4",
|
|
59
|
+
"@hey-api/openapi-ts": "^0.80.2",
|
|
60
|
+
"@types/js-yaml": "^4.0.9",
|
|
61
|
+
"@types/lodash.merge": "^4.6.9",
|
|
62
|
+
"@types/node": "^24.0.14",
|
|
63
|
+
"@types/react": "^19",
|
|
64
|
+
"openapi-typescript-codegen": "^0.29.0",
|
|
65
|
+
"tsx": "^4.20.3",
|
|
66
|
+
"typescript": "^5.8.3"
|
|
67
|
+
}
|
|
68
|
+
}
|