Skip to content

Commit 49736ff

Browse files
committed
feat(SchemaOrgDebug)!: renamed from SchemaOrgInspector and functional
1 parent 4e841b0 commit 49736ff

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default defineConfig({
175175
text: 'Utility Components',
176176
items: [
177177
// to build
178-
{ text: 'SchemaOrgInspector 🔨', link: '/components/inspector' },
178+
{ text: 'SchemaOrgDebug 🔨', link: '/components/inspector' },
179179
],
180180
},
181181
],
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { defineComponent, h, nextTick, onMounted, ref } from 'vue'
2+
3+
export const SchemaOrgDebug = defineComponent({
4+
name: 'SchemaOrgDebug',
5+
props: {
6+
console: {
7+
type: Boolean,
8+
default: false,
9+
},
10+
},
11+
setup() {
12+
const schemaRaw = ref('')
13+
let observer: MutationObserver
14+
15+
onMounted(() => {
16+
nextTick(() => {
17+
let $el = document.querySelector('script[data-id="schema-org-graph"]')
18+
if (!$el)
19+
return
20+
21+
const fetchSchema = () => {
22+
$el = document.querySelector('script[data-id="schema-org-graph"]')
23+
schemaRaw.value = $el?.innerText
24+
}
25+
26+
// Create an observer instance linked to the callback function
27+
observer = new MutationObserver(fetchSchema)
28+
29+
// Start observing the target node for configured mutations
30+
observer.observe(document.body, {
31+
childList: true,
32+
characterData: true,
33+
attributes: true,
34+
subtree: true,
35+
})
36+
37+
fetchSchema()
38+
})
39+
})
40+
41+
onBeforeUnmount(() => {
42+
observer?.disconnect()
43+
})
44+
45+
return () => {
46+
return h('div', {
47+
style: {
48+
display: 'inline-block',
49+
},
50+
}, [h('div', {
51+
style: {
52+
backgroundColor: '#282839',
53+
color: '#c5c6c9',
54+
padding: '5px',
55+
borderRadius: '5px',
56+
width: '900px',
57+
height: '600px',
58+
overflowY: 'auto',
59+
boxShadow: '3px 4px 15px rgb(0 0 0 / 10%)',
60+
},
61+
}, [
62+
h('pre', { style: { textAlign: 'left' } }, schemaRaw.value),
63+
])])
64+
}
65+
},
66+
})

packages/schema-org/runtime/components/SchemaOrgInspector.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './nodes'
2-
export * from './SchemaOrgInspector'
2+
export * from './SchemaOrgDebug'

packages/schema-org/src/meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ export const schemaOrgAutoImports = [
3737
]
3838

3939
export const schemaOrgComponents = [
40-
'SchemaOrgInspector',
40+
'SchemaOrgDebug',
4141
...RootSchemas.map(s => `SchemaOrg${s}`),
4242
]

playgrounds/nuxt3/app.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ const nav = [
9595
</div>
9696
<NuxtPage />
9797
</div>
98+
<div>
99+
<div>
100+
<SchemaOrgDebug />
101+
</div>
102+
</div>
98103
</div>
99104
</div>
100105
</div>

0 commit comments

Comments
 (0)