@hypericon/mico 0.3.14 → 0.3.16
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.
|
@@ -31,12 +31,16 @@ export declare const Tree: m.Component<{
|
|
|
31
31
|
}) => void) | undefined;
|
|
32
32
|
/** Optional message to display in defined but empty children lists */
|
|
33
33
|
emptyChildrenMessage?: string | undefined;
|
|
34
|
-
/** Optionally override the default icon for a collapsed
|
|
35
|
-
collapsedIcon?: m.Vnode<any,
|
|
36
|
-
/** Optionally override the default icon for an expanded
|
|
37
|
-
expandedIcon?: m.Vnode<any,
|
|
34
|
+
/** Optionally override the default icon for a collapsed node */
|
|
35
|
+
collapsedIcon?: m.Vnode<any, any> | undefined;
|
|
36
|
+
/** Optionally override the default icon for an expanded node */
|
|
37
|
+
expandedIcon?: m.Vnode<any, any> | undefined;
|
|
38
|
+
/** Optionally override the default toggle icon for a node that cannot toggle */
|
|
39
|
+
noToggleIcon?: m.Vnode<any, any> | undefined;
|
|
38
40
|
/** Optionally enable toggling of expansion nodes by clicking their labels */
|
|
39
41
|
toggleExpansionWithLabel?: boolean | undefined;
|
|
42
|
+
/** Optionally override the default nesting width */
|
|
43
|
+
nestingWidth?: string | undefined;
|
|
40
44
|
/** Optional CSS classes to apply to the root div */
|
|
41
45
|
class?: string | undefined;
|
|
42
46
|
/** Optional CSS styles to apply to the root div */
|
|
@@ -80,12 +84,16 @@ export declare function createTree<TNodeData extends object = {}>(): m.Component
|
|
|
80
84
|
}) => void) | undefined;
|
|
81
85
|
/** Optional message to display in defined but empty children lists */
|
|
82
86
|
emptyChildrenMessage?: string | undefined;
|
|
83
|
-
/** Optionally override the default icon for a collapsed
|
|
84
|
-
collapsedIcon?: m.Vnode<any,
|
|
85
|
-
/** Optionally override the default icon for an expanded
|
|
86
|
-
expandedIcon?: m.Vnode<any,
|
|
87
|
+
/** Optionally override the default icon for a collapsed node */
|
|
88
|
+
collapsedIcon?: m.Vnode<any, any> | undefined;
|
|
89
|
+
/** Optionally override the default icon for an expanded node */
|
|
90
|
+
expandedIcon?: m.Vnode<any, any> | undefined;
|
|
91
|
+
/** Optionally override the default toggle icon for a node that cannot toggle */
|
|
92
|
+
noToggleIcon?: m.Vnode<any, any> | undefined;
|
|
87
93
|
/** Optionally enable toggling of expansion nodes by clicking their labels */
|
|
88
94
|
toggleExpansionWithLabel?: boolean | undefined;
|
|
95
|
+
/** Optionally override the default nesting width */
|
|
96
|
+
nestingWidth?: string | undefined;
|
|
89
97
|
/** Optional CSS classes to apply to the root div */
|
|
90
98
|
class?: string | undefined;
|
|
91
99
|
/** Optional CSS styles to apply to the root div */
|
|
@@ -8,6 +8,7 @@ const utils_1 = require("@hypericon/utils");
|
|
|
8
8
|
const mithril_1 = __importDefault(require("mithril"));
|
|
9
9
|
const icon_1 = require("../icon");
|
|
10
10
|
const DATA_TRANSFER_TYPE = "application/tree-data";
|
|
11
|
+
const DEFAULT_NESTING_WIDTH = "1.5rem";
|
|
11
12
|
/**
|
|
12
13
|
* An untyped tree component (see `createTree<T>()`)
|
|
13
14
|
*/
|
|
@@ -47,7 +48,9 @@ function createTree() {
|
|
|
47
48
|
emptyChildrenMessage: attrs.emptyChildrenMessage,
|
|
48
49
|
collapsedIcon: attrs.collapsedIcon,
|
|
49
50
|
expandedIcon: attrs.expandedIcon,
|
|
51
|
+
noToggleIcon: attrs.noToggleIcon,
|
|
50
52
|
toggleExpansionWithLabel: attrs.toggleExpansionWithLabel,
|
|
53
|
+
nestingWidth: attrs.nestingWidth || DEFAULT_NESTING_WIDTH,
|
|
51
54
|
});
|
|
52
55
|
})),
|
|
53
56
|
]);
|
|
@@ -66,6 +69,8 @@ function createTree() {
|
|
|
66
69
|
return;
|
|
67
70
|
if (!ev.dataTransfer)
|
|
68
71
|
return;
|
|
72
|
+
if (node.draggable === false)
|
|
73
|
+
return;
|
|
69
74
|
attrs.enableLogging && console.log(`start dragging`, node.data);
|
|
70
75
|
ev.dataTransfer.setData(DATA_TRANSFER_TYPE, JSON.stringify(node.data));
|
|
71
76
|
ev.dataTransfer.effectAllowed = "move";
|
|
@@ -132,7 +137,7 @@ function createTree() {
|
|
|
132
137
|
style: `display: flex; align-items: stretch; max-width: 100%; overflow-x: hidden; ${(attrs.toggleExpansionWithLabel && enableToggling) ? `cursor: pointer;` : ``}`,
|
|
133
138
|
}, [
|
|
134
139
|
expanded ? (0, mithril_1.default)("button.mico-tree-toggle", {
|
|
135
|
-
style: `width:
|
|
140
|
+
style: `width: ${attrs.nestingWidth}; flex: none;`,
|
|
136
141
|
// class: enableToggling ? `hover:text-primary` : `text-view-icon`,
|
|
137
142
|
disabled: !enableToggling,
|
|
138
143
|
onclick: (ev) => {
|
|
@@ -144,7 +149,7 @@ function createTree() {
|
|
|
144
149
|
},
|
|
145
150
|
}, attrs.expandedIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "chevron-down" })) : undefined,
|
|
146
151
|
collapsed ? (0, mithril_1.default)("button.mico-tree-toggle", {
|
|
147
|
-
style: `width:
|
|
152
|
+
style: `width: ${attrs.nestingWidth}; flex: none;`,
|
|
148
153
|
// class: enableToggling ? `hover:text-primary` : `text-view-icon`,
|
|
149
154
|
disabled: !enableToggling,
|
|
150
155
|
onclick: (ev) => {
|
|
@@ -155,10 +160,13 @@ function createTree() {
|
|
|
155
160
|
(_a = attrs.ontoggle) === null || _a === void 0 ? void 0 : _a.call(attrs, { node, expanded: true, recursive: ev.altKey });
|
|
156
161
|
},
|
|
157
162
|
}, attrs.collapsedIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "chevron-right" })) : undefined,
|
|
163
|
+
(!canHaveChildren) ? (0, mithril_1.default)(".mico-tree-toggle", {
|
|
164
|
+
style: `width: ${attrs.nestingWidth}; flex: none;`,
|
|
165
|
+
}, attrs.noToggleIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "caret-right" })) : [],
|
|
158
166
|
(0, mithril_1.default)(".mico-tree-label", {
|
|
159
167
|
class: `${targettingDragClass}`,
|
|
160
168
|
style: "position: relative; flex: 1 1 0%; overflow-x: hidden;",
|
|
161
|
-
draggable: enableReordering,
|
|
169
|
+
draggable: enableReordering && (node.draggable !== false),
|
|
162
170
|
onclick: (ev) => {
|
|
163
171
|
var _a;
|
|
164
172
|
this.handleClick(ev, node);
|
|
@@ -181,7 +189,9 @@ function createTree() {
|
|
|
181
189
|
]),
|
|
182
190
|
]),
|
|
183
191
|
// Any nested children within the item
|
|
184
|
-
(expanded) ? (0, mithril_1.default)("ul",
|
|
192
|
+
(expanded) ? (0, mithril_1.default)("ul", {
|
|
193
|
+
style: `margin-left: ${attrs.nestingWidth};`,
|
|
194
|
+
}, [
|
|
185
195
|
...(node.children || []).map((child, i) => {
|
|
186
196
|
return (0, mithril_1.default)(TreeNode, {
|
|
187
197
|
// key: child.key,
|
|
@@ -197,7 +207,9 @@ function createTree() {
|
|
|
197
207
|
emptyChildrenMessage: attrs.emptyChildrenMessage,
|
|
198
208
|
collapsedIcon: attrs.collapsedIcon,
|
|
199
209
|
expandedIcon: attrs.expandedIcon,
|
|
210
|
+
noToggleIcon: attrs.noToggleIcon,
|
|
200
211
|
toggleExpansionWithLabel: attrs.toggleExpansionWithLabel,
|
|
212
|
+
nestingWidth: attrs.nestingWidth,
|
|
201
213
|
});
|
|
202
214
|
}),
|
|
203
215
|
(canHaveChildren && !hasChildren && emptyChildrenMessage !== undefined)
|
|
@@ -2,6 +2,8 @@ import m from "mithril";
|
|
|
2
2
|
export interface TreeNode<T extends object = {}> {
|
|
3
3
|
label: string | m.Vnode<any>;
|
|
4
4
|
expanded: boolean;
|
|
5
|
+
/** Optionally disable dragging where it would otherwise be enabled */
|
|
6
|
+
draggable?: boolean;
|
|
5
7
|
children?: TreeNode<T>[];
|
|
6
8
|
data: T;
|
|
7
9
|
}
|