feat(context-menu): pass file path to NSFW level selector

- Add `cardPath` parameter to `show` method in NsfwLevelSelector component
- Include `filePath` from card dataset when calling selector in ModelContextMenuMixin
- Clear `cardPath` from dataset when hiding selector to prevent stale data

This enables the NSFW level selector to access the file path context, which may be needed for backend operations when changing NSFW levels.
This commit is contained in:
Will Miao
2025-12-09 22:13:00 +08:00
parent 6b3a11e01a
commit fbb95bc623
2 changed files with 4 additions and 1 deletions

View File

@@ -55,6 +55,7 @@ export const ModelContextMenuMixin = {
const filePath = card.dataset.filepath;
selector.show({
currentLevel,
cardPath: filePath,
onSelect: async (level) => {
if (!filePath) return false;
try {

View File

@@ -26,6 +26,7 @@ function buildController(selectorElement) {
const hide = () => {
selectorElement.style.display = 'none';
selectorElement.dataset.cardPath = '';
isOpen = false;
if (typeof onClose === 'function') {
onClose();
@@ -34,11 +35,12 @@ function buildController(selectorElement) {
onClose = null;
};
const show = ({ currentLevel = 0, onSelect: selectCb, onClose: closeCb, multipleLabel = '' } = {}) => {
const show = ({ currentLevel = 0, onSelect: selectCb, onClose: closeCb, multipleLabel = '', cardPath = '' } = {}) => {
onSelect = selectCb || null;
onClose = closeCb || null;
isOpen = true;
ignoreNextOutside = true; // ignore the click that triggered open
selectorElement.dataset.cardPath = cardPath || '';
// Position near center of viewport
const viewportWidth = document.documentElement.clientWidth;