@hypericon/mico 0.5.1 → 0.5.2

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.
@@ -20,5 +20,10 @@ export declare class MenuManager {
20
20
  */
21
21
  show(ev: MouseEvent | undefined, menuContents: m.ChildArrayOrPrimitive, options?: MenuOptions): Promise<void>;
22
22
  hide(): void;
23
+ /**
24
+ * Set the default behavior for whether menus are added as children of the element that raised the event.
25
+ * @param asChild
26
+ */
27
+ setDefaultAsChild(asChild: boolean): void;
23
28
  }
24
29
  export declare const menuMgr: MenuManager;
@@ -50,6 +50,7 @@ class MenuManager {
50
50
  * @param menuContents
51
51
  */
52
52
  show(ev, menuContents, options) {
53
+ var _a;
53
54
  return __awaiter(this, void 0, void 0, function* () {
54
55
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
55
56
  if (this.isOpen) {
@@ -67,10 +68,9 @@ class MenuManager {
67
68
  ]);
68
69
  this._menuVnode.next(menuVnode);
69
70
  // m.render(this.containerEl, menuVnode);
70
- if ((options === null || options === void 0 ? void 0 : options.asChild) && (ev === null || ev === void 0 ? void 0 : ev.target) && ev.target instanceof HTMLElement) {
71
+ const asChild = (_a = options === null || options === void 0 ? void 0 : options.asChild) !== null && _a !== void 0 ? _a : menu_settings_1.MENU_SETTINGS.AS_CHILD;
72
+ if (asChild && (ev === null || ev === void 0 ? void 0 : ev.target) && ev.target instanceof HTMLElement) {
71
73
  this.directParentEl = ev.target;
72
- // m.render(ev.target, menuVnode);
73
- // this.containerEl = ev.target;
74
74
  this.directParentWrapperEl = document.createElement("div");
75
75
  this.directParentEl.append(this.directParentWrapperEl);
76
76
  mithril_1.default.render(this.directParentWrapperEl, menuVnode);
@@ -78,8 +78,6 @@ class MenuManager {
78
78
  else {
79
79
  mithril_1.default.render(this.containerEl, menuVnode);
80
80
  }
81
- // m.render(this.containerEl, menuVnode);
82
- // console.log("Added menu");
83
81
  });
84
82
  }
85
83
  hide() {
@@ -91,6 +89,13 @@ class MenuManager {
91
89
  this.directParentEl = undefined;
92
90
  // console.log("Closed menu");
93
91
  }
92
+ /**
93
+ * Set the default behavior for whether menus are added as children of the element that raised the event.
94
+ * @param asChild
95
+ */
96
+ setDefaultAsChild(asChild) {
97
+ menu_settings_1.MENU_SETTINGS.AS_CHILD = asChild;
98
+ }
94
99
  }
95
100
  exports.MenuManager = MenuManager;
96
101
  exports.menuMgr = new MenuManager();
@@ -6,4 +6,5 @@ export declare const MENU_SETTINGS: {
6
6
  MENU_BUTTON_ICON_CLASS: string;
7
7
  MENU_BUTTON_HINT_CLASS: string;
8
8
  MENU_SEPARATOR_CLASS: string;
9
+ AS_CHILD: boolean;
9
10
  };
@@ -9,4 +9,5 @@ exports.MENU_SETTINGS = {
9
9
  MENU_BUTTON_ICON_CLASS: "",
10
10
  MENU_BUTTON_HINT_CLASS: "",
11
11
  MENU_SEPARATOR_CLASS: "",
12
+ AS_CHILD: false, // Default to not adding the menu as a child of the element that raised the event
12
13
  };
@@ -20,5 +20,10 @@ export declare class MenuManager {
20
20
  */
21
21
  show(ev: MouseEvent | undefined, menuContents: m.ChildArrayOrPrimitive, options?: MenuOptions): Promise<void>;
22
22
  hide(): void;
23
+ /**
24
+ * Set the default behavior for whether menus are added as children of the element that raised the event.
25
+ * @param asChild
26
+ */
27
+ setDefaultAsChild(asChild: boolean): void;
23
28
  }
24
29
  export declare const menuMgr: MenuManager;
@@ -50,6 +50,7 @@ class MenuManager {
50
50
  * @param menuContents
51
51
  */
52
52
  show(ev, menuContents, options) {
53
+ var _a;
53
54
  return __awaiter(this, void 0, void 0, function* () {
54
55
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
55
56
  if (this.isOpen) {
@@ -67,10 +68,9 @@ class MenuManager {
67
68
  ]);
68
69
  this._menuVnode.next(menuVnode);
69
70
  // m.render(this.containerEl, menuVnode);
70
- if ((options === null || options === void 0 ? void 0 : options.asChild) && (ev === null || ev === void 0 ? void 0 : ev.target) && ev.target instanceof HTMLElement) {
71
+ const asChild = (_a = options === null || options === void 0 ? void 0 : options.asChild) !== null && _a !== void 0 ? _a : menu_settings_1.MENU_SETTINGS.AS_CHILD;
72
+ if (asChild && (ev === null || ev === void 0 ? void 0 : ev.target) && ev.target instanceof HTMLElement) {
71
73
  this.directParentEl = ev.target;
72
- // m.render(ev.target, menuVnode);
73
- // this.containerEl = ev.target;
74
74
  this.directParentWrapperEl = document.createElement("div");
75
75
  this.directParentEl.append(this.directParentWrapperEl);
76
76
  mithril_1.default.render(this.directParentWrapperEl, menuVnode);
@@ -78,8 +78,6 @@ class MenuManager {
78
78
  else {
79
79
  mithril_1.default.render(this.containerEl, menuVnode);
80
80
  }
81
- // m.render(this.containerEl, menuVnode);
82
- // console.log("Added menu");
83
81
  });
84
82
  }
85
83
  hide() {
@@ -91,6 +89,13 @@ class MenuManager {
91
89
  this.directParentEl = undefined;
92
90
  // console.log("Closed menu");
93
91
  }
92
+ /**
93
+ * Set the default behavior for whether menus are added as children of the element that raised the event.
94
+ * @param asChild
95
+ */
96
+ setDefaultAsChild(asChild) {
97
+ menu_settings_1.MENU_SETTINGS.AS_CHILD = asChild;
98
+ }
94
99
  }
95
100
  exports.MenuManager = MenuManager;
96
101
  exports.menuMgr = new MenuManager();
@@ -6,4 +6,5 @@ export declare const MENU_SETTINGS: {
6
6
  MENU_BUTTON_ICON_CLASS: string;
7
7
  MENU_BUTTON_HINT_CLASS: string;
8
8
  MENU_SEPARATOR_CLASS: string;
9
+ AS_CHILD: boolean;
9
10
  };
@@ -9,4 +9,5 @@ exports.MENU_SETTINGS = {
9
9
  MENU_BUTTON_ICON_CLASS: "",
10
10
  MENU_BUTTON_HINT_CLASS: "",
11
11
  MENU_SEPARATOR_CLASS: "",
12
+ AS_CHILD: false, // Default to not adding the menu as a child of the element that raised the event
12
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypericon/mico",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "UI components and utilities with Mithril",
5
5
  "author": "Ed Johnson, Hypericon Ltd",
6
6
  "license": "MIT",