-
Notifications
You must be signed in to change notification settings - Fork 456
feat(gnoweb): change built-in playground and run views into features #5774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeronimoalbi
wants to merge
14
commits into
gnolang:playground2
Choose a base branch
from
jeronimoalbi:feat/gnoweb-playground-feature
base: playground2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1c303a9
feat: refactor playground and run views into features
jeronimoalbi 75baeb3
feat: change run feature to use component's copy button template
jeronimoalbi 9f30703
chore: fix docs
jeronimoalbi ca89afc
chore: rename playground's feature client adapter
jeronimoalbi 223d59b
chore: fix typos
jeronimoalbi 38a9c78
feat: check playground feat dependency values
jeronimoalbi d99869d
feat: check run feat dependency values
jeronimoalbi 53f6185
feat: fix decompression bomb attack vector in playground feature
jeronimoalbi 56dbb30
ci: make egnerate
jeronimoalbi 870cc7a
feat: change fork view to return error page on files read failure
jeronimoalbi 167d64c
feat: change fork view to fetch files async and limit size
jeronimoalbi 9682008
chore: remove template name when parsing
jeronimoalbi 7466039
feat: add `@gnoweb/js` alias for TS feature imports
jeronimoalbi 99dcec3
Merge branch 'playground2' into feat/gnoweb-playground-feature
jeronimoalbi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,22 +1,6 @@ | ||
| package components | ||
|
|
||
| // PlaygroundViewType identifies the playground feature view in | ||
| // layout-level switch cases (see layout_index.go). The data type | ||
| // and view constructor live in the playground feature package. | ||
| const PlaygroundViewType ViewType = "playground-view" | ||
|
|
||
| type PlaygroundData struct { | ||
| // InitialCode is pre-filled code (e.g. from fork) | ||
| InitialCode string | ||
| // ForkFrom is the package path this was forked from | ||
| ForkFrom string | ||
| // Remote is the RPC endpoint | ||
| Remote string | ||
| // ChainId is the current chain ID | ||
| ChainId string | ||
| // Domain is the node domain | ||
| Domain string | ||
| // DefaultFile is the filename that should be focus on first load | ||
| DefaultFile string | ||
| } | ||
|
|
||
| func PlaygroundView(data PlaygroundData) *View { | ||
| return NewTemplateView(PlaygroundViewType, "renderPlayground", data) | ||
| } |
This file contains hidden or 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,23 +1,6 @@ | ||
| package components | ||
|
|
||
| import "path" | ||
|
|
||
| // RunViewType identifies the run feature view in layout-level switch | ||
| // cases (see layout_index.go). The data type and view constructor live | ||
| // in the run feature package. | ||
| const RunViewType ViewType = "run-view" | ||
|
|
||
| // RunData holds the data for the maketx-run scratchpad view. | ||
| type RunData struct { | ||
| PkgPath string // full path, e.g. "gno.land/r/demo/boards" | ||
| Domain string // e.g. "gno.land" | ||
| Remote string // e.g. "https://rpc.gno.land:443" | ||
| ChainId string // e.g. "portal-loop" | ||
| } | ||
|
|
||
| // PkgAlias returns the last segment of the import path, used as the package alias | ||
| // in the generated template code (e.g. "boards" from "gno.land/r/demo/boards"). | ||
| func (d RunData) PkgAlias() string { | ||
| return path.Base(d.PkgPath) | ||
| } | ||
|
|
||
| func RunView(data RunData) *View { | ||
| return NewTemplateView(RunViewType, "renderRun", data) | ||
| } |
This file contains hidden or 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,30 @@ | ||
| package playground | ||
|
|
||
| import ( | ||
| "html/template" | ||
| "io" | ||
|
|
||
| "github.com/gnolang/gno/gno.land/pkg/gnoweb/components" | ||
| ) | ||
|
|
||
| type playgroundComponent struct { | ||
| tmpl *template.Template | ||
| name string | ||
| data any | ||
| } | ||
|
|
||
| func (c *playgroundComponent) Render(w io.Writer) error { | ||
| return c.tmpl.ExecuteTemplate(w, c.name, c.data) | ||
| } | ||
|
|
||
| // NewPageView wraps the playground template. | ||
| func NewPageView(data PlaygroundData) *components.View { | ||
| return &components.View{ | ||
| Type: components.PlaygroundViewType, | ||
| Component: &playgroundComponent{ | ||
| tmpl: PageTemplate, | ||
| name: "renderPage", | ||
| data: data, | ||
| }, | ||
| } | ||
| } |
This file contains hidden or 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,7 @@ | ||
| // Package playground implements the gnoweb playground feature. | ||
| // | ||
| // It serves the standalone playground page at /_/play, the fork view | ||
| // (?fork on a package or realm URL — concatenates the source files | ||
| // into the playground), and the JSON API endpoints used by the | ||
| // playground UI (/_/api/eval, /_/api/funcs). | ||
| package playground |
This file contains hidden or 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,69 @@ | ||
| package playground | ||
|
|
||
| import ( | ||
| "context" | ||
| "log/slog" | ||
|
|
||
| "github.com/gnolang/gno/gnovm/pkg/doc" | ||
| ) | ||
|
|
||
| // ClientAdapter is the subset of the gnoweb chain-client interface that | ||
| // the playground feature consumes. Declared locally so feature/playground | ||
| // does not import the gnoweb package. The signatures match the | ||
| // corresponding methods on gnoweb.ClientAdapter so a *gnoweb.MockClient | ||
| // or *gnoweb.rpcClient satisfies this contract through a thin adapter | ||
| // wired in at construction time. | ||
| type ClientAdapter interface { | ||
| // ListFiles is used by the fork view to enumerate package sources. | ||
| ListFiles(ctx context.Context, path string) ([]string, error) | ||
|
|
||
| // File is used by the fork view to read each source file. | ||
| File(ctx context.Context, path, filename string) ([]byte, error) | ||
|
|
||
| // Doc is used by the funcs API to enumerate exported functions. | ||
| Doc(ctx context.Context, path string) (*doc.JSONDocumentation, error) | ||
|
|
||
| // Eval is used by the eval API to run an expression against a | ||
| // realm via vm/qeval. | ||
| Eval(ctx context.Context, data string) ([]byte, error) | ||
| } | ||
|
|
||
| // Deps gathers the dependencies the playground Handler needs. | ||
| type Deps struct { | ||
| Client ClientAdapter | ||
|
|
||
| // Logger falls back to slog.Default(). | ||
| Logger *slog.Logger | ||
|
|
||
| // Domain is the chain domain (e.g. "gno.land"). | ||
| Domain string | ||
|
|
||
| // Remote is the RPC endpoint surfaced to the playground UI so it | ||
| // can show the user which node it is talking to. | ||
| Remote string | ||
|
|
||
| // ChainId is the active chain id surfaced to the playground UI. | ||
| ChainId string | ||
| } | ||
|
|
||
| // Handler owns the playground feature state. | ||
| type Handler struct { | ||
| deps Deps | ||
| limiter *rateLimiter | ||
| } | ||
|
|
||
| // New validates required deps and returns a Handler. | ||
| func New(deps Deps) *Handler { | ||
| if deps.Client == nil { | ||
| panic("playground.New: Client is required") | ||
| } | ||
|
|
||
| if deps.Logger == nil { | ||
| deps.Logger = slog.Default() | ||
| } | ||
|
|
||
| return &Handler{ | ||
| deps: deps, | ||
| limiter: newRateLimiter(evalBurstSize, evalRefillInterval), | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validation is asymmetric here no? Client panics if nil, but empty Domain / Remote / ChainId slide through silently even though they all end up rendered into the page. Not necessarily wrong (maybe empty defaults are legitimate in dev?), just felt inconsistent enough to flag. Either validate them all or drop a one-liner saying empties are intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 38a9c78 and also for run feature in d99869d