This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add component inspector to support component tree navigable (#200)
--------- Co-authored-by: webfansplz <308241863@qq.com>
- Loading branch information
1 parent
cd9e534
commit 3e730ae
Showing
19 changed files
with
265 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
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { ComponentWalker, InstanceMap } from './tree' | ||
export { getInstanceState, processSetupState, getInstanceDetails, getSetupStateInfo } from './data' | ||
export { getInstanceOrVnodeRect, getRootElementsFromComponentInstance } from './el' | ||
export { getInstanceName } from './util' |
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
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
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,48 @@ | ||
import type { ComponentInternalInstance } from 'vue' | ||
|
||
export function getComponentTypeName(options: any) { | ||
return options.name || options._componentTag || options.__vdevtools_guessedName || options.__name | ||
} | ||
|
||
function saveComponentName(instance: ComponentInternalInstance, key: string) { | ||
return key | ||
} | ||
|
||
export function getComponentFileName(options: any) { | ||
const file = options.__file // injected by vite | ||
// TODO: classify | ||
if (file) { | ||
const filename = options.__file?.match(/\/?([^/]+?)(\.[^/.]+)?$/)?.[1] | ||
return filename ?? file | ||
} | ||
// return classify(basename(file, '.vue')) | ||
} | ||
|
||
/** | ||
* Get the appropriate display name for an instance. | ||
* | ||
* @param {Vue} instance | ||
* @return {String} | ||
*/ | ||
export function getInstanceName(instance: any) { | ||
const name = getComponentTypeName(instance.type || {}) | ||
if (name) | ||
return name | ||
if (instance.root === instance) | ||
return 'Root' | ||
for (const key in instance.parent?.type?.components) { | ||
if (instance.parent.type.components[key] === instance.type) | ||
return saveComponentName(instance, key) | ||
} | ||
|
||
for (const key in instance.appContext?.components) { | ||
if (instance.appContext.components[key] === instance.type) | ||
return saveComponentName(instance, key) | ||
} | ||
|
||
const fileName = getComponentFileName(instance.type || {}) | ||
if (fileName) | ||
return fileName | ||
|
||
return 'Anonymous Component' | ||
} |
Oops, something went wrong.