@@ -5,13 +5,26 @@ import {
5
5
Box ,
6
6
Button ,
7
7
ButtonGroup ,
8
+ Flash ,
8
9
} from "@primer/react" ;
9
10
import "./index.css" ;
10
11
11
12
import initPomsky , { PomskyResult , compile } from "pomsky-wasm" ;
12
13
import { memo , useEffect , useState } from "react" ;
13
14
import pomskyWASM from "./pomsky-wasm.json" ;
14
15
16
+ import Editor from "./Editor" ;
17
+ import Show from "./Show" ;
18
+
19
+ function findRowColContext ( str : string , start : number ) {
20
+ const previousLines = str . slice ( 0 , start ) . split ( "\n" ) ;
21
+ const row = previousLines . length ;
22
+ const column = ( previousLines [ previousLines . length - 1 ] ?? "" ) . length + 1 ;
23
+ const context = str . split ( "\n" ) [ previousLines . length ] ;
24
+
25
+ return { row, column, context } ;
26
+ }
27
+
15
28
export default memo ( function ( props : FileBlockProps ) {
16
29
const {
17
30
context,
@@ -20,6 +33,8 @@ export default memo(function (props: FileBlockProps) {
20
33
onUpdateMetadata,
21
34
onUpdateContent,
22
35
BlockComponent,
36
+ isEditable,
37
+ originalContent,
23
38
} = props ;
24
39
const language = Boolean ( context . path )
25
40
? getLanguageFromFilename ( context . path )
@@ -49,21 +64,21 @@ export default memo(function (props: FileBlockProps) {
49
64
> ( "JavaScript" ) ;
50
65
51
66
const [ pomskyResult , setPomskyResult ] = useState < PomskyResult | null > ( ) ;
52
-
67
+ const [ didError , setDidError ] = useState ( false ) ;
53
68
useEffect ( ( ) => {
54
- if ( didInit ) setPomskyResult ( compile ( content , flavor . toLowerCase ( ) ) ) ;
69
+ if ( didInit ) {
70
+ const result = compile ( content , flavor . toLowerCase ( ) ) ;
71
+ console . debug ( result ) ;
72
+ setPomskyResult ( result ) ;
73
+ setDidError ( result ?. output == null ) ;
74
+ }
55
75
} , [ didInit , content , flavor ] ) ;
56
76
57
77
return (
58
- < Box
59
- position = "relative"
60
- display = "flex"
61
- flexDirection = "column"
62
- width = "100%"
63
- height = "100%"
64
- >
78
+ < Box className = "pomsky-viewer" >
65
79
< Show when = { isPomsky } >
66
80
< Box
81
+ className = "header"
67
82
borderColor = "border.default"
68
83
borderWidth = { 1 }
69
84
borderStyle = "solid"
@@ -73,10 +88,8 @@ export default memo(function (props: FileBlockProps) {
73
88
borderRight = "hidden"
74
89
p = { 2 }
75
90
bg = "canvas.subtle"
76
- display = "flex"
77
- minHeight = { 48 }
78
91
>
79
- < ButtonGroup sx = { { display : "flex" , alignItems : "center" } } >
92
+ < ButtonGroup >
80
93
< Button
81
94
onClick = { ( ) => setTab ( "pomsky" ) }
82
95
disabled = { tab === "pomsky" }
@@ -147,72 +160,56 @@ export default memo(function (props: FileBlockProps) {
147
160
</ ActionList >
148
161
</ ActionMenu . Overlay >
149
162
</ ActionMenu >
163
+ < Show when = { didError } > Error!</ Show >
150
164
</ Box >
151
165
< Show when = { tab === "pomsky" } >
152
- < textarea
153
- className = "content"
154
- spellCheck = "false"
155
- value = { content }
156
- onChange = { ( event ) => {
157
- onUpdateContent ( event . target . value ) ;
166
+ < Editor
167
+ text = { originalContent }
168
+ onChange = { ( text ) => {
169
+ onUpdateContent ( text ) ;
158
170
} }
159
171
/>
160
- { /* <BlockComponent
161
- block={{
162
- owner: "githubnext",
163
- repo: "blocks-examples",
164
- id: "code-block",
165
- }}
166
- /> */ }
167
172
</ Show >
168
173
< Show when = { tab === "regex" } >
169
174
< Show when = { didInit } >
170
175
< pre className = "content" >
171
176
< code >
172
- < Show
173
- when = {
174
- pomskyResult &&
175
- pomskyResult ?. diagnostics . length > 0
176
- }
177
- >
178
- { JSON . stringify (
179
- pomskyResult ?. diagnostics ,
180
- null ,
181
- "\t"
182
- ) }
183
- </ Show >
184
- < Show
185
- when = {
186
- pomskyResult &&
187
- pomskyResult ?. diagnostics . length === 0
188
- }
189
- >
190
- { pomskyResult ?. output }
177
+ < Show when = { didError } >
178
+ < Box p = { 3 } >
179
+ < Flash variant = "danger" >
180
+ { JSON . stringify (
181
+ pomskyResult ?. diagnostics ,
182
+ null ,
183
+ "\t"
184
+ ) }
185
+ </ Flash >
186
+ </ Box >
191
187
</ Show >
188
+ < Show when = { ! didError } > { pomskyResult ?. output } </ Show >
192
189
</ code >
193
190
</ pre >
194
191
</ Show >
195
192
< Show when = { ! didInit } >
196
- < Box p = { 3 } > Pomsky WASM is still initializing.</ Box >
193
+ < Box p = { 3 } >
194
+ < Flash variant = "warning" >
195
+ Pomsky WASM is still initializing.
196
+ </ Flash >
197
+ </ Box >
197
198
</ Show >
198
199
</ Show >
199
200
</ Show >
200
201
< Show when = { ! isPomsky } >
201
202
< Box p = { 3 } >
202
- < code > { context . file } </ code > is not Pomsky code.
203
- < br />
204
- This block only works on files ending with < code >
205
- .pom
206
- </ code > or < code > .pomsky</ code > .
203
+ < Flash variant = "danger" >
204
+ < code > { context . file } </ code > is not Pomsky code.
205
+ < br />
206
+ This block only works on files ending with < code >
207
+ .pom
208
+ </ code > { " " }
209
+ or < code > .pomsky</ code > .
210
+ </ Flash >
207
211
</ Box >
208
212
</ Show >
209
213
</ Box >
210
214
) ;
211
215
} ) ;
212
-
213
- function Show ( props : {
214
- when : boolean | any ;
215
- children ?: null | string | JSX . Element | JSX . Element [ ] ;
216
- } ) {
217
- return < > { props . when ? props . children : null } </ > ;
218
- }
0 commit comments