1+ "enable aexpr" ;
2+
3+ import Morph from 'src/components/widgets/lively-morph.js' ;
4+ import loadDropbox , { Graph } from 'src/client/triples/triples.js' ;
5+ import MultiSelection from 'src/client/vivide/multiselection.js' ;
6+ import { copyTextToClipboard } from 'utils' ;
7+
8+ export default class KnotCopyViewer extends Morph {
9+ get multiSelection ( ) {
10+ return this . _multiSelection = this . _multiSelection ||
11+ new MultiSelection ( this ) ;
12+ }
13+
14+ async initialize ( ) {
15+ this . windowTitle = "KnotCopyViewer" ;
16+ this . registerButtons ( )
17+
18+ lively . html . registerKeys ( this ) ; // automatically installs handler for some methods
19+
20+
21+
22+ await this . loadGraph ( )
23+ }
24+
25+ get list ( ) {
26+ return this . get ( "#list" )
27+ }
28+
29+ async loadGraph ( ) {
30+ let graph = await Graph . getInstance ( ) ;
31+
32+ graph . knots
33+ . filter ( knot => knot . url . endsWith ( "md" ) && ! knot . label ( ) . startsWith ( "Research-Diary" ) )
34+ . forEach ( ( knot , index ) => {
35+ let listItem = < li tabindex = "0" > </ li > ;
36+ listItem . innerHTML = knot . label ( ) ;
37+ listItem . setAttribute ( "tabindex" , "0" ) ;
38+ listItem . addEventListener ( "focus" , async ( ) => {
39+ this . showKnot ( knot , listItem ) ;
40+ } ) ;
41+ listItem . addEventListener ( "keydown" , async ( ) => {
42+ lively . notify ( 'fooo' )
43+ } ) ;
44+ this . appendChild ( listItem ) ;
45+ } ) ;
46+ }
47+
48+ showKnot ( knot , item ) {
49+ this . knot = knot ;
50+ this . item = item ;
51+ let editorComp = this . get ( '#editor' ) ;
52+ editorComp . value = knot . content ;
53+ copyTextToClipboard ( `${ knot . content }
54+
55+ ` )
56+ lively . notify ( knot . label ( ) )
57+ }
58+
59+ // this method is autmatically registered through the ``registerKeys`` method
60+ onKeyDown ( evt ) {
61+ lively . notify ( "Key Down!" + evt . charCode )
62+ }
63+
64+ // this method is automatically registered as handler through ``registerButtons``
65+ onPlusButton ( ) {
66+ this . get ( "#textField" ) . value = parseFloat ( this . get ( "#textField" ) . value ) + 1
67+ }
68+
69+ onMinusButton ( ) {
70+ this . get ( "#textField" ) . value = parseFloat ( this . get ( "#textField" ) . value ) - 1
71+ }
72+
73+ /* Lively-specific API */
74+
75+
76+ livelyMigrate ( other ) {
77+ // whenever a component is replaced with a newer version during development
78+ // this method is called on the new object during migration, but before initialization
79+ //this.someJavaScriptProperty = other.someJavaScriptProperty
80+ }
81+ }
0 commit comments