@hypericon/mico 0.3.15 → 0.3.17
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.
|
@@ -41,6 +41,8 @@ export declare const Tree: m.Component<{
|
|
|
41
41
|
toggleExpansionWithLabel?: boolean | undefined;
|
|
42
42
|
/** Optionally override the default nesting width */
|
|
43
43
|
nestingWidth?: string | undefined;
|
|
44
|
+
/** Optionally override the default toggle button width */
|
|
45
|
+
toggleButtonWidth?: string | undefined;
|
|
44
46
|
/** Optional CSS classes to apply to the root div */
|
|
45
47
|
class?: string | undefined;
|
|
46
48
|
/** Optional CSS styles to apply to the root div */
|
|
@@ -94,6 +96,8 @@ export declare function createTree<TNodeData extends object = {}>(): m.Component
|
|
|
94
96
|
toggleExpansionWithLabel?: boolean | undefined;
|
|
95
97
|
/** Optionally override the default nesting width */
|
|
96
98
|
nestingWidth?: string | undefined;
|
|
99
|
+
/** Optionally override the default toggle button width */
|
|
100
|
+
toggleButtonWidth?: string | undefined;
|
|
97
101
|
/** Optional CSS classes to apply to the root div */
|
|
98
102
|
class?: string | undefined;
|
|
99
103
|
/** Optional CSS styles to apply to the root div */
|
|
@@ -9,6 +9,7 @@ const mithril_1 = __importDefault(require("mithril"));
|
|
|
9
9
|
const icon_1 = require("../icon");
|
|
10
10
|
const DATA_TRANSFER_TYPE = "application/tree-data";
|
|
11
11
|
const DEFAULT_NESTING_WIDTH = "1.5rem";
|
|
12
|
+
const DEFAULT_TOGGLE_WIDTH = "1.5rem";
|
|
12
13
|
/**
|
|
13
14
|
* An untyped tree component (see `createTree<T>()`)
|
|
14
15
|
*/
|
|
@@ -51,6 +52,7 @@ function createTree() {
|
|
|
51
52
|
noToggleIcon: attrs.noToggleIcon,
|
|
52
53
|
toggleExpansionWithLabel: attrs.toggleExpansionWithLabel,
|
|
53
54
|
nestingWidth: attrs.nestingWidth || DEFAULT_NESTING_WIDTH,
|
|
55
|
+
toggleButtonWidth: attrs.toggleButtonWidth || DEFAULT_TOGGLE_WIDTH,
|
|
54
56
|
});
|
|
55
57
|
})),
|
|
56
58
|
]);
|
|
@@ -69,6 +71,8 @@ function createTree() {
|
|
|
69
71
|
return;
|
|
70
72
|
if (!ev.dataTransfer)
|
|
71
73
|
return;
|
|
74
|
+
if (node.draggable === false)
|
|
75
|
+
return;
|
|
72
76
|
attrs.enableLogging && console.log(`start dragging`, node.data);
|
|
73
77
|
ev.dataTransfer.setData(DATA_TRANSFER_TYPE, JSON.stringify(node.data));
|
|
74
78
|
ev.dataTransfer.effectAllowed = "move";
|
|
@@ -135,7 +139,7 @@ function createTree() {
|
|
|
135
139
|
style: `display: flex; align-items: stretch; max-width: 100%; overflow-x: hidden; ${(attrs.toggleExpansionWithLabel && enableToggling) ? `cursor: pointer;` : ``}`,
|
|
136
140
|
}, [
|
|
137
141
|
expanded ? (0, mithril_1.default)("button.mico-tree-toggle", {
|
|
138
|
-
style: `width: ${attrs.
|
|
142
|
+
style: `width: ${attrs.toggleButtonWidth}; flex: none;`,
|
|
139
143
|
// class: enableToggling ? `hover:text-primary` : `text-view-icon`,
|
|
140
144
|
disabled: !enableToggling,
|
|
141
145
|
onclick: (ev) => {
|
|
@@ -147,7 +151,7 @@ function createTree() {
|
|
|
147
151
|
},
|
|
148
152
|
}, attrs.expandedIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "chevron-down" })) : undefined,
|
|
149
153
|
collapsed ? (0, mithril_1.default)("button.mico-tree-toggle", {
|
|
150
|
-
style: `width: ${attrs.
|
|
154
|
+
style: `width: ${attrs.toggleButtonWidth}; flex: none;`,
|
|
151
155
|
// class: enableToggling ? `hover:text-primary` : `text-view-icon`,
|
|
152
156
|
disabled: !enableToggling,
|
|
153
157
|
onclick: (ev) => {
|
|
@@ -159,12 +163,12 @@ function createTree() {
|
|
|
159
163
|
},
|
|
160
164
|
}, attrs.collapsedIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "chevron-right" })) : undefined,
|
|
161
165
|
(!canHaveChildren) ? (0, mithril_1.default)(".mico-tree-toggle", {
|
|
162
|
-
style: `width: ${attrs.
|
|
166
|
+
style: `width: ${attrs.toggleButtonWidth}; flex: none;`,
|
|
163
167
|
}, attrs.noToggleIcon || (0, mithril_1.default)(icon_1.Icon, { fas: "caret-right" })) : [],
|
|
164
168
|
(0, mithril_1.default)(".mico-tree-label", {
|
|
165
169
|
class: `${targettingDragClass}`,
|
|
166
170
|
style: "position: relative; flex: 1 1 0%; overflow-x: hidden;",
|
|
167
|
-
draggable: enableReordering,
|
|
171
|
+
draggable: enableReordering && (node.draggable !== false),
|
|
168
172
|
onclick: (ev) => {
|
|
169
173
|
var _a;
|
|
170
174
|
this.handleClick(ev, node);
|
|
@@ -208,6 +212,7 @@ function createTree() {
|
|
|
208
212
|
noToggleIcon: attrs.noToggleIcon,
|
|
209
213
|
toggleExpansionWithLabel: attrs.toggleExpansionWithLabel,
|
|
210
214
|
nestingWidth: attrs.nestingWidth,
|
|
215
|
+
toggleButtonWidth: attrs.toggleButtonWidth,
|
|
211
216
|
});
|
|
212
217
|
}),
|
|
213
218
|
(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
|
}
|