Skip to content

Commit 212d231

Browse files
committed
Redesign block & content structure
1 parent 66d287d commit 212d231

File tree

6 files changed

+129
-110
lines changed

6 files changed

+129
-110
lines changed

iwsy/iwsy.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ const IWSY = (container, text) => {
151151
if (!block.element) {
152152
createBlock(block);
153153
}
154-
const content = script.content[item.content];
155-
const converter = new showdown.Converter();
156-
block.textPanel.innerHTML = converter.makeHtml(content.split(`%0a`).join(`\n`));
154+
for (const text of script.content) {
155+
if (text.name === item.content) {
156+
const converter = new showdown.Converter();
157+
block.textPanel.innerHTML =
158+
converter.makeHtml(text.content.split(`%0a`).join(`\n`));
159+
}
160+
}
157161
}
158162
}
159163
}

iwsy/resources/ecs/blocks.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
variable PropertyNames
2222
variable PropertyName
2323
variable SelectedBlock
24+
variable SavedIndex
2425
variable Message
2526
variable N
2627
variable NBlocks
@@ -93,16 +94,17 @@ Restart:
9394
set the text of EditButton to property `name` of Block
9495
create Link in Cell
9596
create DeleteBlock in Link
96-
set the style of DeleteBlock to `width:1em;margin:0.1em 0 0 0.2em`
97+
set the style of DeleteBlock to `width:1em;margin:0.2em 0 0 0.2em`
9798
set attribute `src` of DeleteBlock to `/resources/icon/stop.png`
9899
create Editor in Row
99100
set the style of Editor to `margin:0.5em;border:1px solid black;padding:0.2em;display:none`
100101
add 1 to N
101102
end
102103
on click EditButton
103104
begin
104-
gosub to SaveSelectedBlock
105-
put the index of EditButton into SelectedBlock
105+
put the index of EditButton into SavedIndex
106+
gosub to SaveSelectedBlock
107+
put SavedIndex into SelectedBlock
106108
put 0 into N
107109
while N is less than NBlocks
108110
begin
@@ -118,10 +120,10 @@ Restart:
118120
end
119121
index EditButton to SelectedBlock
120122
index Editor to SelectedBlock
123+
index SaveButton to SelectedBlock
121124
if style `display` of Editor is `none`
122125
begin
123126
set style `background` of EditButton to `lightgray`
124-
index SaveButton to SelectedBlock
125127
set style `display` of Editor to `block`
126128
put element SelectedBlock of Blocks into Block
127129
put the json count of PropertyNames into N
@@ -149,7 +151,6 @@ Restart:
149151
end
150152
else
151153
begin
152-
gosub to SaveSelectedBlock
153154
clear Editor
154155
set style `display` of Editor to `none`
155156
end
@@ -166,6 +167,7 @@ Restart:
166167
! Save the seleced block
167168
SaveSelectedBlock:
168169
if SelectedBlock is -1 return
170+
index EditButton to SelectedBlock
169171
put element SelectedBlock of Blocks into Block
170172
put 0 into N
171173
while N is less than the json count of PropertyNames
@@ -175,6 +177,7 @@ SaveSelectedBlock:
175177
set property PropertyName of Block to the text of PropertyValue
176178
add 1 to N
177179
end
180+
set the text of EditButton to property `name` of Block
178181
set element SelectedBlock of Blocks to Block
179182
set property `blocks` of Presentation to Blocks
180183

iwsy/resources/ecs/content.txt

Lines changed: 79 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
import div Panel and variable Presentation
66

77
div Editor
8+
div Title
9+
div Table
810
div Row
911
div Cell
10-
div Title
11-
table Table
12-
tr TR
13-
td TD
14-
span ItemNameSpan
1512
input ItemNameInput
1613
textarea TextArea
1714
button EditButton
@@ -24,10 +21,11 @@
2421
variable ItemNames
2522
variable ItemName
2623
variable SelectedItem
27-
variable Action
24+
variable SavedIndex
2825
variable Message
2926
variable N
30-
variable B
27+
variable NumItems
28+
variable Content
3129

3230
put -1 into SelectedItem
3331

@@ -44,7 +42,14 @@ Start:
4442

