Skip to content

Commit

Permalink
♻ refactor(JS): replace NodeList with Array.from for better compatibi…
Browse files Browse the repository at this point in the history
…lity (#2254)
  • Loading branch information
capdiem authored Nov 20, 2024
1 parent 7b7f478 commit 0fe6b05
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 62 deletions.
51 changes: 0 additions & 51 deletions src/Masa.Blazor.JS/build-js.ps1

This file was deleted.

6 changes: 3 additions & 3 deletions src/Masa.Blazor.JS/src/interop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ export function getMenuOrDialogMaxZIndex(exclude: Element[] = [], element: Eleme
const zis = [getZIndex(base)]

const activeElements = [
...document.getElementsByClassName('m-menu__content--active'),
...document.getElementsByClassName('m-dialog__content--active'),
...Array.from(document.getElementsByClassName('m-menu__content--active')),
...Array.from(document.getElementsByClassName('m-dialog__content--active')),
]

// Get z-index for all active dialogs
Expand All @@ -719,7 +719,7 @@ export function getMenuOrDialogMaxZIndex(exclude: Element[] = [], element: Eleme
}

export function getMaxZIndex() {
return [...document.all].reduce((r, e) => Math.max(r, +window.getComputedStyle(e).zIndex || 0), 0)
return Array.from(document.all).reduce((r, e) => Math.max(r, +window.getComputedStyle(e).zIndex || 0), 0)
}

export function getStyle(element, styleProp) {
Expand Down
1 change: 0 additions & 1 deletion src/Masa.Blazor.JS/src/mixins/activatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Activatable extends Delayable {
closeOnOutsideClick: boolean;
closeOnContentClick: boolean;

isActive: boolean;
activatorListeners: Listeners = {};
popupListeners: Listeners = {};

Expand Down
2 changes: 1 addition & 1 deletion src/Masa.Blazor.JS/src/proxies/sortable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SortableProxy {
...rest,
scroll: true,
onMove: (evt, originalEvent) => {
const ignoreElements = [...this.el.querySelectorAll(ignore)];
const ignoreElements = Array.from(this.el.querySelectorAll(ignore));
if (ignoreElements.length) {
let dragged: HTMLElement;
let target: HTMLElement;
Expand Down
6 changes: 3 additions & 3 deletions src/Masa.Blazor.JS/src/ripple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default function registerRippleObserver() {
const observer = new MutationObserver((mutationsList, observer) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList" && mutation.addedNodes.length > 0) {
for (const node of mutation.addedNodes) {
for (const node of Array.from(mutation.addedNodes)) {
if (node instanceof HTMLElement) {
if (
node.nodeType === Node.ELEMENT_NODE &&
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function registerRippleObserver() {
}

if (mutation.type === "childList" && mutation.removedNodes.length > 0) {
for (const node of mutation.removedNodes) {
for (const node of Array.from(mutation.removedNodes)) {
if (node instanceof HTMLElement) {
if (node.nodeType === Node.ELEMENT_NODE && node._ripple) {
removeListeners(node);
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function registerRippleObserver() {
return options;
}

const initialElements = document.querySelectorAll("[ripple]");
const initialElements = Array.from(document.querySelectorAll("[ripple]"));

for (const element of initialElements) {
updateRipple(element, convertRippleAttributeToOptions(element), false);
Expand Down
2 changes: 1 addition & 1 deletion src/Masa.Blazor/wwwroot/js/masa-blazor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Masa.Blazor/wwwroot/js/masa-blazor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Masa.Blazor/wwwroot/js/mixins/activatable/index.js.map

Large diffs are not rendered by default.

0 comments on commit 0fe6b05

Please sign in to comment.