1
0
mirror of synced 2025-12-16 03:48:03 +08:00

feat(elements): delete node

This commit is contained in:
redhoodsu
2022-12-19 21:45:24 +08:00
parent e7a012712e
commit 25c75bf4e6
6 changed files with 53 additions and 8 deletions

View File

@@ -65,7 +65,7 @@
"licia": "^1.37.0", "licia": "^1.37.0",
"luna-console": "^1.2.0", "luna-console": "^1.2.0",
"luna-data-grid": "^0.3.2", "luna-data-grid": "^0.3.2",
"luna-dom-viewer": "^1.1.1", "luna-dom-viewer": "^1.1.2",
"luna-modal": "^1.0.0", "luna-modal": "^1.0.0",
"luna-notification": "^0.1.4", "luna-notification": "^0.1.4",
"luna-object-viewer": "^0.2.4", "luna-object-viewer": "^0.2.4",

View File

@@ -9,7 +9,7 @@ import toNum from 'licia/toNum'
import copy from 'licia/copy' import copy from 'licia/copy'
import isMobile from 'licia/isMobile' import isMobile from 'licia/isMobile'
import LunaDomViewer from 'luna-dom-viewer' import LunaDomViewer from 'luna-dom-viewer'
import { isErudaEl, classPrefix as c } from '../lib/util' import { isErudaEl, classPrefix as c, isChobitsuEl } from '../lib/util'
import evalCss from '../lib/evalCss' import evalCss from '../lib/evalCss'
import Detail from './Detail' import Detail from './Detail'
import chobitsu from '../lib/chobitsu' import chobitsu from '../lib/chobitsu'
@@ -39,7 +39,7 @@ export default class Elements extends Tool {
this.config = this._detail.config this.config = this._detail.config
this._domViewer = new LunaDomViewer(this._$domViewer.get(0), { this._domViewer = new LunaDomViewer(this._$domViewer.get(0), {
node: this._htmlEl, node: this._htmlEl,
ignore: (node) => isErudaEl(node), ignore: (node) => isErudaEl(node) || isChobitsuEl(node),
}) })
this._domViewer.expand() this._domViewer.expand()
this._bindEvent() this._bindEvent()
@@ -77,10 +77,12 @@ export default class Elements extends Tool {
const $control = this._$control const $control = this._$control
const $showDetail = $control.find(c('.show-detail')) const $showDetail = $control.find(c('.show-detail'))
const $copyNode = $control.find(c('.copy-node')) const $copyNode = $control.find(c('.copy-node'))
const $deleteNode = $control.find(c('.delete-node'))
const iconDisabled = c('icon-disabled') const iconDisabled = c('icon-disabled')
$showDetail.addClass(iconDisabled) $showDetail.addClass(iconDisabled)
$copyNode.addClass(iconDisabled) $copyNode.addClass(iconDisabled)
$deleteNode.addClass(iconDisabled)
const node = this._curNode const node = this._curNode
@@ -88,6 +90,9 @@ export default class Elements extends Tool {
return return
} }
if (node !== document.documentElement && node !== document.body) {
$deleteNode.rmClass(iconDisabled)
}
$copyNode.rmClass(iconDisabled) $copyNode.rmClass(iconDisabled)
if (node.nodeType === Node.ELEMENT_NODE) { if (node.nodeType === Node.ELEMENT_NODE) {
@@ -102,6 +107,7 @@ export default class Elements extends Tool {
<span class="icon icon-select select"></span> <span class="icon icon-select select"></span>
<span class="icon icon-eye show-detail"></span> <span class="icon icon-eye show-detail"></span>
<span class="icon icon-copy copy-node"></span> <span class="icon icon-copy copy-node"></span>
<span class="icon icon-delete delete-node"></span>
</div> </div>
<div class="dom-viewer-container"> <div class="dom-viewer-container">
<div class="dom-viewer"></div> <div class="dom-viewer"></div>
@@ -157,6 +163,7 @@ export default class Elements extends Tool {
.on('click', c('.select'), this._toggleSelect) .on('click', c('.select'), this._toggleSelect)
.on('click', c('.show-detail'), () => this._detail.show(this._curNode)) .on('click', c('.show-detail'), () => this._detail.show(this._curNode))
.on('click', c('.copy-node'), this._copyNode) .on('click', c('.copy-node'), this._copyNode)
.on('click', c('.delete-node'), this._deleteNode)
this._domViewer.on('select', this._setNode) this._domViewer.on('select', this._setNode)
@@ -164,6 +171,15 @@ export default class Elements extends Tool {
.domain('Overlay') .domain('Overlay')
.on('inspectNodeRequested', this._inspectNodeRequested) .on('inspectNodeRequested', this._inspectNodeRequested)
} }
_deleteNode = () => {
const node = this._curNode
if (node.parentNode) {
node.parentNode.removeChild(node)
}
this._back()
}
_copyNode = () => { _copyNode = () => {
const node = this._curNode const node = this._curNode

View File

@@ -14,6 +14,9 @@
.icon-copy { .icon-copy {
right: 23px; right: 23px;
} }
.icon-delete {
right: 46px;
}
} }
.dom-viewer-container { .dom-viewer-container {
@include overflow-auto(y); @include overflow-auto(y);

View File

@@ -211,6 +211,21 @@ export function isErudaEl(el) {
return false return false
} }
export function isChobitsuEl(el) {
while (el) {
let className = ''
if (el.getAttribute) {
className = el.getAttribute('class') || ''
}
if (contain(className, '__chobitsu-hide__')) {
return true
}
el = el.parentNode
}
return false
}
export const evalCss = evalCssUtil export const evalCss = evalCssUtil
export function classPrefix(str) { export function classPrefix(str) {

View File

@@ -222,9 +222,23 @@
.luna-dom-viewer-html-comment { .luna-dom-viewer-html-comment {
color: var(--comment-color); color: var(--comment-color);
} }
.luna-dom-viewer-tree-item {
&:hover {
.luna-dom-viewer-selection {
background: var(--contrast);
}
}
&.luna-dom-viewer-selected {
.luna-dom-viewer-selection { .luna-dom-viewer-selection {
background: var(--highlight); background: var(--highlight);
} }
}
&.luna-dom-viewer-selected:focus {
.luna-dom-viewer-selection {
background: var(--contrast);
}
}
}
.luna-dom-viewer-text-node { .luna-dom-viewer-text-node {
.luna-dom-viewer-key { .luna-dom-viewer-key {
color: var(--var-color); color: var(--var-color);

View File

@@ -1,9 +1,6 @@
body, html { body, html {
padding: 0; padding: 0;
margin: 0; margin: 0;
}
* {
font-family: 'Avenir Next', Avenir, 'Helvetica Neue', Helvetica, 'Franklin Gothic Medium', 'Franklin Gothic', 'ITC Franklin Gothic', Arial, sans-serif; font-family: 'Avenir Next', Avenir, 'Helvetica Neue', Helvetica, 'Franklin Gothic Medium', 'Franklin Gothic', 'ITC Franklin Gothic', Arial, sans-serif;
} }