4543
Restart:
4644
put property `content` of Presentation into Items
47-
put the json keys of Items into ItemNames
45+
set ItemNames to array
46+
put 0 into N
47+
while N is less than the json count of Items
48+
begin
49+
put element N of Items into Item
50+
json add property `name` of Item to ItemNames
51+
add 1 to N
52+
end
4853

4954
clear Panel
5055
create Row in Panel
@@ -68,99 +73,89 @@ Restart:
6873
go to Restart
6974
end
7075

71-
put the json keys of Items into ItemNames
72-
put the json count of ItemNames into N
73-
set the elements of ItemNameSpan to N
74-
set the elements of ItemNameInput to N
75-
set the elements of EditButton to N
76-
set the elements of Editor to N
77-
set the elements of SaveButton to N
78-
set the elements of DeleteItem to N
79-
set the elements of TextArea to N
76+
put the json count of Items into NumItems
77+
set the elements of EditButton to NumItems
78+
set the elements of Editor to NumItems
79+
set the elements of SaveButton to NumItems
80+
set the elements of DeleteItem to NumItems
81+
set the elements of ItemNameInput to NumItems
82+
set the elements of TextArea to NumItems
8083
create Table in Panel
8184
set the style of Table to `width:100%`
82-
put 0 into B
83-
while B is less than the elements of EditButton
85+
put 0 into N
86+
while N is less than the elements of EditButton
8487
begin
85-
index EditButton to B
86-
index DeleteItem to B
87-
index ItemNameSpan to B
88-
index ItemNameInput to B
89-
put element B of ItemNames into ItemName
90-
create TR in Table
91-
create TD in TR
92-
set the style of TD to `width:8em;border:1px solid black`
93-
index ItemNameSpan to B
94-
create ItemNameSpan in TD
95-
set the content of ItemNameSpan to ItemName
96-
index ItemNameInput to B
97-
create ItemNameInput in TD
98-
set the style of ItemNameInput to `width:100%;display:none`
99-
set the content of ItemNameInput to ItemName
100-
create TD in TR
101-
set the style of TD to `border:1px solid black`
102-
index Editor to B
103-
create Row in TD
104-
set the style of Row to `display:flex`
105-
create EditButton in Row
106-
set the style of EditButton to `flex:1`
107-
set the text of EditButton to `Edit`
88+
index EditButton to N
89+
index DeleteItem to N
90+
index Editor to N
91+
index ItemNameInput to N
92+
put element N of Items into Item
93+
put property `name` of Item into ItemName
94+
create Row in Table
10895
create Cell in Row
109-
set the style of Cell to `width:1.4em;text-align:center`
96+
set the style of Cell to `width:100%;display:flex`
97+
create EditButton in Cell
98+
set the style of EditButton to `flex:1`
99+
set the text of EditButton to ItemName
110100
create Link in Cell
111101
create DeleteItem in Link
112-
set the style of DeleteItem to `width:1em;margin-top:0.1em`
102+
set the style of DeleteItem to `width:1em;margin:0.2em 0 0 0.2em`
113103
set attribute `src` of DeleteItem to `/resources/icon/stop.png`
114-
create Editor in TD
115-
set the style of Editor to `display:none`
116-
add 1 to B
104+
create Editor in Row
105+
set the style of Editor to `margin:0.5em;border:1px solid black;padding:0.2em;display:none`
106+
add 1 to N
117107
end
118108
on click EditButton
119109
begin
120-
gosub to SaveSelectedItem
121-
put the index of EditButton into SelectedItem
122-
put the text of EditButton into Action
110+
put the index of EditButton into SavedIndex
111+
gosub to SaveSelectedItem
112+
put SavedIndex into SelectedItem
123113
put 0 into N
124-
while N is less than the json count of ItemNames
114+
while N is less than NumItems
125115
begin
126-
index EditButton to N
127-
set style `background` of EditButton to ``
128-
set the text of EditButton to `Edit`
129-
index ItemNameSpan to N
130-
index ItemNameInput to N
131-
set the content of ItemNameSpan to the text of ItemNameInput
132-
set style `display` of ItemNameSpan to `inline`
133-
set style `display` of ItemNameInput to `none`
134-
index Editor to N
135-
set style `display` of Editor to `none`
116+
if N is not SelectedItem
117+
begin
118+
index EditButton to N
119+
set style `background` of EditButton to ``
120+
index Editor to N
121+
set style `display` of Editor to `none`
122+
clear Editor
123+
end
136124
add 1 to N
137125
end
138126
index EditButton to SelectedItem
139-
if Action is `Edit`
127+
index ItemNameInput to SelectedItem
128+
index TextArea to SelectedItem
129+
index SaveButton to SelectedItem
130+
index Editor to SelectedItem
131+
if style `display` of Editor is `none`
140132
begin
133+
put element SelectedItem of Items into Item
141134
set style `background` of EditButton to `lightgray`
142-
set the text of EditButton to `Close`
143-
index ItemNameSpan to SelectedItem
144-
index ItemNameInput to SelectedItem
145-
index TextArea to SelectedItem
146-
index SaveButton to SelectedItem
147-
set style `display` of ItemNameSpan to `none`
148-
set style `display` of ItemNameInput to `inline`
149-
index Editor to SelectedItem
135+
create Row in Editor
136+
set the style of Row to `display:flex`
137+
create Cell in Row
138+
set the style of Cell to `width:5em`
139+
set the content of Cell to `Name`
140+
create ItemNameInput in Row
141+
set the style of ItemNameInput to `flex:1`
142+
set the text of ItemNameInput to property `name` of Item
150143
set style `display` of Editor to `block`
151-
clear Editor
152144
create TextArea in Editor
153145
set the style of TextArea to `width:100%;max-width:100%;height:8em`
154-
put element SelectedItem of ItemNames into ItemName
155-
put property ItemName of Items into Item
156-
replace `%0a` with newline in Item
157-
set the content of TextArea to Item
146+
put property `content` of Item into Content
147+
replace `%0a` with newline in Content
148+
set the content of TextArea to Content
158149
create SaveButton in Editor
159150
set the style of SaveButton to `width:100%`
160151
set the text of SaveButton to `Save`
161152
on click SaveButton gosub to SaveSelectedItem
162153
end
163-
else gosub to SaveSelectedItem
154+
else
155+
begin
156+
clear Editor
157+
set style `display` of Editor to `none`
158+
end
164159
end
165160
on click DeleteItem
166161
begin
@@ -177,14 +172,15 @@ Restart:
177172
SaveSelectedItem:
178173
if SelectedItem is -1 return
179174
index ItemNameInput to SelectedItem
175+
index EditButton to SelectedItem
176+
put element SelectedItem of Items into Item
177+
set property `name` of Item to the text of ItemNameInput
178+
set the text of EditButton to the text of ItemNameInput
180179
index TextArea to SelectedItem
181-
put the content of TextArea into Item
182-
replace newline with `%0a` in Item
183-
set property ItemName of Items to Item
184-
if ItemNameInput is not ItemName json delete property ItemName of Items
185-
put ItemNameInput into ItemName
186-
set element SelectedItem of ItemNames to ItemName
187-
set property ItemName of Items to Item
180+
put the content of TextArea into Content
181+
replace newline with `%0a` in Content
182+
set property `content` of Item to Content
183+
set element SelectedItem of Items to Item
188184
set property `content` of Presentation to Items
189185

