@gisce/ooui 2.38.0 → 2.40.0-alpha.1
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 +2 -0
- package/dist/Card.d.ts +18 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/Kanban.d.ts +80 -0
- package/dist/Kanban.d.ts.map +1 -0
- package/dist/WidgetFactory.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ooui.es.js +1194 -1007
- package/dist/ooui.es.js.map +1 -1
- package/package.json +1 -1
- package/src/Card.ts +52 -0
- package/src/Kanban.ts +285 -0
- package/src/WidgetFactory.ts +5 -0
- package/src/index.ts +4 -0
- package/src/spec/Card.spec.ts +89 -0
- package/src/spec/Kanban.spec.ts +364 -0
package/package.json
CHANGED
package/src/Card.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Spinner from "./Spinner";
|
|
2
|
+
|
|
3
|
+
class Card extends Spinner {
|
|
4
|
+
_title: string | null = null;
|
|
5
|
+
get title(): string | null {
|
|
6
|
+
return this._title;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
set title(value: string | null) {
|
|
10
|
+
this._title = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_icon: string | null = null;
|
|
14
|
+
get icon(): string | null {
|
|
15
|
+
return this._icon;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
set icon(value: string | null) {
|
|
19
|
+
this._icon = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Height of the card component
|
|
24
|
+
*/
|
|
25
|
+
_height: number | undefined = undefined;
|
|
26
|
+
|
|
27
|
+
get height(): number | undefined {
|
|
28
|
+
return this._height;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
set height(value: number | undefined) {
|
|
32
|
+
this._height = value;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor(props: any) {
|
|
36
|
+
super(props);
|
|
37
|
+
if (props) {
|
|
38
|
+
if (props.title) {
|
|
39
|
+
this._title = props.title;
|
|
40
|
+
}
|
|
41
|
+
if (props.icon) {
|
|
42
|
+
this._icon = props.icon;
|
|
43
|
+
}
|
|
44
|
+
if (props.height) {
|
|
45
|
+
const parsedHeight = parseInt(props.height);
|
|
46
|
+
this._height = isNaN(parsedHeight) ? undefined : parsedHeight;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default Card;
|
package/src/Kanban.ts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import WidgetFactory from "./WidgetFactory";
|
|
2
|
+
import Widget from "./Widget";
|
|
3
|
+
import Button from "./Button";
|
|
4
|
+
import { replaceEntities } from "./helpers/attributeParser";
|
|
5
|
+
import { parseBoolAttribute, ParsedNode } from "./helpers/nodeParser";
|
|
6
|
+
import * as txml from "txml";
|
|
7
|
+
import { parseContext } from "./helpers/contextParser";
|
|
8
|
+
|
|
9
|
+
export type KanbanField = Widget & {
|
|
10
|
+
sum?: string; // Aggregation label (e.g., "Total hours")
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type KanbanButton = Button & {
|
|
14
|
+
states?: string; // Comma-separated states where button should show
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
class Kanban {
|
|
18
|
+
/**
|
|
19
|
+
* Object containing fields specification of the kanban.
|
|
20
|
+
*/
|
|
21
|
+
_fields: any;
|
|
22
|
+
get fields() {
|
|
23
|
+
return this._fields;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Array of field widgets to display in cards
|
|
28
|
+
*/
|
|
29
|
+
_card_fields: KanbanField[] = [];
|
|
30
|
+
get card_fields(): KanbanField[] {
|
|
31
|
+
return this._card_fields;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Array of button widgets to display in cards
|
|
36
|
+
*/
|
|
37
|
+
_buttons: KanbanButton[] = [];
|
|
38
|
+
get buttons(): KanbanButton[] {
|
|
39
|
+
return this._buttons;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_string: string | null = null;
|
|
43
|
+
get string(): string | null {
|
|
44
|
+
return this._string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Widget type
|
|
49
|
+
*/
|
|
50
|
+
_type: string = "kanban";
|
|
51
|
+
get type(): string {
|
|
52
|
+
return this._type;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Field that defines the columns (e.g., "state")
|
|
57
|
+
*/
|
|
58
|
+
_column_field: string | null = null;
|
|
59
|
+
get column_field(): string | null {
|
|
60
|
+
return this._column_field;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Enable dragging cards between columns
|
|
65
|
+
*/
|
|
66
|
+
_drag: boolean = true;
|
|
67
|
+
get drag(): boolean {
|
|
68
|
+
return this._drag;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Enable sorting cards within columns
|
|
73
|
+
*/
|
|
74
|
+
_sort: boolean = true;
|
|
75
|
+
get sort(): boolean {
|
|
76
|
+
return this._sort;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Enable setting max cards per column (WIP limits)
|
|
81
|
+
*/
|
|
82
|
+
_set_max_cards: boolean = false;
|
|
83
|
+
get set_max_cards(): boolean {
|
|
84
|
+
return this._set_max_cards;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Color expression value (e.g., "blue:state=='draft';green:state=='done'")
|
|
89
|
+
*/
|
|
90
|
+
_colors: string | null = null;
|
|
91
|
+
get colors(): string | null {
|
|
92
|
+
return this._colors;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Context for each field in the kanban
|
|
97
|
+
*/
|
|
98
|
+
_contextForFields: Record<string, any> = {};
|
|
99
|
+
get contextForFields(): Record<string, any> {
|
|
100
|
+
return this._contextForFields;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
set contextForFields(value: Record<string, any>) {
|
|
104
|
+
this._contextForFields = value;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Map of fields that have sum aggregation
|
|
109
|
+
* Key: field name, Value: sum label (e.g., "Total hours")
|
|
110
|
+
*/
|
|
111
|
+
_aggregations: Record<string, string> = {};
|
|
112
|
+
get aggregations(): Record<string, string> {
|
|
113
|
+
return this._aggregations;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
constructor(fields: Object) {
|
|
117
|
+
this._fields = fields;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
parse(xml: string) {
|
|
121
|
+
const view = txml
|
|
122
|
+
.parse(xml)
|
|
123
|
+
.filter((el: ParsedNode) => el.tagName === "kanban")[0];
|
|
124
|
+
|
|
125
|
+
// Parse kanban attributes
|
|
126
|
+
this._string = view.attributes.string || null;
|
|
127
|
+
if (this._string) {
|
|
128
|
+
this._string = replaceEntities(this._string);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
this._column_field = view.attributes.column_field || null;
|
|
132
|
+
if (!this._column_field) {
|
|
133
|
+
throw new Error("Kanban view must have a column_field attribute");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this._drag =
|
|
137
|
+
view.attributes.drag !== undefined
|
|
138
|
+
? parseBoolAttribute(view.attributes.drag)
|
|
139
|
+
: true;
|
|
140
|
+
this._sort =
|
|
141
|
+
view.attributes.sort !== undefined
|
|
142
|
+
? parseBoolAttribute(view.attributes.sort)
|
|
143
|
+
: true;
|
|
144
|
+
this._set_max_cards =
|
|
145
|
+
view.attributes.set_max_cards !== undefined
|
|
146
|
+
? parseBoolAttribute(view.attributes.set_max_cards)
|
|
147
|
+
: false;
|
|
148
|
+
|
|
149
|
+
this._colors = view.attributes.colors || null;
|
|
150
|
+
if (this._colors) {
|
|
151
|
+
this._colors = replaceEntities(this._colors);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const widgetFactory = new WidgetFactory();
|
|
155
|
+
|
|
156
|
+
// Parse children (fields and buttons)
|
|
157
|
+
view.children.forEach((element: ParsedNode) => {
|
|
158
|
+
const { tagName, attributes } = element;
|
|
159
|
+
|
|
160
|
+
if (tagName === "field") {
|
|
161
|
+
this._parseField(element, attributes, widgetFactory);
|
|
162
|
+
} else if (tagName === "button") {
|
|
163
|
+
this._parseButton(element, attributes);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private _parseField(
|
|
169
|
+
_element: ParsedNode,
|
|
170
|
+
attributes: any,
|
|
171
|
+
widgetFactory: WidgetFactory,
|
|
172
|
+
) {
|
|
173
|
+
const { name, widget, sum } = attributes;
|
|
174
|
+
|
|
175
|
+
if (!name) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!this._fields[name]) {
|
|
180
|
+
throw new Error(`Field ${name} doesn't exist in fields definition`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const fieldDef = this._fields[name];
|
|
184
|
+
let widgetType = fieldDef.type;
|
|
185
|
+
|
|
186
|
+
// Handle domain override
|
|
187
|
+
if (
|
|
188
|
+
((Array.isArray(fieldDef?.domain) && fieldDef?.domain.length === 0) ||
|
|
189
|
+
fieldDef?.domain === false) &&
|
|
190
|
+
attributes.domain &&
|
|
191
|
+
attributes.domain.length > 0
|
|
192
|
+
) {
|
|
193
|
+
delete fieldDef.domain;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Parse context
|
|
197
|
+
const widgetContext = parseContext({
|
|
198
|
+
context: attributes.context || fieldDef.context,
|
|
199
|
+
values: {},
|
|
200
|
+
fields: this._fields,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const mergedAttrs = {
|
|
204
|
+
...fieldDef,
|
|
205
|
+
...attributes,
|
|
206
|
+
fieldsWidgetType: fieldDef?.type,
|
|
207
|
+
context: widgetContext,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
this._contextForFields[name] = widgetContext;
|
|
211
|
+
|
|
212
|
+
// Override widget type if specified
|
|
213
|
+
if (widget) {
|
|
214
|
+
widgetType = widget;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Create the widget
|
|
218
|
+
if (!mergedAttrs.invisible) {
|
|
219
|
+
const fieldWidget = widgetFactory.createWidget(
|
|
220
|
+
widgetType,
|
|
221
|
+
mergedAttrs,
|
|
222
|
+
) as KanbanField;
|
|
223
|
+
|
|
224
|
+
// Handle aggregation (sum)
|
|
225
|
+
if (sum) {
|
|
226
|
+
fieldWidget.sum = replaceEntities(sum);
|
|
227
|
+
this._aggregations[name] = replaceEntities(sum);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
this._card_fields.push(fieldWidget);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private _parseButton(_element: ParsedNode, attributes: any) {
|
|
235
|
+
const { name, type, string, states } = attributes;
|
|
236
|
+
|
|
237
|
+
if (!name) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const buttonProps = {
|
|
242
|
+
...attributes,
|
|
243
|
+
name,
|
|
244
|
+
buttonType: type || "object",
|
|
245
|
+
string: string || "",
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const button = new Button(buttonProps) as KanbanButton;
|
|
249
|
+
|
|
250
|
+
// Parse states attribute (e.g., "draft,open")
|
|
251
|
+
if (states) {
|
|
252
|
+
button.states = states;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this._buttons.push(button);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Find the widgets matching with param id
|
|
260
|
+
* @param {string} id id to find
|
|
261
|
+
*/
|
|
262
|
+
findById(id: string): Widget | null {
|
|
263
|
+
const foundField = this._card_fields.find((item) => {
|
|
264
|
+
if (item.findById) {
|
|
265
|
+
return item.findById(id);
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if (foundField) {
|
|
271
|
+
return foundField;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const foundButton = this._buttons.find((item) => {
|
|
275
|
+
if (item.findById) {
|
|
276
|
+
return item.findById(id);
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return foundButton || null;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export default Kanban;
|
package/src/WidgetFactory.ts
CHANGED
|
@@ -45,6 +45,7 @@ import Spinner from "./Spinner";
|
|
|
45
45
|
import Carousel from "./Carousel";
|
|
46
46
|
import ColorPicker from "./ColorPicker";
|
|
47
47
|
import QRCode from "./QRCode";
|
|
48
|
+
import Card from "./Card";
|
|
48
49
|
|
|
49
50
|
class WidgetFactory {
|
|
50
51
|
/**
|
|
@@ -63,6 +64,9 @@ class WidgetFactory {
|
|
|
63
64
|
case "group":
|
|
64
65
|
this._widgetClass = Group;
|
|
65
66
|
break;
|
|
67
|
+
case "card":
|
|
68
|
+
this._widgetClass = Card;
|
|
69
|
+
break;
|
|
66
70
|
case "label":
|
|
67
71
|
this._widgetClass = Label;
|
|
68
72
|
break;
|
|
@@ -227,6 +231,7 @@ class WidgetFactory {
|
|
|
227
231
|
case "notebook":
|
|
228
232
|
case "page":
|
|
229
233
|
case "group":
|
|
234
|
+
case "card":
|
|
230
235
|
return new this._widgetClass({ ...props, type: finalType });
|
|
231
236
|
case "button":
|
|
232
237
|
return new this._widgetClass({
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Avatar from "./Avatar";
|
|
2
2
|
import Form from "./Form";
|
|
3
3
|
import Tree from "./Tree";
|
|
4
|
+
import Kanban from "./Kanban";
|
|
4
5
|
import Char from "./Char";
|
|
5
6
|
import Container from "./Container";
|
|
6
7
|
import ContainerWidget from "./ContainerWidget";
|
|
@@ -57,6 +58,7 @@ import Spinner from "./Spinner";
|
|
|
57
58
|
import Carousel from "./Carousel";
|
|
58
59
|
import ColorPicker from "./ColorPicker";
|
|
59
60
|
import QRCode from "./QRCode";
|
|
61
|
+
import Card from "./Card";
|
|
60
62
|
|
|
61
63
|
import {
|
|
62
64
|
Graph,
|
|
@@ -85,6 +87,7 @@ export {
|
|
|
85
87
|
Widget,
|
|
86
88
|
Form,
|
|
87
89
|
Tree,
|
|
90
|
+
Kanban,
|
|
88
91
|
NewLine,
|
|
89
92
|
Boolean,
|
|
90
93
|
One2many,
|
|
@@ -150,4 +153,5 @@ export {
|
|
|
150
153
|
Carousel,
|
|
151
154
|
ColorPicker,
|
|
152
155
|
QRCode,
|
|
156
|
+
Card,
|
|
153
157
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import Card from "../Card";
|
|
2
|
+
import WidgetImpl from "./fixtures/WidgetImpl";
|
|
3
|
+
import WidgetFactory from "../WidgetFactory";
|
|
4
|
+
import { it, expect, describe } from "vitest";
|
|
5
|
+
|
|
6
|
+
describe("A Card", () => {
|
|
7
|
+
it("should be constructed with 4 columns and a colspan of 4", () => {
|
|
8
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
9
|
+
expect(card4.colspan).toBe(4);
|
|
10
|
+
expect(card4.container.columns).toBe(4);
|
|
11
|
+
});
|
|
12
|
+
it("should be constructed with 6 columns and a colspan of 2", () => {
|
|
13
|
+
const card4 = new Card({ col: 6, colspan: 2 });
|
|
14
|
+
expect(card4.colspan).toBe(2);
|
|
15
|
+
expect(card4.container.columns).toBe(6);
|
|
16
|
+
});
|
|
17
|
+
it("should have 1 rows if 4 items", () => {
|
|
18
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
19
|
+
card4.container.addWidget(new WidgetImpl({ name: "1" }));
|
|
20
|
+
card4.container.addWidget(new WidgetImpl({ name: "2" }));
|
|
21
|
+
card4.container.addWidget(new WidgetImpl({ name: "3" }));
|
|
22
|
+
card4.container.addWidget(new WidgetImpl({ name: "4" }));
|
|
23
|
+
expect(card4.container.rows.length).toBe(1);
|
|
24
|
+
});
|
|
25
|
+
it("should have 2 rows if 5 items", () => {
|
|
26
|
+
const card4 = new Card({ col: 4, colspan: 4 });
|
|
27
|
+
card4.container.addWidget(new WidgetImpl({ name: "1" }));
|
|
28
|
+
card4.container.addWidget(new WidgetImpl({ name: "2" }));
|
|
29
|
+
card4.container.addWidget(new WidgetImpl({ name: "3" }));
|
|
30
|
+
card4.container.addWidget(new WidgetImpl({ name: "4" }));
|
|
31
|
+
card4.container.addWidget(new WidgetImpl({ name: "5" }));
|
|
32
|
+
expect(card4.container.rows.length).toBe(2);
|
|
33
|
+
});
|
|
34
|
+
it("can have an icon property", () => {
|
|
35
|
+
const widgetFactory = new WidgetFactory();
|
|
36
|
+
const props = {
|
|
37
|
+
title: "General",
|
|
38
|
+
icon: "home",
|
|
39
|
+
};
|
|
40
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
41
|
+
expect(widget.icon).toEqual("home");
|
|
42
|
+
});
|
|
43
|
+
it("can have a title property", () => {
|
|
44
|
+
const widgetFactory = new WidgetFactory();
|
|
45
|
+
const props = {
|
|
46
|
+
title: "Card Title",
|
|
47
|
+
icon: "user",
|
|
48
|
+
};
|
|
49
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
50
|
+
expect(widget.title).toEqual("Card Title");
|
|
51
|
+
});
|
|
52
|
+
it("can have a height property", () => {
|
|
53
|
+
const widgetFactory = new WidgetFactory();
|
|
54
|
+
const props = {
|
|
55
|
+
title: "Card Title",
|
|
56
|
+
height: "200",
|
|
57
|
+
};
|
|
58
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
59
|
+
expect(widget.height).toEqual(200);
|
|
60
|
+
});
|
|
61
|
+
it("should handle invalid height values", () => {
|
|
62
|
+
const widgetFactory = new WidgetFactory();
|
|
63
|
+
const props = {
|
|
64
|
+
title: "Card Title",
|
|
65
|
+
height: "invalid",
|
|
66
|
+
};
|
|
67
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
68
|
+
expect(widget.height).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
describe("working as a spinner", () => {
|
|
71
|
+
it("should be loading false as default", () => {
|
|
72
|
+
const widgetFactory = new WidgetFactory();
|
|
73
|
+
const props = {
|
|
74
|
+
title: "A card",
|
|
75
|
+
};
|
|
76
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
77
|
+
expect(widget.loading).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
it("should be loading true if set", () => {
|
|
80
|
+
const widgetFactory = new WidgetFactory();
|
|
81
|
+
const props = {
|
|
82
|
+
title: "A card",
|
|
83
|
+
loading: true,
|
|
84
|
+
};
|
|
85
|
+
const widget = widgetFactory.createWidget("card", props);
|
|
86
|
+
expect(widget.loading).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|