You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2022/11/01 15:33:56 UTC
[myfaces-tobago] 02/04: refactor(typescript): MenuStore
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch t5_selectMany
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
commit cda55429af8e61138fb1caaad0ff2c16455db41c
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue Nov 1 14:00:19 2022 +0100
refactor(typescript): MenuStore
Use dedicated MenuStore Typescript Class.
---
.../src/main/ts/tobago-dropdown.ts | 22 +++++++---------
.../src/main/ts/tobago-menu-store.ts | 29 ++++++++++++++++++++++
.../src/main/ts/tobago-popover.ts | 9 +++----
.../src/main/ts/tobago-range.ts | 5 ----
.../src/main/ts/tobago-suggest.ts | 8 ++----
5 files changed, 43 insertions(+), 30 deletions(-)
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
index c05adf9ba4..545b4d0152 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-dropdown.ts
@@ -15,21 +15,22 @@
* limitations under the License.
*/
+import {MenuStore} from "./tobago-menu-store";
import {BootstrapEvents} from "./BootstrapEvents";
+const TobagoDropdownEvent = {
+ HIDE: "tobago.dropdown.hide",
+ HIDDEN: "tobago.dropdown.hidden",
+ SHOW: "tobago.dropdown.show",
+ SHOWN: "tobago.dropdown.shown"
+};
+
/**
* The dropdown implementation of Bootstrap does not move the menu to the tobago-page-menuStore. This behavior is
* implemented in this class.
*/
class Dropdown extends HTMLElement {
- private readonly TobagoEvents = {
- HIDE: "tobago.dropdown.hide",
- HIDDEN: "tobago.dropdown.hidden",
- SHOW: "tobago.dropdown.show",
- SHOWN: "tobago.dropdown.shown"
- };
-
constructor() {
super();
if (!this.classList.contains("tobago-dropdown-submenu")) { // ignore submenus
@@ -48,7 +49,7 @@ class Dropdown extends HTMLElement {
this.dispatchEvent(new CustomEvent(this.TobagoEvents.SHOW));
if (!this.insideNavbar()) {
- this.menuStore.appendChild(this.dropdownMenu);
+ MenuStore.appendChild(this.dropdownMenu);
}
this.dispatchEvent(new CustomEvent(this.TobagoEvents.SHOWN));
@@ -75,11 +76,6 @@ class Dropdown extends HTMLElement {
const root = this.getRootNode() as ShadowRoot | Document;
return root.querySelector(`.dropdown-menu[name='${this.id}']`);
}
-
- private get menuStore(): HTMLDivElement {
- const root = this.getRootNode() as ShadowRoot | Document;
- return root.querySelector(".tobago-page-menuStore");
- }
}
document.addEventListener("tobago.init", function (event: Event): void {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-menu-store.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-menu-store.ts
new file mode 100644
index 0000000000..2d988b0bf9
--- /dev/null
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-menu-store.ts
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export class MenuStore {
+ static appendChild<T extends Node>(node: T): T {
+ return MenuStore.get().appendChild(node);
+ }
+
+ static get(): HTMLDivElement {
+ const root = document.getRootNode() as ShadowRoot | Document;
+ return root.querySelector<HTMLDivElement>(".tobago-page-menuStore");
+ }
+}
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popover.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popover.ts
index 18558a1947..4a1b83167b 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popover.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-popover.ts
@@ -20,6 +20,8 @@
// import Popover from "bootstrap/dist/js/bootstrap.bundle";
// import {createPopper} from "@popperjs/core/dist/esm/popper";
import {Popover} from "bootstrap";
+import {MenuStore} from "./tobago-menu-store";
+
// import {Popover} from "bootstrap/dist/js/bootstrap.bundle";
class TobagoPopover extends HTMLElement {
@@ -32,18 +34,13 @@ class TobagoPopover extends HTMLElement {
connectedCallback(): void {
this.popover = new Popover(this.trigger, {
- container: this.menuStore
+ container: MenuStore.get()
});
}
get trigger(): HTMLElement {
return this;
}
-
- private get menuStore(): HTMLDivElement {
- const root = this.getRootNode() as ShadowRoot | Document;
- return root.querySelector(".tobago-page-menuStore");
- }
}
document.addEventListener("tobago.init", function (event: Event): void {
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-range.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-range.ts
index 0b99d0471c..dff2bf8139 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-range.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-range.ts
@@ -36,11 +36,6 @@ class TobagoRange extends HTMLElement {
return this.querySelector(".tobago-tooltip");
}
- private get menuStore(): HTMLDivElement {
- const root = this.getRootNode() as ShadowRoot | Document;
- return root.querySelector(".tobago-page-menuStore");
- }
-
private updateTooltip(): void {
this.tooltip.textContent = this.range.value;
diff --git a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
index 2a55b517f5..7c6ae9a33f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/ts/tobago-suggest.ts
@@ -17,6 +17,7 @@
import Autocomplete from "@trevoreyre/autocomplete-js";
import {SuggestFilter} from "./tobago-suggest-filter";
+import {MenuStore} from "./tobago-menu-store";
export class Suggest {
@@ -86,7 +87,7 @@ export class Suggest {
new Autocomplete(this.base, options);
if (!this.localMenu) {
- this.menuStore.append(this.resultList);
+ MenuStore.appendChild(this.resultList);
}
}
@@ -201,11 +202,6 @@ export class Suggest {
return this.base.dataset.position;
}
- private get menuStore(): HTMLDivElement {
- const root = this.base.getRootNode() as ShadowRoot | Document;
- return root.querySelector(".tobago-page-menuStore");
- }
-
private get update(): boolean {
return this.suggest.getAttribute("update") !== null;
}