190186
! Tell the parent to refresh the script

iwsy/resources/ecs/scripted.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
button Save
1616
button Delete
1717
variable Name
18-
variable CurrentName
1918
variable Content
2019
variable Current
2120
variable Password

iwsy/resources/ecs/steps.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
variable Blocks
4646
variable Block
4747
variable Contents
48+
variable Content
4849
variable Target
4950
variable Duration
5051
variable URL
@@ -303,7 +304,6 @@ CreateNewStep:
303304
! Edit a single step
304305
EditStep:
305306
put property `blocks` of Presentation into Blocks
306-
put property `content` of Presentation into Contents
307307
set BlockNames to array
308308
put 0 into N
309309
while N is less than the json count of Blocks
@@ -312,7 +312,15 @@ EditStep:
312312
json add property `name` of Block to BlockNames
313313
add 1 to N
314314
end
315-
put the json keys of Contents into ContentNames
315+
put property `content` of Presentation into Contents
316+
set ContentNames to array
317+
put 0 into N
318+
while N is less than the json count of Contents
319+
begin
320+
put element N of Contents into Content
321+
json add property `name` of Content to ContentNames
322+
add 1 to N
323+
end
316324
put element SelectedStep of Steps into CurrentStep
317325

318326
clear Editor

0 commit comments

Comments
 (0)