@gisce/ooui 1.0.0-alpha.4 → 1.0.0-alpha.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/dist/Field.d.ts +6 -0
- package/dist/Field.d.ts.map +1 -1
- package/dist/Widget.d.ts +4 -4
- 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 +188 -178
- package/dist/ooui.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Field.ts +17 -1
- package/src/Widget.ts +11 -6
- package/src/helpers/attributeParser.ts +5 -0
- package/src/spec/Form.spec.ts +46 -21
- package/src/spec/Widget.spec.ts +0 -6
- package/src/spec/attributeParser.spec.ts +36 -1
package/package.json
CHANGED
package/src/Field.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Widget from "./Widget";
|
|
2
|
-
import { replaceEntities } from "./helpers/attributeParser";
|
|
2
|
+
import { replaceEntities, isTrue } from "./helpers/attributeParser";
|
|
3
3
|
|
|
4
4
|
class Field extends Widget {
|
|
5
5
|
/**
|
|
@@ -69,6 +69,18 @@ class Field extends Widget {
|
|
|
69
69
|
this._tooltip = value;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Tooltip inline
|
|
74
|
+
*/
|
|
75
|
+
_tooltipInline: boolean = false;
|
|
76
|
+
get tooltipInline(): boolean {
|
|
77
|
+
return this._tooltipInline;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
set tooltipInline(value: boolean) {
|
|
81
|
+
this._tooltipInline = value;
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
/**
|
|
73
85
|
* Activated (default is true)
|
|
74
86
|
*/
|
|
@@ -152,6 +164,10 @@ class Field extends Widget {
|
|
|
152
164
|
if (props.selection) {
|
|
153
165
|
this._selectionValues = new Map(props.selection);
|
|
154
166
|
}
|
|
167
|
+
|
|
168
|
+
if (props.help_inline) {
|
|
169
|
+
this.tooltipInline = isTrue(props.help_inline);
|
|
170
|
+
}
|
|
155
171
|
}
|
|
156
172
|
}
|
|
157
173
|
|
package/src/Widget.ts
CHANGED
|
@@ -12,14 +12,14 @@ abstract class Widget {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Determines if widget is read only (default is
|
|
15
|
+
* Determines if widget is read only (default is undefined)
|
|
16
16
|
*/
|
|
17
|
-
_readOnly: boolean;
|
|
18
|
-
get readOnly(): boolean {
|
|
17
|
+
_readOnly: boolean | undefined;
|
|
18
|
+
get readOnly(): boolean | undefined {
|
|
19
19
|
return this._readOnly;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
set readOnly(value: boolean) {
|
|
22
|
+
set readOnly(value: boolean | undefined) {
|
|
23
23
|
this._readOnly = value;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -106,20 +106,25 @@ abstract class Widget {
|
|
|
106
106
|
|
|
107
107
|
constructor(props?: any) {
|
|
108
108
|
this._colspan = Widget._defaultColspan;
|
|
109
|
-
this._readOnly = false;
|
|
110
109
|
this._invisible = false;
|
|
111
110
|
|
|
112
111
|
if (props) {
|
|
113
112
|
if (props.colspan) {
|
|
114
113
|
this._colspan = +props.colspan;
|
|
115
114
|
}
|
|
116
|
-
if (props.readonly) {
|
|
115
|
+
if (props.readonly !== undefined) {
|
|
117
116
|
if (
|
|
118
117
|
props.readonly === "1" ||
|
|
119
118
|
props.readonly === 1 ||
|
|
120
119
|
props.readonly === true
|
|
121
120
|
) {
|
|
122
121
|
this._readOnly = true;
|
|
122
|
+
} else if (
|
|
123
|
+
props.readonly === "0" ||
|
|
124
|
+
props.readonly === 0 ||
|
|
125
|
+
props.readonly === false
|
|
126
|
+
) {
|
|
127
|
+
this._readOnly = false;
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
if (props.invisible) {
|
package/src/spec/Form.spec.ts
CHANGED
|
@@ -335,29 +335,54 @@ describe("A Form", () => {
|
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
337
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
338
|
+
describe("If field has a help message", () => {
|
|
339
|
+
it("should be able to parse a field with tooltip", () => {
|
|
340
|
+
const fields = {
|
|
341
|
+
char1: {
|
|
342
|
+
size: 128,
|
|
343
|
+
string: "Name",
|
|
344
|
+
type: "char",
|
|
345
|
+
help: "tooltip string",
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
const xmlViewForm = `<?xml version="1.0"?>
|
|
349
|
+
<form string="Form1">
|
|
350
|
+
<group name="group">
|
|
351
|
+
<field colspan="1" name="char1" />
|
|
352
|
+
</group>
|
|
353
|
+
</form>`;
|
|
354
|
+
const form = new Form(fields);
|
|
355
|
+
form.parse(xmlViewForm);
|
|
355
356
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
const field = form.findById("char1") as Char;
|
|
358
|
+
expect(field).not.toBeNull();
|
|
359
|
+
expect(field.tooltip).toBe("tooltip string");
|
|
360
|
+
expect(field.tooltipInline).toBeFalsy();
|
|
361
|
+
});
|
|
362
|
+
it("should be inline if attribute help_inline is set", () => {
|
|
363
|
+
const fields = {
|
|
364
|
+
char1: {
|
|
365
|
+
size: 128,
|
|
366
|
+
string: "Name",
|
|
367
|
+
type: "char",
|
|
368
|
+
help: "tooltip string",
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
const xmlViewForm = `<?xml version="1.0"?>
|
|
372
|
+
<form string="Form1">
|
|
373
|
+
<group name="group">
|
|
374
|
+
<field colspan="1" name="char1" help_inline="1"/>
|
|
375
|
+
</group>
|
|
376
|
+
</form>`;
|
|
377
|
+
const form = new Form(fields);
|
|
378
|
+
form.parse(xmlViewForm);
|
|
360
379
|
|
|
380
|
+
const field = form.findById("char1") as Char;
|
|
381
|
+
expect(field).not.toBeNull();
|
|
382
|
+
expect(field.tooltip).toBe("tooltip string");
|
|
383
|
+
expect(field.tooltipInline).toBeTruthy();
|
|
384
|
+
});
|
|
385
|
+
});
|
|
361
386
|
it("should properly parse a password field", () => {
|
|
362
387
|
const arch =
|
|
363
388
|
'<form><group><field name="password" password="True" readonly="0"/></group></form>';
|
package/src/spec/Widget.spec.ts
CHANGED
|
@@ -21,12 +21,6 @@ describe("A Widget", () => {
|
|
|
21
21
|
expect(widget.colspan).toBe(3);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("should be readOnly false by default", () => {
|
|
25
|
-
const widget = new WidgetImpl();
|
|
26
|
-
|
|
27
|
-
expect(widget.readOnly).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
24
|
it("colspan should be of type Number", () => {
|
|
31
25
|
const widget = new WidgetImpl();
|
|
32
26
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { it, expect, describe } from "vitest";
|
|
2
|
-
import { evaluateAttributes } from "../helpers/attributeParser";
|
|
2
|
+
import { evaluateAttributes, isTrue } from "../helpers/attributeParser";
|
|
3
3
|
|
|
4
4
|
const fields = {
|
|
5
5
|
force_potencia_adscrita: {
|
|
@@ -212,4 +212,39 @@ describe("An Attribute Parser", () => {
|
|
|
212
212
|
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
213
213
|
});
|
|
214
214
|
});
|
|
215
|
+
describe("isTrue method", () => {
|
|
216
|
+
it("should return true when value is 'True'", () => {
|
|
217
|
+
expect(isTrue("True")).toBeTruthy();
|
|
218
|
+
});
|
|
219
|
+
it("should return true when value is 'true'", () => {
|
|
220
|
+
expect(isTrue("true")).toBeTruthy();
|
|
221
|
+
});
|
|
222
|
+
it("should return true when value is true", () => {
|
|
223
|
+
expect(isTrue(true)).toBeTruthy();
|
|
224
|
+
});
|
|
225
|
+
it("should return true when value is '1'", () => {
|
|
226
|
+
expect(isTrue("1")).toBeTruthy();
|
|
227
|
+
});
|
|
228
|
+
it("should return true when value is 1", () => {
|
|
229
|
+
expect(isTrue(1)).toBeTruthy();
|
|
230
|
+
});
|
|
231
|
+
it("should return false when value is 'False'", () => {
|
|
232
|
+
expect(isTrue("False")).toBeFalsy();
|
|
233
|
+
});
|
|
234
|
+
it("should return false when value is 'false'", () => {
|
|
235
|
+
expect(isTrue("false")).toBeFalsy();
|
|
236
|
+
});
|
|
237
|
+
it("should return false when value is false", () => {
|
|
238
|
+
expect(isTrue(false)).toBeFalsy();
|
|
239
|
+
});
|
|
240
|
+
it("should return false when value is '0'", () => {
|
|
241
|
+
expect(isTrue("0")).toBeFalsy();
|
|
242
|
+
});
|
|
243
|
+
it("should return false when value is 0", () => {
|
|
244
|
+
expect(isTrue(0)).toBeFalsy();
|
|
245
|
+
});
|
|
246
|
+
it("should return false when value is undefined", () => {
|
|
247
|
+
expect(isTrue(undefined)).toBeFalsy();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
215
250
|
});
|