@gisce/ooui 2.23.0-alpha.1 → 2.23.0-alpha.2
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/dist/Field.d.ts +2 -0
- package/dist/Field.d.ts.map +1 -1
- package/dist/Form.d.ts.map +1 -1
- package/dist/Widget.d.ts.map +1 -1
- package/dist/helpers/attributeParser.d.ts +1 -0
- package/dist/helpers/attributeParser.d.ts.map +1 -1
- package/dist/ooui.es.js +269 -262
- package/dist/ooui.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Field.ts +8 -0
- package/src/Form.ts +10 -1
- package/src/Widget.ts +2 -12
- package/src/helpers/attributeParser.ts +16 -0
- package/src/spec/Form.spec.ts +30 -0
package/package.json
CHANGED
package/src/Field.ts
CHANGED
|
@@ -106,6 +106,14 @@ class Field extends Widget {
|
|
|
106
106
|
this._sum = value;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
get suffix(): string {
|
|
110
|
+
return this._parsedWidgetProps.suffix || "";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get prefix(): string {
|
|
114
|
+
return this._parsedWidgetProps.prefix || "";
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
/**
|
|
110
118
|
* Values and keys
|
|
111
119
|
*/
|
package/src/Form.ts
CHANGED
|
@@ -3,7 +3,11 @@ import Container from "./Container";
|
|
|
3
3
|
import ContainerWidget from "./ContainerWidget";
|
|
4
4
|
import Widget from "./Widget";
|
|
5
5
|
import { ParsedNode } from "./helpers/nodeParser";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
evaluateAttributes,
|
|
8
|
+
replaceEntities,
|
|
9
|
+
parseWidgetProps,
|
|
10
|
+
} from "./helpers/attributeParser";
|
|
7
11
|
import { evaluateStates, evaluateButtonStates } from "./helpers/stateParser";
|
|
8
12
|
import { parseContext } from "./helpers/contextParser";
|
|
9
13
|
import { parseOnChange } from "./helpers/onChangeParser";
|
|
@@ -208,6 +212,11 @@ class Form {
|
|
|
208
212
|
);
|
|
209
213
|
}
|
|
210
214
|
widgetType = this._fields[name].type;
|
|
215
|
+
// Merge _fields[widget_props] with attributes[widget_props]
|
|
216
|
+
attributes.widget_props = {
|
|
217
|
+
...parseWidgetProps(attributes.widget_props),
|
|
218
|
+
...(this._fields[name].widget_props || {}),
|
|
219
|
+
};
|
|
211
220
|
}
|
|
212
221
|
tagAttributes = {
|
|
213
222
|
...this._fields[name],
|
package/src/Widget.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { replaceEntities } from "./helpers/attributeParser";
|
|
1
|
+
import { replaceEntities, parseWidgetProps } from "./helpers/attributeParser";
|
|
2
2
|
import { parseBoolAttribute } from "./helpers/nodeParser";
|
|
3
3
|
|
|
4
4
|
abstract class Widget {
|
|
@@ -161,17 +161,7 @@ abstract class Widget {
|
|
|
161
161
|
this._fieldType = props.fieldsWidgetType;
|
|
162
162
|
}
|
|
163
163
|
if (props.widget_props) {
|
|
164
|
-
|
|
165
|
-
try {
|
|
166
|
-
this._parsedWidgetProps = JSON.parse(
|
|
167
|
-
props.widget_props.replace(/'/g, '"'),
|
|
168
|
-
);
|
|
169
|
-
} catch (err) {
|
|
170
|
-
console.error("Error parsing widget_props");
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
this._parsedWidgetProps = props.widget_props;
|
|
174
|
-
}
|
|
164
|
+
this._parsedWidgetProps = parseWidgetProps(props.widget_props);
|
|
175
165
|
}
|
|
176
166
|
if (props.key) {
|
|
177
167
|
this._key = props.key;
|
|
@@ -184,6 +184,22 @@ const parseAttributes = ({
|
|
|
184
184
|
return newAttributes;
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
+
export const parseWidgetProps = (widget_props: string | object): object => {
|
|
188
|
+
if (widget_props === undefined) {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
191
|
+
if (typeof widget_props === "string") {
|
|
192
|
+
try {
|
|
193
|
+
return JSON.parse(widget_props.replace(/'/g, '"'));
|
|
194
|
+
} catch (err) {
|
|
195
|
+
console.error("Error parsing widget_props");
|
|
196
|
+
return {};
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
return widget_props;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
187
203
|
export const parseJsonAttributes = ({
|
|
188
204
|
attrs,
|
|
189
205
|
values,
|
package/src/spec/Form.spec.ts
CHANGED
|
@@ -6065,4 +6065,34 @@ describe("A Form", () => {
|
|
|
6065
6065
|
expect(form.autorefreshableFields.length).toBe(1);
|
|
6066
6066
|
expect(form.autorefreshableFields[0]).toBe("field_char");
|
|
6067
6067
|
});
|
|
6068
|
+
describe("If the field has widget_props", () => {
|
|
6069
|
+
it("should merge widget_props from fields definition and xml", () => {
|
|
6070
|
+
const fields = {
|
|
6071
|
+
field_integer: {
|
|
6072
|
+
readonly: 1,
|
|
6073
|
+
string: "Power",
|
|
6074
|
+
type: "integer",
|
|
6075
|
+
widget_props: {
|
|
6076
|
+
suffix: "kW",
|
|
6077
|
+
},
|
|
6078
|
+
},
|
|
6079
|
+
};
|
|
6080
|
+
|
|
6081
|
+
const xmlViewForm = `<?xml version="1.0"?>
|
|
6082
|
+
<form string="Form1">
|
|
6083
|
+
<field name="field_integer" widget_props="{'prefix': 'Wow'}" />
|
|
6084
|
+
</form>`;
|
|
6085
|
+
|
|
6086
|
+
const form = new Form(fields);
|
|
6087
|
+
form.parse(xmlViewForm, {
|
|
6088
|
+
values: {
|
|
6089
|
+
field_integer: 10,
|
|
6090
|
+
},
|
|
6091
|
+
});
|
|
6092
|
+
const field = form.findById("field_integer") as Field;
|
|
6093
|
+
expect(field).toBeDefined();
|
|
6094
|
+
expect(field.suffix).toBe("kW");
|
|
6095
|
+
expect(field.prefix).toBe("Wow");
|
|
6096
|
+
});
|
|
6097
|
+
});
|
|
6068
6098
|
});
|