@hypericon/mico 0.2.7 → 0.3.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/dist/components/dialog/Dialog.d.ts +1 -0
- package/dist/components/dialog/Dialog.js +11 -0
- package/dist/components/dialog/dialog-manager.d.ts +45 -0
- package/dist/components/dialog/dialog-manager.js +173 -0
- package/dist/components/dialog/index.d.ts +1 -0
- package/dist/components/dialog/index.js +18 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/menu/index.d.ts +1 -1
- package/dist/components/menu/index.js +1 -1
- package/dist/components/menu/{menu-service.d.ts → menu-manager.d.ts} +2 -2
- package/dist/components/menu/{menu-service.js → menu-manager.js} +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// export const Dialog: m.Component<{
|
|
4
|
+
// created?: (args: {}) => any,
|
|
5
|
+
// }> = {
|
|
6
|
+
// view({ attrs, children }) {
|
|
7
|
+
// return m("dialog", {}, [
|
|
8
|
+
// children,
|
|
9
|
+
// ]);
|
|
10
|
+
// }
|
|
11
|
+
// };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import m from "mithril";
|
|
2
|
+
export interface DialogManagerOptions {
|
|
3
|
+
containerEl?: HTMLElement;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface OpenDialogResult {
|
|
7
|
+
close: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class DialogManager {
|
|
10
|
+
private containerEl;
|
|
11
|
+
private currentDialog;
|
|
12
|
+
get isOpen(): boolean;
|
|
13
|
+
private debug;
|
|
14
|
+
constructor(options?: DialogManagerOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Open a new dialog with the given contents.
|
|
17
|
+
*
|
|
18
|
+
* Note: to make use of Mithril's auto-redraw system, the dialog must be defined as a component,
|
|
19
|
+
* not a Vnode.
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* ```ts
|
|
23
|
+
* open(MyDialog, { ... }); // WILL redraw
|
|
24
|
+
* open(m("h1", "...")); // will NOT redraw
|
|
25
|
+
* ```
|
|
26
|
+
* @param dialog
|
|
27
|
+
* @param attrs
|
|
28
|
+
* @returns once the dialog has been created and is being displayed to the user
|
|
29
|
+
*/
|
|
30
|
+
open<A = {}>(dialog: m.Component<A, any> | m.Vnode<any, any>, attrs?: A, opts?: {
|
|
31
|
+
backdropDismiss?: boolean;
|
|
32
|
+
noEscape?: boolean;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
private _open;
|
|
35
|
+
private openWithComponent;
|
|
36
|
+
private openWithVnode;
|
|
37
|
+
/**
|
|
38
|
+
* Close the open dialog.
|
|
39
|
+
*
|
|
40
|
+
* Silently does nothing if no dialog is open.
|
|
41
|
+
*/
|
|
42
|
+
close(): void;
|
|
43
|
+
private closeThis;
|
|
44
|
+
}
|
|
45
|
+
export declare const dialogMgr: DialogManager;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.dialogMgr = exports.DialogManager = void 0;
|
|
16
|
+
const mithril_1 = __importDefault(require("mithril"));
|
|
17
|
+
class DialogManager {
|
|
18
|
+
get isOpen() { return this.currentDialog !== undefined; }
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.debug = false;
|
|
21
|
+
if (options === null || options === void 0 ? void 0 : options.debug)
|
|
22
|
+
this.debug = options.debug;
|
|
23
|
+
if (options === null || options === void 0 ? void 0 : options.containerEl) {
|
|
24
|
+
this.containerEl = options.containerEl;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.containerEl = document.createElement("div");
|
|
28
|
+
this.containerEl.classList.add("mico-dialog-container");
|
|
29
|
+
document.body.append(this.containerEl);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Open a new dialog with the given contents.
|
|
34
|
+
*
|
|
35
|
+
* Note: to make use of Mithril's auto-redraw system, the dialog must be defined as a component,
|
|
36
|
+
* not a Vnode.
|
|
37
|
+
*
|
|
38
|
+
* Example:
|
|
39
|
+
* ```ts
|
|
40
|
+
* open(MyDialog, { ... }); // WILL redraw
|
|
41
|
+
* open(m("h1", "...")); // will NOT redraw
|
|
42
|
+
* ```
|
|
43
|
+
* @param dialog
|
|
44
|
+
* @param attrs
|
|
45
|
+
* @returns once the dialog has been created and is being displayed to the user
|
|
46
|
+
*/
|
|
47
|
+
open(dialog, attrs, opts) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const element = this.containerEl;
|
|
50
|
+
const manager = this;
|
|
51
|
+
const dialogId = `${Math.random().toString().replace("0.", "")}`;
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
mithril_1.default.mount(element, {
|
|
54
|
+
oninit() {
|
|
55
|
+
//
|
|
56
|
+
},
|
|
57
|
+
oncreate({ dom }) {
|
|
58
|
+
var _a;
|
|
59
|
+
const dialog = dom;
|
|
60
|
+
(_a = dialog.showModal) === null || _a === void 0 ? void 0 : _a.call(dialog);
|
|
61
|
+
manager.currentDialog = dialog;
|
|
62
|
+
// Optionally wire up the backdrop to dismiss the dialog
|
|
63
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.backdropDismiss) === true) {
|
|
64
|
+
dialog.addEventListener("click", (ev) => {
|
|
65
|
+
// console.log(ev);
|
|
66
|
+
if (ev.target !== dom)
|
|
67
|
+
return;
|
|
68
|
+
const dialogRect = dom.getBoundingClientRect();
|
|
69
|
+
const isInDialog = (ev.clientY >= dialogRect.top) &&
|
|
70
|
+
(ev.clientY <= dialogRect.bottom) &&
|
|
71
|
+
(ev.clientX >= dialogRect.left) &&
|
|
72
|
+
(ev.clientX <= dialogRect.right);
|
|
73
|
+
if (!isInDialog)
|
|
74
|
+
manager.close();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
resolve();
|
|
78
|
+
},
|
|
79
|
+
onremove() {
|
|
80
|
+
manager.debug && console.log("mounted component onremove()");
|
|
81
|
+
resolve(undefined);
|
|
82
|
+
},
|
|
83
|
+
view() {
|
|
84
|
+
return (0, mithril_1.default)("dialog", {
|
|
85
|
+
id: dialogId,
|
|
86
|
+
key: dialogId,
|
|
87
|
+
class: "mico-dialog",
|
|
88
|
+
onclose: () => {
|
|
89
|
+
manager.debug && console.log("dialog onclose()");
|
|
90
|
+
mithril_1.default.mount(manager.containerEl, null);
|
|
91
|
+
},
|
|
92
|
+
oncancel: (ev) => {
|
|
93
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.noEscape) === true) {
|
|
94
|
+
ev.preventDefault();
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
}, [
|
|
98
|
+
("view" in dialog)
|
|
99
|
+
? (0, mithril_1.default)(dialog, Object.assign({}, attrs))
|
|
100
|
+
: dialog,
|
|
101
|
+
]);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// This was attempting to intercept a certain function and then return a result from open()
|
|
108
|
+
// asynchronously, but it was all getting needlessly complicated
|
|
109
|
+
_open(dialog, attrs, options) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const element = this.containerEl;
|
|
112
|
+
const manager = this;
|
|
113
|
+
const dialogId = `${Math.random().toString()}`;
|
|
114
|
+
// const resultFnKey = options?.resultFn;
|
|
115
|
+
// if (resultFnKey) {
|
|
116
|
+
// if (attrs) {
|
|
117
|
+
// attrs[resultFnKey] =
|
|
118
|
+
// }
|
|
119
|
+
// }
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
mithril_1.default.mount(element, {
|
|
122
|
+
oninit() {
|
|
123
|
+
//
|
|
124
|
+
},
|
|
125
|
+
oncreate({ dom }) {
|
|
126
|
+
var _a;
|
|
127
|
+
const dialog = dom;
|
|
128
|
+
(_a = dialog.showModal) === null || _a === void 0 ? void 0 : _a.call(dialog);
|
|
129
|
+
manager.currentDialog = dialog;
|
|
130
|
+
},
|
|
131
|
+
onremove() {
|
|
132
|
+
console.log("mounted component onremove()");
|
|
133
|
+
resolve(undefined);
|
|
134
|
+
},
|
|
135
|
+
view() {
|
|
136
|
+
return (0, mithril_1.default)("dialog", {
|
|
137
|
+
id: dialogId,
|
|
138
|
+
key: dialogId,
|
|
139
|
+
onclose: () => {
|
|
140
|
+
console.log("dialog onclose()");
|
|
141
|
+
mithril_1.default.mount(manager.containerEl, null);
|
|
142
|
+
},
|
|
143
|
+
}, [
|
|
144
|
+
("view" in dialog)
|
|
145
|
+
? (0, mithril_1.default)(dialog, Object.assign({}, attrs))
|
|
146
|
+
: dialog,
|
|
147
|
+
]);
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
openWithComponent(dialog) { }
|
|
154
|
+
openWithVnode(dialog) { }
|
|
155
|
+
/**
|
|
156
|
+
* Close the open dialog.
|
|
157
|
+
*
|
|
158
|
+
* Silently does nothing if no dialog is open.
|
|
159
|
+
*/
|
|
160
|
+
close() {
|
|
161
|
+
var _a;
|
|
162
|
+
// m.mount(this.containerEl, null);
|
|
163
|
+
(_a = this.currentDialog) === null || _a === void 0 ? void 0 : _a.close();
|
|
164
|
+
}
|
|
165
|
+
// an attempt to close a specific dialog, but only one can be open at once anyway
|
|
166
|
+
closeThis(dialog) {
|
|
167
|
+
console.log("close:");
|
|
168
|
+
console.log(dialog);
|
|
169
|
+
console.log(dialog.prototype);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.DialogManager = DialogManager;
|
|
173
|
+
exports.dialogMgr = new DialogManager();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dialog-manager";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// export * from "./Dialog";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
__exportStar(require("./dialog-manager"), exports);
|
package/dist/components/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
// export * from "./accordion";
|
|
18
18
|
// export * from "./data-grid";
|
|
19
19
|
// export * from "./data-table";
|
|
20
|
+
__exportStar(require("./dialog"), exports);
|
|
20
21
|
// export * from "./drawer";
|
|
21
22
|
// export * from "./form";
|
|
22
23
|
__exportStar(require("./icon"), exports);
|
|
@@ -18,5 +18,5 @@ __exportStar(require("./Menu"), exports);
|
|
|
18
18
|
__exportStar(require("./MenuButton"), exports);
|
|
19
19
|
__exportStar(require("./MenuSeparator"), exports);
|
|
20
20
|
__exportStar(require("./menu-constants"), exports);
|
|
21
|
-
__exportStar(require("./menu-
|
|
21
|
+
__exportStar(require("./menu-manager"), exports);
|
|
22
22
|
__exportStar(require("./menu-settings"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import m from "mithril";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class MenuManager {
|
|
3
3
|
private containerEl;
|
|
4
4
|
private _menuVnode;
|
|
5
5
|
menuVnode$: import("rxjs").Observable<m.Vnode<any, any> | undefined>;
|
|
@@ -18,4 +18,4 @@ export declare class MenuService {
|
|
|
18
18
|
show(ev: MouseEvent | undefined, menuContents: m.ChildArrayOrPrimitive): Promise<void>;
|
|
19
19
|
hide(): void;
|
|
20
20
|
}
|
|
21
|
-
export declare const
|
|
21
|
+
export declare const menuMgr: MenuManager;
|
|
@@ -12,12 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.menuMgr = exports.MenuManager = void 0;
|
|
16
16
|
const mithril_1 = __importDefault(require("mithril"));
|
|
17
17
|
const rxjs_1 = require("rxjs");
|
|
18
18
|
const Menu_1 = require("./Menu");
|
|
19
19
|
const menu_settings_1 = require("./menu-settings");
|
|
20
|
-
class
|
|
20
|
+
class MenuManager {
|
|
21
21
|
get menuVnode() { return this._menuVnode.value; }
|
|
22
22
|
get isOpen() {
|
|
23
23
|
return Boolean(this.menuVnode);
|
|
@@ -74,5 +74,5 @@ class MenuService {
|
|
|
74
74
|
// console.log("Closed menu");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
exports.
|
|
78
|
-
exports.
|
|
77
|
+
exports.MenuManager = MenuManager;
|
|
78
|
+
exports.menuMgr = new MenuManager();
|