@@ -15,6 +15,7 @@ import { NodeInfo } from '../types/node-info';
1515interface FileInfo {
1616 fileName : string ;
1717 lines : string [ ] ;
18+ fileContent : string ;
1819}
1920
2021const selectFile = ( ) => {
@@ -32,7 +33,11 @@ const selectFile = () => {
3233 reader . addEventListener ( 'load' , ( event ) => {
3334 if ( event && event . target && event . target . result ) {
3435 const lines = ( event . target . result as string ) . split ( / \r \n | \n / ) ;
35- resolve ( { lines, fileName : files [ 0 ] . name } ) ;
36+ resolve ( {
37+ lines,
38+ fileContent : event . target . result as string ,
39+ fileName : files [ 0 ] . name ,
40+ } ) ;
3641 }
3742 input . remove ( ) ;
3843 } ) ;
@@ -50,18 +55,22 @@ const selectFile = () => {
5055
5156export const loadTextFileNodeName = 'load-text-file' ;
5257const fieldName = 'fileName' ;
53- export const loadTextFile = ( _updated : ( ) => void ) : NodeTask < NodeInfo > => {
58+ export const loadTextFile = ( updated : ( ) => void ) : NodeTask < NodeInfo > => {
5459 let node : IRectNodeComponent < NodeInfo > ;
5560 let htmlNode : INodeComponent < NodeInfo > | undefined = undefined ;
5661 let hasInitialValue = true ;
5762 let rect : ReturnType < IFlowCanvasBase < NodeInfo > [ 'createRect' ] > | undefined =
5863 undefined ;
5964 let lines : string [ ] = [ ] ;
65+ let fileContent = '' ;
6066 const initializeCompute = ( ) => {
6167 hasInitialValue = true ;
6268 if ( htmlNode && htmlNode . domElement ) {
6369 htmlNode . domElement . textContent = 'Click to load text file' ;
70+ ( htmlNode . domElement as HTMLElement ) . title = '' ;
6471 }
72+ fileContent = '' ;
73+ lines = [ ] ;
6574 return ;
6675 } ;
6776 const compute = ( ) => {
@@ -70,6 +79,12 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
7079 hasInitialValue = false ;
7180 }
7281 }
82+ if ( ! node . nodeInfo ?. formValues ?. parseLines ) {
83+ return {
84+ result : fileContent ,
85+ followPath : undefined ,
86+ } ;
87+ }
7388 return {
7489 result : lines ,
7590 followPath : undefined ,
@@ -100,9 +115,12 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
100115 . then ( ( fileInfo ) => {
101116 if ( htmlNode && fileInfo && node ) {
102117 lines = fileInfo . lines ;
103- ( htmlNode . domElement as HTMLImageElement ) . textContent = `${
118+ fileContent = fileInfo . fileContent ;
119+ const fileName = `${
104120 fileInfo . fileName
105- } : ${ lines . length . toString ( ) } `;
121+ } : ${ lines . length . toString ( ) } lines`;
122+ ( htmlNode . domElement as HTMLElement ) . textContent = fileName ;
123+ ( htmlNode . domElement as HTMLElement ) . title = fileName ;
106124 }
107125 resolve ( ) ;
108126 } )
@@ -112,11 +130,30 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
112130 } ) ;
113131 } ,
114132 } ,
133+ {
134+ fieldType : FormFieldType . Checkbox ,
135+ fieldName : 'parseLines' ,
136+ label : 'Parse lines' ,
137+ value : initalValues ?. [ 'parseLines' ] ?? false ,
138+ onChange : ( value : string ) => {
139+ if ( ! node . nodeInfo ) {
140+ return ;
141+ }
142+ node . nodeInfo . formValues = {
143+ ...node . nodeInfo . formValues ,
144+ parseLines : Boolean ( value ) ,
145+ } ;
146+
147+ if ( updated ) {
148+ updated ( ) ;
149+ }
150+ } ,
151+ } ,
115152 ] ;
116153 htmlNode = createElement (
117154 'div' ,
118155 {
119- class : '' ,
156+ class : 'overflow-hidden whitespace-nowrap text-ellipsis ' ,
120157 } ,
121158 undefined ,
122159 '-'
@@ -170,13 +207,6 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
170207 }
171208 ) ;
172209
173- if ( initalValues && initalValues [ fieldName ] && htmlNode ?. domElement ) {
174- hasInitialValue = false ;
175- (
176- htmlNode . domElement as HTMLImageElement
177- ) . src = `data:image/png;base64,${ initalValues [ fieldName ] } ` ;
178- }
179-
180210 if ( ! rect . nodeComponent ) {
181211 throw new Error ( 'rect.nodeComponent is undefined' ) ;
182212 }
@@ -188,7 +218,7 @@ export const loadTextFile = (_updated: () => void): NodeTask<NodeInfo> => {
188218 node . nodeInfo . compute = compute ;
189219 node . nodeInfo . initializeCompute = initializeCompute ;
190220 node . nodeInfo . formValues = {
191- image : initalValues ?. [ fieldName ] ?? '' ,
221+ parseLines : Boolean ( initalValues ?. [ 'parseLines' ] ) ?? false ,
192222 } ;
193223 }
194224 return node ;
0 commit comments