Skip to content

Commit 4808d16

Browse files
committed
Added style, fixed reset bug
1 parent cb436bb commit 4808d16

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

store-editor.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"encoding/xml"
1313

14+
"github.com/aymerick/douceur/parser"
1415
"github.com/dave/flux"
1516
"github.com/dave/jennifer/jen"
1617
)
@@ -20,7 +21,7 @@ const defaultText = `
2021
<p>
2122
Enter HTML here and the vecty syntax will appear opposite.
2223
</p>
23-
<p class="foo bar baz">
24+
<p class="foo bar baz" style="foo:bar; baz: qux!important;">
2425
<a href="href" id="id" data-foo="bar" foo="bar">Props</a>
2526
<input type="checkbox" checked="true" autofocus="true" />
2627
</p>
@@ -110,6 +111,21 @@ func (s *EditorStore) transcode() error {
110111
g.Qual("github.com/gopherjs/vecty", "Markup").CustomFunc(call, func(g *jen.Group) {
111112
for _, v := range token.Attr {
112113
switch {
114+
case v.Name.Local == "style":
115+
css, err := parser.ParseDeclarations(v.Value)
116+
if err != nil {
117+
outer = err
118+
return
119+
}
120+
for _, dec := range css {
121+
if dec.Important {
122+
dec.Value += "!important"
123+
}
124+
g.Qual("github.com/gopherjs/vecty", "Style").Call(
125+
jen.Lit(dec.Property),
126+
jen.Lit(dec.Value),
127+
)
128+
}
113129
case v.Name.Local == "class":
114130
g.Qual("github.com/gopherjs/vecty", "Class").CallFunc(func(g *jen.Group) {
115131
classes := strings.Split(v.Value, " ")

view-editor.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ type Editor struct {
1919
editor ace.Editor
2020
id, lang string
2121
change func(string)
22+
readonly bool
2223
}
2324

24-
func NewEditor(app *App, id, lang, text string, change func(string)) *Editor {
25+
func NewEditor(app *App, id, lang, text string, readonly bool, change func(string)) *Editor {
2526
v := &Editor{
26-
app: app,
27-
lang: lang,
28-
id: id,
29-
change: change,
30-
Text: text,
27+
app: app,
28+
lang: lang,
29+
id: id,
30+
change: change,
31+
Text: text,
32+
readonly: readonly,
3133
}
3234
return v
3335
}
@@ -58,7 +60,7 @@ func (v *Editor) Mount() {
5860
}
5961

6062
func (v *Editor) Render() vecty.ComponentOrHTML {
61-
if v.editor.Object != nil && v.Text != v.editor.GetValue() {
63+
if !v.readonly && v.editor.Object != nil && v.Text != v.editor.GetValue() {
6264
// only update the editor if the text is changed
6365
v.editor.SetValue(v.Text)
6466
v.editor.ClearSelection()

view-page.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (v *Page) renderLeft() *vecty.HTML {
5858
prop.ID("left"),
5959
vecty.Class("split"),
6060
),
61-
NewEditor(v.app, "html-editor", "html", v.app.Editor.Html(), func(value string) {
61+
NewEditor(v.app, "html-editor", "html", v.app.Editor.Html(), true, func(value string) {
6262
v.app.Dispatch(&UserChangedTextAction{
6363
Text: value,
6464
})
@@ -72,6 +72,6 @@ func (v *Page) renderRight() *vecty.HTML {
7272
prop.ID("right"),
7373
vecty.Class("split"),
7474
),
75-
NewEditor(v.app, "code-editor", "golang", v.app.Editor.Code(), nil),
75+
NewEditor(v.app, "code-editor", "golang", v.app.Editor.Code(), false, nil),
7676
)
7777
}

0 commit comments

Comments
 (0)