@@ -122,10 +122,10 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
122122 'font-size: 150%; padding-top: 1em; padding-bottom: 1em; width: 100%;'
123123 ]
124124
125- const author = kb . any ( chunk , ns . dc ( 'author' ) )
125+ const author = kb . any ( chunk as any , ns . dc ( 'author' ) )
126126 if ( ! colors && author ) {
127127 // Hash the user webid for now -- later allow user selection!
128- const bgcolor = lightColorHash ( author )
128+ const bgcolor = lightColorHash ( author as any )
129129 colors =
130130 'color: ' +
131131 ( pending ? '#888' : 'black' ) +
@@ -136,7 +136,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
136136
137137 // @@ TODO Need to research when this can be an object with the indent stored in value
138138 // and when the indent is stored as a Number itself, not in an object.
139- let indent = kb . any ( chunk , PAD ( 'indent' ) )
139+ let indent : any = kb . any ( chunk as any , PAD ( 'indent' ) )
140140
141141 indent = indent ? indent . value : 0
142142 const style =
@@ -150,17 +150,17 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
150150 const removePart = function ( part : NotepadPart ) {
151151 const chunk = part . subject
152152 if ( ! chunk ) throw new Error ( 'No chunk for line to be deleted!' ) // just in case
153- const prev = kb . any ( undefined , PAD ( 'next' ) , chunk )
154- const next = kb . any ( chunk , PAD ( 'next' ) )
153+ const prev : any = kb . any ( undefined , PAD ( 'next' ) , chunk as any )
154+ const next : any = kb . any ( chunk as any , PAD ( 'next' ) )
155155 if ( prev . sameTerm ( subject ) && next . sameTerm ( subject ) ) {
156156 // Last one
157157 log ( "You can't delete the only line." )
158158 return
159159 }
160160
161161 const del = kb
162- . statementsMatching ( chunk , undefined , undefined , padDoc )
163- . concat ( kb . statementsMatching ( undefined , undefined , chunk , padDoc ) )
162+ . statementsMatching ( chunk as any , undefined , undefined , padDoc )
163+ . concat ( kb . statementsMatching ( undefined , undefined , chunk as any , padDoc ) )
164164 const ins = [ st ( prev , PAD ( 'next' ) , next , padDoc ) ]
165165
166166 // @@ TODO what should we do if chunk is not a NamedNode should we
@@ -170,7 +170,9 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
170170
171171 log ( 'Deleting line ' + label )
172172 }
173-
173+ if ( ! updater ) {
174+ throw new Error ( 'have no updater' )
175+ }
174176 // @@ TODO below you can see that before is redefined and not a boolean
175177 updater . update ( del , ins , function ( uri , ok , errorMessage , response ) {
176178 if ( ok ) {
@@ -186,7 +188,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
186188 before . firstChild . focus ( )
187189 }
188190 }
189- } else if ( response && response . status === 409 ) {
191+ } else if ( response && ( response as any ) . status === 409 ) {
190192 // Conflict
191193 setPartStyle ( part , 'color: black; background-color: #ffd;' ) // yellow
192194 part . state = 0 // Needs downstream refresh
@@ -200,20 +202,23 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
200202 log ( ' removePart FAILED ' + chunk + ': ' + errorMessage )
201203 log ( " removePart was deleteing :'" + del )
202204 setPartStyle ( part , 'color: black; background-color: #fdd;' ) // failed
203- const res = response ? response . status : ' [no response field] '
204- complain ( 'Error ' + res + ' saving changes: ' + errorMessage . true ) // upstream,
205+ const res = response ? ( response as any ) . status : ' [no response field] '
206+ complain ( 'Error ' + res + ' saving changes: ' + ( errorMessage as any ) . true ) // upstream,
205207 // updater.requestDownstreamAction(padDoc, reloadAndSync);
206208 }
207209 } )
208210 } // removePart
209211
210212 const changeIndent = function ( part : NotepadPart , chunk : string , delta ) {
211- const del = kb . statementsMatching ( chunk , PAD ( 'indent' ) )
213+ const del = kb . statementsMatching ( chunk as any , PAD ( 'indent' ) )
212214 const current = del . length ? Number ( del [ 0 ] . object . value ) : 0
213215 if ( current + delta < - 3 ) return // limit negative indent
214216 const newIndent = current + delta
215217 const ins = st ( chunk as any , PAD ( 'indent' ) , newIndent , padDoc )
216- updater . update ( del , ins , function ( uri , ok , errorBody ) {
218+ if ( ! updater ) {
219+ throw new Error ( 'no updater' )
220+ }
221+ updater . update ( del , ins as any , function ( uri , ok , errorBody ) {
217222 if ( ! ok ) {
218223 log (
219224 "Indent change FAILED '" +
@@ -255,6 +260,10 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
255260 */
256261 const addListeners = function ( part : any , chunk : any ) {
257262 part . addEventListener ( 'keydown' , function ( event ) {
263+ if ( ! updater ) {
264+ throw new Error ( 'no updater' )
265+ }
266+
258267 let queueProperty , queue
259268 // up 38; down 40; left 37; right 39 tab 9; shift 16; escape 27
260269 switch ( event . keyCode ) {
@@ -337,9 +346,8 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
337346
338347 const updateStore = function ( part : NotepadPart ) {
339348 const chunk : any = part . subject
340-
341349 setPartStyle ( part , undefined , true )
342- const old = kb . any ( chunk , ns . sioc ( 'content' ) ) . value
350+ const old = ( kb . any ( chunk , ns . sioc ( 'content' ) ) as any ) . value
343351 const del = [ st ( chunk , ns . sioc ( 'content' ) , old , padDoc ) ]
344352 let ins
345353 if ( part . value ) {
@@ -370,21 +378,24 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
370378 newOne +
371379 "' "
372380 ) */
381+ if ( ! updater ) {
382+ throw new Error ( 'no updater' )
383+ }
373384
374385 updater . update ( del , ins , function ( uri , ok , errorBody , xhr ) {
375386 if ( ! ok ) {
376387 // alert("clash " + errorBody);
377388 log (
378389 ' patch FAILED ' +
379- xhr . status +
390+ ( xhr as any ) . status +
380391 " for '" +
381392 old +
382393 "' -> '" +
383394 newOne +
384395 "': " +
385396 errorBody
386397 )
387- if ( xhr . status === 409 ) {
398+ if ( ( xhr as any ) . status === 409 ) {
388399 // Conflict - @@ we assume someone else
389400 setPartStyle ( part , 'color: black; background-color: #fdd;' )
390401 part . state = 0 // Needs downstream refresh
@@ -396,7 +407,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
396407 setPartStyle ( part , 'color: black; background-color: #fdd;' ) // failed pink
397408 part . state = 0
398409 complain (
399- ' Error ' + xhr . status + ' sending data: ' + errorBody ,
410+ ' Error ' + ( xhr as any ) . status + ' sending data: ' + errorBody ,
400411 true
401412 )
402413 beep ( 1.0 , 128 ) // Other
@@ -451,7 +462,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
451462 // @@ TODO Need to research before as it appears to be used as an Element and a boolean
452463 const newPartAfter = function ( tr1 : HTMLTableElement , chunk : String , before ?: NotepadElement | boolean ) {
453464 // @@ take chunk and add listeners
454- let text = kb . any ( chunk , ns . sioc ( 'content' ) )
465+ let text : any = kb . any ( chunk as any , ns . sioc ( 'content' ) )
455466 text = text ? text . value : ''
456467 const tr = dom . createElement ( 'tr' )
457468 if ( before ) {
@@ -528,6 +539,9 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
528539 }
529540
530541 log ( ' Fresh chunk ' + label + ' proposed' )
542+ if ( ! updater ) {
543+ throw new Error ( 'no updater' )
544+ }
531545 updater . update ( del , ins , function ( uri , ok , errorBody , _xhr ) {
532546 if ( ! ok ) {
533547 // alert("Error writing new line " + label + ": " + errorBody);
@@ -608,8 +622,8 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
608622
609623 const sts = kb . statementsMatching ( undefined , ns . sioc ( 'contents' ) )
610624 sts . forEach ( function ( st ) {
611- if ( ! found [ st . subject . uri ] ) {
612- complain2 ( 'Loose chunk! ' + st . subject . uri )
625+ if ( ! found [ st . subject . value ] ) {
626+ complain2 ( 'Loose chunk! ' + st . subject . value )
613627 }
614628 } )
615629 }
@@ -639,7 +653,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
639653 // Find which lines correspond to existing chunks
640654
641655 for (
642- let chunk = kb . the ( subject , PAD ( 'next' ) ) ;
656+ let chunk = kb . the ( subject , PAD ( 'next' ) ) as unknown as any ;
643657 ! chunk . sameTerm ( subject ) ;
644658 chunk = kb . the ( chunk , PAD ( 'next' ) )
645659 ) {
@@ -663,11 +677,11 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
663677 // Insert any new lines and update old ones
664678 row = table . firstChild // might be null
665679 for (
666- let chunk = kb . the ( subject , PAD ( 'next' ) ) ;
680+ let chunk = kb . the ( subject , PAD ( 'next' ) ) as unknown as any ;
667681 ! chunk . sameTerm ( subject ) ;
668682 chunk = kb . the ( chunk , PAD ( 'next' ) )
669683 ) {
670- const text = kb . any ( chunk , ns . sioc ( 'content' ) ) . value
684+ const text = ( kb . any ( chunk , ns . sioc ( 'content' ) ) as any ) . value
671685 // superstitious -- don't mess with unchanged input fields
672686 // which may be selected by the user
673687 if ( row && manif [ chunk . uri ] ) {
@@ -718,12 +732,15 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
718732 let retryTimeout = 1000 // ms
719733 const tryReload = function ( ) {
720734 log ( 'try reload - timeout = ' + retryTimeout )
735+ if ( ! updater ) {
736+ throw new Error ( 'no updater' )
737+ }
721738 updater . reload ( updater . store , padDoc , function ( ok , message , xhr ) {
722739 reloading = false
723740 if ( ok ) {
724741 checkAndSync ( )
725742 } else {
726- if ( xhr . status === 0 ) {
743+ if ( ( xhr as any ) . status === 0 ) {
727744 complain (
728745 'Network error refreshing the pad. Retrying in ' +
729746 retryTimeout / 1000
@@ -734,7 +751,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
734751 } else {
735752 complain (
736753 'Error ' +
737- xhr . status +
754+ ( xhr as any ) . status +
738755 'refreshing the pad:' +
739756 message +
740757 '. Stopped. ' +
@@ -773,9 +790,12 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
773790 st ( subject , PAD ( 'next' ) , subject , padDoc )
774791 ]
775792
776- updater . update ( [ ] , insertables , function ( uri : string , ok : boolean , errorBody : string ) {
793+ if ( ! updater ) {
794+ throw new Error ( 'no updater' )
795+ }
796+ updater . update ( [ ] , insertables , function ( uri : string | null | undefined , ok : boolean , errorBody ?: string ) {
777797 if ( ! ok ) {
778- complain ( errorBody )
798+ complain ( errorBody || '' )
779799 } else {
780800 log ( 'Initial pad created' )
781801 newChunk ( ) // Add a first chunck
@@ -795,7 +815,7 @@ export function notepad (dom: HTMLDocument, padDoc: NamedNode, subject: NamedNod
795815export function getChunks ( subject : NamedNode , kb : IndexedFormula ) {
796816 const chunks : any [ ] = [ ]
797817 for (
798- let chunk = kb . the ( subject , PAD ( 'next' ) ) ;
818+ let chunk : any = kb . the ( subject , PAD ( 'next' ) ) ;
799819 ! chunk . sameTerm ( subject ) ;
800820 chunk = kb . the ( chunk , PAD ( 'next' ) )
801821 ) {
0 commit comments