1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < script src ="flowquery.min.js "> </ script >
7+ < title > FlowQuery</ title >
8+ < style >
9+ body {
10+ display : flex;
11+ flex-direction : column;
12+ align-items : center;
13+ justify-content : center;
14+ height : 100vh ;
15+ margin : 0 ; /* Prevent unexpected scroll issues */
16+ padding : 0 ;
17+ box-sizing : border-box;
18+ }
19+
20+ # input {
21+ margin-top : 5px ;
22+ width : 100% ;
23+ height : 300px ;
24+ font-family : monospace;
25+ resize : none;
26+ box-sizing : border-box; /* Include padding/border in width/height */
27+ }
28+
29+ # output {
30+ margin-top : 5px ;
31+ width : 100% ;
32+ flex-grow : 1 ;
33+ overflow-y : auto;
34+ font-family : monospace;
35+ box-sizing : border-box;
36+ max-height : calc ( 100vh - 300px - 5px ) ; /* Prevent excessive growth */
37+ }
38+ </ style >
39+ < script >
40+ function createTable ( results ) {
41+ const table = document . createElement ( "table" ) ;
42+
43+ if ( results . length === 0 ) return table ;
44+
45+ const headerRow = document . createElement ( "tr" ) ;
46+ Object . entries ( results [ 0 ] ) . forEach ( ( [ key , _ ] ) => {
47+ const th = document . createElement ( "th" ) ;
48+ th . style . textAlign = "left" ;
49+ th . textContent = key ;
50+ headerRow . appendChild ( th ) ;
51+ } ) ;
52+
53+ table . appendChild ( headerRow ) ;
54+
55+ results . forEach ( row => {
56+ const tr = document . createElement ( "tr" ) ;
57+ Object . entries ( row ) . forEach ( ( [ _ , value ] ) => {
58+ const td = document . createElement ( "td" ) ;
59+ if ( typeof value === "object" || Array . isArray ( value ) ) {
60+ td . textContent = JSON . stringify ( value ) ;
61+ } else {
62+ td . textContent = value ;
63+ }
64+ tr . appendChild ( td ) ;
65+ } ) ;
66+ table . appendChild ( tr ) ;
67+ } ) ;
68+
69+ return table ;
70+ }
71+
72+ function run ( ) {
73+ const input = document . getElementById ( "input" ) . value ;
74+ const output = document . getElementById ( "output" ) ;
75+ output . innerHTML = "" ;
76+ try {
77+ const flowquery = new FlowQuery ( input ) ;
78+ flowquery . run ( ) . then ( ( ) => {
79+ const table = createTable ( flowquery . results ) ;
80+ output . appendChild ( table ) ;
81+ } ) . catch ( e => {
82+ console . error ( e ) ;
83+ output . innerHTML = e . message ;
84+ } ) ;
85+ } catch ( e ) {
86+ console . error ( e ) ;
87+ output . innerHTML = e . message ;
88+ return ;
89+ }
90+ }
91+ </ script >
92+ </ head >
93+ < body >
94+ < textarea
95+ id ="input "
96+ rows ="10 "
97+ placeholder ="Type your FlowQuery statement here and press Shift+Enter to run it. "
98+ onkeydown ="if (event.key === 'Enter' && event.shiftKey) {
99+ run();
100+ event.preventDefault();
101+ } "
102+ > </ textarea >
103+ < div id ="output "> </ div >
104+ </ body >
105+ </ html >
0 commit comments