Skip to content

Commit dc93ccc

Browse files
committed
Added a post about 7GUIs.
1 parent d70de1e commit dc93ccc

File tree

16 files changed

+344
-80
lines changed

16 files changed

+344
-80
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
nodejs 20.10.0
22
mint 0.26.0
3+
yarn 1.22.19

assets/examples/7GUIs/TemperatureConverter.mint

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ type Field {
66
}
77

88
component Main {
9-
state celsius : Field = Field.Initial("")
109
state fahrenheit : Field = Field.Initial("")
10+
state celsius : Field = Field.Initial("")
1111

1212
style root {
1313
white-space: nowrap;
@@ -25,14 +25,12 @@ component Main {
2525
}
2626

2727
fun toFahrenheit (value : String) {
28-
Number.fromString(value)
29-
|> Maybe.map(
28+
Maybe.map(Number.fromString(value),
3029
(celsius : Number) { {celsius, Math.round(celsius * (9 / 5) + 32)} })
3130
}
3231

3332
fun toCelsius (value : String) {
34-
Number.fromString(value)
35-
|> Maybe.map(
33+
Maybe.map(Number.fromString(value),
3634
(fahrenheit : Number) {
3735
{fahrenheit, Math.round((fahrenheit - 32) * (5 / 9))}
3836
})
@@ -56,19 +54,15 @@ component Main {
5654

5755
if String.isEmpty(cleaned) {
5856
next { celsius: Field.Initial(value) }
57+
} else if let Just({celsius, fahrenheit}) = toFahrenheit(cleaned) {
58+
next {
59+
fahrenheit: Field.Valid(Number.toString(fahrenheit)),
60+
celsius: Field.Valid(Number.toString(celsius))
61+
}
5962
} else {
60-
case toFahrenheit(cleaned) {
61-
Just({celsius, fahrenheit}) =>
62-
next {
63-
fahrenheit: Field.Valid(Number.toString(fahrenheit)),
64-
celsius: Field.Valid(Number.toString(celsius))
65-
}
66-
67-
=>
68-
next {
69-
fahrenheit: Field.OutOfSync(getValue(fahrenheit)),
70-
celsius: Field.Invalid(cleaned)
71-
}
63+
next {
64+
fahrenheit: Field.OutOfSync(getValue(fahrenheit)),
65+
celsius: Field.Invalid(cleaned)
7266
}
7367
}
7468
}
@@ -82,19 +76,15 @@ component Main {
8276

8377
if String.isEmpty(cleaned) {
8478
next { fahrenheit: Field.Initial(value) }
79+
} else if let Just({fahrenheit, celsius}) = toCelsius(cleaned) {
80+
next {
81+
fahrenheit: Field.Valid(Number.toString(fahrenheit)),
82+
celsius: Field.Valid(Number.toString(celsius))
83+
}
8584
} else {
86-
case toCelsius(cleaned) {
87-
Just({fahrenheit, celsius}) =>
88-
next {
89-
fahrenheit: Field.Valid(Number.toString(fahrenheit)),
90-
celsius: Field.Valid(Number.toString(celsius))
91-
}
92-
93-
=>
94-
next {
95-
celsius: Field.OutOfSync(getValue(celsius)),
96-
fahrenheit: Field.Invalid(cleaned)
97-
}
85+
next {
86+
celsius: Field.OutOfSync(getValue(celsius)),
87+
fahrenheit: Field.Invalid(cleaned)
9888
}
9989
}
10090
}

assets/ide.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Ide.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ const debounce = (callback, wait) => {
2323
};
2424

2525
export default class Ide {
26-
constructor({orientation, onChange, endpoint, value, base, previewHeight} = params) {
26+
constructor({orientation, onChange, endpoint, value, base, previewHeight, editorHeight} = params) {
2727
this.decorations = {};
2828
this.value = value;
2929

30-
this.setupDom(base, orientation, previewHeight);
30+
this.setupDom(base, orientation, previewHeight, editorHeight);
3131
this.setupEditor(onChange);
3232
this.setupClient(endpoint);
3333
}
3434

35-
setupDom(element, orientation, previewHeight) {
35+
setupDom(element, orientation, previewHeight, editorHeight) {
3636
const shadow = element.attachShadow({ mode: 'closed' });
3737

3838
let statusBarStyles = "";
@@ -42,7 +42,7 @@ export default class Ide {
4242
if (orientation == "vertical") {
4343
ideStyles = `
4444
grid-template-areas: "status" "editor" "preview";
45-
grid-template-rows: auto 1fr ${previewHeight};
45+
grid-template-rows: auto ${editorHeight} ${previewHeight};
4646
`;
4747

4848
statusBarStyles = `

source/Components/Ide.mint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ component Ide {
88
// The height of the preview.
99
property previewHeight : String = "1fr"
1010

11+
// The height of the editor.
12+
property editorHeight : String = "1fr"
13+
1114
// Whether or not the component is bordered.
1215
property bordered : Bool = false
1316

@@ -30,6 +33,7 @@ component Ide {
3033
#{this}.ide = new Ide({
3134
previewHeight: #{previewHeight},
3235
endpoint: #{@SANDBOX_ENDPOINT},
36+
editorHeight: #{editorHeight},
3337
orientation: #{orientation},
3438
onChange: #{onChange},
3539
value: #{value},

source/Components/SimpleIde.mint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ component SimpleIde {
55
// The height of the preview.
66
property previewHeight : String = "1fr"
77

8+
// The height of the editor.
9+
property editorHeight : String = "1fr"
10+
811
// The project to edit.
912
property contents : String
1013

1114
// Renders the component.
1215
fun render : Html {
1316
<Ide
1417
previewHeight={previewHeight}
18+
editorHeight={editorHeight}
1519
onChange={Promise.never1}
1620
orientation={orientation}
1721
bordered={true}

source/Data/Posts.mint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Data {
2+
const POSTS = defer { "7GUIs" => Posts.SEVEN_GUIS }
3+
}

source/Extra/ContentInstrumenter.mint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module ContentInstrumenter {
5252
fun instrument (html : Html, skipAnchors : Bool = false) : Html {
5353
VNode.walk(html,
5454
(vnode : VNode) {
55-
if `!#{vnode}.instrumented` {
55+
if `#{vnode} && !#{vnode}.instrumented` {
5656
case decode VNode.type(vnode) as String {
5757
Ok("h2") =>
5858
if skipAnchors {

source/Extra/VNode.mint

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ module VNode {
100100
fun walk (vnode : Html, function : Function(VNode, a)) : Html {
101101
`
102102
(() => {
103-
if (Array.isArray(#{vnode})) {
103+
if (#{vnode} === null || #{vnode} === undefined) {
104+
} else if (Array.isArray(#{vnode})) {
104105
#{vnode}.forEach((item) => #{walk}(item, #{function}))
105106
} else {
106107
if (typeof #{vnode} !== "string") {

source/Main.mint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ component Main {
5959
userStatus={UserStatus.Initial}
6060
/> or <Loader/>
6161

62+
Article(news, contents) =>
63+
<Pages.News.Page news={news} contents={contents}/>
64+
65+
Articles(news, posts) => <Pages.News.Index news={news} posts={posts}/>
6266
ExampleIndex(data) => <Pages.Examples.Index data={data}/> or <Loader/>
6367
FeatureMatrix => <Pages.FeatureMatrix/> or <Loader/>
6468
FromIndex(data) => <Pages.From.Index data={data}/>

0 commit comments

Comments
 (0)