Storybook: Inspection tool - support for popups added
This commit is contained in:
parent
cbaf1b8a78
commit
b87231e14b
|
@ -173,28 +173,36 @@ ApplicationWindow {
|
|||
})
|
||||
}
|
||||
|
||||
function activateInspection(item) {
|
||||
inspectionWindow.inspect(item)
|
||||
inspectionWindow.show()
|
||||
inspectionWindow.requestActivate()
|
||||
}
|
||||
|
||||
onInspectClicked: {
|
||||
const getItems = typeName =>
|
||||
InspectionUtils.findItemsByTypeName(
|
||||
viewLoader.item, typeName)
|
||||
|
||||
const items = [
|
||||
...getItems(root.currentPage),
|
||||
...getItems("Custom" + root.currentPage)
|
||||
]
|
||||
|
||||
if (items.length === 0) {
|
||||
console.warn(`Item of type "${root.currentPage}" not found. Nothing to inspect.`)
|
||||
return
|
||||
}
|
||||
|
||||
const lca = InspectionUtils.lowestCommonAncestor(
|
||||
items, viewLoader.item)
|
||||
|
||||
inspectionWindow.inspect(lca.parent.contentItem === lca
|
||||
? lca.parent : lca)
|
||||
inspectionWindow.show()
|
||||
inspectionWindow.requestActivate()
|
||||
if (lca) {
|
||||
activateInspection(lca.parent.contentItem === lca
|
||||
? lca.parent : lca)
|
||||
return
|
||||
}
|
||||
|
||||
if (Overlay.overlay.children.length > 0) {
|
||||
activateInspection(Overlay.overlay.children[0])
|
||||
return
|
||||
}
|
||||
|
||||
nothingToInspectDialog.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,6 +253,26 @@ ApplicationWindow {
|
|||
id: inspectionWindow
|
||||
}
|
||||
|
||||
Dialog {
|
||||
id: nothingToInspectDialog
|
||||
|
||||
anchors.centerIn: Overlay.overlay
|
||||
width: contentItem.implicitWidth + leftPadding + rightPadding
|
||||
|
||||
title: "No items to inspect found"
|
||||
standardButtons: Dialog.Ok
|
||||
modal: true
|
||||
|
||||
contentItem: Label {
|
||||
text: `
|
||||
Tips:
|
||||
• For inline components use naming convention of adding
|
||||
"Custom" at the begining (like Custom${root.currentPage})
|
||||
• For popups set closePolicy to "Popup.NoAutoClose""
|
||||
`
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: figmaWindow
|
||||
|
||||
|
|
|
@ -81,6 +81,9 @@ QtObject {
|
|||
}
|
||||
|
||||
function lowestCommonAncestor(items, commonAncestor) {
|
||||
if (items.length === 0)
|
||||
return null
|
||||
|
||||
const paths = items.map(item => pathToAncestor(item, commonAncestor))
|
||||
|
||||
let candidate = null
|
||||
|
|
Loading…
Reference in New Issue