vertical orientation for phones

This commit is contained in:
2024-11-09 11:26:42 -08:00
parent 3daf6b4dc2
commit e814ebfb02
3 changed files with 42 additions and 10 deletions

View File

@@ -51,6 +51,7 @@ document.addEventListener("keydown", (ev) => {
const LOADING = "module Loading\n" const LOADING = "module Loading\n"
let value = localStorage.code || LOADING; let value = localStorage.code || LOADING;
let initialVertical = localStorage.vertical == 'true'
// let result = document.getElementById("result")!; // let result = document.getElementById("result")!;
@@ -135,7 +136,7 @@ function Tabs() {
return h( return h(
"div", "div",
{ className: "tabPanel" }, { className: "tabPanel right" },
h("div", { className: "tabBar" }, Tab(RESULTS), Tab(JAVASCRIPT)), h("div", { className: "tabBar" }, Tab(RESULTS), Tab(JAVASCRIPT)),
h("div", { className: "tabBody" }, body) h("div", { className: "tabBody" }, body)
); );
@@ -152,7 +153,7 @@ const SAMPLES = [
"TypeClass.newt", "TypeClass.newt",
]; ];
function EditWrap() { function EditWrap({vertical, toggle}: {vertical: boolean, toggle: () => void}) {
const options = SAMPLES.map((value) => h("option", { value }, value)); const options = SAMPLES.map((value) => h("option", { value }, value));
const onChange = async (ev: ChangeEvent) => { const onChange = async (ev: ChangeEvent) => {
@@ -163,9 +164,10 @@ function EditWrap() {
} }
}; };
let d = vertical ? "M0 0 h20 v20 h-20 z M0 10 h20" : "M0 0 h20 v20 h-20 z M10 0 v20"
return h( return h(
"div", "div",
{ className: "tabPanel" }, { className: "tabPanel left" },
h( h(
"div", "div",
{ className: "tabBar" }, { className: "tabBar" },
@@ -174,17 +176,29 @@ function EditWrap() {
{ onChange }, { onChange },
h("option", { value: "" }, "choose sample"), h("option", { value: "" }, "choose sample"),
options options
) ),
h('div', {style: {flex: '1 1'}}),
h('button', {onClick: toggle},
h('svg', {width:20, height: 20},
h('path',{d,fill:'none',stroke:'black'})
)
)
), ),
h("div", { className: "tabBody" }, h(Editor, { initialValue: value })) h("div", { className: "tabBody" }, h(Editor, { initialValue: value }))
); );
} }
function App() { function App() {
let [vertical,setVertical] = useState(initialVertical)
let toggle = () => {
setVertical(!vertical)
localStorage.vertical = !vertical
}
let className = `wrapper ${vertical?"vertical":"horizontal"}`
return h( return h(
"div", "div",
{ className: "wrapper" }, { className },
h(EditWrap, {}), h(EditWrap, {vertical, toggle}),
h(Tabs, {}) h(Tabs, {})
); );
} }

View File

@@ -61,7 +61,7 @@ export let newtConfig: monaco.languages.LanguageConfiguration = {
export let newtTokens: monaco.languages.IMonarchLanguage = { export let newtTokens: monaco.languages.IMonarchLanguage = {
// Set defaultToken to invalid to see what you do not tokenize yet // Set defaultToken to invalid to see what you do not tokenize yet
defaultToken: "invalid", // defaultToken: "invalid",
keywords: [ keywords: [
"let", "let",
@@ -83,7 +83,7 @@ export let newtTokens: monaco.languages.IMonarchLanguage = {
tokenizer: { tokenizer: {
root: [ root: [
[ [
/[a-z_$][\w$]*/, /[a-z_$'][\w$]*/,
{ cases: { "@keywords": "keyword", "@default": "identifier" } }, { cases: { "@keywords": "keyword", "@default": "identifier" } },
], ],
[/[A-Z][\w\$]*/, "type.identifier"], [/[A-Z][\w\$]*/, "type.identifier"],

View File

@@ -8,16 +8,34 @@
#editor { #editor {
height: 100%; height: 100%;
} }
.wrapper { .wrapper.horizontal {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
height: 100%; height: 100%;
} }
.wrapper > div { .wrapper.horizontal > div {
flex: 1 1; flex: 1 1;
/* allow smaller than natural */ /* allow smaller than natural */
width: 100px; width: 100px;
} }
.wrapper.vertical {
display: flex;
flex-direction: column;
height: 100%;
}
.wrapper.vertical .tabPanel.left {
flex: .6 .6;
height: 100px;
}
.wrapper.vertical .tabPanel.right {
flex: .4 .4;
height: 100px;
}
.tabBar button {
border: none;
padding: none;
background: inherit;
}
.tabPanel { .tabPanel {
display: flex; display: flex;
flex-direction: column; flex-direction: column;