-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55fb8b1
commit ed31305
Showing
6 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {hasClosestBlock} from "../../util/hasClosest"; | ||
|
||
export const selectRow = (checkElement: Element, type: "toggle" | "select" | "unselect") => { | ||
const rowElement = checkElement.parentElement; | ||
const useElement = checkElement.querySelector("use"); | ||
if (rowElement.classList.contains("av__row--header")) { | ||
if ("#iconCheck" === useElement.getAttribute("xlink:href")) { | ||
rowElement.parentElement.querySelectorAll(".av__firstcol").forEach(item => { | ||
item.querySelector("use").setAttribute("xlink:href", "#iconUncheck"); | ||
item.parentElement.classList.remove("av__row--select"); | ||
}); | ||
} else { | ||
rowElement.parentElement.querySelectorAll(".av__firstcol").forEach(item => { | ||
item.querySelector("use").setAttribute("xlink:href", "#iconCheck"); | ||
item.parentElement.classList.add("av__row--select"); | ||
}); | ||
} | ||
} else { | ||
if (type === "select" || (useElement.getAttribute("xlink:href") === "#iconUncheck" && type === "toggle")) { | ||
checkElement.parentElement.classList.add("av__row--select"); | ||
useElement.setAttribute("xlink:href", "#iconCheck"); | ||
} else if (type === "unselect" || (useElement.getAttribute("xlink:href") === "#iconCheck" && type === "toggle")) { | ||
checkElement.parentElement.classList.remove("av__row--select"); | ||
useElement.setAttribute("xlink:href", "#iconUncheck"); | ||
} | ||
} | ||
updateHeader(rowElement); | ||
} | ||
|
||
export const updateHeader = (rowElement: HTMLElement) => { | ||
const blockElement = hasClosestBlock(rowElement); | ||
if (!blockElement) { | ||
return; | ||
} | ||
const selectCount = rowElement.parentElement.querySelectorAll(".av__row--select:not(.av__row--header)").length; | ||
const diffCount = rowElement.parentElement.childElementCount - 3 - selectCount; | ||
const headElement = rowElement.parentElement.firstElementChild; | ||
const headUseElement = headElement.querySelector("use"); | ||
const counterElement = blockElement.querySelector(".av__counter"); | ||
const avHeadElement = blockElement.querySelector(".av__header") as HTMLElement; | ||
if (diffCount === 0 && rowElement.parentElement.childElementCount - 3 !== 0) { | ||
headElement.classList.add("av__row--select"); | ||
headUseElement.setAttribute("xlink:href", "#iconCheck"); | ||
} else if (diffCount === rowElement.parentElement.childElementCount - 3) { | ||
headElement.classList.remove("av__row--select"); | ||
headUseElement.setAttribute("xlink:href", "#iconUncheck"); | ||
counterElement.classList.add("fn__none"); | ||
avHeadElement.style.position = ""; | ||
return; | ||
} else if (diffCount > 0) { | ||
headElement.classList.add("av__row--select"); | ||
headUseElement.setAttribute("xlink:href", "#iconIndeterminateCheck"); | ||
} | ||
counterElement.classList.remove("fn__none"); | ||
counterElement.innerHTML = `${selectCount} selected`; | ||
avHeadElement.style.position = "sticky"; | ||
}; | ||
|
||
export const insertAttrViewBlockAnimation = (blockElement: Element, size: number, previousId: string, avId?: string) => { | ||
const previousElement = blockElement.querySelector(`.av__row[data-id="${previousId}"]`) || blockElement.querySelector(".av__row--header"); | ||
let colHTML = ""; | ||
previousElement.querySelectorAll(".av__cell").forEach((item: HTMLElement) => { | ||
colHTML += `<div class="av__cell" style="width: ${item.style.width}" ${item.getAttribute("data-block-id") ? ' data-detached="true"' : ""}><span class="av__pulse"></span></div>`; | ||
}); | ||
|
||
let html = ""; | ||
new Array(size).fill(1).forEach(() => { | ||
html += `<div class="av__row" data-avid="${avId}"> | ||
<div style="width: 24px"></div> | ||
${colHTML} | ||
</div>`; | ||
}); | ||
previousElement.insertAdjacentHTML("afterend", html); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters