-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to view source and edit components (#169)
* Add ability to view source and edit components * Add inspect page * Fix href issue * Fix comments * Fix widget path not being passed on gateway * Fix widget path in dependencies
- Loading branch information
1 parent
847dfe3
commit a70a2e2
Showing
8 changed files
with
299 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const src = props.src; | ||
const code = props.code ?? Social.get(src); | ||
|
||
const dependencyMatch = | ||
code && code.matchAll(/<Widget[\s\S]*?src=.*?"(.+)"[\s\S]*?\/>/g); | ||
let dependencySources = [...(dependencyMatch || [])] | ||
.map((r) => r[1]) | ||
.filter((r) => !!r); | ||
dependencySources = dependencySources | ||
.filter((r, i) => dependencySources.indexOf(r) === i && r !== "(.+)") | ||
.map((src) => { | ||
const parts = src.split("/"); | ||
return { src, accountId: parts[0], widgetName: parts[2] }; | ||
}); | ||
|
||
const { href } = VM.require("buildhub.near/widget/lib.url") || { | ||
href: () => {}, | ||
}; | ||
|
||
return ( | ||
<> | ||
{dependencySources.map((c, i) => ( | ||
<div key={c.src}> | ||
<Widget | ||
src="mob.near/widget/ComponentSearch.Item" | ||
props={{ | ||
link: `/${c.src}`, | ||
accountId: c.accountId, | ||
widgetName: c.widgetName, | ||
extraButtons: ({ widgetPath }) => ( | ||
<Link | ||
className="btn btn-outline-secondary" | ||
//href={`#/mob.near/widget/WidgetSource?src=${widgetPath}`} | ||
to={href({ | ||
widgetSrc: "buildhub.near/widget/app", | ||
params: { | ||
page: "inspect", | ||
widgetPath: widgetPath, | ||
}, | ||
})} | ||
> | ||
Source | ||
</Link> | ||
), | ||
}} | ||
/> | ||
</div> | ||
))} | ||
</> | ||
); |
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,26 @@ | ||
const src = props.src ?? "mob.near/widget/WidgetSource"; | ||
const blockHeight = props.blockHeight; | ||
const [accountId, widget, widgetName] = src.split("/"); | ||
|
||
const code = Social.get(src, blockHeight); | ||
|
||
const text = ` | ||
\`\`\`jsx | ||
${code} | ||
\`\`\` | ||
`; | ||
|
||
return ( | ||
<> | ||
<Widget | ||
src="mob.near/widget/WidgetMetadata" | ||
props={{ accountId, widgetName, expanded: true }} | ||
/> | ||
<Markdown text={text} /> | ||
<h3>Dependencies</h3> | ||
<Widget | ||
src="buildhub.near/widget/inspect.WidgetDependencies" | ||
props={{ src, code }} | ||
/> | ||
</> | ||
); |
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,33 @@ | ||
const StyledWidgetSource = styled.div` | ||
pre { | ||
margin: 1rem 0; | ||
div { | ||
border-radius: 1rem; | ||
} | ||
} | ||
h3 { | ||
color: var(--text-color, #fff); | ||
margin-bottom: 1rem; | ||
} | ||
.text-truncate { | ||
color: var(--text-color, #fff); | ||
} | ||
span { | ||
color: var(--text-color, #fff); | ||
} | ||
`; | ||
|
||
return ( | ||
<StyledWidgetSource className="container-xl my-3" data-bs-theme="dark"> | ||
<Widget | ||
src="buildhub.near/widget/inspect.WidgetSource" | ||
props={{ | ||
src: props.widgetPath, | ||
}} | ||
loading="" | ||
/> | ||
</StyledWidgetSource> | ||
); |
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